/
htmlPanel.js
2859 lines (2438 loc) · 92.8 KB
/
htmlPanel.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
define([
"firebug/lib/object",
"firebug/firebug",
"firebug/lib/domplate",
"firebug/chrome/reps",
"firebug/lib/locale",
"firebug/html/htmlLib",
"firebug/lib/events",
"firebug/js/sourceLink",
"firebug/lib/css",
"firebug/lib/dom",
"firebug/chrome/window",
"firebug/lib/options",
"firebug/lib/xpath",
"firebug/lib/string",
"firebug/lib/xml",
"firebug/lib/array",
"firebug/lib/persist",
"firebug/chrome/menu",
"firebug/lib/url",
"firebug/css/cssReps",
"firebug/js/breakpoint",
"firebug/editor/editor",
"firebug/chrome/searchBox",
"firebug/html/insideOutBox",
"firebug/html/inspector",
"firebug/html/layout"
],
function(Obj, Firebug, Domplate, FirebugReps, Locale, HTMLLib, Events,
SourceLink, Css, Dom, Win, Options, Xpath, Str, Xml, Arr, Persist, Menu,
Url, CSSInfoTip) {
with (Domplate) {
// ********************************************************************************************* //
// Constants
const Cc = Components.classes;
const Ci = Components.interfaces;
const MODIFICATION = window.MutationEvent.MODIFICATION;
const ADDITION = window.MutationEvent.ADDITION;
const REMOVAL = window.MutationEvent.REMOVAL;
const BP_BREAKONATTRCHANGE = 1;
const BP_BREAKONCHILDCHANGE = 2;
const BP_BREAKONREMOVE = 3;
const BP_BREAKONTEXT = 4;
var KeyEvent = window.KeyEvent;
// ********************************************************************************************* //
Firebug.HTMLModule = Obj.extend(Firebug.Module,
{
dispatchName: "htmlModule",
initialize: function(prefDomain, prefNames)
{
Firebug.Module.initialize.apply(this, arguments);
Firebug.connection.addListener(this.DebuggerListener);
},
shutdown: function()
{
Firebug.Module.shutdown.apply(this, arguments);
Firebug.connection.removeListener(this.DebuggerListener);
},
initContext: function(context, persistedState)
{
Firebug.Module.initContext.apply(this, arguments);
context.mutationBreakpoints = new MutationBreakpointGroup();
},
loadedContext: function(context, persistedState)
{
context.mutationBreakpoints.load(context);
// If there are mutation breakpoints, make sure the HTML panel
// is automatically created and mutation listeners registered.
// Mutation breakpoints should work even if the HTML panel has
// never been selected by the user since the page load.
if (!context.mutationBreakpoints.isEmpty())
{
var panel = context.getPanel("html");
panel.registerMutationListeners();
}
},
destroyContext: function(context, persistedState)
{
Firebug.Module.destroyContext.apply(this, arguments);
context.mutationBreakpoints.store(context);
},
deleteNode: function(node, context)
{
Events.dispatch(this.fbListeners, "onBeginFirebugChange", [node, context]);
node.parentNode.removeChild(node);
Events.dispatch(this.fbListeners, "onEndFirebugChange", [node, context]);
},
deleteAttribute: function(node, attr, context)
{
Events.dispatch(this.fbListeners, "onBeginFirebugChange", [node, context]);
node.removeAttribute(attr);
Events.dispatch(this.fbListeners, "onEndFirebugChange", [node, context]);
}
});
// ********************************************************************************************* //
Firebug.HTMLPanel = function() {};
var WalkingPanel = Obj.extend(Firebug.Panel, HTMLLib.ElementWalkerFunctions);
Firebug.HTMLPanel.prototype = Obj.extend(WalkingPanel,
{
inspectable: true,
toggleEditing: function()
{
if (this.editing)
this.stopEditing();
else
this.editNode(this.selection);
},
stopEditing: function()
{
Firebug.Editor.stopEditing();
if (!this.selection.parentNode)
{
Firebug.chrome.clearStatusPath();
// nextSelection is set in mutation handlers. When the editing mode stops
// this variable (if set) will be used as the next selected node, effectivelly
// replacing the old selected node that doesn't have to exit any more (after
// the editing).
// If nextSelection is not set a default node (e.g. body) will be selected.
// See issue 5506
this.select(this.nextSelection, true);
delete this.nextSelection;
}
},
isEditing: function()
{
var editButton = Firebug.chrome.$("fbToggleHTMLEditing");
return (this.editing && editButton.getAttribute("checked") === "true");
},
resetSearch: function()
{
delete this.lastSearch;
},
select: function(object, forceUpdate)
{
if (!object)
object = this.getDefaultSelection();
if (FBTrace.DBG_PANELS)
{
FBTrace.sysout("firebug.select " + this.name + " forceUpdate: " + forceUpdate + " " +
object + ((object == this.selection) ? "==" : "!=") + this.selection);
}
if (forceUpdate || object != this.selection)
{
this.selection = object;
this.updateSelection(object);
// The Edit button (in the toolbar) must be updated every time the selection
// changes. Some elements (such as <html>) can't be edited (see issue 5506).
var edit = Firebug.chrome.$("fbToggleHTMLEditing");
edit.disabled = object ? Css.nonEditableTags.hasOwnProperty(object.localName) : false;
// Distribute selection change further to listeners.
Events.dispatch(Firebug.uiListeners, "onObjectSelected", [object, this]);
// If the 'free text' edit mode is active change the current markup
// displayed in the editor (textarea) so, it corresponds to the current
// selection. This typically happens when the user click on object-status-path
// buttons in the toolbar.
if (this.isEditing())
this.editNode(object);
}
},
selectNext: function()
{
var objectBox = this.ioBox.createObjectBox(this.selection);
var next = this.ioBox.getNextObjectBox(objectBox);
if (next)
{
this.select(next.repObject);
if (Firebug.Inspector.inspecting)
Firebug.Inspector.inspectNode(next.repObject);
}
},
selectPrevious: function()
{
var objectBox = this.ioBox.createObjectBox(this.selection);
var previous = this.ioBox.getPreviousObjectBox(objectBox);
if (previous)
{
this.select(previous.repObject);
if (Firebug.Inspector.inspecting)
Firebug.Inspector.inspectNode(previous.repObject);
}
},
selectNodeBy: function(dir)
{
if (dir == "up")
{
this.selectPrevious();
}
else if (dir == "down")
{
this.selectNext();
}
else if (dir == "left")
{
var box = this.ioBox.createObjectBox(this.selection);
if (!Css.hasClass(box, "open"))
this.select(this.ioBox.getParentObjectBox(box).repObject);
else
this.ioBox.contractObject(this.selection);
}
else if (dir == "right")
{
var box = this.ioBox.createObjectBox(this.selection);
if (!Css.hasClass(box, "open"))
this.ioBox.expandObject(this.selection);
else
this.selectNext();
}
Firebug.Inspector.highlightObject(this.selection, this.context);
},
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
editNewAttribute: function(elt)
{
var objectNodeBox = this.ioBox.findObjectBox(elt);
if (objectNodeBox)
{
var labelBox = objectNodeBox.querySelector("*> .nodeLabel > .nodeLabelBox");
var bracketBox = labelBox.querySelector("*> .nodeBracket");
Firebug.Editor.insertRow(bracketBox, "before");
}
},
editAttribute: function(elt, attrName)
{
var objectNodeBox = this.ioBox.findObjectBox(elt);
if (objectNodeBox)
{
var attrBox = HTMLLib.findNodeAttrBox(objectNodeBox, attrName);
if (attrBox)
{
var attrValueBox = attrBox.childNodes[3];
var value = elt.getAttribute(attrName);
Firebug.Editor.startEditing(attrValueBox, value);
}
}
},
deleteAttribute: function(elt, attrName)
{
Firebug.HTMLModule.deleteAttribute(elt, attrName, this.context);
},
localEditors:{}, // instantiated editor cache
editNode: function(node)
{
var objectNodeBox = this.ioBox.findObjectBox(node);
if (objectNodeBox)
{
var type = Xml.getElementType(node);
var editor = this.localEditors[type];
if (!editor)
{
// look for special purpose editor (inserted by an extension),
// otherwise use our html editor
var specializedEditor = Firebug.HTMLPanel.Editors[type] ||
Firebug.HTMLPanel.Editors["html"];
editor = this.localEditors[type] = new specializedEditor(this.document);
}
this.startEditingNode(node, objectNodeBox, editor, type);
}
},
startEditingNode: function(node, box, editor, type)
{
switch (type)
{
case "html":
case "xhtml":
this.startEditingHTMLNode(node, box, editor);
break;
default:
this.startEditingXMLNode(node, box, editor);
}
},
startEditingXMLNode: function(node, box, editor)
{
var xml = Xml.getElementXML(node);
Firebug.Editor.startEditing(box, xml, editor);
},
startEditingHTMLNode: function(node, box, editor)
{
if (Css.nonEditableTags.hasOwnProperty(node.localName))
return;
editor.innerEditMode = node.localName in Css.innerEditableTags;
var html = editor.innerEditMode ? node.innerHTML : Xml.getElementHTML(node);
Firebug.Editor.startEditing(box, html, editor);
},
deleteNode: function(node, dir)
{
dir = dir || "up";
var box = this.ioBox.createObjectBox(node);
if (Css.hasClass(box, "open"))
this.ioBox.contractObject(this.selection);
this.selectNodeBy(dir);
Firebug.HTMLModule.deleteNode(node, this.context);
},
toggleAll: function(event, node)
{
var expandExternalContentNodes = Events.isShift(event);
this.ioBox.toggleObject(node, true, expandExternalContentNodes ?
null : ["link", "script", "style"]);
},
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
getElementSourceText: function(node)
{
if (this.sourceElements)
{
var index = this.sourceElementNodes.indexOf(node);
if (index != -1)
return this.sourceElements[index];
}
var lines;
var url = HTMLLib.getSourceHref(node);
if (url)
{
lines = this.context.sourceCache.load(url);
}
else
{
var text = HTMLLib.getSourceText(node);
lines = Str.splitLines(text);
}
var sourceElt = new Firebug.HTMLModule.SourceText(lines, node);
if (!this.sourceElements)
{
this.sourceElements = [sourceElt];
this.sourceElementNodes = [node];
}
else
{
this.sourceElements.push(sourceElt);
this.sourceElementNodes.push(node);
}
return sourceElt;
},
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
registerMutationListeners: function(win)
{
if (this.context.attachedMutation)
return;
this.context.attachedMutation = true;
var self = this;
function addListeners(win)
{
var doc = win.document;
// xxxHonza: an iframe doesn't have to be loaded yet so, do not
// register mutation elements in such cases since they wouldn't
// be removed.
// The listeners can be registered later in watchWindowDelayed,
// but it's also risky. Mutation listeners should be registered
// at the moment when it's clear that the window/frame has been
// loaded.
if (doc.location == "about:blank")
return;
Events.addEventListener(doc, "DOMAttrModified", self.onMutateAttr, false);
Events.addEventListener(doc, "DOMCharacterDataModified", self.onMutateText, false);
Events.addEventListener(doc, "DOMNodeInserted", self.onMutateNode, false);
Events.addEventListener(doc, "DOMNodeRemoved", self.onMutateNode, false);
}
// If a window is specified use it, otherwise register listeners for all
// context windows (including the main window and all embedded iframes).
if (win)
addListeners(win);
else
Win.iterateWindows(this.context.window, addListeners);
},
unregisterMutationListeners: function(win)
{
var self = this;
function removeListeners(win)
{
var doc = win.document;
Events.removeEventListener(doc, "DOMAttrModified", self.onMutateAttr, false);
Events.removeEventListener(doc, "DOMCharacterDataModified", self.onMutateText, false);
Events.removeEventListener(doc, "DOMNodeInserted", self.onMutateNode, false);
Events.removeEventListener(doc, "DOMNodeRemoved", self.onMutateNode, false);
}
if (win)
removeListeners(win);
else
Win.iterateWindows(this.context.window, removeListeners);
},
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
mutateAttr: function(target, attrChange, attrName, attrValue)
{
// Every time the user scrolls we get this pointless mutation event, which
// is only bad for performance
if (attrName == "curpos")
return;
// Due to the delay call this may or may not exist in the tree anymore
if (!this.ioBox.isInExistingRoot(target))
{
if (FBTrace.DBG_HTML)
FBTrace.sysout("mutateAttr: different tree " + target, target);
return;
}
if (FBTrace.DBG_HTML)
{
FBTrace.sysout("html.mutateAttr target:"+target+" attrChange:"+attrChange+
" attrName:"+attrName+" attrValue: "+attrValue, target);
}
this.markChange();
var objectNodeBox = Firebug.scrollToMutations || Firebug.expandMutations ?
this.ioBox.createObjectBox(target) : this.ioBox.findObjectBox(target);
if (!objectNodeBox)
return;
if (Xml.isVisible(objectNodeBox.repObject))
Css.removeClass(objectNodeBox, "nodeHidden");
else
Css.setClass(objectNodeBox, "nodeHidden");
if (attrChange == MODIFICATION || attrChange == ADDITION)
{
var nodeAttr = HTMLLib.findNodeAttrBox(objectNodeBox, attrName);
if (FBTrace.DBG_HTML)
FBTrace.sysout("mutateAttr " + attrChange + " " + attrName + "=" + attrValue +
" node: " + nodeAttr, nodeAttr);
if (nodeAttr && nodeAttr.childNodes.length > 3)
{
var attrValueBox = nodeAttr.querySelector("*> .nodeValue");
var attrValueText = attrValueBox.firstChild;
if (attrValueText)
attrValueText.nodeValue = attrValue;
else
attrValueBox.innerHTML = Str.escapeForTextNode(attrValue);
this.highlightMutation(attrValueBox, objectNodeBox, "mutated");
}
else
{
var attr = target.getAttributeNode(attrName);
if (FBTrace.DBG_HTML)
FBTrace.sysout("mutateAttr getAttributeNode " + attrChange + " " + attrName +
"=" + attrValue + " node: " + attr, attr);
if (attr)
{
var nodeAttr = Firebug.HTMLPanel.AttrNode.tag.replace({attr: attr},
this.document);
var labelBox = objectNodeBox.querySelector("*> .nodeLabel > .nodeLabelBox");
var bracketBox = labelBox.querySelector("*> .nodeBracket");
labelBox.insertBefore(nodeAttr, bracketBox);
this.highlightMutation(nodeAttr, objectNodeBox, "mutated");
}
}
}
else if (attrChange == REMOVAL)
{
var nodeAttr = HTMLLib.findNodeAttrBox(objectNodeBox, attrName);
if (nodeAttr)
nodeAttr.parentNode.removeChild(nodeAttr);
// We want to highlight regardless as the domplate may have been
// generated after the attribute was removed from the node
this.highlightMutation(objectNodeBox, objectNodeBox, "mutated");
}
Firebug.Inspector.repaint();
},
mutateText: function(target, parent, textValue)
{
// Due to the delay call this may or may not exist in the tree anymore
if (!this.ioBox.isInExistingRoot(target))
{
if (FBTrace.DBG_HTML)
FBTrace.sysout("mutateText: different tree " + target, target);
return;
}
this.markChange();
var parentNodeBox = Firebug.scrollToMutations || Firebug.expandMutations ?
this.ioBox.createObjectBox(parent) : this.ioBox.findObjectBox(parent);
if (!parentNodeBox)
{
if (FBTrace.DBG_HTML)
FBTrace.sysout("html.mutateText failed to update text, parent node " +
"box does not exist");
return;
}
if (!Firebug.showFullTextNodes)
textValue = Str.cropMultipleLines(textValue);
var parentTag = getNodeBoxTag(parentNodeBox);
if (parentTag == Firebug.HTMLPanel.TextElement.tag)
{
if (FBTrace.DBG_HTML)
FBTrace.sysout("html.mutateText target: " + target + " parent: " + parent);
// Rerender the entire parentNodeBox. Proper entity-display logic will
// be automatically applied according to the preferences.
var newParentNodeBox = parentTag.replace({object: parentNodeBox.repObject}, this.document);
if (parentNodeBox.parentNode)
parentNodeBox.parentNode.replaceChild(newParentNodeBox, parentNodeBox);
// Reselect if the element was selected before.
if (this.selection && (!this.selection.parentNode || parent == this.selection))
this.ioBox.select(parent, true);
var nodeText = HTMLLib.getTextElementTextBox(newParentNodeBox);
if (!nodeText.firstChild)
{
if (FBTrace.DBG_HTML)
{
FBTrace.sysout("html.mutateText failed to update text, " +
"TextElement firstChild does not exist");
}
return;
}
// Highlight the text box only (not the entire parentNodeBox/element).
this.highlightMutation(nodeText, newParentNodeBox, "mutated");
}
else
{
var childBox = this.ioBox.getChildObjectBox(parentNodeBox);
if (!childBox)
{
if (FBTrace.DBG_HTML)
{
FBTrace.sysout("html.mutateText failed to update text, " +
"no child object box found");
}
return;
}
var textNodeBox = this.ioBox.findChildObjectBox(childBox, target);
if (textNodeBox)
{
// structure for comment and cdata. Are there others?
textNodeBox.firstChild.firstChild.nodeValue = textValue;
this.highlightMutation(textNodeBox, parentNodeBox, "mutated");
}
else if (Firebug.scrollToMutations || Firebug.expandMutations)
{
// We are not currently rendered but we are set to highlight
var objectBox = this.ioBox.createObjectBox(target);
this.highlightMutation(objectBox, objectBox, "mutated");
}
}
},
mutateNode: function(target, parent, nextSibling, removal)
{
if (FBTrace.DBG_HTML)
FBTrace.sysout("html.mutateNode target:" + target + " parent:" + parent +
(removal ? "REMOVE" : ""));
// Due to the delay call this may or may not exist in the tree anymore
if (!removal && !this.ioBox.isInExistingRoot(target))
{
if (FBTrace.DBG_HTML)
FBTrace.sysout("mutateNode: different tree " + target, target);
return;
}
this.markChange(); // This invalidates the panels for every mutate
var parentNodeBox = Firebug.scrollToMutations || Firebug.expandMutations
? this.ioBox.createObjectBox(parent)
: this.ioBox.findObjectBox(parent);
if (FBTrace.DBG_HTML)
FBTrace.sysout("html.mutateNode parent:" + parent + " parentNodeBox:" +
parentNodeBox);
if (!parentNodeBox)
return;
if (!Firebug.showTextNodesWithWhitespace && this.isWhitespaceText(target))
return;
// target is only whitespace
var newParentTag = getNodeTag(parent);
var oldParentTag = getNodeBoxTag(parentNodeBox);
if (newParentTag == oldParentTag)
{
if (parentNodeBox.populated)
{
if (removal)
{
this.ioBox.removeChildBox(parentNodeBox, target);
this.highlightMutation(parentNodeBox, parentNodeBox, "mutated");
}
else
{
var childBox = this.ioBox.getChildObjectBox(parentNodeBox);
var comments = Firebug.showCommentNodes;
var whitespaces = Firebug.showTextNodesWithWhitespace;
// Get the right next sibling that match following criteria:
// 1) It's not a whitespace text node in case 'show whitespaces' is false.
// 2) It's not a comment in case 'show comments' is false.
// 3) There is a child box already created for it in the HTML panel UI so,
// the new one can be inserted before, otherwise it would be appended
// at the end (issue 5255)
while (nextSibling && (
(!whitespaces && HTMLLib.isWhitespaceText(nextSibling)) ||
(!comments && nextSibling instanceof window.Comment) ||
(!this.ioBox.findChildObjectBox(childBox, nextSibling))))
{
nextSibling = this.findNextSibling(nextSibling);
}
var objectBox = nextSibling ?
this.ioBox.insertChildBoxBefore(parentNodeBox, target, nextSibling) :
this.ioBox.appendChildBox(parentNodeBox, target);
if (this.selection && (!this.selection.parentNode || parent == this.selection))
{
// If the editing mode is currently active, remembe the target mutation.
// The mutation is coming from user changes and will be selected as soon
// as the editing mode is finished. Only HTMLElement can be selected
// (not a simple text node)
// See issue 5506
if (this.isEditing() && (target instanceof window.HTMLElement))
this.nextSelection = target;
}
this.highlightMutation(objectBox, objectBox, "mutated");
}
}
else // !parentNodeBox.populated
{
var newParentNodeBox = newParentTag.replace({object: parent}, this.document);
parentNodeBox.parentNode.replaceChild(newParentNodeBox, parentNodeBox);
if (this.selection && (!this.selection.parentNode || parent == this.selection))
this.ioBox.select(parent, true);
this.highlightMutation(newParentNodeBox, newParentNodeBox, "mutated");
if (!removal && (Firebug.scrollToMutations || Firebug.expandMutations))
{
var objectBox = this.ioBox.createObjectBox(target);
this.highlightMutation(objectBox, objectBox, "mutated");
}
}
}
else // newParentTag != oldParentTag
{
var newParentNodeBox = newParentTag.replace({object: parent}, this.document);
if (parentNodeBox.parentNode)
parentNodeBox.parentNode.replaceChild(newParentNodeBox, parentNodeBox);
if (Css.hasClass(parentNodeBox, "open"))
this.ioBox.toggleObjectBox(newParentNodeBox, true);
if (this.selection && (!this.selection.parentNode || parent == this.selection))
this.ioBox.select(parent, true);
this.highlightMutation(newParentNodeBox, newParentNodeBox, "mutated");
if (!removal && (Firebug.scrollToMutations || Firebug.expandMutations))
{
var objectBox = this.ioBox.createObjectBox(target);
this.highlightMutation(objectBox, objectBox, "mutated");
}
}
},
highlightMutation: function(elt, objectBox, type)
{
if (FBTrace.DBG_HTML)
FBTrace.sysout("html.highlightMutation Firebug.highlightMutations:" +
Firebug.highlightMutations, {elt: elt, objectBox: objectBox, type: type});
if (!elt)
return;
if (Firebug.scrollToMutations || Firebug.expandMutations)
{
if (this.context.mutationTimeout)
{
this.context.clearTimeout(this.context.mutationTimeout);
delete this.context.mutationTimeout;
}
var ioBox = this.ioBox;
var panelNode = this.panelNode;
this.context.mutationTimeout = this.context.setTimeout(function()
{
ioBox.openObjectBox(objectBox);
if (Firebug.scrollToMutations)
Dom.scrollIntoCenterView(objectBox, panelNode);
}, 200);
}
if (Firebug.highlightMutations)
Css.setClassTimed(elt, type, this.context);
},
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// InsideOutBoxView implementation
createObjectBox: function(object, isRoot)
{
if (FBTrace.DBG_HTML)
{
FBTrace.sysout("html.createObjectBox(" + Css.getElementCSSSelector(object) +
", isRoot:" + (isRoot? "true" : "false")+")");
}
var tag = getNodeTag(object);
if (tag)
return tag.replace({object: object}, this.document);
},
getParentObject: function(node)
{
if (node instanceof Firebug.HTMLModule.SourceText)
return node.owner;
var parentNode = this.getParentNode(node);
// for chromebug to avoid climbing out to browser.xul
if (node.nodeName == "#document")
return null;
//if (FBTrace.DBG_HTML)
// FBTrace.sysout("html.getParentObject for "+node.nodeName+" parentNode:"+
// Css.getElementCSSSelector(parentNode));
if (parentNode)
{
if (parentNode.nodeType == 9) // then parentNode is Document element
{
if (parentNode.defaultView)
{
if (parentNode.defaultView == this.context.window)
return parentNode;
if (FBTrace.DBG_HTML)
{
FBTrace.sysout("getParentObject parentNode.nodeType 9, frameElement:"+
parentNode.defaultView.frameElement);
}
return parentNode.defaultView.frameElement;
}
else
{
var skipParent = this.getEmbedConnection(parentNode);
if (FBTrace.DBG_HTML)
FBTrace.sysout("getParentObject skipParent:" +
(skipParent ? skipParent.nodeName : "none"));
if (skipParent)
return skipParent;
else
return null; // parent is document element, but no window at defaultView.
}
}
else if (!parentNode.localName)
{
if (FBTrace.DBG_HTML)
FBTrace.sysout("getParentObject: null localName must be window, no parentObject");
return null;
}
else
{
return parentNode;
}
}
else
{
// Documents have no parentNode; Attr, Document, DocumentFragment, Entity,
// and Notation. top level windows have no parentNode
if (node && node.nodeType == 9) // document type
{
// generally a reference to the window object for the document, however
// that is not defined in the specification
if (node.defaultView)
{
var embeddingFrame = node.defaultView.frameElement;
if (embeddingFrame)
return embeddingFrame.contentDocument;
}
else
{
// a Document object without a parentNode or window
return null; // top level has no parent
}
}
}
},
setEmbedConnection: function(node, skipChild)
{
if (!this.embeddedBrowserParents)
{
this.embeddedBrowserParents = [];
this.embeddedBrowserDocument = [];
}
this.embeddedBrowserDocument.push(skipChild);
// store our adopted child in a side table
this.embeddedBrowserParents.push(node);
if (FBTrace.DBG_HTML)
FBTrace.sysout("Found skipChild " + Css.getElementCSSSelector(skipChild) +
" for " + Css.getElementCSSSelector(node) + " with node.contentDocument " +
node.contentDocument);
return skipChild;
},
getEmbedConnection: function(node)
{
if (this.embeddedBrowserParents)
{
var index = this.embeddedBrowserParents.indexOf(node);
if (index !== -1)
return this.embeddedBrowserDocument[index];
}
},
/**
* @param: node a DOM node from the Web page
* @param: index counter for important children, may skip whitespace
* @param: previousSibling a node from the web page
*/
getChildObject: function(node, index, previousSibling)
{
if (!node)
{
FBTrace.sysout("getChildObject: null node");
return;
}
if (FBTrace.DBG_HTML)
FBTrace.sysout("getChildObject " + node.tagName + " index " + index +
" previousSibling: " +
(previousSibling ? Css.getElementCSSSelector(previousSibling) : "null"),
{node: node, previousSibling:previousSibling});
if (this.isSourceElement(node))
{
if (index == 0)
return this.getElementSourceText(node);
else
return null; // no siblings of source elements
}
else if (node instanceof window.Document)
{
if (previousSibling !== null)
return this.getNextSibling(previousSibling);
else
return this.getFirstChild(node);
}
else if (node.contentDocument) // then the node is a frame
{
if (index == 0)
{
// punch thru and adopt the root element as our child
var skipChild = node.contentDocument.documentElement;
// (the node's).(type 9 document).(HTMLElement)
return this.setEmbedConnection(node, skipChild);
}
else if (previousSibling)
{
// Next child of a document (after doc-type) is <html>.
return this.getNextSibling(previousSibling);
}
}
else if (node.getSVGDocument && node.getSVGDocument()) // then the node is a frame
{
if (index == 0)
{
var skipChild = node.getSVGDocument().documentElement; // unwrap
// (the node's).(type 9 document).(HTMLElement)
return this.setEmbedConnection(node, skipChild);
}
else
{
return null;
}
}
var child;
if (previousSibling) // then we are walking
child = this.getNextSibling(previousSibling); // may return null, meaning done with iteration.
else
child = this.getFirstChild(node); // child is set to at the beginning of an iteration.
if (FBTrace.DBG_HTML)
FBTrace.sysout("getChildObject firstChild " + Css.getElementCSSSelector(child) +
" with Firebug.showTextNodesWithWhitespace " +
Firebug.showTextNodesWithWhitespace);
if (Firebug.showTextNodesWithWhitespace) // then the index is true to the node list
{
return child;
}
else
{
for (; child; child = this.getNextSibling(child))
{
if (!this.isWhitespaceText(child))
return child;
}
}
return null; // we have no children worth showing.
},
isWhitespaceText: function(node)
{
return HTMLLib.isWhitespaceText(node);
},