| 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" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 (!preview_enabled_ && !extension_action()->GetIsVisible(tab_id))) { | 97 (!preview_enabled_ && !extension_action()->GetIsVisible(tab_id))) { |
| 98 SetVisible(false); | 98 SetVisible(false); |
| 99 return; | 99 return; |
| 100 } | 100 } |
| 101 | 101 |
| 102 // Set the tooltip. | 102 // Set the tooltip. |
| 103 tooltip_ = extension_action()->GetTitle(tab_id); | 103 tooltip_ = extension_action()->GetTitle(tab_id); |
| 104 SetTooltipText(base::UTF8ToUTF16(tooltip_)); | 104 SetTooltipText(base::UTF8ToUTF16(tooltip_)); |
| 105 | 105 |
| 106 // Set the image. | 106 // Set the image. |
| 107 gfx::Image icon = view_controller_->GetIcon(contents); | 107 gfx::Image icon = view_controller_->GetIcon(contents, GetPreferredSize()); |
| 108 if (!icon.IsEmpty()) | 108 if (!icon.IsEmpty()) |
| 109 SetImage(*icon.ToImageSkia()); | 109 SetImage(*icon.ToImageSkia()); |
| 110 | 110 |
| 111 SetVisible(true); | 111 SetVisible(true); |
| 112 } | 112 } |
| 113 | 113 |
| 114 void PageActionImageView::PaintChildren(const ui::PaintContext& context) { | |
| 115 View::PaintChildren(context); | |
| 116 int tab_id = SessionTabHelper::IdForTab(GetCurrentWebContents()); | |
| 117 if (tab_id >= 0) { | |
| 118 ui::PaintRecorder recorder(context); | |
| 119 view_controller_->extension_action()->PaintBadge(recorder.canvas(), | |
| 120 GetLocalBounds(), tab_id); | |
| 121 } | |
| 122 } | |
| 123 | |
| 124 void PageActionImageView::UpdateState() { | 114 void PageActionImageView::UpdateState() { |
| 125 UpdateVisibility(GetCurrentWebContents()); | 115 UpdateVisibility(GetCurrentWebContents()); |
| 126 } | 116 } |
| 127 | 117 |
| 128 views::View* PageActionImageView::GetAsView() { | 118 views::View* PageActionImageView::GetAsView() { |
| 129 return this; | 119 return this; |
| 130 } | 120 } |
| 131 | 121 |
| 132 bool PageActionImageView::IsMenuRunning() const { | 122 bool PageActionImageView::IsMenuRunning() const { |
| 133 return menu_runner_.get() != nullptr; | 123 return menu_runner_.get() != nullptr; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 164 nullptr, // No menu button for page action views. | 154 nullptr, // No menu button for page action views. |
| 165 gfx::Rect(screen_loc, size()), | 155 gfx::Rect(screen_loc, size()), |
| 166 views::MENU_ANCHOR_TOPLEFT, | 156 views::MENU_ANCHOR_TOPLEFT, |
| 167 source_type) == views::MenuRunner::MENU_DELETED) { | 157 source_type) == views::MenuRunner::MENU_DELETED) { |
| 168 return; | 158 return; |
| 169 } | 159 } |
| 170 | 160 |
| 171 menu_runner_.reset(); | 161 menu_runner_.reset(); |
| 172 view_controller_->OnContextMenuClosed(); | 162 view_controller_->OnContextMenuClosed(); |
| 173 } | 163 } |
| OLD | NEW |