| 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 #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/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/extensions/api/commands/command_service.h" | 8 #include "chrome/browser/extensions/api/commands/command_service.h" |
| 9 #include "chrome/browser/extensions/extension_action.h" | 9 #include "chrome/browser/extensions/extension_action.h" |
| 10 #include "chrome/browser/extensions/extension_action_icon_factory.h" | 10 #include "chrome/browser/extensions/extension_action_icon_factory.h" |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 | 168 |
| 169 bool PageActionImageView::OnKeyPressed(const ui::KeyEvent& event) { | 169 bool PageActionImageView::OnKeyPressed(const ui::KeyEvent& event) { |
| 170 if (event.key_code() == ui::VKEY_SPACE || | 170 if (event.key_code() == ui::VKEY_SPACE || |
| 171 event.key_code() == ui::VKEY_RETURN) { | 171 event.key_code() == ui::VKEY_RETURN) { |
| 172 ExecuteAction(ExtensionPopup::SHOW); | 172 ExecuteAction(ExtensionPopup::SHOW); |
| 173 return true; | 173 return true; |
| 174 } | 174 } |
| 175 return false; | 175 return false; |
| 176 } | 176 } |
| 177 | 177 |
| 178 void PageActionImageView::ShowContextMenuForView(View* source, | 178 void PageActionImageView::ShowContextMenuForView( |
| 179 const gfx::Point& point) { | 179 View* source, |
| 180 const gfx::Point& point, |
| 181 ui::MenuSourceType source_type) { |
| 180 const Extension* extension = owner_->profile()->GetExtensionService()-> | 182 const Extension* extension = owner_->profile()->GetExtensionService()-> |
| 181 GetExtensionById(page_action()->extension_id(), false); | 183 GetExtensionById(page_action()->extension_id(), false); |
| 182 if (!extension->ShowConfigureContextMenus()) | 184 if (!extension->ShowConfigureContextMenus()) |
| 183 return; | 185 return; |
| 184 | 186 |
| 185 scoped_refptr<ExtensionContextMenuModel> context_menu_model( | 187 scoped_refptr<ExtensionContextMenuModel> context_menu_model( |
| 186 new ExtensionContextMenuModel(extension, browser_, this)); | 188 new ExtensionContextMenuModel(extension, browser_, this)); |
| 187 menu_runner_.reset(new views::MenuRunner(context_menu_model.get())); | 189 menu_runner_.reset(new views::MenuRunner(context_menu_model.get())); |
| 188 gfx::Point screen_loc; | 190 gfx::Point screen_loc; |
| 189 views::View::ConvertPointToScreen(this, &screen_loc); | 191 views::View::ConvertPointToScreen(this, &screen_loc); |
| 190 if (menu_runner_->RunMenuAt(GetWidget(), NULL, gfx::Rect(screen_loc, size()), | 192 if (menu_runner_->RunMenuAt(GetWidget(), NULL, gfx::Rect(screen_loc, size()), |
| 191 views::MenuItemView::TOPLEFT, views::MenuRunner::HAS_MNEMONICS | | 193 views::MenuItemView::TOPLEFT, source_type, |
| 192 views::MenuRunner::CONTEXT_MENU) == | 194 views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU) == |
| 193 views::MenuRunner::MENU_DELETED) | 195 views::MenuRunner::MENU_DELETED) |
| 194 return; | 196 return; |
| 195 } | 197 } |
| 196 | 198 |
| 197 bool PageActionImageView::AcceleratorPressed( | 199 bool PageActionImageView::AcceleratorPressed( |
| 198 const ui::Accelerator& accelerator) { | 200 const ui::Accelerator& accelerator) { |
| 199 DCHECK(visible()); // Should not have happened due to CanHandleAccelerator. | 201 DCHECK(visible()); // Should not have happened due to CanHandleAccelerator. |
| 200 | 202 |
| 201 ExecuteAction(ExtensionPopup::SHOW); | 203 ExecuteAction(ExtensionPopup::SHOW); |
| 202 return true; | 204 return true; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 | 278 |
| 277 popup_ = ExtensionPopup::ShowPopup(popup_url, browser_, this, arrow, | 279 popup_ = ExtensionPopup::ShowPopup(popup_url, browser_, this, arrow, |
| 278 show_action); | 280 show_action); |
| 279 popup_->GetWidget()->AddObserver(this); | 281 popup_->GetWidget()->AddObserver(this); |
| 280 } | 282 } |
| 281 | 283 |
| 282 void PageActionImageView::HidePopup() { | 284 void PageActionImageView::HidePopup() { |
| 283 if (popup_) | 285 if (popup_) |
| 284 popup_->GetWidget()->Close(); | 286 popup_->GetWidget()->Close(); |
| 285 } | 287 } |
| OLD | NEW |