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 "webkit/renderer/compositor_bindings/web_scrollbar_layer_impl.h" | 5 #include "webkit/renderer/compositor_bindings/web_scrollbar_layer_impl.h" |
6 | 6 |
| 7 #include "cc/base/switches.h" |
7 #include "cc/layers/scrollbar_layer.h" | 8 #include "cc/layers/scrollbar_layer.h" |
| 9 #include "cc/layers/scrollbar_layer_interface.h" |
| 10 #include "cc/layers/solid_color_scrollbar_layer.h" |
8 #include "third_party/WebKit/public/platform/WebScrollbar.h" | 11 #include "third_party/WebKit/public/platform/WebScrollbar.h" |
9 #include "webkit/renderer/compositor_bindings/scrollbar_impl.h" | 12 #include "webkit/renderer/compositor_bindings/scrollbar_impl.h" |
10 #include "webkit/renderer/compositor_bindings/web_layer_impl.h" | 13 #include "webkit/renderer/compositor_bindings/web_layer_impl.h" |
11 | 14 |
12 using cc::ScrollbarLayer; | 15 using cc::ScrollbarLayer; |
| 16 using cc::SolidColorScrollbarLayer; |
| 17 |
| 18 namespace { |
| 19 |
| 20 cc::ScrollbarOrientation ConvertOrientation( |
| 21 WebKit::WebScrollbar::Orientation orientation) { |
| 22 return orientation == WebKit::WebScrollbar::Horizontal ? cc::HORIZONTAL |
| 23 : cc::VERTICAL; |
| 24 } |
| 25 |
| 26 const int kSolidColorScrollbarThumbThickness = 3; |
| 27 |
| 28 scoped_refptr<cc::Layer> CreateScrollbarLayer( |
| 29 WebKit::WebScrollbar* scrollbar, |
| 30 WebKit::WebScrollbarThemePainter painter, |
| 31 WebKit::WebScrollbarThemeGeometry* geometry) { |
| 32 if (cc::switches::AreOverlayScrollbarsEnabled()) { |
| 33 return SolidColorScrollbarLayer::Create( |
| 34 ConvertOrientation(scrollbar->orientation()), |
| 35 kSolidColorScrollbarThumbThickness, |
| 36 0); |
| 37 } else { |
| 38 return ScrollbarLayer::Create( |
| 39 scoped_ptr<cc::Scrollbar>(new webkit::ScrollbarImpl( |
| 40 make_scoped_ptr(scrollbar), painter, make_scoped_ptr(geometry))), |
| 41 0); |
| 42 } |
| 43 } |
| 44 |
| 45 } // namespace |
13 | 46 |
14 namespace webkit { | 47 namespace webkit { |
15 | 48 |
16 WebScrollbarLayerImpl::WebScrollbarLayerImpl( | 49 WebScrollbarLayerImpl::WebScrollbarLayerImpl( |
17 WebKit::WebScrollbar* scrollbar, | 50 WebKit::WebScrollbar* scrollbar, |
18 WebKit::WebScrollbarThemePainter painter, | 51 WebKit::WebScrollbarThemePainter painter, |
19 WebKit::WebScrollbarThemeGeometry* geometry) | 52 WebKit::WebScrollbarThemeGeometry* geometry) |
20 : layer_(new WebLayerImpl(ScrollbarLayer::Create( | 53 : layer_(new WebLayerImpl( |
21 scoped_ptr<cc::Scrollbar>(new ScrollbarImpl( | 54 CreateScrollbarLayer(scrollbar, painter, geometry))) {} |
22 make_scoped_ptr(scrollbar), | |
23 painter, | |
24 make_scoped_ptr(geometry))).Pass(), 0))) {} | |
25 | 55 |
26 WebScrollbarLayerImpl::~WebScrollbarLayerImpl() {} | 56 WebScrollbarLayerImpl::~WebScrollbarLayerImpl() {} |
27 | 57 |
28 WebKit::WebLayer* WebScrollbarLayerImpl::layer() { return layer_.get(); } | 58 WebKit::WebLayer* WebScrollbarLayerImpl::layer() { return layer_.get(); } |
29 | 59 |
30 void WebScrollbarLayerImpl::setScrollLayer(WebKit::WebLayer* layer) { | 60 void WebScrollbarLayerImpl::setScrollLayer(WebKit::WebLayer* layer) { |
31 int id = layer ? static_cast<WebLayerImpl*>(layer)->layer()->id() : 0; | 61 int id = layer ? static_cast<WebLayerImpl*>(layer)->layer()->id() : 0; |
32 static_cast<ScrollbarLayer*>(layer_->layer())->SetScrollLayerId(id); | 62 layer_->layer()->ToScrollbarLayer()->SetScrollLayerId(id); |
33 } | 63 } |
34 | 64 |
35 } // namespace webkit | 65 } // namespace webkit |
OLD | NEW |