Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ui/views/animation/toolbar_ink_drop_delegate.h" | |
| 6 | |
| 7 #include "ui/events/event.h" | |
| 8 #include "ui/events/scoped_target_handler.h" | |
| 9 #include "ui/views/animation/ink_drop_animation_controller.h" | |
| 10 #include "ui/views/animation/ink_drop_animation_controller_factory.h" | |
| 11 #include "ui/views/animation/ink_drop_host.h" | |
| 12 #include "ui/views/animation/ink_drop_state.h" | |
| 13 #include "ui/views/view.h" | |
| 14 | |
| 15 namespace views { | |
| 16 | |
| 17 ToolbarInkDropDelegate::ToolbarInkDropDelegate(InkDropHost* ink_drop_host, | |
| 18 ui::EventTarget* event_target) | |
| 19 : event_handler_(event_target), | |
|
bruthig
2015/11/19 16:49:53
|event_handler_| should not be needed. See commen
varkha
2015/11/19 23:34:35
Done.
| |
| 20 target_handler_(new ui::ScopedTargetHandler(event_target, this)), | |
| 21 ink_drop_host_(ink_drop_host), | |
| 22 ink_drop_animation_controller_( | |
| 23 InkDropAnimationControllerFactory:: | |
| 24 CreateInkDropAnimationController(ink_drop_host_)) {} | |
| 25 | |
| 26 ToolbarInkDropDelegate::~ToolbarInkDropDelegate() { | |
| 27 } | |
| 28 | |
| 29 void ToolbarInkDropDelegate::SetInkDropSize(int large_size, | |
| 30 int large_corner_radius, | |
| 31 int small_size, | |
| 32 int small_corner_radius) { | |
| 33 ink_drop_animation_controller_->SetInkDropSize( | |
| 34 gfx::Size(large_size, large_size), large_corner_radius, | |
| 35 gfx::Size(small_size, small_size), small_corner_radius); | |
| 36 } | |
| 37 | |
| 38 void ToolbarInkDropDelegate::OnLayout() { | |
| 39 ink_drop_animation_controller_->SetInkDropCenter( | |
| 40 ink_drop_host_->CalculateInkDropCenter()); | |
| 41 } | |
| 42 | |
| 43 void ToolbarInkDropDelegate::OnAction(InkDropState state) { | |
| 44 ink_drop_animation_controller_->AnimateToState(state); | |
| 45 } | |
| 46 | |
| 47 //////////////////////////////////////////////////////////////////////////////// | |
| 48 // ui::EventHandler: | |
| 49 | |
| 50 void ToolbarInkDropDelegate::OnEvent(ui::Event* event) { | |
| 51 // Dispatch to |event_handler_| first and then to |target_handler_|. | |
| 52 EventHandler::OnEvent(event); | |
| 53 if (target_handler_->original_target_handler()) | |
| 54 target_handler_->original_target_handler()->OnEvent(event); | |
| 55 } | |
| 56 | |
| 57 void ToolbarInkDropDelegate::OnKeyEvent(ui::KeyEvent* event) { | |
| 58 event_handler_->OnKeyEvent(event); | |
| 59 } | |
| 60 | |
| 61 void ToolbarInkDropDelegate::OnMouseEvent(ui::MouseEvent* event) { | |
| 62 event_handler_->OnMouseEvent(event); | |
| 63 } | |
| 64 | |
| 65 void ToolbarInkDropDelegate::OnScrollEvent(ui::ScrollEvent* event) { | |
| 66 event_handler_->OnScrollEvent(event); | |
| 67 } | |
| 68 | |
| 69 void ToolbarInkDropDelegate::OnTouchEvent(ui::TouchEvent* event) { | |
| 70 event_handler_->OnTouchEvent(event); | |
| 71 } | |
| 72 | |
| 73 void ToolbarInkDropDelegate::OnGestureEvent(ui::GestureEvent* event) { | |
| 74 event_handler_->OnGestureEvent(event); | |
| 75 | |
| 76 // TODO(varkha): Check if |this| has been deleted. | |
| 77 InkDropState ink_drop_state = InkDropState::HIDDEN; | |
| 78 switch (event->type()) { | |
| 79 case ui::ET_GESTURE_TAP_DOWN: | |
| 80 ink_drop_state = InkDropState::ACTION_PENDING; | |
| 81 // The ui::ET_GESTURE_TAP_DOWN event needs to be marked as handled so that | |
| 82 // subsequent events for the gesture are sent to |this|. | |
| 83 event->SetHandled(); | |
| 84 break; | |
| 85 case ui::ET_GESTURE_LONG_PRESS: | |
| 86 ink_drop_state = InkDropState::SLOW_ACTION_PENDING; | |
| 87 break; | |
| 88 case ui::ET_GESTURE_LONG_TAP: | |
| 89 ink_drop_state = InkDropState::SLOW_ACTION; | |
| 90 break; | |
| 91 case ui::ET_GESTURE_SCROLL_BEGIN: | |
| 92 case ui::ET_GESTURE_END: | |
| 93 ink_drop_state = InkDropState::HIDDEN; | |
| 94 break; | |
| 95 default: | |
| 96 return; | |
| 97 } | |
| 98 | |
| 99 InkDropState current_ink_drop_state = | |
| 100 ink_drop_animation_controller_->GetInkDropState(); | |
| 101 | |
| 102 if (ink_drop_state == InkDropState::HIDDEN && | |
| 103 (current_ink_drop_state == InkDropState::QUICK_ACTION || | |
| 104 current_ink_drop_state == InkDropState::SLOW_ACTION || | |
| 105 current_ink_drop_state == InkDropState::DEACTIVATED)) { | |
| 106 // These InkDropStates automatically transition to the HIDDEN state so we | |
| 107 // don't make an explicit call. Explicitly animating to HIDDEN in this case | |
| 108 // would prematurely pre-empt these animations. | |
| 109 return; | |
| 110 } | |
| 111 ink_drop_animation_controller_->AnimateToState(ink_drop_state); | |
| 112 } | |
| 113 | |
| 114 void ToolbarInkDropDelegate::OnCancelMode(ui::CancelModeEvent* event) { | |
| 115 event_handler_->OnCancelMode(event); | |
| 116 } | |
| 117 | |
| 118 } // namespace views | |
| OLD | NEW |