Skip to content

Commit

Permalink
Use chrome_pdf::Timer within PDFiumEngine.
Browse files Browse the repository at this point in the history
Change-Id: Ic73c423813ef2a9ca095c5ce99fff2f769aa9556
Reviewed-on: https://chromium-review.googlesource.com/1094442
Commit-Queue: Art Snake <[email protected]>
Reviewed-by: dsinclair <[email protected]>
Cr-Commit-Position: refs/heads/master@{#566897}
  • Loading branch information
art-snake authored and Commit Bot committed Jun 13, 2018
1 parent 599a9e3 commit 444fcaa
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 45 deletions.
12 changes: 0 additions & 12 deletions pdf/out_of_process_instance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1235,10 +1235,6 @@ void OutOfProcessInstance::DidOpenPreview(int32_t result) {
}
}

void OutOfProcessInstance::OnClientTouchTimerFired(int32_t id) {
engine_->OnTouchTimerCallback(id);
}

void OutOfProcessInstance::CalculateBackgroundParts() {
background_parts_.clear();
int left_width = available_area_.x();
Expand Down Expand Up @@ -1562,14 +1558,6 @@ pp::URLLoader OutOfProcessInstance::CreateURLLoader() {
return CreateURLLoaderInternal();
}

void OutOfProcessInstance::ScheduleTouchTimerCallback(int id,
base::TimeDelta delay) {
pp::CompletionCallback callback = callback_factory_.NewCallback(
&OutOfProcessInstance::OnClientTouchTimerFired);
pp::Module::Get()->core()->CallOnMainThread(delay.InMilliseconds(), callback,
id);
}

std::vector<PDFEngine::Client::SearchStringResult>
OutOfProcessInstance::SearchString(const base::char16* string,
const base::char16* term,
Expand Down
4 changes: 0 additions & 4 deletions pdf/out_of_process_instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,6 @@ class OutOfProcessInstance : public pp::Instance,
void DidOpen(int32_t result);
void DidOpenPreview(int32_t result);

// Called when the timer is fired.
void OnClientTouchTimerFired(int32_t id);

// Called to print without re-entrancy issues.
void OnPrint(int32_t);

Expand Down Expand Up @@ -135,7 +132,6 @@ class OutOfProcessInstance : public pp::Instance,
const void* data,
int length) override;
pp::URLLoader CreateURLLoader() override;
void ScheduleTouchTimerCallback(int id, base::TimeDelta delay) override;
std::vector<SearchStringResult> SearchString(const base::char16* string,
const base::char16* term,
bool case_sensitive) override;
Expand Down
6 changes: 0 additions & 6 deletions pdf/pdf_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,6 @@ class PDFEngine {
// Creates and returns new URL loader for partial document requests.
virtual pp::URLLoader CreateURLLoader() = 0;

// Calls the client's OnTouchTimerCallback() function in |delay| with the
// given |id|.
virtual void ScheduleTouchTimerCallback(int id, base::TimeDelta delay) {}

// Searches the given string for "term" and returns the results. Unicode-
// aware.
struct SearchStringResult {
Expand Down Expand Up @@ -361,8 +357,6 @@ class PDFEngine {
virtual int GetVerticalScrollbarYPosition() = 0;
// Set color / grayscale rendering modes.
virtual void SetGrayscale(bool grayscale) = 0;
// Callback for timer that's set with ScheduleTouchTimerCallback().
virtual void OnTouchTimerCallback(int id) = 0;
// Get the number of characters on a given page.
virtual int GetCharCount(int page_index) = 0;
// Get the bounds in page pixels of a character on a given page.
Expand Down
31 changes: 17 additions & 14 deletions pdf/pdfium/pdfium_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,18 @@ void ShutdownSDK() {
TearDownV8();
}

PDFiumEngine::TouchTimer::TouchTimer(PDFiumEngine* engine,
int id,
const pp::TouchInputEvent& event)
: Timer(kTouchLongPressTimeout), engine_(engine), id_(id), event_(event) {}

PDFiumEngine::TouchTimer::~TouchTimer() = default;

void PDFiumEngine::TouchTimer::OnTimer() {
engine_->HandleLongPress(event_);
engine_->KillTouchTimer(id_);
}

std::unique_ptr<PDFEngine> PDFEngine::Create(PDFEngine::Client* client,
bool enable_javascript) {
return std::make_unique<PDFiumEngine>(client, enable_javascript);
Expand Down Expand Up @@ -1087,20 +1099,20 @@ bool PDFiumEngine::HandleEvent(const pp::InputEvent& event) {
rv = OnChar(pp::KeyboardInputEvent(event));
break;
case PP_INPUTEVENT_TYPE_TOUCHSTART: {
KillTouchTimer(next_touch_timer_id_);
KillTouchTimer(last_touch_timer_id_);

pp::TouchInputEvent touch_event(event);
if (touch_event.GetTouchCount(PP_TOUCHLIST_TYPE_TARGETTOUCHES) == 1)
ScheduleTouchTimer(touch_event);
break;
}
case PP_INPUTEVENT_TYPE_TOUCHEND:
KillTouchTimer(next_touch_timer_id_);
KillTouchTimer(last_touch_timer_id_);
break;
case PP_INPUTEVENT_TYPE_TOUCHMOVE:
// TODO(dsinclair): This should allow a little bit of movement (up to the
// touch radii) to account for finger jiggle.
KillTouchTimer(next_touch_timer_id_);
KillTouchTimer(last_touch_timer_id_);
break;
default:
break;
Expand Down Expand Up @@ -2370,14 +2382,6 @@ void PDFiumEngine::SetGrayscale(bool grayscale) {
render_grayscale_ = grayscale;
}

void PDFiumEngine::OnTouchTimerCallback(int id) {
if (!touch_timers_.count(id))
return;

HandleLongPress(touch_timers_[id]);
KillTouchTimer(id);
}

void PDFiumEngine::HandleLongPress(const pp::TouchInputEvent& event) {
pp::FloatPoint fp =
event.GetTouchByIndex(PP_TOUCHLIST_TYPE_TARGETTOUCHES, 0).position();
Expand Down Expand Up @@ -3507,9 +3511,8 @@ bool PDFiumEngine::IsPointInEditableFormTextArea(FPDF_PAGE page,
}

void PDFiumEngine::ScheduleTouchTimer(const pp::TouchInputEvent& evt) {
touch_timers_[++next_touch_timer_id_] = evt;
client_->ScheduleTouchTimerCallback(next_touch_timer_id_,
kTouchLongPressTimeout);
const int timer_id = ++last_touch_timer_id_;
touch_timers_[timer_id] = std::make_unique<TouchTimer>(this, timer_id, evt);
}

void PDFiumEngine::KillTouchTimer(int timer_id) {
Expand Down
20 changes: 17 additions & 3 deletions pdf/pdfium/pdfium_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "pdf/pdfium/pdfium_page.h"
#include "pdf/pdfium/pdfium_print.h"
#include "pdf/pdfium/pdfium_range.h"
#include "pdf/timer.h"
#include "ppapi/cpp/completion_callback.h"
#include "ppapi/cpp/dev/buffer_dev.h"
#include "ppapi/cpp/image_data.h"
Expand Down Expand Up @@ -103,7 +104,6 @@ class PDFiumEngine : public PDFEngine,
pp::Rect GetPageScreenRect(int page_index) const override;
int GetVerticalScrollbarYPosition() override;
void SetGrayscale(bool grayscale) override;
void OnTouchTimerCallback(int id) override;
int GetCharCount(int page_index) override;
pp::FloatRect GetCharBounds(int page_index, int char_index) override;
uint32_t GetCharUnicode(int page_index, int char_index) override;
Expand Down Expand Up @@ -146,6 +146,20 @@ class PDFiumEngine : public PDFEngine,
FPDF_FORMHANDLE form() const { return form_.get(); }

private:
class TouchTimer : public Timer {
public:
TouchTimer(PDFiumEngine* engine, int id, const pp::TouchInputEvent& event);
~TouchTimer() override;

// Timer overrides:
void OnTimer() override;

private:
PDFiumEngine* engine_;
const int id_;
const pp::TouchInputEvent event_;
};

// This helper class is used to detect the difference in selection between
// construction and destruction. At destruction, it invalidates all the
// parts that are newly selected, along with all the parts that used to be
Expand Down Expand Up @@ -606,8 +620,8 @@ class PDFiumEngine : public PDFEngine,
pp::Size default_page_size_;

// Used to manage timers for touch long press.
std::map<int, pp::TouchInputEvent> touch_timers_;
int next_touch_timer_id_ = 0;
std::map<int, std::unique_ptr<TouchTimer>> touch_timers_;
int last_touch_timer_id_ = 0;

// Holds the zero-based page index of the last page that the mouse clicked on.
int last_page_mouse_down_ = -1;
Expand Down
5 changes: 0 additions & 5 deletions pdf/preview_mode_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,6 @@ pp::URLLoader PreviewModeClient::CreateURLLoader() {
return pp::URLLoader();
}

void PreviewModeClient::ScheduleTouchTimerCallback(int id,
base::TimeDelta delay) {
NOTREACHED();
}

std::vector<PDFEngine::Client::SearchStringResult>
PreviewModeClient::SearchString(const base::char16* string,
const base::char16* term,
Expand Down
1 change: 0 additions & 1 deletion pdf/preview_mode_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ class PreviewModeClient : public PDFEngine::Client {
const void* data,
int length) override;
pp::URLLoader CreateURLLoader() override;
void ScheduleTouchTimerCallback(int id, base::TimeDelta delay) override;
std::vector<SearchStringResult> SearchString(const base::char16* string,
const base::char16* term,
bool case_sensitive) override;
Expand Down

0 comments on commit 444fcaa

Please sign in to comment.