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

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: 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 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 if (!frame()) 577 if (!frame())
603 return 0; 578 return 0;
604 579
605 return domWindow()->location(); 580 return domWindow()->location();
606 } 581 }
607 582
608 void Document::childrenChanged(const ChildrenChange& change) 583 void Document::childrenChanged(const ChildrenChange& change)
609 { 584 {
610 ContainerNode::childrenChanged(change); 585 ContainerNode::childrenChanged(change);
611 m_documentElement = ElementTraversal::firstWithin(*this); 586 m_documentElement = ElementTraversal::firstWithin(*this);
587 }
612 588
613 // Installs the viewport scrolling callback (the "applyScroll" in Scroll 589 void Document::setRootScroller(Element* newScroller, ExceptionState& exceptionSt ate)
614 // Customization lingo) on the documentElement. This callback is 590 {
615 // responsible for viewport related scroll actions like top controls 591 DCHECK(newScroller);
616 // movement and overscroll glow as well as actually scrolling the root 592
617 // viewport. 593 if (ownerElement()) {
618 updateViewportApplyScroll(m_documentElement); 594 exceptionState.throwDOMException(
595 WrongDocumentError,
596 "Root scroller can only be set on the top-level document.");
tdresser 2016/04/26 20:43:49 These are web developer facing - would we devs kno
bokan 2016/04/26 23:06:23 Done.
597 return;
598 }
599
600 if (newScroller->document() != this) {
601 exceptionState.throwDOMException(
602 WrongDocumentError,
603 "Element isn't part of this document.");
604 return;
605 }
606
607 FrameHost* host = frameHost();
608 if (!host)
609 return;
610
611 RootScroller* rootScroller = host->rootScroller();
612 DCHECK(rootScroller);
613
614 if (!rootScroller->set(*newScroller)) {
615 exceptionState.throwDOMException(
616 InvalidStateError,
617 "Element cannot be set as root scroller.");
tdresser 2016/04/26 20:43:50 In what cases could this happen? Can we be more sp
bokan 2016/04/26 23:06:23 I'm being intentionally vague here, it's one of th
618 }
619 }
620
621 Element* Document::rootScroller()
622 {
623 if (ownerElement())
624 return documentElement();
625
626 FrameHost* host = frameHost();
627 if (!host)
628 return nullptr;
629
630 RootScroller* rootScroller = host->rootScroller();
631 DCHECK(rootScroller);
632
633 updateLayoutIgnorePendingStylesheets();
634
635 return rootScroller->getCurrent();
619 } 636 }
620 637
621 AtomicString Document::convertLocalName(const AtomicString& name) 638 AtomicString Document::convertLocalName(const AtomicString& name)
622 { 639 {
623 return isHTMLDocument() ? name.lower() : name; 640 return isHTMLDocument() ? name.lower() : name;
624 } 641 }
625 642
626 Element* Document::createElement(const AtomicString& name, ExceptionState& excep tionState) 643 Element* Document::createElement(const AtomicString& name, ExceptionState& excep tionState)
627 { 644 {
628 if (!isValidName(name)) { 645 if (!isValidName(name)) {
(...skipping 1278 matching lines...) Expand 10 before | Expand all | Expand 10 after
1907 // suppressed for them. We're interested in tracking the time of the 1924 // suppressed for them. We're interested in tracking the time of the
1908 // first real or 'paintable' layout. 1925 // first real or 'paintable' layout.
1909 // TODO(esprehn): This doesn't really make sense, why not track the first 1926 // TODO(esprehn): This doesn't really make sense, why not track the first
1910 // beginFrame? This will catch the first layout in a page that does lots 1927 // beginFrame? This will catch the first layout in a page that does lots
1911 // of layout thrashing even though that layout might not be followed by 1928 // of layout thrashing even though that layout might not be followed by
1912 // a paint for many seconds. 1929 // a paint for many seconds.
1913 if (isRenderingReady() && body() && !styleEngine().hasPendingSheets()) { 1930 if (isRenderingReady() && body() && !styleEngine().hasPendingSheets()) {
1914 if (!m_documentTiming.firstLayout()) 1931 if (!m_documentTiming.firstLayout())
1915 m_documentTiming.markFirstLayout(); 1932 m_documentTiming.markFirstLayout();
1916 } 1933 }
1934
1935 if (!ownerElement() && frameHost()) {
1936 if (RootScroller* rootScroller = frameHost()->rootScroller())
1937 rootScroller->didUpdateTopDocumentLayout();
1938 }
1917 } 1939 }
1918 1940
1919 void Document::setNeedsFocusedElementCheck() 1941 void Document::setNeedsFocusedElementCheck()
1920 { 1942 {
1921 setNeedsStyleRecalc(LocalStyleChange, StyleChangeReasonForTracing::createWit hExtraData(StyleChangeReason::PseudoClass, StyleChangeExtraData::Focus)); 1943 setNeedsStyleRecalc(LocalStyleChange, StyleChangeReasonForTracing::createWit hExtraData(StyleChangeReason::PseudoClass, StyleChangeExtraData::Focus));
1922 } 1944 }
1923 1945
1924 void Document::clearFocusedElementSoon() 1946 void Document::clearFocusedElementSoon()
1925 { 1947 {
1926 if (!m_clearFocusedElementTimer.isActive()) 1948 if (!m_clearFocusedElementTimer.isActive())
(...skipping 3978 matching lines...) Expand 10 before | Expand all | Expand 10 after
5905 #ifndef NDEBUG 5927 #ifndef NDEBUG
5906 using namespace blink; 5928 using namespace blink;
5907 void showLiveDocumentInstances() 5929 void showLiveDocumentInstances()
5908 { 5930 {
5909 Document::WeakDocumentSet& set = Document::liveDocumentSet(); 5931 Document::WeakDocumentSet& set = Document::liveDocumentSet();
5910 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); 5932 fprintf(stderr, "There are %u documents currently alive:\n", set.size());
5911 for (Document* document : set) 5933 for (Document* document : set)
5912 fprintf(stderr, "- Document %p URL: %s\n", document, document->url().get String().utf8().data()); 5934 fprintf(stderr, "- Document %p URL: %s\n", document, document->url().get String().utf8().data());
5913 } 5935 }
5914 #endif 5936 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698