Commit a3f39ec7 authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Add backend support for displaying/hiding PDF annotations.

Add message handling in the PDF plugin for displaying/hiding PDF
annotations and hook it up to PDFiumEngine, which already has support
for this feature.

Bug: 642982
Change-Id: I18f4dfb9aed4639936d9392a260289224f5dc1f9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2242793
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: default avatarDaniel Hosseinian <dhoss@chromium.org>
Cr-Commit-Position: refs/heads/master@{#778997}
parent 01891f83
...@@ -163,6 +163,9 @@ constexpr char kJSRotateCounterclockwiseType[] = "rotateCounterclockwise"; ...@@ -163,6 +163,9 @@ constexpr char kJSRotateCounterclockwiseType[] = "rotateCounterclockwise";
// Toggle two-up view (Page -> Plugin) // Toggle two-up view (Page -> Plugin)
constexpr char kJSSetTwoUpViewType[] = "setTwoUpView"; constexpr char kJSSetTwoUpViewType[] = "setTwoUpView";
constexpr char kJSEnableTwoUpView[] = "enableTwoUpView"; constexpr char kJSEnableTwoUpView[] = "enableTwoUpView";
// Display annotations (Page -> Plugin)
constexpr char kJSDisplayAnnotationsType[] = "displayAnnotations";
constexpr char kJSDisplayAnnotations[] = "display";
// Select all text in the document (Page -> Plugin) // Select all text in the document (Page -> Plugin)
constexpr char kJSSelectAllType[] = "selectAll"; constexpr char kJSSelectAllType[] = "selectAll";
// Get the selected text in the document (Page -> Plugin) // Get the selected text in the document (Page -> Plugin)
...@@ -565,6 +568,8 @@ void OutOfProcessInstance::HandleMessage(const pp::Var& message) { ...@@ -565,6 +568,8 @@ void OutOfProcessInstance::HandleMessage(const pp::Var& message) {
RotateCounterclockwise(); RotateCounterclockwise();
} else if (type == kJSSetTwoUpViewType) { } else if (type == kJSSetTwoUpViewType) {
HandleSetTwoUpViewMessage(dict); HandleSetTwoUpViewMessage(dict);
} else if (type == kJSDisplayAnnotationsType) {
HandleDisplayAnnotations(dict);
} else if (type == kJSSelectAllType) { } else if (type == kJSSelectAllType) {
engine_->SelectAll(); engine_->SelectAll();
} else if (type == kJSBackgroundColorChangedType) { } else if (type == kJSBackgroundColorChangedType) {
...@@ -1514,6 +1519,17 @@ void OutOfProcessInstance::HandleBackgroundColorChangedMessage( ...@@ -1514,6 +1519,17 @@ void OutOfProcessInstance::HandleBackgroundColorChangedMessage(
&background_color_); &background_color_);
} }
void OutOfProcessInstance::HandleDisplayAnnotations(
const pp::VarDictionary& dict) {
if (!dict.Get(pp::Var(kJSDisplayAnnotations)).is_bool()) {
NOTREACHED();
return;
}
engine_->DisplayAnnotations(
dict.Get(pp::Var(kJSDisplayAnnotations)).AsBool());
}
void OutOfProcessInstance::HandleGetNamedDestinationMessage( void OutOfProcessInstance::HandleGetNamedDestinationMessage(
const pp::VarDictionary& dict) { const pp::VarDictionary& dict) {
if (!dict.Get(pp::Var(kJSGetNamedDestination)).is_string()) { if (!dict.Get(pp::Var(kJSGetNamedDestination)).is_string()) {
......
...@@ -163,6 +163,7 @@ class OutOfProcessInstance : public pp::Instance, ...@@ -163,6 +163,7 @@ class OutOfProcessInstance : public pp::Instance,
private: private:
// Message handlers. // Message handlers.
void HandleBackgroundColorChangedMessage(const pp::VarDictionary& dict); void HandleBackgroundColorChangedMessage(const pp::VarDictionary& dict);
void HandleDisplayAnnotations(const pp::VarDictionary& dict);
void HandleGetNamedDestinationMessage(const pp::VarDictionary& dict); void HandleGetNamedDestinationMessage(const pp::VarDictionary& dict);
void HandleGetPasswordCompleteMessage(const pp::VarDictionary& dict); void HandleGetPasswordCompleteMessage(const pp::VarDictionary& dict);
void HandleGetSelectedTextMessage(); void HandleGetSelectedTextMessage();
......
...@@ -343,6 +343,7 @@ class PDFEngine { ...@@ -343,6 +343,7 @@ class PDFEngine {
virtual void RotateClockwise() = 0; virtual void RotateClockwise() = 0;
virtual void RotateCounterclockwise() = 0; virtual void RotateCounterclockwise() = 0;
virtual void SetTwoUpView(bool enable) = 0; virtual void SetTwoUpView(bool enable) = 0;
virtual void DisplayAnnotations(bool display) = 0;
// Applies the document layout options proposed by a call to // Applies the document layout options proposed by a call to
// PDFEngine::Client::ProposeDocumentLayout(), returning the overall size of // PDFEngine::Client::ProposeDocumentLayout(), returning the overall size of
......
...@@ -2008,6 +2008,14 @@ void PDFiumEngine::SetTwoUpView(bool enable) { ...@@ -2008,6 +2008,14 @@ void PDFiumEngine::SetTwoUpView(bool enable) {
ProposeNextDocumentLayout(); ProposeNextDocumentLayout();
} }
void PDFiumEngine::DisplayAnnotations(bool display) {
if (render_annots_ == display)
return;
render_annots_ = display;
InvalidateAllPages();
}
void PDFiumEngine::InvalidateAllPages() { void PDFiumEngine::InvalidateAllPages() {
CancelPaints(); CancelPaints();
StopFind(); StopFind();
......
...@@ -100,6 +100,7 @@ class PDFiumEngine : public PDFEngine, ...@@ -100,6 +100,7 @@ class PDFiumEngine : public PDFEngine,
void RotateClockwise() override; void RotateClockwise() override;
void RotateCounterclockwise() override; void RotateCounterclockwise() override;
void SetTwoUpView(bool enable) override; void SetTwoUpView(bool enable) override;
void DisplayAnnotations(bool display) override;
pp::Size ApplyDocumentLayout(const DocumentLayout::Options& options) override; pp::Size ApplyDocumentLayout(const DocumentLayout::Options& options) override;
std::string GetSelectedText() override; std::string GetSelectedText() override;
bool CanEditText() override; bool CanEditText() override;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment