Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: chrome/browser/ui/views/browser_actions_container.cc

Issue 7057058: Convert BrowserActionsContainer context menu from Menu2 to MenuItemView. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix anchor position for RTL and non-RTL. Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/views/browser_actions_container.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/views/browser_actions_container.h" 5 #include "chrome/browser/ui/views/browser_actions_container.h"
6 6
7 #include "base/stl_util-inl.h" 7 #include "base/stl_util-inl.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/extensions/extension_browser_event_router.h" 10 #include "chrome/browser/extensions/extension_browser_event_router.h"
(...skipping 24 matching lines...) Expand all
35 #include "third_party/skia/include/effects/SkGradientShader.h" 35 #include "third_party/skia/include/effects/SkGradientShader.h"
36 #include "ui/base/accessibility/accessible_view_state.h" 36 #include "ui/base/accessibility/accessible_view_state.h"
37 #include "ui/base/animation/slide_animation.h" 37 #include "ui/base/animation/slide_animation.h"
38 #include "ui/base/l10n/l10n_util.h" 38 #include "ui/base/l10n/l10n_util.h"
39 #include "ui/base/resource/resource_bundle.h" 39 #include "ui/base/resource/resource_bundle.h"
40 #include "ui/base/theme_provider.h" 40 #include "ui/base/theme_provider.h"
41 #include "ui/gfx/canvas.h" 41 #include "ui/gfx/canvas.h"
42 #include "ui/gfx/canvas_skia.h" 42 #include "ui/gfx/canvas_skia.h"
43 #include "views/controls/button/menu_button.h" 43 #include "views/controls/button/menu_button.h"
44 #include "views/controls/button/text_button.h" 44 #include "views/controls/button/text_button.h"
45 #include "views/controls/menu/menu_2.h" 45 #include "views/controls/menu/menu_item_view.h"
46 #include "views/controls/menu/menu_model_adapter.h"
46 #include "views/drag_utils.h" 47 #include "views/drag_utils.h"
47 #include "views/metrics.h" 48 #include "views/metrics.h"
48 #include "views/window/window.h" 49 #include "views/window/window.h"
49 50
50 // Horizontal spacing between most items in the container, as well as after the 51 // Horizontal spacing between most items in the container, as well as after the
51 // last item or chevron (if visible). 52 // last item or chevron (if visible).
52 static const int kItemSpacing = ToolbarView::kStandardSpacing; 53 static const int kItemSpacing = ToolbarView::kStandardSpacing;
53 // Horizontal spacing before the chevron (if visible). 54 // Horizontal spacing before the chevron (if visible).
54 static const int kChevronSpacing = kItemSpacing - 2; 55 static const int kChevronSpacing = kItemSpacing - 2;
55 56
(...skipping 17 matching lines...) Expand all
73 74
74 // No UpdateState() here because View hierarchy not setup yet. Our parent 75 // No UpdateState() here because View hierarchy not setup yet. Our parent
75 // should call UpdateState() after creation. 76 // should call UpdateState() after creation.
76 77
77 registrar_.Add(this, NotificationType::EXTENSION_BROWSER_ACTION_UPDATED, 78 registrar_.Add(this, NotificationType::EXTENSION_BROWSER_ACTION_UPDATED,
78 Source<ExtensionAction>(browser_action_)); 79 Source<ExtensionAction>(browser_action_));
79 } 80 }
80 81
81 void BrowserActionButton::Destroy() { 82 void BrowserActionButton::Destroy() {
82 if (showing_context_menu_) { 83 if (showing_context_menu_) {
83 context_menu_menu_->CancelMenu(); 84 context_menu_menu_->Cancel();
84 MessageLoop::current()->DeleteSoon(FROM_HERE, this); 85 MessageLoop::current()->DeleteSoon(FROM_HERE, this);
85 } else { 86 } else {
86 delete this; 87 delete this;
87 } 88 }
88 } 89 }
89 90
90 void BrowserActionButton::ViewHierarchyChanged( 91 void BrowserActionButton::ViewHierarchyChanged(
91 bool is_add, View* parent, View* child) { 92 bool is_add, View* parent, View* child) {
92 if (is_add && child == this) { 93 if (is_add && child == this) {
93 // The Browser Action API does not allow the default icon path to be 94 // The Browser Action API does not allow the default icon path to be
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 bool BrowserActionButton::OnMousePressed(const views::MouseEvent& event) { 213 bool BrowserActionButton::OnMousePressed(const views::MouseEvent& event) {
213 if (!event.IsRightMouseButton()) { 214 if (!event.IsRightMouseButton()) {
214 return IsPopup() ? 215 return IsPopup() ?
215 MenuButton::OnMousePressed(event) : TextButton::OnMousePressed(event); 216 MenuButton::OnMousePressed(event) : TextButton::OnMousePressed(event);
216 } 217 }
217 218
218 // Get the top left point of this button in screen coordinates. 219 // Get the top left point of this button in screen coordinates.
219 gfx::Point point = gfx::Point(0, 0); 220 gfx::Point point = gfx::Point(0, 0);
220 ConvertPointToScreen(this, &point); 221 ConvertPointToScreen(this, &point);
221 222
223 // Align with button left edge for RTL, right edge otherwise.
Peter Kasting 2011/06/08 20:29:43 This seems backwards. We want to align to the lef
rhashimoto 2011/06/09 00:26:23 It looks like we indeed align to the left edge on
224 if (!base::i18n::IsRTL())
225 point.Offset(width(), 0);
226
222 // Make the menu appear below the button. 227 // Make the menu appear below the button.
223 point.Offset(0, height()); 228 point.Offset(0, height());
224 229
225 ShowContextMenu(point, true); 230 ShowContextMenu(point, true);
226 return false; 231 return false;
227 } 232 }
228 233
229 void BrowserActionButton::OnMouseReleased(const views::MouseEvent& event) { 234 void BrowserActionButton::OnMouseReleased(const views::MouseEvent& event) {
230 if (IsPopup() || showing_context_menu_) { 235 if (IsPopup() || showing_context_menu_) {
231 // TODO(erikkay) this never actually gets called (probably because of the 236 // TODO(erikkay) this never actually gets called (probably because of the
(...skipping 20 matching lines...) Expand all
252 bool is_mouse_gesture) { 257 bool is_mouse_gesture) {
253 if (!extension()->ShowConfigureContextMenus()) 258 if (!extension()->ShowConfigureContextMenus())
254 return; 259 return;
255 260
256 showing_context_menu_ = true; 261 showing_context_menu_ = true;
257 SetButtonPushed(); 262 SetButtonPushed();
258 263
259 // Reconstructs the menu every time because the menu's contents are dynamic. 264 // Reconstructs the menu every time because the menu's contents are dynamic.
260 context_menu_contents_ = 265 context_menu_contents_ =
261 new ExtensionContextMenuModel(extension(), panel_->browser(), panel_); 266 new ExtensionContextMenuModel(extension(), panel_->browser(), panel_);
262 context_menu_menu_.reset(new views::Menu2(context_menu_contents_.get())); 267 views::MenuModelAdapter menu_model_adapter(context_menu_contents_.get());
263 context_menu_menu_->RunContextMenuAt(p); 268 context_menu_menu_.reset(new views::MenuItemView(&menu_model_adapter));
269 menu_model_adapter.BuildMenu(context_menu_menu_.get());
270 context_menu_menu_->RunMenuAt(GetWindow()->GetNativeWindow(), NULL,
271 gfx::Rect(p, gfx::Size()), views::MenuItemView::TOPRIGHT, true);
Peter Kasting 2011/06/08 20:29:43 Nit: I mentioned this in the last code review and
rhashimoto 2011/06/09 00:26:23 I believe the API allows the specification of a Re
Peter Kasting 2011/06/09 00:39:09 This makes callers who use just a point construct
rhashimoto 2011/06/09 01:15:27 I can add convenience API to pass a Point, but I t
Peter Kasting 2011/06/09 17:43:57 This worries me. The old APIs took a point. That
rhashimoto 2011/06/09 18:19:00 I filed crosbug.com/85585.
264 272
265 SetButtonNotPushed(); 273 SetButtonNotPushed();
266 showing_context_menu_ = false; 274 showing_context_menu_ = false;
275 context_menu_menu_.reset(NULL);
Peter Kasting 2011/06/08 20:29:43 Do we really need to use a scoped_ptr if we're res
rhashimoto 2011/06/09 00:26:23 Done.
267 } 276 }
268 277
269 void BrowserActionButton::SetButtonPushed() { 278 void BrowserActionButton::SetButtonPushed() {
270 SetState(views::CustomButton::BS_PUSHED); 279 SetState(views::CustomButton::BS_PUSHED);
271 menu_visible_ = true; 280 menu_visible_ = true;
272 } 281 }
273 282
274 void BrowserActionButton::SetButtonNotPushed() { 283 void BrowserActionButton::SetButtonNotPushed() {
275 SetState(views::CustomButton::BS_NORMAL); 284 SetState(views::CustomButton::BS_NORMAL);
276 menu_visible_ = false; 285 menu_visible_ = false;
(...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after
1095 } 1104 }
1096 } 1105 }
1097 1106
1098 bool BrowserActionsContainer::ShouldDisplayBrowserAction( 1107 bool BrowserActionsContainer::ShouldDisplayBrowserAction(
1099 const Extension* extension) { 1108 const Extension* extension) {
1100 // Only display incognito-enabled extensions while in incognito mode. 1109 // Only display incognito-enabled extensions while in incognito mode.
1101 return 1110 return
1102 (!profile_->IsOffTheRecord() || 1111 (!profile_->IsOffTheRecord() ||
1103 profile_->GetExtensionService()->IsIncognitoEnabled(extension->id())); 1112 profile_->GetExtensionService()->IsIncognitoEnabled(extension->id()));
1104 } 1113 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/browser_actions_container.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698