OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/animation/ink_drop_host_view.h" | 5 #include "ui/views/animation/ink_drop_host_view.h" |
6 | 6 |
7 #include "ui/events/event.h" | 7 #include "ui/events/event.h" |
8 #include "ui/events/scoped_target_handler.h" | 8 #include "ui/events/scoped_target_handler.h" |
9 #include "ui/gfx/color_palette.h" | 9 #include "ui/gfx/color_palette.h" |
10 #include "ui/gfx/geometry/size_conversions.h" | 10 #include "ui/gfx/geometry/size_conversions.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 // static | 34 // static |
35 const int InkDropHostView::kInkDropSmallCornerRadius = 2; | 35 const int InkDropHostView::kInkDropSmallCornerRadius = 2; |
36 | 36 |
37 // An EventHandler that is guaranteed to be invoked and is not prone to | 37 // An EventHandler that is guaranteed to be invoked and is not prone to |
38 // InkDropHostView descendents who do not call | 38 // InkDropHostView descendents who do not call |
39 // InkDropHostView::OnGestureEvent(). | 39 // InkDropHostView::OnGestureEvent(). |
40 // | 40 // |
41 // TODO(bruthig): Consider getting rid of this class. | 41 // TODO(bruthig): Consider getting rid of this class. |
42 class InkDropHostView::InkDropGestureHandler : public ui::EventHandler { | 42 class InkDropHostView::InkDropGestureHandler : public ui::EventHandler { |
43 public: | 43 public: |
44 InkDropGestureHandler(View* view, InkDrop* ink_drop) | 44 InkDropGestureHandler(InkDropHostView* host_view, InkDrop* ink_drop) |
45 : ink_drop_(ink_drop), target_handler_(view, this) {} | 45 : target_handler_(new ui::ScopedTargetHandler(host_view, this)), |
| 46 host_view_(host_view), |
| 47 ink_drop_(ink_drop) {} |
46 | 48 |
47 ~InkDropGestureHandler() override {} | 49 ~InkDropGestureHandler() override {} |
48 | 50 |
49 // ui::EventHandler: | 51 // ui::EventHandler: |
50 void OnGestureEvent(ui::GestureEvent* event) override { | 52 void OnGestureEvent(ui::GestureEvent* event) override { |
51 InkDropState current_ink_drop_state = ink_drop_->GetTargetInkDropState(); | 53 InkDropState current_ink_drop_state = ink_drop_->GetTargetInkDropState(); |
52 | 54 |
53 InkDropState ink_drop_state = InkDropState::HIDDEN; | 55 InkDropState ink_drop_state = InkDropState::HIDDEN; |
54 switch (event->type()) { | 56 switch (event->type()) { |
55 case ui::ET_GESTURE_TAP_DOWN: | 57 case ui::ET_GESTURE_TAP_DOWN: |
(...skipping 22 matching lines...) Expand all Loading... |
78 | 80 |
79 if (ink_drop_state == InkDropState::HIDDEN && | 81 if (ink_drop_state == InkDropState::HIDDEN && |
80 (current_ink_drop_state == InkDropState::ACTION_TRIGGERED || | 82 (current_ink_drop_state == InkDropState::ACTION_TRIGGERED || |
81 current_ink_drop_state == InkDropState::ALTERNATE_ACTION_TRIGGERED || | 83 current_ink_drop_state == InkDropState::ALTERNATE_ACTION_TRIGGERED || |
82 current_ink_drop_state == InkDropState::DEACTIVATED)) { | 84 current_ink_drop_state == InkDropState::DEACTIVATED)) { |
83 // These InkDropStates automatically transition to the HIDDEN state so we | 85 // These InkDropStates automatically transition to the HIDDEN state so we |
84 // don't make an explicit call. Explicitly animating to HIDDEN in this | 86 // don't make an explicit call. Explicitly animating to HIDDEN in this |
85 // case would prematurely pre-empt these animations. | 87 // case would prematurely pre-empt these animations. |
86 return; | 88 return; |
87 } | 89 } |
88 ink_drop_->AnimateToState(ink_drop_state); | 90 host_view_->AnimateInkDrop(ink_drop_state, event); |
89 } | 91 } |
90 | 92 |
91 private: | 93 private: |
| 94 // Allows |this| to handle all GestureEvents on |host_view_|. |
| 95 std::unique_ptr<ui::ScopedTargetHandler> target_handler_; |
| 96 |
| 97 // The host view to cache ui::Events to when animating the ink drop. |
| 98 InkDropHostView* host_view_; |
| 99 |
92 // Animation controller for the ink drop ripple effect. | 100 // Animation controller for the ink drop ripple effect. |
93 InkDrop* ink_drop_; | 101 InkDrop* ink_drop_; |
94 | 102 |
95 // An instance of ScopedTargetHandler allowing |this| to handle events. | |
96 ui::ScopedTargetHandler target_handler_; | |
97 | |
98 DISALLOW_COPY_AND_ASSIGN(InkDropGestureHandler); | 103 DISALLOW_COPY_AND_ASSIGN(InkDropGestureHandler); |
99 }; | 104 }; |
100 | 105 |
101 InkDropHostView::InkDropHostView() | 106 InkDropHostView::InkDropHostView() |
102 : ink_drop_(new InkDropStub()), | 107 : ink_drop_(new InkDropStub()), |
103 ink_drop_size_(kInkDropSize, kInkDropSize), | 108 ink_drop_size_(kInkDropSize, kInkDropSize), |
104 old_paint_to_layer_(false), | 109 old_paint_to_layer_(false), |
105 destroying_(false) {} | 110 destroying_(false) {} |
106 | 111 |
107 InkDropHostView::~InkDropHostView() { | 112 InkDropHostView::~InkDropHostView() { |
(...skipping 14 matching lines...) Expand all Loading... |
122 // No need to do anything when called during shutdown, and if a derived | 127 // No need to do anything when called during shutdown, and if a derived |
123 // class has overridden Add/RemoveInkDropLayer, running this implementation | 128 // class has overridden Add/RemoveInkDropLayer, running this implementation |
124 // would be wrong. | 129 // would be wrong. |
125 if (destroying_) | 130 if (destroying_) |
126 return; | 131 return; |
127 layer()->Remove(ink_drop_layer); | 132 layer()->Remove(ink_drop_layer); |
128 SetPaintToLayer(old_paint_to_layer_); | 133 SetPaintToLayer(old_paint_to_layer_); |
129 } | 134 } |
130 | 135 |
131 std::unique_ptr<InkDropRipple> InkDropHostView::CreateInkDropRipple() const { | 136 std::unique_ptr<InkDropRipple> InkDropHostView::CreateInkDropRipple() const { |
| 137 return CreateDefaultInkDropRipple(GetLocalBounds().CenterPoint()); |
| 138 } |
| 139 |
| 140 std::unique_ptr<InkDropHighlight> InkDropHostView::CreateInkDropHighlight() |
| 141 const { |
| 142 return CreateDefaultInkDropHighlight(GetLocalBounds().CenterPoint()); |
| 143 } |
| 144 |
| 145 std::unique_ptr<InkDropRipple> InkDropHostView::CreateDefaultInkDropRipple( |
| 146 const gfx::Point& center_point) const { |
132 std::unique_ptr<InkDropRipple> ripple(new SquareInkDropRipple( | 147 std::unique_ptr<InkDropRipple> ripple(new SquareInkDropRipple( |
133 CalculateLargeInkDropSize(ink_drop_size_), kInkDropLargeCornerRadius, | 148 CalculateLargeInkDropSize(ink_drop_size_), kInkDropLargeCornerRadius, |
134 ink_drop_size_, kInkDropSmallCornerRadius, GetInkDropCenter(), | 149 ink_drop_size_, kInkDropSmallCornerRadius, center_point, |
135 GetInkDropBaseColor())); | 150 GetInkDropBaseColor())); |
136 return ripple; | 151 return ripple; |
137 } | 152 } |
138 | 153 |
139 std::unique_ptr<InkDropHighlight> InkDropHostView::CreateInkDropHighlight() | 154 std::unique_ptr<InkDropHighlight> |
140 const { | 155 InkDropHostView::CreateDefaultInkDropHighlight( |
| 156 const gfx::Point& center_point) const { |
141 std::unique_ptr<InkDropHighlight> highlight( | 157 std::unique_ptr<InkDropHighlight> highlight( |
142 new InkDropHighlight(ink_drop_size_, kInkDropSmallCornerRadius, | 158 new InkDropHighlight(ink_drop_size_, kInkDropSmallCornerRadius, |
143 GetInkDropCenter(), GetInkDropBaseColor())); | 159 center_point, GetInkDropBaseColor())); |
144 highlight->set_explode_size(CalculateLargeInkDropSize(ink_drop_size_)); | 160 highlight->set_explode_size(CalculateLargeInkDropSize(ink_drop_size_)); |
145 return highlight; | 161 return highlight; |
146 } | 162 } |
147 | 163 |
| 164 gfx::Point InkDropHostView::GetInkDropCenterBasedOnLastEvent() const { |
| 165 return last_ripple_triggering_event_ |
| 166 ? last_ripple_triggering_event_->location() |
| 167 : GetLocalBounds().CenterPoint(); |
| 168 } |
| 169 |
| 170 void InkDropHostView::AnimateInkDrop(InkDropState state, |
| 171 const ui::LocatedEvent* event) { |
| 172 last_ripple_triggering_event_.reset( |
| 173 event ? ui::Event::Clone(*event).release()->AsLocatedEvent() : nullptr); |
| 174 ink_drop_->AnimateToState(state); |
| 175 } |
| 176 |
148 void InkDropHostView::VisibilityChanged(View* starting_from, bool is_visible) { | 177 void InkDropHostView::VisibilityChanged(View* starting_from, bool is_visible) { |
149 View::VisibilityChanged(starting_from, is_visible); | 178 View::VisibilityChanged(starting_from, is_visible); |
150 if (GetWidget() && !is_visible) { | 179 if (GetWidget() && !is_visible) { |
151 ink_drop()->AnimateToState(InkDropState::HIDDEN); | 180 ink_drop()->AnimateToState(InkDropState::HIDDEN); |
152 ink_drop()->SetHovered(false); | 181 ink_drop()->SetHovered(false); |
153 } | 182 } |
154 } | 183 } |
155 | 184 |
156 void InkDropHostView::OnFocus() { | 185 void InkDropHostView::OnFocus() { |
157 views::View::OnFocus(); | 186 views::View::OnFocus(); |
(...skipping 14 matching lines...) Expand all Loading... |
172 break; | 201 break; |
173 case ui::ET_MOUSE_EXITED: | 202 case ui::ET_MOUSE_EXITED: |
174 ink_drop_->SetHovered(false); | 203 ink_drop_->SetHovered(false); |
175 break; | 204 break; |
176 default: | 205 default: |
177 break; | 206 break; |
178 } | 207 } |
179 View::OnMouseEvent(event); | 208 View::OnMouseEvent(event); |
180 } | 209 } |
181 | 210 |
182 gfx::Point InkDropHostView::GetInkDropCenter() const { | |
183 return GetLocalBounds().CenterPoint(); | |
184 } | |
185 | |
186 SkColor InkDropHostView::GetInkDropBaseColor() const { | 211 SkColor InkDropHostView::GetInkDropBaseColor() const { |
187 NOTREACHED(); | 212 NOTREACHED(); |
188 return gfx::kPlaceholderColor; | 213 return gfx::kPlaceholderColor; |
189 } | 214 } |
190 | 215 |
191 bool InkDropHostView::ShouldShowInkDropForFocus() const { | 216 bool InkDropHostView::ShouldShowInkDropForFocus() const { |
192 return false; | 217 return false; |
193 } | 218 } |
194 | 219 |
195 void InkDropHostView::SetHasInkDrop(bool has_an_ink_drop) { | 220 void InkDropHostView::SetHasInkDrop(bool has_an_ink_drop) { |
196 if (has_an_ink_drop) { | 221 if (has_an_ink_drop) { |
197 ink_drop_.reset(new InkDropImpl(this)); | 222 ink_drop_.reset(new InkDropImpl(this)); |
198 gesture_handler_.reset(new InkDropGestureHandler(this, ink_drop_.get())); | 223 gesture_handler_.reset(new InkDropGestureHandler(this, ink_drop_.get())); |
199 } else { | 224 } else { |
200 gesture_handler_.reset(); | 225 gesture_handler_.reset(); |
201 ink_drop_.reset(new InkDropStub()); | 226 ink_drop_.reset(new InkDropStub()); |
202 } | 227 } |
203 } | 228 } |
204 | 229 |
205 void InkDropHostView::AnimateInkDrop(InkDropState ink_drop_state) { | |
206 ink_drop_->AnimateToState(ink_drop_state); | |
207 } | |
208 | |
209 } // namespace views | 230 } // namespace views |
OLD | NEW |