Bug 1174575 - Part 1: Define CSSPseudoElement interface. r=birtles, r=smaug
authorBoris Chiou <boris.chiou@gmail.com>
Mon, 01 Feb 2016 23:49:00 +0100
changeset 283632 e06a6a44eeeca3f9883dc7a8cd9b79ec41903d4f
parent 283631 2a70aa2e1d133fe6b2ac7a580109f2218214d4ad
child 283633 acd70f0308ecf867e1de65f279aff8bf1a37ff32
push id17536
push usercbook@mozilla.com
push dateWed, 10 Feb 2016 13:30:18 +0000
treeherderfx-team@31150215eedf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbirtles, smaug
bugs1174575
milestone47.0a1
Bug 1174575 - Part 1: Define CSSPseudoElement interface. r=birtles, r=smaug Create CSSPseudoElement.webidl, CSSPseudoElement.h, and CSSPseudoElement.cpp.
dom/animation/CSSPseudoElement.cpp
dom/animation/CSSPseudoElement.h
dom/animation/moz.build
dom/tests/mochitest/general/test_interfaces.html
dom/webidl/CSSPseudoElement.webidl
dom/webidl/moz.build
modules/libpref/init/all.js
new file mode 100644
--- /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<JSObject*> aGivenProto)
+{
+  return CSSPseudoElementBinding::Wrap(aCx, this, aGivenProto);
+}
+
+void
+CSSPseudoElement::GetAnimations(nsTArray<RefPtr<Animation>>& aRetVal)
+{
+  // Bug 1234403: Implement this API.
+  NS_NOTREACHED("CSSPseudoElement::GetAnimations() is not implemented yet.");
+}
+
+already_AddRefed<Animation>
+CSSPseudoElement::Animate(
+    JSContext* aContext,
+    JS::Handle<JSObject*> 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
new file mode 100644
--- /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<JSObject*> aGivenProto) override;
+
+  void GetType(nsString& aRetVal) const { }
+  already_AddRefed<Element> ParentElement() const { return nullptr; }
+
+  void GetAnimations(nsTArray<RefPtr<Animation>>& aRetVal);
+  already_AddRefed<Animation>
+    Animate(JSContext* aContext,
+            JS::Handle<JSObject*> aFrames,
+            const UnrestrictedDoubleOrKeyframeAnimationOptions& aOptions,
+            ErrorResult& aError);
+};
+
+} // namespace dom
+} // namespace mozilla
+
+#endif // mozilla_dom_CSSPseudoElement_h
--- a/dom/animation/moz.build
+++ b/dom/animation/moz.build
@@ -7,16 +7,17 @@
 MOCHITEST_MANIFESTS += ['test/mochitest.ini']
 MOCHITEST_CHROME_MANIFESTS += ['test/chrome.ini']
 
 EXPORTS.mozilla.dom += [
     'Animation.h',
     'AnimationEffectReadOnly.h',
     'AnimationEffectTimingReadOnly.h',
     'AnimationTimeline.h',
+    'CSSPseudoElement.h',
     'DocumentTimeline.h',
     'KeyframeEffect.h',
 ]
 
 EXPORTS.mozilla += [
     'AnimationComparator.h',
     'AnimationUtils.h',
     'AnimValuesStyleRule.h',
@@ -30,16 +31,17 @@ EXPORTS.mozilla += [
 UNIFIED_SOURCES += [
     'Animation.cpp',
     'AnimationEffectReadOnly.cpp',
     'AnimationEffectTimingReadOnly.cpp',
     'AnimationTimeline.cpp',
     'AnimationUtils.cpp',
     'AnimValuesStyleRule.cpp',
     'ComputedTimingFunction.cpp',
+    'CSSPseudoElement.cpp',
     'DocumentTimeline.cpp',
     'EffectCompositor.cpp',
     'EffectSet.cpp',
     'KeyframeEffect.cpp',
     'PendingAnimationTracker.cpp',
 ]
 
 LOCAL_INCLUDES += [
--- a/dom/tests/mochitest/general/test_interfaces.html
+++ b/dom/tests/mochitest/general/test_interfaces.html
@@ -347,16 +347,18 @@ var interfaceNamesInGlobalScope =
     "CSSMozDocumentRule",
 // IMPORTANT: Do not change this list without review from a DOM peer!
     "CSSNameSpaceRule",
 // IMPORTANT: Do not change this list without review from a DOM peer!
     "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!
     "CSSRuleList",
 // IMPORTANT: Do not change this list without review from a DOM peer!
     "CSSStyleDeclaration",
 // IMPORTANT: Do not change this list without review from a DOM peer!
     "CSSStyleRule",
 // IMPORTANT: Do not change this list without review from a DOM peer!
new file mode 100644
--- /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;
--- a/dom/webidl/moz.build
+++ b/dom/webidl/moz.build
@@ -92,16 +92,17 @@ WEBIDL_FILES = [
     'CreateOfferRequest.webidl',
     'Crypto.webidl',
     'CSPDictionaries.webidl',
     'CSPReport.webidl',
     'CSS.webidl',
     'CSSAnimation.webidl',
     'CSSLexer.webidl',
     'CSSPrimitiveValue.webidl',
+    'CSSPseudoElement.webidl',
     'CSSRuleList.webidl',
     'CSSStyleDeclaration.webidl',
     'CSSStyleSheet.webidl',
     'CSSTransition.webidl',
     'CSSValue.webidl',
     'CSSValueList.webidl',
     'DataContainerEvent.webidl',
     'DataStore.webidl',
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -2530,16 +2530,19 @@ pref("layout.frame_rate.precise", false)
 
 // pref to control whether layout warnings that are hit quite often are enabled
 pref("layout.spammy_warnings.enabled", false);
 
 // Should we fragment floats inside CSS column layout?
 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
 pref("dom.animations-api.core.enabled", true);
 #endif
 
 // pref to permit users to make verified SOAP calls by default
 pref("capability.policy.default.SOAPCall.invokeVerifySourceHeader", "allAccess");