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 #include "chrome/browser/ui/cocoa/browser_window_cocoa.h" | 5 #include "chrome/browser/ui/cocoa/browser_window_cocoa.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/mac/mac_util.h" | 10 #include "base/mac/mac_util.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 | 59 |
60 #if defined(ENABLE_ONE_CLICK_SIGNIN) | 60 #if defined(ENABLE_ONE_CLICK_SIGNIN) |
61 #import "chrome/browser/ui/cocoa/one_click_signin_bubble_controller.h" | 61 #import "chrome/browser/ui/cocoa/one_click_signin_bubble_controller.h" |
62 #import "chrome/browser/ui/cocoa/one_click_signin_dialog_controller.h" | 62 #import "chrome/browser/ui/cocoa/one_click_signin_dialog_controller.h" |
63 #endif | 63 #endif |
64 | 64 |
65 using content::NativeWebKeyboardEvent; | 65 using content::NativeWebKeyboardEvent; |
66 using content::SSLStatus; | 66 using content::SSLStatus; |
67 using content::WebContents; | 67 using content::WebContents; |
68 | 68 |
69 namespace { | |
70 | |
71 NSPoint GetPointForBubble(content::WebContents* web_contents, | |
72 int x_offset, | |
73 int y_offset) { | |
74 NSView* view = web_contents->GetNativeView(); | |
75 NSRect bounds = [view bounds]; | |
76 NSPoint point; | |
77 point.x = NSMinX(bounds) + x_offset; | |
78 // The view's origin is at the bottom but |rect|'s origin is at the top. | |
79 point.y = NSMaxY(bounds) - y_offset; | |
80 point = [view convertPoint:point toView:nil]; | |
81 point = [[view window] convertBaseToScreen:point]; | |
82 return point; | |
83 } | |
84 | |
85 } // namespace | |
86 | |
87 BrowserWindowCocoa::BrowserWindowCocoa(Browser* browser, | 69 BrowserWindowCocoa::BrowserWindowCocoa(Browser* browser, |
88 BrowserWindowController* controller) | 70 BrowserWindowController* controller) |
89 : browser_(browser), | 71 : browser_(browser), |
90 controller_(controller), | 72 controller_(controller), |
91 initial_show_state_(ui::SHOW_STATE_DEFAULT), | 73 initial_show_state_(ui::SHOW_STATE_DEFAULT), |
92 attention_request_id_(0) { | 74 attention_request_id_(0) { |
93 | 75 |
94 gfx::Rect bounds; | 76 gfx::Rect bounds; |
95 chrome::GetSavedWindowBoundsAndShowState(browser_, | 77 chrome::GetSavedWindowBoundsAndShowState(browser_, |
96 &bounds, | 78 &bounds, |
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
670 [controller_ destroyBrowser]; | 652 [controller_ destroyBrowser]; |
671 | 653 |
672 // at this point the controller is dead (autoreleased), so | 654 // at this point the controller is dead (autoreleased), so |
673 // make sure we don't try to reference it any more. | 655 // make sure we don't try to reference it any more. |
674 } | 656 } |
675 | 657 |
676 NSWindow* BrowserWindowCocoa::window() const { | 658 NSWindow* BrowserWindowCocoa::window() const { |
677 return [controller_ window]; | 659 return [controller_ window]; |
678 } | 660 } |
679 | 661 |
680 void BrowserWindowCocoa::ShowAvatarBubble(WebContents* web_contents, | |
681 const gfx::Rect& rect) { | |
682 NSPoint point = GetPointForBubble(web_contents, rect.right(), rect.bottom()); | |
683 | |
684 // |menu| will automatically release itself on close. | |
685 AvatarMenuBubbleController* menu = | |
686 [[AvatarMenuBubbleController alloc] initWithBrowser:browser_ | |
687 anchoredAt:point]; | |
688 [[menu bubble] setAlignment:info_bubble::kAlignEdgeToAnchorEdge]; | |
689 [menu showWindow:nil]; | |
690 } | |
691 | |
692 void BrowserWindowCocoa::ShowAvatarBubbleFromAvatarButton( | 662 void BrowserWindowCocoa::ShowAvatarBubbleFromAvatarButton( |
693 AvatarBubbleMode mode, | 663 AvatarBubbleMode mode, |
694 const signin::ManageAccountsParams& manage_accounts_params) { | 664 const signin::ManageAccountsParams& manage_accounts_params) { |
695 AvatarBaseController* controller = [controller_ avatarButtonController]; | 665 AvatarBaseController* controller = [controller_ avatarButtonController]; |
696 NSView* anchor = [controller buttonView]; | 666 NSView* anchor = [controller buttonView]; |
697 if ([anchor isHiddenOrHasHiddenAncestor]) | 667 if ([anchor isHiddenOrHasHiddenAncestor]) |
698 anchor = [[controller_ toolbarController] wrenchButton]; | 668 anchor = [[controller_ toolbarController] wrenchButton]; |
699 [controller showAvatarBubbleAnchoredAt:anchor | 669 [controller showAvatarBubbleAnchoredAt:anchor |
700 withMode:mode | 670 withMode:mode |
701 withServiceType:manage_accounts_params.service_type]; | 671 withServiceType:manage_accounts_params.service_type]; |
702 } | 672 } |
703 | 673 |
704 int | 674 int |
705 BrowserWindowCocoa::GetRenderViewHeightInsetWithDetachedBookmarkBar() { | 675 BrowserWindowCocoa::GetRenderViewHeightInsetWithDetachedBookmarkBar() { |
706 if (browser_->bookmark_bar_state() != BookmarkBar::DETACHED) | 676 if (browser_->bookmark_bar_state() != BookmarkBar::DETACHED) |
707 return 0; | 677 return 0; |
708 return 40; | 678 return 40; |
709 } | 679 } |
710 | 680 |
711 void BrowserWindowCocoa::ExecuteExtensionCommand( | 681 void BrowserWindowCocoa::ExecuteExtensionCommand( |
712 const extensions::Extension* extension, | 682 const extensions::Extension* extension, |
713 const extensions::Command& command) { | 683 const extensions::Command& command) { |
714 [cocoa_controller() executeExtensionCommand:extension->id() command:command]; | 684 [cocoa_controller() executeExtensionCommand:extension->id() command:command]; |
715 } | 685 } |
OLD | NEW |