Commit 5e6254ef authored by Xianzhu Wang's avatar Xianzhu Wang Committed by Commit Bot

Make cc::Scrollbar ref-counted

This prepares for blink::ScrollbarDisplayItem (for CompositeAfterPaint
composited scrollbars) which will share ownership of cc::Scrollbar
with cc's painted scrollbar layers.

Also make sure that cc::Scrollbar is accessed from the main-thread
only.

Bug: 931486
Change-Id: If64b14d8d917272873d35f33302ecbb66b20126b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1884577Reviewed-by: default avatarPhilip Rogers <pdr@chromium.org>
Commit-Queue: Xianzhu Wang <wangxianzhu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#710872}
parent d00a5115
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef CC_INPUT_SCROLLBAR_H_ #ifndef CC_INPUT_SCROLLBAR_H_
#define CC_INPUT_SCROLLBAR_H_ #define CC_INPUT_SCROLLBAR_H_
#include "base/memory/ref_counted.h"
#include "cc/cc_export.h" #include "cc/cc_export.h"
#include "cc/paint/paint_canvas.h" #include "cc/paint/paint_canvas.h"
#include "ui/gfx/geometry/point.h" #include "ui/gfx/geometry/point.h"
...@@ -42,10 +43,8 @@ enum ScrollbarPart { ...@@ -42,10 +43,8 @@ enum ScrollbarPart {
NO_PART, NO_PART,
}; };
class Scrollbar { class Scrollbar : public base::RefCounted<Scrollbar> {
public: public:
virtual ~Scrollbar() {}
virtual ScrollbarOrientation Orientation() const = 0; virtual ScrollbarOrientation Orientation() const = 0;
virtual bool IsLeftSideVerticalScrollbar() const = 0; virtual bool IsLeftSideVerticalScrollbar() const = 0;
virtual gfx::Point Location() const = 0; virtual gfx::Point Location() const = 0;
...@@ -77,6 +76,10 @@ class Scrollbar { ...@@ -77,6 +76,10 @@ class Scrollbar {
virtual bool UsesNinePatchThumbResource() const = 0; virtual bool UsesNinePatchThumbResource() const = 0;
virtual gfx::Size NinePatchThumbCanvasSize() const = 0; virtual gfx::Size NinePatchThumbCanvasSize() const = 0;
virtual gfx::Rect NinePatchThumbAperture() const = 0; virtual gfx::Rect NinePatchThumbAperture() const = 0;
protected:
friend class base::RefCounted<Scrollbar>;
virtual ~Scrollbar() {}
}; };
} // namespace cc } // namespace cc
......
...@@ -26,21 +26,23 @@ namespace cc { ...@@ -26,21 +26,23 @@ namespace cc {
std::unique_ptr<LayerImpl> PaintedOverlayScrollbarLayer::CreateLayerImpl( std::unique_ptr<LayerImpl> PaintedOverlayScrollbarLayer::CreateLayerImpl(
LayerTreeImpl* tree_impl) { LayerTreeImpl* tree_impl) {
return PaintedOverlayScrollbarLayerImpl::Create( return PaintedOverlayScrollbarLayerImpl::Create(
tree_impl, id(), scrollbar_->Orientation(), tree_impl, id(), orientation_, is_left_side_vertical_scrollbar_);
scrollbar_->IsLeftSideVerticalScrollbar());
} }
scoped_refptr<PaintedOverlayScrollbarLayer> scoped_refptr<PaintedOverlayScrollbarLayer>
PaintedOverlayScrollbarLayer::Create(std::unique_ptr<Scrollbar> scrollbar) { PaintedOverlayScrollbarLayer::Create(scoped_refptr<Scrollbar> scrollbar) {
return base::WrapRefCounted( return base::WrapRefCounted(
new PaintedOverlayScrollbarLayer(std::move(scrollbar))); new PaintedOverlayScrollbarLayer(std::move(scrollbar)));
} }
PaintedOverlayScrollbarLayer::PaintedOverlayScrollbarLayer( PaintedOverlayScrollbarLayer::PaintedOverlayScrollbarLayer(
std::unique_ptr<Scrollbar> scrollbar) scoped_refptr<Scrollbar> scrollbar)
: scrollbar_(std::move(scrollbar)), : scrollbar_(std::move(scrollbar)),
thumb_thickness_(scrollbar_->ThumbThickness()), thumb_thickness_(scrollbar_->ThumbThickness()),
thumb_length_(scrollbar_->ThumbLength()) { thumb_length_(scrollbar_->ThumbLength()),
orientation_(scrollbar_->Orientation()),
is_left_side_vertical_scrollbar_(
scrollbar_->IsLeftSideVerticalScrollbar()) {
DCHECK(scrollbar_->HasThumb()); DCHECK(scrollbar_->HasThumb());
DCHECK(scrollbar_->IsOverlay()); DCHECK(scrollbar_->IsOverlay());
DCHECK(scrollbar_->UsesNinePatchThumbResource()); DCHECK(scrollbar_->UsesNinePatchThumbResource());
...@@ -49,7 +51,7 @@ PaintedOverlayScrollbarLayer::PaintedOverlayScrollbarLayer( ...@@ -49,7 +51,7 @@ PaintedOverlayScrollbarLayer::PaintedOverlayScrollbarLayer(
PaintedOverlayScrollbarLayer::~PaintedOverlayScrollbarLayer() = default; PaintedOverlayScrollbarLayer::~PaintedOverlayScrollbarLayer() = default;
bool PaintedOverlayScrollbarLayer::OpacityCanAnimateOnImplThread() const { bool PaintedOverlayScrollbarLayer::OpacityCanAnimateOnImplThread() const {
return scrollbar_->IsOverlay(); return true;
} }
void PaintedOverlayScrollbarLayer::PushPropertiesTo(LayerImpl* layer) { void PaintedOverlayScrollbarLayer::PushPropertiesTo(LayerImpl* layer) {
...@@ -60,7 +62,7 @@ void PaintedOverlayScrollbarLayer::PushPropertiesTo(LayerImpl* layer) { ...@@ -60,7 +62,7 @@ void PaintedOverlayScrollbarLayer::PushPropertiesTo(LayerImpl* layer) {
scrollbar_layer->SetThumbThickness(thumb_thickness_); scrollbar_layer->SetThumbThickness(thumb_thickness_);
scrollbar_layer->SetThumbLength(thumb_length_); scrollbar_layer->SetThumbLength(thumb_length_);
if (scrollbar_->Orientation() == HORIZONTAL) { if (orientation_ == HORIZONTAL) {
scrollbar_layer->SetTrackStart(track_rect_.x()); scrollbar_layer->SetTrackStart(track_rect_.x());
scrollbar_layer->SetTrackLength(track_rect_.width()); scrollbar_layer->SetTrackLength(track_rect_.width());
} else { } else {
...@@ -102,6 +104,14 @@ gfx::Rect PaintedOverlayScrollbarLayer::OriginThumbRectForPainting() const { ...@@ -102,6 +104,14 @@ gfx::Rect PaintedOverlayScrollbarLayer::OriginThumbRectForPainting() const {
} }
bool PaintedOverlayScrollbarLayer::Update() { bool PaintedOverlayScrollbarLayer::Update() {
// These properties should never change.
DCHECK_EQ(orientation_, scrollbar_->Orientation());
DCHECK_EQ(is_left_side_vertical_scrollbar_,
scrollbar_->IsLeftSideVerticalScrollbar());
DCHECK(scrollbar_->HasThumb());
DCHECK(scrollbar_->IsOverlay());
DCHECK(scrollbar_->UsesNinePatchThumbResource());
bool updated = false; bool updated = false;
updated |= Layer::Update(); updated |= Layer::Update();
......
...@@ -23,7 +23,7 @@ class CC_EXPORT PaintedOverlayScrollbarLayer : public ScrollbarLayerBase { ...@@ -23,7 +23,7 @@ class CC_EXPORT PaintedOverlayScrollbarLayer : public ScrollbarLayerBase {
PaintedOverlayScrollbarLayer& operator=(const PaintedOverlayScrollbarLayer&) = PaintedOverlayScrollbarLayer& operator=(const PaintedOverlayScrollbarLayer&) =
delete; delete;
static scoped_refptr<PaintedOverlayScrollbarLayer> Create( static scoped_refptr<PaintedOverlayScrollbarLayer> Create(
std::unique_ptr<Scrollbar> scrollbar); scoped_refptr<Scrollbar> scrollbar);
bool OpacityCanAnimateOnImplThread() const override; bool OpacityCanAnimateOnImplThread() const override;
bool Update() override; bool Update() override;
...@@ -31,7 +31,7 @@ class CC_EXPORT PaintedOverlayScrollbarLayer : public ScrollbarLayerBase { ...@@ -31,7 +31,7 @@ class CC_EXPORT PaintedOverlayScrollbarLayer : public ScrollbarLayerBase {
void PushPropertiesTo(LayerImpl* layer) override; void PushPropertiesTo(LayerImpl* layer) override;
protected: protected:
explicit PaintedOverlayScrollbarLayer(std::unique_ptr<Scrollbar> scrollbar); explicit PaintedOverlayScrollbarLayer(scoped_refptr<Scrollbar> scrollbar);
~PaintedOverlayScrollbarLayer() override; ~PaintedOverlayScrollbarLayer() override;
private: private:
...@@ -49,7 +49,7 @@ class CC_EXPORT PaintedOverlayScrollbarLayer : public ScrollbarLayerBase { ...@@ -49,7 +49,7 @@ class CC_EXPORT PaintedOverlayScrollbarLayer : public ScrollbarLayerBase {
bool PaintThumbIfNeeded(); bool PaintThumbIfNeeded();
bool PaintTickmarks(); bool PaintTickmarks();
std::unique_ptr<Scrollbar> scrollbar_; scoped_refptr<Scrollbar> scrollbar_;
int thumb_thickness_; int thumb_thickness_;
int thumb_length_; int thumb_length_;
...@@ -58,6 +58,9 @@ class CC_EXPORT PaintedOverlayScrollbarLayer : public ScrollbarLayerBase { ...@@ -58,6 +58,9 @@ class CC_EXPORT PaintedOverlayScrollbarLayer : public ScrollbarLayerBase {
gfx::Rect aperture_; gfx::Rect aperture_;
const ScrollbarOrientation orientation_;
const bool is_left_side_vertical_scrollbar_;
std::unique_ptr<ScopedUIResource> thumb_resource_; std::unique_ptr<ScopedUIResource> thumb_resource_;
std::unique_ptr<ScopedUIResource> track_resource_; std::unique_ptr<ScopedUIResource> track_resource_;
}; };
......
...@@ -37,6 +37,8 @@ class MockScrollbar : public FakeScrollbar { ...@@ -37,6 +37,8 @@ class MockScrollbar : public FakeScrollbar {
} }
private: private:
~MockScrollbar() override = default;
bool paint_tickmarks_called_ = false; bool paint_tickmarks_called_ = false;
}; };
...@@ -48,12 +50,11 @@ TEST(PaintedOverlayScrollbarLayerTest, PaintTickmarks) { ...@@ -48,12 +50,11 @@ TEST(PaintedOverlayScrollbarLayerTest, PaintTickmarks) {
auto layer_tree_host = FakeLayerTreeHost::Create( auto layer_tree_host = FakeLayerTreeHost::Create(
&fake_client_, &task_graph_runner_, animation_host.get()); &fake_client_, &task_graph_runner_, animation_host.get());
MockScrollbar* scrollbar = new MockScrollbar(); auto scrollbar = base::MakeRefCounted<MockScrollbar>();
scrollbar->set_has_tickmarks(false); scrollbar->set_has_tickmarks(false);
scoped_refptr<PaintedOverlayScrollbarLayer> scrollbar_layer = scoped_refptr<PaintedOverlayScrollbarLayer> scrollbar_layer =
PaintedOverlayScrollbarLayer::Create( PaintedOverlayScrollbarLayer::Create(scrollbar);
std::unique_ptr<Scrollbar>(scrollbar));
scrollbar_layer->SetIsDrawable(true); scrollbar_layer->SetIsDrawable(true);
scrollbar_layer->SetBounds(gfx::Size(100, 100)); scrollbar_layer->SetBounds(gfx::Size(100, 100));
......
...@@ -15,31 +15,33 @@ namespace cc { ...@@ -15,31 +15,33 @@ namespace cc {
std::unique_ptr<LayerImpl> PaintedScrollbarLayer::CreateLayerImpl( std::unique_ptr<LayerImpl> PaintedScrollbarLayer::CreateLayerImpl(
LayerTreeImpl* tree_impl) { LayerTreeImpl* tree_impl) {
return PaintedScrollbarLayerImpl::Create( return PaintedScrollbarLayerImpl::Create(tree_impl, id(), orientation_,
tree_impl, id(), scrollbar_->Orientation(), is_left_side_vertical_scrollbar_,
scrollbar_->IsLeftSideVerticalScrollbar(), scrollbar_->IsOverlay()); is_overlay_);
} }
scoped_refptr<PaintedScrollbarLayer> PaintedScrollbarLayer::Create( scoped_refptr<PaintedScrollbarLayer> PaintedScrollbarLayer::Create(
std::unique_ptr<Scrollbar> scrollbar) { scoped_refptr<Scrollbar> scrollbar) {
return base::WrapRefCounted(new PaintedScrollbarLayer(std::move(scrollbar))); return base::WrapRefCounted(new PaintedScrollbarLayer(std::move(scrollbar)));
} }
PaintedScrollbarLayer::PaintedScrollbarLayer( PaintedScrollbarLayer::PaintedScrollbarLayer(scoped_refptr<Scrollbar> scrollbar)
std::unique_ptr<Scrollbar> scrollbar)
: scrollbar_(std::move(scrollbar)), : scrollbar_(std::move(scrollbar)),
internal_contents_scale_(1.f), internal_contents_scale_(1.f),
supports_drag_snap_back_(false),
thumb_thickness_(scrollbar_->ThumbThickness()), thumb_thickness_(scrollbar_->ThumbThickness()),
thumb_length_(scrollbar_->ThumbLength()), thumb_length_(scrollbar_->ThumbLength()),
is_overlay_(scrollbar_->IsOverlay()), thumb_opacity_(scrollbar_->ThumbOpacity()),
has_thumb_(scrollbar_->HasThumb()), has_thumb_(scrollbar_->HasThumb()),
thumb_opacity_(scrollbar_->ThumbOpacity()) {} supports_drag_snap_back_(scrollbar_->SupportsDragSnapBack()),
is_left_side_vertical_scrollbar_(
scrollbar_->IsLeftSideVerticalScrollbar()),
is_overlay_(scrollbar_->IsOverlay()),
orientation_(scrollbar_->Orientation()) {}
PaintedScrollbarLayer::~PaintedScrollbarLayer() = default; PaintedScrollbarLayer::~PaintedScrollbarLayer() = default;
bool PaintedScrollbarLayer::OpacityCanAnimateOnImplThread() const { bool PaintedScrollbarLayer::OpacityCanAnimateOnImplThread() const {
return scrollbar_->IsOverlay(); return is_overlay_;
} }
void PaintedScrollbarLayer::PushPropertiesTo(LayerImpl* layer) { void PaintedScrollbarLayer::PushPropertiesTo(LayerImpl* layer) {
...@@ -56,7 +58,7 @@ void PaintedScrollbarLayer::PushPropertiesTo(LayerImpl* layer) { ...@@ -56,7 +58,7 @@ void PaintedScrollbarLayer::PushPropertiesTo(LayerImpl* layer) {
scrollbar_layer->SetBackButtonRect(back_button_rect_); scrollbar_layer->SetBackButtonRect(back_button_rect_);
scrollbar_layer->SetForwardButtonRect(forward_button_rect_); scrollbar_layer->SetForwardButtonRect(forward_button_rect_);
scrollbar_layer->SetThumbLength(thumb_length_); scrollbar_layer->SetThumbLength(thumb_length_);
if (scrollbar_->Orientation() == HORIZONTAL) { if (orientation_ == HORIZONTAL) {
scrollbar_layer->SetTrackStart(track_rect_.x()); scrollbar_layer->SetTrackStart(track_rect_.x());
scrollbar_layer->SetTrackLength(track_rect_.width()); scrollbar_layer->SetTrackLength(track_rect_.width());
} else { } else {
...@@ -103,24 +105,23 @@ gfx::Rect PaintedScrollbarLayer::ScrollbarLayerRectToContentRect( ...@@ -103,24 +105,23 @@ gfx::Rect PaintedScrollbarLayer::ScrollbarLayerRectToContentRect(
} }
gfx::Rect PaintedScrollbarLayer::OriginThumbRect() const { gfx::Rect PaintedScrollbarLayer::OriginThumbRect() const {
gfx::Size thumb_size; return orientation_ == HORIZONTAL
if (scrollbar_->Orientation() == HORIZONTAL) { ? gfx::Rect(thumb_length_, thumb_thickness_)
thumb_size = : gfx::Rect(thumb_thickness_, thumb_length_);
gfx::Size(scrollbar_->ThumbLength(), scrollbar_->ThumbThickness());
} else {
thumb_size =
gfx::Size(scrollbar_->ThumbThickness(), scrollbar_->ThumbLength());
}
return gfx::Rect(thumb_size);
} }
void PaintedScrollbarLayer::UpdateThumbAndTrackGeometry() { void PaintedScrollbarLayer::UpdateThumbAndTrackGeometry() {
UpdateProperty(scrollbar_->SupportsDragSnapBack(), &supports_drag_snap_back_); // These properties should never change.
DCHECK_EQ(supports_drag_snap_back_, scrollbar_->SupportsDragSnapBack());
DCHECK_EQ(is_left_side_vertical_scrollbar_,
scrollbar_->IsLeftSideVerticalScrollbar());
DCHECK_EQ(is_overlay_, scrollbar_->IsOverlay());
DCHECK_EQ(orientation_, scrollbar_->Orientation());
UpdateProperty(scrollbar_->TrackRect(), &track_rect_); UpdateProperty(scrollbar_->TrackRect(), &track_rect_);
UpdateProperty(scrollbar_->BackButtonRect(), &back_button_rect_); UpdateProperty(scrollbar_->BackButtonRect(), &back_button_rect_);
UpdateProperty(scrollbar_->ForwardButtonRect(), &forward_button_rect_); UpdateProperty(scrollbar_->ForwardButtonRect(), &forward_button_rect_);
UpdateProperty(scrollbar_->Location(), &location_); UpdateProperty(scrollbar_->Location(), &location_);
UpdateProperty(scrollbar_->IsOverlay(), &is_overlay_);
UpdateProperty(scrollbar_->HasThumb(), &has_thumb_); UpdateProperty(scrollbar_->HasThumb(), &has_thumb_);
if (has_thumb_) { if (has_thumb_) {
UpdateProperty(scrollbar_->ThumbThickness(), &thumb_thickness_); UpdateProperty(scrollbar_->ThumbThickness(), &thumb_thickness_);
......
...@@ -18,7 +18,7 @@ class CC_EXPORT PaintedScrollbarLayer : public ScrollbarLayerBase { ...@@ -18,7 +18,7 @@ class CC_EXPORT PaintedScrollbarLayer : public ScrollbarLayerBase {
std::unique_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) override; std::unique_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) override;
static scoped_refptr<PaintedScrollbarLayer> Create( static scoped_refptr<PaintedScrollbarLayer> Create(
std::unique_ptr<Scrollbar> scrollbar); scoped_refptr<Scrollbar> scrollbar);
PaintedScrollbarLayer(const PaintedScrollbarLayer&) = delete; PaintedScrollbarLayer(const PaintedScrollbarLayer&) = delete;
PaintedScrollbarLayer& operator=(const PaintedScrollbarLayer&) = delete; PaintedScrollbarLayer& operator=(const PaintedScrollbarLayer&) = delete;
...@@ -33,7 +33,7 @@ class CC_EXPORT PaintedScrollbarLayer : public ScrollbarLayerBase { ...@@ -33,7 +33,7 @@ class CC_EXPORT PaintedScrollbarLayer : public ScrollbarLayerBase {
} }
protected: protected:
explicit PaintedScrollbarLayer(std::unique_ptr<Scrollbar> scrollbar); explicit PaintedScrollbarLayer(scoped_refptr<Scrollbar> scrollbar);
~PaintedScrollbarLayer() override; ~PaintedScrollbarLayer() override;
// For unit tests // For unit tests
...@@ -63,7 +63,7 @@ class CC_EXPORT PaintedScrollbarLayer : public ScrollbarLayerBase { ...@@ -63,7 +63,7 @@ class CC_EXPORT PaintedScrollbarLayer : public ScrollbarLayerBase {
const gfx::Rect& content_rect, const gfx::Rect& content_rect,
ScrollbarPart part); ScrollbarPart part);
std::unique_ptr<Scrollbar> scrollbar_; scoped_refptr<Scrollbar> scrollbar_;
ElementId scroll_element_id_; ElementId scroll_element_id_;
float internal_contents_scale_; float internal_contents_scale_;
...@@ -71,20 +71,22 @@ class CC_EXPORT PaintedScrollbarLayer : public ScrollbarLayerBase { ...@@ -71,20 +71,22 @@ class CC_EXPORT PaintedScrollbarLayer : public ScrollbarLayerBase {
// Snapshot of properties taken in UpdateThumbAndTrackGeometry and used in // Snapshot of properties taken in UpdateThumbAndTrackGeometry and used in
// PushPropertiesTo. // PushPropertiesTo.
bool supports_drag_snap_back_;
int thumb_thickness_; int thumb_thickness_;
int thumb_length_; int thumb_length_;
gfx::Point location_; gfx::Point location_;
gfx::Rect track_rect_; gfx::Rect track_rect_;
gfx::Rect back_button_rect_; gfx::Rect back_button_rect_;
gfx::Rect forward_button_rect_; gfx::Rect forward_button_rect_;
bool is_overlay_; float thumb_opacity_;
bool has_thumb_; bool has_thumb_;
const bool supports_drag_snap_back_;
const bool is_left_side_vertical_scrollbar_;
const bool is_overlay_;
const ScrollbarOrientation orientation_;
std::unique_ptr<ScopedUIResource> track_resource_; std::unique_ptr<ScopedUIResource> track_resource_;
std::unique_ptr<ScopedUIResource> thumb_resource_; std::unique_ptr<ScopedUIResource> thumb_resource_;
float thumb_opacity_;
}; };
} // namespace cc } // namespace cc
......
...@@ -26,6 +26,9 @@ class MockScrollbar : public FakeScrollbar { ...@@ -26,6 +26,9 @@ class MockScrollbar : public FakeScrollbar {
/*has_thumb*/ true, /*has_thumb*/ true,
/*is_overlay*/ false) {} /*is_overlay*/ false) {}
MOCK_METHOD2(PaintPart, void(PaintCanvas* canvas, ScrollbarPart part)); MOCK_METHOD2(PaintPart, void(PaintCanvas* canvas, ScrollbarPart part));
private:
~MockScrollbar() override = default;
}; };
TEST(PaintedScrollbarLayerTest, NeedsPaint) { TEST(PaintedScrollbarLayerTest, NeedsPaint) {
...@@ -36,9 +39,9 @@ TEST(PaintedScrollbarLayerTest, NeedsPaint) { ...@@ -36,9 +39,9 @@ TEST(PaintedScrollbarLayerTest, NeedsPaint) {
auto layer_tree_host = FakeLayerTreeHost::Create( auto layer_tree_host = FakeLayerTreeHost::Create(
&fake_client_, &task_graph_runner_, animation_host.get()); &fake_client_, &task_graph_runner_, animation_host.get());
MockScrollbar* scrollbar = new MockScrollbar(); auto scrollbar = base::MakeRefCounted<MockScrollbar>();
scoped_refptr<PaintedScrollbarLayer> scrollbar_layer = scoped_refptr<PaintedScrollbarLayer> scrollbar_layer =
PaintedScrollbarLayer::Create(std::unique_ptr<Scrollbar>(scrollbar)); PaintedScrollbarLayer::Create(scrollbar);
scrollbar_layer->SetIsDrawable(true); scrollbar_layer->SetIsDrawable(true);
scrollbar_layer->SetBounds(gfx::Size(100, 100)); scrollbar_layer->SetBounds(gfx::Size(100, 100));
...@@ -55,13 +58,13 @@ TEST(PaintedScrollbarLayerTest, NeedsPaint) { ...@@ -55,13 +58,13 @@ TEST(PaintedScrollbarLayerTest, NeedsPaint) {
EXPECT_CALL(*scrollbar, PaintPart(_, THUMB)).Times(1); EXPECT_CALL(*scrollbar, PaintPart(_, THUMB)).Times(1);
EXPECT_CALL(*scrollbar, PaintPart(_, TRACK)).Times(1); EXPECT_CALL(*scrollbar, PaintPart(_, TRACK)).Times(1);
scrollbar_layer->Update(); scrollbar_layer->Update();
Mock::VerifyAndClearExpectations(scrollbar); Mock::VerifyAndClearExpectations(scrollbar.get());
// The next update will paint nothing because the first update caused a paint. // The next update will paint nothing because the first update caused a paint.
EXPECT_CALL(*scrollbar, PaintPart(_, THUMB)).Times(0); EXPECT_CALL(*scrollbar, PaintPart(_, THUMB)).Times(0);
EXPECT_CALL(*scrollbar, PaintPart(_, TRACK)).Times(0); EXPECT_CALL(*scrollbar, PaintPart(_, TRACK)).Times(0);
scrollbar_layer->Update(); scrollbar_layer->Update();
Mock::VerifyAndClearExpectations(scrollbar); Mock::VerifyAndClearExpectations(scrollbar.get());
// Enable the thumb. // Enable the thumb.
EXPECT_CALL(*scrollbar, PaintPart(_, THUMB)).Times(1); EXPECT_CALL(*scrollbar, PaintPart(_, THUMB)).Times(1);
...@@ -69,7 +72,7 @@ TEST(PaintedScrollbarLayerTest, NeedsPaint) { ...@@ -69,7 +72,7 @@ TEST(PaintedScrollbarLayerTest, NeedsPaint) {
scrollbar->set_needs_paint_thumb(true); scrollbar->set_needs_paint_thumb(true);
scrollbar->set_needs_paint_track(false); scrollbar->set_needs_paint_track(false);
scrollbar_layer->Update(); scrollbar_layer->Update();
Mock::VerifyAndClearExpectations(scrollbar); Mock::VerifyAndClearExpectations(scrollbar.get());
// Enable the track. // Enable the track.
EXPECT_CALL(*scrollbar, PaintPart(_, THUMB)).Times(0); EXPECT_CALL(*scrollbar, PaintPart(_, THUMB)).Times(0);
...@@ -77,7 +80,7 @@ TEST(PaintedScrollbarLayerTest, NeedsPaint) { ...@@ -77,7 +80,7 @@ TEST(PaintedScrollbarLayerTest, NeedsPaint) {
scrollbar->set_needs_paint_thumb(false); scrollbar->set_needs_paint_thumb(false);
scrollbar->set_needs_paint_track(true); scrollbar->set_needs_paint_track(true);
scrollbar_layer->Update(); scrollbar_layer->Update();
Mock::VerifyAndClearExpectations(scrollbar); Mock::VerifyAndClearExpectations(scrollbar.get());
} }
} // namespace } // namespace
......
...@@ -137,7 +137,7 @@ class BaseScrollbarLayerTest : public testing::Test { ...@@ -137,7 +137,7 @@ class BaseScrollbarLayerTest : public testing::Test {
LayerImpl* LayerImplForScrollAreaAndScrollbar( LayerImpl* LayerImplForScrollAreaAndScrollbar(
FakeLayerTreeHost* host, FakeLayerTreeHost* host,
std::unique_ptr<Scrollbar> scrollbar, scoped_refptr<Scrollbar> scrollbar,
bool reverse_order, bool reverse_order,
bool use_solid_color_scrollbar, bool use_solid_color_scrollbar,
int thumb_thickness, int thumb_thickness,
...@@ -195,6 +195,9 @@ class FakePaintedOverlayScrollbar : public FakeScrollbar { ...@@ -195,6 +195,9 @@ class FakePaintedOverlayScrollbar : public FakeScrollbar {
gfx::Rect NinePatchThumbAperture() const override { gfx::Rect NinePatchThumbAperture() const override {
return gfx::Rect(1, 1, 1, 1); return gfx::Rect(1, 1, 1, 1);
} }
private:
~FakePaintedOverlayScrollbar() override = default;
}; };
// Test that a painted overlay scrollbar will repaint and recrate its resource // Test that a painted overlay scrollbar will repaint and recrate its resource
...@@ -203,11 +206,9 @@ class FakePaintedOverlayScrollbar : public FakeScrollbar { ...@@ -203,11 +206,9 @@ class FakePaintedOverlayScrollbar : public FakeScrollbar {
TEST_F(ScrollbarLayerTest, RepaintOverlayWhenResourceDisposed) { TEST_F(ScrollbarLayerTest, RepaintOverlayWhenResourceDisposed) {
scoped_refptr<Layer> layer_tree_root = Layer::Create(); scoped_refptr<Layer> layer_tree_root = Layer::Create();
scoped_refptr<Layer> content_layer = Layer::Create(); scoped_refptr<Layer> content_layer = Layer::Create();
std::unique_ptr<FakePaintedOverlayScrollbar> scrollbar( auto fake_scrollbar = base::MakeRefCounted<FakePaintedOverlayScrollbar>();
new FakePaintedOverlayScrollbar);
FakePaintedOverlayScrollbar* fake_scrollbar = scrollbar.get();
scoped_refptr<PaintedOverlayScrollbarLayer> scrollbar_layer = scoped_refptr<PaintedOverlayScrollbarLayer> scrollbar_layer =
PaintedOverlayScrollbarLayer::Create(std::move(scrollbar)); PaintedOverlayScrollbarLayer::Create(fake_scrollbar);
scrollbar_layer->SetScrollElementId(layer_tree_root->element_id()); scrollbar_layer->SetScrollElementId(layer_tree_root->element_id());
// Setup. // Setup.
...@@ -258,11 +259,12 @@ class FakeNinePatchScrollbar : public FakeScrollbar { ...@@ -258,11 +259,12 @@ class FakeNinePatchScrollbar : public FakeScrollbar {
: FakeScrollbar(/*paint*/ true, /*has_thumb*/ true, /*is_overlay*/ true) { : FakeScrollbar(/*paint*/ true, /*has_thumb*/ true, /*is_overlay*/ true) {
} }
bool UsesNinePatchThumbResource() const override { return true; } bool UsesNinePatchThumbResource() const override { return true; }
private:
~FakeNinePatchScrollbar() override = default;
}; };
TEST_F(ScrollbarLayerTest, ScrollElementIdPushedAcrossCommit) { TEST_F(ScrollbarLayerTest, ScrollElementIdPushedAcrossCommit) {
std::unique_ptr<Scrollbar> scrollbar1(new FakeScrollbar);
std::unique_ptr<Scrollbar> scrollbar2(new FakeNinePatchScrollbar);
scoped_refptr<Layer> layer_tree_root = Layer::Create(); scoped_refptr<Layer> layer_tree_root = Layer::Create();
scoped_refptr<Layer> layer_a = Layer::Create(); scoped_refptr<Layer> layer_a = Layer::Create();
scoped_refptr<Layer> layer_b = Layer::Create(); scoped_refptr<Layer> layer_b = Layer::Create();
...@@ -270,10 +272,11 @@ TEST_F(ScrollbarLayerTest, ScrollElementIdPushedAcrossCommit) { ...@@ -270,10 +272,11 @@ TEST_F(ScrollbarLayerTest, ScrollElementIdPushedAcrossCommit) {
layer_b->SetElementId(LayerIdToElementIdForTesting(layer_b->id())); layer_b->SetElementId(LayerIdToElementIdForTesting(layer_b->id()));
scoped_refptr<PaintedScrollbarLayer> painted_scrollbar_layer = scoped_refptr<PaintedScrollbarLayer> painted_scrollbar_layer =
PaintedScrollbarLayer::Create(std::move(scrollbar1)); PaintedScrollbarLayer::Create(base::MakeRefCounted<FakeScrollbar>());
painted_scrollbar_layer->SetScrollElementId(layer_a->element_id()); painted_scrollbar_layer->SetScrollElementId(layer_a->element_id());
scoped_refptr<PaintedOverlayScrollbarLayer> painted_overlay_scrollbar_layer = scoped_refptr<PaintedOverlayScrollbarLayer> painted_overlay_scrollbar_layer =
PaintedOverlayScrollbarLayer::Create(std::move(scrollbar2)); PaintedOverlayScrollbarLayer::Create(
base::MakeRefCounted<FakeNinePatchScrollbar>());
painted_overlay_scrollbar_layer->SetScrollElementId(layer_a->element_id()); painted_overlay_scrollbar_layer->SetScrollElementId(layer_a->element_id());
scoped_refptr<SolidColorScrollbarLayer> solid_color_scrollbar_layer = scoped_refptr<SolidColorScrollbarLayer> solid_color_scrollbar_layer =
SolidColorScrollbarLayer::Create(VERTICAL, 1, 1, false); SolidColorScrollbarLayer::Create(VERTICAL, 1, 1, false);
...@@ -331,13 +334,12 @@ TEST_F(ScrollbarLayerTest, ScrollElementIdPushedAcrossCommit) { ...@@ -331,13 +334,12 @@ TEST_F(ScrollbarLayerTest, ScrollElementIdPushedAcrossCommit) {
} }
TEST_F(ScrollbarLayerTest, ScrollOffsetSynchronization) { TEST_F(ScrollbarLayerTest, ScrollOffsetSynchronization) {
std::unique_ptr<Scrollbar> scrollbar(new FakeScrollbar);
scoped_refptr<Layer> layer_tree_root = Layer::Create(); scoped_refptr<Layer> layer_tree_root = Layer::Create();
scoped_refptr<Layer> scroll_layer = Layer::Create(); scoped_refptr<Layer> scroll_layer = Layer::Create();
scroll_layer->SetElementId(LayerIdToElementIdForTesting(scroll_layer->id())); scroll_layer->SetElementId(LayerIdToElementIdForTesting(scroll_layer->id()));
scoped_refptr<Layer> content_layer = Layer::Create(); scoped_refptr<Layer> content_layer = Layer::Create();
scoped_refptr<PaintedScrollbarLayer> scrollbar_layer = scoped_refptr<PaintedScrollbarLayer> scrollbar_layer =
PaintedScrollbarLayer::Create(std::move(scrollbar)); PaintedScrollbarLayer::Create(base::MakeRefCounted<FakeScrollbar>());
scrollbar_layer->SetScrollElementId(scroll_layer->element_id()); scrollbar_layer->SetScrollElementId(scroll_layer->element_id());
// Choose bounds to give max_scroll_offset = (30, 50). // Choose bounds to give max_scroll_offset = (30, 50).
...@@ -571,9 +573,9 @@ TEST_F(ScrollbarLayerTest, SolidColorDrawQuads) { ...@@ -571,9 +573,9 @@ TEST_F(ScrollbarLayerTest, SolidColorDrawQuads) {
const int kTrackStart = 1; const int kTrackStart = 1;
const int kTrackLength = 100; const int kTrackLength = 100;
std::unique_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true));
LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar(
layer_tree_host_.get(), std::move(scrollbar), false, true, layer_tree_host_.get(),
base::MakeRefCounted<FakeScrollbar>(false, true, true), false, true,
kThumbThickness, kTrackStart); kThumbThickness, kTrackStart);
ScrollbarLayerImplBase* scrollbar_layer_impl = ScrollbarLayerImplBase* scrollbar_layer_impl =
static_cast<SolidColorScrollbarLayerImpl*>( static_cast<SolidColorScrollbarLayerImpl*>(
...@@ -632,16 +634,13 @@ TEST_F(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) { ...@@ -632,16 +634,13 @@ TEST_F(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) {
const int kTrackStart = 0; const int kTrackStart = 0;
const int kTrackLength = 10; const int kTrackLength = 10;
std::unique_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true));
scoped_refptr<Layer> layer_tree_root = Layer::Create(); scoped_refptr<Layer> layer_tree_root = Layer::Create();
scoped_refptr<Layer> scroll_layer = Layer::Create(); scoped_refptr<Layer> scroll_layer = Layer::Create();
scroll_layer->SetElementId(LayerIdToElementIdForTesting(scroll_layer->id())); scroll_layer->SetElementId(LayerIdToElementIdForTesting(scroll_layer->id()));
scoped_refptr<Layer> child1 = Layer::Create(); scoped_refptr<Layer> child1 = Layer::Create();
const bool kIsLeftSideVerticalScrollbar = false; const bool kIsLeftSideVerticalScrollbar = false;
scoped_refptr<SolidColorScrollbarLayer> child2 = scoped_refptr<SolidColorScrollbarLayer> child2 =
SolidColorScrollbarLayer::Create(scrollbar->Orientation(), SolidColorScrollbarLayer::Create(HORIZONTAL, kThumbThickness, kTrackStart,
kThumbThickness, kTrackStart,
kIsLeftSideVerticalScrollbar); kIsLeftSideVerticalScrollbar);
child2->SetScrollElementId(scroll_layer->element_id()); child2->SetScrollElementId(scroll_layer->element_id());
scroll_layer->AddChild(child1); scroll_layer->AddChild(child1);
...@@ -689,8 +688,6 @@ TEST_F(ScrollbarLayerTest, ScrollbarLayerOpacity) { ...@@ -689,8 +688,6 @@ TEST_F(ScrollbarLayerTest, ScrollbarLayerOpacity) {
const int kThumbThickness = 3; const int kThumbThickness = 3;
const int kTrackStart = 0; const int kTrackStart = 0;
std::unique_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true));
scoped_refptr<Layer> layer_tree_root = Layer::Create(); scoped_refptr<Layer> layer_tree_root = Layer::Create();
scoped_refptr<Layer> scroll_layer = Layer::Create(); scoped_refptr<Layer> scroll_layer = Layer::Create();
scroll_layer->SetElementId(ElementId(200)); scroll_layer->SetElementId(ElementId(200));
...@@ -698,8 +695,7 @@ TEST_F(ScrollbarLayerTest, ScrollbarLayerOpacity) { ...@@ -698,8 +695,7 @@ TEST_F(ScrollbarLayerTest, ScrollbarLayerOpacity) {
scoped_refptr<SolidColorScrollbarLayer> scrollbar_layer; scoped_refptr<SolidColorScrollbarLayer> scrollbar_layer;
const bool kIsLeftSideVerticalScrollbar = false; const bool kIsLeftSideVerticalScrollbar = false;
scrollbar_layer = SolidColorScrollbarLayer::Create( scrollbar_layer = SolidColorScrollbarLayer::Create(
scrollbar->Orientation(), kThumbThickness, kTrackStart, HORIZONTAL, kThumbThickness, kTrackStart, kIsLeftSideVerticalScrollbar);
kIsLeftSideVerticalScrollbar);
scrollbar_layer->SetScrollElementId(scroll_layer->element_id()); scrollbar_layer->SetScrollElementId(scroll_layer->element_id());
scrollbar_layer->SetElementId(ElementId(300)); scrollbar_layer->SetElementId(ElementId(300));
scroll_layer->AddChild(child1); scroll_layer->AddChild(child1);
...@@ -767,7 +763,6 @@ TEST_F(ScrollbarLayerTest, ScrollbarLayerPushProperties) { ...@@ -767,7 +763,6 @@ TEST_F(ScrollbarLayerTest, ScrollbarLayerPushProperties) {
// its properties after scroll layer. // its properties after scroll layer.
const int kThumbThickness = 3; const int kThumbThickness = 3;
const int kTrackStart = 0; const int kTrackStart = 0;
std::unique_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true));
scoped_refptr<Layer> layer_tree_root = Layer::Create(); scoped_refptr<Layer> layer_tree_root = Layer::Create();
scoped_refptr<Layer> scroll_layer = Layer::Create(); scoped_refptr<Layer> scroll_layer = Layer::Create();
...@@ -775,8 +770,7 @@ TEST_F(ScrollbarLayerTest, ScrollbarLayerPushProperties) { ...@@ -775,8 +770,7 @@ TEST_F(ScrollbarLayerTest, ScrollbarLayerPushProperties) {
scoped_refptr<Layer> child1 = Layer::Create(); scoped_refptr<Layer> child1 = Layer::Create();
const bool kIsLeftSideVerticalScrollbar = false; const bool kIsLeftSideVerticalScrollbar = false;
scoped_refptr<SolidColorScrollbarLayer> scrollbar_layer = scoped_refptr<SolidColorScrollbarLayer> scrollbar_layer =
SolidColorScrollbarLayer::Create(scrollbar->Orientation(), SolidColorScrollbarLayer::Create(HORIZONTAL, kThumbThickness, kTrackStart,
kThumbThickness, kTrackStart,
kIsLeftSideVerticalScrollbar); kIsLeftSideVerticalScrollbar);
scrollbar_layer->SetScrollElementId(scroll_layer->element_id()); scrollbar_layer->SetScrollElementId(scroll_layer->element_id());
scroll_layer->AddChild(child1); scroll_layer->AddChild(child1);
...@@ -915,10 +909,8 @@ TEST_F(AuraScrollbarLayerTest, ScrollbarLayerCreateAfterSetScrollable) { ...@@ -915,10 +909,8 @@ TEST_F(AuraScrollbarLayerTest, ScrollbarLayerCreateAfterSetScrollable) {
layer_tree_host_->CommitAndCreatePendingTree(); layer_tree_host_->CommitAndCreatePendingTree();
host_impl->ActivateSyncTree(); host_impl->ActivateSyncTree();
std::unique_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true));
scoped_refptr<SolidColorScrollbarLayer> scrollbar_layer = scoped_refptr<SolidColorScrollbarLayer> scrollbar_layer =
SolidColorScrollbarLayer::Create(scrollbar->Orientation(), SolidColorScrollbarLayer::Create(HORIZONTAL, kThumbThickness, kTrackStart,
kThumbThickness, kTrackStart,
kIsLeftSideVerticalScrollbar); kIsLeftSideVerticalScrollbar);
scrollbar_layer->SetScrollElementId(scroll_layer->element_id()); scrollbar_layer->SetScrollElementId(scroll_layer->element_id());
scroll_layer->InsertChild(scrollbar_layer, 1); scroll_layer->InsertChild(scrollbar_layer, 1);
...@@ -1035,7 +1027,6 @@ class ScrollbarLayerTestResourceCreationAndRelease : public ScrollbarLayerTest { ...@@ -1035,7 +1027,6 @@ class ScrollbarLayerTestResourceCreationAndRelease : public ScrollbarLayerTest {
int expected_created, int expected_created,
int expected_deleted, int expected_deleted,
bool use_solid_color_scrollbar) { bool use_solid_color_scrollbar) {
std::unique_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, false));
scoped_refptr<Layer> layer_tree_root = Layer::Create(); scoped_refptr<Layer> layer_tree_root = Layer::Create();
scoped_refptr<Layer> content_layer = Layer::Create(); scoped_refptr<Layer> content_layer = Layer::Create();
scoped_refptr<ScrollbarLayerBase> scrollbar_layer; scoped_refptr<ScrollbarLayerBase> scrollbar_layer;
...@@ -1044,10 +1035,11 @@ class ScrollbarLayerTestResourceCreationAndRelease : public ScrollbarLayerTest { ...@@ -1044,10 +1035,11 @@ class ScrollbarLayerTestResourceCreationAndRelease : public ScrollbarLayerTest {
const int kTrackStart = 0; const int kTrackStart = 0;
const bool kIsLeftSideVerticalScrollbar = false; const bool kIsLeftSideVerticalScrollbar = false;
scrollbar_layer = SolidColorScrollbarLayer::Create( scrollbar_layer = SolidColorScrollbarLayer::Create(
scrollbar->Orientation(), kThumbThickness, kTrackStart, HORIZONTAL, kThumbThickness, kTrackStart,
kIsLeftSideVerticalScrollbar); kIsLeftSideVerticalScrollbar);
} else { } else {
scrollbar_layer = PaintedScrollbarLayer::Create(std::move(scrollbar)); scrollbar_layer = PaintedScrollbarLayer::Create(
base::MakeRefCounted<FakeScrollbar>(false, true, false));
} }
scrollbar_layer->SetScrollElementId(layer_tree_root->element_id()); scrollbar_layer->SetScrollElementId(layer_tree_root->element_id());
layer_tree_root->AddChild(content_layer); layer_tree_root->AddChild(content_layer);
......
...@@ -24,20 +24,20 @@ scoped_refptr<FakePaintedScrollbarLayer> FakePaintedScrollbarLayer::Create( ...@@ -24,20 +24,20 @@ scoped_refptr<FakePaintedScrollbarLayer> FakePaintedScrollbarLayer::Create(
bool is_left_side_vertical_scrollbar, bool is_left_side_vertical_scrollbar,
bool is_overlay, bool is_overlay,
ElementId scrolling_element_id) { ElementId scrolling_element_id) {
FakeScrollbar* fake_scrollbar = auto fake_scrollbar = base::MakeRefCounted<FakeScrollbar>(
new FakeScrollbar(paint_during_update, has_thumb, orientation, paint_during_update, has_thumb, orientation,
is_left_side_vertical_scrollbar, is_overlay); is_left_side_vertical_scrollbar, is_overlay);
return base::WrapRefCounted( return base::WrapRefCounted(new FakePaintedScrollbarLayer(
new FakePaintedScrollbarLayer(fake_scrollbar, scrolling_element_id)); std::move(fake_scrollbar), scrolling_element_id));
} }
FakePaintedScrollbarLayer::FakePaintedScrollbarLayer( FakePaintedScrollbarLayer::FakePaintedScrollbarLayer(
FakeScrollbar* fake_scrollbar, scoped_refptr<FakeScrollbar> fake_scrollbar,
ElementId scroll_element_id) ElementId scroll_element_id)
: PaintedScrollbarLayer(std::unique_ptr<Scrollbar>(fake_scrollbar)), : PaintedScrollbarLayer(fake_scrollbar),
update_count_(0), update_count_(0),
push_properties_count_(0), push_properties_count_(0),
fake_scrollbar_(fake_scrollbar) { fake_scrollbar_(fake_scrollbar.get()) {
SetScrollElementId(scroll_element_id); SetScrollElementId(scroll_element_id);
SetBounds(gfx::Size(1, 1)); SetBounds(gfx::Size(1, 1));
SetIsDrawable(true); SetIsDrawable(true);
......
...@@ -48,14 +48,12 @@ class FakePaintedScrollbarLayer : public PaintedScrollbarLayer { ...@@ -48,14 +48,12 @@ class FakePaintedScrollbarLayer : public PaintedScrollbarLayer {
UIResourceId thumb_resource_id() { UIResourceId thumb_resource_id() {
return PaintedScrollbarLayer::thumb_resource_id(); return PaintedScrollbarLayer::thumb_resource_id();
} }
FakeScrollbar* fake_scrollbar() { FakeScrollbar* fake_scrollbar() { return fake_scrollbar_; }
return fake_scrollbar_;
}
using PaintedScrollbarLayer::UpdateInternalContentScale; using PaintedScrollbarLayer::UpdateInternalContentScale;
using PaintedScrollbarLayer::UpdateThumbAndTrackGeometry; using PaintedScrollbarLayer::UpdateThumbAndTrackGeometry;
private: private:
FakePaintedScrollbarLayer(FakeScrollbar* fake_scrollbar, FakePaintedScrollbarLayer(scoped_refptr<FakeScrollbar> fake_scrollbar,
ElementId scrolling_element_id); ElementId scrolling_element_id);
~FakePaintedScrollbarLayer() override; ~FakePaintedScrollbarLayer() override;
......
...@@ -21,7 +21,6 @@ class FakeScrollbar : public Scrollbar { ...@@ -21,7 +21,6 @@ class FakeScrollbar : public Scrollbar {
bool is_left_side_vertical_scrollbar, bool is_left_side_vertical_scrollbar,
bool is_overlay); bool is_overlay);
FakeScrollbar(const FakeScrollbar&) = delete; FakeScrollbar(const FakeScrollbar&) = delete;
~FakeScrollbar() override;
FakeScrollbar& operator=(const FakeScrollbar&) = delete; FakeScrollbar& operator=(const FakeScrollbar&) = delete;
...@@ -65,6 +64,9 @@ class FakeScrollbar : public Scrollbar { ...@@ -65,6 +64,9 @@ class FakeScrollbar : public Scrollbar {
gfx::Rect GetPartRect(ScrollbarPart part) const; gfx::Rect GetPartRect(ScrollbarPart part) const;
protected:
~FakeScrollbar() override;
private: private:
bool paint_; bool paint_;
bool has_thumb_; bool has_thumb_;
......
...@@ -68,6 +68,8 @@ class PaintedScrollbar : public FakeScrollbar { ...@@ -68,6 +68,8 @@ class PaintedScrollbar : public FakeScrollbar {
void set_paint_scale(int scale) { paint_scale_ = scale; } void set_paint_scale(int scale) { paint_scale_ = scale; }
private: private:
~PaintedScrollbar() override = default;
int paint_scale_ = 4; int paint_scale_ = 4;
SkColor color_ = SK_ColorGREEN; SkColor color_ = SK_ColorGREEN;
}; };
...@@ -88,7 +90,7 @@ TEST_P(LayerTreeHostScrollbarsPixelTest, NoScale) { ...@@ -88,7 +90,7 @@ TEST_P(LayerTreeHostScrollbarsPixelTest, NoScale) {
scoped_refptr<SolidColorLayer> background = scoped_refptr<SolidColorLayer> background =
CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorWHITE); CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorWHITE);
auto scrollbar = std::make_unique<PaintedScrollbar>(gfx::Size(200, 200)); auto scrollbar = base::MakeRefCounted<PaintedScrollbar>(gfx::Size(200, 200));
scoped_refptr<PaintedScrollbarLayer> layer = scoped_refptr<PaintedScrollbarLayer> layer =
PaintedScrollbarLayer::Create(std::move(scrollbar)); PaintedScrollbarLayer::Create(std::move(scrollbar));
layer->SetIsDrawable(true); layer->SetIsDrawable(true);
...@@ -107,7 +109,7 @@ TEST_P(LayerTreeHostScrollbarsPixelTest, DeviceScaleFactor) { ...@@ -107,7 +109,7 @@ TEST_P(LayerTreeHostScrollbarsPixelTest, DeviceScaleFactor) {
scoped_refptr<SolidColorLayer> background = scoped_refptr<SolidColorLayer> background =
CreateSolidColorLayer(gfx::Rect(100, 100), SK_ColorWHITE); CreateSolidColorLayer(gfx::Rect(100, 100), SK_ColorWHITE);
auto scrollbar = std::make_unique<PaintedScrollbar>(gfx::Size(100, 100)); auto scrollbar = base::MakeRefCounted<PaintedScrollbar>(gfx::Size(100, 100));
scoped_refptr<PaintedScrollbarLayer> layer = scoped_refptr<PaintedScrollbarLayer> layer =
PaintedScrollbarLayer::Create(std::move(scrollbar)); PaintedScrollbarLayer::Create(std::move(scrollbar));
layer->SetIsDrawable(true); layer->SetIsDrawable(true);
...@@ -122,7 +124,7 @@ TEST_P(LayerTreeHostScrollbarsPixelTest, TransformScale) { ...@@ -122,7 +124,7 @@ TEST_P(LayerTreeHostScrollbarsPixelTest, TransformScale) {
scoped_refptr<SolidColorLayer> background = scoped_refptr<SolidColorLayer> background =
CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorWHITE); CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorWHITE);
auto scrollbar = std::make_unique<PaintedScrollbar>(gfx::Size(100, 100)); auto scrollbar = base::MakeRefCounted<PaintedScrollbar>(gfx::Size(100, 100));
scoped_refptr<PaintedScrollbarLayer> layer = scoped_refptr<PaintedScrollbarLayer> layer =
PaintedScrollbarLayer::Create(std::move(scrollbar)); PaintedScrollbarLayer::Create(std::move(scrollbar));
layer->SetIsDrawable(true); layer->SetIsDrawable(true);
...@@ -149,7 +151,7 @@ TEST_P(LayerTreeHostScrollbarsPixelTest, MAYBE_HugeTransformScale) { ...@@ -149,7 +151,7 @@ TEST_P(LayerTreeHostScrollbarsPixelTest, MAYBE_HugeTransformScale) {
scoped_refptr<SolidColorLayer> background = scoped_refptr<SolidColorLayer> background =
CreateSolidColorLayer(gfx::Rect(400, 400), SK_ColorWHITE); CreateSolidColorLayer(gfx::Rect(400, 400), SK_ColorWHITE);
auto scrollbar = std::make_unique<PaintedScrollbar>(gfx::Size(10, 400)); auto scrollbar = base::MakeRefCounted<PaintedScrollbar>(gfx::Size(10, 400));
scrollbar->set_paint_scale(1); scrollbar->set_paint_scale(1);
scoped_refptr<PaintedScrollbarLayer> layer = scoped_refptr<PaintedScrollbarLayer> layer =
PaintedScrollbarLayer::Create(std::move(scrollbar)); PaintedScrollbarLayer::Create(std::move(scrollbar));
...@@ -245,6 +247,9 @@ class PaintedOverlayScrollbar : public FakeScrollbar { ...@@ -245,6 +247,9 @@ class PaintedOverlayScrollbar : public FakeScrollbar {
gfx::Rect NinePatchThumbAperture() const override { gfx::Rect NinePatchThumbAperture() const override {
return gfx::Rect(3, 3, 1, 1); return gfx::Rect(3, 3, 1, 1);
} }
private:
~PaintedOverlayScrollbar() override = default;
}; };
INSTANTIATE_TEST_SUITE_P(, INSTANTIATE_TEST_SUITE_P(,
...@@ -257,7 +262,7 @@ TEST_P(LayerTreeHostOverlayScrollbarsPixelTest, NinePatchScrollbarScaledUp) { ...@@ -257,7 +262,7 @@ TEST_P(LayerTreeHostOverlayScrollbarsPixelTest, NinePatchScrollbarScaledUp) {
scoped_refptr<SolidColorLayer> background = scoped_refptr<SolidColorLayer> background =
CreateSolidColorLayer(gfx::Rect(400, 400), SK_ColorWHITE); CreateSolidColorLayer(gfx::Rect(400, 400), SK_ColorWHITE);
auto scrollbar = std::make_unique<PaintedOverlayScrollbar>(); auto scrollbar = base::MakeRefCounted<PaintedOverlayScrollbar>();
scoped_refptr<PaintedOverlayScrollbarLayer> layer = scoped_refptr<PaintedOverlayScrollbarLayer> layer =
PaintedOverlayScrollbarLayer::Create(std::move(scrollbar)); PaintedOverlayScrollbarLayer::Create(std::move(scrollbar));
...@@ -281,7 +286,7 @@ TEST_P(LayerTreeHostOverlayScrollbarsPixelTest, NinePatchScrollbarScaledDown) { ...@@ -281,7 +286,7 @@ TEST_P(LayerTreeHostOverlayScrollbarsPixelTest, NinePatchScrollbarScaledDown) {
scoped_refptr<SolidColorLayer> background = scoped_refptr<SolidColorLayer> background =
CreateSolidColorLayer(gfx::Rect(400, 400), SK_ColorWHITE); CreateSolidColorLayer(gfx::Rect(400, 400), SK_ColorWHITE);
auto scrollbar = std::make_unique<PaintedOverlayScrollbar>(); auto scrollbar = base::MakeRefCounted<PaintedOverlayScrollbar>();
scoped_refptr<PaintedOverlayScrollbarLayer> layer = scoped_refptr<PaintedOverlayScrollbarLayer> layer =
PaintedOverlayScrollbarLayer::Create(std::move(scrollbar)); PaintedOverlayScrollbarLayer::Create(std::move(scrollbar));
......
...@@ -983,8 +983,7 @@ class LayerTreeHostContextTestDontUseLostResources ...@@ -983,8 +983,7 @@ class LayerTreeHostContextTestDontUseLostResources
layer_tree_host()->SetDebugState(debug_state); layer_tree_host()->SetDebugState(debug_state);
scoped_refptr<PaintedScrollbarLayer> scrollbar = scoped_refptr<PaintedScrollbarLayer> scrollbar =
PaintedScrollbarLayer::Create( PaintedScrollbarLayer::Create(base::MakeRefCounted<FakeScrollbar>());
std::unique_ptr<Scrollbar>(new FakeScrollbar));
scrollbar->SetScrollElementId(layer->element_id()); scrollbar->SetScrollElementId(layer->element_id());
scrollbar->SetBounds(gfx::Size(10, 10)); scrollbar->SetBounds(gfx::Size(10, 10));
scrollbar->SetIsDrawable(true); scrollbar->SetIsDrawable(true);
......
...@@ -257,8 +257,8 @@ static scoped_refptr<cc::ScrollbarLayerBase> CreateScrollbarLayer( ...@@ -257,8 +257,8 @@ static scoped_refptr<cc::ScrollbarLayerBase> CreateScrollbarLayer(
Scrollbar& scrollbar, Scrollbar& scrollbar,
float device_scale_factor) { float device_scale_factor) {
ScrollbarTheme& theme = scrollbar.GetTheme(); ScrollbarTheme& theme = scrollbar.GetTheme();
auto scrollbar_delegate = auto scrollbar_delegate = base::MakeRefCounted<ScrollbarLayerDelegate>(
std::make_unique<ScrollbarLayerDelegate>(scrollbar, device_scale_factor); scrollbar, device_scale_factor);
scoped_refptr<cc::ScrollbarLayerBase> scrollbar_layer; scoped_refptr<cc::ScrollbarLayerBase> scrollbar_layer;
if (theme.UsesOverlayScrollbars() && theme.UsesNinePatchThumbResource()) { if (theme.UsesOverlayScrollbars() && theme.UsesNinePatchThumbResource()) {
scrollbar_layer = scrollbar_layer =
......
...@@ -4,8 +4,7 @@ ...@@ -4,8 +4,7 @@
#include "third_party/blink/renderer/core/scroll/scrollbar_layer_delegate.h" #include "third_party/blink/renderer/core/scroll/scrollbar_layer_delegate.h"
#include "third_party/blink/public/platform/web_point.h" #include "cc/paint/paint_canvas.h"
#include "third_party/blink/public/platform/web_rect.h"
#include "third_party/blink/renderer/core/scroll/scroll_types.h" #include "third_party/blink/renderer/core/scroll/scroll_types.h"
#include "third_party/blink/renderer/core/scroll/scrollable_area.h" #include "third_party/blink/renderer/core/scroll/scrollable_area.h"
#include "third_party/blink/renderer/core/scroll/scrollbar.h" #include "third_party/blink/renderer/core/scroll/scrollbar.h"
...@@ -39,7 +38,6 @@ class ScopedScrollbarPainter { ...@@ -39,7 +38,6 @@ class ScopedScrollbarPainter {
ScrollbarLayerDelegate::ScrollbarLayerDelegate(blink::Scrollbar& scrollbar, ScrollbarLayerDelegate::ScrollbarLayerDelegate(blink::Scrollbar& scrollbar,
float device_scale_factor) float device_scale_factor)
: scrollbar_(&scrollbar), : scrollbar_(&scrollbar),
theme_(scrollbar.GetTheme()),
device_scale_factor_(device_scale_factor) {} device_scale_factor_(device_scale_factor) {}
ScrollbarLayerDelegate::~ScrollbarLayerDelegate() = default; ScrollbarLayerDelegate::~ScrollbarLayerDelegate() = default;
...@@ -55,7 +53,7 @@ bool ScrollbarLayerDelegate::IsLeftSideVerticalScrollbar() const { ...@@ -55,7 +53,7 @@ bool ScrollbarLayerDelegate::IsLeftSideVerticalScrollbar() const {
} }
bool ScrollbarLayerDelegate::HasThumb() const { bool ScrollbarLayerDelegate::HasThumb() const {
return theme_.HasThumb(*scrollbar_); return scrollbar_->GetTheme().HasThumb(*scrollbar_);
} }
bool ScrollbarLayerDelegate::IsOverlay() const { bool ScrollbarLayerDelegate::IsOverlay() const {
...@@ -67,45 +65,45 @@ gfx::Point ScrollbarLayerDelegate::Location() const { ...@@ -67,45 +65,45 @@ gfx::Point ScrollbarLayerDelegate::Location() const {
} }
int ScrollbarLayerDelegate::ThumbThickness() const { int ScrollbarLayerDelegate::ThumbThickness() const {
IntRect thumb_rect = theme_.ThumbRect(*scrollbar_); IntRect thumb_rect = scrollbar_->GetTheme().ThumbRect(*scrollbar_);
if (scrollbar_->Orientation() == kHorizontalScrollbar) if (scrollbar_->Orientation() == kHorizontalScrollbar)
return thumb_rect.Height(); return thumb_rect.Height();
return thumb_rect.Width(); return thumb_rect.Width();
} }
int ScrollbarLayerDelegate::ThumbLength() const { int ScrollbarLayerDelegate::ThumbLength() const {
IntRect thumb_rect = theme_.ThumbRect(*scrollbar_); IntRect thumb_rect = scrollbar_->GetTheme().ThumbRect(*scrollbar_);
if (scrollbar_->Orientation() == kHorizontalScrollbar) if (scrollbar_->Orientation() == kHorizontalScrollbar)
return thumb_rect.Width(); return thumb_rect.Width();
return thumb_rect.Height(); return thumb_rect.Height();
} }
gfx::Rect ScrollbarLayerDelegate::TrackRect() const { gfx::Rect ScrollbarLayerDelegate::TrackRect() const {
IntRect track_rect = theme_.TrackRect(*scrollbar_); IntRect track_rect = scrollbar_->GetTheme().TrackRect(*scrollbar_);
track_rect.MoveBy(-scrollbar_->Location()); track_rect.MoveBy(-scrollbar_->Location());
return track_rect; return track_rect;
} }
bool ScrollbarLayerDelegate::SupportsDragSnapBack() const { bool ScrollbarLayerDelegate::SupportsDragSnapBack() const {
return theme_.SupportsDragSnapBack(); return scrollbar_->GetTheme().SupportsDragSnapBack();
} }
gfx::Rect ScrollbarLayerDelegate::BackButtonRect() const { gfx::Rect ScrollbarLayerDelegate::BackButtonRect() const {
IntRect back_button_rect = IntRect back_button_rect = scrollbar_->GetTheme().BackButtonRect(
theme_.BackButtonRect(*scrollbar_, blink::kBackButtonStartPart); *scrollbar_, blink::kBackButtonStartPart);
back_button_rect.MoveBy(-scrollbar_->Location()); back_button_rect.MoveBy(-scrollbar_->Location());
return back_button_rect; return back_button_rect;
} }
gfx::Rect ScrollbarLayerDelegate::ForwardButtonRect() const { gfx::Rect ScrollbarLayerDelegate::ForwardButtonRect() const {
IntRect forward_button_rect = IntRect forward_button_rect = scrollbar_->GetTheme().ForwardButtonRect(
theme_.ForwardButtonRect(*scrollbar_, blink::kForwardButtonEndPart); *scrollbar_, blink::kForwardButtonEndPart);
forward_button_rect.MoveBy(-scrollbar_->Location()); forward_button_rect.MoveBy(-scrollbar_->Location());
return forward_button_rect; return forward_button_rect;
} }
float ScrollbarLayerDelegate::ThumbOpacity() const { float ScrollbarLayerDelegate::ThumbOpacity() const {
return theme_.ThumbOpacity(*scrollbar_); return scrollbar_->GetTheme().ThumbOpacity(*scrollbar_);
} }
bool ScrollbarLayerDelegate::NeedsPaintPart(cc::ScrollbarPart part) const { bool ScrollbarLayerDelegate::NeedsPaintPart(cc::ScrollbarPart part) const {
...@@ -115,17 +113,18 @@ bool ScrollbarLayerDelegate::NeedsPaintPart(cc::ScrollbarPart part) const { ...@@ -115,17 +113,18 @@ bool ScrollbarLayerDelegate::NeedsPaintPart(cc::ScrollbarPart part) const {
} }
bool ScrollbarLayerDelegate::UsesNinePatchThumbResource() const { bool ScrollbarLayerDelegate::UsesNinePatchThumbResource() const {
return theme_.UsesNinePatchThumbResource(); return scrollbar_->GetTheme().UsesNinePatchThumbResource();
} }
gfx::Size ScrollbarLayerDelegate::NinePatchThumbCanvasSize() const { gfx::Size ScrollbarLayerDelegate::NinePatchThumbCanvasSize() const {
DCHECK(theme_.UsesNinePatchThumbResource()); DCHECK(scrollbar_->GetTheme().UsesNinePatchThumbResource());
return static_cast<gfx::Size>(theme_.NinePatchThumbCanvasSize(*scrollbar_)); return static_cast<gfx::Size>(
scrollbar_->GetTheme().NinePatchThumbCanvasSize(*scrollbar_));
} }
gfx::Rect ScrollbarLayerDelegate::NinePatchThumbAperture() const { gfx::Rect ScrollbarLayerDelegate::NinePatchThumbAperture() const {
DCHECK(theme_.UsesNinePatchThumbResource()); DCHECK(scrollbar_->GetTheme().UsesNinePatchThumbResource());
return theme_.NinePatchThumbAperture(*scrollbar_); return scrollbar_->GetTheme().NinePatchThumbAperture(*scrollbar_);
} }
bool ScrollbarLayerDelegate::ShouldPaint() const { bool ScrollbarLayerDelegate::ShouldPaint() const {
...@@ -152,28 +151,28 @@ void ScrollbarLayerDelegate::PaintPart(cc::PaintCanvas* canvas, ...@@ -152,28 +151,28 @@ void ScrollbarLayerDelegate::PaintPart(cc::PaintCanvas* canvas,
if (!ShouldPaint()) if (!ShouldPaint())
return; return;
auto& theme = scrollbar_->GetTheme();
ScopedScrollbarPainter painter(*canvas, device_scale_factor_); ScopedScrollbarPainter painter(*canvas, device_scale_factor_);
// The canvas coordinate space is relative to the part's origin. // The canvas coordinate space is relative to the part's origin.
switch (part) { switch (part) {
case cc::THUMB: { case cc::THUMB: {
IntRect rect(IntPoint(), IntRect rect(IntPoint(), UsesNinePatchThumbResource()
UsesNinePatchThumbResource() ? theme.NinePatchThumbCanvasSize(*scrollbar_)
? theme_.NinePatchThumbCanvasSize(*scrollbar_) : theme.ThumbRect(*scrollbar_).Size());
: theme_.ThumbRect(*scrollbar_).Size()); theme.PaintThumb(painter.Context(), *scrollbar_, rect);
theme_.PaintThumb(painter.Context(), *scrollbar_, rect);
scrollbar_->ClearThumbNeedsRepaint(); scrollbar_->ClearThumbNeedsRepaint();
break; break;
} }
case cc::TRACK: { case cc::TRACK: {
theme_.PaintTrackAndButtonsForCompositor(painter.Context(), *scrollbar_); theme.PaintTrackAndButtonsForCompositor(painter.Context(), *scrollbar_);
theme_.PaintTickmarks(painter.Context(), *scrollbar_, theme.PaintTickmarks(painter.Context(), *scrollbar_,
IntRect(TrackRect())); IntRect(TrackRect()));
scrollbar_->ClearTrackNeedsRepaint(); scrollbar_->ClearTrackNeedsRepaint();
break; break;
} }
case cc::TICKMARKS: { case cc::TICKMARKS: {
IntRect rect(IntPoint(), theme_.TrackRect(*scrollbar_).Size()); IntRect rect(IntPoint(), theme.TrackRect(*scrollbar_).Size());
theme_.PaintTickmarks(painter.Context(), *scrollbar_, rect); theme.PaintTickmarks(painter.Context(), *scrollbar_, rect);
break; break;
} }
default: default:
......
...@@ -5,22 +5,14 @@ ...@@ -5,22 +5,14 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_SCROLL_SCROLLBAR_LAYER_DELEGATE_H_ #ifndef THIRD_PARTY_BLINK_RENDERER_CORE_SCROLL_SCROLLBAR_LAYER_DELEGATE_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_SCROLL_SCROLLBAR_LAYER_DELEGATE_H_ #define THIRD_PARTY_BLINK_RENDERER_CORE_SCROLL_SCROLLBAR_LAYER_DELEGATE_H_
#include <memory>
#include "base/macros.h" #include "base/macros.h"
#include "cc/input/scrollbar.h" #include "cc/input/scrollbar.h"
#include "cc/paint/paint_canvas.h"
#include "third_party/blink/renderer/core/core_export.h" #include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/platform/heap/persistent.h" #include "third_party/blink/renderer/platform/heap/persistent.h"
namespace cc {
class PaintCanvas;
}
namespace blink { namespace blink {
class Scrollbar; class Scrollbar;
class ScrollbarTheme;
// Implementation of cc::Scrollbar, providing a delegate to query about // Implementation of cc::Scrollbar, providing a delegate to query about
// scrollbar state and to paint the image in the scrollbar. // scrollbar state and to paint the image in the scrollbar.
...@@ -28,7 +20,6 @@ class CORE_EXPORT ScrollbarLayerDelegate : public cc::Scrollbar { ...@@ -28,7 +20,6 @@ class CORE_EXPORT ScrollbarLayerDelegate : public cc::Scrollbar {
public: public:
ScrollbarLayerDelegate(blink::Scrollbar& scrollbar, ScrollbarLayerDelegate(blink::Scrollbar& scrollbar,
float device_scale_factor); float device_scale_factor);
~ScrollbarLayerDelegate() override;
// cc::Scrollbar implementation. // cc::Scrollbar implementation.
cc::ScrollbarOrientation Orientation() const override; cc::ScrollbarOrientation Orientation() const override;
...@@ -59,13 +50,11 @@ class CORE_EXPORT ScrollbarLayerDelegate : public cc::Scrollbar { ...@@ -59,13 +50,11 @@ class CORE_EXPORT ScrollbarLayerDelegate : public cc::Scrollbar {
gfx::Rect NinePatchThumbAperture() const override; gfx::Rect NinePatchThumbAperture() const override;
private: private:
bool ShouldPaint() const; ~ScrollbarLayerDelegate() override;
// Accessed by main and compositor threads, e.g., the compositor thread bool ShouldPaint() const;
// checks |Orientation()|.
CrossThreadPersistent<blink::Scrollbar> scrollbar_;
ScrollbarTheme& theme_; Persistent<blink::Scrollbar> scrollbar_;
float device_scale_factor_; float device_scale_factor_;
DISALLOW_COPY_AND_ASSIGN(ScrollbarLayerDelegate); DISALLOW_COPY_AND_ASSIGN(ScrollbarLayerDelegate);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment