0

Add PDFExtensionTest for opening context menu from touch selection menu

This CL adds a browser test for TouchSelectionMenu in PDF. There is no
utility class which could help in determining when touch selection menu
is opened. This CL adds TouchSelectionMenuWaiter() to determine when
touch selection menu is shown and helps in executing commands on the
touch selection menu.

Fix some nits in TouchSelectionMenuViews along the way.

Bug: 1027842
Change-Id: I9ce95ab2b697d474fedddec2777f75252f520d6f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2082750
Reviewed-by: Lei Zhang <thestig@chromium.org>
Reviewed-by: Alex Moshchuk <alexmos@chromium.org>
Reviewed-by: Peter Kasting <pkasting@chromium.org>
Commit-Queue: Ankit Kumar 🌪️ <ankk@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#764914}
This commit is contained in:
Ankit Kumar
2020-05-02 05:32:38 +00:00
committed by Commit Bot
parent 066fbf1c75
commit b64aca8258
14 changed files with 201 additions and 16 deletions

@ -117,6 +117,8 @@ constexpr char kJSDataToSave[] = "dataToSave";
constexpr char kJSHasUnsavedChanges[] = "hasUnsavedChanges";
// Consume save token (Plugin -> Page)
constexpr char kJSConsumeSaveTokenType[] = "consumeSaveToken";
// Notify when touch selection occurs (Plugin -> Page)
constexpr char kJSTouchSelectionOccurredType[] = "touchSelectionOccurred";
// Go to page (Plugin -> Page)
constexpr char kJSGoToPageType[] = "goToPage";
constexpr char kJSPageNumber[] = "page";
@ -1444,6 +1446,12 @@ void OutOfProcessInstance::NotifySelectedFindResultChanged(
SelectedFindResultChanged(current_find_index);
}
void OutOfProcessInstance::NotifyTouchSelectionOccurred() {
pp::VarDictionary message;
message.Set(kType, kJSTouchSelectionOccurredType);
PostMessage(message);
}
void OutOfProcessInstance::GetDocumentPassword(
pp::CompletionCallbackWithOutput<pp::Var> callback) {
if (password_callback_) {

@ -111,6 +111,7 @@ class OutOfProcessInstance : public pp::Instance,
void UpdateTickMarks(const std::vector<pp::Rect>& tickmarks) override;
void NotifyNumberOfFindResultsChanged(int total, bool final_result) override;
void NotifySelectedFindResultChanged(int current_find_index) override;
void NotifyTouchSelectionOccurred() override;
void GetDocumentPassword(
pp::CompletionCallbackWithOutput<pp::Var> callback) override;
void Beep() override;

@ -176,6 +176,8 @@ class PDFEngine {
// Updates the index of the currently selected search item.
virtual void NotifySelectedFindResultChanged(int current_find_index) {}
virtual void NotifyTouchSelectionOccurred() {}
// Prompts the user for a password to open this document. The callback is
// called when the password is retrieved.
virtual void GetDocumentPassword(

@ -1083,6 +1083,9 @@ void PDFiumEngine::OnMultipleClick(int click_count,
selection_.push_back(PDFiumRange(pages_[page_index].get(), start_index,
end_index - start_index));
if (handling_long_press_)
client_->NotifyTouchSelectionOccurred();
}
bool PDFiumEngine::OnLeftMouseDown(const pp::MouseInputEvent& event) {
@ -2330,6 +2333,7 @@ void PDFiumEngine::SetGrayscale(bool grayscale) {
}
void PDFiumEngine::HandleLongPress(const pp::TouchInputEvent& event) {
base::AutoReset<bool> handling_long_press_guard(&handling_long_press_, true);
pp::FloatPoint fp =
event.GetTouchByIndex(PP_TOUCHLIST_TYPE_TARGETTOUCHES, 0).position();
pp::Point point;

@ -702,6 +702,9 @@ class PDFiumEngine : public PDFEngine,
// Timer for touch long press detection.
base::OneShotTimer touch_timer_;
// Set to true when handling long touch press.
bool handling_long_press_ = false;
// The focus item type for the currently focused object.
FocusElementType focus_item_type_ = FocusElementType::kNone;