Author: yradtsevich
Date: 2010-03-23 10:25:55 -0400 (Tue, 23 Mar 2010)
New Revision: 20981
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/editor/VpeSelectionBuilder.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
Log:
https://jira.jboss.org/jira/browse/JBIDE-5042
Enhance DnD support in VPE
VPE Refactoring
- Drag&Drop-related methods have been moved from VpeSelectionBuilder to VpeDnD.
- Other minor changes like commenting unused methods etc.
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-03-23
13:33:10 UTC (rev 20980)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/dnd/VpeDnD.java 2010-03-23
14:25:55 UTC (rev 20981)
@@ -14,6 +14,7 @@
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.jboss.tools.common.model.XModelObject;
import org.jboss.tools.common.model.options.PreferenceModelUtilities;
@@ -35,11 +36,14 @@
import org.jboss.tools.vpe.editor.VpeSourceInnerDragInfo;
import org.jboss.tools.vpe.editor.VpeSourceInnerDropInfo;
import org.jboss.tools.vpe.editor.VpeVisualCaretInfo;
+import org.jboss.tools.vpe.editor.VpeVisualDomBuilder;
import org.jboss.tools.vpe.editor.VpeVisualInnerDragInfo;
import org.jboss.tools.vpe.editor.VpeVisualInnerDropInfo;
import org.jboss.tools.vpe.editor.mozilla.MozillaDropInfo;
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.VisualDomUtil;
import org.jboss.tools.vpe.editor.util.VpeDndUtil;
import org.jboss.tools.vpe.xulrunner.XPCOM;
@@ -49,7 +53,9 @@
import org.mozilla.interfaces.nsIDOMEvent;
import org.mozilla.interfaces.nsIDOMEventTarget;
import org.mozilla.interfaces.nsIDOMMouseEvent;
+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;
@@ -71,6 +77,8 @@
* Class responsible for Drag&Drop functionality
*/
public class VpeDnD implements MozillaDndListener {
+ private static int HUGE_DISTANCE = 999999;
+
/*
* Default transfer data
*/
@@ -140,7 +148,7 @@
* Starts drag session
* @param dragetElement
*/
- public void startDragSession(nsIDOMEvent domEvent) {
+ private void startDragSession(nsIDOMEvent domEvent) {
nsISupportsArray transArray = (nsISupportsArray) getComponentManager()
.createInstanceByContractID(XPCOM.NS_SUPPORTSARRAY_CONTRACTID, null,
nsISupportsArray.NS_ISUPPORTSARRAY_IID);
@@ -183,44 +191,6 @@
return iTransferable;
}
- /**
- * @return the componentManager
- */
- public nsIComponentManager getComponentManager() {
-
- if(componentManager==null) {
-
- componentManager = Mozilla.getInstance()
- .getComponentManager();
- }
- return componentManager;
- }
-
- /**
- * @return the serviceManager
- */
- public nsIServiceManager getServiceManager() {
-
- if(serviceManager==null) {
- serviceManager = Mozilla.getInstance()
- .getServiceManager();
- }
- return serviceManager;
- }
-
- /**
- * @return the dragService
- */
- public nsIDragService getDragService() {
-
- if(dragService==null) {
- dragService = (nsIDragService) getServiceManager()
- .getServiceByContractID(XPCOM.NS_DRAGSERVICE_CONTRACTID,
- nsIDragService.NS_IDRAGSERVICE_IID);
- }
- return dragService;
- }
-
private void refreshCanDrop(nsIDOMEvent event) {
boolean canDrop = true;
@@ -266,7 +236,7 @@
mouseEvent.stopPropagation();
}
- public void externalDropAny(final String flavor, final String data, final Point range,
+ private void externalDropAny(final String flavor, final String data, final Point range,
Node container) {
if (flavor == null || flavor.length() == 0)
return;
@@ -296,7 +266,7 @@
dropCommand.execute(dropData);
}
- public boolean canInnerDrag(nsIDOMMouseEvent event) {
+ private boolean canInnerDrag(nsIDOMMouseEvent event) {
vpeController.onHideTooltip();
if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
@@ -307,8 +277,7 @@
innerDragInfo = null;
}
boolean canDrag = false;
- VpeVisualInnerDragInfo dragInfo = vpeController.getSelectionBuilder()
- .getInnerDragInfo(event);
+ VpeVisualInnerDragInfo dragInfo = getInnerDragInfo(event);
if (dragInfo != null) {
nsIDOMNode dragNode = dragInfo.getNode();
if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
@@ -351,7 +320,7 @@
return canDrag;
}
- public MozillaDropInfo canInnerDrop(nsIDOMMouseEvent event) {
+ private MozillaDropInfo canInnerDrop(nsIDOMMouseEvent event) {
vpeController.onHideTooltip();
if (vpeController.getDropWindow().isActive()) {
@@ -383,8 +352,7 @@
nsIDOMNode caretParent = null;
long caretOffset = 0;
if (innerDragInfo != null) {
- VpeVisualInnerDropInfo visualDropInfo = vpeController.getSelectionBuilder()
- .getInnerDropInfo(event);
+ VpeVisualInnerDropInfo visualDropInfo = getInnerDropInfo(event);
if (visualDropInfo.getDropContainer() != null) {
if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
System.out.print(" x: " //$NON-NLS-1$
@@ -429,15 +397,14 @@
return new MozillaDropInfo(canDrop, caretParent, caretOffset);
}
- public void innerDrop(nsIDOMMouseEvent event) {
+ private void innerDrop(nsIDOMMouseEvent event) {
vpeController.onHideTooltip();
if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
System.out.print("<<<<<< innerDrop"); //$NON-NLS-1$
}
if (innerDragInfo != null) {
- VpeVisualInnerDropInfo visualDropInfo = vpeController.getSelectionBuilder()
- .getInnerDropInfo(event);
+ VpeVisualInnerDropInfo visualDropInfo = getInnerDropInfo(event);
if (visualDropInfo.getDropContainer() != null) {
if (VpeDebug.PRINT_VISUAL_INNER_DRAGDROP_EVENT) {
System.out
@@ -477,11 +444,10 @@
}
}
- public void externalDrop(nsIDOMMouseEvent mouseEvent, String flavor, String data) {
+ private void externalDrop(nsIDOMMouseEvent mouseEvent, String flavor, String data) {
vpeController.onHideTooltip();
- VpeVisualInnerDropInfo visualDropInfo = vpeController.getSelectionBuilder()
- .getInnerDropInfo(mouseEvent);
+ VpeVisualInnerDropInfo visualDropInfo = getInnerDropInfo(mouseEvent);
Point range = vpeController.getSelectionBuilder().getSourceSelectionRangeAtVisualNode(
visualDropInfo.getDropContainer(), (int) visualDropInfo
.getDropOffset());
@@ -558,7 +524,7 @@
}
}
- public MozillaDropInfo canExternalDrop(nsIDOMMouseEvent mouseEvent, String flavor,
String data) {
+ private MozillaDropInfo canExternalDrop(nsIDOMMouseEvent mouseEvent, String flavor,
String data) {
InnerDragBuffer.object = null;
vpeController.onHideTooltip();
@@ -605,8 +571,7 @@
&& !TLDUtil.isTaglib(object)) {
IFile f = (IFile) EclipseResourceUtil.getResource(object);
canDrop = f != null;
- VpeVisualInnerDropInfo visualDropInfo = vpeController.getSelectionBuilder()
- .getInnerDropInfo(mouseEvent);
+ VpeVisualInnerDropInfo visualDropInfo = getInnerDropInfo(mouseEvent);
caretParent = visualDropInfo.getDropContainer();
caretOffset = visualDropInfo.getDropOffset();
} else {
@@ -614,8 +579,7 @@
if (tagname.indexOf("taglib") >= 0)tagname = "taglib";
//$NON-NLS-1$ //$NON-NLS-2$
Node sourceDragNode = ((Document) vpeController.getModel().getAdapter(
Document.class)).createElement(tagname);
- VpeVisualInnerDropInfo visualDropInfo = vpeController.getSelectionBuilder()
- .getInnerDropInfo(mouseEvent);
+ VpeVisualInnerDropInfo visualDropInfo = getInnerDropInfo(mouseEvent);
if (visualDropInfo.getDropContainer() != null) {
VpeSourceInnerDropInfo sourceDropInfo = vpeController.getVisualBuilder()
.getSourceInnerDropInfo(sourceDragNode,
@@ -638,8 +602,7 @@
}
} else if (XulRunnerEditor.TRANS_FLAVOR_kFileMime.equals(flavor)
|| XulRunnerEditor.TRANS_FLAVOR_kURLMime.equals(flavor)) {
- VpeVisualInnerDropInfo visualDropInfo = vpeController.getSelectionBuilder()
- .getInnerDropInfo(mouseEvent);
+ VpeVisualInnerDropInfo visualDropInfo = getInnerDropInfo(mouseEvent);
caretParent = visualDropInfo.getDropContainer();
caretOffset = visualDropInfo.getDropOffset();
canDrop = true;
@@ -653,6 +616,269 @@
}
+ /**
+ * @return the componentManager
+ */
+ private nsIComponentManager getComponentManager() {
+
+ if(componentManager==null) {
+
+ componentManager = Mozilla.getInstance()
+ .getComponentManager();
+ }
+ return componentManager;
+ }
+
+ /**
+ * @return the serviceManager
+ */
+ private nsIServiceManager getServiceManager() {
+
+ if(serviceManager==null) {
+ serviceManager = Mozilla.getInstance()
+ .getServiceManager();
+ }
+ return serviceManager;
+ }
+
+ /**
+ * @return the dragService
+ */
+ private nsIDragService getDragService() {
+
+ if(dragService==null) {
+ dragService = (nsIDragService) getServiceManager()
+ .getServiceByContractID(XPCOM.NS_DRAGSERVICE_CONTRACTID,
+ nsIDragService.NS_IDRAGSERVICE_IID);
+ }
+ return dragService;
+ }
+
+ private VpeVisualInnerDragInfo getInnerDragInfo(nsIDOMMouseEvent event) {
+ nsIDOMElement selectedElement =
vpeController.getVisualBuilder().getXulRunnerEditor().getLastSelectedElement();
+ if (selectedElement == null) {
+ return null;
+ } else {
+ return new VpeVisualInnerDragInfo(selectedElement);
+ }
+
+ // fix of JBIDE-4998
+// nsISelection selection = visualSelectionController.getSelection(
+// nsISelectionController.SELECTION_NORMAL);
+// nsIDOMNode focusNode = selection.getFocusNode();
+// nsIDOMNode anchorNode = selection.getAnchorNode();
+// //when we select input this function return null
+// //but we select elemnt
+// if(focusNode==null && anchorNode==null) {
+// nsIDOMNode visualNode =(nsIDOMNode) event.getTarget()
+// .queryInterface(nsIDOMNode.NS_IDOMNODE_IID);
+// //fix of JBIDE-1097
+// if(HTML.TAG_SPAN.equalsIgnoreCase(visualNode.getNodeName())) {
+// if(visualBuilder.getXulRunnerEditor().getLastSelectedElement() != null
+// && !visualBuilder.getNodeBounds(
+// visualBuilder.getXulRunnerEditor()
+// .getLastSelectedElement())
+// .contains(VisualDomUtil.getMousePoint(event))) {
+// return null;
+// }
+// }
+// int offset = (int) VisualDomUtil.getOffset(visualNode);
+// selection.removeAllRanges();
+// selection.collapse(visualNode.getParentNode(), offset);
+// try {
+// selection.extend(visualNode.getParentNode(), offset + 1);
+// } catch(XPCOMException ex) {
+// //just ignore exception
+// // throws when we trying drag element which already resizing
+// return null;
+// }
+// focusNode = selection.getFocusNode();
+// anchorNode = selection.getAnchorNode();
+// }
+// if (focusNode != null && focusNode.equals(anchorNode)) {
+// int focusOffset = selection.getFocusOffset();
+// int anchorOffset = selection.getAnchorOffset();
+// int offset = Math.min(focusOffset, anchorOffset);
+// int length = Math.max(focusOffset, anchorOffset) - offset;
+//
+// int focusNodeType = focusNode.getNodeType();
+// if (focusNodeType == nsIDOMNode.ELEMENT_NODE) {
+// if (length == 1) {
+// nsIDOMNodeList children = focusNode.getChildNodes();
+// nsIDOMNode selectedNode = children.item(
+// Math.min(focusOffset, anchorOffset));
+// if
(visualBuilder.getNodeBounds(selectedNode).contains(VisualDomUtil.getMousePoint(event)))
{
+// int selectedNodeType = selectedNode.getNodeType();
+// if (selectedNodeType == nsIDOMNode.ELEMENT_NODE) {
+// return new
VpeVisualInnerDragInfo((nsIDOMElement)selectedNode.queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID));
+// } else if (selectedNodeType == nsIDOMNode.TEXT_NODE) {
+// return new VpeVisualInnerDragInfo(selectedNode, 0,
selectedNode.getNodeValue().length());
+// }
+// }
+// }
+// } else if (focusNodeType == nsIDOMNode.TEXT_NODE) {
+// return new VpeVisualInnerDragInfo(focusNode, offset, length);
+// }
+// }
+//
+// return null;
+ }
+
+ private VpeVisualInnerDropInfo getInnerDropInfo(nsIDOMEvent event) {
+ nsIDOMNSUIEvent nsuiEvent = (nsIDOMNSUIEvent)
event.queryInterface(nsIDOMNSUIEvent.NS_IDOMNSUIEVENT_IID);
+ nsIDOMNode dropContainer = null;
+ int dropOffset = 0;
+ int mouseX = nsuiEvent.getPageX();
+ int mouseY = nsuiEvent.getPageY();
+ nsIDOMNode originalNode =
vpeController.getVisualBuilder().getOriginalTargetNode(event);
+ if (originalNode == null || originalNode.getParentNode() == null ||
+ originalNode.getParentNode().getNodeType() == Node.DOCUMENT_NODE) {
+ return new VpeVisualInnerDropInfo(null, 0, mouseX, mouseY);
+ }
+ 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 = vpeController.getVisualBuilder().getNodeBounds(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 = vpeController.getVisualBuilder().getNodeBounds(closestNode);
+ if (VpeVisualDomBuilder.canInsertAfter(mouseX, mouseY, rect)) {
+ dropOffset++;
+ }
+ }
+ }
+ VpeVisualInnerDropInfo info = new VpeVisualInnerDropInfo(dropContainer, dropOffset,
mouseX, mouseY);
+ return info;
+ }
+
+ 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 = vpeController.getVisualBuilder().getNodeBounds(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 VpeSourceInnerDropInfo canExternalDropMacro(XModelObject object, Node
parentNode, int offset) {
// String tagname = vpeController.getTagName(object);
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-03-23
13:33:10 UTC (rev 20980)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeSelectionBuilder.java 2010-03-23
14:25:55 UTC (rev 20981)
@@ -12,7 +12,6 @@
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
import org.eclipse.wst.xml.core.internal.document.CommentImpl;
import org.eclipse.wst.xml.core.internal.document.ElementImpl;
@@ -23,9 +22,7 @@
import org.jboss.tools.vpe.editor.mapping.VpeNodeMapping;
import org.jboss.tools.vpe.editor.selection.VpeSelectionController;
import org.jboss.tools.vpe.editor.template.VpePseudoContentCreator;
-import org.jboss.tools.vpe.editor.template.VpeTemplate;
import org.jboss.tools.vpe.editor.util.HTML;
-import org.jboss.tools.vpe.editor.util.SelectionUtil;
import org.jboss.tools.vpe.editor.util.TextUtil;
import org.jboss.tools.vpe.editor.util.VisualDomUtil;
import org.jboss.tools.vpe.xulrunner.editor.XulRunnerEditor;
@@ -41,7 +38,6 @@
import org.mozilla.interfaces.nsISelection;
import org.mozilla.interfaces.nsISelectionController;
import org.mozilla.interfaces.nsISelectionDisplay;
-import org.mozilla.xpcom.XPCOMException;
import org.w3c.dom.Attr;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -854,13 +850,15 @@
return new VpeVisualCaretInfo(this, nsuiEvent.getRangeParent(),
nsuiEvent.getRangeOffset());
}
- void showVisualDragCaret(nsIDOMNode node, int offset) {
- visualBuilder.showDragCaret(node, offset);
- }
+//this method is never used
+// void showVisualDragCaret(nsIDOMNode node, int offset) {
+// visualBuilder.showDragCaret(node, offset);
+// }
- void hideVisualDragCaret() {
- visualBuilder.hideDragCaret();
- }
+//this method is never used
+// void hideVisualDragCaret() {
+// visualBuilder.hideDragCaret();
+// }
int getSourcePosition(nsIDOMNode visualInitNode, int visualInitOffset) {
int position = 0;
@@ -964,180 +962,9 @@
return new Point(position, offset);
}
- nsIDOMNode getOriginalTargetNode(nsIDOMEvent event) {
- nsIDOMNode targetNode = VisualDomUtil.getTargetNode(event);
- if (HTML.TAG_INPUT.equalsIgnoreCase(targetNode.getNodeName())) {
- return targetNode;
- }
- nsIDOMNSEvent nsEvent = (nsIDOMNSEvent)
event.queryInterface(nsIDOMNSEvent.NS_IDOMNSEVENT_IID);
- // TODO Sergey Vasilyev figure out with TmpRealOriginalTarget
-// nsIDOMEventTarget target = nsEvent.getTmpRealOriginalTarget();
- nsIDOMEventTarget target = nsEvent.getOriginalTarget();
- nsIDOMNode originalNode = (nsIDOMNode)
target.queryInterface(nsIDOMNode.NS_IDOMNODE_IID);
- if (VpeVisualDomBuilder.isAnonElement(originalNode)) {
- originalNode = visualBuilder.getLastSelectedElement();
- }
- return originalNode;
- }
-
- public VpeVisualInnerDropInfo getInnerDropInfo(nsIDOMEvent event) {
- nsIDOMNSUIEvent nsuiEvent = (nsIDOMNSUIEvent)
event.queryInterface(nsIDOMNSUIEvent.NS_IDOMNSUIEVENT_IID);
- nsIDOMNode dropContainer = null;
- int dropOffset = 0;
- int mouseX = nsuiEvent.getPageX();
- int mouseY = nsuiEvent.getPageY();
- nsIDOMNode originalNode = getOriginalTargetNode(event);
- if (originalNode == null || originalNode.getParentNode() == null ||
- originalNode.getParentNode().getNodeType() == Node.DOCUMENT_NODE) {
- return new VpeVisualInnerDropInfo(null, 0, mouseX, mouseY);
- }
- 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 = visualBuilder.getNodeBounds(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 = visualBuilder.getNodeBounds(closestNode);
- if (VpeVisualDomBuilder.canInsertAfter(mouseX, mouseY, rect)) {
- dropOffset++;
- }
- }
- }
- VpeVisualInnerDropInfo info = new VpeVisualInnerDropInfo(dropContainer, dropOffset,
mouseX, mouseY);
- return info;
- }
-
- 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 = visualBuilder.getNodeBounds(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;
- }
-
void setVisualElementSelection(nsIDOMMouseEvent mouseEvent) {
nsISelection selection =
visualSelectionController.getSelection(nsISelectionController.SELECTION_NORMAL);
- nsIDOMNode visualNode = getOriginalTargetNode(mouseEvent);
+ nsIDOMNode visualNode = visualBuilder.getOriginalTargetNode(mouseEvent);
if (selection.containsNode(visualNode, false) ||
VpeVisualDomBuilder.isAnonElement(visualNode)) {
return;
}
@@ -1154,37 +981,38 @@
}
- nsIDOMElement getDragElement(nsIDOMMouseEvent mouseEvent) {
- nsIDOMElement dragElement = visualBuilder.getDragElement(mouseEvent);
- if (dragElement != null) {
- return dragElement;
- }
-
- nsIDOMNode visualNode = VisualDomUtil.getTargetNode(mouseEvent);
- //FIX FOR JBIDE-1468 added by Sergey Dzmitrovich
- if (visualNode != null
- && visualNode.getNodeType() == Node.ELEMENT_NODE
- && (HTML.TAG_INPUT.equalsIgnoreCase(visualNode.getNodeName())
- || HTML.TAG_OPTION.equalsIgnoreCase(visualNode
- .getNodeName())
- || HTML.TAG_BUTTON.equalsIgnoreCase(visualNode
- .getNodeName()) || HTML.TAG_SELECT
- .equalsIgnoreCase(visualNode.getNodeName()))
- /*&& !selection.containsNode(visualNode, false)*/
- && visualBuilder.canInnerDrag((nsIDOMElement) visualNode
- .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID))) {
- return (nsIDOMElement) visualNode
- .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID);
- }
- return null;
- }
+//this method is never used
+// nsIDOMElement getDragElement(nsIDOMMouseEvent mouseEvent) {
+// nsIDOMElement dragElement = visualBuilder.getDragElement(mouseEvent);
+// if (dragElement != null) {
+// return dragElement;
+// }
+//
+// nsIDOMNode visualNode = VisualDomUtil.getTargetNode(mouseEvent);
+// //FIX FOR JBIDE-1468 added by Sergey Dzmitrovich
+// if (visualNode != null
+// && visualNode.getNodeType() == Node.ELEMENT_NODE
+// && (HTML.TAG_INPUT.equalsIgnoreCase(visualNode.getNodeName())
+// || HTML.TAG_OPTION.equalsIgnoreCase(visualNode
+// .getNodeName())
+// || HTML.TAG_BUTTON.equalsIgnoreCase(visualNode
+// .getNodeName()) || HTML.TAG_SELECT
+// .equalsIgnoreCase(visualNode.getNodeName()))
+// /*&& !selection.containsNode(visualNode, false)*/
+// && visualBuilder.canInnerDrag((nsIDOMElement) visualNode
+// .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID))) {
+// return (nsIDOMElement) visualNode
+// .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID);
+// }
+// return null;
+// }
nsIDOMElement getAppropriateElementForSelection(nsIDOMEvent event) {
nsISelection selection =
visualSelectionController.getSelection(nsISelectionController.SELECTION_NORMAL);
nsIDOMNode visualNode = VisualDomUtil.getTargetNode(event);
if (visualNode != null) {
if (!HTML.TAG_INPUT.equalsIgnoreCase(visualNode.getNodeName())) {
- visualNode = getOriginalTargetNode(event);
+ visualNode = visualBuilder.getOriginalTargetNode(event);
}
if (visualNode != null && visualNode.getNodeType() == Node.ELEMENT_NODE
&& !selection.containsNode((nsIDOMNode)visualNode, false)) {
VpeElementMapping elementMapping = domMapping.getNearElementMapping(visualNode);
@@ -1208,77 +1036,6 @@
setSelection(selection);
}
- public VpeVisualInnerDragInfo getInnerDragInfo(nsIDOMMouseEvent event) {
- nsIDOMElement selectedElement
- = visualBuilder.getXulRunnerEditor().getLastSelectedElement();
- if (selectedElement == null) {
- return null;
- } else {
- return new VpeVisualInnerDragInfo(selectedElement);
- }
-
- // fix of JBIDE-4998
-// nsISelection selection = visualSelectionController.getSelection(
-// nsISelectionController.SELECTION_NORMAL);
-// nsIDOMNode focusNode = selection.getFocusNode();
-// nsIDOMNode anchorNode = selection.getAnchorNode();
-// //when we select input this function return null
-// //but we select elemnt
-// if(focusNode==null && anchorNode==null) {
-// nsIDOMNode visualNode =(nsIDOMNode) event.getTarget()
-// .queryInterface(nsIDOMNode.NS_IDOMNODE_IID);
-// //fix of JBIDE-1097
-// if(HTML.TAG_SPAN.equalsIgnoreCase(visualNode.getNodeName())) {
-// if(visualBuilder.getXulRunnerEditor().getLastSelectedElement() != null
-// && !visualBuilder.getNodeBounds(
-// visualBuilder.getXulRunnerEditor()
-// .getLastSelectedElement())
-// .contains(VisualDomUtil.getMousePoint(event))) {
-// return null;
-// }
-// }
-// int offset = (int) VisualDomUtil.getOffset(visualNode);
-// selection.removeAllRanges();
-// selection.collapse(visualNode.getParentNode(), offset);
-// try {
-// selection.extend(visualNode.getParentNode(), offset + 1);
-// } catch(XPCOMException ex) {
-// //just ignore exception
-// // throws when we trying drag element which already resizing
-// return null;
-// }
-// focusNode = selection.getFocusNode();
-// anchorNode = selection.getAnchorNode();
-// }
-// if (focusNode != null && focusNode.equals(anchorNode)) {
-// int focusOffset = selection.getFocusOffset();
-// int anchorOffset = selection.getAnchorOffset();
-// int offset = Math.min(focusOffset, anchorOffset);
-// int length = Math.max(focusOffset, anchorOffset) - offset;
-//
-// int focusNodeType = focusNode.getNodeType();
-// if (focusNodeType == nsIDOMNode.ELEMENT_NODE) {
-// if (length == 1) {
-// nsIDOMNodeList children = focusNode.getChildNodes();
-// nsIDOMNode selectedNode = children.item(
-// Math.min(focusOffset, anchorOffset));
-// if
(visualBuilder.getNodeBounds(selectedNode).contains(VisualDomUtil.getMousePoint(event)))
{
-// int selectedNodeType = selectedNode.getNodeType();
-// if (selectedNodeType == nsIDOMNode.ELEMENT_NODE) {
-// return new
VpeVisualInnerDragInfo((nsIDOMElement)selectedNode.queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID));
-// } else if (selectedNodeType == nsIDOMNode.TEXT_NODE) {
-// return new VpeVisualInnerDragInfo(selectedNode, 0,
selectedNode.getNodeValue().length());
-// }
-// }
-// }
-// } else if (focusNodeType == nsIDOMNode.TEXT_NODE) {
-// return new VpeVisualInnerDragInfo(focusNode, offset, length);
-// }
-// }
-//
-// return null;
- }
-
void setMouseUpSelection(nsIDOMMouseEvent mouseEvent) {
}
@@ -1303,35 +1060,36 @@
}
}
- void setCaretAtMouse(nsIDOMMouseEvent mouseEvent) {
- nsIDOMNode visualNode = VisualDomUtil.getTargetNode(mouseEvent);
- boolean isAnonElement = VpeVisualDomBuilder.isAnonElement(visualNode);
- if (isAnonElement) return;
- VpeVisualInnerDropInfo visualDropInfo = getInnerDropInfo(mouseEvent);
- nsIDOMNode visuaDropContainer = visualDropInfo.getDropContainer();
- if (visuaDropContainer.getNodeType() == Node.TEXT_NODE) return;
- int visualDropOffset = (int)visualDropInfo.getDropOffset();
- if (visualDropOffset > 0) {
- nsIDOMNodeList visualChildren = visuaDropContainer.getChildNodes();
- nsIDOMNode visualChild = visualChildren.item(visualDropOffset - 1);
- boolean isText = visualChild.getNodeType() == Node.TEXT_NODE;
- if (isText) return;
- }
- nsISelection selection =
visualSelectionController.getSelection(nsISelectionController.SELECTION_NORMAL);
- if (!VisualDomUtil.isSelectionContains(selection, visuaDropContainer,
visualDropOffset)) {
- setVisualCaret(visuaDropContainer, visualDropOffset);
- // TODO Sergey Vasilyev figure out with nsIFrameSelection
-// nsIFrameSelection frameSelection = presShell.getFrameSelection();
-// if (frameSelection != null) {
-// frameSelection.setMouseDownState(true);
-// }
-
- // was commented by Max Areshkau (with this code scrolling doesn't works)
- //
-// mouseEvent.preventDefault();
-// mouseEvent.stopPropagation();
- }
- }
+// this method is never used
+// void setCaretAtMouse(nsIDOMMouseEvent mouseEvent) {
+// nsIDOMNode visualNode = VisualDomUtil.getTargetNode(mouseEvent);
+// boolean isAnonElement = VpeVisualDomBuilder.isAnonElement(visualNode);
+// if (isAnonElement) return;
+// VpeVisualInnerDropInfo visualDropInfo = getInnerDropInfo(mouseEvent);
+// nsIDOMNode visuaDropContainer = visualDropInfo.getDropContainer();
+// if (visuaDropContainer.getNodeType() == Node.TEXT_NODE) return;
+// int visualDropOffset = (int)visualDropInfo.getDropOffset();
+// if (visualDropOffset > 0) {
+// nsIDOMNodeList visualChildren = visuaDropContainer.getChildNodes();
+// nsIDOMNode visualChild = visualChildren.item(visualDropOffset - 1);
+// boolean isText = visualChild.getNodeType() == Node.TEXT_NODE;
+// if (isText) return;
+// }
+// nsISelection selection =
visualSelectionController.getSelection(nsISelectionController.SELECTION_NORMAL);
+// if (!VisualDomUtil.isSelectionContains(selection, visuaDropContainer,
visualDropOffset)) {
+// setVisualCaret(visuaDropContainer, visualDropOffset);
+// // TODO Sergey Vasilyev figure out with nsIFrameSelection
+//// nsIFrameSelection frameSelection = presShell.getFrameSelection();
+//// if (frameSelection != null) {
+//// frameSelection.setMouseDownState(true);
+//// }
+//
+// // was commented by Max Areshkau (with this code scrolling doesn't works)
+// //
+//// mouseEvent.preventDefault();
+//// mouseEvent.stopPropagation();
+// }
+// }
void setVisualCaret(nsIDOMNode visualNode, int offset) {
nsISelection selection =
visualSelectionController.getSelection(nsISelectionController.SELECTION_NORMAL);
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-03-23
13:33:10 UTC (rev 20980)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualCaretInfo.java 2010-03-23
14:25:55 UTC (rev 20981)
@@ -34,15 +34,17 @@
public int getRageOffset(){
return rangeOffset;
}
+
+//this method is never used
+// public void showCaret() {
+// selectionBuilder.showVisualDragCaret(rangeParent, rangeOffset);
+// }
+
+//this method is never used
+// public void hideCaret() {
+// selectionBuilder.hideVisualDragCaret();
+// }
- public void showCaret() {
- selectionBuilder.showVisualDragCaret(rangeParent, rangeOffset);
- }
-
- public void hideCaret() {
- selectionBuilder.hideVisualDragCaret();
- }
-
public int getSourcePosition() {
return selectionBuilder.getSourcePosition(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-03-23
13:33:10 UTC (rev 20980)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java 2010-03-23
14:25:55 UTC (rev 20981)
@@ -76,8 +76,11 @@
import org.mozilla.interfaces.nsIDOMAttr;
import org.mozilla.interfaces.nsIDOMDocument;
import org.mozilla.interfaces.nsIDOMElement;
+import org.mozilla.interfaces.nsIDOMEvent;
+import org.mozilla.interfaces.nsIDOMEventTarget;
import org.mozilla.interfaces.nsIDOMHTMLDocument;
import org.mozilla.interfaces.nsIDOMMouseEvent;
+import org.mozilla.interfaces.nsIDOMNSEvent;
import org.mozilla.interfaces.nsIDOMNode;
import org.mozilla.interfaces.nsIDOMNodeList;
import org.mozilla.interfaces.nsIDOMRange;
@@ -891,7 +894,7 @@
return false;
}
- static boolean isPseudoElement(nsIDOMNode visualNode) {
+ public static boolean isPseudoElement(nsIDOMNode visualNode) {
if (visualNode == null) {
return false;
}
@@ -1554,7 +1557,7 @@
}
}
- static boolean isAnonElement(nsIDOMNode visualNode) {
+ public static boolean isAnonElement(nsIDOMNode visualNode) {
if (visualNode != null
&& visualNode.getNodeType() == nsIDOMNode.ELEMENT_NODE) {
String attrValue = ((nsIDOMElement) visualNode
@@ -1938,12 +1941,12 @@
return buffer.toString();
}
- Rectangle getNodeBounds(nsIDOMNode visualNode) {
+ public Rectangle getNodeBounds(nsIDOMNode visualNode) {
return XulRunnerVpeUtils.getElementBounds(visualNode);
}
- static boolean canInsertAfter(int x, int y, Rectangle rect) {
+ public static boolean canInsertAfter(int x, int y, Rectangle rect) {
if (y > (rect.y + rect.height) || x > (rect.x + rect.width)) {
return true;
}
@@ -2076,6 +2079,22 @@
}
return null;
}
+
+ public nsIDOMNode getOriginalTargetNode(nsIDOMEvent event) {
+ nsIDOMNode targetNode = VisualDomUtil.getTargetNode(event);
+ if (HTML.TAG_INPUT.equalsIgnoreCase(targetNode.getNodeName())) {
+ return targetNode;
+ }
+ nsIDOMNSEvent nsEvent = (nsIDOMNSEvent)
event.queryInterface(nsIDOMNSEvent.NS_IDOMNSEVENT_IID);
+ // TODO Sergey Vasilyev figure out with TmpRealOriginalTarget
+// nsIDOMEventTarget target = nsEvent.getTmpRealOriginalTarget();
+ nsIDOMEventTarget target = nsEvent.getOriginalTarget();
+ nsIDOMNode originalNode = (nsIDOMNode)
target.queryInterface(nsIDOMNode.NS_IDOMNODE_IID);
+ if (VpeVisualDomBuilder.isAnonElement(originalNode)) {
+ originalNode = getLastSelectedElement();
+ }
+ return originalNode;
+ }
public VpeSourceInnerDragInfo getSourceInnerDragInfo(
VpeVisualInnerDragInfo visualDragInfo) {