Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edge: Inherit dark theme from Eclipse #1530

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Edge extends WebBrowser {

// Display.getData() keys
static final String APPLOCAL_DIR_KEY = "org.eclipse.swt.internal.win32.appLocalDir";
static final String EDGE_USE_DARK_PREFERED_COLOR_SCHEME = "org.eclipse.swt.internal.win32.Edge.useDarkPreferedColorScheme"; //$NON-NLS-1$

// System.getProperty() keys
static final String BROWSER_DIR_PROP = "org.eclipse.swt.browser.EdgeDir";
Expand All @@ -64,6 +65,7 @@ public WebViewEnvironment(ICoreWebView2Environment environment) {
private static Map<Display, WebViewEnvironment> webViewEnvironments = new HashMap<>();
ICoreWebView2Controller controller;
ICoreWebView2Settings settings;
ICoreWebView2Profile profile;
ICoreWebView2Environment2 environment2;
private final WebViewProvider webViewProvider = new WebViewProvider();

Expand Down Expand Up @@ -285,6 +287,7 @@ class WebViewProvider {
private CompletableFuture<ICoreWebView2_2> webView_2Future = new CompletableFuture<>();
private CompletableFuture<ICoreWebView2_11> webView_11Future = new CompletableFuture<>();
private CompletableFuture<ICoreWebView2_12> webView_12Future = new CompletableFuture<>();
private CompletableFuture<ICoreWebView2_13> webView_13Future = new CompletableFuture<>();

private CompletableFuture<Void> lastWebViewTask = webViewFuture.thenRun(() -> {});

Expand All @@ -295,6 +298,7 @@ ICoreWebView2 initializeWebView(ICoreWebView2Controller controller) {
initializeWebView_2(webView);
initializeWebView_11(webView);
initializeWebView_12(webView);
initializeWebView_13(webView);
webViewFuture.complete(webView);
return webView;
}
Expand Down Expand Up @@ -329,6 +333,16 @@ private void initializeWebView_12(ICoreWebView2 webView) {
}
}

private void initializeWebView_13(ICoreWebView2 webView) {
long[] ppv = new long[1];
int hr = webView.QueryInterface(COM.IID_ICoreWebView2_13, ppv);
if (hr == COM.S_OK) {
webView_13Future.complete(new ICoreWebView2_13(ppv[0]));
} else {
webView_13Future.cancel(true);
}
}

ICoreWebView2 getWebView(boolean waitForPendingWebviewTasksToFinish) {
if(waitForPendingWebviewTasksToFinish) {
waitForFutureToFinish(lastWebViewTask);
Expand Down Expand Up @@ -372,6 +386,18 @@ boolean isWebView_12Available() {
return !webView_12Future.isCancelled();
}

ICoreWebView2_13 getWebView_13(boolean waitForPendingWebviewTasksToFinish) {
if(waitForPendingWebviewTasksToFinish) {
waitForFutureToFinish(lastWebViewTask);
}
return webView_13Future.join();
}

boolean isWebView_13Available() {
waitForFutureToFinish(webView_13Future);
return !webView_13Future.isCancelled();
}

/*
* Schedule a given runnable in a queue to execute when the webView is free and
* has finished all the pending tasks queued before it.
Expand Down Expand Up @@ -547,6 +573,18 @@ void setupBrowser(int hr, long pv) {
settings.put_IsStatusBarEnabled(false);
}

if (webViewProvider.isWebView_13Available()) {
webViewProvider.getWebView_13(false).get_Profile(ppv);
profile = new ICoreWebView2Profile(ppv[0]);

// Dark theme inherited from application theme
if (Boolean.TRUE.equals(browser.getDisplay().getData(EDGE_USE_DARK_PREFERED_COLOR_SCHEME))) {
profile.put_PreferredColorScheme(/* COREWEBVIEW2_PREFERRED_COLOR_SCHEME_DARK */ 2);
} else {
profile.put_PreferredColorScheme(/* COREWEBVIEW2_PREFERRED_COLOR_SCHEME_AUTO */ 0);
}
}

long[] token = new long[1];
IUnknown handler;
handler = newCallback(this::handleCloseRequested);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public class COM extends OS {
public static final GUID IID_ICoreWebView2_2 = IIDFromString("{9E8F0CF8-E670-4B5E-B2BC-73E061E3184C}"); //$NON-NLS-1$
public static final GUID IID_ICoreWebView2_11 = IIDFromString("{0BE78E56-C193-4051-B943-23B460C08BDB}"); //$NON-NLS-1$
public static final GUID IID_ICoreWebView2_12 = IIDFromString("{35D69927-BCFA-4566-9349-6B3E0D154CAC}"); //$NON-NLS-1$
public static final GUID IID_ICoreWebView2_13 = IIDFromString("{F75F09A8-667E-4983-88D6-C8773F315E84}"); //$NON-NLS-1$

// IA2 related GUIDS
public static final GUID IIDIAccessible2 = IIDFromString("{E89F726E-C4F4-4c19-BB19-B647D7FA8478}"); //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*******************************************************************************
* Copyright (c) 2024 SAP SE and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* SAP SE - initial implementation
*******************************************************************************/
package org.eclipse.swt.internal.ole.win32;

public class ICoreWebView2Profile extends IUnknown {

public ICoreWebView2Profile(long address) {
super(address);
}

public int get_ProfileName(long[] value) {
return COM.VtblCall(3, address, value);
}

public int get_IsInPrivateModeEnabled(long[] value) {
return COM.VtblCall(4, address, value);
}

public int get_ProfilePath(long[] value) {
return COM.VtblCall(5, address, value);
}

public int get_DefaultDownloadFolderPath(long[] value) {
return COM.VtblCall(6, address, value);
}

public int put_DefaultDownloadFolderPath(long[] value) {
return COM.VtblCall(7, address, value);
}

public int get_PreferredColorScheme(long[] value) {
return COM.VtblCall(8, address, value);
}

public int put_PreferredColorScheme(long value) {
return COM.VtblCall(9, address, value);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*******************************************************************************
* Copyright (c) 2024 SAP SE and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* SAP SE - initial implementation
*******************************************************************************/
package org.eclipse.swt.internal.ole.win32;

public class ICoreWebView2_13 extends ICoreWebView2_12 {

public ICoreWebView2_13(long address) {
super(address);
}

public int get_Profile(long[] value) {
return COM.VtblCall(105, address, value);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2285,6 +2285,7 @@ public static final void setTheme(boolean isDarkTheme) {
display.setData("org.eclipse.swt.internal.win32.Combo.useDarkTheme", isDarkTheme);
display.setData("org.eclipse.swt.internal.win32.ProgressBar.useColors", isDarkTheme);
display.setData("org.eclipse.swt.internal.win32.Text.useDarkThemeIcons", isDarkTheme);
display.setData("org.eclipse.swt.internal.win32.Edge.useDarkPreferedColorScheme", isDarkTheme);
}

public static final boolean SetWindowText (long hWnd, TCHAR lpString) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,17 @@ public class Display extends Device implements Executor {
*/
static final String USE_DARKTHEME_TEXT_ICONS = "org.eclipse.swt.internal.win32.Text.useDarkThemeIcons"; //$NON-NLS-1$
boolean textUseDarkthemeIcons = false;
/**
* Use dark prefered color scheme in Edge browser.
* Note:<br>
* <ul>
* <li>When setting this property on the display, it is first AND'ed with !disableCustomThemeTweaks.
* <li>The data is then read from withing Edge.
* <li>This is to avoid adding public methods/members.
* </ul>
* Expects a <code>boolean</code> value.
*/
static final String EDGE_USE_DARK_PREFERED_COLOR_SCHEME = "org.eclipse.swt.internal.win32.Edge.useDarkPreferedColorScheme"; //$NON-NLS-1$

/* Custom icons */
private HashMap<Integer, Long> sizeToSearchIconHandle = new HashMap<>();
Expand Down Expand Up @@ -4575,6 +4586,9 @@ public void setData (String key, Object value) {
case USE_DARKTHEME_TEXT_ICONS:
textUseDarkthemeIcons = !disableCustomThemeTweaks && _toBoolean(value);
break;
case EDGE_USE_DARK_PREFERED_COLOR_SCHEME:
value = !disableCustomThemeTweaks && _toBoolean(value);
break;
}

/* Remove the key/value pair */
Expand Down
Loading