CefFindHandler
Header: cef_find_handler.h
Category: Browser Handlers
Overview
User-implemented handler interfaces returned from CefClient and registered with CefBrowserHost.
CefFindHandler
Source File: include/cef_find_handler.h
Process / Thread Context: Browser Process / UI Thread (class comment: "The
Purpose: User-implemented interface to handle events related to find
Methods
void OnFindResult(CefRefPtr<CefBrowser> browser, int identifier, int count, const CefRect& selectionRect, int activeMatchOrdinal, bool finalUpdate)
Parameters:
browser: The browser whose find result is being reported.identifier: Unique incremental identifier for the currently active search (matches theidentifierreturned byCefBrowserHost::Find).count: Number of matches currently identified.selectionRect: Location of the active match (in window coordinates).activeMatchOrdinal: The 1-based position of the currently active match within the result set.finalUpdate:trueif this is the last find notification for this search (socountandactiveMatchOrdinalare final).
Return Value: None.
Usage Instruction: Use to drive a find-in-page UI ("Match 3 of 27"). CEF calls this multiple times during a search as matches are progressively discovered; wait for finalUpdate == true before finalizing your UI counts.
Threading Constraint: Called on the UI thread.
Usage Example
cpp
#include "include/cef_find_handler.h"
#include "include/cef_browser.h"
#include "include/cef_client.h"
class MyFindHandler : public CefFindHandler {
public:
void OnFindResult(CefRefPtr<CefBrowser> browser,
int identifier,
int count,
const CefRect& selectionRect,
int activeMatchOrdinal,
bool finalUpdate) override {
// Update find UI: "Match {activeMatchOrdinal} of {count}".
if (finalUpdate) {
// Search complete for |identifier|; counts are final.
}
}
IMPLEMENT_REFCOUNTING(MyFindHandler);
};
class MyClient : public CefClient {
public:
CefRefPtr<CefFindHandler> GetFindHandler() override {
return new MyFindHandler();
}
// Elsewhere in the app:
// int identifier = browser->GetHost()->Find("search text", true, false, true);
// The handler above will receive OnFindResult callbacks for that identifier.
};