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 */
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
{
21 bool CSS::Supports(const GlobalObject
&, const nsACString
& aProperty
,
22 const nsACString
& aValue
) {
23 return Servo_CSSSupports2(&aProperty
, &aValue
);
27 bool CSS::Supports(const GlobalObject
&, const nsACString
& aCondition
) {
28 return Servo_CSSSupports(&aCondition
, /* ua = */ false, /* chrome = */ false,
29 /* quirks = */ false);
33 void CSS::Escape(const GlobalObject
&, const nsAString
& aIdent
,
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");
45 return window
->GetExtantDoc();
49 HighlightRegistry
* CSS::GetHighlights(const GlobalObject
& aGlobal
,
51 Document
* doc
= GetDocument(aGlobal
);
53 aRv
.ThrowUnknownError("No document associated to this global?");
56 return &doc
->HighlightRegistry();
60 void CSS::RegisterProperty(const GlobalObject
& aGlobal
,
61 const PropertyDefinition
& aDefinition
,
63 Document
* doc
= GetDocument(aGlobal
);
65 return aRv
.ThrowUnknownError("No document associated to this global?");
67 doc
->StyleSetForPresShellOrMediaQueryEvaluation()->RegisterProperty(
71 } // namespace mozilla::dom