Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(563)

Side by Side Diff: chrome/browser/ui/cocoa/translate/translate_bubble_controller.mm

Issue 151283006: Mac OS X: Show the Translate icon on Omnibox (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@issue-307352-translate-bubble-2
Patch Set: . Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #import "chrome/browser/ui/cocoa/translate/translate_bubble_controller.h"
6
7 #include "base/mac/scoped_nsobject.h"
8 #include "chrome/browser/translate/translate_ui_delegate.h"
9 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
10 #import "chrome/browser/ui/cocoa/info_bubble_view.h"
11 #import "chrome/browser/ui/cocoa/info_bubble_window.h"
12 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h"
13 #include "chrome/browser/ui/translate/translate_bubble_model_impl.h"
14 #import "ui/base/cocoa/flipped_view.h"
15
16 namespace {
17
18 const CGFloat kWindowWidth = 320;
Nico 2014/02/05 06:07:18 "const" has implicit internal linkage, no need for
hajimehoshi 2014/02/05 11:08:03 Done.
19
20 } // namespace
21
22 @implementation TranslateBubbleController
23
24 static TranslateBubbleController* translateBubbleController_ = NULL;
25
26 + (void)showBubbleWithBrowserWindowController:(BrowserWindowController*)controll er
Nico 2014/02/05 06:07:18 80 cols
hajimehoshi 2014/02/05 11:08:03 Done.
27 webContents:(content::WebContents*)webContents
28 viewState:
29 (TranslateBubbleModel::ViewState)viewState
30 errorType:(TranslateErrors::Type)errorType {
31 if (translateBubbleController_) {
32 // When the user reads the advanced setting panel, the bubble should not be
33 // changed because he/she is focusing on the bubble.
34 if (translateBubbleController_->webContents_ == webContents &&
35 translateBubbleController_->model_->GetViewState() ==
36 TranslateBubbleModel::VIEW_STATE_ADVANCED) {
37 return;
38 }
39 if (viewState != TranslateBubbleModel::VIEW_STATE_ERROR)
40 [translateBubbleController_ switchView:viewState];
41 else
42 [translateBubbleController_ switchToErrorView:errorType];
43 return;
44 }
45
46 // FIXME(hajimehoshi): Set the initial languages correctly.
Nico 2014/02/05 06:07:18 fixme
hajimehoshi 2014/02/05 11:08:03 Lower cases? Done.
47 std::string sourceLanguage = "xx";
48 std::string targetLanguage = "yy";
49
50 scoped_ptr<TranslateUIDelegate> uiDelegate(
51 new TranslateUIDelegate(webContents, sourceLanguage, targetLanguage));
52 scoped_ptr<TranslateBubbleModel> model(
53 new TranslateBubbleModelImpl(viewState, uiDelegate.Pass()));
54 translateBubbleController_ = [[TranslateBubbleController alloc]
55 initWithBrowserWindowController:controller
56 model:model.Pass()
57 webContents:webContents];
58 [translateBubbleController_ showWindow:nil];
59 }
60
61 - (id)initWithBrowserWindowController:(BrowserWindowController*)controller
62 model:(scoped_ptr<TranslateBubbleModel>)model
63 webContents:(content::WebContents*)webContents {
64 webContents_ = webContents;
Nico 2014/02/05 06:07:18 You can't write to ivars before the `self = …` has
hajimehoshi 2014/02/05 11:08:03 Done.
65 model_ = model.Pass();
66 translateExecuted_ = NO;
67 if (model_->GetViewState() !=
68 TranslateBubbleModel::VIEW_STATE_BEFORE_TRANSLATE) {
69 translateExecuted_ = YES;
70 }
71
72 NSWindow* parentWindow = [controller window];
73
74 // Use an arbitrary size; it will be changed in performLayout.
75 NSRect contentRect = NSMakeRect(0, 0, kWindowWidth, 100);
76 base::scoped_nsobject<InfoBubbleWindow> window(
77 [[InfoBubbleWindow alloc] initWithContentRect:contentRect
78 styleMask:NSBorderlessWindowMask
79 backing:NSBackingStoreBuffered
80 defer:NO]);
81
82 if ((self = [super initWithWindow:window
83 parentWindow:parentWindow
84 anchoredAt:NSZeroPoint])) {
85 // Create the container view that uses flipped coordinates.
86 CGFloat x = info_bubble::kBubbleCornerRadius;
87 CGFloat y = -info_bubble::kBubbleCornerRadius;
88 NSRect contentFrame = NSMakeRect(x, y, kWindowWidth, 100);
89 NSView* contentView = [[FlippedView alloc] initWithFrame:contentFrame];
90 [[window contentView] setSubviews:@[contentView]];
91
92 [self performLayout];
93
94 // This class will release itself when the bubble closes. See
95 // -[BaseBubbleController windowWillClose:].
96 [self retain];
97 }
98 return self;
99 }
100
101 - (void)windowWillClose:(NSNotification*)notification {
102 DCHECK_EQ(translateBubbleController_, self);
103 translateBubbleController_ = NULL;
104 [super windowWillClose:notification];
105 }
106
107 - (void)showWindow:(id)sender {
108 BrowserWindowController* controller = [self.parentWindow windowController];
109 NSPoint anchorPoint = [[controller toolbarController] translateBubblePoint];
110 anchorPoint = [self.parentWindow convertBaseToScreen:anchorPoint];
111 [self setAnchorPoint:anchorPoint];
112 [super showWindow:sender];
113 }
114
115 - (void)switchView:(TranslateBubbleModel::ViewState)viewState {
116 if (model_->GetViewState() == viewState)
117 return;
118
119 model_->SetViewState(viewState);
120 [self performLayout];
121 }
122
123 - (void)switchToErrorView:(TranslateErrors::Type)errorType {
124 // FIXME(hajimehoshi): Implement this.
125 }
126
127 - (void)performLayout {
128 // FIXME(hajimehoshi): Now this shows just an empty bubble. Implement this.
129 [[self window] display];
130 }
131
132 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698