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

Side by Side Diff: third_party/polymer/v1_0/components-chromium/iron-fit-behavior/iron-fit-behavior-extracted.js

Issue 1984963002: Roll Polymer elements (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 `Polymer.IronFitBehavior` fits an element in another element using `max-height` and `max-width`, and 2 `Polymer.IronFitBehavior` fits an element in another element using `max-height` and `max-width`, and
3 optionally centers it in the window or another element. 3 optionally centers it in the window or another element.
4 4
5 The element will only be sized and/or positioned if it has not already been size d and/or positioned 5 The element will only be sized and/or positioned if it has not already been size d and/or positioned
6 by CSS. 6 by CSS.
7 7
8 CSS properties | Action 8 CSS properties | Action
9 -----------------------------|------------------------------------------- 9 -----------------------------|-------------------------------------------
10 `position` set | Element is not centered horizontally or verticall y 10 `position` set | Element is not centered horizontally or verticall y
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 this.style[property] = info.inlineStyle[property]; 297 this.style[property] = info.inlineStyle[property];
298 } 298 }
299 299
300 this._fitInfo = null; 300 this._fitInfo = null;
301 }, 301 },
302 302
303 /** 303 /**
304 * Equivalent to calling `resetFit()` and `fit()`. Useful to call this after 304 * Equivalent to calling `resetFit()` and `fit()`. Useful to call this after
305 * the element or the `fitInto` element has been resized, or if any of the 305 * the element or the `fitInto` element has been resized, or if any of the
306 * positioning properties (e.g. `horizontalAlign, verticalAlign`) is updated . 306 * positioning properties (e.g. `horizontalAlign, verticalAlign`) is updated .
307 * It preserves the scroll position of the sizingTarget.
307 */ 308 */
308 refit: function() { 309 refit: function() {
310 var scrollLeft = this.sizingTarget.scrollLeft;
311 var scrollTop = this.sizingTarget.scrollTop;
309 this.resetFit(); 312 this.resetFit();
310 this.fit(); 313 this.fit();
314 this.sizingTarget.scrollLeft = scrollLeft;
315 this.sizingTarget.scrollTop = scrollTop;
311 }, 316 },
312 317
313 /** 318 /**
314 * Positions the element according to `horizontalAlign, verticalAlign`. 319 * Positions the element according to `horizontalAlign, verticalAlign`.
315 */ 320 */
316 position: function() { 321 position: function() {
317 if (!this.horizontalAlign && !this.verticalAlign) { 322 if (!this.horizontalAlign && !this.verticalAlign) {
318 // needs to be centered, and it is done after constrain. 323 // needs to be centered, and it is done after constrain.
319 return; 324 return;
320 } 325 }
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 positions[5].left = positions[7].left -= positionRect.width; 529 positions[5].left = positions[7].left -= positionRect.width;
525 } 530 }
526 531
527 // Consider auto as null for coding convenience. 532 // Consider auto as null for coding convenience.
528 vAlign = vAlign === 'auto' ? null : vAlign; 533 vAlign = vAlign === 'auto' ? null : vAlign;
529 hAlign = hAlign === 'auto' ? null : hAlign; 534 hAlign = hAlign === 'auto' ? null : hAlign;
530 535
531 var position; 536 var position;
532 for (var i = 0; i < positions.length; i++) { 537 for (var i = 0; i < positions.length; i++) {
533 var pos = positions[i]; 538 var pos = positions[i];
534 // Align is ok if:
535 // - Horizontal AND vertical are required and match, or
536 // - Only vertical is required and matches, or
537 // - Only horizontal is required and matches.
538 var alignOk = (pos.verticalAlign === vAlign && pos.horizontalAlign === h Align) ||
539 (pos.verticalAlign === vAlign && !hAlign) ||
540 (pos.horizontalAlign === hAlign && !vAlign);
541 539
542 // If both vAlign and hAlign are defined, return exact match. 540 // If both vAlign and hAlign are defined, return exact match.
543 // For dynamicAlign and noOverlap we'll have more than one candidate, so 541 // For dynamicAlign and noOverlap we'll have more than one candidate, so
544 // we'll have to check the croppedArea to make the best choice. 542 // we'll have to check the croppedArea to make the best choice.
545 if (!this.dynamicAlign && !this.noOverlap && vAlign && hAlign && alignOk ) { 543 if (!this.dynamicAlign && !this.noOverlap &&
544 pos.verticalAlign === vAlign && pos.horizontalAlign === hAlign) {
546 position = pos; 545 position = pos;
547 break; 546 break;
548 } 547 }
549 548
549 // Align is ok if alignment preferences are respected. If no preferences ,
550 // it is considered ok.
551 var alignOk = (!vAlign || pos.verticalAlign === vAlign) &&
552 (!hAlign || pos.horizontalAlign === hAlign);
553
550 // Filter out elements that don't match the alignment (if defined). 554 // Filter out elements that don't match the alignment (if defined).
551 // With dynamicAlign, we need to consider all the positions to find the 555 // With dynamicAlign, we need to consider all the positions to find the
552 // one that minimizes the cropped area. 556 // one that minimizes the cropped area.
553 if (!this.dynamicAlign && (vAlign || hAlign) && !alignOk) { 557 if (!this.dynamicAlign && !alignOk) {
554 continue; 558 continue;
555 } 559 }
556 560
557 position = position || pos; 561 position = position || pos;
558 pos.croppedArea = this.__getCroppedArea(pos, size, fitRect); 562 pos.croppedArea = this.__getCroppedArea(pos, size, fitRect);
559 var diff = pos.croppedArea - position.croppedArea; 563 var diff = pos.croppedArea - position.croppedArea;
560 // Check which crops less. If it crops equally, 564 // Check which crops less. If it crops equally, check if align is ok.
561 // check for alignment preferences.
562 if (diff < 0 || (diff === 0 && alignOk)) { 565 if (diff < 0 || (diff === 0 && alignOk)) {
563 position = pos; 566 position = pos;
564 } 567 }
568 // If not cropped and respects the align requirements, keep it.
569 // This allows to prefer positions overlapping horizontally over the
570 // ones overlapping vertically.
571 if (position.croppedArea === 0 && alignOk) {
572 break;
573 }
565 } 574 }
566 575
567 return position; 576 return position;
568 } 577 }
569 578
570 }; 579 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698