Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/bubble_icon_view.h" | 5 #include "chrome/browser/ui/views/location_bar/bubble_icon_view.h" |
| 6 | 6 |
| 7 #include "chrome/browser/command_updater.h" | 7 #include "chrome/browser/command_updater.h" |
| 8 #include "ui/accessibility/ax_view_state.h" | 8 #include "ui/accessibility/ax_view_state.h" |
| 9 #include "ui/base/material_design/material_design_controller.h" | |
| 10 #include "ui/events/event.h" | 9 #include "ui/events/event.h" |
| 11 #include "ui/gfx/color_palette.h" | 10 #include "ui/gfx/color_palette.h" |
| 12 #include "ui/gfx/color_utils.h" | 11 #include "ui/gfx/color_utils.h" |
| 13 #include "ui/gfx/paint_vector_icon.h" | 12 #include "ui/gfx/paint_vector_icon.h" |
| 14 #include "ui/native_theme/native_theme.h" | 13 #include "ui/native_theme/native_theme.h" |
| 15 #include "ui/views/animation/ink_drop_highlight.h" | 14 #include "ui/views/animation/ink_drop_highlight.h" |
| 16 #include "ui/views/bubble/bubble_dialog_delegate.h" | 15 #include "ui/views/bubble/bubble_dialog_delegate.h" |
| 17 | 16 |
| 18 BubbleIconView::BubbleIconView(CommandUpdater* command_updater, int command_id) | 17 BubbleIconView::BubbleIconView(CommandUpdater* command_updater, int command_id) |
| 19 : image_(new views::ImageView()), | 18 : image_(new views::ImageView()), |
| 20 command_updater_(command_updater), | 19 command_updater_(command_updater), |
| 21 command_id_(command_id), | 20 command_id_(command_id), |
| 22 active_(false), | 21 active_(false), |
| 23 suppress_mouse_released_action_(false) { | 22 suppress_mouse_released_action_(false) { |
| 24 AddChildView(image_); | 23 AddChildView(image_); |
| 25 image_->set_interactive(false); | 24 image_->set_interactive(false); |
| 26 image_->EnableCanvasFlippingForRTLUI(true); | 25 image_->EnableCanvasFlippingForRTLUI(true); |
| 27 if (ui::MaterialDesignController::IsModeMaterial()) { | 26 SetInkDropMode(InkDropMode::ON); |
| 28 SetInkDropMode(InkDropMode::ON); | 27 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); |
| 29 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); | |
| 30 } else { | |
| 31 image_->SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); | |
| 32 } | |
| 33 } | 28 } |
| 34 | 29 |
| 35 BubbleIconView::~BubbleIconView() {} | 30 BubbleIconView::~BubbleIconView() {} |
| 36 | 31 |
| 37 bool BubbleIconView::IsBubbleShowing() const { | 32 bool BubbleIconView::IsBubbleShowing() const { |
| 38 // If the bubble is being destroyed, it's considered showing though it may be | 33 // If the bubble is being destroyed, it's considered showing though it may be |
| 39 // already invisible currently. | 34 // already invisible currently. |
| 40 return GetBubble() != nullptr; | 35 return GetBubble() != nullptr; |
| 41 } | 36 } |
| 42 | 37 |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 176 void BubbleIconView::ExecuteCommand(ExecuteSource source) { | 171 void BubbleIconView::ExecuteCommand(ExecuteSource source) { |
| 177 OnExecuting(source); | 172 OnExecuting(source); |
| 178 if (command_updater_) | 173 if (command_updater_) |
| 179 command_updater_->ExecuteCommand(command_id_); | 174 command_updater_->ExecuteCommand(command_id_); |
| 180 } | 175 } |
| 181 | 176 |
| 182 gfx::VectorIconId BubbleIconView::GetVectorIcon() const { | 177 gfx::VectorIconId BubbleIconView::GetVectorIcon() const { |
| 183 return gfx::VectorIconId::VECTOR_ICON_NONE; | 178 return gfx::VectorIconId::VECTOR_ICON_NONE; |
| 184 } | 179 } |
| 185 | 180 |
| 186 bool BubbleIconView::SetRasterIcon() { | |
| 187 return false; | |
| 188 } | |
| 189 | |
| 190 void BubbleIconView::OnBoundsChanged(const gfx::Rect& previous_bounds) { | 181 void BubbleIconView::OnBoundsChanged(const gfx::Rect& previous_bounds) { |
| 191 views::BubbleDialogDelegateView* bubble = GetBubble(); | 182 views::BubbleDialogDelegateView* bubble = GetBubble(); |
| 192 if (bubble) | 183 if (bubble) |
| 193 bubble->OnAnchorBoundsChanged(); | 184 bubble->OnAnchorBoundsChanged(); |
| 194 } | 185 } |
| 195 | 186 |
| 196 void BubbleIconView::UpdateIcon() { | 187 void BubbleIconView::UpdateIcon() { |
| 197 if (SetRasterIcon()) | 188 const int icon_size = 16; |
|
Peter Kasting
2016/09/19 23:46:45
Nit: Make constexpr, name kConstantStyle... or jus
Evan Stade
2016/09/20 17:37:03
Done.
| |
| 198 return; | |
| 199 | |
| 200 const int icon_size = | |
| 201 ui::MaterialDesignController::IsModeMaterial() ? 16 : 18; | |
| 202 const ui::NativeTheme* theme = GetNativeTheme(); | 189 const ui::NativeTheme* theme = GetNativeTheme(); |
| 203 SkColor icon_color = | 190 SkColor icon_color = |
| 204 active_ | 191 active_ |
| 205 ? theme->GetSystemColor(ui::NativeTheme::kColorId_CallToActionColor) | 192 ? theme->GetSystemColor(ui::NativeTheme::kColorId_CallToActionColor) |
| 206 : GetInkDropBaseColor(); | 193 : GetInkDropBaseColor(); |
| 207 image_->SetImage( | 194 image_->SetImage( |
| 208 gfx::CreateVectorIcon(GetVectorIcon(), icon_size, icon_color)); | 195 gfx::CreateVectorIcon(GetVectorIcon(), icon_size, icon_color)); |
| 209 } | 196 } |
| 210 | 197 |
| 211 void BubbleIconView::SetActiveInternal(bool active) { | 198 void BubbleIconView::SetActiveInternal(bool active) { |
| 212 if (active_ == active) | 199 if (active_ == active) |
| 213 return; | 200 return; |
| 214 active_ = active; | 201 active_ = active; |
| 215 UpdateIcon(); | 202 UpdateIcon(); |
| 216 } | 203 } |
| OLD | NEW |