Chromium Code Reviews| 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/location_bar/plus_decoration.h" | 5 #import "chrome/browser/ui/cocoa/location_bar/plus_decoration.h" |
| 6 | 6 |
| 7 #include "chrome/browser/ui/browser.h" | 7 #import "chrome/browser/ui/cocoa/location_bar/action_box_menu_bubble_controller. h" |
| 8 #include "chrome/browser/ui/browser_commands.h" | |
| 9 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" | |
| 10 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h" | 8 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h" |
| 11 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" | 9 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
| 12 #import "chrome/browser/ui/cocoa/menu_controller.h" | 10 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" |
| 13 #include "grit/generated_resources.h" | 11 #include "grit/generated_resources.h" |
| 14 #include "grit/theme_resources.h" | 12 #include "grit/theme_resources.h" |
| 15 #include "ui/base/l10n/l10n_util_mac.h" | 13 #include "ui/base/l10n/l10n_util_mac.h" |
| 16 | 14 |
| 17 namespace { | 15 namespace { |
| 18 // The offset to apply to the menu so that it clears the bottom border of the | 16 // The offset to apply to the menu so that it clears the bottom border of the |
| 19 // omnibox. | 17 // omnibox. |
| 20 const CGFloat kAnchorPointYOffset = 4.0; | 18 const CGFloat kAnchorPointYOffset = 4.0; |
| 21 const CGFloat kAnchorPointFrameHeight = 23.0; | 19 const CGFloat kAnchorPointFrameHeight = 23.0; |
| 22 } // namespace | 20 } // namespace |
| 23 | 21 |
| 24 PlusDecoration::PlusDecoration(LocationBarViewMac* owner, | 22 PlusDecoration::PlusDecoration(LocationBarViewMac* owner, |
| 25 Browser* browser) | 23 Browser* browser) |
| 26 : owner_(owner), | 24 : owner_(owner), |
| 27 browser_(browser), | 25 browser_(browser), |
| 28 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(browser, this)) { | 26 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(browser, this)) { |
| 29 SetVisible(true); | 27 SetVisible(true); |
| 30 ResetIcon(); | 28 ResetIcon(); |
| 31 } | 29 } |
| 32 | 30 |
| 33 PlusDecoration::~PlusDecoration() { | 31 PlusDecoration::~PlusDecoration() { |
| 34 } | 32 } |
| 35 | 33 |
| 36 NSPoint PlusDecoration::GetActionBoxAnchorPoint() { | 34 NSPoint PlusDecoration::GetActionBoxAnchorPoint() { |
| 37 AutocompleteTextField* field = owner_->GetAutocompleteTextField(); | 35 AutocompleteTextField* field = owner_->GetAutocompleteTextField(); |
| 38 NSRect bounds = [field bounds]; | 36 NSRect bounds = [field bounds]; |
| 39 return NSMakePoint(NSMaxX(bounds), NSMaxY(bounds)); | 37 NSPoint anchor = NSMakePoint(NSMaxX(bounds) - 1, NSMaxY(bounds) - 2); |
|
Scott Hess - ex-Googler
2012/10/12 23:02:47
Provide some explanation of the magic constants.
beaudoin
2012/10/13 00:20:55
Done.
| |
| 38 anchor = [field convertPoint:anchor toView:nil]; | |
| 39 return [[field window] convertBaseToScreen:anchor]; | |
|
Scott Hess - ex-Googler
2012/10/12 23:02:47
-[ChromeToMobileBubbleController showWindow:] also
beaudoin
2012/10/13 00:20:55
The alignment concerns are slighty different here
| |
| 40 } | 40 } |
| 41 | 41 |
| 42 void PlusDecoration::ResetIcon() { | 42 void PlusDecoration::ResetIcon() { |
| 43 SetIcons( | 43 SetIcons( |
| 44 IDR_ACTION_BOX_BUTTON_NORMAL, | 44 IDR_ACTION_BOX_BUTTON_NORMAL, |
| 45 IDR_ACTION_BOX_BUTTON_HOVER, | 45 IDR_ACTION_BOX_BUTTON_HOVER, |
| 46 IDR_ACTION_BOX_BUTTON_PUSHED); | 46 IDR_ACTION_BOX_BUTTON_PUSHED); |
| 47 } | 47 } |
| 48 | 48 |
| 49 void PlusDecoration::SetTemporaryIcon(int image_id) { | 49 void PlusDecoration::SetTemporaryIcon(int image_id) { |
| 50 SetIcons(image_id, image_id, image_id); | 50 SetIcons(image_id, image_id, image_id); |
| 51 } | 51 } |
| 52 | 52 |
| 53 bool PlusDecoration::AcceptsMousePress() { | 53 bool PlusDecoration::AcceptsMousePress() { |
| 54 return true; | 54 return true; |
| 55 } | 55 } |
| 56 | 56 |
| 57 bool PlusDecoration::OnMousePressed(NSRect frame) { | 57 bool PlusDecoration::OnMousePressed(NSRect frame) { |
| 58 controller_.OnButtonClicked(); | 58 controller_.OnButtonClicked(); |
| 59 return true; | 59 return true; |
| 60 } | 60 } |
| 61 | 61 |
| 62 NSString* PlusDecoration::GetToolTip() { | 62 NSString* PlusDecoration::GetToolTip() { |
| 63 return l10n_util::GetNSStringWithFixup(IDS_TOOLTIP_ACTION_BOX_BUTTON); | 63 return l10n_util::GetNSStringWithFixup(IDS_TOOLTIP_ACTION_BOX_BUTTON); |
| 64 } | 64 } |
| 65 | 65 |
| 66 void PlusDecoration::ShowMenu(scoped_ptr<ActionBoxMenuModel> menu_model) { | 66 void PlusDecoration::ShowMenu(scoped_ptr<ActionBoxMenuModel> menu_model) { |
|
Scott Hess - ex-Googler
2012/10/12 23:02:47
This will close the existing menu and open a new o
beaudoin
2012/10/13 00:20:55
This is exactly what happened. I have created crbu
| |
| 67 // Controller for the menu attached to the plus decoration. | 67 // Controller for the menu attached to the plus decoration. |
| 68 scoped_nsobject<MenuController> menu_controller( | 68 // |menu_controller_| will automatically release itself on close. |
| 69 [[MenuController alloc] initWithModel:menu_model.get() | 69 ActionBoxMenuBubbleController* menu_controller = |
| 70 useWithPopUpButtonCell:YES]); | 70 [[ActionBoxMenuBubbleController alloc] |
| 71 initWithBrowser:browser_ | |
| 72 usingModel:menu_model.PassAs<ui::MenuModel>() | |
| 73 anchoredAt:GetActionBoxAnchorPoint()]; | |
| 71 | 74 |
| 72 NSMenu* menu = [menu_controller menu]; | 75 [menu_controller showWindow:nil]; |
| 73 | |
| 74 // Align the menu popup to that its top-right corner matches the bottom-right | |
| 75 // corner of the omnibox. | |
| 76 AutocompleteTextField* field = owner_->GetAutocompleteTextField(); | |
| 77 NSPoint point = GetActionBoxAnchorPoint(); | |
| 78 NSRect popUpFrame = NSMakeRect(point.x - menu.size.width, | |
| 79 kAnchorPointYOffset, menu.size.width, kAnchorPointFrameHeight); | |
| 80 scoped_nsobject<NSPopUpButtonCell> pop_up_cell( | |
| 81 [[NSPopUpButtonCell alloc] initTextCell:@"" pullsDown:YES]); | |
| 82 DCHECK(pop_up_cell.get()); | |
| 83 | |
| 84 [pop_up_cell setMenu:menu]; | |
| 85 [pop_up_cell selectItem:nil]; | |
| 86 [pop_up_cell attachPopUpWithFrame:popUpFrame inView:field]; | |
| 87 [pop_up_cell performClickWithFrame:popUpFrame inView:field]; | |
| 88 } | 76 } |
| 89 | 77 |
| 90 void PlusDecoration::SetIcons(int normal_id, int hover_id, int pressed_id) { | 78 void PlusDecoration::SetIcons(int normal_id, int hover_id, int pressed_id) { |
| 91 SetNormalImage(OmniboxViewMac::ImageForResource(normal_id)); | 79 SetNormalImage(OmniboxViewMac::ImageForResource(normal_id)); |
| 92 SetHoverImage(OmniboxViewMac::ImageForResource(hover_id)); | 80 SetHoverImage(OmniboxViewMac::ImageForResource(hover_id)); |
| 93 SetPressedImage(OmniboxViewMac::ImageForResource(pressed_id)); | 81 SetPressedImage(OmniboxViewMac::ImageForResource(pressed_id)); |
| 94 } | 82 } |
| OLD | NEW |