Index: cc/pinch_zoom_scrollbar_geometry.cc |
diff --git a/cc/pinch_zoom_scrollbar_geometry.cc b/cc/pinch_zoom_scrollbar_geometry.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b19efc144f6af962b7e5b0d46b24458e334ad272 |
--- /dev/null |
+++ b/cc/pinch_zoom_scrollbar_geometry.cc |
@@ -0,0 +1,93 @@ |
+// 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/pinch_zoom_scrollbar_geometry.h" |
+ |
+#include "third_party/WebKit/Source/Platform/chromium/public/WebScrollbar.h" |
+ |
+namespace WebKit { |
+ |
+WebScrollbarThemeGeometry* PinchZoomScrollbarGeometry::clone() const { |
+ 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.
|
+} |
+ |
+int PinchZoomScrollbarGeometry::thumbPosition(WebScrollbar* scrollbar) { |
+ if (scrollbar->enabled()) { |
+ float size = scrollbar->maximum(); |
+ if (!size) |
+ return 1; |
+ int value = std::min(std::max(0, scrollbar->value()), scrollbar->maximum()); |
+ float pos = (trackLength(scrollbar) - thumbLength(scrollbar)) * value / size; |
+ 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 trackLength = this->trackLength(scrollbar); |
+ int length = proportion * trackLength + 0.5f; |
+ length = std::max(length, kTrackWidth); |
+ if (length > trackLength) |
+ length = 0; |
+ return length; |
+} |
+ |
+int PinchZoomScrollbarGeometry::trackPosition(WebScrollbar*) { |
+ return 0; |
+} |
+ |
+int PinchZoomScrollbarGeometry::trackLength(WebScrollbar* scrollbar) { |
+ WebRect track = trackRect(scrollbar); |
+ if (scrollbar->orientation() == WebScrollbar::Horizontal) |
+ return track.width; |
+ else |
+ return track.height; |
+} |
+ |
+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 thumbPos = thumbPosition(scrollbar); |
+ int thickness = scrollbarThickness(scrollbar); |
+ if (scrollbar->orientation() == WebScrollbar::Horizontal) |
+ return WebRect(track.x + thumbPos, track.y + (track.height - thickness) / 2, |
+ thumbLength(scrollbar), thickness); |
+ else |
+ return WebRect(track.x + (track.width - thickness) / 2, track.y + thumbPos, |
+ thickness, thumbLength(scrollbar)); |
+} |
+ |
+int PinchZoomScrollbarGeometry::minimumThumbLength(WebScrollbar* scrollbar) { |
+ return scrollbarThickness(scrollbar); |
+} |
+ |
+int PinchZoomScrollbarGeometry::scrollbarThickness(WebScrollbar*) { |
+ return kTrackWidth; |
+} |
+ |
+WebRect PinchZoomScrollbarGeometry::constrainTrackRectToTrackPieces(WebScrollbar*, const WebRect& rect) { |
+ return rect; |
+} |
+ |
+void PinchZoomScrollbarGeometry::splitTrack( |
+ WebScrollbar* scrollbar, const WebRect& track, WebRect& startTrack, WebRect& thumb, |
+ WebRect& endTrack) { |
+ thumb = thumbRect(scrollbar); |
+ startTrack = WebRect(); |
+ endTrack = WebRect(); |
+} |
+ |
+} // namespace WebKit |