no bug - Import translations from android-l10n r=release a=l10n CLOSED TREE
[gecko.git] / layout / style / CSS.cpp
blob28db5a34c5fb7f98ac68ae697d23ebafeffe5b35
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 "mozilla/dom/DocumentInlines.h"
16 #include "nsStyleUtil.h"
17 #include "xpcpublic.h"
19 namespace mozilla::dom {
21 /* static */
22 bool CSS::Supports(const GlobalObject&, const nsACString& aProperty,
23 const nsACString& aValue) {
24 return Servo_CSSSupports2(&aProperty, &aValue);
27 /* static */
28 bool CSS::Supports(const GlobalObject&, const nsACString& aCondition) {
29 return Servo_CSSSupports(&aCondition, /* ua = */ false, /* chrome = */ false,
30 /* quirks = */ false);
33 /* static */
34 void CSS::Escape(const GlobalObject&, const nsAString& aIdent,
35 nsAString& aReturn) {
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");
43 if (!window) {
44 return nullptr;
46 return window->GetExtantDoc();
49 /* static */
50 HighlightRegistry* CSS::GetHighlights(const GlobalObject& aGlobal,
51 ErrorResult& aRv) {
52 Document* doc = GetDocument(aGlobal);
53 if (!doc) {
54 aRv.ThrowUnknownError("No document associated to this global?");
55 return nullptr;
57 return &doc->HighlightRegistry();
60 /* static */
61 void CSS::RegisterProperty(const GlobalObject& aGlobal,
62 const PropertyDefinition& aDefinition,
63 ErrorResult& aRv) {
64 Document* doc = GetDocument(aGlobal);
65 if (!doc) {
66 return aRv.ThrowUnknownError("No document associated to this global?");
68 doc->EnsureStyleSet().RegisterProperty(aDefinition, aRv);
71 } // namespace mozilla::dom