0

[unseasoned-pdf] Implement PdfViewWebPlugin::ExecuteEditCommand().

Implement PdfViewWebPlugin::ExecuteEditCommand() which is the
Pepper-free equivalents for PepperWebPluginImpl::ExecuteEditCommand().

Bug: 1204729
Change-Id: Idad14e734efab16797187bc746e820c1d15813f2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2874874
Reviewed-by: Daniel Hosseinian <dhoss@chromium.org>
Commit-Queue: Hui Yingst <nigi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#882395}
This commit is contained in:
Hui Yingst
2021-05-13 01:15:58 +00:00
committed by Chromium LUCI CQ
parent 7710c3f8f9
commit b074b224d9
2 changed files with 69 additions and 0 deletions

@ -342,6 +342,26 @@ bool PdfViewWebPlugin::CanRedo() const {
return engine()->CanRedo();
}
bool PdfViewWebPlugin::ExecuteEditCommand(const blink::WebString& name,
const blink::WebString& value) {
if (name == "SelectAll")
return SelectAll();
if (name == "Cut")
return Cut();
if (name == "Paste" || name == "PasteAndMatchStyle")
return Paste(value);
if (name == "Undo")
return Undo();
if (name == "Redo")
return Redo();
return false;
}
blink::WebTextInputType PdfViewWebPlugin::GetPluginTextInputType() {
return text_input_type_;
}
@ -574,4 +594,44 @@ void PdfViewWebPlugin::InvalidatePluginContainer() {
container_wrapper_->Invalidate();
}
bool PdfViewWebPlugin::SelectAll() {
if (!CanEditText())
return false;
engine()->SelectAll();
return true;
}
bool PdfViewWebPlugin::Cut() {
if (!HasSelection() || !CanEditText())
return false;
engine()->ReplaceSelection("");
return true;
}
bool PdfViewWebPlugin::Paste(const blink::WebString& value) {
if (!CanEditText())
return false;
engine()->ReplaceSelection(value.Utf8());
return true;
}
bool PdfViewWebPlugin::Undo() {
if (!CanUndo())
return false;
engine()->Undo();
return true;
}
bool PdfViewWebPlugin::Redo() {
if (!CanRedo())
return false;
engine()->Redo();
return true;
}
} // namespace chrome_pdf

@ -109,6 +109,8 @@ class PdfViewWebPlugin final : public PdfViewPluginBase,
bool HasEditableText() const override;
bool CanUndo() const override;
bool CanRedo() const override;
bool ExecuteEditCommand(const blink::WebString& name,
const blink::WebString& value) override;
blink::WebTextInputType GetPluginTextInputType() override;
// PdfViewPluginBase:
@ -198,6 +200,13 @@ class PdfViewWebPlugin final : public PdfViewPluginBase,
// page in it.
void InvalidatePluginContainer();
// Text editing methods.
bool SelectAll();
bool Cut();
bool Paste(const blink::WebString& value);
bool Undo();
bool Redo();
blink::WebString selected_text_;
blink::WebTextInputType text_input_type_ =