Commit 622b1a48 authored by akling@apple.com's avatar akling@apple.com

Node::document() should return a reference.

<https://webkit.org/b/120496>

Reviewed by Antti Koivisto.

Now that orphan DocumentType nodes also have document pointers, it's no longer
possible to have a null Node::document().

Cement this by making document() return a reference, and remove the various
null checks exposed by this.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@154877 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 26e1d24f
2013-08-30 Andreas Kling <akling@apple.com>
Node::document() should return a reference.
<https://webkit.org/b/120496>
Reviewed by Antti Koivisto.
Now that orphan DocumentType nodes also have document pointers, it's no longer
possible to have a null Node::document().
Cement this by making document() return a reference, and remove the various
null checks exposed by this.
2013-08-30 Andrei Parvu <parvu@adobe.com>
[CSS Masking] -webkit-mask-repeat: space does not work
......@@ -138,7 +138,7 @@ AccessibilityObject* AXObjectCache::focusedImageMapUIElement(HTMLAreaElement* ar
if (!imageElement)
return 0;
AccessibilityObject* axRenderImage = areaElement->document()->axObjectCache()->getOrCreate(imageElement);
AccessibilityObject* axRenderImage = areaElement->document().axObjectCache()->getOrCreate(imageElement);
if (!axRenderImage)
return 0;
......@@ -716,7 +716,7 @@ void AXObjectCache::postNotification(Node* node, AXNotification notification, bo
if (!node)
return;
postNotification(object.get(), node->document(), notification, postToElement, postType);
postNotification(object.get(), &node->document(), notification, postToElement, postType);
}
void AXObjectCache::postNotification(AccessibilityObject* object, Document* document, AXNotification notification, bool postToElement, PostType postType)
......@@ -923,7 +923,7 @@ void AXObjectCache::textMarkerDataForVisiblePosition(TextMarkerData& textMarkerD
}
// find or create an accessibility object for this node
AXObjectCache* cache = domNode->document()->axObjectCache();
AXObjectCache* cache = domNode->document().axObjectCache();
RefPtr<AccessibilityObject> obj = cache->getOrCreate(domNode);
textMarkerData.axID = obj.get()->axObjectID();
......@@ -955,7 +955,7 @@ void AXObjectCache::clearTextMarkerNodesInUse(Document* document)
// Check each node to see if it's inside the document being deleted.
HashSet<Node*> nodesToDelete;
for (; it != end; ++it) {
if ((*it)->document() == document)
if (&(*it)->document() == document)
nodesToDelete.add(*it);
}
......
......@@ -62,7 +62,7 @@ AccessibilityObject* AccessibilityImageMapLink::parentObject() const
if (!m_mapElement.get() || !m_mapElement->renderer())
return 0;
return m_mapElement->document()->axObjectCache()->getOrCreate(m_mapElement->renderer());
return m_mapElement->document().axObjectCache()->getOrCreate(m_mapElement->renderer());
}
AccessibilityRole AccessibilityImageMapLink::roleValue() const
......
......@@ -178,7 +178,7 @@ AccessibilityObject* AccessibilityListBoxOption::parentObject() const
if (!parentNode)
return 0;
return m_optionElement->document()->axObjectCache()->getOrCreate(parentNode);
return m_optionElement->document().axObjectCache()->getOrCreate(parentNode);
}
void AccessibilityListBoxOption::setSelected(bool selected)
......
......@@ -262,7 +262,7 @@ Document* AccessibilityNodeObject::document() const
{
if (!node())
return 0;
return node()->document();
return &node()->document();
}
AccessibilityRole AccessibilityNodeObject::determineAccessibilityRole()
......
......@@ -315,11 +315,7 @@ bool AccessibilityObject::hasMisspelling() const
if (!node())
return false;
Document* document = node()->document();
if (!document)
return false;
Frame* frame = document->frame();
Frame* frame = node()->document().frame();
if (!frame)
return false;
......@@ -375,11 +371,7 @@ AccessibilityObject* AccessibilityObject::firstAccessibleObjectFromNode(const No
if (!node)
return 0;
Document* document = node->document();
if (!document)
return 0;
AXObjectCache* cache = document->axObjectCache();
AXObjectCache* cache = node->document().axObjectCache();
AccessibilityObject* accessibleObject = cache->getOrCreate(node->renderer());
while (accessibleObject && accessibleObject->accessibilityIsIgnored()) {
......@@ -577,7 +569,7 @@ bool AccessibilityObject::press() const
Element* actionElem = actionElement();
if (!actionElem)
return false;
if (Frame* f = actionElem->document()->frame())
if (Frame* f = actionElem->document().frame())
f->loader().resetMultipleFormSubmissionProtection();
UserGestureIndicator gestureIndicator(DefinitelyProcessingUserGesture);
......
......@@ -647,9 +647,9 @@ String AccessibilityRenderObject::textUnderElement(AccessibilityTextUnderElement
// If possible, use a text iterator to get the text, so that whitespace
// is handled consistently.
if (Node* node = this->node()) {
if (Frame* frame = node->document()->frame()) {
if (Frame* frame = node->document().frame()) {
// catch stale WebCoreAXObject (see <rdar://problem/3960196>)
if (frame->document() != node->document())
if (frame->document() != &node->document())
return String();
return plainText(rangeOfContents(node).get(), textIteratorBehaviorForTextRange());
......@@ -932,7 +932,7 @@ void AccessibilityRenderObject::addRadioButtonGroupMembers(AccessibilityChildren
linkedUIElements.append(object);
}
} else {
RefPtr<NodeList> list = node->document()->getElementsByTagName("input");
RefPtr<NodeList> list = node->document().getElementsByTagName("input");
unsigned len = list->length();
for (unsigned i = 0; i < len; ++i) {
if (isHTMLInputElement(list->item(i))) {
......
......@@ -185,8 +185,8 @@ void AXObjectCache::nodeTextChangePlatformNotification(AccessibilityObject* obje
return;
// Ensure document's layout is up-to-date before using TextIterator.
Document* document = node->document();
document->updateLayout();
Document& document = node->document();
document.updateLayout();
// Select the right signal to be emitted
CString detail;
......@@ -211,7 +211,7 @@ void AXObjectCache::nodeTextChangePlatformNotification(AccessibilityObject* obje
// Consider previous text objects that might be present for
// the current accessibility object to ensure we emit the
// right offset (e.g. multiline text areas).
RefPtr<Range> range = Range::create(document, node->parentNode(), 0, node, 0);
RefPtr<Range> range = Range::create(&document, node->parentNode(), 0, node, 0);
offsetToEmit = offset + TextIterator::rangeLength(range.get());
}
......
......@@ -247,7 +247,7 @@ static gint webkitAccessibleHyperlinkGetStartIndex(AtkHyperlink* link)
if (!parentNode)
return 0;
RefPtr<Range> range = Range::create(node->document(), firstPositionInOrBeforeNode(parentNode), firstPositionInOrBeforeNode(node));
RefPtr<Range> range = Range::create(&node->document(), firstPositionInOrBeforeNode(parentNode), firstPositionInOrBeforeNode(node));
return getRangeLengthForObject(coreObject, range.get());
}
......@@ -271,7 +271,7 @@ static gint webkitAccessibleHyperlinkGetEndIndex(AtkHyperlink* link)
if (!parentNode)
return 0;
RefPtr<Range> range = Range::create(node->document(), firstPositionInOrBeforeNode(parentNode), lastPositionInOrAfterNode(node));
RefPtr<Range> range = Range::create(&node->document(), firstPositionInOrBeforeNode(parentNode), lastPositionInOrAfterNode(node));
return getRangeLengthForObject(coreObject, range.get());
}
......
......@@ -554,12 +554,12 @@ static void getSelectionOffsetsForObject(AccessibilityObject* coreObject, Visibl
// Calculate position of the selected range inside the object.
Position parentFirstPosition = firstPositionInOrBeforeNode(node);
RefPtr<Range> rangeInParent = Range::create(node->document(), parentFirstPosition, nodeRangeStart);
RefPtr<Range> rangeInParent = Range::create(&node->document(), parentFirstPosition, nodeRangeStart);
// Set values for start offsets and calculate initial range length.
// These values might be adjusted later to cover special cases.
startOffset = webCoreOffsetToAtkOffset(coreObject, TextIterator::rangeLength(rangeInParent.get(), true));
RefPtr<Range> nodeRange = Range::create(node->document(), nodeRangeStart, nodeRangeEnd);
RefPtr<Range> nodeRange = Range::create(&node->document(), nodeRangeStart, nodeRangeEnd);
int rangeLength = TextIterator::rangeLength(nodeRange.get(), true);
// Special cases that are only relevant when working with *_END boundaries.
......
......@@ -1647,7 +1647,7 @@ static void AXAttributedStringAppendText(NSMutableAttributedString* attrString,
if (range->endContainer() != scope && !range->endContainer()->isDescendantOf(scope))
return NSMakeRange(NSNotFound, 0);
RefPtr<Range> testRange = Range::create(scope->document(), scope, 0, range->startContainer(), range->startOffset());
RefPtr<Range> testRange = Range::create(&scope->document(), scope, 0, range->startContainer(), range->startOffset());
ASSERT(testRange->startContainer() == scope);
int startPosition = TextIterator::rangeLength(testRange.get());
......
......@@ -717,9 +717,9 @@ static void AXAttributeStringSetBlockquoteLevel(NSMutableAttributedString* attrS
static void AXAttributeStringSetSpelling(NSMutableAttributedString* attrString, Node* node, const UChar* chars, int charLength, NSRange range)
{
if (unifiedTextCheckerEnabled(node->document()->frame())) {
if (unifiedTextCheckerEnabled(node->document().frame())) {
// Check the spelling directly since document->markersForNode() does not store the misspelled marking when the cursor is in a word.
TextCheckerClient* checker = node->document()->frame()->editor().textChecker();
TextCheckerClient* checker = node->document().frame()->editor().textChecker();
// checkTextOfParagraph is the only spelling/grammar checker implemented in WK1 and WK2
Vector<TextCheckingResult> results;
......@@ -740,7 +740,7 @@ static void AXAttributeStringSetSpelling(NSMutableAttributedString* attrString,
int currentPosition = 0;
while (charLength > 0) {
const UChar* charData = chars + currentPosition;
TextCheckerClient* checker = node->document()->frame()->editor().textChecker();
TextCheckerClient* checker = node->document().frame()->editor().textChecker();
int misspellingLocation = -1;
int misspellingLength = 0;
......
......@@ -171,7 +171,7 @@ void AXObjectCache::handleFocusedUIElementChanged(Node*, Node* newFocusedNode)
if (!newFocusedNode)
return;
Page* page = newFocusedNode->document()->page();
Page* page = newFocusedNode->document().page();
if (!page || !page->chrome().platformPageClient())
return;
......
......@@ -73,7 +73,7 @@ bool BindingSecurity::shouldAllowAccessToFrame(BindingState* state, Frame* targe
bool BindingSecurity::shouldAllowAccessToNode(BindingState* state, Node* target)
{
return target && canAccessDocument(state, target->document());
return target && canAccessDocument(state, &target->document());
}
bool BindingSecurity::allowSettingFrameSrcToJavascriptUrl(BindingState* state, HTMLFrameElementBase* frame, const String& value)
......
......@@ -45,10 +45,7 @@ static WebCore::Frame* getFrameFromHandle(void* objectHandle)
WebCore::Node* node = static_cast<WebCore::Node*>(objectHandle);
if (!node->inDocument())
return 0;
WebCore::Document* document = node->document();
if (!document)
return 0;
return document->frame();
return node->document().frame();
}
void DOMObjectCache::forget(void* objectHandle)
......
......@@ -84,14 +84,14 @@ JSValue JSHTMLCanvasElement::getContext(ExecState* exec)
if (!context)
return jsNull();
JSValue jsValue = toJS(exec, globalObject(), WTF::getPtr(context));
if (InspectorInstrumentation::canvasAgentEnabled(canvas->document())) {
if (InspectorInstrumentation::canvasAgentEnabled(&canvas->document())) {
ScriptObject contextObject(exec, jsValue.getObject());
ScriptObject wrapped;
if (context->is2d())
wrapped = InspectorInstrumentation::wrapCanvas2DRenderingContextForInstrumentation(canvas->document(), contextObject);
wrapped = InspectorInstrumentation::wrapCanvas2DRenderingContextForInstrumentation(&canvas->document(), contextObject);
#if ENABLE(WEBGL)
else if (context->is3d())
wrapped = InspectorInstrumentation::wrapWebGLRenderingContextForInstrumentation(canvas->document(), contextObject);
wrapped = InspectorInstrumentation::wrapWebGLRenderingContextForInstrumentation(&canvas->document(), contextObject);
#endif
if (!wrapped.hasNoValue())
return wrapped.jsValue();
......
......@@ -39,7 +39,7 @@ JSScope* JSHTMLElement::pushEventHandlerScope(ExecState* exec, JSScope* scope) c
HTMLElement* element = impl();
// The document is put on first, fall back to searching it only after the element and form.
scope = JSWithScope::create(exec, asObject(toJS(exec, globalObject(), element->document())), scope);
scope = JSWithScope::create(exec, asObject(toJS(exec, globalObject(), &element->document())), scope);
// The form is next, searched before the document, but after the element itself.
if (HTMLFormElement* form = element->form())
......
......@@ -228,17 +228,13 @@ JSValue JSInjectedScriptHost::getEventListeners(ExecState* exec)
Node* node = toNode(value);
if (!node)
return jsUndefined();
// This can only happen for orphan DocumentType nodes.
Document* document = node->document();
if (!node->document())
return jsUndefined();
Vector<EventListenerInfo> listenersArray;
impl()->getEventListenersImpl(node, listenersArray);
JSObject* result = constructEmptyObject(exec);
for (size_t i = 0; i < listenersArray.size(); ++i) {
JSArray* listeners = getJSListenerFunctions(exec, document, listenersArray[i]);
JSArray* listeners = getJSListenerFunctions(exec, &node->document(), listenersArray[i]);
if (!listeners->length())
continue;
AtomicString eventType = listenersArray[i].eventType;
......
......@@ -276,7 +276,7 @@ JSValue toJSNewlyCreated(ExecState* exec, JSDOMGlobalObject* globalObject, Node*
void willCreatePossiblyOrphanedTreeByRemovalSlowCase(Node* root)
{
ScriptState* scriptState = mainWorldScriptState(root->document()->frame());
ScriptState* scriptState = mainWorldScriptState(root->document().frame());
if (!scriptState)
return;
......
......@@ -66,7 +66,7 @@ inline void willCreatePossiblyOrphanedTreeByRemoval(Node* root)
inline void* root(Node* node)
{
if (node->inDocument())
return node->document();
return &node->document();
while (node->parentOrShadowHostNode())
node = node->parentOrShadowHostNode();
......
......@@ -63,13 +63,13 @@ PassRefPtr<JSLazyEventListener> createAttributeEventListener(Node* node, const Q
String sourceURL;
// FIXME: We should be able to provide accurate source information for frameless documents, too (e.g. for importing nodes from XMLHttpRequest.responseXML).
if (Frame* frame = node->document()->frame()) {
if (Frame* frame = node->document().frame()) {
ScriptController& scriptController = frame->script();
if (!scriptController.canExecuteScripts(AboutToExecuteScript))
return 0;
position = scriptController.eventHandlerPosition();
sourceURL = node->document()->url().string();
sourceURL = node->document().url().string();
}
return JSLazyEventListener::create(name.localName().string(), eventParameterName(node->isSVGElement()), value, node, sourceURL, position, 0, mainThreadNormalWorld());
......
......@@ -76,10 +76,7 @@ ScriptState* scriptStateFromNode(DOMWrapperWorld* world, Node* node)
{
if (!node)
return 0;
Document* document = node->document();
if (!document)
return 0;
Frame* frame = document->frame();
Frame* frame = node->document().frame();
if (!frame)
return 0;
if (!frame->script().canExecuteScripts(NotAboutToExecuteScript))
......
......@@ -195,7 +195,7 @@ static NSArray *kit(const Vector<IntRect>& rects)
- (JSC::Bindings::RootObject*)_rootObject
{
WebCore::Frame* frame = core(self)->document()->frame();
WebCore::Frame* frame = core(self)->document().frame();
if (!frame)
return 0;
return frame->script().bindingRootObject();
......@@ -261,7 +261,7 @@ id <DOMEventTarget> kit(WebCore::EventTarget* eventTarget)
- (NSRect)boundingBox
{
// FIXME: Could we move this function to WebCore::Node and autogenerate?
core(self)->document()->updateLayoutIgnorePendingStylesheets();
core(self)->document().updateLayoutIgnorePendingStylesheets();
WebCore::RenderObject* renderer = core(self)->renderer();
if (!renderer)
return NSZeroRect;
......@@ -281,7 +281,7 @@ id <DOMEventTarget> kit(WebCore::EventTarget* eventTarget)
{
// FIXME: Could we move this function to WebCore::Node and autogenerate?
WebCore::Node* node = core(self);
WebCore::Frame* frame = node->document()->frame();
WebCore::Frame* frame = node->document().frame();
if (!frame)
return nil;
return frame->nodeImage(node).get();
......@@ -289,7 +289,7 @@ id <DOMEventTarget> kit(WebCore::EventTarget* eventTarget)
- (NSArray *)textRects
{
core(self)->document()->updateLayoutIgnorePendingStylesheets();
core(self)->document().updateLayoutIgnorePendingStylesheets();
if (!core(self)->renderer())
return nil;
Vector<WebCore::IntRect> rects;
......@@ -398,14 +398,14 @@ id <DOMEventTarget> kit(WebCore::EventTarget* eventTarget)
ASSERT(name);
WebCore::Element* element = core(self);
ASSERT(element);
return element->document()->completeURL(stripLeadingAndTrailingHTMLSpaces(element->getAttribute(name)));
return element->document().completeURL(stripLeadingAndTrailingHTMLSpaces(element->getAttribute(name)));
}
- (BOOL)isFocused
{
// FIXME: Could we move this function to WebCore::Element and autogenerate?
WebCore::Element* element = core(self);
return element->document()->focusedElement() == element;
return element->document().focusedElement() == element;
}
@end
......
......@@ -94,10 +94,10 @@
{
// Returns bounding rect of text field, in screen coordinates.
NSRect result = [self boundingBox];
if (!core(self)->document()->view())
if (!core(self)->document().view())
return result;
NSView* view = core(self)->document()->view()->documentView();
NSView* view = core(self)->document().view()->documentView();
result = [view convertRect:result toView:nil];
result.origin = [[view window] convertBaseToScreen:result.origin];
return result;
......
......@@ -112,9 +112,7 @@ void removeDOMWrapper(DOMObjectInternal* impl)
WebCore::Node *nodeImpl = core(n);
// Dig up Interpreter and ExecState.
WebCore::Frame *frame = 0;
if (WebCore::Document* document = nodeImpl->document())
frame = document->frame();
WebCore::Frame *frame = nodeImpl->document().frame();
if (!frame)
return;
......
......@@ -80,7 +80,7 @@ CSSCursorImageValue::~CSSCursorImageValue()
for (; it != end; ++it) {
SVGElement* referencedElement = *it;
referencedElement->cursorImageValueRemoved();
if (SVGCursorElement* cursorElement = resourceReferencedByCursorElement(url, referencedElement->document()))
if (SVGCursorElement* cursorElement = resourceReferencedByCursorElement(url, &referencedElement->document()))
cursorElement->removeClient(referencedElement);
}
#endif
......@@ -111,7 +111,7 @@ bool CSSCursorImageValue::updateIfSVGCursorIsUsed(Element* element)
return false;
String url = static_cast<CSSImageValue*>(m_imageValue.get())->url();
if (SVGCursorElement* cursorElement = resourceReferencedByCursorElement(url, element->document())) {
if (SVGCursorElement* cursorElement = resourceReferencedByCursorElement(url, &element->document())) {
// FIXME: This will override hot spot specified in CSS, which is probably incorrect.
SVGLengthContext lengthContext(0);
m_hasHotSpot = true;
......@@ -121,7 +121,7 @@ bool CSSCursorImageValue::updateIfSVGCursorIsUsed(Element* element)
float y = roundf(cursorElement->y().value(lengthContext));
m_hotSpot.setY(static_cast<int>(y));
if (cachedImageURL() != element->document()->completeURL(cursorElement->href()))
if (cachedImageURL() != element->document().completeURL(cursorElement->href()))
clearCachedImage();
SVGElement* svgElement = toSVGElement(element);
......
......@@ -184,7 +184,7 @@ void CSSDefaultStyleSheets::ensureDefaultStyleSheetsForElement(Element* element,
#if ENABLE(VIDEO)
if (!mediaControlsStyleSheet && (element->hasTag