0

[unseasoned-pdf] Implement Find-in-Page

The CL implements find-in-page for unseasoned pdf-viewer.
- Register `PdfViewWebPlugin` as a plugin find handler.
- Notify `WebPluginContainer` the status of find requests in plugin.
- Scroll tick marks are not implemented as part of this CL.

Bug: 1199999
Change-Id: Ib468769c29e67c9a498b5000bbef72fcffa4f252
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3000502
Commit-Queue: Ankit Kumar 🌪️ <ankk@microsoft.com>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#898095}
This commit is contained in:
Ankit Kumar 🌪️
2021-07-02 09:34:01 +00:00
committed by Chromium LUCI CQ
parent 7d5c2028a6
commit 98dd957e85
3 changed files with 55 additions and 5 deletions

@ -136,6 +136,16 @@ class BlinkContainerWrapper final : public PdfViewWebPlugin::ContainerWrapper {
void Invalidate() override { container_->Invalidate(); }
void ReportFindInPageMatchCount(int identifier,
int total,
bool final_update) override {
container_->ReportFindInPageMatchCount(identifier, total, final_update);
}
void ReportFindInPageSelection(int identifier, int index) override {
container_->ReportFindInPageSelection(identifier, index);
}
float DeviceScaleFactor() const override {
return container_->DeviceScaleFactor();
}
@ -233,6 +243,10 @@ bool PdfViewWebPlugin::InitializeCommon(
// TODO(crbug.com/1123621): Consider calling ValidateDocumentUrl() or
// something like it once the process model has been finalized.
// Allow the plugin to handle find requests.
if (container)
container->UsePluginAsFindHandler();
absl::optional<ParsedParams> params = ParseWebPluginParams(initial_params_);
// The contents of `initial_params_` are no longer needed.
@ -463,16 +477,19 @@ blink::WebURL PdfViewWebPlugin::LinkAtPosition(
bool PdfViewWebPlugin::StartFind(const blink::WebString& search_text,
bool case_sensitive,
int /*identifier*/) {
int identifier) {
find_identifier_ = identifier;
engine()->StartFind(search_text.Utf8(), case_sensitive);
return true;
}
void PdfViewWebPlugin::SelectFindResult(bool forward, int /*identifier*/) {
void PdfViewWebPlugin::SelectFindResult(bool forward, int identifier) {
find_identifier_ = identifier;
engine()->SelectFindResult(forward);
}
void PdfViewWebPlugin::StopFind() {
find_identifier_ = -1;
engine()->StopFind();
// TODO(crbug.com/1199999): Clear tickmarks on scroller when find is
// dismissed.
@ -490,9 +507,25 @@ void PdfViewWebPlugin::UpdateTickMarks(
const std::vector<gfx::Rect>& tickmarks) {}
void PdfViewWebPlugin::NotifyNumberOfFindResultsChanged(int total,
bool final_result) {}
bool final_result) {
// After stopping search and setting `find_identifier_` to -1 there still may
// be a NotifyNumberOfFindResultsChanged notification pending from engine.
// Just ignore them.
if (find_identifier_ == -1 || !container_wrapper_)
return;
container_wrapper_->ReportFindInPageMatchCount(find_identifier_, total,
final_result);
// TODO(crbug.com/1199999): Set tickmarks on scroller.
}
void PdfViewWebPlugin::NotifySelectedFindResultChanged(int current_find_index) {
if (find_identifier_ == -1 || !container_wrapper_)
return;
DCHECK_GE(current_find_index, -1);
container_wrapper_->ReportFindInPageSelection(find_identifier_,
current_find_index + 1);
}
void PdfViewWebPlugin::Alert(const std::string& message) {

@ -61,6 +61,15 @@ class PdfViewWebPlugin final : public PdfViewPluginBase,
// page in it.
virtual void Invalidate() = 0;
// Notify the web plugin container about the total matches of a find
// request.
virtual void ReportFindInPageMatchCount(int identifier,
int total,
bool final_update) = 0;
// Notify the web plugin container about the selected find result in plugin.
virtual void ReportFindInPageSelection(int identifier, int index) = 0;
// Returns the device scale factor.
virtual float DeviceScaleFactor() const = 0;
@ -155,8 +164,8 @@ class PdfViewWebPlugin final : public PdfViewPluginBase,
blink::WebURL LinkAtPosition(const gfx::Point& /*position*/) const override;
bool StartFind(const blink::WebString& search_text,
bool case_sensitive,
int /*identifier*/) override;
void SelectFindResult(bool forward, int /*identifier*/) override;
int identifier) override;
void SelectFindResult(bool forward, int identifier) override;
void StopFind() override;
blink::WebTextInputType GetPluginTextInputType() override;
@ -264,6 +273,10 @@ class PdfViewWebPlugin final : public PdfViewPluginBase,
blink::WebString selected_text_;
// The id of the current find operation, or -1 if no current operation is
// present.
int find_identifier_ = -1;
blink::WebTextInputType text_input_type_ =
blink::WebTextInputType::kWebTextInputTypeNone;

@ -92,6 +92,10 @@ class FakeContainerWrapper final : public PdfViewWebPlugin::ContainerWrapper {
// PdfViewWebPlugin::ContainerWrapper:
void Invalidate() override {}
MOCK_METHOD(void, ReportFindInPageMatchCount, (int, int, bool), (override));
MOCK_METHOD(void, ReportFindInPageSelection, (int, int), (override));
float DeviceScaleFactor() const override { return device_scale_; }
MOCK_METHOD(void,