| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "chrome/browser/ui/cocoa/one_click_signin_bubble_controller.h" | 5 #import "chrome/browser/ui/cocoa/one_click_signin_bubble_controller.h" |
| 6 | 6 |
| 7 #include "base/strings/sys_string_conversions.h" |
| 7 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 8 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 8 #import "chrome/browser/ui/cocoa/info_bubble_window.h" | 9 #import "chrome/browser/ui/cocoa/info_bubble_window.h" |
| 9 #import "chrome/browser/ui/cocoa/one_click_signin_view_controller.h" | 10 #import "chrome/browser/ui/cocoa/one_click_signin_view_controller.h" |
| 10 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" | 11 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" |
| 11 | 12 |
| 12 namespace { | 13 namespace { |
| 13 | 14 |
| 14 void PerformClose(OneClickSigninBubbleController* controller) { | 15 void PerformClose(OneClickSigninBubbleController* controller) { |
| 15 [controller close]; | 16 [controller close]; |
| 16 } | 17 } |
| 17 | 18 |
| 18 } // namespace | 19 } // namespace |
| 19 | 20 |
| 20 @implementation OneClickSigninBubbleController | 21 @implementation OneClickSigninBubbleController |
| 21 | 22 |
| 22 - (id)initWithBrowserWindowController:(BrowserWindowController*)controller | 23 - (id)initWithBrowserWindowController:(BrowserWindowController*)controller |
| 24 webContents:(content::WebContents*)webContents |
| 25 errorMessage:(NSString*)errorMessage |
| 23 callback:(const BrowserWindow::StartSyncCallback&) | 26 callback:(const BrowserWindow::StartSyncCallback&) |
| 24 syncCallback { | 27 syncCallback{ |
| 25 viewController_.reset([[OneClickSigninViewController alloc] | 28 viewController_.reset([[OneClickSigninViewController alloc] |
| 26 initWithNibName:@"OneClickSigninBubble" | 29 initWithNibName:@"OneClickSigninBubble" |
| 27 webContents:NULL | 30 webContents:webContents |
| 28 syncCallback:syncCallback | 31 syncCallback:syncCallback |
| 29 closeCallback:base::Bind(PerformClose, self) | 32 closeCallback:base::Bind(PerformClose, self) |
| 30 isModalDialog:NO]); | 33 isSyncDialog:NO |
| 34 errorMessage:errorMessage]); |
| 35 |
| 31 NSWindow* parentWindow = [controller window]; | 36 NSWindow* parentWindow = [controller window]; |
| 32 | 37 |
| 33 // Set the anchor point to right below the wrench menu. | 38 // Set the anchor point to right below the wrench menu. |
| 34 NSView* wrenchButton = [[controller toolbarController] wrenchButton]; | 39 NSView* wrenchButton = [[controller toolbarController] wrenchButton]; |
| 35 const NSRect bounds = [wrenchButton bounds]; | 40 const NSRect bounds = [wrenchButton bounds]; |
| 36 NSPoint anchorPoint = NSMakePoint(NSMidX(bounds), NSMaxY(bounds)); | 41 NSPoint anchorPoint = NSMakePoint(NSMidX(bounds), NSMaxY(bounds)); |
| 37 anchorPoint = [wrenchButton convertPoint:anchorPoint toView:nil]; | 42 anchorPoint = [wrenchButton convertPoint:anchorPoint toView:nil]; |
| 38 anchorPoint = [parentWindow convertBaseToScreen:anchorPoint]; | 43 anchorPoint = [parentWindow convertBaseToScreen:anchorPoint]; |
| 39 | 44 |
| 40 // Create an empty window into which content is placed. | 45 // Create an empty window into which content is placed. |
| 41 NSRect viewBounds = [[viewController_ view] bounds]; | 46 NSRect viewBounds = [[viewController_ view] bounds]; |
| 42 scoped_nsobject<InfoBubbleWindow> window( | 47 scoped_nsobject<InfoBubbleWindow> window( |
| 43 [[InfoBubbleWindow alloc] initWithContentRect:viewBounds | 48 [[InfoBubbleWindow alloc] initWithContentRect:viewBounds |
| 44 styleMask:NSBorderlessWindowMask | 49 styleMask:NSBorderlessWindowMask |
| 45 backing:NSBackingStoreBuffered | 50 backing:NSBackingStoreBuffered |
| 46 defer:NO]); | 51 defer:NO]); |
| 47 if (self = [super initWithWindow:window | 52 if (self = [super initWithWindow:window |
| 48 parentWindow:parentWindow | 53 parentWindow:parentWindow |
| 49 anchoredAt:anchorPoint]) { | 54 anchoredAt:anchorPoint]) { |
| 50 [[window contentView] addSubview:[viewController_ view]]; | 55 [[window contentView] addSubview:[viewController_ view]]; |
| 51 // This class will release itself when the bubble closes. See | 56 // This class will release itself when the bubble closes. See |
| 52 // -[BaseBubbleController windowWillClose:]. | 57 // -[BaseBubbleController windowWillClose:]. |
| 53 [self retain]; | 58 [self retain]; |
| 54 } | 59 } |
| 60 |
| 55 return self; | 61 return self; |
| 56 } | 62 } |
| 57 | 63 |
| 58 - (OneClickSigninViewController*)viewController { | 64 - (OneClickSigninViewController*)viewController { |
| 59 return viewController_; | 65 return viewController_; |
| 60 } | 66 } |
| 61 | 67 |
| 62 - (void)windowWillClose:(NSNotification*)notification { | 68 - (void)windowWillClose:(NSNotification*)notification { |
| 63 [viewController_ viewWillClose]; | 69 [viewController_ viewWillClose]; |
| 64 [super windowWillClose:notification]; | 70 [super windowWillClose:notification]; |
| 65 } | 71 } |
| 66 | 72 |
| 67 @end // OneClickSigninBubbleController | 73 @end // OneClickSigninBubbleController |
| OLD | NEW |