| 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/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
| 12 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 13 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
| 13 #include "extensions/browser/extension_registry.h" | 14 #include "extensions/browser/extension_registry.h" |
| 14 #include "ui/accessibility/ax_view_state.h" | 15 #include "ui/accessibility/ax_view_state.h" |
| 15 #include "ui/events/event.h" | 16 #include "ui/events/event.h" |
| 16 #include "ui/gfx/canvas.h" | 17 #include "ui/gfx/canvas.h" |
| 17 #include "ui/gfx/image/image.h" | 18 #include "ui/gfx/image/image.h" |
| 18 | 19 |
| 19 // static | 20 // static |
| 20 const char PageActionImageView::kViewClassName[] = "PageActionImageView"; | 21 const char PageActionImageView::kViewClassName[] = "PageActionImageView"; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 } | 81 } |
| 81 | 82 |
| 82 void PageActionImageView::OnGestureEvent(ui::GestureEvent* event) { | 83 void PageActionImageView::OnGestureEvent(ui::GestureEvent* event) { |
| 83 if (event->type() == ui::ET_GESTURE_TAP) { | 84 if (event->type() == ui::ET_GESTURE_TAP) { |
| 84 view_controller_->ExecuteActionByUser(); | 85 view_controller_->ExecuteActionByUser(); |
| 85 event->SetHandled(); | 86 event->SetHandled(); |
| 86 } | 87 } |
| 87 } | 88 } |
| 88 | 89 |
| 89 void PageActionImageView::UpdateVisibility(content::WebContents* contents) { | 90 void PageActionImageView::UpdateVisibility(content::WebContents* contents) { |
| 90 int tab_id = view_controller_->GetCurrentTabId(); | 91 int tab_id = GetCurrentTabId(); |
| 91 | |
| 92 if (!contents || | 92 if (!contents || |
| 93 tab_id == -1 || | 93 tab_id == -1 || |
| 94 (!preview_enabled_ && !extension_action()->GetIsVisible(tab_id))) { | 94 (!preview_enabled_ && !extension_action()->GetIsVisible(tab_id))) { |
| 95 SetVisible(false); | 95 SetVisible(false); |
| 96 return; | 96 return; |
| 97 } | 97 } |
| 98 | 98 |
| 99 // Set the tooltip. | 99 // Set the tooltip. |
| 100 tooltip_ = extension_action()->GetTitle(tab_id); | 100 tooltip_ = extension_action()->GetTitle(tab_id); |
| 101 SetTooltipText(base::UTF8ToUTF16(tooltip_)); | 101 SetTooltipText(base::UTF8ToUTF16(tooltip_)); |
| 102 | 102 |
| 103 // Set the image. | 103 // Set the image. |
| 104 gfx::Image icon = view_controller_->GetIcon(tab_id); | 104 gfx::Image icon = view_controller_->GetIcon(tab_id); |
| 105 if (!icon.IsEmpty()) | 105 if (!icon.IsEmpty()) |
| 106 SetImage(*icon.ToImageSkia()); | 106 SetImage(*icon.ToImageSkia()); |
| 107 | 107 |
| 108 SetVisible(true); | 108 SetVisible(true); |
| 109 } | 109 } |
| 110 | 110 |
| 111 void PageActionImageView::PaintChildren(gfx::Canvas* canvas, | 111 void PageActionImageView::PaintChildren(gfx::Canvas* canvas, |
| 112 const views::CullSet& cull_set) { | 112 const views::CullSet& cull_set) { |
| 113 View::PaintChildren(canvas, cull_set); | 113 View::PaintChildren(canvas, cull_set); |
| 114 int tab_id = view_controller_->GetCurrentTabId(); | 114 int tab_id = GetCurrentTabId(); |
| 115 if (tab_id >= 0) { | 115 if (tab_id >= 0) { |
| 116 view_controller_->extension_action()->PaintBadge( | 116 view_controller_->extension_action()->PaintBadge( |
| 117 canvas, GetLocalBounds(), tab_id); | 117 canvas, GetLocalBounds(), tab_id); |
| 118 } | 118 } |
| 119 } | 119 } |
| 120 | 120 |
| 121 void PageActionImageView::OnIconUpdated() { | 121 void PageActionImageView::OnIconUpdated() { |
| 122 UpdateVisibility(GetCurrentWebContents()); | 122 UpdateVisibility(owner_->GetWebContents()); |
| 123 } | 123 } |
| 124 | 124 |
| 125 views::View* PageActionImageView::GetAsView() { | 125 views::View* PageActionImageView::GetAsView() { |
| 126 return this; | 126 return this; |
| 127 } | 127 } |
| 128 | 128 |
| 129 bool PageActionImageView::IsShownInMenu() { | 129 bool PageActionImageView::IsShownInMenu() { |
| 130 return false; | 130 return false; |
| 131 } | 131 } |
| 132 | 132 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 144 } | 144 } |
| 145 | 145 |
| 146 views::View* PageActionImageView::GetReferenceViewForPopup() { | 146 views::View* PageActionImageView::GetReferenceViewForPopup() { |
| 147 return this; | 147 return this; |
| 148 } | 148 } |
| 149 | 149 |
| 150 views::MenuButton* PageActionImageView::GetContextMenuButton() { | 150 views::MenuButton* PageActionImageView::GetContextMenuButton() { |
| 151 return NULL; // No menu button for page action views. | 151 return NULL; // No menu button for page action views. |
| 152 } | 152 } |
| 153 | 153 |
| 154 content::WebContents* PageActionImageView::GetCurrentWebContents() { | 154 int PageActionImageView::GetCurrentTabId() const { |
| 155 return owner_->GetWebContents(); | 155 content::WebContents* web_contents = owner_->GetWebContents(); |
| 156 return web_contents ? SessionTabHelper::IdForTab(web_contents) : -1; |
| 156 } | 157 } |
| 157 | 158 |
| 158 void PageActionImageView::HideActivePopup() { | 159 void PageActionImageView::HideActivePopup() { |
| 159 // The only popup that will be active is this popup. | 160 // The only popup that will be active is this popup. |
| 160 view_controller_->HidePopup(); | 161 view_controller_->HidePopup(); |
| 161 } | 162 } |
| OLD | NEW |