| 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/extension_action.h" | 8 #include "chrome/browser/extensions/extension_action.h" |
| 9 #include "chrome/browser/platform_util.h" | 9 #include "chrome/browser/platform_util.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/sessions/session_tab_helper.h" | 11 #include "chrome/browser/sessions/session_tab_helper.h" |
| 12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 13 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
| 14 #include "extensions/browser/extension_registry.h" | 14 #include "extensions/browser/extension_registry.h" |
| 15 #include "ui/accessibility/ax_view_state.h" | 15 #include "ui/accessibility/ax_view_state.h" |
| 16 #include "ui/events/event.h" | 16 #include "ui/events/event.h" |
| 17 #include "ui/gfx/canvas.h" | 17 #include "ui/gfx/canvas.h" |
| 18 #include "ui/gfx/image/image.h" | 18 #include "ui/gfx/image/image.h" |
| 19 | 19 |
| 20 // static | 20 // static |
| 21 const char PageActionImageView::kViewClassName[] = "PageActionImageView"; | 21 const char PageActionImageView::kViewClassName[] = "PageActionImageView"; |
| 22 | 22 |
| 23 PageActionImageView::PageActionImageView(LocationBarView* owner, | 23 PageActionImageView::PageActionImageView(LocationBarView* owner, |
| 24 ExtensionAction* page_action, | 24 ExtensionAction* page_action, |
| 25 Browser* browser) | 25 Browser* browser) |
| 26 : view_controller_(new ExtensionActionViewController( | 26 : view_controller_(new ExtensionActionViewControllerViews( |
| 27 extensions::ExtensionRegistry::Get(browser->profile())-> | 27 extensions::ExtensionRegistry::Get(browser->profile())-> |
| 28 enabled_extensions().GetByID(page_action->extension_id()), | 28 enabled_extensions().GetByID(page_action->extension_id()), |
| 29 browser, | 29 browser, |
| 30 page_action)), | 30 page_action)), |
| 31 owner_(owner), | 31 owner_(owner), |
| 32 preview_enabled_(false) { | 32 preview_enabled_(false) { |
| 33 // There should be an associated focus manager so that we can safely register | 33 // There should be an associated focus manager so that we can safely register |
| 34 // accelerators for commands. | 34 // accelerators for commands. |
| 35 DCHECK(GetFocusManagerForAccelerator()); | 35 DCHECK(GetFocusManagerForAccelerator()); |
| 36 SetAccessibilityFocusable(true); | 36 SetAccessibilityFocusable(true); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 void PageActionImageView::PaintChildren(gfx::Canvas* canvas, | 110 void PageActionImageView::PaintChildren(gfx::Canvas* canvas, |
| 111 const views::CullSet& cull_set) { | 111 const views::CullSet& cull_set) { |
| 112 View::PaintChildren(canvas, cull_set); | 112 View::PaintChildren(canvas, cull_set); |
| 113 int tab_id = SessionTabHelper::IdForTab(GetCurrentWebContents()); | 113 int tab_id = SessionTabHelper::IdForTab(GetCurrentWebContents()); |
| 114 if (tab_id >= 0) { | 114 if (tab_id >= 0) { |
| 115 view_controller_->extension_action()->PaintBadge( | 115 view_controller_->extension_action()->PaintBadge( |
| 116 canvas, GetLocalBounds(), tab_id); | 116 canvas, GetLocalBounds(), tab_id); |
| 117 } | 117 } |
| 118 } | 118 } |
| 119 | 119 |
| 120 void PageActionImageView::OnIconUpdated() { | 120 void PageActionImageView::UpdateState() { |
| 121 UpdateVisibility(GetCurrentWebContents()); | 121 UpdateVisibility(GetCurrentWebContents()); |
| 122 } | 122 } |
| 123 | 123 |
| 124 views::View* PageActionImageView::GetAsView() { | 124 views::View* PageActionImageView::GetAsView() { |
| 125 return this; | 125 return this; |
| 126 } | 126 } |
| 127 | 127 |
| 128 bool PageActionImageView::IsShownInMenu() { | 128 bool PageActionImageView::IsShownInMenu() { |
| 129 return false; | 129 return false; |
| 130 } | 130 } |
| 131 | 131 |
| 132 views::FocusManager* PageActionImageView::GetFocusManagerForAccelerator() { | 132 views::FocusManager* PageActionImageView::GetFocusManagerForAccelerator() { |
| 133 return owner_->GetFocusManager(); | 133 return owner_->GetFocusManager(); |
| 134 } | 134 } |
| 135 | 135 |
| 136 views::Widget* PageActionImageView::GetParentForContextMenu() { | 136 views::Widget* PageActionImageView::GetParentForContextMenu() { |
| 137 return GetWidget(); | 137 return GetWidget(); |
| 138 } | 138 } |
| 139 | 139 |
| 140 ExtensionActionViewController* | 140 ExtensionActionViewControllerViews* |
| 141 PageActionImageView::GetPreferredPopupViewController() { | 141 PageActionImageView::GetPreferredPopupViewController() { |
| 142 return view_controller_.get(); | 142 return view_controller_.get(); |
| 143 } | 143 } |
| 144 | 144 |
| 145 views::View* PageActionImageView::GetReferenceViewForPopup() { | 145 views::View* PageActionImageView::GetReferenceViewForPopup() { |
| 146 return this; | 146 return this; |
| 147 } | 147 } |
| 148 | 148 |
| 149 views::MenuButton* PageActionImageView::GetContextMenuButton() { | 149 views::MenuButton* PageActionImageView::GetContextMenuButton() { |
| 150 return NULL; // No menu button for page action views. | 150 return NULL; // No menu button for page action views. |
| 151 } | 151 } |
| 152 | 152 |
| 153 content::WebContents* PageActionImageView::GetCurrentWebContents() const { | 153 content::WebContents* PageActionImageView::GetCurrentWebContents() const { |
| 154 return owner_->GetWebContents(); | 154 return owner_->GetWebContents(); |
| 155 } | 155 } |
| 156 | 156 |
| 157 void PageActionImageView::HideActivePopup() { | 157 void PageActionImageView::HideActivePopup() { |
| 158 // The only popup that will be active is this popup. | 158 // The only popup that will be active is this popup. |
| 159 view_controller_->HidePopup(); | 159 view_controller_->HidePopup(); |
| 160 } | 160 } |
| OLD | NEW |