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

Side by Side Diff: Source/core/dom/TreeScope.cpp

Issue 112953007: Make TreeScope::documentScope() return a reference and ensure m_documentScope is never NULL (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Added FIXMEs Created 6 years, 11 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 | « Source/core/dom/TreeScope.h ('k') | Source/core/dom/TreeScopeAdopter.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 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All Rights Reserved. 2 * Copyright (C) 2011 Google Inc. All Rights Reserved.
3 * Copyright (C) 2012 Apple Inc. All rights reserved. 3 * Copyright (C) 2012 Apple Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 : m_rootNode(document) 73 : m_rootNode(document)
74 , m_documentScope(document) 74 , m_documentScope(document)
75 , m_parentTreeScope(0) 75 , m_parentTreeScope(0)
76 , m_guardRefCount(0) 76 , m_guardRefCount(0)
77 , m_idTargetObserverRegistry(IdTargetObserverRegistry::create()) 77 , m_idTargetObserverRegistry(IdTargetObserverRegistry::create())
78 { 78 {
79 ASSERT(document); 79 ASSERT(document);
80 m_rootNode->setTreeScope(this); 80 m_rootNode->setTreeScope(this);
81 } 81 }
82 82
83 TreeScope::TreeScope()
84 : m_rootNode(0)
85 , m_documentScope(0)
86 , m_parentTreeScope(0)
87 , m_guardRefCount(0)
88 {
89 }
90
91 TreeScope::~TreeScope() 83 TreeScope::~TreeScope()
92 { 84 {
93 ASSERT(!m_guardRefCount); 85 ASSERT(!m_guardRefCount);
94 m_rootNode->setTreeScope(0); 86 m_rootNode->setTreeScope(0);
95 87
96 if (m_selection) { 88 if (m_selection) {
97 m_selection->clearTreeScope(); 89 m_selection->clearTreeScope();
98 m_selection = 0; 90 m_selection = 0;
99 } 91 }
100 92
101 if (m_parentTreeScope) 93 if (m_parentTreeScope)
102 m_parentTreeScope->guardDeref(); 94 m_parentTreeScope->guardDeref();
103 } 95 }
104 96
105 bool TreeScope::rootNodeHasTreeSharedParent() const 97 bool TreeScope::rootNodeHasTreeSharedParent() const
106 { 98 {
107 return rootNode()->hasTreeSharedParent(); 99 return rootNode()->hasTreeSharedParent();
108 } 100 }
109 101
110 void TreeScope::destroyTreeScopeData() 102 void TreeScope::destroyTreeScopeData()
111 { 103 {
112 m_elementsById.clear(); 104 m_elementsById.clear();
113 m_imageMapsByName.clear(); 105 m_imageMapsByName.clear();
114 m_labelsByForAttribute.clear(); 106 m_labelsByForAttribute.clear();
115 } 107 }
116 108
117 void TreeScope::clearDocumentScope()
118 {
119 ASSERT(rootNode()->isDocumentNode());
120 m_documentScope = 0;
121 }
122
123 void TreeScope::setParentTreeScope(TreeScope* newParentScope) 109 void TreeScope::setParentTreeScope(TreeScope* newParentScope)
124 { 110 {
125 // A document node cannot be re-parented. 111 // A document node cannot be re-parented.
126 ASSERT(!rootNode()->isDocumentNode()); 112 ASSERT(!rootNode()->isDocumentNode());
127 // Every scope other than document needs a parent scope. 113 // Every scope other than document needs a parent scope.
128 ASSERT(newParentScope); 114 ASSERT(newParentScope);
129 115
130 newParentScope->guardRef(); 116 newParentScope->guardRef();
131 if (m_parentTreeScope) 117 if (m_parentTreeScope)
132 m_parentTreeScope->guardDeref(); 118 m_parentTreeScope->guardDeref();
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 for (ShadowRoot* root = element->youngestShadowRoot(); root; root = root ->olderShadowRoot()) 492 for (ShadowRoot* root = element->youngestShadowRoot(); root; root = root ->olderShadowRoot())
507 root->setNeedsStyleRecalcForViewportUnits(); 493 root->setNeedsStyleRecalcForViewportUnits();
508 RenderStyle* style = element->renderStyle(); 494 RenderStyle* style = element->renderStyle();
509 if (style && style->hasViewportUnits()) 495 if (style && style->hasViewportUnits())
510 element->setNeedsStyleRecalc(LocalStyleChange); 496 element->setNeedsStyleRecalc(LocalStyleChange);
511 } 497 }
512 } 498 }
513 499
514 KURL TreeScope::completeURL(const String& url) const 500 KURL TreeScope::completeURL(const String& url) const
515 { 501 {
516 ASSERT(documentScope()); 502 return documentScope().completeURLWithOverride(url, baseURL());
517 return documentScope()->completeURLWithOverride(url, baseURL());
518 } 503 }
519 504
520 } // namespace WebCore 505 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/dom/TreeScope.h ('k') | Source/core/dom/TreeScopeAdopter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698