Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(110)

Side by Side Diff: Source/devtools/front_end/View.js

Issue 197823010: [DevTools] Add minimum size to WebInspector.View. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@splitdip2
Patch Set: width/height -> right/bottom Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 }, 222 },
223 223
224 willHide: function() 224 willHide: function()
225 { 225 {
226 }, 226 },
227 227
228 onResize: function() 228 onResize: function()
229 { 229 {
230 }, 230 },
231 231
232 onLayout: function()
233 {
234 },
235
232 /** 236 /**
233 * @param {?Element} parentElement 237 * @param {?Element} parentElement
234 * @param {!Element=} insertBefore 238 * @param {!Element=} insertBefore
235 */ 239 */
236 show: function(parentElement, insertBefore) 240 show: function(parentElement, insertBefore)
237 { 241 {
238 WebInspector.View._assert(parentElement, "Attempt to attach view with no parent element"); 242 WebInspector.View._assert(parentElement, "Attempt to attach view with no parent element");
239 243
240 // Update view hierarchy 244 // Update view hierarchy
241 if (this.element.parentElement !== parentElement) { 245 if (this.element.parentElement !== parentElement) {
(...skipping 27 matching lines...) Expand all
269 if (insertBefore) 273 if (insertBefore)
270 WebInspector.View._originalInsertBefore.call(parentElement, this .element, insertBefore); 274 WebInspector.View._originalInsertBefore.call(parentElement, this .element, insertBefore);
271 else 275 else
272 WebInspector.View._originalAppendChild.call(parentElement, this. element); 276 WebInspector.View._originalAppendChild.call(parentElement, this. element);
273 } 277 }
274 278
275 if (this._parentIsShowing()) { 279 if (this._parentIsShowing()) {
276 this._processWasShown(); 280 this._processWasShown();
277 this._cacheSize(); 281 this._cacheSize();
278 } 282 }
283
284 if (this._parentView && this._hasNonZeroMinimumSize())
285 this._parentView.invalidateMinimumSize();
279 }, 286 },
280 287
281 /** 288 /**
282 * @param {boolean=} overrideHideOnDetach 289 * @param {boolean=} overrideHideOnDetach
283 */ 290 */
284 detach: function(overrideHideOnDetach) 291 detach: function(overrideHideOnDetach)
285 { 292 {
286 var parentElement = this.element.parentElement; 293 var parentElement = this.element.parentElement;
287 if (!parentElement) 294 if (!parentElement)
288 return; 295 return;
289 296
290 if (this._parentIsShowing()) { 297 if (this._parentIsShowing()) {
291 this._processDiscardCachedSize(); 298 this._processDiscardCachedSize();
292 this._processWillHide(); 299 this._processWillHide();
293 } 300 }
294 301
295 if (this._hideOnDetach && !overrideHideOnDetach) { 302 if (this._hideOnDetach && !overrideHideOnDetach) {
296 this.element.classList.remove("visible"); 303 this.element.classList.remove("visible");
297 this._visible = false; 304 this._visible = false;
298 if (this._parentIsShowing()) 305 if (this._parentIsShowing())
299 this._processWasHidden(); 306 this._processWasHidden();
307 if (this._parentView && this._hasNonZeroMinimumSize())
308 this._parentView.invalidateMinimumSize();
300 return; 309 return;
301 } 310 }
302 311
303 // Force legal removal 312 // Force legal removal
304 WebInspector.View._decrementViewCounter(parentElement, this.element); 313 WebInspector.View._decrementViewCounter(parentElement, this.element);
305 WebInspector.View._originalRemoveChild.call(parentElement, this.element) ; 314 WebInspector.View._originalRemoveChild.call(parentElement, this.element) ;
306 315
307 this._visible = false; 316 this._visible = false;
308 if (this._parentIsShowing()) 317 if (this._parentIsShowing())
309 this._processWasHidden(); 318 this._processWasHidden();
310 319
311 // Update view hierarchy 320 // Update view hierarchy
312 if (this._parentView) { 321 if (this._parentView) {
313 var childIndex = this._parentView._children.indexOf(this); 322 var childIndex = this._parentView._children.indexOf(this);
314 WebInspector.View._assert(childIndex >= 0, "Attempt to remove non-ch ild view"); 323 WebInspector.View._assert(childIndex >= 0, "Attempt to remove non-ch ild view");
315 this._parentView._children.splice(childIndex, 1); 324 this._parentView._children.splice(childIndex, 1);
325 var parent = this._parentView;
316 this._parentView = null; 326 this._parentView = null;
327 if (this._hasNonZeroMinimumSize())
328 parent.invalidateMinimumSize();
317 } else 329 } else
318 WebInspector.View._assert(this._isRoot, "Removing non-root view from DOM"); 330 WebInspector.View._assert(this._isRoot, "Removing non-root view from DOM");
319 }, 331 },
320 332
321 detachChildViews: function() 333 detachChildViews: function()
322 { 334 {
323 var children = this._children.slice(); 335 var children = this._children.slice();
324 for (var i = 0; i < children.length; ++i) 336 for (var i = 0; i < children.length; ++i)
325 children[i].detach(); 337 children[i].detach();
326 }, 338 },
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 { 387 {
376 if (!this.isShowing()) 388 if (!this.isShowing())
377 return; 389 return;
378 this._processDiscardCachedSize(); 390 this._processDiscardCachedSize();
379 // No matter what notification we are in, dispatching onResize is not ne eded. 391 // No matter what notification we are in, dispatching onResize is not ne eded.
380 if (!this._inNotification()) 392 if (!this._inNotification())
381 this._callOnVisibleChildren(this._processOnResize); 393 this._callOnVisibleChildren(this._processOnResize);
382 this._cacheSize(); 394 this._cacheSize();
383 }, 395 },
384 396
397 doLayout: function()
398 {
399 if (!this.isShowing())
400 return;
401 this._notify(this.onLayout);
402 this.doResize();
403 },
404
385 registerRequiredCSS: function(cssFile) 405 registerRequiredCSS: function(cssFile)
386 { 406 {
387 if (window.flattenImports) 407 if (window.flattenImports)
388 cssFile = cssFile.split("/").reverse()[0]; 408 cssFile = cssFile.split("/").reverse()[0];
389 this._cssFiles.push(cssFile); 409 this._cssFiles.push(cssFile);
390 }, 410 },
391 411
392 _loadCSSIfNeeded: function() 412 _loadCSSIfNeeded: function()
393 { 413 {
394 for (var i = 0; i < this._cssFiles.length; ++i) { 414 for (var i = 0; i < this._cssFiles.length; ++i) {
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 this._loadCSSIfNeeded(); 513 this._loadCSSIfNeeded();
494 WebInspector.View._originalAppendChild.call(document.body, this.element) ; 514 WebInspector.View._originalAppendChild.call(document.body, this.element) ;
495 this.element.positionAt(0, 0); 515 this.element.positionAt(0, 0);
496 var result = new Size(this.element.offsetWidth, this.element.offsetHeigh t); 516 var result = new Size(this.element.offsetWidth, this.element.offsetHeigh t);
497 this.element.positionAt(undefined, undefined); 517 this.element.positionAt(undefined, undefined);
498 WebInspector.View._originalRemoveChild.call(document.body, this.element) ; 518 WebInspector.View._originalRemoveChild.call(document.body, this.element) ;
499 this._disableCSSIfNeeded(); 519 this._disableCSSIfNeeded();
500 return result; 520 return result;
501 }, 521 },
502 522
523 /**
524 * @return {!Size}
525 */
526 calculateMinimumSize: function()
527 {
528 return new Size(0, 0);
529 },
530
531 /**
532 * @return {!Size}
533 */
534 minimumSize: function()
535 {
536 if (typeof this._minimumSize !== "undefined")
537 return this._minimumSize;
538 if (typeof this._cachedMinimumSize === "undefined")
539 this._cachedMinimumSize = this.calculateMinimumSize();
540 return this._cachedMinimumSize;
541 },
542
543 /**
544 * @param {number} width
545 * @param {number} height
546 */
547 setMinimumSize: function(width, height)
548 {
549 this._minimumSize = new Size(width, height);
550 this.invalidateMinimumSize();
551 },
552
553 /**
554 * @return {boolean}
555 */
556 _hasNonZeroMinimumSize: function()
557 {
558 var size = this.minimumSize();
559 return size.width || size.height;
560 },
561
562 invalidateMinimumSize: function()
563 {
564 var cached = this._cachedMinimumSize;
565 delete this._cachedMinimumSize;
566 var actual = this.minimumSize();
567 if (!actual.isEqual(cached) && this._parentView)
568 this._parentView.invalidateMinimumSize();
569 else
570 this.doLayout();
571 },
572
503 __proto__: WebInspector.Object.prototype 573 __proto__: WebInspector.Object.prototype
504 } 574 }
505 575
506 WebInspector.View._originalAppendChild = Element.prototype.appendChild; 576 WebInspector.View._originalAppendChild = Element.prototype.appendChild;
507 WebInspector.View._originalInsertBefore = Element.prototype.insertBefore; 577 WebInspector.View._originalInsertBefore = Element.prototype.insertBefore;
508 WebInspector.View._originalRemoveChild = Element.prototype.removeChild; 578 WebInspector.View._originalRemoveChild = Element.prototype.removeChild;
509 WebInspector.View._originalRemoveChildren = Element.prototype.removeChildren; 579 WebInspector.View._originalRemoveChildren = Element.prototype.removeChildren;
510 580
511 WebInspector.View._incrementViewCounter = function(parentElement, childElement) 581 WebInspector.View._incrementViewCounter = function(parentElement, childElement)
512 { 582 {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 * @constructor 614 * @constructor
545 * @extends {WebInspector.View} 615 * @extends {WebInspector.View}
546 */ 616 */
547 WebInspector.VBox = function() 617 WebInspector.VBox = function()
548 { 618 {
549 WebInspector.View.call(this); 619 WebInspector.View.call(this);
550 this.element.classList.add("vbox"); 620 this.element.classList.add("vbox");
551 }; 621 };
552 622
553 WebInspector.VBox.prototype = { 623 WebInspector.VBox.prototype = {
624 /**
625 * @return {!Size}
626 */
627 calculateMinimumSize: function()
vsevik 2014/03/19 16:59:49 We should look at box.minimumSize as well. This i
dgozman 2014/03/19 19:43:49 I'm not sure I understand this comment. We don't h
628 {
629 var width = 0;
630 var height = 0;
631
632 /**
633 * @this {!WebInspector.View}
634 */
635 function updateForChild()
636 {
637 var size = this.minimumSize();
638 width = Math.max(width, size.width);
639 height += size.height;
640 }
641
642 this._callOnVisibleChildren(updateForChild);
643 return new Size(width, height);
644 },
645
554 __proto__: WebInspector.View.prototype 646 __proto__: WebInspector.View.prototype
555 }; 647 };
556 648
557 /** 649 /**
558 * @constructor 650 * @constructor
559 * @extends {WebInspector.View} 651 * @extends {WebInspector.View}
560 */ 652 */
561 WebInspector.HBox = function() 653 WebInspector.HBox = function()
562 { 654 {
563 WebInspector.View.call(this); 655 WebInspector.View.call(this);
564 this.element.classList.add("hbox"); 656 this.element.classList.add("hbox");
565 }; 657 };
566 658
567 WebInspector.HBox.prototype = { 659 WebInspector.HBox.prototype = {
660 /**
661 * @return {!Size}
662 */
663 calculateMinimumSize: function()
664 {
665 var width = 0;
666 var height = 0;
667
668 /**
669 * @this {!WebInspector.View}
670 */
671 function updateForChild()
672 {
673 var size = this.minimumSize();
674 width += size.width;
675 height = Math.max(height, size.height);
676 }
677
678 this._callOnVisibleChildren(updateForChild);
679 return new Size(width, height);
680 },
681
568 __proto__: WebInspector.View.prototype 682 __proto__: WebInspector.View.prototype
569 }; 683 };
570 684
571 /** 685 /**
572 * @constructor 686 * @constructor
573 * @extends {WebInspector.VBox} 687 * @extends {WebInspector.VBox}
574 * @param {function()} resizeCallback 688 * @param {function()} resizeCallback
575 */ 689 */
576 WebInspector.VBoxWithResizeCallback = function(resizeCallback) 690 WebInspector.VBoxWithResizeCallback = function(resizeCallback)
577 { 691 {
(...skipping 27 matching lines...) Expand all
605 { 719 {
606 WebInspector.View._assert(!child.__viewCounter && !child.__view, "Attempt to remove element containing view via regular DOM operation"); 720 WebInspector.View._assert(!child.__viewCounter && !child.__view, "Attempt to remove element containing view via regular DOM operation");
607 return WebInspector.View._originalRemoveChild.call(this, child); 721 return WebInspector.View._originalRemoveChild.call(this, child);
608 } 722 }
609 723
610 Element.prototype.removeChildren = function() 724 Element.prototype.removeChildren = function()
611 { 725 {
612 WebInspector.View._assert(!this.__viewCounter, "Attempt to remove element co ntaining view via regular DOM operation"); 726 WebInspector.View._assert(!this.__viewCounter, "Attempt to remove element co ntaining view via regular DOM operation");
613 WebInspector.View._originalRemoveChildren.call(this); 727 WebInspector.View._originalRemoveChildren.call(this);
614 } 728 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698