Bug 1839315: part 4) Link from `SheetLoadData::mWasAlternate` to spec. r=emilio DONTBUILD
[gecko.git] / layout / style / CSS.cpp
blobbfb93f9560a71585402f0acda4a2cc037abc964c
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
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 /* DOM object holding utility CSS functions */
9 #include "CSS.h"
11 #include "mozilla/dom/BindingDeclarations.h"
12 #include "mozilla/dom/HighlightRegistry.h"
13 #include "mozilla/ServoBindings.h"
14 #include "mozilla/dom/Document.h"
15 #include "nsStyleUtil.h"
16 #include "xpcpublic.h"
18 namespace mozilla::dom {
20 /* static */
21 bool CSS::Supports(const GlobalObject&, const nsACString& aProperty,
22 const nsACString& aValue) {
23 return Servo_CSSSupports2(&aProperty, &aValue);
26 /* static */
27 bool CSS::Supports(const GlobalObject&, const nsACString& aCondition) {
28 return Servo_CSSSupports(&aCondition, /* ua = */ false, /* chrome = */ false,
29 /* quirks = */ false);
32 /* static */
33 void CSS::Escape(const GlobalObject&, const nsAString& aIdent,
34 nsAString& aReturn) {
35 nsStyleUtil::AppendEscapedCSSIdent(aIdent, aReturn);
38 static Document* GetDocument(const GlobalObject& aGlobal) {
39 nsCOMPtr<nsPIDOMWindowInner> window =
40 do_QueryInterface(aGlobal.GetAsSupports());
41 MOZ_DIAGNOSTIC_ASSERT(window, "CSS is only exposed to window globals");
42 if (!window) {
43 return nullptr;
45 return window->GetExtantDoc();
48 /* static */
49 HighlightRegistry* CSS::GetHighlights(const GlobalObject& aGlobal,
50 ErrorResult& aRv) {
51 Document* doc = GetDocument(aGlobal);
52 if (!doc) {
53 aRv.ThrowUnknownError("No document associated to this global?");
54 return nullptr;
56 return &doc->HighlightRegistry();
59 /* static */
60 void CSS::RegisterProperty(const GlobalObject& aGlobal,
61 const PropertyDefinition& aDefinition,
62 ErrorResult& aRv) {
63 Document* doc = GetDocument(aGlobal);
64 if (!doc) {
65 return aRv.ThrowUnknownError("No document associated to this global?");
67 doc->StyleSetForPresShellOrMediaQueryEvaluation()->RegisterProperty(
68 aDefinition, aRv);
71 } // namespace mozilla::dom