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

Side by Side Diff: cc/pinch_zoom_scrollbar_geometry.cc

Issue 11550035: Implement pinch-zoom scaling for main-frame scrollbars and pinch-zoom overlay scrollbars. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Revised per latest comments. 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
OLDNEW
(Empty)
1 // Copyright 2013 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/pinch_zoom_scrollbar_geometry.h"
6
7 #include "third_party/WebKit/Source/Platform/chromium/public/WebScrollbar.h"
8
9 namespace cc {
10
11 const int PinchZoomScrollbarGeometry::kTrackWidth = 10;
12
13 WebScrollbarThemeGeometry* PinchZoomScrollbarGeometry::clone() const {
14 return static_cast<WebScrollbarThemeGeometry*>(
15 new PinchZoomScrollbarGeometry());
16 }
17
18 int PinchZoomScrollbarGeometry::thumbPosition(WebScrollbar* scrollbar) {
19 if (scrollbar->enabled()) {
20 float size = scrollbar->maximum();
21 if (!size)
22 return 1;
23 int value = std::min(std::max(0, scrollbar->value()), scrollbar->maximum());
24 float pos = (trackLength(scrollbar) - thumbLength(scrollbar)) *
25 value / size;
26 return static_cast<int>(floorf((pos > 0 && pos < 1) ? 1 : pos));
27 }
28 return 0;
29 }
30
31 int PinchZoomScrollbarGeometry::thumbLength(WebScrollbar* scrollbar) {
32 if (!scrollbar->enabled())
33 return 0;
34
35 float size = std::max(scrollbar->size().width, scrollbar->size().height);
36 float proportion = size / scrollbar->totalSize();
37 int trackLength = this->trackLength(scrollbar);
38 int length = proportion * trackLength + 0.5f;
39 length = std::max(length, kTrackWidth);
40 if (length > trackLength)
41 length = 0;
42 return length;
43 }
44
45 int PinchZoomScrollbarGeometry::trackPosition(WebScrollbar*) {
46 return 0;
47 }
48
49 int PinchZoomScrollbarGeometry::trackLength(WebScrollbar* scrollbar) {
50 WebRect track = trackRect(scrollbar);
51 if (scrollbar->orientation() == WebScrollbar::Horizontal)
52 return track.width;
53 else
54 return track.height;
55 }
56
57 bool PinchZoomScrollbarGeometry::hasButtons(WebScrollbar*) {
58 return false;
59 }
60
61 bool PinchZoomScrollbarGeometry::hasThumb(WebScrollbar*) {
62 return true;
63 }
64
65 WebRect PinchZoomScrollbarGeometry::trackRect(WebScrollbar* scrollbar) {
66 int thickness = scrollbarThickness(scrollbar);
67 if (scrollbar->orientation() == WebScrollbar::Horizontal)
68 return WebRect(scrollbar->location().x, scrollbar->location().y,
69 scrollbar->size().width, thickness);
70 else
71 return WebRect(scrollbar->location().x, scrollbar->location().y,
72 thickness, scrollbar->size().height);
73 }
74
75 WebRect PinchZoomScrollbarGeometry::thumbRect(WebScrollbar* scrollbar) {
76 WebRect track = trackRect(scrollbar);
77 int thumbPos = thumbPosition(scrollbar);
78 int thickness = scrollbarThickness(scrollbar);
79 if (scrollbar->orientation() == WebScrollbar::Horizontal)
80 return WebRect(track.x + thumbPos, track.y + (track.height - thickness) / 2,
81 thumbLength(scrollbar), thickness);
82 else
83 return WebRect(track.x + (track.width - thickness) / 2, track.y + thumbPos,
84 thickness, thumbLength(scrollbar));
85 }
86
87 int PinchZoomScrollbarGeometry::minimumThumbLength(WebScrollbar* scrollbar) {
88 return scrollbarThickness(scrollbar);
89 }
90
91 int PinchZoomScrollbarGeometry::scrollbarThickness(WebScrollbar*) {
92 return kTrackWidth;
93 }
94
95 WebRect PinchZoomScrollbarGeometry::backButtonStartRect(WebScrollbar*) {
96 return WebRect();
97 }
98
99 WebRect PinchZoomScrollbarGeometry::backButtonEndRect(WebScrollbar*) {
100 return WebRect();
101 }
102
103 WebRect PinchZoomScrollbarGeometry::forwardButtonStartRect(WebScrollbar*) {
104 return WebRect();
105 }
106
107 WebRect PinchZoomScrollbarGeometry::forwardButtonEndRect(WebScrollbar*) {
108 return WebRect();
109 }
110
111 WebRect PinchZoomScrollbarGeometry::constrainTrackRectToTrackPieces(
112 WebScrollbar*, const WebRect& rect) {
113 return rect;
114 }
115
116 void PinchZoomScrollbarGeometry::splitTrack(
117 WebScrollbar* scrollbar, const WebRect& track, WebRect& startTrack,
118 WebRect& thumb, WebRect& endTrack) {
119 thumb = thumbRect(scrollbar);
120 startTrack = WebRect();
121 endTrack = WebRect();
122 }
123
124 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698