Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(703)

Side by Side Diff: cc/scrollbar_geometry_fixed_thumb.cc

Issue 12603013: Part 10 of cc/ directory shuffles: layers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/scrollbar_geometry_fixed_thumb.h ('k') | cc/scrollbar_geometry_stub.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 "cc/scrollbar_geometry_fixed_thumb.h"
6
7 #include <cmath>
8
9 #include "third_party/WebKit/Source/Platform/chromium/public/WebRect.h"
10 #include "third_party/WebKit/Source/Platform/chromium/public/WebScrollbar.h"
11
12 using WebKit::WebRect;
13 using WebKit::WebScrollbar;
14 using WebKit::WebScrollbarThemeGeometry;
15
16 namespace cc {
17
18 scoped_ptr<ScrollbarGeometryFixedThumb> ScrollbarGeometryFixedThumb::create(scop ed_ptr<WebScrollbarThemeGeometry> geometry)
19 {
20 return make_scoped_ptr(new ScrollbarGeometryFixedThumb(geometry.Pass()));
21 }
22
23 ScrollbarGeometryFixedThumb::~ScrollbarGeometryFixedThumb()
24 {
25 }
26
27 WebScrollbarThemeGeometry* ScrollbarGeometryFixedThumb::clone() const
28 {
29 ScrollbarGeometryFixedThumb* geometry = new ScrollbarGeometryFixedThumb(make _scoped_ptr(ScrollbarGeometryStub::clone()));
30 geometry->m_thumbSize = m_thumbSize;
31 return geometry;
32 }
33
34 int ScrollbarGeometryFixedThumb::thumbLength(WebScrollbar* scrollbar)
35 {
36 if (scrollbar->orientation() == WebScrollbar::Horizontal)
37 return m_thumbSize.width();
38 return m_thumbSize.height();
39 }
40
41 int ScrollbarGeometryFixedThumb::thumbPosition(WebScrollbar* scrollbar)
42 {
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));
50 }
51 return 0;
52 }
53 void ScrollbarGeometryFixedThumb::splitTrack(WebScrollbar* scrollbar, const WebR ect& unconstrainedTrackRect, WebRect& beforeThumbRect, WebRect& thumbRect, WebRe ct& afterThumbRect)
54 {
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.
63
64 WebRect trackRect = constrainTrackRectToTrackPieces(scrollbar, unconstrained TrackRect);
65 int thickness = scrollbar->orientation() == WebScrollbar::Horizontal ? scrol lbar->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.hei ght - 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, tr ackRect.height);
71 } else {
72 thumbRect = WebRect(trackRect.x + (trackRect.width - thickness) / 2, tra ckRect.y + thumbPos, thickness, thumbLength(scrollbar));
73 beforeThumbRect = WebRect(trackRect.x, trackRect.y, trackRect.width, thu mbPos + thumbRect.height / 2);
74 afterThumbRect = WebRect(trackRect.x, trackRect.y + beforeThumbRect.heig ht, trackRect.width, trackRect.y + trackRect.height - beforeThumbRect.y - before ThumbRect.height);
75 }
76 }
77
78 ScrollbarGeometryFixedThumb::ScrollbarGeometryFixedThumb(scoped_ptr<WebScrollbar ThemeGeometry> geometry)
79 : ScrollbarGeometryStub(geometry.Pass())
80 {
81 }
82
83 } // namespace cc
OLDNEW
« no previous file with comments | « cc/scrollbar_geometry_fixed_thumb.h ('k') | cc/scrollbar_geometry_stub.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698