| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "config.h" | |
| 6 | |
| 7 #if USE(ACCELERATED_COMPOSITING) | |
| 8 | |
| 9 #include "CCScrollbarLayerImpl.h" | |
| 10 | |
| 11 #include "CCQuadSink.h" | |
| 12 #include "CCScrollbarAnimationController.h" | |
| 13 #include "CCTextureDrawQuad.h" | |
| 14 | |
| 15 using WebKit::WebRect; | |
| 16 using WebKit::WebScrollbar; | |
| 17 | |
| 18 namespace cc { | |
| 19 | |
| 20 scoped_ptr<CCScrollbarLayerImpl> CCScrollbarLayerImpl::create(int id) | |
| 21 { | |
| 22 return make_scoped_ptr(new CCScrollbarLayerImpl(id)); | |
| 23 } | |
| 24 | |
| 25 CCScrollbarLayerImpl::CCScrollbarLayerImpl(int id) | |
| 26 : CCLayerImpl(id) | |
| 27 , m_scrollbar(this) | |
| 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) | |
| 38 , m_enabled(false) | |
| 39 , m_isCustomScrollbar(false) | |
| 40 , m_isOverlayScrollbar(false) | |
| 41 { | |
| 42 } | |
| 43 | |
| 44 CCScrollbarLayerImpl::~CCScrollbarLayerImpl() | |
| 45 { | |
| 46 } | |
| 47 | |
| 48 void CCScrollbarLayerImpl::setScrollbarGeometry(PassOwnPtr<CCScrollbarGeometryFi
xedThumb> geometry) | |
| 49 { | |
| 50 m_geometry = geometry; | |
| 51 } | |
| 52 | |
| 53 void CCScrollbarLayerImpl::setScrollbarData(WebScrollbar* scrollbar) | |
| 54 { | |
| 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(); | |
| 65 | |
| 66 scrollbar->getTickmarks(m_tickmarks); | |
| 67 | |
| 68 m_geometry->update(scrollbar); | |
| 69 } | |
| 70 | |
| 71 static FloatRect toUVRect(const WebRect& r, const IntRect& bounds) | |
| 72 { | |
| 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<f
loat>(r.height) / bounds.height()); | |
| 75 } | |
| 76 | |
| 77 void CCScrollbarLayerImpl::appendQuads(CCQuadSink& quadSink, CCAppendQuadsData&
appendQuadsData) | |
| 78 { | |
| 79 bool premultipledAlpha = false; | |
| 80 bool flipped = false; | |
| 81 FloatRect uvRect(0, 0, 1, 1); | |
| 82 IntRect boundsRect(IntPoint(), bounds()); | |
| 83 IntRect contentBoundsRect(IntPoint(), contentBounds()); | |
| 84 | |
| 85 CCSharedQuadState* sharedQuadState = quadSink.useSharedQuadState(createShare
dQuadState()); | |
| 86 appendDebugBorderQuad(quadSink, sharedQuadState, appendQuadsData); | |
| 87 | |
| 88 WebRect thumbRect, backTrackRect, foreTrackRect; | |
| 89 m_geometry->splitTrack(&m_scrollbar, m_geometry->trackRect(&m_scrollbar), ba
ckTrackRect, thumbRect, foreTrackRect); | |
| 90 if (!m_geometry->hasThumb(&m_scrollbar)) | |
| 91 thumbRect = WebRect(); | |
| 92 | |
| 93 if (m_thumbResourceId && !thumbRect.isEmpty()) { | |
| 94 scoped_ptr<CCTextureDrawQuad> quad = CCTextureDrawQuad::create(sharedQua
dState, layerRectToContentRect(thumbRect), m_thumbResourceId, premultipledAlpha,
uvRect, flipped); | |
| 95 quad->setNeedsBlending(); | |
| 96 quadSink.append(quad.PassAs<CCDrawQuad>(), appendQuadsData); | |
| 97 } | |
| 98 | |
| 99 if (!m_backTrackResourceId) | |
| 100 return; | |
| 101 | |
| 102 // We only paint the track in two parts if we were given a texture for the f
orward track part. | |
| 103 if (m_foreTrackResourceId && !foreTrackRect.isEmpty()) | |
| 104 quadSink.append(CCTextureDrawQuad::create(sharedQuadState, layerRectToCo
ntentRect(foreTrackRect), m_foreTrackResourceId, premultipledAlpha, toUVRect(for
eTrackRect, boundsRect), flipped).PassAs<CCDrawQuad>(), appendQuadsData); | |
| 105 | |
| 106 // 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 | |
| 107 // fore track quads. The back track texture contains (and displays) the butt
ons. | |
| 108 if (!contentBoundsRect.isEmpty()) | |
| 109 quadSink.append(CCTextureDrawQuad::create(sharedQuadState, IntRect(conte
ntBoundsRect), m_backTrackResourceId, premultipledAlpha, uvRect, flipped).PassAs
<CCDrawQuad>(), appendQuadsData); | |
| 110 } | |
| 111 | |
| 112 void CCScrollbarLayerImpl::didLoseContext() | |
| 113 { | |
| 114 m_backTrackResourceId = 0; | |
| 115 m_foreTrackResourceId = 0; | |
| 116 m_thumbResourceId = 0; | |
| 117 } | |
| 118 | |
| 119 bool CCScrollbarLayerImpl::CCScrollbar::isOverlay() const | |
| 120 { | |
| 121 return m_owner->m_isOverlayScrollbar; | |
| 122 } | |
| 123 | |
| 124 int CCScrollbarLayerImpl::CCScrollbar::value() const | |
| 125 { | |
| 126 return m_owner->m_currentPos; | |
| 127 } | |
| 128 | |
| 129 WebKit::WebPoint CCScrollbarLayerImpl::CCScrollbar::location() const | |
| 130 { | |
| 131 return WebKit::WebPoint(); | |
| 132 } | |
| 133 | |
| 134 WebKit::WebSize CCScrollbarLayerImpl::CCScrollbar::size() const | |
| 135 { | |
| 136 return WebKit::WebSize(m_owner->bounds().width(), m_owner->bounds().height()
); | |
| 137 } | |
| 138 | |
| 139 bool CCScrollbarLayerImpl::CCScrollbar::enabled() const | |
| 140 { | |
| 141 return m_owner->m_enabled; | |
| 142 } | |
| 143 | |
| 144 int CCScrollbarLayerImpl::CCScrollbar::maximum() const | |
| 145 { | |
| 146 return m_owner->m_maximum; | |
| 147 } | |
| 148 | |
| 149 int CCScrollbarLayerImpl::CCScrollbar::totalSize() const | |
| 150 { | |
| 151 return m_owner->m_totalSize; | |
| 152 } | |
| 153 | |
| 154 bool CCScrollbarLayerImpl::CCScrollbar::isScrollViewScrollbar() const | |
| 155 { | |
| 156 return m_owner->m_isScrollViewScrollbar; | |
| 157 } | |
| 158 | |
| 159 bool CCScrollbarLayerImpl::CCScrollbar::isScrollableAreaActive() const | |
| 160 { | |
| 161 return m_owner->m_isScrollableAreaActive; | |
| 162 } | |
| 163 | |
| 164 void CCScrollbarLayerImpl::CCScrollbar::getTickmarks(WebKit::WebVector<WebRect>&
tickmarks) const | |
| 165 { | |
| 166 tickmarks = m_owner->m_tickmarks; | |
| 167 } | |
| 168 | |
| 169 WebScrollbar::ScrollbarControlSize CCScrollbarLayerImpl::CCScrollbar::controlSiz
e() const | |
| 170 { | |
| 171 return m_owner->m_controlSize; | |
| 172 } | |
| 173 | |
| 174 WebScrollbar::ScrollbarPart CCScrollbarLayerImpl::CCScrollbar::pressedPart() con
st | |
| 175 { | |
| 176 return m_owner->m_pressedPart; | |
| 177 } | |
| 178 | |
| 179 WebScrollbar::ScrollbarPart CCScrollbarLayerImpl::CCScrollbar::hoveredPart() con
st | |
| 180 { | |
| 181 return m_owner->m_hoveredPart; | |
| 182 } | |
| 183 | |
| 184 WebScrollbar::ScrollbarOverlayStyle CCScrollbarLayerImpl::CCScrollbar::scrollbar
OverlayStyle() const | |
| 185 { | |
| 186 return m_owner->m_scrollbarOverlayStyle; | |
| 187 } | |
| 188 | |
| 189 WebScrollbar::Orientation CCScrollbarLayerImpl::CCScrollbar::orientation() const | |
| 190 { | |
| 191 return m_owner->m_orientation; | |
| 192 } | |
| 193 | |
| 194 bool CCScrollbarLayerImpl::CCScrollbar::isCustomScrollbar() const | |
| 195 { | |
| 196 return m_owner->m_isCustomScrollbar; | |
| 197 } | |
| 198 | |
| 199 const char* CCScrollbarLayerImpl::layerTypeAsString() const | |
| 200 { | |
| 201 return "ScrollbarLayer"; | |
| 202 } | |
| 203 | |
| 204 } | |
| 205 | |
| 206 #endif // USE(ACCELERATED_COMPOSITING) | |
| OLD | NEW |