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/command_updater.h" | |
8 #include "chrome/browser/extensions/extension_system.h" | 7 #include "chrome/browser/extensions/extension_system.h" |
msw
2012/08/30 00:41:43
remove unnecessary include.
Cait (Slow)
2012/08/30 01:33:29
Done.
| |
9 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
10 #include "chrome/browser/ui/browser_commands.h" | 9 #include "chrome/browser/ui/browser_commands.h" |
11 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" | 10 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" |
12 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h" | 11 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h" |
13 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" | 12 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
14 #import "chrome/browser/ui/cocoa/menu_controller.h" | 13 #import "chrome/browser/ui/cocoa/menu_controller.h" |
15 #include "chrome/browser/ui/toolbar/action_box_menu_model.h" | 14 #include "chrome/browser/ui/toolbar/action_box_menu_model.h" |
16 #include "grit/generated_resources.h" | 15 #include "grit/generated_resources.h" |
17 #include "grit/theme_resources.h" | 16 #include "grit/theme_resources.h" |
18 #include "ui/base/l10n/l10n_util_mac.h" | 17 #include "ui/base/l10n/l10n_util_mac.h" |
19 | 18 |
20 namespace { | 19 namespace { |
21 // The offset to apply to the menu so that it clears the bottom border of the | 20 // The offset to apply to the menu so that it clears the bottom border of the |
22 // omnibox. | 21 // omnibox. |
23 const CGFloat kAnchorPointYOffset = 4.0; | 22 const CGFloat kAnchorPointYOffset = 4.0; |
24 const CGFloat kAnchorPointFrameHeight = 23.0; | 23 const CGFloat kAnchorPointFrameHeight = 23.0; |
25 } // namespace | 24 } // namespace |
26 | 25 |
27 PlusDecoration::PlusDecoration(LocationBarViewMac* owner, | 26 PlusDecoration::PlusDecoration(LocationBarViewMac* owner, Browser* browser) |
msw
2012/08/30 00:41:43
nit: one arg per line when the initializer list do
Cait (Slow)
2012/08/30 01:33:29
Done.
| |
28 CommandUpdater* command_updater, Browser* browser) | |
29 : owner_(owner), | 27 : owner_(owner), |
30 command_updater_(command_updater), | |
31 browser_(browser) { | 28 browser_(browser) { |
32 SetVisible(true); | 29 SetVisible(true); |
33 | 30 |
34 const int image_id = IDR_ACTION_BOX_BUTTON; | 31 const int image_id = IDR_ACTION_BOX_BUTTON; |
35 SetImage(OmniboxViewMac::ImageForResource(image_id)); | 32 SetImage(OmniboxViewMac::ImageForResource(image_id)); |
36 const int tip_id = IDS_TOOLTIP_ACTION_BOX_BUTTON; | 33 const int tip_id = IDS_TOOLTIP_ACTION_BOX_BUTTON; |
37 tooltip_.reset([l10n_util::GetNSStringWithFixup(tip_id) retain]); | 34 tooltip_.reset([l10n_util::GetNSStringWithFixup(tip_id) retain]); |
38 } | 35 } |
39 | 36 |
40 PlusDecoration::~PlusDecoration() { | 37 PlusDecoration::~PlusDecoration() { |
41 } | 38 } |
42 | 39 |
43 bool PlusDecoration::AcceptsMousePress() { | 40 bool PlusDecoration::AcceptsMousePress() { |
44 return true; | 41 return true; |
45 } | 42 } |
46 | 43 |
47 bool PlusDecoration::OnMousePressed(NSRect frame) { | 44 bool PlusDecoration::OnMousePressed(NSRect frame) { |
48 ExtensionService* extension_service = extensions::ExtensionSystem::Get( | 45 ActionBoxMenuModel menu_model(browser_); |
49 browser_->profile())->extension_service(); | |
50 ActionBoxMenuModel menu_model(browser_, extension_service); | |
51 | 46 |
52 // Controller for the menu attached to the plus decoration. | 47 // Controller for the menu attached to the plus decoration. |
53 scoped_nsobject<MenuController> menu_controller( | 48 scoped_nsobject<MenuController> menu_controller( |
54 [[MenuController alloc] initWithModel:&menu_model | 49 [[MenuController alloc] initWithModel:&menu_model |
55 useWithPopUpButtonCell:YES]); | 50 useWithPopUpButtonCell:YES]); |
56 | 51 |
57 NSMenu* menu = [menu_controller menu]; | 52 NSMenu* menu = [menu_controller menu]; |
58 | 53 |
59 // Align the menu popup to that its top-right corner matches the bottom-right | 54 // Align the menu popup to that its top-right corner matches the bottom-right |
60 // corner of the omnibox. | 55 // corner of the omnibox. |
(...skipping 14 matching lines...) Expand all Loading... | |
75 | 70 |
76 NSString* PlusDecoration::GetToolTip() { | 71 NSString* PlusDecoration::GetToolTip() { |
77 return tooltip_.get(); | 72 return tooltip_.get(); |
78 } | 73 } |
79 | 74 |
80 NSPoint PlusDecoration::GetActionBoxAnchorPoint() { | 75 NSPoint PlusDecoration::GetActionBoxAnchorPoint() { |
81 AutocompleteTextField* field = owner_->GetAutocompleteTextField(); | 76 AutocompleteTextField* field = owner_->GetAutocompleteTextField(); |
82 NSRect bounds = [field bounds]; | 77 NSRect bounds = [field bounds]; |
83 return NSMakePoint(NSMaxX(bounds), NSMaxY(bounds)); | 78 return NSMakePoint(NSMaxX(bounds), NSMaxY(bounds)); |
84 } | 79 } |
OLD | NEW |