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" |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
125 // potentially destroyed InkDropHosts and remove |destroying_|. | 125 // potentially destroyed InkDropHosts and remove |destroying_|. |
126 destroying_ = true; | 126 destroying_ = true; |
127 } | 127 } |
128 | 128 |
129 void InkDropHostView::AddInkDropLayer(ui::Layer* ink_drop_layer) { | 129 void InkDropHostView::AddInkDropLayer(ui::Layer* ink_drop_layer) { |
130 old_paint_to_layer_ = layer() != nullptr; | 130 old_paint_to_layer_ = layer() != nullptr; |
131 if (!old_paint_to_layer_) | 131 if (!old_paint_to_layer_) |
132 SetPaintToLayer(); | 132 SetPaintToLayer(); |
133 | 133 |
134 layer()->SetFillsBoundsOpaquely(false); | 134 layer()->SetFillsBoundsOpaquely(false); |
135 ink_drop_mask_ = CreateInkDropMask(); | 135 InstallInkDropMask(ink_drop_layer); |
136 if (ink_drop_mask_) | |
137 ink_drop_layer->SetMaskLayer(ink_drop_mask_->layer()); | |
138 layer()->Add(ink_drop_layer); | 136 layer()->Add(ink_drop_layer); |
139 layer()->StackAtBottom(ink_drop_layer); | 137 layer()->StackAtBottom(ink_drop_layer); |
140 } | 138 } |
141 | 139 |
142 void InkDropHostView::RemoveInkDropLayer(ui::Layer* ink_drop_layer) { | 140 void InkDropHostView::RemoveInkDropLayer(ui::Layer* ink_drop_layer) { |
143 // No need to do anything when called during shutdown, and if a derived | 141 // No need to do anything when called during shutdown, and if a derived |
144 // class has overridden Add/RemoveInkDropLayer, running this implementation | 142 // class has overridden Add/RemoveInkDropLayer, running this implementation |
145 // would be wrong. | 143 // would be wrong. |
146 if (destroying_) | 144 if (destroying_) |
147 return; | 145 return; |
148 layer()->Remove(ink_drop_layer); | 146 layer()->Remove(ink_drop_layer); |
149 // Layers safely handle destroying a mask layer before the masked layer. | 147 // Layers safely handle destroying a mask layer before the masked layer. |
150 ink_drop_mask_.reset(); | 148 ink_drop_mask_.reset(); |
bruthig
2017/04/27 20:22:45
nit: Should this call ResetInkDropMask()?
Evan Stade
2017/04/27 20:27:49
I don't have a strong opinion but if I read that i
| |
151 if (!old_paint_to_layer_) | 149 if (!old_paint_to_layer_) |
152 DestroyLayer(); | 150 DestroyLayer(); |
153 } | 151 } |
154 | 152 |
155 std::unique_ptr<InkDrop> InkDropHostView::CreateInkDrop() { | 153 std::unique_ptr<InkDrop> InkDropHostView::CreateInkDrop() { |
156 return CreateDefaultInkDropImpl(); | 154 return CreateDefaultInkDropImpl(); |
157 } | 155 } |
158 | 156 |
159 std::unique_ptr<InkDropRipple> InkDropHostView::CreateInkDropRipple() const { | 157 std::unique_ptr<InkDropRipple> InkDropHostView::CreateInkDropRipple() const { |
160 return CreateDefaultInkDropRipple(GetLocalBounds().CenterPoint()); | 158 return CreateDefaultInkDropRipple(GetLocalBounds().CenterPoint()); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
273 InkDrop* InkDropHostView::GetInkDrop() { | 271 InkDrop* InkDropHostView::GetInkDrop() { |
274 if (!ink_drop_) { | 272 if (!ink_drop_) { |
275 if (ink_drop_mode_ == InkDropMode::OFF || !PlatformStyle::kUseRipples) | 273 if (ink_drop_mode_ == InkDropMode::OFF || !PlatformStyle::kUseRipples) |
276 ink_drop_ = base::MakeUnique<InkDropStub>(); | 274 ink_drop_ = base::MakeUnique<InkDropStub>(); |
277 else | 275 else |
278 ink_drop_ = CreateInkDrop(); | 276 ink_drop_ = CreateInkDrop(); |
279 } | 277 } |
280 return ink_drop_.get(); | 278 return ink_drop_.get(); |
281 } | 279 } |
282 | 280 |
281 void InkDropHostView::InstallInkDropMask(ui::Layer* ink_drop_layer) { | |
282 ink_drop_mask_ = CreateInkDropMask(); | |
283 if (ink_drop_mask_) | |
284 ink_drop_layer->SetMaskLayer(ink_drop_mask_->layer()); | |
285 } | |
286 | |
287 void InkDropHostView::ResetInkDropMask() { | |
288 ink_drop_mask_.reset(); | |
289 } | |
290 | |
283 std::unique_ptr<InkDropImpl> InkDropHostView::CreateDefaultInkDropImpl() { | 291 std::unique_ptr<InkDropImpl> InkDropHostView::CreateDefaultInkDropImpl() { |
284 std::unique_ptr<InkDropImpl> ink_drop = | 292 std::unique_ptr<InkDropImpl> ink_drop = |
285 base::MakeUnique<InkDropImpl>(this, size()); | 293 base::MakeUnique<InkDropImpl>(this, size()); |
286 ink_drop->SetAutoHighlightMode( | 294 ink_drop->SetAutoHighlightMode( |
287 views::InkDropImpl::AutoHighlightMode::HIDE_ON_RIPPLE); | 295 views::InkDropImpl::AutoHighlightMode::HIDE_ON_RIPPLE); |
288 return ink_drop; | 296 return ink_drop; |
289 } | 297 } |
290 | 298 |
291 std::unique_ptr<InkDropImpl> | 299 std::unique_ptr<InkDropImpl> |
292 InkDropHostView::CreateDefaultFloodFillInkDropImpl() { | 300 InkDropHostView::CreateDefaultFloodFillInkDropImpl() { |
293 std::unique_ptr<views::InkDropImpl> ink_drop = | 301 std::unique_ptr<views::InkDropImpl> ink_drop = |
294 InkDropHostView::CreateDefaultInkDropImpl(); | 302 InkDropHostView::CreateDefaultInkDropImpl(); |
295 ink_drop->SetAutoHighlightMode( | 303 ink_drop->SetAutoHighlightMode( |
296 views::InkDropImpl::AutoHighlightMode::SHOW_ON_RIPPLE); | 304 views::InkDropImpl::AutoHighlightMode::SHOW_ON_RIPPLE); |
297 return ink_drop; | 305 return ink_drop; |
298 } | 306 } |
299 | 307 |
300 } // namespace views | 308 } // namespace views |
OLD | NEW |