Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(125)

Side by Side Diff: ui/views/animation/ink_drop_host_view.cc

Issue 2396133005: [ash-md] Animates ToggleButton highlight to move it in sync with the thumb (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 std::unique_ptr<ui::ScopedTargetHandler> target_handler_; 101 std::unique_ptr<ui::ScopedTargetHandler> target_handler_;
102 102
103 // The host view to cache ui::Events to when animating the ink drop. 103 // The host view to cache ui::Events to when animating the ink drop.
104 InkDropHostView* host_view_; 104 InkDropHostView* host_view_;
105 105
106 DISALLOW_COPY_AND_ASSIGN(InkDropGestureHandler); 106 DISALLOW_COPY_AND_ASSIGN(InkDropGestureHandler);
107 }; 107 };
108 108
109 InkDropHostView::InkDropHostView() 109 InkDropHostView::InkDropHostView()
110 : ink_drop_(new InkDropStub()), 110 : ink_drop_(new InkDropStub()),
111 ink_drop_layer_(nullptr),
111 ink_drop_size_(kInkDropSize, kInkDropSize), 112 ink_drop_size_(kInkDropSize, kInkDropSize),
112 ink_drop_visible_opacity_(kInkDropVisibleOpacity), 113 ink_drop_visible_opacity_(kInkDropVisibleOpacity),
113 old_paint_to_layer_(false), 114 old_paint_to_layer_(false),
114 destroying_(false) {} 115 destroying_(false) {}
115 116
116 InkDropHostView::~InkDropHostView() { 117 InkDropHostView::~InkDropHostView() {
117 // TODO(bruthig): Improve InkDropImpl to be safer about calling back to 118 // TODO(bruthig): Improve InkDropImpl to be safer about calling back to
118 // potentially destroyed InkDropHosts and remove |destroying_|. 119 // potentially destroyed InkDropHosts and remove |destroying_|.
119 destroying_ = true; 120 destroying_ = true;
120 } 121 }
121 122
122 void InkDropHostView::AddInkDropLayer(ui::Layer* ink_drop_layer) { 123 void InkDropHostView::AddInkDropLayer(ui::Layer* ink_drop_layer) {
123 old_paint_to_layer_ = layer() != nullptr; 124 old_paint_to_layer_ = layer() != nullptr;
124 SetPaintToLayer(true); 125 SetPaintToLayer(true);
125 layer()->SetFillsBoundsOpaquely(false); 126 layer()->SetFillsBoundsOpaquely(false);
126 layer()->Add(ink_drop_layer); 127 layer()->Add(ink_drop_layer);
127 layer()->StackAtBottom(ink_drop_layer); 128 layer()->StackAtBottom(ink_drop_layer);
129 ink_drop_layer_ = ink_drop_layer;
128 } 130 }
129 131
130 void InkDropHostView::RemoveInkDropLayer(ui::Layer* ink_drop_layer) { 132 void InkDropHostView::RemoveInkDropLayer(ui::Layer* ink_drop_layer) {
131 // No need to do anything when called during shutdown, and if a derived 133 // No need to do anything when called during shutdown, and if a derived
132 // class has overridden Add/RemoveInkDropLayer, running this implementation 134 // class has overridden Add/RemoveInkDropLayer, running this implementation
133 // would be wrong. 135 // would be wrong.
134 if (destroying_) 136 if (destroying_)
135 return; 137 return;
138 DCHECK_EQ(ink_drop_layer_, ink_drop_layer);
139 ink_drop_layer_ = nullptr;
136 layer()->Remove(ink_drop_layer); 140 layer()->Remove(ink_drop_layer);
137 SetPaintToLayer(old_paint_to_layer_); 141 SetPaintToLayer(old_paint_to_layer_);
138 } 142 }
139 143
140 std::unique_ptr<InkDropRipple> InkDropHostView::CreateInkDropRipple() const { 144 std::unique_ptr<InkDropRipple> InkDropHostView::CreateInkDropRipple() const {
141 return CreateDefaultInkDropRipple(GetLocalBounds().CenterPoint()); 145 return CreateDefaultInkDropRipple(GetLocalBounds().CenterPoint());
142 } 146 }
143 147
144 std::unique_ptr<InkDropHighlight> InkDropHostView::CreateInkDropHighlight() 148 std::unique_ptr<InkDropHighlight> InkDropHostView::CreateInkDropHighlight()
145 const { 149 const {
146 return CreateDefaultInkDropHighlight( 150 return CreateDefaultInkDropHighlight(
147 gfx::RectF(GetLocalBounds()).CenterPoint()); 151 gfx::RectF(GetLocalBounds()).CenterPoint());
148 } 152 }
149 153
154 void InkDropHostView::OffsetInkDropRipple(const gfx::Vector2d& offset) {
155 if (!ink_drop_layer_)
156 return;
157 gfx::Transform transform;
158 transform.Translate(offset.x(), offset.y());
159 ink_drop_layer_->SetTransform(transform);
160 }
161
150 std::unique_ptr<InkDropRipple> InkDropHostView::CreateDefaultInkDropRipple( 162 std::unique_ptr<InkDropRipple> InkDropHostView::CreateDefaultInkDropRipple(
151 const gfx::Point& center_point) const { 163 const gfx::Point& center_point) const {
152 std::unique_ptr<InkDropRipple> ripple(new SquareInkDropRipple( 164 std::unique_ptr<InkDropRipple> ripple(new SquareInkDropRipple(
153 CalculateLargeInkDropSize(ink_drop_size_), kInkDropLargeCornerRadius, 165 CalculateLargeInkDropSize(ink_drop_size_), kInkDropLargeCornerRadius,
154 ink_drop_size_, kInkDropSmallCornerRadius, center_point, 166 ink_drop_size_, kInkDropSmallCornerRadius, center_point,
155 GetInkDropBaseColor(), ink_drop_visible_opacity())); 167 GetInkDropBaseColor(), ink_drop_visible_opacity()));
156 return ripple; 168 return ripple;
157 } 169 }
158 170
159 std::unique_ptr<InkDropHighlight> 171 std::unique_ptr<InkDropHighlight>
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 else 251 else
240 ink_drop_.reset(new InkDropImpl(this)); 252 ink_drop_.reset(new InkDropImpl(this));
241 253
242 if (ink_drop_mode != InkDropMode::ON) 254 if (ink_drop_mode != InkDropMode::ON)
243 gesture_handler_.reset(); 255 gesture_handler_.reset();
244 else if (!gesture_handler_) 256 else if (!gesture_handler_)
245 gesture_handler_.reset(new InkDropGestureHandler(this)); 257 gesture_handler_.reset(new InkDropGestureHandler(this));
246 } 258 }
247 259
248 } // namespace views 260 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698