* Gets the effective layout for an element. * * If class 'i-amphtml-layout' is present, then directly use its value. * Else calculate layout based on element attributes and return the width/height. * * @param {Element} element * @return {InternalEffectiveLayoutDef}
(element)
| 236 | * @return {InternalEffectiveLayoutDef} |
| 237 | */ |
| 238 | function getEffectiveLayoutInternal(element) { |
| 239 | // Parse layout from the element. |
| 240 | const layoutAttr = element.getAttribute('layout'); |
| 241 | const widthAttr = element.getAttribute('width'); |
| 242 | const heightAttr = element.getAttribute('height'); |
| 243 | const sizesAttr = element.getAttribute('sizes'); |
| 244 | const heightsAttr = element.getAttribute('heights'); |
| 245 | |
| 246 | // Input layout attributes. |
| 247 | const inputLayout = layoutAttr ? parseLayout(layoutAttr) : null; |
| 248 | userAssert( |
| 249 | inputLayout !== undefined, |
| 250 | 'Invalid "layout" value: %s, %s', |
| 251 | layoutAttr, |
| 252 | element |
| 253 | ); |
| 254 | /** |
| 255 | * @type {string|null|undefined} |
| 256 | * @const |
| 257 | */ |
| 258 | const inputWidth = |
| 259 | widthAttr && widthAttr != 'auto' ? parseLength(widthAttr) : widthAttr; |
| 260 | userAssert( |
| 261 | inputWidth !== undefined, |
| 262 | 'Invalid "width" value: %s, %s', |
| 263 | widthAttr, |
| 264 | element |
| 265 | ); |
| 266 | /** |
| 267 | * @type {string|null|undefined} |
| 268 | * @const |
| 269 | */ |
| 270 | const inputHeight = |
| 271 | heightAttr && heightAttr != 'fluid' ? parseLength(heightAttr) : heightAttr; |
| 272 | userAssert( |
| 273 | inputHeight !== undefined, |
| 274 | 'Invalid "height" value: %s, %s', |
| 275 | heightAttr, |
| 276 | element |
| 277 | ); |
| 278 | |
| 279 | // Effective layout attributes. These are effectively constants. |
| 280 | let width; |
| 281 | let height; |
| 282 | let layout; |
| 283 | |
| 284 | // Calculate effective width and height. |
| 285 | if ( |
| 286 | (!inputLayout || |
| 287 | inputLayout == Layout_Enum.FIXED || |
| 288 | inputLayout == Layout_Enum.FIXED_HEIGHT) && |
| 289 | (!inputWidth || !inputHeight) && |
| 290 | hasNaturalDimensions(element.tagName) |
| 291 | ) { |
| 292 | // Default width and height: handle elements that do not specify a |
| 293 | // width/height and are defined to have natural browser dimensions. |
| 294 | const dimensions = getNaturalDimensions(element); |
| 295 | width = |
no test coverage detected