2
* Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions
8
* 1. Redistributions of source code must retain the above
9
* copyright notice, this list of conditions and the following
11
* 2. Redistributions in binary form must reproduce the above
12
* copyright notice, this list of conditions and the following
13
* disclaimer in the documentation and/or other materials
14
* provided with the distribution.
16
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
19
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
20
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
21
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
25
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
27
* OF THE POSSIBILITY OF SUCH DAMAGE.
32
* @extends {WebInspector.View}
33
* @param {WebInspector.NamedFlow} flow
35
WebInspector.CSSNamedFlowView = function(flow)
37
WebInspector.View.call(this);
38
this.element.addStyleClass("css-named-flow");
39
this.element.addStyleClass("outline-disclosure");
41
this._treeOutline = new TreeOutline(this.element.createChild("ol"), true);
43
this._contentTreeItem = new TreeElement(WebInspector.UIString("content"), null, true);
44
this._treeOutline.appendChild(this._contentTreeItem);
46
this._regionsTreeItem = new TreeElement(WebInspector.UIString("region chain"), null, true);
47
this._regionsTreeItem.expand();
48
this._treeOutline.appendChild(this._regionsTreeItem);
52
var content = flow.content;
53
for (var i = 0; i < content.length; ++i)
54
this._insertContentNode(content[i]);
56
var regions = flow.regions;
57
for (var i = 0; i < regions.length; ++i)
58
this._insertRegion(regions[i]);
61
WebInspector.CSSNamedFlowView.OversetTypeMessageMap = {
67
WebInspector.CSSNamedFlowView.prototype = {
69
* @param {WebInspector.DOMNode=} rootDOMNode
70
* @return {?WebInspector.ElementsTreeOutline}
72
_createFlowTreeOutline: function(rootDOMNode)
77
var treeOutline = new WebInspector.ElementsTreeOutline(false, false, true);
78
treeOutline.element.addStyleClass("named-flow-element");
79
treeOutline.setVisible(true);
80
treeOutline.rootDOMNode = rootDOMNode;
81
treeOutline.wireToDomAgent();
82
WebInspector.domAgent.removeEventListener(WebInspector.DOMAgent.Events.DocumentUpdated, treeOutline._elementsTreeUpdater._documentUpdated, treeOutline._elementsTreeUpdater);
88
* @param {DOMAgent.NodeId} contentNodeId
89
* @param {number=} index
91
_insertContentNode: function(contentNodeId, index)
93
var treeOutline = this._createFlowTreeOutline(WebInspector.domAgent.nodeForId(contentNodeId));
94
var treeItem = new TreeElement(treeOutline.element, treeOutline);
96
if (index === undefined) {
97
this._contentTreeItem.appendChild(treeItem);
101
this._contentTreeItem.insertChild(treeItem, index);
105
* @param {CSSAgent.Region} region
106
* @param {number=} index
108
_insertRegion: function(region, index)
110
var treeOutline = this._createFlowTreeOutline(WebInspector.domAgent.nodeForId(region.nodeId));
111
treeOutline.element.addStyleClass("region-" + region.regionOverset);
113
var treeItem = new TreeElement(treeOutline.element, treeOutline);
114
var oversetText = WebInspector.UIString(WebInspector.CSSNamedFlowView.OversetTypeMessageMap[region.regionOverset]);
115
treeItem.tooltip = WebInspector.UIString("Region is %s.", oversetText);
117
if (index === undefined) {
118
this._regionsTreeItem.appendChild(treeItem);
122
this._regionsTreeItem.insertChild(treeItem, index);
132
this._update(newFlow);
136
* @param {TreeElement} regionTreeItem
137
* @param {string} newRegionOverset
138
* @param {string} oldRegionOverset
140
_updateRegionOverset: function(regionTreeItem, newRegionOverset, oldRegionOverset)
142
var element = regionTreeItem.representedObject.element;
143
element.removeStyleClass("region-" + oldRegionOverset);
144
element.addStyleClass("region-" + newRegionOverset);
146
var oversetText = WebInspector.UIString(WebInspector.CSSNamedFlowView.OversetTypeMessageMap[newRegionOverset]);
147
regionTreeItem.tooltip = WebInspector.UIString("Region is %s." , oversetText);
151
* @param {Array.<DOMAgent.NodeId>} oldContent
152
* @param {Array.<DOMAgent.NodeId>} newContent
154
_mergeContentNodes: function(oldContent, newContent)
157
for (var i = 0; i < newContent.length; ++i)
158
nodeIdSet[newContent[i]] = true;
160
var oldContentIndex = 0;
161
var newContentIndex = 0;
162
var contentTreeChildIndex = 0;
164
while(oldContentIndex < oldContent.length || newContentIndex < newContent.length) {
165
if (oldContentIndex === oldContent.length) {
166
this._insertContentNode(newContent[newContentIndex]);
171
if (newContentIndex === newContent.length) {
172
this._contentTreeItem.removeChildAtIndex(contentTreeChildIndex);
177
if (oldContent[oldContentIndex] === newContent[newContentIndex]) {
180
++contentTreeChildIndex;
184
if (nodeIdSet[oldContent[oldContentIndex]]) {
185
this._insertContentNode(newContent[newContentIndex], contentTreeChildIndex);
187
++contentTreeChildIndex;
191
this._contentTreeItem.removeChildAtIndex(contentTreeChildIndex);
197
* @param {Array.<CSSAgent.Region>} oldRegions
198
* @param {Array.<CSSAgent.Region>} newRegions
200
_mergeRegions: function(oldRegions, newRegions)
203
for (var i = 0; i < newRegions.length; ++i)
204
nodeIdSet[newRegions[i].nodeId] = true;
206
var oldRegionsIndex = 0;
207
var newRegionsIndex = 0;
208
var regionsTreeChildIndex = 0;
210
while(oldRegionsIndex < oldRegions.length || newRegionsIndex < newRegions.length) {
211
if (oldRegionsIndex === oldRegions.length) {
212
this._insertRegion(newRegions[newRegionsIndex]);
217
if (newRegionsIndex === newRegions.length) {
218
this._regionsTreeItem.removeChildAtIndex(regionsTreeChildIndex);
223
if (oldRegions[oldRegionsIndex].nodeId === newRegions[newRegionsIndex].nodeId) {
224
if (oldRegions[oldRegionsIndex].regionOverset !== newRegions[newRegionsIndex].regionOverset)
225
this._updateRegionOverset(this._regionsTreeItem.children[regionsTreeChildIndex], newRegions[newRegionsIndex].regionOverset, oldRegions[oldRegionsIndex].regionOverset);
228
++regionsTreeChildIndex;
232
if (nodeIdSet[oldRegions[oldRegionsIndex].nodeId]) {
233
this._insertRegion(newRegions[newRegionsIndex], regionsTreeChildIndex);
235
++regionsTreeChildIndex;
239
this._regionsTreeItem.removeChildAtIndex(regionsTreeChildIndex);
245
* @param {WebInspector.NamedFlow} newFlow
247
_update: function(newFlow)
249
this._mergeContentNodes(this._flow.content, newFlow.content);
250
this._mergeRegions(this._flow.regions, newFlow.regions);
252
this._flow = newFlow;
255
__proto__: WebInspector.View.prototype