blob: b01ec88b9d6010ea444d65c066b52759fad28e67 [file] [log] [blame]
[email protected]89583602012-09-18 21:51:411// Copyright 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]a8461d82012-10-16 21:11:145#include "cc/scrollbar_layer.h"
[email protected]89583602012-09-18 21:51:416
[email protected]c4040a522012-10-21 15:01:407#include "cc/scrollbar_animation_controller.h"
8#include "cc/scrollbar_layer_impl.h"
[email protected]4456eee22012-10-19 18:16:389#include "cc/single_thread_proxy.h"
[email protected]101441ce2012-10-16 01:45:0310#include "cc/test/fake_web_scrollbar_theme_geometry.h"
[email protected]a8461d82012-10-16 21:11:1411#include "cc/tree_synchronizer.h"
[email protected]7f0c53db2012-10-02 00:23:1812#include "testing/gtest/include/gtest/gtest.h"
[email protected]89583602012-09-18 21:51:4113#include <public/WebScrollbar.h>
14#include <public/WebScrollbarThemeGeometry.h>
15#include <public/WebScrollbarThemePainter.h>
16
[email protected]ba565742012-11-10 09:29:4817namespace cc {
[email protected]89583602012-09-18 21:51:4118namespace {
19
20class FakeWebScrollbar : public WebKit::WebScrollbar {
21public:
[email protected]31161582012-10-16 21:08:0322 static scoped_ptr<FakeWebScrollbar> create() { return make_scoped_ptr(new FakeWebScrollbar()); }
[email protected]89583602012-09-18 21:51:4123
24 // WebScrollbar implementation
25 virtual bool isOverlay() const OVERRIDE { return false; }
26 virtual int value() const OVERRIDE { return 0; }
27 virtual WebKit::WebPoint location() const OVERRIDE { return WebKit::WebPoint(); }
28 virtual WebKit::WebSize size() const OVERRIDE { return WebKit::WebSize(); }
29 virtual bool enabled() const OVERRIDE { return true; }
30 virtual int maximum() const OVERRIDE { return 0; }
31 virtual int totalSize() const OVERRIDE { return 0; }
32 virtual bool isScrollViewScrollbar() const OVERRIDE { return false; }
33 virtual bool isScrollableAreaActive() const OVERRIDE { return true; }
34 virtual void getTickmarks(WebKit::WebVector<WebKit::WebRect>&) const OVERRIDE { }
35 virtual ScrollbarControlSize controlSize() const OVERRIDE { return WebScrollbar::RegularScrollbar; }
36 virtual ScrollbarPart pressedPart() const OVERRIDE { return WebScrollbar::NoPart; }
37 virtual ScrollbarPart hoveredPart() const OVERRIDE { return WebScrollbar::NoPart; }
38 virtual ScrollbarOverlayStyle scrollbarOverlayStyle() const OVERRIDE { return WebScrollbar::ScrollbarOverlayStyleDefault; }
39 virtual bool isCustomScrollbar() const OVERRIDE { return false; }
40 virtual Orientation orientation() const OVERRIDE { return WebScrollbar::Horizontal; }
41};
42
[email protected]96baf3e2012-10-22 23:09:5543TEST(ScrollbarLayerTest, resolveScrollLayerPointer)
[email protected]89583602012-09-18 21:51:4144{
[email protected]89583602012-09-18 21:51:4145 WebKit::WebScrollbarThemePainter painter;
46
47 {
[email protected]31161582012-10-16 21:08:0348 scoped_ptr<WebKit::WebScrollbar> scrollbar(FakeWebScrollbar::create());
[email protected]96baf3e2012-10-22 23:09:5549 scoped_refptr<Layer> layerTreeRoot = Layer::create();
50 scoped_refptr<Layer> child1 = Layer::create();
51 scoped_refptr<Layer> child2 = ScrollbarLayer::create(scrollbar.Pass(), painter, WebKit::FakeWebScrollbarThemeGeometry::create(), child1->id());
[email protected]89583602012-09-18 21:51:4152 layerTreeRoot->addChild(child1);
53 layerTreeRoot->addChild(child2);
54
[email protected]96baf3e2012-10-22 23:09:5555 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), scoped_ptr<LayerImpl>(), 0);
[email protected]89583602012-09-18 21:51:4156
[email protected]96baf3e2012-10-22 23:09:5557 LayerImpl* ccChild1 = layerImplTreeRoot->children()[0];
58 ScrollbarLayerImpl* ccChild2 = static_cast<ScrollbarLayerImpl*>(layerImplTreeRoot->children()[1]);
[email protected]89583602012-09-18 21:51:4159
60 EXPECT_TRUE(ccChild1->scrollbarAnimationController());
61 EXPECT_EQ(ccChild1->horizontalScrollbarLayer(), ccChild2);
62 }
63
64 { // another traverse order
[email protected]31161582012-10-16 21:08:0365 scoped_ptr<WebKit::WebScrollbar> scrollbar(FakeWebScrollbar::create());
[email protected]96baf3e2012-10-22 23:09:5566 scoped_refptr<Layer> layerTreeRoot = Layer::create();
67 scoped_refptr<Layer> child2 = Layer::create();
68 scoped_refptr<Layer> child1 = ScrollbarLayer::create(scrollbar.Pass(), painter, WebKit::FakeWebScrollbarThemeGeometry::create(), child2->id());
[email protected]89583602012-09-18 21:51:4169 layerTreeRoot->addChild(child1);
70 layerTreeRoot->addChild(child2);
71
[email protected]96baf3e2012-10-22 23:09:5572 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), scoped_ptr<LayerImpl>(), 0);
[email protected]89583602012-09-18 21:51:4173
[email protected]96baf3e2012-10-22 23:09:5574 ScrollbarLayerImpl* ccChild1 = static_cast<ScrollbarLayerImpl*>(layerImplTreeRoot->children()[0]);
75 LayerImpl* ccChild2 = layerImplTreeRoot->children()[1];
[email protected]89583602012-09-18 21:51:4176
77 EXPECT_TRUE(ccChild2->scrollbarAnimationController());
78 EXPECT_EQ(ccChild2->horizontalScrollbarLayer(), ccChild1);
79 }
80}
81
[email protected]96baf3e2012-10-22 23:09:5582TEST(ScrollbarLayerTest, scrollOffsetSynchronization)
[email protected]89583602012-09-18 21:51:4183{
[email protected]89583602012-09-18 21:51:4184 WebKit::WebScrollbarThemePainter painter;
85
[email protected]31161582012-10-16 21:08:0386 scoped_ptr<WebKit::WebScrollbar> scrollbar(FakeWebScrollbar::create());
[email protected]96baf3e2012-10-22 23:09:5587 scoped_refptr<Layer> layerTreeRoot = Layer::create();
88 scoped_refptr<Layer> contentLayer = Layer::create();
89 scoped_refptr<Layer> scrollbarLayer = ScrollbarLayer::create(scrollbar.Pass(), painter, WebKit::FakeWebScrollbarThemeGeometry::create(), layerTreeRoot->id());
[email protected]89583602012-09-18 21:51:4190 layerTreeRoot->addChild(contentLayer);
91 layerTreeRoot->addChild(scrollbarLayer);
92
[email protected]c9c1ebe2012-11-05 20:46:1393 layerTreeRoot->setScrollOffset(gfx::Vector2d(10, 20));
94 layerTreeRoot->setMaxScrollOffset(gfx::Vector2d(30, 50));
95 contentLayer->setBounds(gfx::Size(100, 200));
[email protected]89583602012-09-18 21:51:4196
[email protected]96baf3e2012-10-22 23:09:5597 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), scoped_ptr<LayerImpl>(), 0);
[email protected]89583602012-09-18 21:51:4198
[email protected]96baf3e2012-10-22 23:09:5599 ScrollbarLayerImpl* ccScrollbarLayer = static_cast<ScrollbarLayerImpl*>(layerImplTreeRoot->children()[1]);
[email protected]89583602012-09-18 21:51:41100
101 EXPECT_EQ(10, ccScrollbarLayer->currentPos());
102 EXPECT_EQ(100, ccScrollbarLayer->totalSize());
103 EXPECT_EQ(30, ccScrollbarLayer->maximum());
104
[email protected]c9c1ebe2012-11-05 20:46:13105 layerTreeRoot->setScrollOffset(gfx::Vector2d(100, 200));
106 layerTreeRoot->setMaxScrollOffset(gfx::Vector2d(300, 500));
107 contentLayer->setBounds(gfx::Size(1000, 2000));
[email protected]89583602012-09-18 21:51:41108
[email protected]96baf3e2012-10-22 23:09:55109 ScrollbarAnimationController* scrollbarController = layerImplTreeRoot->scrollbarAnimationController();
110 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), layerImplTreeRoot.Pass(), 0);
111 EXPECT_EQ(scrollbarController, layerImplTreeRoot->scrollbarAnimationController());
[email protected]89583602012-09-18 21:51:41112
113 EXPECT_EQ(100, ccScrollbarLayer->currentPos());
114 EXPECT_EQ(1000, ccScrollbarLayer->totalSize());
115 EXPECT_EQ(300, ccScrollbarLayer->maximum());
116
[email protected]c9c1ebe2012-11-05 20:46:13117 layerImplTreeRoot->scrollBy(gfx::Vector2d(12, 34));
[email protected]89583602012-09-18 21:51:41118
119 EXPECT_EQ(112, ccScrollbarLayer->currentPos());
120 EXPECT_EQ(1000, ccScrollbarLayer->totalSize());
121 EXPECT_EQ(300, ccScrollbarLayer->maximum());
122}
123
[email protected]ba565742012-11-10 09:29:48124} // namespace
125} // namespace cc