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 "mozilla/dom/DocumentInlines.h"
16 #include "nsStyleUtil.h"
17 #include "xpcpublic.h"
19 namespace mozilla::dom
{
22 bool CSS::Supports(const GlobalObject
&, const nsACString
& aProperty
,
23 const nsACString
& aValue
) {
24 return Servo_CSSSupports2(&aProperty
, &aValue
);
28 bool CSS::Supports(const GlobalObject
&, const nsACString
& aCondition
) {
29 return Servo_CSSSupports(&aCondition
, /* ua = */ false, /* chrome = */ false,
30 /* quirks = */ false);
34 void CSS::Escape(const GlobalObject
&, const nsAString
& aIdent
,
36 nsStyleUtil::AppendEscapedCSSIdent(aIdent
, aReturn
);
39 static Document
* GetDocument(const GlobalObject
& aGlobal
) {
40 nsCOMPtr
<nsPIDOMWindowInner
> window
=
41 do_QueryInterface(aGlobal
.GetAsSupports());
42 MOZ_DIAGNOSTIC_ASSERT(window
, "CSS is only exposed to window globals");
46 return window
->GetExtantDoc();
50 HighlightRegistry
* CSS::GetHighlights(const GlobalObject
& aGlobal
,
52 Document
* doc
= GetDocument(aGlobal
);
54 aRv
.ThrowUnknownError("No document associated to this global?");
57 return &doc
->HighlightRegistry();
61 void CSS::RegisterProperty(const GlobalObject
& aGlobal
,
62 const PropertyDefinition
& aDefinition
,
64 Document
* doc
= GetDocument(aGlobal
);
66 return aRv
.ThrowUnknownError("No document associated to this global?");
68 doc
->EnsureStyleSet().RegisterProperty(aDefinition
, aRv
);
71 } // namespace mozilla::dom