* Applies a size change to the element. * * This method is called by Resources and shouldn't be called by anyone * else. This method must always be called in the mutation context. * * @param {number|undefined} newHeight * @param {number|undefined} newWidth * @param
(newHeight, newWidth, opt_newMargins)
| 1094 | * @package |
| 1095 | */ |
| 1096 | applySize(newHeight, newWidth, opt_newMargins) { |
| 1097 | const sizer = this.getSizer_(); |
| 1098 | if (sizer) { |
| 1099 | // From the moment height is changed the element becomes fully |
| 1100 | // responsible for managing its height. Aspect ratio is no longer |
| 1101 | // preserved. |
| 1102 | this.sizerElement = null; |
| 1103 | this.resetSizer_(sizer); |
| 1104 | this.mutateOrInvoke_(() => { |
| 1105 | if (sizer) { |
| 1106 | dom.removeElement(sizer); |
| 1107 | } |
| 1108 | }); |
| 1109 | } |
| 1110 | if (newHeight !== undefined) { |
| 1111 | setStyle(this, 'height', newHeight, 'px'); |
| 1112 | } |
| 1113 | if (newWidth !== undefined) { |
| 1114 | setStyle(this, 'width', newWidth, 'px'); |
| 1115 | } |
| 1116 | if (opt_newMargins) { |
| 1117 | if (opt_newMargins.top != null) { |
| 1118 | setStyle(this, 'marginTop', opt_newMargins.top, 'px'); |
| 1119 | } |
| 1120 | if (opt_newMargins.right != null) { |
| 1121 | setStyle(this, 'marginRight', opt_newMargins.right, 'px'); |
| 1122 | } |
| 1123 | if (opt_newMargins.bottom != null) { |
| 1124 | setStyle(this, 'marginBottom', opt_newMargins.bottom, 'px'); |
| 1125 | } |
| 1126 | if (opt_newMargins.left != null) { |
| 1127 | setStyle(this, 'marginLeft', opt_newMargins.left, 'px'); |
| 1128 | } |
| 1129 | } |
| 1130 | if (this.isAwaitingSize_()) { |
| 1131 | this.sizeProvided_(); |
| 1132 | } |
| 1133 | dom.dispatchCustomEvent(this, AmpEvents_Enum.SIZE_CHANGED); |
| 1134 | } |
| 1135 | |
| 1136 | /** |
| 1137 | * Called when the element is first connected to the DOM. |
no test coverage detected