Author: yradtsevich
Date: 2010-04-21 05:10:45 -0400 (Wed, 21 Apr 2010)
New Revision: 21574
Added:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/dnd/VpeDnDHelper.java
Removed:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/dnd/
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/META-INF/MANIFEST.MF
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/dnd/DndUtil.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/dnd/DropableArea.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/dnd/VpeDnD.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeSelectionBuilder.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeSourceDomBuilder.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualCaretInfo.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaEventAdapter.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/listener/MozillaDndListener.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeAbstractTemplate.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-5042
Enhance DnD support in VPE
- Highlighting of drop container has been added.
- Drop algorithm has been rewritten.
- Code has been refactored.
Modified: trunk/vpe/plugins/org.jboss.tools.vpe/META-INF/MANIFEST.MF
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/META-INF/MANIFEST.MF 2010-04-21 08:46:06 UTC
(rev 21573)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/META-INF/MANIFEST.MF 2010-04-21 09:10:45 UTC
(rev 21574)
@@ -26,7 +26,6 @@
org.jboss.tools.vpe.editor.selection,
org.jboss.tools.vpe.editor.template,
org.jboss.tools.vpe.editor.template.custom,
- org.jboss.tools.vpe.editor.template.dnd,
org.jboss.tools.vpe.editor.template.expression,
org.jboss.tools.vpe.editor.template.resize,
org.jboss.tools.vpe.editor.template.textformating,
Modified: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/dnd/DndUtil.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/dnd/DndUtil.java 2010-04-21
08:46:06 UTC (rev 21573)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/dnd/DndUtil.java 2010-04-21
09:10:45 UTC (rev 21574)
@@ -27,6 +27,7 @@
import org.mozilla.interfaces.nsIDOMDocument;
import org.mozilla.interfaces.nsIDOMElement;
import org.mozilla.interfaces.nsIDOMNSDocument;
+import org.mozilla.interfaces.nsIDOMNode;
import org.mozilla.interfaces.nsIDragService;
import org.mozilla.interfaces.nsIDragSession;
import org.mozilla.interfaces.nsIServiceManager;
@@ -234,10 +235,13 @@
}
}
- public static nsIDOMElement getElementFromPoint(nsIDOMNSDocument document,
- int x, int y) {
- nsIDOMElement element = document.elementFromPoint(x, y);
+ public static nsIDOMElement getElementFromPoint(nsIDOMDocument document,
+ int clientX, int clientY) {
+ nsIDOMNSDocument nsDocument = (nsIDOMNSDocument) document
+ .queryInterface(nsIDOMNSDocument.NS_IDOMNSDOCUMENT_IID);
+ nsIDOMElement element = nsDocument.elementFromPoint(clientX, clientY);
+
Stack<nsIDOMElement> hiddenElements = new Stack<nsIDOMElement>();
Stack<String> hiddenElementsStyles = new Stack<String>();
while (element != null && isTemporaryDndElement(element)) {
@@ -245,7 +249,7 @@
hiddenElementsStyles.push(element.getAttribute(HTML.ATTR_STYLE));
element.setAttribute(HTML.ATTR_STYLE, "display:none !important;");
- element = document.elementFromPoint(x, y);
+ element = nsDocument.elementFromPoint(clientX, clientY);
}
while (!hiddenElements.empty()) {
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/dnd/DropableArea.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/dnd/DropableArea.java 2010-04-21
08:46:06 UTC (rev 21573)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/dnd/DropableArea.java 2010-04-21
09:10:45 UTC (rev 21574)
@@ -31,11 +31,11 @@
public class DropableArea {
private boolean visible;
private EnumSet<DropTarget> dropTargets;
- private final nsIDOMDocument document;
+ private nsIDOMDocument document;
private nsIDOMNode node;
private nsIDOMElement domArea;
private static final String AREA_COLOR = "rgba(166, 202, 240, 0.5)";
//$NON-NLS-1$
- private DropTarget hightlightedDropTarget;
+ private DropTarget highlightedDropTarget;
/**
*
@@ -51,6 +51,9 @@
public void setNode(nsIDOMNode node) {
this.node = node;
}
+ public nsIDOMNode getNode() {
+ return node;
+ }
/**
* @param dropTargets cannot be null
@@ -63,37 +66,37 @@
this.visible = visible;
}
- public void setHighlightedSpot(int mouseX, int mouseY) {
- this.hightlightedDropTarget = getHighlightedDropTarget(mouseX, mouseY);
- }
-
- public DropTarget getHighlightedDropTarget(int mouseX, int mouseY) {
+ public void setHighlightedDropTarget(int mouseX, int mouseY) {
if (node == null) {
- return null;
+ highlightedDropTarget = null;
}
Rectangle bounds = XulRunnerVpeUtils.getElementBounds(node);
if (dropTargets.contains(DropTarget.BEFORE)
&& bounds.x <= mouseX
&& mouseX < bounds.x + bounds.width / 5) {
- return DropTarget.BEFORE;
+ highlightedDropTarget = DropTarget.BEFORE;
} else if (dropTargets.contains(DropTarget.AFTER)
&& bounds.x + bounds.width * 4 / 5 <= mouseX
&& mouseX < bounds.x + bounds.width) {
- return DropTarget.AFTER;
+ highlightedDropTarget = DropTarget.AFTER;
} else if (dropTargets.contains(DropTarget.BEGIN)
&& bounds.y <= mouseY
&& mouseY < bounds.y + bounds.height / 5) {
- return DropTarget.BEGIN;
+ highlightedDropTarget = DropTarget.BEGIN;
} else if (dropTargets.contains(DropTarget.END)
&& bounds.y + bounds.height * 4 / 5 <= mouseY
&& mouseY < bounds.y + bounds.height) {
- return DropTarget.END;
+ highlightedDropTarget = DropTarget.END;
} else {
- return null;
+ highlightedDropTarget = null;
}
}
-
+
+ public DropTarget getHighlightedDropTarget() {
+ return highlightedDropTarget;
+ }
+
public void redraw() {
if (!visible || node == null) {
if (domArea != null) {
@@ -156,15 +159,24 @@
contentArea.removeChild(oldDomArea);
}
}
-
+
+ public void dispose() {
+ setVisible(false);
+ redraw();
+
+ document = null;
+ node = null;
+ domArea = null;
+ }
+
private String getColor(DropTarget dropTarget) {
- if (dropTarget == hightlightedDropTarget) {
+ if (dropTarget == highlightedDropTarget) {
return "red";
} else {
return "black";
}
}
-
+
private nsIDOMElement createRect(Rectangle coords, String color) {
nsIDOMElement rect = createElement(HTML.TAG_DIV);
Modified: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/dnd/VpeDnD.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/dnd/VpeDnD.java 2010-04-21
08:46:06 UTC (rev 21573)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/dnd/VpeDnD.java 2010-04-21
09:10:45 UTC (rev 21574)
@@ -11,62 +11,45 @@
******************************************************************************/
package org.jboss.tools.vpe.dnd;
+import java.util.EnumSet;
+
import org.eclipse.core.resources.IFile;
-import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Display;
-import org.eclipse.wst.xml.core.internal.document.NodeImpl;
+import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
+import org.eclipse.wst.sse.ui.StructuredTextEditor;
+import org.eclipse.wst.xml.core.internal.document.ElementImpl;
import org.jboss.tools.common.model.XModelObject;
import org.jboss.tools.common.model.options.PreferenceModelUtilities;
-import org.jboss.tools.common.model.ui.dnd.ModelTransfer;
-import org.jboss.tools.common.model.ui.editors.dnd.DropCommandFactory;
-import org.jboss.tools.common.model.ui.editors.dnd.DropData;
import org.jboss.tools.common.model.ui.editors.dnd.DropUtils;
-import org.jboss.tools.common.model.ui.editors.dnd.IDropCommand;
+import org.jboss.tools.common.model.ui.editors.dnd.context.IDNDTextEditor;
import org.jboss.tools.common.model.ui.editors.dnd.context.InnerDragBuffer;
import org.jboss.tools.common.model.util.EclipseResourceUtil;
-import org.jboss.tools.jst.jsp.JspEditorPlugin;
-import org.jboss.tools.jst.jsp.jspeditor.JSPTextEditor;
-import org.jboss.tools.jst.jsp.jspeditor.dnd.JSPTagProposalFactory;
-import org.jboss.tools.jst.jsp.preferences.IVpePreferencesPage;
import org.jboss.tools.jst.web.tld.model.TLDUtil;
import org.jboss.tools.vpe.VpeDebug;
import org.jboss.tools.vpe.dnd.DndUtil.DragTransferData;
import org.jboss.tools.vpe.editor.VpeController;
import org.jboss.tools.vpe.editor.VpeSourceDropInfo;
import org.jboss.tools.vpe.editor.VpeSourceInnerDragInfo;
-import org.jboss.tools.vpe.editor.VpeVisualCaretInfo;
import org.jboss.tools.vpe.editor.VpeVisualDomBuilder;
-import org.jboss.tools.vpe.editor.VpeVisualDropInfo;
import org.jboss.tools.vpe.editor.VpeVisualInnerDragInfo;
import org.jboss.tools.vpe.editor.mapping.VpeElementMapping;
import org.jboss.tools.vpe.editor.mapping.VpeNodeMapping;
-import org.jboss.tools.vpe.editor.mozilla.MozillaDropInfo;
import org.jboss.tools.vpe.editor.mozilla.MozillaEditor;
import org.jboss.tools.vpe.editor.mozilla.listener.MozillaDndListener;
-import org.jboss.tools.vpe.editor.selection.VpeSelectionController;
-import org.jboss.tools.vpe.editor.template.VpePseudoContentCreator;
-import org.jboss.tools.vpe.editor.util.HTML;
-import org.jboss.tools.vpe.editor.util.TextUtil;
-import org.jboss.tools.vpe.editor.util.VisualDomUtil;
import org.jboss.tools.vpe.editor.util.VpeDndUtil;
import org.jboss.tools.vpe.xulrunner.XPCOM;
import org.jboss.tools.vpe.xulrunner.editor.XulRunnerEditor;
-import org.jboss.tools.vpe.xulrunner.editor.XulRunnerVpeUtils;
import org.mozilla.interfaces.nsIComponentManager;
import org.mozilla.interfaces.nsIDOMDocument;
import org.mozilla.interfaces.nsIDOMElement;
import org.mozilla.interfaces.nsIDOMEvent;
-import org.mozilla.interfaces.nsIDOMEventTarget;
import org.mozilla.interfaces.nsIDOMMouseEvent;
-import org.mozilla.interfaces.nsIDOMNSDocument;
import org.mozilla.interfaces.nsIDOMNSUIEvent;
import org.mozilla.interfaces.nsIDOMNode;
-import org.mozilla.interfaces.nsIDOMNodeList;
import org.mozilla.interfaces.nsIDragService;
import org.mozilla.interfaces.nsIFile;
-import org.mozilla.interfaces.nsISelectionController;
import org.mozilla.interfaces.nsIServiceManager;
import org.mozilla.interfaces.nsISupports;
import org.mozilla.interfaces.nsISupportsArray;
@@ -74,20 +57,20 @@
import org.mozilla.interfaces.nsISupportsString;
import org.mozilla.interfaces.nsITransferable;
import org.mozilla.xpcom.Mozilla;
-import org.mozilla.xpcom.XPCOMException;
-import org.w3c.dom.Attr;
import org.w3c.dom.Document;
-import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
/**
+ * Class responsible for Drag&Drop functionality
+ *
* @author Max Areshkau
* @author Yahor Radtsevich (yradtsevich)
- *
- * Class responsible for Drag&Drop functionality
*/
+// TODO: cleanup the code
public class VpeDnD implements MozillaDndListener {
+ private static final String TAG_TAGLIB = "taglib"; //$NON-NLS-1$
+
private static int HUGE_DISTANCE = 999999;
/*
@@ -110,8 +93,10 @@
private nsIDragService dragService;
private VpeController vpeController;
- private VpeVisualInnerDragInfo innerDragInfo = null;
+
+ private VpeSourceInnerDragInfo sourceInnerDragInfo = null;
private DraggablePattern draggablePattern;
+ private DropableArea dropableArea;
public VpeDnD(VpeController vpeController, MozillaEditor mozillaEditor) {
this.vpeController = vpeController;
@@ -123,9 +108,10 @@
.getLastSelectedElement();
// start drag sessionvpe-element
if (isDraggable(selectedElement)) {
- Point mousePosition = getMousePosition(domEvent);
- draggablePattern.startSession(mousePosition.x, mousePosition.y);
+ Point pageCoords = getPageCoords(domEvent);
+ draggablePattern.startSession(pageCoords.x, pageCoords.y);
startDragSession(selectedElement);
+
draggablePattern.closeSession();
domEvent.stopPropagation();
domEvent.preventDefault();
@@ -139,16 +125,24 @@
public void dragOver(nsIDOMEvent event) {
final nsIDOMMouseEvent mouseEvent =
(nsIDOMMouseEvent) event.queryInterface(nsIDOMMouseEvent.NS_IDOMMOUSEEVENT_IID);
+
+ final XulRunnerEditor editor = vpeController.getXulRunnerEditor();
+ new ScrollingSupport(editor).scroll(mouseEvent);
+
+ final DropResolver dropResolver;
if (isInnerDragSession()) {
- Point mousePosition = getMousePosition(event);
+ dropResolver = getDropResolverForInternalDrop();
+
+ Point mousePosition = getPageCoords(event);
draggablePattern.moveTo(mousePosition.x, mousePosition.y);
+ } else {
+ dropResolver = getDropResolverForExternalDrop();
}
- final XulRunnerEditor editor = vpeController.getXulRunnerEditor();
- new ScrollingSupport(editor).scroll(mouseEvent);
+ highlightDropTargets(dropResolver, mouseEvent);
refreshCanDrop(event);
vpeController.onRefresh();
}
-
+
/**
* Drop Event handler
* @param domEvent
@@ -163,9 +157,19 @@
//in this case it's is external drag
externalDrop((nsIDOMMouseEvent)domEvent.queryInterface(nsIDOMMouseEvent.NS_IDOMMOUSEEVENT_IID),
VpeController.MODEL_FLAVOR, ""); //$NON-NLS-1$
}
+ disposeDropableArea();
vpeController.onRefresh();
}
-
+
+ public void dragExit(nsIDOMEvent domEvent) {
+// disposeDropableArea();
+ nsIDOMNode visualNode = (nsIDOMNode) domEvent.getTarget()
+ .queryInterface(nsIDOMNode.NS_IDOMNODE_IID);
+ if (visualNode.getNodeType()==nsIDOMNode.DOCUMENT_NODE) {
+ disposeDropableArea();
+ }
+ }
+
public void selectionChanged() {
nsIDOMElement selectedElement = vpeController.getXulRunnerEditor()
.getLastSelectedElement();
@@ -180,6 +184,135 @@
return draggablePattern.isDragIconClicked(mouseEvent);
}
+ private DropResolver getDropResolverForExternalDrop() {
+ if (getDragService().getCurrentSession()
+ .isDataFlavorSupported(VpeController.MODEL_FLAVOR)) {
+ XModelObject object = PreferenceModelUtilities.getPreferenceModel()
+ .getModelBuffer().source();
+ if (object.getFileType() == XModelObject.FILE
+ && !TLDUtil.isTaglib(object)) {
+ final IFile f = (IFile) EclipseResourceUtil.getResource(object);
+ return getSimpleDropResolver(f != null);
+ } else {
+ String tagname = vpeController.getTagName(object);
+ if (tagname.indexOf(TAG_TAGLIB) >= 0) {
+ tagname = TAG_TAGLIB;
+ }
+ Node dropContainer = ((Document) vpeController.getModel()
+ .getAdapter(Document.class)).createElement(tagname);
+
+ return getDropResolverForNode(dropContainer);
+ }
+ } else {
+ return getSimpleDropResolver(true);
+ }
+ }
+
+ private DropResolver getDropResolverForInternalDrop() {
+ return getDropResolverForNode(sourceInnerDragInfo.getNode());
+ }
+
+ private DropResolver getSimpleDropResolver(final boolean canDrop) {
+ return new DropResolver() {
+ public boolean canDrop(Node node) {
+ return canDrop;
+ }
+ };
+ }
+
+ private DropResolver getDropResolverForNode(final Node draggedNode) {
+ return new DropResolver() {
+ public boolean canDrop(Node container) {
+ VpeNodeMapping nodeMapping = vpeController.getDomMapping()
+ .getNodeMapping(container);
+
+ boolean canDrop = false;
+ if (nodeMapping != null && nodeMapping instanceof VpeElementMapping) {
+ canDrop = ((VpeElementMapping) nodeMapping).getTemplate()
+ .canInnerDrop(vpeController.getPageContext(),
+ container, draggedNode);
+ }
+
+ return canDrop;
+ }
+ };
+ }
+
+ private void highlightDropTargets(DropResolver dropResolver, nsIDOMMouseEvent event) {
+ nsIDOMDocument document = vpeController.getVisualBuilder()
+ .getOriginalTargetNode(event).getOwnerDocument();
+
+ Point clientCoords = getClientCoords(event);
+
+ nsIDOMNode originalVisualNode = DndUtil.getElementFromPoint(document,
+ clientCoords.x, clientCoords.y);
+ if (originalVisualNode == null) {
+ return;
+ }
+
+ if (dropableArea == null) {
+ dropableArea = new DropableArea(document);
+ }
+ Node originalSourceNode = vpeController.getDomMapping()
+ .getNearSourceNode(originalVisualNode);
+ if (originalSourceNode.getNodeType() == Node.TEXT_NODE) {
+ originalSourceNode = originalSourceNode.getParentNode();
+ }
+
+ final Node highlightedNode;
+ final EnumSet<DropTarget> dropTargets;
+ if (dropResolver.canDrop(originalSourceNode)) {
+ highlightedNode = originalSourceNode;
+
+ Node originalSourceNodeParent = originalSourceNode.getParentNode();
+ if (originalSourceNodeParent != null
+ && dropResolver.canDrop(originalSourceNodeParent)) {
+ dropTargets = EnumSet.of(DropTarget.BEFORE, DropTarget.AFTER,
+ DropTarget.BEGIN, DropTarget.END);
+ } else {
+ dropTargets = EnumSet.of(DropTarget.BEGIN, DropTarget.END);
+ }
+ } else {
+ Node sourceNode;
+ Node sourceNodeParent = originalSourceNode;
+ boolean nodeFound = false;
+ do {
+ sourceNode = sourceNodeParent;
+ sourceNodeParent = sourceNode.getParentNode();
+ nodeFound = dropResolver.canDrop(sourceNodeParent);
+ } while (sourceNodeParent != null && !nodeFound);
+
+ if (nodeFound) {
+ highlightedNode = sourceNode;
+ dropTargets = EnumSet.of(DropTarget.BEFORE, DropTarget.AFTER);
+ } else {
+ highlightedNode = null;
+ dropTargets = EnumSet.noneOf(DropTarget.class);
+ }
+ }
+
+ dropableArea.setDropTargets(dropTargets);
+ dropableArea.setNode(
+ vpeController.getDomMapping().getNearVisualNode(highlightedNode));
+ Point mouseCoords = getPageCoords(event);
+ dropableArea.setHighlightedDropTarget(mouseCoords.x, mouseCoords.y);
+ dropableArea.setVisible(true);
+ dropableArea.redraw();
+ }
+
+ private Point getClientCoords(nsIDOMEvent event) {
+ final nsIDOMMouseEvent mouseEvent =
+ (nsIDOMMouseEvent) event.queryInterface(nsIDOMMouseEvent.NS_IDOMMOUSEEVENT_IID);
+ return new Point(mouseEvent.getClientX(), mouseEvent.getClientY());
+ }
+
+ private void disposeDropableArea() {
+ if (dropableArea != null) {
+ dropableArea.dispose();
+ dropableArea = null;
+ }
+ }
+
/**
* Starts drag session
* @param dragetElement
@@ -224,76 +357,83 @@
}
private void refreshCanDrop(nsIDOMEvent event) {
- boolean canDrop = true;
nsIDOMMouseEvent mouseEvent = (nsIDOMMouseEvent)
event.queryInterface(nsIDOMMouseEvent.NS_IDOMMOUSEEVENT_IID);
- //in this condition early was check for xulelement
- if
(getDragService().getCurrentSession().isDataFlavorSupported(VpeController.MODEL_FLAVOR))
{
- MozillaDropInfo info;
-
- if(isInnerDragSession()){
- info = canInnerDrop(mouseEvent);
- } else {
- info = canExternalDrop(mouseEvent, VpeController.MODEL_FLAVOR, "");
//$NON-NLS-1$
- }
- if (info != null) {
- canDrop = info.canDrop();
- }
- }
- //sets possability to drop current element here
- //Added by estherbin fix jbide-1046
- VpeSelectionController selectionController =
vpeController.getVisualSelectionController();
- final VpeVisualCaretInfo visualCaretInfo =
vpeController.getSelectionBuilder().getVisualCaretInfo(event);
-
- final nsIDOMEventTarget target = event.getTarget();
- final nsIDOMNode targetDomNode = (nsIDOMNode)
target.queryInterface(nsIDOMNode.NS_IDOMNODE_IID);
-// final nsIDOMNode selectedVisualNode =
controller.getXulRunnerEditor().getLastSelectedNode();
- try {
- if ((targetDomNode.getFirstChild() != null) &&
(targetDomNode.getFirstChild().getNodeType() == nsIDOMNode.TEXT_NODE)) {
-
selectionController.getSelection(nsISelectionController.SELECTION_NORMAL).collapse(targetDomNode.getFirstChild(),
- visualCaretInfo.getRageOffset());
- } else if ((targetDomNode.getNodeType() != nsIDOMNode.TEXT_NODE)) {
-
selectionController.getSelection(nsISelectionController.SELECTION_NORMAL).collapse(targetDomNode,
0);
- }
- } catch (XPCOMException xpcome) {
- event.stopPropagation();
- event.preventDefault();
- }
-
- //sets possability to drop current element here
- getDragService().getCurrentSession().setCanDrop(canDrop);
+ getDragService().getCurrentSession().setCanDrop(dropableArea != null
+ && dropableArea.getHighlightedDropTarget() != null);
mouseEvent.preventDefault();
mouseEvent.stopPropagation();
+
+// boolean canDrop = true;
+// //in this condition early was check for xulelement
+// if
(getDragService().getCurrentSession().isDataFlavorSupported(VpeController.MODEL_FLAVOR))
{
+// MozillaDropInfo info;
+//
+// if(isInnerDragSession()){
+// info = canInnerDrop(mouseEvent);
+// } else {
+// info = canExternalDrop(mouseEvent, VpeController.MODEL_FLAVOR, "");
//$NON-NLS-1$
+// }
+// if (info != null) {
+// canDrop = info.canDrop();
+// }
+// }
+// //sets possability to drop current element here
+// //Added by estherbin fix jbide-1046
+// VpeSelectionController selectionController =
vpeController.getVisualSelectionController();
+// final VpeVisualCaretInfo visualCaretInfo =
vpeController.getSelectionBuilder().getVisualCaretInfo(event);
+//
+// final nsIDOMEventTarget target = event.getTarget();
+// final nsIDOMNode targetDomNode = (nsIDOMNode)
target.queryInterface(nsIDOMNode.NS_IDOMNODE_IID);
+//// final nsIDOMNode selectedVisualNode =
controller.getXulRunnerEditor().getLastSelectedNode();
+// try {
+// if ((targetDomNode.getFirstChild() != null) &&
(targetDomNode.getFirstChild().getNodeType() == nsIDOMNode.TEXT_NODE)) {
+//
selectionController.getSelection(nsISelectionController.SELECTION_NORMAL).collapse(targetDomNode.getFirstChild(),
+// visualCaretInfo.getRageOffset());
+// } else if ((targetDomNode.getNodeType() != nsIDOMNode.TEXT_NODE)) {
+//
selectionController.getSelection(nsISelectionController.SELECTION_NORMAL).collapse(targetDomNode,
0);
+// }
+// } catch (XPCOMException xpcome) {
+// event.stopPropagation();
+// event.preventDefault();
+// }
}
- private void externalDropAny(final String flavor, final String data, final Point range,
- Node container) {
- if (flavor == null || flavor.length() == 0)
+ private void externalDropAny(final String flavor, final String data,
+ final Point range) {
+ StructuredTextEditor sourceEditor = vpeController.getSourceEditor();
+ if (flavor == null || flavor.length() == 0
+ || !(sourceEditor instanceof IDNDTextEditor)) {
return;
- IDropCommand dropCommand = DropCommandFactory.getInstance()
- .getDropCommand(flavor, JSPTagProposalFactory.getInstance());
-
- boolean promptAttributes = JspEditorPlugin.getDefault()
- .getPreferenceStore().getBoolean(
- IVpePreferencesPage.ASK_TAG_ATTRIBUTES_ON_TAG_INSERT);
- dropCommand.getDefaultModel().setPromptForTagAttributesRequired(
- promptAttributes);
- DropData dropData = new DropData(flavor, data,
- vpeController.getSourceEditor().getEditorInput(),
- (ISourceViewer) vpeController.getSourceEditor().getAdapter(ISourceViewer.class),
- vpeController.new VpeSelectionProvider(range.x, range.y),
- container);
-
- /*
- *
https://jira.jboss.org/jira/browse/JBIDE-4982 Setting the value
- * provider to create tag insert dialog.
- */
- if (vpeController.getSourceEditor() instanceof JSPTextEditor) {
- dropData.setValueProvider(((JSPTextEditor) vpeController.getSourceEditor())
- .createAttributeDescriptorValueProvider());
}
-
- dropCommand.execute(dropData);
+
+ //vpeController.getSourceEditor().getTextViewer().getTextWidget().setCaretOffset(range.x);
+ sourceEditor.setHighlightRange(range.x, range.y, true);
+ ((IDNDTextEditor) sourceEditor).runDropCommand(flavor, data);
+// IDropCommand dropCommand = DropCommandFactory.getInstance()
+// .getDropCommand(flavor, JSPTagProposalFactory.getInstance());
+//
+// boolean promptAttributes = JspEditorPlugin.getDefault()
+// .getPreferenceStore().getBoolean(
+// IVpePreferencesPage.ASK_TAG_ATTRIBUTES_ON_TAG_INSERT);
+// dropCommand.getDefaultModel().setPromptForTagAttributesRequired(
+// promptAttributes);
+// DropData dropData = new DropData(flavor, data,
+// vpeController.getSourceEditor().getEditorInput(),
+// (ISourceViewer) vpeController.getSourceEditor().getAdapter(ISourceViewer.class),
+// vpeController.new VpeSelectionProvider(range.x, range.y),
+// container);
+//
+// /*
+// *
https://jira.jboss.org/jira/browse/JBIDE-4982 Setting the value
+// * provider to create tag insert dialog.
+// */
+// if (vpeController.getSourceEditor() instanceof JSPTextEditor) {
+// dropData.setValueProvider(((JSPTextEditor) vpeController.getSourceEditor())
+// .createAttributeDescriptorValueProvider());
+// }
+//
+// dropCommand.execute(dropData);
}
private boolean isInnerDragSession() {
@@ -306,9 +446,8 @@
if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
System.out.print("<<<<<< canInnerDrag"); //$NON-NLS-1$
}
- if (innerDragInfo != null) {
- innerDragInfo.release();
- innerDragInfo = null;
+ if (sourceInnerDragInfo != null) {
+ sourceInnerDragInfo = null;
}
boolean canDrag = false;
VpeVisualInnerDragInfo dragInfo = getInnerDragInfo(element);
@@ -325,15 +464,15 @@
break;
}
case nsIDOMNode.TEXT_NODE: {
- canDrag = vpeController.getVisualBuilder().isTextEditable(dragNode);
+ vpeController.getVisualBuilder();
+ canDrag = VpeVisualDomBuilder.isTextEditable(dragNode);
break;
}
}
if (canDrag) {
- VpeSourceInnerDragInfo sourceInnerDragInfo = vpeController.getVisualBuilder()
+ sourceInnerDragInfo = vpeController.getVisualBuilder()
.getSourceInnerDragInfo(dragInfo);
if (sourceInnerDragInfo.getNode() != null) {
- innerDragInfo = dragInfo;
InnerDragBuffer.object = sourceInnerDragInfo.getNode();
Display.getDefault().asyncExec(new Runnable() {
public void run() {
@@ -341,6 +480,7 @@
}
});
} else {
+ sourceInnerDragInfo = null;
canDrag = false;
}
}
@@ -354,115 +494,104 @@
return canDrag;
}
- private MozillaDropInfo canInnerDrop(nsIDOMMouseEvent event) {
- vpeController.onHideTooltip();
+// this method is never used
+// private MozillaDropInfo canInnerDrop(nsIDOMMouseEvent event) {
+// vpeController.onHideTooltip();
+//
+// if (vpeController.getDropWindow().isActive()) {
+// if (!event.getAltKey()) {
+// vpeController.getDropWindow().close();
+// } else {
+// return null;
+// }
+// }
+// if (event.getAltKey()) {
+// nsIDOMNode visualNode = VisualDomUtil.getTargetNode(event);
+// Node sourceNode = vpeController.getDomMapping().getNearSourceNode(visualNode);
+// if (sourceNode != null) {
+// vpeController.getDropWindow().setActive(true);
+// vpeController.getDropWindow().setEventPosition(event.getScreenX(), event
+// .getScreenY());
+// vpeController.getDropWindow().setInitialTargetNode(sourceNode);
+// vpeController.getDropWindow().open();
+// event.stopPropagation();
+// event.preventDefault();
+// return null;
+// }
+// }
+// if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
+// System.out.print("<<<<<< canInnerDrop"); //$NON-NLS-1$
+// }
+// boolean canDrop = false;
+//
+// nsIDOMNode caretParent = null;
+// long caretOffset = 0;
+// if (sourceInnerDragInfo != null) {
+// VpeVisualDropInfo visualDropInfo = getDropInfo(event);
+// if (visualDropInfo.getDropContainer() != null) {
+// if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
+// System.out.print(" container: " //$NON-NLS-1$
+// + visualDropInfo.getDropContainer().getNodeName()
+// + "(" //$NON-NLS-1$
+// + visualDropInfo.getDropContainer()
+// + ") parent: " //$NON-NLS-1$
+// + visualDropInfo.getDropContainer().getParentNode()
+// .getNodeName()
+// + "(" //$NON-NLS-1$
+// + visualDropInfo.getDropContainer().getParentNode()
+// + ") offset: " //$NON-NLS-1$
+// + visualDropInfo.getDropOffset());
+// }
+// VpeSourceDropInfo sourceDropInfo
+// = getSourceDropInfo(sourceInnerDragInfo.getNode(),
+// visualDropInfo, true);
+// canDrop = sourceDropInfo.canDrop();
+// if (canDrop) {
+// VpeVisualDropInfo newVisualDropInfo
+// = getDropInfo(sourceDropInfo.getContainer(),
+// sourceDropInfo.getOffset());
+// if (newVisualDropInfo != null) {
+// correctVisualDropPosition(event,
+// newVisualDropInfo, visualDropInfo);
+// caretParent = newVisualDropInfo.getDropContainer();
+// caretOffset = newVisualDropInfo.getDropOffset();
+// }
+// }
+// }
+// visualDropInfo.release();
+// }
+// if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
+// System.out.println(" canDrop: " + canDrop); //$NON-NLS-1$
+// }
+// return new MozillaDropInfo(canDrop, caretParent, caretOffset);
+// }
- if (vpeController.getDropWindow().isActive()) {
- if (!event.getAltKey()) {
- vpeController.getDropWindow().close();
- } else {
- return null;
- }
- }
- if (event.getAltKey()) {
- nsIDOMNode visualNode = VisualDomUtil.getTargetNode(event);
- Node sourceNode = vpeController.getDomMapping().getNearSourceNode(visualNode);
- if (sourceNode != null) {
- vpeController.getDropWindow().setActive(true);
- vpeController.getDropWindow().setEventPosition(event.getScreenX(), event
- .getScreenY());
- vpeController.getDropWindow().setInitialTargetNode(sourceNode);
- vpeController.getDropWindow().open();
- event.stopPropagation();
- event.preventDefault();
- return null;
- }
- }
- if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
- System.out.print("<<<<<< canInnerDrop"); //$NON-NLS-1$
- }
- boolean canDrop = false;
-
- nsIDOMNode caretParent = null;
- long caretOffset = 0;
- if (innerDragInfo != null) {
- VpeVisualDropInfo visualDropInfo = getDropInfo(event);
- if (visualDropInfo.getDropContainer() != null) {
- if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
- System.out.print(" container: " //$NON-NLS-1$
- + visualDropInfo.getDropContainer().getNodeName()
- + "(" //$NON-NLS-1$
- + visualDropInfo.getDropContainer()
- + ") parent: " //$NON-NLS-1$
- + visualDropInfo.getDropContainer().getParentNode()
- .getNodeName()
- + "(" //$NON-NLS-1$
- + visualDropInfo.getDropContainer().getParentNode()
- + ") offset: " //$NON-NLS-1$
- + visualDropInfo.getDropOffset());
- }
- VpeSourceInnerDragInfo sourceInnerDragInfo = vpeController.getVisualBuilder()
- .getSourceInnerDragInfo(innerDragInfo);
- VpeSourceDropInfo sourceDropInfo
- = getSourceDropInfo(sourceInnerDragInfo.getNode(),
- visualDropInfo, true);
- canDrop = sourceDropInfo.canDrop();
- if (canDrop) {
- VpeVisualDropInfo newVisualDropInfo
- = getDropInfo(sourceDropInfo.getContainer(),
- sourceDropInfo.getOffset());
- if (newVisualDropInfo != null) {
- correctVisualDropPosition(event,
- newVisualDropInfo, visualDropInfo);
- caretParent = newVisualDropInfo.getDropContainer();
- caretOffset = newVisualDropInfo.getDropOffset();
- }
- }
- }
- visualDropInfo.release();
- }
- if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
- System.out.println(" canDrop: " + canDrop); //$NON-NLS-1$
- }
- return new MozillaDropInfo(canDrop, caretParent, caretOffset);
- }
-
private void innerDrop(nsIDOMMouseEvent event) {
vpeController.onHideTooltip();
if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
System.out.print("<<<<<< innerDrop"); //$NON-NLS-1$
}
- if (innerDragInfo != null) {
- VpeVisualDropInfo visualDropInfo = getDropInfo(event);
- if (visualDropInfo.getDropContainer() != null) {
+ if (sourceInnerDragInfo != null) {
+ VpeSourceDropInfo sourceDropInfo = getDropInfo(event);
+ if (sourceDropInfo.getContainer() != null) {
if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
System.out
- .print(" container: " + visualDropInfo.getDropContainer().getNodeName()
+ //$NON-NLS-1$
- "(" + visualDropInfo.getDropContainer() //$NON-NLS-1$
+ .print(" container: " + sourceDropInfo.getContainer().getNodeName() +
//$NON-NLS-1$
+ "(" + sourceDropInfo.getContainer() //$NON-NLS-1$
+ ")" + //$NON-NLS-1$
" offset: " //$NON-NLS-1$
- + visualDropInfo.getDropOffset());
+ + sourceDropInfo.getOffset());
}
-
- VpeSourceInnerDragInfo sourceInnerDragInfo = vpeController.getVisualBuilder()
- .getSourceInnerDragInfo(innerDragInfo);
- VpeSourceDropInfo sourceDropInfo
- = getSourceDropInfo(sourceInnerDragInfo.getNode(),
- visualDropInfo, true);
+
if (sourceDropInfo.canDrop()) {
- VpeVisualDropInfo newVisualDropInfo
- = getDropInfo(sourceDropInfo.getContainer(),
- sourceDropInfo.getOffset());
- if (newVisualDropInfo != null) {
- correctVisualDropPosition(event,
- newVisualDropInfo, visualDropInfo);
- vpeController.getVisualBuilder().innerDrop(sourceInnerDragInfo,
- sourceDropInfo);
- if (innerDragInfo != null) {
- innerDragInfo.release();
- innerDragInfo = null;
- }
+ VpeDnDHelper dropper = new VpeDnDHelper();
+ dropper.setDndData(false, true);
+ dropper.drop(vpeController.getPageContext(),
+ sourceInnerDragInfo, sourceDropInfo);
+
+ if (sourceInnerDragInfo != null) {
+ sourceInnerDragInfo = null;
}
}
}
@@ -471,185 +600,13 @@
System.out.println();
}
}
-
- private void correctVisualDropPosition(nsIDOMMouseEvent mouseEvent,
- VpeVisualDropInfo newVisualDropInfo,
- VpeVisualDropInfo oldVisualDropInfo) {
- nsIDOMNode newVisualDropContainer = newVisualDropInfo
- .getDropContainer();
- nsIDOMNode oldVisualDropContainer = oldVisualDropInfo
- .getDropContainer();
- if (newVisualDropContainer.equals(oldVisualDropContainer)) {
- newVisualDropInfo.setDropOffset(oldVisualDropInfo.getDropOffset());
- return;
- }
-
- nsIDOMNode child = oldVisualDropContainer;
- while (child != null && child.getNodeType() != Node.DOCUMENT_NODE) {
- nsIDOMNode parent = child.getParentNode();
- if (newVisualDropContainer.equals(parent)) {
- long offset = VisualDomUtil.getOffset(child);
- Rectangle rect = XulRunnerVpeUtils.getElementBounds(child);
-
- nsIDOMNSUIEvent nsuiEvent = (nsIDOMNSUIEvent)
- mouseEvent.queryInterface(nsIDOMNSUIEvent.NS_IDOMNSUIEVENT_IID);
- int mouseX = nsuiEvent.getPageX();
- int mouseY = nsuiEvent.getPageY();
-
- if (canInsertAfter(mouseX, mouseY, rect)) {
- offset++;
- }
- newVisualDropInfo.setDropOffset(offset);
- }
- child = parent;
- }
- }
-
- private VpeSourceDropInfo getSourceDropInfo(Node sourceDragNode,
- VpeVisualDropInfo visualDropInfo, boolean checkParentTemplates) {
- nsIDOMNode visualDropContainer = visualDropInfo.getDropContainer();
- long visualDropOffset = visualDropInfo.getDropOffset();
- Node sourceDropContainer = null;
- int sourceDropOffset = 0;
-
- switch (visualDropContainer.getNodeType()) {
- case nsIDOMNode.ELEMENT_NODE:
- nsIDOMNode visualOffsetNode = null;
- boolean afterFlag = false;
- long visualChildCount = VisualDomUtil
- .getChildCount(visualDropContainer);
- if (visualDropOffset < visualChildCount) {
- visualOffsetNode = VisualDomUtil.getChildNode(
- visualDropContainer, visualDropOffset);
- if (VpeVisualDomBuilder.isPseudoElement(visualOffsetNode)
- || VpeVisualDomBuilder.isAnonElement(visualOffsetNode)) {
- visualOffsetNode = VpeVisualDomBuilder
- .getLastAppreciableVisualChild(visualDropContainer);
- afterFlag = true;
- }
- } else {
- visualOffsetNode =
VpeVisualDomBuilder.getLastAppreciableVisualChild(visualDropContainer);
- afterFlag = visualChildCount != 0;
- }
- if (visualOffsetNode != null) {
- Node sourceOffsetNode = vpeController.getDomMapping()
- .getSourceNode(visualOffsetNode);
- if (sourceOffsetNode != null) {
- sourceDropContainer = sourceOffsetNode.getParentNode();
- sourceDropOffset = ((NodeImpl) sourceOffsetNode).getIndex();
- if (afterFlag) {
- sourceDropOffset++;
- }
- }
- }
- if (sourceDropContainer == null) {
- sourceDropContainer = vpeController.getDomMapping()
- .getNearSourceNode(visualDropContainer);
- if (sourceDropContainer != null) {
- sourceDropOffset = sourceDropContainer.getChildNodes()
- .getLength();
- }
- }
- if (sourceDropContainer == null) {
- sourceDropContainer = vpeController.getDomMapping()
- .getNearSourceNode(
- vpeController.getVisualBuilder().getContentArea());
- sourceDropOffset = sourceDropContainer.getChildNodes()
- .getLength();
- }
- break;
- case nsIDOMNode.TEXT_NODE:
- VpeNodeMapping nodeMapping = vpeController.getDomMapping()
- .getNearNodeMapping(visualDropContainer);
- // switch (nodeMapping.getType()) {
- // case VpeNodeMapping.TEXT_MAPPING:
- sourceDropContainer = nodeMapping.getSourceNode();
- sourceDropOffset = TextUtil.sourceInnerPosition(sourceDropContainer
- .getNodeValue(), visualDropOffset);
- // break;
- // case VpeNodeMapping.ELEMENT_MAPPING:
- // it's attribute
- if (VpeVisualDomBuilder.isTextEditable(visualDropContainer)) {
- String[] atributeNames = ((VpeElementMapping) nodeMapping)
- .getTemplate().getOutputAttributeNames();
- if (atributeNames != null && atributeNames.length > 0) {
- Element sourceElement = (Element) nodeMapping
- .getSourceNode();
- sourceDropContainer = sourceElement
- .getAttributeNode(atributeNames[0]);
- sourceDropOffset = TextUtil.sourceInnerPosition(
- sourceDropContainer.getNodeValue(),
- visualDropOffset);
- }
- }
- nodeMapping.getVisualNode();
- // }
- // break;
- }
- if (sourceDropContainer != null) {
- return getSourceDropInfo(sourceDragNode, sourceDropContainer,
- sourceDropOffset, checkParentTemplates);
- } else {
- return new VpeSourceDropInfo(null, 0, false);
- }
- }
-
- private VpeSourceDropInfo getSourceDropInfo(Node dragNode,
- Node container, int offset, boolean checkParentsTemplates) {
- // Thread.dumpStack();
- boolean canDrop = false;
- switch (container.getNodeType()) {
- case Node.ELEMENT_NODE:
- VpeNodeMapping nodeMapping = vpeController.getDomMapping()
- .getNodeMapping(container);
- if (nodeMapping != null && nodeMapping instanceof VpeElementMapping) {
- canDrop = ((VpeElementMapping) nodeMapping).getTemplate()
- .canInnerDrop(vpeController.getPageContext(), container, dragNode);
- }
- if (!canDrop) {
- if (!checkParentsTemplates)
- return new VpeSourceDropInfo(container, offset,
- canDrop);
- // offset = ((NodeImpl)container).getIndex();
- // container = container.getParentNode();
- // TODO Max Areshkau unclear logic , if we can drop on element
- // why we trying to drop
- // this on parent
- // return getSourceDropInfo(dragNode, container, offset,
- // false);
- return new VpeSourceDropInfo(container, offset, canDrop);
- }
- break;
- case Node.TEXT_NODE:
- case Node.DOCUMENT_NODE:
- canDrop = true;
- break;
- case Node.ATTRIBUTE_NODE:
- canDrop = true;
- break;
- }
- if (canDrop) {
- return new VpeSourceDropInfo(container, offset, canDrop);
- } else {
- return new VpeSourceDropInfo(null, 0, canDrop);
- }
- }
-
- private boolean canInsertAfter(int x, int y, Rectangle rect) {
- if (y > (rect.y + rect.height) || x > (rect.x + rect.width)) {
- return true;
- }
- return y >= rect.x && x > (rect.x + rect.width / 2);
- }
-
private void externalDrop(nsIDOMMouseEvent mouseEvent, String flavor, String data) {
vpeController.onHideTooltip();
- VpeVisualDropInfo visualDropInfo = getDropInfo(mouseEvent);
- Point range = vpeController.getSelectionBuilder().getSourceSelectionRangeAtVisualNode(
- visualDropInfo.getDropContainer(), (int) visualDropInfo
- .getDropOffset());
+ VpeSourceDropInfo dropInfo = getDropInfo(mouseEvent);
+ Point range = getSourceSelectionRange(
+ dropInfo.getContainer(), dropInfo.getOffset());
// if (MODEL_FLAVOR.equals(flavor)) {
// XModelObject object = PreferenceModelUtilities.getPreferenceModel()
@@ -708,12 +665,13 @@
// }
// }
- if (visualDropInfo.getDropContainer() != null && data != null) {
+ if (dropInfo.getContainer() != null && data != null) {
if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
System.out
- .println(" drop! container: " +
visualDropInfo.getDropContainer().getNodeName()); //$NON-NLS-1$
+ .println(" drop! container: " + dropInfo.getContainer().getNodeName());
//$NON-NLS-1$
}
- externalDropAny(aFlavor, data, range, null);
+
+ externalDropAny(aFlavor, data, range);
// TypedEvent tEvent = new TypedEvent(mouseEvent);
// tEvent.data = data;
@@ -722,106 +680,44 @@
// DnDUtil.fireDnDEvent(dropContext, textEditor, tEvent);
}
}
-
- private MozillaDropInfo canExternalDrop(nsIDOMMouseEvent mouseEvent, String flavor,
String data) {
- InnerDragBuffer.object = null;
- vpeController.onHideTooltip();
-
- if (vpeController.getDropWindow().isActive()) {
- if (!mouseEvent.getAltKey()) {
- vpeController.getDropWindow().close();
- } else {
- return new MozillaDropInfo(false, null, 0);
- }
- }
- if (mouseEvent.getAltKey()) {
- nsIDOMEvent event = (nsIDOMEvent) mouseEvent
- .queryInterface(nsIDOMEvent.NS_IDOMEVENT_IID);
- nsIDOMNode visualNode = (nsIDOMNode) event.getTarget()
- .queryInterface(nsIDOMNode.NS_IDOMNODE_IID);
- Node sourceNode = vpeController.getDomMapping().getNearSourceNode(visualNode);
- if (sourceNode != null) {
- if (ModelTransfer.MODEL.equals(flavor)) {
- // XModelObject object =
- // PreferenceModelUtilities.getPreferenceModel().
- // getModelBuffer().source();
- // InnerDragBuffer.object = object;
- } else {
- vpeController.getDropWindow().setFlavor(flavor);
+
+ private Point getSourceSelectionRange(Node sourceInitNode, int sourceInitOffset) {
+ int offset=0;
+ int position=0;
+ switch (sourceInitNode.getNodeType()) {
+ case Node.TEXT_NODE:
+ offset = Math.min(sourceInitOffset, sourceInitNode.getNodeValue().length());
+ position = vpeController.getSourceBuilder()
+ .getPosition(sourceInitNode, offset, false);
+ break;
+ case Node.ELEMENT_NODE:
+ case Node.DOCUMENT_NODE:
+ NodeList children = sourceInitNode.getChildNodes();
+ int count = children.getLength();
+ if (sourceInitOffset < count) {
+ // insert before the child with index sourceInitOffset
+ Node sourceNode = children.item(sourceInitOffset);
+ position = ((IndexedRegion)sourceNode).getStartOffset();
+ } else if (count > 0) {
+ // insert after the last child
+ Node sourceNode = children.item(count - 1);
+ position = ((IndexedRegion)sourceNode).getEndOffset();
+ } else { // if (count == 0)
+ // insert as a child
+ position = ((IndexedRegion)sourceInitNode).getStartOffset();
+ if (sourceInitNode instanceof ElementImpl) {
+ ElementImpl element = (ElementImpl)sourceInitNode;
+ if (element.isContainer()) {
+ position = element.getStartEndOffset();
+ }
}
- vpeController.getDropWindow().setActive(true);
- vpeController.getDropWindow().setEventPosition(mouseEvent.getScreenX(), mouseEvent
- .getScreenY());
- vpeController.getDropWindow().setInitialTargetNode(sourceNode);
- vpeController.getDropWindow().open();
- mouseEvent.stopPropagation();
- mouseEvent.preventDefault();
- return new MozillaDropInfo(false, null, 0);
}
+ break;
}
- boolean canDrop = false;
- nsIDOMNode caretParent = null;
- long caretOffset = 0;
-
- if (VpeController.MODEL_FLAVOR.equals(flavor)) {
- XModelObject object = PreferenceModelUtilities.getPreferenceModel()
- .getModelBuffer().source();
- if (object.getFileType() == XModelObject.FILE
- && !TLDUtil.isTaglib(object)) {
- IFile f = (IFile) EclipseResourceUtil.getResource(object);
- canDrop = f != null;
- VpeVisualDropInfo visualDropInfo = getDropInfo(mouseEvent);
- caretParent = visualDropInfo.getDropContainer();
- caretOffset = visualDropInfo.getDropOffset();
- } else {
- String tagname = vpeController.getTagName(object);
- if (tagname.indexOf("taglib") >= 0)tagname = "taglib";
//$NON-NLS-1$ //$NON-NLS-2$
- Node sourceDragNode = ((Document) vpeController.getModel().getAdapter(
- Document.class)).createElement(tagname);
- VpeVisualDropInfo visualDropInfo = getDropInfo(mouseEvent);
- if (visualDropInfo.getDropContainer() != null) {
- VpeSourceDropInfo sourceDropInfo
- = getSourceDropInfo(
- sourceDragNode, visualDropInfo, true);
- canDrop = sourceDropInfo.canDrop();
- if (canDrop) {
- VpeVisualDropInfo newVisualDropInfo
- = getDropInfo(
- sourceDropInfo.getContainer(),
- sourceDropInfo.getOffset());
- if (newVisualDropInfo != null) {
- correctVisualDropPosition(mouseEvent,
- newVisualDropInfo, visualDropInfo);
- caretParent = newVisualDropInfo.getDropContainer();
- caretOffset = newVisualDropInfo.getDropOffset();
- }
- }
- }
- visualDropInfo.release();
- }
- } else if (XulRunnerEditor.TRANS_FLAVOR_kFileMime.equals(flavor)
- || XulRunnerEditor.TRANS_FLAVOR_kURLMime.equals(flavor)) {
- VpeVisualDropInfo visualDropInfo = getDropInfo(mouseEvent);
- caretParent = visualDropInfo.getDropContainer();
- caretOffset = visualDropInfo.getDropOffset();
- canDrop = true;
-
- }
- if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
- System.out.println(" canDrop: " + canDrop //$NON-NLS-1$
- + (canDrop ?
- " container: " //$NON-NLS-1$
- + caretParent.getNodeName()
- + " offset: " //$NON-NLS-1$
- + caretOffset
- : "")); //$NON-NLS-1$
- }
- return new MozillaDropInfo(canDrop, caretParent, caretOffset);
-
+ return new Point(position, 0);
}
-
- private Point getMousePosition(nsIDOMEvent domEvent) {
+ private Point getPageCoords(nsIDOMEvent domEvent) {
nsIDOMNSUIEvent nsuiEvent = (nsIDOMNSUIEvent)
domEvent.queryInterface(nsIDOMNSUIEvent.NS_IDOMNSUIEVENT_IID);
return new Point(nsuiEvent.getPageX(), nsuiEvent.getPageY());
@@ -934,236 +830,545 @@
// return null;
}
- private VpeVisualDropInfo getDropInfo(nsIDOMEvent event) {
- nsIDOMNSUIEvent nsuiEvent = (nsIDOMNSUIEvent)
- event.queryInterface(nsIDOMNSUIEvent.NS_IDOMNSUIEVENT_IID);
- nsIDOMNode dropContainer = null;
+ private VpeSourceDropInfo getDropInfo(nsIDOMEvent event) {
+ Node dropContainer = null;
int dropOffset = 0;
- int mouseX = nsuiEvent.getPageX();
- int mouseY = nsuiEvent.getPageY();
-
- nsIDOMDocument document = vpeController.getVisualBuilder()
- .getOriginalTargetNode(event).getOwnerDocument();
-
- nsIDOMNSDocument nsDocument = (nsIDOMNSDocument) document
- .queryInterface(nsIDOMNSDocument.NS_IDOMNSDOCUMENT_IID);
- nsIDOMNode originalNode = DndUtil.getElementFromPoint(nsDocument, mouseX, mouseY);
-// if (originalNode != null) {
-// if (dropableArea == null) {
-// dropableArea = new DropableArea(document);
-// dropableArea.setDropSpots(EnumSet.allOf(DropSpot.class));
-// }
-// dropableArea.setNode(originalNode);
-// dropableArea.setHighlightedSpot(mouseX, mouseY);
-// dropableArea.setVisible(true);
-// dropableArea.redraw();
-// }
-
- if (originalNode == null || originalNode.getParentNode() == null ||
- originalNode.getParentNode().getNodeType() == Node.DOCUMENT_NODE) {
- return new VpeVisualDropInfo(null, 0);
- }
- if (originalNode.getNodeType() == Node.TEXT_NODE) {
- dropContainer = nsuiEvent.getRangeParent();
- nsIDOMNode containerForPseudoContent = VpePseudoContentCreator
- .getContainerForPseudoContent(dropContainer);
- if (containerForPseudoContent != null) {
- dropContainer = containerForPseudoContent;
- dropOffset = 0;
- } else {
- dropOffset = nsuiEvent.getRangeOffset();
- }
- } else {
- int closestXDistance = HUGE_DISTANCE;
- int closestYDistance = HUGE_DISTANCE;
- boolean inNodeFlag = false;
- nsIDOMNode closestNode = null;
-
- nsIDOMNodeList childen = originalNode.getChildNodes();
- long count = childen.getLength();
- for (long i = 0; i < count; i++) {
- nsIDOMNode child = childen.item(i);
- if (VpeVisualDomBuilder.isPseudoElement(child)
- || VpeVisualDomBuilder.isAnonElement(child)) {
- continue;
- }
- Rectangle rect = XulRunnerVpeUtils.getElementBounds(child);
- int fromTop = mouseY - rect.y;
- int fromBottom = mouseY - rect.y - rect.height;
-
- int yDistance;
- if (fromTop > 0 && fromBottom < 0) {
- yDistance = 0;
- } else {
- yDistance = Math.min(Math.abs(fromTop), Math.abs(fromBottom));
- }
-
- if (yDistance <= closestYDistance && rect.width > 0 &&
rect.height > 0) {
- if (yDistance < closestYDistance) {
- closestXDistance = HUGE_DISTANCE;
- }
- int fromLeft = mouseX - rect.x;
- int fromRight = mouseX - rect.x - rect.width;
-
- int xDistance;
- if (fromLeft > 0 && fromRight < 0) {
- xDistance = 0;
- } else {
- xDistance = Math.min(Math.abs(fromLeft), Math.abs(fromRight));
- }
- if (xDistance == 0 && yDistance == 0) {
- closestNode = child;
- inNodeFlag = true;
+ boolean canDrop = false;
+ if (dropableArea != null && dropableArea.getNode() != null
+ && dropableArea.getHighlightedDropTarget() != null) {
+ canDrop = true;
+ DropTarget dropTarget = dropableArea.getHighlightedDropTarget();
+ Node targetNode = vpeController.getDomMapping()
+ .getNearSourceNode(dropableArea.getNode());
+
+ if (dropTarget == DropTarget.BEFORE || dropTarget == DropTarget.AFTER) {
+ dropContainer = targetNode.getParentNode();
+ int offset = 0;
+ for (int i = 0; i < dropContainer.getChildNodes().getLength(); i++) {
+ if (targetNode.equals(dropContainer.getChildNodes().item(i))) {
break;
}
-
- if (xDistance < closestXDistance || (xDistance == closestXDistance &&
rect.x <= mouseX)) {
- closestXDistance = xDistance;
- closestYDistance = yDistance;
- closestNode = child;
- }
+ offset++;
}
- }
-
- if (closestNode == null) {
- closestNode = originalNode;
- inNodeFlag = true;
- }
- if (inNodeFlag) {
- if (closestNode.getNodeType() == Node.TEXT_NODE) {
- dropContainer = nsuiEvent.getRangeParent();
- dropOffset = nsuiEvent.getRangeOffset();
- } else {
- if (HTML.TAG_COLGROUP.equalsIgnoreCase(closestNode.getNodeName())) {
- nsIDOMNode nearChild = getNearChild(closestNode, mouseX, mouseY);
- if (nearChild != null && nearChild.getNodeType() == Node.ELEMENT_NODE) {
- dropContainer = nearChild;
- } else {
- dropContainer = closestNode;
- }
- } else {
- dropContainer = closestNode;
- }
+
+ if (dropTarget == DropTarget.BEFORE) {
+ dropOffset = offset;
+ } else if (dropTarget == DropTarget.AFTER) {
+ dropOffset = offset + 1;
+ }
+ } else if(dropTarget == DropTarget.BEGIN || dropTarget == DropTarget.END) {
+ dropContainer = targetNode;
+ if (dropTarget == DropTarget.BEGIN) {
dropOffset = 0;
+ } else if (dropTarget == DropTarget.END) {
+ dropOffset = dropContainer.getChildNodes().getLength();
}
- } else {
- dropContainer = closestNode.getParentNode();
- dropOffset = (int)VisualDomUtil.getOffset(closestNode);
- Rectangle rect = XulRunnerVpeUtils.getElementBounds(closestNode);
- if (canInsertAfter(mouseX, mouseY, rect)) {
- dropOffset++;
- }
}
}
- VpeVisualDropInfo info = new VpeVisualDropInfo(dropContainer, dropOffset);
- return info;
+
+ return new VpeSourceDropInfo(dropContainer, dropOffset, canDrop);
+
+// nsIDOMNSUIEvent nsuiEvent = (nsIDOMNSUIEvent)
+// event.queryInterface(nsIDOMNSUIEvent.NS_IDOMNSUIEVENT_IID);
+// int mouseX = nsuiEvent.getPageX();
+// int mouseY = nsuiEvent.getPageY();
+// nsIDOMNode dropContainer = null;
+// int dropOffset = 0;
+//
+// nsIDOMDocument document = vpeController.getVisualBuilder()
+// .getOriginalTargetNode(event).getOwnerDocument();
+//
+// nsIDOMNode originalNode = DndUtil.getElementFromPoint(document, mouseX, mouseY);
+//// if (originalNode != null) {
+//// if (dropableArea == null) {
+//// dropableArea = new DropableArea(document);
+//// dropableArea.setDropSpots(EnumSet.allOf(DropSpot.class));
+//// }
+//// dropableArea.setNode(originalNode);
+//// dropableArea.setHighlightedSpot(mouseX, mouseY);
+//// dropableArea.setVisible(true);
+//// dropableArea.redraw();
+//// }
+//
+// if (originalNode == null || originalNode.getParentNode() == null ||
+// originalNode.getParentNode().getNodeType() == Node.DOCUMENT_NODE) {
+// return new VpeVisualDropInfo(null, 0);
+// }
+// if (originalNode.getNodeType() == Node.TEXT_NODE) {
+// dropContainer = nsuiEvent.getRangeParent();
+// nsIDOMNode containerForPseudoContent = VpePseudoContentCreator
+// .getContainerForPseudoContent(dropContainer);
+// if (containerForPseudoContent != null) {
+// dropContainer = containerForPseudoContent;
+// dropOffset = 0;
+// } else {
+// dropOffset = nsuiEvent.getRangeOffset();
+// }
+// } else {
+// int closestXDistance = HUGE_DISTANCE;
+// int closestYDistance = HUGE_DISTANCE;
+// boolean inNodeFlag = false;
+// nsIDOMNode closestNode = null;
+//
+// nsIDOMNodeList childen = originalNode.getChildNodes();
+// long count = childen.getLength();
+// for (long i = 0; i < count; i++) {
+// nsIDOMNode child = childen.item(i);
+// if (VpeVisualDomBuilder.isPseudoElement(child)
+// || VpeVisualDomBuilder.isAnonElement(child)) {
+// continue;
+// }
+// Rectangle rect = XulRunnerVpeUtils.getElementBounds(child);
+// int fromTop = mouseY - rect.y;
+// int fromBottom = mouseY - rect.y - rect.height;
+//
+// int yDistance;
+// if (fromTop > 0 && fromBottom < 0) {
+// yDistance = 0;
+// } else {
+// yDistance = Math.min(Math.abs(fromTop), Math.abs(fromBottom));
+// }
+//
+// if (yDistance <= closestYDistance && rect.width > 0 &&
rect.height > 0) {
+// if (yDistance < closestYDistance) {
+// closestXDistance = HUGE_DISTANCE;
+// }
+// int fromLeft = mouseX - rect.x;
+// int fromRight = mouseX - rect.x - rect.width;
+//
+// int xDistance;
+// if (fromLeft > 0 && fromRight < 0) {
+// xDistance = 0;
+// } else {
+// xDistance = Math.min(Math.abs(fromLeft), Math.abs(fromRight));
+// }
+// if (xDistance == 0 && yDistance == 0) {
+// closestNode = child;
+// inNodeFlag = true;
+// break;
+// }
+//
+// if (xDistance < closestXDistance || (xDistance == closestXDistance &&
rect.x <= mouseX)) {
+// closestXDistance = xDistance;
+// closestYDistance = yDistance;
+// closestNode = child;
+// }
+// }
+// }
+//
+// if (closestNode == null) {
+// closestNode = originalNode;
+// inNodeFlag = true;
+// }
+// if (inNodeFlag) {
+// if (closestNode.getNodeType() == Node.TEXT_NODE) {
+// dropContainer = nsuiEvent.getRangeParent();
+// dropOffset = nsuiEvent.getRangeOffset();
+// } else {
+// if (HTML.TAG_COLGROUP.equalsIgnoreCase(closestNode.getNodeName())) {
+// nsIDOMNode nearChild = getNearChild(closestNode, mouseX, mouseY);
+// if (nearChild != null && nearChild.getNodeType() == Node.ELEMENT_NODE) {
+// dropContainer = nearChild;
+// } else {
+// dropContainer = closestNode;
+// }
+// } else {
+// dropContainer = closestNode;
+// }
+// dropOffset = 0;
+// }
+// } else {
+// dropContainer = closestNode.getParentNode();
+// dropOffset = (int)VisualDomUtil.getOffset(closestNode);
+// Rectangle rect = XulRunnerVpeUtils.getElementBounds(closestNode);
+// if (canInsertAfter(mouseX, mouseY, rect)) {
+// dropOffset++;
+// }
+// }
+// }
}
-
- private VpeVisualDropInfo getDropInfo(Node sourceDropContainer,
- int sourceDropOffset) {
- nsIDOMNode visualDropContainer = null;
- long visualDropOffset = 0;
- switch (sourceDropContainer.getNodeType()) {
- case Node.TEXT_NODE:
- visualDropContainer =
vpeController.getDomMapping().getVisualNode(sourceDropContainer);
- visualDropOffset = TextUtil.visualInnerPosition(sourceDropContainer
- .getNodeValue(), sourceDropOffset);
- break;
- case Node.ELEMENT_NODE:
- case Node.DOCUMENT_NODE:
- NodeList sourceChildren = sourceDropContainer.getChildNodes();
- if (sourceDropOffset < sourceChildren.getLength()) {
- Node sourceChild = sourceChildren.item(sourceDropOffset);
- nsIDOMNode visualChild = vpeController.getDomMapping().getVisualNode(sourceChild);
- if (visualChild != null) {
- visualDropContainer = visualChild.getParentNode();
-
- visualDropOffset = VisualDomUtil.getOffset(visualChild);
- }
- }
- if (visualDropContainer == null) {
- visualDropContainer = vpeController.getDomMapping()
- .getNearVisualNode(sourceDropContainer);
- nsIDOMNode visualChild =
VpeVisualDomBuilder.getLastAppreciableVisualChild(visualDropContainer);
- if (visualChild != null) {
- visualDropOffset = VisualDomUtil.getOffset(visualChild) + 1;
- } else {
- visualDropOffset = 0;
- }
- }
- break;
- case Node.ATTRIBUTE_NODE:
- Element sourceElement = ((Attr) sourceDropContainer)
- .getOwnerElement();
- VpeElementMapping elementMapping = vpeController.getDomMapping()
- .getNearElementMapping(sourceElement);
- nsIDOMNode textNode = elementMapping.getTemplate()
- .getOutputTextNode(vpeController.getPageContext(), sourceElement,
- elementMapping.getData());
- if (textNode != null) {
- visualDropContainer = textNode;
- visualDropOffset = TextUtil.visualInnerPosition(
- sourceDropContainer.getNodeValue(), sourceDropOffset);
- }
- break;
- }
- if (visualDropContainer == null) {
- return null;
- }
- return new VpeVisualDropInfo(visualDropContainer, visualDropOffset);
+ private interface DropResolver {
+ public boolean canDrop(Node node);
}
- private nsIDOMNode getNearChild(nsIDOMNode container, int x, int y) {
- int closestXDistance = HUGE_DISTANCE;
- int closestYDistance = HUGE_DISTANCE;
- nsIDOMNode closestNode = null;
+// TODO: delete the following methods, as they are never used
+// this method is never used
+// private boolean canInsertAfter(int x, int y, Rectangle rect) {
+// if (y > (rect.y + rect.height) || x > (rect.x + rect.width)) {
+// return true;
+// }
+// return y >= rect.x && x > (rect.x + rect.width / 2);
+// }
+
+// this method is never used
+// private MozillaDropInfo canExternalDrop(nsIDOMMouseEvent mouseEvent, String flavor,
String data) {
+// InnerDragBuffer.object = null;
+// vpeController.onHideTooltip();
+//
+// if (vpeController.getDropWindow().isActive()) {
+// if (!mouseEvent.getAltKey()) {
+// vpeController.getDropWindow().close();
+// } else {
+// return new MozillaDropInfo(false, null, 0);
+// }
+// }
+// if (mouseEvent.getAltKey()) {
+// nsIDOMNode visualNode = (nsIDOMNode) mouseEvent.getTarget()
+// .queryInterface(nsIDOMNode.NS_IDOMNODE_IID);
+// Node sourceNode = vpeController.getDomMapping().getNearSourceNode(visualNode);
+// if (sourceNode != null) {
+// if (ModelTransfer.MODEL.equals(flavor)) {
+// // XModelObject object =
+// // PreferenceModelUtilities.getPreferenceModel().
+// // getModelBuffer().source();
+// // InnerDragBuffer.object = object;
+// } else {
+// vpeController.getDropWindow().setFlavor(flavor);
+// }
+// vpeController.getDropWindow().setActive(true);
+// vpeController.getDropWindow().setEventPosition(mouseEvent.getScreenX(), mouseEvent
+// .getScreenY());
+// vpeController.getDropWindow().setInitialTargetNode(sourceNode);
+// vpeController.getDropWindow().open();
+// mouseEvent.stopPropagation();
+// mouseEvent.preventDefault();
+// return new MozillaDropInfo(false, null, 0);
+// }
+// }
+// boolean canDrop = false;
+// nsIDOMNode caretParent = null;
+// long caretOffset = 0;
+//
+// if (VpeController.MODEL_FLAVOR.equals(flavor)) {
+// XModelObject object = PreferenceModelUtilities.getPreferenceModel()
+// .getModelBuffer().source();
+// if (object.getFileType() == XModelObject.FILE
+// && !TLDUtil.isTaglib(object)) {
+// IFile f = (IFile) EclipseResourceUtil.getResource(object);
+// canDrop = f != null;
+// VpeVisualDropInfo visualDropInfo = getDropInfo(mouseEvent);
+// caretParent = visualDropInfo.getDropContainer();
+// caretOffset = visualDropInfo.getDropOffset();
+// } else {
+// String tagname = vpeController.getTagName(object);
+// if (tagname.indexOf("taglib") >= 0)tagname = "taglib";
//$NON-NLS-1$ //$NON-NLS-2$
+// Node sourceDragNode = ((Document) vpeController.getModel().getAdapter(
+// Document.class)).createElement(tagname);
+// VpeVisualDropInfo visualDropInfo = getDropInfo(mouseEvent);
+// if (visualDropInfo.getDropContainer() != null) {
+// VpeSourceDropInfo sourceDropInfo
+// = getSourceDropInfo(
+// sourceDragNode, visualDropInfo, true);
+// canDrop = sourceDropInfo.canDrop();
+// if (canDrop) {
+// VpeVisualDropInfo newVisualDropInfo
+// = getDropInfo(
+// sourceDropInfo.getContainer(),
+// sourceDropInfo.getOffset());
+// if (newVisualDropInfo != null) {
+// correctVisualDropPosition(mouseEvent,
+// newVisualDropInfo, visualDropInfo);
+// caretParent = newVisualDropInfo.getDropContainer();
+// caretOffset = newVisualDropInfo.getDropOffset();
+// }
+// }
+// }
+// visualDropInfo.release();
+// }
+// } else if (XulRunnerEditor.TRANS_FLAVOR_kFileMime.equals(flavor)
+// || XulRunnerEditor.TRANS_FLAVOR_kURLMime.equals(flavor)) {
+// VpeVisualDropInfo visualDropInfo = getDropInfo(mouseEvent);
+// caretParent = visualDropInfo.getDropContainer();
+// caretOffset = visualDropInfo.getDropOffset();
+// canDrop = true;
+//
+// }
+// if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
+// System.out.println(" canDrop: " + canDrop //$NON-NLS-1$
+// + (canDrop ?
+// " container: " //$NON-NLS-1$
+// + caretParent.getNodeName()
+// + " offset: " //$NON-NLS-1$
+// + caretOffset
+// : "")); //$NON-NLS-1$
+// }
+// return new MozillaDropInfo(canDrop, caretParent, caretOffset);
+//
+// }
- nsIDOMNodeList childen = container.getChildNodes();
- long count = childen.getLength();
- for (long i = 0; i < count; i++) {
- nsIDOMNode child = childen.item(i);
- if (VpeVisualDomBuilder.isPseudoElement(child) ||
VpeVisualDomBuilder.isAnonElement(child)) {
- continue;
- }
- Rectangle rect = XulRunnerVpeUtils.getElementBounds(child);
- int fromTop = y - rect.y;
- int fromBottom = y - rect.y - rect.height;
+// this method is never used
+// private VpeSourceDropInfo getSourceDropInfo(Node dragNode,
+// Node container, int offset, boolean checkParentsTemplates) {
+// // Thread.dumpStack();
+// boolean canDrop = false;
+// switch (container.getNodeType()) {
+// case Node.ELEMENT_NODE:
+// VpeNodeMapping nodeMapping = vpeController.getDomMapping()
+// .getNodeMapping(container);
+// if (nodeMapping != null && nodeMapping instanceof VpeElementMapping) {
+// canDrop = ((VpeElementMapping) nodeMapping).getTemplate()
+// .canInnerDrop(vpeController.getPageContext(), container, dragNode);
+// }
+// if (!canDrop) {
+// if (!checkParentsTemplates)
+// return new VpeSourceDropInfo(container, offset,
+// canDrop);
+// // offset = ((NodeImpl)container).getIndex();
+// // container = container.getParentNode();
+// // TODO Max Areshkau unclear logic , if we can drop on element
+// // why we trying to drop
+// // this on parent
+// // return getSourceDropInfo(dragNode, container, offset,
+// // false);
+// return new VpeSourceDropInfo(container, offset, canDrop);
+// }
+// break;
+// case Node.TEXT_NODE:
+// case Node.DOCUMENT_NODE:
+// canDrop = true;
+// break;
+// case Node.ATTRIBUTE_NODE:
+// canDrop = true;
+// break;
+// }
+// if (canDrop) {
+// return new VpeSourceDropInfo(container, offset, canDrop);
+// } else {
+// return new VpeSourceDropInfo(null, 0, canDrop);
+// }
+// }
- int yDistance;
- if (fromTop > 0 && fromBottom < 0) {
- yDistance = 0;
- } else {
- yDistance = Math.min(Math.abs(fromTop), Math.abs(fromBottom));
- }
-
- if (yDistance <= closestYDistance && rect.width > 0 &&
rect.height > 0) {
- if (yDistance < closestYDistance) {
- closestXDistance = HUGE_DISTANCE;
- }
- int fromLeft = x - rect.x;
- int fromRight = x - rect.x - rect.width;
+// this method is never used
+// private VpeSourceDropInfo getSourceDropInfo(Node sourceDragNode,
+// VpeVisualDropInfo visualDropInfo, boolean checkParentTemplates) {
+// nsIDOMNode visualDropContainer = visualDropInfo.getDropContainer();
+// long visualDropOffset = visualDropInfo.getDropOffset();
+// Node sourceDropContainer = null;
+// int sourceDropOffset = 0;
+//
+// switch (visualDropContainer.getNodeType()) {
+// case nsIDOMNode.ELEMENT_NODE:
+// nsIDOMNode visualOffsetNode = null;
+// boolean afterFlag = false;
+// long visualChildCount = VisualDomUtil
+// .getChildCount(visualDropContainer);
+// if (visualDropOffset < visualChildCount) {
+// visualOffsetNode = VisualDomUtil.getChildNode(
+// visualDropContainer, visualDropOffset);
+// if (VpeVisualDomBuilder.isPseudoElement(visualOffsetNode)
+// || VpeVisualDomBuilder.isAnonElement(visualOffsetNode)) {
+// visualOffsetNode = VpeVisualDomBuilder
+// .getLastAppreciableVisualChild(visualDropContainer);
+// afterFlag = true;
+// }
+// } else {
+// visualOffsetNode =
VpeVisualDomBuilder.getLastAppreciableVisualChild(visualDropContainer);
+// afterFlag = visualChildCount != 0;
+// }
+// if (visualOffsetNode != null) {
+// Node sourceOffsetNode = vpeController.getDomMapping()
+// .getSourceNode(visualOffsetNode);
+// if (sourceOffsetNode != null) {
+// sourceDropContainer = sourceOffsetNode.getParentNode();
+// sourceDropOffset = ((NodeImpl) sourceOffsetNode).getIndex();
+// if (afterFlag) {
+// sourceDropOffset++;
+// }
+// }
+// }
+// if (sourceDropContainer == null) {
+// sourceDropContainer = vpeController.getDomMapping()
+// .getNearSourceNode(visualDropContainer);
+// if (sourceDropContainer != null) {
+// sourceDropOffset = sourceDropContainer.getChildNodes()
+// .getLength();
+// }
+// }
+// if (sourceDropContainer == null) {
+// sourceDropContainer = vpeController.getDomMapping()
+// .getNearSourceNode(
+// vpeController.getVisualBuilder().getContentArea());
+// sourceDropOffset = sourceDropContainer.getChildNodes()
+// .getLength();
+// }
+// break;
+// case nsIDOMNode.TEXT_NODE:
+// VpeNodeMapping nodeMapping = vpeController.getDomMapping()
+// .getNearNodeMapping(visualDropContainer);
+// // switch (nodeMapping.getType()) {
+// // case VpeNodeMapping.TEXT_MAPPING:
+// sourceDropContainer = nodeMapping.getSourceNode();
+// sourceDropOffset = TextUtil.sourceInnerPosition(sourceDropContainer
+// .getNodeValue(), visualDropOffset);
+// // break;
+// // case VpeNodeMapping.ELEMENT_MAPPING:
+// // it's attribute
+// if (VpeVisualDomBuilder.isTextEditable(visualDropContainer)) {
+// String[] atributeNames = ((VpeElementMapping) nodeMapping)
+// .getTemplate().getOutputAttributeNames();
+// if (atributeNames != null && atributeNames.length > 0) {
+// Element sourceElement = (Element) nodeMapping
+// .getSourceNode();
+// sourceDropContainer = sourceElement
+// .getAttributeNode(atributeNames[0]);
+// sourceDropOffset = TextUtil.sourceInnerPosition(
+// sourceDropContainer.getNodeValue(),
+// visualDropOffset);
+// }
+// }
+// }
+// if (sourceDropContainer != null) {
+// return getSourceDropInfo(sourceDragNode, sourceDropContainer,
+// sourceDropOffset, checkParentTemplates);
+// } else {
+// return new VpeSourceDropInfo(null, 0, false);
+// }
+// }
- int xDistance;
- if (fromLeft > 0 && fromRight < 0) {
- xDistance = 0;
- } else {
- xDistance = Math.min(Math.abs(fromLeft), Math.abs(fromRight));
- }
- if (xDistance == 0 && yDistance == 0) {
- closestNode = child;
- break;
- }
- if (xDistance < closestXDistance || (xDistance == closestXDistance &&
rect.x <= x)) {
- closestXDistance = xDistance;
- closestYDistance = yDistance;
- closestNode = child;
- }
- }
- }
- return closestNode;
- }
// this method is never used
+// private void correctVisualDropPosition(nsIDOMMouseEvent mouseEvent,
+// VpeVisualDropInfo newVisualDropInfo,
+// VpeVisualDropInfo oldVisualDropInfo) {
+// nsIDOMNode newVisualDropContainer = newVisualDropInfo
+// .getDropContainer();
+// nsIDOMNode oldVisualDropContainer = oldVisualDropInfo
+// .getDropContainer();
+//
+// if (newVisualDropContainer.equals(oldVisualDropContainer)) {
+// newVisualDropInfo.setDropOffset(oldVisualDropInfo.getDropOffset());
+// return;
+// }
+//
+// nsIDOMNode child = oldVisualDropContainer;
+// while (child != null && child.getNodeType() != Node.DOCUMENT_NODE) {
+// nsIDOMNode parent = child.getParentNode();
+// if (newVisualDropContainer.equals(parent)) {
+// long offset = VisualDomUtil.getOffset(child);
+// Rectangle rect = XulRunnerVpeUtils.getElementBounds(child);
+//
+// nsIDOMNSUIEvent nsuiEvent = (nsIDOMNSUIEvent)
+// mouseEvent.queryInterface(nsIDOMNSUIEvent.NS_IDOMNSUIEVENT_IID);
+// int mouseX = nsuiEvent.getPageX();
+// int mouseY = nsuiEvent.getPageY();
+//
+// if (canInsertAfter(mouseX, mouseY, rect)) {
+// offset++;
+// }
+// newVisualDropInfo.setDropOffset(offset);
+// }
+// child = parent;
+// }
+// }
+
+// this method is never used
+// private VpeVisualDropInfo getDropInfo(Node sourceDropContainer,
+// int sourceDropOffset) {
+// nsIDOMNode visualDropContainer = null;
+// long visualDropOffset = 0;
+//
+// switch (sourceDropContainer.getNodeType()) {
+// case Node.TEXT_NODE:
+// visualDropContainer =
vpeController.getDomMapping().getVisualNode(sourceDropContainer);
+// visualDropOffset = TextUtil.visualInnerPosition(sourceDropContainer
+// .getNodeValue(), sourceDropOffset);
+// break;
+// case Node.ELEMENT_NODE:
+// case Node.DOCUMENT_NODE:
+// NodeList sourceChildren = sourceDropContainer.getChildNodes();
+// if (sourceDropOffset < sourceChildren.getLength()) {
+// Node sourceChild = sourceChildren.item(sourceDropOffset);
+// nsIDOMNode visualChild = vpeController.getDomMapping().getVisualNode(sourceChild);
+// if (visualChild != null) {
+// visualDropContainer = visualChild.getParentNode();
+//
+// visualDropOffset = VisualDomUtil.getOffset(visualChild);
+// }
+// }
+// if (visualDropContainer == null) {
+// visualDropContainer = vpeController.getDomMapping()
+// .getNearVisualNode(sourceDropContainer);
+// nsIDOMNode visualChild =
VpeVisualDomBuilder.getLastAppreciableVisualChild(visualDropContainer);
+// if (visualChild != null) {
+// visualDropOffset = VisualDomUtil.getOffset(visualChild) + 1;
+// } else {
+// visualDropOffset = 0;
+// }
+// }
+// break;
+// case Node.ATTRIBUTE_NODE:
+// Element sourceElement = ((Attr) sourceDropContainer)
+// .getOwnerElement();
+// VpeElementMapping elementMapping = vpeController.getDomMapping()
+// .getNearElementMapping(sourceElement);
+// nsIDOMNode textNode = elementMapping.getTemplate()
+// .getOutputTextNode(vpeController.getPageContext(), sourceElement,
+// elementMapping.getData());
+// if (textNode != null) {
+// visualDropContainer = textNode;
+// visualDropOffset = TextUtil.visualInnerPosition(
+// sourceDropContainer.getNodeValue(), sourceDropOffset);
+// }
+// break;
+// }
+// if (visualDropContainer == null) {
+// return null;
+// }
+// return new VpeVisualDropInfo(visualDropContainer, visualDropOffset);
+// }
+
+// this method is never used
+// private nsIDOMNode getNearChild(nsIDOMNode container, int x, int y) {
+// int closestXDistance = HUGE_DISTANCE;
+// int closestYDistance = HUGE_DISTANCE;
+// nsIDOMNode closestNode = null;
+//
+// nsIDOMNodeList childen = container.getChildNodes();
+// long count = childen.getLength();
+// for (long i = 0; i < count; i++) {
+// nsIDOMNode child = childen.item(i);
+// if (VpeVisualDomBuilder.isPseudoElement(child) ||
VpeVisualDomBuilder.isAnonElement(child)) {
+// continue;
+// }
+// Rectangle rect = XulRunnerVpeUtils.getElementBounds(child);
+// int fromTop = y - rect.y;
+// int fromBottom = y - rect.y - rect.height;
+//
+// int yDistance;
+// if (fromTop > 0 && fromBottom < 0) {
+// yDistance = 0;
+// } else {
+// yDistance = Math.min(Math.abs(fromTop), Math.abs(fromBottom));
+// }
+//
+// if (yDistance <= closestYDistance && rect.width > 0 &&
rect.height > 0) {
+// if (yDistance < closestYDistance) {
+// closestXDistance = HUGE_DISTANCE;
+// }
+// int fromLeft = x - rect.x;
+// int fromRight = x - rect.x - rect.width;
+//
+// int xDistance;
+// if (fromLeft > 0 && fromRight < 0) {
+// xDistance = 0;
+// } else {
+// xDistance = Math.min(Math.abs(fromLeft), Math.abs(fromRight));
+// }
+// if (xDistance == 0 && yDistance == 0) {
+// closestNode = child;
+// break;
+// }
+// if (xDistance < closestXDistance || (xDistance == closestXDistance &&
rect.x <= x)) {
+// closestXDistance = xDistance;
+// closestYDistance = yDistance;
+// closestNode = child;
+// }
+// }
+// }
+// return closestNode;
+// }
+
+// this method is never used
// public VpeSourceDropInfo canExternalDropMacro(XModelObject object, Node parentNode,
int offset) {
// String tagname = vpeController.getTagName(object);
// Node sourceDragNode = ((Document)
vpeController.getModel().getAdapter(Document.class))
Copied:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/dnd/VpeDnDHelper.java (from
rev 21518,
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/dnd/VpeDnd.java)
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/dnd/VpeDnDHelper.java
(rev 0)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/dnd/VpeDnDHelper.java 2010-04-21
09:10:45 UTC (rev 21574)
@@ -0,0 +1,284 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.vpe.dnd;
+
+import java.util.HashSet;
+
+import org.jboss.tools.vpe.editor.VpeSourceInnerDragInfo;
+import org.jboss.tools.vpe.editor.VpeSourceDropInfo;
+import org.jboss.tools.vpe.editor.context.VpePageContext;
+import org.jboss.tools.vpe.editor.template.VpeTemplateManager;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Text;
+
+
+public class VpeDnDHelper {
+ static final String TAG_DRAG = VpeTemplateManager.VPE_PREFIX +
"drag"; //$NON-NLS-1$
+ static final String TAG_DROP = VpeTemplateManager.VPE_PREFIX +
"drop"; //$NON-NLS-1$
+ static final String TAG_CONTAINER_CHILD = VpeTemplateManager.VPE_PREFIX +
"container-child"; //$NON-NLS-1$
+
+ static final String ATTRIBUTE_START_ENABLE = "start-enable"; //$NON-NLS-1$
+ static final String ATTRIBUTE_CONTAINER = "container"; //$NON-NLS-1$
+ static final String ATTRIBUTE_TAG_NAME = "tag-name"; //$NON-NLS-1$
+
+ static final String STRING_YES = "yes"; //$NON-NLS-1$
+
+ private boolean dragEnabled = false;
+ private boolean isContainer = false;
+ private HashSet<String> enabledTags = null;
+
+ public void setDndData(boolean dragEnabled, boolean isContainer){
+ this.dragEnabled = dragEnabled;
+ this.isContainer = isContainer;
+ enabledTags = null;
+ }
+
+ public void setDndData(Element node){
+ enabledTags = null;
+ NodeList children = node.getChildNodes();
+ if (children != null) {
+ int len = children.getLength();
+ boolean dragFlag = false;
+ boolean dropFlag = false;
+ for (int i = 0; i < len; i++) {
+ Node innerNode = children.item(i);
+ if (innerNode.getNodeType() == Node.ELEMENT_NODE) {
+ String name = innerNode.getNodeName();
+ if (name.startsWith(VpeTemplateManager.VPE_PREFIX)) {
+ if (!dragFlag && TAG_DRAG.equals(name)) {
+ if(STRING_YES.equalsIgnoreCase(((Element)innerNode).getAttribute(ATTRIBUTE_START_ENABLE)))
dragEnabled = true;
+ else dragEnabled = false;
+ dragFlag = true;
+ }
+ if (!dropFlag && TAG_DROP.equals(name)){
+ if(STRING_YES.equalsIgnoreCase(((Element)innerNode).getAttribute(ATTRIBUTE_CONTAINER)))
isContainer = true;
+ else isContainer = false;
+
+ dropFlag = true;
+ NodeList childNodes = innerNode.getChildNodes();
+ if (childNodes != null) {
+ int childNodesLength = childNodes.getLength();
+ if (childNodesLength > 0) {
+ enabledTags = new HashSet<String>();
+ }
+ for (int j = 0; j < childNodesLength; j++) {
+ Node child = childNodes.item(j);
+ if (child.getNodeType() == Node.ELEMENT_NODE) {
+ String tagName = child.getNodeName();
+ if (tagName.startsWith(VpeTemplateManager.VPE_PREFIX)) {
+ if (TAG_CONTAINER_CHILD.equals(tagName)) {
+ enabledTags.add(((Element)child).getAttribute(ATTRIBUTE_TAG_NAME).toLowerCase());
+ }
+ }
+ }
+ }
+ }
+ }
+ if(dragFlag && dropFlag)break;
+ }
+ }
+ }
+ }
+ }
+
+ public boolean isDragEnabled(){
+ return dragEnabled;
+ }
+
+ public boolean isDropEnabled(VpePageContext pageContext, Node container, Node node){
+ if(!pageContext.isAbsolutePosition() && isAncestor(container, node)) return
false;
+ if(isContainer){
+ if(enabledTags != null && enabledTags.size() > 0){
+ String name = node.getNodeType() == Node.ELEMENT_NODE ?
node.getLocalName().toLowerCase() : node.getNodeName();
+ if(enabledTags.contains(name)) return true;
+ else return false;
+ }else return true;
+ }
+ return false;
+ }
+
+ private boolean isAncestor(Node container, Node node){
+ Node curent = container;
+ while(curent != null){
+ if(curent.equals(node))return true;
+ curent = curent.getParentNode();
+ }
+ return false;
+ }
+
+ private void removeTextFromTextNode(Node node, int start, int end){
+ Node parent = node.getParentNode();
+ boolean split1=true, split2=true;
+ String text = node.getNodeValue();
+ if(start == 0)split1 = false;
+ if(end == (text.length()+1))split2 = false;
+ if(split1 && split2){
+ String text1 = text.substring(0,start);
+ String text2 = text.substring(end, text.length());
+
+ node.setNodeValue(text1+text2);
+ }else if(split1){
+ String text1 = text.substring(0,start);
+
+ node.setNodeValue(text1);
+ }else if(split2){
+ String text1 = text.substring(end, text.length());
+
+ node.setNodeValue(text1);
+ }else{
+ parent.removeChild(node);
+ }
+ }
+
+ private void insertTextIntoTextNode(Node node, String text, int offset) {
+ String oldText = node.getNodeValue();
+ if(oldText == null) return;
+ String newText = oldText.substring(0, offset)+text+oldText.substring(offset,
oldText.length());
+ node.setNodeValue(newText);
+ }
+
+ private void replaceTextInTextNode(Node node, int offset, int selStart, int selEnd) {
+ if (offset >= selStart && offset <= selEnd) {
+ return;
+ }
+ String oldText = node.getNodeValue();
+ if (oldText == null) {
+ return;
+ }
+ String selText = oldText.substring(selStart, selEnd);
+ String newText = null;
+ if (offset < selStart) {
+ newText = oldText.substring(0, offset) + selText + oldText.substring(offset, selStart)
+ oldText.substring(selEnd);
+ } else {
+ newText = oldText.substring(0, selStart) + oldText.substring(selEnd, offset) + selText
+ oldText.substring(offset);
+ }
+ node.setNodeValue(newText);
+ }
+
+ private void insertAnyTextIntoAnyText(Node container, int offset, Node node, int start,
int end) {
+ String nodeText = node.getNodeValue();
+ String draggedText = nodeText.substring(start, end);
+
+ if (node == container) {
+ replaceTextInTextNode(container, offset, start, end);
+ } else {
+ removeTextFromTextNode(node, start, end);
+ insertTextIntoTextNode(container, draggedText, offset);
+ }
+ }
+
+ public void drop(VpePageContext pageContext, VpeSourceInnerDragInfo dragInfo,
VpeSourceDropInfo dropInfo){
+ Node container = dropInfo.getContainer();
+ int offset = dropInfo.getOffset();
+ Node node = dragInfo.getNode();
+
+ switch (node.getNodeType()) {
+ case Node.TEXT_NODE:
+ case Node.ATTRIBUTE_NODE:
+ String nodeText = node.getNodeValue();
+ int beginPosition = Math.min(dragInfo.getOffset(), nodeText.length());
+ int endPosition = Math.min(dragInfo.getOffset() + dragInfo.getLength(),
nodeText.length());
+
+ switch (container.getNodeType()) {
+ case Node.TEXT_NODE:
+ case Node.ATTRIBUTE_NODE:
+ insertAnyTextIntoAnyText(container, offset, node, beginPosition, endPosition);
+ break;
+
+ case Node.ELEMENT_NODE:
+ case Node.DOCUMENT_NODE:
+ NodeList children = container.getChildNodes();
+ int count = children.getLength();
+ Node child = null;
+ boolean insertBefore = true;
+ if (offset < count) {
+ if (offset > 0) {
+ child = children.item(offset - 1);
+ insertBefore = false;
+ if (child.getNodeType() != Node.TEXT_NODE) {
+ child = children.item(offset);
+ insertBefore = true;
+ }
+ } else {
+ child = children.item(offset);
+ }
+ } else if (count > 0) {
+ child = children.item(count - 1);
+ insertBefore = false;
+ }
+ if (child != null && child.getNodeType() == Node.TEXT_NODE) {
+ if (insertBefore) {
+ insertAnyTextIntoAnyText(child, 0, node, beginPosition, endPosition);
+ } else {
+ insertAnyTextIntoAnyText(child, child.getNodeValue().length(), node, beginPosition,
endPosition);
+ }
+ } else {
+ removeTextFromTextNode(node, beginPosition, endPosition);
+ Document document = container.getNodeType()== Node.DOCUMENT_NODE ? (Document)
container : container.getOwnerDocument();
+ Node textNode = document.createTextNode(nodeText.substring(beginPosition,
endPosition));
+ if (offset < count) {
+ container.insertBefore(textNode, child);
+ } else {
+ container.appendChild(textNode);
+ }
+ }
+ break;
+ }
+ break;
+
+ case Node.ELEMENT_NODE:
+ if (!isAncestor(container, node)) {
+ Node parent = node.getParentNode();
+
+ switch (container.getNodeType()) {
+ case Node.TEXT_NODE:
+ Text text = (Text)container;
+ String str1 = text.getNodeValue().substring(0,offset);
+ String str2 = text.getNodeValue().substring(offset,text.getNodeValue().length());
+ //text.setNodeValue(str1);
+ //Text newText = text.splitText(offset);
+ Text newText = text.getOwnerDocument().createTextNode(str2);
+ text.getParentNode().insertBefore(newText, text.getNextSibling());
+ parent.removeChild(node);
+ text.getParentNode().insertBefore(node, newText);
+ text.getParentNode().removeChild(text);
+ Text oldText = text.getOwnerDocument().createTextNode(str1);
+ node.getParentNode().insertBefore(oldText, node);
+ break;
+
+ case Node.ELEMENT_NODE:
+ case Node.DOCUMENT_NODE:
+ NodeList children = container.getChildNodes();
+ int count = children.getLength();
+ Node child = null;
+ if (offset < count) {
+ child = children.item(offset);
+ } else if (count > 0) {
+ child = children.item(count - 1);
+ }
+ if (node != child) {
+ parent.removeChild(node);
+ if (offset < count) {
+ container.insertBefore(node, child);
+ } else {
+ container.appendChild(node);
+ }
+ }
+ break;
+ }
+ }
+ break;
+ }
+ }
+}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeSelectionBuilder.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeSelectionBuilder.java 2010-04-21
08:46:06 UTC (rev 21573)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeSelectionBuilder.java 2010-04-21
09:10:45 UTC (rev 21574)
@@ -908,7 +908,7 @@
return position;
}
- public Point getSourceSelectionRangeAtVisualNode(nsIDOMNode visualInitNode, int
visualInitOffset) {
+ private Point getSourceSelectionRangeAtVisualNode(nsIDOMNode visualInitNode, int
visualInitOffset) {
if (visualInitNode.getNodeType() == Node.TEXT_NODE) {
Node sourceNode = domMapping.getSourceNode(visualInitNode);
if (sourceNode == null) {
@@ -930,37 +930,6 @@
}
}
- Point getSourceSelectionRange(Node sourceInitNode, int sourceInitOffset) {
- int offset=0;
- int position=0;
- switch (sourceInitNode.getNodeType()) {
- case Node.TEXT_NODE:
- offset = Math.min(sourceInitOffset, sourceInitNode.getNodeValue().length());
- position = sourceBuilder.getPosition(sourceInitNode, offset, false);
- break;
- case Node.ELEMENT_NODE:
- case Node.DOCUMENT_NODE:
- NodeList children = sourceInitNode.getChildNodes();
- int count = children.getLength();
- if (sourceInitOffset < count) {
- Node sourceNode = children.item(sourceInitOffset);
- position = ((IndexedRegion)sourceNode).getStartOffset();
- } else if (count > 0) {
- Node sourceNode = children.item(count - 1);
- position = ((IndexedRegion)sourceNode).getEndOffset();
- } else {
- position = ((IndexedRegion)sourceInitNode).getStartOffset();
- if (sourceInitNode instanceof ElementImpl) {
- ElementImpl element = (ElementImpl)sourceInitNode;
- if (element.isContainer()) {
- position = element.getStartEndOffset();
- }
- }
- }
- break;
- }
- return new Point(position, offset);
- }
void setVisualElementSelection(nsIDOMMouseEvent mouseEvent) {
nsISelection selection =
visualSelectionController.getSelection(nsISelectionController.SELECTION_NORMAL);
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeSourceDomBuilder.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeSourceDomBuilder.java 2010-04-21
08:46:06 UTC (rev 21573)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeSourceDomBuilder.java 2010-04-21
09:10:45 UTC (rev 21574)
@@ -353,7 +353,7 @@
return empty;
}
- int getPosition(Node sourceNode, int offset, boolean innerFlag) {
+ public int getPosition(Node sourceNode, int offset, boolean innerFlag) {
int start = 0;
if (sourceNode != null) {
start = ((IndexedRegion) sourceNode).getStartOffset() + offset;
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualCaretInfo.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualCaretInfo.java 2010-04-21
08:46:06 UTC (rev 21573)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualCaretInfo.java 2010-04-21
09:10:45 UTC (rev 21574)
@@ -48,8 +48,4 @@
public int getSourcePosition() {
return selectionBuilder.getSourcePosition(rangeParent, rangeOffset);
}
-
- Point getSourceSelectionRange() {
- return selectionBuilder.getSourceSelectionRangeAtVisualNode(rangeParent, rangeOffset);
- }
}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java 2010-04-21
08:46:06 UTC (rev 21573)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java 2010-04-21
09:10:45 UTC (rev 21574)
@@ -44,6 +44,7 @@
import org.jboss.tools.jst.web.tld.TaglibData;
import org.jboss.tools.vpe.VpeDebug;
import org.jboss.tools.vpe.VpePlugin;
+import org.jboss.tools.vpe.dnd.VpeDnDHelper;
import org.jboss.tools.vpe.editor.context.VpePageContext;
import org.jboss.tools.vpe.editor.mapping.VpeDomMapping;
import org.jboss.tools.vpe.editor.mapping.VpeElementData;
@@ -60,7 +61,6 @@
import org.jboss.tools.vpe.editor.template.VpeTemplate;
import org.jboss.tools.vpe.editor.template.VpeTemplateManager;
import org.jboss.tools.vpe.editor.template.VpeToggableTemplate;
-import org.jboss.tools.vpe.editor.template.dnd.VpeDnd;
import org.jboss.tools.vpe.editor.template.expression.VpeExpressionException;
import org.jboss.tools.vpe.editor.util.ElService;
import org.jboss.tools.vpe.editor.util.FaceletUtil;
@@ -164,7 +164,6 @@
unborderedVisualNodes.add(HTML.TAG_LI);
unborderedVisualNodes.add(HTML.TAG_BR);
}
- private VpeDnd dropper;
private Map<IStorage, Document> includeDocuments = new HashMap<IStorage,
Document>();
private boolean showInvisibleTags;
@@ -181,8 +180,6 @@
// this.visualContentArea = visualEditor.getContentArea();
this.pageContext = pageContext;
// this.headNode = visualEditor.getHeadNode();
- dropper = new VpeDnd();
- dropper.setDndData(false, true);
// if (isFacelet()) {
// faceletFile = true;
@@ -1647,11 +1644,6 @@
}
}
- public void innerDrop(VpeSourceInnerDragInfo dragInfo,
- VpeSourceDropInfo dropInfo) {
- dropper.drop(pageContext, dragInfo, dropInfo);
- }
-
nsIDOMElement getNearDragElement(Element visualElement) {
VpeElementMapping elementMapping = domMapping
.getNearElementMapping(visualElement);
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaEventAdapter.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaEventAdapter.java 2010-04-21
08:46:06 UTC (rev 21573)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaEventAdapter.java 2010-04-21
09:10:45 UTC (rev 21574)
@@ -92,11 +92,6 @@
contentArea.addEventListener(MozillaEventAdapter.MOUSEUPEVENTTYPE, this, false);
contentArea.addEventListener(MozillaEventAdapter.MOUSEMOVEEVENTTYPE, this, false);
contentArea.addEventListener(MozillaEventAdapter.CONTEXTMENUEVENTTYPE, this, false);
- contentArea.addEventListener(MozillaEventAdapter.DRAGDROPEVENT, this, false);
- contentArea.addEventListener(MozillaEventAdapter.DRAGENTEREVENT, this, false);
- contentArea.addEventListener(MozillaEventAdapter.DRAGEXITEVENT,this, false);
- contentArea.addEventListener(MozillaEventAdapter.DRAGGESTUREEVENT, this, false);
- contentArea.addEventListener(MozillaEventAdapter.DRAGOVEREVENT, this, false);
contentArea.addEventListener(MozillaEventAdapter.DBLCLICK, this, false);
}
if (window != null) {
@@ -108,6 +103,12 @@
selectionPrivate.addSelectionListener(this);
}
if (document != null) {
+ document.addEventListener(MozillaEventAdapter.DRAGDROPEVENT, this, false);
+ document.addEventListener(MozillaEventAdapter.DRAGENTEREVENT, this, false);
+ document.addEventListener(MozillaEventAdapter.DRAGEXITEVENT,this, false);
+ document.addEventListener(MozillaEventAdapter.DRAGGESTUREEVENT, this, false);
+ document.addEventListener(MozillaEventAdapter.DRAGOVEREVENT, this, false);
+
document.addEventListener(MozillaEventAdapter.KEYPRESS, this, false);
//as a fix of
https://jira.jboss.org/jira/browse/JBIDE-4022
//scroll event listener was added for selection border redrawing
@@ -127,15 +128,16 @@
contentArea.removeEventListener(MozillaEventAdapter.MOUSEUPEVENTTYPE, this, false);
contentArea.removeEventListener(MozillaEventAdapter.MOUSEMOVEEVENTTYPE, this, false);
contentArea.removeEventListener(MozillaEventAdapter.CONTEXTMENUEVENTTYPE, this,
false);
- contentArea.removeEventListener(MozillaEventAdapter.DRAGDROPEVENT, this, false);
- contentArea.removeEventListener(MozillaEventAdapter.DRAGENTEREVENT, this, false);
- contentArea.removeEventListener(MozillaEventAdapter.DRAGEXITEVENT, this, false);
- contentArea.removeEventListener(MozillaEventAdapter.DRAGGESTUREEVENT, this, false);
- contentArea.removeEventListener(MozillaEventAdapter.DRAGOVEREVENT, this, false);
contentArea.removeEventListener(MozillaEventAdapter.DBLCLICK, this, false);
contentArea = null;
}
if (document != null) {
+ document.removeEventListener(MozillaEventAdapter.DRAGDROPEVENT, this, false);
+ document.removeEventListener(MozillaEventAdapter.DRAGENTEREVENT, this, false);
+ document.removeEventListener(MozillaEventAdapter.DRAGEXITEVENT, this, false);
+ document.removeEventListener(MozillaEventAdapter.DRAGGESTUREEVENT, this, false);
+ document.removeEventListener(MozillaEventAdapter.DRAGOVEREVENT, this, false);
+
document.removeEventListener(MozillaEventAdapter.KEYPRESS, this, false);
document.removeEventListener(MozillaEventAdapter.SCROLL, this, false);
document = null;
@@ -282,7 +284,10 @@
} else if(DRAGENTEREVENT.equals(eventType)) {
//just ignore this event
} else if(DRAGEXITEVENT.equals(eventType)) {
- //just ignore this event
+ for (MozillaDndListener listener : listeners.getListeners(
+ MozillaDndListener.class)) {
+ listener.dragExit(domEvent);
+ }
} else if(DRAGOVEREVENT.equals(eventType)) {
for (MozillaDndListener listener : listeners.getListeners(
MozillaDndListener.class)) {
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/listener/MozillaDndListener.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/listener/MozillaDndListener.java 2010-04-21
08:46:06 UTC (rev 21573)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/listener/MozillaDndListener.java 2010-04-21
09:10:45 UTC (rev 21574)
@@ -38,4 +38,6 @@
// void dragExit(nsIDOMEvent event);
// void drop(nsIDOMEvent event);
// void onPasteOrDrop(nsIDOMMouseEvent mouseEvent, String flavor, String data);
+
+ void dragExit(nsIDOMEvent domEvent);
}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeAbstractTemplate.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeAbstractTemplate.java 2010-04-21
08:46:06 UTC (rev 21573)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeAbstractTemplate.java 2010-04-21
09:10:45 UTC (rev 21574)
@@ -23,6 +23,7 @@
import org.eclipse.wst.xml.core.internal.document.ElementImpl;
import org.jboss.tools.jst.jsp.editor.ITextFormatter;
import org.jboss.tools.vpe.VpePlugin;
+import org.jboss.tools.vpe.dnd.VpeDnDHelper;
import org.jboss.tools.vpe.editor.VpeSourceInnerDragInfo;
import org.jboss.tools.vpe.editor.VpeSourceDropInfo;
import org.jboss.tools.vpe.editor.context.VpePageContext;
@@ -31,7 +32,6 @@
import org.jboss.tools.vpe.editor.mapping.VpeElementData;
import org.jboss.tools.vpe.editor.mapping.VpeElementMapping;
import org.jboss.tools.vpe.editor.selection.VpeSourceSelection;
-import org.jboss.tools.vpe.editor.template.dnd.VpeDnd;
import org.jboss.tools.vpe.editor.template.expression.VpeExpressionException;
import org.jboss.tools.vpe.editor.template.resize.VpeResizer;
import org.jboss.tools.vpe.editor.template.textformating.TextFormatingData;
@@ -76,7 +76,7 @@
// TODO Max Areshkau add DnD support
/** The dragger. */
- private VpeDnd dragger;
+ private VpeDnDHelper dragger;
/** The text formating data. */
private TextFormatingData textFormatingData;
@@ -321,7 +321,7 @@
private void initDndHandler(Element templateSection) {
if (getDragger() == null) {
- setDragger(new VpeDnd());
+ setDragger(new VpeDnDHelper());
getDragger().setDndData(templateSection);
}
}
@@ -1279,7 +1279,7 @@
*
* @return the dragger
*/
- public VpeDnd getDragger() {
+ public VpeDnDHelper getDragger() {
return dragger;
}
@@ -1289,7 +1289,7 @@
*
* @param dragger the dragger to set
*/
- public void setDragger(VpeDnd dragger) {
+ public void setDragger(VpeDnDHelper dragger) {
this.dragger = dragger;
}