Chromium Code Reviews| 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 "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "ui/events/event.h" | 8 #include "ui/events/event.h" |
| 9 #include "ui/events/scoped_target_handler.h" | 9 #include "ui/events/scoped_target_handler.h" |
| 10 #include "ui/gfx/color_palette.h" | 10 #include "ui/gfx/color_palette.h" |
| 11 #include "ui/gfx/geometry/size_conversions.h" | 11 #include "ui/gfx/geometry/size_conversions.h" |
| 12 #include "ui/views/animation/ink_drop.h" | 12 #include "ui/views/animation/ink_drop.h" |
| 13 #include "ui/views/animation/ink_drop_highlight.h" | 13 #include "ui/views/animation/ink_drop_highlight.h" |
| 14 #include "ui/views/animation/ink_drop_impl.h" | 14 #include "ui/views/animation/ink_drop_impl.h" |
| 15 #include "ui/views/animation/ink_drop_mask.h" | 15 #include "ui/views/animation/ink_drop_mask.h" |
| 16 #include "ui/views/animation/ink_drop_stub.h" | 16 #include "ui/views/animation/ink_drop_stub.h" |
| 17 #include "ui/views/animation/square_ink_drop_ripple.h" | 17 #include "ui/views/animation/square_ink_drop_ripple.h" |
| 18 #include "ui/views/style/platform_style.h" | |
| 18 | 19 |
| 19 namespace views { | 20 namespace views { |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 // The scale factor to compute the large size of the default | 23 // The scale factor to compute the large size of the default |
| 23 // SquareInkDropRipple. | 24 // SquareInkDropRipple. |
| 24 const float kLargeInkDropScale = 1.333f; | 25 const float kLargeInkDropScale = 1.333f; |
| 25 | 26 |
| 26 // Default opacity of the ink drop when it is visible. | 27 // Default opacity of the ink drop when it is visible. |
| 27 const float kInkDropVisibleOpacity = 0.175f; | 28 const float kInkDropVisibleOpacity = 0.175f; |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 195 } | 196 } |
| 196 | 197 |
| 197 gfx::Point InkDropHostView::GetInkDropCenterBasedOnLastEvent() const { | 198 gfx::Point InkDropHostView::GetInkDropCenterBasedOnLastEvent() const { |
| 198 return last_ripple_triggering_event_ | 199 return last_ripple_triggering_event_ |
| 199 ? last_ripple_triggering_event_->location() | 200 ? last_ripple_triggering_event_->location() |
| 200 : GetLocalBounds().CenterPoint(); | 201 : GetLocalBounds().CenterPoint(); |
| 201 } | 202 } |
| 202 | 203 |
| 203 void InkDropHostView::AnimateInkDrop(InkDropState state, | 204 void InkDropHostView::AnimateInkDrop(InkDropState state, |
| 204 const ui::LocatedEvent* event) { | 205 const ui::LocatedEvent* event) { |
| 206 // On Mac, ink drops are never used: https://crbug.com/701888 | |
| 207 if (!PlatformStyle::kUseRipples) | |
| 208 return; | |
| 209 | |
| 205 #if defined(OS_WIN) | 210 #if defined(OS_WIN) |
| 206 // On Windows, don't initiate ink-drops for touch/gesture events. | 211 // On Windows, don't initiate ink-drops for touch/gesture events. |
| 207 // Additionally, certain event states should dismiss existing ink-drop | 212 // Additionally, certain event states should dismiss existing ink-drop |
| 208 // animations. If the state is already other than HIDDEN, presumably from | 213 // animations. If the state is already other than HIDDEN, presumably from |
| 209 // a mouse or keyboard event, then the state should be allowed. Conversely, | 214 // a mouse or keyboard event, then the state should be allowed. Conversely, |
| 210 // if the requested state is ACTIVATED, then it should always be allowed. | 215 // if the requested state is ACTIVATED, then it should always be allowed. |
| 211 if (event && (event->IsTouchEvent() || event->IsGestureEvent()) && | 216 if (event && (event->IsTouchEvent() || event->IsGestureEvent()) && |
| 212 GetInkDrop()->GetTargetInkDropState() == InkDropState::HIDDEN && | 217 GetInkDrop()->GetTargetInkDropState() == InkDropState::HIDDEN && |
| 213 state != InkDropState::ACTIVATED) | 218 state != InkDropState::ACTIVATED) |
| 214 return; | 219 return; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 265 return gfx::kPlaceholderColor; | 270 return gfx::kPlaceholderColor; |
| 266 } | 271 } |
| 267 | 272 |
| 268 std::unique_ptr<views::InkDropMask> InkDropHostView::CreateInkDropMask() const { | 273 std::unique_ptr<views::InkDropMask> InkDropHostView::CreateInkDropMask() const { |
| 269 return nullptr; | 274 return nullptr; |
| 270 } | 275 } |
| 271 | 276 |
| 272 InkDrop* InkDropHostView::GetInkDrop() { | 277 InkDrop* InkDropHostView::GetInkDrop() { |
| 273 if (!ink_drop_) { | 278 if (!ink_drop_) { |
| 274 if (ink_drop_mode_ == InkDropMode::OFF) | 279 if (ink_drop_mode_ == InkDropMode::OFF) |
| 275 ink_drop_ = base::MakeUnique<InkDropStub>(); | 280 ink_drop_ = base::MakeUnique<InkDropStub>(); |
|
bruthig
2017/04/21 20:30:08
I think it would be better if you returned an InkD
| |
| 276 else | 281 else |
| 277 ink_drop_ = CreateInkDrop(); | 282 ink_drop_ = CreateInkDrop(); |
| 278 } | 283 } |
| 279 return ink_drop_.get(); | 284 return ink_drop_.get(); |
| 280 } | 285 } |
| 281 | 286 |
| 282 std::unique_ptr<InkDropImpl> InkDropHostView::CreateDefaultInkDropImpl() { | 287 std::unique_ptr<InkDropImpl> InkDropHostView::CreateDefaultInkDropImpl() { |
| 283 std::unique_ptr<InkDropImpl> ink_drop = | 288 std::unique_ptr<InkDropImpl> ink_drop = |
| 284 base::MakeUnique<InkDropImpl>(this, size()); | 289 base::MakeUnique<InkDropImpl>(this, size()); |
| 285 ink_drop->SetAutoHighlightMode( | 290 ink_drop->SetAutoHighlightMode( |
| 286 views::InkDropImpl::AutoHighlightMode::HIDE_ON_RIPPLE); | 291 views::InkDropImpl::AutoHighlightMode::HIDE_ON_RIPPLE); |
| 287 return ink_drop; | 292 return ink_drop; |
| 288 } | 293 } |
| 289 | 294 |
| 290 std::unique_ptr<InkDropImpl> | 295 std::unique_ptr<InkDropImpl> |
| 291 InkDropHostView::CreateDefaultFloodFillInkDropImpl() { | 296 InkDropHostView::CreateDefaultFloodFillInkDropImpl() { |
| 292 std::unique_ptr<views::InkDropImpl> ink_drop = | 297 std::unique_ptr<views::InkDropImpl> ink_drop = |
| 293 InkDropHostView::CreateDefaultInkDropImpl(); | 298 InkDropHostView::CreateDefaultInkDropImpl(); |
| 294 ink_drop->SetAutoHighlightMode( | 299 ink_drop->SetAutoHighlightMode( |
| 295 views::InkDropImpl::AutoHighlightMode::SHOW_ON_RIPPLE); | 300 views::InkDropImpl::AutoHighlightMode::SHOW_ON_RIPPLE); |
| 296 return ink_drop; | 301 return ink_drop; |
| 297 } | 302 } |
| 298 | 303 |
| 299 } // namespace views | 304 } // namespace views |
| OLD | NEW |