Bug 1558546, ensure range element has a frame before starting drag operation, r=hsivonen a=jcristau
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Wed, 12 Jun 2019 15:53:48 +0000
changeset 536934 44d7135f115d5ca4d150424b2b425841d2db4139
parent 536933 545958c08c72b81767cd8460ce82d4d130dfbbbb
child 536935 4c434d19d03d5461e54fa22dfb82eaed4cd6631b
push id2082
push userffxbld-merge
push dateMon, 01 Jul 2019 08:34:18 +0000
treeherdermozilla-release@2fb19d0466d2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershsivonen, jcristau
bugs1558546
milestone68.0
Bug 1558546, ensure range element has a frame before starting drag operation, r=hsivonen a=jcristau This should be the minimal patch to fix the issue (should be safe for branches too). Reusing an existing mouse/touch test for the crash testing. Differential Revision: https://phabricator.services.mozilla.com/D34717
dom/html/HTMLInputElement.cpp
dom/html/test/forms/test_input_range_mouse_and_touch_events.html
--- a/dom/html/HTMLInputElement.cpp
+++ b/dom/html/HTMLInputElement.cpp
@@ -3407,22 +3407,26 @@ nsresult HTMLInputElement::PreHandleEven
     if (weakNumberControlFrame.IsAlive()) {
       numberControlFrame->HandlingInputEvent(false);
     }
   }
   return rv;
 }
 
 void HTMLInputElement::StartRangeThumbDrag(WidgetGUIEvent* aEvent) {
+  nsRangeFrame* rangeFrame = do_QueryFrame(GetPrimaryFrame());
+  if (!rangeFrame) {
+    return;
+  }
+
   mIsDraggingRange = true;
   mRangeThumbDragStartValue = GetValueAsDecimal();
   // Don't use CaptureFlags::RetargetToElement, as that breaks pseudo-class
   // styling of the thumb.
   PresShell::SetCapturingContent(this, CaptureFlags::IgnoreAllowedState);
-  nsRangeFrame* rangeFrame = do_QueryFrame(GetPrimaryFrame());
 
   // Before we change the value, record the current value so that we'll
   // correctly send a 'change' event if appropriate. We need to do this here
   // because the 'focus' event is handled after the 'mousedown' event that
   // we're being called for (i.e. too late to update mFocusedValue, since we'll
   // have changed it by then).
   GetValue(mFocusedValue, CallerType::System);
 
--- a/dom/html/test/forms/test_input_range_mouse_and_touch_events.html
+++ b/dom/html/test/forms/test_input_range_mouse_and_touch_events.html
@@ -196,14 +196,32 @@ function test(synthesizeFunc, clickOrTap
   synthesizeFunc(elem, midX+100, midY, { type: moveName });
   is(elem.value, MAXIMUM_OF_RANGE, "Test " + moveName + " outside range after key press that occurred during a drag changes the value");
   synthesizeFunc(elem, midX, midY, { type: moveName });
   is(elem.value, MIDDLE_OF_RANGE, "Test " + moveName + " in middle of range");
   synthesizeKey("KEY_Home");
   //is(elem.value, MINIMUM_OF_RANGE, "Test KEY_Home during a drag sets the value to the minimum of the range (second time)");
   synthesizeFunc(elem, maxX+100, midY, { type: endName });
   is(elem.value, MAXIMUM_OF_RANGE, "Test " + endName + " outside range after key press that occurred during a drag changes the value");
+
+  function hideElement() {
+    elem.parentNode.style.display = 'none';
+    elem.parentNode.offsetLeft;
+  }
+
+  if (clickOrTap == "click") {
+    elem.addEventListener("mousedown", hideElement);
+  } else if (clickOrTap == "tap") {
+    elem.addEventListener("touchstart", hideElement);
+  }
+  synthesizeFunc(elem, midX, midY, { type: startName });
+  synthesizeFunc(elem, midX, midY, { type: endName });
+  elem.removeEventListener("mousedown", hideElement);
+  elem.removeEventListener("touchstart", hideElement);
+  ok(true, "Hiding the element during mousedown/touchstart shouldn't crash the process.");
+  elem.parentNode.style.display = "block";
+  elem.parentNode.offsetLeft;
 }
 
 </script>
 </pre>
 </body>
 </html>