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

Side by Side Diff: cc/test/fake_scrollbar.cc

Issue 1458703010: Mac: Don't repaint scrollbars every frame (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master2
Patch Set: Sprinkle in some tests Created 5 years, 1 month 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "cc/test/fake_scrollbar.h" 5 #include "cc/test/fake_scrollbar.h"
6 6
7 #include "third_party/skia/include/core/SkCanvas.h" 7 #include "third_party/skia/include/core/SkCanvas.h"
8 #include "ui/gfx/skia_util.h" 8 #include "ui/gfx/skia_util.h"
9 9
10 namespace cc { 10 namespace cc {
11 11
12 FakeScrollbar::FakeScrollbar() 12 FakeScrollbar::FakeScrollbar()
13 : paint_(false), 13 : paint_(false),
14 has_thumb_(false), 14 has_thumb_(false),
15 is_overlay_(false), 15 is_overlay_(false),
16 thumb_thickness_(10), 16 thumb_thickness_(10),
17 thumb_length_(5), 17 thumb_length_(5),
18 thumb_opacity_(1),
19 track_opacity_(1),
20 needs_paint_thumb_(true),
21 needs_paint_track_(true),
18 track_rect_(0, 0, 100, 10), 22 track_rect_(0, 0, 100, 10),
19 fill_color_(SK_ColorGREEN) {} 23 fill_color_(SK_ColorGREEN) {}
20 24
21 FakeScrollbar::FakeScrollbar(bool paint, bool has_thumb, bool is_overlay) 25 FakeScrollbar::FakeScrollbar(bool paint, bool has_thumb, bool is_overlay)
22 : paint_(paint), 26 : paint_(paint),
23 has_thumb_(has_thumb), 27 has_thumb_(has_thumb),
24 is_overlay_(is_overlay), 28 is_overlay_(is_overlay),
25 thumb_thickness_(10), 29 thumb_thickness_(10),
26 thumb_length_(5), 30 thumb_length_(5),
31 thumb_opacity_(1),
32 track_opacity_(1),
33 needs_paint_thumb_(true),
34 needs_paint_track_(true),
27 track_rect_(0, 0, 100, 10), 35 track_rect_(0, 0, 100, 10),
28 fill_color_(SK_ColorGREEN) {} 36 fill_color_(SK_ColorGREEN) {}
29 37
30 FakeScrollbar::~FakeScrollbar() {} 38 FakeScrollbar::~FakeScrollbar() {}
31 39
32 ScrollbarOrientation FakeScrollbar::Orientation() const { 40 ScrollbarOrientation FakeScrollbar::Orientation() const {
33 return HORIZONTAL; 41 return HORIZONTAL;
34 } 42 }
35 43
36 bool FakeScrollbar::IsLeftSideVerticalScrollbar() const { 44 bool FakeScrollbar::IsLeftSideVerticalScrollbar() const {
(...skipping 11 matching lines...) Expand all
48 } 56 }
49 57
50 int FakeScrollbar::ThumbLength() const { 58 int FakeScrollbar::ThumbLength() const {
51 return thumb_length_; 59 return thumb_length_;
52 } 60 }
53 61
54 gfx::Rect FakeScrollbar::TrackRect() const { 62 gfx::Rect FakeScrollbar::TrackRect() const {
55 return track_rect_; 63 return track_rect_;
56 } 64 }
57 65
66 float FakeScrollbar::ThumbOpacity() const {
67 return thumb_opacity_;
68 }
69
70 float FakeScrollbar::TrackOpacity() const {
71 return track_opacity_;
72 }
73
74 bool FakeScrollbar::NeedsPaintPart(ScrollbarPart part) const {
75 if (part == THUMB)
76 return needs_paint_thumb_;
77 return needs_paint_track_;
78 }
79
58 void FakeScrollbar::PaintPart(SkCanvas* canvas, 80 void FakeScrollbar::PaintPart(SkCanvas* canvas,
59 ScrollbarPart part, 81 ScrollbarPart part,
60 const gfx::Rect& content_rect) { 82 const gfx::Rect& content_rect) {
61 if (!paint_) 83 if (!paint_)
62 return; 84 return;
63 85
64 // Fill the scrollbar with a different color each time. 86 // Fill the scrollbar with a different color each time.
65 fill_color_++; 87 fill_color_++;
66 SkPaint paint; 88 SkPaint paint;
67 paint.setAntiAlias(false); 89 paint.setAntiAlias(false);
68 paint.setColor(paint_fill_color()); 90 paint.setColor(paint_fill_color());
69 paint.setStyle(SkPaint::kFill_Style); 91 paint.setStyle(SkPaint::kFill_Style);
70 92
71 // Emulate the how the real scrollbar works by using scrollbar's rect for 93 // Emulate the how the real scrollbar works by using scrollbar's rect for
72 // TRACK and the given content_rect for the THUMB 94 // TRACK and the given content_rect for the THUMB
73 SkRect rect = part == TRACK ? RectToSkRect(TrackRect()) 95 SkRect rect = part == TRACK ? RectToSkRect(TrackRect())
74 : RectToSkRect(content_rect); 96 : RectToSkRect(content_rect);
75 canvas->drawRect(rect, paint); 97 canvas->drawRect(rect, paint);
76 } 98 }
77 99
78 } // namespace cc 100 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698