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

Side by Side Diff: cc/trees/layer_tree_host_pixeltest_scrollbars.cc

Issue 2591863003: Use nine-patch resource for drawing Aura overlay scrollbar thumb. (Closed)
Patch Set: Addressed sadrul@'s feedback Created 3 years, 9 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 #include "cc/input/scrollbar.h" 9 #include "cc/input/scrollbar.h"
10 #include "cc/layers/painted_overlay_scrollbar_layer.h"
10 #include "cc/layers/painted_scrollbar_layer.h" 11 #include "cc/layers/painted_scrollbar_layer.h"
11 #include "cc/layers/solid_color_layer.h" 12 #include "cc/layers/solid_color_layer.h"
12 #include "cc/paint/paint_canvas.h" 13 #include "cc/paint/paint_canvas.h"
13 #include "cc/paint/paint_flags.h" 14 #include "cc/paint/paint_flags.h"
14 #include "cc/test/layer_tree_pixel_test.h" 15 #include "cc/test/layer_tree_pixel_test.h"
15 #include "cc/test/test_in_process_context_provider.h" 16 #include "cc/test/test_in_process_context_provider.h"
17 #include "cc/trees/layer_tree_impl.h"
16 #include "gpu/command_buffer/client/gles2_interface.h" 18 #include "gpu/command_buffer/client/gles2_interface.h"
17 19
18 #if !defined(OS_ANDROID) 20 #if !defined(OS_ANDROID)
19 21
20 namespace cc { 22 namespace cc {
21 namespace { 23 namespace {
22 24
23 class LayerTreeHostScrollbarsPixelTest : public LayerTreePixelTest { 25 class LayerTreeHostScrollbarsPixelTest : public LayerTreePixelTest {
24 protected: 26 protected:
25 LayerTreeHostScrollbarsPixelTest() = default; 27 LayerTreeHostScrollbarsPixelTest() = default;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 62
61 gfx::Rect inset_rect = content_rect; 63 gfx::Rect inset_rect = content_rect;
62 while (!inset_rect.IsEmpty()) { 64 while (!inset_rect.IsEmpty()) {
63 int big = paint_scale_ + 2; 65 int big = paint_scale_ + 2;
64 int small = paint_scale_; 66 int small = paint_scale_;
65 inset_rect.Inset(big, big, small, small); 67 inset_rect.Inset(big, big, small, small);
66 canvas->drawRect(RectToSkRect(inset_rect), flags); 68 canvas->drawRect(RectToSkRect(inset_rect), flags);
67 inset_rect.Inset(big, big, small, small); 69 inset_rect.Inset(big, big, small, small);
68 } 70 }
69 } 71 }
72 bool UsesNinePatchThumbResource() const override { return false; }
73 gfx::Size NinePatchThumbCanvasSize() const override { return gfx::Size(); }
74 gfx::Rect NinePatchThumbAperture() const override { return gfx::Rect(); }
70 75
71 void set_paint_scale(int scale) { paint_scale_ = scale; } 76 void set_paint_scale(int scale) { paint_scale_ = scale; }
72 77
73 private: 78 private:
74 int paint_scale_ = 4; 79 int paint_scale_ = 4;
75 bool thumb_ = false; 80 bool thumb_ = false;
76 SkColor color_ = SK_ColorGREEN; 81 SkColor color_ = SK_ColorGREEN;
77 gfx::Rect rect_; 82 gfx::Rect rect_;
78 }; 83 };
79 84
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 gfx::PointF(-10.f * scale + 400.f, -400.f * scale + 400.f)); 166 gfx::PointF(-10.f * scale + 400.f, -400.f * scale + 400.f));
162 167
163 gfx::Transform scale_transform; 168 gfx::Transform scale_transform;
164 scale_transform.Scale(scale, scale); 169 scale_transform.Scale(scale, scale);
165 layer->SetTransform(scale_transform); 170 layer->SetTransform(scale_transform);
166 171
167 RunPixelTest(PIXEL_TEST_GL, background, 172 RunPixelTest(PIXEL_TEST_GL, background,
168 base::FilePath(FILE_PATH_LITERAL("spiral_64_scale.png"))); 173 base::FilePath(FILE_PATH_LITERAL("spiral_64_scale.png")));
169 } 174 }
170 175
176 class LayerTreeHostOverlayScrollbarsPixelTest
177 : public LayerTreeHostScrollbarsPixelTest {
178 protected:
179 LayerTreeHostOverlayScrollbarsPixelTest() = default;
180
181 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override {
182 LayerImpl* layer = host_impl->active_tree()->LayerById(scrollbar_layer_id_);
183 ScrollbarLayerImplBase* scrollbar = layer->ToScrollbarLayer();
184 scrollbar->SetThumbThicknessScaleFactor(thickness_scale_);
185 }
186
187 int scrollbar_layer_id_;
188 float thickness_scale_;
189 };
190
191 class PaintedOverlayScrollbar : public PaintedScrollbar {
192 public:
193 ~PaintedOverlayScrollbar() override = default;
194
195 int ThumbThickness() const override { return 15; }
196 int ThumbLength() const override { return 50; }
197 gfx::Rect TrackRect() const override { return gfx::Rect(0, 0, 15, 400); }
198 bool HasThumb() const override { return true; }
199 bool IsOverlay() const override { return true; }
200 void PaintPart(PaintCanvas* canvas,
201 ScrollbarPart part,
202 const gfx::Rect& content_rect) override {
203 // The outside of the rect will be painted with a 1 pixel black, red, then
204 // blue border. The inside will be solid blue. This will allow the test to
205 // ensure that scaling the thumb doesn't scale the border at all. Note
206 // that the inside of the border must be the same color as the center tile
207 // to prevent an interpolation from being applied.
208 PaintFlags flags;
209 flags.setStyle(PaintFlags::kFill_Style);
210 flags.setStrokeWidth(SkIntToScalar(1));
211 flags.setColor(SK_ColorBLACK);
212
213 gfx::Rect inset_rect = content_rect;
214
215 canvas->drawRect(RectToSkRect(inset_rect), flags);
216
217 flags.setColor(SK_ColorRED);
218 inset_rect.Inset(1, 1);
219 canvas->drawRect(RectToSkRect(inset_rect), flags);
220
221 flags.setColor(SK_ColorBLUE);
222 inset_rect.Inset(1, 1);
223 canvas->drawRect(RectToSkRect(inset_rect), flags);
224 }
225 bool UsesNinePatchThumbResource() const override { return true; }
226 gfx::Size NinePatchThumbCanvasSize() const override {
227 return gfx::Size(7, 7);
228 }
229 gfx::Rect NinePatchThumbAperture() const override {
230 return gfx::Rect(3, 3, 1, 1);
231 }
232 };
233
234 // Simulate increasing the thickness of a painted overlay scrollbar. Ensure that
235 // the scrollbar border remains crisp.
236 TEST_F(LayerTreeHostOverlayScrollbarsPixelTest, NinePatchScrollbarScaledUp) {
237 scoped_refptr<SolidColorLayer> background =
238 CreateSolidColorLayer(gfx::Rect(400, 400), SK_ColorWHITE);
239
240 auto scrollbar = base::MakeUnique<PaintedOverlayScrollbar>();
241 scoped_refptr<PaintedOverlayScrollbarLayer> layer =
242 PaintedOverlayScrollbarLayer::Create(std::move(scrollbar),
243 Layer::INVALID_ID);
244
245 scrollbar_layer_id_ = layer->id();
246 thickness_scale_ = 5.f;
247
248 layer->SetIsDrawable(true);
249 layer->SetBounds(gfx::Size(10, 300));
250 background->AddChild(layer);
251
252 layer->SetPosition(gfx::PointF(185, 10));
253
254 RunPixelTest(
255 PIXEL_TEST_GL, background,
256 base::FilePath(FILE_PATH_LITERAL("overlay_scrollbar_scaled_up.png")));
257 }
258
259 // Simulate decreasing the thickness of a painted overlay scrollbar. Ensure that
260 // the scrollbar border remains crisp.
261 TEST_F(LayerTreeHostOverlayScrollbarsPixelTest, NinePatchScrollbarScaledDown) {
262 scoped_refptr<SolidColorLayer> background =
263 CreateSolidColorLayer(gfx::Rect(400, 400), SK_ColorWHITE);
264
265 auto scrollbar = base::MakeUnique<PaintedOverlayScrollbar>();
266 scoped_refptr<PaintedOverlayScrollbarLayer> layer =
267 PaintedOverlayScrollbarLayer::Create(std::move(scrollbar),
268 Layer::INVALID_ID);
269
270 scrollbar_layer_id_ = layer->id();
271 thickness_scale_ = 0.4f;
272
273 layer->SetIsDrawable(true);
274 layer->SetBounds(gfx::Size(10, 300));
275 background->AddChild(layer);
276
277 layer->SetPosition(gfx::PointF(185, 10));
278
279 RunPixelTest(
280 PIXEL_TEST_GL, background,
281 base::FilePath(FILE_PATH_LITERAL("overlay_scrollbar_scaled_down.png")));
282 }
283
171 } // namespace 284 } // namespace
172 } // namespace cc 285 } // namespace cc
173 286
174 #endif // OS_ANDROID 287 #endif // OS_ANDROID
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698