Bug 1028497 - Part 2: Add Web IDL interfaces for CSS Font Loading API. r=bzbarsky
authorCameron McCormack <cam@mcc.id.au>
Thu, 02 Oct 2014 12:32:05 +1000
changeset 231529 52e4991a82169afddad8f0da702a1421a6bd1019
parent 231528 37b5d218d686b9728499e87752a2805da989d27b
child 231530 1c827b73c45f272b36ec07e1f1660c07c07febd4
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)
reviewersbzbarsky
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 2: Add Web IDL interfaces for CSS Font Loading API. r=bzbarsky
dom/events/test/test_all_synthetic_events.html
dom/tests/mochitest/general/test_interfaces.html
dom/webidl/CSSFontFaceLoadEvent.webidl
dom/webidl/Document.webidl
dom/webidl/FontFace.webidl
dom/webidl/FontFaceSet.webidl
dom/webidl/FontFaceSource.webidl
dom/webidl/WorkerGlobalScope.webidl
dom/webidl/moz.build
modules/libpref/init/all.js
--- a/dom/events/test/test_all_synthetic_events.html
+++ b/dom/events/test/test_all_synthetic_events.html
@@ -97,16 +97,20 @@ const kEventConstructors = {
                                              },
   CompositionEvent:                          { create: function (aName, aProps) {
                                                          var e = document.createEvent("compositionevent");
                                                          e.initCompositionEvent(aName, aProps.bubbles, aProps.cancelable,
                                                                                 aProps.view, aProps.data, aProps.locale);
                                                          return e;
                                                        },
                                              },
+  CSSFontFaceLoadEvent:                      { create: function (aName, aProps) {
+                                                         return new CSSFontFaceLoadEvent(aName, aProps);
+                                                       },
+                                             },
   CustomEvent:                               { create: function (aName, aProps) {
                                                          return new CustomEvent(aName, aProps);
                                                        },
                                              },
   DataErrorEvent:                            { create: function (aName, aProps) {
                                                           return new DataErrorEvent(aName, aProps);
                                                        },
                                              },
--- a/dom/tests/mochitest/general/test_interfaces.html
+++ b/dom/tests/mochitest/general/test_interfaces.html
@@ -250,16 +250,18 @@ var interfaceNamesInGlobalScope =
     "CSS2Properties",
 // IMPORTANT: Do not change this list without review from a DOM peer!
     "CSSCharsetRule",
 // IMPORTANT: Do not change this list without review from a DOM peer!
     "CSSConditionRule",
 // IMPORTANT: Do not change this list without review from a DOM peer!
     "CSSCounterStyleRule",
 // IMPORTANT: Do not change this list without review from a DOM peer!
+    {name: "CSSFontFaceLoadEvent", pref: "layout.css.font-loading-api.enabled"},
+// IMPORTANT: Do not change this list without review from a DOM peer!
     "CSSFontFaceRule",
 // IMPORTANT: Do not change this list without review from a DOM peer!
     "CSSFontFeatureValuesRule",
 // IMPORTANT: Do not change this list without review from a DOM peer!
     "CSSGroupingRule",
 // IMPORTANT: Do not change this list without review from a DOM peer!
     "CSSImportRule",
 // IMPORTANT: Do not change this list without review from a DOM peer!
@@ -394,16 +396,20 @@ var interfaceNamesInGlobalScope =
     "FileReader",
 // IMPORTANT: Do not change this list without review from a DOM peer!
     {name: "FMRadio", b2g: true},
 // IMPORTANT: Do not change this list without review from a DOM peer!
     "FocusEvent",
 // IMPORTANT: Do not change this list without review from a DOM peer!
     "FormData",
 // IMPORTANT: Do not change this list without review from a DOM peer!
+    {name: "FontFace", pref: "layout.css.font-loading-api.enabled"},
+// IMPORTANT: Do not change this list without review from a DOM peer!
+    {name: "FontFaceSet", pref: "layout.css.font-loading-api.enabled"},
+// IMPORTANT: Do not change this list without review from a DOM peer!
     "GainNode",
 // IMPORTANT: Do not change this list without review from a DOM peer!
     {name: "Gamepad", b2g: false},
 // IMPORTANT: Do not change this list without review from a DOM peer!
     {name: "GamepadAxisMoveEvent", b2g: false},
 // IMPORTANT: Do not change this list without review from a DOM peer!
     {name: "GamepadButtonEvent", b2g: false},
 // IMPORTANT: Do not change this list without review from a DOM peer!
new file mode 100644
--- /dev/null
+++ b/dom/webidl/CSSFontFaceLoadEvent.webidl
@@ -0,0 +1,21 @@
+/* -*- 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
+ * http://dev.w3.org/csswg/css-font-loading/#FontFaceSet-interface
+ *
+ * Copyright © 2014 W3C® (MIT, ERCIM, Keio, Beihang), All Rights Reserved. W3C
+ * liability, trademark and document use rules apply.
+ */
+
+dictionary CSSFontFaceLoadEventInit : EventInit {
+  sequence<FontFace> fontfaces = [];
+};
+
+[Constructor(DOMString type, optional CSSFontFaceLoadEventInit eventInitDict),
+ Pref="layout.css.font-loading-api.enabled"]
+interface CSSFontFaceLoadEvent : Event {
+  [Cached, Constant] readonly attribute sequence<FontFace> fontfaces;
+};
--- a/dom/webidl/Document.webidl
+++ b/dom/webidl/Document.webidl
@@ -356,8 +356,9 @@ partial interface Document {
 };
 
 Document implements XPathEvaluator;
 Document implements GlobalEventHandlers;
 Document implements TouchEventHandlers;
 Document implements ParentNode;
 Document implements OnErrorEventHandlerForNodes;
 Document implements GeometryUtils;
+Document implements FontFaceSource;
new file mode 100644
--- /dev/null
+++ b/dom/webidl/FontFace.webidl
@@ -0,0 +1,46 @@
+/* -*- 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
+ * http://dev.w3.org/csswg/css-font-loading/#fontface-interface
+ *
+ * Copyright © 2014 W3C® (MIT, ERCIM, Keio, Beihang), All Rights Reserved. W3C
+ * liability, trademark and document use rules apply.
+ */
+
+typedef (ArrayBuffer or ArrayBufferView) BinaryData;
+
+dictionary FontFaceDescriptors {
+  DOMString style = "normal";
+  DOMString weight = "normal";
+  DOMString stretch = "normal";
+  DOMString unicodeRange = "U+0-10FFFF";
+  DOMString variant = "normal";
+  DOMString featureSettings = "normal";
+};
+
+enum FontFaceLoadStatus { "unloaded", "loading", "loaded", "error" };
+
+// Bug 1072107 is for exposing this in workers.
+// [Exposed=(Window,Worker)]
+[Constructor(DOMString family,
+             (DOMString or BinaryData) source,
+             optional FontFaceDescriptors descriptors),
+ Pref="layout.css.font-loading-api.enabled"]
+interface FontFace {
+  [SetterThrows] attribute DOMString family;
+  [SetterThrows] attribute DOMString style;
+  [SetterThrows] attribute DOMString weight;
+  [SetterThrows] attribute DOMString stretch;
+  [SetterThrows] attribute DOMString unicodeRange;
+  [SetterThrows] attribute DOMString variant;
+  [SetterThrows] attribute DOMString featureSettings;
+
+  readonly attribute FontFaceLoadStatus status;
+
+  Promise<FontFace> load();
+
+  readonly attribute Promise<FontFace> loaded;
+};
new file mode 100644
--- /dev/null
+++ b/dom/webidl/FontFaceSet.webidl
@@ -0,0 +1,63 @@
+/* -*- 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
+ * http://dev.w3.org/csswg/css-font-loading/#FontFaceSet-interface
+ *
+ * Copyright © 2014 W3C® (MIT, ERCIM, Keio, Beihang), All Rights Reserved. W3C
+ * liability, trademark and document use rules apply.
+ */
+
+enum FontFaceSetLoadStatus { "loading", "loaded" };
+
+// Bug 1072762 is for the FontFaceSet constructor.
+// [Constructor(sequence<FontFace> initialFaces)]
+[Pref="layout.css.font-loading-api.enabled"]
+interface FontFaceSet : EventTarget {
+
+  // Emulate the Set interface, until we can extend Set correctly.
+  // Implementing these commented out operations and the iterator is
+  // bug 1072101.
+  // readonly attribute unsigned long size;
+  [Throws] void add(FontFace font);
+  boolean has(FontFace font);
+  [Throws] boolean delete(FontFace font);
+  void clear();
+  // Iterator entries();
+  // Iterator keys();
+  // Iterator values();
+  // void forEach(ForEachCallback cb, optional any thisArg);
+  // FontFace iterator;
+
+  // -- events for when loading state changes
+  attribute EventHandler onloading;
+  attribute EventHandler onloadingdone;
+  attribute EventHandler onloadingerror;
+
+  // check and start loads if appropriate
+  // and fulfill promise when all loads complete
+  // Not implemented yet: bug 1072102.
+  [Throws] Promise<sequence<FontFace>> load(DOMString font, optional DOMString text = " ");
+
+  // return whether all fonts in the fontlist are loaded
+  // (does not initiate load if not available)
+  // Not implemented yet: bug 1072102.
+  // [Throws] boolean check(DOMString font, optional DOMString text = " ");
+
+  // async notification that font loading and layout operations are done
+  [Throws] readonly attribute Promise<void> ready;
+
+  // loading state, "loading" while one or more fonts loading, "loaded" otherwise
+  readonly attribute FontFaceSetLoadStatus status;
+};
+
+// This provides access to the FontFace objects in the FontFaceSet until we
+// get iterators working (bug 1072101).  Don't enable the pref for the CSS Font
+// Loading API until the iterator is available, as we don't want to expose more
+// indexed properties on the Web.
+partial interface FontFaceSet {
+  getter FontFace (unsigned long index);
+  readonly attribute unsigned long length;
+};
new file mode 100644
--- /dev/null
+++ b/dom/webidl/FontFaceSource.webidl
@@ -0,0 +1,18 @@
+/* -*- 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
+ * http://dev.w3.org/csswg/css-font-loading/#font-face-source
+ *
+ * Copyright © 2014 W3C® (MIT, ERCIM, Keio, Beihang), All Rights Reserved. W3C
+ * liability, trademark and document use rules apply.
+ */
+
+[NoInterfaceObject]
+interface FontFaceSource {
+
+  [Throws, Pref="layout.css.font-loading-api.enabled"]
+  readonly attribute FontFaceSet fonts;
+};
--- a/dom/webidl/WorkerGlobalScope.webidl
+++ b/dom/webidl/WorkerGlobalScope.webidl
@@ -34,16 +34,19 @@ partial interface WorkerGlobalScope {
   void importScripts(DOMString... urls);
 
   readonly attribute WorkerNavigator navigator;
 };
 
 WorkerGlobalScope implements WindowTimers;
 WorkerGlobalScope implements WindowBase64;
 
+// Not implemented yet: bug 1072107.
+// WorkerGlobalScope implements FontFaceSource;
+
 // Mozilla extensions
 partial interface WorkerGlobalScope {
   attribute EventHandler onclose;
 
   void dump(optional DOMString str);
 
   // XXXbz no spec for this yet, because the webperf WG is a bit dysfunctional
   readonly attribute Performance performance;
--- a/dom/webidl/moz.build
+++ b/dom/webidl/moz.build
@@ -125,16 +125,19 @@ WEBIDL_FILES = [
     'EventSource.webidl',
     'EventTarget.webidl',
     'File.webidl',
     'FileList.webidl',
     'FileMode.webidl',
     'FileReader.webidl',
     'FileReaderSync.webidl',
     'FocusEvent.webidl',
+    'FontFace.webidl',
+    'FontFaceSet.webidl',
+    'FontFaceSource.webidl',
     'FormData.webidl',
     'Function.webidl',
     'GainNode.webidl',
     'Geolocation.webidl',
     'GeometryUtils.webidl',
     'GetUserMediaRequest.webidl',
     'Headers.webidl',
     'History.webidl',
@@ -643,16 +646,17 @@ if CONFIG['MOZ_B2G_FM']:
 
 GENERATED_EVENTS_WEBIDL_FILES = [
     'AutocompleteErrorEvent.webidl',
     'BlobEvent.webidl',
     'CallEvent.webidl',
     'CallGroupErrorEvent.webidl',
     'CFStateChangeEvent.webidl',
     'CloseEvent.webidl',
+    'CSSFontFaceLoadEvent.webidl',
     'DataErrorEvent.webidl',
     'DataStoreChangeEvent.webidl',
     'DeviceLightEvent.webidl',
     'DeviceOrientationEvent.webidl',
     'DeviceProximityEvent.webidl',
     'DeviceStorageChangeEvent.webidl',
     'DOMTransactionEvent.webidl',
     'DownloadEvent.webidl',
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -2114,16 +2114,19 @@ pref("layout.css.scroll-behavior.spring-
 // oscillate.
 // When greater than 1.0, the system is over-damped; it will reach the target at
 // reduced speed without overshooting.
 // When equal to 1.0, the system is critically-damped; it will reach the target
 // at the greatest speed without overshooting.
 pref("layout.css.scroll-behavior.damping-ratio", "1.0");
 
 // Is support for document.fonts enabled?
+//
+// Don't enable the pref for the CSS Font Loading API until bug 1072101 is
+// fixed, as we don't want to expose more indexed properties on the Web.
 pref("layout.css.font-loading-api.enabled", false);
 
 // pref for which side vertical scrollbars should be on
 // 0 = end-side in UI direction
 // 1 = end-side in document/content direction
 // 2 = right
 // 3 = left
 pref("layout.scrollbar.side", 0);