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

Unified Diff: Source/core/dom/Node.cpp

Issue 23819007: Have Node::document() return a reference instead of a pointer (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase on master Created 7 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/dom/Node.h ('k') | Source/core/dom/NodeIterator.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/dom/Node.cpp
diff --git a/Source/core/dom/Node.cpp b/Source/core/dom/Node.cpp
index 9c563c07b4cbf96044eb8c8e96711a622cf7ee2f..7cf67788ec5d74f369bb0315871cb385fa3f5967 100644
--- a/Source/core/dom/Node.cpp
+++ b/Source/core/dom/Node.cpp
@@ -600,7 +600,7 @@ void Node::normalize()
// Both non-empty text nodes. Merge them.
unsigned offset = text->length();
text->appendData(nextText->data());
- document()->textNodesMerged(nextText.get(), offset);
+ document().textNodesMerged(nextText.get(), offset);
nextText->remove(IGNORE_EXCEPTION);
}
@@ -634,13 +634,13 @@ const AtomicString& Node::namespaceURI() const
bool Node::isContentEditable(UserSelectAllTreatment treatment)
{
- document()->updateStyleIfNeeded();
+ document().updateStyleIfNeeded();
return rendererIsEditable(Editable, treatment);
}
bool Node::isContentRichlyEditable()
{
- document()->updateStyleIfNeeded();
+ document().updateStyleIfNeeded();
return rendererIsEditable(RichlyEditable, UserSelectAllIsAlwaysNonEditable);
}
@@ -684,11 +684,10 @@ bool Node::isEditableToAccessibility(EditableLevel editableLevel) const
if (editableLevel == RichlyEditable)
return false;
- ASSERT(document());
ASSERT(AXObjectCache::accessibilityEnabled());
- ASSERT(document()->existingAXObjectCache());
+ ASSERT(document().existingAXObjectCache());
- if (AXObjectCache* cache = document()->existingAXObjectCache())
+ if (AXObjectCache* cache = document().existingAXObjectCache())
return cache->rootAXEditableElement(this);
return false;
@@ -792,8 +791,8 @@ void Node::markAncestorsWithChildNeedsDistributionRecalc()
{
for (Node* node = this; node && !node->childNeedsDistributionRecalc(); node = node->parentOrShadowHostNode())
node->setChildNeedsDistributionRecalc();
- if (document()->childNeedsDistributionRecalc())
- document()->scheduleStyleRecalc();
+ if (document().childNeedsDistributionRecalc())
+ document().scheduleStyleRecalc();
}
inline void Node::setStyleChange(StyleChangeType changeType)
@@ -806,8 +805,8 @@ inline void Node::markAncestorsWithChildNeedsStyleRecalc()
for (ContainerNode* p = parentOrShadowHostNode(); p && !p->childNeedsStyleRecalc(); p = p->parentOrShadowHostNode())
p->setChildNeedsStyleRecalc();
- if (document()->needsStyleRecalc() || document()->childNeedsStyleRecalc())
- document()->scheduleStyleRecalc();
+ if (document().needsStyleRecalc() || document().childNeedsStyleRecalc())
+ document().scheduleStyleRecalc();
}
void Node::refEventTarget()
@@ -865,10 +864,10 @@ bool Node::shouldHaveFocusAppearance() const
bool Node::isInert() const
{
- const HTMLDialogElement* dialog = document()->activeModalDialog();
+ const HTMLDialogElement* dialog = document().activeModalDialog();
if (dialog && !containsIncludingShadowDOM(dialog) && !dialog->containsIncludingShadowDOM(this))
return true;
- return document()->ownerElement() && document()->ownerElement()->isInert();
+ return document().ownerElement() && document().ownerElement()->isInert();
}
unsigned Node::nodeIndex() const
@@ -925,10 +924,10 @@ void Node::invalidateNodeListCachesInAncestors(const QualifiedName* attrName, El
if (attrName && !attributeOwnerElement)
return;
- if (!document()->shouldInvalidateNodeListCaches(attrName))
+ if (!document().shouldInvalidateNodeListCaches(attrName))
return;
- document()->invalidateNodeListCaches(attrName);
+ document().invalidateNodeListCaches(attrName);
for (Node* node = this; node; node = node->parentNode()) {
if (!node->hasRareData())
@@ -1001,7 +1000,7 @@ bool Node::containsIncludingShadowDOM(const Node* node) const
if (this == node)
return true;
- if (document() != node->document())
+ if (&document() != &node->document())
return false;
if (inDocument() != node->inDocument())
@@ -1063,7 +1062,7 @@ inline void Node::detachNode(Node* root, const AttachContext& context)
void Node::reattach(const AttachContext& context)
{
// FIXME: Text::updateTextRenderer calls reattach outside a style recalc.
- ASSERT(document()->inStyleRecalc() || isTextNode());
+ ASSERT(document().inStyleRecalc() || isTextNode());
AttachContext reattachContext(context);
reattachContext.performingReattach = true;
@@ -1079,7 +1078,7 @@ void Node::attach(const AttachContext&)
// If this node got a renderer it may be the previousRenderer() of sibling text nodes and thus affect the
// result of Text::textRendererIsNeeded() for those nodes.
// FIXME: This loop is no longer required once we lazy attach all the time.
- if (renderer() && !document()->inStyleRecalc()) {
+ if (renderer() && !document().inStyleRecalc()) {
for (Node* next = nextSibling(); next; next = next->nextSibling()) {
if (next->renderer())
break;
@@ -1129,13 +1128,13 @@ void Node::detach(const AttachContext& context)
// Do not remove the element's hovered and active status
// if performing a reattach.
if (!context.performingReattach) {
- Document* doc = document();
+ Document& doc = document();
if (isUserActionElement()) {
if (hovered())
- doc->hoveredNodeDetached(this);
+ doc.hoveredNodeDetached(this);
if (inActiveChain())
- doc->activeChainNodeDetached(this);
- doc->userActionElements().didDetach(this);
+ doc.activeChainNodeDetached(this);
+ doc.userActionElements().didDetach(this);
}
}
@@ -1229,7 +1228,7 @@ bool Node::canStartSelection() const
bool Node::isRegisteredWithNamedFlow() const
{
- return document()->renderView()->flowThreadController()->isContentNodeRegisteredWithAnyNamedFlow(this);
+ return document().renderView()->flowThreadController()->isContentNodeRegisteredWithAnyNamedFlow(this);
}
Element* Node::shadowHost() const
@@ -1319,7 +1318,7 @@ bool Node::isRootEditableElement() const
Element* Node::rootEditableElement(EditableType editableType) const
{
if (editableType == HasEditableAXRole) {
- if (AXObjectCache* cache = document()->existingAXObjectCache())
+ if (AXObjectCache* cache = document().existingAXObjectCache())
return const_cast<Element*>(cache->rootAXEditableElement(this));
}
@@ -1350,7 +1349,7 @@ PassRefPtr<NodeList> Node::getElementsByTagName(const AtomicString& localName)
if (localName.isNull())
return 0;
- if (document()->isHTMLDocument())
+ if (document().isHTMLDocument())
return ensureRareData()->ensureNodeLists()->addCacheWithAtomicName<HTMLTagNodeList>(this, HTMLTagNodeListType, localName);
return ensureRareData()->ensureNodeLists()->addCacheWithAtomicName<TagNodeList>(this, TagNodeListType, localName);
}
@@ -1389,7 +1388,7 @@ PassRefPtr<Element> Node::querySelector(const AtomicString& selectors, Exception
return 0;
}
- SelectorQuery* selectorQuery = document()->selectorQueryCache()->add(selectors, document(), es);
+ SelectorQuery* selectorQuery = document().selectorQueryCache()->add(selectors, &document(), es);
if (!selectorQuery)
return 0;
return selectorQuery->queryFirst(this);
@@ -1402,7 +1401,7 @@ PassRefPtr<NodeList> Node::querySelectorAll(const AtomicString& selectors, Excep
return 0;
}
- SelectorQuery* selectorQuery = document()->selectorQueryCache()->add(selectors, document(), es);
+ SelectorQuery* selectorQuery = document().selectorQueryCache()->add(selectors, &document(), es);
if (!selectorQuery)
return 0;
return selectorQuery->queryAll(this);
@@ -1410,7 +1409,7 @@ PassRefPtr<NodeList> Node::querySelectorAll(const AtomicString& selectors, Excep
Document* Node::ownerDocument() const
{
- Document* doc = document();
+ Document* doc = &document();
return doc == this ? 0 : doc;
}
@@ -1710,7 +1709,7 @@ void Node::setTextContent(const String& text, ExceptionState& es)
ChildListMutationScope mutation(this);
container->removeChildren();
if (!text.isEmpty())
- container->appendChild(document()->createTextNode(text), es);
+ container->appendChild(document().createTextNode(text), es);
return;
}
case DOCUMENT_NODE:
@@ -2060,8 +2059,8 @@ void Node::formatForDebugger(char* buffer, unsigned length) const
static ContainerNode* parentOrShadowHostOrFrameOwner(const Node* node)
{
ContainerNode* parent = node->parentOrShadowHostNode();
- if (!parent && node->document()->frame())
- parent = node->document()->frame()->ownerElement();
+ if (!parent && node->document().frame())
+ parent = node->document().frame()->ownerElement();
return parent;
}
@@ -2134,7 +2133,7 @@ const AtomicString& Node::interfaceName() const
ScriptExecutionContext* Node::scriptExecutionContext() const
{
- return document();
+ return &document();
}
void Node::didMoveToNewDocument(Document* oldDocument)
@@ -2146,7 +2145,7 @@ void Node::didMoveToNewDocument(Document* oldDocument)
if (!listenerMap.isEmpty()) {
Vector<AtomicString> types = listenerMap.eventTypes();
for (unsigned i = 0; i < types.size(); ++i)
- document()->addListenerTypeIfNeeded(types[i]);
+ document().addListenerTypeIfNeeded(types[i]);
}
}
@@ -2157,31 +2156,31 @@ void Node::didMoveToNewDocument(Document* oldDocument)
const EventListenerVector& mousewheelListeners = getEventListeners(eventNames().mousewheelEvent);
for (size_t i = 0; i < mousewheelListeners.size(); ++i) {
oldDocument->didRemoveWheelEventHandler();
- document()->didAddWheelEventHandler();
+ document().didAddWheelEventHandler();
}
const EventListenerVector& wheelListeners = getEventListeners(eventNames().wheelEvent);
for (size_t i = 0; i < wheelListeners.size(); ++i) {
oldDocument->didRemoveWheelEventHandler();
- document()->didAddWheelEventHandler();
+ document().didAddWheelEventHandler();
}
if (const TouchEventTargetSet* touchHandlers = oldDocument ? oldDocument->touchEventTargets() : 0) {
while (touchHandlers->contains(this)) {
oldDocument->didRemoveTouchEventHandler(this);
- document()->didAddTouchEventHandler(this);
+ document().didAddTouchEventHandler(this);
}
}
if (Vector<OwnPtr<MutationObserverRegistration> >* registry = mutationObserverRegistry()) {
for (size_t i = 0; i < registry->size(); ++i) {
- document()->addMutationObserverTypes(registry->at(i)->mutationTypes());
+ document().addMutationObserverTypes(registry->at(i)->mutationTypes());
}
}
if (HashSet<MutationObserverRegistration*>* transientRegistry = transientMutationObserverRegistry()) {
for (HashSet<MutationObserverRegistration*>::iterator iter = transientRegistry->begin(); iter != transientRegistry->end(); ++iter) {
- document()->addMutationObserverTypes((*iter)->mutationTypes());
+ document().addMutationObserverTypes((*iter)->mutationTypes());
}
}
}
@@ -2191,12 +2190,12 @@ static inline bool tryAddEventListener(Node* targetNode, const AtomicString& eve
if (!targetNode->EventTarget::addEventListener(eventType, listener, useCapture))
return false;
- Document* document = targetNode->document();
- document->addListenerTypeIfNeeded(eventType);
+ Document& document = targetNode->document();
+ document.addListenerTypeIfNeeded(eventType);
if (eventType == eventNames().wheelEvent || eventType == eventNames().mousewheelEvent)
- document->didAddWheelEventHandler();
+ document.didAddWheelEventHandler();
else if (eventNames().isTouchEventType(eventType))
- document->didAddTouchEventHandler(targetNode);
+ document.didAddTouchEventHandler(targetNode);
return true;
}
@@ -2213,11 +2212,11 @@ static inline bool tryRemoveEventListener(Node* targetNode, const AtomicString&
// FIXME: Notify Document that the listener has vanished. We need to keep track of a number of
// listeners for each type, not just a bool - see https://bugs.webkit.org/show_bug.cgi?id=33861
- Document* document = targetNode->document();
+ Document& document = targetNode->document();
if (eventType == eventNames().wheelEvent || eventType == eventNames().mousewheelEvent)
- document->didRemoveWheelEventHandler();
+ document.didRemoveWheelEventHandler();
else if (eventNames().isTouchEventType(eventType))
- document->didRemoveTouchEventHandler(targetNode);
+ document.didRemoveTouchEventHandler(targetNode);
return true;
}
@@ -2318,7 +2317,7 @@ void Node::registerMutationObserver(MutationObserver* observer, MutationObserver
registration = registry.last().get();
}
- document()->addMutationObserverTypes(registration->mutationTypes());
+ document().addMutationObserverTypes(registration->mutationTypes());
}
void Node::unregisterMutationObserver(MutationObserverRegistration* registration)
@@ -2358,7 +2357,7 @@ void Node::unregisterTransientMutationObserver(MutationObserverRegistration* reg
void Node::notifyMutationObserversNodeWillDetach()
{
- if (!document()->hasMutationObservers())
+ if (!document().hasMutationObservers())
return;
for (Node* node = parentNode(); node; node = node->parentNode()) {
@@ -2412,7 +2411,7 @@ void Node::dispatchSubtreeModifiedEvent()
ASSERT(!NoEventDispatchAssertion::isEventDispatchForbidden());
- if (!document()->hasListenerType(Document::DOMSUBTREEMODIFIED_LISTENER))
+ if (!document().hasListenerType(Document::DOMSUBTREEMODIFIED_LISTENER))
return;
dispatchScopedEvent(MutationEvent::create(eventNames().DOMSubtreeModifiedEvent, true));
@@ -2421,7 +2420,7 @@ void Node::dispatchSubtreeModifiedEvent()
bool Node::dispatchDOMActivateEvent(int detail, PassRefPtr<Event> underlyingEvent)
{
ASSERT(!NoEventDispatchAssertion::isEventDispatchForbidden());
- RefPtr<UIEvent> event = UIEvent::create(eventNames().DOMActivateEvent, true, true, document()->defaultView(), detail);
+ RefPtr<UIEvent> event = UIEvent::create(eventNames().DOMActivateEvent, true, true, document().defaultView(), detail);
event->setUnderlyingEvent(underlyingEvent);
dispatchScopedEvent(event);
return event->defaultHandled();
@@ -2429,18 +2428,18 @@ bool Node::dispatchDOMActivateEvent(int detail, PassRefPtr<Event> underlyingEven
bool Node::dispatchKeyEvent(const PlatformKeyboardEvent& event)
{
- return EventDispatcher::dispatchEvent(this, KeyboardEventDispatchMediator::create(KeyboardEvent::create(event, document()->defaultView())));
+ return EventDispatcher::dispatchEvent(this, KeyboardEventDispatchMediator::create(KeyboardEvent::create(event, document().defaultView())));
}
bool Node::dispatchMouseEvent(const PlatformMouseEvent& event, const AtomicString& eventType,
int detail, Node* relatedTarget)
{
- return EventDispatcher::dispatchEvent(this, MouseEventDispatchMediator::create(MouseEvent::create(eventType, document()->defaultView(), event, detail, relatedTarget)));
+ return EventDispatcher::dispatchEvent(this, MouseEventDispatchMediator::create(MouseEvent::create(eventType, document().defaultView(), event, detail, relatedTarget)));
}
bool Node::dispatchGestureEvent(const PlatformGestureEvent& event)
{
- RefPtr<GestureEvent> gestureEvent = GestureEvent::create(document()->defaultView(), event);
+ RefPtr<GestureEvent> gestureEvent = GestureEvent::create(document().defaultView(), event);
if (!gestureEvent.get())
return false;
return EventDispatcher::dispatchEvent(this, GestureEventDispatchMediator::create(gestureEvent));
@@ -2458,7 +2457,7 @@ void Node::dispatchSimulatedClick(Event* underlyingEvent, SimulatedClickMouseEve
bool Node::dispatchBeforeLoadEvent(const String& sourceURL)
{
- if (!document()->hasListenerType(Document::BEFORELOAD_LISTENER))
+ if (!document().hasListenerType(Document::BEFORELOAD_LISTENER))
return true;
RefPtr<Node> protector(this);
@@ -2469,7 +2468,7 @@ bool Node::dispatchBeforeLoadEvent(const String& sourceURL)
bool Node::dispatchWheelEvent(const PlatformWheelEvent& event)
{
- return EventDispatcher::dispatchEvent(this, WheelEventDispatchMediator::create(event, document()->defaultView()));
+ return EventDispatcher::dispatchEvent(this, WheelEventDispatchMediator::create(event, document().defaultView()));
}
void Node::dispatchChangeEvent()
@@ -2489,7 +2488,7 @@ void Node::defaultEventHandler(Event* event)
const AtomicString& eventType = event->type();
if (eventType == eventNames().keydownEvent || eventType == eventNames().keypressEvent) {
if (event->isKeyboardEvent()) {
- if (Frame* frame = document()->frame())
+ if (Frame* frame = document().frame())
frame->eventHandler()->defaultKeyboardEventHandler(toKeyboardEvent(event));
}
} else if (eventType == eventNames().clickEvent) {
@@ -2497,11 +2496,11 @@ void Node::defaultEventHandler(Event* event)
if (dispatchDOMActivateEvent(detail, event))
event->setDefaultHandled();
} else if (eventType == eventNames().contextmenuEvent) {
- if (Page* page = document()->page())
+ if (Page* page = document().page())
page->contextMenuController().handleContextMenuEvent(event);
} else if (eventType == eventNames().textInputEvent) {
if (event->hasInterface(eventNames().interfaceForTextEvent))
- if (Frame* frame = document()->frame())
+ if (Frame* frame = document().frame())
frame->eventHandler()->defaultTextInputEventHandler(static_cast<TextEvent*>(event));
#if OS(WINDOWS)
} else if (eventType == eventNames().mousedownEvent && event->isMouseEvent()) {
@@ -2515,7 +2514,7 @@ void Node::defaultEventHandler(Event* event)
renderer = renderer->parent();
if (renderer) {
- if (Frame* frame = document()->frame())
+ if (Frame* frame = document().frame())
frame->eventHandler()->startPanScrolling(renderer);
}
}
@@ -2530,7 +2529,7 @@ void Node::defaultEventHandler(Event* event)
startNode = startNode->parentOrShadowHostNode();
if (startNode && startNode->renderer())
- if (Frame* frame = document()->frame())
+ if (Frame* frame = document().frame())
frame->eventHandler()->defaultWheelEventHandler(startNode, wheelEvent);
} else if (event->type() == eventNames().webkitEditableContentChangedEvent) {
dispatchInputEvent();
@@ -2607,7 +2606,7 @@ void Node::removedLastRef()
void Node::textRects(Vector<IntRect>& rects) const
{
- RefPtr<Range> range = Range::create(document());
+ RefPtr<Range> range = Range::create(&document());
range->selectNodeContents(const_cast<Node*>(this), IGNORE_EXCEPTION);
range->textRects(rects);
}
@@ -2652,7 +2651,7 @@ void Node::updateAncestorConnectedSubframeCountForInsertion() const
PassRefPtr<NodeList> Node::getDestinationInsertionPoints()
{
- document()->updateDistributionForNodeIfNeeded(this);
+ document().updateDistributionForNodeIfNeeded(this);
Vector<InsertionPoint*, 8> insertionPoints;
collectInsertionPointsWhereNodeIsDistributed(this, insertionPoints);
Vector<RefPtr<Node> > filteredInsertionPoints;
@@ -2689,41 +2688,41 @@ size_t Node::numberOfScopedHTMLStyleChildren() const
void Node::setFocus(bool flag)
{
- document()->userActionElements().setFocused(this, flag);
+ document().userActionElements().setFocused(this, flag);
}
void Node::setActive(bool flag, bool)
{
- document()->userActionElements().setActive(this, flag);
+ document().userActionElements().setActive(this, flag);
}
void Node::setHovered(bool flag)
{
- document()->userActionElements().setHovered(this, flag);
+ document().userActionElements().setHovered(this, flag);
}
bool Node::isUserActionElementActive() const
{
ASSERT(isUserActionElement());
- return document()->userActionElements().isActive(this);
+ return document().userActionElements().isActive(this);
}
bool Node::isUserActionElementInActiveChain() const
{
ASSERT(isUserActionElement());
- return document()->userActionElements().isInActiveChain(this);
+ return document().userActionElements().isInActiveChain(this);
}
bool Node::isUserActionElementHovered() const
{
ASSERT(isUserActionElement());
- return document()->userActionElements().isHovered(this);
+ return document().userActionElements().isHovered(this);
}
bool Node::isUserActionElementFocused() const
{
ASSERT(isUserActionElement());
- return document()->userActionElements().isFocused(this);
+ return document().userActionElements().isFocused(this);
}
void Node::setCustomElementState(CustomElementState newState)
« no previous file with comments | « Source/core/dom/Node.h ('k') | Source/core/dom/NodeIterator.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698