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

Side by Side Diff: third_party/WebKit/Source/core/dom/Document.cpp

Issue 1942623002: Rename Document::ownerElement to localOwner and fix main frame checks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) 5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org)
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r ights reserved. 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r ights reserved.
7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. 8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved.
9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) 9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved. 10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved.
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 // insert one), so we resume here too. That does mean XHTML documents make 591 // insert one), so we resume here too. That does mean XHTML documents make
592 // frames when there's only a <head>, but such documents are pretty rare. 592 // frames when there's only a <head>, but such documents are pretty rare.
593 if (m_documentElement && !isHTMLDocument()) 593 if (m_documentElement && !isHTMLDocument())
594 beginLifecycleUpdatesIfRenderingReady(); 594 beginLifecycleUpdatesIfRenderingReady();
595 } 595 }
596 596
597 void Document::setRootScroller(Element* newScroller, ExceptionState& exceptionSt ate) 597 void Document::setRootScroller(Element* newScroller, ExceptionState& exceptionSt ate)
598 { 598 {
599 DCHECK(newScroller); 599 DCHECK(newScroller);
600 600
601 if (ownerElement()) { 601 if (!frame()) {
602 exceptionState.throwDOMException(
603 InvalidStateError,
604 "Root scroller cannot be set on a document not attached to a window. ");
605 return;
606 }
607
608 if (!frame()->isMainFrame()) {
602 exceptionState.throwDOMException( 609 exceptionState.throwDOMException(
603 WrongDocumentError, 610 WrongDocumentError,
604 "Root scroller cannot be set on a document within a frame."); 611 "Root scroller cannot be set on a document within a frame.");
605 return; 612 return;
606 } 613 }
607 614
608 if (newScroller->document() != this) { 615 if (newScroller->document() != this) {
609 exceptionState.throwDOMException( 616 exceptionState.throwDOMException(
610 WrongDocumentError, 617 WrongDocumentError,
611 "Element isn't in this document."); 618 "Element isn't in this document.");
612 return; 619 return;
613 } 620 }
614 621
615 FrameHost* host = frameHost(); 622 FrameHost* host = frameHost();
616 if (!host) 623 if (!host)
617 return; 624 return;
618 625
619 RootScroller* rootScroller = host->rootScroller(); 626 RootScroller* rootScroller = host->rootScroller();
620 DCHECK(rootScroller); 627 DCHECK(rootScroller);
621 628
622 if (!rootScroller->set(*newScroller)) { 629 if (!rootScroller->set(*newScroller)) {
623 exceptionState.throwDOMException( 630 exceptionState.throwDOMException(
624 InvalidStateError, 631 InvalidStateError,
625 "Element cannot be set as root scroller. Must be block or iframe."); 632 "Element cannot be set as root scroller. Must be block or iframe.");
626 } 633 }
627 } 634 }
628 635
629 Element* Document::rootScroller() 636 Element* Document::rootScroller()
630 { 637 {
631 if (ownerElement()) 638 if (!frame())
639 return nullptr;
640
641 // TODO(bokan): Should child frames return the documentElement or nullptr?
642 if (!frame()->isMainFrame())
632 return documentElement(); 643 return documentElement();
633 644
634 FrameHost* host = frameHost(); 645 FrameHost* host = frameHost();
635 if (!host) 646 if (!host)
636 return nullptr; 647 return nullptr;
637 648
638 RootScroller* rootScroller = host->rootScroller(); 649 RootScroller* rootScroller = host->rootScroller();
639 DCHECK(rootScroller); 650 DCHECK(rootScroller);
640 651
641 updateLayoutIgnorePendingStylesheets(); 652 updateLayoutIgnorePendingStylesheets();
(...skipping 1253 matching lines...) Expand 10 before | Expand all | Expand 10 after
1895 1906
1896 ScriptForbiddenScope forbidScript; 1907 ScriptForbiddenScope forbidScript;
1897 1908
1898 FrameView* frameView = view(); 1909 FrameView* frameView = view();
1899 if (frameView && frameView->isInPerformLayout()) { 1910 if (frameView && frameView->isInPerformLayout()) {
1900 // View layout should not be re-entrant. 1911 // View layout should not be re-entrant.
1901 ASSERT_NOT_REACHED(); 1912 ASSERT_NOT_REACHED();
1902 return; 1913 return;
1903 } 1914 }
1904 1915
1905 if (HTMLFrameOwnerElement* owner = ownerElement()) 1916 if (HTMLFrameOwnerElement* owner = localOwnerElement())
1906 owner->document().updateLayout(); 1917 owner->document().updateLayout();
1907 1918
1908 updateLayoutTree(); 1919 updateLayoutTree();
1909 1920
1910 if (!isActive()) 1921 if (!isActive())
1911 return; 1922 return;
1912 1923
1913 if (frameView->needsLayout()) 1924 if (frameView->needsLayout())
1914 frameView->layout(); 1925 frameView->layout();
1915 1926
(...skipping 17 matching lines...) Expand all
1933 // first real or 'paintable' layout. 1944 // first real or 'paintable' layout.
1934 // TODO(esprehn): This doesn't really make sense, why not track the first 1945 // TODO(esprehn): This doesn't really make sense, why not track the first
1935 // beginFrame? This will catch the first layout in a page that does lots 1946 // beginFrame? This will catch the first layout in a page that does lots
1936 // of layout thrashing even though that layout might not be followed by 1947 // of layout thrashing even though that layout might not be followed by
1937 // a paint for many seconds. 1948 // a paint for many seconds.
1938 if (isRenderingReady() && body() && !styleEngine().hasPendingSheets()) { 1949 if (isRenderingReady() && body() && !styleEngine().hasPendingSheets()) {
1939 if (!m_documentTiming.firstLayout()) 1950 if (!m_documentTiming.firstLayout())
1940 m_documentTiming.markFirstLayout(); 1951 m_documentTiming.markFirstLayout();
1941 } 1952 }
1942 1953
1943 if (!ownerElement() && frameHost()) { 1954 if (!localOwnerElement() && frameHost()) {
1944 if (RootScroller* rootScroller = frameHost()->rootScroller()) 1955 if (RootScroller* rootScroller = frameHost()->rootScroller())
1945 rootScroller->didUpdateTopDocumentLayout(); 1956 rootScroller->didUpdateTopDocumentLayout();
1946 } 1957 }
1947 } 1958 }
1948 1959
1949 void Document::setNeedsFocusedElementCheck() 1960 void Document::setNeedsFocusedElementCheck()
1950 { 1961 {
1951 setNeedsStyleRecalc(LocalStyleChange, StyleChangeReasonForTracing::createWit hExtraData(StyleChangeReason::PseudoClass, StyleChangeExtraData::Focus)); 1962 setNeedsStyleRecalc(LocalStyleChange, StyleChangeReasonForTracing::createWit hExtraData(StyleChangeReason::PseudoClass, StyleChangeExtraData::Focus));
1952 } 1963 }
1953 1964
(...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after
2662 if (frame()->navigationScheduler().locationChangePending() && elapsedTime() < cLayoutScheduleThreshold) { 2673 if (frame()->navigationScheduler().locationChangePending() && elapsedTime() < cLayoutScheduleThreshold) {
2663 // Just bail out. Before or during the onload we were shifted to another page. 2674 // Just bail out. Before or during the onload we were shifted to another page.
2664 // The old i-Bench suite does this. When this happens don't bother paint ing or laying out. 2675 // The old i-Bench suite does this. When this happens don't bother paint ing or laying out.
2665 m_loadEventProgress = LoadEventCompleted; 2676 m_loadEventProgress = LoadEventCompleted;
2666 return; 2677 return;
2667 } 2678 }
2668 2679
2669 // We used to force a synchronous display and flush here. This really isn't 2680 // We used to force a synchronous display and flush here. This really isn't
2670 // necessary and can in fact be actively harmful if pages are loading at a r ate of > 60fps 2681 // necessary and can in fact be actively harmful if pages are loading at a r ate of > 60fps
2671 // (if your platform is syncing flushes and limiting them to 60fps). 2682 // (if your platform is syncing flushes and limiting them to 60fps).
2672 if (!ownerElement() || (ownerElement()->layoutObject() && !ownerElement()->l ayoutObject()->needsLayout())) { 2683 if (!localOwnerElement() || (localOwnerElement()->layoutObject() && !localOw nerElement()->layoutObject()->needsLayout())) {
2673 updateLayoutTree(); 2684 updateLayoutTree();
2674 2685
2675 // Always do a layout after loading if needed. 2686 // Always do a layout after loading if needed.
2676 if (view() && layoutView() && (!layoutView()->firstChild() || layoutView ()->needsLayout())) 2687 if (view() && layoutView() && (!layoutView()->firstChild() || layoutView ()->needsLayout()))
2677 view()->layout(); 2688 view()->layout();
2678 } 2689 }
2679 2690
2680 m_loadEventProgress = LoadEventCompleted; 2691 m_loadEventProgress = LoadEventCompleted;
2681 2692
2682 if (frame() && layoutView() && settings()->accessibilityEnabled()) { 2693 if (frame() && layoutView() && settings()->accessibilityEnabled()) {
(...skipping 1356 matching lines...) Expand 10 before | Expand all | Expand 10 after
4039 // Need to re-evaluate time-to-effect-change for any running animati ons. 4050 // Need to re-evaluate time-to-effect-change for any running animati ons.
4040 view()->scheduleAnimation(); 4051 view()->scheduleAnimation();
4041 } 4052 }
4042 } else if (eventType == EventTypeNames::webkitTransitionEnd || eventType == EventTypeNames::transitionend) { 4053 } else if (eventType == EventTypeNames::webkitTransitionEnd || eventType == EventTypeNames::transitionend) {
4043 addListenerType(TRANSITIONEND_LISTENER); 4054 addListenerType(TRANSITIONEND_LISTENER);
4044 } else if (eventType == EventTypeNames::scroll) { 4055 } else if (eventType == EventTypeNames::scroll) {
4045 addListenerType(SCROLL_LISTENER); 4056 addListenerType(SCROLL_LISTENER);
4046 } 4057 }
4047 } 4058 }
4048 4059
4049 HTMLFrameOwnerElement* Document::ownerElement() const 4060 HTMLFrameOwnerElement* Document::localOwnerElement() const
4050 { 4061 {
4051 if (!frame()) 4062 if (!frame())
4052 return 0; 4063 return 0;
4053 // FIXME: This probably breaks the attempts to layout after a load is finish ed in implicitClose(), and probably tons of other things... 4064 // FIXME: This probably breaks the attempts to layout after a load is finish ed in implicitClose(), and probably tons of other things...
4054 return frame()->deprecatedLocalOwner(); 4065 return frame()->deprecatedLocalOwner();
4055 } 4066 }
4056 4067
4057 bool Document::isInInvisibleSubframe() const 4068 bool Document::isInInvisibleSubframe() const
4058 { 4069 {
4059 if (!ownerElement()) 4070 if (!localOwnerElement())
4060 return false; // this is the root element 4071 return false; // this is the root element
4061 4072
4062 DCHECK(frame()); 4073 DCHECK(frame());
4063 return !frame()->ownerLayoutObject(); 4074 return !frame()->ownerLayoutObject();
4064 } 4075 }
4065 4076
4066 String Document::cookie(ExceptionState& exceptionState) const 4077 String Document::cookie(ExceptionState& exceptionState) const
4067 { 4078 {
4068 if (settings() && !settings()->cookieEnabled()) 4079 if (settings() && !settings()->cookieEnabled())
4069 return String(); 4080 return String();
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after
4634 if (!parent || !parent->isLocalFrame()) 4645 if (!parent || !parent->isLocalFrame())
4635 return 0; 4646 return 0;
4636 return toLocalFrame(parent)->document(); 4647 return toLocalFrame(parent)->document();
4637 } 4648 }
4638 4649
4639 Document& Document::topDocument() const 4650 Document& Document::topDocument() const
4640 { 4651 {
4641 // FIXME: Not clear what topDocument() should do in the OOPI case--should it return the topmost 4652 // FIXME: Not clear what topDocument() should do in the OOPI case--should it return the topmost
4642 // available Document, or something else? 4653 // available Document, or something else?
4643 Document* doc = const_cast<Document*>(this); 4654 Document* doc = const_cast<Document*>(this);
4644 for (HTMLFrameOwnerElement* element = doc->ownerElement(); element; element = doc->ownerElement()) 4655 for (HTMLFrameOwnerElement* element = doc->localOwnerElement(); element; ele ment = doc->localOwnerElement())
4645 doc = &element->document(); 4656 doc = &element->document();
4646 4657
4647 DCHECK(doc); 4658 DCHECK(doc);
4648 return *doc; 4659 return *doc;
4649 } 4660 }
4650 4661
4651 Document* Document::contextDocument() 4662 Document* Document::contextDocument()
4652 { 4663 {
4653 if (m_contextDocument) 4664 if (m_contextDocument)
4654 return m_contextDocument; 4665 return m_contextDocument;
(...skipping 885 matching lines...) Expand 10 before | Expand all | Expand 10 after
5540 void Document::updateHoverActiveState(const HitTestRequest& request, Element* in nerElement) 5551 void Document::updateHoverActiveState(const HitTestRequest& request, Element* in nerElement)
5541 { 5552 {
5542 DCHECK(!request.readOnly()); 5553 DCHECK(!request.readOnly());
5543 5554
5544 if (request.active() && m_frame) 5555 if (request.active() && m_frame)
5545 m_frame->eventHandler().notifyElementActivated(); 5556 m_frame->eventHandler().notifyElementActivated();
5546 5557
5547 Element* innerElementInDocument = innerElement; 5558 Element* innerElementInDocument = innerElement;
5548 while (innerElementInDocument && innerElementInDocument->document() != this) { 5559 while (innerElementInDocument && innerElementInDocument->document() != this) {
5549 innerElementInDocument->document().updateHoverActiveState(request, inner ElementInDocument); 5560 innerElementInDocument->document().updateHoverActiveState(request, inner ElementInDocument);
5550 innerElementInDocument = innerElementInDocument->document().ownerElement (); 5561 innerElementInDocument = innerElementInDocument->document().localOwnerEl ement();
5551 } 5562 }
5552 5563
5553 updateDistribution(); 5564 updateDistribution();
5554 Element* oldActiveElement = activeHoverElement(); 5565 Element* oldActiveElement = activeHoverElement();
5555 if (oldActiveElement && !request.active()) { 5566 if (oldActiveElement && !request.active()) {
5556 // The oldActiveElement layoutObject is null, dropped on :active by sett ing display: none, 5567 // The oldActiveElement layoutObject is null, dropped on :active by sett ing display: none,
5557 // for instance. We still need to clear the ActiveChain as the mouse is released. 5568 // for instance. We still need to clear the ActiveChain as the mouse is released.
5558 for (Node* node = oldActiveElement; node; node = FlatTreeTraversal::pare nt(*node)) { 5569 for (Node* node = oldActiveElement; node; node = FlatTreeTraversal::pare nt(*node)) {
5559 DCHECK(!node->isTextNode()); 5570 DCHECK(!node->isTextNode());
5560 node->setActive(false); 5571 node->setActive(false);
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
5973 #ifndef NDEBUG 5984 #ifndef NDEBUG
5974 using namespace blink; 5985 using namespace blink;
5975 void showLiveDocumentInstances() 5986 void showLiveDocumentInstances()
5976 { 5987 {
5977 Document::WeakDocumentSet& set = Document::liveDocumentSet(); 5988 Document::WeakDocumentSet& set = Document::liveDocumentSet();
5978 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); 5989 fprintf(stderr, "There are %u documents currently alive:\n", set.size());
5979 for (Document* document : set) 5990 for (Document* document : set)
5980 fprintf(stderr, "- Document %p URL: %s\n", document, document->url().get String().utf8().data()); 5991 fprintf(stderr, "- Document %p URL: %s\n", document, document->url().get String().utf8().data());
5981 } 5992 }
5982 #endif 5993 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698