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

Unified Diff: cc/layers/scrollbar_layer_impl_base.cc

Issue 18341009: Refactor cc scrollbar layers to separate solid-color vs desktop. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address tfarina@'s comments. Created 7 years, 5 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/layers/scrollbar_layer_impl_base.cc
diff --git a/cc/layers/scrollbar_layer_impl_base.cc b/cc/layers/scrollbar_layer_impl_base.cc
new file mode 100644
index 0000000000000000000000000000000000000000..9da2b2ba021ada17cc5757eecee809a0a25cb8d9
--- /dev/null
+++ b/cc/layers/scrollbar_layer_impl_base.cc
@@ -0,0 +1,110 @@
+// Copyright 2012 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/layers/scrollbar_layer_impl_base.h"
+#include "ui/gfx/rect_conversions.h"
+
+namespace cc {
+
+void ScrollbarLayerImplBase::PushPropertiesTo(LayerImpl* layer) {
+ LayerImpl::PushPropertiesTo(layer);
+}
+
+ScrollbarLayerImplBase* ScrollbarLayerImplBase::ToScrollbarLayerBase() {
+ return this;
+}
+
+gfx::Rect ScrollbarLayerImplBase::ScrollbarLayerRectToContentRect(
+ gfx::RectF layer_rect) const {
+ // Don't intersect with the bounds as in layerRectToContentRect() because
+ // layer_rect here might be in coordinates of the containing layer.
+ gfx::RectF content_rect = gfx::ScaleRect(layer_rect,
+ contents_scale_x(),
+ contents_scale_y());
+ return gfx::ToEnclosingRect(content_rect);
+}
+
+gfx::Rect ScrollbarLayerImplBase::ComputeThumbQuadRectInternal(
+ int thumb_length,
+ float track_length,
+ int track_start,
+ int thumb_thickness) const {
+ // Thumb extent is the length of the thumb in the scrolling direction, thumb
+ // thickness is in the perpendicular direction. Here's an example of a
+ // horizontal scrollbar - inputs are above the scrollbar, computed values
+ // below:
+ //
+ // |<------------------- track_length_ ------------------->|
+ //
+ // |--| <-- start_offset
+ //
+ // +--+----------------------------+------------------+-------+--+
+ // |<|| |##################| ||>|
+ // +--+----------------------------+------------------+-------+--+
+ //
+ // |<- thumb_length ->|
+ //
+ // |<------- thumb_offset -------->|
+ //
+ // For painted, scrollbars, the length is fixed. For solid color scrollbars we
+ // have to compute it. The ratio of the thumb's length to the track's length
+ // is the same as that of the visible viewport to the total viewport, unless
+ // that would make the thumb's length less than its thickness.
+ //
+ // vertical_adjust_ is used when the layer geometry from the main thread is
+ // not in sync with what the user sees. For instance on Android scrolling the
+ // top bar controls out of view reveals more of the page content. We want the
+ // root layer scrollbars to reflect what the user sees even if we haven't
+ // received new layer geometry from the main thread. If the user has scrolled
+ // down by 50px and the initial viewport size was 950px the geometry would
+ // look something like this:
+ //
+ // vertical_adjust_ = 50, scroll position 0, visible ratios 99%
+ // Layer geometry: Desired thumb positions:
+ // +--------------------+-+ +----------------------+ <-- 0px
+ // | |v| | #|
+ // | |e| | #|
+ // | |r| | #|
+ // | |t| | #|
+ // | |i| | #|
+ // | |c| | #|
+ // | |a| | #|
+ // | |l| | #|
+ // | | | | #|
+ // | |l| | #|
+ // | |a| | #|
+ // | |y| | #|
+ // | |e| | #|
+ // | |r| | #|
+ // +--------------------+-+ | #|
+ // | horizontal layer | | | #|
+ // +--------------------+-+ | #| <-- 950px
+ // | | | #|
+ // | | |##################### |
+ // +----------------------+ +----------------------+ <-- 1000px
+ //
+ // The layer geometry is set up for a 950px tall viewport, but the user can
+ // actually see down to 1000px. Thus we have to move the quad for the
+ // horizontal scrollbar down by the vertical_adjust_ factor and lay the
+ // vertical thumb out on a track lengthed by the vertical_adjust_ factor. This
+ // means the quads may extend outside the layer's bounds.
+
+ // With the length known, we can compute the thumb's position.
+ float ratio = current_pos_ / maximum_;
+ float max_offset = track_length - thumb_length;
+ int thumb_offset = static_cast<int>(ratio * max_offset) + track_start;
+
+ gfx::RectF thumb_rect;
+ if (orientation_ == HORIZONTAL) {
+ thumb_rect = gfx::RectF(thumb_offset, vertical_adjust_,
+ thumb_length, thumb_thickness);
+ } else {
+ thumb_rect = gfx::RectF(0.f, thumb_offset,
+ thumb_thickness, thumb_length);
+ }
+
+ return ScrollbarLayerRectToContentRect(thumb_rect);
+}
+
+} // namespace cc

Powered by Google App Engine
This is Rietveld 408576698