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

Side by Side Diff: third_party/WebKit/Source/core/frame/VisualViewport.cpp

Issue 2735543002: Separate VisualViewport layer tree creation from attachment. (Closed)
Patch Set: Created 3 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 // First try to use the anchor's delta to scroll the FrameView. 312 // First try to use the anchor's delta to scroll the FrameView.
313 FloatSize anchorDeltaUnusedByScroll = anchorDelta; 313 FloatSize anchorDeltaUnusedByScroll = anchorDelta;
314 314
315 // Manually bubble any remaining anchor delta up to the visual viewport. 315 // Manually bubble any remaining anchor delta up to the visual viewport.
316 FloatPoint newLocation(FloatPoint(getScrollOffset()) + 316 FloatPoint newLocation(FloatPoint(getScrollOffset()) +
317 anchorDeltaUnusedByScroll); 317 anchorDeltaUnusedByScroll);
318 setScaleAndLocation(newPageScale, newLocation); 318 setScaleAndLocation(newPageScale, newLocation);
319 return true; 319 return true;
320 } 320 }
321 321
322 // Modifies the top of the graphics layer tree to add layers needed to support 322 void VisualViewport::createLayerTree() {
323 // the inner/outer viewport fixed-position model for pinch zoom. When finished, 323 if (m_innerViewportScrollLayer)
324 // the tree will look like this (with * denoting added layers): 324 return;
325 // 325
326 // *rootTransformLayer 326 DCHECK(!m_overlayScrollbarHorizontal && !m_overlayScrollbarVertical &&
327 // +- *innerViewportContainerLayer (fixed pos container) 327 !m_overscrollElasticityLayer && !m_pageScaleLayer &&
328 // +- *overscrollElasticityLayer 328 !m_innerViewportContainerLayer);
329 // | +- *pageScaleLayer 329
330 // | +- *innerViewportScrollLayer 330 // FIXME: The root transform layer should only be created on demand.
331 // | +-- overflowControlsHostLayer (root layer) 331 m_rootTransformLayer = GraphicsLayer::create(this);
332 // | | [ owned by PaintLayerCompositor ] 332 m_innerViewportContainerLayer = GraphicsLayer::create(this);
333 // | +-- outerViewportContainerLayer (fixed pos container) 333 m_overscrollElasticityLayer = GraphicsLayer::create(this);
334 // | | [frame container layer in PaintLayerCompositor] 334 m_pageScaleLayer = GraphicsLayer::create(this);
335 // | | +-- outerViewportScrollLayer 335 m_innerViewportScrollLayer = GraphicsLayer::create(this);
336 // | | | [frame scroll layer in PaintLayerCompositor] 336 m_overlayScrollbarHorizontal = GraphicsLayer::create(this);
337 // | | +-- content layers ... 337 m_overlayScrollbarVertical = GraphicsLayer::create(this);
338 // +- *PageOverlay for InspectorOverlay 338
339 // +- *PageOverlay for ColorOverlay 339 ScrollingCoordinator* coordinator = frameHost().page().scrollingCoordinator();
340 // +- horizontalScrollbarLayer [ owned by PaintLayerCompositor ] 340 DCHECK(coordinator);
341 // +- verticalScrollbarLayer [ owned by PaintLayerCompositor ] 341 coordinator->setLayerIsContainerForFixedPositionLayers(
342 // +- scroll corner (non-overlay only) [ owned by PaintLayerCompositor ] 342 m_innerViewportScrollLayer.get(), true);
343 // 343
344 void VisualViewport::attachToLayerTree(GraphicsLayer* currentLayerTreeRoot) { 344 // Set masks to bounds so the compositor doesn't clobber a manually
345 TRACE_EVENT1("blink", "VisualViewport::attachToLayerTree", 345 // set inner viewport container layer size.
346 m_innerViewportContainerLayer->setMasksToBounds(
347 frameHost().page().settings().getMainFrameClipsContent());
348 m_innerViewportContainerLayer->setSize(FloatSize(m_size));
349
350 m_innerViewportScrollLayer->platformLayer()->setScrollClipLayer(
351 m_innerViewportContainerLayer->platformLayer());
352 m_innerViewportScrollLayer->platformLayer()->setUserScrollable(true, true);
353 if (mainFrame()) {
354 if (Document* document = mainFrame()->document()) {
355 m_innerViewportScrollLayer->setElementId(createCompositorElementId(
356 DOMNodeIds::idForNode(document), CompositorSubElementId::Viewport));
357 }
358 }
359
360 m_rootTransformLayer->addChild(m_innerViewportContainerLayer.get());
361 m_innerViewportContainerLayer->addChild(m_overscrollElasticityLayer.get());
362 m_overscrollElasticityLayer->addChild(m_pageScaleLayer.get());
363 m_pageScaleLayer->addChild(m_innerViewportScrollLayer.get());
364
365 // Ensure this class is set as the scroll layer's ScrollableArea.
366 coordinator->scrollableAreaScrollLayerDidChange(this);
367
368 initializeScrollbars();
369 }
370
371 void VisualViewport::attachLayerTree(GraphicsLayer* currentLayerTreeRoot) {
372 TRACE_EVENT1("blink", "VisualViewport::attachLayerTree",
346 "currentLayerTreeRoot", (bool)currentLayerTreeRoot); 373 "currentLayerTreeRoot", (bool)currentLayerTreeRoot);
347 if (!currentLayerTreeRoot) { 374 if (!currentLayerTreeRoot) {
348 if (m_innerViewportScrollLayer) 375 if (m_innerViewportScrollLayer)
349 m_innerViewportScrollLayer->removeAllChildren(); 376 m_innerViewportScrollLayer->removeAllChildren();
350 return; 377 return;
351 } 378 }
352 379
353 if (currentLayerTreeRoot->parent() && 380 if (currentLayerTreeRoot->parent() &&
354 currentLayerTreeRoot->parent() == m_innerViewportScrollLayer.get()) 381 currentLayerTreeRoot->parent() == m_innerViewportScrollLayer.get())
355 return; 382 return;
356 383
357 if (!m_innerViewportScrollLayer) { 384 DCHECK(m_innerViewportScrollLayer);
358 ASSERT(!m_overlayScrollbarHorizontal && !m_overlayScrollbarVertical &&
359 !m_overscrollElasticityLayer && !m_pageScaleLayer &&
360 !m_innerViewportContainerLayer);
361
362 // FIXME: The root transform layer should only be created on demand.
363 m_rootTransformLayer = GraphicsLayer::create(this);
364 m_innerViewportContainerLayer = GraphicsLayer::create(this);
365 m_overscrollElasticityLayer = GraphicsLayer::create(this);
366 m_pageScaleLayer = GraphicsLayer::create(this);
367 m_innerViewportScrollLayer = GraphicsLayer::create(this);
368 m_overlayScrollbarHorizontal = GraphicsLayer::create(this);
369 m_overlayScrollbarVertical = GraphicsLayer::create(this);
370
371 ScrollingCoordinator* coordinator =
372 frameHost().page().scrollingCoordinator();
373 ASSERT(coordinator);
374 coordinator->setLayerIsContainerForFixedPositionLayers(
375 m_innerViewportScrollLayer.get(), true);
376
377 // Set masks to bounds so the compositor doesn't clobber a manually
378 // set inner viewport container layer size.
379 m_innerViewportContainerLayer->setMasksToBounds(
380 frameHost().page().settings().getMainFrameClipsContent());
381 m_innerViewportContainerLayer->setSize(FloatSize(m_size));
382
383 m_innerViewportScrollLayer->platformLayer()->setScrollClipLayer(
384 m_innerViewportContainerLayer->platformLayer());
385 m_innerViewportScrollLayer->platformLayer()->setUserScrollable(true, true);
386 if (mainFrame()) {
387 if (Document* document = mainFrame()->document()) {
388 m_innerViewportScrollLayer->setElementId(createCompositorElementId(
389 DOMNodeIds::idForNode(document), CompositorSubElementId::Viewport));
390 }
391 }
392
393 m_rootTransformLayer->addChild(m_innerViewportContainerLayer.get());
394 m_innerViewportContainerLayer->addChild(m_overscrollElasticityLayer.get());
395 m_overscrollElasticityLayer->addChild(m_pageScaleLayer.get());
396 m_pageScaleLayer->addChild(m_innerViewportScrollLayer.get());
397
398 // Ensure this class is set as the scroll layer's ScrollableArea.
399 coordinator->scrollableAreaScrollLayerDidChange(this);
400
401 initializeScrollbars();
402 }
403
404 m_innerViewportScrollLayer->removeAllChildren(); 385 m_innerViewportScrollLayer->removeAllChildren();
405 m_innerViewportScrollLayer->addChild(currentLayerTreeRoot); 386 m_innerViewportScrollLayer->addChild(currentLayerTreeRoot);
406 } 387 }
407 388
408 void VisualViewport::initializeScrollbars() { 389 void VisualViewport::initializeScrollbars() {
409 // Do nothing if not attached to layer tree yet - will initialize upon attach. 390 // Do nothing if not attached to layer tree yet - will initialize upon attach.
410 if (!m_innerViewportContainerLayer) 391 if (!m_innerViewportContainerLayer)
411 return; 392 return;
412 393
413 if (visualViewportSuppliesScrollbars() && 394 if (visualViewportSuppliesScrollbars() &&
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
855 } else if (graphicsLayer == m_rootTransformLayer.get()) { 836 } else if (graphicsLayer == m_rootTransformLayer.get()) {
856 name = "Root Transform Layer"; 837 name = "Root Transform Layer";
857 } else { 838 } else {
858 ASSERT_NOT_REACHED(); 839 ASSERT_NOT_REACHED();
859 } 840 }
860 841
861 return name; 842 return name;
862 } 843 }
863 844
864 } // namespace blink 845 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698