summaryrefslogtreecommitdiffstats
path: root/cc/layers/painted_scrollbar_layer_impl.cc
diff options
context:
space:
mode:
authorwjmaclean@chromium.org <wjmaclean@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-30 20:25:33 +0000
committerwjmaclean@chromium.org <wjmaclean@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-30 20:25:33 +0000
commit80413d78d7c48360fbcb5a891d05841298e07d3d (patch)
tree94bd11f2d6f4881cbd6382ca45bd5c35c9fd9c65 /cc/layers/painted_scrollbar_layer_impl.cc
parent2d6a5a2fb1e111096d625bc4021c54d0988ae847 (diff)
downloadchromium_src-80413d78d7c48360fbcb5a891d05841298e07d3d.zip
chromium_src-80413d78d7c48360fbcb5a891d05841298e07d3d.tar.gz
chromium_src-80413d78d7c48360fbcb5a891d05841298e07d3d.tar.bz2
Refactor cc scrollbar layers architecture.
This CL separates the solid-color scrollbar functionality into its own class structure, resulting in the following hierarchy: ScrollbarLayerInterface (pure-virtual) | -------- PaintedScrollbarLayer (for outer-viewport) | --------- SolidColorScrollbarLayer (for inner-viewport) (Android, pinch-zoom) ScrollbarLayerImplBase | ----- PaintedScrollbarLayerImpl (for outer-viewport) | ----- SolidColorScrollbarLayerImpl (for inner-viewport) (Android, pinch-zoom) In this architecture, solid-color scrollbars can live side-by side with regular desktop scrollbars, and no longer require a WebScrollbar in order to be created. The scrolling LayerImpl's only know about ScrollbarLayerImplBase, and the TreeSynchronizer & LTI only deal with *Base layer types. The ScrollbarLayerImplBase layer is not pure virtual, but rather attempts to collect any common functionality, and the result is much simpler classes for SolidColorScrollbarLayerImpl. Work remaining: 1) Once the pinch-viewport layers are in place in CC, we can get rid of vertical adjust (I think), and so LTI::UpdateSolidColorScrollbars() can go away. When this goes away, some of the interface for ScrollbarLayerImplBase can be simplified as well. Review URL: https://chromiumcodereview.appspot.com/18341009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@220637 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/layers/painted_scrollbar_layer_impl.cc')
-rw-r--r--cc/layers/painted_scrollbar_layer_impl.cc187
1 files changed, 23 insertions, 164 deletions
diff --git a/cc/layers/painted_scrollbar_layer_impl.cc b/cc/layers/painted_scrollbar_layer_impl.cc
index 621cf39..83685c3 100644
--- a/cc/layers/painted_scrollbar_layer_impl.cc
+++ b/cc/layers/painted_scrollbar_layer_impl.cc
@@ -29,35 +29,26 @@ PaintedScrollbarLayerImpl::PaintedScrollbarLayerImpl(
LayerTreeImpl* tree_impl,
int id,
ScrollbarOrientation orientation)
- : LayerImpl(tree_impl, id),
+ : ScrollbarLayerImplBase(tree_impl, id, orientation),
track_ui_resource_id_(0),
thumb_ui_resource_id_(0),
- current_pos_(0.f),
- maximum_(0),
thumb_thickness_(0),
thumb_length_(0),
track_start_(0),
track_length_(0),
- orientation_(orientation),
vertical_adjust_(0.f),
- visible_to_total_length_ratio_(1.f),
- scroll_layer_id_(Layer::INVALID_ID),
- is_overlay_scrollbar_(false) {}
+ scroll_layer_id_(Layer::INVALID_ID) {}
PaintedScrollbarLayerImpl::~PaintedScrollbarLayerImpl() {}
-PaintedScrollbarLayerImpl* PaintedScrollbarLayerImpl::ToScrollbarLayer() {
- return this;
-}
-
scoped_ptr<LayerImpl> PaintedScrollbarLayerImpl::CreateLayerImpl(
LayerTreeImpl* tree_impl) {
- return PaintedScrollbarLayerImpl::Create(tree_impl, id(), orientation_)
+ return PaintedScrollbarLayerImpl::Create(tree_impl, id(), orientation())
.PassAs<LayerImpl>();
}
void PaintedScrollbarLayerImpl::PushPropertiesTo(LayerImpl* layer) {
- LayerImpl::PushPropertiesTo(layer);
+ ScrollbarLayerImplBase::PushPropertiesTo(layer);
PaintedScrollbarLayerImpl* scrollbar_layer =
static_cast<PaintedScrollbarLayerImpl*>(layer);
@@ -66,7 +57,6 @@ void PaintedScrollbarLayerImpl::PushPropertiesTo(LayerImpl* layer) {
scrollbar_layer->SetThumbLength(thumb_length_);
scrollbar_layer->SetTrackStart(track_start_);
scrollbar_layer->SetTrackLength(track_length_);
- scrollbar_layer->set_is_overlay_scrollbar(is_overlay_scrollbar_);
scrollbar_layer->set_track_ui_resource_id(track_ui_resource_id_);
scrollbar_layer->set_thumb_ui_resource_id(thumb_ui_resource_id_);
@@ -74,9 +64,7 @@ void PaintedScrollbarLayerImpl::PushPropertiesTo(LayerImpl* layer) {
bool PaintedScrollbarLayerImpl::WillDraw(DrawMode draw_mode,
ResourceProvider* resource_provider) {
- if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE &&
- !layer_tree_impl()->settings().solid_color_scrollbars)
- return false;
+ DCHECK(draw_mode != DRAW_MODE_RESOURCELESS_SOFTWARE);
return LayerImpl::WillDraw(draw_mode, resource_provider);
}
@@ -96,16 +84,6 @@ void PaintedScrollbarLayerImpl::AppendQuads(
gfx::Rect thumb_quad_rect = ComputeThumbQuadRect();
- if (layer_tree_impl()->settings().solid_color_scrollbars) {
- scoped_ptr<SolidColorDrawQuad> quad = SolidColorDrawQuad::Create();
- quad->SetNew(shared_quad_state,
- thumb_quad_rect,
- layer_tree_impl()->settings().solid_color_scrollbar_color,
- false);
- quad_sink->Append(quad.PassAs<DrawQuad>(), append_quads_data);
- return;
- }
-
ResourceProvider::ResourceId thumb_resource_id =
layer_tree_impl()->ResourceIdForUIResource(thumb_ui_resource_id_);
ResourceProvider::ResourceId track_resource_id =
@@ -147,26 +125,9 @@ void PaintedScrollbarLayerImpl::AppendQuads(
}
}
-ScrollbarOrientation PaintedScrollbarLayerImpl::Orientation() const {
- return orientation_;
-}
-
-float PaintedScrollbarLayerImpl::CurrentPos() const {
- return current_pos_;
-}
-
-int PaintedScrollbarLayerImpl::Maximum() const {
- return maximum_;
-}
-
-gfx::Rect PaintedScrollbarLayerImpl::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);
+void PaintedScrollbarLayerImpl::DidLoseOutputSurface() {
+ track_ui_resource_id_ = 0;
+ thumb_ui_resource_id_ = 0;
}
void PaintedScrollbarLayerImpl::SetThumbThickness(int thumb_thickness) {
@@ -176,12 +137,21 @@ void PaintedScrollbarLayerImpl::SetThumbThickness(int thumb_thickness) {
NoteLayerPropertyChanged();
}
+int PaintedScrollbarLayerImpl::ThumbThickness() const {
+ return thumb_thickness_;
+}
+
void PaintedScrollbarLayerImpl::SetThumbLength(int thumb_length) {
if (thumb_length_ == thumb_length)
return;
thumb_length_ = thumb_length;
NoteLayerPropertyChanged();
}
+
+int PaintedScrollbarLayerImpl::ThumbLength() const {
+ return thumb_length_;
+}
+
void PaintedScrollbarLayerImpl::SetTrackStart(int track_start) {
if (track_start_ == track_start)
return;
@@ -189,6 +159,10 @@ void PaintedScrollbarLayerImpl::SetTrackStart(int track_start) {
NoteLayerPropertyChanged();
}
+int PaintedScrollbarLayerImpl::TrackStart() const {
+ return track_start_;
+}
+
void PaintedScrollbarLayerImpl::SetTrackLength(int track_length) {
if (track_length_ == track_length)
return;
@@ -196,123 +170,8 @@ void PaintedScrollbarLayerImpl::SetTrackLength(int track_length) {
NoteLayerPropertyChanged();
}
-void PaintedScrollbarLayerImpl::SetVerticalAdjust(float vertical_adjust) {
- if (vertical_adjust_ == vertical_adjust)
- return;
- vertical_adjust_ = vertical_adjust;
- NoteLayerPropertyChanged();
-}
-
-void PaintedScrollbarLayerImpl::SetVisibleToTotalLengthRatio(float ratio) {
- if (visible_to_total_length_ratio_ == ratio)
- return;
- visible_to_total_length_ratio_ = ratio;
- NoteLayerPropertyChanged();
-}
-
-void PaintedScrollbarLayerImpl::SetCurrentPos(float current_pos) {
- if (current_pos_ == current_pos)
- return;
- current_pos_ = current_pos;
- NoteLayerPropertyChanged();
-}
-
-void PaintedScrollbarLayerImpl::SetMaximum(int maximum) {
- if (maximum_ == maximum)
- return;
- maximum_ = maximum;
- NoteLayerPropertyChanged();
-}
-
-gfx::Rect PaintedScrollbarLayerImpl::ComputeThumbQuadRect() 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.
-
- int thumb_length = thumb_length_;
- float track_length = track_length_;
- if (orientation_ == VERTICAL)
- track_length += vertical_adjust_;
-
- if (layer_tree_impl()->settings().solid_color_scrollbars) {
- thumb_length = std::max(
- static_cast<int>(visible_to_total_length_ratio_ * track_length),
- thumb_thickness_);
- }
-
- // With the length known, we can compute the thumb's position.
- float clamped_current_pos =
- std::min(std::max(current_pos_, 0.f), static_cast<float>(maximum_));
- float ratio = clamped_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);
+float PaintedScrollbarLayerImpl::TrackLength() const {
+ return track_length_ + (orientation() == VERTICAL ? vertical_adjust() : 0);
}
const char* PaintedScrollbarLayerImpl::LayerTypeAsString() const {