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" |
11 #include "ui/gfx/animation/throb_animation.h" | 11 #include "ui/gfx/animation/throb_animation.h" |
12 #include "ui/gfx/screen.h" | 12 #include "ui/gfx/screen.h" |
| 13 #include "ui/views/animation/ink_drop_delegate.h" |
13 #include "ui/views/controls/button/blue_button.h" | 14 #include "ui/views/controls/button/blue_button.h" |
14 #include "ui/views/controls/button/checkbox.h" | 15 #include "ui/views/controls/button/checkbox.h" |
15 #include "ui/views/controls/button/image_button.h" | 16 #include "ui/views/controls/button/image_button.h" |
16 #include "ui/views/controls/button/label_button.h" | 17 #include "ui/views/controls/button/label_button.h" |
17 #include "ui/views/controls/button/menu_button.h" | 18 #include "ui/views/controls/button/menu_button.h" |
18 #include "ui/views/controls/button/radio_button.h" | 19 #include "ui/views/controls/button/radio_button.h" |
19 #include "ui/views/widget/widget.h" | 20 #include "ui/views/widget/widget.h" |
20 | 21 |
21 #if defined(USE_AURA) | 22 #if defined(USE_AURA) |
22 #include "ui/aura/client/capture_client.h" | 23 #include "ui/aura/client/capture_client.h" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 NotifyAccessibilityEvent(ui::AX_EVENT_FOCUS, true); | 110 NotifyAccessibilityEvent(ui::AX_EVENT_FOCUS, true); |
110 } | 111 } |
111 | 112 |
112 bool CustomButton::IsHotTracked() const { | 113 bool CustomButton::IsHotTracked() const { |
113 return state_ == STATE_HOVERED; | 114 return state_ == STATE_HOVERED; |
114 } | 115 } |
115 | 116 |
116 //////////////////////////////////////////////////////////////////////////////// | 117 //////////////////////////////////////////////////////////////////////////////// |
117 // CustomButton, View overrides: | 118 // CustomButton, View overrides: |
118 | 119 |
| 120 void CustomButton::Layout() { |
| 121 if (ink_drop_delegate_) |
| 122 ink_drop_delegate_->OnLayout(); |
| 123 } |
| 124 |
119 void CustomButton::OnEnabledChanged() { | 125 void CustomButton::OnEnabledChanged() { |
120 if (enabled() ? (state_ != STATE_DISABLED) : (state_ == STATE_DISABLED)) | 126 if (enabled() ? (state_ != STATE_DISABLED) : (state_ == STATE_DISABLED)) |
121 return; | 127 return; |
122 | 128 |
123 if (enabled()) | 129 if (enabled()) |
124 SetState(ShouldEnterHoveredState() ? STATE_HOVERED : STATE_NORMAL); | 130 SetState(ShouldEnterHoveredState() ? STATE_HOVERED : STATE_NORMAL); |
125 else | 131 else |
126 SetState(STATE_DISABLED); | 132 SetState(STATE_DISABLED); |
127 } | 133 } |
128 | 134 |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 if (state_ != STATE_DISABLED) | 283 if (state_ != STATE_DISABLED) |
278 SetState(STATE_NORMAL); | 284 SetState(STATE_NORMAL); |
279 View::ShowContextMenu(p, source_type); | 285 View::ShowContextMenu(p, source_type); |
280 } | 286 } |
281 | 287 |
282 void CustomButton::OnDragDone() { | 288 void CustomButton::OnDragDone() { |
283 // Only reset the state to normal if the button isn't currently disabled | 289 // Only reset the state to normal if the button isn't currently disabled |
284 // (since disabled buttons may still be able to be dragged). | 290 // (since disabled buttons may still be able to be dragged). |
285 if (state_ != STATE_DISABLED) | 291 if (state_ != STATE_DISABLED) |
286 SetState(STATE_NORMAL); | 292 SetState(STATE_NORMAL); |
| 293 if (ink_drop_delegate_) |
| 294 ink_drop_delegate_->OnAction(InkDropState::HIDDEN); |
287 } | 295 } |
288 | 296 |
289 void CustomButton::GetAccessibleState(ui::AXViewState* state) { | 297 void CustomButton::GetAccessibleState(ui::AXViewState* state) { |
290 Button::GetAccessibleState(state); | 298 Button::GetAccessibleState(state); |
291 switch (state_) { | 299 switch (state_) { |
292 case STATE_HOVERED: | 300 case STATE_HOVERED: |
293 state->AddStateFlag(ui::AX_STATE_HOVERED); | 301 state->AddStateFlag(ui::AX_STATE_HOVERED); |
294 break; | 302 break; |
295 case STATE_PRESSED: | 303 case STATE_PRESSED: |
296 state->AddStateFlag(ui::AX_STATE_PRESSED); | 304 state->AddStateFlag(ui::AX_STATE_PRESSED); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 aura::client::GetCaptureClient(root_window); | 372 aura::client::GetCaptureClient(root_window); |
365 aura::Window* capture_window = | 373 aura::Window* capture_window = |
366 capture_client ? capture_client->GetGlobalCaptureWindow() : nullptr; | 374 capture_client ? capture_client->GetGlobalCaptureWindow() : nullptr; |
367 check_mouse_position = !capture_window || capture_window == root_window; | 375 check_mouse_position = !capture_window || capture_window == root_window; |
368 } | 376 } |
369 #endif | 377 #endif |
370 | 378 |
371 return check_mouse_position && IsMouseHovered(); | 379 return check_mouse_position && IsMouseHovered(); |
372 } | 380 } |
373 | 381 |
| 382 void CustomButton::SetInkDropDelegate( |
| 383 scoped_ptr<InkDropDelegate> ink_drop_delegate) { |
| 384 ink_drop_delegate_ = ink_drop_delegate.Pass(); |
| 385 } |
| 386 |
374 //////////////////////////////////////////////////////////////////////////////// | 387 //////////////////////////////////////////////////////////////////////////////// |
375 // CustomButton, View overrides (protected): | 388 // CustomButton, View overrides (protected): |
376 | 389 |
| 390 void CustomButton::OnBoundsChanged(const gfx::Rect& previous_bounds) { |
| 391 if (ink_drop_delegate_) |
| 392 ink_drop_delegate_->OnLayout(); |
| 393 } |
| 394 |
377 void CustomButton::ViewHierarchyChanged( | 395 void CustomButton::ViewHierarchyChanged( |
378 const ViewHierarchyChangedDetails& details) { | 396 const ViewHierarchyChangedDetails& details) { |
379 if (!details.is_add && state_ != STATE_DISABLED) | 397 if (!details.is_add && state_ != STATE_DISABLED) |
380 SetState(STATE_NORMAL); | 398 SetState(STATE_NORMAL); |
381 } | 399 } |
382 | 400 |
383 void CustomButton::OnBlur() { | 401 void CustomButton::OnBlur() { |
384 if (IsHotTracked()) | 402 if (IsHotTracked()) |
385 SetState(STATE_NORMAL); | 403 SetState(STATE_NORMAL); |
386 } | 404 } |
387 | 405 |
388 bool CustomButton::IsChildWidget() const { | 406 bool CustomButton::IsChildWidget() const { |
389 return GetWidget() && GetWidget()->GetTopLevelWidget() != GetWidget(); | 407 return GetWidget() && GetWidget()->GetTopLevelWidget() != GetWidget(); |
390 } | 408 } |
391 | 409 |
392 bool CustomButton::FocusInChildWidget() const { | 410 bool CustomButton::FocusInChildWidget() const { |
393 return GetWidget() && | 411 return GetWidget() && |
394 GetWidget()->GetRootView()->Contains( | 412 GetWidget()->GetRootView()->Contains( |
395 GetFocusManager()->GetFocusedView()); | 413 GetFocusManager()->GetFocusedView()); |
396 } | 414 } |
397 | 415 |
398 } // namespace views | 416 } // namespace views |
OLD | NEW |