Author: yradtsevich
Date: 2010-09-16 13:46:21 -0400 (Thu, 16 Sep 2010)
New Revision: 24968
Added:
trunk/vpe/plugins/org.jboss.tools.vpe.xulrunner/src/org/jboss/tools/vpe/xulrunner/editor/XulRunnerHint.java
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe.xulrunner/src/org/jboss/tools/vpe/xulrunner/editor/XulRunnerConstants.java
trunk/vpe/plugins/org.jboss.tools.vpe.xulrunner/src/org/jboss/tools/vpe/xulrunner/editor/XulRunnerVpeResizer.java
trunk/vpe/plugins/org.jboss.tools.vpe.xulrunner/src/org/jboss/tools/vpe/xulrunner/util/XulRunnerVpeUtils.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/messages/VpeUIMessages.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/messages.properties
Log:
JBIDE-5970
https://jira.jboss.org/browse/JBIDE-5970:
Add text captions for Drag&Drop actions
- DnD hints are added
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-09-16
16:36:37 UTC (rev 24967)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/dnd/VpeDnD.java 2010-09-16
17:46:21 UTC (rev 24968)
@@ -13,6 +13,7 @@
import static org.jboss.tools.vpe.xulrunner.util.XPCOM.queryInterface;
+import java.text.MessageFormat;
import java.util.EnumSet;
import org.eclipse.core.resources.IFile;
@@ -43,8 +44,10 @@
import org.jboss.tools.vpe.editor.mozilla.listener.MozillaSelectionListener;
import org.jboss.tools.vpe.editor.util.VisualDomUtil;
import org.jboss.tools.vpe.editor.util.VpeDndUtil;
+import org.jboss.tools.vpe.messages.VpeUIMessages;
import org.jboss.tools.vpe.xulrunner.editor.IVpeSelectionListener;
import org.jboss.tools.vpe.xulrunner.editor.XulRunnerEditor;
+import org.jboss.tools.vpe.xulrunner.editor.XulRunnerHint;
import org.jboss.tools.vpe.xulrunner.util.XPCOM;
import org.mozilla.interfaces.nsIComponentManager;
import org.mozilla.interfaces.nsIDOMDocument;
@@ -85,6 +88,10 @@
private VpeController vpeController;
private DraggablePattern draggablePattern;
private DropableArea dropableArea;
+ private XulRunnerHint dropHint;
+
+ /** Offset of dropHint related to mouse cursor*/
+ private static final Point DROP_HINT_OFFSET = new Point(20, -10);
/** The Constant FLAVORS. */
private static final String[] FLAVORS = {
@@ -169,9 +176,10 @@
innerDrop(queryInterface(domEvent, nsIDOMMouseEvent.class));
} else {
//in this case it's is external drag
- externalDrop(queryInterface(domEvent, nsIDOMMouseEvent.class)); //$NON-NLS-1$
+ externalDrop(queryInterface(domEvent, nsIDOMMouseEvent.class));
}
disposeDropableArea();
+ disposeDropHint();
vpeController.onRefresh();
}
@@ -193,12 +201,14 @@
// of drawing the dropable area
if (targetNodeIsTemporary || eventTargetIsAscedantOfDropTarget) {
disposeDropableArea();
+ disposeDropHint();
}
}
}
public void dragEnd(nsIDOMEvent domEvent) {
disposeDropableArea();
+ disposeDropHint();
draggablePattern.closeSession();
}
@@ -368,6 +378,8 @@
}
}
+ Point mouseCoords = getPageCoords(event);
+
if (highlightedNode != null) {
if (dropableArea == null) {
dropableArea = new DropableArea(document);
@@ -376,13 +388,51 @@
dropableArea.setDropTargets(dropTargets);
dropableArea.setNode(
vpeController.getDomMapping().getNearVisualNode(highlightedNode));
- Point mouseCoords = getPageCoords(event);
dropableArea.setHighlightedDropTarget(mouseCoords.x, mouseCoords.y);
dropableArea.setVisible(true);
dropableArea.redraw();
} else {
disposeDropableArea();
+ disposeDropHint();
}
+
+ if (highlightedNode != null && dropableArea.getHighlightedDropTarget() != null)
{
+ if (dropHint == null) {
+ dropHint = new XulRunnerHint(document);
+ }
+ String dropHintValue = null;
+ switch (dropableArea.getHighlightedDropTarget()) {
+ case BEFORE:
+ dropHintValue = MessageFormat.format(
+ VpeUIMessages.VpeDnD_PLACE_BEFORE_INSIDE,
+ highlightedNode.getNodeName(),
+ highlightedNode.getParentNode().getNodeName());
+ break;
+ case AFTER:
+ dropHintValue = MessageFormat.format(
+ VpeUIMessages.VpeDnD_PLACE_AFTER_INSIDE,
+ highlightedNode.getNodeName(),
+ highlightedNode.getParentNode().getNodeName());
+ break;
+ case BEGIN:
+ dropHintValue = MessageFormat.format(
+ VpeUIMessages.VpeDnD_PLACE_AT_THE_BEGINNING_OF,
+ highlightedNode.getNodeName());
+ break;
+ case END:
+ dropHintValue = MessageFormat.format(
+ VpeUIMessages.VpeDnD_PLACE_AT_THE_END_OF,
+ highlightedNode.getNodeName());
+ break;
+ }
+
+ dropHint.setHint(dropHintValue);
+ dropHint.setPosition(new Point(mouseCoords.x + DROP_HINT_OFFSET.x,
+ mouseCoords.y + DROP_HINT_OFFSET.y));
+ dropHint.redraw();
+ } else {
+ disposeDropHint();
+ }
}
private Point getClientCoords(nsIDOMEvent event) {
@@ -397,6 +447,13 @@
dropableArea = null;
}
}
+
+ private void disposeDropHint() {
+ if (dropHint != null) {
+ dropHint.dispose();
+ dropHint = null;
+ }
+ }
/**
* Starts drag session
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/VpeUIMessages.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/VpeUIMessages.java 2010-09-16
16:36:37 UTC (rev 24967)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/VpeUIMessages.java 2010-09-16
17:46:21 UTC (rev 24968)
@@ -69,6 +69,10 @@
public static String CONFIRM_SELECTION_BAR_DIALOG_TOGGLE_MESSAGE;
public static String VPE_UPDATE_JOB_TITLE;
public static String VPE_VISUAL_REFRESH_JOB;
+ public static String VpeDnD_PLACE_AFTER_INSIDE;
+ public static String VpeDnD_PLACE_AT_THE_BEGINNING_OF;
+ public static String VpeDnD_PLACE_AT_THE_END_OF;
+ public static String VpeDnD_PLACE_BEFORE_INSIDE;
public static String VpeExpressionBuilder_ClosingApostropheNotFound;
public static String VpeExpressionBuilder_ClosingBracketNotFound;
public static String VpeExpressionBuilder_FunctionNotFound;
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/messages.properties
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/messages.properties 2010-09-16
16:36:37 UTC (rev 24967)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/messages.properties 2010-09-16
17:46:21 UTC (rev 24968)
@@ -51,6 +51,13 @@
CONFIRM_SELECTION_BAR_DIALOG_TOGGLE_MESSAGE=Always hide selection bar without prompt
VPE_UPDATE_JOB_TITLE=Visual Editor View Update
VPE_VISUAL_REFRESH_JOB=Visual Editor Refresh
+
+# VpeDnD messages
+VpeDnD_PLACE_AFTER_INSIDE=Place after <code>{0}</code> inside
<code>{1}</code>
+VpeDnD_PLACE_AT_THE_BEGINNING_OF=Place at the beginning of <code>{0}</code>
+VpeDnD_PLACE_AT_THE_END_OF=Place at the end of <code>{0}</code>
+VpeDnD_PLACE_BEFORE_INSIDE=Place before <code>{0}</code> inside
<code>{1}</code>
+
VpeExpressionBuilder_ClosingApostropheNotFound=Closing apostrophe is not found
VpeExpressionBuilder_ClosingBracketNotFound=Closing bracket is not found
VpeExpressionBuilder_FunctionNotFound=Function ''{0}'' is not found
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe.xulrunner/src/org/jboss/tools/vpe/xulrunner/editor/XulRunnerConstants.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe.xulrunner/src/org/jboss/tools/vpe/xulrunner/editor/XulRunnerConstants.java 2010-09-16
16:36:37 UTC (rev 24967)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.xulrunner/src/org/jboss/tools/vpe/xulrunner/editor/XulRunnerConstants.java 2010-09-16
17:46:21 UTC (rev 24968)
@@ -23,8 +23,7 @@
/** HTML attributes */
-
- /** HTML_ATTR_CLASS */
+ public static final String HTML_ATTR_STYLE = "style"; //$NON-NLS-1$
public static final String HTML_ATTR_CLASS = "class"; //$NON-NLS-1$
/** HTML_ATTR_ANONLOCATION */
@@ -47,6 +46,8 @@
/** HTML_VALUE_HIDDEN */
public static final String HTML_VALUE_HIDDEN = "hidden"; //$NON-NLS-1$
+
+ public static final String HTML_VALUE_VISIBILITY_HIDDEN = "visibility:hidden";
//$NON-NLS-1$
/** HTML_VALUE_TRUE */
public static final String HTML_VALUE_TRUE = "true"; //$NON-NLS-1$
Added:
trunk/vpe/plugins/org.jboss.tools.vpe.xulrunner/src/org/jboss/tools/vpe/xulrunner/editor/XulRunnerHint.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe.xulrunner/src/org/jboss/tools/vpe/xulrunner/editor/XulRunnerHint.java
(rev 0)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.xulrunner/src/org/jboss/tools/vpe/xulrunner/editor/XulRunnerHint.java 2010-09-16
17:46:21 UTC (rev 24968)
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2010 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.vpe.xulrunner.editor;
+
+import static org.jboss.tools.vpe.xulrunner.util.XPCOM.queryInterface;
+
+import org.eclipse.swt.graphics.Point;
+import org.jboss.tools.vpe.xulrunner.util.XulRunnerVpeUtils;
+import org.mozilla.interfaces.nsIDOMDocument;
+import org.mozilla.interfaces.nsIDOMElement;
+import org.mozilla.interfaces.nsIDOMNSHTMLElement;
+
+/**
+ * Shows a hint in a XulRunner document.
+ *
+ * @author Yahor Radtsevich (yradtsevich)
+ */
+public class XulRunnerHint {
+ private Point position;
+ private nsIDOMDocument document;
+ private nsIDOMElement hintElement;
+ private String hint;
+
+ public XulRunnerHint(nsIDOMDocument document) {
+ this.document = document;
+ }
+
+ /**
+ * Hint to show. If {@code null} is passed, then hide.
+ */
+ public void setHint(String hint) {
+ this.hint = hint;
+ }
+
+ public void setPosition(Point position) {
+ this.position = position;
+ }
+
+ public void redraw() {
+
+ if (hintElement == null) {
+ nsIDOMElement parent = XulRunnerVpeUtils.getRootElement(document);
+ hintElement = XulRunnerVpeUtils.createAnonymousElement(document,
+ XulRunnerConstants.HTML_TAG_SPAN, parent,
+ XulRunnerConstants.VPE_CLASS_NAME_MOZ_RESIZING_INFO, false);
+ }
+
+ nsIDOMNSHTMLElement hintHtmlElement = queryInterface(hintElement,
+ nsIDOMNSHTMLElement.class);
+
+ if (hint == null) {
+ hintHtmlElement.setInnerHTML(""); //$NON-NLS-1$
+ hintElement.setAttribute(XulRunnerConstants.HTML_ATTR_STYLE,
+ XulRunnerConstants.HTML_VALUE_VISIBILITY_HIDDEN);
+ } else {
+ hintElement.setAttribute(XulRunnerConstants.HTML_ATTR_STYLE, "");
//$NON-NLS-1$
+ hintHtmlElement.setInnerHTML(hint);
+ XulRunnerVpeUtils.setElementPosition(hintElement, position.x, position.y);
+ }
+ }
+
+ public void dispose() {
+ if (hintElement != null && hintElement.getParentNode() != null) {
+ hintElement.getParentNode().removeChild(hintElement);
+ }
+ hintElement = null;
+ document = null;
+ }
+}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe.xulrunner/src/org/jboss/tools/vpe/xulrunner/editor/XulRunnerVpeResizer.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe.xulrunner/src/org/jboss/tools/vpe/xulrunner/editor/XulRunnerVpeResizer.java 2010-09-16
16:36:37 UTC (rev 24967)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.xulrunner/src/org/jboss/tools/vpe/xulrunner/editor/XulRunnerVpeResizer.java 2010-09-16
17:46:21 UTC (rev 24968)
@@ -18,15 +18,11 @@
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.jboss.tools.vpe.xulrunner.util.XulRunnerVpeUtils;
-import org.mozilla.interfaces.nsIDOMCSSStyleDeclaration;
import org.mozilla.interfaces.nsIDOMDocument;
import org.mozilla.interfaces.nsIDOMElement;
-import org.mozilla.interfaces.nsIDOMElementCSSInlineStyle;
import org.mozilla.interfaces.nsIDOMEvent;
import org.mozilla.interfaces.nsIDOMEventListener;
import org.mozilla.interfaces.nsIDOMEventTarget;
-import org.mozilla.interfaces.nsIDOMHTMLDocument;
-import org.mozilla.interfaces.nsIDOMHTMLElement;
import org.mozilla.interfaces.nsIDOMMouseEvent;
import org.mozilla.interfaces.nsIDOMNode;
@@ -95,7 +91,7 @@
/** resizingShadow */
private nsIDOMElement resizingShadow;
- private nsIDOMElement resizingInfo;
+ private XulRunnerHint resizingInfo;
/** domDocument */
private nsIDOMDocument domDocument;
@@ -161,7 +157,7 @@
(elementBounds.height <= 0) ||
(elementBounds.height > MAX_SIZE)) return;
- nsIDOMElement bodyElement = getRootElement();
+ nsIDOMElement bodyElement = XulRunnerVpeUtils.getRootElement(domDocument);
if (bodyElement == null ) return;
@@ -224,9 +220,9 @@
setAllResizersPosition();
resizingShadow = createShadow(bodyElement);
- setElementPosition(resizingShadow, elementBounds.x, elementBounds.y);
+ XulRunnerVpeUtils.setElementPosition(resizingShadow, elementBounds.x,
elementBounds.y);
- resizingInfo = createResizingInfo(bodyElement);
+ resizingInfo = new XulRunnerHint(domDocument);
}
@@ -234,9 +230,12 @@
* @see org.jboss.vpe.mozilla.resizer.IVpeResizer#hide()
*/
public void hide() {
- nsIDOMElement bodyElement;
-
- bodyElement = getRootElement();
+ if (resizingInfo != null) {
+ resizingInfo.dispose();
+ resizingInfo = null;
+ }
+
+ nsIDOMElement bodyElement = XulRunnerVpeUtils.getRootElement(domDocument);
if ( bodyElement == null ) {
return;
}
@@ -280,17 +279,11 @@
parentNode.removeChild(markerBottomRight);
}
-
if ( resizingShadow != null ) {
parentNode.removeChild(resizingShadow);
resizingShadow = null;
}
- if (resizingInfo != null) {
- parentNode.removeChild(resizingInfo);
- resizingInfo = null;
- }
-
markerBottom = null;
markerTop = null;
markerLeft = null;
@@ -302,7 +295,6 @@
resizingObject = null;
}
-
/* (non-Javadoc)
* @see org.jboss.vpe.mozilla.resizer.IVpeResizer#mouseDown(int, int,
org.mozilla.interfaces.nsIDOMElement)
@@ -347,19 +339,12 @@
Rectangle shadowBounds = new Rectangle(newX, newY, newWidth, newHeight);
- setElementBounds(resizingShadow, shadowBounds);
+ XulRunnerVpeUtils.setElementBounds(resizingShadow, shadowBounds);
redrawResizingInfo(shadowBounds);
}
}
private void redrawResizingInfo(Rectangle bounds) {
- while (resizingInfo.hasChildNodes()) {
- resizingInfo.removeChild(resizingInfo.getLastChild());
- }
-
- resizingInfo.appendChild(domDocument.createTextNode(
- String.format(RESIZING_INFO_FORMAT, bounds.width, bounds.height)));
-
Point position;
switch (usedResizeMarker) {
case RESIZER_MARKER_TOPLEFT:
@@ -400,7 +385,11 @@
position.x += RESIZING_INFO_OFFSET.x;
position.y += RESIZING_INFO_OFFSET.y;
- setElementPosition(resizingInfo, position.x, position.y);
+
+ resizingInfo.setHint(
+ String.format(RESIZING_INFO_FORMAT, bounds.width, bounds.height));
+ resizingInfo.setPosition(position);
+ resizingInfo.redraw();
}
@@ -449,49 +438,21 @@
}
/**
- * create a anonymous dom-element
*
- * @param aTag
- * a tag of dom element
- * @param aParentNode
- * @param aAnonClass
- * @param isCreatedHidden
- * @return
- */
- private nsIDOMElement createAnonymousElement(String aTag, nsIDOMNode aParentNode, String
aAnonClass, boolean isCreatedHidden) {
- nsIDOMElement returnElement = null;
-
- returnElement = domDocument.createElement(aTag);
-
- // add the "hidden" class if needed
- if (isCreatedHidden) {
- returnElement.setAttribute(XulRunnerConstants.HTML_ATTR_CLASS,
XulRunnerConstants.HTML_VALUE_HIDDEN);
- }
-
- // add an _moz_anonclass attribute if needed
- if ( aAnonClass.length() != 0 ) {
- returnElement.setAttribute(XulRunnerConstants.STRING_MOZ_ANONCLASS, aAnonClass);
- }
-
- aParentNode.appendChild(returnElement);
-
- return returnElement;
- }
-
- /**
- *
* @param parentNode
* @param originalObject
* @return
*/
private nsIDOMElement createShadow(nsIDOMNode parentNode) {
- return createAnonymousElement(XulRunnerConstants.HTML_TAG_SPAN,
+ return XulRunnerVpeUtils.createAnonymousElement(domDocument,
+ XulRunnerConstants.HTML_TAG_SPAN,
parentNode, XulRunnerConstants.VPE_CLASS_NAME_MOZ_RESIZING_SHADOW,
true);
}
private nsIDOMElement createResizingInfo(nsIDOMNode parentNode) {
- return createAnonymousElement(XulRunnerConstants.HTML_TAG_SPAN,
+ return XulRunnerVpeUtils.createAnonymousElement(domDocument,
+ XulRunnerConstants.HTML_TAG_SPAN,
parentNode, XulRunnerConstants.VPE_CLASS_NAME_MOZ_RESIZING_INFO,
true);
}
@@ -541,9 +502,8 @@
// make the shadow appear
resizingShadow.removeAttribute(XulRunnerConstants.HTML_ATTR_CLASS);
// position it
- setElementBounds(resizingShadow, elementBounds);
+ XulRunnerVpeUtils.setElementBounds(resizingShadow, elementBounds);
- resizingInfo.removeAttribute(XulRunnerConstants.HTML_ATTR_CLASS);
redrawResizingInfo(elementBounds);
@@ -650,37 +610,16 @@
return result;
}
-
/**
- * Get root element
- *
- * @return root element
- */
- private nsIDOMElement getRootElement() {
-
- nsIDOMElement bodyElement = null;
-
- nsIDOMHTMLDocument htmlDocument = queryInterface(domDocument,
nsIDOMHTMLDocument.class);
-
- if ( htmlDocument != null ) {
- nsIDOMHTMLElement htmlBody = htmlDocument.getBody();
-
- if ( htmlBody != null ) {
- bodyElement = queryInterface(htmlBody, nsIDOMElement.class);
- } // if
- } // if
-
- return bodyElement;
- }
-
- /**
* Create a new resizer element
* @param resizerMarkerString
* @param parentNode
* @return a new resizer element
*/
private nsIDOMElement createResizer(String resizerMarkerString, nsIDOMNode parentNode)
{
- nsIDOMElement aNewResizer = createAnonymousElement(XulRunnerConstants.HTML_TAG_SPAN,
parentNode, XulRunnerConstants.VPE_CLASSNAME_MOZ_RESIZER, false );
+ nsIDOMElement aNewResizer = XulRunnerVpeUtils.createAnonymousElement(
+ domDocument, XulRunnerConstants.HTML_TAG_SPAN, parentNode,
+ XulRunnerConstants.VPE_CLASSNAME_MOZ_RESIZER, false);
nsIDOMEventTarget evtTarget = queryInterface(aNewResizer, nsIDOMEventTarget.class);
@@ -708,67 +647,49 @@
int rh = (int)((resizerHeight+ 1) / 2);
if (markerTopLeft != null) {
- setElementPosition(markerTopLeft, left-resizerWidth-2, top-resizerHeight-2);
+ XulRunnerVpeUtils.setElementPosition(
+ markerTopLeft, left-resizerWidth-2, top-resizerHeight-2);
}
if (markerTop != null) {
- setElementPosition(markerTop, left+width/2-rw, top-resizerHeight-2);
+ XulRunnerVpeUtils.setElementPosition(
+ markerTop, left+width/2-rw, top-resizerHeight-2);
}
if (markerTopRight != null) {
- setElementPosition(markerTopRight, left+width, top-resizerHeight-2);
+ XulRunnerVpeUtils.setElementPosition(
+ markerTopRight, left+width, top-resizerHeight-2);
}
if (markerLeft != null) {
- setElementPosition(markerLeft, left-resizerWidth-2, top+height/2-rh);
+ XulRunnerVpeUtils.setElementPosition(
+ markerLeft, left-resizerWidth-2, top+height/2-rh);
}
if (markerRight != null) {
- setElementPosition(markerRight, left+width, top+height/2-rh);
+ XulRunnerVpeUtils.setElementPosition(
+ markerRight, left+width, top+height/2-rh);
}
if (markerBottomLeft != null) {
- setElementPosition(markerBottomLeft, left-resizerWidth-2, top+height);
+ XulRunnerVpeUtils.setElementPosition(
+ markerBottomLeft, left-resizerWidth-2, top+height);
}
if (markerBottom != null) {
- setElementPosition(markerBottom, left+width/2-rw, top+height);
+ XulRunnerVpeUtils.setElementPosition(
+ markerBottom, left+width/2-rw, top+height);
}
if (markerBottomRight != null) {
- setElementPosition(markerBottomRight, left+width, top+height);
+ XulRunnerVpeUtils.setElementPosition(
+ markerBottomRight, left+width, top+height);
}
}
-
- private void setElementPosition(nsIDOMElement domElement, int left,int top) {
- setStylePropertyPixels(domElement,XulRunnerConstants.HTML_ATTR_LEFT, left);
- setStylePropertyPixels(domElement,XulRunnerConstants.HTML_ATTR_TOP, top);
- }
- private void setElementSize(nsIDOMElement domElement, int width,int height) {
- setStylePropertyPixels(domElement, XulRunnerConstants.HTML_ATTR_WIDTH, width);
- setStylePropertyPixels(domElement, XulRunnerConstants.HTML_ATTR_HEIGHT, height);
- }
-
- private void setElementBounds(nsIDOMElement domElement, Rectangle bounds) {
- setElementPosition(domElement, bounds.x, bounds.y);
- setElementSize(domElement, bounds.width, bounds.height);
- }
-
-
/**
*
- * @param aElement
- * @param aProperty
- * @param aValue
- */
- private void setStylePropertyPixels(nsIDOMElement aElement, String aProperty, int
aValue) {
- setStyle(aElement, aProperty, aValue + "px"); //$NON-NLS-1$
- }
-
- /**
- *
* @param aX
* @param aY
* @param aW
@@ -783,38 +704,7 @@
// mPreserveRatio = aPreserveRatio;
}
-
/**
- * Set style for nsIDOMElement
- * @param domElement
- * @param cssPropertyName
- * @param cssPropertyValue
- */
- private void setStyle(nsIDOMElement domElement, String cssPropertyName, String
cssPropertyValue) {
- nsIDOMElementCSSInlineStyle inlineStyles = queryInterface(domElement,
nsIDOMElementCSSInlineStyle.class);
-
- if ( inlineStyles == null) {
- return;
- }
-
- nsIDOMCSSStyleDeclaration cssDecl = inlineStyles.getStyle();
-
- if ( cssDecl == null) {
- return;
- }
-
- if (cssPropertyValue.length() == 0 ) {
- // an empty value means we have to remove the property
- cssDecl.removeProperty(cssPropertyName);
- } else {
- // let's recreate the declaration as it was
- String priority = cssDecl.getPropertyPriority(cssPropertyName);
- cssDecl.setProperty(cssPropertyName, cssPropertyValue, priority);
- }
- }
-
-
- /**
*
* @param aClientX
* @param aClientY
@@ -827,7 +717,7 @@
if (resizingInfo == null) {
return;
}
- resizingInfo.setAttribute(XulRunnerConstants.HTML_ATTR_CLASS,
XulRunnerConstants.HTML_VALUE_HIDDEN);
+ resizingInfo.dispose();
if( activeHandle != null) {
activeHandle.removeAttribute(XulRunnerConstants.STRING_MOZ_ACTIVATED);
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe.xulrunner/src/org/jboss/tools/vpe/xulrunner/util/XulRunnerVpeUtils.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe.xulrunner/src/org/jboss/tools/vpe/xulrunner/util/XulRunnerVpeUtils.java 2010-09-16
16:36:37 UTC (rev 24967)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.xulrunner/src/org/jboss/tools/vpe/xulrunner/util/XulRunnerVpeUtils.java 2010-09-16
17:46:21 UTC (rev 24968)
@@ -15,23 +15,130 @@
import org.eclipse.swt.graphics.Rectangle;
import org.jboss.tools.vpe.xulrunner.BrowserPlugin;
-//import org.mozilla.interfaces.nsIAccessNode;
-//import org.mozilla.interfaces.nsIAccessible;
-//import org.mozilla.interfaces.nsIAccessibleCoordinateType;
-//import org.mozilla.interfaces.nsIAccessibleRetrieval;
-//import org.mozilla.interfaces.nsIAccessibleText;
+import org.jboss.tools.vpe.xulrunner.editor.XulRunnerConstants;
+import org.mozilla.interfaces.nsIDOMCSSStyleDeclaration;
+import org.mozilla.interfaces.nsIDOMDocument;
+import org.mozilla.interfaces.nsIDOMElement;
+import org.mozilla.interfaces.nsIDOMElementCSSInlineStyle;
+import org.mozilla.interfaces.nsIDOMHTMLDocument;
+import org.mozilla.interfaces.nsIDOMHTMLElement;
import org.mozilla.interfaces.nsIDOMNSElement;
import org.mozilla.interfaces.nsIDOMNSHTMLElement;
import org.mozilla.interfaces.nsIDOMNode;
import org.mozilla.interfaces.nsIDOMText;
-import org.mozilla.xpcom.Mozilla;
import org.mozilla.xpcom.XPCOMException;
/**
* @author dsakovich(a)exadel.com
*/
public class XulRunnerVpeUtils {
+ /**
+ * Get root element
+ *
+ * @return root element
+ */
+ public static nsIDOMElement getRootElement(nsIDOMDocument domDocument) {
+
+ nsIDOMElement bodyElement = null;
+
+ nsIDOMHTMLDocument htmlDocument = queryInterface(domDocument,
nsIDOMHTMLDocument.class);
+
+ if ( htmlDocument != null ) {
+ nsIDOMHTMLElement htmlBody = htmlDocument.getBody();
+
+ if ( htmlBody != null ) {
+ bodyElement = queryInterface(htmlBody, nsIDOMElement.class);
+ } // if
+ } // if
+
+ return bodyElement;
+ }
+
+ public static void setElementPosition(nsIDOMElement domElement, int left,int top) {
+ setStylePropertyPixels(domElement,XulRunnerConstants.HTML_ATTR_LEFT, left);
+ setStylePropertyPixels(domElement,XulRunnerConstants.HTML_ATTR_TOP, top);
+ }
+
+ public static void setElementSize(nsIDOMElement domElement, int width,int height) {
+ setStylePropertyPixels(domElement, XulRunnerConstants.HTML_ATTR_WIDTH, width);
+ setStylePropertyPixels(domElement, XulRunnerConstants.HTML_ATTR_HEIGHT, height);
+ }
+
+ public static void setElementBounds(nsIDOMElement domElement, Rectangle bounds) {
+ setElementPosition(domElement, bounds.x, bounds.y);
+ setElementSize(domElement, bounds.width, bounds.height);
+ }
+ /**
+ *
+ * @param aElement
+ * @param aProperty
+ * @param aValue
+ */
+ public static void setStylePropertyPixels(nsIDOMElement aElement, String aProperty, int
aValue) {
+ setStyle(aElement, aProperty, aValue + "px"); //$NON-NLS-1$
+ }
+
+ /**
+ * Set style for nsIDOMElement
+ * @param domElement
+ * @param cssPropertyName
+ * @param cssPropertyValue
+ */
+ public static void setStyle(nsIDOMElement domElement, String cssPropertyName, String
cssPropertyValue) {
+ nsIDOMElementCSSInlineStyle inlineStyles = queryInterface(domElement,
nsIDOMElementCSSInlineStyle.class);
+
+ if ( inlineStyles == null) {
+ return;
+ }
+
+ nsIDOMCSSStyleDeclaration cssDecl = inlineStyles.getStyle();
+
+ if ( cssDecl == null) {
+ return;
+ }
+
+ if (cssPropertyValue.length() == 0 ) {
+ // an empty value means we have to remove the property
+ cssDecl.removeProperty(cssPropertyName);
+ } else {
+ // let's recreate the declaration as it was
+ String priority = cssDecl.getPropertyPriority(cssPropertyName);
+ cssDecl.setProperty(cssPropertyName, cssPropertyValue, priority);
+ }
+ }
+
+ /**
+ * create a anonymous dom-element
+ *
+ * @param aTag
+ * a tag of dom element
+ * @param aParentNode
+ * @param aAnonClass
+ * @param isCreatedHidden
+ * @return
+ */
+ public static nsIDOMElement createAnonymousElement(nsIDOMDocument domDocument,
+ String aTag, nsIDOMNode aParentNode, String aAnonClass, boolean isCreatedHidden) {
+ nsIDOMElement element = null;
+
+ element = domDocument.createElement(aTag);
+
+ // add the "hidden" class if needed
+ if (isCreatedHidden) {
+ element.setAttribute(XulRunnerConstants.HTML_ATTR_CLASS,
XulRunnerConstants.HTML_VALUE_HIDDEN);
+ }
+
+ // add an _moz_anonclass attribute if needed
+ if ( aAnonClass.length() != 0 ) {
+ element.setAttribute(XulRunnerConstants.STRING_MOZ_ANONCLASS, aAnonClass);
+ }
+
+ aParentNode.appendChild(element);
+
+ return element;
+ }
+
private static int findPosX(nsIDOMNSHTMLElement boxObject) {
int curleft = 0;