Bug 1028497 - Part 3: Add skeleton implementations of CSSFontFaceLoadEvent, FontFace, FontFaceSet and FontFaceSource. r=jdaggett
authorCameron McCormack <cam@mcc.id.au>
Thu, 02 Oct 2014 12:32:05 +1000
changeset 231530 1c827b73c45f272b36ec07e1f1660c07c07febd4
parent 231529 52e4991a82169afddad8f0da702a1421a6bd1019
child 231531 54ded49a16876d77c49567fb6d6419e167275775
push id4187
push userbhearsum@mozilla.com
push dateFri, 28 Nov 2014 15:29:12 +0000
treeherdermozilla-beta@f23cc6a30c11 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdaggett
bugs1028497
milestone35.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1028497 - Part 3: Add skeleton implementations of CSSFontFaceLoadEvent, FontFace, FontFaceSet and FontFaceSource. r=jdaggett
content/base/public/nsIDocument.h
content/base/src/nsDocument.cpp
content/base/src/nsGkAtomList.h
layout/style/FontFace.cpp
layout/style/FontFace.h
layout/style/FontFaceSet.cpp
layout/style/FontFaceSet.h
layout/style/moz.build
--- a/content/base/public/nsIDocument.h
+++ b/content/base/public/nsIDocument.h
@@ -101,16 +101,17 @@ struct CustomElementDefinition;
 class DocumentFragment;
 class DocumentType;
 class DOMImplementation;
 class DOMStringList;
 class Element;
 struct ElementRegistrationOptions;
 class Event;
 class EventTarget;
+class FontFaceSet;
 class FrameRequestCallback;
 class ImportManager;
 class OverfillCallback;
 class HTMLBodyElement;
 struct LifecycleCallbackArgs;
 class Link;
 class GlobalObject;
 class NodeFilter;
@@ -2385,16 +2386,19 @@ public:
 
     nsWeakPtr weakNode = do_GetWeakReference(node);
 
     if (weakNode) {
       mBlockedTrackingNodes.AppendElement(weakNode);
     }
   }
 
+  // FontFaceSource
+  mozilla::dom::FontFaceSet* GetFonts(mozilla::ErrorResult& aRv);
+
 private:
   uint64_t mWarnedAbout;
   SelectorCache mSelectorCache;
 
 protected:
   ~nsIDocument();
   nsPropertyTable* GetExtraPropertyTable(uint16_t aCategory);
 
--- a/content/base/src/nsDocument.cpp
+++ b/content/base/src/nsDocument.cpp
@@ -218,16 +218,17 @@
 #include "nsIDocumentEncoder.h"
 #include "nsIDocumentActivity.h"
 #include "nsIStructuredCloneContainer.h"
 #include "nsIMutableArray.h"
 #include "nsContentPermissionHelper.h"
 #include "mozilla/dom/DOMStringList.h"
 #include "nsWindowMemoryReporter.h"
 #include "nsLocation.h"
+#include "mozilla/dom/FontFaceSet.h"
 
 #ifdef MOZ_MEDIA_NAVIGATOR
 #include "mozilla/MediaManager.h"
 #endif // MOZ_MEDIA_NAVIGATOR
 #ifdef MOZ_WEBRTC
 #include "IPeerConnection.h"
 #endif // MOZ_WEBRTC
 
@@ -12410,8 +12411,14 @@ nsAutoSyncOperation::nsAutoSyncOperation
 nsAutoSyncOperation::~nsAutoSyncOperation()
 {
   for (int32_t i = 0; i < mDocuments.Count(); ++i) {
     mDocuments[i]->SetIsInSyncOperation(false);
   }
   nsContentUtils::SetMicroTaskLevel(mMicroTaskLevel);
 }
 
+FontFaceSet*
+nsIDocument::GetFonts(ErrorResult& aRv)
+{
+  aRv.Throw(NS_ERROR_FAILURE);
+  return nullptr;
+}
--- a/content/base/src/nsGkAtomList.h
+++ b/content/base/src/nsGkAtomList.h
@@ -770,16 +770,19 @@ GK_ATOM(oninstall, "oninstall")
 GK_ATOM(oninvalid, "oninvalid")
 GK_ATOM(onkeydown, "onkeydown")
 GK_ATOM(onkeypress, "onkeypress")
 GK_ATOM(onkeyup, "onkeyup")
 GK_ATOM(onlanguagechange, "onlanguagechange")
 GK_ATOM(onlevelchange, "onlevelchange")
 GK_ATOM(onLoad, "onLoad")
 GK_ATOM(onload, "onload")
+GK_ATOM(onloading, "onloading")
+GK_ATOM(onloadingdone, "onloadingdone")
+GK_ATOM(onloadingerror, "onloadingerror")
 GK_ATOM(onpopstate, "onpopstate")
 GK_ATOM(only, "only")               // this one is not an event
 GK_ATOM(onmessage, "onmessage")
 GK_ATOM(onmousedown, "onmousedown")
 GK_ATOM(onmouseenter, "onmouseenter")
 GK_ATOM(onmouseleave, "onmouseleave")
 GK_ATOM(onmousemove, "onmousemove")
 GK_ATOM(onmouseout, "onmouseout")
new file mode 100644
--- /dev/null
+++ b/layout/style/FontFace.cpp
@@ -0,0 +1,139 @@
+/* -*- Mode: C++; 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/. */
+
+#include "mozilla/dom/FontFace.h"
+
+#include "mozilla/dom/FontFaceBinding.h"
+#include "mozilla/dom/Promise.h"
+
+using namespace mozilla::dom;
+
+NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(FontFace, mParent, mLoaded)
+
+NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(FontFace)
+  NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
+  NS_INTERFACE_MAP_ENTRY(nsISupports)
+NS_INTERFACE_MAP_END
+
+NS_IMPL_CYCLE_COLLECTING_ADDREF(FontFace)
+NS_IMPL_CYCLE_COLLECTING_RELEASE(FontFace)
+
+FontFace::FontFace(nsISupports* aParent)
+  : mParent(aParent)
+{
+  MOZ_COUNT_CTOR(FontFace);
+
+  SetIsDOMBinding();
+}
+
+FontFace::~FontFace()
+{
+  MOZ_COUNT_DTOR(FontFace);
+}
+
+JSObject*
+FontFace::WrapObject(JSContext* aCx)
+{
+  return FontFaceBinding::Wrap(aCx, this);
+}
+
+already_AddRefed<FontFace>
+FontFace::Constructor(const GlobalObject& aGlobal,
+                      const nsAString& aFamily,
+                      const StringOrArrayBufferOrArrayBufferView& aSource,
+                      const FontFaceDescriptors& aDescriptors,
+                      ErrorResult& aRV)
+{
+  nsRefPtr<FontFace> obj = new FontFace(aGlobal.GetAsSupports());
+  return obj.forget();
+}
+
+void
+FontFace::GetFamily(nsString& aResult)
+{
+}
+
+void
+FontFace::SetFamily(const nsAString& aValue, ErrorResult& aRv)
+{
+}
+
+void
+FontFace::GetStyle(nsString& aResult)
+{
+}
+
+void
+FontFace::SetStyle(const nsAString& aValue, ErrorResult& aRv)
+{
+}
+
+void
+FontFace::GetWeight(nsString& aResult)
+{
+}
+
+void
+FontFace::SetWeight(const nsAString& aValue, ErrorResult& aRv)
+{
+}
+
+void
+FontFace::GetStretch(nsString& aResult)
+{
+}
+
+void
+FontFace::SetStretch(const nsAString& aValue, ErrorResult& aRv)
+{
+}
+
+void
+FontFace::GetUnicodeRange(nsString& aResult)
+{
+}
+
+void
+FontFace::SetUnicodeRange(const nsAString& aValue, ErrorResult& aRv)
+{
+}
+
+void
+FontFace::GetVariant(nsString& aResult)
+{
+}
+
+void
+FontFace::SetVariant(const nsAString& aValue, ErrorResult& aRv)
+{
+}
+
+void
+FontFace::GetFeatureSettings(nsString& aResult)
+{
+}
+
+void
+FontFace::SetFeatureSettings(const nsAString& aValue, ErrorResult& aRv)
+{
+}
+
+FontFaceLoadStatus
+FontFace::Status()
+{
+  return FontFaceLoadStatus::Unloaded;
+}
+
+Promise*
+FontFace::Load()
+{
+  return Loaded();
+}
+
+Promise*
+FontFace::Loaded()
+{
+  return nullptr;
+}
new file mode 100644
--- /dev/null
+++ b/layout/style/FontFace.h
@@ -0,0 +1,71 @@
+/* -*- Mode: C++; 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/. */
+
+#ifndef mozilla_dom_FontFace_h
+#define mozilla_dom_FontFace_h
+
+#include "nsWrapperCache.h"
+#include "mozilla/dom/FontFaceBinding.h"
+
+namespace mozilla {
+namespace dom {
+struct FontFaceDescriptors;
+class Promise;
+class StringOrArrayBufferOrArrayBufferView;
+}
+}
+
+namespace mozilla {
+namespace dom {
+
+class FontFace MOZ_FINAL : public nsISupports,
+                           public nsWrapperCache
+{
+public:
+  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
+  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(FontFace)
+
+  nsISupports* GetParentObject() const { return mParent; }
+  virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
+
+  // Web IDL
+  static already_AddRefed<FontFace>
+  Constructor(const GlobalObject& aGlobal,
+              const nsAString& aFamily,
+              const mozilla::dom::StringOrArrayBufferOrArrayBufferView& aSource,
+              const mozilla::dom::FontFaceDescriptors& aDescriptors,
+              ErrorResult& aRV);
+
+  void GetFamily(nsString& aResult);
+  void SetFamily(const nsAString& aValue, mozilla::ErrorResult& aRv);
+  void GetStyle(nsString& aResult);
+  void SetStyle(const nsAString& aValue, mozilla::ErrorResult& aRv);
+  void GetWeight(nsString& aResult);
+  void SetWeight(const nsAString& aValue, mozilla::ErrorResult& aRv);
+  void GetStretch(nsString& aResult);
+  void SetStretch(const nsAString& aValue, mozilla::ErrorResult& aRv);
+  void GetUnicodeRange(nsString& aResult);
+  void SetUnicodeRange(const nsAString& aValue, mozilla::ErrorResult& aRv);
+  void GetVariant(nsString& aResult);
+  void SetVariant(const nsAString& aValue, mozilla::ErrorResult& aRv);
+  void GetFeatureSettings(nsString& aResult);
+  void SetFeatureSettings(const nsAString& aValue, mozilla::ErrorResult& aRv);
+
+  mozilla::dom::FontFaceLoadStatus Status();
+  mozilla::dom::Promise* Load();
+  mozilla::dom::Promise* Loaded();
+
+private:
+  FontFace(nsISupports* aParent);
+  ~FontFace();
+
+  nsCOMPtr<nsISupports> mParent;
+  nsRefPtr<mozilla::dom::Promise> mLoaded;
+};
+
+} // namespace dom
+} // namespace mozilla
+
+#endif // !defined(mozilla_dom_FontFace_h)
new file mode 100644
--- /dev/null
+++ b/layout/style/FontFaceSet.cpp
@@ -0,0 +1,109 @@
+/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
+/* vim: set ts=2 et sw=2 tw=80: */
+/* 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 "FontFaceSet.h"
+
+#include "mozilla/dom/FontFaceSetBinding.h"
+#include "mozilla/dom/Promise.h"
+
+using namespace mozilla::dom;
+
+NS_IMPL_CYCLE_COLLECTION_INHERITED(FontFaceSet,
+                                   DOMEventTargetHelper,
+                                   mReady)
+
+NS_IMPL_ADDREF_INHERITED(FontFaceSet, DOMEventTargetHelper)
+NS_IMPL_RELEASE_INHERITED(FontFaceSet, DOMEventTargetHelper)
+NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(FontFaceSet)
+NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
+
+FontFaceSet::FontFaceSet(nsPIDOMWindow* aWindow)
+  : DOMEventTargetHelper(aWindow)
+{
+  MOZ_COUNT_CTOR(FontFaceSet);
+}
+
+FontFaceSet::~FontFaceSet()
+{
+  MOZ_COUNT_DTOR(FontFaceSet);
+}
+
+JSObject*
+FontFaceSet::WrapObject(JSContext* aContext)
+{
+  return FontFaceSetBinding::Wrap(aContext, this);
+}
+
+already_AddRefed<Promise>
+FontFaceSet::Load(const nsAString& aFont,
+                  const nsAString& aText,
+                  ErrorResult& aRv)
+{
+  aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
+  return nullptr;
+}
+
+bool
+FontFaceSet::Check(const nsAString& aFont,
+                   const nsAString& aText,
+                   ErrorResult& aRv)
+{
+  aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
+  return false;
+}
+
+Promise*
+FontFaceSet::GetReady(ErrorResult& aRv)
+{
+  if (!mReady) {
+    aRv.Throw(NS_ERROR_FAILURE);
+    return nullptr;
+  }
+
+  return mReady;
+}
+
+FontFaceSetLoadStatus
+FontFaceSet::Status()
+{
+  return FontFaceSetLoadStatus::Loaded;
+}
+
+FontFaceSet*
+FontFaceSet::Add(FontFace& aFontFace, ErrorResult& aRv)
+{
+  return this;
+}
+
+void
+FontFaceSet::Clear()
+{
+}
+
+bool
+FontFaceSet::Delete(FontFace& aFontFace, ErrorResult& aRv)
+{
+  return false;
+}
+
+bool
+FontFaceSet::Has(FontFace& aFontFace)
+{
+  return false;
+}
+
+FontFace*
+FontFaceSet::IndexedGetter(uint32_t aIndex, bool& aFound)
+{
+  aFound = false;
+  return nullptr;
+}
+
+uint32_t
+FontFaceSet::Length()
+{
+  return 0;
+}
new file mode 100644
--- /dev/null
+++ b/layout/style/FontFaceSet.h
@@ -0,0 +1,64 @@
+/* -*- Mode: C++; 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/. */
+
+#ifndef mozilla_dom_FontFaceSet_h
+#define mozilla_dom_FontFaceSet_h
+
+#include "mozilla/DOMEventTargetHelper.h"
+#include "mozilla/dom/FontFaceSetBinding.h"
+#include "nsPIDOMWindow.h"
+
+class nsPIDOMWindow;
+
+namespace mozilla {
+namespace dom {
+class FontFace;
+class Promise;
+}
+}
+
+namespace mozilla {
+namespace dom {
+
+class FontFaceSet MOZ_FINAL : public DOMEventTargetHelper
+{
+public:
+  NS_DECL_ISUPPORTS_INHERITED
+  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(FontFaceSet, DOMEventTargetHelper)
+
+  FontFaceSet(nsPIDOMWindow* aWindow);
+
+  virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
+
+  // Web IDL
+  IMPL_EVENT_HANDLER(loading)
+  IMPL_EVENT_HANDLER(loadingdone)
+  IMPL_EVENT_HANDLER(loadingerror)
+  already_AddRefed<mozilla::dom::Promise> Load(const nsAString& aFont,
+                                               const nsAString& aText,
+                                               mozilla::ErrorResult& aRv);
+  bool Check(const nsAString& aFont,
+             const nsAString& aText,
+             mozilla::ErrorResult& aRv);
+  mozilla::dom::Promise* GetReady(mozilla::ErrorResult& aRv);
+  mozilla::dom::FontFaceSetLoadStatus Status();
+
+  FontFaceSet* Add(FontFace& aFontFace, mozilla::ErrorResult& aRv);
+  void Clear();
+  bool Delete(FontFace& aFontFace, mozilla::ErrorResult& aRv);
+  bool Has(FontFace& aFontFace);
+  FontFace* IndexedGetter(uint32_t aIndex, bool& aFound);
+  uint32_t Length();
+
+private:
+  ~FontFaceSet();
+
+  nsRefPtr<mozilla::dom::Promise> mReady;
+};
+
+} // namespace dom
+} // namespace mozilla
+
+#endif // !defined(mozilla_dom_FontFaceSet_h)
--- a/layout/style/moz.build
+++ b/layout/style/moz.build
@@ -63,16 +63,18 @@ EXPORTS.mozilla += [
     'CSSVariableValues.h',
     'StyleAnimationValue.h',
 ]
 
 EXPORTS.mozilla.dom += [
     'CSS.h',
     'CSSRuleList.h',
     'CSSValue.h',
+    'FontFace.h',
+    'FontFaceSet.h',
     'MediaQueryList.h',
 ]
 
 EXPORTS.mozilla.css += [
     'Declaration.h',
     'ErrorReporter.h',
     'GroupRule.h',
     'ImageLoader.h',
@@ -89,16 +91,17 @@ UNIFIED_SOURCES += [
     'CSS.cpp',
     'CSSRuleList.cpp',
     'CSSStyleSheet.cpp',
     'CSSVariableDeclarations.cpp',
     'CSSVariableResolver.cpp',
     'CSSVariableValues.cpp',
     'Declaration.cpp',
     'ErrorReporter.cpp',
+    'FontFace.cpp',
     'ImageLoader.cpp',
     'Loader.cpp',
     'MediaQueryList.cpp',
     'nsAnimationManager.cpp',
     'nsComputedDOMStyle.cpp',
     'nsCSSAnonBoxes.cpp',
     'nsCSSDataBlock.cpp',
     'nsCSSKeywords.cpp',
@@ -130,18 +133,20 @@ UNIFIED_SOURCES += [
     'nsStyleUtil.cpp',
     'nsTransitionManager.cpp',
     'StyleAnimationValue.cpp',
     'StyleRule.cpp',
     'SVGAttrAnimationRuleProcessor.cpp',
 ]
 
 # nsCSSRuleProcessor.cpp needs to be built separately because it uses plarena.h.
-# nsFontFaceLoader.cpp needs to be built separately because it forces NSPR logging.
+# FontFaceSet.cpp and nsFontFaceLoader.cpp need to be built separately because
+# they force NSPR logging.
 SOURCES += [
+    'FontFaceSet.cpp',
     'nsCSSRuleProcessor.cpp',
     'nsFontFaceLoader.cpp',
 ]
 
 FAIL_ON_WARNINGS = True
 
 MSVC_ENABLE_PGO = True