Skip to content

Commit ea8962a

Browse files
style fixes
1 parent 19cbe85 commit ea8962a

1 file changed

Lines changed: 31 additions & 29 deletions

File tree

specs/Appearance.md

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,77 +2,76 @@ Theme API
22
===
33

44
# Background
5-
This API's main use is to set the overall appearance/theme 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.
5+
This API's main use is to set the overall appearance/theme 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.
77

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

1111
![Alt text](./media/EdgeSettingsAppearance.png "a title")
1212
# Examples
1313

14-
### C++
14+
## C++
1515

1616
```cpp
17+
wil::com_ptr<ICoreWebView2Controller> m_controller;
1718

1819
void ViewComponent::SetTheme(COREWEBVIEW2_THEME_KIND value)
1920
{
20-
21-
wil::com_ptr<ICoreWebView2Controller4> webViewController4;
21+
wil::com_ptr<ICoreWebView2Controller4> m_controller;
2222

23-
m_appWindow->GetWebViewController()->QueryInterface(IID_PPV_ARGS(&webViewController4));
23+
CHECK_FAILURE(m_controller->QueryInterface(IID_PPV_ARGS(&webViewController4)));
2424
if (webViewController4)
2525
{
2626
CHECK_FAILURE(webViewController4->put_Theme(value));
2727
}
2828
}
29-
3029
```
31-
### C#
30+
31+
## C#
3232
3333
```c#
3434
3535
private CoreWebView2Controller m_controller;
3636
3737
void SetTheme(CoreWebView2ThemeKind value)
3838
{
39+
// Check for runtime support
3940
try
4041
{
4142
m_controller.Theme = value;
4243
}
43-
catch (Exception)
44+
catch (NotImplementedException exception)
4445
{
45-
// if theme api isnt supported in CoreWebView2Controller ignore the call.
46+
MessageBox.Show(this, "Set Theme Failed: " + exception.Message,
47+
"Set Theme");
4648
}
4749
}
48-
50+
4951
```
5052

5153
# API Details
52-
54+
## C++
5355
```
5456
[uuid(5f817cce-5d36-4cd0-a1d5-aaaf95c8685f), object, pointer_default(unique)]
5557
interface ICoreWebView2Controller4 : ICoreWebView2Controller3 {
56-
57-
/// The Theme property sets the overall theme of the webview2 instance.
58-
/// The input parameter is either COREWEBVIEW2_THEME_KIND_SYSTEM,
58+
/// The Theme property sets the overall theme of the WebView2 instance.
59+
/// The input parameter is either COREWEBVIEW2_THEME_KIND_SYSTEM,
5960
/// COREWEBVIEW2_THEME_KIND_LIGHT, or COREWEBVIEW2_THEME_KIND_DARK.
6061
/// Note that this API applies theme to WebView2 pages, dialogs, menus,
61-
/// and sets the media feature `prefers-color-scheme` for websites to respond to.
62-
63-
/// Returns the value of the `Theme` property.
62+
/// and sets the media feature `prefers-color-scheme` for websites to respond to.
63+
///
64+
/// \snippet ViewComponents.cpp SetAppearance
65+
/// Returns the value of the `Appearance` property.
6466
[propget] HRESULT Theme(
65-
[out, retval] COREWEBVIEW2_THEME_KIND* value);
67+
[out, retval] COREWEBVIEW2_THEME_KIND* value);
6668
6769
/// Sets the `Theme` property.
6870
[propput] HRESULT Theme(
6971
[in] COREWEBVIEW2_THEME_KIND value);
70-
7172
}
72-
```
73-
```
74-
/// An enum to represent the options for WebView2 Theme: system, light, or dark.
7573
74+
/// An enum to represent the options for WebView2 Theme: system, light, or dark.
7675
[v1_enum]
7776
typedef enum COREWEBVIEW2_THEME_KIND {
7877
@@ -86,28 +85,31 @@ typedef enum COREWEBVIEW2_THEME_KIND {
8685
COREWEBVIEW2_THEME_KIND_DARK
8786
8887
} COREWEBVIEW2_THEME_KIND;
89-
9088
```
9189

92-
### WinRT
90+
### C#
9391
```
9492
namespace Microsoft.Web.WebView2.Core
9593
{
94+
[doc_string("An enum to represent the options for WebView2 Theme: system, light, or dark.")]
9695
enum CoreWebView2ThemeKind
9796
{
97+
[doc_string("System theme.")]
9898
System = 0,
99+
[doc_string("Light theme.")]
99100
Light = 1,
101+
[doc_string("Dark theme.")]
100102
Dark = 2,
101103
};
102-
104+
103105
unsealed runtimeclass CoreWebView2Controller
104106
{
105-
//...
107+
// ...
108+
106109
[interface_name("Microsoft.Web.WebView2.Core.ICoreWebView2Controller4")]
107110
{
108111
// ICoreWebView2Controller4 members
109112
CoreWebView2ThemeKind Theme { get; set; };
110-
111113
}
112114
}
113115
}

0 commit comments

Comments
 (0)