Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 const CGFloat kWindowWidth = 320; | |
| 17 | |
| 18 @implementation TranslateBubbleController | |
| 19 | |
| 20 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.
| |
| 21 | |
| 22 + (void) | |
| 23 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.
| |
| 24 webContents:(content::WebContents*)webContents | |
| 25 viewState: | |
| 26 (TranslateBubbleModel::ViewState)viewState | |
| 27 errorType:(TranslateErrors::Type)errorType { | |
| 28 if (translateBubbleController_) { | |
| 29 // When the user reads the advanced setting panel, the bubble should not be | |
| 30 // changed because he/she is focusing on the bubble. | |
| 31 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
| |
| 32 translateBubbleController_->model_->GetViewState() == | |
| 33 TranslateBubbleModel::VIEW_STATE_ADVANCED) { | |
| 34 return; | |
| 35 } | |
| 36 if (viewState != TranslateBubbleModel::VIEW_STATE_ERROR) | |
| 37 [translateBubbleController_ switchView:viewState]; | |
| 38 else | |
| 39 [translateBubbleController_ switchToErrorView:errorType]; | |
| 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(viewState, uiDelegate.Pass())); | |
| 51 translateBubbleController_ = [[TranslateBubbleController alloc] | |
| 52 initWithBrowserWindowController:controller | |
| 53 model:model.Pass() | |
| 54 webContents:webContents]; | |
| 55 [translateBubbleController_ showWindow:nil]; | |
| 56 } | |
| 57 | |
| 58 - (id)initWithBrowserWindowController:(BrowserWindowController*)controller | |
| 59 model:(scoped_ptr<TranslateBubbleModel>)model | |
| 60 webContents:(content::WebContents*)webContents { | |
| 61 NSWindow* parentWindow = [controller window]; | |
| 62 | |
| 63 // Use an arbitrary size; it will be changed in performLayout. | |
| 64 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.
| |
| 65 base::scoped_nsobject<InfoBubbleWindow> window( | |
| 66 [[InfoBubbleWindow alloc] initWithContentRect:contentRect | |
| 67 styleMask:NSBorderlessWindowMask | |
| 68 backing:NSBackingStoreBuffered | |
| 69 defer:NO]); | |
| 70 | |
| 71 if ((self = [super initWithWindow:window | |
| 72 parentWindow:parentWindow | |
| 73 anchoredAt:NSZeroPoint])) { | |
| 74 webContents_ = webContents; | |
| 75 model_ = model.Pass(); | |
| 76 translateExecuted_ = NO; | |
| 77 if (model_->GetViewState() != | |
| 78 TranslateBubbleModel::VIEW_STATE_BEFORE_TRANSLATE) { | |
| 79 translateExecuted_ = YES; | |
| 80 } | |
| 81 | |
| 82 // Create the container view that uses flipped coordinates. | |
| 83 CGFloat x = info_bubble::kBubbleCornerRadius; | |
| 84 CGFloat y = -info_bubble::kBubbleCornerRadius; | |
| 85 NSRect contentFrame = NSMakeRect(x, y, kWindowWidth, 100); | |
| 86 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.
| |
| 87 [[window contentView] setSubviews:@[ contentView ]]; | |
| 88 | |
| 89 [self performLayout]; | |
| 90 | |
| 91 // This class will release itself when the bubble closes. See | |
| 92 // -[BaseBubbleController windowWillClose:]. | |
| 93 [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.
| |
| 94 } | |
| 95 return self; | |
| 96 } | |
| 97 | |
| 98 - (void)windowWillClose:(NSNotification*)notification { | |
| 99 DCHECK_EQ(translateBubbleController_, self); | |
| 100 translateBubbleController_ = NULL; | |
| 101 [super windowWillClose:notification]; | |
| 102 } | |
| 103 | |
| 104 - (void)showWindow:(id)sender { | |
| 105 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.
| |
| 106 NSPoint anchorPoint = [[controller toolbarController] translateBubblePoint]; | |
| 107 anchorPoint = [self.parentWindow convertBaseToScreen:anchorPoint]; | |
| 108 [self setAnchorPoint:anchorPoint]; | |
| 109 [super showWindow:sender]; | |
| 110 } | |
| 111 | |
| 112 - (void)switchView:(TranslateBubbleModel::ViewState)viewState { | |
| 113 if (model_->GetViewState() == viewState) | |
| 114 return; | |
| 115 | |
| 116 model_->SetViewState(viewState); | |
| 117 [self performLayout]; | |
| 118 } | |
| 119 | |
| 120 - (void)switchToErrorView:(TranslateErrors::Type)errorType { | |
| 121 // fixme(hajimehoshi): Implement this. | |
| 122 } | |
| 123 | |
| 124 - (void)performLayout { | |
| 125 // fixme(hajimehoshi): Now this shows just an empty bubble. Implement this. | |
| 126 [[self window] display]; | |
| 127 } | |
| 128 | |
| 129 @end | |
| OLD | NEW |