Bug 1247420 - part1: removeContentState. r=smaug
authorGabor Krizsanits <gkrizsanits@mozilla.com>
Wed, 30 Mar 2016 11:54:27 +0200
changeset 291069 d791887510c81cbea2d241054c6494bd4b712efb
parent 291068 9b0efb1e937b20d69d596c778849b0163b4cba45
child 291070 61241975d4dab068524ab4c77eb045f79815c058
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1247420
milestone48.0a1
Bug 1247420 - part1: removeContentState. r=smaug
layout/inspector/inDOMUtils.cpp
layout/inspector/inIDOMUtils.idl
layout/inspector/tests/test_bug462789.html
--- a/layout/inspector/inDOMUtils.cpp
+++ b/layout/inspector/inDOMUtils.cpp
@@ -1090,31 +1090,46 @@ inDOMUtils::GetBindingURLs(nsIDOMElement
   }
 
   urls.forget(_retval);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 inDOMUtils::SetContentState(nsIDOMElement* aElement,
-                            EventStates::InternalType aState)
+                            EventStates::InternalType aState,
+                            bool* aRetVal)
 {
   NS_ENSURE_ARG_POINTER(aElement);
 
   RefPtr<EventStateManager> esm =
     inLayoutUtils::GetEventStateManagerFor(aElement);
-  if (esm) {
-    nsCOMPtr<nsIContent> content;
-    content = do_QueryInterface(aElement);
+  NS_ENSURE_TRUE(esm, NS_ERROR_INVALID_ARG);
+
+  nsCOMPtr<nsIContent> content;
+  content = do_QueryInterface(aElement);
+  NS_ENSURE_TRUE(content, NS_ERROR_INVALID_ARG);
+
+  *aRetVal = esm->SetContentState(content, EventStates(aState));
+  return NS_OK;
+}
 
-    // XXX Invalid cast of bool to nsresult (bug 778108)
-    return (nsresult)esm->SetContentState(content, EventStates(aState));
-  }
+NS_IMETHODIMP
+inDOMUtils::RemoveContentState(nsIDOMElement* aElement,
+                               EventStates::InternalType aState,
+                               bool* aRetVal)
+{
+  NS_ENSURE_ARG_POINTER(aElement);
 
-  return NS_ERROR_FAILURE;
+  RefPtr<EventStateManager> esm =
+    inLayoutUtils::GetEventStateManagerFor(aElement);
+  NS_ENSURE_TRUE(esm, NS_ERROR_INVALID_ARG);
+
+  *aRetVal = esm->SetContentState(nullptr, EventStates(aState));
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 inDOMUtils::GetContentState(nsIDOMElement* aElement,
                             EventStates::InternalType* aState)
 {
   *aState = 0;
   nsCOMPtr<nsIContent> content = do_QueryInterface(aElement);
--- a/layout/inspector/inIDOMUtils.idl
+++ b/layout/inspector/inIDOMUtils.idl
@@ -12,17 +12,17 @@ interface nsIDOMDocument;
 interface nsIDOMCSSRule;
 interface nsIDOMCSSStyleRule;
 interface nsIDOMNode;
 interface nsIDOMNodeList;
 interface nsIDOMFontFaceList;
 interface nsIDOMRange;
 interface nsIDOMCSSStyleSheet;
 
-[scriptable, uuid(ec3dc3d5-41d1-4d08-ace5-7e944de6614d)]
+[scriptable, uuid(362e98c3-82c2-4ad8-8dcb-00e8e4eab497)]
 interface inIDOMUtils : nsISupports
 {
   // CSS utilities
   void getAllStyleSheets (in nsIDOMDocument aDoc,
                           [optional] out unsigned long aLength,
                           [array, size_is (aLength), retval] out nsISupports aSheets);
   nsISupportsArray getCSSStyleRules(in nsIDOMElement aElement, [optional] in DOMString aPseudo);
 
@@ -153,17 +153,27 @@ interface inIDOMUtils : nsISupports
   nsIDOMNodeList getChildrenForNode(in nsIDOMNode aNode,
                                     in boolean aShowingAnonymousContent);
   
   // XBL utilities
   nsIArray getBindingURLs(in nsIDOMElement aElement);
 
   // content state utilities
   unsigned long long getContentState(in nsIDOMElement aElement);
-  void setContentState(in nsIDOMElement aElement, in unsigned long long aState);
+  /**
+   * Setting and removing content state on an element. Both these functions
+   * calling EventStateManager::SetContentState internally, the difference is
+   * that for the remove case we simply pass in nullptr for the element.
+   * Use them accordingly.
+   *
+   * @return Returns true if the state was set successfully. See more details
+   * in EventStateManager.h SetContentState.
+   */
+  bool setContentState(in nsIDOMElement aElement, in unsigned long long aState);
+  bool removeContentState(in nsIDOMElement aElement, in unsigned long long aState);
 
   nsIDOMFontFaceList getUsedFontFaces(in nsIDOMRange aRange);
 
   /**
    * Get the names of all the supported pseudo-elements.
    * Pseudo-elements which are only accepted in UA style sheets are
    * not included.
    *
--- a/layout/inspector/tests/test_bug462789.html
+++ b/layout/inspector/tests/test_bug462789.html
@@ -15,17 +15,17 @@ https://bugzilla.mozilla.org/show_bug.cg
   
 </div>
 <pre id="test">
 <script type="application/javascript">
 
 /** Test for Bug 462789 **/
 
 function do_test() {
-  const ERROR_FAILURE = 0x80004005;
+  const ERROR_INVALID_ARG = 0x80070057;
   const DOCUMENT_NODE_TYPE = 9;
 
   var utils = SpecialPowers.Cc["@mozilla.org/inspector/dom-utils;1"]
                              .getService(SpecialPowers.Ci.inIDOMUtils);
 
   var iframe = document.getElementById("bug462789_iframe");
   var docElement = iframe.contentDocument.documentElement;
   var body = docElement.children[1];
@@ -74,17 +74,17 @@ function do_test() {
   catch(e) { ok(false, "Got an exception: " + e); }
 
   try {
     utils.setContentState(docElement, false);
     ok(false, "expected an exception"); 
   }
   catch(e) {
     e = SpecialPowers.wrap(e);
-    is(e.result, ERROR_FAILURE, "got the expected exception");
+    is(e.result, ERROR_INVALID_ARG, "got the expected exception");
   }
 
   SimpleTest.finish();
 }
 
 SimpleTest.waitForExplicitFinish();
 addLoadEvent(do_test);