OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
3 * Copyright (C) 2011 Google Inc. All Rights Reserved. | 3 * Copyright (C) 2011 Google Inc. All Rights Reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 var styleElement = document.createElement("style"); | 60 var styleElement = document.createElement("style"); |
61 styleElement.type = "text/css"; | 61 styleElement.type = "text/css"; |
62 styleElement.textContent = loadResource(cssFile) + WebInspector.View._buildS
ourceURL(cssFile); | 62 styleElement.textContent = loadResource(cssFile) + WebInspector.View._buildS
ourceURL(cssFile); |
63 document.head.insertBefore(styleElement, document.head.firstChild); | 63 document.head.insertBefore(styleElement, document.head.firstChild); |
64 return styleElement; | 64 return styleElement; |
65 } | 65 } |
66 | 66 |
67 WebInspector.View.prototype = { | 67 WebInspector.View.prototype = { |
68 markAsRoot: function() | 68 markAsRoot: function() |
69 { | 69 { |
70 WebInspector.View._assert(!this.element.parentElement, "Attempt to mark
as root attached node"); | 70 WebInspector.View.__assert(!this.element.parentElement, "Attempt to mark
as root attached node"); |
71 this._isRoot = true; | 71 this._isRoot = true; |
72 }, | 72 }, |
73 | 73 |
74 /** | 74 /** |
75 * @return {?WebInspector.View} | 75 * @return {?WebInspector.View} |
76 */ | 76 */ |
77 parentView: function() | 77 parentView: function() |
78 { | 78 { |
79 return this._parentView; | 79 return this._parentView; |
80 }, | 80 }, |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 onLayout: function() | 198 onLayout: function() |
199 { | 199 { |
200 }, | 200 }, |
201 | 201 |
202 /** | 202 /** |
203 * @param {?Element} parentElement | 203 * @param {?Element} parentElement |
204 * @param {?Element=} insertBefore | 204 * @param {?Element=} insertBefore |
205 */ | 205 */ |
206 show: function(parentElement, insertBefore) | 206 show: function(parentElement, insertBefore) |
207 { | 207 { |
208 WebInspector.View._assert(parentElement, "Attempt to attach view with no
parent element"); | 208 WebInspector.View.__assert(parentElement, "Attempt to attach view with n
o parent element"); |
209 | 209 |
210 // Update view hierarchy | 210 // Update view hierarchy |
211 if (this.element.parentElement !== parentElement) { | 211 if (this.element.parentElement !== parentElement) { |
212 if (this.element.parentElement) | 212 if (this.element.parentElement) |
213 this.detach(); | 213 this.detach(); |
214 | 214 |
215 var currentParent = parentElement; | 215 var currentParent = parentElement; |
216 while (currentParent && !currentParent.__view) | 216 while (currentParent && !currentParent.__view) |
217 currentParent = currentParent.parentElement; | 217 currentParent = currentParent.parentElement; |
218 | 218 |
219 if (currentParent) { | 219 if (currentParent) { |
220 this._parentView = currentParent.__view; | 220 this._parentView = currentParent.__view; |
221 this._parentView._children.push(this); | 221 this._parentView._children.push(this); |
222 this._isRoot = false; | 222 this._isRoot = false; |
223 } else | 223 } else |
224 WebInspector.View._assert(this._isRoot, "Attempt to attach view
to orphan node"); | 224 WebInspector.View.__assert(this._isRoot, "Attempt to attach view
to orphan node"); |
225 } else if (this._visible) { | 225 } else if (this._visible) { |
226 return; | 226 return; |
227 } | 227 } |
228 | 228 |
229 this._visible = true; | 229 this._visible = true; |
230 | 230 |
231 if (this._parentIsShowing()) | 231 if (this._parentIsShowing()) |
232 this._processWillShow(); | 232 this._processWillShow(); |
233 | 233 |
234 this.element.classList.add("visible"); | 234 this.element.classList.add("visible"); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 WebInspector.View._decrementViewCounter(parentElement, this.element); | 277 WebInspector.View._decrementViewCounter(parentElement, this.element); |
278 WebInspector.View._originalRemoveChild.call(parentElement, this.element)
; | 278 WebInspector.View._originalRemoveChild.call(parentElement, this.element)
; |
279 | 279 |
280 this._visible = false; | 280 this._visible = false; |
281 if (this._parentIsShowing()) | 281 if (this._parentIsShowing()) |
282 this._processWasHidden(); | 282 this._processWasHidden(); |
283 | 283 |
284 // Update view hierarchy | 284 // Update view hierarchy |
285 if (this._parentView) { | 285 if (this._parentView) { |
286 var childIndex = this._parentView._children.indexOf(this); | 286 var childIndex = this._parentView._children.indexOf(this); |
287 WebInspector.View._assert(childIndex >= 0, "Attempt to remove non-ch
ild view"); | 287 WebInspector.View.__assert(childIndex >= 0, "Attempt to remove non-c
hild view"); |
288 this._parentView._children.splice(childIndex, 1); | 288 this._parentView._children.splice(childIndex, 1); |
289 var parent = this._parentView; | 289 var parent = this._parentView; |
290 this._parentView = null; | 290 this._parentView = null; |
291 if (this._hasNonZeroConstraints()) | 291 if (this._hasNonZeroConstraints()) |
292 parent.invalidateConstraints(); | 292 parent.invalidateConstraints(); |
293 } else | 293 } else |
294 WebInspector.View._assert(this._isRoot, "Removing non-root view from
DOM"); | 294 WebInspector.View.__assert(this._isRoot, "Removing non-root view fro
m DOM"); |
295 }, | 295 }, |
296 | 296 |
297 detachChildViews: function() | 297 detachChildViews: function() |
298 { | 298 { |
299 var children = this._children.slice(); | 299 var children = this._children.slice(); |
300 for (var i = 0; i < children.length; ++i) | 300 for (var i = 0; i < children.length; ++i) |
301 children[i].detach(); | 301 children[i].detach(); |
302 }, | 302 }, |
303 | 303 |
304 /** | 304 /** |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
555 var count = (childElement.__viewCounter || 0) + (childElement.__view ? 1 : 0
); | 555 var count = (childElement.__viewCounter || 0) + (childElement.__view ? 1 : 0
); |
556 if (!count) | 556 if (!count) |
557 return; | 557 return; |
558 | 558 |
559 while (parentElement) { | 559 while (parentElement) { |
560 parentElement.__viewCounter -= count; | 560 parentElement.__viewCounter -= count; |
561 parentElement = parentElement.parentElement; | 561 parentElement = parentElement.parentElement; |
562 } | 562 } |
563 } | 563 } |
564 | 564 |
565 WebInspector.View._assert = function(condition, message) | 565 WebInspector.View.__assert = function(condition, message) |
566 { | 566 { |
567 if (!condition) { | 567 if (!condition) { |
568 console.trace(); | 568 console.trace(); |
569 throw new Error(message); | 569 throw new Error(message); |
570 } | 570 } |
571 } | 571 } |
572 | 572 |
573 /** | 573 /** |
574 * @constructor | 574 * @constructor |
575 * @extends {WebInspector.View} | 575 * @extends {WebInspector.View} |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
662 __proto__: WebInspector.VBox.prototype | 662 __proto__: WebInspector.VBox.prototype |
663 } | 663 } |
664 | 664 |
665 /** | 665 /** |
666 * @param {?Node} child | 666 * @param {?Node} child |
667 * @return {?Node} | 667 * @return {?Node} |
668 * @suppress {duplicate} | 668 * @suppress {duplicate} |
669 */ | 669 */ |
670 Element.prototype.appendChild = function(child) | 670 Element.prototype.appendChild = function(child) |
671 { | 671 { |
672 WebInspector.View._assert(!child.__view || child.parentElement === this, "At
tempt to add view via regular DOM operation."); | 672 WebInspector.View.__assert(!child.__view || child.parentElement === this, "A
ttempt to add view via regular DOM operation."); |
673 return WebInspector.View._originalAppendChild.call(this, child); | 673 return WebInspector.View._originalAppendChild.call(this, child); |
674 } | 674 } |
675 | 675 |
676 /** | 676 /** |
677 * @param {?Node} child | 677 * @param {?Node} child |
678 * @param {?Node} anchor | 678 * @param {?Node} anchor |
679 * @return {!Node} | 679 * @return {!Node} |
680 * @suppress {duplicate} | 680 * @suppress {duplicate} |
681 */ | 681 */ |
682 Element.prototype.insertBefore = function(child, anchor) | 682 Element.prototype.insertBefore = function(child, anchor) |
683 { | 683 { |
684 WebInspector.View._assert(!child.__view || child.parentElement === this, "At
tempt to add view via regular DOM operation."); | 684 WebInspector.View.__assert(!child.__view || child.parentElement === this, "A
ttempt to add view via regular DOM operation."); |
685 return WebInspector.View._originalInsertBefore.call(this, child, anchor); | 685 return WebInspector.View._originalInsertBefore.call(this, child, anchor); |
686 } | 686 } |
687 | 687 |
688 /** | 688 /** |
689 * @param {?Node} child | 689 * @param {?Node} child |
690 * @return {!Node} | 690 * @return {!Node} |
691 * @suppress {duplicate} | 691 * @suppress {duplicate} |
692 */ | 692 */ |
693 Element.prototype.removeChild = function(child) | 693 Element.prototype.removeChild = function(child) |
694 { | 694 { |
695 WebInspector.View._assert(!child.__viewCounter && !child.__view, "Attempt to
remove element containing view via regular DOM operation"); | 695 WebInspector.View.__assert(!child.__viewCounter && !child.__view, "Attempt t
o remove element containing view via regular DOM operation"); |
696 return WebInspector.View._originalRemoveChild.call(this, child); | 696 return WebInspector.View._originalRemoveChild.call(this, child); |
697 } | 697 } |
698 | 698 |
699 Element.prototype.removeChildren = function() | 699 Element.prototype.removeChildren = function() |
700 { | 700 { |
701 WebInspector.View._assert(!this.__viewCounter, "Attempt to remove element co
ntaining view via regular DOM operation"); | 701 WebInspector.View.__assert(!this.__viewCounter, "Attempt to remove element c
ontaining view via regular DOM operation"); |
702 WebInspector.View._originalRemoveChildren.call(this); | 702 WebInspector.View._originalRemoveChildren.call(this); |
703 } | 703 } |
OLD | NEW |