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

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: Nico'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..63ce0dfa37e1797aa169bf2a24fb2d645d68b01d
--- /dev/null
+++ b/chrome/browser/ui/cocoa/translate/translate_bubble_controller.mm
@@ -0,0 +1,129 @@
+// 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"
+
+const CGFloat kWindowWidth = 320;
+
+@implementation TranslateBubbleController
+
+static TranslateBubbleController* translateBubbleController_ = NULL;
groby-ooo-7-16 2014/02/11 00:43:55 Is there any way for an object to hold this contro
hajimehoshi 2014/02/25 09:31:07 Hmm, like StarDecoration, I implemented to show th
groby-ooo-7-16 2014/02/26 03:13:58 I think you should stick with the CommandUpdater s
hajimehoshi 2014/02/26 09:18:18 Thanks. I agree to move this. Done.
+
++ (void)
+ showBubbleWithBrowserWindowController:(BrowserWindowController*)controller
groby-ooo-7-16 2014/02/11 00:43:55 Please keep return type and method name on same li
hajimehoshi 2014/02/25 09:31:07 Done.
+ webContents:(content::WebContents*)webContents
+ viewState:
+ (TranslateBubbleModel::ViewState)viewState
+ errorType:(TranslateErrors::Type)errorType {
+ if (translateBubbleController_) {
+ // 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 &&
groby-ooo-7-16 2014/02/11 00:43:55 I'm curious - can translateBubbleController ever h
hajimehoshi 2014/02/25 09:31:07 No, translatebubbleController can have only one we
+ translateBubbleController_->model_->GetViewState() ==
+ TranslateBubbleModel::VIEW_STATE_ADVANCED) {
+ return;
+ }
+ if (viewState != TranslateBubbleModel::VIEW_STATE_ERROR)
+ [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(viewState, uiDelegate.Pass()));
+ translateBubbleController_ = [[TranslateBubbleController alloc]
+ initWithBrowserWindowController:controller
+ model:model.Pass()
+ webContents:webContents];
+ [translateBubbleController_ showWindow:nil];
+}
+
+- (id)initWithBrowserWindowController:(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 = NSMakeRect(0, 0, kWindowWidth, 100);
groby-ooo-7-16 2014/02/11 00:43:55 Use ui::kWindowSizeDeterminedLater, and then set t
hajimehoshi 2014/02/25 09:31:07 Done.
+ 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;
+ if (model_->GetViewState() !=
+ TranslateBubbleModel::VIEW_STATE_BEFORE_TRANSLATE) {
+ translateExecuted_ = YES;
+ }
+
+ // Create the container view that uses flipped coordinates.
+ CGFloat x = info_bubble::kBubbleCornerRadius;
+ CGFloat y = -info_bubble::kBubbleCornerRadius;
+ NSRect contentFrame = NSMakeRect(x, y, kWindowWidth, 100);
+ NSView* contentView = [[FlippedView alloc] initWithFrame:contentFrame];
groby-ooo-7-16 2014/02/11 00:43:55 Unless you need the FlippedView, I would skip this
hajimehoshi 2014/02/25 09:31:07 Removed this once. Done.
+ [[window contentView] setSubviews:@[ contentView ]];
+
+ [self performLayout];
+
+ // This class will release itself when the bubble closes. See
+ // -[BaseBubbleController windowWillClose:].
+ [self retain];
groby-ooo-7-16 2014/02/11 00:43:55 The class is already retained through the alloc ca
hajimehoshi 2014/02/25 09:31:07 Done.
+ }
+ return self;
+}
+
+- (void)windowWillClose:(NSNotification*)notification {
+ DCHECK_EQ(translateBubbleController_, self);
+ translateBubbleController_ = NULL;
+ [super windowWillClose:notification];
+}
+
+- (void)showWindow:(id)sender {
+ BrowserWindowController* controller = [self.parentWindow windowController];
groby-ooo-7-16 2014/02/11 00:43:55 nit:Since the rest of the file doesn't use dot not
hajimehoshi 2014/02/25 09:31:07 Done.
+ 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