[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 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 | |
[email protected] | c4040a52 | 2012-10-21 15:01:40 | [diff] [blame] | 5 | #include "cc/scrollbar_layer_impl.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6 | |
[email protected] | 55a124d0 | 2012-10-22 03:07:13 | [diff] [blame] | 7 | #include "cc/quad_sink.h" |
[email protected] | c4040a52 | 2012-10-21 15:01:40 | [diff] [blame] | 8 | #include "cc/scrollbar_animation_controller.h" |
[email protected] | 4456eee2 | 2012-10-19 18:16:38 | [diff] [blame] | 9 | #include "cc/texture_draw_quad.h" |
[email protected] | d0f9836 | 2012-11-01 23:02:38 | [diff] [blame] | 10 | #include "ui/gfx/rect_conversions.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 11 | |
| 12 | using WebKit::WebRect; |
| 13 | using WebKit::WebScrollbar; |
| 14 | |
[email protected] | 9c88e56 | 2012-09-14 22:21:30 | [diff] [blame] | 15 | namespace cc { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 16 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 17 | scoped_ptr<ScrollbarLayerImpl> ScrollbarLayerImpl::create(int id) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 18 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 19 | return make_scoped_ptr(new ScrollbarLayerImpl(id)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 20 | } |
| 21 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 22 | ScrollbarLayerImpl::ScrollbarLayerImpl(int id) |
| 23 | : LayerImpl(id) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 24 | , 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] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 41 | ScrollbarLayerImpl::~ScrollbarLayerImpl() |
[email protected] | 49306751 | 2012-09-19 23:34:10 | [diff] [blame] | 42 | { |
| 43 | } |
| 44 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 45 | void ScrollbarLayerImpl::setScrollbarGeometry(scoped_ptr<ScrollbarGeometryFixedThumb> geometry) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 46 | { |
[email protected] | 3116158 | 2012-10-16 21:08:03 | [diff] [blame] | 47 | m_geometry = geometry.Pass(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 48 | } |
| 49 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 50 | void ScrollbarLayerImpl::setScrollbarData(WebScrollbar* scrollbar) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 51 | { |
| 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] | 467b361 | 2012-08-28 07:41:16 | [diff] [blame] | 64 | |
| 65 | m_geometry->update(scrollbar); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 66 | } |
| 67 | |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 68 | static gfx::RectF toUVRect(const gfx::Rect& r, const gfx::Rect& bounds) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 69 | { |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 70 | return gfx::ScaleRect(r, 1.0 / bounds.width(), 1.0 / bounds.height()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 71 | } |
| 72 | |
[email protected] | d0f9836 | 2012-11-01 23:02:38 | [diff] [blame] | 73 | gfx::Rect ScrollbarLayerImpl::scrollbarLayerRectToContentRect(const gfx::Rect& layerRect) const |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 74 | { |
| 75 | // Don't intersect with the bounds as in layerRectToContentRect() because |
| 76 | // layerRect here might be in coordinates of the containing layer. |
[email protected] | d0f9836 | 2012-11-01 23:02:38 | [diff] [blame] | 77 | gfx::RectF contentRect = gfx::ScaleRect(layerRect, contentsScaleX(), contentsScaleY()); |
| 78 | return gfx::ToEnclosingRect(contentRect); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 79 | } |
| 80 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 81 | void ScrollbarLayerImpl::appendQuads(QuadSink& quadSink, AppendQuadsData& appendQuadsData) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 82 | { |
| 83 | bool premultipledAlpha = false; |
| 84 | bool flipped = false; |
[email protected] | aad0a007 | 2012-11-01 18:15:58 | [diff] [blame] | 85 | gfx::RectF uvRect(0, 0, 1, 1); |
| 86 | gfx::Rect boundsRect(gfx::Point(), bounds()); |
| 87 | gfx::Rect contentBoundsRect(gfx::Point(), contentBounds()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 88 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 89 | SharedQuadState* sharedQuadState = quadSink.useSharedQuadState(createSharedQuadState()); |
[email protected] | 8922820 | 2012-08-29 03:20:30 | [diff] [blame] | 90 | appendDebugBorderQuad(quadSink, sharedQuadState, appendQuadsData); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 91 | |
| 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] | 35d7e96 | 2012-11-17 06:10:06 | [diff] [blame] | 98 | gfx::Rect quadRect(scrollbarLayerRectToContentRect(thumbRect)); |
| 99 | gfx::Rect opaqueRect; |
[email protected] | c22418b | 2012-11-20 23:06:26 | [diff] [blame] | 100 | scoped_ptr<TextureDrawQuad> quad = TextureDrawQuad::Create(); |
| 101 | quad->SetNew(sharedQuadState, quadRect, opaqueRect, m_thumbResourceId, premultipledAlpha, uvRect, flipped); |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 102 | quadSink.append(quad.PassAs<DrawQuad>(), appendQuadsData); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 103 | } |
| 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] | 35d7e96 | 2012-11-17 06:10:06 | [diff] [blame] | 109 | if (m_foreTrackResourceId && !foreTrackRect.isEmpty()) { |
| 110 | gfx::Rect quadRect(scrollbarLayerRectToContentRect(foreTrackRect)); |
| 111 | gfx::Rect opaqueRect(contentsOpaque() ? quadRect : gfx::Rect()); |
[email protected] | c22418b | 2012-11-20 23:06:26 | [diff] [blame] | 112 | 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] | 35d7e96 | 2012-11-17 06:10:06 | [diff] [blame] | 115 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 116 | |
| 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] | 35d7e96 | 2012-11-17 06:10:06 | [diff] [blame] | 119 | if (!contentBoundsRect.IsEmpty()) { |
| 120 | gfx::Rect quadRect(contentBoundsRect); |
| 121 | gfx::Rect opaqueRect(contentsOpaque() ? quadRect : gfx::Rect()); |
[email protected] | c22418b | 2012-11-20 23:06:26 | [diff] [blame] | 122 | 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] | 35d7e96 | 2012-11-17 06:10:06 | [diff] [blame] | 125 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 126 | } |
| 127 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 128 | void ScrollbarLayerImpl::didLoseContext() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 129 | { |
| 130 | m_backTrackResourceId = 0; |
| 131 | m_foreTrackResourceId = 0; |
| 132 | m_thumbResourceId = 0; |
| 133 | } |
| 134 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 135 | bool ScrollbarLayerImpl::Scrollbar::isOverlay() const |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 136 | { |
| 137 | return m_owner->m_isOverlayScrollbar; |
| 138 | } |
| 139 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 140 | int ScrollbarLayerImpl::Scrollbar::value() const |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 141 | { |
| 142 | return m_owner->m_currentPos; |
| 143 | } |
| 144 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 145 | WebKit::WebPoint ScrollbarLayerImpl::Scrollbar::location() const |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 146 | { |
| 147 | return WebKit::WebPoint(); |
| 148 | } |
| 149 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 150 | WebKit::WebSize ScrollbarLayerImpl::Scrollbar::size() const |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 151 | { |
[email protected] | e1324f25 | 2012-09-24 21:39:15 | [diff] [blame] | 152 | return WebKit::WebSize(m_owner->bounds().width(), m_owner->bounds().height()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 153 | } |
| 154 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 155 | bool ScrollbarLayerImpl::Scrollbar::enabled() const |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 156 | { |
| 157 | return m_owner->m_enabled; |
| 158 | } |
| 159 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 160 | int ScrollbarLayerImpl::Scrollbar::maximum() const |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 161 | { |
| 162 | return m_owner->m_maximum; |
| 163 | } |
| 164 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 165 | int ScrollbarLayerImpl::Scrollbar::totalSize() const |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 166 | { |
| 167 | return m_owner->m_totalSize; |
| 168 | } |
| 169 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 170 | bool ScrollbarLayerImpl::Scrollbar::isScrollViewScrollbar() const |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 171 | { |
| 172 | return m_owner->m_isScrollViewScrollbar; |
| 173 | } |
| 174 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 175 | bool ScrollbarLayerImpl::Scrollbar::isScrollableAreaActive() const |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 176 | { |
| 177 | return m_owner->m_isScrollableAreaActive; |
| 178 | } |
| 179 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 180 | void ScrollbarLayerImpl::Scrollbar::getTickmarks(WebKit::WebVector<WebRect>& tickmarks) const |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 181 | { |
| 182 | tickmarks = m_owner->m_tickmarks; |
| 183 | } |
| 184 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 185 | WebScrollbar::ScrollbarControlSize ScrollbarLayerImpl::Scrollbar::controlSize() const |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 186 | { |
| 187 | return m_owner->m_controlSize; |
| 188 | } |
| 189 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 190 | WebScrollbar::ScrollbarPart ScrollbarLayerImpl::Scrollbar::pressedPart() const |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 191 | { |
| 192 | return m_owner->m_pressedPart; |
| 193 | } |
| 194 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 195 | WebScrollbar::ScrollbarPart ScrollbarLayerImpl::Scrollbar::hoveredPart() const |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 196 | { |
| 197 | return m_owner->m_hoveredPart; |
| 198 | } |
| 199 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 200 | WebScrollbar::ScrollbarOverlayStyle ScrollbarLayerImpl::Scrollbar::scrollbarOverlayStyle() const |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 201 | { |
| 202 | return m_owner->m_scrollbarOverlayStyle; |
| 203 | } |
| 204 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 205 | WebScrollbar::Orientation ScrollbarLayerImpl::Scrollbar::orientation() const |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 206 | { |
| 207 | return m_owner->m_orientation; |
| 208 | } |
| 209 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 210 | bool ScrollbarLayerImpl::Scrollbar::isCustomScrollbar() const |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 211 | { |
| 212 | return m_owner->m_isCustomScrollbar; |
| 213 | } |
| 214 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 215 | const char* ScrollbarLayerImpl::layerTypeAsString() const |
[email protected] | 49306751 | 2012-09-19 23:34:10 | [diff] [blame] | 216 | { |
| 217 | return "ScrollbarLayer"; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 218 | } |
[email protected] | 49306751 | 2012-09-19 23:34:10 | [diff] [blame] | 219 | |
[email protected] | bc5e77c | 2012-11-05 20:00:49 | [diff] [blame] | 220 | } // namespace cc |