From 65213e019835542bf7a8fcd3fa6222ca788bdaaa Mon Sep 17 00:00:00 2001 From: "wjmaclean@chromium.org" Date: Wed, 20 Mar 2013 14:53:03 +0000 Subject: [PATCH] Chromify scrollbar_geometry_fixed_thumb.* BUG=none Review URL: https://chromiumcodereview.appspot.com/12617018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@189274 0039d316-1c4b-4281-b951-d872f2087c98 --- ...ar_animation_controller_linear_fade_unittest.cc | 2 +- cc/layers/scrollbar_geometry_fixed_thumb.cc | 191 ++++++++++++--------- cc/layers/scrollbar_geometry_fixed_thumb.h | 38 ++-- cc/layers/scrollbar_layer.cc | 2 +- cc/layers/scrollbar_layer_impl.cc | 2 +- 5 files changed, 133 insertions(+), 102 deletions(-) rewrite cc/layers/scrollbar_geometry_fixed_thumb.cc (62%) diff --git a/cc/animation/scrollbar_animation_controller_linear_fade_unittest.cc b/cc/animation/scrollbar_animation_controller_linear_fade_unittest.cc index b791f39b153a..08e80b0a7388 100644 --- a/cc/animation/scrollbar_animation_controller_linear_fade_unittest.cc +++ b/cc/animation/scrollbar_animation_controller_linear_fade_unittest.cc @@ -22,7 +22,7 @@ class ScrollbarAnimationControllerLinearFadeTest : public testing::Test { virtual void SetUp() { scroll_layer_ = LayerImpl::Create(host_impl_.active_tree(), 1); scoped_ptr geometry( - ScrollbarGeometryFixedThumb::create( + ScrollbarGeometryFixedThumb::Create( FakeWebScrollbarThemeGeometry::create(false))); scrollbar_layer_ = ScrollbarLayerImpl::Create( host_impl_.active_tree(), 2, geometry.Pass()); diff --git a/cc/layers/scrollbar_geometry_fixed_thumb.cc b/cc/layers/scrollbar_geometry_fixed_thumb.cc dissimilarity index 62% index 07c1cb57f308..aaca66e6682f 100644 --- a/cc/layers/scrollbar_geometry_fixed_thumb.cc +++ b/cc/layers/scrollbar_geometry_fixed_thumb.cc @@ -1,83 +1,108 @@ -// 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_geometry_fixed_thumb.h" - -#include - -#include "third_party/WebKit/Source/Platform/chromium/public/WebRect.h" -#include "third_party/WebKit/Source/Platform/chromium/public/WebScrollbar.h" - -using WebKit::WebRect; -using WebKit::WebScrollbar; -using WebKit::WebScrollbarThemeGeometry; - -namespace cc { - -scoped_ptr ScrollbarGeometryFixedThumb::create(scoped_ptr geometry) -{ - return make_scoped_ptr(new ScrollbarGeometryFixedThumb(geometry.Pass())); -} - -ScrollbarGeometryFixedThumb::~ScrollbarGeometryFixedThumb() -{ -} - -WebScrollbarThemeGeometry* ScrollbarGeometryFixedThumb::clone() const -{ - ScrollbarGeometryFixedThumb* geometry = new ScrollbarGeometryFixedThumb(make_scoped_ptr(ScrollbarGeometryStub::clone())); - geometry->m_thumbSize = m_thumbSize; - return geometry; -} - -int ScrollbarGeometryFixedThumb::thumbLength(WebScrollbar* scrollbar) -{ - if (scrollbar->orientation() == WebScrollbar::Horizontal) - return m_thumbSize.width(); - return m_thumbSize.height(); -} - -int ScrollbarGeometryFixedThumb::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(floorf((pos < 1 && pos > 0) ? 1 : pos)); - } - return 0; -} -void ScrollbarGeometryFixedThumb::splitTrack(WebScrollbar* scrollbar, const WebRect& unconstrainedTrackRect, WebRect& beforeThumbRect, WebRect& thumbRect, WebRect& afterThumbRect) -{ - // This is a reimplementation of ScrollbarThemeComposite::splitTrack. - // Because the WebScrollbarThemeGeometry functions call down to native - // ScrollbarThemeComposite code which uses ScrollbarThemeComposite virtual - // helpers, there's no way to override a helper like thumbLength from - // the WebScrollbarThemeGeometry level. So, these three functions - // (splitTrack, thumbPosition, thumbLength) are copied here so that the - // WebScrollbarThemeGeometry helper functions are used instead and - // a fixed size thumbLength can be used. - - WebRect trackRect = constrainTrackRectToTrackPieces(scrollbar, unconstrainedTrackRect); - int thickness = scrollbar->orientation() == WebScrollbar::Horizontal ? scrollbar->size().height : scrollbar->size().width; - int thumbPos = thumbPosition(scrollbar); - if (scrollbar->orientation() == WebScrollbar::Horizontal) { - thumbRect = WebRect(trackRect.x + thumbPos, trackRect.y + (trackRect.height - thickness) / 2, thumbLength(scrollbar), thickness); - beforeThumbRect = WebRect(trackRect.x, trackRect.y, thumbPos + thumbRect.width / 2, trackRect.height); - afterThumbRect = WebRect(trackRect.x + beforeThumbRect.width, trackRect.y, trackRect.x + trackRect.width - beforeThumbRect.x - beforeThumbRect.width, trackRect.height); - } else { - thumbRect = WebRect(trackRect.x + (trackRect.width - thickness) / 2, trackRect.y + thumbPos, thickness, thumbLength(scrollbar)); - beforeThumbRect = WebRect(trackRect.x, trackRect.y, trackRect.width, thumbPos + thumbRect.height / 2); - afterThumbRect = WebRect(trackRect.x, trackRect.y + beforeThumbRect.height, trackRect.width, trackRect.y + trackRect.height - beforeThumbRect.y - beforeThumbRect.height); - } -} - -ScrollbarGeometryFixedThumb::ScrollbarGeometryFixedThumb(scoped_ptr geometry) - : ScrollbarGeometryStub(geometry.Pass()) -{ -} - -} // namespace cc +// 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_geometry_fixed_thumb.h" + +#include +#include + +#include "third_party/WebKit/Source/Platform/chromium/public/WebRect.h" +#include "third_party/WebKit/Source/Platform/chromium/public/WebScrollbar.h" + +using WebKit::WebRect; +using WebKit::WebScrollbar; +using WebKit::WebScrollbarThemeGeometry; + +namespace cc { + +scoped_ptr ScrollbarGeometryFixedThumb::Create( + scoped_ptr geometry) { + return make_scoped_ptr(new ScrollbarGeometryFixedThumb(geometry.Pass())); +} + +ScrollbarGeometryFixedThumb::~ScrollbarGeometryFixedThumb() {} + +WebScrollbarThemeGeometry* ScrollbarGeometryFixedThumb::clone() const { + ScrollbarGeometryFixedThumb* geometry = new ScrollbarGeometryFixedThumb( + make_scoped_ptr(ScrollbarGeometryStub::clone())); + geometry->thumb_size_ = thumb_size_; + return geometry; +} + +int ScrollbarGeometryFixedThumb::thumbLength(WebScrollbar* scrollbar) { + if (scrollbar->orientation() == WebScrollbar::Horizontal) + return thumb_size_.width(); + return thumb_size_.height(); +} + +int ScrollbarGeometryFixedThumb::thumbPosition(WebScrollbar* scrollbar) { + if (!scrollbar->enabled()) + return 0; + + 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(floorf((pos < 1 && pos > 0) ? 1 : pos)); +} +void ScrollbarGeometryFixedThumb::splitTrack( + WebScrollbar* scrollbar, + const WebRect& unconstrained_track_rect, + WebRect& before_thumb_rect, + WebRect& thumb_rect, + WebRect& after_thumb_rect) { + // This is a reimplementation of ScrollbarThemeComposite::splitTrack. + // Because the WebScrollbarThemeGeometry functions call down to native + // ScrollbarThemeComposite code which uses ScrollbarThemeComposite virtual + // helpers, there's no way to override a helper like thumbLength from + // the WebScrollbarThemeGeometry level. So, these three functions + // (splitTrack, thumb_position, thumbLength) are copied here so that the + // WebScrollbarThemeGeometry helper functions are used instead and + // a fixed size thumbLength can be used. + + WebRect track_rect = + constrainTrackRectToTrackPieces(scrollbar, unconstrained_track_rect); + int thickness = scrollbar->orientation() == WebScrollbar::Horizontal + ? scrollbar->size().height + : scrollbar->size().width; + int thumb_pos = thumbPosition(scrollbar); + if (scrollbar->orientation() == WebScrollbar::Horizontal) { + thumb_rect = WebRect(track_rect.x + thumb_pos, + track_rect.y + (track_rect.height - thickness) / 2, + thumbLength(scrollbar), + thickness); + before_thumb_rect = WebRect(track_rect.x, + track_rect.y, + thumb_pos + thumb_rect.width / 2, + track_rect.height); + after_thumb_rect = WebRect(track_rect.x + before_thumb_rect.width, + track_rect.y, + track_rect.x + track_rect.width - + before_thumb_rect.x - before_thumb_rect.width, + track_rect.height); + } else { + thumb_rect = WebRect(track_rect.x + (track_rect.width - thickness) / 2, + track_rect.y + thumb_pos, + thickness, + thumbLength(scrollbar)); + before_thumb_rect = WebRect(track_rect.x, + track_rect.y, + track_rect.width, + thumb_pos + thumb_rect.height / 2); + after_thumb_rect = + WebRect(track_rect.x, + track_rect.y + before_thumb_rect.height, + track_rect.width, + track_rect.y + track_rect.height - before_thumb_rect.y - + before_thumb_rect.height); + } +} + +ScrollbarGeometryFixedThumb::ScrollbarGeometryFixedThumb( + scoped_ptr geometry) + : ScrollbarGeometryStub(geometry.Pass()) {} + +} // namespace cc diff --git a/cc/layers/scrollbar_geometry_fixed_thumb.h b/cc/layers/scrollbar_geometry_fixed_thumb.h index f94110410d2c..983a70c8323a 100644 --- a/cc/layers/scrollbar_geometry_fixed_thumb.h +++ b/cc/layers/scrollbar_geometry_fixed_thumb.h @@ -16,22 +16,28 @@ namespace cc { // the total size of the scrollable area, changing the thumb length) while not // requiring the thumb resource to be repainted. class CC_EXPORT ScrollbarGeometryFixedThumb : public ScrollbarGeometryStub { -public: - static scoped_ptr create(scoped_ptr); - virtual ~ScrollbarGeometryFixedThumb(); - - void setThumbSize(gfx::Size size) { m_thumbSize = size; } - - // WebScrollbarThemeGeometry interface - virtual WebKit::WebScrollbarThemeGeometry* clone() const OVERRIDE; - virtual int thumbLength(WebKit::WebScrollbar*) OVERRIDE; - virtual int thumbPosition(WebKit::WebScrollbar*) OVERRIDE; - virtual void splitTrack(WebKit::WebScrollbar*, const WebKit::WebRect& track, WebKit::WebRect& startTrack, WebKit::WebRect& thumb, WebKit::WebRect& endTrack) OVERRIDE; - -private: - explicit ScrollbarGeometryFixedThumb(scoped_ptr); - - gfx::Size m_thumbSize; + public: + static scoped_ptr Create( + scoped_ptr geometry); + virtual ~ScrollbarGeometryFixedThumb(); + + void set_thumb_size(gfx::Size size) { thumb_size_ = size; } + + // WebScrollbarThemeGeometry interface + virtual WebKit::WebScrollbarThemeGeometry* clone() const OVERRIDE; + virtual int thumbLength(WebKit::WebScrollbar* scrollbar) OVERRIDE; + virtual int thumbPosition(WebKit::WebScrollbar* scrollbar) OVERRIDE; + virtual void splitTrack(WebKit::WebScrollbar* scrollbar, + const WebKit::WebRect& track, + WebKit::WebRect& start_track, + WebKit::WebRect& thumb, + WebKit::WebRect& end_track) OVERRIDE; + + private: + explicit ScrollbarGeometryFixedThumb( + scoped_ptr geometry); + + gfx::Size thumb_size_; }; } diff --git a/cc/layers/scrollbar_layer.cc b/cc/layers/scrollbar_layer.cc index 4f648e692d9e..1681b6f73eb5 100644 --- a/cc/layers/scrollbar_layer.cc +++ b/cc/layers/scrollbar_layer.cc @@ -22,7 +22,7 @@ scoped_ptr ScrollbarLayer::CreateLayerImpl( return ScrollbarLayerImpl::Create( tree_impl, id(), - ScrollbarGeometryFixedThumb::create(make_scoped_ptr(geometry_->clone()))) + ScrollbarGeometryFixedThumb::Create(make_scoped_ptr(geometry_->clone()))) .PassAs(); } diff --git a/cc/layers/scrollbar_layer_impl.cc b/cc/layers/scrollbar_layer_impl.cc index 63a17cc55161..affc4b7b0653 100644 --- a/cc/layers/scrollbar_layer_impl.cc +++ b/cc/layers/scrollbar_layer_impl.cc @@ -83,7 +83,7 @@ void ScrollbarLayerImpl::SetThumbSize(gfx::Size size) { DCHECK(layer_tree_impl()->IsPendingTree()); return; } - geometry_->setThumbSize(size); + geometry_->set_thumb_size(size); } void ScrollbarLayerImpl::SetViewportWithinScrollableArea( -- 2.11.4.GIT