[email protected] | 3a83478b | 2013-08-22 20:55:17 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 3a83478b | 2013-08-22 20:55:17 | [diff] [blame] | 5 | #include "cc/layers/painted_scrollbar_layer_impl.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6 | |
[email protected] | 3a73d22 | 2013-07-26 13:53:18 | [diff] [blame] | 7 | #include <algorithm> |
| 8 | |
[email protected] | 95e4e1a0 | 2013-03-18 07:09:09 | [diff] [blame] | 9 | #include "cc/animation/scrollbar_animation_controller.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 10 | #include "cc/layers/layer.h" |
[email protected] | 89e8267 | 2013-03-18 07:50:56 | [diff] [blame] | 11 | #include "cc/quads/solid_color_draw_quad.h" |
| 12 | #include "cc/quads/texture_draw_quad.h" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 13 | #include "cc/trees/layer_tree_impl.h" |
| 14 | #include "cc/trees/layer_tree_settings.h" |
vmpstr | 11b77b43 | 2014-10-07 20:11:40 | [diff] [blame] | 15 | #include "cc/trees/occlusion.h" |
heejin.r.chung | d28506ba | 2014-10-23 16:36:20 | [diff] [blame^] | 16 | #include "ui/gfx/geometry/rect_conversions.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 17 | |
[email protected] | 9c88e56 | 2012-09-14 22:21:30 | [diff] [blame] | 18 | namespace cc { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 19 | |
[email protected] | 3a83478b | 2013-08-22 20:55:17 | [diff] [blame] | 20 | scoped_ptr<PaintedScrollbarLayerImpl> PaintedScrollbarLayerImpl::Create( |
[email protected] | 3138b26 | 2013-03-08 18:39:08 | [diff] [blame] | 21 | LayerTreeImpl* tree_impl, |
| 22 | int id, |
[email protected] | c28df4c1 | 2013-05-22 17:36:49 | [diff] [blame] | 23 | ScrollbarOrientation orientation) { |
[email protected] | 3a83478b | 2013-08-22 20:55:17 | [diff] [blame] | 24 | return make_scoped_ptr( |
| 25 | new PaintedScrollbarLayerImpl(tree_impl, id, orientation)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 26 | } |
| 27 | |
[email protected] | 3a83478b | 2013-08-22 20:55:17 | [diff] [blame] | 28 | PaintedScrollbarLayerImpl::PaintedScrollbarLayerImpl( |
[email protected] | 3138b26 | 2013-03-08 18:39:08 | [diff] [blame] | 29 | LayerTreeImpl* tree_impl, |
| 30 | int id, |
[email protected] | c28df4c1 | 2013-05-22 17:36:49 | [diff] [blame] | 31 | ScrollbarOrientation orientation) |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 32 | : ScrollbarLayerImplBase(tree_impl, id, orientation, false, false), |
[email protected] | 45b46d38 | 2013-08-14 02:18:58 | [diff] [blame] | 33 | track_ui_resource_id_(0), |
| 34 | thumb_ui_resource_id_(0), |
[email protected] | c28df4c1 | 2013-05-22 17:36:49 | [diff] [blame] | 35 | thumb_thickness_(0), |
| 36 | thumb_length_(0), |
| 37 | track_start_(0), |
| 38 | track_length_(0), |
[email protected] | ffb2720f | 2013-03-15 19:18:37 | [diff] [blame] | 39 | vertical_adjust_(0.f), |
[email protected] | 80413d7 | 2013-08-30 20:25:33 | [diff] [blame] | 40 | scroll_layer_id_(Layer::INVALID_ID) {} |
[email protected] | 3138b26 | 2013-03-08 18:39:08 | [diff] [blame] | 41 | |
[email protected] | 3a83478b | 2013-08-22 20:55:17 | [diff] [blame] | 42 | PaintedScrollbarLayerImpl::~PaintedScrollbarLayerImpl() {} |
[email protected] | 3138b26 | 2013-03-08 18:39:08 | [diff] [blame] | 43 | |
[email protected] | 3a83478b | 2013-08-22 20:55:17 | [diff] [blame] | 44 | scoped_ptr<LayerImpl> PaintedScrollbarLayerImpl::CreateLayerImpl( |
[email protected] | 3138b26 | 2013-03-08 18:39:08 | [diff] [blame] | 45 | LayerTreeImpl* tree_impl) { |
danakj | f446a07 | 2014-09-27 21:55:48 | [diff] [blame] | 46 | return PaintedScrollbarLayerImpl::Create(tree_impl, id(), orientation()); |
[email protected] | 3138b26 | 2013-03-08 18:39:08 | [diff] [blame] | 47 | } |
| 48 | |
[email protected] | 3a83478b | 2013-08-22 20:55:17 | [diff] [blame] | 49 | void PaintedScrollbarLayerImpl::PushPropertiesTo(LayerImpl* layer) { |
[email protected] | 80413d7 | 2013-08-30 20:25:33 | [diff] [blame] | 50 | ScrollbarLayerImplBase::PushPropertiesTo(layer); |
[email protected] | 3138b26 | 2013-03-08 18:39:08 | [diff] [blame] | 51 | |
[email protected] | 3a83478b | 2013-08-22 20:55:17 | [diff] [blame] | 52 | PaintedScrollbarLayerImpl* scrollbar_layer = |
| 53 | static_cast<PaintedScrollbarLayerImpl*>(layer); |
[email protected] | 3138b26 | 2013-03-08 18:39:08 | [diff] [blame] | 54 | |
[email protected] | 5493fc4 | 2013-08-15 01:46:22 | [diff] [blame] | 55 | scrollbar_layer->SetThumbThickness(thumb_thickness_); |
| 56 | scrollbar_layer->SetThumbLength(thumb_length_); |
| 57 | scrollbar_layer->SetTrackStart(track_start_); |
| 58 | scrollbar_layer->SetTrackLength(track_length_); |
[email protected] | 3138b26 | 2013-03-08 18:39:08 | [diff] [blame] | 59 | |
[email protected] | 45b46d38 | 2013-08-14 02:18:58 | [diff] [blame] | 60 | scrollbar_layer->set_track_ui_resource_id(track_ui_resource_id_); |
| 61 | scrollbar_layer->set_thumb_ui_resource_id(thumb_ui_resource_id_); |
[email protected] | 3138b26 | 2013-03-08 18:39:08 | [diff] [blame] | 62 | } |
| 63 | |
[email protected] | 3a83478b | 2013-08-22 20:55:17 | [diff] [blame] | 64 | bool PaintedScrollbarLayerImpl::WillDraw(DrawMode draw_mode, |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 65 | ResourceProvider* resource_provider) { |
[email protected] | 80413d7 | 2013-08-30 20:25:33 | [diff] [blame] | 66 | DCHECK(draw_mode != DRAW_MODE_RESOURCELESS_SOFTWARE); |
[email protected] | a877bc138 | 2013-06-29 20:56:20 | [diff] [blame] | 67 | return LayerImpl::WillDraw(draw_mode, resource_provider); |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 68 | } |
| 69 | |
[email protected] | 3a83478b | 2013-08-22 20:55:17 | [diff] [blame] | 70 | void PaintedScrollbarLayerImpl::AppendQuads( |
[email protected] | c6707fd | 2014-06-23 05:50:36 | [diff] [blame] | 71 | RenderPass* render_pass, |
vmpstr | 11b77b43 | 2014-10-07 20:11:40 | [diff] [blame] | 72 | const Occlusion& occlusion_in_content_space, |
[email protected] | 3a83478b | 2013-08-22 20:55:17 | [diff] [blame] | 73 | AppendQuadsData* append_quads_data) { |
[email protected] | 3138b26 | 2013-03-08 18:39:08 | [diff] [blame] | 74 | bool premultipled_alpha = true; |
| 75 | bool flipped = false; |
| 76 | gfx::PointF uv_top_left(0.f, 0.f); |
| 77 | gfx::PointF uv_bottom_right(1.f, 1.f); |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 78 | gfx::Rect bounds_rect(bounds()); |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 79 | gfx::Rect content_bounds_rect(content_bounds()); |
[email protected] | 3138b26 | 2013-03-08 18:39:08 | [diff] [blame] | 80 | |
[email protected] | c6707fd | 2014-06-23 05:50:36 | [diff] [blame] | 81 | SharedQuadState* shared_quad_state = |
| 82 | render_pass->CreateAndAppendSharedQuadState(); |
[email protected] | 9be1adc | 2014-05-07 15:39:41 | [diff] [blame] | 83 | PopulateSharedQuadState(shared_quad_state); |
| 84 | |
[email protected] | b48a0b1 | 2014-06-20 20:20:32 | [diff] [blame] | 85 | AppendDebugBorderQuad( |
[email protected] | c6707fd | 2014-06-23 05:50:36 | [diff] [blame] | 86 | render_pass, content_bounds(), shared_quad_state, append_quads_data); |
[email protected] | 3138b26 | 2013-03-08 18:39:08 | [diff] [blame] | 87 | |
[email protected] | c28df4c1 | 2013-05-22 17:36:49 | [diff] [blame] | 88 | gfx::Rect thumb_quad_rect = ComputeThumbQuadRect(); |
vmpstr | 5b88d99 | 2014-09-18 23:25:04 | [diff] [blame] | 89 | gfx::Rect visible_thumb_quad_rect = |
vmpstr | 11b77b43 | 2014-10-07 20:11:40 | [diff] [blame] | 90 | occlusion_in_content_space.GetUnoccludedContentRect(thumb_quad_rect); |
[email protected] | c28df4c1 | 2013-05-22 17:36:49 | [diff] [blame] | 91 | |
[email protected] | 45b46d38 | 2013-08-14 02:18:58 | [diff] [blame] | 92 | ResourceProvider::ResourceId thumb_resource_id = |
| 93 | layer_tree_impl()->ResourceIdForUIResource(thumb_ui_resource_id_); |
| 94 | ResourceProvider::ResourceId track_resource_id = |
| 95 | layer_tree_impl()->ResourceIdForUIResource(track_ui_resource_id_); |
| 96 | |
[email protected] | 90963ef | 2014-04-17 18:03:29 | [diff] [blame] | 97 | if (thumb_resource_id && !visible_thumb_quad_rect.IsEmpty()) { |
[email protected] | 3138b26 | 2013-03-08 18:39:08 | [diff] [blame] | 98 | gfx::Rect opaque_rect; |
| 99 | const float opacity[] = {1.0f, 1.0f, 1.0f, 1.0f}; |
[email protected] | f7030c3 | 2014-07-03 18:54:34 | [diff] [blame] | 100 | TextureDrawQuad* quad = |
| 101 | render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>(); |
[email protected] | 3138b26 | 2013-03-08 18:39:08 | [diff] [blame] | 102 | quad->SetNew(shared_quad_state, |
[email protected] | c28df4c1 | 2013-05-22 17:36:49 | [diff] [blame] | 103 | thumb_quad_rect, |
[email protected] | 3138b26 | 2013-03-08 18:39:08 | [diff] [blame] | 104 | opaque_rect, |
[email protected] | 9bf06c7 | 2014-03-07 18:16:24 | [diff] [blame] | 105 | visible_thumb_quad_rect, |
[email protected] | 45b46d38 | 2013-08-14 02:18:58 | [diff] [blame] | 106 | thumb_resource_id, |
[email protected] | 3138b26 | 2013-03-08 18:39:08 | [diff] [blame] | 107 | premultipled_alpha, |
| 108 | uv_top_left, |
| 109 | uv_bottom_right, |
[email protected] | d18b4d6 | 2013-07-12 05:33:49 | [diff] [blame] | 110 | SK_ColorTRANSPARENT, |
[email protected] | 3138b26 | 2013-03-08 18:39:08 | [diff] [blame] | 111 | opacity, |
| 112 | flipped); |
[email protected] | 3138b26 | 2013-03-08 18:39:08 | [diff] [blame] | 113 | } |
| 114 | |
[email protected] | 45b46d38 | 2013-08-14 02:18:58 | [diff] [blame] | 115 | gfx::Rect track_quad_rect = content_bounds_rect; |
vmpstr | 5b88d99 | 2014-09-18 23:25:04 | [diff] [blame] | 116 | gfx::Rect visible_track_quad_rect = |
vmpstr | 11b77b43 | 2014-10-07 20:11:40 | [diff] [blame] | 117 | occlusion_in_content_space.GetUnoccludedContentRect(track_quad_rect); |
[email protected] | 90963ef | 2014-04-17 18:03:29 | [diff] [blame] | 118 | if (track_resource_id && !visible_track_quad_rect.IsEmpty()) { |
[email protected] | 45b46d38 | 2013-08-14 02:18:58 | [diff] [blame] | 119 | gfx::Rect opaque_rect(contents_opaque() ? track_quad_rect : gfx::Rect()); |
[email protected] | 3138b26 | 2013-03-08 18:39:08 | [diff] [blame] | 120 | const float opacity[] = {1.0f, 1.0f, 1.0f, 1.0f}; |
[email protected] | f7030c3 | 2014-07-03 18:54:34 | [diff] [blame] | 121 | TextureDrawQuad* quad = |
| 122 | render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>(); |
[email protected] | 3138b26 | 2013-03-08 18:39:08 | [diff] [blame] | 123 | quad->SetNew(shared_quad_state, |
[email protected] | 45b46d38 | 2013-08-14 02:18:58 | [diff] [blame] | 124 | track_quad_rect, |
[email protected] | 3138b26 | 2013-03-08 18:39:08 | [diff] [blame] | 125 | opaque_rect, |
[email protected] | 9bf06c7 | 2014-03-07 18:16:24 | [diff] [blame] | 126 | visible_track_quad_rect, |
[email protected] | 45b46d38 | 2013-08-14 02:18:58 | [diff] [blame] | 127 | track_resource_id, |
[email protected] | 3138b26 | 2013-03-08 18:39:08 | [diff] [blame] | 128 | premultipled_alpha, |
| 129 | uv_top_left, |
| 130 | uv_bottom_right, |
[email protected] | d18b4d6 | 2013-07-12 05:33:49 | [diff] [blame] | 131 | SK_ColorTRANSPARENT, |
[email protected] | 3138b26 | 2013-03-08 18:39:08 | [diff] [blame] | 132 | opacity, |
| 133 | flipped); |
[email protected] | 3138b26 | 2013-03-08 18:39:08 | [diff] [blame] | 134 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 135 | } |
| 136 | |
[email protected] | 3a83478b | 2013-08-22 20:55:17 | [diff] [blame] | 137 | void PaintedScrollbarLayerImpl::SetThumbThickness(int thumb_thickness) { |
[email protected] | 5493fc4 | 2013-08-15 01:46:22 | [diff] [blame] | 138 | if (thumb_thickness_ == thumb_thickness) |
| 139 | return; |
| 140 | thumb_thickness_ = thumb_thickness; |
| 141 | NoteLayerPropertyChanged(); |
| 142 | } |
| 143 | |
[email protected] | 80413d7 | 2013-08-30 20:25:33 | [diff] [blame] | 144 | int PaintedScrollbarLayerImpl::ThumbThickness() const { |
| 145 | return thumb_thickness_; |
| 146 | } |
| 147 | |
[email protected] | 3a83478b | 2013-08-22 20:55:17 | [diff] [blame] | 148 | void PaintedScrollbarLayerImpl::SetThumbLength(int thumb_length) { |
[email protected] | 5493fc4 | 2013-08-15 01:46:22 | [diff] [blame] | 149 | if (thumb_length_ == thumb_length) |
| 150 | return; |
| 151 | thumb_length_ = thumb_length; |
| 152 | NoteLayerPropertyChanged(); |
| 153 | } |
[email protected] | 80413d7 | 2013-08-30 20:25:33 | [diff] [blame] | 154 | |
| 155 | int PaintedScrollbarLayerImpl::ThumbLength() const { |
| 156 | return thumb_length_; |
| 157 | } |
| 158 | |
[email protected] | 3a83478b | 2013-08-22 20:55:17 | [diff] [blame] | 159 | void PaintedScrollbarLayerImpl::SetTrackStart(int track_start) { |
[email protected] | 5493fc4 | 2013-08-15 01:46:22 | [diff] [blame] | 160 | if (track_start_ == track_start) |
| 161 | return; |
| 162 | track_start_ = track_start; |
| 163 | NoteLayerPropertyChanged(); |
| 164 | } |
| 165 | |
[email protected] | 80413d7 | 2013-08-30 20:25:33 | [diff] [blame] | 166 | int PaintedScrollbarLayerImpl::TrackStart() const { |
| 167 | return track_start_; |
| 168 | } |
| 169 | |
[email protected] | 3a83478b | 2013-08-22 20:55:17 | [diff] [blame] | 170 | void PaintedScrollbarLayerImpl::SetTrackLength(int track_length) { |
[email protected] | 5493fc4 | 2013-08-15 01:46:22 | [diff] [blame] | 171 | if (track_length_ == track_length) |
| 172 | return; |
| 173 | track_length_ = track_length; |
| 174 | NoteLayerPropertyChanged(); |
| 175 | } |
| 176 | |
[email protected] | 80413d7 | 2013-08-30 20:25:33 | [diff] [blame] | 177 | float PaintedScrollbarLayerImpl::TrackLength() const { |
| 178 | return track_length_ + (orientation() == VERTICAL ? vertical_adjust() : 0); |
[email protected] | c28df4c1 | 2013-05-22 17:36:49 | [diff] [blame] | 179 | } |
| 180 | |
[email protected] | 41bee9f0 | 2014-01-09 01:11:35 | [diff] [blame] | 181 | bool PaintedScrollbarLayerImpl::IsThumbResizable() const { |
| 182 | return false; |
| 183 | } |
| 184 | |
[email protected] | 3a83478b | 2013-08-22 20:55:17 | [diff] [blame] | 185 | const char* PaintedScrollbarLayerImpl::LayerTypeAsString() const { |
| 186 | return "cc::PaintedScrollbarLayerImpl"; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 187 | } |
[email protected] | 49306751 | 2012-09-19 23:34:10 | [diff] [blame] | 188 | |
[email protected] | bc5e77c | 2012-11-05 20:00:49 | [diff] [blame] | 189 | } // namespace cc |