From 39ab9e9583d60639bd3baf458ccfba5612c2b5de Mon Sep 17 00:00:00 2001 From: Neil Deakin Date: Mon, 8 Sep 2008 12:09:35 -0400 Subject: [PATCH] Bug 452787, change to ignore selection when inside a draggable html element, r=smaug,sr=roc --- content/base/public/nsContentUtils.h | 4 +--- content/base/src/nsContentUtils.cpp | 21 +++++++++++++++++++++ content/events/src/nsEventStateManager.cpp | 11 +++-------- content/events/test/test_dragstart.html | 8 +++++--- 4 files changed, 30 insertions(+), 14 deletions(-) diff --git a/content/base/public/nsContentUtils.h b/content/base/public/nsContentUtils.h index f1d89059809..9be08e654c3 100644 --- a/content/base/public/nsContentUtils.h +++ b/content/base/public/nsContentUtils.h @@ -665,9 +665,7 @@ public: * @param aContent The content node to test. * @return whether it's draggable */ - static PRBool ContentIsDraggable(nsIContent* aContent) { - return IsDraggableImage(aContent) || IsDraggableLink(aContent); - } + static PRBool ContentIsDraggable(nsIContent* aContent); /** * Method that decides whether a content node is a draggable image diff --git a/content/base/src/nsContentUtils.cpp b/content/base/src/nsContentUtils.cpp index e1d990ca810..af8b8ae2990 100644 --- a/content/base/src/nsContentUtils.cpp +++ b/content/base/src/nsContentUtils.cpp @@ -89,6 +89,7 @@ #include "nsIDOMHTMLDocument.h" #include "nsIDOMHTMLCollection.h" #include "nsIDOMHTMLFormElement.h" +#include "nsIDOMNSHTMLElement.h" #include "nsIForm.h" #include "nsIFormControl.h" #include "nsGkAtoms.h" @@ -2453,6 +2454,26 @@ nsContentUtils::GetImageFromContent(nsIImageLoadingContent* aContent, return image; } +// static +PRBool +nsContentUtils::ContentIsDraggable(nsIContent* aContent) +{ + nsCOMPtr htmlElement = do_QueryInterface(aContent); + if (htmlElement) { + PRBool draggable = PR_FALSE; + htmlElement->GetDraggable(&draggable); + if (draggable) + return PR_TRUE; + + if (aContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::draggable, + nsGkAtoms::_false, eIgnoreCase) + return PR_FALSE; + } + + // special handling for content area image and link dragging + return IsDraggableImage(aContent) || IsDraggableLink(aContent); +} + // static PRBool nsContentUtils::IsDraggableImage(nsIContent* aContent) diff --git a/content/events/src/nsEventStateManager.cpp b/content/events/src/nsEventStateManager.cpp index 2d659614f1f..18c964dcc83 100644 --- a/content/events/src/nsEventStateManager.cpp +++ b/content/events/src/nsEventStateManager.cpp @@ -2143,14 +2143,9 @@ nsEventStateManager::DetermineDragTarget(nsPresContext* aPresContext, } // if no node in the hierarchy was found to drag, but the GetDragData method - // returned a node, use that returned node. Otherwise, just use the original - // node that was clicked. - if (!dragContent) { - if (dragDataNode) - dragContent = originalDragContent; - else - dragContent = mGestureDownContent; - } + // returned a node, use that returned node. Otherwise, nothing is draggable. + if (!dragContent && dragDataNode) + dragContent = dragDataNode; if (dragContent) { // if an ancestor node was used instead, clear the drag data diff --git a/content/events/test/test_dragstart.html b/content/events/test/test_dragstart.html index 271dca52488..27728a9eaf2 100644 --- a/content/events/test/test_dragstart.html +++ b/content/events/test/test_dragstart.html @@ -82,6 +82,10 @@ function afterDragTests() sendMouseEventsForDrag("dragfalse"); gDragInfo = { target: $("spanfalse").firstChild, testid: "draggable false child" }; sendMouseEventsForDrag("spanfalse"); + + synthesizeMouse(draggable, 12, 12, { type: "mouseup" }); + if (gExtraDragTests == 4) + SimpleTest.finish(); } function sendMouseEventsForDrag(nodeid) @@ -462,8 +466,6 @@ function onDragStartDraggable(event) ok(dt.mozItemCount == 0 && dt.types.length == 0 && event.originalTarget == gDragInfo.target, gDragInfo.testid); gExtraDragTests++; - if (gExtraDragTests == 6) - SimpleTest.finish(); } function checkOneDataItem(dt, expectedtypes, expecteddata, index, testid) @@ -528,7 +530,7 @@ function expectError(fn, eid, testid) -
+
This is a draggable area.