[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 1 | // 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] | a8461d8 | 2012-10-16 21:11:14 | [diff] [blame] | 5 | #include "cc/scrollbar_layer.h" |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 6 | |
[email protected] | c4040a52 | 2012-10-21 15:01:40 | [diff] [blame] | 7 | #include "cc/scrollbar_animation_controller.h" |
| 8 | #include "cc/scrollbar_layer_impl.h" |
[email protected] | 4456eee2 | 2012-10-19 18:16:38 | [diff] [blame] | 9 | #include "cc/single_thread_proxy.h" |
[email protected] | 101441ce | 2012-10-16 01:45:03 | [diff] [blame] | 10 | #include "cc/test/fake_web_scrollbar_theme_geometry.h" |
[email protected] | a8461d8 | 2012-10-16 21:11:14 | [diff] [blame] | 11 | #include "cc/tree_synchronizer.h" |
[email protected] | 7f0c53db | 2012-10-02 00:23:18 | [diff] [blame] | 12 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 13 | #include <public/WebScrollbar.h> |
| 14 | #include <public/WebScrollbarThemeGeometry.h> |
| 15 | #include <public/WebScrollbarThemePainter.h> |
| 16 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame^] | 17 | namespace cc { |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 18 | namespace { |
| 19 | |
| 20 | class FakeWebScrollbar : public WebKit::WebScrollbar { |
| 21 | public: |
[email protected] | 3116158 | 2012-10-16 21:08:03 | [diff] [blame] | 22 | static scoped_ptr<FakeWebScrollbar> create() { return make_scoped_ptr(new FakeWebScrollbar()); } |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 23 | |
| 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] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 43 | TEST(ScrollbarLayerTest, resolveScrollLayerPointer) |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 44 | { |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 45 | WebKit::WebScrollbarThemePainter painter; |
| 46 | |
| 47 | { |
[email protected] | 3116158 | 2012-10-16 21:08:03 | [diff] [blame] | 48 | scoped_ptr<WebKit::WebScrollbar> scrollbar(FakeWebScrollbar::create()); |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 49 | 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] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 52 | layerTreeRoot->addChild(child1); |
| 53 | layerTreeRoot->addChild(child2); |
| 54 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 55 | scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), scoped_ptr<LayerImpl>(), 0); |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 56 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 57 | LayerImpl* ccChild1 = layerImplTreeRoot->children()[0]; |
| 58 | ScrollbarLayerImpl* ccChild2 = static_cast<ScrollbarLayerImpl*>(layerImplTreeRoot->children()[1]); |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 59 | |
| 60 | EXPECT_TRUE(ccChild1->scrollbarAnimationController()); |
| 61 | EXPECT_EQ(ccChild1->horizontalScrollbarLayer(), ccChild2); |
| 62 | } |
| 63 | |
| 64 | { // another traverse order |
[email protected] | 3116158 | 2012-10-16 21:08:03 | [diff] [blame] | 65 | scoped_ptr<WebKit::WebScrollbar> scrollbar(FakeWebScrollbar::create()); |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 66 | 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] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 69 | layerTreeRoot->addChild(child1); |
| 70 | layerTreeRoot->addChild(child2); |
| 71 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 72 | scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), scoped_ptr<LayerImpl>(), 0); |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 73 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 74 | ScrollbarLayerImpl* ccChild1 = static_cast<ScrollbarLayerImpl*>(layerImplTreeRoot->children()[0]); |
| 75 | LayerImpl* ccChild2 = layerImplTreeRoot->children()[1]; |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 76 | |
| 77 | EXPECT_TRUE(ccChild2->scrollbarAnimationController()); |
| 78 | EXPECT_EQ(ccChild2->horizontalScrollbarLayer(), ccChild1); |
| 79 | } |
| 80 | } |
| 81 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 82 | TEST(ScrollbarLayerTest, scrollOffsetSynchronization) |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 83 | { |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 84 | WebKit::WebScrollbarThemePainter painter; |
| 85 | |
[email protected] | 3116158 | 2012-10-16 21:08:03 | [diff] [blame] | 86 | scoped_ptr<WebKit::WebScrollbar> scrollbar(FakeWebScrollbar::create()); |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 87 | 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] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 90 | layerTreeRoot->addChild(contentLayer); |
| 91 | layerTreeRoot->addChild(scrollbarLayer); |
| 92 | |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 93 | layerTreeRoot->setScrollOffset(gfx::Vector2d(10, 20)); |
| 94 | layerTreeRoot->setMaxScrollOffset(gfx::Vector2d(30, 50)); |
| 95 | contentLayer->setBounds(gfx::Size(100, 200)); |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 96 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 97 | scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), scoped_ptr<LayerImpl>(), 0); |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 98 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 99 | ScrollbarLayerImpl* ccScrollbarLayer = static_cast<ScrollbarLayerImpl*>(layerImplTreeRoot->children()[1]); |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 100 | |
| 101 | EXPECT_EQ(10, ccScrollbarLayer->currentPos()); |
| 102 | EXPECT_EQ(100, ccScrollbarLayer->totalSize()); |
| 103 | EXPECT_EQ(30, ccScrollbarLayer->maximum()); |
| 104 | |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 105 | layerTreeRoot->setScrollOffset(gfx::Vector2d(100, 200)); |
| 106 | layerTreeRoot->setMaxScrollOffset(gfx::Vector2d(300, 500)); |
| 107 | contentLayer->setBounds(gfx::Size(1000, 2000)); |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 108 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 109 | ScrollbarAnimationController* scrollbarController = layerImplTreeRoot->scrollbarAnimationController(); |
| 110 | layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), layerImplTreeRoot.Pass(), 0); |
| 111 | EXPECT_EQ(scrollbarController, layerImplTreeRoot->scrollbarAnimationController()); |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 112 | |
| 113 | EXPECT_EQ(100, ccScrollbarLayer->currentPos()); |
| 114 | EXPECT_EQ(1000, ccScrollbarLayer->totalSize()); |
| 115 | EXPECT_EQ(300, ccScrollbarLayer->maximum()); |
| 116 | |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 117 | layerImplTreeRoot->scrollBy(gfx::Vector2d(12, 34)); |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 118 | |
| 119 | EXPECT_EQ(112, ccScrollbarLayer->currentPos()); |
| 120 | EXPECT_EQ(1000, ccScrollbarLayer->totalSize()); |
| 121 | EXPECT_EQ(300, ccScrollbarLayer->maximum()); |
| 122 | } |
| 123 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame^] | 124 | } // namespace |
| 125 | } // namespace cc |