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

Unified 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 side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698