| 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/location_bar/page_action_image_view.h" | 5 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/extensions/extension_browser_event_router.h" | 8 #include "chrome/browser/extensions/extension_browser_event_router.h" |
| 9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
| 10 #include "chrome/browser/platform_util.h" | 10 #include "chrome/browser/platform_util.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/ui/browser_list.h" | 12 #include "chrome/browser/ui/browser_list.h" |
| 13 #include "chrome/browser/ui/views/frame/browser_view.h" | 13 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 14 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 14 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
| 15 #include "chrome/common/extensions/extension_action.h" | 15 #include "chrome/common/extensions/extension_action.h" |
| 16 #include "chrome/common/extensions/extension_resource.h" | 16 #include "chrome/common/extensions/extension_resource.h" |
| 17 #include "ui/base/accessibility/accessible_view_state.h" | 17 #include "ui/base/accessibility/accessible_view_state.h" |
| 18 #include "views/controls/menu/menu_item_view.h" | 18 #include "views/controls/menu/menu_item_view.h" |
| 19 #include "views/controls/menu/menu_model_adapter.h" | 19 #include "views/controls/menu/menu_model_adapter.h" |
| 20 #include "views/controls/menu/menu_runner.h" |
| 20 | 21 |
| 21 PageActionImageView::PageActionImageView(LocationBarView* owner, | 22 PageActionImageView::PageActionImageView(LocationBarView* owner, |
| 22 ExtensionAction* page_action) | 23 ExtensionAction* page_action) |
| 23 : owner_(owner), | 24 : owner_(owner), |
| 24 page_action_(page_action), | 25 page_action_(page_action), |
| 25 ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)), | 26 ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)), |
| 26 current_tab_id_(-1), | 27 current_tab_id_(-1), |
| 27 preview_enabled_(false), | 28 preview_enabled_(false), |
| 28 popup_(NULL) { | 29 popup_(NULL) { |
| 29 const Extension* extension = owner_->browser()->profile()-> | 30 const Extension* extension = owner_->browser()->profile()-> |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 bool is_mouse_gesture) { | 137 bool is_mouse_gesture) { |
| 137 const Extension* extension = owner_->browser()->profile()-> | 138 const Extension* extension = owner_->browser()->profile()-> |
| 138 GetExtensionService()->GetExtensionById(page_action()->extension_id(), | 139 GetExtensionService()->GetExtensionById(page_action()->extension_id(), |
| 139 false); | 140 false); |
| 140 if (!extension->ShowConfigureContextMenus()) | 141 if (!extension->ShowConfigureContextMenus()) |
| 141 return; | 142 return; |
| 142 | 143 |
| 143 scoped_refptr<ExtensionContextMenuModel> context_menu_model( | 144 scoped_refptr<ExtensionContextMenuModel> context_menu_model( |
| 144 new ExtensionContextMenuModel(extension, owner_->browser(), this)); | 145 new ExtensionContextMenuModel(extension, owner_->browser(), this)); |
| 145 views::MenuModelAdapter menu_model_adapter(context_menu_model.get()); | 146 views::MenuModelAdapter menu_model_adapter(context_menu_model.get()); |
| 146 views::MenuItemView menu(&menu_model_adapter); | 147 views::MenuRunner menu_runner(menu_model_adapter.CreateMenu()); |
| 147 menu_model_adapter.BuildMenu(&menu); | |
| 148 | 148 |
| 149 gfx::Point screen_loc; | 149 gfx::Point screen_loc; |
| 150 views::View::ConvertPointToScreen(this, &screen_loc); | 150 views::View::ConvertPointToScreen(this, &screen_loc); |
| 151 menu.RunMenuAt(GetWidget(), NULL, gfx::Rect(screen_loc, size()), | 151 if (menu_runner.RunMenuAt(GetWidget(), NULL, gfx::Rect(screen_loc, size()), |
| 152 views::MenuItemView::TOPLEFT, true); | 152 views::MenuItemView::TOPLEFT, views::MenuRunner::HAS_MNEMONICS) == |
| 153 views::MenuRunner::MENU_DELETED) |
| 154 return; |
| 153 } | 155 } |
| 154 | 156 |
| 155 void PageActionImageView::OnImageLoaded( | 157 void PageActionImageView::OnImageLoaded( |
| 156 SkBitmap* image, const ExtensionResource& resource, int index) { | 158 SkBitmap* image, const ExtensionResource& resource, int index) { |
| 157 // We loaded icons()->size() icons, plus one extra if the page action had | 159 // We loaded icons()->size() icons, plus one extra if the page action had |
| 158 // a default icon. | 160 // a default icon. |
| 159 int total_icons = static_cast<int>(page_action_->icon_paths()->size()); | 161 int total_icons = static_cast<int>(page_action_->icon_paths()->size()); |
| 160 if (!page_action_->default_icon_path().empty()) | 162 if (!page_action_->default_icon_path().empty()) |
| 161 total_icons++; | 163 total_icons++; |
| 162 DCHECK(index < total_icons); | 164 DCHECK(index < total_icons); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 void PageActionImageView::ExtensionPopupIsClosing(ExtensionPopup* popup) { | 232 void PageActionImageView::ExtensionPopupIsClosing(ExtensionPopup* popup) { |
| 231 DCHECK_EQ(popup_, popup); | 233 DCHECK_EQ(popup_, popup); |
| 232 // ExtensionPopup is ref-counted, so we don't need to delete it. | 234 // ExtensionPopup is ref-counted, so we don't need to delete it. |
| 233 popup_ = NULL; | 235 popup_ = NULL; |
| 234 } | 236 } |
| 235 | 237 |
| 236 void PageActionImageView::HidePopup() { | 238 void PageActionImageView::HidePopup() { |
| 237 if (popup_) | 239 if (popup_) |
| 238 popup_->Close(); | 240 popup_->Close(); |
| 239 } | 241 } |
| OLD | NEW |