| 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 #import "ui/base/cocoa/window_size_constants.h" |
| 16 |
| 17 @implementation TranslateBubbleController |
| 18 |
| 19 - (id)initWithParentWindow:(BrowserWindowController*)controller |
| 20 model:(scoped_ptr<TranslateBubbleModel>)model |
| 21 webContents:(content::WebContents*)webContents { |
| 22 NSWindow* parentWindow = [controller window]; |
| 23 |
| 24 // Use an arbitrary size; it will be changed in performLayout. |
| 25 NSRect contentRect = ui::kWindowSizeDeterminedLater; |
| 26 base::scoped_nsobject<InfoBubbleWindow> window( |
| 27 [[InfoBubbleWindow alloc] initWithContentRect:contentRect |
| 28 styleMask:NSBorderlessWindowMask |
| 29 backing:NSBackingStoreBuffered |
| 30 defer:NO]); |
| 31 |
| 32 if ((self = [super initWithWindow:window |
| 33 parentWindow:parentWindow |
| 34 anchoredAt:NSZeroPoint])) { |
| 35 webContents_ = webContents; |
| 36 model_ = model.Pass(); |
| 37 if (model_->GetViewState() != |
| 38 TranslateBubbleModel::VIEW_STATE_BEFORE_TRANSLATE) { |
| 39 translateExecuted_ = YES; |
| 40 } |
| 41 |
| 42 [self performLayout]; |
| 43 } |
| 44 return self; |
| 45 } |
| 46 |
| 47 @synthesize webContents = webContents_; |
| 48 |
| 49 - (const TranslateBubbleModel*)model { |
| 50 return model_.get(); |
| 51 } |
| 52 |
| 53 - (void)showWindow:(id)sender { |
| 54 BrowserWindowController* controller = [[self parentWindow] windowController]; |
| 55 NSPoint anchorPoint = [[controller toolbarController] translateBubblePoint]; |
| 56 anchorPoint = [[self parentWindow] convertBaseToScreen:anchorPoint]; |
| 57 [self setAnchorPoint:anchorPoint]; |
| 58 [super showWindow:sender]; |
| 59 } |
| 60 |
| 61 - (void)switchView:(TranslateBubbleModel::ViewState)viewState { |
| 62 if (model_->GetViewState() == viewState) |
| 63 return; |
| 64 |
| 65 model_->SetViewState(viewState); |
| 66 [self performLayout]; |
| 67 } |
| 68 |
| 69 - (void)switchToErrorView:(TranslateErrors::Type)errorType { |
| 70 // TODO(hajimehoshi): Implement this. |
| 71 } |
| 72 |
| 73 - (void)performLayout { |
| 74 // TODO(hajimehoshi): Now this shows just an empty bubble. Implement this. |
| 75 [[self window] display]; |
| 76 } |
| 77 |
| 78 @end |
| OLD | NEW |