| 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 "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include "cc/scrollbar_layer_impl.h" | 7 #include "cc/scrollbar_layer_impl.h" |
| 8 | 8 |
| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 m_isScrollViewScrollbar = scrollbar->isScrollViewScrollbar(); | 59 m_isScrollViewScrollbar = scrollbar->isScrollViewScrollbar(); |
| 60 m_enabled = scrollbar->enabled(); | 60 m_enabled = scrollbar->enabled(); |
| 61 m_isCustomScrollbar = scrollbar->isCustomScrollbar(); | 61 m_isCustomScrollbar = scrollbar->isCustomScrollbar(); |
| 62 m_isOverlayScrollbar = scrollbar->isOverlay(); | 62 m_isOverlayScrollbar = scrollbar->isOverlay(); |
| 63 | 63 |
| 64 scrollbar->getTickmarks(m_tickmarks); | 64 scrollbar->getTickmarks(m_tickmarks); |
| 65 | 65 |
| 66 m_geometry->update(scrollbar); | 66 m_geometry->update(scrollbar); |
| 67 } | 67 } |
| 68 | 68 |
| 69 static FloatRect toUVRect(const WebRect& r, const IntRect& bounds) | 69 static gfx::RectF toUVRect(const gfx::Rect& r, const gfx::Rect& bounds) |
| 70 { | 70 { |
| 71 return FloatRect(static_cast<float>(r.x) / bounds.width(), static_cast<float
>(r.y) / bounds.height(), | 71 return gfx::ScaleRect(r, 1.0 / bounds.width(), 1.0 / bounds.height()); |
| 72 static_cast<float>(r.width) / bounds.width(), static_cast<f
loat>(r.height) / bounds.height()); | |
| 73 } | 72 } |
| 74 | 73 |
| 75 IntRect ScrollbarLayerImpl::scrollbarLayerRectToContentRect(const WebRect& layer
Rect) const | 74 IntRect ScrollbarLayerImpl::scrollbarLayerRectToContentRect(const WebRect& layer
Rect) const |
| 76 { | 75 { |
| 77 // Don't intersect with the bounds as in layerRectToContentRect() because | 76 // Don't intersect with the bounds as in layerRectToContentRect() because |
| 78 // layerRect here might be in coordinates of the containing layer. | 77 // layerRect here might be in coordinates of the containing layer. |
| 79 FloatRect contentRect(layerRect.x, layerRect.y, layerRect.width, layerRect.h
eight); | 78 FloatRect contentRect(layerRect.x, layerRect.y, layerRect.width, layerRect.h
eight); |
| 80 contentRect.scale(contentsScaleX(), contentsScaleY()); | 79 contentRect.scale(contentsScaleX(), contentsScaleY()); |
| 81 return enclosingIntRect(contentRect); | 80 return enclosingIntRect(contentRect); |
| 82 } | 81 } |
| 83 | 82 |
| 84 void ScrollbarLayerImpl::appendQuads(QuadSink& quadSink, AppendQuadsData& append
QuadsData) | 83 void ScrollbarLayerImpl::appendQuads(QuadSink& quadSink, AppendQuadsData& append
QuadsData) |
| 85 { | 84 { |
| 86 bool premultipledAlpha = false; | 85 bool premultipledAlpha = false; |
| 87 bool flipped = false; | 86 bool flipped = false; |
| 88 FloatRect uvRect(0, 0, 1, 1); | 87 gfx::RectF uvRect(0, 0, 1, 1); |
| 89 IntRect boundsRect(IntPoint(), bounds()); | 88 gfx::Rect boundsRect(gfx::Point(), bounds()); |
| 90 IntRect contentBoundsRect(IntPoint(), contentBounds()); | 89 gfx::Rect contentBoundsRect(gfx::Point(), contentBounds()); |
| 91 | 90 |
| 92 SharedQuadState* sharedQuadState = quadSink.useSharedQuadState(createSharedQ
uadState()); | 91 SharedQuadState* sharedQuadState = quadSink.useSharedQuadState(createSharedQ
uadState()); |
| 93 appendDebugBorderQuad(quadSink, sharedQuadState, appendQuadsData); | 92 appendDebugBorderQuad(quadSink, sharedQuadState, appendQuadsData); |
| 94 | 93 |
| 95 WebRect thumbRect, backTrackRect, foreTrackRect; | 94 WebRect thumbRect, backTrackRect, foreTrackRect; |
| 96 m_geometry->splitTrack(&m_scrollbar, m_geometry->trackRect(&m_scrollbar), ba
ckTrackRect, thumbRect, foreTrackRect); | 95 m_geometry->splitTrack(&m_scrollbar, m_geometry->trackRect(&m_scrollbar), ba
ckTrackRect, thumbRect, foreTrackRect); |
| 97 if (!m_geometry->hasThumb(&m_scrollbar)) | 96 if (!m_geometry->hasThumb(&m_scrollbar)) |
| 98 thumbRect = WebRect(); | 97 thumbRect = WebRect(); |
| 99 | 98 |
| 100 if (m_thumbResourceId && !thumbRect.isEmpty()) { | 99 if (m_thumbResourceId && !thumbRect.isEmpty()) { |
| 101 scoped_ptr<TextureDrawQuad> quad = TextureDrawQuad::create(sharedQuadSta
te, scrollbarLayerRectToContentRect(thumbRect), m_thumbResourceId, premultipledA
lpha, uvRect, flipped); | 100 scoped_ptr<TextureDrawQuad> quad = TextureDrawQuad::create(sharedQuadSta
te, scrollbarLayerRectToContentRect(thumbRect), m_thumbResourceId, premultipledA
lpha, uvRect, flipped); |
| 102 quad->setNeedsBlending(); | 101 quad->setNeedsBlending(); |
| 103 quadSink.append(quad.PassAs<DrawQuad>(), appendQuadsData); | 102 quadSink.append(quad.PassAs<DrawQuad>(), appendQuadsData); |
| 104 } | 103 } |
| 105 | 104 |
| 106 if (!m_backTrackResourceId) | 105 if (!m_backTrackResourceId) |
| 107 return; | 106 return; |
| 108 | 107 |
| 109 // We only paint the track in two parts if we were given a texture for the f
orward track part. | 108 // We only paint the track in two parts if we were given a texture for the f
orward track part. |
| 110 if (m_foreTrackResourceId && !foreTrackRect.isEmpty()) | 109 if (m_foreTrackResourceId && !foreTrackRect.isEmpty()) |
| 111 quadSink.append(TextureDrawQuad::create(sharedQuadState, scrollbarLayerR
ectToContentRect(foreTrackRect), m_foreTrackResourceId, premultipledAlpha, toUVR
ect(foreTrackRect, boundsRect), flipped).PassAs<DrawQuad>(), appendQuadsData); | 110 quadSink.append(TextureDrawQuad::create(sharedQuadState, scrollbarLayerR
ectToContentRect(foreTrackRect), m_foreTrackResourceId, premultipledAlpha, toUVR
ect(foreTrackRect, boundsRect), flipped).PassAs<DrawQuad>(), appendQuadsData); |
| 112 | 111 |
| 113 // Order matters here: since the back track texture is being drawn to the en
tire contents rect, we must append it after the thumb and | 112 // Order matters here: since the back track texture is being drawn to the en
tire contents rect, we must append it after the thumb and |
| 114 // fore track quads. The back track texture contains (and displays) the butt
ons. | 113 // fore track quads. The back track texture contains (and displays) the butt
ons. |
| 115 if (!contentBoundsRect.isEmpty()) | 114 if (!contentBoundsRect.IsEmpty()) |
| 116 quadSink.append(TextureDrawQuad::create(sharedQuadState, IntRect(content
BoundsRect), m_backTrackResourceId, premultipledAlpha, uvRect, flipped).PassAs<D
rawQuad>(), appendQuadsData); | 115 quadSink.append(TextureDrawQuad::create(sharedQuadState, gfx::Rect(conte
ntBoundsRect), m_backTrackResourceId, premultipledAlpha, uvRect, flipped).PassAs
<DrawQuad>(), appendQuadsData); |
| 117 } | 116 } |
| 118 | 117 |
| 119 void ScrollbarLayerImpl::didLoseContext() | 118 void ScrollbarLayerImpl::didLoseContext() |
| 120 { | 119 { |
| 121 m_backTrackResourceId = 0; | 120 m_backTrackResourceId = 0; |
| 122 m_foreTrackResourceId = 0; | 121 m_foreTrackResourceId = 0; |
| 123 m_thumbResourceId = 0; | 122 m_thumbResourceId = 0; |
| 124 } | 123 } |
| 125 | 124 |
| 126 bool ScrollbarLayerImpl::Scrollbar::isOverlay() const | 125 bool ScrollbarLayerImpl::Scrollbar::isOverlay() const |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 { | 201 { |
| 203 return m_owner->m_isCustomScrollbar; | 202 return m_owner->m_isCustomScrollbar; |
| 204 } | 203 } |
| 205 | 204 |
| 206 const char* ScrollbarLayerImpl::layerTypeAsString() const | 205 const char* ScrollbarLayerImpl::layerTypeAsString() const |
| 207 { | 206 { |
| 208 return "ScrollbarLayer"; | 207 return "ScrollbarLayer"; |
| 209 } | 208 } |
| 210 | 209 |
| 211 } | 210 } |
| OLD | NEW |