Bug 1876868 [wpt PR 44242] - [Grid] Fix layout with max-content, aspect ratio, and...
[gecko.git] / parser / html / nsHtml5DocumentBuilder.cpp
blobb2220253dc41a548187ee80eec7f250c79707e00
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() = default;
37 nsresult nsHtml5DocumentBuilder::MarkAsBroken(nsresult aReason) {
38 mBroken = aReason;
39 return aReason;
42 void nsHtml5DocumentBuilder::UpdateStyleSheet(nsIContent* aElement) {
43 auto* linkStyle = LinkStyle::FromNode(*aElement);
44 if (!linkStyle) {
45 MOZ_ASSERT(nsNameSpaceManager::GetInstance()->mSVGDisabled,
46 "Node didn't QI to style, but SVG wasn't disabled.");
47 return;
50 auto updateOrError = linkStyle->EnableUpdatesAndUpdateStyleSheet(
51 mRunsToCompletion ? nullptr : this);
53 if (updateOrError.isOk() && updateOrError.unwrap().ShouldBlock() &&
54 !mRunsToCompletion) {
55 ++mPendingSheetCount;
56 mScriptLoader->AddParserBlockingScriptExecutionBlocker();
60 void nsHtml5DocumentBuilder::SetDocumentMode(nsHtml5DocumentMode m) {
61 nsCompatibility mode = eCompatibility_NavQuirks;
62 const char* errMsgId = nullptr;
64 switch (m) {
65 case STANDARDS_MODE:
66 mode = eCompatibility_FullStandards;
67 break;
68 case ALMOST_STANDARDS_MODE:
69 mode = eCompatibility_AlmostStandards;
70 errMsgId = "errAlmostStandardsDoctypeVerbose";
71 break;
72 case QUIRKS_MODE:
73 mode = eCompatibility_NavQuirks;
74 errMsgId = "errQuirkyDoctypeVerbose";
75 break;
77 mDocument->SetCompatibilityMode(mode);
79 if (errMsgId && !mDocument->IsLoadedAsData()) {
80 nsCOMPtr<nsIURI> docURI = mDocument->GetDocumentURI();
81 bool isData = false;
82 docURI->SchemeIs("data", &isData);
83 bool isHttp = false;
84 docURI->SchemeIs("http", &isHttp);
85 bool isHttps = false;
86 docURI->SchemeIs("https", &isHttps);
88 nsCOMPtr<nsIPrincipal> principal = mDocument->GetPrincipal();
89 if (principal->GetIsNullPrincipal() && !isData && !isHttp && !isHttps) {
90 // Don't normally warn for null principals. It may well be internal
91 // documents for which the warning is not applicable.
92 return;
95 nsContentUtils::ReportToConsole(
96 nsIScriptError::warningFlag, "HTML_PARSER__DOCTYPE"_ns, mDocument,
97 nsContentUtils::eHTMLPARSER_PROPERTIES, errMsgId);
101 // nsContentSink overrides
103 void nsHtml5DocumentBuilder::UpdateChildCounts() {
104 // No-op
107 nsresult nsHtml5DocumentBuilder::FlushTags() { return NS_OK; }