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

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: Fix impl-side painting issues. Created 7 years, 10 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 WebKit {
10
11 WebScrollbarThemeGeometry* PinchZoomScrollbarGeometry::clone() const {
12 return static_cast<WebScrollbarThemeGeometry*>(new PinchZoomScrollbarGeometry( ));
jamesr 2013/02/26 20:48:46 Chromium style line wraps at 80 columns, do that h
wjmaclean 2013/03/01 15:30:32 Done.
13 }
14
15 int PinchZoomScrollbarGeometry::thumbPosition(WebScrollbar* scrollbar) {
16 if (scrollbar->enabled()) {
17 float size = scrollbar->maximum();
18 if (!size)
19 return 1;
20 int value = std::min(std::max(0, scrollbar->value()), scrollbar->maximum());
21 float pos = (trackLength(scrollbar) - thumbLength(scrollbar)) * value / size ;
22 return static_cast<int>(floorf((pos > 0 && pos < 1) ? 1 : pos));
23 }
24 return 0;
25 }
26
27 int PinchZoomScrollbarGeometry::thumbLength(WebScrollbar* scrollbar) {
28 if (!scrollbar->enabled())
29 return 0;
30
31 float size = std::max(scrollbar->size().width, scrollbar->size().height);
32 float proportion = size / scrollbar->totalSize();
33 int trackLength = this->trackLength(scrollbar);
34 int length = proportion * trackLength + 0.5f;
35 length = std::max(length, kTrackWidth);
36 if (length > trackLength)
37 length = 0;
38 return length;
39 }
40
41 int PinchZoomScrollbarGeometry::trackPosition(WebScrollbar*) {
42 return 0;
43 }
44
45 int PinchZoomScrollbarGeometry::trackLength(WebScrollbar* scrollbar) {
46 WebRect track = trackRect(scrollbar);
47 if (scrollbar->orientation() == WebScrollbar::Horizontal)
48 return track.width;
49 else
50 return track.height;
51 }
52
53 WebRect PinchZoomScrollbarGeometry::trackRect(WebScrollbar* scrollbar) {
54 int thickness = scrollbarThickness(scrollbar);
55 if (scrollbar->orientation() == WebScrollbar::Horizontal)
56 return WebRect(scrollbar->location().x, scrollbar->location().y, scrollbar-> size().width, thickness);
57 else
58 return WebRect(scrollbar->location().x, scrollbar->location().y, thickness, scrollbar->size().height);
59 }
60
61 WebRect PinchZoomScrollbarGeometry::thumbRect(WebScrollbar* scrollbar) {
62 WebRect track = trackRect(scrollbar);
63 int thumbPos = thumbPosition(scrollbar);
64 int thickness = scrollbarThickness(scrollbar);
65 if (scrollbar->orientation() == WebScrollbar::Horizontal)
66 return WebRect(track.x + thumbPos, track.y + (track.height - thickness) / 2,
67 thumbLength(scrollbar), thickness);
68 else
69 return WebRect(track.x + (track.width - thickness) / 2, track.y + thumbPos,
70 thickness, thumbLength(scrollbar));
71 }
72
73 int PinchZoomScrollbarGeometry::minimumThumbLength(WebScrollbar* scrollbar) {
74 return scrollbarThickness(scrollbar);
75 }
76
77 int PinchZoomScrollbarGeometry::scrollbarThickness(WebScrollbar*) {
78 return kTrackWidth;
79 }
80
81 WebRect PinchZoomScrollbarGeometry::constrainTrackRectToTrackPieces(WebScrollbar *, const WebRect& rect) {
82 return rect;
83 }
84
85 void PinchZoomScrollbarGeometry::splitTrack(
86 WebScrollbar* scrollbar, const WebRect& track, WebRect& startTrack, WebRect& t humb,
87 WebRect& endTrack) {
88 thumb = thumbRect(scrollbar);
89 startTrack = WebRect();
90 endTrack = WebRect();
91 }
92
93 } // namespace WebKit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698