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

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: Remove duplication in const overload 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()) {
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.
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())
dcheng 2016/05/07 06:09:07 Is it necessary to distinguish this case? We previ
bokan 2016/05/09 20:43:58 Done.
639 return nullptr;
640
641 // TODO(bokan): Should child frames return the documentElement or nullptr?
642 if (!isInMainFrame())
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();
642 653
643 return rootScroller->get(); 654 return rootScroller->get();
644 } 655 }
645 656
657 bool Document::isInMainFrame() const
658 {
659 return frame() && frame()->isMainFrame();
660 }
661
646 AtomicString Document::convertLocalName(const AtomicString& name) 662 AtomicString Document::convertLocalName(const AtomicString& name)
647 { 663 {
648 return isHTMLDocument() ? name.lower() : name; 664 return isHTMLDocument() ? name.lower() : name;
649 } 665 }
650 666
651 Element* Document::createElement(const AtomicString& name, ExceptionState& excep tionState) 667 Element* Document::createElement(const AtomicString& name, ExceptionState& excep tionState)
652 { 668 {
653 if (!isValidName(name)) { 669 if (!isValidName(name)) {
654 exceptionState.throwDOMException(InvalidCharacterError, "The tag name pr ovided ('" + name + "') is not a valid name."); 670 exceptionState.throwDOMException(InvalidCharacterError, "The tag name pr ovided ('" + name + "') is not a valid name.");
655 return nullptr; 671 return nullptr;
(...skipping 1239 matching lines...) Expand 10 before | Expand all | Expand 10 after
1895 1911
1896 ScriptForbiddenScope forbidScript; 1912 ScriptForbiddenScope forbidScript;
1897 1913
1898 FrameView* frameView = view(); 1914 FrameView* frameView = view();
1899 if (frameView && frameView->isInPerformLayout()) { 1915 if (frameView && frameView->isInPerformLayout()) {
1900 // View layout should not be re-entrant. 1916 // View layout should not be re-entrant.
1901 ASSERT_NOT_REACHED(); 1917 ASSERT_NOT_REACHED();
1902 return; 1918 return;
1903 } 1919 }
1904 1920
1905 if (HTMLFrameOwnerElement* owner = ownerElement()) 1921 if (HTMLFrameOwnerElement* owner = localOwnerElement())
1906 owner->document().updateLayout(); 1922 owner->document().updateLayout();
1907 1923
1908 updateLayoutTree(); 1924 updateLayoutTree();
1909 1925
1910 if (!isActive()) 1926 if (!isActive())
1911 return; 1927 return;
1912 1928
1913 if (frameView->needsLayout()) 1929 if (frameView->needsLayout())
1914 frameView->layout(); 1930 frameView->layout();
1915 1931
(...skipping 17 matching lines...) Expand all
1933 // first real or 'paintable' layout. 1949 // first real or 'paintable' layout.
1934 // TODO(esprehn): This doesn't really make sense, why not track the first 1950 // 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 1951 // 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 1952 // of layout thrashing even though that layout might not be followed by
1937 // a paint for many seconds. 1953 // a paint for many seconds.
1938 if (isRenderingReady() && body() && !styleEngine().hasPendingSheets()) { 1954 if (isRenderingReady() && body() && !styleEngine().hasPendingSheets()) {
1939 if (!m_documentTiming.firstLayout()) 1955 if (!m_documentTiming.firstLayout())
1940 m_documentTiming.markFirstLayout(); 1956 m_documentTiming.markFirstLayout();
1941 } 1957 }
1942 1958
1943 if (!ownerElement() && frameHost()) { 1959 if (isInMainFrame() && frameHost()) {
1944 if (RootScroller* rootScroller = frameHost()->rootScroller()) 1960 DCHECK(frameHost()->rootScroller());
1945 rootScroller->didUpdateTopDocumentLayout(); 1961 frameHost()->rootScroller()->didUpdateTopDocumentLayout();
1946 } 1962 }
1947 } 1963 }
1948 1964
1949 void Document::setNeedsFocusedElementCheck() 1965 void Document::setNeedsFocusedElementCheck()
1950 { 1966 {
1951 setNeedsStyleRecalc(LocalStyleChange, StyleChangeReasonForTracing::createWit hExtraData(StyleChangeReason::PseudoClass, StyleChangeExtraData::Focus)); 1967 setNeedsStyleRecalc(LocalStyleChange, StyleChangeReasonForTracing::createWit hExtraData(StyleChangeReason::PseudoClass, StyleChangeExtraData::Focus));
1952 } 1968 }
1953 1969
1954 void Document::clearFocusedElementSoon() 1970 void Document::clearFocusedElementSoon()
1955 { 1971 {
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after
2662 if (frame()->navigationScheduler().locationChangePending() && elapsedTime() < cLayoutScheduleThreshold) { 2678 if (frame()->navigationScheduler().locationChangePending() && elapsedTime() < cLayoutScheduleThreshold) {
2663 // Just bail out. Before or during the onload we were shifted to another page. 2679 // 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. 2680 // The old i-Bench suite does this. When this happens don't bother paint ing or laying out.
2665 m_loadEventProgress = LoadEventCompleted; 2681 m_loadEventProgress = LoadEventCompleted;
2666 return; 2682 return;
2667 } 2683 }
2668 2684
2669 // We used to force a synchronous display and flush here. This really isn't 2685 // 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 2686 // 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). 2687 // (if your platform is syncing flushes and limiting them to 60fps).
2672 if (!ownerElement() || (ownerElement()->layoutObject() && !ownerElement()->l ayoutObject()->needsLayout())) { 2688 if (!localOwnerElement() || (localOwnerElement()->layoutObject() && !localOw nerElement()->layoutObject()->needsLayout())) {
2673 updateLayoutTree(); 2689 updateLayoutTree();
2674 2690
2675 // Always do a layout after loading if needed. 2691 // Always do a layout after loading if needed.
2676 if (view() && layoutView() && (!layoutView()->firstChild() || layoutView ()->needsLayout())) 2692 if (view() && layoutView() && (!layoutView()->firstChild() || layoutView ()->needsLayout()))
2677 view()->layout(); 2693 view()->layout();
2678 } 2694 }
2679 2695
2680 m_loadEventProgress = LoadEventCompleted; 2696 m_loadEventProgress = LoadEventCompleted;
2681 2697
2682 if (frame() && layoutView() && settings()->accessibilityEnabled()) { 2698 if (frame() && layoutView() && settings()->accessibilityEnabled()) {
(...skipping 1362 matching lines...) Expand 10 before | Expand all | Expand 10 after
4045 // Need to re-evaluate time-to-effect-change for any running animati ons. 4061 // Need to re-evaluate time-to-effect-change for any running animati ons.
4046 view()->scheduleAnimation(); 4062 view()->scheduleAnimation();
4047 } 4063 }
4048 } else if (eventType == EventTypeNames::webkitTransitionEnd || eventType == EventTypeNames::transitionend) { 4064 } else if (eventType == EventTypeNames::webkitTransitionEnd || eventType == EventTypeNames::transitionend) {
4049 addListenerType(TRANSITIONEND_LISTENER); 4065 addListenerType(TRANSITIONEND_LISTENER);
4050 } else if (eventType == EventTypeNames::scroll) { 4066 } else if (eventType == EventTypeNames::scroll) {
4051 addListenerType(SCROLL_LISTENER); 4067 addListenerType(SCROLL_LISTENER);
4052 } 4068 }
4053 } 4069 }
4054 4070
4055 HTMLFrameOwnerElement* Document::ownerElement() const 4071 HTMLFrameOwnerElement* Document::localOwnerElement() const
4056 { 4072 {
4057 if (!frame()) 4073 if (!frame())
4058 return 0; 4074 return 0;
4059 // FIXME: This probably breaks the attempts to layout after a load is finish ed in implicitClose(), and probably tons of other things... 4075 // FIXME: This probably breaks the attempts to layout after a load is finish ed in implicitClose(), and probably tons of other things...
4060 return frame()->deprecatedLocalOwner(); 4076 return frame()->deprecatedLocalOwner();
4061 } 4077 }
4062 4078
4063 bool Document::isInInvisibleSubframe() const 4079 bool Document::isInInvisibleSubframe() const
4064 { 4080 {
4065 if (!ownerElement()) 4081 if (!localOwnerElement())
4066 return false; // this is the root element 4082 return false; // this is a local root element
4067 4083
4084 // TODO(bokan): This looks like it doesn't work in OOPIF.
4068 DCHECK(frame()); 4085 DCHECK(frame());
4069 return !frame()->ownerLayoutObject(); 4086 return !frame()->ownerLayoutObject();
4070 } 4087 }
4071 4088
4072 String Document::cookie(ExceptionState& exceptionState) const 4089 String Document::cookie(ExceptionState& exceptionState) const
4073 { 4090 {
4074 if (settings() && !settings()->cookieEnabled()) 4091 if (settings() && !settings()->cookieEnabled())
4075 return String(); 4092 return String();
4076 4093
4077 // FIXME: The HTML5 DOM spec states that this attribute can raise an 4094 // FIXME: The HTML5 DOM spec states that this attribute can raise an
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after
4640 if (!parent || !parent->isLocalFrame()) 4657 if (!parent || !parent->isLocalFrame())
4641 return 0; 4658 return 0;
4642 return toLocalFrame(parent)->document(); 4659 return toLocalFrame(parent)->document();
4643 } 4660 }
4644 4661
4645 Document& Document::topDocument() const 4662 Document& Document::topDocument() const
4646 { 4663 {
4647 // FIXME: Not clear what topDocument() should do in the OOPI case--should it return the topmost 4664 // FIXME: Not clear what topDocument() should do in the OOPI case--should it return the topmost
4648 // available Document, or something else? 4665 // available Document, or something else?
4649 Document* doc = const_cast<Document*>(this); 4666 Document* doc = const_cast<Document*>(this);
4650 for (HTMLFrameOwnerElement* element = doc->ownerElement(); element; element = doc->ownerElement()) 4667 for (HTMLFrameOwnerElement* element = doc->localOwnerElement(); element; ele ment = doc->localOwnerElement())
4651 doc = &element->document(); 4668 doc = &element->document();
4652 4669
4653 DCHECK(doc); 4670 DCHECK(doc);
4654 return *doc; 4671 return *doc;
4655 } 4672 }
4656 4673
4657 Document* Document::contextDocument() 4674 Document* Document::contextDocument()
4658 { 4675 {
4659 if (m_contextDocument) 4676 if (m_contextDocument)
4660 return m_contextDocument; 4677 return m_contextDocument;
(...skipping 885 matching lines...) Expand 10 before | Expand all | Expand 10 after
5546 void Document::updateHoverActiveState(const HitTestRequest& request, Element* in nerElement) 5563 void Document::updateHoverActiveState(const HitTestRequest& request, Element* in nerElement)
5547 { 5564 {
5548 DCHECK(!request.readOnly()); 5565 DCHECK(!request.readOnly());
5549 5566
5550 if (request.active() && m_frame) 5567 if (request.active() && m_frame)
5551 m_frame->eventHandler().notifyElementActivated(); 5568 m_frame->eventHandler().notifyElementActivated();
5552 5569
5553 Element* innerElementInDocument = innerElement; 5570 Element* innerElementInDocument = innerElement;
5554 while (innerElementInDocument && innerElementInDocument->document() != this) { 5571 while (innerElementInDocument && innerElementInDocument->document() != this) {
5555 innerElementInDocument->document().updateHoverActiveState(request, inner ElementInDocument); 5572 innerElementInDocument->document().updateHoverActiveState(request, inner ElementInDocument);
5556 innerElementInDocument = innerElementInDocument->document().ownerElement (); 5573 innerElementInDocument = innerElementInDocument->document().localOwnerEl ement();
5557 } 5574 }
5558 5575
5559 updateDistribution(); 5576 updateDistribution();
5560 Element* oldActiveElement = activeHoverElement(); 5577 Element* oldActiveElement = activeHoverElement();
5561 if (oldActiveElement && !request.active()) { 5578 if (oldActiveElement && !request.active()) {
5562 // The oldActiveElement layoutObject is null, dropped on :active by sett ing display: none, 5579 // The oldActiveElement layoutObject is null, dropped on :active by sett ing display: none,
5563 // for instance. We still need to clear the ActiveChain as the mouse is released. 5580 // for instance. We still need to clear the ActiveChain as the mouse is released.
5564 for (Node* node = oldActiveElement; node; node = FlatTreeTraversal::pare nt(*node)) { 5581 for (Node* node = oldActiveElement; node; node = FlatTreeTraversal::pare nt(*node)) {
5565 DCHECK(!node->isTextNode()); 5582 DCHECK(!node->isTextNode());
5566 node->setActive(false); 5583 node->setActive(false);
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
5979 #ifndef NDEBUG 5996 #ifndef NDEBUG
5980 using namespace blink; 5997 using namespace blink;
5981 void showLiveDocumentInstances() 5998 void showLiveDocumentInstances()
5982 { 5999 {
5983 Document::WeakDocumentSet& set = Document::liveDocumentSet(); 6000 Document::WeakDocumentSet& set = Document::liveDocumentSet();
5984 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); 6001 fprintf(stderr, "There are %u documents currently alive:\n", set.size());
5985 for (Document* document : set) 6002 for (Document* document : set)
5986 fprintf(stderr, "- Document %p URL: %s\n", document, document->url().get String().utf8().data()); 6003 fprintf(stderr, "- Document %p URL: %s\n", document, document->url().get String().utf8().data());
5987 } 6004 }
5988 #endif 6005 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698