Author: dsakovich
Date: 2007-11-01 15:50:18 -0400 (Thu, 01 Nov 2007)
New Revision: 4647
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe.xulrunner/src/org/jboss/tools/vpe/xulrunner/editor/XulRunnerVpeUtils.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/util/VpeDndUtil.java
Log:
http://jira.jboss.org/jira/browse/JBIDE-1143
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 2007-11-01
19:49:18 UTC (rev 4646)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java 2007-11-01
19:50:18 UTC (rev 4647)
@@ -65,16 +65,14 @@
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.VpeDebugUtil;
-import org.jboss.tools.vpe.editor.util.VpeDndUtil;
import org.jboss.tools.vpe.editor.util.VpeStyleUtil;
import org.jboss.tools.vpe.xulrunner.editor.XulRunnerEditor;
+import org.jboss.tools.vpe.xulrunner.editor.XulRunnerVpeUtils;
import org.mozilla.interfaces.nsIDOMAttr;
import org.mozilla.interfaces.nsIDOMDocument;
import org.mozilla.interfaces.nsIDOMElement;
import org.mozilla.interfaces.nsIDOMHTMLInputElement;
import org.mozilla.interfaces.nsIDOMMouseEvent;
-import org.mozilla.interfaces.nsIDOMNamedNodeMap;
import org.mozilla.interfaces.nsIDOMNode;
import org.mozilla.interfaces.nsIDOMNodeList;
import org.mozilla.interfaces.nsIDOMRange;
@@ -88,1956 +86,1965 @@
import org.w3c.dom.NodeList;
public class VpeVisualDomBuilder extends VpeDomBuilder {
- /** REGEX_EL */
- private static final Pattern REGEX_EL = Pattern.compile("[\\$|\\#]\\{.*\\}",
Pattern.MULTILINE + Pattern.DOTALL);
-
- private static final String PSEUDO_ELEMENT = "br";
- private static final String PSEUDO_ELEMENT_ATTR = "vpe:pseudo-element";
- private static final String INIT_ELEMENT_ATTR = "vpe:init-element";
- private static final String MOZ_ANONCLASS_ATTR = "_MOZ_ANONCLASS";
- private static final String COMMENT_STYLE = "font-style:italic; color:green";
- private static final String COMMENT_PREFIX = "";
- private static final String COMMENT_SUFFIX = "";
- private static final String INCLUDE_ELEMENT_ATTR = "vpe:include-element";
- private static final int DRAG_AREA_WIDTH = 10;
- private static final int DRAG_AREA_HEIGHT = 10;
- private static final String ATTR_XMLNS = "xmlns";
+ /** REGEX_EL */
+ private static final Pattern REGEX_EL = Pattern.compile(
+ "[\\$|\\#]\\{.*\\}", Pattern.MULTILINE + Pattern.DOTALL);
- private MozillaEditor visualEditor;
- private XulRunnerEditor xulRunnerEditor;
- private nsIDOMDocument visualDocument;
- private nsIDOMElement visualContentArea;
- private VpePageContext pageContext;
- private VpeDnD dnd;
- private nsIDOMNode headNode;
- private List includeStack;
- boolean rebuildFlag = false;
-
- /** faceletFile */
- private boolean faceletFile = false;
+ private static final String PSEUDO_ELEMENT = "br";
+ private static final String PSEUDO_ELEMENT_ATTR = "vpe:pseudo-element";
+ private static final String INIT_ELEMENT_ATTR = "vpe:init-element";
+ private static final String MOZ_ANONCLASS_ATTR = "_MOZ_ANONCLASS";
+ private static final String COMMENT_STYLE = "font-style:italic;
color:green";
+ private static final String COMMENT_PREFIX = "";
+ private static final String COMMENT_SUFFIX = "";
+ private static final String INCLUDE_ELEMENT_ATTR = "vpe:include-element";
+ private static final int DRAG_AREA_WIDTH = 10;
+ private static final int DRAG_AREA_HEIGHT = 10;
+ private static final String ATTR_XMLNS = "xmlns";
- private static final String ATTR_VPE = "vpe";
- private static final String ATTR_VPE_INLINE_LINK_VALUE = "inlinelink";
+ private MozillaEditor visualEditor;
+ private XulRunnerEditor xulRunnerEditor;
+ private nsIDOMDocument visualDocument;
+ private nsIDOMElement visualContentArea;
+ private VpePageContext pageContext;
+ private VpeDnD dnd;
+ private nsIDOMNode headNode;
+ private List includeStack;
+ boolean rebuildFlag = false;
- private static final String ATTR_REL_STYLESHEET_VALUE = "stylesheet";
+ /** faceletFile */
+ private boolean faceletFile = false;
- private static final String YES_STRING = "yes";
- private static final String NO_STRING = "no";
- private static final String ZERO_STRING = "0";
- private static final String EMPTY_STRING = "";
+ private static final String ATTR_VPE = "vpe";
+ private static final String ATTR_VPE_INLINE_LINK_VALUE = "inlinelink";
- private static final String ATRIBUTE_BORDER = "border";
- private static final String ATRIBUTE_CELLSPACING = "cellspacing";
- private static final String ATRIBUTE_CELLPADDING = "cellpadding";
+ private static final String ATTR_REL_STYLESHEET_VALUE = "stylesheet";
- private static final String DOTTED_BORDER_STYLE = "border : 1px dotted
#808080";
- private static final String DOTTED_BORDER_STYLE_FOR_IMG = "1px dotted
#808080";
- private static final String DOTTED_BORDER_STYLE_FOR_TD = "border-left : 1px dotted
#808080; border-right : 1px dotted #808080; border-top : 1px dotted #808080; border-bottom
: 0px; color:#0051DD; background-color:#ECF3FF; padding-left: 3px; padding-right: 3px;
line-height : 10px; font-family : arial; font-size : 10px; text-align:top; margin : 1px;
-moz-user-modify : read-only";
- private static final String DOTTED_BORDER_STYLE_FOR_SPAN = "border : 1px solid
#0051DD; color:#0051DD; background-color:#ECF3FF; padding-left: 3px; padding-right: 3px;
line-height : 10px; font-family : arial; font-size : 10px; text-align:top; margin : 1px;
-moz-user-modify : read-only";
+ private static final String YES_STRING = "yes";
+ private static final String NO_STRING = "no";
+ private static final String ZERO_STRING = "0";
+ private static final String EMPTY_STRING = "";
- static private HashSet<String> unborderedSourceNodes = new
HashSet<String>();
- static {
- unborderedSourceNodes.add(HTML.TAG_HTML);
- unborderedSourceNodes.add(HTML.TAG_HEAD);
- unborderedSourceNodes.add(HTML.TAG_BODY);
+ private static final String ATRIBUTE_BORDER = "border";
+ private static final String ATRIBUTE_CELLSPACING = "cellspacing";
+ private static final String ATRIBUTE_CELLPADDING = "cellpadding";
+
+ private static final String DOTTED_BORDER_STYLE = "border : 1px dotted
#808080";
+ private static final String DOTTED_BORDER_STYLE_FOR_IMG = "1px dotted
#808080";
+ private static final String DOTTED_BORDER_STYLE_FOR_TD = "border-left : 1px
dotted #808080; border-right : 1px dotted #808080; border-top : 1px dotted #808080;
border-bottom : 0px; color:#0051DD; background-color:#ECF3FF; padding-left: 3px;
padding-right: 3px; line-height : 10px; font-family : arial; font-size : 10px;
text-align:top; margin : 1px; -moz-user-modify : read-only";
+ private static final String DOTTED_BORDER_STYLE_FOR_SPAN = "border : 1px solid
#0051DD; color:#0051DD; background-color:#ECF3FF; padding-left: 3px; padding-right: 3px;
line-height : 10px; font-family : arial; font-size : 10px; text-align:top; margin : 1px;
-moz-user-modify : read-only";
+
+ static private HashSet<String> unborderedSourceNodes = new
HashSet<String>();
+ static {
+ unborderedSourceNodes.add(HTML.TAG_HTML);
+ unborderedSourceNodes.add(HTML.TAG_HEAD);
+ unborderedSourceNodes.add(HTML.TAG_BODY);
+ }
+
+ static private HashSet<String> unborderedVisualNodes = new
HashSet<String>();
+ static {
+ unborderedVisualNodes.add(HTML.TAG_TBODY);
+ unborderedVisualNodes.add(HTML.TAG_THEAD);
+ unborderedVisualNodes.add(HTML.TAG_TR);
+ unborderedVisualNodes.add(HTML.TAG_TD);
+ unborderedVisualNodes.add(HTML.TAG_COL);
+ unborderedVisualNodes.add(HTML.TAG_COLS);
+ unborderedVisualNodes.add(HTML.TAG_COLGROUP);
+ unborderedVisualNodes.add(HTML.TAG_LI);
+ unborderedVisualNodes.add(HTML.TAG_BR);
+ }
+ private VpeDnd dropper;
+
+ public VpeVisualDomBuilder(VpeDomMapping domMapping,
+ INodeAdapter sorceAdapter, VpeTemplateManager templateManager,
+ MozillaEditor visualEditor, VpePageContext pageContext) {
+ super(domMapping, sorceAdapter, templateManager);
+ this.visualEditor = visualEditor;
+ xulRunnerEditor = visualEditor.getXulRunnerEditor();
+ this.visualDocument = visualEditor.getDomDocument();
+ this.visualContentArea = visualEditor.getContentArea();
+ this.dnd = new VpeDnD();
+ this.pageContext = pageContext;
+ this.headNode = visualEditor.getHeadNode();
+ dropper = new VpeDnd();
+ dropper.setDndData(false, true);
+
+ if (isFacelet()) {
+ faceletFile = true;
+ } else {
+ faceletFile = false;
}
- static private HashSet<String> unborderedVisualNodes = new
HashSet<String>();
- static {
- unborderedVisualNodes.add(HTML.TAG_TBODY);
- unborderedVisualNodes.add(HTML.TAG_THEAD);
- unborderedVisualNodes.add(HTML.TAG_TR);
- unborderedVisualNodes.add(HTML.TAG_TD);
- unborderedVisualNodes.add(HTML.TAG_COL);
- unborderedVisualNodes.add(HTML.TAG_COLS);
- unborderedVisualNodes.add(HTML.TAG_COLGROUP);
- unborderedVisualNodes.add(HTML.TAG_LI);
- unborderedVisualNodes.add(HTML.TAG_BR);
+ }
+
+ public void buildDom(Document sourceDocument) {
+ includeStack = new ArrayList();
+ IEditorInput input = pageContext.getEditPart().getEditorInput();
+ if (input instanceof IFileEditorInput) {
+ IFile file = ((IFileEditorInput) input).getFile();
+ if (file != null) {
+ includeStack.add(new VpeIncludeInfo(null, file, pageContext
+ .getSourceBuilder().getSourceDocument()));
+ }
}
- private VpeDnd dropper;
+ pageContext.refreshConnector();
+ pageContext.installIncludeElements();
+ addChildren(null, sourceDocument, visualContentArea);
+ registerNodes(new VpeNodeMapping(sourceDocument, visualContentArea));
+ }
- public VpeVisualDomBuilder(VpeDomMapping domMapping,
- INodeAdapter sorceAdapter, VpeTemplateManager templateManager,
- MozillaEditor visualEditor, VpePageContext pageContext) {
- super(domMapping, sorceAdapter, templateManager);
- this.visualEditor = visualEditor;
- xulRunnerEditor = visualEditor.getXulRunnerEditor();
- this.visualDocument = visualEditor.getDomDocument();
- this.visualContentArea = visualEditor.getContentArea();
- this.dnd = new VpeDnD();
- this.pageContext = pageContext;
- this.headNode = visualEditor.getHeadNode();
- dropper = new VpeDnd();
- dropper.setDndData(false, true);
-
- if ( isFacelet() ) {
- faceletFile = true;
- } else {
- faceletFile = false;
- }
+ public void rebuildDom(Document sourceDocument) {
+ cleanHead();
+ domMapping.clear(visualContentArea);
+ pageContext.clearAll();
+ refreshExternalLinks();
+ pageContext.getBundle().refreshRegisteredBundles();
+ nsIDOMNodeList children = visualContentArea.getChildNodes();
+ long len = children.getLength();
+ for (long i = len - 1; i >= 0; i--) {
+ visualContentArea.removeChild(children.item(i));
}
- public void buildDom(Document sourceDocument) {
- includeStack = new ArrayList();
- IEditorInput input = pageContext.getEditPart().getEditorInput();
- if (input instanceof IFileEditorInput) {
- IFile file = ((IFileEditorInput) input).getFile();
- if (file != null) {
- includeStack.add(new VpeIncludeInfo(null, file, pageContext
- .getSourceBuilder().getSourceDocument()));
- }
- }
- pageContext.refreshConnector();
- pageContext.installIncludeElements();
- addChildren(null, sourceDocument, visualContentArea);
- registerNodes(new VpeNodeMapping(sourceDocument, visualContentArea));
+ if (sourceDocument != null) {
+ buildDom(sourceDocument);
}
- public void rebuildDom(Document sourceDocument) {
- cleanHead();
- domMapping.clear(visualContentArea);
- pageContext.clearAll();
- refreshExternalLinks();
- pageContext.getBundle().refreshRegisteredBundles();
+ rebuildFlag = true;
+ }
- nsIDOMNodeList children = visualContentArea.getChildNodes();
- long len = children.getLength();
- for (long i = len - 1; i >= 0; i--) {
- visualContentArea.removeChild(children.item(i));
- }
+ // temporary, will be change to prefference's variable
+ // private boolean borderVisible = true;
- if (sourceDocument != null) {
- buildDom(sourceDocument);
- }
-
- rebuildFlag = true;
+ private boolean addNode(Node sourceNode, nsIDOMNode visualNextNode,
+ nsIDOMNode visualContainer) {
+ nsIDOMNode visualNewNode = createNode(sourceNode, visualContainer);
+ // Fix for JBIDE-1097
+ try {
+ if (visualNewNode != null) {
+ nsIDOMHTMLInputElement iDOMInputElement = (nsIDOMHTMLInputElement) visualNewNode
+ .queryInterface(nsIDOMHTMLInputElement.NS_IDOMHTMLINPUTELEMENT_IID);
+ iDOMInputElement.setReadOnly(true);
+ }
+ } catch (XPCOMException ex) {
+ // just ignore this exception
}
+ if (visualNewNode != null) {
+ if (visualNextNode == null) {
+ visualContainer.appendChild(visualNewNode);
+ } else {
+ visualContainer.insertBefore(visualNewNode, visualNextNode);
+ }
+ return true;
+ }
- // temporary, will be change to prefference's variable
- // private boolean borderVisible = true;
+ return false;
+ }
- private boolean addNode(Node sourceNode, nsIDOMNode visualNextNode,
- nsIDOMNode visualContainer) {
- nsIDOMNode visualNewNode = createNode(sourceNode, visualContainer);
- //Fix for JBIDE-1097
- try {
- if(visualNewNode!=null) {
- nsIDOMHTMLInputElement iDOMInputElement = (nsIDOMHTMLInputElement)
visualNewNode.queryInterface(nsIDOMHTMLInputElement.NS_IDOMHTMLINPUTELEMENT_IID);
- iDOMInputElement.setReadOnly(true);
- }
- } catch(XPCOMException ex) {
- //just ignore this exception
- }
- if (visualNewNode != null) {
- if (visualNextNode == null) {
- visualContainer.appendChild(visualNewNode);
- } else {
- visualContainer.insertBefore(visualNewNode, visualNextNode);
- }
- return true;
- }
-
- return false;
+ private nsIDOMElement createBorder(Node sourceNode,
+ nsIDOMElement visualNode, boolean block) {
+ nsIDOMElement border = null;
+ if (visualNode == null)
+ return null;
+ if (unborderedSourceNodes.contains(sourceNode.getNodeName()
+ .toLowerCase()))
+ return null;
+ if (unborderedVisualNodes.contains(visualNode.getNodeName()
+ .toLowerCase()))
+ return null;
+ if (HTML.TAG_IMG.equalsIgnoreCase(visualNode.getNodeName())) {
+ String width = visualNode.getAttribute(ATRIBUTE_BORDER);
+ if (width == null || ZERO_STRING.equalsIgnoreCase(width)
+ || EMPTY_STRING.equalsIgnoreCase(width)) {
+ String style = visualNode
+ .getAttribute(VpeStyleUtil.ATTRIBUTE_STYLE);
+ style = VpeStyleUtil.setParameterInStyle(style,
+ ATRIBUTE_BORDER, DOTTED_BORDER_STYLE_FOR_IMG);
+ visualNode.setAttribute(VpeStyleUtil.ATTRIBUTE_STYLE, style);
+ }
+ return null;
}
+ if (block) {
+ if (YES_STRING.equals(VpePreference.USE_DETAIL_BORDER.getValue())) {
+ border = visualDocument.createElement(HTML.TAG_TABLE);
+ border.setAttribute(ATRIBUTE_CELLSPACING, ZERO_STRING);
+ border.setAttribute(ATRIBUTE_CELLPADDING, ZERO_STRING);
- private nsIDOMElement createBorder(Node sourceNode,
- nsIDOMElement visualNode, boolean block) {
- nsIDOMElement border = null;
- if (visualNode == null)
- return null;
- if (unborderedSourceNodes.contains(sourceNode.getNodeName()
- .toLowerCase()))
- return null;
- if (unborderedVisualNodes.contains(visualNode.getNodeName()
- .toLowerCase()))
- return null;
- if (HTML.TAG_IMG.equalsIgnoreCase(visualNode.getNodeName())) {
- String width = visualNode.getAttribute(ATRIBUTE_BORDER);
- if (width == null || ZERO_STRING.equalsIgnoreCase(width)
- || EMPTY_STRING.equalsIgnoreCase(width)) {
- String style = visualNode
- .getAttribute(VpeStyleUtil.ATTRIBUTE_STYLE);
- style = VpeStyleUtil.setParameterInStyle(style,
- ATRIBUTE_BORDER, DOTTED_BORDER_STYLE_FOR_IMG);
- visualNode.setAttribute(VpeStyleUtil.ATTRIBUTE_STYLE, style);
- }
- return null;
- }
- if (block) {
- if (YES_STRING.equals(VpePreference.USE_DETAIL_BORDER.getValue())) {
- border = visualDocument.createElement(HTML.TAG_TABLE);
- border.setAttribute(ATRIBUTE_CELLSPACING, ZERO_STRING);
- border.setAttribute(ATRIBUTE_CELLPADDING, ZERO_STRING);
+ nsIDOMElement tr1 = visualDocument.createElement(HTML.TAG_TR);
+ border.appendChild(tr1);
+ nsIDOMElement td1 = visualDocument.createElement(HTML.TAG_TD);
+ td1.setAttribute(VpeStyleUtil.ATTRIBUTE_STYLE,
+ DOTTED_BORDER_STYLE_FOR_TD);
+ nsIDOMText text = visualDocument.createTextNode(sourceNode
+ .getNodeName());
+ td1.appendChild(text);
+ tr1.appendChild(td1);
+ nsIDOMElement tr2 = visualDocument.createElement(HTML.TAG_TR);
+ border.appendChild(tr2);
+ nsIDOMElement td2 = visualDocument.createElement(HTML.TAG_TD);
+ tr2.appendChild(td2);
+ nsIDOMElement p = visualDocument.createElement(HTML.TAG_P);
+ p.setAttribute(VpeStyleUtil.ATTRIBUTE_STYLE,
+ DOTTED_BORDER_STYLE);
+ td2.appendChild(p);
- nsIDOMElement tr1 = visualDocument.createElement(HTML.TAG_TR);
- border.appendChild(tr1);
- nsIDOMElement td1 = visualDocument.createElement(HTML.TAG_TD);
- td1.setAttribute(VpeStyleUtil.ATTRIBUTE_STYLE,
- DOTTED_BORDER_STYLE_FOR_TD);
- nsIDOMText text = visualDocument.createTextNode(sourceNode
- .getNodeName());
- td1.appendChild(text);
- tr1.appendChild(td1);
- nsIDOMElement tr2 = visualDocument.createElement(HTML.TAG_TR);
- border.appendChild(tr2);
- nsIDOMElement td2 = visualDocument.createElement(HTML.TAG_TD);
- tr2.appendChild(td2);
- nsIDOMElement p = visualDocument.createElement(HTML.TAG_P);
- p.setAttribute(VpeStyleUtil.ATTRIBUTE_STYLE,
- DOTTED_BORDER_STYLE);
- td2.appendChild(p);
+ p.appendChild(visualNode);
- p.appendChild(visualNode);
+ } else {
+ border = visualDocument.createElement(HTML.TAG_TABLE);
+ border.setAttribute(ATRIBUTE_CELLSPACING, ZERO_STRING);
+ border.setAttribute(ATRIBUTE_CELLPADDING, ZERO_STRING);
- } else {
- border = visualDocument.createElement(HTML.TAG_TABLE);
- border.setAttribute(ATRIBUTE_CELLSPACING, ZERO_STRING);
- border.setAttribute(ATRIBUTE_CELLPADDING, ZERO_STRING);
+ nsIDOMElement tr2 = visualDocument.createElement(HTML.TAG_TR);
+ border.appendChild(tr2);
+ nsIDOMElement td2 = visualDocument.createElement(HTML.TAG_TD);
+ tr2.appendChild(td2);
+ nsIDOMElement p = visualDocument.createElement(HTML.TAG_P);
+ p.setAttribute(VpeStyleUtil.ATTRIBUTE_STYLE,
+ DOTTED_BORDER_STYLE);
+ td2.appendChild(p);
- nsIDOMElement tr2 = visualDocument.createElement(HTML.TAG_TR);
- border.appendChild(tr2);
- nsIDOMElement td2 = visualDocument.createElement(HTML.TAG_TD);
- tr2.appendChild(td2);
- nsIDOMElement p = visualDocument.createElement(HTML.TAG_P);
- p.setAttribute(VpeStyleUtil.ATTRIBUTE_STYLE,
- DOTTED_BORDER_STYLE);
- td2.appendChild(p);
+ p.appendChild(visualNode);
+ }
+ } else {
+ border = visualDocument.createElement(HTML.TAG_SPAN);
+ border.setAttribute(VpeStyleUtil.ATTRIBUTE_STYLE,
+ DOTTED_BORDER_STYLE);
+ if (YES_STRING.equals(VpePreference.USE_DETAIL_BORDER.getValue())) {
+ nsIDOMElement name = visualDocument
+ .createElement(HTML.TAG_SPAN);
+ name.setAttribute(VpeStyleUtil.ATTRIBUTE_STYLE,
+ DOTTED_BORDER_STYLE_FOR_SPAN);
+ nsIDOMText text = visualDocument.createTextNode(sourceNode
+ .getNodeName());
+ name.appendChild(text);
+ border.appendChild(name);
+ }
+ border.appendChild(visualNode);
+ }
+ if (VpeStyleUtil.getAbsolute((Element) sourceNode) && border != null) {
+ int top = VpeStyleUtil.getSizeFromStyle((Element) sourceNode,
+ VpeStyleUtil.ATTRIBUTE_STYLE + VpeStyleUtil.DOT_STRING
+ + VpeStyleUtil.PARAMETER_TOP);
+ int left = VpeStyleUtil.getSizeFromStyle((Element) sourceNode,
+ VpeStyleUtil.ATTRIBUTE_STYLE + VpeStyleUtil.DOT_STRING
+ + VpeStyleUtil.PARAMETER_LEFT);
- p.appendChild(visualNode);
- }
- } else {
- border = visualDocument.createElement(HTML.TAG_SPAN);
- border.setAttribute(VpeStyleUtil.ATTRIBUTE_STYLE,
- DOTTED_BORDER_STYLE);
- if (YES_STRING.equals(VpePreference.USE_DETAIL_BORDER.getValue())) {
- nsIDOMElement name = visualDocument
- .createElement(HTML.TAG_SPAN);
- name.setAttribute(VpeStyleUtil.ATTRIBUTE_STYLE,
- DOTTED_BORDER_STYLE_FOR_SPAN);
- nsIDOMText text = visualDocument.createTextNode(sourceNode
- .getNodeName());
- name.appendChild(text);
- border.appendChild(name);
- }
- border.appendChild(visualNode);
- }
- if (VpeStyleUtil.getAbsolute((Element) sourceNode) && border != null) {
- int top = VpeStyleUtil.getSizeFromStyle((Element) sourceNode,
- VpeStyleUtil.ATTRIBUTE_STYLE + VpeStyleUtil.DOT_STRING
- + VpeStyleUtil.PARAMETER_TOP);
- int left = VpeStyleUtil.getSizeFromStyle((Element) sourceNode,
- VpeStyleUtil.ATTRIBUTE_STYLE + VpeStyleUtil.DOT_STRING
- + VpeStyleUtil.PARAMETER_LEFT);
+ String style = visualNode
+ .getAttribute(VpeStyleUtil.ATTRIBUTE_STYLE);
+ style = VpeStyleUtil.deleteFromString(style,
+ VpeStyleUtil.PARAMETER_POSITION,
+ VpeStyleUtil.SEMICOLON_STRING);
+ style = VpeStyleUtil.deleteFromString(style,
+ VpeStyleUtil.PARAMETER_TOP, VpeStyleUtil.SEMICOLON_STRING);
+ style = VpeStyleUtil.deleteFromString(style,
+ VpeStyleUtil.PARAMETER_LEFT, VpeStyleUtil.SEMICOLON_STRING);
+ visualNode.setAttribute(VpeStyleUtil.ATTRIBUTE_STYLE, style);
- String style = visualNode
- .getAttribute(VpeStyleUtil.ATTRIBUTE_STYLE);
- style = VpeStyleUtil.deleteFromString(style,
- VpeStyleUtil.PARAMETER_POSITION,
- VpeStyleUtil.SEMICOLON_STRING);
- style = VpeStyleUtil.deleteFromString(style,
- VpeStyleUtil.PARAMETER_TOP, VpeStyleUtil.SEMICOLON_STRING);
- style = VpeStyleUtil.deleteFromString(style,
- VpeStyleUtil.PARAMETER_LEFT, VpeStyleUtil.SEMICOLON_STRING);
- visualNode.setAttribute(VpeStyleUtil.ATTRIBUTE_STYLE, style);
-
- style = border.getAttribute(VpeStyleUtil.ATTRIBUTE_STYLE);
- style = VpeStyleUtil.setAbsolute(style);
- if (top != -1)
- style = VpeStyleUtil.setSizeInStyle(style,
- VpeStyleUtil.PARAMETER_TOP, top);
- if (left != -1)
- style = VpeStyleUtil.setSizeInStyle(style,
- VpeStyleUtil.PARAMETER_LEFT, left);
- border.setAttribute(VpeStyleUtil.ATTRIBUTE_STYLE, style);
- }
- return border;
+ style = border.getAttribute(VpeStyleUtil.ATTRIBUTE_STYLE);
+ style = VpeStyleUtil.setAbsolute(style);
+ if (top != -1)
+ style = VpeStyleUtil.setSizeInStyle(style,
+ VpeStyleUtil.PARAMETER_TOP, top);
+ if (left != -1)
+ style = VpeStyleUtil.setSizeInStyle(style,
+ VpeStyleUtil.PARAMETER_LEFT, left);
+ border.setAttribute(VpeStyleUtil.ATTRIBUTE_STYLE, style);
}
+ return border;
+ }
- protected nsIDOMNode createNode(Node sourceNode,
- nsIDOMNode visualOldContainer) {
- boolean registerFlag = isCurrentMainDocument();
- switch (sourceNode.getNodeType()) {
- case Node.ELEMENT_NODE:
- Map<?, ?> xmlnsMap = createXmlns((Element) sourceNode);
- Set<Node> ifDependencySet = new HashSet<Node>();
- pageContext.setCurrentVisualNode(visualOldContainer);
- VpeTemplate template = templateManager.getTemplate(pageContext,
- (Element) sourceNode, ifDependencySet);
+ protected nsIDOMNode createNode(Node sourceNode,
+ nsIDOMNode visualOldContainer) {
+ boolean registerFlag = isCurrentMainDocument();
+ switch (sourceNode.getNodeType()) {
+ case Node.ELEMENT_NODE:
+ Map<?, ?> xmlnsMap = createXmlns((Element) sourceNode);
+ Set<Node> ifDependencySet = new HashSet<Node>();
+ pageContext.setCurrentVisualNode(visualOldContainer);
+ VpeTemplate template = templateManager.getTemplate(pageContext,
+ (Element) sourceNode, ifDependencySet);
- VpeCreationData creationData = template.create(pageContext,
- sourceNode, visualDocument);
- pageContext.setCurrentVisualNode(null);
- nsIDOMElement visualNewElement = (nsIDOMElement) creationData
- .getNode();
+ VpeCreationData creationData = template.create(pageContext,
+ sourceNode, visualDocument);
+ pageContext.setCurrentVisualNode(null);
+ nsIDOMElement visualNewElement = (nsIDOMElement) creationData
+ .getNode();
- if (visualNewElement != null)
- correctVisualAttribute(visualNewElement);
+ if (visualNewElement != null)
+ correctVisualAttribute(visualNewElement);
- nsIDOMElement border = null;
- setTooltip((Element) sourceNode, visualNewElement);
- if (YES_STRING.equals(VpePreference.SHOW_BORDER_FOR_ALL_TAGS
- .getValue())
- && visualNewElement != null) {
- boolean block = true;
- if (template.getTagDescription(null, null, null,
- visualNewElement, null).getDisplayType() == VpeTagDescription.DISPLAY_TYPE_INLINE)
{
- block = false;
- }
- border = createBorder(sourceNode, visualNewElement, block);
- }
- if (!isCurrentMainDocument() && visualNewElement != null) {
- setReadOnlyElement(visualNewElement);
- }
- if (registerFlag) {
- VpeElementMapping elementMapping = new VpeElementMapping(
- (Element) sourceNode, visualNewElement, border,
- template, ifDependencySet, creationData.getData());
- elementMapping.setXmlnsMap(xmlnsMap);
- registerNodes(elementMapping);
- }
- if (template.isChildren()) {
- List<?> childrenInfoList = creationData.getChildrenInfoList();
- if (childrenInfoList == null) {
- addChildren(template, sourceNode,
- visualNewElement != null ? visualNewElement
- : visualOldContainer);
- } else {
- addChildren(template, sourceNode, visualOldContainer,
- childrenInfoList);
- }
- }
- pageContext.setCurrentVisualNode(visualOldContainer);
- template.validate(pageContext, (Element) sourceNode,
- visualDocument, creationData);
- pageContext.setCurrentVisualNode(null);
- if (border != null)
- return border;
- else
- return visualNewElement;
- case Node.TEXT_NODE:
- return createTextNode(sourceNode, registerFlag);
- case Node.COMMENT_NODE:
- if (!YES_STRING.equals(VpePreference.SHOW_COMMENTS.getValue())) {
- return null;
- }
- nsIDOMElement visualNewComment = createComment(sourceNode);
- if (registerFlag) {
- registerNodes(new VpeNodeMapping(sourceNode, visualNewComment));
- }
- return visualNewComment;
+ nsIDOMElement border = null;
+ setTooltip((Element) sourceNode, visualNewElement);
+ if (YES_STRING.equals(VpePreference.SHOW_BORDER_FOR_ALL_TAGS
+ .getValue())
+ && visualNewElement != null) {
+ boolean block = true;
+ if (template.getTagDescription(null, null, null,
+ visualNewElement, null).getDisplayType() == VpeTagDescription.DISPLAY_TYPE_INLINE) {
+ block = false;
}
+ border = createBorder(sourceNode, visualNewElement, block);
+ }
+ if (!isCurrentMainDocument() && visualNewElement != null) {
+ setReadOnlyElement(visualNewElement);
+ }
+ if (registerFlag) {
+ VpeElementMapping elementMapping = new VpeElementMapping(
+ (Element) sourceNode, visualNewElement, border,
+ template, ifDependencySet, creationData.getData());
+ elementMapping.setXmlnsMap(xmlnsMap);
+ registerNodes(elementMapping);
+ }
+ if (template.isChildren()) {
+ List<?> childrenInfoList = creationData.getChildrenInfoList();
+ if (childrenInfoList == null) {
+ addChildren(template, sourceNode,
+ visualNewElement != null ? visualNewElement
+ : visualOldContainer);
+ } else {
+ addChildren(template, sourceNode, visualOldContainer,
+ childrenInfoList);
+ }
+ }
+ pageContext.setCurrentVisualNode(visualOldContainer);
+ template.validate(pageContext, (Element) sourceNode,
+ visualDocument, creationData);
+ pageContext.setCurrentVisualNode(null);
+ if (border != null)
+ return border;
+ else
+ return visualNewElement;
+ case Node.TEXT_NODE:
+ return createTextNode(sourceNode, registerFlag);
+ case Node.COMMENT_NODE:
+ if (!YES_STRING.equals(VpePreference.SHOW_COMMENTS.getValue())) {
return null;
+ }
+ nsIDOMElement visualNewComment = createComment(sourceNode);
+ if (registerFlag) {
+ registerNodes(new VpeNodeMapping(sourceNode, visualNewComment));
+ }
+ return visualNewComment;
}
+ return null;
+ }
- private void correctVisualAttribute(nsIDOMElement element) {
+ private void correctVisualAttribute(nsIDOMElement element) {
- String styleValue = element.getAttribute(HTML.TAG_STYLE);
- String backgroundValue = element
- .getAttribute(VpeStyleUtil.PARAMETR_BACKGROND);
+ String styleValue = element.getAttribute(HTML.TAG_STYLE);
+ String backgroundValue = element
+ .getAttribute(VpeStyleUtil.PARAMETR_BACKGROND);
- if (styleValue != null) {
- styleValue = VpeStyleUtil.addFullPathIntoURLValue(styleValue,
- pageContext.getEditPart().getEditorInput());
- element.setAttribute(HTML.TAG_STYLE, styleValue);
- }
- if (backgroundValue != null) {
- backgroundValue = VpeStyleUtil
- .addFullPathIntoBackgroundValue(backgroundValue,
- pageContext.getEditPart().getEditorInput());
- element.setAttribute(VpeStyleUtil.PARAMETR_BACKGROND,
- backgroundValue);
- }
+ if (styleValue != null) {
+ styleValue = VpeStyleUtil.addFullPathIntoURLValue(styleValue,
+ pageContext.getEditPart().getEditorInput());
+ element.setAttribute(HTML.TAG_STYLE, styleValue);
}
+ if (backgroundValue != null) {
+ backgroundValue = VpeStyleUtil
+ .addFullPathIntoBackgroundValue(backgroundValue,
+ pageContext.getEditPart().getEditorInput());
+ element.setAttribute(VpeStyleUtil.PARAMETR_BACKGROND,
+ backgroundValue);
+ }
+ }
- protected nsIDOMElement createComment(Node sourceNode) {
- nsIDOMElement div = visualDocument.createElement(HTML.TAG_DIV);
- div.setAttribute(VpeStyleUtil.ATTRIBUTE_STYLE, COMMENT_STYLE);
- String value = COMMENT_PREFIX + sourceNode.getNodeValue()
- + COMMENT_SUFFIX;
- nsIDOMText text = visualDocument.createTextNode(value);
- div.appendChild(text);
- return div;
+ protected nsIDOMElement createComment(Node sourceNode) {
+ nsIDOMElement div = visualDocument.createElement(HTML.TAG_DIV);
+ div.setAttribute(VpeStyleUtil.ATTRIBUTE_STYLE, COMMENT_STYLE);
+ String value = COMMENT_PREFIX + sourceNode.getNodeValue()
+ + COMMENT_SUFFIX;
+ nsIDOMText text = visualDocument.createTextNode(value);
+ div.appendChild(text);
+ return div;
+ }
+
+ protected void addChildren(VpeTemplate containerTemplate,
+ Node sourceContainer, nsIDOMNode visualContainer) {
+ NodeList sourceNodes = sourceContainer.getChildNodes();
+ int len = sourceNodes.getLength();
+ int childrenCount = 0;
+ for (int i = 0; i < len; i++) {
+ Node sourceNode = sourceNodes.item(i);
+ if (addNode(sourceNode, null, visualContainer)) {
+ childrenCount++;
+ }
}
+ if (childrenCount == 0) {
+ setPseudoContent(containerTemplate, sourceContainer,
+ visualContainer);
+ }
+ }
- protected void addChildren(VpeTemplate containerTemplate,
- Node sourceContainer, nsIDOMNode visualContainer) {
- NodeList sourceNodes = sourceContainer.getChildNodes();
- int len = sourceNodes.getLength();
- int childrenCount = 0;
- for (int i = 0; i < len; i++) {
- Node sourceNode = sourceNodes.item(i);
- if (addNode(sourceNode, null, visualContainer)) {
- childrenCount++;
- }
+ protected void addChildren(VpeTemplate containerTemplate,
+ Node sourceContainer, nsIDOMNode visualOldContainer,
+ List<?> childrenInfoList) {
+ for (int i = 0; i < childrenInfoList.size(); i++) {
+ VpeChildrenInfo info = (VpeChildrenInfo) childrenInfoList.get(i);
+ nsIDOMNode visualParent = info.getVisualParent();
+ if (visualParent == null)
+ visualParent = visualOldContainer;
+ List<?> sourceChildren = info.getSourceChildren();
+ int childrenCount = 0;
+ if (sourceChildren != null) {
+ for (int j = 0; j < sourceChildren.size(); j++) {
+ if (addNode((Node) sourceChildren.get(j), null,
+ visualParent)) {
+ childrenCount++;
+ }
}
- if (childrenCount == 0) {
- setPseudoContent(containerTemplate, sourceContainer,
- visualContainer);
- }
+ }
+ if (childrenCount == 0) {
+ setPseudoContent(containerTemplate, sourceContainer,
+ visualParent);
+ }
}
+ }
- protected void addChildren(VpeTemplate containerTemplate,
- Node sourceContainer, nsIDOMNode visualOldContainer,
- List<?> childrenInfoList) {
- for (int i = 0; i < childrenInfoList.size(); i++) {
- VpeChildrenInfo info = (VpeChildrenInfo) childrenInfoList.get(i);
- nsIDOMNode visualParent = info.getVisualParent();
- if (visualParent == null)
- visualParent = visualOldContainer;
- List<?> sourceChildren = info.getSourceChildren();
- int childrenCount = 0;
- if (sourceChildren != null) {
- for (int j = 0; j < sourceChildren.size(); j++) {
- if (addNode((Node) sourceChildren.get(j), null,
- visualParent)) {
- childrenCount++;
- }
- }
- }
- if (childrenCount == 0) {
- setPseudoContent(containerTemplate, sourceContainer,
- visualParent);
- }
- }
+ // /////////////////////////////////////////////////////////////////////////
+ public nsIDOMNode addStyleNodeToHead(String styleText) {
+ nsIDOMNode newStyle = visualDocument
+ .createElement(VpeStyleUtil.ATTRIBUTE_STYLE);
+
+ if (styleText != null) {
+ nsIDOMText newText = visualDocument.createTextNode(styleText);
+ newStyle.appendChild(newText);
}
+ headNode.appendChild(newStyle);
+ return newStyle;
+ }
- // /////////////////////////////////////////////////////////////////////////
- public nsIDOMNode addStyleNodeToHead(String styleText) {
- nsIDOMNode newStyle = visualDocument
- .createElement(VpeStyleUtil.ATTRIBUTE_STYLE);
+ public nsIDOMNode replaceStyleNodeToHead(nsIDOMNode oldStyleNode,
+ String styleText) {
+ nsIDOMElement newStyle = visualDocument
+ .createElement(VpeStyleUtil.ATTRIBUTE_STYLE);
- if (styleText != null) {
- nsIDOMText newText = visualDocument.createTextNode(styleText);
- newStyle.appendChild(newText);
- }
- headNode.appendChild(newStyle);
- return newStyle;
+ if (styleText != null) {
+ nsIDOMNode newText = visualDocument.createTextNode(styleText);
+ newStyle.appendChild(newText);
}
- public nsIDOMNode replaceStyleNodeToHead(nsIDOMNode oldStyleNode,
- String styleText) {
- nsIDOMElement newStyle = visualDocument
- .createElement(VpeStyleUtil.ATTRIBUTE_STYLE);
+ headNode.replaceChild(newStyle, oldStyleNode);
+ return newStyle;
+ }
- if (styleText != null) {
- nsIDOMNode newText = visualDocument.createTextNode(styleText);
- newStyle.appendChild(newText);
- }
+ public void removeStyleNodeFromHead(nsIDOMNode oldStyleNode) {
+ headNode.removeChild(oldStyleNode);
+ }
- headNode.replaceChild(newStyle, oldStyleNode);
- return newStyle;
+ void addExternalLinks() {
+ IEditorInput input = pageContext.getEditPart().getEditorInput();
+ IFile file = null;
+ if (input instanceof IFileEditorInput) {
+ file = ((IFileEditorInput) input).getFile();
}
-
- public void removeStyleNodeFromHead(nsIDOMNode oldStyleNode) {
- headNode.removeChild(oldStyleNode);
+ ResourceReference[] l = null;
+ if (file != null) {
+ l = CSSReferenceList.getInstance().getAllResources(file);
}
-
- void addExternalLinks() {
- IEditorInput input = pageContext.getEditPart().getEditorInput();
- IFile file = null;
- if (input instanceof IFileEditorInput) {
- file = ((IFileEditorInput) input).getFile();
- }
- ResourceReference[] l = null;
- if (file != null) {
- l = CSSReferenceList.getInstance().getAllResources(file);
- }
- if (l != null) {
- for (int i = 0; i < l.length; i++) {
- ResourceReference item = l[i];
- addLinkNodeToHead("file:///" + item.getLocation(), YES_STRING);
- }
- }
+ if (l != null) {
+ for (int i = 0; i < l.length; i++) {
+ ResourceReference item = l[i];
+ addLinkNodeToHead("file:///" + item.getLocation(), YES_STRING);
+ }
}
+ }
- void removeExternalLinks() {
- nsIDOMNodeList childs = headNode.getChildNodes();
- long length = childs.getLength();
- for (long i = length - 1; i >= 0; i--) {
- nsIDOMNode node = childs.item(i);
- if (node.getNodeType() == nsIDOMNode.ELEMENT_NODE) {
- boolean isLink = false;
- boolean isStyle = false;
- if ((isLink = HTML.TAG_LINK
- .equalsIgnoreCase(node.getNodeName()))
- || (isStyle = HTML.TAG_STYLE.equalsIgnoreCase(node
- .getNodeName()))) {
- nsIDOMElement element = (nsIDOMElement) node
- .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID);
- if ((isLink || (isStyle && ATTR_VPE_INLINE_LINK_VALUE
- .equalsIgnoreCase(element.getAttribute(ATTR_VPE))))
- && YES_STRING.equalsIgnoreCase(element
- .getAttribute("ext"))) {
- headNode.removeChild(node);
- }
- }
- }
+ void removeExternalLinks() {
+ nsIDOMNodeList childs = headNode.getChildNodes();
+ long length = childs.getLength();
+ for (long i = length - 1; i >= 0; i--) {
+ nsIDOMNode node = childs.item(i);
+ if (node.getNodeType() == nsIDOMNode.ELEMENT_NODE) {
+ boolean isLink = false;
+ boolean isStyle = false;
+ if ((isLink = HTML.TAG_LINK
+ .equalsIgnoreCase(node.getNodeName()))
+ || (isStyle = HTML.TAG_STYLE.equalsIgnoreCase(node
+ .getNodeName()))) {
+ nsIDOMElement element = (nsIDOMElement) node
+ .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID);
+ if ((isLink || (isStyle && ATTR_VPE_INLINE_LINK_VALUE
+ .equalsIgnoreCase(element.getAttribute(ATTR_VPE))))
+ && YES_STRING.equalsIgnoreCase(element
+ .getAttribute("ext"))) {
+ headNode.removeChild(node);
+ }
}
+ }
}
+ }
- void refreshExternalLinks() {
- removeExternalLinks();
- addExternalLinks();
- }
+ void refreshExternalLinks() {
+ removeExternalLinks();
+ addExternalLinks();
+ }
- // ==========================================================
- void resetPseudoElement(nsIDOMNode visualNode) {
- if (visualNode != null) {
- nsIDOMNode visualParent = visualNode.getParentNode();
- if (visualParent != null) {
- PseudoInfo info = getPseudoInfo(visualParent);
- if (info.pseudoNode == null && !info.isElements) {
- addPseudoElementImpl(visualParent);
- } else if (info.pseudoNode != null && info.isElements) {
- visualParent.removeChild(info.pseudoNode);
- }
- }
+ // ==========================================================
+ void resetPseudoElement(nsIDOMNode visualNode) {
+ if (visualNode != null) {
+ nsIDOMNode visualParent = visualNode.getParentNode();
+ if (visualParent != null) {
+ PseudoInfo info = getPseudoInfo(visualParent);
+ if (info.pseudoNode == null && !info.isElements) {
+ addPseudoElementImpl(visualParent);
+ } else if (info.pseudoNode != null && info.isElements) {
+ visualParent.removeChild(info.pseudoNode);
}
+ }
}
+ }
- private PseudoInfo getPseudoInfo(nsIDOMNode visualParent) {
- nsIDOMNode pseudoNode = null;
- boolean isElements = false;
+ private PseudoInfo getPseudoInfo(nsIDOMNode visualParent) {
+ nsIDOMNode pseudoNode = null;
+ boolean isElements = false;
- if (visualParent == null)
- return new PseudoInfo();
- nsIDOMNodeList visualNodes = visualParent.getChildNodes();
- if (visualNodes == null)
- return new PseudoInfo();
+ if (visualParent == null)
+ return new PseudoInfo();
+ nsIDOMNodeList visualNodes = visualParent.getChildNodes();
+ if (visualNodes == null)
+ return new PseudoInfo();
- long length = visualNodes.getLength();
- for (long i = 0; i < length; i++) {
- nsIDOMNode visualNode = visualNodes.item(i);
- if (pseudoNode == null && isPseudoElement(visualNode)) {
- pseudoNode = visualNode;
- } else if (!isEmptyText(visualNode)) {
- isElements = true;
- }
- if (pseudoNode != null && isElements) {
- break;
- }
- }
- return new PseudoInfo(pseudoNode, isElements);
+ long length = visualNodes.getLength();
+ for (long i = 0; i < length; i++) {
+ nsIDOMNode visualNode = visualNodes.item(i);
+ if (pseudoNode == null && isPseudoElement(visualNode)) {
+ pseudoNode = visualNode;
+ } else if (!isEmptyText(visualNode)) {
+ isElements = true;
+ }
+ if (pseudoNode != null && isElements) {
+ break;
+ }
}
+ return new PseudoInfo(pseudoNode, isElements);
+ }
- static boolean isInitElement(nsIDOMNode visualNode) {
- if (visualNode == null) {
- return false;
- }
+ static boolean isInitElement(nsIDOMNode visualNode) {
+ if (visualNode == null) {
+ return false;
+ }
- if (visualNode.getNodeType() != Node.ELEMENT_NODE) {
- return false;
- }
+ if (visualNode.getNodeType() != Node.ELEMENT_NODE) {
+ return false;
+ }
- if (YES_STRING.equalsIgnoreCase(((nsIDOMElement) visualNode)
- .getAttribute(INIT_ELEMENT_ATTR))) {
- return true;
- }
-
- return false;
+ if (YES_STRING.equalsIgnoreCase(((nsIDOMElement) visualNode)
+ .getAttribute(INIT_ELEMENT_ATTR))) {
+ return true;
}
- static boolean isPseudoElement(nsIDOMNode visualNode) {
- if (visualNode == null) {
- return false;
- }
+ return false;
+ }
- if (visualNode.getNodeType() != Node.ELEMENT_NODE) {
- return false;
- }
+ static boolean isPseudoElement(nsIDOMNode visualNode) {
+ if (visualNode == null) {
+ return false;
+ }
- if (YES_STRING.equalsIgnoreCase(((nsIDOMElement) visualNode
- .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID))
- .getAttribute(PSEUDO_ELEMENT_ATTR))) {
- return true;
- }
+ if (visualNode.getNodeType() != Node.ELEMENT_NODE) {
+ return false;
+ }
- return false;
+ if (YES_STRING.equalsIgnoreCase(((nsIDOMElement) visualNode
+ .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID))
+ .getAttribute(PSEUDO_ELEMENT_ATTR))) {
+ return true;
}
- private void setPseudoContent(VpeTemplate containerTemplate,
- Node sourceContainer, nsIDOMNode visualContainer) {
- if (containerTemplate != null) {
- containerTemplate.setPseudoContent(pageContext, sourceContainer,
- visualContainer, visualDocument);
- } else {
- VpeDefaultPseudoContentCreator.getInstance().setPseudoContent(
- pageContext, sourceContainer, visualContainer,
- visualDocument);
- }
+ return false;
+ }
- // if (isEmptyElement(visualContainer)) {
- // addPseudoElementImpl(visualContainer);
- // }
+ private void setPseudoContent(VpeTemplate containerTemplate,
+ Node sourceContainer, nsIDOMNode visualContainer) {
+ if (containerTemplate != null) {
+ containerTemplate.setPseudoContent(pageContext, sourceContainer,
+ visualContainer, visualDocument);
+ } else {
+ VpeDefaultPseudoContentCreator.getInstance().setPseudoContent(
+ pageContext, sourceContainer, visualContainer,
+ visualDocument);
}
- private void addPseudoElementImpl(nsIDOMNode visualParent) {
- if (!templateManager.isWithoutPseudoElementContainer(visualParent
- .getNodeName())) {
- if (VpeDebug.VISUAL_ADD_PSEUDO_ELEMENT) {
- System.out.println("-------------------- addPseudoElement: "
- + visualParent.getNodeName());
- }
- nsIDOMElement visualPseudoElement = visualDocument
- .createElement(PSEUDO_ELEMENT);
- visualPseudoElement.setAttribute(PSEUDO_ELEMENT_ATTR, "yes");
- visualParent.appendChild(visualPseudoElement);
- }
+ // if (isEmptyElement(visualContainer)) {
+ // addPseudoElementImpl(visualContainer);
+ // }
+ }
+
+ private void addPseudoElementImpl(nsIDOMNode visualParent) {
+ if (!templateManager.isWithoutPseudoElementContainer(visualParent
+ .getNodeName())) {
+ if (VpeDebug.VISUAL_ADD_PSEUDO_ELEMENT) {
+ System.out.println("-------------------- addPseudoElement: "
+ + visualParent.getNodeName());
+ }
+ nsIDOMElement visualPseudoElement = visualDocument
+ .createElement(PSEUDO_ELEMENT);
+ visualPseudoElement.setAttribute(PSEUDO_ELEMENT_ATTR, "yes");
+ visualParent.appendChild(visualPseudoElement);
}
+ }
- public boolean isEmptyElement(nsIDOMNode visualParent) {
- nsIDOMNodeList visualNodes = visualParent.getChildNodes();
- long len = visualNodes.getLength();
+ public boolean isEmptyElement(nsIDOMNode visualParent) {
+ nsIDOMNodeList visualNodes = visualParent.getChildNodes();
+ long len = visualNodes.getLength();
- if ((len == 0) || (len == 1 && isEmptyText(visualNodes.item(0)))) {
- return true;
- }
-
- return false;
+ if ((len == 0) || (len == 1 && isEmptyText(visualNodes.item(0)))) {
+ return true;
}
- public boolean isEmptyDocument() {
- nsIDOMNodeList visualNodes = visualContentArea.getChildNodes();
- long len = visualNodes.getLength();
- if ((len == 0)
- || (len == 1 && (isEmptyText(visualNodes.item(0)) ||
isPseudoElement(visualNodes
- .item(0))))) {
- return true;
- }
+ return false;
+ }
- return false;
+ public boolean isEmptyDocument() {
+ nsIDOMNodeList visualNodes = visualContentArea.getChildNodes();
+ long len = visualNodes.getLength();
+ if ((len == 0)
+ || (len == 1 && (isEmptyText(visualNodes.item(0)) ||
isPseudoElement(visualNodes
+ .item(0))))) {
+ return true;
}
- private boolean isEmptyText(nsIDOMNode visualNode) {
- if (visualNode == null
- || (visualNode.getNodeType() != nsIDOMNode.TEXT_NODE)) {
- return false;
- }
+ return false;
+ }
- if (visualNode.getNodeValue().trim().length() == 0) {
- return true;
- }
+ private boolean isEmptyText(nsIDOMNode visualNode) {
+ if (visualNode == null
+ || (visualNode.getNodeType() != nsIDOMNode.TEXT_NODE)) {
+ return false;
+ }
- return false;
+ if (visualNode.getNodeValue().trim().length() == 0) {
+ return true;
}
- // ==========================================================
+ return false;
+ }
- public void updateNode(Node sourceNode) {
- if (sourceNode == null)
- return;
+ // ==========================================================
- switch (sourceNode.getNodeType()) {
- case Node.DOCUMENT_NODE:
- rebuildDom((Document) sourceNode);
- break;
- case Node.COMMENT_NODE:
- updateComment(sourceNode);
- break;
- default:
- updateElement(getNodeForUpdate(sourceNode));
- }
+ public void updateNode(Node sourceNode) {
+ if (sourceNode == null)
+ return;
+
+ switch (sourceNode.getNodeType()) {
+ case Node.DOCUMENT_NODE:
+ rebuildDom((Document) sourceNode);
+ break;
+ case Node.COMMENT_NODE:
+ updateComment(sourceNode);
+ break;
+ default:
+ updateElement(getNodeForUpdate(sourceNode));
}
+ }
- // TODO Ssergey Vasilyev make a common code for figuring out
- // if it is need to update parent node or not
- private Node getNodeForUpdate(Node sourceNode) {
- /* Changing of <tr> or <td> tags can affect whole the table */
- Node sourceTable = getParentTable(sourceNode, 2);
- if (sourceTable != null) {
- return sourceTable;
- }
+ // TODO Ssergey Vasilyev make a common code for figuring out
+ // if it is need to update parent node or not
+ private Node getNodeForUpdate(Node sourceNode) {
+ /* Changing of <tr> or <td> tags can affect whole the table */
+ Node sourceTable = getParentTable(sourceNode, 2);
+ if (sourceTable != null) {
+ return sourceTable;
+ }
- /* Changing of an <option> tag can affect the parent select */
- Node sourceSelect = getParentSelect(sourceNode);
- if (sourceSelect != null) {
- return sourceSelect;
- }
-
- return sourceNode;
+ /* Changing of an <option> tag can affect the parent select */
+ Node sourceSelect = getParentSelect(sourceNode);
+ if (sourceSelect != null) {
+ return sourceSelect;
}
- private void updateComment(Node sourceNode) {
- VpeNodeMapping mapping = domMapping.getNodeMapping(sourceNode);
- if (mapping != null
- && mapping.getType() == VpeNodeMapping.COMMENT_MAPPING) {
- nsIDOMNodeList visualNodes = mapping.getVisualNode()
- .getChildNodes();
+ return sourceNode;
+ }
- if (visualNodes.getLength() > 0) {
- visualNodes.item(0).setNodeValue(sourceNode.getNodeValue());
- }
- }
+ private void updateComment(Node sourceNode) {
+ VpeNodeMapping mapping = domMapping.getNodeMapping(sourceNode);
+ if (mapping != null
+ && mapping.getType() == VpeNodeMapping.COMMENT_MAPPING) {
+ nsIDOMNodeList visualNodes = mapping.getVisualNode()
+ .getChildNodes();
+
+ if (visualNodes.getLength() > 0) {
+ visualNodes.item(0).setNodeValue(sourceNode.getNodeValue());
+ }
}
+ }
- private void updateElement(Node sourceNode) {
- VpeElementMapping elementMapping = null;
- VpeNodeMapping nodeMapping = domMapping.getNodeMapping(sourceNode);
- if (nodeMapping instanceof VpeElementMapping) {
- elementMapping = (VpeElementMapping) nodeMapping;
- if (elementMapping != null && elementMapping.getTemplate() != null) {
- Node updateNode = elementMapping.getTemplate()
- .getNodeForUptate(pageContext,
- elementMapping.getSourceNode(),
- elementMapping.getVisualNode(),
- elementMapping.getData());
- if (updateNode != null && updateNode != sourceNode) {
- updateNode(updateNode);
- return;
- }
- }
+ private void updateElement(Node sourceNode) {
+ VpeElementMapping elementMapping = null;
+ VpeNodeMapping nodeMapping = domMapping.getNodeMapping(sourceNode);
+ if (nodeMapping instanceof VpeElementMapping) {
+ elementMapping = (VpeElementMapping) nodeMapping;
+ if (elementMapping != null && elementMapping.getTemplate() != null) {
+ Node updateNode = elementMapping.getTemplate()
+ .getNodeForUptate(pageContext,
+ elementMapping.getSourceNode(),
+ elementMapping.getVisualNode(),
+ elementMapping.getData());
+ if (updateNode != null && updateNode != sourceNode) {
+ updateNode(updateNode);
+ return;
}
- nsIDOMNode visualOldNode = domMapping.remove(sourceNode);
- if (visualOldNode != null) {
- if (elementMapping != null) {
- nsIDOMElement border = elementMapping.getBorder();
- if (border != null) {
- visualOldNode = border;
- }
- }
- nsIDOMNode visualContainer = visualOldNode.getParentNode();
- nsIDOMNode visualNextNode = visualOldNode.getNextSibling();
- if (visualContainer != null) {
- visualContainer.removeChild(visualOldNode);
- addNode(sourceNode, visualNextNode, visualContainer);
- }
- } else {
- if (sourceNode.getNodeType() == Node.TEXT_NODE) {
- updateNode(sourceNode.getParentNode());
- }
+ }
+ }
+ nsIDOMNode visualOldNode = domMapping.remove(sourceNode);
+ if (visualOldNode != null) {
+ if (elementMapping != null) {
+ nsIDOMElement border = elementMapping.getBorder();
+ if (border != null) {
+ visualOldNode = border;
}
+ }
+ nsIDOMNode visualContainer = visualOldNode.getParentNode();
+ nsIDOMNode visualNextNode = visualOldNode.getNextSibling();
+ if (visualContainer != null) {
+ visualContainer.removeChild(visualOldNode);
+ addNode(sourceNode, visualNextNode, visualContainer);
+ }
+ } else {
+ if (sourceNode.getNodeType() == Node.TEXT_NODE) {
+ updateNode(sourceNode.getParentNode());
+ }
}
+ }
- public void removeNode(Node sourceNode) {
- domMapping.remove(sourceNode);
+ public void removeNode(Node sourceNode) {
+ domMapping.remove(sourceNode);
+ }
+
+ private Node getParentTable(Node sourceNode, int depth) {
+ Node parentNode = sourceNode.getParentNode();
+ for (int i = 0; parentNode != null && i < depth; parentNode = parentNode
+ .getParentNode(), i++) {
+ if (HTML.TAG_TABLE.equalsIgnoreCase(parentNode.getNodeName())) {
+ return parentNode;
+ }
}
+ return null;
+ }
- private Node getParentTable(Node sourceNode, int depth) {
- Node parentNode = sourceNode.getParentNode();
- for (int i = 0; parentNode != null && i < depth; parentNode = parentNode
- .getParentNode(), i++) {
- if (HTML.TAG_TABLE.equalsIgnoreCase(parentNode.getNodeName())) {
- return parentNode;
- }
- }
- return null;
+ private Node getParentSelect(Node sourceNode) {
+ if (HTML.TAG_OPTION.equalsIgnoreCase(sourceNode.getNodeName())) {
+ Node parentNode = sourceNode.getParentNode();
+ if (HTML.TAG_SELECT.equalsIgnoreCase(parentNode.getNodeName())) {
+ return parentNode;
+ }
}
+ return null;
+ }
- private Node getParentSelect(Node sourceNode) {
- if (HTML.TAG_OPTION.equalsIgnoreCase(sourceNode.getNodeName())) {
- Node parentNode = sourceNode.getParentNode();
- if (HTML.TAG_SELECT.equalsIgnoreCase(parentNode.getNodeName())) {
- return parentNode;
- }
+ public void setText(Node sourceText) {
+ Node sourceParent = sourceText.getParentNode();
+ if (sourceParent != null && sourceParent.getLocalName() != null) {
+ String sourceParentName = sourceParent.getLocalName();
+ if (HTML.TAG_TEXTAREA.equalsIgnoreCase(sourceParentName)
+ || HTML.TAG_OPTION.equalsIgnoreCase(sourceParentName)) {
+ updateNode(sourceText.getParentNode());
+ return;
+ }
+ }
+ nsIDOMNode visualText = domMapping.getVisualNode(sourceText);
+ if (visualText != null) {
+ String visualValue = TextUtil.visualText(sourceText.getNodeValue());
+ visualText.setNodeValue(visualValue);
+ } else {
+ VpeNodeMapping nodeMapping = domMapping
+ .getNodeMapping(sourceParent);
+ if (nodeMapping != null
+ && nodeMapping.getType() == VpeNodeMapping.ELEMENT_MAPPING) {
+ VpeTemplate template = ((VpeElementMapping) nodeMapping)
+ .getTemplate();
+ if (template != null) {
+ if (!template.containsText()) {
+ return;
+ }
}
- return null;
+ }
+ updateNode(sourceText);
}
+ }
- public void setText(Node sourceText) {
- Node sourceParent = sourceText.getParentNode();
- if (sourceParent != null && sourceParent.getLocalName() != null) {
- String sourceParentName = sourceParent.getLocalName();
- if (HTML.TAG_TEXTAREA.equalsIgnoreCase(sourceParentName)
- || HTML.TAG_OPTION.equalsIgnoreCase(sourceParentName)) {
- updateNode(sourceText.getParentNode());
- return;
- }
- }
- nsIDOMNode visualText = domMapping.getVisualNode(sourceText);
- if (visualText != null) {
- String visualValue = TextUtil.visualText(sourceText.getNodeValue());
- visualText.setNodeValue(visualValue);
+ public void setAttribute(Element sourceElement, String name, String value) {
+ VpeElementMapping elementMapping = (VpeElementMapping) domMapping
+ .getNodeMapping(sourceElement);
+ if (elementMapping != null) {
+ if (elementMapping.isIfDependencyFromAttribute(name)) {
+ updateElement(sourceElement);
+ } else {
+ VpeTemplate template = elementMapping.getTemplate();
+ if (elementMapping.getBorder() != null) {
+ updateElement(sourceElement);
+ } else if (template.isRecreateAtAttrChange(pageContext,
+ sourceElement, visualDocument,
+ (nsIDOMElement) elementMapping.getVisualNode(),
+ elementMapping.getData(), name, value)) {
+ updateElement(sourceElement);
} else {
- VpeNodeMapping nodeMapping = domMapping
- .getNodeMapping(sourceParent);
- if (nodeMapping != null
- && nodeMapping.getType() == VpeNodeMapping.ELEMENT_MAPPING) {
- VpeTemplate template = ((VpeElementMapping) nodeMapping)
- .getTemplate();
- if (template != null) {
- if (!template.containsText()) {
- return;
- }
- }
+ nsIDOMElement visualElement = (nsIDOMElement) elementMapping
+ .getVisualNode();
+ if (visualElement != null) {
+ String visualElementName = visualElement.getNodeName();
+ if (HTML.TAG_SELECT.equalsIgnoreCase(visualElementName)) {
+ updateElement(sourceElement);
+ return;
+ } else if (HTML.TAG_OPTION
+ .equalsIgnoreCase(visualElementName)) {
+ updateElement(sourceElement.getParentNode());
+ return;
+ } else if (HTML.TAG_INPUT
+ .equalsIgnoreCase(visualElementName)) {
+ updateElement(sourceElement);
}
- updateNode(sourceText);
+ }
+ setXmlnsAttribute(elementMapping, name, value);
+ template.setAttribute(pageContext, sourceElement,
+ visualDocument, visualElement, elementMapping
+ .getData(), name, value);
+ resetTooltip(sourceElement, visualElement);
}
+ }
}
+ }
- public void setAttribute(Element sourceElement, String name, String value) {
- VpeElementMapping elementMapping = (VpeElementMapping) domMapping
- .getNodeMapping(sourceElement);
- if (elementMapping != null) {
- if (elementMapping.isIfDependencyFromAttribute(name)) {
- updateElement(sourceElement);
- } else {
- VpeTemplate template = elementMapping.getTemplate();
- if (elementMapping.getBorder() != null) {
- updateElement(sourceElement);
- } else if (template.isRecreateAtAttrChange(pageContext,
- sourceElement, visualDocument,
- (nsIDOMElement) elementMapping.getVisualNode(),
- elementMapping.getData(), name, value)) {
- updateElement(sourceElement);
- } else {
- nsIDOMElement visualElement = (nsIDOMElement) elementMapping
- .getVisualNode();
- if (visualElement != null) {
- String visualElementName = visualElement.getNodeName();
- if (HTML.TAG_SELECT.equalsIgnoreCase(visualElementName)) {
- updateElement(sourceElement);
- return;
- } else if (HTML.TAG_OPTION
- .equalsIgnoreCase(visualElementName)) {
- updateElement(sourceElement.getParentNode());
- return;
- } else if (HTML.TAG_INPUT
- .equalsIgnoreCase(visualElementName)) {
- updateElement(sourceElement);
- }
- }
- setXmlnsAttribute(elementMapping, name, value);
- template.setAttribute(pageContext, sourceElement,
- visualDocument, visualElement, elementMapping
- .getData(), name, value);
- resetTooltip(sourceElement, visualElement);
- }
- }
- }
- }
+ public void stopToggle(Node sourceNode) {
+ if (!(sourceNode instanceof Element))
+ return;
- public void stopToggle(Node sourceNode) {
- if (!(sourceNode instanceof Element))
- return;
+ Element sourceElement = (Element) sourceNode;
+ VpeElementMapping elementMapping = (VpeElementMapping) domMapping
+ .getNodeMapping(sourceElement);
+ if (elementMapping != null) {
+ VpeTemplate template = elementMapping.getTemplate();
- Element sourceElement = (Element) sourceNode;
- VpeElementMapping elementMapping = (VpeElementMapping) domMapping
- .getNodeMapping(sourceElement);
- if (elementMapping != null) {
- VpeTemplate template = elementMapping.getTemplate();
-
- if (template instanceof VpeToggableTemplate) {
- ((VpeToggableTemplate) template).stopToggling(sourceElement);
- }
- }
+ if (template instanceof VpeToggableTemplate) {
+ ((VpeToggableTemplate) template).stopToggling(sourceElement);
+ }
}
+ }
- public boolean doToggle(nsIDOMNode visualNode) {
- if (visualNode == null)
- return false;
- nsIDOMElement visualElement = null;
- try {
+ public boolean doToggle(nsIDOMNode visualNode) {
+ if (visualNode == null)
+ return false;
+ nsIDOMElement visualElement = null;
+ try {
- visualElement = (nsIDOMElement) visualNode
- .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID);
- } catch (XPCOMException exception) {
- visualElement = (nsIDOMElement) visualNode.getParentNode()
- .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID);
- }
- if (visualElement == null)
- return false;
+ visualElement = (nsIDOMElement) visualNode
+ .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID);
+ } catch (XPCOMException exception) {
+ visualElement = (nsIDOMElement) visualNode.getParentNode()
+ .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID);
+ }
+ if (visualElement == null)
+ return false;
- nsIDOMAttr toggleIdAttr = visualElement
- .getAttributeNode("vpe-user-toggle-id");
- if (toggleIdAttr == null)
- return false;
- String toggleId = toggleIdAttr.getNodeValue();
+ nsIDOMAttr toggleIdAttr = visualElement
+ .getAttributeNode("vpe-user-toggle-id");
+ if (toggleIdAttr == null)
+ return false;
+ String toggleId = toggleIdAttr.getNodeValue();
- if (toggleId == null)
- return false;
+ if (toggleId == null)
+ return false;
- boolean toggleLookup = false;
- nsIDOMAttr toggleLookupAttr = visualElement
- .getAttributeNode("vpe-user-toggle-lookup-parent");
- if (toggleLookupAttr != null) {
- toggleLookup = "true".equals(toggleLookupAttr.getNodeValue());
- }
+ boolean toggleLookup = false;
+ nsIDOMAttr toggleLookupAttr = visualElement
+ .getAttributeNode("vpe-user-toggle-lookup-parent");
+ if (toggleLookupAttr != null) {
+ toggleLookup = "true".equals(toggleLookupAttr.getNodeValue());
+ }
- VpeElementMapping elementMapping = (VpeElementMapping) domMapping
- .getNodeMapping(getLastSelectedElement());
- Node sourceNode = (Node) domMapping
- .getSourceNode(getLastSelectedElement());
- if (sourceNode == null)
- return false;
+ VpeElementMapping elementMapping = (VpeElementMapping) domMapping
+ .getNodeMapping(getLastSelectedElement());
+ Node sourceNode = (Node) domMapping
+ .getSourceNode(getLastSelectedElement());
+ if (sourceNode == null)
+ return false;
- Element sourceElement = (Element) (sourceNode instanceof Element ? sourceNode
- : sourceNode.getParentNode());
+ Element sourceElement = (Element) (sourceNode instanceof Element ? sourceNode
+ : sourceNode.getParentNode());
- if (elementMapping != null) {
- VpeTemplate template = elementMapping.getTemplate();
+ if (elementMapping != null) {
+ VpeTemplate template = elementMapping.getTemplate();
- while (toggleLookup && sourceElement != null
- && !(template instanceof VpeToggableTemplate)) {
- sourceElement = (Element) sourceElement.getParentNode();
- if (sourceElement == null)
- break;
- elementMapping = (VpeElementMapping) domMapping
- .getNodeMapping(sourceElement);
- if (elementMapping == null)
- continue;
- template = elementMapping.getTemplate();
- }
+ while (toggleLookup && sourceElement != null
+ && !(template instanceof VpeToggableTemplate)) {
+ sourceElement = (Element) sourceElement.getParentNode();
+ if (sourceElement == null)
+ break;
+ elementMapping = (VpeElementMapping) domMapping
+ .getNodeMapping(sourceElement);
+ if (elementMapping == null)
+ continue;
+ template = elementMapping.getTemplate();
+ }
- if (template instanceof VpeToggableTemplate) {
- ((VpeToggableTemplate) template).toggle(this, sourceElement,
- toggleId);
- updateElement(sourceElement);
- return true;
- }
- }
- return false;
+ if (template instanceof VpeToggableTemplate) {
+ ((VpeToggableTemplate) template).toggle(this, sourceElement,
+ toggleId);
+ updateElement(sourceElement);
+ return true;
+ }
}
+ return false;
+ }
- public void removeAttribute(Element sourceElement, String name) {
- VpeElementMapping elementMapping = (VpeElementMapping) domMapping
- .getNodeMapping(sourceElement);
- if (elementMapping != null) {
- if (elementMapping.isIfDependencyFromAttribute(name)) {
- updateElement(sourceElement);
- } else {
- VpeTemplate template = elementMapping.getTemplate();
- if (template.isRecreateAtAttrChange(pageContext, sourceElement,
- visualDocument, (nsIDOMElement) elementMapping
- .getVisualNode(), elementMapping.getData(),
- name, null)) {
- updateElement(sourceElement);
- } else {
- removeXmlnsAttribute(elementMapping, name);
- template.removeAttribute(pageContext, sourceElement,
- visualDocument, (nsIDOMElement) elementMapping
- .getVisualNode(), elementMapping.getData(),
- name);
- resetTooltip(sourceElement, (nsIDOMElement) elementMapping
- .getVisualNode());
- }
- }
+ public void removeAttribute(Element sourceElement, String name) {
+ VpeElementMapping elementMapping = (VpeElementMapping) domMapping
+ .getNodeMapping(sourceElement);
+ if (elementMapping != null) {
+ if (elementMapping.isIfDependencyFromAttribute(name)) {
+ updateElement(sourceElement);
+ } else {
+ VpeTemplate template = elementMapping.getTemplate();
+ if (template.isRecreateAtAttrChange(pageContext, sourceElement,
+ visualDocument, (nsIDOMElement) elementMapping
+ .getVisualNode(), elementMapping.getData(),
+ name, null)) {
+ updateElement(sourceElement);
+ } else {
+ removeXmlnsAttribute(elementMapping, name);
+ template.removeAttribute(pageContext, sourceElement,
+ visualDocument, (nsIDOMElement) elementMapping
+ .getVisualNode(), elementMapping.getData(),
+ name);
+ resetTooltip(sourceElement, (nsIDOMElement) elementMapping
+ .getVisualNode());
}
+ }
}
+ }
- public void refreshBundleValues(Element sourceElement) {
- VpeElementMapping elementMapping = (VpeElementMapping) domMapping
- .getNodeMapping(sourceElement);
- if (elementMapping != null) {
- VpeTemplate template = elementMapping.getTemplate();
- template.refreshBundleValues(pageContext, sourceElement,
- elementMapping.getData());
- }
+ public void refreshBundleValues(Element sourceElement) {
+ VpeElementMapping elementMapping = (VpeElementMapping) domMapping
+ .getNodeMapping(sourceElement);
+ if (elementMapping != null) {
+ VpeTemplate template = elementMapping.getTemplate();
+ template.refreshBundleValues(pageContext, sourceElement,
+ elementMapping.getData());
}
+ }
- boolean isContentArea(nsIDOMNode visualNode) {
- return visualContentArea.equals(visualNode);
- }
+ boolean isContentArea(nsIDOMNode visualNode) {
+ return visualContentArea.equals(visualNode);
+ }
- nsIDOMElement getContentArea() {
- return visualContentArea;
- }
+ nsIDOMElement getContentArea() {
+ return visualContentArea;
+ }
- void setSelectionRectangle(nsIDOMElement visualElement) {
- setSelectionRectangle(visualElement, true);
- }
+ void setSelectionRectangle(nsIDOMElement visualElement) {
+ setSelectionRectangle(visualElement, true);
+ }
- void setSelectionRectangle(nsIDOMElement visualElement, boolean scroll) {
- int resizerConstrains = getResizerConstrains(visualElement);
- visualEditor.setSelectionRectangle(visualElement, resizerConstrains,
- scroll);
- }
+ void setSelectionRectangle(nsIDOMElement visualElement, boolean scroll) {
+ int resizerConstrains = getResizerConstrains(visualElement);
+ visualEditor.setSelectionRectangle(visualElement, resizerConstrains,
+ scroll);
+ }
- public nsIDOMNode addLinkNodeToHead(String href_val, String ext_val) {
- nsIDOMElement newNode = createLinkNode(href_val,
- ATTR_REL_STYLESHEET_VALUE, ext_val);
- headNode.appendChild(newNode);
- return newNode;
- }
+ public nsIDOMNode addLinkNodeToHead(String href_val, String ext_val) {
+ nsIDOMElement newNode = createLinkNode(href_val,
+ ATTR_REL_STYLESHEET_VALUE, ext_val);
+ headNode.appendChild(newNode);
+ return newNode;
+ }
- public nsIDOMNode replaceLinkNodeToHead(nsIDOMNode oldNode,
- String href_val, String ext_val) {
- nsIDOMNode newNode = createLinkNode(href_val,
- ATTR_REL_STYLESHEET_VALUE, ext_val);
- headNode.replaceChild(newNode, oldNode);
- return newNode;
- }
+ public nsIDOMNode replaceLinkNodeToHead(nsIDOMNode oldNode,
+ String href_val, String ext_val) {
+ nsIDOMNode newNode = createLinkNode(href_val,
+ ATTR_REL_STYLESHEET_VALUE, ext_val);
+ headNode.replaceChild(newNode, oldNode);
+ return newNode;
+ }
- public nsIDOMNode replaceLinkNodeToHead(String href_val, String ext_val) {
- nsIDOMNode newNode = null;
- nsIDOMNode oldNode = getLinkNode(href_val, ext_val);
- if (oldNode == null) {
- newNode = addLinkNodeToHead(href_val, ext_val);
- }
- return newNode;
+ public nsIDOMNode replaceLinkNodeToHead(String href_val, String ext_val) {
+ nsIDOMNode newNode = null;
+ nsIDOMNode oldNode = getLinkNode(href_val, ext_val);
+ if (oldNode == null) {
+ newNode = addLinkNodeToHead(href_val, ext_val);
}
+ return newNode;
+ }
- public void removeLinkNodeFromHead(nsIDOMNode node) {
- headNode.removeChild(node);
- }
+ public void removeLinkNodeFromHead(nsIDOMNode node) {
+ headNode.removeChild(node);
+ }
- private nsIDOMElement createLinkNode(String href_val, String rel_val,
- String ext_val) {
- nsIDOMElement linkNode = null;
- if ((ATTR_REL_STYLESHEET_VALUE.equalsIgnoreCase(rel_val))
- && href_val.startsWith("file:")) {
- /*
- * Because of the Mozilla caches the linked css files we replace tag
- * <link rel="styleseet" href="file://..."> with tag
<style
- * vpe="ATTR_VPE_INLINE_LINK_VALUE">file content</style> It is
- * LinkReplacer
- */
- linkNode = visualDocument.createElement(HTML.TAG_STYLE);
- linkNode.setAttribute(ATTR_VPE, ATTR_VPE_INLINE_LINK_VALUE);
+ private nsIDOMElement createLinkNode(String href_val, String rel_val,
+ String ext_val) {
+ nsIDOMElement linkNode = null;
+ if ((ATTR_REL_STYLESHEET_VALUE.equalsIgnoreCase(rel_val))
+ && href_val.startsWith("file:")) {
+ /*
+ * Because of the Mozilla caches the linked css files we replace tag
+ * <link rel="styleseet" href="file://..."> with tag
<style
+ * vpe="ATTR_VPE_INLINE_LINK_VALUE">file content</style> It is
+ * LinkReplacer
+ */
+ linkNode = visualDocument.createElement(HTML.TAG_STYLE);
+ linkNode.setAttribute(ATTR_VPE, ATTR_VPE_INLINE_LINK_VALUE);
- /* Copy links attributes into our <style> */
- linkNode.setAttribute(VpeTemplateManager.ATTR_LINK_HREF, href_val);
- linkNode.setAttribute(VpeTemplateManager.ATTR_LINK_EXT, ext_val);
- try {
- StringBuffer styleText = new StringBuffer(EMPTY_STRING);
- URL url = new URL((new Path(href_val)).toOSString());
- String fileName=url.getFile();
- BufferedReader in = new BufferedReader(new FileReader(
- (fileName)));
- String str = EMPTY_STRING;
- while ((str = in.readLine()) != null) {
- styleText.append(str);
- }
-
- String styleForParse = styleText.toString();
- styleForParse = VpeStyleUtil.addFullPathIntoURLValue(
- styleForParse, href_val);
-
- in.close();
- nsIDOMText textNode = visualDocument
- .createTextNode(styleForParse);
- linkNode.appendChild(textNode);
- return linkNode;
- } catch (FileNotFoundException fnfe) {
- /* File which was pointed by user is not exists. Do nothing. */
- } catch (IOException ioe) {
- VpePlugin.getPluginLog().logError(ioe.getMessage(), ioe);
- }
+ /* Copy links attributes into our <style> */
+ linkNode.setAttribute(VpeTemplateManager.ATTR_LINK_HREF, href_val);
+ linkNode.setAttribute(VpeTemplateManager.ATTR_LINK_EXT, ext_val);
+ try {
+ StringBuffer styleText = new StringBuffer(EMPTY_STRING);
+ URL url = new URL((new Path(href_val)).toOSString());
+ String fileName = url.getFile();
+ BufferedReader in = new BufferedReader(new FileReader(
+ (fileName)));
+ String str = EMPTY_STRING;
+ while ((str = in.readLine()) != null) {
+ styleText.append(str);
}
- linkNode = visualDocument.createElement(HTML.TAG_LINK);
- linkNode.setAttribute(VpeTemplateManager.ATTR_LINK_REL, rel_val);
- linkNode.setAttribute(VpeTemplateManager.ATTR_LINK_HREF, href_val);
- linkNode.setAttribute(VpeTemplateManager.ATTR_LINK_EXT, ext_val);
+ String styleForParse = styleText.toString();
+ styleForParse = VpeStyleUtil.addFullPathIntoURLValue(
+ styleForParse, href_val);
+ in.close();
+ nsIDOMText textNode = visualDocument
+ .createTextNode(styleForParse);
+ linkNode.appendChild(textNode);
return linkNode;
+ } catch (FileNotFoundException fnfe) {
+ /* File which was pointed by user is not exists. Do nothing. */
+ } catch (IOException ioe) {
+ VpePlugin.getPluginLog().logError(ioe.getMessage(), ioe);
+ }
}
- private boolean isLinkReplacer(nsIDOMNode node) {
- return HTML.TAG_STYLE.equalsIgnoreCase(node.getNodeName())
- && ATTR_VPE_INLINE_LINK_VALUE
- .equalsIgnoreCase(((nsIDOMElement) node
- .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID))
- .getAttribute(ATTR_VPE));
- }
+ linkNode = visualDocument.createElement(HTML.TAG_LINK);
+ linkNode.setAttribute(VpeTemplateManager.ATTR_LINK_REL, rel_val);
+ linkNode.setAttribute(VpeTemplateManager.ATTR_LINK_HREF, href_val);
+ linkNode.setAttribute(VpeTemplateManager.ATTR_LINK_EXT, ext_val);
- private nsIDOMNode getLinkNode(String href_val, String ext_val) {
- nsIDOMNodeList children = headNode.getChildNodes();
- long len = children.getLength();
- for (long i = len - 1; i >= 0; i--) {
- nsIDOMNode node = children.item(i);
- if (node.getNodeType() == Node.ELEMENT_NODE) {
- if (HTML.TAG_LINK.equalsIgnoreCase(node.getNodeName())
- || isLinkReplacer(node)) {
- nsIDOMElement element = (nsIDOMElement) node
- .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID);
- if (ext_val.equalsIgnoreCase(element
- .getAttribute(VpeTemplateManager.ATTR_LINK_EXT))
- && href_val
- .equalsIgnoreCase(element
- .getAttribute(VpeTemplateManager.ATTR_LINK_HREF))) {
- return node;
- }
- }
- }
+ return linkNode;
+ }
+
+ private boolean isLinkReplacer(nsIDOMNode node) {
+ return HTML.TAG_STYLE.equalsIgnoreCase(node.getNodeName())
+ && ATTR_VPE_INLINE_LINK_VALUE
+ .equalsIgnoreCase(((nsIDOMElement) node
+ .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID))
+ .getAttribute(ATTR_VPE));
+ }
+
+ private nsIDOMNode getLinkNode(String href_val, String ext_val) {
+ nsIDOMNodeList children = headNode.getChildNodes();
+ long len = children.getLength();
+ for (long i = len - 1; i >= 0; i--) {
+ nsIDOMNode node = children.item(i);
+ if (node.getNodeType() == Node.ELEMENT_NODE) {
+ if (HTML.TAG_LINK.equalsIgnoreCase(node.getNodeName())
+ || isLinkReplacer(node)) {
+ nsIDOMElement element = (nsIDOMElement) node
+ .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID);
+ if (ext_val.equalsIgnoreCase(element
+ .getAttribute(VpeTemplateManager.ATTR_LINK_EXT))
+ && href_val
+ .equalsIgnoreCase(element
+ .getAttribute(VpeTemplateManager.ATTR_LINK_HREF))) {
+ return node;
+ }
}
- return null;
+ }
}
+ return null;
+ }
- private void cleanHead() {
- nsIDOMNodeList children = headNode.getChildNodes();
- long len = children.getLength();
- for (long i = len - 1; i >= 0; i--) {
- nsIDOMNode node = children.item(i);
- if (node.getNodeType() == Node.ELEMENT_NODE) {
- String name = node.getNodeName();
- if (HTML.TAG_LINK.equalsIgnoreCase(name)
- || isLinkReplacer(node)) {
- if (NO_STRING.equalsIgnoreCase(((nsIDOMElement) node
- .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID))
- .getAttribute("ext"))) {
- // int linkAddress =
- // MozillaSupports.queryInterface(node,
- // nsIStyleSheetLinkingElement.NS_ISTYLESHEETLINKINGELEMENT_IID);
- // nsIStyleSheetLinkingElement linkingElement = new
- // nsIStyleSheetLinkingElement(linkAddress);
- // linkingElement.removeStyleSheet();
- node = headNode.removeChild(node);
- }
- } else if (HTML.TAG_STYLE.equalsIgnoreCase(node.getNodeName())
- && (!YES_STRING
- .equalsIgnoreCase(((nsIDOMElement) node
- .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID))
- .getAttribute(ATTR_VPE)))) {
- node = headNode.removeChild(node);
- }
- }
+ private void cleanHead() {
+ nsIDOMNodeList children = headNode.getChildNodes();
+ long len = children.getLength();
+ for (long i = len - 1; i >= 0; i--) {
+ nsIDOMNode node = children.item(i);
+ if (node.getNodeType() == Node.ELEMENT_NODE) {
+ String name = node.getNodeName();
+ if (HTML.TAG_LINK.equalsIgnoreCase(name)
+ || isLinkReplacer(node)) {
+ if (NO_STRING.equalsIgnoreCase(((nsIDOMElement) node
+ .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID))
+ .getAttribute("ext"))) {
+ // int linkAddress =
+ // MozillaSupports.queryInterface(node,
+ // nsIStyleSheetLinkingElement.NS_ISTYLESHEETLINKINGELEMENT_IID);
+ // nsIStyleSheetLinkingElement linkingElement = new
+ // nsIStyleSheetLinkingElement(linkAddress);
+ // linkingElement.removeStyleSheet();
+ node = headNode.removeChild(node);
+ }
+ } else if (HTML.TAG_STYLE.equalsIgnoreCase(node.getNodeName())
+ && (!YES_STRING
+ .equalsIgnoreCase(((nsIDOMElement) node
+ .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID))
+ .getAttribute(ATTR_VPE)))) {
+ node = headNode.removeChild(node);
}
+ }
}
+ }
- private class PseudoInfo {
- private nsIDOMNode pseudoNode;
- private boolean isElements;
+ private class PseudoInfo {
+ private nsIDOMNode pseudoNode;
+ private boolean isElements;
- private PseudoInfo() {
- this(null, false);
- }
-
- private PseudoInfo(nsIDOMNode pseudoNode, boolean isElements) {
- this.pseudoNode = pseudoNode;
- this.isElements = isElements;
- }
+ private PseudoInfo() {
+ this(null, false);
}
- void showDragCaret(nsIDOMNode node, int offset) {
- xulRunnerEditor.showDragCaret(node, offset);
+ private PseudoInfo(nsIDOMNode pseudoNode, boolean isElements) {
+ this.pseudoNode = pseudoNode;
+ this.isElements = isElements;
}
+ }
- void hideDragCaret() {
+ void showDragCaret(nsIDOMNode node, int offset) {
+ xulRunnerEditor.showDragCaret(node, offset);
+ }
- xulRunnerEditor.hideDragCaret();
- }
+ void hideDragCaret() {
- private int getResizerConstrains(nsIDOMNode visualNode) {
- VpeNodeMapping nodeMapping = domMapping.getNodeMapping(visualNode);
- if (nodeMapping != null
- && nodeMapping.getType() == VpeNodeMapping.ELEMENT_MAPPING) {
- return ((VpeElementMapping) nodeMapping).getTemplate()
- .getTagDescription(pageContext,
- (Element) nodeMapping.getSourceNode(),
- visualDocument,
- (nsIDOMElement) nodeMapping.getVisualNode(),
- ((VpeElementMapping) nodeMapping).getData())
- .getResizeConstrains();
- }
- return VpeTagDescription.RESIZE_CONSTRAINS_NONE;
+ xulRunnerEditor.hideDragCaret();
+ }
+
+ private int getResizerConstrains(nsIDOMNode visualNode) {
+ VpeNodeMapping nodeMapping = domMapping.getNodeMapping(visualNode);
+ if (nodeMapping != null
+ && nodeMapping.getType() == VpeNodeMapping.ELEMENT_MAPPING) {
+ return ((VpeElementMapping) nodeMapping).getTemplate()
+ .getTagDescription(pageContext,
+ (Element) nodeMapping.getSourceNode(),
+ visualDocument,
+ (nsIDOMElement) nodeMapping.getVisualNode(),
+ ((VpeElementMapping) nodeMapping).getData())
+ .getResizeConstrains();
}
+ return VpeTagDescription.RESIZE_CONSTRAINS_NONE;
+ }
- public void resize(nsIDOMElement element, int resizerConstrains, int top,
- int left, int width, int height) {
- VpeElementMapping elementMapping = (VpeElementMapping) domMapping
- .getNodeMapping(element);
- if (elementMapping != null) {
- elementMapping.getTemplate().resize(pageContext,
- (Element) elementMapping.getSourceNode(), visualDocument,
- element, elementMapping.getData(), resizerConstrains, top,
- left, width, height);
- }
+ public void resize(nsIDOMElement element, int resizerConstrains, int top,
+ int left, int width, int height) {
+ VpeElementMapping elementMapping = (VpeElementMapping) domMapping
+ .getNodeMapping(element);
+ if (elementMapping != null) {
+ elementMapping.getTemplate().resize(pageContext,
+ (Element) elementMapping.getSourceNode(), visualDocument,
+ element, elementMapping.getData(), resizerConstrains, top,
+ left, width, height);
}
+ }
- static boolean isAnonElement(nsIDOMNode visualNode) {
- if (visualNode != null
- && visualNode.getNodeType() == nsIDOMNode.ELEMENT_NODE) {
- String attrValue = ((nsIDOMElement) visualNode
- .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID))
- .getAttribute(MOZ_ANONCLASS_ATTR);
+ static boolean isAnonElement(nsIDOMNode visualNode) {
+ if (visualNode != null
+ && visualNode.getNodeType() == nsIDOMNode.ELEMENT_NODE) {
+ String attrValue = ((nsIDOMElement) visualNode
+ .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID))
+ .getAttribute(MOZ_ANONCLASS_ATTR);
- return attrValue != null && attrValue.length() > 0;
- }
-
- return false;
+ return attrValue != null && attrValue.length() > 0;
}
- boolean canInnerDrag(nsIDOMElement visualDragElement) {
- VpeNodeMapping node = domMapping.getNodeMapping(visualDragElement);
- if (node instanceof VpeElementMapping) {
- VpeElementMapping elementMapping = (VpeElementMapping) node;
- if (elementMapping != null) {
- return elementMapping.getTemplate().canInnerDrag(pageContext,
- (Element) elementMapping.getSourceNode(),
- visualDocument, visualDragElement,
- elementMapping.getData());
- }
- }
- return false;
+ return false;
+ }
+
+ boolean canInnerDrag(nsIDOMElement visualDragElement) {
+ VpeNodeMapping node = domMapping.getNodeMapping(visualDragElement);
+ if (node instanceof VpeElementMapping) {
+ VpeElementMapping elementMapping = (VpeElementMapping) node;
+ if (elementMapping != null) {
+ return elementMapping.getTemplate().canInnerDrag(pageContext,
+ (Element) elementMapping.getSourceNode(),
+ visualDocument, visualDragElement,
+ elementMapping.getData());
+ }
}
+ return false;
+ }
- VpeSourceInnerDropInfo getSourceInnerDropInfo(Node sourceDragNode,
- VpeVisualInnerDropInfo visualDropInfo, boolean checkParentTemplates) {
- nsIDOMNode visualDropContainer = visualDropInfo.getDropContainer();
- long visualDropOffset = visualDropInfo.getDropOffset();
- Node sourceDropContainer = null;
- int sourceDropOffset = 0;
+ VpeSourceInnerDropInfo getSourceInnerDropInfo(Node sourceDragNode,
+ VpeVisualInnerDropInfo 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 (isPseudoElement(visualOffsetNode)
- || isAnonElement(visualOffsetNode)) {
- visualOffsetNode = getLastAppreciableVisualChild(visualDropContainer);
- afterFlag = true;
- }
- } else {
- visualOffsetNode = getLastAppreciableVisualChild(visualDropContainer);
- afterFlag = visualChildCount != 0;
- }
- if (visualOffsetNode != null) {
- Node sourceOffsetNode = domMapping
- .getSourceNode(visualOffsetNode);
- if (sourceOffsetNode != null) {
- sourceDropContainer = sourceOffsetNode.getParentNode();
- sourceDropOffset = ((NodeImpl) sourceOffsetNode).getIndex();
- if (afterFlag) {
- sourceDropOffset++;
- }
- }
- }
- if (sourceDropContainer == null) {
- sourceDropContainer = domMapping
- .getNearSourceNode(visualDropContainer);
- if (sourceDropContainer != null) {
- sourceDropOffset = sourceDropContainer.getChildNodes()
- .getLength();
- }
- }
- if (sourceDropContainer == null) {
- sourceDropContainer = domMapping
- .getNearSourceNode(visualContentArea);
- sourceDropOffset = sourceDropContainer.getChildNodes()
- .getLength();
- }
- break;
- case nsIDOMNode.TEXT_NODE:
- VpeNodeMapping nodeMapping = domMapping
- .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 (isTextEditable(visualDropContainer)) {
- String[] atributeNames = ((VpeElementMapping) nodeMapping)
- .getTemplate().getOutputAtributeNames();
- 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;
+ 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 (isPseudoElement(visualOffsetNode)
+ || isAnonElement(visualOffsetNode)) {
+ visualOffsetNode = getLastAppreciableVisualChild(visualDropContainer);
+ afterFlag = true;
}
+ } else {
+ visualOffsetNode = getLastAppreciableVisualChild(visualDropContainer);
+ afterFlag = visualChildCount != 0;
+ }
+ if (visualOffsetNode != null) {
+ Node sourceOffsetNode = domMapping
+ .getSourceNode(visualOffsetNode);
+ if (sourceOffsetNode != null) {
+ sourceDropContainer = sourceOffsetNode.getParentNode();
+ sourceDropOffset = ((NodeImpl) sourceOffsetNode).getIndex();
+ if (afterFlag) {
+ sourceDropOffset++;
+ }
+ }
+ }
+ if (sourceDropContainer == null) {
+ sourceDropContainer = domMapping
+ .getNearSourceNode(visualDropContainer);
if (sourceDropContainer != null) {
- return getSourceInnerDropInfo(sourceDragNode, sourceDropContainer,
- sourceDropOffset, checkParentTemplates);
- } else {
- return new VpeSourceInnerDropInfo(null, 0, false);
+ sourceDropOffset = sourceDropContainer.getChildNodes()
+ .getLength();
}
+ }
+ if (sourceDropContainer == null) {
+ sourceDropContainer = domMapping
+ .getNearSourceNode(visualContentArea);
+ sourceDropOffset = sourceDropContainer.getChildNodes()
+ .getLength();
+ }
+ break;
+ case nsIDOMNode.TEXT_NODE:
+ VpeNodeMapping nodeMapping = domMapping
+ .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 (isTextEditable(visualDropContainer)) {
+ String[] atributeNames = ((VpeElementMapping) nodeMapping)
+ .getTemplate().getOutputAtributeNames();
+ 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 getSourceInnerDropInfo(sourceDragNode, sourceDropContainer,
+ sourceDropOffset, checkParentTemplates);
+ } else {
+ return new VpeSourceInnerDropInfo(null, 0, false);
+ }
+ }
- VpeSourceInnerDropInfo getSourceInnerDropInfo(Node dragNode,
- Node container, int offset, boolean checkParentsTemplates) {
- // Thread.dumpStack();
- boolean canDrop = false;
- switch (container.getNodeType()) {
- case Node.ELEMENT_NODE:
- VpeNodeMapping nodeMapping = domMapping.getNodeMapping(container);
- if (nodeMapping != null
- && nodeMapping.getType() == VpeNodeMapping.ELEMENT_MAPPING) {
- canDrop = ((VpeElementMapping) nodeMapping).getTemplate()
- .canInnerDrop(pageContext, container, dragNode);
- }
- if (!canDrop) {
- if (!checkParentsTemplates)
- return new VpeSourceInnerDropInfo(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 getSourceInnerDropInfo(dragNode, container, offset,
- // false);
- return new VpeSourceInnerDropInfo(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 VpeSourceInnerDropInfo(container, offset, canDrop);
+ VpeSourceInnerDropInfo getSourceInnerDropInfo(Node dragNode,
+ Node container, int offset, boolean checkParentsTemplates) {
+ // Thread.dumpStack();
+ boolean canDrop = false;
+ switch (container.getNodeType()) {
+ case Node.ELEMENT_NODE:
+ VpeNodeMapping nodeMapping = domMapping.getNodeMapping(container);
+ if (nodeMapping != null
+ && nodeMapping.getType() == VpeNodeMapping.ELEMENT_MAPPING) {
+ canDrop = ((VpeElementMapping) nodeMapping).getTemplate()
+ .canInnerDrop(pageContext, container, dragNode);
+ }
+ if (!canDrop) {
+ if (!checkParentsTemplates)
+ return new VpeSourceInnerDropInfo(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 getSourceInnerDropInfo(dragNode, container, offset,
+ // false);
+ return new VpeSourceInnerDropInfo(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 VpeSourceInnerDropInfo(container, offset, canDrop);
+ } else {
+ return new VpeSourceInnerDropInfo(null, 0, canDrop);
+ }
+ }
+
+ public void innerDrop(Node dragNode, Node container, int offset) {
+ VpeNodeMapping mapping = domMapping.getNearNodeMapping(container);
+ if (mapping != null) {
+ nsIDOMNode visualDropContainer = mapping.getVisualNode();
+ switch (mapping.getType()) {
+ case VpeNodeMapping.TEXT_MAPPING:
+ break;
+ case VpeNodeMapping.ELEMENT_MAPPING:
+ nsIDOMNode visualParent = visualDropContainer.getParentNode();
+ VpeNodeMapping oldMapping = mapping;
+ mapping = domMapping.getNearNodeMapping(visualParent);
+ if (mapping != null
+ && mapping.getType() == VpeNodeMapping.ELEMENT_MAPPING) {
+ ((VpeElementMapping) mapping).getTemplate()
+ .innerDrop(
+ pageContext,
+ new VpeSourceInnerDragInfo(dragNode, 0, 0),
+ new VpeSourceInnerDropInfo(container,
+ offset, true));
} else {
- return new VpeSourceInnerDropInfo(null, 0, canDrop);
+ ((VpeElementMapping) oldMapping).getTemplate()
+ .innerDrop(
+ pageContext,
+ new VpeSourceInnerDragInfo(dragNode, 0, 0),
+ new VpeSourceInnerDropInfo(container,
+ offset, true));
}
+ }
+
}
+ }
- public void innerDrop(Node dragNode, Node container, int offset) {
- VpeNodeMapping mapping = domMapping.getNearNodeMapping(container);
- if (mapping != null) {
- nsIDOMNode visualDropContainer = mapping.getVisualNode();
- switch (mapping.getType()) {
- case VpeNodeMapping.TEXT_MAPPING:
- break;
- case VpeNodeMapping.ELEMENT_MAPPING:
- nsIDOMNode visualParent = visualDropContainer.getParentNode();
- VpeNodeMapping oldMapping = mapping;
- mapping = domMapping.getNearNodeMapping(visualParent);
- if (mapping != null
- && mapping.getType() == VpeNodeMapping.ELEMENT_MAPPING) {
- ((VpeElementMapping) mapping).getTemplate()
- .innerDrop(
- pageContext,
- new VpeSourceInnerDragInfo(dragNode, 0, 0),
- new VpeSourceInnerDropInfo(container,
- offset, true));
- } else {
- ((VpeElementMapping) oldMapping).getTemplate()
- .innerDrop(
- pageContext,
- new VpeSourceInnerDragInfo(dragNode, 0, 0),
- new VpeSourceInnerDropInfo(container,
- offset, true));
- }
- }
+ void innerDrop(VpeSourceInnerDragInfo dragInfo,
+ VpeSourceInnerDropInfo dropInfo) {
+ dropper.drop(pageContext, dragInfo, dropInfo);
+ }
- }
+ nsIDOMElement getNearDragElement(Element visualElement) {
+ VpeElementMapping elementMapping = domMapping
+ .getNearElementMapping(visualElement);
+ while (elementMapping != null) {
+ if (canInnerDrag(elementMapping.getVisualElement())) {
+ return elementMapping.getVisualElement();
+ }
+ elementMapping = domMapping.getNearElementMapping(elementMapping
+ .getVisualNode().getParentNode());
}
+ return null;
+ }
- void innerDrop(VpeSourceInnerDragInfo dragInfo,
- VpeSourceInnerDropInfo dropInfo) {
- dropper.drop(pageContext, dragInfo, dropInfo);
+ nsIDOMElement getDragElement(nsIDOMElement visualElement) {
+ VpeElementMapping elementMapping = domMapping
+ .getNearElementMapping(visualElement);
+ if (elementMapping != null
+ && canInnerDrag(elementMapping.getVisualElement())) {
+ return elementMapping.getVisualElement();
}
+ return null;
+ }
- nsIDOMElement getNearDragElement(Element visualElement) {
- VpeElementMapping elementMapping = domMapping
- .getNearElementMapping(visualElement);
- while (elementMapping != null) {
- if (canInnerDrag(elementMapping.getVisualElement())) {
- return elementMapping.getVisualElement();
+ public boolean isTextEditable(nsIDOMNode visualNode) {
+ if (visualNode != null) {
+ nsIDOMNode parent = visualNode.getParentNode();
+ if (parent != null
+ && parent.getNodeType() == nsIDOMNode.ELEMENT_NODE) {
+ nsIDOMElement element = (nsIDOMElement) parent
+ .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID);
+ nsIDOMAttr style = element.getAttributeNode("style");
+ if (style != null) {
+ String styleValue = style.getNodeValue();
+ String[] items = styleValue.split(";");
+ for (int i = 0; i < items.length; i++) {
+ String[] item = items[i].split(":");
+ if ("-moz-user-modify".equals(item[0].trim())
+ && "read-only".equals(item[1].trim())) {
+ return false;
}
- elementMapping = domMapping.getNearElementMapping(elementMapping
- .getVisualNode().getParentNode());
+ }
}
- return null;
- }
-
- nsIDOMElement getDragElement(nsIDOMElement visualElement) {
- VpeElementMapping elementMapping = domMapping
- .getNearElementMapping(visualElement);
- if (elementMapping != null
- && canInnerDrag(elementMapping.getVisualElement())) {
- return elementMapping.getVisualElement();
+ nsIDOMAttr classAttr = element.getAttributeNode("class");
+ if (classAttr != null) {
+ String classValue = classAttr.getNodeValue().trim();
+ if ("__any__tag__caption".equals(classValue)) {
+ return false;
+ }
}
- return null;
+ }
}
+ return true;
+ }
- public boolean isTextEditable(nsIDOMNode visualNode) {
- if (visualNode != null) {
- nsIDOMNode parent = visualNode.getParentNode();
- if (parent != null
- && parent.getNodeType() == nsIDOMNode.ELEMENT_NODE) {
- nsIDOMElement element = (nsIDOMElement) parent
- .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID);
- nsIDOMAttr style = element.getAttributeNode("style");
- if (style != null) {
- String styleValue = style.getNodeValue();
- String[] items = styleValue.split(";");
- for (int i = 0; i < items.length; i++) {
- String[] item = items[i].split(":");
- if ("-moz-user-modify".equals(item[0].trim())
- && "read-only".equals(item[1].trim())) {
- return false;
- }
- }
- }
- nsIDOMAttr classAttr = element.getAttributeNode("class");
- if (classAttr != null) {
- String classValue = classAttr.getNodeValue().trim();
- if ("__any__tag__caption".equals(classValue)) {
- return false;
- }
- }
- }
- }
- return true;
- }
+ VpeVisualInnerDropInfo getInnerDropInfo(Node sourceDropContainer,
+ int sourceDropOffset) {
+ nsIDOMNode visualDropContainer = null;
+ long visualDropOffset = 0;
- VpeVisualInnerDropInfo getInnerDropInfo(Node sourceDropContainer,
- int sourceDropOffset) {
- nsIDOMNode visualDropContainer = null;
- long visualDropOffset = 0;
+ switch (sourceDropContainer.getNodeType()) {
+ case Node.TEXT_NODE:
+ visualDropContainer = domMapping.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 = domMapping.getVisualNode(sourceChild);
+ if (visualChild != null) {
+ visualDropContainer = visualChild.getParentNode();
- switch (sourceDropContainer.getNodeType()) {
- case Node.TEXT_NODE:
- visualDropContainer = domMapping.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 = domMapping.getVisualNode(sourceChild);
- if (visualChild != null) {
- visualDropContainer = visualChild.getParentNode();
-
- visualDropOffset = VisualDomUtil.getOffset(visualChild);
- }
- }
- if (visualDropContainer == null) {
- visualDropContainer = domMapping
- .getNearVisualNode(sourceDropContainer);
- nsIDOMNode visualChild = 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 = domMapping
- .getNearElementMapping(sourceElement);
- nsIDOMNode textNode = elementMapping.getTemplate()
- .getOutputTextNode(pageContext, sourceElement,
- elementMapping.getData());
- if (textNode != null) {
- visualDropContainer = textNode;
- visualDropOffset = TextUtil.visualInnerPosition(
- sourceDropContainer.getNodeValue(), sourceDropOffset);
- }
- break;
+ visualDropOffset = VisualDomUtil.getOffset(visualChild);
}
- if (visualDropContainer == null) {
- return null;
+ }
+ if (visualDropContainer == null) {
+ visualDropContainer = domMapping
+ .getNearVisualNode(sourceDropContainer);
+ nsIDOMNode visualChild = getLastAppreciableVisualChild(visualDropContainer);
+ if (visualChild != null) {
+ visualDropOffset = VisualDomUtil.getOffset(visualChild) + 1;
+ } else {
+ visualDropOffset = 0;
}
- return new VpeVisualInnerDropInfo(visualDropContainer,
- visualDropOffset, 0, 0);
+ }
+ break;
+ case Node.ATTRIBUTE_NODE:
+ Element sourceElement = ((Attr) sourceDropContainer)
+ .getOwnerElement();
+ VpeElementMapping elementMapping = domMapping
+ .getNearElementMapping(sourceElement);
+ nsIDOMNode textNode = elementMapping.getTemplate()
+ .getOutputTextNode(pageContext, sourceElement,
+ elementMapping.getData());
+ if (textNode != null) {
+ visualDropContainer = textNode;
+ visualDropOffset = TextUtil.visualInnerPosition(
+ sourceDropContainer.getNodeValue(), sourceDropOffset);
+ }
+ break;
}
+ if (visualDropContainer == null) {
+ return null;
+ }
+ return new VpeVisualInnerDropInfo(visualDropContainer,
+ visualDropOffset, 0, 0);
+ }
- protected void setTooltip(Element sourceElement, nsIDOMElement visualElement) {
- if (visualElement != null && sourceElement != null
- && !((ElementImpl) sourceElement).isJSPTag()) {
- if (HTML.TAG_HTML.equalsIgnoreCase(sourceElement.getNodeName()))
- return;
- String titleValue = getTooltip(sourceElement);
+ protected void setTooltip(Element sourceElement, nsIDOMElement visualElement) {
+ if (visualElement != null && sourceElement != null
+ && !((ElementImpl) sourceElement).isJSPTag()) {
+ if (HTML.TAG_HTML.equalsIgnoreCase(sourceElement.getNodeName()))
+ return;
+ String titleValue = getTooltip(sourceElement);
- if (titleValue != null) {
- titleValue = titleValue.replaceAll("&", "&");
- titleValue = titleValue.replaceAll("<", "<");
- titleValue = titleValue.replaceAll(">", ">");
- }
+ if (titleValue != null) {
+ titleValue = titleValue.replaceAll("&", "&");
+ titleValue = titleValue.replaceAll("<", "<");
+ titleValue = titleValue.replaceAll(">", ">");
+ }
- if (titleValue != null) {
- // visualElement.setAttribute("title", titleValue);
- setTooltip(visualElement, titleValue);
- }
- }
+ if (titleValue != null) {
+ // visualElement.setAttribute("title", titleValue);
+ setTooltip(visualElement, titleValue);
+ }
}
+ }
- protected void setTooltip(nsIDOMElement visualElement, String titleValue) {
- visualElement.setAttribute("title", titleValue);
- nsIDOMNodeList children = visualElement.getChildNodes();
- long len = children.getLength();
- for (long i = 0; i < len; i++) {
- nsIDOMNode child = children.item(i);
- if (child.getNodeType() == nsIDOMNode.ELEMENT_NODE) {
- setTooltip(((nsIDOMElement) child
- .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID)),
- titleValue);
- }
- }
+ protected void setTooltip(nsIDOMElement visualElement, String titleValue) {
+ visualElement.setAttribute("title", titleValue);
+ nsIDOMNodeList children = visualElement.getChildNodes();
+ long len = children.getLength();
+ for (long i = 0; i < len; i++) {
+ nsIDOMNode child = children.item(i);
+ if (child.getNodeType() == nsIDOMNode.ELEMENT_NODE) {
+ setTooltip(((nsIDOMElement) child
+ .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID)),
+ titleValue);
+ }
}
+ }
- private void resetTooltip(Element sourceElement, nsIDOMElement visualElement) {
- if (visualElement != null && sourceElement != null
- && !((ElementImpl) sourceElement).isJSPTag()) {
- if (HTML.TAG_HTML.equalsIgnoreCase(sourceElement.getNodeName()))
- return;
- String titleValue = getTooltip(sourceElement);
+ private void resetTooltip(Element sourceElement, nsIDOMElement visualElement) {
+ if (visualElement != null && sourceElement != null
+ && !((ElementImpl) sourceElement).isJSPTag()) {
+ if (HTML.TAG_HTML.equalsIgnoreCase(sourceElement.getNodeName()))
+ return;
+ String titleValue = getTooltip(sourceElement);
- if (titleValue != null) {
- titleValue = titleValue.replaceAll("&", "&");
- titleValue = titleValue.replaceAll("<", "<");
- titleValue = titleValue.replaceAll(">", ">");
- }
+ if (titleValue != null) {
+ titleValue = titleValue.replaceAll("&", "&");
+ titleValue = titleValue.replaceAll("<", "<");
+ titleValue = titleValue.replaceAll(">", ">");
+ }
- if (titleValue != null) {
- resetTooltip(visualElement, titleValue);
- }
- }
+ if (titleValue != null) {
+ resetTooltip(visualElement, titleValue);
+ }
}
+ }
- private void resetTooltip(nsIDOMElement visualElement, String titleValue) {
- visualElement.setAttribute("title", titleValue);
- nsIDOMNodeList children = visualElement.getChildNodes();
- long len = children.getLength();
- for (long i = 0; i < len; i++) {
- nsIDOMNode child = children.item(i);
- if (child.getNodeType() == nsIDOMNode.ELEMENT_NODE) {
- if (domMapping.getNodeMapping(child) == null) {
- resetTooltip((nsIDOMElement) child
- .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID),
- titleValue);
- }
- }
+ private void resetTooltip(nsIDOMElement visualElement, String titleValue) {
+ visualElement.setAttribute("title", titleValue);
+ nsIDOMNodeList children = visualElement.getChildNodes();
+ long len = children.getLength();
+ for (long i = 0; i < len; i++) {
+ nsIDOMNode child = children.item(i);
+ if (child.getNodeType() == nsIDOMNode.ELEMENT_NODE) {
+ if (domMapping.getNodeMapping(child) == null) {
+ resetTooltip((nsIDOMElement) child
+ .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID),
+ titleValue);
}
+ }
}
+ }
- private String getTooltip(Element sourceElement) {
- StringBuffer buffer = new StringBuffer();
- buffer.append(sourceElement.getNodeName());
- NamedNodeMap attrs = sourceElement.getAttributes();
- int len = attrs.getLength();
- for (int i = 0; i < len; i++) {
- if (i == 7) {
- return buffer.append("\n\t... ").toString();
- }
- int valueLength = attrs.item(i).getNodeValue().length();
- if (valueLength > 30) {
- StringBuffer temp = new StringBuffer();
- temp.append(attrs.item(i).getNodeValue().substring(0, 15)
- + " ... "
- + attrs.item(i).getNodeValue().substring(
- valueLength - 15, valueLength));
- buffer.append("\n" + attrs.item(i).getNodeName() + ": " + temp);
- } else
- buffer.append("\n" + attrs.item(i).getNodeName() + ": "
- + attrs.item(i).getNodeValue());
+ private String getTooltip(Element sourceElement) {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(sourceElement.getNodeName());
+ NamedNodeMap attrs = sourceElement.getAttributes();
+ int len = attrs.getLength();
+ for (int i = 0; i < len; i++) {
+ if (i == 7) {
+ return buffer.append("\n\t... ").toString();
+ }
+ int valueLength = attrs.item(i).getNodeValue().length();
+ if (valueLength > 30) {
+ StringBuffer temp = new StringBuffer();
+ temp.append(attrs.item(i).getNodeValue().substring(0, 15)
+ + " ... "
+ + attrs.item(i).getNodeValue().substring(
+ valueLength - 15, valueLength));
+ buffer.append("\n" + attrs.item(i).getNodeName() + ": " + temp);
+ } else
+ buffer.append("\n" + attrs.item(i).getNodeName() + ": "
+ + attrs.item(i).getNodeValue());
- }
-
- return buffer.toString();
}
- Rectangle getNodeBounds(nsIDOMNode visualNode) {
+ return buffer.toString();
+ }
- return VpeDndUtil.getBounds(visualNode);
- }
+ Rectangle getNodeBounds(nsIDOMNode visualNode) {
- static 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);
+ return XulRunnerVpeUtils.getElementBounds(visualNode);
+ }
+
+ static 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);
+ }
- static nsIDOMNode getLastAppreciableVisualChild(nsIDOMNode visualParent) {
- nsIDOMNode visualLastChild = null;
- nsIDOMNodeList visualChildren = visualParent.getChildNodes();
- long len = visualChildren.getLength();
- for (long i = len - 1; i >= 0; i--) {
- nsIDOMNode visualChild = visualChildren.item(i);
- if (!isPseudoElement(visualChild) && !isAnonElement(visualChild)) {
- visualLastChild = visualChild;
- break;
- }
- }
- return visualLastChild;
+ static nsIDOMNode getLastAppreciableVisualChild(nsIDOMNode visualParent) {
+ nsIDOMNode visualLastChild = null;
+ nsIDOMNodeList visualChildren = visualParent.getChildNodes();
+ long len = visualChildren.getLength();
+ for (long i = len - 1; i >= 0; i--) {
+ nsIDOMNode visualChild = visualChildren.item(i);
+ if (!isPseudoElement(visualChild) && !isAnonElement(visualChild)) {
+ visualLastChild = visualChild;
+ break;
+ }
}
+ return visualLastChild;
+ }
- void correctVisualDropPosition(VpeVisualInnerDropInfo newVisualDropInfo,
- VpeVisualInnerDropInfo oldVisualDropInfo) {
- nsIDOMNode newVisualDropContainer = newVisualDropInfo
- .getDropContainer();
- nsIDOMNode oldVisualDropContainer = oldVisualDropInfo
- .getDropContainer();
+ void correctVisualDropPosition(VpeVisualInnerDropInfo newVisualDropInfo,
+ VpeVisualInnerDropInfo oldVisualDropInfo) {
+ nsIDOMNode newVisualDropContainer = newVisualDropInfo
+ .getDropContainer();
+ nsIDOMNode oldVisualDropContainer = oldVisualDropInfo
+ .getDropContainer();
- if (newVisualDropContainer.equals(oldVisualDropContainer)) {
- newVisualDropInfo.setDropOffset(oldVisualDropInfo.getDropOffset());
- return;
- }
+ 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 = getNodeBounds(child);
- if (canInsertAfter(oldVisualDropInfo.getMouseX(),
- oldVisualDropInfo.getMouseY(), rect)) {
- offset++;
- }
- newVisualDropInfo.setDropOffset(offset);
- }
- child = parent;
+ 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 = getNodeBounds(child);
+ if (canInsertAfter(oldVisualDropInfo.getMouseX(),
+ oldVisualDropInfo.getMouseY(), rect)) {
+ offset++;
}
+ newVisualDropInfo.setDropOffset(offset);
+ }
+ child = parent;
}
+ }
- public nsIDOMRange createDOMRange() {
- return xulRunnerEditor.createDOMRange();
- }
+ public nsIDOMRange createDOMRange() {
+ return xulRunnerEditor.createDOMRange();
+ }
- public nsIDOMRange createDOMRange(nsIDOMNode selectedNode) {
- nsIDOMRange range = createDOMRange();
- range.selectNode(selectedNode);
- return range;
- }
+ public nsIDOMRange createDOMRange(nsIDOMNode selectedNode) {
+ nsIDOMRange range = createDOMRange();
+ range.selectNode(selectedNode);
+ return range;
+ }
- public static boolean isIncludeElement(nsIDOMElement visualElement) {
- return YES_STRING.equalsIgnoreCase(visualElement
- .getAttribute(INCLUDE_ELEMENT_ATTR));
- }
+ public static boolean isIncludeElement(nsIDOMElement visualElement) {
+ return YES_STRING.equalsIgnoreCase(visualElement
+ .getAttribute(INCLUDE_ELEMENT_ATTR));
+ }
- public static void markIncludeElement(nsIDOMElement visualElement) {
- visualElement.setAttribute(INCLUDE_ELEMENT_ATTR, YES_STRING);
- }
+ public static void markIncludeElement(nsIDOMElement visualElement) {
+ visualElement.setAttribute(INCLUDE_ELEMENT_ATTR, YES_STRING);
+ }
- protected void setReadOnlyElement(nsIDOMElement node) {
- String style = node.getAttribute(VpeStyleUtil.ATTRIBUTE_STYLE);
- style = VpeStyleUtil.setParameterInStyle(style, "-moz-user-modify",
- "read-only");
- node.setAttribute(VpeStyleUtil.ATTRIBUTE_STYLE, style);
- }
+ protected void setReadOnlyElement(nsIDOMElement node) {
+ String style = node.getAttribute(VpeStyleUtil.ATTRIBUTE_STYLE);
+ style = VpeStyleUtil.setParameterInStyle(style, "-moz-user-modify",
+ "read-only");
+ node.setAttribute(VpeStyleUtil.ATTRIBUTE_STYLE, style);
+ }
- void setMoveCursor(nsIDOMMouseEvent mouseEvent) {
+ void setMoveCursor(nsIDOMMouseEvent mouseEvent) {
- nsIDOMElement selectedElement = xulRunnerEditor
- .getLastSelectedElement();
- if (selectedElement != null && canInnerDrag(selectedElement)) {
- if (inDragArea(getNodeBounds(selectedElement), VisualDomUtil
- .getMousePoint(mouseEvent))) {
- // change cursor
- Cursor cursor1 = new Cursor(xulRunnerEditor.getDisplay(),
- SWT.CURSOR_SIZEALL);
- xulRunnerEditor.setCursor(cursor1);
- }
- }
+ nsIDOMElement selectedElement = xulRunnerEditor
+ .getLastSelectedElement();
+ if (selectedElement != null && canInnerDrag(selectedElement)) {
+ if (inDragArea(getNodeBounds(selectedElement), VisualDomUtil
+ .getMousePoint(mouseEvent))) {
+ // change cursor
+ Cursor cursor1 = new Cursor(xulRunnerEditor.getDisplay(),
+ SWT.CURSOR_SIZEALL);
+ xulRunnerEditor.setCursor(cursor1);
+ }
}
+ }
- private boolean inDragArea(Rectangle dragArea, Point mousePoint) {
- // TODO add drag and drop support
- return dragArea.contains(mousePoint)
- && mousePoint.x < (dragArea.x + DRAG_AREA_WIDTH)
- && mousePoint.y < (dragArea.y + DRAG_AREA_HEIGHT);
- }
+ private boolean inDragArea(Rectangle dragArea, Point mousePoint) {
+ // TODO add drag and drop support
+ return dragArea.contains(mousePoint)
+ && mousePoint.x < (dragArea.x + DRAG_AREA_WIDTH)
+ && mousePoint.y < (dragArea.y + DRAG_AREA_HEIGHT);
+ }
- nsIDOMElement getDragElement(nsIDOMMouseEvent mouseEvent) {
+ nsIDOMElement getDragElement(nsIDOMMouseEvent mouseEvent) {
- nsIDOMElement selectedElement = xulRunnerEditor
- .getLastSelectedElement();
- if (selectedElement != null && canInnerDrag(selectedElement)) {
- if (inDragArea(getNodeBounds(selectedElement), VisualDomUtil
- .getMousePoint(mouseEvent))) {
- return selectedElement;
- }
- }
- return null;
+ nsIDOMElement selectedElement = xulRunnerEditor
+ .getLastSelectedElement();
+ if (selectedElement != null && canInnerDrag(selectedElement)) {
+ if (inDragArea(getNodeBounds(selectedElement), VisualDomUtil
+ .getMousePoint(mouseEvent))) {
+ return selectedElement;
+ }
}
+ return null;
+ }
- VpeSourceInnerDragInfo getSourceInnerDragInfo(
- VpeVisualInnerDragInfo visualDragInfo) {
- nsIDOMNode visualNode = visualDragInfo.getNode();
- int offset = visualDragInfo.getOffset();
- int length = visualDragInfo.getLength();
+ VpeSourceInnerDragInfo getSourceInnerDragInfo(
+ VpeVisualInnerDragInfo visualDragInfo) {
+ nsIDOMNode visualNode = visualDragInfo.getNode();
+ int offset = visualDragInfo.getOffset();
+ int length = visualDragInfo.getLength();
- VpeNodeMapping nodeMapping = domMapping.getNearNodeMapping(visualNode);
- Node sourceNode = nodeMapping.getSourceNode();
+ VpeNodeMapping nodeMapping = domMapping.getNearNodeMapping(visualNode);
+ Node sourceNode = nodeMapping.getSourceNode();
- if (sourceNode != null) {
- switch (sourceNode.getNodeType()) {
- case Node.TEXT_NODE:
- int end = TextUtil.sourceInnerPosition(visualNode
- .getNodeValue(), offset + length);
- offset = TextUtil.sourceInnerPosition(
- visualNode.getNodeValue(), offset);
- length = end - offset;
- break;
- case Node.ELEMENT_NODE:
- if (visualNode.getNodeType() == Node.TEXT_NODE) {
- // it's attribute
- sourceNode = null;
- if (isTextEditable(visualNode)) {
- String[] atributeNames = ((VpeElementMapping) nodeMapping)
- .getTemplate().getOutputAtributeNames();
- if (atributeNames != null && atributeNames.length > 0) {
- Element sourceElement = (Element) nodeMapping
- .getSourceNode();
- sourceNode = sourceElement
- .getAttributeNode(atributeNames[0]);
- end = TextUtil.sourceInnerPosition(visualNode
- .getNodeValue(), offset + length);
- offset = TextUtil.sourceInnerPosition(visualNode
- .getNodeValue(), offset);
- length = end - offset;
- }
- }
- }
- break;
+ if (sourceNode != null) {
+ switch (sourceNode.getNodeType()) {
+ case Node.TEXT_NODE:
+ int end = TextUtil.sourceInnerPosition(visualNode
+ .getNodeValue(), offset + length);
+ offset = TextUtil.sourceInnerPosition(
+ visualNode.getNodeValue(), offset);
+ length = end - offset;
+ break;
+ case Node.ELEMENT_NODE:
+ if (visualNode.getNodeType() == Node.TEXT_NODE) {
+ // it's attribute
+ sourceNode = null;
+ if (isTextEditable(visualNode)) {
+ String[] atributeNames = ((VpeElementMapping) nodeMapping)
+ .getTemplate().getOutputAtributeNames();
+ if (atributeNames != null && atributeNames.length > 0) {
+ Element sourceElement = (Element) nodeMapping
+ .getSourceNode();
+ sourceNode = sourceElement
+ .getAttributeNode(atributeNames[0]);
+ end = TextUtil.sourceInnerPosition(visualNode
+ .getNodeValue(), offset + length);
+ offset = TextUtil.sourceInnerPosition(visualNode
+ .getNodeValue(), offset);
+ length = end - offset;
}
+ }
}
- return new VpeSourceInnerDragInfo(sourceNode, offset, length);
+ break;
+ }
}
+ return new VpeSourceInnerDragInfo(sourceNode, offset, length);
+ }
- public nsIDOMText getOutputTextNode(Attr attr) {
- Element sourceElement = ((Attr) attr).getOwnerElement();
- VpeElementMapping elementMapping = domMapping
- .getNearElementMapping(sourceElement);
- if (elementMapping != null) {
- return elementMapping.getTemplate().getOutputTextNode(pageContext,
- sourceElement, elementMapping.getData());
- }
- return null;
+ public nsIDOMText getOutputTextNode(Attr attr) {
+ Element sourceElement = ((Attr) attr).getOwnerElement();
+ VpeElementMapping elementMapping = domMapping
+ .getNearElementMapping(sourceElement);
+ if (elementMapping != null) {
+ return elementMapping.getTemplate().getOutputTextNode(pageContext,
+ sourceElement, elementMapping.getData());
}
+ return null;
+ }
- nsIDOMElement getLastSelectedElement() {
+ nsIDOMElement getLastSelectedElement() {
- return xulRunnerEditor.getLastSelectedElement();
- }
+ return xulRunnerEditor.getLastSelectedElement();
+ }
- public void pushIncludeStack(VpeIncludeInfo includeInfo) {
- includeStack.add(includeInfo);
- }
+ public void pushIncludeStack(VpeIncludeInfo includeInfo) {
+ includeStack.add(includeInfo);
+ }
- public VpeIncludeInfo popIncludeStack() {
- VpeIncludeInfo includeInfo = null;
- if (includeStack.size() > 0) {
- includeInfo = (VpeIncludeInfo) includeStack.remove(includeStack
- .size() - 1);
- }
- return includeInfo;
+ public VpeIncludeInfo popIncludeStack() {
+ VpeIncludeInfo includeInfo = null;
+ if (includeStack.size() > 0) {
+ includeInfo = (VpeIncludeInfo) includeStack.remove(includeStack
+ .size() - 1);
}
+ return includeInfo;
+ }
- public boolean isFileInIncludeStack(IFile file) {
- if (file == null)
- return false;
- for (int i = 0; i < includeStack.size(); i++) {
- if (file.equals(((VpeIncludeInfo) includeStack.get(i)).getFile())) {
- return true;
- }
- }
- return false;
+ public boolean isFileInIncludeStack(IFile file) {
+ if (file == null)
+ return false;
+ for (int i = 0; i < includeStack.size(); i++) {
+ if (file.equals(((VpeIncludeInfo) includeStack.get(i)).getFile())) {
+ return true;
+ }
}
+ return false;
+ }
- protected boolean isCurrentMainDocument() {
- return includeStack.size() <= 1;
- }
+ protected boolean isCurrentMainDocument() {
+ return includeStack.size() <= 1;
+ }
- public int getCurrentMainIncludeOffset() {
- if (includeStack.size() <= 1)
- return -1;
- VpeIncludeInfo info = (VpeIncludeInfo) includeStack.get(1);
- return ((IndexedRegion) info.getElement()).getStartOffset();
- }
+ public int getCurrentMainIncludeOffset() {
+ if (includeStack.size() <= 1)
+ return -1;
+ VpeIncludeInfo info = (VpeIncludeInfo) includeStack.get(1);
+ return ((IndexedRegion) info.getElement()).getStartOffset();
+ }
- public VpeIncludeInfo getCurrentIncludeInfo() {
- if (includeStack.size() <= 0)
- return null;
- return (VpeIncludeInfo) includeStack.get(includeStack.size() - 1);
- }
+ public VpeIncludeInfo getCurrentIncludeInfo() {
+ if (includeStack.size() <= 0)
+ return null;
+ return (VpeIncludeInfo) includeStack.get(includeStack.size() - 1);
+ }
- public VpeIncludeInfo getRootIncludeInfo() {
- if (includeStack.size() <= 1)
- return null;
- return (VpeIncludeInfo) includeStack.get(1);
- }
+ public VpeIncludeInfo getRootIncludeInfo() {
+ if (includeStack.size() <= 1)
+ return null;
+ return (VpeIncludeInfo) includeStack.get(1);
+ }
- void dispose() {
- cleanHead();
- domMapping.clear(visualContentArea);
- pageContext.dispose();
- }
+ void dispose() {
+ cleanHead();
+ domMapping.clear(visualContentArea);
+ pageContext.dispose();
+ }
- protected Map createXmlns(Element sourceNode) {
- NamedNodeMap attrs = ((Element) sourceNode).getAttributes();
- if (attrs != null) {
- Map xmlnsMap = new HashMap();
- for (int i = 0; i < attrs.getLength(); i++) {
- addTaglib(sourceNode, xmlnsMap, attrs.item(i).getNodeName(),
- true);
- }
- if (xmlnsMap.size() > 0) {
- return xmlnsMap;
- }
- }
- return null;
+ protected Map createXmlns(Element sourceNode) {
+ NamedNodeMap attrs = ((Element) sourceNode).getAttributes();
+ if (attrs != null) {
+ Map xmlnsMap = new HashMap();
+ for (int i = 0; i < attrs.getLength(); i++) {
+ addTaglib(sourceNode, xmlnsMap, attrs.item(i).getNodeName(),
+ true);
+ }
+ if (xmlnsMap.size() > 0) {
+ return xmlnsMap;
+ }
}
+ return null;
+ }
- private void setXmlnsAttribute(VpeElementMapping elementMapping,
- String name, String value) {
- Element sourceElement = (Element) elementMapping.getSourceNode();
- if (sourceElement != null) {
- Map xmlnsMap = elementMapping.getXmlnsMap();
- if (xmlnsMap == null)
- xmlnsMap = new HashMap();
- addTaglib(sourceElement, xmlnsMap, name, true);
- elementMapping.setXmlnsMap(xmlnsMap.size() > 0 ? xmlnsMap : null);
- }
+ private void setXmlnsAttribute(VpeElementMapping elementMapping,
+ String name, String value) {
+ Element sourceElement = (Element) elementMapping.getSourceNode();
+ if (sourceElement != null) {
+ Map xmlnsMap = elementMapping.getXmlnsMap();
+ if (xmlnsMap == null)
+ xmlnsMap = new HashMap();
+ addTaglib(sourceElement, xmlnsMap, name, true);
+ elementMapping.setXmlnsMap(xmlnsMap.size() > 0 ? xmlnsMap : null);
}
+ }
- private void removeXmlnsAttribute(VpeElementMapping elementMapping,
- String name) {
- Element sourceElement = (Element) elementMapping.getSourceNode();
- if (sourceElement != null) {
- Map xmlnsMap = elementMapping.getXmlnsMap();
- if (xmlnsMap != null) {
- Object id = xmlnsMap.remove(name);
- if (id != null) {
- pageContext.setTaglib(((Integer) id).intValue(), null,
- null, true);
- elementMapping.setXmlnsMap(xmlnsMap.size() > 0 ? xmlnsMap
- : null);
- }
- }
+ private void removeXmlnsAttribute(VpeElementMapping elementMapping,
+ String name) {
+ Element sourceElement = (Element) elementMapping.getSourceNode();
+ if (sourceElement != null) {
+ Map xmlnsMap = elementMapping.getXmlnsMap();
+ if (xmlnsMap != null) {
+ Object id = xmlnsMap.remove(name);
+ if (id != null) {
+ pageContext.setTaglib(((Integer) id).intValue(), null,
+ null, true);
+ elementMapping.setXmlnsMap(xmlnsMap.size() > 0 ? xmlnsMap
+ : null);
}
+ }
}
+ }
- private void addTaglib(Element sourceElement, Map xmlnsMap,
- String attrName, boolean ns) {
- Attr attr = sourceElement.getAttributeNode(attrName);
- if (ATTR_XMLNS.equals(attr.getPrefix())) {
- xmlnsMap.put(attr.getNodeName(), Integer.valueOf(attr.hashCode()));
- pageContext.setTaglib(attr.hashCode(), attr.getNodeValue(), attr
- .getLocalName(), ns);
- }
+ private void addTaglib(Element sourceElement, Map xmlnsMap,
+ String attrName, boolean ns) {
+ Attr attr = sourceElement.getAttributeNode(attrName);
+ if (ATTR_XMLNS.equals(attr.getPrefix())) {
+ xmlnsMap.put(attr.getNodeName(), Integer.valueOf(attr.hashCode()));
+ pageContext.setTaglib(attr.hashCode(), attr.getNodeValue(), attr
+ .getLocalName(), ns);
}
+ }
- /**
- * @return the dnd
- */
- public VpeDnD getDnd() {
+ /**
+ * @return the dnd
+ */
+ public VpeDnD getDnd() {
- return dnd;
- }
+ return dnd;
+ }
- /**
- * @param dnd
- * the dnd to set
- */
- public void setDnd(VpeDnD dnd) {
+ /**
+ * @param dnd
+ * the dnd to set
+ */
+ public void setDnd(VpeDnD dnd) {
- this.dnd = dnd;
- }
+ this.dnd = dnd;
+ }
- /**
- * @return the pageContext
- */
- protected VpePageContext getPageContext() {
- return pageContext;
- }
+ /**
+ * @return the pageContext
+ */
+ protected VpePageContext getPageContext() {
+ return pageContext;
+ }
- /**
- * @param pageContext
- * the pageContext to set
- */
- protected void setPageContext(VpePageContext pageContext) {
- this.pageContext = pageContext;
- }
+ /**
+ * @param pageContext
+ * the pageContext to set
+ */
+ protected void setPageContext(VpePageContext pageContext) {
+ this.pageContext = pageContext;
+ }
- /**
- * @return the visualDocument
- */
- protected nsIDOMDocument getVisualDocument() {
- return visualDocument;
- }
+ /**
+ * @return the visualDocument
+ */
+ protected nsIDOMDocument getVisualDocument() {
+ return visualDocument;
+ }
- /**
- * @param visualDocument
- * the visualDocument to set
- */
- protected void setVisualDocument(nsIDOMDocument visualDocument) {
- this.visualDocument = visualDocument;
- }
-
- /**
- * Check this file is facelet
- * @return this if file is facelet, otherwize false
- */
- private boolean isFacelet() {
- boolean isFacelet = false;
-
- IEditorInput iEditorInput = pageContext.getEditPart().getEditorInput();
- if ( iEditorInput instanceof IFileEditorInput ) {
- IFileEditorInput iFileEditorInput = (IFileEditorInput) iEditorInput;
-
- IFile iFile = iFileEditorInput.getFile();
-
- IProject project = iFile.getProject();
- IModelNature nature = EclipseResourceUtil.getModelNature(project);
- if (nature != null) {
- XModel model = nature.getModel();
- XModelObject webXML = WebAppHelper.getWebApp(model);
- XModelObject param = WebAppHelper.findWebAppContextParam(webXML,
"javax.faces.DEFAULT_SUFFIX");
- if ( param != null ) {
- String value = param.getAttributeValue("param-value");
-
- if ( value.length() != 0 && iFile.getName().endsWith(value)) {
- isFacelet = true;
- }
- }
- }
+ /**
+ * @param visualDocument
+ * the visualDocument to set
+ */
+ protected void setVisualDocument(nsIDOMDocument visualDocument) {
+ this.visualDocument = visualDocument;
+ }
+
+ /**
+ * Check this file is facelet
+ *
+ * @return this if file is facelet, otherwize false
+ */
+ private boolean isFacelet() {
+ boolean isFacelet = false;
+
+ IEditorInput iEditorInput = pageContext.getEditPart().getEditorInput();
+ if (iEditorInput instanceof IFileEditorInput) {
+ IFileEditorInput iFileEditorInput = (IFileEditorInput) iEditorInput;
+
+ IFile iFile = iFileEditorInput.getFile();
+
+ IProject project = iFile.getProject();
+ IModelNature nature = EclipseResourceUtil.getModelNature(project);
+ if (nature != null) {
+ XModel model = nature.getModel();
+ XModelObject webXML = WebAppHelper.getWebApp(model);
+ XModelObject param = WebAppHelper.findWebAppContextParam(
+ webXML, "javax.faces.DEFAULT_SUFFIX");
+ if (param != null) {
+ String value = param.getAttributeValue("param-value");
+
+ if (value.length() != 0 && iFile.getName().endsWith(value)) {
+ isFacelet = true;
+ }
}
-
- return isFacelet;
+ }
}
- /**
- * Create a visual element for text node
- * @param sourceNode
- * @param registerFlag
- * @return a visual element for text node
- */
-
- protected nsIDOMNode createTextNode(Node sourceNode, boolean registerFlag ) {
- String sourceText = sourceNode.getNodeValue();
- if (sourceText.trim().length() <= 0) {
- registerNodes(new VpeNodeMapping(sourceNode, null));
- return null;
- }
+ return isFacelet;
+ }
- if (faceletFile) {
- Matcher matcher_EL = REGEX_EL.matcher(sourceText);
- if (matcher_EL.find()) {
- BundleMap bundle = pageContext.getBundle();
- int offset = pageContext.getVisualBuilder().getCurrentMainIncludeOffset();
- if (offset == -1) offset = ((IndexedRegion)sourceNode).getStartOffset();
- String jsfValue = bundle.getBundleValue(sourceText, offset);
- sourceText = jsfValue;
- }
- }
- String visualText = TextUtil.visualText(sourceText);
+ /**
+ * Create a visual element for text node
+ *
+ * @param sourceNode
+ * @param registerFlag
+ * @return a visual element for text node
+ */
- nsIDOMNode visualNewTextNode = visualDocument.createTextNode(visualText);
- if (registerFlag) {
- registerNodes(new VpeNodeMapping(sourceNode, visualNewTextNode));
- }
+ protected nsIDOMNode createTextNode(Node sourceNode, boolean registerFlag) {
+ String sourceText = sourceNode.getNodeValue();
+ if (sourceText.trim().length() <= 0) {
+ registerNodes(new VpeNodeMapping(sourceNode, null));
+ return null;
+ }
- return visualNewTextNode;
+ if (faceletFile) {
+ Matcher matcher_EL = REGEX_EL.matcher(sourceText);
+ if (matcher_EL.find()) {
+ BundleMap bundle = pageContext.getBundle();
+ int offset = pageContext.getVisualBuilder()
+ .getCurrentMainIncludeOffset();
+ if (offset == -1)
+ offset = ((IndexedRegion) sourceNode).getStartOffset();
+ String jsfValue = bundle.getBundleValue(sourceText, offset);
+ sourceText = jsfValue;
+ }
}
+ String visualText = TextUtil.visualText(sourceText);
- /**
- * @return the xulRunnerEditor
- */
- public XulRunnerEditor getXulRunnerEditor() {
- return xulRunnerEditor;
+ nsIDOMNode visualNewTextNode = visualDocument
+ .createTextNode(visualText);
+ if (registerFlag) {
+ registerNodes(new VpeNodeMapping(sourceNode, visualNewTextNode));
}
- /**
- * @param xulRunnerEditor the xulRunnerEditor to set
- */
- public void setXulRunnerEditor(XulRunnerEditor xulRunnerEditor) {
- this.xulRunnerEditor = xulRunnerEditor;
- }
+ return visualNewTextNode;
+ }
+
+ /**
+ * @return the xulRunnerEditor
+ */
+ public XulRunnerEditor getXulRunnerEditor() {
+ return xulRunnerEditor;
+ }
+
+ /**
+ * @param xulRunnerEditor
+ * the xulRunnerEditor to set
+ */
+ public void setXulRunnerEditor(XulRunnerEditor xulRunnerEditor) {
+ this.xulRunnerEditor = xulRunnerEditor;
+ }
}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/VpeDndUtil.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/VpeDndUtil.java 2007-11-01
19:49:18 UTC (rev 4646)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/VpeDndUtil.java 2007-11-01
19:50:18 UTC (rev 4647)
@@ -7,79 +7,38 @@
*
* Contributors:
* Exadel, Inc. and Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
+ ******************************************************************************/
package org.jboss.tools.vpe.editor.util;
import java.util.Properties;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.viewers.ISelectionProvider;
-import org.eclipse.swt.graphics.Rectangle;
import org.jboss.tools.common.model.ui.dnd.DnDUtil;
import org.jboss.tools.common.model.ui.editor.IModelObjectEditorInput;
import org.jboss.tools.common.model.ui.views.palette.PaletteInsertHelper;
import org.jboss.tools.vpe.VpePlugin;
-import org.mozilla.interfaces.nsIDOMNSHTMLElement;
-import org.mozilla.interfaces.nsIDOMNode;
-import org.mozilla.xpcom.XPCOMException;
public class VpeDndUtil {
- public static boolean isDropEnabled(IModelObjectEditorInput input){
- return DnDUtil.isPasteEnabled(input.getXModelObject());
- }
-
- public static void drop(IModelObjectEditorInput input, ISourceViewer viewer,
ISelectionProvider provider){
- Properties properties = new Properties();
- properties.setProperty("isDrop", "true");
- properties.setProperty("actionSourceGUIComponentID",
"editor");
- properties.setProperty("accepsAsString", "true");
- properties.put("selectionProvider", provider);
- properties.put("viewer", viewer);
-
- try{
- DnDUtil.paste(input.getXModelObject(), properties);
- PaletteInsertHelper.insertIntoEditor(viewer, properties);
- }catch(Exception ex){
- VpePlugin.getPluginLog().logError(ex);
- }
- }
-
- /**
- *
- * @param visualNode
- * @return returns absolute position and size of visual node
- */
- public static Rectangle getBounds(nsIDOMNode visualNode) {
- try {
-
- nsIDOMNSHTMLElement domNSHTMLElement = (nsIDOMNSHTMLElement)
visualNode.queryInterface(nsIDOMNSHTMLElement.NS_IDOMNSHTMLELEMENT_IID);
- int offsetLeft=domNSHTMLElement.getOffsetLeft();
- int offsetTop =domNSHTMLElement.getOffsetTop();
- int offsetWidth=domNSHTMLElement.getOffsetWidth();
- int offsetHeight=domNSHTMLElement.getOffsetHeight();
- while(true) {
-
- try{
-
- if(domNSHTMLElement.getOffsetParent()==null) {
- break;
- }
-
- domNSHTMLElement=(nsIDOMNSHTMLElement)
domNSHTMLElement.getOffsetParent().queryInterface(nsIDOMNSHTMLElement.NS_IDOMNSHTMLELEMENT_IID);
- offsetLeft+=domNSHTMLElement.getOffsetLeft();
- offsetTop+=domNSHTMLElement.getOffsetTop();
- } catch(XPCOMException ex){
- break;
- }
- }
+ public static boolean isDropEnabled(IModelObjectEditorInput input) {
+ return DnDUtil.isPasteEnabled(input.getXModelObject());
+ }
- return new Rectangle(offsetLeft, offsetTop,offsetWidth,offsetHeight);
-
- } catch(XPCOMException xpcomException) {
-
- //TODO Max Areshkau
- //If node not not implement nsIDOMNSHTMLElement, may be check best take a parent node
- return new Rectangle(0, 0, 0,0);
- }
+ public static void drop(IModelObjectEditorInput input,
+ ISourceViewer viewer, ISelectionProvider provider) {
+ Properties properties = new Properties();
+ properties.setProperty("isDrop", "true");
+ properties.setProperty("actionSourceGUIComponentID", "editor");
+ properties.setProperty("accepsAsString", "true");
+ properties.put("selectionProvider", provider);
+ properties.put("viewer", viewer);
+
+ try {
+ DnDUtil.paste(input.getXModelObject(), properties);
+ PaletteInsertHelper.insertIntoEditor(viewer, properties);
+ } catch (Exception ex) {
+ VpePlugin.getPluginLog().logError(ex);
}
+ }
+
}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe.xulrunner/src/org/jboss/tools/vpe/xulrunner/editor/XulRunnerVpeUtils.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe.xulrunner/src/org/jboss/tools/vpe/xulrunner/editor/XulRunnerVpeUtils.java 2007-11-01
19:49:18 UTC (rev 4646)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.xulrunner/src/org/jboss/tools/vpe/xulrunner/editor/XulRunnerVpeUtils.java 2007-11-01
19:50:18 UTC (rev 4647)
@@ -12,44 +12,35 @@
package org.jboss.tools.vpe.xulrunner.editor;
import org.eclipse.swt.graphics.Rectangle;
+import org.mozilla.interfaces.nsIBoxObject;
+import org.mozilla.interfaces.nsIDOMDocument;
import org.mozilla.interfaces.nsIDOMElement;
-import org.mozilla.interfaces.nsIDOMNSHTMLElement;
+import org.mozilla.interfaces.nsIDOMNSDocument;
+import org.mozilla.interfaces.nsIDOMNode;
import org.mozilla.xpcom.XPCOMException;
/**
- * @author A. Yukhovich
+ * @author dsakovich(a)exadel.com
*/
public class XulRunnerVpeUtils {
- /**
- * @param domElement
- * @return
- */
- static public Rectangle getElementBounds(nsIDOMElement domElement) {
- try {
- nsIDOMNSHTMLElement domNSHTMLElement = (nsIDOMNSHTMLElement)
domElement.queryInterface(nsIDOMNSHTMLElement.NS_IDOMNSHTMLELEMENT_IID);
- int offsetLeft = domNSHTMLElement.getOffsetLeft();
- int offsetTop = domNSHTMLElement.getOffsetTop();
- int width = domNSHTMLElement.getOffsetWidth();
- int height = domNSHTMLElement.getOffsetHeight();
-
- while (true) {
- try {
- if (domNSHTMLElement.getOffsetParent() == null) {
- break;
- }
+ /**
+ * @param domElement
+ * @return Rectangle
+ */
+ static public Rectangle getElementBounds(nsIDOMNode domNode) {
+ try {
+ nsIDOMElement domElement = (nsIDOMElement) domNode
+ .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID);
+ nsIDOMDocument document = domElement.getOwnerDocument();
+ nsIDOMNSDocument nsDocument = (nsIDOMNSDocument) document
+ .queryInterface(nsIDOMNSDocument.NS_IDOMNSDOCUMENT_IID);
+ nsIBoxObject boxObject = nsDocument.getBoxObjectFor(domElement);
+ return new Rectangle(boxObject.getX(), boxObject.getY(), boxObject
+ .getWidth(), boxObject.getHeight());
- domNSHTMLElement = (nsIDOMNSHTMLElement)
domNSHTMLElement.getOffsetParent().queryInterface(nsIDOMNSHTMLElement.NS_IDOMNSHTMLELEMENT_IID);
- offsetLeft += domNSHTMLElement.getOffsetLeft();
- offsetTop += domNSHTMLElement.getOffsetTop();
- } catch (XPCOMException ex) {
- break;
- }
- }
- return new Rectangle(offsetLeft, offsetTop, width, height);
-
- } catch (XPCOMException xpcomException) {
- return new Rectangle(0, 0, 0, 0);
- }
+ } catch (XPCOMException xpcomException) {
+ return new Rectangle(0, 0, 0, 0);
}
+ }
}