| 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_dialog_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)) { | |
| 26 AddChildView(image_); | 25 AddChildView(image_); |
| 27 image_->set_interactive(false); | 26 image_->set_interactive(false); |
| 28 image_->EnableCanvasFlippingForRTLUI(true); | 27 image_->EnableCanvasFlippingForRTLUI(true); |
| 29 image_->SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); | 28 if (ui::MaterialDesignController::IsModeMaterial()) |
| 29 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); |
| 30 else |
| 31 image_->SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); |
| 32 |
| 33 set_ink_drop_delegate( |
| 34 base::WrapUnique(new views::ButtonInkDropDelegate(this, this))); |
| 30 } | 35 } |
| 31 | 36 |
| 32 BubbleIconView::~BubbleIconView() {} | 37 BubbleIconView::~BubbleIconView() {} |
| 33 | 38 |
| 34 bool BubbleIconView::IsBubbleShowing() const { | 39 bool BubbleIconView::IsBubbleShowing() const { |
| 35 // If the bubble is being destroyed, it's considered showing though it may be | 40 // If the bubble is being destroyed, it's considered showing though it may be |
| 36 // already invisible currently. | 41 // already invisible currently. |
| 37 return GetBubble() != nullptr; | 42 return GetBubble() != nullptr; |
| 38 } | 43 } |
| 39 | 44 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 65 | 70 |
| 66 void BubbleIconView::Layout() { | 71 void BubbleIconView::Layout() { |
| 67 View::Layout(); | 72 View::Layout(); |
| 68 image_->SetBoundsRect(GetLocalBounds()); | 73 image_->SetBoundsRect(GetLocalBounds()); |
| 69 } | 74 } |
| 70 | 75 |
| 71 bool BubbleIconView::OnMousePressed(const ui::MouseEvent& event) { | 76 bool BubbleIconView::OnMousePressed(const ui::MouseEvent& event) { |
| 72 // If the bubble is showing then don't reshow it when the mouse is released. | 77 // If the bubble is showing then don't reshow it when the mouse is released. |
| 73 suppress_mouse_released_action_ = IsBubbleShowing(); | 78 suppress_mouse_released_action_ = IsBubbleShowing(); |
| 74 if (!suppress_mouse_released_action_ && event.IsOnlyLeftMouseButton()) | 79 if (!suppress_mouse_released_action_ && event.IsOnlyLeftMouseButton()) |
| 75 ink_drop_delegate_->OnAction(views::InkDropState::ACTION_PENDING); | 80 ink_drop_delegate()->OnAction(views::InkDropState::ACTION_PENDING); |
| 76 | 81 |
| 77 // We want to show the bubble on mouse release; that is the standard behavior | 82 // We want to show the bubble on mouse release; that is the standard behavior |
| 78 // for buttons. | 83 // for buttons. |
| 79 return true; | 84 return true; |
| 80 } | 85 } |
| 81 | 86 |
| 82 void BubbleIconView::OnMouseReleased(const ui::MouseEvent& event) { | 87 void BubbleIconView::OnMouseReleased(const ui::MouseEvent& event) { |
| 83 // If this is the second click on this view then the bubble was showing on the | 88 // If this is the second click on this view then the bubble was showing on the |
| 84 // mouse pressed event and is hidden now. Prevent the bubble from reshowing by | 89 // mouse pressed event and is hidden now. Prevent the bubble from reshowing by |
| 85 // doing nothing here. | 90 // doing nothing here. |
| 86 if (suppress_mouse_released_action_) { | 91 if (suppress_mouse_released_action_) { |
| 87 suppress_mouse_released_action_ = false; | 92 suppress_mouse_released_action_ = false; |
| 88 OnPressed(false); | 93 OnPressed(false); |
| 89 return; | 94 return; |
| 90 } | 95 } |
| 91 if (!event.IsLeftMouseButton()) | 96 if (!event.IsLeftMouseButton()) |
| 92 return; | 97 return; |
| 93 | 98 |
| 94 const bool activated = HitTestPoint(event.location()); | 99 const bool activated = HitTestPoint(event.location()); |
| 95 ink_drop_delegate_->OnAction(activated ? views::InkDropState::ACTIVATED | 100 ink_drop_delegate()->OnAction(activated ? views::InkDropState::ACTIVATED |
| 96 : views::InkDropState::HIDDEN); | 101 : views::InkDropState::HIDDEN); |
| 97 if (activated) | 102 if (activated) |
| 98 ExecuteCommand(EXECUTE_SOURCE_MOUSE); | 103 ExecuteCommand(EXECUTE_SOURCE_MOUSE); |
| 99 OnPressed(activated); | 104 OnPressed(activated); |
| 100 } | 105 } |
| 101 | 106 |
| 102 bool BubbleIconView::OnKeyPressed(const ui::KeyEvent& event) { | 107 bool BubbleIconView::OnKeyPressed(const ui::KeyEvent& event) { |
| 103 if (event.key_code() != ui::VKEY_RETURN && event.key_code() != ui::VKEY_SPACE) | 108 if (event.key_code() != ui::VKEY_RETURN && event.key_code() != ui::VKEY_SPACE) |
| 104 return false; | 109 return false; |
| 105 | 110 |
| 106 ink_drop_delegate_->OnAction(views::InkDropState::ACTIVATED); | 111 ink_drop_delegate()->OnAction(views::InkDropState::ACTIVATED); |
| 107 // As with CustomButton, return activates on key down and space activates on | 112 // As with CustomButton, return activates on key down and space activates on |
| 108 // key up. | 113 // key up. |
| 109 if (event.key_code() == ui::VKEY_RETURN) | 114 if (event.key_code() == ui::VKEY_RETURN) |
| 110 ExecuteCommand(EXECUTE_SOURCE_KEYBOARD); | 115 ExecuteCommand(EXECUTE_SOURCE_KEYBOARD); |
| 111 return true; | 116 return true; |
| 112 } | 117 } |
| 113 | 118 |
| 114 bool BubbleIconView::OnKeyReleased(const ui::KeyEvent& event) { | 119 bool BubbleIconView::OnKeyReleased(const ui::KeyEvent& event) { |
| 115 if (event.key_code() != ui::VKEY_SPACE) | 120 if (event.key_code() != ui::VKEY_SPACE) |
| 116 return false; | 121 return false; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 137 } | 142 } |
| 138 | 143 |
| 139 void BubbleIconView::RemoveInkDropLayer(ui::Layer* ink_drop_layer) { | 144 void BubbleIconView::RemoveInkDropLayer(ui::Layer* ink_drop_layer) { |
| 140 views::InkDropHostView::RemoveInkDropLayer(ink_drop_layer); | 145 views::InkDropHostView::RemoveInkDropLayer(ink_drop_layer); |
| 141 image_->SetPaintToLayer(false); | 146 image_->SetPaintToLayer(false); |
| 142 } | 147 } |
| 143 | 148 |
| 144 std::unique_ptr<views::InkDropHover> BubbleIconView::CreateInkDropHover() | 149 std::unique_ptr<views::InkDropHover> BubbleIconView::CreateInkDropHover() |
| 145 const { | 150 const { |
| 146 // BubbleIconView views don't show hover effect. | 151 // BubbleIconView views don't show hover effect. |
| 147 return nullptr; | 152 return HasFocus() ? InkDropHostView::CreateInkDropHover() : nullptr; |
| 148 } | 153 } |
| 149 | 154 |
| 150 SkColor BubbleIconView::GetInkDropBaseColor() const { | 155 SkColor BubbleIconView::GetInkDropBaseColor() const { |
| 151 return color_utils::DeriveDefaultIconColor(GetNativeTheme()->GetSystemColor( | 156 return color_utils::DeriveDefaultIconColor(GetNativeTheme()->GetSystemColor( |
| 152 ui::NativeTheme::kColorId_TextfieldDefaultColor)); | 157 ui::NativeTheme::kColorId_TextfieldDefaultColor)); |
| 153 } | 158 } |
| 154 | 159 |
| 160 bool BubbleIconView::ShouldShowInkDropForFocus() const { |
| 161 return true; |
| 162 } |
| 163 |
| 155 void BubbleIconView::OnGestureEvent(ui::GestureEvent* event) { | 164 void BubbleIconView::OnGestureEvent(ui::GestureEvent* event) { |
| 156 if (event->type() == ui::ET_GESTURE_TAP) { | 165 if (event->type() == ui::ET_GESTURE_TAP) { |
| 157 ink_drop_delegate_->OnAction(views::InkDropState::ACTIVATED); | 166 ink_drop_delegate()->OnAction(views::InkDropState::ACTIVATED); |
| 158 ExecuteCommand(EXECUTE_SOURCE_GESTURE); | 167 ExecuteCommand(EXECUTE_SOURCE_GESTURE); |
| 159 event->SetHandled(); | 168 event->SetHandled(); |
| 160 } | 169 } |
| 161 } | 170 } |
| 162 | 171 |
| 163 void BubbleIconView::OnWidgetDestroying(views::Widget* widget) { | 172 void BubbleIconView::OnWidgetDestroying(views::Widget* widget) { |
| 164 widget->RemoveObserver(this); | 173 widget->RemoveObserver(this); |
| 165 } | 174 } |
| 166 | 175 |
| 167 void BubbleIconView::OnWidgetVisibilityChanged(views::Widget* widget, | 176 void BubbleIconView::OnWidgetVisibilityChanged(views::Widget* widget, |
| 168 bool visible) { | 177 bool visible) { |
| 169 // |widget| is a bubble that has just got shown / hidden. | 178 // |widget| is a bubble that has just got shown / hidden. |
| 170 if (!visible) | 179 if (!visible) |
| 171 ink_drop_delegate_->OnAction(views::InkDropState::DEACTIVATED); | 180 ink_drop_delegate()->OnAction(views::InkDropState::DEACTIVATED); |
| 172 } | 181 } |
| 173 | 182 |
| 174 void BubbleIconView::ExecuteCommand(ExecuteSource source) { | 183 void BubbleIconView::ExecuteCommand(ExecuteSource source) { |
| 175 OnExecuting(source); | 184 OnExecuting(source); |
| 176 if (command_updater_) | 185 if (command_updater_) |
| 177 command_updater_->ExecuteCommand(command_id_); | 186 command_updater_->ExecuteCommand(command_id_); |
| 178 } | 187 } |
| 179 | 188 |
| 180 gfx::VectorIconId BubbleIconView::GetVectorIcon() const { | 189 gfx::VectorIconId BubbleIconView::GetVectorIcon() const { |
| 181 return gfx::VectorIconId::VECTOR_ICON_NONE; | 190 return gfx::VectorIconId::VECTOR_ICON_NONE; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 205 image_->SetImage( | 214 image_->SetImage( |
| 206 gfx::CreateVectorIcon(GetVectorIcon(), icon_size, icon_color)); | 215 gfx::CreateVectorIcon(GetVectorIcon(), icon_size, icon_color)); |
| 207 } | 216 } |
| 208 | 217 |
| 209 void BubbleIconView::SetActiveInternal(bool active) { | 218 void BubbleIconView::SetActiveInternal(bool active) { |
| 210 if (active_ == active) | 219 if (active_ == active) |
| 211 return; | 220 return; |
| 212 active_ = active; | 221 active_ = active; |
| 213 UpdateIcon(); | 222 UpdateIcon(); |
| 214 } | 223 } |
| OLD | NEW |