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_stub.h" | 16 #include "ui/views/animation/ink_drop_stub.h" |
| 16 #include "ui/views/animation/square_ink_drop_ripple.h" | 17 #include "ui/views/animation/square_ink_drop_ripple.h" |
| 17 | 18 |
| 18 namespace views { | 19 namespace views { |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 // Size used for the default SquareInkDropRipple. | 22 // Size used for the default SquareInkDropRipple. |
| 22 const int kInkDropSize = 24; | 23 const int kInkDropSize = 24; |
| 23 | 24 |
| 24 // The scale factor to compute the large size of the default | 25 // The scale factor to compute the large size of the default |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 121 InkDropHostView::~InkDropHostView() { | 122 InkDropHostView::~InkDropHostView() { |
| 122 // TODO(bruthig): Improve InkDropImpl to be safer about calling back to | 123 // TODO(bruthig): Improve InkDropImpl to be safer about calling back to |
| 123 // potentially destroyed InkDropHosts and remove |destroying_|. | 124 // potentially destroyed InkDropHosts and remove |destroying_|. |
| 124 destroying_ = true; | 125 destroying_ = true; |
| 125 } | 126 } |
| 126 | 127 |
| 127 void InkDropHostView::AddInkDropLayer(ui::Layer* ink_drop_layer) { | 128 void InkDropHostView::AddInkDropLayer(ui::Layer* ink_drop_layer) { |
| 128 old_paint_to_layer_ = layer() != nullptr; | 129 old_paint_to_layer_ = layer() != nullptr; |
| 129 SetPaintToLayer(true); | 130 SetPaintToLayer(true); |
| 130 layer()->SetFillsBoundsOpaquely(false); | 131 layer()->SetFillsBoundsOpaquely(false); |
| 132 ink_drop_mask_ = CreateInkDropMask(); | |
| 133 if (ink_drop_mask_) | |
| 134 ink_drop_layer->SetMaskLayer(ink_drop_mask_->layer()); | |
| 131 layer()->Add(ink_drop_layer); | 135 layer()->Add(ink_drop_layer); |
| 132 layer()->StackAtBottom(ink_drop_layer); | 136 layer()->StackAtBottom(ink_drop_layer); |
| 133 } | 137 } |
| 134 | 138 |
| 135 void InkDropHostView::RemoveInkDropLayer(ui::Layer* ink_drop_layer) { | 139 void InkDropHostView::RemoveInkDropLayer(ui::Layer* ink_drop_layer) { |
| 136 // No need to do anything when called during shutdown, and if a derived | 140 // No need to do anything when called during shutdown, and if a derived |
| 137 // class has overridden Add/RemoveInkDropLayer, running this implementation | 141 // class has overridden Add/RemoveInkDropLayer, running this implementation |
| 138 // would be wrong. | 142 // would be wrong. |
| 139 if (destroying_) | 143 if (destroying_) |
| 140 return; | 144 return; |
| 141 layer()->Remove(ink_drop_layer); | 145 layer()->Remove(ink_drop_layer); |
| 146 ink_drop_layer->SetMaskLayer(nullptr); | |
| 147 ink_drop_mask_.reset(); | |
| 142 SetPaintToLayer(old_paint_to_layer_); | 148 SetPaintToLayer(old_paint_to_layer_); |
| 143 } | 149 } |
| 144 | 150 |
| 145 std::unique_ptr<InkDrop> InkDropHostView::CreateInkDrop() { | 151 std::unique_ptr<InkDrop> InkDropHostView::CreateInkDrop() { |
| 146 return CreateDefaultInkDropImpl(); | 152 return CreateDefaultInkDropImpl(); |
| 147 } | 153 } |
| 148 | 154 |
| 149 std::unique_ptr<InkDropRipple> InkDropHostView::CreateInkDropRipple() const { | 155 std::unique_ptr<InkDropRipple> InkDropHostView::CreateInkDropRipple() const { |
| 150 return CreateDefaultInkDropRipple(GetLocalBounds().CenterPoint()); | 156 return CreateDefaultInkDropRipple(GetLocalBounds().CenterPoint()); |
| 151 } | 157 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 204 if (event && (event->IsTouchEvent() || event->IsGestureEvent()) && | 210 if (event && (event->IsTouchEvent() || event->IsGestureEvent()) && |
| 205 GetInkDrop()->GetTargetInkDropState() == InkDropState::HIDDEN && | 211 GetInkDrop()->GetTargetInkDropState() == InkDropState::HIDDEN && |
| 206 state != InkDropState::ACTIVATED) | 212 state != InkDropState::ACTIVATED) |
| 207 return; | 213 return; |
| 208 #endif | 214 #endif |
| 209 last_ripple_triggering_event_.reset( | 215 last_ripple_triggering_event_.reset( |
| 210 event ? ui::Event::Clone(*event).release()->AsLocatedEvent() : nullptr); | 216 event ? ui::Event::Clone(*event).release()->AsLocatedEvent() : nullptr); |
| 211 GetInkDrop()->AnimateToState(state); | 217 GetInkDrop()->AnimateToState(state); |
| 212 } | 218 } |
| 213 | 219 |
| 220 void InkDropHostView::OnBoundsChanged(const gfx::Rect& previous_bounds) { | |
| 221 if (ink_drop_) | |
| 222 ink_drop_->HostSizeChanged(size()); | |
|
bruthig
2016/11/14 21:07:41
Should we be re-creating/applying the mask here to
bruthig
2016/11/14 21:45:41
Discussed offline, my request is not needed until
| |
| 223 } | |
| 224 | |
| 214 void InkDropHostView::VisibilityChanged(View* starting_from, bool is_visible) { | 225 void InkDropHostView::VisibilityChanged(View* starting_from, bool is_visible) { |
| 215 View::VisibilityChanged(starting_from, is_visible); | 226 View::VisibilityChanged(starting_from, is_visible); |
| 216 if (GetWidget() && !is_visible) { | 227 if (GetWidget() && !is_visible) { |
| 217 GetInkDrop()->AnimateToState(InkDropState::HIDDEN); | 228 GetInkDrop()->AnimateToState(InkDropState::HIDDEN); |
| 218 GetInkDrop()->SetHovered(false); | 229 GetInkDrop()->SetHovered(false); |
| 219 } | 230 } |
| 220 } | 231 } |
| 221 | 232 |
| 222 void InkDropHostView::OnFocus() { | 233 void InkDropHostView::OnFocus() { |
| 223 views::View::OnFocus(); | 234 views::View::OnFocus(); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 244 break; | 255 break; |
| 245 } | 256 } |
| 246 View::OnMouseEvent(event); | 257 View::OnMouseEvent(event); |
| 247 } | 258 } |
| 248 | 259 |
| 249 SkColor InkDropHostView::GetInkDropBaseColor() const { | 260 SkColor InkDropHostView::GetInkDropBaseColor() const { |
| 250 NOTREACHED(); | 261 NOTREACHED(); |
| 251 return gfx::kPlaceholderColor; | 262 return gfx::kPlaceholderColor; |
| 252 } | 263 } |
| 253 | 264 |
| 265 std::unique_ptr<views::InkDropMask> InkDropHostView::CreateInkDropMask() const { | |
| 266 return nullptr; | |
| 267 } | |
| 268 | |
| 254 InkDrop* InkDropHostView::GetInkDrop() { | 269 InkDrop* InkDropHostView::GetInkDrop() { |
| 255 if (!ink_drop_) { | 270 if (!ink_drop_) { |
| 256 if (ink_drop_mode_ == InkDropMode::OFF) | 271 if (ink_drop_mode_ == InkDropMode::OFF) |
| 257 ink_drop_ = base::MakeUnique<InkDropStub>(); | 272 ink_drop_ = base::MakeUnique<InkDropStub>(); |
| 258 else | 273 else |
| 259 ink_drop_ = CreateInkDrop(); | 274 ink_drop_ = CreateInkDrop(); |
| 260 } | 275 } |
| 261 return ink_drop_.get(); | 276 return ink_drop_.get(); |
| 262 } | 277 } |
| 263 | 278 |
| 264 std::unique_ptr<InkDropImpl> InkDropHostView::CreateDefaultInkDropImpl() { | 279 std::unique_ptr<InkDropImpl> InkDropHostView::CreateDefaultInkDropImpl() { |
| 265 std::unique_ptr<InkDropImpl> ink_drop = base::MakeUnique<InkDropImpl>(this); | 280 std::unique_ptr<InkDropImpl> ink_drop = |
| 281 base::MakeUnique<InkDropImpl>(this, size()); | |
| 266 ink_drop->SetAutoHighlightMode( | 282 ink_drop->SetAutoHighlightMode( |
| 267 views::InkDropImpl::AutoHighlightMode::HIDE_ON_RIPPLE); | 283 views::InkDropImpl::AutoHighlightMode::HIDE_ON_RIPPLE); |
| 268 return ink_drop; | 284 return ink_drop; |
| 269 } | 285 } |
| 270 | 286 |
| 271 std::unique_ptr<InkDropImpl> | 287 std::unique_ptr<InkDropImpl> |
| 272 InkDropHostView::CreateDefaultFloodFillInkDropImpl() { | 288 InkDropHostView::CreateDefaultFloodFillInkDropImpl() { |
| 273 std::unique_ptr<views::InkDropImpl> ink_drop = | 289 std::unique_ptr<views::InkDropImpl> ink_drop = |
| 274 InkDropHostView::CreateDefaultInkDropImpl(); | 290 InkDropHostView::CreateDefaultInkDropImpl(); |
| 275 ink_drop->SetAutoHighlightMode( | 291 ink_drop->SetAutoHighlightMode( |
| 276 views::InkDropImpl::AutoHighlightMode::SHOW_ON_RIPPLE); | 292 views::InkDropImpl::AutoHighlightMode::SHOW_ON_RIPPLE); |
| 277 return ink_drop; | 293 return ink_drop; |
| 278 } | 294 } |
| 279 | 295 |
| 280 } // namespace views | 296 } // namespace views |
| OLD | NEW |