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
,
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
) {
42 void nsHtml5DocumentBuilder::SetDocumentCharsetAndSource(
43 NotNull
<const Encoding
*> aEncoding
, int32_t aCharsetSource
) {
45 mDocument
->SetDocumentCharacterSetSource(aCharsetSource
);
46 mDocument
->SetDocumentCharacterSet(aEncoding
);
50 void nsHtml5DocumentBuilder::UpdateStyleSheet(nsIContent
* aElement
) {
51 auto* linkStyle
= LinkStyle::FromNode(*aElement
);
53 MOZ_ASSERT(nsNameSpaceManager::GetInstance()->mSVGDisabled
,
54 "Node didn't QI to style, but SVG wasn't disabled.");
58 // Break out of the doc update created by Flush() to zap a runnable
59 // waiting to call UpdateStyleSheet without the right observer
62 if (MOZ_UNLIKELY(!mParser
)) {
63 // EndDocUpdate ran stuff that called nsIParser::Terminate()
67 linkStyle
->SetEnableUpdates(true);
70 linkStyle
->UpdateStyleSheet(mRunsToCompletion
? nullptr : this);
72 if (updateOrError
.isOk() && updateOrError
.unwrap().ShouldBlock() &&
75 mScriptLoader
->AddParserBlockingScriptExecutionBlocker();
82 void nsHtml5DocumentBuilder::SetDocumentMode(nsHtml5DocumentMode m
) {
83 nsCompatibility mode
= eCompatibility_NavQuirks
;
86 mode
= eCompatibility_FullStandards
;
88 case ALMOST_STANDARDS_MODE
:
89 mode
= eCompatibility_AlmostStandards
;
92 mode
= eCompatibility_NavQuirks
;
95 mDocument
->SetCompatibilityMode(mode
);
98 // nsContentSink overrides
100 void nsHtml5DocumentBuilder::UpdateChildCounts() {
104 nsresult
nsHtml5DocumentBuilder::FlushTags() { return NS_OK
; }