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/toolbar/toolbar_button.h" | 5 #include "chrome/browser/ui/views/toolbar/toolbar_button.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 29 ui::MenuModel* model) | 29 ui::MenuModel* model) |
| 30 : views::LabelButton(listener, base::string16()), | 30 : views::LabelButton(listener, base::string16()), |
| 31 model_(model), | 31 model_(model), |
| 32 menu_showing_(false), | 32 menu_showing_(false), |
| 33 y_position_on_lbuttondown_(0), | 33 y_position_on_lbuttondown_(0), |
| 34 show_menu_factory_(this) { | 34 show_menu_factory_(this) { |
| 35 #if defined(OS_CHROMEOS) | 35 #if defined(OS_CHROMEOS) |
| 36 // The ink drop animation is only targeted at ChromeOS because there is | 36 // The ink drop animation is only targeted at ChromeOS because there is |
| 37 // concern it will conflict with OS level touch feedback in a bad way. | 37 // concern it will conflict with OS level touch feedback in a bad way. |
| 38 if (ui::MaterialDesignController::IsModeMaterial()) { | 38 if (ui::MaterialDesignController::IsModeMaterial()) { |
| 39 SetPaintToLayer(true); | |
|
jonross
2015/08/07 17:14:31
Will this now always be the responsibility of the
bruthig
2015/08/07 22:00:45
Yes, the reason being that the InkDropHost could p
tdanderson
2015/08/10 16:31:01
It may be a good idea to include this in a comment
bruthig
2015/08/10 21:57:15
Done. See documentation for the InkDropHost.
| |
| 39 ink_drop_animation_controller_.reset( | 40 ink_drop_animation_controller_.reset( |
| 40 new views::InkDropAnimationController(this)); | 41 new views::InkDropAnimationController(this)); |
| 41 layer()->SetFillsBoundsOpaquely(false); | 42 layer()->SetFillsBoundsOpaquely(false); |
| 42 image()->SetPaintToLayer(true); | 43 image()->SetPaintToLayer(true); |
| 43 image()->SetFillsBoundsOpaquely(false); | 44 image()->SetFillsBoundsOpaquely(false); |
| 44 } | 45 } |
| 45 #endif // defined(OS_CHROMEOS) | 46 #endif // defined(OS_CHROMEOS) |
| 46 | 47 |
| 47 set_context_menu_controller(this); | 48 set_context_menu_controller(this); |
| 48 } | 49 } |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 79 ui::ThemeProvider* provider = GetThemeProvider(); | 80 ui::ThemeProvider* provider = GetThemeProvider(); |
| 80 if (provider && provider->UsingSystemTheme()) { | 81 if (provider && provider->UsingSystemTheme()) { |
| 81 int inset = provider->GetDisplayProperty( | 82 int inset = provider->GetDisplayProperty( |
| 82 ThemeProperties::PROPERTY_TOOLBAR_BUTTON_BORDER_INSET); | 83 ThemeProperties::PROPERTY_TOOLBAR_BUTTON_BORDER_INSET); |
| 83 size.Enlarge(2 * inset, 2 * inset); | 84 size.Enlarge(2 * inset, 2 * inset); |
| 84 } | 85 } |
| 85 } | 86 } |
| 86 return size; | 87 return size; |
| 87 } | 88 } |
| 88 | 89 |
| 90 void ToolbarButton::Layout() { | |
| 91 LabelButton::Layout(); | |
| 92 if (ui::MaterialDesignController::IsModeMaterial()) | |
| 93 LayoutInkDrop(); | |
| 94 } | |
| 95 | |
| 89 bool ToolbarButton::OnMousePressed(const ui::MouseEvent& event) { | 96 bool ToolbarButton::OnMousePressed(const ui::MouseEvent& event) { |
| 90 if (enabled() && ShouldShowMenu() && | 97 if (enabled() && ShouldShowMenu() && |
| 91 IsTriggerableEvent(event) && HitTestPoint(event.location())) { | 98 IsTriggerableEvent(event) && HitTestPoint(event.location())) { |
| 92 // Store the y pos of the mouse coordinates so we can use them later to | 99 // Store the y pos of the mouse coordinates so we can use them later to |
| 93 // determine if the user dragged the mouse down (which should pop up the | 100 // determine if the user dragged the mouse down (which should pop up the |
| 94 // drag down menu immediately, instead of waiting for the timer) | 101 // drag down menu immediately, instead of waiting for the timer) |
| 95 y_position_on_lbuttondown_ = event.y(); | 102 y_position_on_lbuttondown_ = event.y(); |
| 96 | 103 |
| 97 // Schedule a task that will show the menu. | 104 // Schedule a task that will show the menu. |
| 98 const int kMenuTimerDelay = 500; | 105 const int kMenuTimerDelay = 500; |
| 99 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 106 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 100 FROM_HERE, base::Bind(&ToolbarButton::ShowDropDownMenu, | 107 FROM_HERE, base::Bind(&ToolbarButton::ShowDropDownMenu, |
| 101 show_menu_factory_.GetWeakPtr(), | 108 show_menu_factory_.GetWeakPtr(), |
| 102 ui::GetMenuSourceTypeForEvent(event)), | 109 ui::GetMenuSourceTypeForEvent(event)), |
| 103 base::TimeDelta::FromMilliseconds(kMenuTimerDelay)); | 110 base::TimeDelta::FromMilliseconds(kMenuTimerDelay)); |
| 104 } | 111 } |
| 112 | |
| 113 if (ui::MaterialDesignController::IsModeMaterial()) | |
| 114 ink_drop_animation_controller_->AnimateToState( | |
| 115 views::InkDropState::ACTION_PENDING); | |
| 116 | |
| 105 return LabelButton::OnMousePressed(event); | 117 return LabelButton::OnMousePressed(event); |
| 106 } | 118 } |
| 107 | 119 |
| 108 bool ToolbarButton::OnMouseDragged(const ui::MouseEvent& event) { | 120 bool ToolbarButton::OnMouseDragged(const ui::MouseEvent& event) { |
| 109 bool result = LabelButton::OnMouseDragged(event); | 121 bool result = LabelButton::OnMouseDragged(event); |
| 110 | 122 |
| 111 if (show_menu_factory_.HasWeakPtrs()) { | 123 if (show_menu_factory_.HasWeakPtrs()) { |
| 112 // If the mouse is dragged to a y position lower than where it was when | 124 // If the mouse is dragged to a y position lower than where it was when |
| 113 // clicked then we should not wait for the menu to appear but show | 125 // clicked then we should not wait for the menu to appear but show |
| 114 // it immediately. | 126 // it immediately. |
| 115 if (event.y() > y_position_on_lbuttondown_ + GetHorizontalDragThreshold()) { | 127 if (event.y() > y_position_on_lbuttondown_ + GetHorizontalDragThreshold()) { |
| 116 show_menu_factory_.InvalidateWeakPtrs(); | 128 show_menu_factory_.InvalidateWeakPtrs(); |
| 117 ShowDropDownMenu(ui::GetMenuSourceTypeForEvent(event)); | 129 ShowDropDownMenu(ui::GetMenuSourceTypeForEvent(event)); |
|
jonross
2015/08/07 17:14:31
State change?
bruthig
2015/08/07 22:00:45
I've omitted setting the ACTIVATED state for the t
jonross
2015/08/10 20:32:02
Acknowledged.
| |
| 118 } | 130 } |
| 119 } | 131 } |
| 120 | 132 |
| 121 return result; | 133 return result; |
| 122 } | 134 } |
| 123 | 135 |
| 124 void ToolbarButton::OnMouseReleased(const ui::MouseEvent& event) { | 136 void ToolbarButton::OnMouseReleased(const ui::MouseEvent& event) { |
| 125 if (IsTriggerableEvent(event) || | 137 if (IsTriggerableEvent(event) || |
| 126 (event.IsRightMouseButton() && !HitTestPoint(event.location()))) { | 138 (event.IsRightMouseButton() && !HitTestPoint(event.location()))) { |
| 127 LabelButton::OnMouseReleased(event); | 139 LabelButton::OnMouseReleased(event); |
| 128 } | 140 } |
| 129 | 141 |
| 130 if (IsTriggerableEvent(event)) | 142 if (IsTriggerableEvent(event)) |
| 131 show_menu_factory_.InvalidateWeakPtrs(); | 143 show_menu_factory_.InvalidateWeakPtrs(); |
| 144 | |
| 145 if (ui::MaterialDesignController::IsModeMaterial()) | |
| 146 ink_drop_animation_controller_->AnimateToState(views::InkDropState::HIDDEN); | |
| 132 } | 147 } |
| 133 | 148 |
| 134 void ToolbarButton::OnMouseCaptureLost() { | 149 void ToolbarButton::OnMouseCaptureLost() { |
| 135 } | 150 } |
| 136 | 151 |
| 137 void ToolbarButton::OnMouseExited(const ui::MouseEvent& event) { | 152 void ToolbarButton::OnMouseExited(const ui::MouseEvent& event) { |
| 138 // Starting a drag results in a MouseExited, we need to ignore it. | 153 // Starting a drag results in a MouseExited, we need to ignore it. |
| 139 // A right click release triggers an exit event. We want to | 154 // A right click release triggers an exit event. We want to |
| 140 // remain in a PUSHED state until the drop down menu closes. | 155 // remain in a PUSHED state until the drop down menu closes. |
| 141 if (state_ != STATE_DISABLED && !InDrag() && state_ != STATE_PRESSED) | 156 if (state_ != STATE_DISABLED && !InDrag() && state_ != STATE_PRESSED) |
| 142 SetState(STATE_NORMAL); | 157 SetState(STATE_NORMAL); |
| 143 } | 158 } |
| 144 | 159 |
| 145 void ToolbarButton::OnGestureEvent(ui::GestureEvent* event) { | 160 void ToolbarButton::OnGestureEvent(ui::GestureEvent* event) { |
| 146 if (menu_showing_) { | 161 if (menu_showing_) { |
| 147 // While dropdown menu is showing the button should not handle gestures. | 162 // While dropdown menu is showing the button should not handle gestures. |
| 148 event->StopPropagation(); | 163 event->StopPropagation(); |
| 149 return; | 164 return; |
| 150 } | 165 } |
| 151 | 166 |
| 167 if (ui::MaterialDesignController::IsModeMaterial()) { | |
| 168 switch (event->type()) { | |
| 169 case ui::ET_GESTURE_TAP_DOWN: | |
| 170 ink_drop_animation_controller_->AnimateToState( | |
| 171 views::InkDropState::ACTION_PENDING); | |
| 172 break; | |
| 173 case ui::ET_GESTURE_LONG_PRESS: | |
| 174 ink_drop_animation_controller_->AnimateToState( | |
| 175 views::InkDropState::SLOW_ACTION); | |
| 176 break; | |
| 177 case ui::ET_GESTURE_TAP: | |
| 178 ink_drop_animation_controller_->AnimateToState( | |
| 179 views::InkDropState::QUICK_ACTION); | |
| 180 break; | |
| 181 case ui::ET_GESTURE_END: | |
| 182 case ui::ET_GESTURE_TAP_CANCEL: | |
|
jonross
2015/08/07 17:14:31
We won't receive these if TAP_DOWN is not marked a
bruthig
2015/08/07 22:00:45
Done.
tdanderson
2015/08/10 16:31:01
Did you verify this? It seems to me that the imple
jonross
2015/08/10 20:32:02
Well I would be concerned about each usage of the
bruthig
2015/08/10 21:57:15
I could call LabelButton::OnGestureEvent(...) befo
tdanderson
2015/08/11 12:57:36
I would prefer that, but I don't think it's necess
bruthig
2015/08/11 14:31:10
Done.
| |
| 183 ink_drop_animation_controller_->AnimateToState( | |
| 184 views::InkDropState::HIDDEN); | |
| 185 break; | |
| 186 default: | |
| 187 break; | |
| 188 } | |
| 189 } | |
| 190 | |
| 152 LabelButton::OnGestureEvent(event); | 191 LabelButton::OnGestureEvent(event); |
| 153 } | 192 } |
| 154 | 193 |
| 155 void ToolbarButton::GetAccessibleState(ui::AXViewState* state) { | 194 void ToolbarButton::GetAccessibleState(ui::AXViewState* state) { |
| 156 CustomButton::GetAccessibleState(state); | 195 CustomButton::GetAccessibleState(state); |
| 157 state->role = ui::AX_ROLE_BUTTON_DROP_DOWN; | 196 state->role = ui::AX_ROLE_BUTTON_DROP_DOWN; |
| 158 state->default_action = l10n_util::GetStringUTF16(IDS_APP_ACCACTION_PRESS); | 197 state->default_action = l10n_util::GetStringUTF16(IDS_APP_ACCACTION_PRESS); |
| 159 state->AddStateFlag(ui::AX_STATE_HASPOPUP); | 198 state->AddStateFlag(ui::AX_STATE_HASPOPUP); |
| 160 } | 199 } |
| 161 | 200 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 194 void ToolbarButton::ShowContextMenuForView(View* source, | 233 void ToolbarButton::ShowContextMenuForView(View* source, |
| 195 const gfx::Point& point, | 234 const gfx::Point& point, |
| 196 ui::MenuSourceType source_type) { | 235 ui::MenuSourceType source_type) { |
| 197 if (!enabled()) | 236 if (!enabled()) |
| 198 return; | 237 return; |
| 199 | 238 |
| 200 show_menu_factory_.InvalidateWeakPtrs(); | 239 show_menu_factory_.InvalidateWeakPtrs(); |
| 201 ShowDropDownMenu(source_type); | 240 ShowDropDownMenu(source_type); |
| 202 } | 241 } |
| 203 | 242 |
| 243 void ToolbarButton::AddInkDropLayer(ui::Layer* ink_drop_layer) { | |
| 244 layer()->Add(ink_drop_layer); | |
| 245 layer()->StackAtBottom(ink_drop_layer); | |
| 246 } | |
| 247 | |
| 248 void ToolbarButton::RemoveInkDropLayer(ui::Layer* ink_drop_layer) { | |
| 249 layer()->Remove(ink_drop_layer); | |
| 250 } | |
| 251 | |
| 204 bool ToolbarButton::ShouldEnterPushedState(const ui::Event& event) { | 252 bool ToolbarButton::ShouldEnterPushedState(const ui::Event& event) { |
| 205 // Enter PUSHED state on press with Left or Right mouse button or on taps. | 253 // Enter PUSHED state on press with Left or Right mouse button or on taps. |
| 206 // Remain in this state while the context menu is open. | 254 // Remain in this state while the context menu is open. |
| 207 return event.type() == ui::ET_GESTURE_TAP || | 255 return event.type() == ui::ET_GESTURE_TAP || |
| 208 event.type() == ui::ET_GESTURE_TAP_DOWN || | 256 event.type() == ui::ET_GESTURE_TAP_DOWN || |
| 209 (event.IsMouseEvent() && ((ui::EF_LEFT_MOUSE_BUTTON | | 257 (event.IsMouseEvent() && ((ui::EF_LEFT_MOUSE_BUTTON | |
| 210 ui::EF_RIGHT_MOUSE_BUTTON) & event.flags()) != 0); | 258 ui::EF_RIGHT_MOUSE_BUTTON) & event.flags()) != 0); |
| 211 } | 259 } |
| 212 | 260 |
| 213 bool ToolbarButton::ShouldShowMenu() { | 261 bool ToolbarButton::ShouldShowMenu() { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 278 views::MenuRunner::RunResult result = | 326 views::MenuRunner::RunResult result = |
| 279 menu_runner_->RunMenuAt(GetWidget(), | 327 menu_runner_->RunMenuAt(GetWidget(), |
| 280 NULL, | 328 NULL, |
| 281 gfx::Rect(menu_position, gfx::Size(0, 0)), | 329 gfx::Rect(menu_position, gfx::Size(0, 0)), |
| 282 views::MENU_ANCHOR_TOPLEFT, | 330 views::MENU_ANCHOR_TOPLEFT, |
| 283 source_type); | 331 source_type); |
| 284 if (result == views::MenuRunner::MENU_DELETED) | 332 if (result == views::MenuRunner::MENU_DELETED) |
| 285 return; | 333 return; |
| 286 } | 334 } |
| 287 | 335 |
| 336 if (ui::MaterialDesignController::IsModeMaterial()) | |
| 337 ink_drop_animation_controller_->AnimateToState(views::InkDropState::HIDDEN); | |
|
jonross
2015/08/07 17:14:31
Can the transition to Hidden be triggered twice fo
bruthig
2015/08/07 22:00:45
My thinking is that the InkDropAnimationController
jonross
2015/08/10 20:32:02
Acknowledged.
| |
| 338 | |
| 288 menu_showing_ = false; | 339 menu_showing_ = false; |
| 289 | 340 |
| 290 // Need to explicitly clear mouse handler so that events get sent | 341 // Need to explicitly clear mouse handler so that events get sent |
| 291 // properly after the menu finishes running. If we don't do this, then | 342 // properly after the menu finishes running. If we don't do this, then |
| 292 // the first click to other parts of the UI is eaten. | 343 // the first click to other parts of the UI is eaten. |
| 293 SetMouseHandler(NULL); | 344 SetMouseHandler(NULL); |
| 294 | 345 |
| 295 // Set the state back to normal after the drop down menu is closed. | 346 // Set the state back to normal after the drop down menu is closed. |
| 296 if (state_ != STATE_DISABLED) | 347 if (state_ != STATE_DISABLED) |
| 297 SetState(STATE_NORMAL); | 348 SetState(STATE_NORMAL); |
| 298 } | 349 } |
| 299 | 350 |
| 351 void ToolbarButton::LayoutInkDrop() { | |
| 352 ink_drop_animation_controller_->SetSize(gfx::Size(width(), height())); | |
| 353 } | |
| 354 | |
| 300 const char* ToolbarButton::GetClassName() const { | 355 const char* ToolbarButton::GetClassName() const { |
| 301 return "ToolbarButton"; | 356 return "ToolbarButton"; |
| 302 } | 357 } |
| OLD | NEW |