Chromium Code Reviews| Index: third_party/WebKit/Source/core/dom/Document.cpp |
| diff --git a/third_party/WebKit/Source/core/dom/Document.cpp b/third_party/WebKit/Source/core/dom/Document.cpp |
| index c8e19ff67dd7b76877a042ace84c8aa926ef0f41..9c9f2a922638e3786f2de545b13bd9030688dc60 100644 |
| --- a/third_party/WebKit/Source/core/dom/Document.cpp |
| +++ b/third_party/WebKit/Source/core/dom/Document.cpp |
| @@ -598,7 +598,14 @@ void Document::setRootScroller(Element* newScroller, ExceptionState& exceptionSt |
| { |
| DCHECK(newScroller); |
| - if (ownerElement()) { |
| + if (!frame()) { |
|
dcheng
2016/05/07 06:09:07
Having to add an extra case here feels awkward to
bokan
2016/05/09 20:43:58
Done.
|
| + exceptionState.throwDOMException( |
| + InvalidStateError, |
| + "Root scroller cannot be set on a document not attached to a window."); |
| + return; |
| + } |
| + |
| + if (!frame()->isMainFrame()) { |
| exceptionState.throwDOMException( |
| WrongDocumentError, |
| "Root scroller cannot be set on a document within a frame."); |
| @@ -628,7 +635,11 @@ void Document::setRootScroller(Element* newScroller, ExceptionState& exceptionSt |
| Element* Document::rootScroller() |
| { |
| - if (ownerElement()) |
| + if (!frame()) |
|
dcheng
2016/05/07 06:09:07
Is it necessary to distinguish this case? We previ
bokan
2016/05/09 20:43:58
Done.
|
| + return nullptr; |
| + |
| + // TODO(bokan): Should child frames return the documentElement or nullptr? |
| + if (!isInMainFrame()) |
| return documentElement(); |
| FrameHost* host = frameHost(); |
| @@ -643,6 +654,11 @@ Element* Document::rootScroller() |
| return rootScroller->get(); |
| } |
| +bool Document::isInMainFrame() const |
| +{ |
| + return frame() && frame()->isMainFrame(); |
| +} |
| + |
| AtomicString Document::convertLocalName(const AtomicString& name) |
| { |
| return isHTMLDocument() ? name.lower() : name; |
| @@ -1902,7 +1918,7 @@ void Document::updateLayout() |
| return; |
| } |
| - if (HTMLFrameOwnerElement* owner = ownerElement()) |
| + if (HTMLFrameOwnerElement* owner = localOwnerElement()) |
| owner->document().updateLayout(); |
| updateLayoutTree(); |
| @@ -1940,9 +1956,9 @@ void Document::layoutUpdated() |
| m_documentTiming.markFirstLayout(); |
| } |
| - if (!ownerElement() && frameHost()) { |
| - if (RootScroller* rootScroller = frameHost()->rootScroller()) |
| - rootScroller->didUpdateTopDocumentLayout(); |
| + if (isInMainFrame() && frameHost()) { |
| + DCHECK(frameHost()->rootScroller()); |
| + frameHost()->rootScroller()->didUpdateTopDocumentLayout(); |
| } |
| } |
| @@ -2669,7 +2685,7 @@ void Document::implicitClose() |
| // We used to force a synchronous display and flush here. This really isn't |
| // necessary and can in fact be actively harmful if pages are loading at a rate of > 60fps |
| // (if your platform is syncing flushes and limiting them to 60fps). |
| - if (!ownerElement() || (ownerElement()->layoutObject() && !ownerElement()->layoutObject()->needsLayout())) { |
| + if (!localOwnerElement() || (localOwnerElement()->layoutObject() && !localOwnerElement()->layoutObject()->needsLayout())) { |
| updateLayoutTree(); |
| // Always do a layout after loading if needed. |
| @@ -4052,7 +4068,7 @@ void Document::addListenerTypeIfNeeded(const AtomicString& eventType) |
| } |
| } |
| -HTMLFrameOwnerElement* Document::ownerElement() const |
| +HTMLFrameOwnerElement* Document::localOwnerElement() const |
| { |
| if (!frame()) |
| return 0; |
| @@ -4062,9 +4078,10 @@ HTMLFrameOwnerElement* Document::ownerElement() const |
| bool Document::isInInvisibleSubframe() const |
| { |
| - if (!ownerElement()) |
| - return false; // this is the root element |
| + if (!localOwnerElement()) |
| + return false; // this is a local root element |
| + // TODO(bokan): This looks like it doesn't work in OOPIF. |
| DCHECK(frame()); |
| return !frame()->ownerLayoutObject(); |
| } |
| @@ -4647,7 +4664,7 @@ Document& Document::topDocument() const |
| // FIXME: Not clear what topDocument() should do in the OOPI case--should it return the topmost |
| // available Document, or something else? |
| Document* doc = const_cast<Document*>(this); |
| - for (HTMLFrameOwnerElement* element = doc->ownerElement(); element; element = doc->ownerElement()) |
| + for (HTMLFrameOwnerElement* element = doc->localOwnerElement(); element; element = doc->localOwnerElement()) |
| doc = &element->document(); |
| DCHECK(doc); |
| @@ -5553,7 +5570,7 @@ void Document::updateHoverActiveState(const HitTestRequest& request, Element* in |
| Element* innerElementInDocument = innerElement; |
| while (innerElementInDocument && innerElementInDocument->document() != this) { |
| innerElementInDocument->document().updateHoverActiveState(request, innerElementInDocument); |
| - innerElementInDocument = innerElementInDocument->document().ownerElement(); |
| + innerElementInDocument = innerElementInDocument->document().localOwnerElement(); |
| } |
| updateDistribution(); |