Commit 97f51aaa authored by Artur Signell's avatar Artur Signell
Browse files

dragndrop: Allow drag'n'drop to start from elements inside a shadow root (Bug 1521471) r=emilio

Before this change, only elements inside the shadow root tree were scanned for the
draggable=true attribute. We now check the flattened tree instead so an element
inside a shadow root can start a drag for an element containing the shadow root.

Differential Revision: https://phabricator.services.mozilla.com/D30365

--HG--
extra : moz-landing-system : lando
parent 97c03720
Loading
Loading
Loading
Loading
+31 −1
Original line number Original line Diff line number Diff line
@@ -68,6 +68,9 @@ function afterDragTests()
//  synthesizeMouse(draggable, 15, 15, { type: "mousemove" });
//  synthesizeMouse(draggable, 15, 15, { type: "mousemove" });
//  sendMouseEventsForDrag("input");
//  sendMouseEventsForDrag("input");


  // draggable element inside a shadow root
  sendMouseEventsForShadowRootDrag();

  // next, check if the draggable attribute can be used to adjust the drag target
  // next, check if the draggable attribute can be used to adjust the drag target
  gDragInfo = { target: $("dragtrue"), testid: "draggable true node" };
  gDragInfo = { target: $("dragtrue"), testid: "draggable true node" };
  sendMouseEventsForDrag("dragtrue");
  sendMouseEventsForDrag("dragtrue");
@@ -79,7 +82,7 @@ function afterDragTests()
  sendMouseEventsForDrag("spanfalse");
  sendMouseEventsForDrag("spanfalse");


  synthesizeMouse(draggable, 12, 12, { type: "mouseup" });
  synthesizeMouse(draggable, 12, 12, { type: "mouseup" });
  if (gExtraDragTests == 4)
  if (gExtraDragTests == 5)
    SimpleTest.finish();
    SimpleTest.finish();
}
}


@@ -90,6 +93,13 @@ function sendMouseEventsForDrag(nodeid)
  synthesizeMouse(draggable, 10, 10, { type: "mousemove" });
  synthesizeMouse(draggable, 10, 10, { type: "mousemove" });
  synthesizeMouse(draggable, 12, 12, { type: "mousemove" });
  synthesizeMouse(draggable, 12, 12, { type: "mousemove" });
}
}
function sendMouseEventsForShadowRootDrag()
{
  var draggable = $("shadow_host_containing_draggable").shadowRoot.firstElementChild;
  synthesizeMouse(draggable, 3, 3, { type: "mousedown" });
  synthesizeMouse(draggable, 10, 10, { type: "mousemove" });
  synthesizeMouse(draggable, 12, 12, { type: "mousemove" });
}


function doDragStartSelection(event)
function doDragStartSelection(event)
{
{
@@ -454,6 +464,18 @@ function doDragStartInput(event)
//  event.preventDefault();
//  event.preventDefault();
}
}



function doDragStartInShadowRoot(event)
{
  is(event.type, "dragstart", "shadow root dragstart event type");
  is(event.target, $("shadow_host_containing_draggable"), "shadow root dragstart event target");
  is(event.bubbles, true, "shadow root dragstart event bubbles");
  is(event.cancelable, true, "shadow root dragstart event cancelable");

  event.preventDefault();

  gExtraDragTests++;
}
function doDragStartSynthetic(event)
function doDragStartSynthetic(event)
{
{
  is(event.type, "dragstart", "synthetic dragstart event type");
  is(event.type, "dragstart", "synthetic dragstart event type");
@@ -596,5 +618,13 @@ function expectError(fn, eid, testid)
<div id="synthetic" ondragstart="doDragStartSynthetic(event)">Synthetic Event Dispatch</div>
<div id="synthetic" ondragstart="doDragStartSynthetic(event)">Synthetic Event Dispatch</div>
<div id="synthetic2" ondragover="doDragOverSynthetic(event)">Synthetic Event Dispatch</div>
<div id="synthetic2" ondragover="doDragOverSynthetic(event)">Synthetic Event Dispatch</div>


<div draggable="true" id="shadow_host_containing_draggable"></div>

<script>
shadow_host_containing_draggable.attachShadow({ mode: 'open' }).innerHTML = 
`<span>Inside shadow root</span>`;
shadow_host_containing_draggable.addEventListener("dragstart", doDragStartInShadowRoot);

</script>
</body>
</body>
</html>
</html>
+1 −1
Original line number Original line Diff line number Diff line
@@ -4249,7 +4249,7 @@ nsFrame::HandlePress(nsPresContext* aPresContext, WidgetGUIEvent* aEvent,


  if (!mouseEvent->IsAlt()) {
  if (!mouseEvent->IsAlt()) {
    for (nsIContent* content = mContent; content;
    for (nsIContent* content = mContent; content;
         content = content->GetParent()) {
         content = content->GetFlattenedTreeParent()) {
      if (nsContentUtils::ContentIsDraggable(content) &&
      if (nsContentUtils::ContentIsDraggable(content) &&
          !content->IsEditable()) {
          !content->IsEditable()) {
        // coordinate stuff is the fix for bug #55921
        // coordinate stuff is the fix for bug #55921