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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/translate/translate_bubble_controller.mm
diff --git a/chrome/browser/ui/cocoa/translate/translate_bubble_controller.mm b/chrome/browser/ui/cocoa/translate/translate_bubble_controller.mm
new file mode 100644
index 0000000000000000000000000000000000000000..fd570a13a20c8e93c6c3fbfd2538cf929177acdd
--- /dev/null
+++ b/chrome/browser/ui/cocoa/translate/translate_bubble_controller.mm
@@ -0,0 +1,122 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "chrome/browser/ui/cocoa/translate/translate_bubble_controller.h"
+
+#include "base/mac/scoped_nsobject.h"
+#include "chrome/browser/translate/translate_ui_delegate.h"
+#import "chrome/browser/ui/cocoa/browser_window_controller.h"
+#import "chrome/browser/ui/cocoa/info_bubble_view.h"
+#import "chrome/browser/ui/cocoa/info_bubble_window.h"
+#import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h"
+#include "chrome/browser/ui/translate/translate_bubble_model_impl.h"
+#import "ui/base/cocoa/flipped_view.h"
+#import "ui/base/cocoa/window_size_constants.h"
+
+@implementation TranslateBubbleController
+
+static TranslateBubbleController* translateBubbleController_ = NULL;
+
++ (void)showForParentWindow:(BrowserWindowController*)controller
+ webContents:(content::WebContents*)webContents
+ step:(TranslateTabHelper::TranslateStep)step
+ errorType:(TranslateErrors::Type)errorType {
+ if (translateBubbleController_) {
hajimehoshi 2014/02/26 09:18:18 I remembered that this logic was very similar to T
+ // When the user reads the advanced setting panel, the bubble should not be
+ // changed because he/she is focusing on the bubble.
+ if (translateBubbleController_->webContents_ == webContents &&
+ translateBubbleController_->model_->GetViewState() ==
+ TranslateBubbleModel::VIEW_STATE_ADVANCED) {
+ return;
+ }
+ if (step != TranslateTabHelper::TRANSLATE_ERROR) {
+ TranslateBubbleModel::ViewState viewState =
+ TranslateBubbleModelImpl::TranslateStepToViewState(step);
+ [translateBubbleController_ switchView:viewState];
+ } else {
+ [translateBubbleController_ switchToErrorView:errorType];
+ }
+ return;
+ }
+
+ // fixme(hajimehoshi): Set the initial languages correctly.
+ std::string sourceLanguage = "xx";
+ std::string targetLanguage = "yy";
+
+ scoped_ptr<TranslateUIDelegate> uiDelegate(
+ new TranslateUIDelegate(webContents, sourceLanguage, targetLanguage));
+ scoped_ptr<TranslateBubbleModel> model(
+ new TranslateBubbleModelImpl(step, uiDelegate.Pass()));
+ translateBubbleController_ = [[TranslateBubbleController alloc]
+ initForParentWindow:controller
+ model:model.Pass()
+ webContents:webContents];
+ [translateBubbleController_ showWindow:nil];
+}
+
++ (TranslateBubbleController*)current {
+ return translateBubbleController_;
+}
+
+- (id)initForParentWindow:(BrowserWindowController*)controller
+ model:(scoped_ptr<TranslateBubbleModel>)model
+ webContents:(content::WebContents*)webContents {
+ NSWindow* parentWindow = [controller window];
+
+ // Use an arbitrary size; it will be changed in performLayout.
+ NSRect contentRect = ui::kWindowSizeDeterminedLater;
+ base::scoped_nsobject<InfoBubbleWindow> window(
+ [[InfoBubbleWindow alloc] initWithContentRect:contentRect
+ styleMask:NSBorderlessWindowMask
+ backing:NSBackingStoreBuffered
+ defer:NO]);
+
+ if ((self = [super initWithWindow:window
+ parentWindow:parentWindow
+ anchoredAt:NSZeroPoint])) {
+ webContents_ = webContents;
+ model_ = model.Pass();
+ 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.
+ if (model_->GetViewState() !=
+ TranslateBubbleModel::VIEW_STATE_BEFORE_TRANSLATE) {
+ translateExecuted_ = YES;
+ }
+
+ [self performLayout];
+ }
+ return self;
+}
+
+- (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.
+ DCHECK_EQ(translateBubbleController_, self);
+ translateBubbleController_ = NULL;
+ [super windowWillClose:notification];
+}
+
+- (void)showWindow:(id)sender {
+ BrowserWindowController* controller = [[self parentWindow] windowController];
+ NSPoint anchorPoint = [[controller toolbarController] translateBubblePoint];
+ anchorPoint = [[self parentWindow] convertBaseToScreen:anchorPoint];
+ [self setAnchorPoint:anchorPoint];
+ [super showWindow:sender];
+}
+
+- (void)switchView:(TranslateBubbleModel::ViewState)viewState {
+ if (model_->GetViewState() == viewState)
+ return;
+
+ model_->SetViewState(viewState);
+ [self performLayout];
+}
+
+- (void)switchToErrorView:(TranslateErrors::Type)errorType {
+ // fixme(hajimehoshi): Implement this.
+}
+
+- (void)performLayout {
+ // fixme(hajimehoshi): Now this shows just an empty bubble. Implement this.
+ [[self window] display];
+}
+
+@end

Powered by Google App Engine
This is Rietveld 408576698