Commit 86cd4c56 authored by Ankit Kumar's avatar Ankit Kumar Committed by Commit Bot

Rename last_page_mouse_down_ to last_focused_page_ in PDFiumEngine

This CL renames |PDFiumEngine::last_page_mouse_down_| to
|PDFiumEngine::last_focused_page_|. This is part of a larger effort to
make focus move from one page to the next on a tab event.

Bug: 989040
Change-Id: I22cab91bb4965afaeae1755b51c11d88f69aeafc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2060444
Commit-Queue: Ankit Kumar 🌪️ <ankk@microsoft.com>
Reviewed-by: default avatarKevin Babbitt <kbabbitt@microsoft.com>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#758070}
parent 4452c67d
...@@ -1056,7 +1056,7 @@ bool PDFiumEngine::OnLeftMouseDown(const pp::MouseInputEvent& event) { ...@@ -1056,7 +1056,7 @@ bool PDFiumEngine::OnLeftMouseDown(const pp::MouseInputEvent& event) {
return true; return true;
if (page_index != -1) { if (page_index != -1) {
last_page_mouse_down_ = page_index; last_focused_page_ = page_index;
double page_x; double page_x;
double page_y; double page_y;
DeviceToPage(page_index, point, &page_x, &page_y); DeviceToPage(page_index, point, &page_x, &page_y);
...@@ -1328,8 +1328,8 @@ bool PDFiumEngine::OnMouseMove(const pp::MouseInputEvent& event) { ...@@ -1328,8 +1328,8 @@ bool PDFiumEngine::OnMouseMove(const pp::MouseInputEvent& event) {
// If in form text area while left mouse button is held down, check if form // If in form text area while left mouse button is held down, check if form
// text selection needs to be updated. // text selection needs to be updated.
if (mouse_left_button_down_ && area == PDFiumPage::FORM_TEXT_AREA && if (mouse_left_button_down_ && area == PDFiumPage::FORM_TEXT_AREA &&
last_page_mouse_down_ != -1) { last_focused_page_ != -1) {
SetFormSelectedText(form(), pages_[last_page_mouse_down_]->GetPage()); SetFormSelectedText(form(), pages_[last_focused_page_]->GetPage());
} }
if (kViewerImplementedPanning && mouse_middle_button_down_) { if (kViewerImplementedPanning && mouse_middle_button_down_) {
...@@ -1479,10 +1479,10 @@ bool PDFiumEngine::ExtendSelection(int page_index, int char_index) { ...@@ -1479,10 +1479,10 @@ bool PDFiumEngine::ExtendSelection(int page_index, int char_index) {
} }
bool PDFiumEngine::OnKeyDown(const pp::KeyboardInputEvent& event) { bool PDFiumEngine::OnKeyDown(const pp::KeyboardInputEvent& event) {
if (last_page_mouse_down_ == -1) if (last_focused_page_ == -1)
return false; return false;
bool rv = !!FORM_OnKeyDown(form(), pages_[last_page_mouse_down_]->GetPage(), bool rv = !!FORM_OnKeyDown(form(), pages_[last_focused_page_]->GetPage(),
event.GetKeyCode(), event.GetModifiers()); event.GetKeyCode(), event.GetModifiers());
if (event.GetKeyCode() == ui::VKEY_BACK || if (event.GetKeyCode() == ui::VKEY_BACK ||
...@@ -1502,11 +1502,11 @@ bool PDFiumEngine::OnKeyDown(const pp::KeyboardInputEvent& event) { ...@@ -1502,11 +1502,11 @@ bool PDFiumEngine::OnKeyDown(const pp::KeyboardInputEvent& event) {
} }
bool PDFiumEngine::OnKeyUp(const pp::KeyboardInputEvent& event) { bool PDFiumEngine::OnKeyUp(const pp::KeyboardInputEvent& event) {
if (last_page_mouse_down_ == -1) if (last_focused_page_ == -1)
return false; return false;
// Check if form text selection needs to be updated. // Check if form text selection needs to be updated.
FPDF_PAGE page = pages_[last_page_mouse_down_]->GetPage(); FPDF_PAGE page = pages_[last_focused_page_]->GetPage();
if (in_form_text_area_) if (in_form_text_area_)
SetFormSelectedText(form(), page); SetFormSelectedText(form(), page);
...@@ -1514,11 +1514,11 @@ bool PDFiumEngine::OnKeyUp(const pp::KeyboardInputEvent& event) { ...@@ -1514,11 +1514,11 @@ bool PDFiumEngine::OnKeyUp(const pp::KeyboardInputEvent& event) {
} }
bool PDFiumEngine::OnChar(const pp::KeyboardInputEvent& event) { bool PDFiumEngine::OnChar(const pp::KeyboardInputEvent& event) {
if (last_page_mouse_down_ == -1) if (last_focused_page_ == -1)
return false; return false;
base::string16 str = base::UTF8ToUTF16(event.GetCharacterText().AsString()); base::string16 str = base::UTF8ToUTF16(event.GetCharacterText().AsString());
return !!FORM_OnChar(form(), pages_[last_page_mouse_down_]->GetPage(), str[0], return !!FORM_OnChar(form(), pages_[last_focused_page_]->GetPage(), str[0],
event.GetModifiers()); event.GetModifiers());
} }
...@@ -1953,45 +1953,45 @@ bool PDFiumEngine::CanEditText() { ...@@ -1953,45 +1953,45 @@ bool PDFiumEngine::CanEditText() {
bool PDFiumEngine::HasEditableText() { bool PDFiumEngine::HasEditableText() {
DCHECK(CanEditText()); DCHECK(CanEditText());
if (last_page_mouse_down_ == -1) if (last_focused_page_ == -1)
return false; return false;
FPDF_PAGE page = pages_[last_page_mouse_down_]->GetPage(); FPDF_PAGE page = pages_[last_focused_page_]->GetPage();
// If the return value is 2, that corresponds to "\0\0". // If the return value is 2, that corresponds to "\0\0".
return FORM_GetFocusedText(form(), page, nullptr, 0) > 2; return FORM_GetFocusedText(form(), page, nullptr, 0) > 2;
} }
void PDFiumEngine::ReplaceSelection(const std::string& text) { void PDFiumEngine::ReplaceSelection(const std::string& text) {
DCHECK(CanEditText()); DCHECK(CanEditText());
if (last_page_mouse_down_ != -1) { if (last_focused_page_ != -1) {
base::string16 text_wide = base::UTF8ToUTF16(text); base::string16 text_wide = base::UTF8ToUTF16(text);
FPDF_WIDESTRING text_pdf_wide = FPDF_WIDESTRING text_pdf_wide =
reinterpret_cast<FPDF_WIDESTRING>(text_wide.c_str()); reinterpret_cast<FPDF_WIDESTRING>(text_wide.c_str());
FORM_ReplaceSelection(form(), pages_[last_page_mouse_down_]->GetPage(), FORM_ReplaceSelection(form(), pages_[last_focused_page_]->GetPage(),
text_pdf_wide); text_pdf_wide);
} }
} }
bool PDFiumEngine::CanUndo() { bool PDFiumEngine::CanUndo() {
if (last_page_mouse_down_ == -1) if (last_focused_page_ == -1)
return false; return false;
return !!FORM_CanUndo(form(), pages_[last_page_mouse_down_]->GetPage()); return !!FORM_CanUndo(form(), pages_[last_focused_page_]->GetPage());
} }
bool PDFiumEngine::CanRedo() { bool PDFiumEngine::CanRedo() {
if (last_page_mouse_down_ == -1) if (last_focused_page_ == -1)
return false; return false;
return !!FORM_CanRedo(form(), pages_[last_page_mouse_down_]->GetPage()); return !!FORM_CanRedo(form(), pages_[last_focused_page_]->GetPage());
} }
void PDFiumEngine::Undo() { void PDFiumEngine::Undo() {
if (last_page_mouse_down_ != -1) if (last_focused_page_ != -1)
FORM_Undo(form(), pages_[last_page_mouse_down_]->GetPage()); FORM_Undo(form(), pages_[last_focused_page_]->GetPage());
} }
void PDFiumEngine::Redo() { void PDFiumEngine::Redo() {
if (last_page_mouse_down_ != -1) if (last_focused_page_ != -1)
FORM_Redo(form(), pages_[last_page_mouse_down_]->GetPage()); FORM_Redo(form(), pages_[last_focused_page_]->GetPage());
} }
void PDFiumEngine::HandleAccessibilityAction( void PDFiumEngine::HandleAccessibilityAction(
...@@ -2690,11 +2690,11 @@ void PDFiumEngine::CalculateVisiblePages() { ...@@ -2690,11 +2690,11 @@ void PDFiumEngine::CalculateVisiblePages() {
pages_[i]->Unload(); pages_[i]->Unload();
} }
// If the last mouse down was on a page that's no longer visible, reset // If the last focused page was a page that's no longer visible, reset
// that variable so that we don't send keyboard events to it (the focus // that variable so that we don't send keyboard events to it (the focus
// will be lost when the page is first closed anyways). // will be lost when the page is first closed anyways).
if (static_cast<int>(i) == last_page_mouse_down_) if (static_cast<int>(i) == last_focused_page_)
last_page_mouse_down_ = -1; last_focused_page_ = -1;
} }
} }
......
...@@ -681,8 +681,9 @@ class PDFiumEngine : public PDFEngine, ...@@ -681,8 +681,9 @@ class PDFiumEngine : public PDFEngine,
// Timer for touch long press detection. // Timer for touch long press detection.
base::OneShotTimer touch_timer_; base::OneShotTimer touch_timer_;
// Holds the zero-based page index of the last page that the mouse clicked on. // Holds the zero-based page index of the last page that had the focused
int last_page_mouse_down_ = -1; // object.
int last_focused_page_ = -1;
// Holds the zero-based page index of the most visible page; refreshed by // Holds the zero-based page index of the most visible page; refreshed by
// calling CalculateVisiblePages() // calling CalculateVisiblePages()
......
...@@ -207,7 +207,7 @@ FPDF_PAGE PDFiumFormFiller::Form_GetPage(FPDF_FORMFILLINFO* param, ...@@ -207,7 +207,7 @@ FPDF_PAGE PDFiumFormFiller::Form_GetPage(FPDF_FORMFILLINFO* param,
FPDF_PAGE PDFiumFormFiller::Form_GetCurrentPage(FPDF_FORMFILLINFO* param, FPDF_PAGE PDFiumFormFiller::Form_GetCurrentPage(FPDF_FORMFILLINFO* param,
FPDF_DOCUMENT document) { FPDF_DOCUMENT document) {
PDFiumEngine* engine = GetEngine(param); PDFiumEngine* engine = GetEngine(param);
int index = engine->last_page_mouse_down_; int index = engine->last_focused_page_;
if (index == -1) { if (index == -1) {
index = engine->GetMostVisiblePage(); index = engine->GetMostVisiblePage();
if (index == -1) { if (index == -1) {
...@@ -235,7 +235,7 @@ void PDFiumFormFiller::Form_ExecuteNamedAction(FPDF_FORMFILLINFO* param, ...@@ -235,7 +235,7 @@ void PDFiumFormFiller::Form_ExecuteNamedAction(FPDF_FORMFILLINFO* param,
return; return;
} }
int index = engine->last_page_mouse_down_; int index = engine->last_focused_page_;
/* Don't try to calculate the most visible page if we don't have a left click /* Don't try to calculate the most visible page if we don't have a left click
before this event (this code originally copied Form_GetCurrentPage which of before this event (this code originally copied Form_GetCurrentPage which of
course needs to do that and which doesn't have recursion). This can end up course needs to do that and which doesn't have recursion). This can end up
......
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