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

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

Issue 1896793002: Rename (updateLayout/updateStyle).*.() to updateStyleAndLayout.*.() (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 620 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 if (ownerElement()) 631 if (ownerElement())
632 return documentElement(); 632 return documentElement();
633 633
634 FrameHost* host = frameHost(); 634 FrameHost* host = frameHost();
635 if (!host) 635 if (!host)
636 return nullptr; 636 return nullptr;
637 637
638 RootScroller* rootScroller = host->rootScroller(); 638 RootScroller* rootScroller = host->rootScroller();
639 DCHECK(rootScroller); 639 DCHECK(rootScroller);
640 640
641 updateLayoutIgnorePendingStylesheets(); 641 updateStyleAndLayoutIgnorePendingStylesheets();
642 642
643 return rootScroller->get(); 643 return rootScroller->get();
644 } 644 }
645 645
646 AtomicString Document::convertLocalName(const AtomicString& name) 646 AtomicString Document::convertLocalName(const AtomicString& name)
647 { 647 {
648 return isHTMLDocument() ? name.lower() : name; 648 return isHTMLDocument() ? name.lower() : name;
649 } 649 }
650 650
651 Element* Document::createElement(const AtomicString& name, ExceptionState& excep tionState) 651 Element* Document::createElement(const AtomicString& name, ExceptionState& excep tionState)
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
1151 return nullptr; 1151 return nullptr;
1152 1152
1153 Position rangeCompliantPosition = positionWithAffinity.position().parentAnch oredEquivalent(); 1153 Position rangeCompliantPosition = positionWithAffinity.position().parentAnch oredEquivalent();
1154 return Range::createAdjustedToTreeScope(*this, rangeCompliantPosition); 1154 return Range::createAdjustedToTreeScope(*this, rangeCompliantPosition);
1155 } 1155 }
1156 1156
1157 Element* Document::scrollingElement() 1157 Element* Document::scrollingElement()
1158 { 1158 {
1159 if (RuntimeEnabledFeatures::scrollTopLeftInteropEnabled()) { 1159 if (RuntimeEnabledFeatures::scrollTopLeftInteropEnabled()) {
1160 if (inQuirksMode()) { 1160 if (inQuirksMode()) {
1161 updateLayoutTree(); 1161 updateStyleAndLayoutTree();
1162 HTMLBodyElement* body = firstBodyElement(); 1162 HTMLBodyElement* body = firstBodyElement();
1163 if (body && body->layoutObject() && body->layoutObject()->hasOverflo wClip()) 1163 if (body && body->layoutObject() && body->layoutObject()->hasOverflo wClip())
1164 return nullptr; 1164 return nullptr;
1165 1165
1166 return body; 1166 return body;
1167 } 1167 }
1168 1168
1169 return documentElement(); 1169 return documentElement();
1170 } 1170 }
1171 1171
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
1671 DCHECK(!node.childNeedsStyleRecalc()); 1671 DCHECK(!node.childNeedsStyleRecalc());
1672 DCHECK(!node.childNeedsDistributionRecalc()); 1672 DCHECK(!node.childNeedsDistributionRecalc());
1673 DCHECK(!node.needsStyleInvalidation()); 1673 DCHECK(!node.needsStyleInvalidation());
1674 DCHECK(!node.childNeedsStyleInvalidation()); 1674 DCHECK(!node.childNeedsStyleInvalidation());
1675 for (ShadowRoot* shadowRoot = node.youngestShadowRoot(); shadowRoot; sha dowRoot = shadowRoot->olderShadowRoot()) 1675 for (ShadowRoot* shadowRoot = node.youngestShadowRoot(); shadowRoot; sha dowRoot = shadowRoot->olderShadowRoot())
1676 assertLayoutTreeUpdated(*shadowRoot); 1676 assertLayoutTreeUpdated(*shadowRoot);
1677 } 1677 }
1678 } 1678 }
1679 #endif 1679 #endif
1680 1680
1681 void Document::updateLayoutTree() 1681 void Document::updateStyleAndLayoutTree()
1682 { 1682 {
1683 DCHECK(isMainThread()); 1683 DCHECK(isMainThread());
1684 1684
1685 ScriptForbiddenScope forbidScript; 1685 ScriptForbiddenScope forbidScript;
1686 // We should forbid script execution for plugins here because update while l ayout is changing, 1686 // We should forbid script execution for plugins here because update while l ayout is changing,
1687 // HTMLPlugin element can be reattached and plugin can be destroyed. Plugin can execute scripts 1687 // HTMLPlugin element can be reattached and plugin can be destroyed. Plugin can execute scripts
1688 // on destroy. It produces crash without PluginScriptForbiddenScope: crbug.c om/550427. 1688 // on destroy. It produces crash without PluginScriptForbiddenScope: crbug.c om/550427.
1689 PluginScriptForbiddenScope pluginForbidScript; 1689 PluginScriptForbiddenScope pluginForbidScript;
1690 1690
1691 if (!view() || !isActive()) 1691 if (!view() || !isActive())
(...skipping 14 matching lines...) Expand all
1706 } 1706 }
1707 1707
1708 if (inStyleRecalc()) 1708 if (inStyleRecalc())
1709 return; 1709 return;
1710 1710
1711 // Entering here from inside layout, paint etc. would be catastrophic since recalcStyle can 1711 // Entering here from inside layout, paint etc. would be catastrophic since recalcStyle can
1712 // tear down the layout tree or (unfortunately) run script. Kill the whole l ayoutObject if 1712 // tear down the layout tree or (unfortunately) run script. Kill the whole l ayoutObject if
1713 // someone managed to get into here in states not allowing tree mutations. 1713 // someone managed to get into here in states not allowing tree mutations.
1714 RELEASE_ASSERT(lifecycle().stateAllowsTreeMutations()); 1714 RELEASE_ASSERT(lifecycle().stateAllowsTreeMutations());
1715 1715
1716 TRACE_EVENT_BEGIN1("blink,devtools.timeline", "UpdateLayoutTree", "beginData ", InspectorRecalculateStylesEvent::data(frame())); 1716 TRACE_EVENT_BEGIN1("blink,devtools.timeline", "UpdateStyleAndLayoutTree", "b eginData", InspectorRecalculateStylesEvent::data(frame()));
1717 TRACE_EVENT_SCOPED_SAMPLING_STATE("blink", "UpdateLayoutTree"); 1717 TRACE_EVENT_SCOPED_SAMPLING_STATE("blink", "UpdateStyleAndLayoutTree");
1718 1718
1719 unsigned startElementCount = styleEngine().styleForElementCount(); 1719 unsigned startElementCount = styleEngine().styleForElementCount();
1720 1720
1721 InspectorInstrumentation::StyleRecalc instrumentation(this); 1721 InspectorInstrumentation::StyleRecalc instrumentation(this);
1722 1722
1723 DocumentAnimations::updateAnimationTimingIfNeeded(*this); 1723 DocumentAnimations::updateAnimationTimingIfNeeded(*this);
1724 evaluateMediaQueryListIfNeeded(); 1724 evaluateMediaQueryListIfNeeded();
1725 updateUseShadowTreesIfNeeded(); 1725 updateUseShadowTreesIfNeeded();
1726 updateDistribution(); 1726 updateDistribution();
1727 updateStyleInvalidationIfNeeded(); 1727 updateStyleInvalidationIfNeeded();
(...skipping 16 matching lines...) Expand all
1744 frame()->eventHandler().dispatchFakeMouseMoveEventSoon(); 1744 frame()->eventHandler().dispatchFakeMouseMoveEventSoon();
1745 1745
1746 if (m_focusedElement && !m_focusedElement->isFocusable()) 1746 if (m_focusedElement && !m_focusedElement->isFocusable())
1747 clearFocusedElementSoon(); 1747 clearFocusedElementSoon();
1748 layoutView()->clearHitTestCache(); 1748 layoutView()->clearHitTestCache();
1749 1749
1750 DCHECK(!DocumentAnimations::needsAnimationTimingUpdate(*this)); 1750 DCHECK(!DocumentAnimations::needsAnimationTimingUpdate(*this));
1751 1751
1752 unsigned elementCount = styleEngine().styleForElementCount() - startElementC ount; 1752 unsigned elementCount = styleEngine().styleForElementCount() - startElementC ount;
1753 1753
1754 TRACE_EVENT_END1("blink,devtools.timeline", "UpdateLayoutTree", "elementCoun t", elementCount); 1754 TRACE_EVENT_END1("blink,devtools.timeline", "UpdateStyleAndLayoutTree", "ele mentCount", elementCount);
1755 1755
1756 #if DCHECK_IS_ON() 1756 #if DCHECK_IS_ON()
1757 assertLayoutTreeUpdated(*this); 1757 assertLayoutTreeUpdated(*this);
1758 #endif 1758 #endif
1759 } 1759 }
1760 1760
1761 void Document::updateStyle() 1761 void Document::updateStyle()
1762 { 1762 {
1763 DCHECK(!view()->shouldThrottleRendering()); 1763 DCHECK(!view()->shouldThrottleRendering());
1764 TRACE_EVENT_BEGIN0("blink,blink_style", "Document::updateStyle"); 1764 TRACE_EVENT_BEGIN0("blink,blink_style", "Document::updateStyle");
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1850 1850
1851 if (needsFullLayoutTreeUpdate() || node.needsStyleRecalc() || node.needsStyl eInvalidation()) 1851 if (needsFullLayoutTreeUpdate() || node.needsStyleRecalc() || node.needsStyl eInvalidation())
1852 return true; 1852 return true;
1853 for (const ContainerNode* ancestor = LayoutTreeBuilderTraversal::parent(node ); ancestor; ancestor = LayoutTreeBuilderTraversal::parent(*ancestor)) { 1853 for (const ContainerNode* ancestor = LayoutTreeBuilderTraversal::parent(node ); ancestor; ancestor = LayoutTreeBuilderTraversal::parent(*ancestor)) {
1854 if (ancestor->needsStyleRecalc() || ancestor->needsStyleInvalidation() | | ancestor->needsAdjacentStyleRecalc()) 1854 if (ancestor->needsStyleRecalc() || ancestor->needsStyleInvalidation() | | ancestor->needsAdjacentStyleRecalc())
1855 return true; 1855 return true;
1856 } 1856 }
1857 return false; 1857 return false;
1858 } 1858 }
1859 1859
1860 void Document::updateLayoutTreeForNode(const Node* node) 1860 void Document::updateStyleAndLayoutTreeForNode(const Node* node)
1861 { 1861 {
1862 DCHECK(node); 1862 DCHECK(node);
1863 if (!needsLayoutTreeUpdateForNode(*node)) 1863 if (!needsLayoutTreeUpdateForNode(*node))
1864 return; 1864 return;
1865 updateLayoutTree(); 1865 updateStyleAndLayoutTree();
1866 } 1866 }
1867 1867
1868 void Document::updateLayoutIgnorePendingStylesheetsForNode(Node* node) 1868 void Document::updateStyleAndLayoutIgnorePendingStylesheetsForNode(Node* node)
1869 { 1869 {
1870 DCHECK(node); 1870 DCHECK(node);
1871 if (!node->inActiveDocument()) 1871 if (!node->inActiveDocument())
1872 return; 1872 return;
1873 updateLayoutIgnorePendingStylesheets(); 1873 updateStyleAndLayoutIgnorePendingStylesheets();
1874 } 1874 }
1875 1875
1876 void Document::updateLayout() 1876 void Document::updateStyleAndLayout()
1877 { 1877 {
1878 DCHECK(isMainThread()); 1878 DCHECK(isMainThread());
1879 1879
1880 ScriptForbiddenScope forbidScript; 1880 ScriptForbiddenScope forbidScript;
1881 1881
1882 FrameView* frameView = view(); 1882 FrameView* frameView = view();
1883 if (frameView && frameView->isInPerformLayout()) { 1883 if (frameView && frameView->isInPerformLayout()) {
1884 // View layout should not be re-entrant. 1884 // View layout should not be re-entrant.
1885 ASSERT_NOT_REACHED(); 1885 ASSERT_NOT_REACHED();
1886 return; 1886 return;
1887 } 1887 }
1888 1888
1889 if (HTMLFrameOwnerElement* owner = ownerElement()) 1889 if (HTMLFrameOwnerElement* owner = ownerElement())
1890 owner->document().updateLayout(); 1890 owner->document().updateStyleAndLayout();
1891 1891
1892 updateLayoutTree(); 1892 updateStyleAndLayoutTree();
1893 1893
1894 if (!isActive()) 1894 if (!isActive())
1895 return; 1895 return;
1896 1896
1897 if (frameView->needsLayout()) 1897 if (frameView->needsLayout())
1898 frameView->layout(); 1898 frameView->layout();
1899 1899
1900 if (lifecycle().state() < DocumentLifecycle::LayoutClean) 1900 if (lifecycle().state() < DocumentLifecycle::LayoutClean)
1901 lifecycle().advanceTo(DocumentLifecycle::LayoutClean); 1901 lifecycle().advanceTo(DocumentLifecycle::LayoutClean);
1902 } 1902 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1936 } 1936 }
1937 1937
1938 void Document::clearFocusedElementSoon() 1938 void Document::clearFocusedElementSoon()
1939 { 1939 {
1940 if (!m_clearFocusedElementTimer.isActive()) 1940 if (!m_clearFocusedElementTimer.isActive())
1941 m_clearFocusedElementTimer.startOneShot(0, BLINK_FROM_HERE); 1941 m_clearFocusedElementTimer.startOneShot(0, BLINK_FROM_HERE);
1942 } 1942 }
1943 1943
1944 void Document::clearFocusedElementTimerFired(Timer<Document>*) 1944 void Document::clearFocusedElementTimerFired(Timer<Document>*)
1945 { 1945 {
1946 updateLayoutTree(); 1946 updateStyleAndLayoutTree();
1947 m_clearFocusedElementTimer.stop(); 1947 m_clearFocusedElementTimer.stop();
1948 1948
1949 if (m_focusedElement && !m_focusedElement->isFocusable()) 1949 if (m_focusedElement && !m_focusedElement->isFocusable())
1950 m_focusedElement->blur(); 1950 m_focusedElement->blur();
1951 } 1951 }
1952 1952
1953 // FIXME: This is a bad idea and needs to be removed eventually. 1953 // FIXME: This is a bad idea and needs to be removed eventually.
1954 // Other browsers load stylesheets before they continue parsing the web page. 1954 // Other browsers load stylesheets before they continue parsing the web page.
1955 // Since we don't, we can run JavaScript code that needs answers before the 1955 // Since we don't, we can run JavaScript code that needs answers before the
1956 // stylesheets are loaded. Doing a layout ignoring the pending stylesheets 1956 // stylesheets are loaded. Doing a layout ignoring the pending stylesheets
1957 // lets us get reasonable answers. The long term solution to this problem is 1957 // lets us get reasonable answers. The long term solution to this problem is
1958 // to instead suspend JavaScript execution. 1958 // to instead suspend JavaScript execution.
1959 void Document::updateLayoutTreeIgnorePendingStylesheets() 1959 void Document::updateStyleAndLayoutTreeIgnorePendingStylesheets()
1960 { 1960 {
1961 StyleEngine::IgnoringPendingStylesheet ignoring(styleEngine()); 1961 StyleEngine::IgnoringPendingStylesheet ignoring(styleEngine());
1962 1962
1963 if (styleEngine().hasPendingSheets()) { 1963 if (styleEngine().hasPendingSheets()) {
1964 // FIXME: We are willing to attempt to suppress painting with outdated s tyle info only once. 1964 // FIXME: We are willing to attempt to suppress painting with outdated s tyle info only once.
1965 // Our assumption is that it would be dangerous to try to stop it a seco nd time, after page 1965 // Our assumption is that it would be dangerous to try to stop it a seco nd time, after page
1966 // content has already been loaded and displayed with accurate style inf ormation. (Our 1966 // content has already been loaded and displayed with accurate style inf ormation. (Our
1967 // suppression involves blanking the whole page at the moment. If it wer e more refined, we 1967 // suppression involves blanking the whole page at the moment. If it wer e more refined, we
1968 // might be able to do something better.) It's worth noting though that this entire method 1968 // might be able to do something better.) It's worth noting though that this entire method
1969 // is a hack, since what we really want to do is suspend JS instead of d oing a layout with 1969 // is a hack, since what we really want to do is suspend JS instead of d oing a layout with
1970 // inaccurate information. 1970 // inaccurate information.
1971 HTMLElement* bodyElement = body(); 1971 HTMLElement* bodyElement = body();
1972 if (bodyElement && !bodyElement->layoutObject() && m_pendingSheetLayout == NoLayoutWithPendingSheets) { 1972 if (bodyElement && !bodyElement->layoutObject() && m_pendingSheetLayout == NoLayoutWithPendingSheets) {
1973 m_pendingSheetLayout = DidLayoutWithPendingSheets; 1973 m_pendingSheetLayout = DidLayoutWithPendingSheets;
1974 styleEngine().resolverChanged(FullStyleUpdate); 1974 styleEngine().resolverChanged(FullStyleUpdate);
1975 } else if (m_hasNodesWithPlaceholderStyle) { 1975 } else if (m_hasNodesWithPlaceholderStyle) {
1976 // If new nodes have been added or style recalc has been done with s tyle sheets still 1976 // If new nodes have been added or style recalc has been done with s tyle sheets still
1977 // pending, some nodes may not have had their real style calculated yet. Normally this 1977 // pending, some nodes may not have had their real style calculated yet. Normally this
1978 // gets cleaned when style sheets arrive but here we need up-to-date style immediately. 1978 // gets cleaned when style sheets arrive but here we need up-to-date style immediately.
1979 setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTracing: :create(StyleChangeReason::CleanupPlaceholderStyles)); 1979 setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTracing: :create(StyleChangeReason::CleanupPlaceholderStyles));
1980 } 1980 }
1981 } 1981 }
1982 updateLayoutTree(); 1982 updateStyleAndLayoutTree();
1983 } 1983 }
1984 1984
1985 void Document::updateLayoutIgnorePendingStylesheets(Document::RunPostLayoutTasks runPostLayoutTasks) 1985 void Document::updateStyleAndLayoutIgnorePendingStylesheets(Document::RunPostLay outTasks runPostLayoutTasks)
1986 { 1986 {
1987 updateLayoutTreeIgnorePendingStylesheets(); 1987 updateStyleAndLayoutTreeIgnorePendingStylesheets();
1988 updateLayout(); 1988 updateStyleAndLayout();
1989 1989
1990 if (runPostLayoutTasks == RunPostLayoutTasksSynchronously && view()) 1990 if (runPostLayoutTasks == RunPostLayoutTasksSynchronously && view())
1991 view()->flushAnyPendingPostLayoutTasks(); 1991 view()->flushAnyPendingPostLayoutTasks();
1992 } 1992 }
1993 1993
1994 PassRefPtr<ComputedStyle> Document::styleForElementIgnoringPendingStylesheets(El ement* element) 1994 PassRefPtr<ComputedStyle> Document::styleForElementIgnoringPendingStylesheets(El ement* element)
1995 { 1995 {
1996 DCHECK_EQ(element->document(), this); 1996 DCHECK_EQ(element->document(), this);
1997 StyleEngine::IgnoringPendingStylesheet ignoring(styleEngine()); 1997 StyleEngine::IgnoringPendingStylesheet ignoring(styleEngine());
1998 return ensureStyleResolver().styleForElement(element, element->parentNode() ? element->parentNode()->ensureComputedStyle() : 0); 1998 return ensureStyleResolver().styleForElement(element, element->parentNode() ? element->parentNode()->ensureComputedStyle() : 0);
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after
2643 // Just bail out. Before or during the onload we were shifted to another page. 2643 // Just bail out. Before or during the onload we were shifted to another page.
2644 // The old i-Bench suite does this. When this happens don't bother paint ing or laying out. 2644 // The old i-Bench suite does this. When this happens don't bother paint ing or laying out.
2645 m_loadEventProgress = LoadEventCompleted; 2645 m_loadEventProgress = LoadEventCompleted;
2646 return; 2646 return;
2647 } 2647 }
2648 2648
2649 // We used to force a synchronous display and flush here. This really isn't 2649 // We used to force a synchronous display and flush here. This really isn't
2650 // necessary and can in fact be actively harmful if pages are loading at a r ate of > 60fps 2650 // necessary and can in fact be actively harmful if pages are loading at a r ate of > 60fps
2651 // (if your platform is syncing flushes and limiting them to 60fps). 2651 // (if your platform is syncing flushes and limiting them to 60fps).
2652 if (!ownerElement() || (ownerElement()->layoutObject() && !ownerElement()->l ayoutObject()->needsLayout())) { 2652 if (!ownerElement() || (ownerElement()->layoutObject() && !ownerElement()->l ayoutObject()->needsLayout())) {
2653 updateLayoutTree(); 2653 updateStyleAndLayoutTree();
2654 2654
2655 // Always do a layout after loading if needed. 2655 // Always do a layout after loading if needed.
2656 if (view() && layoutView() && (!layoutView()->firstChild() || layoutView ()->needsLayout())) 2656 if (view() && layoutView() && (!layoutView()->firstChild() || layoutView ()->needsLayout()))
2657 view()->layout(); 2657 view()->layout();
2658 } 2658 }
2659 2659
2660 m_loadEventProgress = LoadEventCompleted; 2660 m_loadEventProgress = LoadEventCompleted;
2661 2661
2662 if (frame() && layoutView() && settings()->accessibilityEnabled()) { 2662 if (frame() && layoutView() && settings()->accessibilityEnabled()) {
2663 if (AXObjectCache* cache = axObjectCache()) { 2663 if (AXObjectCache* cache = axObjectCache()) {
(...skipping 915 matching lines...) Expand 10 before | Expand all | Expand 10 after
3579 if (view()) { 3579 if (view()) {
3580 Widget* oldWidget = widgetForElement(*oldFocusedElement); 3580 Widget* oldWidget = widgetForElement(*oldFocusedElement);
3581 if (oldWidget) 3581 if (oldWidget)
3582 oldWidget->setFocus(false, params.type); 3582 oldWidget->setFocus(false, params.type);
3583 else 3583 else
3584 view()->setFocus(false, params.type); 3584 view()->setFocus(false, params.type);
3585 } 3585 }
3586 } 3586 }
3587 3587
3588 if (newFocusedElement) 3588 if (newFocusedElement)
3589 updateLayoutTreeForNode(newFocusedElement); 3589 updateStyleAndLayoutTreeForNode(newFocusedElement);
3590 if (newFocusedElement && newFocusedElement->isFocusable()) { 3590 if (newFocusedElement && newFocusedElement->isFocusable()) {
3591 if (newFocusedElement->isRootEditableElement() && !acceptsEditingFocus(* newFocusedElement)) { 3591 if (newFocusedElement->isRootEditableElement() && !acceptsEditingFocus(* newFocusedElement)) {
3592 // delegate blocks focus change 3592 // delegate blocks focus change
3593 focusChangeBlocked = true; 3593 focusChangeBlocked = true;
3594 goto SetFocusedElementDone; 3594 goto SetFocusedElementDone;
3595 } 3595 }
3596 // Set focus on the new node 3596 // Set focus on the new node
3597 m_focusedElement = newFocusedElement; 3597 m_focusedElement = newFocusedElement;
3598 setSequentialFocusNavigationStartingPoint(m_focusedElement.get()); 3598 setSequentialFocusNavigationStartingPoint(m_focusedElement.get());
3599 3599
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
3640 frame()->spellChecker().didBeginEditing(m_focusedElement.get()); 3640 frame()->spellChecker().didBeginEditing(m_focusedElement.get());
3641 3641
3642 // eww, I suck. set the qt focus correctly 3642 // eww, I suck. set the qt focus correctly
3643 // ### find a better place in the code for this 3643 // ### find a better place in the code for this
3644 if (view()) { 3644 if (view()) {
3645 Widget* focusWidget = widgetForElement(*m_focusedElement); 3645 Widget* focusWidget = widgetForElement(*m_focusedElement);
3646 if (focusWidget) { 3646 if (focusWidget) {
3647 // Make sure a widget has the right size before giving it focus. 3647 // Make sure a widget has the right size before giving it focus.
3648 // Otherwise, we are testing edge cases of the Widget code. 3648 // Otherwise, we are testing edge cases of the Widget code.
3649 // Specifically, in WebCore this does not work well for text fie lds. 3649 // Specifically, in WebCore this does not work well for text fie lds.
3650 updateLayout(); 3650 updateStyleAndLayout();
3651 // Re-get the widget in case updating the layout changed things. 3651 // Re-get the widget in case updating the layout changed things.
3652 focusWidget = widgetForElement(*m_focusedElement); 3652 focusWidget = widgetForElement(*m_focusedElement);
3653 } 3653 }
3654 if (focusWidget) 3654 if (focusWidget)
3655 focusWidget->setFocus(true, params.type); 3655 focusWidget->setFocus(true, params.type);
3656 else 3656 else
3657 view()->setFocus(true, params.type); 3657 view()->setFocus(true, params.type);
3658 } 3658 }
3659 } 3659 }
3660 3660
3661 if (!focusChangeBlocked && m_focusedElement) { 3661 if (!focusChangeBlocked && m_focusedElement) {
3662 // Create the AXObject cache in a focus change because Chromium relies o n it. 3662 // Create the AXObject cache in a focus change because Chromium relies o n it.
3663 if (AXObjectCache* cache = axObjectCache()) 3663 if (AXObjectCache* cache = axObjectCache())
3664 cache->handleFocusedUIElementChanged(oldFocusedElement, newFocusedEl ement); 3664 cache->handleFocusedUIElementChanged(oldFocusedElement, newFocusedEl ement);
3665 } 3665 }
3666 3666
3667 if (!focusChangeBlocked && frameHost()) 3667 if (!focusChangeBlocked && frameHost())
3668 frameHost()->chromeClient().focusedNodeChanged(oldFocusedElement, m_focu sedElement.get()); 3668 frameHost()->chromeClient().focusedNodeChanged(oldFocusedElement, m_focu sedElement.get());
3669 3669
3670 SetFocusedElementDone: 3670 SetFocusedElementDone:
3671 updateLayoutTree(); 3671 updateStyleAndLayoutTree();
3672 if (LocalFrame* frame = this->frame()) 3672 if (LocalFrame* frame = this->frame())
3673 frame->selection().didChangeFocus(); 3673 frame->selection().didChangeFocus();
3674 return !focusChangeBlocked; 3674 return !focusChangeBlocked;
3675 } 3675 }
3676 3676
3677 void Document::clearFocusedElement() 3677 void Document::clearFocusedElement()
3678 { 3678 {
3679 setFocusedElement(nullptr, FocusParams(SelectionBehaviorOnFocus::None, WebFo cusTypeNone, nullptr)); 3679 setFocusedElement(nullptr, FocusParams(SelectionBehaviorOnFocus::None, WebFo cusTypeNone, nullptr));
3680 } 3680 }
3681 3681
(...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after
4448 } 4448 }
4449 4449
4450 // Support for Javascript execCommand, and related methods 4450 // Support for Javascript execCommand, and related methods
4451 4451
4452 static Editor::Command command(Document* document, const String& commandName) 4452 static Editor::Command command(Document* document, const String& commandName)
4453 { 4453 {
4454 LocalFrame* frame = document->frame(); 4454 LocalFrame* frame = document->frame();
4455 if (!frame || frame->document() != document) 4455 if (!frame || frame->document() != document)
4456 return Editor::Command(); 4456 return Editor::Command();
4457 4457
4458 document->updateLayoutTree(); 4458 document->updateStyleAndLayoutTree();
4459 return frame->editor().createCommand(commandName, CommandFromDOM); 4459 return frame->editor().createCommand(commandName, CommandFromDOM);
4460 } 4460 }
4461 4461
4462 bool Document::execCommand(const String& commandName, bool, const String& value, ExceptionState& exceptionState) 4462 bool Document::execCommand(const String& commandName, bool, const String& value, ExceptionState& exceptionState)
4463 { 4463 {
4464 if (!isHTMLDocument() && !isXHTMLDocument()) { 4464 if (!isHTMLDocument() && !isXHTMLDocument()) {
4465 exceptionState.throwDOMException(InvalidStateError, "execCommand is only supported on HTML documents."); 4465 exceptionState.throwDOMException(InvalidStateError, "execCommand is only supported on HTML documents.");
4466 return false; 4466 return false;
4467 } 4467 }
4468 if (focusedElement() && isHTMLTextFormControlElement(*focusedElement())) 4468 if (focusedElement() && isHTMLTextFormControlElement(*focusedElement()))
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
4773 const bool mainResourceWasAlreadyRequested = frame->loader().stateMachin e()->committedFirstRealDocumentLoad(); 4773 const bool mainResourceWasAlreadyRequested = frame->loader().stateMachin e()->committedFirstRealDocumentLoad();
4774 4774
4775 // FrameLoader::finishedParsing() might end up calling Document::implici tClose() if all 4775 // FrameLoader::finishedParsing() might end up calling Document::implici tClose() if all
4776 // resource loads are complete. HTMLObjectElements can start loading the ir resources from 4776 // resource loads are complete. HTMLObjectElements can start loading the ir resources from
4777 // post attach callbacks triggered by recalcStyle(). This means if we p arse out an <object> 4777 // post attach callbacks triggered by recalcStyle(). This means if we p arse out an <object>
4778 // tag and then reach the end of the document without updating styles, w e might not have yet 4778 // tag and then reach the end of the document without updating styles, w e might not have yet
4779 // started the resource load and might fire the window load event too ea rly. To avoid this 4779 // started the resource load and might fire the window load event too ea rly. To avoid this
4780 // we force the styles to be up to date before calling FrameLoader::fini shedParsing(). 4780 // we force the styles to be up to date before calling FrameLoader::fini shedParsing().
4781 // See https://bugs.webkit.org/show_bug.cgi?id=36864 starting around com ment 35. 4781 // See https://bugs.webkit.org/show_bug.cgi?id=36864 starting around com ment 35.
4782 if (mainResourceWasAlreadyRequested) 4782 if (mainResourceWasAlreadyRequested)
4783 updateLayoutTree(); 4783 updateStyleAndLayoutTree();
4784 4784
4785 beginLifecycleUpdatesIfRenderingReady(); 4785 beginLifecycleUpdatesIfRenderingReady();
4786 4786
4787 frame->loader().finishedParsing(); 4787 frame->loader().finishedParsing();
4788 4788
4789 TRACE_EVENT_INSTANT1("devtools.timeline", "MarkDOMContent", TRACE_EVENT_ SCOPE_THREAD, "data", InspectorMarkLoadEvent::data(frame)); 4789 TRACE_EVENT_INSTANT1("devtools.timeline", "MarkDOMContent", TRACE_EVENT_ SCOPE_THREAD, "data", InspectorMarkLoadEvent::data(frame));
4790 InspectorInstrumentation::domContentLoadedEventFired(frame); 4790 InspectorInstrumentation::domContentLoadedEventFired(frame);
4791 } 4791 }
4792 4792
4793 // Schedule dropping of the ElementDataCache. We keep it alive for a while a fter parsing finishes 4793 // Schedule dropping of the ElementDataCache. We keep it alive for a while a fter parsing finishes
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
5110 void Document::cancelFocusAppearanceUpdate() 5110 void Document::cancelFocusAppearanceUpdate()
5111 { 5111 {
5112 m_updateFocusAppearanceTimer.stop(); 5112 m_updateFocusAppearanceTimer.stop();
5113 } 5113 }
5114 5114
5115 void Document::updateFocusAppearanceTimerFired(Timer<Document>*) 5115 void Document::updateFocusAppearanceTimerFired(Timer<Document>*)
5116 { 5116 {
5117 Element* element = focusedElement(); 5117 Element* element = focusedElement();
5118 if (!element) 5118 if (!element)
5119 return; 5119 return;
5120 updateLayout(); 5120 updateStyleAndLayout();
5121 if (element->isFocusable()) 5121 if (element->isFocusable())
5122 element->updateFocusAppearance(m_updateFocusAppearanceSelectionBahavior) ; 5122 element->updateFocusAppearance(m_updateFocusAppearanceSelectionBahavior) ;
5123 } 5123 }
5124 5124
5125 void Document::attachRange(Range* range) 5125 void Document::attachRange(Range* range)
5126 { 5126 {
5127 DCHECK(!m_ranges.contains(range)); 5127 DCHECK(!m_ranges.contains(range));
5128 m_ranges.add(range); 5128 m_ranges.add(range);
5129 } 5129 }
5130 5130
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
5359 5359
5360 void Document::loadPluginsSoon() 5360 void Document::loadPluginsSoon()
5361 { 5361 {
5362 // FIXME: Remove this timer once we don't need to compute layout to load plu gins. 5362 // FIXME: Remove this timer once we don't need to compute layout to load plu gins.
5363 if (!m_pluginLoadingTimer.isActive()) 5363 if (!m_pluginLoadingTimer.isActive())
5364 m_pluginLoadingTimer.startOneShot(0, BLINK_FROM_HERE); 5364 m_pluginLoadingTimer.startOneShot(0, BLINK_FROM_HERE);
5365 } 5365 }
5366 5366
5367 void Document::pluginLoadingTimerFired(Timer<Document>*) 5367 void Document::pluginLoadingTimerFired(Timer<Document>*)
5368 { 5368 {
5369 updateLayout(); 5369 updateStyleAndLayout();
5370 } 5370 }
5371 5371
5372 ScriptedAnimationController& Document::ensureScriptedAnimationController() 5372 ScriptedAnimationController& Document::ensureScriptedAnimationController()
5373 { 5373 {
5374 if (!m_scriptedAnimationController) { 5374 if (!m_scriptedAnimationController) {
5375 m_scriptedAnimationController = ScriptedAnimationController::create(this ); 5375 m_scriptedAnimationController = ScriptedAnimationController::create(this );
5376 // We need to make sure that we don't start up the animation controller on a background tab, for example. 5376 // We need to make sure that we don't start up the animation controller on a background tab, for example.
5377 if (!page()) 5377 if (!page())
5378 m_scriptedAnimationController->suspend(); 5378 m_scriptedAnimationController->suspend();
5379 } 5379 }
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after
5969 #ifndef NDEBUG 5969 #ifndef NDEBUG
5970 using namespace blink; 5970 using namespace blink;
5971 void showLiveDocumentInstances() 5971 void showLiveDocumentInstances()
5972 { 5972 {
5973 Document::WeakDocumentSet& set = Document::liveDocumentSet(); 5973 Document::WeakDocumentSet& set = Document::liveDocumentSet();
5974 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); 5974 fprintf(stderr, "There are %u documents currently alive:\n", set.size());
5975 for (Document* document : set) 5975 for (Document* document : set)
5976 fprintf(stderr, "- Document %p URL: %s\n", document, document->url().get String().utf8().data()); 5976 fprintf(stderr, "- Document %p URL: %s\n", document, document->url().get String().utf8().data());
5977 } 5977 }
5978 #endif 5978 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698