From a3a5a1c841f97bcb793a925d9eafb2944fdc551a Mon Sep 17 00:00:00 2001 From: Boris Chiou Date: Mon, 1 Feb 2016 23:49:00 +0100 Subject: [PATCH] Bug 1174575 - Part 1: Define CSSPseudoElement interface. r=birtles, r=smaug Create CSSPseudoElement.webidl, CSSPseudoElement.h, and CSSPseudoElement.cpp. --- dom/animation/CSSPseudoElement.cpp | 44 +++++++++++++++ dom/animation/CSSPseudoElement.h | 56 +++++++++++++++++++ dom/animation/moz.build | 2 + .../mochitest/general/test_interfaces.html | 2 + dom/webidl/CSSPseudoElement.webidl | 25 +++++++++ dom/webidl/moz.build | 1 + modules/libpref/init/all.js | 3 + 7 files changed, 133 insertions(+) create mode 100644 dom/animation/CSSPseudoElement.cpp create mode 100644 dom/animation/CSSPseudoElement.h create mode 100644 dom/webidl/CSSPseudoElement.webidl diff --git a/dom/animation/CSSPseudoElement.cpp b/dom/animation/CSSPseudoElement.cpp new file mode 100644 index 00000000000..5d679874971 --- /dev/null +++ b/dom/animation/CSSPseudoElement.cpp @@ -0,0 +1,44 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim:set ts=2 sw=2 sts=2 et cindent: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "mozilla/dom/CSSPseudoElement.h" +#include "mozilla/dom/CSSPseudoElementBinding.h" + +namespace mozilla { +namespace dom { + +NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(CSSPseudoElement) + +NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(CSSPseudoElement, AddRef) +NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(CSSPseudoElement, Release) + +JSObject* +CSSPseudoElement::WrapObject(JSContext* aCx, JS::Handle aGivenProto) +{ + return CSSPseudoElementBinding::Wrap(aCx, this, aGivenProto); +} + +void +CSSPseudoElement::GetAnimations(nsTArray>& aRetVal) +{ + // Bug 1234403: Implement this API. + NS_NOTREACHED("CSSPseudoElement::GetAnimations() is not implemented yet."); +} + +already_AddRefed +CSSPseudoElement::Animate( + JSContext* aContext, + JS::Handle aFrames, + const UnrestrictedDoubleOrKeyframeAnimationOptions& aOptions, + ErrorResult& aError) +{ + // Bug 1241784: Implement this API. + NS_NOTREACHED("CSSPseudoElement::Animate() is not implemented yet."); + return nullptr; +} + +} // namespace dom +} // namespace mozilla diff --git a/dom/animation/CSSPseudoElement.h b/dom/animation/CSSPseudoElement.h new file mode 100644 index 00000000000..992c4a8b243 --- /dev/null +++ b/dom/animation/CSSPseudoElement.h @@ -0,0 +1,56 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim:set ts=2 sw=2 sts=2 et cindent: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_dom_CSSPseudoElement_h +#define mozilla_dom_CSSPseudoElement_h + +#include "js/TypeDecls.h" +#include "mozilla/Attributes.h" +#include "mozilla/ErrorResult.h" +#include "mozilla/dom/BindingDeclarations.h" +#include "nsWrapperCache.h" + +namespace mozilla { +namespace dom { + +class Animation; +class Element; +class UnrestrictedDoubleOrKeyframeAnimationOptions; + +class CSSPseudoElement final : public nsWrapperCache +{ +public: + NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(CSSPseudoElement) + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(CSSPseudoElement) + +protected: + virtual ~CSSPseudoElement() = default; + +public: + ParentObject GetParentObject() const + { + // This will be implemented in later patch. + return ParentObject(nullptr, nullptr); + } + + virtual JSObject* WrapObject(JSContext* aCx, + JS::Handle aGivenProto) override; + + void GetType(nsString& aRetVal) const { } + already_AddRefed ParentElement() const { return nullptr; } + + void GetAnimations(nsTArray>& aRetVal); + already_AddRefed + Animate(JSContext* aContext, + JS::Handle aFrames, + const UnrestrictedDoubleOrKeyframeAnimationOptions& aOptions, + ErrorResult& aError); +}; + +} // namespace dom +} // namespace mozilla + +#endif // mozilla_dom_CSSPseudoElement_h diff --git a/dom/animation/moz.build b/dom/animation/moz.build index 1127b7a7658..f5ae4a93b9f 100644 --- a/dom/animation/moz.build +++ b/dom/animation/moz.build @@ -12,6 +12,7 @@ EXPORTS.mozilla.dom += [ 'AnimationEffectReadOnly.h', 'AnimationEffectTimingReadOnly.h', 'AnimationTimeline.h', + 'CSSPseudoElement.h', 'DocumentTimeline.h', 'KeyframeEffect.h', ] @@ -35,6 +36,7 @@ UNIFIED_SOURCES += [ 'AnimationUtils.cpp', 'AnimValuesStyleRule.cpp', 'ComputedTimingFunction.cpp', + 'CSSPseudoElement.cpp', 'DocumentTimeline.cpp', 'EffectCompositor.cpp', 'EffectSet.cpp', diff --git a/dom/tests/mochitest/general/test_interfaces.html b/dom/tests/mochitest/general/test_interfaces.html index ea130a1a221..25e6d2e09f4 100644 --- a/dom/tests/mochitest/general/test_interfaces.html +++ b/dom/tests/mochitest/general/test_interfaces.html @@ -351,6 +351,8 @@ var interfaceNamesInGlobalScope = "CSSPageRule", // IMPORTANT: Do not change this list without review from a DOM peer! "CSSPrimitiveValue", +// IMPORTANT: Do not change this list without review from a DOM peer! + {name: "CSSPseudoElement", release: false}, // IMPORTANT: Do not change this list without review from a DOM peer! "CSSRule", // IMPORTANT: Do not change this list without review from a DOM peer! diff --git a/dom/webidl/CSSPseudoElement.webidl b/dom/webidl/CSSPseudoElement.webidl new file mode 100644 index 00000000000..96d191e3af1 --- /dev/null +++ b/dom/webidl/CSSPseudoElement.webidl @@ -0,0 +1,25 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + * + * The origin of this IDL file is + * https://drafts.csswg.org/css-pseudo/#CSSPseudoElement-interface + * https://drafts.csswg.org/cssom/#pseudoelement + * + * Copyright © 2015 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C + * liability, trademark and document use rules apply. + */ + +// Both CSSOM and CSS Pseudo-Elements 4 provide contradictory definitions for +// this interface. +// What we implement here is a minimal subset of the two definitions which we +// ship behind a pref until the specification issues have been resolved. +[Func="nsDocument::IsWebAnimationsEnabled"] +interface CSSPseudoElement { + readonly attribute DOMString type; + readonly attribute Element parentElement; +}; + +// https://w3c.github.io/web-animations/#extensions-to-the-pseudoelement-interface +CSSPseudoElement implements Animatable; diff --git a/dom/webidl/moz.build b/dom/webidl/moz.build index 76dad44d079..4d6b72e50d2 100644 --- a/dom/webidl/moz.build +++ b/dom/webidl/moz.build @@ -97,6 +97,7 @@ WEBIDL_FILES = [ 'CSSAnimation.webidl', 'CSSLexer.webidl', 'CSSPrimitiveValue.webidl', + 'CSSPseudoElement.webidl', 'CSSRuleList.webidl', 'CSSStyleDeclaration.webidl', 'CSSStyleSheet.webidl', diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index ba6cd631b81..d25586b0bea 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -2535,6 +2535,9 @@ pref("layout.spammy_warnings.enabled", false); pref("layout.float-fragments-inside-column.enabled", true); // Is support for the Web Animations API enabled? +// Before enabling this by default, make sure also CSSPseudoElement interface +// has been spec'ed properly, or we should add a separate pref for +// CSSPseudoElement interface. See Bug 1174575 for further details. #ifdef RELEASE_BUILD pref("dom.animations-api.core.enabled", false); #else