add a use_alsa gyp setting
[chromium-blink-merge.git] / cc / scrollbar_geometry_fixed_thumb.cc
blob4e5342271bd69db8d7839f5ce0a717b0ec35e422
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.
5 #include "cc/scrollbar_geometry_fixed_thumb.h"
7 #include <cmath>
9 #include "third_party/WebKit/Source/Platform/chromium/public/WebRect.h"
10 #include "third_party/WebKit/Source/Platform/chromium/public/WebScrollbar.h"
12 using WebKit::WebRect;
13 using WebKit::WebScrollbar;
14 using WebKit::WebScrollbarThemeGeometry;
16 namespace cc {
18 scoped_ptr<ScrollbarGeometryFixedThumb> ScrollbarGeometryFixedThumb::create(scoped_ptr<WebScrollbarThemeGeometry> geometry)
20 return make_scoped_ptr(new ScrollbarGeometryFixedThumb(geometry.Pass()));
23 ScrollbarGeometryFixedThumb::~ScrollbarGeometryFixedThumb()
27 WebScrollbarThemeGeometry* ScrollbarGeometryFixedThumb::clone() const
29 ScrollbarGeometryFixedThumb* geometry = new ScrollbarGeometryFixedThumb(make_scoped_ptr(ScrollbarGeometryStub::clone()));
30 geometry->m_thumbSize = m_thumbSize;
31 return geometry;
34 int ScrollbarGeometryFixedThumb::thumbLength(WebScrollbar* scrollbar)
36 if (scrollbar->orientation() == WebScrollbar::Horizontal)
37 return m_thumbSize.width();
38 return m_thumbSize.height();
41 int ScrollbarGeometryFixedThumb::thumbPosition(WebScrollbar* scrollbar)
43 if (scrollbar->enabled()) {
44 float size = scrollbar->maximum();
45 if (!size)
46 return 1;
47 int value = std::min(std::max(0, scrollbar->value()), scrollbar->maximum());
48 float pos = (trackLength(scrollbar) - thumbLength(scrollbar)) * value / size;
49 return static_cast<int>(floorf((pos < 1 && pos > 0) ? 1 : pos));
51 return 0;
53 void ScrollbarGeometryFixedThumb::splitTrack(WebScrollbar* scrollbar, const WebRect& unconstrainedTrackRect, WebRect& beforeThumbRect, WebRect& thumbRect, WebRect& afterThumbRect)
55 // This is a reimplementation of ScrollbarThemeComposite::splitTrack.
56 // Because the WebScrollbarThemeGeometry functions call down to native
57 // ScrollbarThemeComposite code which uses ScrollbarThemeComposite virtual
58 // helpers, there's no way to override a helper like thumbLength from
59 // the WebScrollbarThemeGeometry level. So, these three functions
60 // (splitTrack, thumbPosition, thumbLength) are copied here so that the
61 // WebScrollbarThemeGeometry helper functions are used instead and
62 // a fixed size thumbLength can be used.
64 WebRect trackRect = constrainTrackRectToTrackPieces(scrollbar, unconstrainedTrackRect);
65 int thickness = scrollbar->orientation() == WebScrollbar::Horizontal ? scrollbar->size().height : scrollbar->size().width;
66 int thumbPos = thumbPosition(scrollbar);
67 if (scrollbar->orientation() == WebScrollbar::Horizontal) {
68 thumbRect = WebRect(trackRect.x + thumbPos, trackRect.y + (trackRect.height - thickness) / 2, thumbLength(scrollbar), thickness);
69 beforeThumbRect = WebRect(trackRect.x, trackRect.y, thumbPos + thumbRect.width / 2, trackRect.height);
70 afterThumbRect = WebRect(trackRect.x + beforeThumbRect.width, trackRect.y, trackRect.x + trackRect.width - beforeThumbRect.x - beforeThumbRect.width, trackRect.height);
71 } else {
72 thumbRect = WebRect(trackRect.x + (trackRect.width - thickness) / 2, trackRect.y + thumbPos, thickness, thumbLength(scrollbar));
73 beforeThumbRect = WebRect(trackRect.x, trackRect.y, trackRect.width, thumbPos + thumbRect.height / 2);
74 afterThumbRect = WebRect(trackRect.x, trackRect.y + beforeThumbRect.height, trackRect.width, trackRect.y + trackRect.height - beforeThumbRect.y - beforeThumbRect.height);
78 ScrollbarGeometryFixedThumb::ScrollbarGeometryFixedThumb(scoped_ptr<WebScrollbarThemeGeometry> geometry)
79 : ScrollbarGeometryStub(geometry.Pass())
83 } // namespace cc