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 "ScrollbarLayerChromium.h" | 7 #include "ScrollbarLayerChromium.h" |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "CCLayerTreeHost.h" | 10 #include "CCLayerTreeHost.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 scrollbarLayer->setThumbResourceId(0); | 68 scrollbarLayer->setThumbResourceId(0); |
69 } | 69 } |
70 | 70 |
71 ScrollbarLayerChromium* ScrollbarLayerChromium::toScrollbarLayerChromium() | 71 ScrollbarLayerChromium* ScrollbarLayerChromium::toScrollbarLayerChromium() |
72 { | 72 { |
73 return this; | 73 return this; |
74 } | 74 } |
75 | 75 |
76 class ScrollbarBackgroundPainter : public LayerPainterChromium { | 76 class ScrollbarBackgroundPainter : public LayerPainterChromium { |
77 public: | 77 public: |
78 static PassOwnPtr<ScrollbarBackgroundPainter> create(WebKit::WebScrollbar* s
crollbar, WebKit::WebScrollbarThemePainter painter, WebKit::WebScrollbarThemeGeo
metry* geometry, WebKit::WebScrollbar::ScrollbarPart trackPart) | 78 static scoped_ptr<ScrollbarBackgroundPainter> create(WebKit::WebScrollbar* s
crollbar, WebKit::WebScrollbarThemePainter painter, WebKit::WebScrollbarThemeGeo
metry* geometry, WebKit::WebScrollbar::ScrollbarPart trackPart) |
79 { | 79 { |
80 return adoptPtr(new ScrollbarBackgroundPainter(scrollbar, painter, geome
try, trackPart)); | 80 return make_scoped_ptr(new ScrollbarBackgroundPainter(scrollbar, painter
, geometry, trackPart)); |
81 } | 81 } |
82 | 82 |
83 virtual void paint(SkCanvas* skCanvas, const IntRect& contentRect, FloatRect
&) OVERRIDE | 83 virtual void paint(SkCanvas* skCanvas, const IntRect& contentRect, FloatRect
&) OVERRIDE |
84 { | 84 { |
85 WebKit::WebCanvas* canvas = skCanvas; | 85 WebKit::WebCanvas* canvas = skCanvas; |
86 // The following is a simplification of ScrollbarThemeComposite::paint. | 86 // The following is a simplification of ScrollbarThemeComposite::paint. |
87 WebKit::WebRect contentWebRect(contentRect.x(), contentRect.y(), content
Rect.width(), contentRect.height()); | 87 WebKit::WebRect contentWebRect(contentRect.x(), contentRect.y(), content
Rect.width(), contentRect.height()); |
88 m_painter.paintScrollbarBackground(canvas, contentWebRect); | 88 m_painter.paintScrollbarBackground(canvas, contentWebRect); |
89 | 89 |
90 if (m_geometry->hasButtons(m_scrollbar)) { | 90 if (m_geometry->hasButtons(m_scrollbar)) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 return true; | 136 return true; |
137 } | 137 } |
138 | 138 |
139 IntSize ScrollbarLayerChromium::contentBounds() const | 139 IntSize ScrollbarLayerChromium::contentBounds() const |
140 { | 140 { |
141 return IntSize(lroundf(bounds().width() * contentsScale()), lroundf(bounds()
.height() * contentsScale())); | 141 return IntSize(lroundf(bounds().width() * contentsScale()), lroundf(bounds()
.height() * contentsScale())); |
142 } | 142 } |
143 | 143 |
144 class ScrollbarThumbPainter : public LayerPainterChromium { | 144 class ScrollbarThumbPainter : public LayerPainterChromium { |
145 public: | 145 public: |
146 static PassOwnPtr<ScrollbarThumbPainter> create(WebKit::WebScrollbar* scroll
bar, WebKit::WebScrollbarThemePainter painter, WebKit::WebScrollbarThemeGeometry
* geometry) | 146 static scoped_ptr<ScrollbarThumbPainter> create(WebKit::WebScrollbar* scroll
bar, WebKit::WebScrollbarThemePainter painter, WebKit::WebScrollbarThemeGeometry
* geometry) |
147 { | 147 { |
148 return adoptPtr(new ScrollbarThumbPainter(scrollbar, painter, geometry))
; | 148 return make_scoped_ptr(new ScrollbarThumbPainter(scrollbar, painter, geo
metry)); |
149 } | 149 } |
150 | 150 |
151 virtual void paint(SkCanvas* skCanvas, const IntRect& contentRect, FloatRect
& opaque) OVERRIDE | 151 virtual void paint(SkCanvas* skCanvas, const IntRect& contentRect, FloatRect
& opaque) OVERRIDE |
152 { | 152 { |
153 WebKit::WebCanvas* canvas = skCanvas; | 153 WebKit::WebCanvas* canvas = skCanvas; |
154 | 154 |
155 // Consider the thumb to be at the origin when painting. | 155 // Consider the thumb to be at the origin when painting. |
156 WebRect thumbRect = m_geometry->thumbRect(m_scrollbar); | 156 WebRect thumbRect = m_geometry->thumbRect(m_scrollbar); |
157 thumbRect.x = 0; | 157 thumbRect.x = 0; |
158 thumbRect.y = 0; | 158 thumbRect.y = 0; |
(...skipping 25 matching lines...) Expand all Loading... |
184 } | 184 } |
185 | 185 |
186 LayerChromium::setLayerTreeHost(host); | 186 LayerChromium::setLayerTreeHost(host); |
187 } | 187 } |
188 | 188 |
189 void ScrollbarLayerChromium::createTextureUpdaterIfNeeded() | 189 void ScrollbarLayerChromium::createTextureUpdaterIfNeeded() |
190 { | 190 { |
191 m_textureFormat = layerTreeHost()->rendererCapabilities().bestTextureFormat; | 191 m_textureFormat = layerTreeHost()->rendererCapabilities().bestTextureFormat; |
192 | 192 |
193 if (!m_backTrackUpdater) | 193 if (!m_backTrackUpdater) |
194 m_backTrackUpdater = CachingBitmapCanvasLayerTextureUpdater::Create(Scro
llbarBackgroundPainter::create(m_scrollbar.get(), m_painter, m_geometry.get(), W
ebKit::WebScrollbar::BackTrackPart)); | 194 m_backTrackUpdater = CachingBitmapCanvasLayerTextureUpdater::Create(Scro
llbarBackgroundPainter::create(m_scrollbar.get(), m_painter, m_geometry.get(), W
ebKit::WebScrollbar::BackTrackPart).PassAs<LayerPainterChromium>()); |
195 if (!m_backTrack) | 195 if (!m_backTrack) |
196 m_backTrack = m_backTrackUpdater->createTexture(layerTreeHost()->content
sTextureManager()); | 196 m_backTrack = m_backTrackUpdater->createTexture(layerTreeHost()->content
sTextureManager()); |
197 | 197 |
198 // Only create two-part track if we think the two parts could be different i
n appearance. | 198 // Only create two-part track if we think the two parts could be different i
n appearance. |
199 if (m_scrollbar->isCustomScrollbar()) { | 199 if (m_scrollbar->isCustomScrollbar()) { |
200 if (!m_foreTrackUpdater) | 200 if (!m_foreTrackUpdater) |
201 m_foreTrackUpdater = CachingBitmapCanvasLayerTextureUpdater::Create(
ScrollbarBackgroundPainter::create(m_scrollbar.get(), m_painter, m_geometry.get(
), WebKit::WebScrollbar::ForwardTrackPart)); | 201 m_foreTrackUpdater = CachingBitmapCanvasLayerTextureUpdater::Create(
ScrollbarBackgroundPainter::create(m_scrollbar.get(), m_painter, m_geometry.get(
), WebKit::WebScrollbar::ForwardTrackPart).PassAs<LayerPainterChromium>()); |
202 if (!m_foreTrack) | 202 if (!m_foreTrack) |
203 m_foreTrack = m_foreTrackUpdater->createTexture(layerTreeHost()->con
tentsTextureManager()); | 203 m_foreTrack = m_foreTrackUpdater->createTexture(layerTreeHost()->con
tentsTextureManager()); |
204 } | 204 } |
205 | 205 |
206 if (!m_thumbUpdater) | 206 if (!m_thumbUpdater) |
207 m_thumbUpdater = CachingBitmapCanvasLayerTextureUpdater::Create(Scrollba
rThumbPainter::create(m_scrollbar.get(), m_painter, m_geometry.get())); | 207 m_thumbUpdater = CachingBitmapCanvasLayerTextureUpdater::Create(Scrollba
rThumbPainter::create(m_scrollbar.get(), m_painter, m_geometry.get()).PassAs<Lay
erPainterChromium>()); |
208 if (!m_thumb) | 208 if (!m_thumb) |
209 m_thumb = m_thumbUpdater->createTexture(layerTreeHost()->contentsTexture
Manager()); | 209 m_thumb = m_thumbUpdater->createTexture(layerTreeHost()->contentsTexture
Manager()); |
210 } | 210 } |
211 | 211 |
212 void ScrollbarLayerChromium::updatePart(CachingBitmapCanvasLayerTextureUpdater*
painter, LayerTextureUpdater::Texture* texture, const IntRect& rect, CCTextureUp
dateQueue& queue, CCRenderingStats& stats) | 212 void ScrollbarLayerChromium::updatePart(CachingBitmapCanvasLayerTextureUpdater*
painter, LayerTextureUpdater::Texture* texture, const IntRect& rect, CCTextureUp
dateQueue& queue, CCRenderingStats& stats) |
213 { | 213 { |
214 // Skip painting and uploading if there are no invalidations and | 214 // Skip painting and uploading if there are no invalidations and |
215 // we already have valid texture data. | 215 // we already have valid texture data. |
216 if (texture->texture()->haveBackingTexture() | 216 if (texture->texture()->haveBackingTexture() |
217 && texture->texture()->size() == rect.size() | 217 && texture->texture()->size() == rect.size() |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 updatePart(m_foreTrackUpdater.get(), m_foreTrack.get(), contentRect, que
ue, stats); | 275 updatePart(m_foreTrackUpdater.get(), m_foreTrack.get(), contentRect, que
ue, stats); |
276 | 276 |
277 // Consider the thumb to be at the origin when painting. | 277 // Consider the thumb to be at the origin when painting. |
278 WebKit::WebRect thumbRect = m_geometry->thumbRect(m_scrollbar.get()); | 278 WebKit::WebRect thumbRect = m_geometry->thumbRect(m_scrollbar.get()); |
279 IntRect originThumbRect = layerRectToContentRect(WebKit::WebRect(0, 0, thumb
Rect.width, thumbRect.height)); | 279 IntRect originThumbRect = layerRectToContentRect(WebKit::WebRect(0, 0, thumb
Rect.width, thumbRect.height)); |
280 if (!originThumbRect.isEmpty()) | 280 if (!originThumbRect.isEmpty()) |
281 updatePart(m_thumbUpdater.get(), m_thumb.get(), originThumbRect, queue,
stats); | 281 updatePart(m_thumbUpdater.get(), m_thumb.get(), originThumbRect, queue,
stats); |
282 } | 282 } |
283 | 283 |
284 } | 284 } |
OLD | NEW |