Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/layers/scrollbar_layer_impl.h" | 5 #include "cc/layers/scrollbar_layer_impl.h" |
| 6 | 6 |
| 7 #include "cc/animation/scrollbar_animation_controller.h" | 7 #include "cc/animation/scrollbar_animation_controller.h" |
| 8 #include "cc/layers/layer.h" | 8 #include "cc/layers/layer.h" |
| 9 #include "cc/layers/quad_sink.h" | 9 #include "cc/layers/quad_sink.h" |
| 10 #include "cc/quads/solid_color_draw_quad.h" | 10 #include "cc/quads/solid_color_draw_quad.h" |
| 11 #include "cc/quads/texture_draw_quad.h" | 11 #include "cc/quads/texture_draw_quad.h" |
| 12 #include "cc/quads/tile_draw_quad.h" | |
| 12 #include "cc/trees/layer_tree_impl.h" | 13 #include "cc/trees/layer_tree_impl.h" |
| 13 #include "cc/trees/layer_tree_settings.h" | 14 #include "cc/trees/layer_tree_settings.h" |
| 14 #include "ui/gfx/rect_conversions.h" | 15 #include "ui/gfx/rect_conversions.h" |
| 15 | 16 |
| 16 namespace cc { | 17 namespace cc { |
| 17 | 18 |
| 18 scoped_ptr<ScrollbarLayerImpl> ScrollbarLayerImpl::Create( | 19 scoped_ptr<ScrollbarLayerImpl> ScrollbarLayerImpl::Create( |
| 19 LayerTreeImpl* tree_impl, | 20 LayerTreeImpl* tree_impl, |
| 20 int id, | 21 int id, |
| 21 ScrollbarOrientation orientation) { | 22 ScrollbarOrientation orientation) { |
| 22 return make_scoped_ptr(new ScrollbarLayerImpl(tree_impl, | 23 return make_scoped_ptr(new ScrollbarLayerImpl(tree_impl, |
| 23 id, | 24 id, |
| 24 orientation)); | 25 orientation)); |
| 25 } | 26 } |
| 26 | 27 |
| 27 ScrollbarLayerImpl::ScrollbarLayerImpl( | 28 ScrollbarLayerImpl::ScrollbarLayerImpl( |
| 28 LayerTreeImpl* tree_impl, | 29 LayerTreeImpl* tree_impl, |
| 29 int id, | 30 int id, |
| 30 ScrollbarOrientation orientation) | 31 ScrollbarOrientation orientation) |
| 31 : LayerImpl(tree_impl, id), | 32 : LayerImpl(tree_impl, id), |
| 32 track_resource_id_(0), | |
| 33 thumb_resource_id_(0), | |
| 34 current_pos_(0.f), | 33 current_pos_(0.f), |
| 35 maximum_(0), | 34 maximum_(0), |
| 36 thumb_thickness_(0), | 35 thumb_thickness_(0), |
| 37 thumb_length_(0), | 36 thumb_length_(0), |
| 38 track_start_(0), | 37 track_start_(0), |
| 39 track_length_(0), | 38 track_length_(0), |
| 40 orientation_(orientation), | 39 orientation_(orientation), |
| 41 vertical_adjust_(0.f), | 40 vertical_adjust_(0.f), |
| 42 visible_to_total_length_ratio_(1.f), | 41 visible_to_total_length_ratio_(1.f), |
| 43 scroll_layer_id_(Layer::INVALID_ID), | 42 scroll_layer_id_(Layer::INVALID_ID), |
| 43 track_ui_resource_id_(0), | |
| 44 thumb_ui_resource_id_(0), | |
| 44 is_scrollable_area_active_(false), | 45 is_scrollable_area_active_(false), |
| 45 is_scroll_view_scrollbar_(false), | 46 is_scroll_view_scrollbar_(false), |
| 46 enabled_(false), | 47 enabled_(false), |
| 47 is_custom_scrollbar_(false), | 48 is_custom_scrollbar_(false), |
| 48 is_overlay_scrollbar_(false) {} | 49 is_overlay_scrollbar_(false) { |
| 50 } | |
| 49 | 51 |
| 50 ScrollbarLayerImpl::~ScrollbarLayerImpl() {} | 52 ScrollbarLayerImpl::~ScrollbarLayerImpl() {} |
| 51 | 53 |
| 52 ScrollbarLayerImpl* ScrollbarLayerImpl::ToScrollbarLayer() { | 54 ScrollbarLayerImpl* ScrollbarLayerImpl::ToScrollbarLayer() { |
| 53 return this; | 55 return this; |
| 54 } | 56 } |
| 55 | 57 |
| 56 scoped_ptr<LayerImpl> ScrollbarLayerImpl::CreateLayerImpl( | 58 scoped_ptr<LayerImpl> ScrollbarLayerImpl::CreateLayerImpl( |
| 57 LayerTreeImpl* tree_impl) { | 59 LayerTreeImpl* tree_impl) { |
| 58 return ScrollbarLayerImpl::Create(tree_impl, | 60 return ScrollbarLayerImpl::Create(tree_impl, |
| 59 id(), | 61 id(), |
| 60 orientation_).PassAs<LayerImpl>(); | 62 orientation_).PassAs<LayerImpl>(); |
| 61 } | 63 } |
| 62 | 64 |
| 63 void ScrollbarLayerImpl::PushPropertiesTo(LayerImpl* layer) { | 65 void ScrollbarLayerImpl::PushPropertiesTo(LayerImpl* layer) { |
| 64 LayerImpl::PushPropertiesTo(layer); | 66 LayerImpl::PushPropertiesTo(layer); |
| 65 | 67 |
| 66 ScrollbarLayerImpl* scrollbar_layer = static_cast<ScrollbarLayerImpl*>(layer); | 68 ScrollbarLayerImpl* scrollbar_layer = static_cast<ScrollbarLayerImpl*>(layer); |
| 67 | 69 |
| 68 scrollbar_layer->set_thumb_thickness(thumb_thickness_); | 70 scrollbar_layer->set_thumb_thickness(thumb_thickness_); |
| 69 scrollbar_layer->set_thumb_length(thumb_length_); | 71 scrollbar_layer->set_thumb_length(thumb_length_); |
| 70 scrollbar_layer->set_track_start(track_start_); | 72 scrollbar_layer->set_track_start(track_start_); |
| 71 scrollbar_layer->set_track_length(track_length_); | 73 scrollbar_layer->set_track_length(track_length_); |
| 72 | 74 |
| 73 scrollbar_layer->set_track_resource_id(track_resource_id_); | 75 if (scrollbar_layer->track_ui_resource_id_ != track_ui_resource_id_ || |
| 74 scrollbar_layer->set_thumb_resource_id(thumb_resource_id_); | 76 scrollbar_layer->thumb_ui_resource_id_ != thumb_ui_resource_id_) { |
| 77 scrollbar_layer->set_track_ui_resource_id(track_ui_resource_id_); | |
| 78 scrollbar_layer->set_thumb_ui_resource_id(thumb_ui_resource_id_); | |
| 79 | |
| 80 NoteLayerPropertyChanged(); | |
|
aelias_OOO_until_Jul13
2013/07/10 23:07:22
This is never called in PushPropertiesTo anywhere
powei
2013/07/11 23:54:44
Done.
| |
| 81 scrollbar_layer->NoteLayerPropertyChanged(); | |
| 82 } | |
| 75 } | 83 } |
| 76 | 84 |
| 77 bool ScrollbarLayerImpl::WillDraw(DrawMode draw_mode, | 85 bool ScrollbarLayerImpl::WillDraw(DrawMode draw_mode, |
|
aelias_OOO_until_Jul13
2013/07/10 23:07:22
Please revert the unnecessary changes in this meth
powei
2013/07/11 23:54:44
Done.
| |
| 78 ResourceProvider* resource_provider) { | 86 ResourceProvider* resource_provider) { |
| 79 if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE && | 87 LayerImpl::WillDraw(draw_mode, resource_provider); |
| 80 !layer_tree_impl()->settings().solid_color_scrollbars) | 88 return draw_mode != DRAW_MODE_RESOURCELESS_SOFTWARE || |
| 81 return false; | 89 layer_tree_impl()->settings().solid_color_scrollbars; |
| 82 return LayerImpl::WillDraw(draw_mode, resource_provider); | |
| 83 } | 90 } |
| 84 | 91 |
| 85 void ScrollbarLayerImpl::AppendQuads(QuadSink* quad_sink, | 92 void ScrollbarLayerImpl::AppendQuads(QuadSink* quad_sink, |
| 86 AppendQuadsData* append_quads_data) { | 93 AppendQuadsData* append_quads_data) { |
| 87 bool premultipled_alpha = true; | |
| 88 bool flipped = false; | |
| 89 gfx::PointF uv_top_left(0.f, 0.f); | |
| 90 gfx::PointF uv_bottom_right(1.f, 1.f); | |
| 91 gfx::Rect bounds_rect(bounds()); | 94 gfx::Rect bounds_rect(bounds()); |
| 92 gfx::Rect content_bounds_rect(content_bounds()); | 95 gfx::Rect content_bounds_rect(content_bounds()); |
| 93 | 96 |
| 94 SharedQuadState* shared_quad_state = | 97 SharedQuadState* shared_quad_state = |
| 95 quad_sink->UseSharedQuadState(CreateSharedQuadState()); | 98 quad_sink->UseSharedQuadState(CreateSharedQuadState()); |
| 96 AppendDebugBorderQuad(quad_sink, shared_quad_state, append_quads_data); | 99 AppendDebugBorderQuad(quad_sink, shared_quad_state, append_quads_data); |
| 97 | 100 |
| 98 gfx::Rect thumb_quad_rect = ComputeThumbQuadRect(); | 101 gfx::Rect thumb_quad_rect = ComputeThumbQuadRect(); |
| 99 | 102 |
| 100 if (layer_tree_impl()->settings().solid_color_scrollbars) { | 103 if (layer_tree_impl()->settings().solid_color_scrollbars) { |
| 101 scoped_ptr<SolidColorDrawQuad> quad = SolidColorDrawQuad::Create(); | 104 scoped_ptr<SolidColorDrawQuad> quad = SolidColorDrawQuad::Create(); |
| 102 quad->SetNew(shared_quad_state, | 105 quad->SetNew(shared_quad_state, |
| 103 thumb_quad_rect, | 106 thumb_quad_rect, |
| 104 layer_tree_impl()->settings().solid_color_scrollbar_color, | 107 layer_tree_impl()->settings().solid_color_scrollbar_color, |
| 105 false); | 108 false); |
| 106 quad_sink->Append(quad.PassAs<DrawQuad>(), append_quads_data); | 109 quad_sink->Append(quad.PassAs<DrawQuad>(), append_quads_data); |
| 107 return; | 110 return; |
| 108 } | 111 } |
| 109 | 112 |
| 110 if (thumb_resource_id_ && !thumb_quad_rect.IsEmpty()) { | 113 gfx::Rect track_quad_rect = content_bounds_rect; |
| 111 gfx::Rect opaque_rect; | 114 |
| 112 const float opacity[] = {1.0f, 1.0f, 1.0f, 1.0f}; | 115 ResourceProvider::ResourceId thumb_resource_id = |
| 113 scoped_ptr<TextureDrawQuad> quad = TextureDrawQuad::Create(); | 116 layer_tree_impl()->ResourceIdForUIResource(thumb_ui_resource_id_); |
| 114 quad->SetNew(shared_quad_state, | 117 ResourceProvider::ResourceId track_resource_id = |
| 115 thumb_quad_rect, | 118 layer_tree_impl()->ResourceIdForUIResource(track_ui_resource_id_); |
| 116 opaque_rect, | 119 |
| 117 thumb_resource_id_, | 120 if (thumb_resource_id) { |
| 118 premultipled_alpha, | 121 scoped_ptr<TileDrawQuad> thumb_quad = TileDrawQuad::Create(); |
|
aelias_OOO_until_Jul13
2013/07/10 23:07:22
TileDrawQuad is not the right choice here, it's on
powei
2013/07/11 23:54:44
Done.
| |
| 119 uv_top_left, | 122 thumb_quad->SetNew(shared_quad_state, |
| 120 uv_bottom_right, | 123 thumb_quad_rect, |
| 121 opacity, | 124 thumb_quad_rect, |
| 122 flipped); | 125 thumb_resource_id, |
| 123 quad_sink->Append(quad.PassAs<DrawQuad>(), append_quads_data); | 126 gfx::RectF(0, 0, 1, 1), |
| 127 gfx::Size(1, 1), | |
| 128 false); | |
| 129 quad_sink->Append(thumb_quad.PassAs<DrawQuad>(), append_quads_data); | |
| 124 } | 130 } |
| 125 | 131 |
| 126 if (!track_resource_id_) | 132 if (!track_quad_rect.IsEmpty() && track_resource_id) { |
| 127 return; | 133 scoped_ptr<TileDrawQuad> track_quad = TileDrawQuad::Create(); |
| 128 | 134 track_quad->SetNew(shared_quad_state, |
| 129 // Order matters here: since the back track texture is being drawn to the | 135 track_quad_rect, |
| 130 // entire contents rect, we must append it after the thumb and fore track | 136 track_quad_rect, |
| 131 // quads. The back track texture contains (and displays) the buttons. | 137 track_resource_id, |
| 132 if (!content_bounds_rect.IsEmpty()) { | 138 gfx::RectF(0, 0, 1, 1), |
| 133 gfx::Rect quad_rect(content_bounds_rect); | 139 gfx::Size(1, 1), |
| 134 gfx::Rect opaque_rect(contents_opaque() ? quad_rect : gfx::Rect()); | 140 false); |
| 135 const float opacity[] = {1.0f, 1.0f, 1.0f, 1.0f}; | 141 quad_sink->Append(track_quad.PassAs<DrawQuad>(), append_quads_data); |
| 136 scoped_ptr<TextureDrawQuad> quad = TextureDrawQuad::Create(); | |
| 137 quad->SetNew(shared_quad_state, | |
| 138 quad_rect, | |
| 139 opaque_rect, | |
| 140 track_resource_id_, | |
| 141 premultipled_alpha, | |
| 142 uv_top_left, | |
| 143 uv_bottom_right, | |
| 144 opacity, | |
| 145 flipped); | |
| 146 quad_sink->Append(quad.PassAs<DrawQuad>(), append_quads_data); | |
| 147 } | 142 } |
| 148 } | 143 } |
| 149 | 144 |
| 150 ScrollbarOrientation ScrollbarLayerImpl::Orientation() const { | 145 ScrollbarOrientation ScrollbarLayerImpl::Orientation() const { |
| 151 return orientation_; | 146 return orientation_; |
| 152 } | 147 } |
| 153 | 148 |
| 154 float ScrollbarLayerImpl::CurrentPos() const { | 149 float ScrollbarLayerImpl::CurrentPos() const { |
| 155 return current_pos_; | 150 return current_pos_; |
| 156 } | 151 } |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 252 thumb_length, thumb_thickness_); | 247 thumb_length, thumb_thickness_); |
| 253 } else { | 248 } else { |
| 254 thumb_rect = gfx::RectF(0.f, thumb_offset, | 249 thumb_rect = gfx::RectF(0.f, thumb_offset, |
| 255 thumb_thickness_, thumb_length); | 250 thumb_thickness_, thumb_length); |
| 256 } | 251 } |
| 257 | 252 |
| 258 return ScrollbarLayerRectToContentRect(thumb_rect); | 253 return ScrollbarLayerRectToContentRect(thumb_rect); |
| 259 } | 254 } |
| 260 | 255 |
| 261 void ScrollbarLayerImpl::DidLoseOutputSurface() { | 256 void ScrollbarLayerImpl::DidLoseOutputSurface() { |
| 262 track_resource_id_ = 0; | |
| 263 thumb_resource_id_ = 0; | |
| 264 } | 257 } |
| 265 | 258 |
| 266 const char* ScrollbarLayerImpl::LayerTypeAsString() const { | 259 const char* ScrollbarLayerImpl::LayerTypeAsString() const { |
| 267 return "cc::ScrollbarLayerImpl"; | 260 return "cc::ScrollbarLayerImpl"; |
| 268 } | 261 } |
| 269 | 262 |
| 263 void ScrollbarLayerImpl::set_track_ui_resource_id(UIResourceId uid) { | |
| 264 track_ui_resource_id_ = uid; | |
| 265 } | |
| 266 | |
| 267 void ScrollbarLayerImpl::set_thumb_ui_resource_id(UIResourceId uid) { | |
| 268 thumb_ui_resource_id_ = uid; | |
| 269 } | |
| 270 | |
| 270 } // namespace cc | 271 } // namespace cc |
| OLD | NEW |