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