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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
186 // Starting a drag results in a MouseCaptureLost, we need to ignore it. | 189 // Starting a drag results in a MouseCaptureLost, we need to ignore it. |
187 if (state_ != STATE_DISABLED && !InDrag()) | 190 if (state_ != STATE_DISABLED && !InDrag()) |
188 SetState(STATE_NORMAL); | 191 SetState(STATE_NORMAL); |
189 if (ink_drop_delegate_) | 192 if (ink_drop_delegate_) |
190 ink_drop_delegate_->OnAction(views::InkDropState::HIDDEN); | 193 ink_drop_delegate_->OnAction(views::InkDropState::HIDDEN); |
191 } | 194 } |
192 | 195 |
193 void CustomButton::OnMouseEntered(const ui::MouseEvent& event) { | 196 void CustomButton::OnMouseEntered(const ui::MouseEvent& event) { |
194 if (state_ != STATE_DISABLED) | 197 if (state_ != STATE_DISABLED) |
195 SetState(STATE_HOVERED); | 198 SetState(STATE_HOVERED); |
199 UpdateInkDropHoverState(); | |
196 } | 200 } |
197 | 201 |
198 void CustomButton::OnMouseExited(const ui::MouseEvent& event) { | 202 void CustomButton::OnMouseExited(const ui::MouseEvent& event) { |
199 // Starting a drag results in a MouseExited, we need to ignore it. | 203 // Starting a drag results in a MouseExited, we need to ignore it. |
200 if (state_ != STATE_DISABLED && !InDrag()) | 204 if (state_ != STATE_DISABLED && !InDrag()) |
201 SetState(STATE_NORMAL); | 205 SetState(STATE_NORMAL); |
206 UpdateInkDropHoverState(); | |
sadrul
2016/01/12 15:55:38
Can ButtonInkDropDelegate take care of updating th
bruthig
2016/01/12 16:27:17
Done.
| |
202 } | 207 } |
203 | 208 |
204 void CustomButton::OnMouseMoved(const ui::MouseEvent& event) { | 209 void CustomButton::OnMouseMoved(const ui::MouseEvent& event) { |
205 if (state_ != STATE_DISABLED) | 210 if (state_ != STATE_DISABLED) |
206 SetState(HitTestPoint(event.location()) ? STATE_HOVERED : STATE_NORMAL); | 211 SetState(HitTestPoint(event.location()) ? STATE_HOVERED : STATE_NORMAL); |
207 } | 212 } |
208 | 213 |
209 bool CustomButton::OnKeyPressed(const ui::KeyEvent& event) { | 214 bool CustomButton::OnKeyPressed(const ui::KeyEvent& event) { |
210 if (state_ == STATE_DISABLED) | 215 if (state_ == STATE_DISABLED) |
211 return false; | 216 return false; |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
345 void CustomButton::RemoveInkDropLayer(ui::Layer* ink_drop_layer) { | 350 void CustomButton::RemoveInkDropLayer(ui::Layer* ink_drop_layer) { |
346 layer()->Remove(ink_drop_layer); | 351 layer()->Remove(ink_drop_layer); |
347 SetFillsBoundsOpaquely(true); | 352 SetFillsBoundsOpaquely(true); |
348 SetPaintToLayer(false); | 353 SetPaintToLayer(false); |
349 } | 354 } |
350 | 355 |
351 gfx::Point CustomButton::CalculateInkDropCenter() const { | 356 gfx::Point CustomButton::CalculateInkDropCenter() const { |
352 return GetLocalBounds().CenterPoint(); | 357 return GetLocalBounds().CenterPoint(); |
353 } | 358 } |
354 | 359 |
360 bool CustomButton::ShouldShowInkDropHover() const { | |
361 return enabled() && IsMouseHovered() && !InDrag(); | |
362 } | |
363 | |
355 //////////////////////////////////////////////////////////////////////////////// | 364 //////////////////////////////////////////////////////////////////////////////// |
356 // CustomButton, protected: | 365 // CustomButton, protected: |
357 | 366 |
358 CustomButton::CustomButton(ButtonListener* listener) | 367 CustomButton::CustomButton(ButtonListener* listener) |
359 : Button(listener), | 368 : Button(listener), |
360 state_(STATE_NORMAL), | 369 state_(STATE_NORMAL), |
361 hover_animation_(this), | 370 hover_animation_(this), |
362 animate_on_state_change_(true), | 371 animate_on_state_change_(true), |
363 is_throbbing_(false), | 372 is_throbbing_(false), |
364 triggerable_event_flags_(ui::EF_LEFT_MOUSE_BUTTON), | 373 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); | 410 aura::client::GetCaptureClient(root_window); |
402 aura::Window* capture_window = | 411 aura::Window* capture_window = |
403 capture_client ? capture_client->GetGlobalCaptureWindow() : nullptr; | 412 capture_client ? capture_client->GetGlobalCaptureWindow() : nullptr; |
404 check_mouse_position = !capture_window || capture_window == root_window; | 413 check_mouse_position = !capture_window || capture_window == root_window; |
405 } | 414 } |
406 #endif | 415 #endif |
407 | 416 |
408 return check_mouse_position && IsMouseHovered(); | 417 return check_mouse_position && IsMouseHovered(); |
409 } | 418 } |
410 | 419 |
420 void CustomButton::UpdateInkDropHoverState() { | |
421 if (ink_drop_delegate_) | |
422 ink_drop_delegate_->SetHovered(ShouldShowInkDropHover()); | |
423 } | |
424 | |
411 //////////////////////////////////////////////////////////////////////////////// | 425 //////////////////////////////////////////////////////////////////////////////// |
412 // CustomButton, View overrides (protected): | 426 // CustomButton, View overrides (protected): |
413 | 427 |
414 void CustomButton::OnBoundsChanged(const gfx::Rect& previous_bounds) { | 428 void CustomButton::OnBoundsChanged(const gfx::Rect& previous_bounds) { |
415 Button::OnBoundsChanged(previous_bounds); | 429 Button::OnBoundsChanged(previous_bounds); |
416 if (ink_drop_delegate_) | 430 if (ink_drop_delegate_) |
417 ink_drop_delegate_->OnLayout(); | 431 ink_drop_delegate_->OnLayout(); |
418 } | 432 } |
419 | 433 |
420 void CustomButton::ViewHierarchyChanged( | 434 void CustomButton::ViewHierarchyChanged( |
(...skipping 23 matching lines...) Expand all Loading... | |
444 return GetWidget() && GetWidget()->GetTopLevelWidget() != GetWidget(); | 458 return GetWidget() && GetWidget()->GetTopLevelWidget() != GetWidget(); |
445 } | 459 } |
446 | 460 |
447 bool CustomButton::FocusInChildWidget() const { | 461 bool CustomButton::FocusInChildWidget() const { |
448 return GetWidget() && | 462 return GetWidget() && |
449 GetWidget()->GetRootView()->Contains( | 463 GetWidget()->GetRootView()->Contains( |
450 GetFocusManager()->GetFocusedView()); | 464 GetFocusManager()->GetFocusedView()); |
451 } | 465 } |
452 | 466 |
453 } // namespace views | 467 } // namespace views |
OLD | NEW |