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(); |
| 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 |
154 void ToolbarButton::OnMouseExited(const ui::MouseEvent& event) { | 160 void ToolbarButton::OnMouseExited(const ui::MouseEvent& event) { |
| 161 UpdateInkDropHoverState(); |
| 162 |
155 // Starting a drag results in a MouseExited, we need to ignore it. | 163 // Starting a drag results in a MouseExited, we need to ignore it. |
156 // A right click release triggers an exit event. We want to | 164 // A right click release triggers an exit event. We want to |
157 // remain in a PUSHED state until the drop down menu closes. | 165 // remain in a PUSHED state until the drop down menu closes. |
158 if (state_ != STATE_DISABLED && !InDrag() && state_ != STATE_PRESSED) | 166 if (state_ != STATE_DISABLED && !InDrag() && state_ != STATE_PRESSED) |
159 SetState(STATE_NORMAL); | 167 SetState(STATE_NORMAL); |
160 } | 168 } |
161 | 169 |
162 void ToolbarButton::OnGestureEvent(ui::GestureEvent* event) { | 170 void ToolbarButton::OnGestureEvent(ui::GestureEvent* event) { |
163 if (menu_showing_) { | 171 if (menu_showing_) { |
164 // While dropdown menu is showing the button should not handle gestures. | 172 // 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 = | 215 scoped_ptr<views::LabelButtonBorder> border = |
208 views::LabelButton::CreateDefaultBorder(); | 216 views::LabelButton::CreateDefaultBorder(); |
209 | 217 |
210 ui::ThemeProvider* provider = GetThemeProvider(); | 218 ui::ThemeProvider* provider = GetThemeProvider(); |
211 if (provider && provider->UsingSystemTheme()) | 219 if (provider && provider->UsingSystemTheme()) |
212 border->set_insets(GetLayoutInsets(TOOLBAR_BUTTON)); | 220 border->set_insets(GetLayoutInsets(TOOLBAR_BUTTON)); |
213 | 221 |
214 return border.Pass(); | 222 return border.Pass(); |
215 } | 223 } |
216 | 224 |
| 225 void ToolbarButton::OnEnabledChanged() { |
| 226 UpdateInkDropHoverState(); |
| 227 } |
| 228 |
217 void ToolbarButton::ShowContextMenuForView(View* source, | 229 void ToolbarButton::ShowContextMenuForView(View* source, |
218 const gfx::Point& point, | 230 const gfx::Point& point, |
219 ui::MenuSourceType source_type) { | 231 ui::MenuSourceType source_type) { |
220 if (!enabled()) | 232 if (!enabled()) |
221 return; | 233 return; |
222 | 234 |
223 show_menu_factory_.InvalidateWeakPtrs(); | 235 show_menu_factory_.InvalidateWeakPtrs(); |
224 ShowDropDownMenu(source_type); | 236 ShowDropDownMenu(source_type); |
225 } | 237 } |
226 | 238 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 new views::MenuRunner(menu, views::MenuRunner::HAS_MNEMONICS)); | 334 new views::MenuRunner(menu, views::MenuRunner::HAS_MNEMONICS)); |
323 result = menu_runner_->RunMenuAt(GetWidget(), nullptr, | 335 result = menu_runner_->RunMenuAt(GetWidget(), nullptr, |
324 gfx::Rect(menu_position, gfx::Size(0, 0)), | 336 gfx::Rect(menu_position, gfx::Size(0, 0)), |
325 views::MENU_ANCHOR_TOPLEFT, source_type); | 337 views::MENU_ANCHOR_TOPLEFT, source_type); |
326 } | 338 } |
327 if (result == views::MenuRunner::MENU_DELETED) | 339 if (result == views::MenuRunner::MENU_DELETED) |
328 return; | 340 return; |
329 | 341 |
330 ink_drop_animation_controller_->AnimateToState( | 342 ink_drop_animation_controller_->AnimateToState( |
331 views::InkDropState::DEACTIVATED); | 343 views::InkDropState::DEACTIVATED); |
| 344 UpdateInkDropHoverState(); |
332 | 345 |
333 menu_showing_ = false; | 346 menu_showing_ = false; |
334 | 347 |
335 // Need to explicitly clear mouse handler so that events get sent | 348 // 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 | 349 // 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. | 350 // the first click to other parts of the UI is eaten. |
338 SetMouseHandler(nullptr); | 351 SetMouseHandler(nullptr); |
339 | 352 |
340 // Set the state back to normal after the drop down menu is closed. | 353 // Set the state back to normal after the drop down menu is closed. |
341 if (state_ != STATE_DISABLED) | 354 if (state_ != STATE_DISABLED) |
342 SetState(STATE_NORMAL); | 355 SetState(STATE_NORMAL); |
343 } | 356 } |
344 | 357 |
345 gfx::Point ToolbarButton::CalculateInkDropCenter() const { | 358 gfx::Point ToolbarButton::CalculateInkDropCenter() const { |
346 return GetLocalBounds().CenterPoint(); | 359 return GetLocalBounds().CenterPoint(); |
347 } | 360 } |
348 | 361 |
| 362 void ToolbarButton::UpdateInkDropHoverState() { |
| 363 ink_drop_animation_controller_->SetHovered((enabled() && IsMouseHovered())); |
| 364 } |
| 365 |
349 const char* ToolbarButton::GetClassName() const { | 366 const char* ToolbarButton::GetClassName() const { |
350 return "ToolbarButton"; | 367 return "ToolbarButton"; |
351 } | 368 } |
OLD | NEW |