4
4
5
5
The WebView2Find API offers methods and events for text finding and navigation
6
6
within a WebView2 control. It enables developers to programmatically initiate find
7
- operations, navigate find results, suppress default UI, and customize find configurations
7
+ operations, navigate find results, suppress default UI, and customize find options
8
8
like query and find direction. It also tracks the status of operations, indicating
9
9
completion, match count changes, and match index changes.
10
10
@@ -26,34 +26,34 @@ completion, match count changes, and match index changes.
26
26
27
27
To initiate a find operation in a WebView2 control, use the ` StartFindAsync ` method.
28
28
This method allows setting the find term and find parameters via the
29
- ` ICoreWebView2FindConfiguration ` interface. Only one find session can be active per
30
- webview environment. Starting another with the same configuration will adjust
29
+ ` ICoreWebView2FindOptions ` interface. Only one find session can be active per
30
+ webview environment. Starting another with the same option will adjust
31
31
the active match index based on the selected Find Direction.
32
- ### Create/Specify a Find Configuration
32
+ ### Create/Specify a Find Option
33
33
#### WIN32 C++
34
34
35
35
``` cpp
36
36
37
- wil::com_ptr<ICoreWebView2FindConfiguration > AppWindow::InitializeFindConfiguration (const std::wstring& findTerm)
37
+ wil::com_ptr<ICoreWebView2FindOptions > AppWindow::InitializeFindOptions (const std::wstring& findTerm)
38
38
{
39
39
// Query for the ICoreWebView2Environment5 interface.
40
40
auto webView2Environment5 = m_webViewEnvironment.try_query<ICoreWebView2Environment5 >();
41
41
CHECK_FEATURE_RETURN(webView2Environment5);
42
42
43
- // Initialize find configuration/settings
44
- wil::com_ptr<ICoreWebView2FindConfiguration> findConfiguration ;
45
- CHECK_FAILURE(webView2Environment5->CreateFindConfiguration(&findConfiguration ));
46
- CHECK_FAILURE(findConfiguration ->put_FindTerm(findTerm.c_str()));
43
+ // Initialize find options
44
+ wil::com_ptr<ICoreWebView2FindOptions> find_options ;
45
+ CHECK_FAILURE(webView2Environment5->CreateFindOptions(&find_options ));
46
+ CHECK_FAILURE(find_options ->put_FindTerm(findTerm.c_str()));
47
47
48
- return findConfiguration ;
48
+ return find_options ;
49
49
}
50
50
```
51
51
52
52
```cpp
53
53
bool AppWindow::ConfigureAndExecuteFind(const std::wstring& findTerm)
54
54
{
55
- auto findConfiguration = InitializeFindConfiguration (findTerm);
56
- if (!findConfiguration )
55
+ auto find_options = InitializeFindOptions (findTerm);
56
+ if (!find_options )
57
57
{
58
58
return false;
59
59
}
@@ -70,7 +70,7 @@ bool AppWindow::ConfigureAndExecuteFind(const std::wstring& findTerm)
70
70
71
71
// Start the find operation with a callback for completion.
72
72
CHECK_FAILURE(webView2Find->StartFind(
73
- findConfiguration .get(),
73
+ find_options .get(),
74
74
Callback<ICoreWebView2FindOperationCompletedHandler>(
75
75
[this](HRESULT result, BOOL status) -> HRESULT
76
76
{
@@ -93,8 +93,8 @@ bool AppWindow::ConfigureAndExecuteFind(const std::wstring& findTerm)
93
93
``` cpp
94
94
bool AppWindow::ExecuteFindWithCustomUI (const std::wstring& findTerm)
95
95
{
96
- auto findConfiguration = InitializeFindConfiguration (findTerm);
97
- if (!findConfiguration )
96
+ auto find_options = InitializeFindOptions (findTerm);
97
+ if (!find_options )
98
98
{
99
99
return false;
100
100
}
@@ -111,7 +111,7 @@ bool AppWindow::ExecuteFindWithCustomUI(const std::wstring& findTerm)
111
111
112
112
// Start the find operation with callback for completion.
113
113
CHECK_FAILURE(webView2Find->StartFind(
114
- findConfiguration .get(),
114
+ find_options .get(),
115
115
Callback<ICoreWebView2FindOperationCompletedHandler>(
116
116
[this](HRESULT result, BOOL status) -> HRESULT
117
117
{
@@ -147,17 +147,17 @@ async Task ConfigureAndExecuteFindWithDefaultUIAsync(string findTerm)
147
147
throw new InvalidOperationException("WebView2 is not initialized.");
148
148
}
149
149
150
- // Initialize the find configuration with specified settings.
151
- var findConfiguration = new CoreWebView2FindConfiguration
150
+ // Initialize the find options with specified settings.
151
+ var find_options = new CoreWebView2FindOptions
152
152
{
153
153
FindTerm = findTerm
154
154
};
155
155
156
156
// By default Find will use the default UI and highlight all matches. If you want different behavior
157
157
// you can change the SuppressDefaultDialog and ShouldHighlightAllMatches properties here.
158
158
159
- // Start the find operation with the specified configuration .
160
- await webView.CoreWebView2.Find.StartFindAsync(findConfiguration );
159
+ // Start the find operation with the specified options .
160
+ await webView.CoreWebView2.Find.StartFindAsync(find_options );
161
161
162
162
// End user interaction is handled via UI.
163
163
}
@@ -180,8 +180,8 @@ async Task ConfigureAndExecuteFindWithCustomUIAsync(string findTerm)
180
180
throw new InvalidOperationException (" WebView2 is not initialized." );
181
181
}
182
182
183
- // Initialize the find configuration with specified settings .
184
- var findConfiguration = new CoreWebView2FindConfiguration
183
+ // Initialize the find options .
184
+ var find_options = new CoreWebView2FindOptions
185
185
{
186
186
FindTerm = findTerm
187
187
};
@@ -190,8 +190,8 @@ async Task ConfigureAndExecuteFindWithCustomUIAsync(string findTerm)
190
190
webView .CoreWebView2 .Find .SuppressDefaultDialog = true ;
191
191
webView .CoreWebView2 .Find .ShouldHighlightAllMatches = true ;
192
192
193
- // Start the find operation with the specified configuration .
194
- await webView .CoreWebView2 .Find .StartFindAsync (findConfiguration );
193
+ // Start the find operation with the specified options .
194
+ await webView .CoreWebView2 .Find .StartFindAsync (find_options );
195
195
// It's expected that the custom UI for navigating between matches (next, previous)
196
196
// and stopping the find operation will be managed by the developer's custom code.
197
197
}
@@ -275,16 +275,16 @@ typedef enum COREWEBVIEW2_FIND_DIRECTION {
275
275
276
276
277
277
// / Interface that provides methods related to the environment settings of CoreWebView2.
278
- // / This interface allows for the creation of new find configuration objects.
278
+ // / This interface allows for the creation of new find options objects.
279
279
// MSOWNERS: core ([email protected] )
280
280
[uuid(f10bddd3-bb59-5d5b-8748 -8a1a53f65d0c), object, pointer_default(unique)]
281
281
interface ICoreWebView2StagingEnvironment5 : IUnknown {
282
- /// Creates a new instance of a FindConfiguration object.
283
- /// This configuration object can be used to define parameters for a find operation.
284
- /// Returns the newly created FindConfiguration object.
282
+ /// Creates a new instance of a FindOptions object.
283
+ /// This options object can be used to define parameters for a find operation.
284
+ /// Returns the newly created FindOptions object.
285
285
// MSOWNERS: core (
[email protected] )
286
- HRESULT CreateFindConfiguration (
287
- [ out, retval] ICoreWebView2StagingFindConfiguration ** value
286
+ HRESULT CreateFindOptions (
287
+ [ out, retval] ICoreWebView2StagingFindOptions ** value
288
288
);
289
289
290
290
@@ -378,14 +378,14 @@ interface ICoreWebView2StagingFind : IUnknown {
378
378
[ in] EventRegistrationToken token);
379
379
380
380
381
- /// Initiates a find using the specified configuration .
381
+ /// Initiates a find using the specified find option .
382
382
/// Displays the Find bar and starts the find operation. If a find session was already ongoing, it will be stopped and replaced with this new instance.
383
- /// If called with an empty string, the Find bar is displayed but no finding occurs. Changing the configuration object after initiation won't affect the ongoing find session.
384
- /// To change the ongoing find session, StartFind must be called again with a new or modified configuration object.
383
+ /// If called with an empty string, the Find bar is displayed but no finding occurs. Changing the find options object after initiation won't affect the ongoing find session.
384
+ /// To change the ongoing find session, Start must be called again with a new or modified find options object.
385
385
/// This method is primarily designed for HTML document queries.
386
386
// MSOWNERS: core (
[email protected] )
387
387
HRESULT StartFind(
388
- [ in] ICoreWebView2StagingFindConfiguration * configuration
388
+ [ in] ICoreWebView2StagingFindOptions * options
389
389
, [ in] ICoreWebView2StagingFindStartFindCompletedHandler* handler
390
390
);
391
391
@@ -409,11 +409,11 @@ interface ICoreWebView2StagingFind : IUnknown {
409
409
410
410
411
411
412
- // / Interface defining the find configuration .
412
+ // / Interface defining the find options .
413
413
// / This interface provides the necessary methods and properties to configure a find operation.
414
414
// MSOWNERS: core ([email protected] )
415
415
[uuid(52a04b23-acc8-5659 -aa2f-26dbe9faafde), object, pointer_default(unique)]
416
- interface ICoreWebView2StagingFindConfiguration : IUnknown {
416
+ interface ICoreWebView2StagingFindOptions : IUnknown {
417
417
/// Gets the ` FindDirection ` property.
418
418
// MSOWNERS: core (
[email protected] )
419
419
[ propget] HRESULT FindDirection([ out, retval] COREWEBVIEW2_FIND_DIRECTION* value);
@@ -476,7 +476,7 @@ interface ICoreWebView2Staging17 : IUnknown {
476
476
```
477
477
478
478
479
- ### Setting Up Find Configuration with MIDL3
479
+ ### Setting Up Find Options with MIDL3
480
480
481
481
### CoreWebView2 Find Configuration and Direction
482
482
@@ -510,25 +510,25 @@ namespace Microsoft.Web.WebView2.Core
510
510
}
511
511
512
512
/// Interface that provides methods related to the environment settings of CoreWebView2.
513
- /// This interface allows for the creation of new find configuration objects.
513
+ /// This interface allows for the creation of new find options objects.
514
514
[com_interface (" staging=ICoreWebView2StagingEnvironment5" )]
515
515
[
ms_owner (
" core" ,
" [email protected] " )]
516
516
interface ICoreWebView2Environment15
517
517
{
518
- /// Creates a new instance of a CoreWebView2FindConfiguration object.
519
- /// This configuration object can be used to define parameters for a find operation.
520
- /// Returns the newly created FindConfiguration object.
521
- CoreWebView2FindConfiguration CreateFindConfiguration ();
518
+ /// Creates a new instance of a CoreWebView2FindOptions object.
519
+ /// This find options object can be used to define parameters for a find operation.
520
+ /// Returns the newly created FindOptions object.
521
+ CoreWebView2FindOptions CreateFindOptions ();
522
522
};
523
523
524
- runtimeclass CoreWebView2FindConfiguration : [default ]ICoreWebView2FindConfiguration {}
524
+ runtimeclass CoreWebView2FindOptions : [default ]ICoreWebView2FindOptions {}
525
525
526
- /// Interface defining the find configuration .
526
+ /// Interface defining the find options .
527
527
/// This interface provides the necessary methods and properties to configure a find operation.
528
- [com_interface (" staging=ICoreWebView2StagingFindConfiguration " )]
528
+ [com_interface (" staging=ICoreWebView2StagingFindOptions " )]
529
529
[
ms_owner (
" core" ,
" [email protected] " )]
530
530
[availability (" staging" )]
531
- interface ICoreWebView2FindConfiguration
531
+ interface ICoreWebView2FindOptions
532
532
{
533
533
/// Gets or sets the find term used for the find operation. Returns the find term.
534
534
String FindTerm { get ; set ; };
@@ -574,10 +574,10 @@ runtimeclass CoreWebView2FindConfiguration : [default]ICoreWebView2FindConfigura
574
574
interface ICoreWebView2Find
575
575
{
576
576
[completed_handler (" " )]
577
- /// Initiates a find using the specified configuration asynchronously.
577
+ /// Initiates a find using the specified options asynchronously.
578
578
/// Displays the Find bar and starts the find operation. If a find session was already ongoing, it will be stopped and replaced with this new instance.
579
- /// If called with an empty string, the Find bar is displayed but no finding occurs. Changing the configuration object after initiation won't affect the ongoing find session.
580
- /// To change the ongoing find session, StartFindAsync must be called again with a new or modified configuration object.
579
+ /// If called with an empty string, the Find bar is displayed but no finding occurs. Changing the find options object after initiation won't affect the ongoing find session.
580
+ /// To change the ongoing find session, StartFindAsync must be called again with a new or modified find options object.
581
581
/// StartFind supports, HTML, PDF, and TXT document queries. In general this api is designed for text based find sessions.
582
582
// // If you start a find session programmatically on another file format that doesnt have text fields, the find session will try to execute but will fail to find any matches. (It will silently fail)
583
583
// / Note: The asynchronous action completes when the UI has been displayed with the find term in the UI bar, and the matches have populated on the counter on the find bar.
@@ -591,7 +591,7 @@ runtimeclass CoreWebView2FindConfiguration : [default]ICoreWebView2FindConfigura
591
591
// / regardless of the previous active match. This behavior indicates that changing the find query initiates a
592
592
// / completely new find session, rather than continuing from the previous match index. This distinction is essential
593
593
// / to understand when utilizing the StartFind method for navigating through text matches.
594
- Windows.Foundation.IAsyncAction StartFindAsync (CoreWebView2FindConfiguration configuration );
594
+ Windows.Foundation.IAsyncAction StartFindAsync (CoreWebView2FindOptions options );
595
595
596
596
597
597
/// Navigates to the next match in the document.
@@ -643,6 +643,6 @@ runtimeclass CoreWebView2FindConfiguration : [default]ICoreWebView2FindConfigura
643
643
This API specification focuses on providing developers with the necessary information
644
644
to integrate text finding and navigation functionalities into WebView2 applications.
645
645
It emphasizes the usage of interfaces such as ` ICoreWebView2Find ` and
646
- ` ICoreWebView2FindConfiguration ` to perform find operations effectively.
646
+ ` ICoreWebView2FindOptions ` to perform find operations effectively.
647
647
648
648
0 commit comments