Bug 917755. Part 5.5: Implement getBoxQuads DOM API. r=jst
authorRobert O'Callahan <robert@ocallahan.org>
Wed, 12 Mar 2014 09:11:38 +0800
changeset 175050 01597ae3e0aa53e5f79930f8665da6c634842e49
parent 175049 d5ffda84968f25999862bb2af49ced96ed719c0a
child 175051 9ae5146d1267816f241a9eeae589a57a3f53ab0f
push id271
push userpvanderbeken@mozilla.com
push dateMon, 24 Mar 2014 22:43:42 +0000
reviewersjst
bugs917755
milestone31.0a1
Bug 917755. Part 5.5: Implement getBoxQuads DOM API. r=jst
content/base/public/nsINode.h
content/base/src/nsINode.cpp
dom/webidl/GeometryUtils.webidl
dom/webidl/moz.build
modules/libpref/src/init/all.js
--- a/content/base/public/nsINode.h
+++ b/content/base/public/nsINode.h
@@ -61,16 +61,18 @@ inline bool IsSpaceCharacter(char16_t aC
   return aChar == ' ' || aChar == '\t' || aChar == '\n' || aChar == '\r' ||
          aChar == '\f';
 }
 inline bool IsSpaceCharacter(char aChar) {
   return aChar == ' ' || aChar == '\t' || aChar == '\n' || aChar == '\r' ||
          aChar == '\f';
 }
 class Element;
+struct BoxQuadOptions;
+class DOMQuad;
 class EventHandlerNonNull;
 class OnErrorEventHandlerNonNull;
 template<typename T> class Optional;
 } // namespace dom
 } // namespace mozilla
 
 #define NODE_FLAG_BIT(n_) (1U << (WRAPPER_CACHE_FLAGS_BITS_USED + (n_)))
 
@@ -274,16 +276,20 @@ private:
 /**
  * An internal interface that abstracts some DOMNode-related parts that both
  * nsIContent and nsIDocument share.  An instance of this interface has a list
  * of nsIContent children and provides access to them.
  */
 class nsINode : public mozilla::dom::EventTarget
 {
 public:
+  typedef mozilla::dom::BoxQuadOptions BoxQuadOptions;
+  typedef mozilla::dom::DOMQuad DOMQuad;
+  typedef mozilla::ErrorResult ErrorResult;
+
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_INODE_IID)
 
   // Among the sub-classes that inherit (directly or indirectly) from nsINode,
   // measurement of the following members may be added later if DMD finds it is
   // worthwhile:
   // - nsGenericHTMLElement:  mForm, mFieldSet
   // - nsGenericHTMLFrameElement: mFrameLoader (bug 672539)
   // - HTMLBodyElement:       mContentStyleRule
@@ -1605,16 +1611,20 @@ public:
    * Remove this node from its parent, if any.
    */
   void Remove();
 
   // ParentNode methods
   mozilla::dom::Element* GetFirstElementChild() const;
   mozilla::dom::Element* GetLastElementChild() const;
 
+  void GetBoxQuads(const BoxQuadOptions& aOptions,
+                   nsTArray<nsRefPtr<DOMQuad> >& aResult,
+                   mozilla::ErrorResult& aRv);
+
 protected:
 
   // Override this function to create a custom slots class.
   // Must not return null.
   virtual nsINode::nsSlots* CreateSlots();
 
   bool HasSlots() const
   {
--- a/content/base/src/nsINode.cpp
+++ b/content/base/src/nsINode.cpp
@@ -98,16 +98,17 @@
 #include "nsCSSParser.h"
 #include "HTMLLegendElement.h"
 #include "nsWrapperCacheInlines.h"
 #include "WrapperFactory.h"
 #include "DocumentType.h"
 #include <algorithm>
 #include "nsGlobalWindow.h"
 #include "nsDOMMutationObserver.h"
+#include "GeometryUtils.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
 nsINode::nsSlots::~nsSlots()
 {
   if (mChildNodes) {
     mChildNodes->DropReference();
@@ -1135,16 +1136,24 @@ NS_IMPL_REMOVE_SYSTEM_EVENT_LISTENER(nsI
 nsresult
 nsINode::PreHandleEvent(EventChainPreVisitor& aVisitor)
 {
   // This is only here so that we can use the NS_DECL_NSIDOMTARGET macro
   NS_ABORT();
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
+void
+nsINode::GetBoxQuads(const BoxQuadOptions& aOptions,
+                     nsTArray<nsRefPtr<DOMQuad> >& aResult,
+                     mozilla::ErrorResult& aRv)
+{
+  mozilla::GetBoxQuads(this, aOptions, aResult, aRv);
+}
+
 nsresult
 nsINode::DispatchEvent(nsIDOMEvent *aEvent, bool* aRetVal)
 {
   // XXX sXBL/XBL2 issue -- do we really want the owner here?  What
   // if that's the XBL document?  Would we want its presshell?  Or what?
   nsCOMPtr<nsIDocument> document = OwnerDoc();
 
   // Do nothing if the element does not belong to a document
new file mode 100644
--- /dev/null
+++ b/dom/webidl/GeometryUtils.webidl
@@ -0,0 +1,38 @@
+/* -*- 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/cssom-view/
+ *
+ * Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
+ * liability, trademark and document use rules apply.
+ */
+
+enum CSSBoxType { "margin", "border", "padding", "content" };
+dictionary BoxQuadOptions {
+  CSSBoxType box = "border";
+  GeometryNode relativeTo;
+};
+
+dictionary ConvertCoordinateOptions {
+  CSSBoxType fromBox = "border";
+  CSSBoxType toBox = "border";
+};
+
+[NoInterfaceObject]
+interface GeometryUtils {
+  [Throws, Pref="layout.css.getBoxQuads.enabled"]
+  sequence<DOMQuad> getBoxQuads(optional BoxQuadOptions options);
+//  DOMQuad convertQuadFromNode(DOMQuad quad, GeometryNode from, optional ConvertCoordinateOptions options);
+//  DOMQuad convertRectFromNode(DOMRectReadOnly rect, GeometryNode from, optional ConvertCoordinateOptions options);
+//  DOMPoint convertPointFromNode(DOMPointInit point, GeometryNode from, optional ConvertCoordinateOptions options);
+};
+
+Text implements GeometryUtils;
+Element implements GeometryUtils;
+// PseudoElement implements GeometryUtils;
+Document implements GeometryUtils;
+
+typedef (Text or Element /* or PseudoElement */ or Document) GeometryNode;
\ No newline at end of file
--- a/dom/webidl/moz.build
+++ b/dom/webidl/moz.build
@@ -110,16 +110,17 @@ WEBIDL_FILES = [
     'FileReader.webidl',
     'FileReaderSync.webidl',
     'FileRequest.webidl',
     'FocusEvent.webidl',
     'FormData.webidl',
     'Function.webidl',
     'GainNode.webidl',
     'Geolocation.webidl',
+    'GeometryUtils.webidl',
     'GetUserMediaRequest.webidl',
     'History.webidl',
     'HTMLAnchorElement.webidl',
     'HTMLAppletElement.webidl',
     'HTMLAreaElement.webidl',
     'HTMLAudioElement.webidl',
     'HTMLBaseElement.webidl',
     'HTMLBodyElement.webidl',
--- a/modules/libpref/src/init/all.js
+++ b/modules/libpref/src/init/all.js
@@ -1811,16 +1811,23 @@ pref("layout.css.sticky.enabled", true);
 pref("layout.css.will-change.enabled", false);
 
 // Is support for DOMPoint enabled?
 pref("layout.css.DOMPoint.enabled", true);
 
 // Is support for DOMQuad enabled?
 pref("layout.css.DOMQuad.enabled", true);
 
+// Is support for GeometryUtils.getBoxQuads enabled?
+#ifdef RELEASE_BUILD
+pref("layout.css.getBoxQuads.enabled", false);
+#else
+pref("layout.css.getBoxQuads.enabled", true);
+#endif
+
 // Is support for CSS "text-align: true X" enabled?
 pref("layout.css.text-align-true-value.enabled", false);
 
 // Is support for the CSS4 image-orientation property enabled?
 pref("layout.css.image-orientation.enabled", true);
 
 // Is support for CSS3 Fonts features enabled?
 // (includes font-variant-*, font-kerning, font-synthesis