OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/views/controls/button/custom_button.h" | 5 #include "ui/views/controls/button/custom_button.h" |
6 | 6 |
7 #include "ui/accessibility/ax_view_state.h" | 7 #include "ui/accessibility/ax_view_state.h" |
8 #include "ui/events/event.h" | 8 #include "ui/events/event.h" |
9 #include "ui/events/event_utils.h" | 9 #include "ui/events/event_utils.h" |
10 #include "ui/events/keycodes/keyboard_codes.h" | 10 #include "ui/events/keycodes/keyboard_codes.h" |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 //////////////////////////////////////////////////////////////////////////////// | 116 //////////////////////////////////////////////////////////////////////////////// |
117 // CustomButton, View overrides: | 117 // CustomButton, View overrides: |
118 | 118 |
119 void CustomButton::Layout() { | 119 void CustomButton::Layout() { |
120 Button::Layout(); | 120 Button::Layout(); |
121 if (ink_drop_delegate_) | 121 if (ink_drop_delegate_) |
122 ink_drop_delegate_->OnLayout(); | 122 ink_drop_delegate_->OnLayout(); |
123 } | 123 } |
124 | 124 |
125 void CustomButton::OnEnabledChanged() { | 125 void CustomButton::OnEnabledChanged() { |
| 126 // TODO(bruthig): Is there any reason we are not calling |
| 127 // Button::OnEnabledChanged() here? |
126 if (enabled() ? (state_ != STATE_DISABLED) : (state_ == STATE_DISABLED)) | 128 if (enabled() ? (state_ != STATE_DISABLED) : (state_ == STATE_DISABLED)) |
127 return; | 129 return; |
128 | 130 |
129 if (enabled()) | 131 if (enabled()) |
130 SetState(ShouldEnterHoveredState() ? STATE_HOVERED : STATE_NORMAL); | 132 SetState(ShouldEnterHoveredState() ? STATE_HOVERED : STATE_NORMAL); |
131 else | 133 else |
132 SetState(STATE_DISABLED); | 134 SetState(STATE_DISABLED); |
| 135 UpdateInkDropHoverState(); |
133 } | 136 } |
134 | 137 |
135 const char* CustomButton::GetClassName() const { | 138 const char* CustomButton::GetClassName() const { |
136 return kViewClassName; | 139 return kViewClassName; |
137 } | 140 } |
138 | 141 |
139 bool CustomButton::OnMousePressed(const ui::MouseEvent& event) { | 142 bool CustomButton::OnMousePressed(const ui::MouseEvent& event) { |
140 if (state_ == STATE_DISABLED) | 143 if (state_ == STATE_DISABLED) |
141 return true; | 144 return true; |
142 if (ShouldEnterPushedState(event) && HitTestPoint(event.location())) { | 145 if (ShouldEnterPushedState(event) && HitTestPoint(event.location())) { |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 void CustomButton::RemoveInkDropLayer(ui::Layer* ink_drop_layer) { | 348 void CustomButton::RemoveInkDropLayer(ui::Layer* ink_drop_layer) { |
346 layer()->Remove(ink_drop_layer); | 349 layer()->Remove(ink_drop_layer); |
347 SetFillsBoundsOpaquely(true); | 350 SetFillsBoundsOpaquely(true); |
348 SetPaintToLayer(false); | 351 SetPaintToLayer(false); |
349 } | 352 } |
350 | 353 |
351 gfx::Point CustomButton::CalculateInkDropCenter() const { | 354 gfx::Point CustomButton::CalculateInkDropCenter() const { |
352 return GetLocalBounds().CenterPoint(); | 355 return GetLocalBounds().CenterPoint(); |
353 } | 356 } |
354 | 357 |
| 358 bool CustomButton::ShouldShowInkDropHover() const { |
| 359 return enabled() && IsMouseHovered() && !InDrag(); |
| 360 } |
| 361 |
355 //////////////////////////////////////////////////////////////////////////////// | 362 //////////////////////////////////////////////////////////////////////////////// |
356 // CustomButton, protected: | 363 // CustomButton, protected: |
357 | 364 |
358 CustomButton::CustomButton(ButtonListener* listener) | 365 CustomButton::CustomButton(ButtonListener* listener) |
359 : Button(listener), | 366 : Button(listener), |
360 state_(STATE_NORMAL), | 367 state_(STATE_NORMAL), |
361 hover_animation_(this), | 368 hover_animation_(this), |
362 animate_on_state_change_(true), | 369 animate_on_state_change_(true), |
363 is_throbbing_(false), | 370 is_throbbing_(false), |
364 triggerable_event_flags_(ui::EF_LEFT_MOUSE_BUTTON), | 371 triggerable_event_flags_(ui::EF_LEFT_MOUSE_BUTTON), |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 aura::client::GetCaptureClient(root_window); | 408 aura::client::GetCaptureClient(root_window); |
402 aura::Window* capture_window = | 409 aura::Window* capture_window = |
403 capture_client ? capture_client->GetGlobalCaptureWindow() : nullptr; | 410 capture_client ? capture_client->GetGlobalCaptureWindow() : nullptr; |
404 check_mouse_position = !capture_window || capture_window == root_window; | 411 check_mouse_position = !capture_window || capture_window == root_window; |
405 } | 412 } |
406 #endif | 413 #endif |
407 | 414 |
408 return check_mouse_position && IsMouseHovered(); | 415 return check_mouse_position && IsMouseHovered(); |
409 } | 416 } |
410 | 417 |
| 418 void CustomButton::UpdateInkDropHoverState() { |
| 419 if (ink_drop_delegate_) |
| 420 ink_drop_delegate_->SetHovered(ShouldShowInkDropHover()); |
| 421 } |
| 422 |
411 //////////////////////////////////////////////////////////////////////////////// | 423 //////////////////////////////////////////////////////////////////////////////// |
412 // CustomButton, View overrides (protected): | 424 // CustomButton, View overrides (protected): |
413 | 425 |
414 void CustomButton::OnBoundsChanged(const gfx::Rect& previous_bounds) { | 426 void CustomButton::OnBoundsChanged(const gfx::Rect& previous_bounds) { |
415 Button::OnBoundsChanged(previous_bounds); | 427 Button::OnBoundsChanged(previous_bounds); |
416 if (ink_drop_delegate_) | 428 if (ink_drop_delegate_) |
417 ink_drop_delegate_->OnLayout(); | 429 ink_drop_delegate_->OnLayout(); |
418 } | 430 } |
419 | 431 |
420 void CustomButton::ViewHierarchyChanged( | 432 void CustomButton::ViewHierarchyChanged( |
(...skipping 23 matching lines...) Expand all Loading... |
444 return GetWidget() && GetWidget()->GetTopLevelWidget() != GetWidget(); | 456 return GetWidget() && GetWidget()->GetTopLevelWidget() != GetWidget(); |
445 } | 457 } |
446 | 458 |
447 bool CustomButton::FocusInChildWidget() const { | 459 bool CustomButton::FocusInChildWidget() const { |
448 return GetWidget() && | 460 return GetWidget() && |
449 GetWidget()->GetRootView()->Contains( | 461 GetWidget()->GetRootView()->Contains( |
450 GetFocusManager()->GetFocusedView()); | 462 GetFocusManager()->GetFocusedView()); |
451 } | 463 } |
452 | 464 |
453 } // namespace views | 465 } // namespace views |
OLD | NEW |