| 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/scrollbar_layer_impl.h" | 5 #include "cc/scrollbar_layer_impl.h" |
| 6 | 6 |
| 7 #include "cc/layer_tree_impl.h" | 7 #include "cc/layer_tree_impl.h" |
| 8 #include "cc/layer_tree_settings.h" | 8 #include "cc/layer_tree_settings.h" |
| 9 #include "cc/quad_sink.h" | 9 #include "cc/quad_sink.h" |
| 10 #include "cc/scrollbar_animation_controller.h" | 10 #include "cc/scrollbar_animation_controller.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 pressed_part_(WebScrollbar::NoPart), | 46 pressed_part_(WebScrollbar::NoPart), |
| 47 hovered_part_(WebScrollbar::NoPart), | 47 hovered_part_(WebScrollbar::NoPart), |
| 48 is_scrollable_area_active_(false), | 48 is_scrollable_area_active_(false), |
| 49 is_scroll_view_scrollbar_(false), | 49 is_scroll_view_scrollbar_(false), |
| 50 enabled_(false), | 50 enabled_(false), |
| 51 is_custom_scrollbar_(false), | 51 is_custom_scrollbar_(false), |
| 52 is_overlay_scrollbar_(false) {} | 52 is_overlay_scrollbar_(false) {} |
| 53 | 53 |
| 54 ScrollbarLayerImpl::~ScrollbarLayerImpl() {} | 54 ScrollbarLayerImpl::~ScrollbarLayerImpl() {} |
| 55 | 55 |
| 56 ScrollbarLayerImpl* ScrollbarLayerImpl::toScrollbarLayer() { | 56 ScrollbarLayerImpl* ScrollbarLayerImpl::ToScrollbarLayer() { |
| 57 return this; | 57 return this; |
| 58 } | 58 } |
| 59 | 59 |
| 60 void ScrollbarLayerImpl::SetScrollbarData(WebScrollbar* scrollbar) { | 60 void ScrollbarLayerImpl::SetScrollbarData(WebScrollbar* scrollbar) { |
| 61 scrollbar_overlay_style_ = scrollbar->scrollbarOverlayStyle(); | 61 scrollbar_overlay_style_ = scrollbar->scrollbarOverlayStyle(); |
| 62 orientation_ = scrollbar->orientation(); | 62 orientation_ = scrollbar->orientation(); |
| 63 control_size_ = scrollbar->controlSize(); | 63 control_size_ = scrollbar->controlSize(); |
| 64 pressed_part_ = scrollbar->pressedPart(); | 64 pressed_part_ = scrollbar->pressedPart(); |
| 65 hovered_part_ = scrollbar->hoveredPart(); | 65 hovered_part_ = scrollbar->hoveredPart(); |
| 66 is_scrollable_area_active_ = scrollbar->isScrollableAreaActive(); | 66 is_scrollable_area_active_ = scrollbar->isScrollableAreaActive(); |
| 67 is_scroll_view_scrollbar_ = scrollbar->isScrollViewScrollbar(); | 67 is_scroll_view_scrollbar_ = scrollbar->isScrollViewScrollbar(); |
| 68 enabled_ = scrollbar->enabled(); | 68 enabled_ = scrollbar->enabled(); |
| 69 is_custom_scrollbar_ = scrollbar->isCustomScrollbar(); | 69 is_custom_scrollbar_ = scrollbar->isCustomScrollbar(); |
| 70 is_overlay_scrollbar_ = scrollbar->isOverlay(); | 70 is_overlay_scrollbar_ = scrollbar->isOverlay(); |
| 71 | 71 |
| 72 scrollbar->getTickmarks(tickmarks_); | 72 scrollbar->getTickmarks(tickmarks_); |
| 73 } | 73 } |
| 74 | 74 |
| 75 void ScrollbarLayerImpl::SetThumbSize(gfx::Size size) { | 75 void ScrollbarLayerImpl::SetThumbSize(gfx::Size size) { |
| 76 thumb_size_ = size; | 76 thumb_size_ = size; |
| 77 if (!geometry_) { | 77 if (!geometry_) { |
| 78 // In impl-side painting, the ScrollbarLayerImpl in the pending tree | 78 // In impl-side painting, the ScrollbarLayerImpl in the pending tree |
| 79 // simply holds properties that are later pushed to the active tree's | 79 // simply holds properties that are later pushed to the active tree's |
| 80 // layer, but it doesn't hold geometry or append quads. | 80 // layer, but it doesn't hold geometry or append quads. |
| 81 DCHECK(layerTreeImpl()->IsPendingTree()); | 81 DCHECK(layer_tree_impl()->IsPendingTree()); |
| 82 return; | 82 return; |
| 83 } | 83 } |
| 84 geometry_->setThumbSize(size); | 84 geometry_->setThumbSize(size); |
| 85 } | 85 } |
| 86 | 86 |
| 87 float ScrollbarLayerImpl::CurrentPos() const { | 87 float ScrollbarLayerImpl::CurrentPos() const { |
| 88 return current_pos_; | 88 return current_pos_; |
| 89 } | 89 } |
| 90 | 90 |
| 91 int ScrollbarLayerImpl::TotalSize() const { | 91 int ScrollbarLayerImpl::TotalSize() const { |
| 92 return total_size_; | 92 return total_size_; |
| 93 } | 93 } |
| 94 | 94 |
| 95 int ScrollbarLayerImpl::Maximum() const { | 95 int ScrollbarLayerImpl::Maximum() const { |
| 96 return maximum_; | 96 return maximum_; |
| 97 } | 97 } |
| 98 | 98 |
| 99 WebKit::WebScrollbar::Orientation ScrollbarLayerImpl::Orientation() const { | 99 WebKit::WebScrollbar::Orientation ScrollbarLayerImpl::Orientation() const { |
| 100 return orientation_; | 100 return orientation_; |
| 101 } | 101 } |
| 102 | 102 |
| 103 static gfx::RectF ToUVRect(gfx::Rect r, gfx::Rect bounds) { | 103 static gfx::RectF ToUVRect(gfx::Rect r, gfx::Rect bounds) { |
| 104 return gfx::ScaleRect(r, 1.f / bounds.width(), 1.f / bounds.height()); | 104 return gfx::ScaleRect(r, 1.f / bounds.width(), 1.f / bounds.height()); |
| 105 } | 105 } |
| 106 | 106 |
| 107 gfx::Rect ScrollbarLayerImpl::ScrollbarLayerRectToContentRect( | 107 gfx::Rect ScrollbarLayerImpl::ScrollbarLayerRectToContentRect( |
| 108 gfx::Rect layer_rect) const { | 108 gfx::Rect layer_rect) const { |
| 109 // Don't intersect with the bounds as in layerRectToContentRect() because | 109 // Don't intersect with the bounds as in LayerRectToContentRect() because |
| 110 // layer_rect here might be in coordinates of the containing layer. | 110 // layer_rect here might be in coordinates of the containing layer. |
| 111 gfx::RectF content_rect = gfx::ScaleRect(layer_rect, | 111 gfx::RectF content_rect = gfx::ScaleRect(layer_rect, |
| 112 contentsScaleX(), | 112 contents_scale_x(), |
| 113 contentsScaleY()); | 113 contents_scale_y()); |
| 114 return gfx::ToEnclosingRect(content_rect); | 114 return gfx::ToEnclosingRect(content_rect); |
| 115 } | 115 } |
| 116 | 116 |
| 117 scoped_ptr<LayerImpl> ScrollbarLayerImpl::createLayerImpl( | 117 scoped_ptr<LayerImpl> ScrollbarLayerImpl::CreateLayerImpl( |
| 118 LayerTreeImpl* tree_impl) { | 118 LayerTreeImpl* tree_impl) { |
| 119 return ScrollbarLayerImpl::Create(tree_impl, | 119 return ScrollbarLayerImpl::Create(tree_impl, |
| 120 id(), | 120 id(), |
| 121 geometry_.Pass()).PassAs<LayerImpl>(); | 121 geometry_.Pass()).PassAs<LayerImpl>(); |
| 122 } | 122 } |
| 123 | 123 |
| 124 void ScrollbarLayerImpl::pushPropertiesTo(LayerImpl* layer) { | 124 void ScrollbarLayerImpl::PushPropertiesTo(LayerImpl* layer) { |
| 125 LayerImpl::pushPropertiesTo(layer); | 125 LayerImpl::PushPropertiesTo(layer); |
| 126 | 126 |
| 127 ScrollbarLayerImpl* scrollbar_layer = static_cast<ScrollbarLayerImpl*>(layer); | 127 ScrollbarLayerImpl* scrollbar_layer = static_cast<ScrollbarLayerImpl*>(layer); |
| 128 | 128 |
| 129 scrollbar_layer->SetScrollbarData(&scrollbar_); | 129 scrollbar_layer->SetScrollbarData(&scrollbar_); |
| 130 scrollbar_layer->SetThumbSize(thumb_size_); | 130 scrollbar_layer->SetThumbSize(thumb_size_); |
| 131 | 131 |
| 132 scrollbar_layer->set_back_track_resource_id(back_track_resource_id_); | 132 scrollbar_layer->set_back_track_resource_id(back_track_resource_id_); |
| 133 scrollbar_layer->set_fore_track_resource_id(fore_track_resource_id_); | 133 scrollbar_layer->set_fore_track_resource_id(fore_track_resource_id_); |
| 134 scrollbar_layer->set_thumb_resource_id(thumb_resource_id_); | 134 scrollbar_layer->set_thumb_resource_id(thumb_resource_id_); |
| 135 } | 135 } |
| 136 | 136 |
| 137 void ScrollbarLayerImpl::appendQuads(QuadSink& quad_sink, | 137 void ScrollbarLayerImpl::AppendQuads(QuadSink* quad_sink, |
| 138 AppendQuadsData& append_quads_data) { | 138 AppendQuadsData* append_quads_data) { |
| 139 bool premultipled_alpha = true; | 139 bool premultipled_alpha = true; |
| 140 bool flipped = false; | 140 bool flipped = false; |
| 141 gfx::PointF uv_top_left(0.f, 0.f); | 141 gfx::PointF uv_top_left(0.f, 0.f); |
| 142 gfx::PointF uv_bottom_right(1.f, 1.f); | 142 gfx::PointF uv_bottom_right(1.f, 1.f); |
| 143 gfx::Rect boundsRect(gfx::Point(), bounds()); | 143 gfx::Rect boundsRect(bounds()); |
| 144 gfx::Rect contentBoundsRect(gfx::Point(), contentBounds()); | 144 gfx::Rect contentBoundsRect(content_bounds()); |
| 145 | 145 |
| 146 SharedQuadState* shared_quad_state = | 146 SharedQuadState* shared_quad_state = |
| 147 quad_sink.useSharedQuadState(createSharedQuadState()); | 147 quad_sink->useSharedQuadState(CreateSharedQuadState()); |
| 148 appendDebugBorderQuad(quad_sink, shared_quad_state, append_quads_data); | 148 AppendDebugBorderQuad(quad_sink, shared_quad_state, append_quads_data); |
| 149 | 149 |
| 150 WebRect thumb_rect, back_track_rect, foreTrackRect; | 150 WebRect thumb_rect, back_track_rect, foreTrackRect; |
| 151 geometry_->splitTrack(&scrollbar_, | 151 geometry_->splitTrack(&scrollbar_, |
| 152 geometry_->trackRect(&scrollbar_), | 152 geometry_->trackRect(&scrollbar_), |
| 153 back_track_rect, | 153 back_track_rect, |
| 154 thumb_rect, | 154 thumb_rect, |
| 155 foreTrackRect); | 155 foreTrackRect); |
| 156 if (!geometry_->hasThumb(&scrollbar_)) | 156 if (!geometry_->hasThumb(&scrollbar_)) |
| 157 thumb_rect = WebRect(); | 157 thumb_rect = WebRect(); |
| 158 | 158 |
| 159 if (layerTreeImpl()->settings().solidColorScrollbars) { | 159 if (layer_tree_impl()->settings().solidColorScrollbars) { |
| 160 int thickness_override = | 160 int thickness_override = |
| 161 layerTreeImpl()->settings().solidColorScrollbarThicknessDIP; | 161 layer_tree_impl()->settings().solidColorScrollbarThicknessDIP; |
| 162 if (thickness_override != -1) { | 162 if (thickness_override != -1) { |
| 163 if (scrollbar_.orientation() == WebScrollbar::Vertical) | 163 if (scrollbar_.orientation() == WebScrollbar::Vertical) |
| 164 thumb_rect.width = thickness_override; | 164 thumb_rect.width = thickness_override; |
| 165 else | 165 else |
| 166 thumb_rect.height = thickness_override; | 166 thumb_rect.height = thickness_override; |
| 167 } | 167 } |
| 168 gfx::Rect quad_rect(ScrollbarLayerRectToContentRect(thumb_rect)); | 168 gfx::Rect quad_rect(ScrollbarLayerRectToContentRect(thumb_rect)); |
| 169 scoped_ptr<SolidColorDrawQuad> quad = SolidColorDrawQuad::Create(); | 169 scoped_ptr<SolidColorDrawQuad> quad = SolidColorDrawQuad::Create(); |
| 170 quad->SetNew(shared_quad_state, | 170 quad->SetNew(shared_quad_state, |
| 171 quad_rect, | 171 quad_rect, |
| 172 layerTreeImpl()->settings().solidColorScrollbarColor); | 172 layer_tree_impl()->settings().solidColorScrollbarColor); |
| 173 quad_sink.append(quad.PassAs<DrawQuad>(), append_quads_data); | 173 quad_sink->append(quad.PassAs<DrawQuad>(), append_quads_data); |
| 174 return; | 174 return; |
| 175 } | 175 } |
| 176 | 176 |
| 177 if (thumb_resource_id_ && !thumb_rect.isEmpty()) { | 177 if (thumb_resource_id_ && !thumb_rect.isEmpty()) { |
| 178 gfx::Rect quad_rect(ScrollbarLayerRectToContentRect(thumb_rect)); | 178 gfx::Rect quad_rect(ScrollbarLayerRectToContentRect(thumb_rect)); |
| 179 gfx::Rect opaque_rect; | 179 gfx::Rect opaque_rect; |
| 180 const float opacity[] = {1.0f, 1.0f, 1.0f, 1.0f}; | 180 const float opacity[] = {1.0f, 1.0f, 1.0f, 1.0f}; |
| 181 scoped_ptr<TextureDrawQuad> quad = TextureDrawQuad::Create(); | 181 scoped_ptr<TextureDrawQuad> quad = TextureDrawQuad::Create(); |
| 182 quad->SetNew(shared_quad_state, | 182 quad->SetNew(shared_quad_state, |
| 183 quad_rect, | 183 quad_rect, |
| 184 opaque_rect, | 184 opaque_rect, |
| 185 thumb_resource_id_, | 185 thumb_resource_id_, |
| 186 premultipled_alpha, | 186 premultipled_alpha, |
| 187 uv_top_left, | 187 uv_top_left, |
| 188 uv_bottom_right, | 188 uv_bottom_right, |
| 189 opacity, | 189 opacity, |
| 190 flipped); | 190 flipped); |
| 191 quad_sink.append(quad.PassAs<DrawQuad>(), append_quads_data); | 191 quad_sink->append(quad.PassAs<DrawQuad>(), append_quads_data); |
| 192 } | 192 } |
| 193 | 193 |
| 194 if (!back_track_resource_id_) | 194 if (!back_track_resource_id_) |
| 195 return; | 195 return; |
| 196 | 196 |
| 197 // We only paint the track in two parts if we were given a texture for the | 197 // We only paint the track in two parts if we were given a texture for the |
| 198 // forward track part. | 198 // forward track part. |
| 199 if (fore_track_resource_id_ && !foreTrackRect.isEmpty()) { | 199 if (fore_track_resource_id_ && !foreTrackRect.isEmpty()) { |
| 200 gfx::Rect quad_rect(ScrollbarLayerRectToContentRect(foreTrackRect)); | 200 gfx::Rect quad_rect(ScrollbarLayerRectToContentRect(foreTrackRect)); |
| 201 gfx::Rect opaque_rect(contentsOpaque() ? quad_rect : gfx::Rect()); | 201 gfx::Rect opaque_rect(contents_opaque() ? quad_rect : gfx::Rect()); |
| 202 gfx::RectF uv_rect(ToUVRect(foreTrackRect, boundsRect)); | 202 gfx::RectF uv_rect(ToUVRect(foreTrackRect, boundsRect)); |
| 203 const float opacity[] = {1.0f, 1.0f, 1.0f, 1.0f}; | 203 const float opacity[] = {1.0f, 1.0f, 1.0f, 1.0f}; |
| 204 scoped_ptr<TextureDrawQuad> quad = TextureDrawQuad::Create(); | 204 scoped_ptr<TextureDrawQuad> quad = TextureDrawQuad::Create(); |
| 205 quad->SetNew(shared_quad_state, | 205 quad->SetNew(shared_quad_state, |
| 206 quad_rect, | 206 quad_rect, |
| 207 opaque_rect, | 207 opaque_rect, |
| 208 fore_track_resource_id_, | 208 fore_track_resource_id_, |
| 209 premultipled_alpha, | 209 premultipled_alpha, |
| 210 uv_rect.origin(), | 210 uv_rect.origin(), |
| 211 uv_rect.bottom_right(), | 211 uv_rect.bottom_right(), |
| 212 opacity, | 212 opacity, |
| 213 flipped); | 213 flipped); |
| 214 quad_sink.append(quad.PassAs<DrawQuad>(), append_quads_data); | 214 quad_sink->append(quad.PassAs<DrawQuad>(), append_quads_data); |
| 215 } | 215 } |
| 216 | 216 |
| 217 // Order matters here: since the back track texture is being drawn to the | 217 // Order matters here: since the back track texture is being drawn to the |
| 218 // entire contents rect, we must append it after the thumb and fore track | 218 // entire contents rect, we must append it after the thumb and fore track |
| 219 // quads. The back track texture contains (and displays) the buttons. | 219 // quads. The back track texture contains (and displays) the buttons. |
| 220 if (!contentBoundsRect.IsEmpty()) { | 220 if (!contentBoundsRect.IsEmpty()) { |
| 221 gfx::Rect quad_rect(contentBoundsRect); | 221 gfx::Rect quad_rect(contentBoundsRect); |
| 222 gfx::Rect opaque_rect(contentsOpaque() ? quad_rect : gfx::Rect()); | 222 gfx::Rect opaque_rect(contents_opaque() ? quad_rect : gfx::Rect()); |
| 223 const float opacity[] = {1.0f, 1.0f, 1.0f, 1.0f}; | 223 const float opacity[] = {1.0f, 1.0f, 1.0f, 1.0f}; |
| 224 scoped_ptr<TextureDrawQuad> quad = TextureDrawQuad::Create(); | 224 scoped_ptr<TextureDrawQuad> quad = TextureDrawQuad::Create(); |
| 225 quad->SetNew(shared_quad_state, | 225 quad->SetNew(shared_quad_state, |
| 226 quad_rect, | 226 quad_rect, |
| 227 opaque_rect, | 227 opaque_rect, |
| 228 back_track_resource_id_, | 228 back_track_resource_id_, |
| 229 premultipled_alpha, | 229 premultipled_alpha, |
| 230 uv_top_left, | 230 uv_top_left, |
| 231 uv_bottom_right, | 231 uv_bottom_right, |
| 232 opacity, | 232 opacity, |
| 233 flipped); | 233 flipped); |
| 234 quad_sink.append(quad.PassAs<DrawQuad>(), append_quads_data); | 234 quad_sink->append(quad.PassAs<DrawQuad>(), append_quads_data); |
| 235 } | 235 } |
| 236 } | 236 } |
| 237 | 237 |
| 238 void ScrollbarLayerImpl::didLoseOutputSurface() { | 238 void ScrollbarLayerImpl::DidLoseOutputSurface() { |
| 239 back_track_resource_id_ = 0; | 239 back_track_resource_id_ = 0; |
| 240 fore_track_resource_id_ = 0; | 240 fore_track_resource_id_ = 0; |
| 241 thumb_resource_id_ = 0; | 241 thumb_resource_id_ = 0; |
| 242 } | 242 } |
| 243 | 243 |
| 244 bool ScrollbarLayerImpl::Scrollbar::isOverlay() const { | 244 bool ScrollbarLayerImpl::Scrollbar::isOverlay() const { |
| 245 return owner_->is_overlay_scrollbar_; | 245 return owner_->is_overlay_scrollbar_; |
| 246 } | 246 } |
| 247 | 247 |
| 248 int ScrollbarLayerImpl::Scrollbar::value() const { | 248 int ScrollbarLayerImpl::Scrollbar::value() const { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 } | 301 } |
| 302 | 302 |
| 303 WebScrollbar::Orientation ScrollbarLayerImpl::Scrollbar::orientation() const { | 303 WebScrollbar::Orientation ScrollbarLayerImpl::Scrollbar::orientation() const { |
| 304 return owner_->orientation_; | 304 return owner_->orientation_; |
| 305 } | 305 } |
| 306 | 306 |
| 307 bool ScrollbarLayerImpl::Scrollbar::isCustomScrollbar() const { | 307 bool ScrollbarLayerImpl::Scrollbar::isCustomScrollbar() const { |
| 308 return owner_->is_custom_scrollbar_; | 308 return owner_->is_custom_scrollbar_; |
| 309 } | 309 } |
| 310 | 310 |
| 311 const char* ScrollbarLayerImpl::layerTypeAsString() const { | 311 const char* ScrollbarLayerImpl::LayerTypeAsString() const { |
| 312 return "ScrollbarLayer"; | 312 return "ScrollbarLayer"; |
| 313 } | 313 } |
| 314 | 314 |
| 315 } // namespace cc | 315 } // namespace cc |
| OLD | NEW |