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

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: groby's review 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 #import "ui/base/cocoa/window_size_constants.h"
16
17 @implementation TranslateBubbleController
18
19 static TranslateBubbleController* translateBubbleController_ = NULL;
20
21 + (void)showForParentWindow:(BrowserWindowController*)controller
22 webContents:(content::WebContents*)webContents
23 step:(TranslateTabHelper::TranslateStep)step
24 errorType:(TranslateErrors::Type)errorType {
25 if (translateBubbleController_) {
hajimehoshi 2014/02/26 09:18:18 I remembered that this logic was very similar to T
26 // When the user reads the advanced setting panel, the bubble should not be
27 // changed because he/she is focusing on the bubble.
28 if (translateBubbleController_->webContents_ == webContents &&
29 translateBubbleController_->model_->GetViewState() ==
30 TranslateBubbleModel::VIEW_STATE_ADVANCED) {
31 return;
32 }
33 if (step != TranslateTabHelper::TRANSLATE_ERROR) {
34 TranslateBubbleModel::ViewState viewState =
35 TranslateBubbleModelImpl::TranslateStepToViewState(step);
36 [translateBubbleController_ switchView:viewState];
37 } else {
38 [translateBubbleController_ switchToErrorView:errorType];
39 }
40 return;
41 }
42
43 // fixme(hajimehoshi): Set the initial languages correctly.
44 std::string sourceLanguage = "xx";
45 std::string targetLanguage = "yy";
46
47 scoped_ptr<TranslateUIDelegate> uiDelegate(
48 new TranslateUIDelegate(webContents, sourceLanguage, targetLanguage));
49 scoped_ptr<TranslateBubbleModel> model(
50 new TranslateBubbleModelImpl(step, uiDelegate.Pass()));
51 translateBubbleController_ = [[TranslateBubbleController alloc]
52 initForParentWindow:controller
53 model:model.Pass()
54 webContents:webContents];
55 [translateBubbleController_ showWindow:nil];
56 }
57
58 + (TranslateBubbleController*)current {
59 return translateBubbleController_;
60 }
61
62 - (id)initForParentWindow:(BrowserWindowController*)controller
63 model:(scoped_ptr<TranslateBubbleModel>)model
64 webContents:(content::WebContents*)webContents {
65 NSWindow* parentWindow = [controller window];
66
67 // Use an arbitrary size; it will be changed in performLayout.
68 NSRect contentRect = ui::kWindowSizeDeterminedLater;
69 base::scoped_nsobject<InfoBubbleWindow> window(
70 [[InfoBubbleWindow alloc] initWithContentRect:contentRect
71 styleMask:NSBorderlessWindowMask
72 backing:NSBackingStoreBuffered
73 defer:NO]);
74
75 if ((self = [super initWithWindow:window
76 parentWindow:parentWindow
77 anchoredAt:NSZeroPoint])) {
78 webContents_ = webContents;
79 model_ = model.Pass();
80 translateExecuted_ = NO;
groby-ooo-7-16 2014/02/26 03:13:58 No need to do this - Cocoa member vars are always
hajimehoshi 2014/02/26 09:18:18 Done.
81 if (model_->GetViewState() !=
82 TranslateBubbleModel::VIEW_STATE_BEFORE_TRANSLATE) {
83 translateExecuted_ = YES;
84 }
85
86 [self performLayout];
87 }
88 return self;
89 }
90
91 - (void)windowWillClose:(NSNotification*)notification {
groby-ooo-7-16 2014/02/26 03:13:58 If you move the BubbleController onto BrowserWindo
hajimehoshi 2014/02/26 09:18:18 Done.
92 DCHECK_EQ(translateBubbleController_, self);
93 translateBubbleController_ = NULL;
94 [super windowWillClose:notification];
95 }
96
97 - (void)showWindow:(id)sender {
98 BrowserWindowController* controller = [[self parentWindow] windowController];
99 NSPoint anchorPoint = [[controller toolbarController] translateBubblePoint];
100 anchorPoint = [[self parentWindow] convertBaseToScreen:anchorPoint];
101 [self setAnchorPoint:anchorPoint];
102 [super showWindow:sender];
103 }
104
105 - (void)switchView:(TranslateBubbleModel::ViewState)viewState {
106 if (model_->GetViewState() == viewState)
107 return;
108
109 model_->SetViewState(viewState);
110 [self performLayout];
111 }
112
113 - (void)switchToErrorView:(TranslateErrors::Type)errorType {
114 // fixme(hajimehoshi): Implement this.
115 }
116
117 - (void)performLayout {
118 // fixme(hajimehoshi): Now this shows just an empty bubble. Implement this.
119 [[self window] display];
120 }
121
122 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698