| 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" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 | 68 |
| 69 void BubbleIconView::Layout() { | 69 void BubbleIconView::Layout() { |
| 70 View::Layout(); | 70 View::Layout(); |
| 71 image_->SetBoundsRect(GetLocalBounds()); | 71 image_->SetBoundsRect(GetLocalBounds()); |
| 72 } | 72 } |
| 73 | 73 |
| 74 bool BubbleIconView::OnMousePressed(const ui::MouseEvent& event) { | 74 bool BubbleIconView::OnMousePressed(const ui::MouseEvent& event) { |
| 75 // If the bubble is showing then don't reshow it when the mouse is released. | 75 // If the bubble is showing then don't reshow it when the mouse is released. |
| 76 suppress_mouse_released_action_ = IsBubbleShowing(); | 76 suppress_mouse_released_action_ = IsBubbleShowing(); |
| 77 if (!suppress_mouse_released_action_ && event.IsOnlyLeftMouseButton()) | 77 if (!suppress_mouse_released_action_ && event.IsOnlyLeftMouseButton()) |
| 78 AnimateInkDrop(views::InkDropState::ACTION_PENDING); | 78 AnimateInkDrop(views::InkDropState::ACTION_PENDING, &event); |
| 79 | 79 |
| 80 // We want to show the bubble on mouse release; that is the standard behavior | 80 // We want to show the bubble on mouse release; that is the standard behavior |
| 81 // for buttons. | 81 // for buttons. |
| 82 return true; | 82 return true; |
| 83 } | 83 } |
| 84 | 84 |
| 85 void BubbleIconView::OnMouseReleased(const ui::MouseEvent& event) { | 85 void BubbleIconView::OnMouseReleased(const ui::MouseEvent& event) { |
| 86 // If this is the second click on this view then the bubble was showing on the | 86 // If this is the second click on this view then the bubble was showing on the |
| 87 // mouse pressed event and is hidden now. Prevent the bubble from reshowing by | 87 // mouse pressed event and is hidden now. Prevent the bubble from reshowing by |
| 88 // doing nothing here. | 88 // doing nothing here. |
| 89 if (suppress_mouse_released_action_) { | 89 if (suppress_mouse_released_action_) { |
| 90 suppress_mouse_released_action_ = false; | 90 suppress_mouse_released_action_ = false; |
| 91 OnPressed(false); | 91 OnPressed(false); |
| 92 return; | 92 return; |
| 93 } | 93 } |
| 94 if (!event.IsLeftMouseButton()) | 94 if (!event.IsLeftMouseButton()) |
| 95 return; | 95 return; |
| 96 | 96 |
| 97 const bool activated = HitTestPoint(event.location()); | 97 const bool activated = HitTestPoint(event.location()); |
| 98 AnimateInkDrop(activated ? views::InkDropState::ACTIVATED | 98 AnimateInkDrop( |
| 99 : views::InkDropState::HIDDEN); | 99 activated ? views::InkDropState::ACTIVATED : views::InkDropState::HIDDEN, |
| 100 &event); |
| 100 if (activated) | 101 if (activated) |
| 101 ExecuteCommand(EXECUTE_SOURCE_MOUSE); | 102 ExecuteCommand(EXECUTE_SOURCE_MOUSE); |
| 102 OnPressed(activated); | 103 OnPressed(activated); |
| 103 } | 104 } |
| 104 | 105 |
| 105 bool BubbleIconView::OnKeyPressed(const ui::KeyEvent& event) { | 106 bool BubbleIconView::OnKeyPressed(const ui::KeyEvent& event) { |
| 106 if (event.key_code() != ui::VKEY_RETURN && event.key_code() != ui::VKEY_SPACE) | 107 if (event.key_code() != ui::VKEY_RETURN && event.key_code() != ui::VKEY_SPACE) |
| 107 return false; | 108 return false; |
| 108 | 109 |
| 109 AnimateInkDrop(views::InkDropState::ACTIVATED); | 110 AnimateInkDrop(views::InkDropState::ACTIVATED, nullptr /* &event */); |
| 110 // As with CustomButton, return activates on key down and space activates on | 111 // As with CustomButton, return activates on key down and space activates on |
| 111 // key up. | 112 // key up. |
| 112 if (event.key_code() == ui::VKEY_RETURN) | 113 if (event.key_code() == ui::VKEY_RETURN) |
| 113 ExecuteCommand(EXECUTE_SOURCE_KEYBOARD); | 114 ExecuteCommand(EXECUTE_SOURCE_KEYBOARD); |
| 114 return true; | 115 return true; |
| 115 } | 116 } |
| 116 | 117 |
| 117 bool BubbleIconView::OnKeyReleased(const ui::KeyEvent& event) { | 118 bool BubbleIconView::OnKeyReleased(const ui::KeyEvent& event) { |
| 118 if (event.key_code() != ui::VKEY_SPACE) | 119 if (event.key_code() != ui::VKEY_SPACE) |
| 119 return false; | 120 return false; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 return color_utils::DeriveDefaultIconColor(GetNativeTheme()->GetSystemColor( | 155 return color_utils::DeriveDefaultIconColor(GetNativeTheme()->GetSystemColor( |
| 155 ui::NativeTheme::kColorId_TextfieldDefaultColor)); | 156 ui::NativeTheme::kColorId_TextfieldDefaultColor)); |
| 156 } | 157 } |
| 157 | 158 |
| 158 bool BubbleIconView::ShouldShowInkDropForFocus() const { | 159 bool BubbleIconView::ShouldShowInkDropForFocus() const { |
| 159 return true; | 160 return true; |
| 160 } | 161 } |
| 161 | 162 |
| 162 void BubbleIconView::OnGestureEvent(ui::GestureEvent* event) { | 163 void BubbleIconView::OnGestureEvent(ui::GestureEvent* event) { |
| 163 if (event->type() == ui::ET_GESTURE_TAP) { | 164 if (event->type() == ui::ET_GESTURE_TAP) { |
| 164 AnimateInkDrop(views::InkDropState::ACTIVATED); | 165 AnimateInkDrop(views::InkDropState::ACTIVATED, event); |
| 165 ExecuteCommand(EXECUTE_SOURCE_GESTURE); | 166 ExecuteCommand(EXECUTE_SOURCE_GESTURE); |
| 166 event->SetHandled(); | 167 event->SetHandled(); |
| 167 } | 168 } |
| 168 } | 169 } |
| 169 | 170 |
| 170 void BubbleIconView::OnWidgetDestroying(views::Widget* widget) { | 171 void BubbleIconView::OnWidgetDestroying(views::Widget* widget) { |
| 171 widget->RemoveObserver(this); | 172 widget->RemoveObserver(this); |
| 172 } | 173 } |
| 173 | 174 |
| 174 void BubbleIconView::OnWidgetVisibilityChanged(views::Widget* widget, | 175 void BubbleIconView::OnWidgetVisibilityChanged(views::Widget* widget, |
| 175 bool visible) { | 176 bool visible) { |
| 176 // |widget| is a bubble that has just got shown / hidden. | 177 // |widget| is a bubble that has just got shown / hidden. |
| 177 if (!visible) | 178 if (!visible) |
| 178 AnimateInkDrop(views::InkDropState::DEACTIVATED); | 179 AnimateInkDrop(views::InkDropState::DEACTIVATED, nullptr /* event */); |
| 179 } | 180 } |
| 180 | 181 |
| 181 void BubbleIconView::ExecuteCommand(ExecuteSource source) { | 182 void BubbleIconView::ExecuteCommand(ExecuteSource source) { |
| 182 OnExecuting(source); | 183 OnExecuting(source); |
| 183 if (command_updater_) | 184 if (command_updater_) |
| 184 command_updater_->ExecuteCommand(command_id_); | 185 command_updater_->ExecuteCommand(command_id_); |
| 185 } | 186 } |
| 186 | 187 |
| 187 gfx::VectorIconId BubbleIconView::GetVectorIcon() const { | 188 gfx::VectorIconId BubbleIconView::GetVectorIcon() const { |
| 188 return gfx::VectorIconId::VECTOR_ICON_NONE; | 189 return gfx::VectorIconId::VECTOR_ICON_NONE; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 212 image_->SetImage( | 213 image_->SetImage( |
| 213 gfx::CreateVectorIcon(GetVectorIcon(), icon_size, icon_color)); | 214 gfx::CreateVectorIcon(GetVectorIcon(), icon_size, icon_color)); |
| 214 } | 215 } |
| 215 | 216 |
| 216 void BubbleIconView::SetActiveInternal(bool active) { | 217 void BubbleIconView::SetActiveInternal(bool active) { |
| 217 if (active_ == active) | 218 if (active_ == active) |
| 218 return; | 219 return; |
| 219 active_ = active; | 220 active_ = active; |
| 220 UpdateIcon(); | 221 UpdateIcon(); |
| 221 } | 222 } |
| OLD | NEW |