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

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

Issue 1913843004: Implementing document.setRootScroller API for main thread scrolling. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@overscrollController
Patch Set: Rebase and remove whitespace in Document.idl 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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 #include "core/loader/FrameLoaderClient.h" 186 #include "core/loader/FrameLoaderClient.h"
187 #include "core/loader/ImageLoader.h" 187 #include "core/loader/ImageLoader.h"
188 #include "core/loader/NavigationScheduler.h" 188 #include "core/loader/NavigationScheduler.h"
189 #include "core/loader/appcache/ApplicationCacheHost.h" 189 #include "core/loader/appcache/ApplicationCacheHost.h"
190 #include "core/page/ChromeClient.h" 190 #include "core/page/ChromeClient.h"
191 #include "core/page/EventWithHitTestResults.h" 191 #include "core/page/EventWithHitTestResults.h"
192 #include "core/page/FocusController.h" 192 #include "core/page/FocusController.h"
193 #include "core/page/FrameTree.h" 193 #include "core/page/FrameTree.h"
194 #include "core/page/Page.h" 194 #include "core/page/Page.h"
195 #include "core/page/PointerLockController.h" 195 #include "core/page/PointerLockController.h"
196 #include "core/page/scrolling/RootScroller.h"
196 #include "core/page/scrolling/ScrollingCoordinator.h" 197 #include "core/page/scrolling/ScrollingCoordinator.h"
197 #include "core/page/scrolling/ViewportScrollCallback.h"
198 #include "core/svg/SVGDocumentExtensions.h" 198 #include "core/svg/SVGDocumentExtensions.h"
199 #include "core/svg/SVGTitleElement.h" 199 #include "core/svg/SVGTitleElement.h"
200 #include "core/svg/SVGUseElement.h" 200 #include "core/svg/SVGUseElement.h"
201 #include "core/timing/DOMWindowPerformance.h" 201 #include "core/timing/DOMWindowPerformance.h"
202 #include "core/timing/Performance.h" 202 #include "core/timing/Performance.h"
203 #include "core/workers/SharedWorkerRepositoryClient.h" 203 #include "core/workers/SharedWorkerRepositoryClient.h"
204 #include "core/xml/parser/XMLDocumentParser.h" 204 #include "core/xml/parser/XMLDocumentParser.h"
205 #include "platform/DateComponents.h" 205 #include "platform/DateComponents.h"
206 #include "platform/EventDispatchForbiddenScope.h" 206 #include "platform/EventDispatchForbiddenScope.h"
207 #include "platform/Histogram.h" 207 #include "platform/Histogram.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 241
242 using namespace HTMLNames; 242 using namespace HTMLNames;
243 243
244 static const unsigned cMaxWriteRecursionDepth = 21; 244 static const unsigned cMaxWriteRecursionDepth = 21;
245 245
246 // This amount of time must have elapsed before we will even consider scheduling a layout without a delay. 246 // This amount of time must have elapsed before we will even consider scheduling a layout without a delay.
247 // FIXME: For faster machines this value can really be lowered to 200. 250 is a dequate, but a little high 247 // FIXME: For faster machines this value can really be lowered to 200. 250 is a dequate, but a little high
248 // for dual G5s. :) 248 // for dual G5s. :)
249 static const int cLayoutScheduleThreshold = 250; 249 static const int cLayoutScheduleThreshold = 250;
250 250
251 namespace {
252
253 void updateViewportApplyScroll(Element* documentElement)
254 {
255 if (!documentElement
256 || !documentElement->isHTMLElement()
257 || documentElement->document().ownerElement())
258 return;
259
260 if (documentElement->getApplyScroll())
261 return;
262
263 ScrollStateCallback* applyScroll =
264 new ViewportScrollCallback(documentElement->document());
265
266 // Use disable-native-scroll since the ViewportScrollCallback needs to
267 // apply scroll actions before (TopControls) and after (overscroll)
268 // scrolling the element so it applies scroll to the element itself.
269 documentElement->setApplyScroll(
270 applyScroll,
271 "disable-native-scroll");
272 }
273
274 } // namespace
275
276 // DOM Level 2 says (letters added): 251 // DOM Level 2 says (letters added):
277 // 252 //
278 // a) Name start characters must have one of the categories Ll, Lu, Lo, Lt, Nl. 253 // a) Name start characters must have one of the categories Ll, Lu, Lo, Lt, Nl.
279 // b) Name characters other than Name-start characters must have one of the cate gories Mc, Me, Mn, Lm, or Nd. 254 // b) Name characters other than Name-start characters must have one of the cate gories Mc, Me, Mn, Lm, or Nd.
280 // c) Characters in the compatibility area (i.e. with character code greater tha n #xF900 and less than #xFFFE) are not allowed in XML names. 255 // c) Characters in the compatibility area (i.e. with character code greater tha n #xF900 and less than #xFFFE) are not allowed in XML names.
281 // d) Characters which have a font or compatibility decomposition (i.e. those wi th a "compatibility formatting tag" in field 5 of the database -- marked by fiel d 5 beginning with a "<") are not allowed. 256 // d) Characters which have a font or compatibility decomposition (i.e. those wi th a "compatibility formatting tag" in field 5 of the database -- marked by fiel d 5 beginning with a "<") are not allowed.
282 // e) The following characters are treated as name-start characters rather than name characters, because the property file classifies them as Alphabetic: [#x02B B-#x02C1], #x0559, #x06E5, #x06E6. 257 // e) The following characters are treated as name-start characters rather than name characters, because the property file classifies them as Alphabetic: [#x02B B-#x02C1], #x0559, #x06E5, #x06E6.
283 // f) Characters #x20DD-#x20E0 are excluded (in accordance with Unicode, section 5.14). 258 // f) Characters #x20DD-#x20E0 are excluded (in accordance with Unicode, section 5.14).
284 // g) Character #x00B7 is classified as an extender, because the property list s o identifies it. 259 // g) Character #x00B7 is classified as an extender, because the property list s o identifies it.
285 // h) Character #x0387 is added as a name character, because #x00B7 is its canon ical equivalent. 260 // h) Character #x0387 is added as a name character, because #x00B7 is its canon ical equivalent.
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 ContainerNode::childrenChanged(change); 585 ContainerNode::childrenChanged(change);
611 m_documentElement = ElementTraversal::firstWithin(*this); 586 m_documentElement = ElementTraversal::firstWithin(*this);
612 587
613 // For non-HTML documents the willInsertBody notification won't happen 588 // For non-HTML documents the willInsertBody notification won't happen
614 // so we resume as soon as we have a document element. Even for XHTML 589 // so we resume as soon as we have a document element. Even for XHTML
615 // documents there may never be a <body> (since the parser won't always 590 // documents there may never be a <body> (since the parser won't always
616 // 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
617 // 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.
618 if (m_documentElement && !isHTMLDocument()) 593 if (m_documentElement && !isHTMLDocument())
619 beginLifecycleUpdatesIfRenderingReady(); 594 beginLifecycleUpdatesIfRenderingReady();
595 }
620 596
621 // Installs the viewport scrolling callback (the "applyScroll" in Scroll 597 void Document::setRootScroller(Element* newScroller, ExceptionState& exceptionSt ate)
622 // Customization lingo) on the documentElement. This callback is 598 {
623 // responsible for viewport related scroll actions like top controls 599 DCHECK(newScroller);
624 // movement and overscroll glow as well as actually scrolling the root 600
625 // viewport. 601 if (ownerElement()) {
626 updateViewportApplyScroll(m_documentElement); 602 exceptionState.throwDOMException(
603 WrongDocumentError,
604 "Root scroller cannot be set on a document within a frame.");
605 return;
606 }
607
608 if (newScroller->document() != this) {
609 exceptionState.throwDOMException(
610 WrongDocumentError,
611 "Element isn't in this document.");
esprehn 2016/05/05 17:29:46 This doesn't really make sense, what if I remove t
612 return;
613 }
614
615 FrameHost* host = frameHost();
616 if (!host)
617 return;
618
619 RootScroller* rootScroller = host->rootScroller();
620 DCHECK(rootScroller);
621
622 if (!rootScroller->set(*newScroller)) {
623 exceptionState.throwDOMException(
624 InvalidStateError,
625 "Element cannot be set as root scroller. Must be block or iframe.");
626 }
627 }
628
629 Element* Document::rootScroller()
630 {
631 if (ownerElement())
632 return documentElement();
633
634 FrameHost* host = frameHost();
635 if (!host)
636 return nullptr;
637
638 RootScroller* rootScroller = host->rootScroller();
639 DCHECK(rootScroller);
640
641 updateLayoutIgnorePendingStylesheets();
642
643 return rootScroller->get();
627 } 644 }
628 645
629 AtomicString Document::convertLocalName(const AtomicString& name) 646 AtomicString Document::convertLocalName(const AtomicString& name)
630 { 647 {
631 return isHTMLDocument() ? name.lower() : name; 648 return isHTMLDocument() ? name.lower() : name;
632 } 649 }
633 650
634 Element* Document::createElement(const AtomicString& name, ExceptionState& excep tionState) 651 Element* Document::createElement(const AtomicString& name, ExceptionState& excep tionState)
635 { 652 {
636 if (!isValidName(name)) { 653 if (!isValidName(name)) {
(...skipping 1278 matching lines...) Expand 10 before | Expand all | Expand 10 after
1915 // suppressed for them. We're interested in tracking the time of the 1932 // suppressed for them. We're interested in tracking the time of the
1916 // first real or 'paintable' layout. 1933 // first real or 'paintable' layout.
1917 // TODO(esprehn): This doesn't really make sense, why not track the first 1934 // TODO(esprehn): This doesn't really make sense, why not track the first
1918 // beginFrame? This will catch the first layout in a page that does lots 1935 // beginFrame? This will catch the first layout in a page that does lots
1919 // of layout thrashing even though that layout might not be followed by 1936 // of layout thrashing even though that layout might not be followed by
1920 // a paint for many seconds. 1937 // a paint for many seconds.
1921 if (isRenderingReady() && body() && !styleEngine().hasPendingSheets()) { 1938 if (isRenderingReady() && body() && !styleEngine().hasPendingSheets()) {
1922 if (!m_documentTiming.firstLayout()) 1939 if (!m_documentTiming.firstLayout())
1923 m_documentTiming.markFirstLayout(); 1940 m_documentTiming.markFirstLayout();
1924 } 1941 }
1942
1943 if (!ownerElement() && frameHost()) {
1944 if (RootScroller* rootScroller = frameHost()->rootScroller())
1945 rootScroller->didUpdateTopDocumentLayout();
1946 }
1925 } 1947 }
1926 1948
1927 void Document::setNeedsFocusedElementCheck() 1949 void Document::setNeedsFocusedElementCheck()
1928 { 1950 {
1929 setNeedsStyleRecalc(LocalStyleChange, StyleChangeReasonForTracing::createWit hExtraData(StyleChangeReason::PseudoClass, StyleChangeExtraData::Focus)); 1951 setNeedsStyleRecalc(LocalStyleChange, StyleChangeReasonForTracing::createWit hExtraData(StyleChangeReason::PseudoClass, StyleChangeExtraData::Focus));
1930 } 1952 }
1931 1953
1932 void Document::clearFocusedElementSoon() 1954 void Document::clearFocusedElementSoon()
1933 { 1955 {
1934 if (!m_clearFocusedElementTimer.isActive()) 1956 if (!m_clearFocusedElementTimer.isActive())
(...skipping 4017 matching lines...) Expand 10 before | Expand all | Expand 10 after
5952 #ifndef NDEBUG 5974 #ifndef NDEBUG
5953 using namespace blink; 5975 using namespace blink;
5954 void showLiveDocumentInstances() 5976 void showLiveDocumentInstances()
5955 { 5977 {
5956 Document::WeakDocumentSet& set = Document::liveDocumentSet(); 5978 Document::WeakDocumentSet& set = Document::liveDocumentSet();
5957 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); 5979 fprintf(stderr, "There are %u documents currently alive:\n", set.size());
5958 for (Document* document : set) 5980 for (Document* document : set)
5959 fprintf(stderr, "- Document %p URL: %s\n", document, document->url().get String().utf8().data()); 5981 fprintf(stderr, "- Document %p URL: %s\n", document, document->url().get String().utf8().data());
5960 } 5982 }
5961 #endif 5983 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698