| Differences between
and this patch
- a/Source/WebCore/ChangeLog +72 lines
Lines 1-3 a/Source/WebCore/ChangeLog_sec1
1
2012-12-06  Elliott Sprehn  <esprehn@gmail.com>
2
3
        [Refactoring] Replace Node's Document pointer with a TreeScope pointer
4
        https://bugs.webkit.org/show_bug.cgi?id=59816
5
6
        Reviewed by NOBODY (OOPS!).
7
8
        Instead of giving every node in a shadow a rare data, which can be quite
9
        large, we replace the Document pointer in Node with a TreeScope pointer
10
        and we give TreeScope a pointer to it's document scope.
11
12
        This introduces no branches in document() because in the common
13
        case document() becomes equivalent to m_treeScope->m_documentScope where
14
        the documentScope is actually m_treeScope so this shouldn't introduce a
15
        perf regression.
16
17
        Note also that TreeScope can never be null after r136328, and the document
18
        pointer is only null for DocumentType nodes so we can use a special
19
        no-document TreeScope for this case that always returns null from
20
        documentScope().
21
22
        No new tests, no change in behavior.
23
24
        * dom/Document.cpp:
25
        (WebCore::Document::Document):
26
        (WebCore::Document::~Document):
27
        (WebCore::Document::suggestedMIMEType):
28
        * dom/Document.h:
29
        (WebCore::Node::isDocumentNode):
30
        (WebCore::Node::Node):
31
        * dom/Element.cpp:
32
        (WebCore::Element::createRareData):
33
        * dom/ElementRareData.h:
34
        (ElementRareData):
35
        (WebCore::ElementRareData::ElementRareData):
36
        * dom/Node.cpp:
37
        (WebCore::Node::~Node):
38
        (WebCore::Node::createRareData):
39
        (WebCore::Node::attach):
40
        (WebCore::Node::reportMemoryUsage):
41
        * dom/Node.h:
42
        (WebCore):
43
        (WebCore::NodeRareDataBase::NodeRareDataBase):
44
        (NodeRareDataBase):
45
        (WebCore::Node::treeScope):
46
        (WebCore::Node::inDocument):
47
        (WebCore::Node::documentInternal):
48
        (WebCore::Node::setTreeScope):
49
        (Node):
50
        * dom/NodeRareData.cpp:
51
        (WebCore::NodeRareData::reportMemoryUsage):
52
        * dom/NodeRareData.h:
53
        (WebCore::NodeRareData::NodeRareData):
54
        * dom/ShadowRoot.cpp:
55
        (WebCore::ShadowRoot::ShadowRoot):
56
        * dom/TreeScope.cpp:
57
        (SameSizeAsTreeScope):
58
        (WebCore::TreeScope::TreeScope):
59
        (WebCore::TreeScope::setParentTreeScope):
60
        * dom/TreeScope.h:
61
        (WebCore):
62
        (TreeScope):
63
        (WebCore::TreeScope::documentScope):
64
        (WebCore::TreeScope::noDocumentInstance):
65
            Returns a special tree scope that has no document for use with
66
            DocumentType nodes.
67
        (WebCore::TreeScope::setDocumentScope):
68
        * dom/TreeScopeAdopter.cpp:
69
        (WebCore::TreeScopeAdopter::moveTreeToNewScope):
70
        (WebCore::TreeScopeAdopter::moveTreeToNewDocument):
71
        (WebCore::TreeScopeAdopter::moveNodeToNewDocument):
72
1
2012-12-06  Rick Byers  <rbyers@chromium.org>
73
2012-12-06  Rick Byers  <rbyers@chromium.org>
2
74
3
        CSS cursor property should support webkit-image-set
75
        CSS cursor property should support webkit-image-set
- a/Source/WebCore/dom/Document.cpp -9 / +5 lines
Lines 434-440 private: a/Source/WebCore/dom/Document.cpp_sec1
434
uint64_t Document::s_globalTreeVersion = 0;
434
uint64_t Document::s_globalTreeVersion = 0;
435
435
436
Document::Document(Frame* frame, const KURL& url, bool isXHTML, bool isHTML)
436
Document::Document(Frame* frame, const KURL& url, bool isXHTML, bool isHTML)
437
    : ContainerNode(0, CreateDocument)
437
    : ContainerNode(this, CreateDocument)
438
    , TreeScope(this)
438
    , TreeScope(this)
439
    , m_guardRefCount(0)
439
    , m_guardRefCount(0)
440
    , m_contextFeatures(ContextFeatures::defaultSwitch())
440
    , m_contextFeatures(ContextFeatures::defaultSwitch())
Lines 506-513 Document::Document(Frame* frame, const KURL& url, bool isXHTML, bool isHTML) a/Source/WebCore/dom/Document.cpp_sec2
506
    , m_didDispatchViewportPropertiesChanged(false)
506
    , m_didDispatchViewportPropertiesChanged(false)
507
#endif
507
#endif
508
{
508
{
509
    m_document = this;
510
511
    m_printing = false;
509
    m_printing = false;
512
    m_paginatedForScreen = false;
510
    m_paginatedForScreen = false;
513
511
Lines 665-672 Document::~Document() a/Source/WebCore/dom/Document.cpp_sec3
665
    for (unsigned i = 0; i < WTF_ARRAY_LENGTH(m_nodeListCounts); i++)
663
    for (unsigned i = 0; i < WTF_ARRAY_LENGTH(m_nodeListCounts); i++)
666
        ASSERT(!m_nodeListCounts[i]);
664
        ASSERT(!m_nodeListCounts[i]);
667
665
668
    m_document = 0;
669
670
    InspectorCounters::decrementCounter(InspectorCounters::DocumentCounter);
666
    InspectorCounters::decrementCounter(InspectorCounters::DocumentCounter);
671
}
667
}
672
668
Lines 1343-1355 void Document::setContent(const String& content) a/Source/WebCore/dom/Document.cpp_sec4
1343
1339
1344
String Document::suggestedMIMEType() const
1340
String Document::suggestedMIMEType() const
1345
{
1341
{
1346
    if (m_document->isXHTMLDocument())
1342
    if (isXHTMLDocument())
1347
        return "application/xhtml+xml";
1343
        return "application/xhtml+xml";
1348
    if (m_document->isSVGDocument())
1344
    if (isSVGDocument())
1349
        return "image/svg+xml";
1345
        return "image/svg+xml";
1350
    if (m_document->xmlStandalone())
1346
    if (xmlStandalone())
1351
        return "text/xml";
1347
        return "text/xml";
1352
    if (m_document->isHTMLDocument())
1348
    if (isHTMLDocument())
1353
        return "text/html";
1349
        return "text/html";
1354
1350
1355
    if (DocumentLoader* documentLoader = loader())
1351
    if (DocumentLoader* documentLoader = loader())
- a/Source/WebCore/dom/Document.h -7 / +5 lines
Lines 1549-1570 inline void Document::notifyRemovePendingSheetIfNeeded() a/Source/WebCore/dom/Document.h_sec1
1549
1549
1550
inline bool Node::isDocumentNode() const
1550
inline bool Node::isDocumentNode() const
1551
{
1551
{
1552
    return this == m_document;
1552
    return this == documentInternal();
1553
}
1554
1555
inline TreeScope* Node::treeScope() const
1556
{
1557
    return hasRareData() ? m_data.m_rareData->treeScope() : documentInternal();
1558
}
1553
}
1559
1554
1560
inline Node::Node(Document* document, ConstructionType type)
1555
inline Node::Node(Document* document, ConstructionType type)
1561
    : m_nodeFlags(type)
1556
    : m_nodeFlags(type)
1562
    , m_document(document)
1557
    , m_treeScope(document)
1563
    , m_previous(0)
1558
    , m_previous(0)
1564
    , m_next(0)
1559
    , m_next(0)
1565
{
1560
{
1566
    if (document)
1561
    if (document)
1567
        document->guardRef();
1562
        document->guardRef();
1563
    else
1564
        m_treeScope = TreeScope::noDocumentInstance();
1565
1568
#if !defined(NDEBUG) || (defined(DUMP_NODE_STATISTICS) && DUMP_NODE_STATISTICS)
1566
#if !defined(NDEBUG) || (defined(DUMP_NODE_STATISTICS) && DUMP_NODE_STATISTICS)
1569
    trackForDebugging();
1567
    trackForDebugging();
1570
#endif
1568
#endif
- a/Source/WebCore/dom/Element.cpp -1 / +1 lines
Lines 217-223 inline ElementRareData* Element::ensureElementRareData() a/Source/WebCore/dom/Element.cpp_sec1
217
217
218
PassOwnPtr<NodeRareData> Element::createRareData()
218
PassOwnPtr<NodeRareData> Element::createRareData()
219
{
219
{
220
    return adoptPtr(new ElementRareData(documentInternal()));
220
    return adoptPtr(new ElementRareData());
221
}
221
}
222
222
223
DEFINE_VIRTUAL_ATTRIBUTE_EVENT_LISTENER(Element, blur);
223
DEFINE_VIRTUAL_ATTRIBUTE_EVENT_LISTENER(Element, blur);
- a/Source/WebCore/dom/ElementRareData.h -4 / +3 lines
Lines 35-41 namespace WebCore { a/Source/WebCore/dom/ElementRareData.h_sec1
35
35
36
class ElementRareData : public NodeRareData {
36
class ElementRareData : public NodeRareData {
37
public:
37
public:
38
    ElementRareData(Document*);
38
    ElementRareData();
39
    virtual ~ElementRareData();
39
    virtual ~ElementRareData();
40
40
41
    void setPseudoElement(PseudoId, PassRefPtr<PseudoElement>);
41
    void setPseudoElement(PseudoId, PassRefPtr<PseudoElement>);
Lines 130-138 inline IntSize defaultMinimumSizeForResizing() a/Source/WebCore/dom/ElementRareData.h_sec2
130
    return IntSize(LayoutUnit::max(), LayoutUnit::max());
130
    return IntSize(LayoutUnit::max(), LayoutUnit::max());
131
}
131
}
132
132
133
inline ElementRareData::ElementRareData(Document* document)
133
inline ElementRareData::ElementRareData()
134
    : NodeRareData(document)
134
    : m_minimumSizeForResizing(defaultMinimumSizeForResizing())
135
    , m_minimumSizeForResizing(defaultMinimumSizeForResizing())
136
    , m_generatedBefore(0)
135
    , m_generatedBefore(0)
137
    , m_generatedAfter(0)
136
    , m_generatedAfter(0)
138
{
137
{
- a/Source/WebCore/dom/Node.cpp -22 / +5 lines
Lines 415-421 Node::~Node() a/Source/WebCore/dom/Node.cpp_sec1
415
    if (renderer())
415
    if (renderer())
416
        detach();
416
        detach();
417
417
418
    Document* doc = m_document;
418
    Document* doc = documentInternal();
419
    if (AXObjectCache::accessibilityEnabled() && doc && doc->axObjectCacheExists() && !isContainerNode())
419
    if (AXObjectCache::accessibilityEnabled() && doc && doc->axObjectCacheExists() && !isContainerNode())
420
        doc->axObjectCache()->remove(this);
420
        doc->axObjectCache()->remove(this);
421
    
421
    
Lines 424-452 Node::~Node() a/Source/WebCore/dom/Node.cpp_sec2
424
    if (m_next)
424
    if (m_next)
425
        m_next->setPreviousSibling(0);
425
        m_next->setPreviousSibling(0);
426
426
427
    if (doc)
427
    if (doc && !isDocumentNode())
428
        doc->guardDeref();
428
        doc->guardDeref();
429
429
430
    InspectorCounters::decrementCounter(InspectorCounters::NodeCounter);
430
    InspectorCounters::decrementCounter(InspectorCounters::NodeCounter);
431
}
431
}
432
432
433
void Node::setDocument(Document* document)
434
{
435
    ASSERT(!inDocument() || m_document == document);
436
    if (inDocument() || m_document == document)
437
        return;
438
439
    m_document = document;
440
}
441
442
void Node::setTreeScope(TreeScope* scope)
443
{
444
    if (!hasRareData() && scope->rootNode()->isDocumentNode())
445
        return;
446
447
    ensureRareData()->setTreeScope(scope);
448
}
449
450
Node* Node::pseudoAwarePreviousSibling() const
433
Node* Node::pseudoAwarePreviousSibling() const
451
{
434
{
452
    if (isElementNode() && !previousSibling()) {
435
    if (isElementNode() && !previousSibling()) {
Lines 496-502 NodeRareData* Node::ensureRareData() a/Source/WebCore/dom/Node.cpp_sec3
496
479
497
PassOwnPtr<NodeRareData> Node::createRareData()
480
PassOwnPtr<NodeRareData> Node::createRareData()
498
{
481
{
499
    return adoptPtr(new NodeRareData(documentInternal()));
482
    return adoptPtr(new NodeRareData());
500
}
483
}
501
484
502
void Node::clearRareData()
485
void Node::clearRareData()
Lines 1219-1225 void Node::attach() a/Source/WebCore/dom/Node.cpp_sec4
1219
    setAttached();
1202
    setAttached();
1220
    clearNeedsStyleRecalc();
1203
    clearNeedsStyleRecalc();
1221
1204
1222
    Document* doc = m_document;
1205
    Document* doc = documentInternal();
1223
    if (AXObjectCache::accessibilityEnabled() && doc && doc->axObjectCacheExists())
1206
    if (AXObjectCache::accessibilityEnabled() && doc && doc->axObjectCacheExists())
1224
        doc->axObjectCache()->updateCacheAfterNodeIsAttached(this);
1207
        doc->axObjectCache()->updateCacheAfterNodeIsAttached(this);
1225
}
1208
}
Lines 2736-2742 void Node::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const a/Source/WebCore/dom/Node.cpp_sec5
2736
    MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::DOM);
2719
    MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::DOM);
2737
    TreeShared<Node, ContainerNode>::reportMemoryUsage(memoryObjectInfo);
2720
    TreeShared<Node, ContainerNode>::reportMemoryUsage(memoryObjectInfo);
2738
    ScriptWrappable::reportMemoryUsage(memoryObjectInfo);
2721
    ScriptWrappable::reportMemoryUsage(memoryObjectInfo);
2739
    info.addMember(m_document);
2722
    info.addMember(m_treeScope);
2740
    info.addMember(m_next);
2723
    info.addMember(m_next);
2741
    info.addMember(m_previous);
2724
    info.addMember(m_previous);
2742
    if (RenderObject* renderer = this->renderer())
2725
    if (RenderObject* renderer = this->renderer())
- a/Source/WebCore/dom/Node.h -17 / +7 lines
Lines 33-38 a/Source/WebCore/dom/Node.h_sec1
33
#include "RenderStyleConstants.h"
33
#include "RenderStyleConstants.h"
34
#include "ScriptWrappable.h"
34
#include "ScriptWrappable.h"
35
#include "SimulatedClickOptions.h"
35
#include "SimulatedClickOptions.h"
36
#include "TreeScope.h"
36
#include "TreeShared.h"
37
#include "TreeShared.h"
37
#include <wtf/Forward.h>
38
#include <wtf/Forward.h>
38
#include <wtf/ListHashSet.h>
39
#include <wtf/ListHashSet.h>
Lines 85-91 class RenderObject; a/Source/WebCore/dom/Node.h_sec2
85
class RenderStyle;
86
class RenderStyle;
86
class ShadowRoot;
87
class ShadowRoot;
87
class TagNodeList;
88
class TagNodeList;
88
class TreeScope;
89
89
90
#if ENABLE(GESTURE_EVENTS)
90
#if ENABLE(GESTURE_EVENTS)
91
class PlatformGestureEvent;
91
class PlatformGestureEvent;
Lines 115-132 public: a/Source/WebCore/dom/Node.h_sec3
115
    RenderObject* renderer() const { return m_renderer; }
115
    RenderObject* renderer() const { return m_renderer; }
116
    void setRenderer(RenderObject* renderer) { m_renderer = renderer; }
116
    void setRenderer(RenderObject* renderer) { m_renderer = renderer; }
117
117
118
    TreeScope* treeScope() const { return m_treeScope; }
119
    void setTreeScope(TreeScope* scope) { m_treeScope = scope; }
120
121
    virtual ~NodeRareDataBase() { }
118
    virtual ~NodeRareDataBase() { }
122
protected:
119
protected:
123
    NodeRareDataBase(TreeScope* scope)
120
    NodeRareDataBase() { }
124
        : m_treeScope(scope)
125
    {
126
    }
127
private:
121
private:
128
    RenderObject* m_renderer;
122
    RenderObject* m_renderer;
129
    TreeScope* m_treeScope;
130
};
123
};
131
124
132
class Node : public EventTarget, public ScriptWrappable, public TreeShared<Node, ContainerNode> {
125
class Node : public EventTarget, public ScriptWrappable, public TreeShared<Node, ContainerNode> {
Lines 461-473 public: a/Source/WebCore/dom/Node.h_sec4
461
        return documentInternal();
454
        return documentInternal();
462
    }
455
    }
463
456
464
    TreeScope* treeScope() const;
457
    TreeScope* treeScope() const { return m_treeScope; }
465
458
466
    // Returns true if this node is associated with a document and is in its associated document's
459
    // Returns true if this node is associated with a document and is in its associated document's
467
    // node tree, false otherwise.
460
    // node tree, false otherwise.
468
    bool inDocument() const 
461
    bool inDocument() const 
469
    { 
462
    { 
470
        ASSERT(m_document || !getFlag(InDocumentFlag));
463
        ASSERT(documentInternal() || !getFlag(InDocumentFlag));
471
        return getFlag(InDocumentFlag);
464
        return getFlag(InDocumentFlag);
472
    }
465
    }
473
466
Lines 785-801 protected: a/Source/WebCore/dom/Node.h_sec5
785
778
786
    void setHasCustomCallbacks() { setFlag(true, HasCustomCallbacksFlag); }
779
    void setHasCustomCallbacks() { setFlag(true, HasCustomCallbacksFlag); }
787
780
788
    Document* documentInternal() const { return m_document; }
781
    Document* documentInternal() const { return treeScope()->documentScope(); }
782
    void setTreeScope(TreeScope* scope) { m_treeScope = scope; }
789
783
790
private:
784
private:
791
    friend class TreeShared<Node, ContainerNode>;
785
    friend class TreeShared<Node, ContainerNode>;
792
786
793
    void removedLastRef();
787
    void removedLastRef();
794
788
795
    // These API should be only used for a tree scope migration.
796
    void setTreeScope(TreeScope*);
797
    void setDocument(Document*);
798
799
    enum EditableLevel { Editable, RichlyEditable };
789
    enum EditableLevel { Editable, RichlyEditable };
800
    bool rendererIsEditable(EditableLevel, UserSelectAllTreatment = UserSelectAllIsAlwaysNonEditable) const;
790
    bool rendererIsEditable(EditableLevel, UserSelectAllTreatment = UserSelectAllIsAlwaysNonEditable) const;
801
    bool isEditableToAccessibility(EditableLevel) const;
791
    bool isEditableToAccessibility(EditableLevel) const;
Lines 837-843 private: a/Source/WebCore/dom/Node.h_sec6
837
#endif
827
#endif
838
828
839
    mutable uint32_t m_nodeFlags;
829
    mutable uint32_t m_nodeFlags;
840
    Document* m_document;
830
    TreeScope* m_treeScope;
841
    Node* m_previous;
831
    Node* m_previous;
842
    Node* m_next;
832
    Node* m_next;
843
    // When a node has rare data we move the renderer into the rare data.
833
    // When a node has rare data we move the renderer into the rare data.
- a/Source/WebCore/dom/NodeRareData.cpp -1 lines
Lines 49-55 void NodeListsNodeData::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) co a/Source/WebCore/dom/NodeRareData.cpp_sec1
49
void NodeRareData::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
49
void NodeRareData::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
50
{
50
{
51
    MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::DOM);
51
    MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::DOM);
52
    info.addMember(treeScope());
53
    info.addMember(m_nodeLists);
52
    info.addMember(m_nodeLists);
54
    info.addMember(m_childNodeList);
53
    info.addMember(m_childNodeList);
55
54
- a/Source/WebCore/dom/NodeRareData.h -3 / +2 lines
Lines 199-207 private: a/Source/WebCore/dom/NodeRareData.h_sec1
199
class NodeRareData : public NodeRareDataBase {
199
class NodeRareData : public NodeRareDataBase {
200
    WTF_MAKE_NONCOPYABLE(NodeRareData); WTF_MAKE_FAST_ALLOCATED;
200
    WTF_MAKE_NONCOPYABLE(NodeRareData); WTF_MAKE_FAST_ALLOCATED;
201
public:    
201
public:    
202
    NodeRareData(Document* document)
202
    NodeRareData()
203
        : NodeRareDataBase(document)
203
        : m_childNodeList(0)
204
        , m_childNodeList(0)
205
        , m_tabIndex(0)
204
        , m_tabIndex(0)
206
        , m_childIndex(0)
205
        , m_childIndex(0)
207
        , m_tabIndexWasSetExplicitly(false)
206
        , m_tabIndexWasSetExplicitly(false)
- a/Source/WebCore/dom/ShadowRoot.cpp -7 / +2 lines
Lines 65-71 COMPILE_ASSERT(sizeof(ShadowRoot) == sizeof(SameSizeAsShadowRoot), shadowroot_sh a/Source/WebCore/dom/ShadowRoot.cpp_sec1
65
65
66
ShadowRoot::ShadowRoot(Document* document)
66
ShadowRoot::ShadowRoot(Document* document)
67
    : DocumentFragment(document, CreateShadowRoot)
67
    : DocumentFragment(document, CreateShadowRoot)
68
    , TreeScope(this)
68
    , TreeScope(this, document)
69
    , m_prev(0)
69
    , m_prev(0)
70
    , m_next(0)
70
    , m_next(0)
71
    , m_numberOfStyles(0)
71
    , m_numberOfStyles(0)
Lines 75-86 ShadowRoot::ShadowRoot(Document* document) a/Source/WebCore/dom/ShadowRoot.cpp_sec2
75
    , m_registeredWithParentShadowRoot(false)
75
    , m_registeredWithParentShadowRoot(false)
76
{
76
{
77
    ASSERT(document);
77
    ASSERT(document);
78
    
78
    setTreeScope(this);
79
    // Assume document as parent scope.
80
    setParentTreeScope(document);
81
    // Shadow tree scopes have the scope pointer point to themselves.
82
    // This way, direct children will receive the correct scope pointer.
83
    ensureRareData()->setTreeScope(this);
84
}
79
}
85
80
86
ShadowRoot::~ShadowRoot()
81
ShadowRoot::~ShadowRoot()
- a/Source/WebCore/dom/TreeScope.cpp -3 / +23 lines
Lines 54-72 namespace WebCore { a/Source/WebCore/dom/TreeScope.cpp_sec1
54
54
55
struct SameSizeAsTreeScope {
55
struct SameSizeAsTreeScope {
56
    virtual ~SameSizeAsTreeScope();
56
    virtual ~SameSizeAsTreeScope();
57
    void* pointers[7];
57
    void* pointers[8];
58
};
58
};
59
59
60
COMPILE_ASSERT(sizeof(TreeScope) == sizeof(SameSizeAsTreeScope), treescope_should_stay_small);
60
COMPILE_ASSERT(sizeof(TreeScope) == sizeof(SameSizeAsTreeScope), treescope_should_stay_small);
61
61
62
using namespace HTMLNames;
62
using namespace HTMLNames;
63
63
64
TreeScope::TreeScope(ContainerNode* rootNode)
64
TreeScope::TreeScope(ContainerNode* rootNode, Document* document)
65
    : m_rootNode(rootNode)
65
    : m_rootNode(rootNode)
66
    , m_parentTreeScope(0)
66
    , m_documentScope(document)
67
    , m_parentTreeScope(document)
67
    , m_idTargetObserverRegistry(IdTargetObserverRegistry::create())
68
    , m_idTargetObserverRegistry(IdTargetObserverRegistry::create())
68
{
69
{
69
    ASSERT(rootNode);
70
    ASSERT(rootNode);
71
    ASSERT(document);
72
    ASSERT(rootNode != document);
73
}
74
75
TreeScope::TreeScope(Document* document)
76
    : m_rootNode(document)
77
    , m_documentScope(document)
78
    , m_parentTreeScope(0)
79
    , m_idTargetObserverRegistry(IdTargetObserverRegistry::create())
80
{
81
    ASSERT(document);
82
}
83
84
TreeScope::TreeScope()
85
    : m_rootNode(0)
86
    , m_documentScope(0)
87
    , m_parentTreeScope(0)
88
{
70
}
89
}
71
90
72
TreeScope::~TreeScope()
91
TreeScope::~TreeScope()
Lines 92-97 void TreeScope::setParentTreeScope(TreeScope* newParentScope) a/Source/WebCore/dom/TreeScope.cpp_sec2
92
    ASSERT(newParentScope);
111
    ASSERT(newParentScope);
93
112
94
    m_parentTreeScope = newParentScope;
113
    m_parentTreeScope = newParentScope;
114
    setDocumentScope(newParentScope->documentScope());
95
}
115
}
96
116
97
Element* TreeScope::getElementById(const AtomicString& elementId) const
117
Element* TreeScope::getElementById(const AtomicString& elementId) const
- a/Source/WebCore/dom/TreeScope.h -1 / +21 lines
Lines 35-40 namespace WebCore { a/Source/WebCore/dom/TreeScope.h_sec1
35
35
36
class ContainerNode;
36
class ContainerNode;
37
class DOMSelection;
37
class DOMSelection;
38
class Document;
38
class Element;
39
class Element;
39
class HTMLLabelElement;
40
class HTMLLabelElement;
40
class HTMLMapElement;
41
class HTMLMapElement;
Lines 46-51 class Node; a/Source/WebCore/dom/TreeScope.h_sec2
46
// the destructor.
47
// the destructor.
47
class TreeScope {
48
class TreeScope {
48
    friend class Document;
49
    friend class Document;
50
    friend class TreeScopeAdopter;
49
51
50
public:
52
public:
51
    TreeScope* parentTreeScope() const { return m_parentTreeScope; }
53
    TreeScope* parentTreeScope() const { return m_parentTreeScope; }
Lines 58-63 public: a/Source/WebCore/dom/TreeScope.h_sec3
58
    void addElementById(const AtomicString& elementId, Element*);
60
    void addElementById(const AtomicString& elementId, Element*);
59
    void removeElementById(const AtomicString& elementId, Element*);
61
    void removeElementById(const AtomicString& elementId, Element*);
60
62
63
    Document* documentScope() const { return m_documentScope; }
64
61
    Node* ancestorInThisScope(Node*) const;
65
    Node* ancestorInThisScope(Node*) const;
62
66
63
    void addImageMap(HTMLMapElement*);
67
    void addImageMap(HTMLMapElement*);
Lines 91-104 public: a/Source/WebCore/dom/TreeScope.h_sec4
91
95
92
    virtual void reportMemoryUsage(MemoryObjectInfo*) const;
96
    virtual void reportMemoryUsage(MemoryObjectInfo*) const;
93
97
98
    static TreeScope* noDocumentInstance()
99
    {
100
        DEFINE_STATIC_LOCAL(TreeScope, instance, ());
101
        return &instance;
102
    }
103
94
protected:
104
protected:
95
    explicit TreeScope(ContainerNode*);
105
    TreeScope(ContainerNode*, Document*);
106
    TreeScope(Document*);
96
    virtual ~TreeScope();
107
    virtual ~TreeScope();
97
108
98
    void destroyTreeScopeData();
109
    void destroyTreeScopeData();
110
    void setDocumentScope(Document* document)
111
    {
112
        ASSERT(document);
113
        ASSERT(this != noDocumentInstance());
114
        m_documentScope = document;
115
    }
99
116
100
private:
117
private:
118
    TreeScope();
119
101
    ContainerNode* m_rootNode;
120
    ContainerNode* m_rootNode;
121
    Document* m_documentScope;
102
    TreeScope* m_parentTreeScope;
122
    TreeScope* m_parentTreeScope;
103
123
104
    OwnPtr<DocumentOrderedMap> m_elementsById;
124
    OwnPtr<DocumentOrderedMap> m_elementsById;
- a/Source/WebCore/dom/TreeScopeAdopter.cpp -3 / +5 lines
Lines 42-55 void TreeScopeAdopter::moveTreeToNewScope(Node* root) const a/Source/WebCore/dom/TreeScopeAdopter.cpp_sec1
42
    // that element may contain stale data as changes made to it will have updated the DOMTreeVersion
42
    // that element may contain stale data as changes made to it will have updated the DOMTreeVersion
43
    // of the document it was moved to. By increasing the DOMTreeVersion of the donating document here
43
    // of the document it was moved to. By increasing the DOMTreeVersion of the donating document here
44
    // we ensure that the collection cache will be invalidated as needed when the element is moved back.
44
    // we ensure that the collection cache will be invalidated as needed when the element is moved back.
45
    Document* oldDocument = m_oldScope ? m_oldScope->rootNode()->document() : 0;
45
    Document* oldDocument = m_oldScope->documentScope();
46
    Document* newDocument = m_newScope->rootNode()->document();
46
    Document* newDocument = m_newScope->documentScope();
47
    bool willMoveToNewDocument = oldDocument != newDocument;
47
    bool willMoveToNewDocument = oldDocument != newDocument;
48
    if (oldDocument && willMoveToNewDocument)
48
    if (oldDocument && willMoveToNewDocument)
49
        oldDocument->incDOMTreeVersion();
49
        oldDocument->incDOMTreeVersion();
50
50
51
    for (Node* node = root; node; node = node->traverseNextNode(root)) {
51
    for (Node* node = root; node; node = node->traverseNextNode(root)) {
52
        node->setTreeScope(m_newScope);
52
        node->setTreeScope(m_newScope);
53
53
        if (node->hasRareData()) {
54
        if (node->hasRareData()) {
54
            NodeRareData* rareData = node->rareData();
55
            NodeRareData* rareData = node->rareData();
55
            if (rareData->nodeLists())
56
            if (rareData->nodeLists())
Lines 96-102 inline void TreeScopeAdopter::moveNodeToNewDocument(Node* node, Document* oldDoc a/Source/WebCore/dom/TreeScopeAdopter.cpp_sec2
96
    if (oldDocument)
97
    if (oldDocument)
97
        oldDocument->moveNodeIteratorsToNewDocument(node, newDocument);
98
        oldDocument->moveNodeIteratorsToNewDocument(node, newDocument);
98
99
99
    node->setDocument(newDocument);
100
    if (node->isShadowRoot())
101
        toShadowRoot(node)->setDocumentScope(newDocument);
100
102
101
#ifndef NDEBUG
103
#ifndef NDEBUG
102
    didMoveToNewDocumentWasCalled = false;
104
    didMoveToNewDocumentWasCalled = false;

Return to Bug 59816