Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(392)

Side by Side Diff: ui/views/controls/button/custom_button.cc

Issue 1411833006: Refactoring to make adding ink drop animations easier (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Refactor ink drop animations (comments in ui/views/) Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
23 #include "ui/aura/window.h" 24 #include "ui/aura/window.h"
24 #endif 25 #endif
25 26
26 namespace views { 27 namespace views {
27 28
29 namespace {
30
31 // A stub InkDropDelegate implementation that always exists and does nothing.
32 // A real InkDropDelegate descendant can be returned by a View's descendant via
33 // GetInkDropDelegate().
34 class InkDropDelegateStub : public InkDropDelegate {
35 public:
36 InkDropDelegateStub() {}
37 ~InkDropDelegateStub() override {}
38
39 // InkDropDelegate:
40 void SetInkDropSize(int large_size,
41 int large_corner_radius,
42 int small_size,
43 int small_corner_radius) override {}
44 void OnBoundsChanged() override {}
45 void OnAction(InkDropState state) override {}
46
47 private:
48 DISALLOW_COPY_AND_ASSIGN(InkDropDelegateStub);
49 };
sadrul 2015/11/25 22:38:58 Still not a fan of this stub. I think we should st
varkha 2015/11/26 00:05:46 Done.
50
28 // How long the hover animation takes if uninterrupted. 51 // How long the hover animation takes if uninterrupted.
29 static const int kHoverFadeDurationMs = 150; 52 static const int kHoverFadeDurationMs = 150;
30 53
54 } // namespace
55
31 // static 56 // static
32 const char CustomButton::kViewClassName[] = "CustomButton"; 57 const char CustomButton::kViewClassName[] = "CustomButton";
33 58
34 //////////////////////////////////////////////////////////////////////////////// 59 ////////////////////////////////////////////////////////////////////////////////
35 // CustomButton, public: 60 // CustomButton, public:
36 61
37 // static 62 // static
38 const CustomButton* CustomButton::AsCustomButton(const views::View* view) { 63 const CustomButton* CustomButton::AsCustomButton(const views::View* view) {
39 return AsCustomButton(const_cast<views::View*>(view)); 64 return AsCustomButton(const_cast<views::View*>(view));
40 } 65 }
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 if (state_ != STATE_DISABLED) 302 if (state_ != STATE_DISABLED)
278 SetState(STATE_NORMAL); 303 SetState(STATE_NORMAL);
279 View::ShowContextMenu(p, source_type); 304 View::ShowContextMenu(p, source_type);
280 } 305 }
281 306
282 void CustomButton::OnDragDone() { 307 void CustomButton::OnDragDone() {
283 // Only reset the state to normal if the button isn't currently disabled 308 // Only reset the state to normal if the button isn't currently disabled
284 // (since disabled buttons may still be able to be dragged). 309 // (since disabled buttons may still be able to be dragged).
285 if (state_ != STATE_DISABLED) 310 if (state_ != STATE_DISABLED)
286 SetState(STATE_NORMAL); 311 SetState(STATE_NORMAL);
312 Button::OnDragDone();
sadrul 2015/11/25 22:38:58 Is this still needed?
varkha 2015/11/26 00:05:47 Done.
313 ink_drop_delegate_->OnAction(InkDropState::HIDDEN);
287 } 314 }
288 315
289 void CustomButton::GetAccessibleState(ui::AXViewState* state) { 316 void CustomButton::GetAccessibleState(ui::AXViewState* state) {
290 Button::GetAccessibleState(state); 317 Button::GetAccessibleState(state);
291 switch (state_) { 318 switch (state_) {
292 case STATE_HOVERED: 319 case STATE_HOVERED:
293 state->AddStateFlag(ui::AX_STATE_HOVERED); 320 state->AddStateFlag(ui::AX_STATE_HOVERED);
294 break; 321 break;
295 case STATE_PRESSED: 322 case STATE_PRESSED:
296 state->AddStateFlag(ui::AX_STATE_PRESSED); 323 state->AddStateFlag(ui::AX_STATE_PRESSED);
(...skipping 20 matching lines...) Expand all
317 void CustomButton::AnimationProgressed(const gfx::Animation* animation) { 344 void CustomButton::AnimationProgressed(const gfx::Animation* animation) {
318 SchedulePaint(); 345 SchedulePaint();
319 } 346 }
320 347
321 //////////////////////////////////////////////////////////////////////////////// 348 ////////////////////////////////////////////////////////////////////////////////
322 // CustomButton, protected: 349 // CustomButton, protected:
323 350
324 CustomButton::CustomButton(ButtonListener* listener) 351 CustomButton::CustomButton(ButtonListener* listener)
325 : Button(listener), 352 : Button(listener),
326 state_(STATE_NORMAL), 353 state_(STATE_NORMAL),
354 ink_drop_delegate_(new InkDropDelegateStub),
327 animate_on_state_change_(true), 355 animate_on_state_change_(true),
328 is_throbbing_(false), 356 is_throbbing_(false),
329 triggerable_event_flags_(ui::EF_LEFT_MOUSE_BUTTON), 357 triggerable_event_flags_(ui::EF_LEFT_MOUSE_BUTTON),
330 request_focus_on_press_(true), 358 request_focus_on_press_(true),
331 notify_action_(NOTIFY_ON_RELEASE) { 359 notify_action_(NOTIFY_ON_RELEASE) {
332 hover_animation_.reset(new gfx::ThrobAnimation(this)); 360 hover_animation_.reset(new gfx::ThrobAnimation(this));
333 hover_animation_->SetSlideDuration(kHoverFadeDurationMs); 361 hover_animation_->SetSlideDuration(kHoverFadeDurationMs);
334 } 362 }
335 363
336 void CustomButton::StateChanged() { 364 void CustomButton::StateChanged() {
(...skipping 30 matching lines...) Expand all
367 check_mouse_position = !capture_window || capture_window == root_window; 395 check_mouse_position = !capture_window || capture_window == root_window;
368 } 396 }
369 #endif 397 #endif
370 398
371 return check_mouse_position && IsMouseHovered(); 399 return check_mouse_position && IsMouseHovered();
372 } 400 }
373 401
374 //////////////////////////////////////////////////////////////////////////////// 402 ////////////////////////////////////////////////////////////////////////////////
375 // CustomButton, View overrides (protected): 403 // CustomButton, View overrides (protected):
376 404
405 void CustomButton::OnBoundsChanged(const gfx::Rect& previous_bounds) {
406 ink_drop_delegate_->OnBoundsChanged();
407 }
408
377 void CustomButton::ViewHierarchyChanged( 409 void CustomButton::ViewHierarchyChanged(
378 const ViewHierarchyChangedDetails& details) { 410 const ViewHierarchyChangedDetails& details) {
379 if (!details.is_add && state_ != STATE_DISABLED) 411 if (!details.is_add && state_ != STATE_DISABLED)
380 SetState(STATE_NORMAL); 412 SetState(STATE_NORMAL);
381 } 413 }
382 414
383 void CustomButton::OnBlur() { 415 void CustomButton::OnBlur() {
384 if (IsHotTracked()) 416 if (IsHotTracked())
385 SetState(STATE_NORMAL); 417 SetState(STATE_NORMAL);
386 } 418 }
387 419
388 bool CustomButton::IsChildWidget() const { 420 bool CustomButton::IsChildWidget() const {
389 return GetWidget() && GetWidget()->GetTopLevelWidget() != GetWidget(); 421 return GetWidget() && GetWidget()->GetTopLevelWidget() != GetWidget();
390 } 422 }
391 423
392 bool CustomButton::FocusInChildWidget() const { 424 bool CustomButton::FocusInChildWidget() const {
393 return GetWidget() && 425 return GetWidget() &&
394 GetWidget()->GetRootView()->Contains( 426 GetWidget()->GetRootView()->Contains(
395 GetFocusManager()->GetFocusedView()); 427 GetFocusManager()->GetFocusedView());
396 } 428 }
397 429
398 } // namespace views 430 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698