blob: 5b6968dc16f399c43f459be52fce8d487965d03e [file] [log] [blame]
[email protected]94f206c12012-08-25 00:09:141// 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.
4
[email protected]c4040a522012-10-21 15:01:405#include "cc/scrollbar_layer_impl.h"
[email protected]94f206c12012-08-25 00:09:146
[email protected]55a124d02012-10-22 03:07:137#include "cc/quad_sink.h"
[email protected]c4040a522012-10-21 15:01:408#include "cc/scrollbar_animation_controller.h"
[email protected]4456eee22012-10-19 18:16:389#include "cc/texture_draw_quad.h"
[email protected]d0f98362012-11-01 23:02:3810#include "ui/gfx/rect_conversions.h"
[email protected]94f206c12012-08-25 00:09:1411
12using WebKit::WebRect;
13using WebKit::WebScrollbar;
14
[email protected]9c88e562012-09-14 22:21:3015namespace cc {
[email protected]94f206c12012-08-25 00:09:1416
[email protected]96baf3e2012-10-22 23:09:5517scoped_ptr<ScrollbarLayerImpl> ScrollbarLayerImpl::create(int id)
[email protected]94f206c12012-08-25 00:09:1418{
[email protected]96baf3e2012-10-22 23:09:5519 return make_scoped_ptr(new ScrollbarLayerImpl(id));
[email protected]94f206c12012-08-25 00:09:1420}
21
[email protected]96baf3e2012-10-22 23:09:5522ScrollbarLayerImpl::ScrollbarLayerImpl(int id)
23 : LayerImpl(id)
[email protected]94f206c12012-08-25 00:09:1424 , m_scrollbar(this)
25 , m_backTrackResourceId(0)
26 , m_foreTrackResourceId(0)
27 , m_thumbResourceId(0)
28 , m_scrollbarOverlayStyle(WebScrollbar::ScrollbarOverlayStyleDefault)
29 , m_orientation(WebScrollbar::Horizontal)
30 , m_controlSize(WebScrollbar::RegularScrollbar)
31 , m_pressedPart(WebScrollbar::NoPart)
32 , m_hoveredPart(WebScrollbar::NoPart)
33 , m_isScrollableAreaActive(false)
34 , m_isScrollViewScrollbar(false)
35 , m_enabled(false)
36 , m_isCustomScrollbar(false)
37 , m_isOverlayScrollbar(false)
38{
39}
40
[email protected]96baf3e2012-10-22 23:09:5541ScrollbarLayerImpl::~ScrollbarLayerImpl()
[email protected]493067512012-09-19 23:34:1042{
43}
44
[email protected]96baf3e2012-10-22 23:09:5545void ScrollbarLayerImpl::setScrollbarGeometry(scoped_ptr<ScrollbarGeometryFixedThumb> geometry)
[email protected]94f206c12012-08-25 00:09:1446{
[email protected]31161582012-10-16 21:08:0347 m_geometry = geometry.Pass();
[email protected]94f206c12012-08-25 00:09:1448}
49
[email protected]96baf3e2012-10-22 23:09:5550void ScrollbarLayerImpl::setScrollbarData(WebScrollbar* scrollbar)
[email protected]94f206c12012-08-25 00:09:1451{
52 m_scrollbarOverlayStyle = scrollbar->scrollbarOverlayStyle();
53 m_orientation = scrollbar->orientation();
54 m_controlSize = scrollbar->controlSize();
55 m_pressedPart = scrollbar->pressedPart();
56 m_hoveredPart = scrollbar->hoveredPart();
57 m_isScrollableAreaActive = scrollbar->isScrollableAreaActive();
58 m_isScrollViewScrollbar = scrollbar->isScrollViewScrollbar();
59 m_enabled = scrollbar->enabled();
60 m_isCustomScrollbar = scrollbar->isCustomScrollbar();
61 m_isOverlayScrollbar = scrollbar->isOverlay();
62
63 scrollbar->getTickmarks(m_tickmarks);
[email protected]467b3612012-08-28 07:41:1664
65 m_geometry->update(scrollbar);
[email protected]94f206c12012-08-25 00:09:1466}
67
[email protected]aad0a0072012-11-01 18:15:5868static gfx::RectF toUVRect(const gfx::Rect& r, const gfx::Rect& bounds)
[email protected]94f206c12012-08-25 00:09:1469{
[email protected]aad0a0072012-11-01 18:15:5870 return gfx::ScaleRect(r, 1.0 / bounds.width(), 1.0 / bounds.height());
[email protected]94f206c12012-08-25 00:09:1471}
72
[email protected]d0f98362012-11-01 23:02:3873gfx::Rect ScrollbarLayerImpl::scrollbarLayerRectToContentRect(const gfx::Rect& layerRect) const
[email protected]904e9132012-11-01 00:12:4774{
75 // Don't intersect with the bounds as in layerRectToContentRect() because
76 // layerRect here might be in coordinates of the containing layer.
[email protected]d0f98362012-11-01 23:02:3877 gfx::RectF contentRect = gfx::ScaleRect(layerRect, contentsScaleX(), contentsScaleY());
78 return gfx::ToEnclosingRect(contentRect);
[email protected]904e9132012-11-01 00:12:4779}
80
[email protected]96baf3e2012-10-22 23:09:5581void ScrollbarLayerImpl::appendQuads(QuadSink& quadSink, AppendQuadsData& appendQuadsData)
[email protected]94f206c12012-08-25 00:09:1482{
83 bool premultipledAlpha = false;
84 bool flipped = false;
[email protected]aad0a0072012-11-01 18:15:5885 gfx::RectF uvRect(0, 0, 1, 1);
86 gfx::Rect boundsRect(gfx::Point(), bounds());
87 gfx::Rect contentBoundsRect(gfx::Point(), contentBounds());
[email protected]94f206c12012-08-25 00:09:1488
[email protected]96baf3e2012-10-22 23:09:5589 SharedQuadState* sharedQuadState = quadSink.useSharedQuadState(createSharedQuadState());
[email protected]89228202012-08-29 03:20:3090 appendDebugBorderQuad(quadSink, sharedQuadState, appendQuadsData);
[email protected]94f206c12012-08-25 00:09:1491
92 WebRect thumbRect, backTrackRect, foreTrackRect;
93 m_geometry->splitTrack(&m_scrollbar, m_geometry->trackRect(&m_scrollbar), backTrackRect, thumbRect, foreTrackRect);
94 if (!m_geometry->hasThumb(&m_scrollbar))
95 thumbRect = WebRect();
96
97 if (m_thumbResourceId && !thumbRect.isEmpty()) {
[email protected]35d7e962012-11-17 06:10:0698 gfx::Rect quadRect(scrollbarLayerRectToContentRect(thumbRect));
99 gfx::Rect opaqueRect;
[email protected]c22418b2012-11-20 23:06:26100 scoped_ptr<TextureDrawQuad> quad = TextureDrawQuad::Create();
101 quad->SetNew(sharedQuadState, quadRect, opaqueRect, m_thumbResourceId, premultipledAlpha, uvRect, flipped);
[email protected]96baf3e2012-10-22 23:09:55102 quadSink.append(quad.PassAs<DrawQuad>(), appendQuadsData);
[email protected]94f206c12012-08-25 00:09:14103 }
104
105 if (!m_backTrackResourceId)
106 return;
107
108 // We only paint the track in two parts if we were given a texture for the forward track part.
[email protected]35d7e962012-11-17 06:10:06109 if (m_foreTrackResourceId && !foreTrackRect.isEmpty()) {
110 gfx::Rect quadRect(scrollbarLayerRectToContentRect(foreTrackRect));
111 gfx::Rect opaqueRect(contentsOpaque() ? quadRect : gfx::Rect());
[email protected]c22418b2012-11-20 23:06:26112 scoped_ptr<TextureDrawQuad> quad = TextureDrawQuad::Create();
113 quad->SetNew(sharedQuadState, quadRect, opaqueRect, m_foreTrackResourceId, premultipledAlpha, toUVRect(foreTrackRect, boundsRect), flipped);
114 quadSink.append(quad.PassAs<DrawQuad>(), appendQuadsData);
[email protected]35d7e962012-11-17 06:10:06115 }
[email protected]94f206c12012-08-25 00:09:14116
117 // Order matters here: since the back track texture is being drawn to the entire contents rect, we must append it after the thumb and
118 // fore track quads. The back track texture contains (and displays) the buttons.
[email protected]35d7e962012-11-17 06:10:06119 if (!contentBoundsRect.IsEmpty()) {
120 gfx::Rect quadRect(contentBoundsRect);
121 gfx::Rect opaqueRect(contentsOpaque() ? quadRect : gfx::Rect());
[email protected]c22418b2012-11-20 23:06:26122 scoped_ptr<TextureDrawQuad> quad = TextureDrawQuad::Create();
123 quad->SetNew(sharedQuadState, quadRect, opaqueRect, m_backTrackResourceId, premultipledAlpha, uvRect, flipped);
124 quadSink.append(quad.PassAs<DrawQuad>(), appendQuadsData);
[email protected]35d7e962012-11-17 06:10:06125 }
[email protected]94f206c12012-08-25 00:09:14126}
127
[email protected]96baf3e2012-10-22 23:09:55128void ScrollbarLayerImpl::didLoseContext()
[email protected]94f206c12012-08-25 00:09:14129{
130 m_backTrackResourceId = 0;
131 m_foreTrackResourceId = 0;
132 m_thumbResourceId = 0;
133}
134
[email protected]96baf3e2012-10-22 23:09:55135bool ScrollbarLayerImpl::Scrollbar::isOverlay() const
[email protected]94f206c12012-08-25 00:09:14136{
137 return m_owner->m_isOverlayScrollbar;
138}
139
[email protected]96baf3e2012-10-22 23:09:55140int ScrollbarLayerImpl::Scrollbar::value() const
[email protected]94f206c12012-08-25 00:09:14141{
142 return m_owner->m_currentPos;
143}
144
[email protected]96baf3e2012-10-22 23:09:55145WebKit::WebPoint ScrollbarLayerImpl::Scrollbar::location() const
[email protected]94f206c12012-08-25 00:09:14146{
147 return WebKit::WebPoint();
148}
149
[email protected]96baf3e2012-10-22 23:09:55150WebKit::WebSize ScrollbarLayerImpl::Scrollbar::size() const
[email protected]94f206c12012-08-25 00:09:14151{
[email protected]e1324f252012-09-24 21:39:15152 return WebKit::WebSize(m_owner->bounds().width(), m_owner->bounds().height());
[email protected]94f206c12012-08-25 00:09:14153}
154
[email protected]96baf3e2012-10-22 23:09:55155bool ScrollbarLayerImpl::Scrollbar::enabled() const
[email protected]94f206c12012-08-25 00:09:14156{
157 return m_owner->m_enabled;
158}
159
[email protected]96baf3e2012-10-22 23:09:55160int ScrollbarLayerImpl::Scrollbar::maximum() const
[email protected]94f206c12012-08-25 00:09:14161{
162 return m_owner->m_maximum;
163}
164
[email protected]96baf3e2012-10-22 23:09:55165int ScrollbarLayerImpl::Scrollbar::totalSize() const
[email protected]94f206c12012-08-25 00:09:14166{
167 return m_owner->m_totalSize;
168}
169
[email protected]96baf3e2012-10-22 23:09:55170bool ScrollbarLayerImpl::Scrollbar::isScrollViewScrollbar() const
[email protected]94f206c12012-08-25 00:09:14171{
172 return m_owner->m_isScrollViewScrollbar;
173}
174
[email protected]96baf3e2012-10-22 23:09:55175bool ScrollbarLayerImpl::Scrollbar::isScrollableAreaActive() const
[email protected]94f206c12012-08-25 00:09:14176{
177 return m_owner->m_isScrollableAreaActive;
178}
179
[email protected]96baf3e2012-10-22 23:09:55180void ScrollbarLayerImpl::Scrollbar::getTickmarks(WebKit::WebVector<WebRect>& tickmarks) const
[email protected]94f206c12012-08-25 00:09:14181{
182 tickmarks = m_owner->m_tickmarks;
183}
184
[email protected]96baf3e2012-10-22 23:09:55185WebScrollbar::ScrollbarControlSize ScrollbarLayerImpl::Scrollbar::controlSize() const
[email protected]94f206c12012-08-25 00:09:14186{
187 return m_owner->m_controlSize;
188}
189
[email protected]96baf3e2012-10-22 23:09:55190WebScrollbar::ScrollbarPart ScrollbarLayerImpl::Scrollbar::pressedPart() const
[email protected]94f206c12012-08-25 00:09:14191{
192 return m_owner->m_pressedPart;
193}
194
[email protected]96baf3e2012-10-22 23:09:55195WebScrollbar::ScrollbarPart ScrollbarLayerImpl::Scrollbar::hoveredPart() const
[email protected]94f206c12012-08-25 00:09:14196{
197 return m_owner->m_hoveredPart;
198}
199
[email protected]96baf3e2012-10-22 23:09:55200WebScrollbar::ScrollbarOverlayStyle ScrollbarLayerImpl::Scrollbar::scrollbarOverlayStyle() const
[email protected]94f206c12012-08-25 00:09:14201{
202 return m_owner->m_scrollbarOverlayStyle;
203}
204
[email protected]96baf3e2012-10-22 23:09:55205WebScrollbar::Orientation ScrollbarLayerImpl::Scrollbar::orientation() const
[email protected]94f206c12012-08-25 00:09:14206{
207 return m_owner->m_orientation;
208}
209
[email protected]96baf3e2012-10-22 23:09:55210bool ScrollbarLayerImpl::Scrollbar::isCustomScrollbar() const
[email protected]94f206c12012-08-25 00:09:14211{
212 return m_owner->m_isCustomScrollbar;
213}
214
[email protected]96baf3e2012-10-22 23:09:55215const char* ScrollbarLayerImpl::layerTypeAsString() const
[email protected]493067512012-09-19 23:34:10216{
217 return "ScrollbarLayer";
[email protected]94f206c12012-08-25 00:09:14218}
[email protected]493067512012-09-19 23:34:10219
[email protected]bc5e77c2012-11-05 20:00:49220} // namespace cc