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

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: Rebase to fix collision with solid colour scrollbars patch. 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/pinch_zoom_scrollbar_geometry.h ('k') | cc/pinch_zoom_scrollbar_painter.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 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 max_value = scrollbar->maximum();
21 if (!max_value)
22 return 1;
23 int value = std::min(std::max(0, scrollbar->value()), scrollbar->maximum());
24 float pos = (trackLength(scrollbar) - thumbLength(scrollbar)) *
25 value / max_value;
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 track_length = this->trackLength(scrollbar);
38 int length = proportion * track_length + 0.5f;
39 length = std::max(length, kTrackWidth);
40 if (length > track_length)
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
76 WebRect PinchZoomScrollbarGeometry::thumbRect(WebScrollbar* scrollbar) {
77 WebRect track = trackRect(scrollbar);
78 int thumb_pos = thumbPosition(scrollbar);
79 int thickness = scrollbarThickness(scrollbar);
80 if (scrollbar->orientation() == WebScrollbar::Horizontal) {
81 return WebRect(track.x + thumb_pos, track.y + (track.height - thickness) /
82 2, thumbLength(scrollbar), thickness);
83 } else {
84 return WebRect(track.x + (track.width - thickness) / 2, track.y + thumb_pos,
85 thickness, thumbLength(scrollbar));
86 }
87 }
88
89 int PinchZoomScrollbarGeometry::minimumThumbLength(WebScrollbar* scrollbar) {
90 return scrollbarThickness(scrollbar);
91 }
92
93 int PinchZoomScrollbarGeometry::scrollbarThickness(WebScrollbar*) {
94 return kTrackWidth;
95 }
96
97 WebRect PinchZoomScrollbarGeometry::backButtonStartRect(WebScrollbar*) {
98 return WebRect();
99 }
100
101 WebRect PinchZoomScrollbarGeometry::backButtonEndRect(WebScrollbar*) {
102 return WebRect();
103 }
104
105 WebRect PinchZoomScrollbarGeometry::forwardButtonStartRect(WebScrollbar*) {
106 return WebRect();
107 }
108
109 WebRect PinchZoomScrollbarGeometry::forwardButtonEndRect(WebScrollbar*) {
110 return WebRect();
111 }
112
113 WebRect PinchZoomScrollbarGeometry::constrainTrackRectToTrackPieces(
114 WebScrollbar*, const WebRect& rect) {
115 return rect;
116 }
117
118 void PinchZoomScrollbarGeometry::splitTrack(
119 WebScrollbar* scrollbar, const WebRect& track, WebRect& start_track,
120 WebRect& thumb, WebRect& end_track) {
121 thumb = thumbRect(scrollbar);
122 start_track = WebRect();
123 end_track = WebRect();
124 }
125
126 } // namespace cc
OLDNEW
« no previous file with comments | « cc/pinch_zoom_scrollbar_geometry.h ('k') | cc/pinch_zoom_scrollbar_painter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698