Skip to content

Commit 348f669

Browse files
author
Jason Stephen
committed
updated spec based on feedback
1 parent 165a3d3 commit 348f669

2 files changed

Lines changed: 42 additions & 29 deletions

File tree

specs/Appearance.md

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,42 @@ Appearance (Theme) API
22
===
33

44
# 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 the dialogs, menus, and so on that WebView2 displays itself as well as the **something** of web content. 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.
5+
This API's main use is to set the overall appearance for WebView2. The options are similar to Edge: match the system default theme, change to light theme, or change to dark theme.
6+
This API has 2 main changes relevant to the end users. First, it sets appearance for WebView2 UI like dialogs, prompts, context menu, etc. And second, this API sets the ['prefers-color-scheme'](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme) [media feature](https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries#media_features). Websites typically media query for this setting in order to set CSS themes for light/dark.
157

8+
Please note this API will only set the overall appearance, but not theme.
9+
For reference, in the screenshot below, this API is meant to expose the Overall Appearance section as a WebView2 API.
1610

11+
![Alt text](.\media\EdgeSettingsAppearance.png "a title")
1712
# Examples
1813

1914
### C++
2015

2116
```cpp
22-
wil::com_ptr<ICoreWebView2StagingController2> webViewStagingController2;
23-
24-
bool ViewComponent::QuerySetAppearance(COREWEBVIEW2_APPEARANCE_TYPE appearance){
17+
18+
bool ViewComponent::SetAppearance(COREWEBVIEW2_APPEARANCE_KIND value)
19+
{
2520

21+
wil::com_ptr<ICoreWebView2StagingController2> webViewStagingController2;
22+
2623
m_appWindow->GetWebViewController()->QueryInterface(IID_PPV_ARGS(&webViewStagingController2));
2724
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);
25+
26+
webViewStagingController2->put_Appearance(value);
3527

3628
return true;
37-
}
29+
}
3830

3931
```
32+
### C#
4033
4134
```c#
4235
4336
private WebView2 m_webview;
4437
45-
void SetAppearance(COREWEBVIEW2_APPEARANCE_TYPE appearance)
38+
void SetAppearance(COREWEBVIEW2_APPEARANCE_KIND value)
4639
{
47-
m_webview.CoreWebView2Controller.put_Appearance(appearance);
40+
m_webview.CoreWebView2Controller.Appearance = value;
4841
}
4942
5043
```
@@ -53,20 +46,40 @@ void SetAppearance(COREWEBVIEW2_APPEARANCE_TYPE appearance)
5346

5447
```
5548
[uuid(5f817cce-5d36-4cd0-a1d5-aaaf95c8685f), object, pointer_default(unique)]
56-
interface ICoreWebView2StagingController2 : IUnknown {
49+
interface ICoreWebView2Controller4 : ICoreWebView2Controller3 {
5750
5851
/// The Appearance property sets the overall theme of the webview2 instance.
59-
/// The input parameter is either COREWEBVIEW2_APPEARANCE_TYPE_SYSTEM,
60-
/// COREWEBVIEW2_APPEARANCE_TYPE_LIGHT, or COREWEBVIEW2_APPEARANCE_TYPE_DARK.
61-
/// Note that this applies to pages, dialogs, and menus.
52+
/// The input parameter is either COREWEBVIEW2_APPEARANCE_KIND_SYSTEM,
53+
/// COREWEBVIEW2_APPEARANCE_KIND_LIGHT, or COREWEBVIEW2_APPEARANCE_KIND_DARK.
54+
/// Note that this API applies appearance to WebView2 pages, dialogs, menus,
55+
/// and sets the media feature `prefers-color-scheme` for websites to respond to.
6256
6357
/// Returns the value of the `Appearance` property.
6458
[propget] HRESULT Appearance(
65-
[out, retval] COREWEBVIEW2_APPEARANCE_TYPE* appearance);
59+
[out, retval] COREWEBVIEW2_APPEARANCE_KIND* value);
6660
6761
/// Sets the `Appearance` property.
6862
[propput] HRESULT Appearance(
69-
[in] COREWEBVIEW2_APPEARANCE_TYPE appearance);
63+
[in] COREWEBVIEW2_APPEARANCE_KIND value);
7064
7165
}
7266
```
67+
```
68+
69+
/// An enum to represent the options for WebView2 appearance: system, light, or dark.
70+
71+
[v1_enum]
72+
typedef enum COREWEBVIEW2_APPEARANCE_KIND {
73+
74+
/// System theme
75+
COREWEBVIEW2_APPEARANCE_KIND_SYSTEM,
76+
77+
/// Light theme
78+
COREWEBVIEW2_APPEARANCE_KIND_LIGHT,
79+
80+
/// Dark theme
81+
COREWEBVIEW2_APPEARANCE_KIND_DARK
82+
83+
} COREWEBVIEW2_APPEARANCE_KIND;
84+
85+
```
19.3 KB
Loading

0 commit comments

Comments
 (0)