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

Side by Side Diff: cc/layers/overlay_scrollbar_layer_impl.cc

Issue 2591863003: Use nine-patch resource for drawing Aura overlay scrollbar thumb. (Closed)
Patch Set: Finish Plumbing Created 4 years 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "cc/layers/overlay_scrollbar_layer_impl.h"
6
7 #include <algorithm>
8
9 #include "base/memory/ptr_util.h"
10 #include "cc/input/scrollbar_animation_controller.h"
11 #include "cc/layers/layer.h"
12 #include "cc/quads/solid_color_draw_quad.h"
13 #include "cc/quads/texture_draw_quad.h"
14 #include "cc/trees/layer_tree_impl.h"
15 #include "cc/trees/layer_tree_settings.h"
16 #include "cc/trees/occlusion.h"
17 #include "ui/gfx/geometry/rect_conversions.h"
18
19 namespace cc {
20
21 std::unique_ptr<OverlayScrollbarLayerImpl> OverlayScrollbarLayerImpl::Create(
22 LayerTreeImpl* tree_impl,
23 int id,
24 ScrollbarOrientation orientation,
25 bool is_left_side_vertical_scrollbar) {
26 return base::WrapUnique(new OverlayScrollbarLayerImpl(
27 tree_impl, id, orientation, is_left_side_vertical_scrollbar));
28 }
29
30 OverlayScrollbarLayerImpl::OverlayScrollbarLayerImpl(
31 LayerTreeImpl* tree_impl,
32 int id,
33 ScrollbarOrientation orientation,
34 bool is_left_side_vertical_scrollbar)
35 : ScrollbarLayerImplBase(tree_impl,
36 id,
37 orientation,
38 is_left_side_vertical_scrollbar,
39 true),
40 thumb_ui_resource_id_(0),
41 thumb_thickness_(0),
42 thumb_length_(0),
43 track_start_(0),
44 track_length_(0) {}
45
46 OverlayScrollbarLayerImpl::~OverlayScrollbarLayerImpl() {}
47
48 std::unique_ptr<LayerImpl> OverlayScrollbarLayerImpl::CreateLayerImpl(
49 LayerTreeImpl* tree_impl) {
50 return OverlayScrollbarLayerImpl::Create(tree_impl, id(), orientation(),
51 is_left_side_vertical_scrollbar());
52 }
53
54 void OverlayScrollbarLayerImpl::PushPropertiesTo(LayerImpl* layer) {
55 ScrollbarLayerImplBase::PushPropertiesTo(layer);
56
57 OverlayScrollbarLayerImpl* scrollbar_layer =
58 static_cast<OverlayScrollbarLayerImpl*>(layer);
59
60 scrollbar_layer->SetThumbThickness(thumb_thickness_);
61 scrollbar_layer->SetThumbLength(thumb_length_);
62 scrollbar_layer->SetTrackStart(track_start_);
63 scrollbar_layer->SetTrackLength(track_length_);
64
65 scrollbar_layer->SetImageBounds(image_bounds_);
66 scrollbar_layer->SetAperture(aperture_);
67
68 scrollbar_layer->set_thumb_ui_resource_id(thumb_ui_resource_id_);
69 }
70
71 bool OverlayScrollbarLayerImpl::WillDraw(DrawMode draw_mode,
72 ResourceProvider* resource_provider) {
73 DCHECK(draw_mode != DRAW_MODE_RESOURCELESS_SOFTWARE);
74 return LayerImpl::WillDraw(draw_mode, resource_provider);
75 }
76
77 void OverlayScrollbarLayerImpl::AppendQuads(
78 RenderPass* render_pass,
79 AppendQuadsData* append_quads_data) {
80 // For overlay scrollbars, the border should match the inset of the aperture
81 // and be symmetrical.
82 gfx::Rect border(aperture_.x(), aperture_.y(), aperture_.x() * 2,
83 aperture_.y() * 2);
84 gfx::Rect thumb_quad_rect(ComputeThumbQuadRect());
85 gfx::Rect layer_occlusion;
86 bool fill_center = true;
87 bool nearest_neighbor = false;
88
89 quad_generator_.SetLayout(image_bounds_, thumb_quad_rect.size(), aperture_,
90 border, layer_occlusion, fill_center);
91
92 SharedQuadState* shared_quad_state =
93 render_pass->CreateAndAppendSharedQuadState();
94 PopulateSharedQuadState(shared_quad_state);
95
96 AppendDebugBorderQuad(render_pass, bounds(), shared_quad_state,
97 append_quads_data);
98
99 if (!thumb_ui_resource_id_)
100 return;
101
102 ResourceId resource =
103 layer_tree_impl()->ResourceIdForUIResource(thumb_ui_resource_id_);
104
105 if (!resource)
106 return;
107
108 std::vector<NinePatchGenerator::Patch> patches =
109 quad_generator_.GeneratePatches();
110
111 const float vertex_opacity[] = {1.0f, 1.0f, 1.0f, 1.0f};
112 const bool opaque =
113 layer_tree_impl()->IsUIResourceOpaque(thumb_ui_resource_id_);
114 static const bool flipped = false;
115 static const bool premultiplied_alpha = true;
116
117 gfx::Vector2dF offset = thumb_quad_rect.OffsetFromOrigin();
118
119 for (const auto& patch : patches) {
120 gfx::Rect output_rect = gfx::ToEnclosingRect(patch.output_rect + offset);
121 gfx::Rect visible_rect =
122 draw_properties().occlusion_in_content_space.GetUnoccludedContentRect(
123 output_rect);
124 gfx::Rect opaque_rect = opaque ? visible_rect : gfx::Rect();
125 if (!visible_rect.IsEmpty()) {
126 gfx::RectF image_rect = patch.normalized_image_rect;
127 TextureDrawQuad* quad =
128 render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>();
129 quad->SetNew(shared_quad_state, output_rect, opaque_rect, visible_rect,
130 resource, premultiplied_alpha, image_rect.origin(),
131 image_rect.bottom_right(), SK_ColorTRANSPARENT,
132 vertex_opacity, flipped, nearest_neighbor, false);
133 ValidateQuadResources(quad);
134 }
135 }
136 }
137
138 void OverlayScrollbarLayerImpl::SetThumbThickness(int thumb_thickness) {
139 if (thumb_thickness_ == thumb_thickness)
140 return;
141 thumb_thickness_ = thumb_thickness;
142 NoteLayerPropertyChanged();
143 }
144
145 int OverlayScrollbarLayerImpl::ThumbThickness() const {
146 return thumb_thickness_;
147 }
148
149 void OverlayScrollbarLayerImpl::SetThumbLength(int thumb_length) {
150 if (thumb_length_ == thumb_length)
151 return;
152 thumb_length_ = thumb_length;
153 NoteLayerPropertyChanged();
154 }
155
156 int OverlayScrollbarLayerImpl::ThumbLength() const {
157 return thumb_length_;
158 }
159
160 void OverlayScrollbarLayerImpl::SetTrackStart(int track_start) {
161 if (track_start_ == track_start)
162 return;
163 track_start_ = track_start;
164 NoteLayerPropertyChanged();
165 }
166
167 int OverlayScrollbarLayerImpl::TrackStart() const {
168 return track_start_;
169 }
170
171 void OverlayScrollbarLayerImpl::SetTrackLength(int track_length) {
172 if (track_length_ == track_length)
173 return;
174 track_length_ = track_length;
175 NoteLayerPropertyChanged();
176 }
177
178 void OverlayScrollbarLayerImpl::SetImageBounds(const gfx::Size& bounds) {
179 if (image_bounds_ == bounds)
180 return;
181 image_bounds_ = bounds;
182 NoteLayerPropertyChanged();
183 }
184
185 void OverlayScrollbarLayerImpl::SetAperture(const gfx::Rect& aperture) {
186 if (aperture_ == aperture)
187 return;
188 aperture_ = aperture;
189 NoteLayerPropertyChanged();
190 }
191
192 float OverlayScrollbarLayerImpl::TrackLength() const {
193 return track_length_ + (orientation() == VERTICAL ? vertical_adjust() : 0);
194 }
195
196 bool OverlayScrollbarLayerImpl::IsThumbResizable() const {
197 return false;
198 }
199
200 const char* OverlayScrollbarLayerImpl::LayerTypeAsString() const {
201 return "cc::OverlayScrollbarLayerImpl";
202 }
203
204 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698