Skip to content

Commit 8353819

Browse files
committed
refact: add FocusableBrowserInformationControl.updateBrowserSize
1 parent b591ac1 commit 8353819

1 file changed

Lines changed: 37 additions & 33 deletions

File tree

org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/hover/FocusableBrowserInformationControl.java

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -86,43 +86,47 @@ protected void createContent(Composite parent) {
8686
if (getInput() == null)
8787
return;
8888
final var browser = (Browser) event.getSource();
89-
@Nullable
90-
Point constraints = getSizeConstraints();
91-
Point hint = computeSizeHint();
92-
setSize(hint.x, hint.y);
93-
94-
safeExecute(browser, "document.getElementsByTagName(\"html\")[0].style.whiteSpace = \"nowrap\""); //$NON-NLS-1$
95-
Double width = 20 + (safeEvaluate(browser, "return document.body.scrollWidth;") instanceof Double evaluated ? evaluated : 0); //$NON-NLS-1$
96-
setSize(width.intValue(), hint.y);
97-
98-
safeExecute(browser, "document.getElementsByTagName(\"html\")[0].style.whiteSpace = \"normal\""); //$NON-NLS-1$
99-
Double height = safeEvaluate(browser, "return document.body.scrollHeight;") instanceof Double evaluated ? evaluated : 0; //$NON-NLS-1$
100-
Object marginTop = safeEvaluate(browser, "return window.getComputedStyle(document.body).marginTop;"); //$NON-NLS-1$
101-
Object marginBottom = safeEvaluate(browser, "return window.getComputedStyle(document.body).marginBottom;"); //$NON-NLS-1$
102-
if (Platform.getPreferencesService().getBoolean(EditorsUI.PLUGIN_ID,
103-
AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SHOW_TEXT_HOVER_AFFORDANCE, true,
104-
null)) {
105-
FontData[] fontDatas = JFaceResources.getDialogFont().getFontData();
106-
height += fontDatas[0].getHeight();
107-
}
108-
109-
width = width * 1.5;
110-
if (Util.isWin32()) {
111-
height = adjust(height, marginTop);
112-
height = adjust(height, marginBottom);
113-
}
114-
if (constraints != null && constraints.x < width) {
115-
width = (double) constraints.x;
116-
}
117-
if (constraints != null && constraints.y < height) {
118-
height = (double) constraints.y;
119-
}
120-
121-
setSize(width.intValue(), height.intValue());
89+
updateBrowserSize(browser);
12290
}));
12391
b.setJavascriptEnabled(true);
12492
}
12593

94+
private void updateBrowserSize(final Browser browser) {
95+
@Nullable
96+
Point constraints = getSizeConstraints();
97+
Point hint = computeSizeHint();
98+
setSize(hint.x, hint.y);
99+
100+
safeExecute(browser, "document.getElementsByTagName(\"html\")[0].style.whiteSpace = \"nowrap\""); //$NON-NLS-1$
101+
Double width = 20 + (safeEvaluate(browser, "return document.body.scrollWidth;") instanceof Double evaluated ? evaluated : 0); //$NON-NLS-1$
102+
setSize(width.intValue(), hint.y);
103+
104+
safeExecute(browser, "document.getElementsByTagName(\"html\")[0].style.whiteSpace = \"normal\""); //$NON-NLS-1$
105+
Double height = safeEvaluate(browser, "return document.body.scrollHeight;") instanceof Double evaluated ? evaluated : 0; //$NON-NLS-1$
106+
Object marginTop = safeEvaluate(browser, "return window.getComputedStyle(document.body).marginTop;"); //$NON-NLS-1$
107+
Object marginBottom = safeEvaluate(browser, "return window.getComputedStyle(document.body).marginBottom;"); //$NON-NLS-1$
108+
if (Platform.getPreferencesService().getBoolean(EditorsUI.PLUGIN_ID,
109+
AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SHOW_TEXT_HOVER_AFFORDANCE, true,
110+
null)) {
111+
FontData[] fontDatas = JFaceResources.getDialogFont().getFontData();
112+
height += fontDatas[0].getHeight();
113+
}
114+
115+
width = width * 1.5;
116+
if (Util.isWin32()) {
117+
height = adjust(height, marginTop);
118+
height = adjust(height, marginBottom);
119+
}
120+
if (constraints != null && constraints.x < width) {
121+
width = (double) constraints.x;
122+
}
123+
if (constraints != null && constraints.y < height) {
124+
height = (double) constraints.y;
125+
}
126+
127+
setSize(width.intValue(), height.intValue());
128+
}
129+
126130
private static @Nullable Object safeEvaluate(Browser browser, String expression) {
127131
try {
128132
return browser.evaluate(expression);

0 commit comments

Comments
 (0)