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 namespace cc { |
| 8 |
| 9 std::unique_ptr<PaintedOverlayScrollbarLayerImpl> |
| 10 PaintedOverlayScrollbarLayerImpl::Create(LayerTreeImpl* tree_impl, |
| 11 int id, |
| 12 ScrollbarOrientation orientation, |
| 13 bool is_left_side_vertical_scrollbar) { |
| 14 return base::WrapUnique(new PaintedOverlayScrollbarLayerImpl( |
| 15 tree_impl, id, orientation, is_left_side_vertical_scrollbar)); |
| 16 } |
| 17 |
| 18 PaintedOverlayScrollbarLayerImpl::PaintedOverlayScrollbarLayerImpl( |
| 19 LayerTreeImpl* tree_impl, |
| 20 int id, |
| 21 ScrollbarOrientation orientation, |
| 22 bool is_left_side_vertical_scrollbar) |
| 23 : ScrollbarLayerImplBase(tree_impl, |
| 24 id, |
| 25 orientation, |
| 26 is_left_side_vertical_scrollbar, |
| 27 true), |
| 28 thumb_ui_resource_id_(0), |
| 29 thumb_thickness_(0), |
| 30 thumb_length_(0), |
| 31 track_start_(0), |
| 32 track_length_(0) {} |
| 33 |
| 34 PaintedOverlayScrollbarLayerImpl::~PaintedOverlayScrollbarLayerImpl() {} |
| 35 |
| 36 std::unique_ptr<LayerImpl> PaintedOverlayScrollbarLayerImpl::CreateLayerImpl( |
| 37 LayerTreeImpl* tree_impl) { |
| 38 return PaintedOverlayScrollbarLayerImpl::Create( |
| 39 tree_impl, id(), orientation(), is_left_side_vertical_scrollbar()); |
| 40 } |
| 41 |
| 42 void PaintedOverlayScrollbarLayerImpl::PushPropertiesTo(LayerImpl* layer) { |
| 43 ScrollbarLayerImplBase::PushPropertiesTo(layer); |
| 44 |
| 45 PaintedOverlayScrollbarLayerImpl* scrollbar_layer = |
| 46 static_cast<PaintedOverlayScrollbarLayerImpl*>(layer); |
| 47 |
| 48 scrollbar_layer->SetThumbThickness(thumb_thickness_); |
| 49 scrollbar_layer->SetThumbLength(thumb_length_); |
| 50 scrollbar_layer->SetTrackStart(track_start_); |
| 51 scrollbar_layer->SetTrackLength(track_length_); |
| 52 |
| 53 scrollbar_layer->SetImageBounds(image_bounds_); |
| 54 scrollbar_layer->SetAperture(aperture_); |
| 55 |
| 56 scrollbar_layer->set_thumb_ui_resource_id(thumb_ui_resource_id_); |
| 57 } |
| 58 |
| 59 bool PaintedOverlayScrollbarLayerImpl::WillDraw( |
| 60 DrawMode draw_mode, |
| 61 ResourceProvider* resource_provider) { |
| 62 DCHECK(draw_mode != DRAW_MODE_RESOURCELESS_SOFTWARE); |
| 63 return LayerImpl::WillDraw(draw_mode, resource_provider); |
| 64 } |
| 65 |
| 66 void PaintedOverlayScrollbarLayerImpl::AppendQuads( |
| 67 RenderPass* render_pass, |
| 68 AppendQuadsData* append_quads_data) { |
| 69 // For overlay scrollbars, the border should match the inset of the aperture |
| 70 // and be symmetrical. |
| 71 gfx::Rect border(aperture_.x(), aperture_.y(), aperture_.x() * 2, |
| 72 aperture_.y() * 2); |
| 73 gfx::Rect thumb_quad_rect(ComputeThumbQuadRect()); |
| 74 gfx::Rect layer_occlusion; |
| 75 bool fill_center = true; |
| 76 bool nearest_neighbor = false; |
| 77 |
| 78 quad_generator_.SetLayout(image_bounds_, thumb_quad_rect.size(), aperture_, |
| 79 border, layer_occlusion, fill_center, |
| 80 nearest_neighbor); |
| 81 |
| 82 SharedQuadState* shared_quad_state = |
| 83 render_pass->CreateAndAppendSharedQuadState(); |
| 84 PopulateSharedQuadState(shared_quad_state); |
| 85 |
| 86 AppendDebugBorderQuad(render_pass, bounds(), shared_quad_state, |
| 87 append_quads_data); |
| 88 |
| 89 std::vector<NinePatchGenerator::Patch> patches = |
| 90 quad_generator_.GeneratePatches(); |
| 91 |
| 92 gfx::Vector2dF offset = thumb_quad_rect.OffsetFromOrigin(); |
| 93 for (auto& patch : patches) |
| 94 patch.output_rect += offset; |
| 95 |
| 96 quad_generator_.AppendQuads(this, thumb_ui_resource_id_, render_pass, |
| 97 shared_quad_state, patches); |
| 98 } |
| 99 |
| 100 void PaintedOverlayScrollbarLayerImpl::SetThumbThickness(int thumb_thickness) { |
| 101 if (thumb_thickness_ == thumb_thickness) |
| 102 return; |
| 103 thumb_thickness_ = thumb_thickness; |
| 104 NoteLayerPropertyChanged(); |
| 105 } |
| 106 |
| 107 int PaintedOverlayScrollbarLayerImpl::ThumbThickness() const { |
| 108 return thumb_thickness_; |
| 109 } |
| 110 |
| 111 void PaintedOverlayScrollbarLayerImpl::SetThumbLength(int thumb_length) { |
| 112 if (thumb_length_ == thumb_length) |
| 113 return; |
| 114 thumb_length_ = thumb_length; |
| 115 NoteLayerPropertyChanged(); |
| 116 } |
| 117 |
| 118 int PaintedOverlayScrollbarLayerImpl::ThumbLength() const { |
| 119 return thumb_length_; |
| 120 } |
| 121 |
| 122 void PaintedOverlayScrollbarLayerImpl::SetTrackStart(int track_start) { |
| 123 if (track_start_ == track_start) |
| 124 return; |
| 125 track_start_ = track_start; |
| 126 NoteLayerPropertyChanged(); |
| 127 } |
| 128 |
| 129 int PaintedOverlayScrollbarLayerImpl::TrackStart() const { |
| 130 return track_start_; |
| 131 } |
| 132 |
| 133 void PaintedOverlayScrollbarLayerImpl::SetTrackLength(int track_length) { |
| 134 if (track_length_ == track_length) |
| 135 return; |
| 136 track_length_ = track_length; |
| 137 NoteLayerPropertyChanged(); |
| 138 } |
| 139 |
| 140 void PaintedOverlayScrollbarLayerImpl::SetImageBounds(const gfx::Size& bounds) { |
| 141 if (image_bounds_ == bounds) |
| 142 return; |
| 143 image_bounds_ = bounds; |
| 144 NoteLayerPropertyChanged(); |
| 145 } |
| 146 |
| 147 void PaintedOverlayScrollbarLayerImpl::SetAperture(const gfx::Rect& aperture) { |
| 148 if (aperture_ == aperture) |
| 149 return; |
| 150 aperture_ = aperture; |
| 151 NoteLayerPropertyChanged(); |
| 152 } |
| 153 |
| 154 float PaintedOverlayScrollbarLayerImpl::TrackLength() const { |
| 155 return track_length_ + (orientation() == VERTICAL ? vertical_adjust() : 0); |
| 156 } |
| 157 |
| 158 bool PaintedOverlayScrollbarLayerImpl::IsThumbResizable() const { |
| 159 return false; |
| 160 } |
| 161 |
| 162 const char* PaintedOverlayScrollbarLayerImpl::LayerTypeAsString() const { |
| 163 return "cc::PaintedOverlayScrollbarLayerImpl"; |
| 164 } |
| 165 |
| 166 } // namespace cc |
OLD | NEW |