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

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: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/pinch_zoom_scrollbar_geometry.h ('k') | cc/pinch_zoom_scrollbar_painter.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..b7555506c4c0164f43a28614176c49c95db4eed3
--- /dev/null
+++ b/cc/pinch_zoom_scrollbar_geometry.cc
@@ -0,0 +1,126 @@
+// 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 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*) {
+ 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*) {
+ return false;
+}
+
+bool PinchZoomScrollbarGeometry::hasThumb(WebScrollbar*) {
+ 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*) {
+ return kTrackWidth;
+}
+
+WebRect PinchZoomScrollbarGeometry::backButtonStartRect(WebScrollbar*) {
+ return WebRect();
+}
+
+WebRect PinchZoomScrollbarGeometry::backButtonEndRect(WebScrollbar*) {
+ return WebRect();
+}
+
+WebRect PinchZoomScrollbarGeometry::forwardButtonStartRect(WebScrollbar*) {
+ return WebRect();
+}
+
+WebRect PinchZoomScrollbarGeometry::forwardButtonEndRect(WebScrollbar*) {
+ return WebRect();
+}
+
+WebRect PinchZoomScrollbarGeometry::constrainTrackRectToTrackPieces(
+ WebScrollbar*, 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
« 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