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