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

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: review comments addressed 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 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 } 240 }
241 241
242 onResize() { 242 onResize() {
243 } 243 }
244 244
245 onLayout() { 245 onLayout() {
246 } 246 }
247 247
248 /** 248 /**
249 * @param {!Element} parentElement 249 * @param {!Element} parentElement
250 * @param {?Element=} insertBefore 250 * @param {?Node=} insertBefore
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._attachedBeforeNode = 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 {?Node=} insertBefore
269 */ 274 */
270 attach(parentWidget) { 275 attach(parentWidget, parentElement, insertBefore) {
271 if (parentWidget === this._parentWidget) 276 parentElement = parentElement || parentWidget.element;
277 if (parentWidget === this._parentWidget) {
278 this._attachedToParentElement = parentElement;
279 this._attachedBeforeNode = insertBefore;
280 if (this._visible)
281 this.showWidget();
272 return; 282 return;
283 }
273 if (this._parentWidget) 284 if (this._parentWidget)
274 this.detach(); 285 this.detach();
275 this._parentWidget = parentWidget; 286 this._parentWidget = parentWidget;
276 this._parentWidget._children.push(this); 287 this._parentWidget._children.push(this);
288 this._attachedToParentElement = parentElement;
289 this._attachedBeforeNode = insertBefore;
277 this._isRoot = false; 290 this._isRoot = false;
278 } 291 }
279 292
280 /** 293 showWidget() {
281 * @param {!Element} parentElement 294 UI.Widget.__assert(this._parentWidget || this._isRoot, 'Attempt to show widg et that has not been attached');
282 * @param {?Element=} insertBefore 295 var parentElement = this._attachedToParentElement;
283 */ 296 var insertBefore = this._attachedBeforeNode;
284 showWidget(parentElement, insertBefore) { 297
285 var currentParent = parentElement; 298 var currentParent = parentElement;
286 while (currentParent && !currentParent.__widget) 299 while (currentParent && !currentParent.__widget)
287 currentParent = currentParent.parentElementOrShadowHost(); 300 currentParent = currentParent.parentElementOrShadowHost();
288 301
289 if (this._isRoot) { 302 if (this._isRoot) {
290 UI.Widget.__assert(!currentParent, 'Attempt to show root widget under anot her widget'); 303 UI.Widget.__assert(!currentParent, 'Attempt to show root widget under anot her widget');
291 } else { 304 } else {
292 UI.Widget.__assert( 305 UI.Widget.__assert(
293 currentParent && currentParent.__widget === this._parentWidget, 306 currentParent && currentParent.__widget === this._parentWidget,
294 'Attempt to show under node belonging to alien widget'); 307 'Attempt to show under node belonging to alien widget');
(...skipping 22 matching lines...) Expand all
317 if (!wasVisible && this._parentIsShowing()) 330 if (!wasVisible && this._parentIsShowing())
318 this._processWasShown(); 331 this._processWasShown();
319 332
320 if (this._parentWidget && this._hasNonZeroConstraints()) 333 if (this._parentWidget && this._hasNonZeroConstraints())
321 this._parentWidget.invalidateConstraints(); 334 this._parentWidget.invalidateConstraints();
322 else 335 else
323 this._processOnResize(); 336 this._processOnResize();
324 } 337 }
325 338
326 hideWidget() { 339 hideWidget() {
327 if (!this._parentWidget) 340 UI.Widget.__assert(this._parentWidget || this._isRoot, 'Attempt to hide widg et that has not been attached');
328 return;
329 this._hideWidget(); 341 this._hideWidget();
330 } 342 }
331 343
332 /** 344 /**
333 * @param {boolean=} overrideHideOnDetach 345 * @param {boolean=} overrideHideOnDetach
334 */ 346 */
335 _hideWidget(overrideHideOnDetach) { 347 _hideWidget(overrideHideOnDetach) {
336 if (!this._visible) 348 if (!this._visible)
337 return; 349 return;
338 this._visible = false; 350 this._visible = false;
339 var parentElement = this.element.parentElement; 351 var parentElement = this.element.parentElement;
352 this._attachedToParentElement = parentElement;
353 this._attachedBeforeNode = this.element.nextSibling;
340 354
341 if (this._parentIsShowing()) 355 if (this._parentIsShowing())
342 this._processWillHide(); 356 this._processWillHide();
343 357
344 if (!overrideHideOnDetach && this.shouldHideOnDetach()) { 358 if (!overrideHideOnDetach && this.shouldHideOnDetach()) {
345 this.element.classList.add('hidden'); 359 this.element.classList.add('hidden');
346 } else { 360 } else {
347 // Force legal removal 361 // Force legal removal
348 UI.Widget._decrementWidgetCounter(parentElement, this.element); 362 UI.Widget._decrementWidgetCounter(parentElement, this.element);
349 UI.Widget._originalRemoveChild.call(parentElement, this.element); 363 UI.Widget._originalRemoveChild.call(parentElement, this.element);
(...skipping 19 matching lines...) Expand all
369 this._parentWidget._children.splice(childIndex, 1); 383 this._parentWidget._children.splice(childIndex, 1);
370 if (this._parentWidget._defaultFocusedChild === this) 384 if (this._parentWidget._defaultFocusedChild === this)
371 this._parentWidget._defaultFocusedChild = null; 385 this._parentWidget._defaultFocusedChild = null;
372 this._parentWidget.childWasDetached(this); 386 this._parentWidget.childWasDetached(this);
373 var parent = this._parentWidget; 387 var parent = this._parentWidget;
374 this._parentWidget = null; 388 this._parentWidget = null;
375 this._processWasDetachedFromHierarchy(); 389 this._processWasDetachedFromHierarchy();
376 } else { 390 } else {
377 UI.Widget.__assert(this._isRoot, 'Removing non-root widget from DOM'); 391 UI.Widget.__assert(this._isRoot, 'Removing non-root widget from DOM');
378 } 392 }
393
394 this._attachedToParentElement = null;
395 this._attachedBeforeNode = null;
379 } 396 }
380 397
381 detachChildWidgets() { 398 detachChildWidgets() {
382 var children = this._children.slice(); 399 var children = this._children.slice();
383 for (var i = 0; i < children.length; ++i) 400 for (var i = 0; i < children.length; ++i)
384 children[i].detach(); 401 children[i].detach();
385 } 402 }
386 403
387 /** 404 /**
388 * @return {!Array.<!Element>} 405 * @return {!Array.<!Element>}
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 } 596 }
580 this._invalidationsRequested = false; 597 this._invalidationsRequested = false;
581 var cached = this._cachedConstraints; 598 var cached = this._cachedConstraints;
582 delete this._cachedConstraints; 599 delete this._cachedConstraints;
583 var actual = this.constraints(); 600 var actual = this.constraints();
584 if (!actual.isEqual(cached) && this._parentWidget) 601 if (!actual.isEqual(cached) && this._parentWidget)
585 this._parentWidget.invalidateConstraints(); 602 this._parentWidget.invalidateConstraints();
586 else 603 else
587 this.doLayout(); 604 this.doLayout();
588 } 605 }
589
590 invalidateSize() {
591 if (this._parentWidget)
592 this._parentWidget.doLayout();
593 }
594 }; 606 };
595 607
596 UI.Widget._originalAppendChild = Element.prototype.appendChild; 608 UI.Widget._originalAppendChild = Element.prototype.appendChild;
597 UI.Widget._originalInsertBefore = Element.prototype.insertBefore; 609 UI.Widget._originalInsertBefore = Element.prototype.insertBefore;
598 UI.Widget._originalRemoveChild = Element.prototype.removeChild; 610 UI.Widget._originalRemoveChild = Element.prototype.removeChild;
599 UI.Widget._originalRemoveChildren = Element.prototype.removeChildren; 611 UI.Widget._originalRemoveChildren = Element.prototype.removeChildren;
600 612
601 613
602 /** 614 /**
603 * @unrestricted 615 * @unrestricted
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 UI.Widget.__assert( 757 UI.Widget.__assert(
746 !child.__widgetCounter && !child.__widget, 758 !child.__widgetCounter && !child.__widget,
747 'Attempt to remove element containing widget via regular DOM operation'); 759 'Attempt to remove element containing widget via regular DOM operation');
748 return UI.Widget._originalRemoveChild.call(this, child); 760 return UI.Widget._originalRemoveChild.call(this, child);
749 }; 761 };
750 762
751 Element.prototype.removeChildren = function() { 763 Element.prototype.removeChildren = function() {
752 UI.Widget.__assert(!this.__widgetCounter, 'Attempt to remove element containin g widget via regular DOM operation'); 764 UI.Widget.__assert(!this.__widgetCounter, 'Attempt to remove element containin g widget via regular DOM operation');
753 UI.Widget._originalRemoveChildren.call(this); 765 UI.Widget._originalRemoveChildren.call(this);
754 }; 766 };
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