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 #include "CCScrollbarGeometryFixedThumb.h" |
| 8 |
| 9 #include <cmath> |
| 10 #include <public/WebRect.h> |
| 11 #include <public/WebScrollbar.h> |
| 12 |
| 13 using WebKit::WebRect; |
| 14 using WebKit::WebScrollbar; |
| 15 using WebKit::WebScrollbarThemeGeometry; |
| 16 |
| 17 namespace WebCore { |
| 18 |
| 19 PassOwnPtr<CCScrollbarGeometryFixedThumb> CCScrollbarGeometryFixedThumb::create(
PassOwnPtr<WebScrollbarThemeGeometry> geometry) |
| 20 { |
| 21 return adoptPtr(new CCScrollbarGeometryFixedThumb(geometry)); |
| 22 } |
| 23 |
| 24 CCScrollbarGeometryFixedThumb::~CCScrollbarGeometryFixedThumb() |
| 25 { |
| 26 } |
| 27 |
| 28 void CCScrollbarGeometryFixedThumb::update(WebScrollbar* scrollbar) |
| 29 { |
| 30 int length = CCScrollbarGeometryStub::thumbLength(scrollbar); |
| 31 |
| 32 if (scrollbar->orientation() == WebScrollbar::Horizontal) |
| 33 m_thumbSize = IntSize(length, scrollbar->size().height); |
| 34 else |
| 35 m_thumbSize = IntSize(scrollbar->size().width, length); |
| 36 } |
| 37 |
| 38 WebScrollbarThemeGeometry* CCScrollbarGeometryFixedThumb::clone() const |
| 39 { |
| 40 CCScrollbarGeometryFixedThumb* geometry = new CCScrollbarGeometryFixedThumb(
adoptPtr(CCScrollbarGeometryStub::clone())); |
| 41 geometry->m_thumbSize = m_thumbSize; |
| 42 return geometry; |
| 43 } |
| 44 |
| 45 int CCScrollbarGeometryFixedThumb::thumbLength(WebScrollbar* scrollbar) |
| 46 { |
| 47 if (scrollbar->orientation() == WebScrollbar::Horizontal) |
| 48 return m_thumbSize.width(); |
| 49 return m_thumbSize.height(); |
| 50 } |
| 51 |
| 52 int CCScrollbarGeometryFixedThumb::thumbPosition(WebScrollbar* scrollbar) |
| 53 { |
| 54 if (scrollbar->enabled()) { |
| 55 float size = scrollbar->maximum(); |
| 56 if (!size) |
| 57 return 1; |
| 58 int value = std::min(std::max(0, scrollbar->value()), scrollbar->maximum
()); |
| 59 float pos = (trackLength(scrollbar) - thumbLength(scrollbar)) * value /
size; |
| 60 return static_cast<int>(floorf((pos < 1 && pos > 0) ? 1 : pos)); |
| 61 } |
| 62 return 0; |
| 63 } |
| 64 void CCScrollbarGeometryFixedThumb::splitTrack(WebScrollbar* scrollbar, const We
bRect& unconstrainedTrackRect, WebRect& beforeThumbRect, WebRect& thumbRect, Web
Rect& afterThumbRect) |
| 65 { |
| 66 // This is a reimplementation of ScrollbarThemeComposite::splitTrack. |
| 67 // Because the WebScrollbarThemeGeometry functions call down to native |
| 68 // ScrollbarThemeComposite code which uses ScrollbarThemeComposite virtual |
| 69 // helpers, there's no way to override a helper like thumbLength from |
| 70 // the WebScrollbarThemeGeometry level. So, these three functions |
| 71 // (splitTrack, thumbPosition, thumbLength) are copied here so that the |
| 72 // WebScrollbarThemeGeometry helper functions are used instead and |
| 73 // a fixed size thumbLength can be used. |
| 74 |
| 75 WebRect trackRect = constrainTrackRectToTrackPieces(scrollbar, unconstrained
TrackRect); |
| 76 int thickness = scrollbar->orientation() == WebScrollbar::Horizontal ? scrol
lbar->size().height : scrollbar->size().width; |
| 77 int thumbPos = thumbPosition(scrollbar); |
| 78 if (scrollbar->orientation() == WebScrollbar::Horizontal) { |
| 79 thumbRect = WebRect(trackRect.x + thumbPos, trackRect.y + (trackRect.hei
ght - thickness) / 2, thumbLength(scrollbar), thickness); |
| 80 beforeThumbRect = WebRect(trackRect.x, trackRect.y, thumbPos + thumbRect
.width / 2, trackRect.height); |
| 81 afterThumbRect = WebRect(trackRect.x + beforeThumbRect.width, trackRect.
y, trackRect.x + trackRect.width - beforeThumbRect.x - beforeThumbRect.width, tr
ackRect.height); |
| 82 } else { |
| 83 thumbRect = WebRect(trackRect.x + (trackRect.width - thickness) / 2, tra
ckRect.y + thumbPos, thickness, thumbLength(scrollbar)); |
| 84 beforeThumbRect = WebRect(trackRect.x, trackRect.y, trackRect.width, thu
mbPos + thumbRect.height / 2); |
| 85 afterThumbRect = WebRect(trackRect.x, trackRect.y + beforeThumbRect.heig
ht, trackRect.width, trackRect.y + trackRect.height - beforeThumbRect.y - before
ThumbRect.height); |
| 86 } |
| 87 } |
| 88 |
| 89 CCScrollbarGeometryFixedThumb::CCScrollbarGeometryFixedThumb(PassOwnPtr<WebScrol
lbarThemeGeometry> geometry) |
| 90 : CCScrollbarGeometryStub(geometry) |
| 91 { |
| 92 } |
| 93 |
| 94 } |
OLD | NEW |