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" | 9 #include "ui/base/material_design/material_design_controller.h" |
| 10 #include "ui/events/event.h" | 10 #include "ui/events/event.h" |
| 11 #include "ui/gfx/color_palette.h" | 11 #include "ui/gfx/color_palette.h" |
| 12 #include "ui/gfx/color_utils.h" | 12 #include "ui/gfx/color_utils.h" |
| 13 #include "ui/gfx/paint_vector_icon.h" | 13 #include "ui/gfx/paint_vector_icon.h" |
| 14 #include "ui/native_theme/native_theme.h" | 14 #include "ui/native_theme/native_theme.h" |
| 15 #include "ui/views/animation/button_ink_drop_delegate.h" | 15 #include "ui/views/animation/button_ink_drop_delegate.h" |
| 16 #include "ui/views/animation/ink_drop_hover.h" | 16 #include "ui/views/animation/ink_drop_hover.h" |
| 17 #include "ui/views/bubble/bubble_delegate.h" | 17 #include "ui/views/bubble/bubble_dialog_delegate.h" |
| 18 | 18 |
| 19 BubbleIconView::BubbleIconView(CommandUpdater* command_updater, int command_id) | 19 BubbleIconView::BubbleIconView(CommandUpdater* command_updater, int command_id) |
| 20 : image_(new views::ImageView()), | 20 : image_(new views::ImageView()), |
| 21 command_updater_(command_updater), | 21 command_updater_(command_updater), |
| 22 command_id_(command_id), | 22 command_id_(command_id), |
| 23 active_(false), | 23 active_(false), |
| 24 suppress_mouse_released_action_(false), | 24 suppress_mouse_released_action_(false), |
| 25 ink_drop_delegate_(new views::ButtonInkDropDelegate(this, this)) { | 25 ink_drop_delegate_(new views::ButtonInkDropDelegate(this, this)) { |
| 26 AddChildView(image_); | 26 AddChildView(image_); |
| 27 image_->set_interactive(false); | 27 image_->set_interactive(false); |
| 28 image_->EnableCanvasFlippingForRTLUI(true); | 28 image_->EnableCanvasFlippingForRTLUI(true); |
| 29 image_->SetAccessibilityFocusable(true); | 29 image_->SetAccessibilityFocusable(true); |
| 30 } | 30 } |
| 31 | 31 |
| 32 BubbleIconView::~BubbleIconView() { | 32 BubbleIconView::~BubbleIconView() { |
| 33 } | 33 } |
| 34 | 34 |
| 35 bool BubbleIconView::IsBubbleShowing() const { | 35 bool BubbleIconView::IsBubbleShowing() const { |
| 36 // If the bubble is being destroyed, it's considered showing though it may be | 36 // If the bubble is being destroyed, it's considered showing though it may be |
| 37 // already invisible currently. | 37 // already invisible currently. |
| 38 return GetBubble() != NULL; | 38 return !!GetBubble(); |
|
sky
2016/03/09 16:18:38
IMO != nullptr is way more readable. Since you don
Evan Stade
2016/03/09 22:37:50
OK
| |
| 39 } | 39 } |
| 40 | 40 |
| 41 void BubbleIconView::SetImage(const gfx::ImageSkia* image_skia) { | 41 void BubbleIconView::SetImage(const gfx::ImageSkia* image_skia) { |
| 42 image_->SetImage(image_skia); | 42 image_->SetImage(image_skia); |
| 43 } | 43 } |
| 44 | 44 |
| 45 const gfx::ImageSkia& BubbleIconView::GetImage() const { | 45 const gfx::ImageSkia& BubbleIconView::GetImage() const { |
| 46 return image_->GetImage(); | 46 return image_->GetImage(); |
| 47 } | 47 } |
| 48 | 48 |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 166 | 166 |
| 167 gfx::VectorIconId BubbleIconView::GetVectorIcon() const { | 167 gfx::VectorIconId BubbleIconView::GetVectorIcon() const { |
| 168 return gfx::VectorIconId::VECTOR_ICON_NONE; | 168 return gfx::VectorIconId::VECTOR_ICON_NONE; |
| 169 } | 169 } |
| 170 | 170 |
| 171 bool BubbleIconView::SetRasterIcon() { | 171 bool BubbleIconView::SetRasterIcon() { |
| 172 return false; | 172 return false; |
| 173 } | 173 } |
| 174 | 174 |
| 175 void BubbleIconView::OnBoundsChanged(const gfx::Rect& previous_bounds) { | 175 void BubbleIconView::OnBoundsChanged(const gfx::Rect& previous_bounds) { |
| 176 views::BubbleDelegateView* bubble = GetBubble(); | 176 views::BubbleDialogDelegateView* bubble = GetBubble(); |
| 177 if (bubble) | 177 if (bubble) |
| 178 bubble->OnAnchorBoundsChanged(); | 178 bubble->OnAnchorBoundsChanged(); |
| 179 } | 179 } |
| 180 | 180 |
| 181 void BubbleIconView::UpdateIcon() { | 181 void BubbleIconView::UpdateIcon() { |
| 182 if (SetRasterIcon()) | 182 if (SetRasterIcon()) |
| 183 return; | 183 return; |
| 184 | 184 |
| 185 const int icon_size = | 185 const int icon_size = |
| 186 ui::MaterialDesignController::IsModeMaterial() ? 16 : 18; | 186 ui::MaterialDesignController::IsModeMaterial() ? 16 : 18; |
| 187 const ui::NativeTheme* theme = GetNativeTheme(); | 187 const ui::NativeTheme* theme = GetNativeTheme(); |
| 188 SkColor icon_color = | 188 SkColor icon_color = |
| 189 active_ | 189 active_ |
| 190 ? theme->GetSystemColor(ui::NativeTheme::kColorId_CallToActionColor) | 190 ? theme->GetSystemColor(ui::NativeTheme::kColorId_CallToActionColor) |
| 191 : GetInkDropBaseColor(); | 191 : GetInkDropBaseColor(); |
| 192 image_->SetImage( | 192 image_->SetImage( |
| 193 gfx::CreateVectorIcon(GetVectorIcon(), icon_size, icon_color)); | 193 gfx::CreateVectorIcon(GetVectorIcon(), icon_size, icon_color)); |
| 194 } | 194 } |
| 195 | 195 |
| 196 void BubbleIconView::SetActiveInternal(bool active) { | 196 void BubbleIconView::SetActiveInternal(bool active) { |
| 197 if (active_ == active) | 197 if (active_ == active) |
| 198 return; | 198 return; |
| 199 active_ = active; | 199 active_ = active; |
| 200 UpdateIcon(); | 200 UpdateIcon(); |
| 201 } | 201 } |
| OLD | NEW |