1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "cc/input/pinch_zoom_scrollbar_geometry.h"
#include <algorithm>
#include "third_party/WebKit/Source/Platform/chromium/public/WebScrollbar.h"
namespace cc {
const int PinchZoomScrollbarGeometry::kTrackWidth = 10;
WebScrollbarThemeGeometry* PinchZoomScrollbarGeometry::clone() const {
return static_cast<WebScrollbarThemeGeometry*>(
new PinchZoomScrollbarGeometry());
}
int PinchZoomScrollbarGeometry::thumbPosition(WebScrollbar* scrollbar) {
if (scrollbar->enabled()) {
float max_value = scrollbar->maximum();
if (!max_value)
return 1;
int value = std::min(std::max(0, scrollbar->value()), scrollbar->maximum());
float pos = (trackLength(scrollbar) - thumbLength(scrollbar)) *
value / max_value;
return static_cast<int>(floorf((pos > 0 && pos < 1) ? 1 : pos));
}
return 0;
}
int PinchZoomScrollbarGeometry::thumbLength(WebScrollbar* scrollbar) {
if (!scrollbar->enabled())
return 0;
float size = std::max(scrollbar->size().width, scrollbar->size().height);
float proportion = size / scrollbar->totalSize();
int track_length = this->trackLength(scrollbar);
int length = proportion * track_length + 0.5f;
length = std::max(length, kTrackWidth);
if (length > track_length)
length = 0;
return length;
}
int PinchZoomScrollbarGeometry::trackPosition(WebScrollbar* scrollbar) {
return 0;
}
int PinchZoomScrollbarGeometry::trackLength(WebScrollbar* scrollbar) {
WebRect track = trackRect(scrollbar);
if (scrollbar->orientation() == WebScrollbar::Horizontal)
return track.width;
else
return track.height;
}
bool PinchZoomScrollbarGeometry::hasButtons(WebScrollbar* scrollbar) {
return false;
}
bool PinchZoomScrollbarGeometry::hasThumb(WebScrollbar* scrollbar) {
return true;
}
WebRect PinchZoomScrollbarGeometry::trackRect(WebScrollbar* scrollbar) {
int thickness = scrollbarThickness(scrollbar);
if (scrollbar->orientation() == WebScrollbar::Horizontal) {
return WebRect(scrollbar->location().x, scrollbar->location().y,
scrollbar->size().width, thickness);
} else {
return WebRect(scrollbar->location().x, scrollbar->location().y,
thickness, scrollbar->size().height);
}
}
WebRect PinchZoomScrollbarGeometry::thumbRect(WebScrollbar* scrollbar) {
WebRect track = trackRect(scrollbar);
int thumb_pos = thumbPosition(scrollbar);
int thickness = scrollbarThickness(scrollbar);
if (scrollbar->orientation() == WebScrollbar::Horizontal) {
return WebRect(track.x + thumb_pos, track.y + (track.height - thickness) /
2, thumbLength(scrollbar), thickness);
} else {
return WebRect(track.x + (track.width - thickness) / 2, track.y + thumb_pos,
thickness, thumbLength(scrollbar));
}
}
int PinchZoomScrollbarGeometry::minimumThumbLength(WebScrollbar* scrollbar) {
return scrollbarThickness(scrollbar);
}
int PinchZoomScrollbarGeometry::scrollbarThickness(WebScrollbar* scrollbar) {
return kTrackWidth;
}
WebRect PinchZoomScrollbarGeometry::backButtonStartRect(
WebScrollbar* scrollbar) {
return WebRect();
}
WebRect PinchZoomScrollbarGeometry::backButtonEndRect(WebScrollbar* scrollbar) {
return WebRect();
}
WebRect PinchZoomScrollbarGeometry::forwardButtonStartRect(
WebScrollbar* scrollbar) {
return WebRect();
}
WebRect PinchZoomScrollbarGeometry::forwardButtonEndRect(
WebScrollbar* scrollbar) {
return WebRect();
}
WebRect PinchZoomScrollbarGeometry::constrainTrackRectToTrackPieces(
WebScrollbar* scrollbar, const WebRect& rect) {
return rect;
}
void PinchZoomScrollbarGeometry::splitTrack(
WebScrollbar* scrollbar, const WebRect& track, WebRect& start_track,
WebRect& thumb, WebRect& end_track) {
thumb = thumbRect(scrollbar);
start_track = WebRect();
end_track = WebRect();
}
} // namespace cc
|