Bug 1687263: part 4) Defer and in some cases avoid removing spellchecking-ranges...
[gecko.git] / parser / html / nsHtml5DocumentBuilder.cpp
blob677db27c44aeca2b5ccc97699a3fabfaef650589
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=2 sw=2 et tw=78: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "nsHtml5DocumentBuilder.h"
9 #include "mozilla/dom/ScriptLoader.h"
10 #include "mozilla/dom/LinkStyle.h"
11 #include "nsNameSpaceManager.h"
13 using mozilla::dom::LinkStyle;
15 NS_IMPL_CYCLE_COLLECTION_INHERITED(nsHtml5DocumentBuilder, nsContentSink,
16 mOwnedElements)
18 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsHtml5DocumentBuilder)
19 NS_INTERFACE_MAP_END_INHERITING(nsContentSink)
21 NS_IMPL_ADDREF_INHERITED(nsHtml5DocumentBuilder, nsContentSink)
22 NS_IMPL_RELEASE_INHERITED(nsHtml5DocumentBuilder, nsContentSink)
24 nsHtml5DocumentBuilder::nsHtml5DocumentBuilder(bool aRunsToCompletion)
25 : mBroken(NS_OK), mFlushState(eHtml5FlushState::eNotFlushing) {
26 mRunsToCompletion = aRunsToCompletion;
29 nsresult nsHtml5DocumentBuilder::Init(mozilla::dom::Document* aDoc,
30 nsIURI* aURI, nsISupports* aContainer,
31 nsIChannel* aChannel) {
32 return nsContentSink::Init(aDoc, aURI, aContainer, aChannel);
35 nsHtml5DocumentBuilder::~nsHtml5DocumentBuilder() {}
37 nsresult nsHtml5DocumentBuilder::MarkAsBroken(nsresult aReason) {
38 mBroken = aReason;
39 return aReason;
42 void nsHtml5DocumentBuilder::SetDocumentCharsetAndSource(
43 NotNull<const Encoding*> aEncoding, int32_t aCharsetSource) {
44 if (mDocument) {
45 mDocument->SetDocumentCharacterSetSource(aCharsetSource);
46 mDocument->SetDocumentCharacterSet(aEncoding);
50 void nsHtml5DocumentBuilder::UpdateStyleSheet(nsIContent* aElement) {
51 auto* linkStyle = LinkStyle::FromNode(*aElement);
52 if (!linkStyle) {
53 MOZ_ASSERT(nsNameSpaceManager::GetInstance()->mSVGDisabled,
54 "Node didn't QI to style, but SVG wasn't disabled.");
55 return;
58 // Break out of the doc update created by Flush() to zap a runnable
59 // waiting to call UpdateStyleSheet without the right observer
60 EndDocUpdate();
62 if (MOZ_UNLIKELY(!mParser)) {
63 // EndDocUpdate ran stuff that called nsIParser::Terminate()
64 return;
67 linkStyle->SetEnableUpdates(true);
69 auto updateOrError =
70 linkStyle->UpdateStyleSheet(mRunsToCompletion ? nullptr : this);
72 if (updateOrError.isOk() && updateOrError.unwrap().ShouldBlock() &&
73 !mRunsToCompletion) {
74 ++mPendingSheetCount;
75 mScriptLoader->AddParserBlockingScriptExecutionBlocker();
78 // Re-open update
79 BeginDocUpdate();
82 void nsHtml5DocumentBuilder::SetDocumentMode(nsHtml5DocumentMode m) {
83 nsCompatibility mode = eCompatibility_NavQuirks;
84 switch (m) {
85 case STANDARDS_MODE:
86 mode = eCompatibility_FullStandards;
87 break;
88 case ALMOST_STANDARDS_MODE:
89 mode = eCompatibility_AlmostStandards;
90 break;
91 case QUIRKS_MODE:
92 mode = eCompatibility_NavQuirks;
93 break;
95 mDocument->SetCompatibilityMode(mode);
98 // nsContentSink overrides
100 void nsHtml5DocumentBuilder::UpdateChildCounts() {
101 // No-op
104 nsresult nsHtml5DocumentBuilder::FlushTags() { return NS_OK; }