1
/* See license.txt for terms of usage */
3
FBL.ns(function() { with (FBL) {
5
// ************************************************************************************************
7
function LayoutPanel() {}
9
LayoutPanel.prototype = extend(Firebug.Panel,
14
DIV({class: "outerLayoutBox"},
15
DIV({class: "offsetLayoutBox $outerTopMode $outerRightMode $outerBottomMode $outerLeftMode"},
16
DIV({class: "layoutEdgeTop layoutEdge"}),
17
DIV({class: "layoutEdgeRight layoutEdge"}),
18
DIV({class: "layoutEdgeBottom layoutEdge"}),
19
DIV({class: "layoutEdgeLeft layoutEdge"}),
21
DIV({class: "layoutLabelTop layoutLabel v$outerTop"},
22
SPAN({class: "editable"}, '$outerTop')
24
DIV({class: "layoutLabelRight layoutLabel v$outerRight"},
25
SPAN({class: "editable"}, '')
27
DIV({class: "layoutLabelBottom layoutLabel v$outerBottom"},
28
SPAN({class: "editable"}, '')
30
DIV({class: "layoutLabelLeft layoutLabel v$outerLeft"},
31
SPAN({class: "editable"}, '$outerLeft')
34
DIV({class: "layoutCaption"}, '$outerLabel'),
36
DIV({class: "marginLayoutBox layoutBox editGroup"},
37
DIV({class: "layoutCaption"}, $STR("LayoutMargin")),
38
DIV({class: "layoutLabelTop layoutLabel v$marginTop"},
39
SPAN({class: "editable"}, '$marginTop')
41
DIV({class: "layoutLabelRight layoutLabel v$marginRight"},
42
SPAN({class: "editable"}, '$marginRight')
44
DIV({class: "layoutLabelBottom layoutLabel v$marginBottom"},
45
SPAN({class: "editable"}, '$marginBottom')
47
DIV({class: "layoutLabelLeft layoutLabel v$marginLeft"},
48
SPAN({class: "editable"}, '$marginLeft')
51
DIV({class: "borderLayoutBox layoutBox editGroup"},
52
DIV({class: "layoutCaption"}, $STR("LayoutBorder")),
53
DIV({class: "layoutLabelTop layoutLabel v$borderTop"},
54
SPAN({class: "editable"}, '$borderTop')
56
DIV({class: "layoutLabelRight layoutLabel v$borderRight"},
57
SPAN({class: "editable"}, '$borderRight')
59
DIV({class: "layoutLabelBottom layoutLabel v$borderBottom"},
60
SPAN({class: "editable"}, '$borderBottom')
62
DIV({class: "layoutLabelLeft layoutLabel v$borderLeft"},
63
SPAN({class: "editable"}, '$borderLeft')
66
DIV({class: "paddingLayoutBox layoutBox editGroup"},
67
DIV({class: "layoutCaption"}, $STR("LayoutPadding")),
68
DIV({class: "layoutLabelTop layoutLabel v$paddingTop"},
69
SPAN({class: "editable"}, '$paddingTop')
71
DIV({class: "layoutLabelRight layoutLabel v$paddingRight"},
72
SPAN({class: "editable"}, '$paddingRight')
74
DIV({class: "layoutLabelBottom layoutLabel v$paddingBottom"},
75
SPAN({class: "editable"}, '$paddingBottom')
77
DIV({class: "layoutLabelLeft layoutLabel v$paddingLeft"},
78
SPAN({class: "editable"}, '$paddingLeft')
81
DIV({class: "contentLayoutBox layoutBox editGroup"},
82
DIV({class: "layoutLabelCenter layoutLabel"},
83
SPAN({class: "layoutLabelWidth layoutLabel editable"}, '$width'),
85
SPAN({class: "layoutLabelHeight layoutLabel editable"}, '$height')
94
getVerticalText: function(n)
96
return getVerticalText(n);
100
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
102
onMouseOver: function(event)
104
var layoutBox = getAncestorByClass(event.target, "layoutBox");
105
var boxFrame = layoutBox ? getBoxFrame(layoutBox) : null;
107
if (this.highlightedBox)
108
removeClass(this.highlightedBox, "highlighted");
110
this.highlightedBox = layoutBox;
113
setClass(layoutBox, "highlighted");
115
Firebug.Inspector.highlightObject(this.selection, this.context, "boxModel", boxFrame);
118
onMouseOut: function(event)
120
var nextTarget = event.relatedTarget;
121
if (nextTarget && getAncestorByClass(nextTarget, "layoutBox"))
124
if (this.highlightedBox)
125
removeClass(this.highlightedBox, "highlighted");
127
this.highlightedBox = null;
129
Firebug.Inspector.highlightObject(null, null, "boxModel");
132
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
138
initialize: function()
140
this.onMouseOver = bind(this.onMouseOver, this);
141
this.onMouseOut = bind(this.onMouseOut, this);
143
Firebug.Panel.initialize.apply(this, arguments);
146
initializeNode: function(oldPanelNode)
148
this.panelNode.addEventListener("mouseover", this.onMouseOver, false);
149
this.panelNode.addEventListener("mouseout", this.onMouseOut, false);
152
destroyNode: function()
154
this.panelNode.removeEventListener("mouseover", this.onMouseOver, false);
155
this.panelNode.removeEventListener("mouseout", this.onMouseOut, false);
158
supportsObject: function(object)
160
return object instanceof Element ? 1 : 0;
165
this.updateSelection(this.selection);
168
updateSelection: function(element)
170
var view = element ? element.ownerDocument.defaultView : null;
172
return this.panelNode.innerHTML = "";
174
var prev = getPreviousElement(element.previousSibling);
175
var next = getNextElement(element.nextSibling);
177
var style = view.getComputedStyle(element, "");
178
var prevStyle = prev ? view.getComputedStyle(prev, "") : null;
179
var nextStyle = next ? view.getComputedStyle(next, "") : null;
181
function getStyle(st, name) { return parseInt(st.getPropertyCSSValue(name).cssText); }
183
var args = readBoxStyles(style);
184
args.width = element.offsetWidth
185
- (args.paddingLeft+args.paddingRight+args.borderLeft+args.borderRight);
186
args.height = element.offsetHeight
187
- (args.paddingTop+args.paddingBottom+args.borderTop+args.borderBottom);
189
args.outerLeft = args.outerRight = args.outerTop = args.outerBottom = 0;
190
args.outerLeftMode = args.outerRightMode = args.outerTopMode = args.outerBottomMode = "";
192
var position = style.getPropertyCSSValue("position").cssText;
193
if (!Firebug.showAdjacentLayout || position == "absolute" || position == "fixed")
195
args.outerLabel = $STR("LayoutOffset");
196
args.outerLeft = element.offsetLeft;
197
args.outerTop = element.offsetTop;
198
args.outerRight = args.outerBottom = 0;
199
args.outerLeftMode = args.outerRightMode = args.outerTopMode
200
= args.outerBottomMode = "absoluteEdge";
204
var parentStyle = isElement(element.parentNode)
205
? view.getComputedStyle(element.parentNode, "")
210
var display = style.getPropertyCSSValue("display").cssText;
211
if (display == "block")
213
var firstSibling = getNextElement(element.parentNode.firstChild);
214
var lastSibling = getPreviousElement(element.parentNode.lastChild);
216
if (firstSibling == element)
218
args.outerTop = getStyle(parentStyle, "padding-top");
219
args.outerTopMode = "parentTop";
223
args.outerTop = getStyle(prevStyle, "margin-bottom");
224
args.outerTopMode = "siblingTop";
227
if (lastSibling == element)
229
args.outerBottom = getStyle(parentStyle, "padding-bottom");
230
args.outerBottomMode = "parentBottom";
234
args.outerBottom = getStyle(nextStyle, "margin-top");
235
args.outerBottomMode = "siblingBottom";
238
args.outerLeft = getStyle(parentStyle, "padding-left");
239
args.outerLeftMode = "parentLeft";
241
args.outerRight = getStyle(parentStyle, "padding-right");
242
args.outerRightMode = "parentRight";
248
args.outerLeft = getStyle(prevStyle, "margin-right");
249
args.outerLeftMode = "siblingLeft";
253
args.outerLeft = getStyle(parentStyle, "padding-left");
254
args.outerLeftMode = "parentLeft";
259
args.outerRight = getStyle(nextStyle, "margin-left");
260
args.outerRightMode = "siblingRight";
264
args.outerRight = getStyle(parentStyle, "padding-right");
265
args.outerRightMode = "parentRight";
268
args.outerTop = getStyle(parentStyle, "padding-top");
269
args.outerTopMode = "parentTop";
271
args.outerBottom = getStyle(parentStyle, "padding-bottom");
272
args.outerBottomMode = "parentBottom";
275
args.outerLabel = $STR("LayoutAdjacent");
278
args.outerLabel = "";
281
this.template.tag.replace(args, this.panelNode);
284
updateOption: function(name, value)
286
if (name == "showAdjacentLayout")
288
this.updateSelection(this.selection);
292
getOptionsMenuItems: function()
295
optionMenu("ShowRulers", "showRulers"),
299
getEditor: function(target, value)
302
this.editor = new LayoutEditor(this.document);
308
// ************************************************************************************************
311
function LayoutEditor(doc)
313
this.initializeInline(doc);
319
LayoutEditor.prototype = domplate(Firebug.InlineEditor.prototype,
321
saveEdit: function(target, value, previousValue)
323
if (!this.panel.selection.style)
326
var labelBox = getAncestorByClass(target, "layoutLabel");
327
var layoutBox = getLayoutBox(labelBox);
329
var boxFrame = getBoxFrame(layoutBox);
330
var boxEdge = getBoxEdge(labelBox);
333
if (boxFrame == "content" || boxFrame == "offset")
334
styleName = boxEdge.toLowerCase();
335
else if (boxFrame == "border")
336
styleName = boxFrame+boxEdge+"Width";
338
styleName = boxFrame+boxEdge;
340
var intValue = value ? value : 0;
341
this.panel.selection.style[styleName] = intValue + "px";
343
if (Firebug.Inspector.highlightedElement == this.panel.selection)
345
var boxFrame = this.highlightedBox ? getBoxFrame(this.highlightedBox) : null;
346
Firebug.Inspector.highlightObject(this.panel.selection, this.panel.context, "boxModel", boxFrame);
349
if (hasClass(target, "layoutVerticalText"))
350
target.innerHTML = getVerticalText(intValue);
352
target.innerHTML = intValue;
354
if (previousValue == "0" && !!value)
355
removeClass(target.parentNode, "v0");
357
setClass(target.parentNode, "v0");
360
endEditing: function(target, value, cancel)
362
// Don't remove groups
367
// ************************************************************************************************
370
function getLayoutBox(element)
372
var re = /([^\s]+)LayoutBox/;
373
for (var box = element; box; box = box.parentNode)
375
if (re.exec(box.className))
380
function getBoxFrame(element)
382
var re = /([^\s]+)LayoutBox/;
383
var m = re.exec(element.className);
384
return m ? m[1] : "";
387
function getBoxEdge(element)
389
var re = /layoutLabel([^\s]+)/;
390
var m = re.exec(element.className);
391
return m ? m[1] : "";
394
function getVerticalText(n)
398
for (var i = 0; i < n.length; ++i)
400
return text.join("<br>");
403
// ************************************************************************************************
405
Firebug.registerPanel(LayoutPanel);
407
// ************************************************************************************************