| 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 // Used for defining the layout of the NSAlert and NSTextField within the | 82 // Used for defining the layout of the NSAlert and NSTextField within the |
| 83 // accessory view. | 83 // accessory view. |
| 84 const int kAppTextFieldVerticalSpacing = 2; | 84 const int kAppTextFieldVerticalSpacing = 2; |
| 85 const int kAppTextFieldWidth = 200; | 85 const int kAppTextFieldWidth = 200; |
| 86 const int kAppTextFieldHeight = 22; | 86 const int kAppTextFieldHeight = 22; |
| 87 const int kBookmarkAppBubbleViewWidth = 200; | 87 const int kBookmarkAppBubbleViewWidth = 200; |
| 88 const int kBookmarkAppBubbleViewHeight = 46; | 88 const int kBookmarkAppBubbleViewHeight = 46; |
| 89 | 89 |
| 90 const int kIconPreviewTargetSize = 64; | 90 const int kIconPreviewTargetSize = 64; |
| 91 | 91 |
| 92 NSPoint GetPointForBubble(content::WebContents* web_contents, | |
| 93 int x_offset, | |
| 94 int y_offset) { | |
| 95 NSView* view = web_contents->GetNativeView(); | |
| 96 NSRect bounds = [view bounds]; | |
| 97 NSPoint point; | |
| 98 point.x = NSMinX(bounds) + x_offset; | |
| 99 // The view's origin is at the bottom but |rect|'s origin is at the top. | |
| 100 point.y = NSMaxY(bounds) - y_offset; | |
| 101 point = [view convertPoint:point toView:nil]; | |
| 102 point = [[view window] convertBaseToScreen:point]; | |
| 103 return point; | |
| 104 } | |
| 105 | |
| 106 } // namespace | 92 } // namespace |
| 107 | 93 |
| 108 BrowserWindowCocoa::BrowserWindowCocoa(Browser* browser, | 94 BrowserWindowCocoa::BrowserWindowCocoa(Browser* browser, |
| 109 BrowserWindowController* controller) | 95 BrowserWindowController* controller) |
| 110 : browser_(browser), | 96 : browser_(browser), |
| 111 controller_(controller), | 97 controller_(controller), |
| 112 initial_show_state_(ui::SHOW_STATE_DEFAULT), | 98 initial_show_state_(ui::SHOW_STATE_DEFAULT), |
| 113 attention_request_id_(0) { | 99 attention_request_id_(0) { |
| 114 | 100 |
| 115 gfx::Rect bounds; | 101 gfx::Rect bounds; |
| (...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 771 [controller_ destroyBrowser]; | 757 [controller_ destroyBrowser]; |
| 772 | 758 |
| 773 // at this point the controller is dead (autoreleased), so | 759 // at this point the controller is dead (autoreleased), so |
| 774 // make sure we don't try to reference it any more. | 760 // make sure we don't try to reference it any more. |
| 775 } | 761 } |
| 776 | 762 |
| 777 NSWindow* BrowserWindowCocoa::window() const { | 763 NSWindow* BrowserWindowCocoa::window() const { |
| 778 return [controller_ window]; | 764 return [controller_ window]; |
| 779 } | 765 } |
| 780 | 766 |
| 781 void BrowserWindowCocoa::ShowAvatarBubble(WebContents* web_contents, | |
| 782 const gfx::Rect& rect) { | |
| 783 NSPoint point = GetPointForBubble(web_contents, rect.right(), rect.bottom()); | |
| 784 | |
| 785 // |menu| will automatically release itself on close. | |
| 786 AvatarMenuBubbleController* menu = | |
| 787 [[AvatarMenuBubbleController alloc] initWithBrowser:browser_ | |
| 788 anchoredAt:point]; | |
| 789 [[menu bubble] setAlignment:info_bubble::kAlignEdgeToAnchorEdge]; | |
| 790 [menu showWindow:nil]; | |
| 791 } | |
| 792 | |
| 793 void BrowserWindowCocoa::ShowAvatarBubbleFromAvatarButton( | 767 void BrowserWindowCocoa::ShowAvatarBubbleFromAvatarButton( |
| 794 AvatarBubbleMode mode, | 768 AvatarBubbleMode mode, |
| 795 const signin::ManageAccountsParams& manage_accounts_params) { | 769 const signin::ManageAccountsParams& manage_accounts_params) { |
| 796 AvatarBaseController* controller = [controller_ avatarButtonController]; | 770 AvatarBaseController* controller = [controller_ avatarButtonController]; |
| 797 NSView* anchor = [controller buttonView]; | 771 NSView* anchor = [controller buttonView]; |
| 798 if ([anchor isHiddenOrHasHiddenAncestor]) | 772 if ([anchor isHiddenOrHasHiddenAncestor]) |
| 799 anchor = [[controller_ toolbarController] wrenchButton]; | 773 anchor = [[controller_ toolbarController] wrenchButton]; |
| 800 [controller showAvatarBubbleAnchoredAt:anchor | 774 [controller showAvatarBubbleAnchoredAt:anchor |
| 801 withMode:mode | 775 withMode:mode |
| 802 withServiceType:manage_accounts_params.service_type]; | 776 withServiceType:manage_accounts_params.service_type]; |
| 803 } | 777 } |
| 804 | 778 |
| 805 int | 779 int |
| 806 BrowserWindowCocoa::GetRenderViewHeightInsetWithDetachedBookmarkBar() { | 780 BrowserWindowCocoa::GetRenderViewHeightInsetWithDetachedBookmarkBar() { |
| 807 if (browser_->bookmark_bar_state() != BookmarkBar::DETACHED) | 781 if (browser_->bookmark_bar_state() != BookmarkBar::DETACHED) |
| 808 return 0; | 782 return 0; |
| 809 return 40; | 783 return 40; |
| 810 } | 784 } |
| 811 | 785 |
| 812 void BrowserWindowCocoa::ExecuteExtensionCommand( | 786 void BrowserWindowCocoa::ExecuteExtensionCommand( |
| 813 const extensions::Extension* extension, | 787 const extensions::Extension* extension, |
| 814 const extensions::Command& command) { | 788 const extensions::Command& command) { |
| 815 [cocoa_controller() executeExtensionCommand:extension->id() command:command]; | 789 [cocoa_controller() executeExtensionCommand:extension->id() command:command]; |
| 816 } | 790 } |
| OLD | NEW |