Fix for bug 815158 (Make HTMLElement.ontouch* work with tristate dom.w3c_touch_events.enabled). r=bz.
authorPeter Van der Beken <peterv@propagandism.org>
Mon, 19 Nov 2012 11:59:13 +0100
changeset 114344 7be28e2ce121d880e1bd8c5c7912191a46cf2cf7
parent 114343 57b33c0ff8bd79f6fbe5b8a1b64747bdd0f5fb14
child 114345 3db4085a10b2fcb585cbc19f15012e69bf218e2d
push id23913
push useremorley@mozilla.com
push dateWed, 28 Nov 2012 17:11:31 +0000
treeherdermozilla-central@17c267a881cf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs815158
milestone20.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
Fix for bug 815158 (Make HTMLElement.ontouch* work with tristate dom.w3c_touch_events.enabled). r=bz.
content/html/content/src/nsGenericHTMLElement.cpp
content/html/content/src/nsGenericHTMLElement.h
dom/webidl/HTMLElement.webidl
--- a/content/html/content/src/nsGenericHTMLElement.cpp
+++ b/content/html/content/src/nsGenericHTMLElement.cpp
@@ -95,16 +95,17 @@
 #include "HTMLPropertiesCollection.h"
 #include "nsVariant.h"
 #include "nsDOMSettableTokenList.h"
 #include "nsThreadUtils.h"
 #include "nsTextFragment.h"
 #include "mozilla/dom/BindingUtils.h"
 #include "mozilla/ErrorResult.h"
 #include "nsHTMLDocument.h"
+#include "nsDOMTouchEvent.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
 class nsINodeInfo;
 class nsIDOMNodeList;
 class nsRuleWalker;
 
@@ -2901,16 +2902,34 @@ nsGenericHTMLElement::GetContextMenu(nsI
 
 bool
 nsGenericHTMLElement::IsLabelable() const
 {
   return Tag() == nsGkAtoms::progress ||
          Tag() == nsGkAtoms::meter;
 }
 
+// static
+bool
+nsGenericHTMLElement::PrefEnabled()
+{
+  // This is a bit of a hack because we don't support non-bool prefs to enable
+  // properties. This function will be called every time a HTMLElement interface
+  // prototype object is created. The first time this is called we set a boolean
+  // pref (dom.w3c_touch_events.expose) which controls the touch event
+  // properties on HTMLElement.
+  static bool sDidSetPref = false;
+  if (!sDidSetPref) {
+    sDidSetPref = true;
+    Preferences::SetBool("dom.w3c_touch_events.expose",
+                         nsDOMTouchEvent::PrefEnabled());
+  }
+  return true;
+}
+
 //----------------------------------------------------------------------
 
 nsGenericHTMLFormElement::nsGenericHTMLFormElement(already_AddRefed<nsINodeInfo> aNodeInfo)
   : nsGenericHTMLElement(aNodeInfo)
   , mForm(nullptr)
   , mFieldSet(nullptr)
 {
   // We should add the NS_EVENT_STATE_ENABLED bit here as needed, but
--- a/content/html/content/src/nsGenericHTMLElement.h
+++ b/content/html/content/src/nsGenericHTMLElement.h
@@ -710,16 +710,18 @@ public:
 
   bool IsHidden() const
   {
     return HasAttr(kNameSpaceID_None, nsGkAtoms::hidden);
   }
 
   virtual bool IsLabelable() const;
 
+  static bool PrefEnabled();
+
 protected:
   /**
    * Add/remove this element to the documents name cache
    */
   void AddToNameTable(nsIAtom* aName) {
     NS_ASSERTION(HasName(), "Node doesn't have name?");
     nsIDocument* doc = GetCurrentDoc();
     if (doc && !IsInAnonymousSubtree()) {
--- a/dom/webidl/HTMLElement.webidl
+++ b/dom/webidl/HTMLElement.webidl
@@ -10,16 +10,17 @@
  * © Copyright 2004-2011 Apple Computer, Inc., Mozilla Foundation, and
  * Opera Software ASA. You are granted a license to use, reproduce
  * and create derivative works of this document.
  */
 
 interface DOMStringMap;
 interface HTMLMenuElement;
 
+[PrefControlled]
 interface HTMLElement : Element {
   // metadata attributes
            attribute DOMString title;
            attribute DOMString lang;
   //         attribute boolean translate;
   [SetterThrows]
            attribute DOMString dir;
   readonly attribute DOMStringMap dataset;
@@ -202,27 +203,27 @@ interface HTMLElement : Element {
 
   [SetterThrows,LenientThis]
            attribute EventHandler onmouseenter;
   [SetterThrows,LenientThis]
            attribute EventHandler onmouseleave;
   [SetterThrows]
            attribute EventHandler onwheel;
 
-  [SetterThrows,Pref="dom.w3c_touch_events.enabled"]
+  [SetterThrows,Pref="dom.w3c_touch_events.expose"]
            attribute EventHandler ontouchstart;
-  [SetterThrows,Pref="dom.w3c_touch_events.enabled"]
+  [SetterThrows,Pref="dom.w3c_touch_events.expose"]
            attribute EventHandler ontouchend;
-  [SetterThrows,Pref="dom.w3c_touch_events.enabled"]
+  [SetterThrows,Pref="dom.w3c_touch_events.expose"]
            attribute EventHandler ontouchmove;
-  [SetterThrows,Pref="dom.w3c_touch_events.enabled"]
+  [SetterThrows,Pref="dom.w3c_touch_events.expose"]
            attribute EventHandler ontouchenter;
-  [SetterThrows,Pref="dom.w3c_touch_events.enabled"]
+  [SetterThrows,Pref="dom.w3c_touch_events.expose"]
            attribute EventHandler ontouchleave;
-  [SetterThrows,Pref="dom.w3c_touch_events.enabled"]
+  [SetterThrows,Pref="dom.w3c_touch_events.expose"]
            attribute EventHandler ontouchcancel;
 
   [SetterThrows]
            attribute EventHandler oncopy;
   [SetterThrows]
            attribute EventHandler oncut;
   [SetterThrows]
            attribute EventHandler onpaste;