3 <!-- ***** BEGIN LICENSE BLOCK *****
4 - Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 - The contents of this file are subject to the Mozilla Public License Version
7 - 1.1 (the "License"); you may not use this file except in compliance with
8 - the License. You may obtain a copy of the License at
9 - http://www.mozilla.org/MPL/
11 - Software distributed under the License is distributed on an "AS IS" basis,
12 - WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 - for the specific language governing rights and limitations under the
16 - The Original Code is BlueGriffon.
18 - The Initial Developer of the Original Code is
19 - Disruptive Innovations SARL.
20 - Portions created by the Initial Developer are Copyright (C) 2006
21 - the Initial Developer. All Rights Reserved.
24 - Daniel Glazman (daniel.glazman@disruptive-innovations.com), Original Author
26 - Alternatively, the contents of this file may be used under the terms of
27 - either the GNU General Public License Version 2 or later (the "GPL"), or
28 - the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 - in which case the provisions of the GPL or the LGPL are applicable instead
30 - of those above. If you wish to allow use of your version of this file only
31 - under the terms of either the GPL or the LGPL, and not to allow others to
32 - use your version of this file under the terms of the MPL, indicate your
33 - decision by deleting the provisions above and replace them with the notice
34 - and other provisions required by the LGPL or the GPL. If you do not delete
35 - the provisions above, a recipient may use your version of this file under
36 - the terms of any one of the MPL, the GPL or the LGPL.
38 - ***** END LICENSE BLOCK ***** -->
41 <bindings id="rulersBindings"
42 xmlns="http://www.mozilla.org/xbl"
43 xmlns:html="http://www.w3.org/1999/xhtml"
44 xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
45 xmlns:xbl="http://www.mozilla.org/xbl"
46 xmlns:svg="http://www.w3.org/2000/svg">
48 <binding id="ruler-base">
54 NotifierUtils.addNotifierCallback("selection", this.selectionChanged, this);
55 NotifierUtils.addNotifierCallback("resizeEvent", this.onResizeEvent, this);
56 NotifierUtils.addNotifierCallback("editorScrolled", this.onEditorScrolled, this);
60 <field name="kSVG_NS">"http://www.w3.org/2000/svg"</field>
62 <field name="mPos">0</field>
63 <field name="mSize">0</field>
64 <field name="mSource">null</field>
65 <field name="mRulerSeparatorPosition">null</field>
66 <field name="mResizing">false</field>
67 <field name="mRuleSeparator">null</field>
69 <method name="onEditorScrolled">
72 var elt = EditorUtils.getSelectionContainer().node;
73 this.selectionChanged(null, elt, true);
78 <method name="onResizeEvent">
81 var elt = EditorUtils.getSelectionContainer().node;
82 this.selectionChanged(null, elt, true);
87 <method name="selectionChanged">
88 <parameter name="aArguments"/>
89 <parameter name="aNode"/>
90 <parameter name="aOneElementSelected"/>
94 var display = this.getComputedStyle(aNode).getPropertyValue("display");
97 display != "inline-block" &&
99 display != "table-cell" &&
100 display != "list-item" &&
101 node.nodeName.toLowerCase() != "img")
103 node = node.parentNode;
104 display = this.getComputedStyle(node).getPropertyValue("display");
107 if (node instanceof Components.interfaces.nsIDOMHTMLTableCellElement)
110 while (child.previousSibling)
111 child = child.previousSibling;
114 if (child.nodeType == Node.ELEMENT_NODE)
115 this._showElementRuler(child);
116 child = child.nextSibling;
120 this._showElementRuler(node);
125 <method name="getComputedStyle">
126 <parameter name="aElt"/>
129 return aElt.ownerDocument.defaultView.getComputedStyle(aElt, "");
134 <property name="mSVGGroup">
137 return document.getAnonymousElementByAttribute(this, "anonid", "SVGGroup");
142 <property name="mHTMLcontainer">
145 return document.getAnonymousElementByAttribute(this, "anonid", "HTMLcontainer");
150 <method name="clean">
153 var svgGroup = this.mSVGGroup;
154 var child = svgGroup.firstChild;
157 var tmp = child.nextSibling;
158 svgGroup.removeChild(child);
169 <binding id="hruler" extends="chrome://bluegriffon/content/bindings/rulers.xml#ruler-base">
171 <html:div anonid="HTMLcontainer"
172 style="margin: 0px; padding: 0px; width: 100%!important; height: 100%">
173 <svg:svg style="width: 100% ! important; height: 16px;" height="16"
174 preserveAspectRatio="xMidYMid meet">
175 <svg:g anonid="SVGGroup"/>
182 <field name="mOriginalX">0</field>
183 <field name="mMarginLeft">0</field>
184 <field name="mWidth">0</field>
186 <method name="_showElementRuler">
187 <parameter name="aElt"/>
190 var w = aElt.clientWidth;
191 var x = aElt.offsetLeft + 12;
193 while (o.offsetParent)
198 if (aElt instanceof Components.interfaces.nsIDOMHTMLTableCellElement)
200 var cs = this.getComputedStyle(aElt);
201 var pl = cs.getPropertyCSSValue("padding-left");
202 var pr = cs.getPropertyCSSValue("padding-right");
204 if (pl.primitiveType == CSSPrimitiveValue.CSS_PX)
206 var plv = pl.getFloatValue(CSSPrimitiveValue.CSS_PX);
210 if (pr.primitiveType == CSSPrimitiveValue.CSS_PX)
212 var prv = pr.getFloatValue(CSSPrimitiveValue.CSS_PX);
216 this.addObject("hruler", x, w, aElt);
221 <property name="mScrollX">
224 return EditorUtils.getCurrentEditorElement() ?
225 EditorUtils.getCurrentEditorElement().contentWindow.scrollX :
231 <method name="addObject">
232 <parameter name="aName"/>
233 <parameter name="aPos"/>
234 <parameter name="aSize"/>
235 <parameter name="aSource"/>
241 var svgGroup = this.mSVGGroup;
242 var realRulerSize = this.mHTMLcontainer.clientWidth;
243 var g = document.createElementNS(this.kSVG_NS, "g");
245 var r = document.createElementNS(this.kSVG_NS, "rect")
246 r.setAttribute("x", (100*(aPos-this.mScrollX)/realRulerSize) + "%");
247 r.setAttribute("y", "0");
248 r.setAttribute("width", (100*aSize/realRulerSize) + "%");
249 r.setAttribute("height", "16");
250 r.setAttribute("anonid", "ruler");
251 r.setAttribute("style", "fill: white; stroke-width: 1px; stroke: gray");
253 var lH = document.createElementNS(this.kSVG_NS, "rect")
254 lH.setAttribute("x", (100*(aPos-this.mScrollX)/realRulerSize) + "%");
255 lH.setAttribute("y", "0");
256 lH.setAttribute("width", (100*4/realRulerSize) + "%");
257 lH.setAttribute("height", "16");
258 lH.setAttribute("style", "fill: gray; stroke-width: 1px; stroke: gray; cursor: w-resize");
259 lH.setAttribute("ruler-position", aPos-12);
260 lH.setAttribute("ruler-size", aSize);
261 lH.setAttribute("class", "hruler-separator");
262 lH.setAttribute("ruler-separator-position", "left");
263 lH.setUserData("source", aSource, null);
265 var rH = document.createElementNS(this.kSVG_NS, "rect")
266 rH.setAttribute("x", (100*(aPos+aSize-4-this.mScrollX)/realRulerSize) + "%");
267 rH.setAttribute("y", "0");
268 rH.setAttribute("width", (100*4/realRulerSize) + "%");
269 rH.setAttribute("height", "16");
270 rH.setAttribute("style", "fill: gray; stroke-width: 1px; stroke: gray; cursor: w-resize");
271 rH.setAttribute("ruler-position", aPos-12);
272 rH.setAttribute("ruler-size", aSize);
273 rH.setAttribute("class", "hruler-separator");
274 rH.setAttribute("ruler-separator-position", "right");
275 rH.setUserData("source", aSource, null);
277 var t = document.createElementNS(this.kSVG_NS, "text");
278 t.setAttribute("x", (100*(aPos-this.mScrollX+aSize/2)/realRulerSize) + "%");
279 t.setAttribute("y", "50%");
281 var text = document.createTextNode(aSize + "px");
288 svgGroup.appendChild(g);
296 <stylesheet src="chrome://bluegriffon/skin/rulers.css"/>
300 <handler event="mousedown">
302 var elt = event.originalTarget;
303 if (elt.getAttribute("class") != "hruler-separator")
306 this.mRulerSeparatorPosition = elt.getAttribute("ruler-separator-position");
308 this.mOriginalX = event.clientX;
309 this.mSource = elt.getUserData("source");
310 this.mMarginLeft = parseFloat(this.getComputedStyle(mSource).getPropertyValue("margin-left"));
311 if (!this.mMarginLeft)
312 this.mMarginLeft = 0;
313 this.mWidth = this.mSource.clientWidth;
314 this.mRuleSeparator = elt;
316 this.mResizing = true;
320 <handler event="mousemove">
325 var x = event.clientX;
326 var realRulerSize = this.mHTMLcontainer.clientWidth;
328 switch (this.mRulerSeparatorPosition)
331 this.mRuleSeparator.setAttribute("x",
332 (100*(this.mPos - this.mOriginalX + x - this.mScrollX)/realRulerSize) + "%");
333 // update main ruler element
334 this.mRuleSeparator.parentNode.firstChild
335 .setAttribute("x", (100*(this.mPos - this.mOriginalX + x- this.mScrollX)/realRulerSize) + "%");
336 this.mRuleSeparator.parentNode.firstChild
337 .setAttribute("width", (100*(this.mSize + this.mOriginalX - x)/realRulerSize) + "%");
339 this.mRuleSeparator.parentNode.lastChild
340 .setAttribute("x", (100*((this.mPos - this.mOriginalX + x- this.mScrollX)+(this.mSize + this.mOriginalX - x)/2)/realRulerSize) + "%");
341 this.mRuleSeparator.parentNode.lastChild.firstChild
342 .data = (this.mSize + this.mOriginalX - x) + "px";
345 this.mRuleSeparator.setAttribute("x",
346 (100*(this.mPos - this.mOriginalX + x + this.mSize - 4- this.mScrollX)/realRulerSize) + "%");
347 // update main ruler element
348 this.mRuleSeparator.parentNode.firstChild
349 .setAttribute("width", (100*(this.mSize - this.mOriginalX + x)/realRulerSize) + "%");
351 this.mRuleSeparator.parentNode.lastChild
352 .setAttribute("x", (100*(this.mPos - this.mScrollX + (this.mSize - this.mOriginalX + x)/2)/realRulerSize) + "%");
353 this.mRuleSeparator.parentNode.lastChild.firstChild
354 .data = (this.mSize - this.mOriginalX + x) + "px";
361 <handler event="mouseup">
366 this.mResizing = false;
367 this.mRuleSeparator = null;
369 var x = event.clientX;
370 var realRulerSize = this.mHTMLcontainer.clientWidth;
371 var styleAttrValue = this.mSource.getAttribute("style");
373 styleAttrValue += ";"
376 switch (this.mRulerSeparatorPosition)
379 styleAttrValue += "margin-left: " + (this.mMarginLeft - this.mOriginalX +
381 styleAttrValue += "; width: " + (this.mWidth + this.mOriginalX -
385 styleAttrValue += "width: " + (this.mWidth - this.mOriginalX +
390 EditorUtils.getCurrentEditor()
391 .setAttribute(this.mSource, "style", styleAttrValue);
392 this.selectionChanged(null, this.mSource, null);
400 <binding id="vruler">
404 <html:div style="margin:0;padding: 0; width: 100%!important; height: 100%;">
405 <svg:svg style="width: 16px ! important; height: 98%" viewBox="0 0 16 100"
406 preserveAspectRatio="xMidYMid meet">
408 <svg:text transform="rotate(-90,8,50)" x="50%" y="50%">foo</svg:text>
415 <stylesheet src="chrome://bluegriffon/skin/rulers.css"/>