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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 137 | 137 |
| 138 void ToolbarButton::OnMouseReleased(const ui::MouseEvent& event) { | 138 void ToolbarButton::OnMouseReleased(const ui::MouseEvent& event) { |
| 139 if (IsTriggerableEvent(event) || | 139 if (IsTriggerableEvent(event) || |
| 140 (event.IsRightMouseButton() && !HitTestPoint(event.location()))) { | 140 (event.IsRightMouseButton() && !HitTestPoint(event.location()))) { |
| 141 LabelButton::OnMouseReleased(event); | 141 LabelButton::OnMouseReleased(event); |
| 142 } | 142 } |
| 143 | 143 |
| 144 if (IsTriggerableEvent(event)) | 144 if (IsTriggerableEvent(event)) |
| 145 show_menu_factory_.InvalidateWeakPtrs(); | 145 show_menu_factory_.InvalidateWeakPtrs(); |
| 146 | 146 |
| 147 UpdateInkDropHoverState(); | |
|
Peter Kasting
2015/10/15 22:21:33
Why do you need this?
bruthig
2015/10/16 14:57:21
It is needed for the following situation:
1.) Lef
Peter Kasting
2015/10/16 18:41:16
It sounds like a bug to me that OnMouseExited() is
bruthig
2015/11/02 16:42:31
I have changed the behavior such that the hover is
| |
| 148 | |
| 147 if (!HitTestPoint(event.location())) | 149 if (!HitTestPoint(event.location())) |
| 148 ink_drop_animation_controller_->AnimateToState(views::InkDropState::HIDDEN); | 150 ink_drop_animation_controller_->AnimateToState(views::InkDropState::HIDDEN); |
| 149 } | 151 } |
| 150 | 152 |
| 151 void ToolbarButton::OnMouseCaptureLost() { | 153 void ToolbarButton::OnMouseCaptureLost() { |
| 152 } | 154 } |
| 153 | 155 |
| 156 void ToolbarButton::OnMouseEntered(const ui::MouseEvent& event) { | |
| 157 UpdateInkDropHoverState(); | |
| 158 } | |
| 159 | |
| 160 void ToolbarButton::OnMouseMoved(const ui::MouseEvent& event) { | |
|
Peter Kasting
2015/10/15 22:21:33
Why do you need this override if you have the ente
bruthig
2015/10/16 14:57:21
This was necessary for the following situation:
1
Peter Kasting
2015/10/16 18:41:16
I don't reproduce the mouse pointer disappearing w
bruthig
2015/10/16 19:10:51
I just want to confirm that you are indeed using a
bruthig
2015/11/02 16:42:31
FTR This is still needed for the following scenari
| |
| 161 UpdateInkDropHoverState(); | |
| 162 } | |
| 163 | |
| 154 void ToolbarButton::OnMouseExited(const ui::MouseEvent& event) { | 164 void ToolbarButton::OnMouseExited(const ui::MouseEvent& event) { |
| 165 UpdateInkDropHoverState(); | |
| 166 | |
| 155 // Starting a drag results in a MouseExited, we need to ignore it. | 167 // Starting a drag results in a MouseExited, we need to ignore it. |
| 156 // A right click release triggers an exit event. We want to | 168 // A right click release triggers an exit event. We want to |
| 157 // remain in a PUSHED state until the drop down menu closes. | 169 // remain in a PUSHED state until the drop down menu closes. |
| 158 if (state_ != STATE_DISABLED && !InDrag() && state_ != STATE_PRESSED) | 170 if (state_ != STATE_DISABLED && !InDrag() && state_ != STATE_PRESSED) |
| 159 SetState(STATE_NORMAL); | 171 SetState(STATE_NORMAL); |
| 160 } | 172 } |
| 161 | 173 |
| 162 void ToolbarButton::OnGestureEvent(ui::GestureEvent* event) { | 174 void ToolbarButton::OnGestureEvent(ui::GestureEvent* event) { |
| 163 if (menu_showing_) { | 175 if (menu_showing_) { |
| 164 // While dropdown menu is showing the button should not handle gestures. | 176 // While dropdown menu is showing the button should not handle gestures. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 207 scoped_ptr<views::LabelButtonBorder> border = | 219 scoped_ptr<views::LabelButtonBorder> border = |
| 208 views::LabelButton::CreateDefaultBorder(); | 220 views::LabelButton::CreateDefaultBorder(); |
| 209 | 221 |
| 210 ui::ThemeProvider* provider = GetThemeProvider(); | 222 ui::ThemeProvider* provider = GetThemeProvider(); |
| 211 if (provider && provider->UsingSystemTheme()) | 223 if (provider && provider->UsingSystemTheme()) |
| 212 border->set_insets(GetLayoutInsets(TOOLBAR_BUTTON)); | 224 border->set_insets(GetLayoutInsets(TOOLBAR_BUTTON)); |
| 213 | 225 |
| 214 return border.Pass(); | 226 return border.Pass(); |
| 215 } | 227 } |
| 216 | 228 |
| 229 void ToolbarButton::OnEnabledChanged() { | |
| 230 UpdateInkDropHoverState(); | |
| 231 } | |
| 232 | |
| 217 void ToolbarButton::ShowContextMenuForView(View* source, | 233 void ToolbarButton::ShowContextMenuForView(View* source, |
| 218 const gfx::Point& point, | 234 const gfx::Point& point, |
| 219 ui::MenuSourceType source_type) { | 235 ui::MenuSourceType source_type) { |
| 220 if (!enabled()) | 236 if (!enabled()) |
| 221 return; | 237 return; |
| 222 | 238 |
| 223 show_menu_factory_.InvalidateWeakPtrs(); | 239 show_menu_factory_.InvalidateWeakPtrs(); |
| 224 ShowDropDownMenu(source_type); | 240 ShowDropDownMenu(source_type); |
| 225 } | 241 } |
| 226 | 242 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 322 new views::MenuRunner(menu, views::MenuRunner::HAS_MNEMONICS)); | 338 new views::MenuRunner(menu, views::MenuRunner::HAS_MNEMONICS)); |
| 323 result = menu_runner_->RunMenuAt(GetWidget(), nullptr, | 339 result = menu_runner_->RunMenuAt(GetWidget(), nullptr, |
| 324 gfx::Rect(menu_position, gfx::Size(0, 0)), | 340 gfx::Rect(menu_position, gfx::Size(0, 0)), |
| 325 views::MENU_ANCHOR_TOPLEFT, source_type); | 341 views::MENU_ANCHOR_TOPLEFT, source_type); |
| 326 } | 342 } |
| 327 if (result == views::MenuRunner::MENU_DELETED) | 343 if (result == views::MenuRunner::MENU_DELETED) |
| 328 return; | 344 return; |
| 329 | 345 |
| 330 ink_drop_animation_controller_->AnimateToState( | 346 ink_drop_animation_controller_->AnimateToState( |
| 331 views::InkDropState::DEACTIVATED); | 347 views::InkDropState::DEACTIVATED); |
| 348 UpdateInkDropHoverState(); | |
|
Peter Kasting
2015/10/15 22:21:33
Why do you need this?
bruthig
2015/10/16 14:57:21
Similar reason to why I needed it in ToolbarButton
Peter Kasting
2015/10/16 18:41:16
Same reply as above.
bruthig
2015/11/02 16:42:31
This has been removed since the hover is turned of
| |
| 332 | 349 |
| 333 menu_showing_ = false; | 350 menu_showing_ = false; |
| 334 | 351 |
| 335 // Need to explicitly clear mouse handler so that events get sent | 352 // Need to explicitly clear mouse handler so that events get sent |
| 336 // properly after the menu finishes running. If we don't do this, then | 353 // properly after the menu finishes running. If we don't do this, then |
| 337 // the first click to other parts of the UI is eaten. | 354 // the first click to other parts of the UI is eaten. |
| 338 SetMouseHandler(nullptr); | 355 SetMouseHandler(nullptr); |
| 339 | 356 |
| 340 // Set the state back to normal after the drop down menu is closed. | 357 // Set the state back to normal after the drop down menu is closed. |
| 341 if (state_ != STATE_DISABLED) | 358 if (state_ != STATE_DISABLED) |
| 342 SetState(STATE_NORMAL); | 359 SetState(STATE_NORMAL); |
| 343 } | 360 } |
| 344 | 361 |
| 345 gfx::Point ToolbarButton::CalculateInkDropCenter() const { | 362 gfx::Point ToolbarButton::CalculateInkDropCenter() const { |
| 346 return GetLocalBounds().CenterPoint(); | 363 return GetLocalBounds().CenterPoint(); |
| 347 } | 364 } |
| 348 | 365 |
| 366 void ToolbarButton::UpdateInkDropHoverState() { | |
| 367 ink_drop_animation_controller_->SetHovered((enabled() && IsMouseHovered())); | |
|
Peter Kasting
2015/10/15 22:21:33
Too many parens
bruthig
2015/10/16 14:57:21
Done.
| |
| 368 } | |
| 369 | |
| 349 const char* ToolbarButton::GetClassName() const { | 370 const char* ToolbarButton::GetClassName() const { |
| 350 return "ToolbarButton"; | 371 return "ToolbarButton"; |
| 351 } | 372 } |
| OLD | NEW |