Implement android_webview url intercepting.
[chromium-blink-merge.git] / cc / tree_synchronizer.cc
blobb7e76bbe9ab16d6843bfb26937329c17e35b6233
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
3 // found in the LICENSE file.
5 #include "config.h"
7 #include "TreeSynchronizer.h"
9 #include "CCLayerImpl.h"
10 #include "CCScrollbarAnimationController.h"
11 #include "CCScrollbarLayerImpl.h"
12 #include "LayerChromium.h"
13 #include "ScrollbarLayerChromium.h"
15 namespace cc {
17 scoped_ptr<CCLayerImpl> TreeSynchronizer::synchronizeTrees(LayerChromium* layerChromiumRoot, scoped_ptr<CCLayerImpl> oldCCLayerImplRoot, CCLayerTreeHostImpl* hostImpl)
19 ScopedPtrCCLayerImplMap oldLayers;
20 RawPtrCCLayerImplMap newLayers;
22 collectExistingCCLayerImplRecursive(oldLayers, oldCCLayerImplRoot.Pass());
24 scoped_ptr<CCLayerImpl> newTree = synchronizeTreeRecursive(newLayers, oldLayers, layerChromiumRoot, hostImpl);
26 updateScrollbarLayerPointersRecursive(newLayers, layerChromiumRoot);
28 return newTree.Pass();
31 void TreeSynchronizer::collectExistingCCLayerImplRecursive(ScopedPtrCCLayerImplMap& oldLayers, scoped_ptr<CCLayerImpl> ccLayerImpl)
33 if (!ccLayerImpl)
34 return;
36 ScopedPtrVector<CCLayerImpl>& children = ccLayerImpl->m_children;
37 for (size_t i = 0; i < children.size(); ++i)
38 collectExistingCCLayerImplRecursive(oldLayers, children.take(i));
40 collectExistingCCLayerImplRecursive(oldLayers, ccLayerImpl->m_maskLayer.Pass());
41 collectExistingCCLayerImplRecursive(oldLayers, ccLayerImpl->m_replicaLayer.Pass());
43 int id = ccLayerImpl->id();
44 oldLayers.set(id, ccLayerImpl.Pass());
47 scoped_ptr<CCLayerImpl> TreeSynchronizer::reuseOrCreateCCLayerImpl(RawPtrCCLayerImplMap& newLayers, ScopedPtrCCLayerImplMap& oldLayers, LayerChromium* layer)
49 scoped_ptr<CCLayerImpl> ccLayerImpl = oldLayers.take(layer->id());
51 if (!ccLayerImpl)
52 ccLayerImpl = layer->createCCLayerImpl();
54 newLayers[layer->id()] = ccLayerImpl.get();
55 return ccLayerImpl.Pass();
58 scoped_ptr<CCLayerImpl> TreeSynchronizer::synchronizeTreeRecursive(RawPtrCCLayerImplMap& newLayers, ScopedPtrCCLayerImplMap& oldLayers, LayerChromium* layer, CCLayerTreeHostImpl* hostImpl)
60 if (!layer)
61 return scoped_ptr<CCLayerImpl>();
63 scoped_ptr<CCLayerImpl> ccLayerImpl = reuseOrCreateCCLayerImpl(newLayers, oldLayers, layer);
65 ccLayerImpl->clearChildList();
66 const std::vector<scoped_refptr<LayerChromium> >& children = layer->children();
67 for (size_t i = 0; i < children.size(); ++i)
68 ccLayerImpl->addChild(synchronizeTreeRecursive(newLayers, oldLayers, children[i].get(), hostImpl));
70 ccLayerImpl->setMaskLayer(synchronizeTreeRecursive(newLayers, oldLayers, layer->maskLayer(), hostImpl));
71 ccLayerImpl->setReplicaLayer(synchronizeTreeRecursive(newLayers, oldLayers, layer->replicaLayer(), hostImpl));
73 layer->pushPropertiesTo(ccLayerImpl.get());
74 ccLayerImpl->setLayerTreeHostImpl(hostImpl);
76 // Remove all dangling pointers. The pointers will be setup later in updateScrollbarLayerPointersRecursive phase
77 if (CCScrollbarAnimationController* scrollbarController = ccLayerImpl->scrollbarAnimationController()) {
78 scrollbarController->setHorizontalScrollbarLayer(0);
79 scrollbarController->setVerticalScrollbarLayer(0);
82 return ccLayerImpl.Pass();
85 void TreeSynchronizer::updateScrollbarLayerPointersRecursive(const RawPtrCCLayerImplMap& newLayers, LayerChromium* layer)
87 if (!layer)
88 return;
90 const std::vector<scoped_refptr<LayerChromium> >& children = layer->children();
91 for (size_t i = 0; i < children.size(); ++i)
92 updateScrollbarLayerPointersRecursive(newLayers, children[i].get());
94 ScrollbarLayerChromium* scrollbarLayer = layer->toScrollbarLayerChromium();
95 if (!scrollbarLayer)
96 return;
98 RawPtrCCLayerImplMap::const_iterator iter = newLayers.find(scrollbarLayer->id());
99 CCScrollbarLayerImpl* ccScrollbarLayerImpl = iter != newLayers.end() ? static_cast<CCScrollbarLayerImpl*>(iter->second) : NULL;
100 iter = newLayers.find(scrollbarLayer->scrollLayerId());
101 CCLayerImpl* ccScrollLayerImpl = iter != newLayers.end() ? iter->second : NULL;
103 ASSERT(ccScrollbarLayerImpl);
104 ASSERT(ccScrollLayerImpl);
106 if (ccScrollbarLayerImpl->orientation() == WebKit::WebScrollbar::Horizontal)
107 ccScrollLayerImpl->setHorizontalScrollbarLayer(ccScrollbarLayerImpl);
108 else
109 ccScrollLayerImpl->setVerticalScrollbarLayer(ccScrollbarLayerImpl);
112 } // namespace cc