Skip to content

Commit

Permalink
Edit mode is indicated in PDF viewer when form fields are modified.
Browse files Browse the repository at this point in the history
This change is gated by the kIsEditModeTracked flag in
pdfium_engine.cc. There should be no functional change yet as the
flag is off.

Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: Ibb6c266a0dbef1b168ef7f52d85ad4b5214ac639
Reviewed-on: https://chromium-review.googlesource.com/769491
Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
Reviewed-by: dsinclair <dsinclair@chromium.org>
Cr-Commit-Position: refs/heads/master@{#517448}
  • Loading branch information
Henrique Nakashima authored and Commit Bot committed Nov 17, 2017
1 parent 6b984fc commit c0ad413
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 2 deletions.
7 changes: 7 additions & 0 deletions chrome/browser/resources/pdf/pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,13 @@ PDFViewer.prototype = {
case 'setIsSelecting':
this.viewportScroller_.setEnableScrolling(message.data.isSelecting);
break;
case 'setIsEditMode':
// TODO(hnakashima): Replace this with final visual indication from UX.
if (message.data.isEditMode)
this.toolbar_.docTitle = document.title + ' (edit mode)';
else
this.toolbar_.docTitle = document.title;
break;
case 'getNamedDestinationReply':
this.paramsParser_.onNamedDestinationReceived(message.data.pageNumber);
break;
Expand Down
12 changes: 12 additions & 0 deletions pdf/out_of_process_instance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ const char kJSNamedDestinationPageNumber[] = "pageNumber";
const char kJSSetIsSelectingType[] = "setIsSelecting";
const char kJSIsSelecting[] = "isSelecting";

// Notify when the document was changed and edit mode is toggled.
const char kJSSetIsEditModeType[] = "setIsEditMode";
const char kJSIsEditMode[] = "isEditMode";

// Notify when a form field is focused (Plugin -> Page)
const char kJSFieldFocusType[] = "formFocusChange";
const char kJSFieldFocus[] = "focused";
Expand Down Expand Up @@ -580,6 +584,7 @@ void OutOfProcessInstance::HandleMessage(const pp::Var& message) {
} else if (type == kJSPrintType) {
Print();
} else if (type == kJSSaveType) {
engine_->KillFormFocus();
pp::PDF::SaveAs(this);
} else if (type == kJSRotateClockwiseType) {
RotateClockwise();
Expand Down Expand Up @@ -1745,6 +1750,13 @@ void OutOfProcessInstance::IsSelectingChanged(bool is_selecting) {
PrintPreviewHistogramEnumeration(SELECT_TEXT);
}

void OutOfProcessInstance::IsEditModeChanged(bool is_edit_mode) {
pp::VarDictionary message;
message.Set(kType, kJSSetIsEditModeType);
message.Set(kJSIsEditMode, pp::Var(is_edit_mode));
PostMessage(message);
}

void OutOfProcessInstance::ProcessPreviewPageInfo(const std::string& url,
int dest_page_index) {
DCHECK(IsPrintPreview());
Expand Down
1 change: 1 addition & 0 deletions pdf/out_of_process_instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ class OutOfProcessInstance : public pp::Instance,
void CancelBrowserDownload() override;
void IsSelectingChanged(bool is_selecting) override;
void SelectionChanged(const pp::Rect& left, const pp::Rect& right) override;
void IsEditModeChanged(bool is_edit_mode) override;

// PreviewModeClient::Client implementation.
void PreviewDocumentLoadComplete() override;
Expand Down
3 changes: 3 additions & 0 deletions pdf/pdf_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ class PDFEngine {

virtual void SelectionChanged(const pp::Rect& left, const pp::Rect& right) {
}

// Sets edit mode state.
virtual void IsEditModeChanged(bool is_edit_mode) {}
};

// Factory method to create an instance of the PDF Engine.
Expand Down
18 changes: 16 additions & 2 deletions pdf/pdfium/pdfium_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ constexpr base::TimeDelta kMaxProgressivePaintTime =
constexpr base::TimeDelta kMaxInitialProgressivePaintTime =
base::TimeDelta::FromMilliseconds(250);

// Flag to turn edit mode tracking on.
// Do not flip until form saving is completely functional.
constexpr bool kIsEditModeTracked = false;

PDFiumEngine* g_engine_for_fontmapper = nullptr;

std::vector<uint32_t> GetPageNumbersFromPrintPageNumberRange(
Expand Down Expand Up @@ -732,7 +736,8 @@ PDFiumEngine::PDFiumEngine(PDFEngine::Client* client)
most_visible_page_(-1),
called_do_document_action_(false),
render_grayscale_(false),
render_annots_(true) {
render_annots_(true),
edit_mode_(false) {
find_factory_.Initialize(this);
password_factory_.Initialize(this);

Expand Down Expand Up @@ -3920,6 +3925,14 @@ void PDFiumEngine::SetSelecting(bool selecting) {
client_->IsSelectingChanged(selecting);
}

void PDFiumEngine::SetEditMode(bool edit_mode) {
if (!kIsEditModeTracked || edit_mode_ == edit_mode)
return;

edit_mode_ = edit_mode;
client_->IsEditModeChanged(edit_mode_);
}

void PDFiumEngine::SetInFormTextArea(bool in_form_text_area) {
// If focus was previously in form text area, clear form text selection.
// Clearing needs to be done before changing focus to ensure the correct
Expand Down Expand Up @@ -4052,7 +4065,8 @@ FPDF_SYSTEMTIME PDFiumEngine::Form_GetLocalTime(FPDF_FORMFILLINFO* param) {
}

void PDFiumEngine::Form_OnChange(FPDF_FORMFILLINFO* param) {
// Don't care about.
PDFiumEngine* engine = static_cast<PDFiumEngine*>(param);
engine->SetEditMode(true);
}

FPDF_PAGE PDFiumEngine::Form_GetPage(FPDF_FORMFILLINFO* param,
Expand Down
5 changes: 5 additions & 0 deletions pdf/pdfium/pdfium_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,9 @@ class PDFiumEngine : public PDFEngine,
pp::VarDictionary TraverseBookmarks(FPDF_BOOKMARK bookmark,
unsigned int depth);

// Set if the document has any local edits.
void SetEditMode(bool edit_mode);

// FPDF_FORMFILLINFO callbacks.
static void Form_Invalidate(FPDF_FORMFILLINFO* param,
FPDF_PAGE page,
Expand Down Expand Up @@ -812,6 +815,8 @@ class PDFiumEngine : public PDFEngine,

pp::Point range_selection_base_;

bool edit_mode_;

DISALLOW_COPY_AND_ASSIGN(PDFiumEngine);
};

Expand Down

0 comments on commit c0ad413

Please sign in to comment.