X Tutup
Skip to content

Commit c44eb52

Browse files
author
zhourenjian
committed
Set other containers invisible to make sure the size of given text is accurate
1 parent 3c9a4fd commit c44eb52

File tree

1 file changed

+20
-0
lines changed
  • sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/internal/browser

1 file changed

+20
-0
lines changed

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/internal/browser/OS.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,10 +352,13 @@ private static Element setupAsPlain(String str, int wrappedWidth) {
352352
c = lineContainer;
353353
}
354354
clearChildren(c);
355+
c.style.display = "inline";
355356
insertText(c, str);
356357
return c;
357358
}
358359

360+
static String[] oldDisplays = new String[0];
361+
359362
private static Element setupAsStyled(String str, String className, String cssText, int wrappedWidth) {
360363
init ();
361364
cssText = wrapCSS(cssText);
@@ -398,6 +401,23 @@ private static Element setupAsStyled(String str, String className, String cssTex
398401
if (wrappedWidth > 0) {
399402
f.style.width = wrappedWidth + "px";
400403
}
404+
/*
405+
* Set other container invisible to make sure the size is accurate
406+
*/
407+
Element[] childNodes = invisibleContainer.childNodes;
408+
for (int i = 0; i < childNodes.length; i++) {
409+
CSSStyle s = childNodes[i].style;
410+
if (childNodes[i] != f) {
411+
if (s.display != "none") {
412+
oldDisplays[i] = s.display;
413+
s.display = "none";
414+
}
415+
} else {
416+
if (oldDisplays[i] != null) {
417+
s.display = oldDisplays[i];
418+
}
419+
}
420+
}
401421
insertText (f, str);
402422
return f;
403423
}

0 commit comments

Comments
 (0)
X Tutup