OLD | NEW |
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.h" | 7 #include "base/stl_util.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 28 matching lines...) Expand all Loading... |
39 #include "ui/base/animation/slide_animation.h" | 39 #include "ui/base/animation/slide_animation.h" |
40 #include "ui/base/l10n/l10n_util.h" | 40 #include "ui/base/l10n/l10n_util.h" |
41 #include "ui/base/resource/resource_bundle.h" | 41 #include "ui/base/resource/resource_bundle.h" |
42 #include "ui/base/theme_provider.h" | 42 #include "ui/base/theme_provider.h" |
43 #include "ui/gfx/canvas.h" | 43 #include "ui/gfx/canvas.h" |
44 #include "ui/gfx/canvas_skia.h" | 44 #include "ui/gfx/canvas_skia.h" |
45 #include "views/controls/button/menu_button.h" | 45 #include "views/controls/button/menu_button.h" |
46 #include "views/controls/button/text_button.h" | 46 #include "views/controls/button/text_button.h" |
47 #include "views/controls/menu/menu_item_view.h" | 47 #include "views/controls/menu/menu_item_view.h" |
48 #include "views/controls/menu/menu_model_adapter.h" | 48 #include "views/controls/menu/menu_model_adapter.h" |
| 49 #include "views/controls/menu/menu_runner.h" |
49 #include "views/drag_utils.h" | 50 #include "views/drag_utils.h" |
50 #include "views/metrics.h" | 51 #include "views/metrics.h" |
51 | 52 |
52 // Horizontal spacing between most items in the container, as well as after the | 53 // Horizontal spacing between most items in the container, as well as after the |
53 // last item or chevron (if visible). | 54 // last item or chevron (if visible). |
54 static const int kItemSpacing = ToolbarView::kStandardSpacing; | 55 static const int kItemSpacing = ToolbarView::kStandardSpacing; |
55 // Horizontal spacing before the chevron (if visible). | 56 // Horizontal spacing before the chevron (if visible). |
56 static const int kChevronSpacing = kItemSpacing - 2; | 57 static const int kChevronSpacing = kItemSpacing - 2; |
57 | 58 |
58 // static | 59 // static |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 bool is_mouse_gesture) { | 249 bool is_mouse_gesture) { |
249 if (!extension()->ShowConfigureContextMenus()) | 250 if (!extension()->ShowConfigureContextMenus()) |
250 return; | 251 return; |
251 | 252 |
252 SetButtonPushed(); | 253 SetButtonPushed(); |
253 | 254 |
254 // Reconstructs the menu every time because the menu's contents are dynamic. | 255 // Reconstructs the menu every time because the menu's contents are dynamic. |
255 scoped_refptr<ExtensionContextMenuModel> context_menu_contents_( | 256 scoped_refptr<ExtensionContextMenuModel> context_menu_contents_( |
256 new ExtensionContextMenuModel(extension(), panel_->browser(), panel_)); | 257 new ExtensionContextMenuModel(extension(), panel_->browser(), panel_)); |
257 views::MenuModelAdapter menu_model_adapter(context_menu_contents_.get()); | 258 views::MenuModelAdapter menu_model_adapter(context_menu_contents_.get()); |
258 views::MenuItemView menu(&menu_model_adapter); | 259 views::MenuRunner menu_runner(menu_model_adapter.CreateMenu()); |
259 menu_model_adapter.BuildMenu(&menu); | |
260 | 260 |
261 context_menu_ = &menu; | 261 context_menu_ = menu_runner.GetMenu(); |
262 gfx::Point screen_loc; | 262 gfx::Point screen_loc; |
263 views::View::ConvertPointToScreen(this, &screen_loc); | 263 views::View::ConvertPointToScreen(this, &screen_loc); |
264 context_menu_->RunMenuAt(GetWidget(), NULL, gfx::Rect(screen_loc, size()), | 264 if (menu_runner.RunMenuAt(GetWidget(), NULL, gfx::Rect(screen_loc, size()), |
265 views::MenuItemView::TOPLEFT, true); | 265 views::MenuItemView::TOPLEFT, views::MenuRunner::HAS_MNEMONICS) == |
| 266 views::MenuRunner::MENU_DELETED) |
| 267 return; |
266 | 268 |
267 SetButtonNotPushed(); | 269 SetButtonNotPushed(); |
268 context_menu_ = NULL; | 270 context_menu_ = NULL; |
269 } | 271 } |
270 | 272 |
271 void BrowserActionButton::SetButtonPushed() { | 273 void BrowserActionButton::SetButtonPushed() { |
272 SetState(views::CustomButton::BS_PUSHED); | 274 SetState(views::CustomButton::BS_PUSHED); |
273 menu_visible_ = true; | 275 menu_visible_ = true; |
274 } | 276 } |
275 | 277 |
(...skipping 821 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1097 } | 1099 } |
1098 } | 1100 } |
1099 | 1101 |
1100 bool BrowserActionsContainer::ShouldDisplayBrowserAction( | 1102 bool BrowserActionsContainer::ShouldDisplayBrowserAction( |
1101 const Extension* extension) { | 1103 const Extension* extension) { |
1102 // Only display incognito-enabled extensions while in incognito mode. | 1104 // Only display incognito-enabled extensions while in incognito mode. |
1103 return | 1105 return |
1104 (!profile_->IsOffTheRecord() || | 1106 (!profile_->IsOffTheRecord() || |
1105 profile_->GetExtensionService()->IsIncognitoEnabled(extension->id())); | 1107 profile_->GetExtensionService()->IsIncognitoEnabled(extension->id())); |
1106 } | 1108 } |
OLD | NEW |