Author: yradtsevich
Date: 2010-10-01 11:12:31 -0400 (Fri, 01 Oct 2010)
New Revision: 25398
Modified:
branches/jbosstools-3.2.0.Beta1/vpe/plugins/org.jboss.tools.vpe.xulrunner/src/org/jboss/tools/vpe/xulrunner/editor/XulRunnerEditor.java
branches/jbosstools-3.2.0.Beta1/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/dnd/DraggablePattern.java
branches/jbosstools-3.2.0.Beta1/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/dnd/DraggableTextSelection.java
branches/jbosstools-3.2.0.Beta1/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/dnd/VpeDnD.java
branches/jbosstools-3.2.0.Beta1/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java
branches/jbosstools-3.2.0.Beta1/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaEventAdapter.java
Log:
JBIDE-7210
https://jira.jboss.org/browse/JBIDE-7210 :
Disabled text editing in VPE Visual Editor
JBIDE-6229
https://jira.jboss.org/browse/JBIDE-6229 :
Implement DnD support for selected text in VPE
- Commit #25094 is rolled back for the 3.2.0.Beta1 branch. The text editing works now, but
the text DnD does not.
Modified:
branches/jbosstools-3.2.0.Beta1/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/dnd/DraggablePattern.java
===================================================================
---
branches/jbosstools-3.2.0.Beta1/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/dnd/DraggablePattern.java 2010-10-01
14:47:13 UTC (rev 25397)
+++
branches/jbosstools-3.2.0.Beta1/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/dnd/DraggablePattern.java 2010-10-01
15:12:31 UTC (rev 25398)
@@ -13,9 +13,12 @@
import static org.jboss.tools.vpe.xulrunner.util.XPCOM.queryInterface;
import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
import org.jboss.tools.vpe.editor.mozilla.MozillaEditor;
import org.jboss.tools.vpe.editor.util.HTML;
import org.jboss.tools.vpe.editor.util.VpeStyleUtil;
+import org.jboss.tools.vpe.xulrunner.util.XulRunnerVpeUtils;
+import org.mozilla.interfaces.nsIDOMCSSStyleDeclaration;
import org.mozilla.interfaces.nsIDOMElement;
import org.mozilla.interfaces.nsIDOMMouseEvent;
import org.mozilla.interfaces.nsIDOMNode;
@@ -26,7 +29,7 @@
* @author Yahor Radtsevich (yradtsevich)
*/
public class DraggablePattern {
- public static final int ICON_HEIGHT = 20;
+ private static final int ICON_HEIGHT = 20;
private static final String DRAG_ICON_ID = "dragIcon"; //$NON-NLS-1$
private static final String DRAG_ICON_FILE = "dragIcon.gif"; //$NON-NLS-1$
Modified:
branches/jbosstools-3.2.0.Beta1/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/dnd/DraggableTextSelection.java
===================================================================
---
branches/jbosstools-3.2.0.Beta1/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/dnd/DraggableTextSelection.java 2010-10-01
14:47:13 UTC (rev 25397)
+++
branches/jbosstools-3.2.0.Beta1/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/dnd/DraggableTextSelection.java 2010-10-01
15:12:31 UTC (rev 25398)
@@ -11,7 +11,9 @@
package org.jboss.tools.vpe.dnd;
import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
import org.jboss.tools.vpe.editor.util.VisualDomUtil;
+import org.jboss.tools.vpe.xulrunner.util.XulRunnerVpeUtils;
import org.mozilla.interfaces.nsIDOMDocument;
import org.mozilla.interfaces.nsIDOMElement;
import org.mozilla.interfaces.nsIDOMNode;
@@ -25,18 +27,16 @@
private final nsIDOMText selectionContainer;
private final int startOffset;
private final int endOffset;
- private Point position;
/**
* NOTE: selectionContainer must contain really selected text. It will
* not work if real selection range do not math offsets.
*/
- public DraggableTextSelection(nsIDOMText selectionContainer, Point position,
+ public DraggableTextSelection(nsIDOMText selectionContainer,
int startOffset, int endOffset) {
this.selectionContainer = selectionContainer;
this.startOffset = startOffset;
this.endOffset = endOffset;
- this.position = position;
}
@@ -62,6 +62,7 @@
* @see org.jboss.tools.vpe.dnd.IDraggableFragment#getPosition()
*/
public Point getPosition() {
- return position;
+ Rectangle bounds = XulRunnerVpeUtils.getTextSelectionBounds(selectionContainer);
+ return new Point(bounds.x, bounds.y);
}
}
Modified:
branches/jbosstools-3.2.0.Beta1/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/dnd/VpeDnD.java
===================================================================
---
branches/jbosstools-3.2.0.Beta1/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/dnd/VpeDnD.java 2010-10-01
14:47:13 UTC (rev 25397)
+++
branches/jbosstools-3.2.0.Beta1/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/dnd/VpeDnD.java 2010-10-01
15:12:31 UTC (rev 25398)
@@ -69,7 +69,6 @@
import org.mozilla.interfaces.nsITransferable;
import org.mozilla.xpcom.Mozilla;
import org.w3c.dom.Document;
-import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
/**
@@ -123,26 +122,9 @@
public void dragStart(nsIDOMEvent domEvent) {
nsIDOMElement selectedElement = getSelectedElement();
- Point pageCoords = getPageCoords(domEvent);
-
- /* for selected text the drag icon is shown
- * when a drag action begins. */
- if (vpeController.getXulRunnerEditor().isTextSelected()) {
- nsISelection selection = vpeController.getXulRunnerEditor().getSelection();
- nsIDOMRange range = selection.getRangeAt(0);
- nsIDOMText textContainer = queryInterface(
- range.getStartContainer(), nsIDOMText.class);
-
- draggablePattern.showDragIcon(new DraggableTextSelection(
- textContainer,
- new Point(pageCoords.x - DraggablePattern.ICON_HEIGHT / 2,
- pageCoords.y + DraggablePattern.ICON_HEIGHT / 2),
- range.getStartOffset(), range.getEndOffset()));
- }
-
// start drag sessionvpe-element
- if (vpeController.getXulRunnerEditor().isTextSelected()
- || isDraggable(selectedElement)) {
+ if (isTextSelected(getVisualSelection()) || isDraggable(selectedElement)) {
+ Point pageCoords = getPageCoords(domEvent);
draggablePattern.startSession(pageCoords.x, pageCoords.y);
startDragSession(selectedElement);
domEvent.stopPropagation();
@@ -153,8 +135,8 @@
private nsIDOMElement getSelectedElement() {
return vpeController.getXulRunnerEditor().getLastSelectedElement();
}
-
- /**Draggable Text
+
+ /**
* Called when drag over event occurs
* @param event
*/
@@ -166,10 +148,8 @@
final DropResolver dropResolver;
if (isInnerDragSession()) {
- if (vpeController.getXulRunnerEditor().isTextSelected()) {
- dropResolver = getDropResolverForNode(getSourceNode(
- vpeController.getXulRunnerEditor()
- .getSelection().getFocusNode()));
+ if (isTextSelected(getVisualSelection())) {
+ dropResolver =
getDropResolverForNode(getSourceNode(getVisualSelection().getFocusNode()));
} else {
dropResolver = getDropResolverForInternalDrop();
}
@@ -237,16 +217,54 @@
}
private void refreshDraggablePattern() {
- nsIDOMElement selectedElement = getSelectedElement();
+ nsISelection selection = getVisualSelection();
+ if (isTextSelected(selection)) {
+ nsIDOMRange range = selection.getRangeAt(0);
+ nsIDOMText textContainer = queryInterface(
+ range.getStartContainer(), nsIDOMText.class);
+
+ draggablePattern.showDragIcon(new DraggableTextSelection(
+ textContainer, range.getStartOffset(), range.getEndOffset()));
+ } else {
+ nsIDOMElement selectedElement = getSelectedElement();
- if (!vpeController.getXulRunnerEditor().isTextSelected() &&
- isDraggable(selectedElement)) {
- draggablePattern.showDragIcon(new DraggableElement(selectedElement));
- } else {
- draggablePattern.hideDragIcon();
+ if (isDraggable(selectedElement)) {
+ draggablePattern.showDragIcon(new DraggableElement(selectedElement));
+ } else {
+ draggablePattern.hideDragIcon();
+ }
}
}
+ private nsISelection getVisualSelection() {
+ return vpeController.getXulRunnerEditor().getWebBrowser()
+ .getContentDOMWindow().getSelection();
+ }
+
+ private boolean isTextSelected(nsISelection selection) {
+ if (selection.getRangeCount() == 0) {
+ // nothing selected
+ return false;
+ }
+
+ nsIDOMRange range = selection.getRangeAt(0);
+ nsIDOMNode container = range.getStartContainer();
+ if (!container.equals(range.getEndContainer())) {
+ // more than one node selected
+ return false;
+ }
+ if (container.getNodeType() != nsIDOMNode.TEXT_NODE) {
+ // not text node is selected
+ return false;
+ }
+ if (range.getStartOffset() == range.getEndOffset()) {
+ // no text selected
+ return false;
+ }
+
+ return true;
+ }
+
public boolean isDragIconClicked(nsIDOMMouseEvent mouseEvent) {
return draggablePattern.isDragIconClicked(mouseEvent);
}
@@ -445,19 +463,7 @@
nsISupportsArray transArray = (nsISupportsArray) getComponentManager()
.createInstanceByContractID(XPCOM.NS_SUPPORTSARRAY_CONTRACTID, null,
nsISupportsArray.NS_ISUPPORTSARRAY_IID);
-
- Node node = getSourceNode(element);
- String text;
- if (node instanceof Element && node instanceof NodeContainer) {
- text = ((NodeContainer)node).getSource();
- } else {
- StyledText textWidget = vpeController.getSourceEditor()
- .getTextViewer().getTextWidget();
- text = textWidget.getSelectionText();
- }
- String xPath = XSLTXPathHelper.calculateXPathToNode(node);
- transArray.appendElement(createTransferable(text, xPath));
-
+ transArray.appendElement(createTransferable(getSourceNode(element)));
getDragService().invokeDragSession(element, transArray, null,
nsIDragService.DRAGDROP_ACTION_MOVE
| nsIDragService.DRAGDROP_ACTION_COPY
@@ -469,17 +475,20 @@
*
* @return transferable object
*/
- private nsITransferable createTransferable(String text, String xPath) {
+ private nsITransferable createTransferable(Node node) {
nsITransferable iTransferable = (nsITransferable) getComponentManager()
.createInstanceByContractID(XPCOM.NS_TRANSFERABLE_CONTRACTID, null,
nsITransferable.NS_ITRANSFERABLE_IID);
-
- nsISupportsString nodeSourceData = createNsISupportsString(text);
- int nodeSourceDataLength = text.length() * 2;
+
+ String nodeSource = ((NodeContainer)node).getSource();
+ nsISupportsString nodeSourceData = createNsISupportsString(nodeSource);
+ int nodeSourceDataLength = nodeSource.length() * 2;
iTransferable.setTransferData(ModelTransfer.MODEL, nodeSourceData,
nodeSourceDataLength);
iTransferable.setTransferData("text/html", nodeSourceData,
nodeSourceDataLength); //$NON-NLS-1$
iTransferable.setTransferData("text/unicode", nodeSourceData,
nodeSourceDataLength); //$NON-NLS-1$
+
+ String xPath = XSLTXPathHelper.calculateXPathToNode(node);
nsISupportsString xPathData = createNsISupportsString(xPath);
iTransferable.setTransferData(DndUtil.VPE_XPATH_FLAVOR, xPathData, xPath.length() *
2);
@@ -565,7 +574,7 @@
System.out.print("<<<<<< innerDrop"); //$NON-NLS-1$
}
- if (vpeController.getXulRunnerEditor().isTextSelected()) {
+ if (isTextSelected(getVisualSelection())) {
// it is inner Drag&Drop of text
StyledText textWidget = vpeController.getSourceEditor()
.getTextViewer().getTextWidget();
Modified:
branches/jbosstools-3.2.0.Beta1/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java
===================================================================
---
branches/jbosstools-3.2.0.Beta1/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java 2010-10-01
14:47:13 UTC (rev 25397)
+++
branches/jbosstools-3.2.0.Beta1/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java 2010-10-01
15:12:31 UTC (rev 25398)
@@ -128,7 +128,6 @@
import org.jboss.tools.vpe.resref.core.RelativeFolderReferenceList;
import org.jboss.tools.vpe.resref.core.TaglibReferenceList;
import org.jboss.tools.vpe.xulrunner.editor.XulRunnerEditor;
-import static org.jboss.tools.vpe.xulrunner.util.XPCOM.queryInterface;
import org.mozilla.interfaces.nsIDOMDocument;
import org.mozilla.interfaces.nsIDOMElement;
import org.mozilla.interfaces.nsIDOMEvent;
@@ -136,7 +135,6 @@
import org.mozilla.interfaces.nsIDOMMouseEvent;
import org.mozilla.interfaces.nsIDOMMutationEvent;
import org.mozilla.interfaces.nsIDOMNode;
-import org.mozilla.interfaces.nsIDOMRange;
import org.mozilla.interfaces.nsISelection;
import org.mozilla.interfaces.nsISelectionListener;
import org.w3c.dom.Attr;
@@ -1204,6 +1202,8 @@
// mareshkau
if (vpeDnD.isDragIconClicked(mouseEvent)) {
vpeDnD.dragStart(mouseEvent);
+ } else {
+ selectionManager.setSelection(mouseEvent);
}
}
} finally {
@@ -1231,13 +1231,6 @@
return;
}
try {
- // if text is selected, then there is no need to select any element
- if (!xulRunnerEditor.isTextSelected() ||
- !xulRunnerEditor.getSelection().containsNode(
- queryInterface(mouseEvent.getTarget(), nsIDOMNode.class), true)) {
- selectionManager.setSelection(mouseEvent);
- };
-
nsIDOMNode visualNode = VisualDomUtil.getTargetNode(mouseEvent);
if (visualNode != null) {
if (VpeDebug.PRINT_VISUAL_MOUSE_EVENT) {
Modified:
branches/jbosstools-3.2.0.Beta1/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaEventAdapter.java
===================================================================
---
branches/jbosstools-3.2.0.Beta1/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaEventAdapter.java 2010-10-01
14:47:13 UTC (rev 25397)
+++
branches/jbosstools-3.2.0.Beta1/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaEventAdapter.java 2010-10-01
15:12:31 UTC (rev 25398)
@@ -282,10 +282,11 @@
listener.onShowContextMenu(0, domEvent, node);
}
} else if(DRAGSTART.equals(eventType)) {
- for (MozillaDndListener listener : listeners.getListeners(
- MozillaDndListener.class)) {
- listener.dragStart(domEvent);
- }
+ // fix of JBIDE-4998: since drag events now are implemented by
+ // handling CLICKEVENTTYPE, there is no need to handle them here
+ //for (DndDomEventListener listener : dndListeners) {
+ // listener.dragGesture(domEvent);
+ //}
} else if(DRAGDROPEVENT.equals(eventType)) {
// calls when drop event occure
for (MozillaDndListener listener : listeners.getListeners(
Modified:
branches/jbosstools-3.2.0.Beta1/vpe/plugins/org.jboss.tools.vpe.xulrunner/src/org/jboss/tools/vpe/xulrunner/editor/XulRunnerEditor.java
===================================================================
---
branches/jbosstools-3.2.0.Beta1/vpe/plugins/org.jboss.tools.vpe.xulrunner/src/org/jboss/tools/vpe/xulrunner/editor/XulRunnerEditor.java 2010-10-01
14:47:13 UTC (rev 25397)
+++
branches/jbosstools-3.2.0.Beta1/vpe/plugins/org.jboss.tools.vpe.xulrunner/src/org/jboss/tools/vpe/xulrunner/editor/XulRunnerEditor.java 2010-10-01
15:12:31 UTC (rev 25398)
@@ -350,37 +350,8 @@
nsISelection selection = domWindow.getSelection();
return selection;
}
-
+
/**
- * Returns {@code true} if and only if the text selection exists and
- * it is containing in single #text node.
- */
- public boolean isTextSelected() {
- nsISelection selection = getSelection();
- if (selection.getRangeCount() == 0) {
- // nothing selected
- return false;
- }
-
- nsIDOMRange range = selection.getRangeAt(0);
- nsIDOMNode container = range.getStartContainer();
- if (!container.equals(range.getEndContainer())) {
- // more than one node selected
- return false;
- }
- if (container.getNodeType() != nsIDOMNode.TEXT_NODE) {
- // not text node is selected
- return false;
- }
- if (range.getStartOffset() == range.getEndOffset()) {
- // no text selected
- return false;
- }
-
- return true;
- }
-
- /**
* Function created to restore functionality of MozillaBrowser
*
* @return