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
3 // found in the LICENSE file.
7 #if USE(ACCELERATED_COMPOSITING)
9 #include "CCScrollbarLayerImpl.h"
11 #include "CCQuadSink.h"
12 #include "CCScrollbarAnimationController.h"
13 #include "CCTextureDrawQuad.h"
15 using WebKit::WebRect
;
16 using WebKit::WebScrollbar
;
20 PassOwnPtr
<CCScrollbarLayerImpl
> CCScrollbarLayerImpl::create(int id
)
22 return adoptPtr(new CCScrollbarLayerImpl(id
));
25 CCScrollbarLayerImpl::CCScrollbarLayerImpl(int id
)
28 , m_backTrackResourceId(0)
29 , m_foreTrackResourceId(0)
30 , m_thumbResourceId(0)
31 , m_scrollbarOverlayStyle(WebScrollbar::ScrollbarOverlayStyleDefault
)
32 , m_orientation(WebScrollbar::Horizontal
)
33 , m_controlSize(WebScrollbar::RegularScrollbar
)
34 , m_pressedPart(WebScrollbar::NoPart
)
35 , m_hoveredPart(WebScrollbar::NoPart
)
36 , m_isScrollableAreaActive(false)
37 , m_isScrollViewScrollbar(false)
39 , m_isCustomScrollbar(false)
40 , m_isOverlayScrollbar(false)
44 CCScrollbarLayerImpl::~CCScrollbarLayerImpl()
48 void CCScrollbarLayerImpl::setScrollbarGeometry(PassOwnPtr
<CCScrollbarGeometryFixedThumb
> geometry
)
50 m_geometry
= geometry
;
53 void CCScrollbarLayerImpl::setScrollbarData(WebScrollbar
* scrollbar
)
55 m_scrollbarOverlayStyle
= scrollbar
->scrollbarOverlayStyle();
56 m_orientation
= scrollbar
->orientation();
57 m_controlSize
= scrollbar
->controlSize();
58 m_pressedPart
= scrollbar
->pressedPart();
59 m_hoveredPart
= scrollbar
->hoveredPart();
60 m_isScrollableAreaActive
= scrollbar
->isScrollableAreaActive();
61 m_isScrollViewScrollbar
= scrollbar
->isScrollViewScrollbar();
62 m_enabled
= scrollbar
->enabled();
63 m_isCustomScrollbar
= scrollbar
->isCustomScrollbar();
64 m_isOverlayScrollbar
= scrollbar
->isOverlay();
66 scrollbar
->getTickmarks(m_tickmarks
);
68 m_geometry
->update(scrollbar
);
71 static FloatRect
toUVRect(const WebRect
& r
, const IntRect
& bounds
)
73 return FloatRect(static_cast<float>(r
.x
) / bounds
.width(), static_cast<float>(r
.y
) / bounds
.height(),
74 static_cast<float>(r
.width
) / bounds
.width(), static_cast<float>(r
.height
) / bounds
.height());
77 void CCScrollbarLayerImpl::appendQuads(CCQuadSink
& quadSink
, CCAppendQuadsData
& appendQuadsData
)
79 bool premultipledAlpha
= false;
81 FloatRect
uvRect(0, 0, 1, 1);
82 IntRect
boundsRect(IntPoint(), bounds());
83 IntRect
contentBoundsRect(IntPoint(), contentBounds());
85 CCSharedQuadState
* sharedQuadState
= quadSink
.useSharedQuadState(createSharedQuadState());
86 appendDebugBorderQuad(quadSink
, sharedQuadState
, appendQuadsData
);
88 WebRect thumbRect
, backTrackRect
, foreTrackRect
;
89 m_geometry
->splitTrack(&m_scrollbar
, m_geometry
->trackRect(&m_scrollbar
), backTrackRect
, thumbRect
, foreTrackRect
);
90 if (!m_geometry
->hasThumb(&m_scrollbar
))
91 thumbRect
= WebRect();
93 if (m_thumbResourceId
&& !thumbRect
.isEmpty()) {
94 scoped_ptr
<CCTextureDrawQuad
> quad
= CCTextureDrawQuad::create(sharedQuadState
, layerRectToContentRect(thumbRect
), m_thumbResourceId
, premultipledAlpha
, uvRect
, flipped
);
95 quad
->setNeedsBlending();
96 quadSink
.append(quad
.PassAs
<CCDrawQuad
>(), appendQuadsData
);
99 if (!m_backTrackResourceId
)
102 // We only paint the track in two parts if we were given a texture for the forward track part.
103 if (m_foreTrackResourceId
&& !foreTrackRect
.isEmpty())
104 quadSink
.append(CCTextureDrawQuad::create(sharedQuadState
, layerRectToContentRect(foreTrackRect
), m_foreTrackResourceId
, premultipledAlpha
, toUVRect(foreTrackRect
, boundsRect
), flipped
).PassAs
<CCDrawQuad
>(), appendQuadsData
);
106 // Order matters here: since the back track texture is being drawn to the entire contents rect, we must append it after the thumb and
107 // fore track quads. The back track texture contains (and displays) the buttons.
108 if (!contentBoundsRect
.isEmpty())
109 quadSink
.append(CCTextureDrawQuad::create(sharedQuadState
, IntRect(contentBoundsRect
), m_backTrackResourceId
, premultipledAlpha
, uvRect
, flipped
).PassAs
<CCDrawQuad
>(), appendQuadsData
);
112 void CCScrollbarLayerImpl::didLoseContext()
114 m_backTrackResourceId
= 0;
115 m_foreTrackResourceId
= 0;
116 m_thumbResourceId
= 0;
119 bool CCScrollbarLayerImpl::CCScrollbar::isOverlay() const
121 return m_owner
->m_isOverlayScrollbar
;
124 int CCScrollbarLayerImpl::CCScrollbar::value() const
126 return m_owner
->m_currentPos
;
129 WebKit::WebPoint
CCScrollbarLayerImpl::CCScrollbar::location() const
131 return WebKit::WebPoint();
134 WebKit::WebSize
CCScrollbarLayerImpl::CCScrollbar::size() const
136 return WebKit::WebSize(m_owner
->bounds().width(), m_owner
->bounds().height());
139 bool CCScrollbarLayerImpl::CCScrollbar::enabled() const
141 return m_owner
->m_enabled
;
144 int CCScrollbarLayerImpl::CCScrollbar::maximum() const
146 return m_owner
->m_maximum
;
149 int CCScrollbarLayerImpl::CCScrollbar::totalSize() const
151 return m_owner
->m_totalSize
;
154 bool CCScrollbarLayerImpl::CCScrollbar::isScrollViewScrollbar() const
156 return m_owner
->m_isScrollViewScrollbar
;
159 bool CCScrollbarLayerImpl::CCScrollbar::isScrollableAreaActive() const
161 return m_owner
->m_isScrollableAreaActive
;
164 void CCScrollbarLayerImpl::CCScrollbar::getTickmarks(WebKit::WebVector
<WebRect
>& tickmarks
) const
166 tickmarks
= m_owner
->m_tickmarks
;
169 WebScrollbar::ScrollbarControlSize
CCScrollbarLayerImpl::CCScrollbar::controlSize() const
171 return m_owner
->m_controlSize
;
174 WebScrollbar::ScrollbarPart
CCScrollbarLayerImpl::CCScrollbar::pressedPart() const
176 return m_owner
->m_pressedPart
;
179 WebScrollbar::ScrollbarPart
CCScrollbarLayerImpl::CCScrollbar::hoveredPart() const
181 return m_owner
->m_hoveredPart
;
184 WebScrollbar::ScrollbarOverlayStyle
CCScrollbarLayerImpl::CCScrollbar::scrollbarOverlayStyle() const
186 return m_owner
->m_scrollbarOverlayStyle
;
189 WebScrollbar::Orientation
CCScrollbarLayerImpl::CCScrollbar::orientation() const
191 return m_owner
->m_orientation
;
194 bool CCScrollbarLayerImpl::CCScrollbar::isCustomScrollbar() const
196 return m_owner
->m_isCustomScrollbar
;
199 const char* CCScrollbarLayerImpl::layerTypeAsString() const
201 return "ScrollbarLayer";
206 #endif // USE(ACCELERATED_COMPOSITING)