Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(354)

Side by Side Diff: cc/layer_tree_host_unittest.cc

Issue 11550035: Implement pinch-zoom scaling for main-frame scrollbars and pinch-zoom overlay scrollbars. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase to fix collision with solid colour scrollbars patch. Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/layer_tree_host_impl.cc ('k') | cc/layer_tree_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/layer_tree_host.h" 5 #include "cc/layer_tree_host.h"
6 6
7 #include "base/synchronization/lock.h" 7 #include "base/synchronization/lock.h"
8 #include "cc/content_layer.h" 8 #include "cc/content_layer.h"
9 #include "cc/content_layer_client.h" 9 #include "cc/content_layer_client.h"
10 #include "cc/frame_rate_controller.h" 10 #include "cc/frame_rate_controller.h"
11 #include "cc/layer_impl.h" 11 #include "cc/layer_impl.h"
12 #include "cc/layer_tree_host_impl.h" 12 #include "cc/layer_tree_host_impl.h"
13 #include "cc/layer_tree_impl.h" 13 #include "cc/layer_tree_impl.h"
14 #include "cc/output_surface.h" 14 #include "cc/output_surface.h"
15 #include "cc/picture_layer.h" 15 #include "cc/picture_layer.h"
16 #include "cc/prioritized_resource.h" 16 #include "cc/prioritized_resource.h"
17 #include "cc/prioritized_resource_manager.h" 17 #include "cc/prioritized_resource_manager.h"
18 #include "cc/resource_update_queue.h" 18 #include "cc/resource_update_queue.h"
19 #include "cc/scrollbar_layer.h"
19 #include "cc/single_thread_proxy.h" 20 #include "cc/single_thread_proxy.h"
20 #include "cc/test/fake_content_layer.h" 21 #include "cc/test/fake_content_layer.h"
21 #include "cc/test/fake_content_layer_client.h" 22 #include "cc/test/fake_content_layer_client.h"
22 #include "cc/test/fake_layer_tree_host_client.h" 23 #include "cc/test/fake_layer_tree_host_client.h"
23 #include "cc/test/fake_output_surface.h" 24 #include "cc/test/fake_output_surface.h"
24 #include "cc/test/fake_proxy.h" 25 #include "cc/test/fake_proxy.h"
25 #include "cc/test/fake_scrollbar_layer.h" 26 #include "cc/test/fake_scrollbar_layer.h"
26 #include "cc/test/geometry_test_utils.h" 27 #include "cc/test/geometry_test_utils.h"
27 #include "cc/test/layer_tree_test_common.h" 28 #include "cc/test/layer_tree_test_common.h"
28 #include "cc/test/occlusion_tracker_test_common.h" 29 #include "cc/test/occlusion_tracker_test_common.h"
(...skipping 2159 matching lines...) Expand 10 before | Expand all | Expand 10 after
2188 private: 2189 private:
2189 FakeContentLayerClient m_client; 2190 FakeContentLayerClient m_client;
2190 scoped_refptr<FakeContentLayer> m_rootLayer; 2191 scoped_refptr<FakeContentLayer> m_rootLayer;
2191 scoped_refptr<FakeContentLayer> m_childLayer1; 2192 scoped_refptr<FakeContentLayer> m_childLayer1;
2192 scoped_refptr<FakeContentLayer> m_childLayer2; 2193 scoped_refptr<FakeContentLayer> m_childLayer2;
2193 int m_numCommits; 2194 int m_numCommits;
2194 }; 2195 };
2195 2196
2196 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestShutdownWithOnlySomeResourcesEvi cted) 2197 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestShutdownWithOnlySomeResourcesEvi cted)
2197 2198
2199 class LayerTreeHostTestPinchZoomScrollbarCreation : public LayerTreeHostTest {
2200 public:
2201 LayerTreeHostTestPinchZoomScrollbarCreation()
2202 : m_rootLayer(ContentLayer::Create(&m_client))
2203 {
2204 m_settings.usePinchZoomScrollbars = true;
2205 }
2206
2207 virtual void beginTest() OVERRIDE
2208 {
2209 m_rootLayer->SetIsDrawable(true);
2210 m_rootLayer->SetBounds(gfx::Size(100, 100));
2211 m_layerTreeHost->SetRootLayer(m_rootLayer);
2212 postSetNeedsCommitToMainThread();
2213 }
2214
2215 virtual void didCommit() OVERRIDE
2216 {
2217 // We always expect two pinch-zoom scrollbar layers.
2218 ASSERT_TRUE(2 == m_rootLayer->children().size());
2219
2220 // Pinch-zoom scrollbar layers always have invalid scrollLayerIds.
2221 ScrollbarLayer* layer1 = m_rootLayer->children()[0]->ToScrollbarLayer();
2222 ASSERT_TRUE(layer1);
2223 EXPECT_EQ(Layer::PINCH_ZOOM_ROOT_SCROLL_LAYER_ID, layer1->scroll_layer_i d());
2224 EXPECT_EQ(0, layer1->opacity());
2225 EXPECT_TRUE(layer1->OpacityCanAnimateOnImplThread());
2226 EXPECT_TRUE(layer1->DrawsContent());
2227
2228 ScrollbarLayer* layer2 = m_rootLayer->children()[1]->ToScrollbarLayer();
2229 ASSERT_TRUE(layer2);
2230 EXPECT_EQ(Layer::PINCH_ZOOM_ROOT_SCROLL_LAYER_ID, layer2->scroll_layer_i d());
2231 EXPECT_EQ(0, layer2->opacity());
2232 EXPECT_TRUE(layer2->OpacityCanAnimateOnImplThread());
2233 EXPECT_TRUE(layer2->DrawsContent());
2234
2235 endTest();
2236 }
2237
2238 virtual void afterTest() OVERRIDE
2239 {
2240 }
2241
2242 private:
2243 FakeContentLayerClient m_client;
2244 scoped_refptr<ContentLayer> m_rootLayer;
2245 };
2246
2247 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestPinchZoomScrollbarCreation)
2248
2249 class LayerTreeHostTestPinchZoomScrollbarResize : public LayerTreeHostTest {
2250 public:
2251 LayerTreeHostTestPinchZoomScrollbarResize()
2252 : m_rootLayer(ContentLayer::Create(&m_client))
2253 , m_numCommits(0)
2254 {
2255 m_settings.usePinchZoomScrollbars = true;
2256 }
2257
2258 virtual void beginTest() OVERRIDE
2259 {
2260 m_rootLayer->SetIsDrawable(true);
2261 m_rootLayer->SetBounds(gfx::Size(100, 100));
2262 m_layerTreeHost->SetRootLayer(m_rootLayer);
2263 m_layerTreeHost->SetViewportSize(gfx::Size(100, 100),
2264 gfx::Size(100, 100));
2265 postSetNeedsCommitToMainThread();
2266 }
2267
2268 virtual void didCommit() OVERRIDE
2269 {
2270 m_numCommits++;
2271
2272 ScrollbarLayer* layer1 = m_rootLayer->children()[0]->ToScrollbarLayer();
2273 ASSERT_TRUE(layer1);
2274 ScrollbarLayer* layer2 = m_rootLayer->children()[1]->ToScrollbarLayer();
2275 ASSERT_TRUE(layer2);
2276
2277 // Get scrollbar thickness from horizontal scrollbar's height.
2278 int thickness = layer1->bounds().height();
2279
2280 if (!layer1->Orientation() == WebKit::WebScrollbar::Horizontal)
2281 std::swap(layer1, layer2);
2282
2283 gfx::Size viewportSize = m_layerTreeHost->layout_viewport_size();
2284 EXPECT_EQ(viewportSize.width() - thickness, layer1->bounds().width());
2285 EXPECT_EQ(viewportSize.height() - thickness, layer2->bounds().height());
2286
2287 switch (m_numCommits) {
2288 case 1:
2289 // Resizing the viewport should also resize the pinch-zoom scrollbars.
2290 m_layerTreeHost->SetViewportSize(gfx::Size(120, 150),
2291 gfx::Size(120, 150));
2292 break;
2293 default:
2294 endTest();
2295 }
2296 }
2297
2298 virtual void afterTest() OVERRIDE
2299 {
2300 }
2301
2302 private:
2303 FakeContentLayerClient m_client;
2304 scoped_refptr<ContentLayer> m_rootLayer;
2305 int m_numCommits;
2306 };
2307
2308 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestPinchZoomScrollbarResize)
2309
2310 class LayerTreeHostTestPinchZoomScrollbarNewRootLayer : public LayerTreeHostTest {
2311 public:
2312 LayerTreeHostTestPinchZoomScrollbarNewRootLayer()
2313 : m_rootLayer(ContentLayer::Create(&m_client))
2314 , m_numCommits(0)
2315 {
2316 m_settings.usePinchZoomScrollbars = true;
2317 }
2318
2319 virtual void beginTest() OVERRIDE
2320 {
2321 m_rootLayer->SetIsDrawable(true);
2322 m_rootLayer->SetBounds(gfx::Size(100, 100));
2323 m_layerTreeHost->SetRootLayer(m_rootLayer);
2324 postSetNeedsCommitToMainThread();
2325 }
2326
2327 virtual void didCommit() OVERRIDE
2328 {
2329 m_numCommits++;
2330
2331 // We always expect two pinch-zoom scrollbar layers.
2332 ASSERT_TRUE(2 == m_rootLayer->children().size());
2333
2334 // Pinch-zoom scrollbar layers always have invalid scrollLayerIds.
2335 ScrollbarLayer* layer1 = m_rootLayer->children()[0]->ToScrollbarLayer();
2336 ASSERT_TRUE(layer1);
2337 EXPECT_EQ(Layer::PINCH_ZOOM_ROOT_SCROLL_LAYER_ID, layer1->scroll_layer_i d());
2338 EXPECT_EQ(0, layer1->opacity());
2339 EXPECT_TRUE(layer1->DrawsContent());
2340
2341 ScrollbarLayer* layer2 = m_rootLayer->children()[1]->ToScrollbarLayer();
2342 ASSERT_TRUE(layer2);
2343 EXPECT_EQ(Layer::PINCH_ZOOM_ROOT_SCROLL_LAYER_ID, layer2->scroll_layer_i d());
2344 EXPECT_EQ(0, layer2->opacity());
2345 EXPECT_TRUE(layer2->DrawsContent());
2346
2347 if (m_numCommits == 1) {
2348 // Create a new root layer and attach to tree to verify the pinch
2349 // zoom scrollbars get correctly re-attached.
2350 m_rootLayer = ContentLayer::Create(&m_client);
2351 m_rootLayer->SetIsDrawable(true);
2352 m_rootLayer->SetBounds(gfx::Size(100, 100));
2353 m_layerTreeHost->SetRootLayer(m_rootLayer);
2354 postSetNeedsCommitToMainThread();
2355 } else
2356 endTest();
2357 }
2358
2359 virtual void afterTest() OVERRIDE
2360 {
2361 }
2362
2363 private:
2364 FakeContentLayerClient m_client;
2365 scoped_refptr<ContentLayer> m_rootLayer;
2366 int m_numCommits;
2367 };
2368
2369 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestPinchZoomScrollbarNewRootLayer)
2370
2198 } // namespace 2371 } // namespace
2199 } // namespace cc 2372 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layer_tree_host_impl.cc ('k') | cc/layer_tree_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698