OLD | NEW |
---|---|
(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/painted_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<PaintedOverlayScrollbarLayerImpl> | |
22 PaintedOverlayScrollbarLayerImpl::Create(LayerTreeImpl* tree_impl, | |
23 int id, | |
24 ScrollbarOrientation orientation, | |
25 bool is_left_side_vertical_scrollbar) { | |
26 return base::WrapUnique(new PaintedOverlayScrollbarLayerImpl( | |
27 tree_impl, id, orientation, is_left_side_vertical_scrollbar)); | |
28 } | |
29 | |
30 PaintedOverlayScrollbarLayerImpl::PaintedOverlayScrollbarLayerImpl( | |
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 PaintedOverlayScrollbarLayerImpl::~PaintedOverlayScrollbarLayerImpl() {} | |
47 | |
48 std::unique_ptr<LayerImpl> PaintedOverlayScrollbarLayerImpl::CreateLayerImpl( | |
49 LayerTreeImpl* tree_impl) { | |
50 return PaintedOverlayScrollbarLayerImpl::Create( | |
51 tree_impl, id(), orientation(), is_left_side_vertical_scrollbar()); | |
52 } | |
53 | |
54 void PaintedOverlayScrollbarLayerImpl::PushPropertiesTo(LayerImpl* layer) { | |
55 ScrollbarLayerImplBase::PushPropertiesTo(layer); | |
56 | |
57 PaintedOverlayScrollbarLayerImpl* scrollbar_layer = | |
58 static_cast<PaintedOverlayScrollbarLayerImpl*>(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 PaintedOverlayScrollbarLayerImpl::WillDraw( | |
72 DrawMode draw_mode, | |
73 ResourceProvider* resource_provider) { | |
74 DCHECK(draw_mode != DRAW_MODE_RESOURCELESS_SOFTWARE); | |
75 return LayerImpl::WillDraw(draw_mode, resource_provider); | |
76 } | |
77 | |
78 void PaintedOverlayScrollbarLayerImpl::AppendQuads( | |
aelias_OOO_until_Jul13
2017/02/28 23:23:51
There's still a bit of code duplication here with
bokan
2017/03/01 00:44:21
Ok, I've moved as much as I could into NinePatchGe
| |
79 RenderPass* render_pass, | |
80 AppendQuadsData* append_quads_data) { | |
81 // For overlay scrollbars, the border should match the inset of the aperture | |
82 // and be symmetrical. | |
83 gfx::Rect border(aperture_.x(), aperture_.y(), aperture_.x() * 2, | |
84 aperture_.y() * 2); | |
85 gfx::Rect thumb_quad_rect(ComputeThumbQuadRect()); | |
86 gfx::Rect layer_occlusion; | |
87 bool fill_center = true; | |
88 bool nearest_neighbor = false; | |
89 | |
90 quad_generator_.SetLayout(image_bounds_, thumb_quad_rect.size(), aperture_, | |
91 border, layer_occlusion, fill_center); | |
92 | |
93 SharedQuadState* shared_quad_state = | |
94 render_pass->CreateAndAppendSharedQuadState(); | |
95 PopulateSharedQuadState(shared_quad_state); | |
96 | |
97 AppendDebugBorderQuad(render_pass, bounds(), shared_quad_state, | |
98 append_quads_data); | |
99 | |
100 if (!thumb_ui_resource_id_) | |
101 return; | |
102 | |
103 ResourceId resource = | |
104 layer_tree_impl()->ResourceIdForUIResource(thumb_ui_resource_id_); | |
105 | |
106 if (!resource) | |
107 return; | |
108 | |
109 std::vector<NinePatchGenerator::Patch> patches = | |
110 quad_generator_.GeneratePatches(); | |
111 | |
112 const float vertex_opacity[] = {1.0f, 1.0f, 1.0f, 1.0f}; | |
113 const bool opaque = | |
114 layer_tree_impl()->IsUIResourceOpaque(thumb_ui_resource_id_); | |
115 static const bool flipped = false; | |
116 static const bool premultiplied_alpha = true; | |
117 | |
118 gfx::Vector2dF offset = thumb_quad_rect.OffsetFromOrigin(); | |
119 | |
120 for (const auto& patch : patches) { | |
121 gfx::Rect output_rect = gfx::ToEnclosingRect(patch.output_rect + offset); | |
122 gfx::Rect visible_rect = | |
123 draw_properties().occlusion_in_content_space.GetUnoccludedContentRect( | |
124 output_rect); | |
125 gfx::Rect opaque_rect = opaque ? visible_rect : gfx::Rect(); | |
126 if (!visible_rect.IsEmpty()) { | |
127 gfx::RectF image_rect = patch.normalized_image_rect; | |
128 TextureDrawQuad* quad = | |
129 render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>(); | |
130 quad->SetNew(shared_quad_state, output_rect, opaque_rect, visible_rect, | |
131 resource, premultiplied_alpha, image_rect.origin(), | |
132 image_rect.bottom_right(), SK_ColorTRANSPARENT, | |
133 vertex_opacity, flipped, nearest_neighbor, false); | |
134 ValidateQuadResources(quad); | |
135 } | |
136 } | |
137 } | |
138 | |
139 void PaintedOverlayScrollbarLayerImpl::SetThumbThickness(int thumb_thickness) { | |
140 if (thumb_thickness_ == thumb_thickness) | |
141 return; | |
142 thumb_thickness_ = thumb_thickness; | |
143 NoteLayerPropertyChanged(); | |
144 } | |
145 | |
146 int PaintedOverlayScrollbarLayerImpl::ThumbThickness() const { | |
147 return thumb_thickness_; | |
148 } | |
149 | |
150 void PaintedOverlayScrollbarLayerImpl::SetThumbLength(int thumb_length) { | |
151 if (thumb_length_ == thumb_length) | |
152 return; | |
153 thumb_length_ = thumb_length; | |
154 NoteLayerPropertyChanged(); | |
155 } | |
156 | |
157 int PaintedOverlayScrollbarLayerImpl::ThumbLength() const { | |
158 return thumb_length_; | |
159 } | |
160 | |
161 void PaintedOverlayScrollbarLayerImpl::SetTrackStart(int track_start) { | |
162 if (track_start_ == track_start) | |
163 return; | |
164 track_start_ = track_start; | |
165 NoteLayerPropertyChanged(); | |
166 } | |
167 | |
168 int PaintedOverlayScrollbarLayerImpl::TrackStart() const { | |
169 return track_start_; | |
170 } | |
171 | |
172 void PaintedOverlayScrollbarLayerImpl::SetTrackLength(int track_length) { | |
173 if (track_length_ == track_length) | |
174 return; | |
175 track_length_ = track_length; | |
176 NoteLayerPropertyChanged(); | |
177 } | |
178 | |
179 void PaintedOverlayScrollbarLayerImpl::SetImageBounds(const gfx::Size& bounds) { | |
180 if (image_bounds_ == bounds) | |
181 return; | |
182 image_bounds_ = bounds; | |
183 NoteLayerPropertyChanged(); | |
184 } | |
185 | |
186 void PaintedOverlayScrollbarLayerImpl::SetAperture(const gfx::Rect& aperture) { | |
187 if (aperture_ == aperture) | |
188 return; | |
189 aperture_ = aperture; | |
190 NoteLayerPropertyChanged(); | |
191 } | |
192 | |
193 float PaintedOverlayScrollbarLayerImpl::TrackLength() const { | |
194 return track_length_ + (orientation() == VERTICAL ? vertical_adjust() : 0); | |
195 } | |
196 | |
197 bool PaintedOverlayScrollbarLayerImpl::IsThumbResizable() const { | |
198 return false; | |
199 } | |
200 | |
201 const char* PaintedOverlayScrollbarLayerImpl::LayerTypeAsString() const { | |
202 return "cc::PaintedOverlayScrollbarLayerImpl"; | |
203 } | |
204 | |
205 } // namespace cc | |
OLD | NEW |