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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/ui/Widget.js

Issue 2570633004: DevTools: remove invalidateSize from Widget, make show/hideWidget receive no params. (Closed)
Patch Set: rebaselined Created 4 years 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
« no previous file with comments | « third_party/WebKit/Source/devtools/front_end/ui/TabbedPane.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 */ 251 */
252 show(parentElement, insertBefore) { 252 show(parentElement, insertBefore) {
253 UI.Widget.__assert(parentElement, 'Attempt to attach widget with no parent e lement'); 253 UI.Widget.__assert(parentElement, 'Attempt to attach widget with no parent e lement');
254 254
255 if (!this._isRoot) { 255 if (!this._isRoot) {
256 // Update widget hierarchy. 256 // Update widget hierarchy.
257 var currentParent = parentElement; 257 var currentParent = parentElement;
258 while (currentParent && !currentParent.__widget) 258 while (currentParent && !currentParent.__widget)
259 currentParent = currentParent.parentElementOrShadowHost(); 259 currentParent = currentParent.parentElementOrShadowHost();
260 UI.Widget.__assert(currentParent, 'Attempt to attach widget to orphan node '); 260 UI.Widget.__assert(currentParent, 'Attempt to attach widget to orphan node ');
261 this.attach(currentParent.__widget); 261 this.attach(currentParent.__widget, parentElement, insertBefore);
262 } else {
263 this._attachedToParentElement = parentElement;
264 this._attachedBeforeElement = insertBefore;
262 } 265 }
263 266
264 this.showWidget(parentElement, insertBefore); 267 this.showWidget();
265 } 268 }
266 269
267 /** 270 /**
268 * @param {!UI.Widget} parentWidget 271 * @param {!UI.Widget} parentWidget
272 * @param {!Element} parentElement
273 * @param {?Element=} insertBefore
269 */ 274 */
270 attach(parentWidget) { 275 attach(parentWidget, parentElement, insertBefore) {
caseq 2016/12/14 01:29:26 Let's avoid exposing this to the public interface,
pfeldman 2016/12/14 01:38:40 Done.
271 if (parentWidget === this._parentWidget) 276 if (parentWidget === this._parentWidget) {
277 this._attachedToParentElement = parentElement;
278 this._attachedBeforeElement = insertBefore;
caseq 2016/12/14 01:29:25 s/Element/Node?
pfeldman 2016/12/14 01:38:40 Done.
279 if (this._visible)
280 this.showWidget();
272 return; 281 return;
282 }
273 if (this._parentWidget) 283 if (this._parentWidget)
274 this.detach(); 284 this.detach();
275 this._parentWidget = parentWidget; 285 this._parentWidget = parentWidget;
276 this._parentWidget._children.push(this); 286 this._parentWidget._children.push(this);
287 this._attachedToParentElement = parentElement;
288 this._attachedBeforeElement = insertBefore;
277 this._isRoot = false; 289 this._isRoot = false;
278 } 290 }
279 291
280 /** 292 showWidget() {
281 * @param {!Element} parentElement 293 UI.Widget.__assert(this._parentWidget || this._isRoot, 'Attempt to show widg et that has not been attached');
282 * @param {?Element=} insertBefore 294 var parentElement = this._attachedToParentElement;
283 */ 295 var insertBefore = this._attachedBeforeElement;
caseq 2016/12/14 01:29:26 Add a check that the element is not gone?
pfeldman 2016/12/14 01:38:40 Browser would throw if something like that happens
284 showWidget(parentElement, insertBefore) { 296
285 var currentParent = parentElement; 297 var currentParent = parentElement;
286 while (currentParent && !currentParent.__widget) 298 while (currentParent && !currentParent.__widget)
287 currentParent = currentParent.parentElementOrShadowHost(); 299 currentParent = currentParent.parentElementOrShadowHost();
288 300
289 if (this._isRoot) { 301 if (this._isRoot) {
290 UI.Widget.__assert(!currentParent, 'Attempt to show root widget under anot her widget'); 302 UI.Widget.__assert(!currentParent, 'Attempt to show root widget under anot her widget');
291 } else { 303 } else {
292 UI.Widget.__assert( 304 UI.Widget.__assert(
293 currentParent && currentParent.__widget === this._parentWidget, 305 currentParent && currentParent.__widget === this._parentWidget,
294 'Attempt to show under node belonging to alien widget'); 306 'Attempt to show under node belonging to alien widget');
(...skipping 22 matching lines...) Expand all
317 if (!wasVisible && this._parentIsShowing()) 329 if (!wasVisible && this._parentIsShowing())
318 this._processWasShown(); 330 this._processWasShown();
319 331
320 if (this._parentWidget && this._hasNonZeroConstraints()) 332 if (this._parentWidget && this._hasNonZeroConstraints())
321 this._parentWidget.invalidateConstraints(); 333 this._parentWidget.invalidateConstraints();
322 else 334 else
323 this._processOnResize(); 335 this._processOnResize();
324 } 336 }
325 337
326 hideWidget() { 338 hideWidget() {
327 if (!this._parentWidget) 339 UI.Widget.__assert(this._parentWidget || this._isRoot, 'Attempt to hide widg et that has not been attached');
328 return;
329 this._hideWidget(); 340 this._hideWidget();
330 } 341 }
331 342
332 /** 343 /**
333 * @param {boolean=} overrideHideOnDetach 344 * @param {boolean=} overrideHideOnDetach
334 */ 345 */
335 _hideWidget(overrideHideOnDetach) { 346 _hideWidget(overrideHideOnDetach) {
336 if (!this._visible) 347 if (!this._visible)
337 return; 348 return;
338 this._visible = false; 349 this._visible = false;
339 var parentElement = this.element.parentElement; 350 var parentElement = this.element.parentElement;
351 this._attachedToParentElement = parentElement;
352 this._attachedBeforeElement = this.element.nextSibling;
340 353
341 if (this._parentIsShowing()) 354 if (this._parentIsShowing())
342 this._processWillHide(); 355 this._processWillHide();
343 356
344 if (!overrideHideOnDetach && this.shouldHideOnDetach()) { 357 if (!overrideHideOnDetach && this.shouldHideOnDetach()) {
345 this.element.classList.add('hidden'); 358 this.element.classList.add('hidden');
346 } else { 359 } else {
347 // Force legal removal 360 // Force legal removal
348 UI.Widget._decrementWidgetCounter(parentElement, this.element); 361 UI.Widget._decrementWidgetCounter(parentElement, this.element);
349 UI.Widget._originalRemoveChild.call(parentElement, this.element); 362 UI.Widget._originalRemoveChild.call(parentElement, this.element);
(...skipping 19 matching lines...) Expand all
369 this._parentWidget._children.splice(childIndex, 1); 382 this._parentWidget._children.splice(childIndex, 1);
370 if (this._parentWidget._defaultFocusedChild === this) 383 if (this._parentWidget._defaultFocusedChild === this)
371 this._parentWidget._defaultFocusedChild = null; 384 this._parentWidget._defaultFocusedChild = null;
372 this._parentWidget.childWasDetached(this); 385 this._parentWidget.childWasDetached(this);
373 var parent = this._parentWidget; 386 var parent = this._parentWidget;
374 this._parentWidget = null; 387 this._parentWidget = null;
375 this._processWasDetachedFromHierarchy(); 388 this._processWasDetachedFromHierarchy();
376 } else { 389 } else {
377 UI.Widget.__assert(this._isRoot, 'Removing non-root widget from DOM'); 390 UI.Widget.__assert(this._isRoot, 'Removing non-root widget from DOM');
378 } 391 }
392
393 this._attachedToParentElement = null;
394 this._attachedBeforeElement = null;
379 } 395 }
380 396
381 detachChildWidgets() { 397 detachChildWidgets() {
382 var children = this._children.slice(); 398 var children = this._children.slice();
383 for (var i = 0; i < children.length; ++i) 399 for (var i = 0; i < children.length; ++i)
384 children[i].detach(); 400 children[i].detach();
385 } 401 }
386 402
387 /** 403 /**
388 * @return {!Array.<!Element>} 404 * @return {!Array.<!Element>}
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 } 595 }
580 this._invalidationsRequested = false; 596 this._invalidationsRequested = false;
581 var cached = this._cachedConstraints; 597 var cached = this._cachedConstraints;
582 delete this._cachedConstraints; 598 delete this._cachedConstraints;
583 var actual = this.constraints(); 599 var actual = this.constraints();
584 if (!actual.isEqual(cached) && this._parentWidget) 600 if (!actual.isEqual(cached) && this._parentWidget)
585 this._parentWidget.invalidateConstraints(); 601 this._parentWidget.invalidateConstraints();
586 else 602 else
587 this.doLayout(); 603 this.doLayout();
588 } 604 }
589
590 invalidateSize() {
591 if (this._parentWidget)
592 this._parentWidget.doLayout();
593 }
594 }; 605 };
595 606
596 UI.Widget._originalAppendChild = Element.prototype.appendChild; 607 UI.Widget._originalAppendChild = Element.prototype.appendChild;
597 UI.Widget._originalInsertBefore = Element.prototype.insertBefore; 608 UI.Widget._originalInsertBefore = Element.prototype.insertBefore;
598 UI.Widget._originalRemoveChild = Element.prototype.removeChild; 609 UI.Widget._originalRemoveChild = Element.prototype.removeChild;
599 UI.Widget._originalRemoveChildren = Element.prototype.removeChildren; 610 UI.Widget._originalRemoveChildren = Element.prototype.removeChildren;
600 611
601 612
602 /** 613 /**
603 * @unrestricted 614 * @unrestricted
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 UI.Widget.__assert( 756 UI.Widget.__assert(
746 !child.__widgetCounter && !child.__widget, 757 !child.__widgetCounter && !child.__widget,
747 'Attempt to remove element containing widget via regular DOM operation'); 758 'Attempt to remove element containing widget via regular DOM operation');
748 return UI.Widget._originalRemoveChild.call(this, child); 759 return UI.Widget._originalRemoveChild.call(this, child);
749 }; 760 };
750 761
751 Element.prototype.removeChildren = function() { 762 Element.prototype.removeChildren = function() {
752 UI.Widget.__assert(!this.__widgetCounter, 'Attempt to remove element containin g widget via regular DOM operation'); 763 UI.Widget.__assert(!this.__widgetCounter, 'Attempt to remove element containin g widget via regular DOM operation');
753 UI.Widget._originalRemoveChildren.call(this); 764 UI.Widget._originalRemoveChildren.call(this);
754 }; 765 };
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/devtools/front_end/ui/TabbedPane.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698