Skip to content

Commit d428505

Browse files
Appearance (Theme) API Spec
1 parent 75c91a7 commit d428505

1 file changed

Lines changed: 61 additions & 0 deletions

File tree

specs/Appearance.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
Appearance (Theme) API
2+
===
3+
4+
# Background
5+
This API's main use case is to set the overall appearance for WebView2. The options are similar to Edge: match the system default theme, light theme, or dark theme.
6+
This API changes thing like dialogs, menus, and web content based on native flags. Please note this API will only set the overall appearance, but not theme.
7+
For reference, in the screenshot below this API is meant to expose the Overall Appearance section as a WebView2 API.
8+
9+
# Conceptual pages (How To)
10+
11+
How to set theme in webview2.
12+
1. Query interface. (Situational)
13+
2. Call put_Appearance to set the Appearance property.
14+
3. The input parameter can be either COREWEBVIEW2_APPEARANCE_TYPE_SYSTEM, COREWEBVIEW2_APPEARANCE_TYPE_LIGHT, or COREWEBVIEW2_APPEARANCE_TYPE_DARK.
15+
16+
17+
# Examples
18+
19+
### C++
20+
21+
```cpp
22+
wil::com_ptr<ICoreWebView2StagingController2> webViewStagingController2;
23+
24+
bool ViewComponent::QuerySetAppearance(COREWEBVIEW2_APPEARANCE_TYPE appearance){
25+
26+
m_appWindow->GetWebViewController()->QueryInterface(IID_PPV_ARGS(&webViewStagingController2));
27+
CHECK_FEATURE_RETURN(webViewStagingController2);
28+
29+
// Input can be either:
30+
// 1. COREWEBVIEW2_APPEARANCE_TYPE_SYSTEM
31+
// 2. COREWEBVIEW2_APPEARANCE_TYPE_LIGHT
32+
// 3. COREWEBVIEW2_APPEARANCE_TYPE_DARK
33+
34+
webViewStagingController2->put_Appearance(appearance);
35+
36+
return true;
37+
}
38+
39+
```
40+
41+
# API Details
42+
43+
```
44+
[uuid(5f817cce-5d36-4cd0-a1d5-aaaf95c8685f), object, pointer_default(unique)]
45+
interface ICoreWebView2StagingController2 : IUnknown {
46+
47+
/// The Appearance property sets the overall theme of the webview2 instance.
48+
/// The input parameter is either COREWEBVIEW2_APPEARANCE_TYPE_SYSTEM,
49+
/// COREWEBVIEW2_APPEARANCE_TYPE_LIGHT, or COREWEBVIEW2_APPEARANCE_TYPE_DARK.
50+
/// Note that this applies to pages, dialogs, and menus.
51+
52+
/// Returns the value of the `Appearance` property.
53+
[propget] HRESULT Appearance(
54+
[out, retval] COREWEBVIEW2_APPEARANCE_TYPE* appearance);
55+
56+
/// Sets the `Appearance` property.
57+
[propput] HRESULT Appearance(
58+
[in] COREWEBVIEW2_APPEARANCE_TYPE appearance);
59+
60+
}
61+
```

0 commit comments

Comments
 (0)