| 40 | | private int hSpacing = -1; |
| 41 | | private int vSpacing = -1; |
| 42 | | private int marginTop = -1; |
| 43 | | private int marginBottom = -1; |
| 44 | | private int marginLeft = -1; |
| 45 | | private int marginRight = -1; |
| | 41 | /** |
| | 42 | * If margin and spacing values has been calculated, this holds the values |
| | 43 | * for the given UIDL style attribute . |
| | 44 | */ |
| | 45 | private static HashMap measuredMargins = new HashMap(); |
| | 46 | |
| | 47 | /** |
| | 48 | * Spacing. Correct values will be set in |
| | 49 | * updateMarginAndSpacingFromCSS(UIDL) |
| | 50 | */ |
| | 51 | private int hSpacing, vSpacing; |
| | 52 | |
| | 53 | /** |
| | 54 | * Margin. Correct values will be set in updateMarginAndSpacingFromCSS(UIDL) |
| | 55 | */ |
| | 56 | private int marginTop, marginBottom, marginLeft, marginRight; |
| 321 | | // TODO Read spacing and margins from CSS as documented in #1904. |
| 322 | | // Somehow refresh after updates |
| 323 | | |
| 324 | | hSpacing = 8; |
| 325 | | vSpacing = 8; |
| 326 | | marginTop = 15; |
| 327 | | marginBottom = 15; |
| 328 | | marginLeft = 18; |
| 329 | | marginRight = 18; |
| | 332 | |
| | 333 | // Style for this layout |
| | 334 | String style = uidl.getStringAttribute("style"); |
| | 335 | if (style == null) { |
| | 336 | style = ""; |
| | 337 | } |
| | 338 | |
| | 339 | // Try to find measured from cache |
| | 340 | int[] r = (int[]) measuredMargins.get(style); |
| | 341 | |
| | 342 | // Measure from DOM |
| | 343 | if (r == null) { |
| | 344 | r = new int[] { 0, 0, 0, 0, 0, 0 }; |
| | 345 | |
| | 346 | // Construct DOM for measurements |
| | 347 | Element e1 = DOM.createTable(); |
| | 348 | DOM.setStyleAttribute(e1, "position", "absolute"); |
| | 349 | DOM.setElementProperty(e1, "cellSpacing", "0"); |
| | 350 | DOM.setElementProperty(e1, "cellPadding", "0"); |
| | 351 | Element e11 = DOM.createTBody(); |
| | 352 | Element e12 = DOM.createTR(); |
| | 353 | Element e13 = DOM.createTD(); |
| | 354 | Element e2 = DOM.createDiv(); |
| | 355 | Element e3 = DOM.createDiv(); |
| | 356 | DOM.setStyleAttribute(e3, "width", "100px"); |
| | 357 | DOM.setStyleAttribute(e3, "height", "100px"); |
| | 358 | DOM.appendChild(getElement(), e1); |
| | 359 | DOM.appendChild(e1, e11); |
| | 360 | DOM.appendChild(e11, e12); |
| | 361 | DOM.appendChild(e12, e13); |
| | 362 | DOM.appendChild(e13, e2); |
| | 363 | DOM.appendChild(e2, e3); |
| | 364 | DOM.setInnerText(e3, "."); |
| | 365 | |
| | 366 | // Measure different properties |
| | 367 | final String[] classes = { "margin-top", "margin-right", |
| | 368 | "margin-bottom", "margin-left", "vspacing", "hspacing" }; |
| | 369 | for (int c = 0; c < 6; c++) { |
| | 370 | StringBuffer styleBuf = new StringBuffer(); |
| | 371 | final String primaryName = getStylePrimaryName(); |
| | 372 | styleBuf.append(primaryName + "-" + classes[c]); |
| | 373 | if (style.length() > 0) { |
| | 374 | final String[] styles = style.split(" "); |
| | 375 | for (int i = 0; i < styles.length; i++) { |
| | 376 | styleBuf.append(" "); |
| | 377 | styleBuf.append(primaryName); |
| | 378 | styleBuf.append("-"); |
| | 379 | styleBuf.append(styles[i]); |
| | 380 | styleBuf.append("-"); |
| | 381 | styleBuf.append(classes[c]); |
| | 382 | } |
| | 383 | } |
| | 384 | DOM.setElementProperty(e2, "className", styleBuf.toString()); |
| | 385 | |
| | 386 | // Measure |
| | 387 | r[c] = DOM.getElementPropertyInt(e1, |
| | 388 | (c % 2) == 1 ? "offsetWidth" : "offsetHeight") - 100; |
| | 389 | } |
| | 390 | |
| | 391 | // Clean-up |
| | 392 | DOM.removeChild(getElement(), e1); |
| | 393 | |
| | 394 | // Cache for further use |
| | 395 | measuredMargins.put(style, r); |
| | 396 | } |
| | 397 | |
| | 398 | // Set the properties |
| | 399 | marginTop = r[0]; |
| | 400 | marginRight = r[1]; |
| | 401 | marginBottom = r[2]; |
| | 402 | marginLeft = r[3]; |
| | 403 | vSpacing = r[4]; |
| | 404 | hSpacing = r[5]; |