Commit caad51c8 authored by Virender Singh's avatar Virender Singh Committed by Commit Bot

Remove PPAPI dependency of touch events from PDFiumEngine

This change removes the pp::TouchInputEvent dependency from
PDFiumEngine. There are two reasons to remove this dependency
- Ability to unit test touch event handling.
- Facilitate the PPAPI deprecation by moving some PPAPI dependencies
  out of PDFiumEngine.

Bug: 1091834
Change-Id: I500faa950bbc8459e78f66fbe84db63f505777c6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2340360
Commit-Queue: Virender Singh <virens@microsoft.com>
Reviewed-by: Ankit Kumar 🌪️ <ankk@microsoft.com>
Reviewed-by: default avatarK. Moon <kmoon@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#798785}
parent 5d6d5ae0
......@@ -61,6 +61,7 @@
#include "third_party/pdfium/public/fpdf_searchex.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/events/keycodes/keyboard_codes.h"
#include "ui/gfx/geometry/point_conversions.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/geometry/vector2d.h"
......@@ -846,8 +847,9 @@ bool PDFiumEngine::HandleEvent(const pp::InputEvent& event) {
case PP_INPUTEVENT_TYPE_TOUCHSTART: {
KillTouchTimer();
pp::TouchInputEvent touch_event(event);
if (touch_event.GetTouchCount(PP_TOUCHLIST_TYPE_TARGETTOUCHES) == 1)
TouchInputEvent touch_event(
GetTouchInputEvent(pp::TouchInputEvent(event)));
if (touch_event.GetTouchCount() == 1)
ScheduleTouchTimer(touch_event);
break;
}
......@@ -2404,11 +2406,9 @@ void PDFiumEngine::SetGrayscale(bool grayscale) {
render_grayscale_ = grayscale;
}
void PDFiumEngine::HandleLongPress(const pp::TouchInputEvent& event) {
void PDFiumEngine::HandleLongPress(const TouchInputEvent& event) {
base::AutoReset<bool> handling_long_press_guard(&handling_long_press_, true);
pp::FloatPoint fp =
event.GetTouchByIndex(PP_TOUCHLIST_TYPE_TARGETTOUCHES, 0).position();
gfx::Point point(fp.x(), fp.y());
gfx::Point point = gfx::ToRoundedPoint(event.GetTargetTouchPoint());
// Send a fake mouse down to trigger the multi-click selection code.
MouseInputEvent mouse_event(
......@@ -3672,7 +3672,7 @@ bool PDFiumEngine::IsAnnotationAnEditableFormTextArea(FPDF_ANNOTATION annot,
return CheckIfEditableFormTextArea(flags, form_type);
}
void PDFiumEngine::ScheduleTouchTimer(const pp::TouchInputEvent& evt) {
void PDFiumEngine::ScheduleTouchTimer(const TouchInputEvent& evt) {
touch_timer_.Start(FROM_HERE, kTouchLongPressTimeout,
base::BindOnce(&PDFiumEngine::HandleLongPress,
base::Unretained(this), evt));
......
......@@ -48,6 +48,7 @@ class KeyboardInputEvent;
class MouseInputEvent;
class PDFiumDocument;
class PDFiumPermissions;
class TouchInputEvent;
namespace draw_utils {
class ShadowMatrix;
......@@ -554,9 +555,9 @@ class PDFiumEngine : public PDFEngine,
// independent of whether it is hidden or not at the moment.
float GetToolbarHeightInScreenCoords();
void ScheduleTouchTimer(const pp::TouchInputEvent& event);
void ScheduleTouchTimer(const TouchInputEvent& event);
void KillTouchTimer();
void HandleLongPress(const pp::TouchInputEvent& event);
void HandleLongPress(const TouchInputEvent& event);
// Returns a VarDictionary (representing a bookmark), which in turn contains
// child VarDictionaries (representing the child bookmarks).
......
......@@ -8,6 +8,7 @@
#include "ppapi/c/pp_rect.h"
#include "ppapi/c/pp_size.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"
......@@ -21,6 +22,10 @@ PP_Point PPPointFromPoint(const gfx::Point& point) {
return PP_MakePoint(point.x(), point.y());
}
gfx::PointF PointFFromPPFloatPoint(const PP_FloatPoint& pp_point) {
return gfx::PointF(pp_point.x, pp_point.y);
}
gfx::Rect RectFromPPRect(const PP_Rect& pp_rect) {
return gfx::Rect(pp_rect.point.x, pp_rect.point.y, pp_rect.size.width,
pp_rect.size.height);
......
......@@ -5,12 +5,14 @@
#ifndef PDF_PPAPI_MIGRATION_GEOMETRY_CONVERSIONS_H_
#define PDF_PPAPI_MIGRATION_GEOMETRY_CONVERSIONS_H_
struct PP_FloatPoint;
struct PP_Point;
struct PP_Rect;
struct PP_Size;
namespace gfx {
class Point;
class PointF;
class Rect;
class Size;
} // namespace gfx
......@@ -20,6 +22,8 @@ namespace chrome_pdf {
gfx::Point PointFromPPPoint(const PP_Point& pp_point);
PP_Point PPPointFromPoint(const gfx::Point& point);
gfx::PointF PointFFromPPFloatPoint(const PP_FloatPoint& pp_point);
gfx::Rect RectFromPPRect(const PP_Rect& pp_rect);
PP_Rect PPRectFromRect(const gfx::Rect& rect);
......
......@@ -12,6 +12,7 @@
#include "ppapi/cpp/size.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"
......@@ -35,6 +36,14 @@ TEST(GeometryConversionsTest, PPPointFromPoint) {
EXPECT_EQ(pp_c_point.y, -1);
}
TEST(GeometryConversionsTest, PointFFromPPFloatPoint) {
gfx::PointF float_point = PointFFromPPFloatPoint(pp::FloatPoint(-1.2f, 2.2f));
EXPECT_EQ(float_point, gfx::PointF(-1.2f, 2.2f));
float_point = PointFFromPPFloatPoint(PP_MakeFloatPoint(-2.2f, 1.2f));
EXPECT_EQ(float_point, gfx::PointF(-2.2f, 1.2f));
}
TEST(GeometryConversionsTest, RectFromPPRect) {
gfx::Rect rect = RectFromPPRect(pp::Rect(-1, 2, 3, 4));
EXPECT_EQ(rect, gfx::Rect(-1, 2, 3, 4));
......
......@@ -2,12 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <stdint.h>
#include "pdf/ppapi_migration/input_event_conversions.h"
#include "base/notreached.h"
#include "pdf/ppapi_migration/geometry_conversions.h"
#include "ppapi/cpp/input_event.h"
#include "ppapi/cpp/var.h"
#include "ui/gfx/geometry/point_conversions.h"
namespace {
......@@ -116,6 +119,24 @@ MouseInputEvent& MouseInputEvent::operator=(const MouseInputEvent& other) =
MouseInputEvent::~MouseInputEvent() = default;
TouchInputEvent::TouchInputEvent(InputEventType event_type,
double time_stamp,
uint32_t modifiers,
const gfx::PointF& target_touch_point,
int32_t touch_count)
: event_type_(event_type),
time_stamp_(time_stamp),
modifiers_(modifiers),
target_touch_point_(target_touch_point),
touch_count_(touch_count) {}
TouchInputEvent::TouchInputEvent(const TouchInputEvent& other) = default;
TouchInputEvent& TouchInputEvent::operator=(const TouchInputEvent& other) =
default;
TouchInputEvent::~TouchInputEvent() = default;
KeyboardInputEvent GetKeyboardInputEvent(const pp::KeyboardInputEvent& event) {
return KeyboardInputEvent(GetEventType(event.GetType()), event.GetTimeStamp(),
event.GetModifiers(), event.GetKeyCode(),
......@@ -130,4 +151,12 @@ MouseInputEvent GetMouseInputEvent(const pp::MouseInputEvent& event) {
PointFromPPPoint(event.GetMovement()));
}
TouchInputEvent GetTouchInputEvent(const pp::TouchInputEvent& event) {
pp::FloatPoint point =
event.GetTouchByIndex(PP_TOUCHLIST_TYPE_TARGETTOUCHES, 0).position();
return TouchInputEvent(GetEventType(event.GetType()), event.GetTimeStamp(),
event.GetModifiers(), PointFFromPPFloatPoint(point),
event.GetTouchCount(PP_TOUCHLIST_TYPE_TARGETTOUCHES));
}
} // namespace chrome_pdf
......@@ -9,10 +9,12 @@
#include <string>
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/point_f.h"
namespace pp {
class KeyboardInputEvent;
class MouseInputEvent;
class TouchInputEvent;
} // namespace pp
namespace chrome_pdf {
......@@ -181,10 +183,46 @@ class MouseInputEvent {
gfx::Point movement_;
};
class TouchInputEvent {
public:
TouchInputEvent(InputEventType event_type,
double time_stamp,
uint32_t modifiers,
const gfx::PointF& target_touch_point,
int32_t touch_count);
TouchInputEvent(const TouchInputEvent& other);
TouchInputEvent& operator=(const TouchInputEvent& other);
~TouchInputEvent();
const InputEventType& GetEventType() const { return event_type_; }
double GetTimeStamp() const { return time_stamp_; }
uint32_t GetModifiers() const { return modifiers_; }
// `pp::TouchInputEvent` exposes a collection of target touch points. We can
// get all the points by passing the index of the point in the collection.
// However, with `chrome_pdf::TouchEvent` the number of target touch points
// are restricted to the first point. This is because PDFiumeEngine at present
// is dependent on only the first target touch point.
const gfx::PointF& GetTargetTouchPoint() const { return target_touch_point_; }
int32_t GetTouchCount() const { return touch_count_; }
private:
InputEventType event_type_ = InputEventType::kNone;
double time_stamp_ = 0;
uint32_t modifiers_ = kInputEventModifierNone;
gfx::PointF target_touch_point_;
int32_t touch_count_ = 0;
};
KeyboardInputEvent GetKeyboardInputEvent(const pp::KeyboardInputEvent& event);
MouseInputEvent GetMouseInputEvent(const pp::MouseInputEvent& event);
TouchInputEvent GetTouchInputEvent(const pp::TouchInputEvent& event);
} // namespace chrome_pdf
#endif // PDF_PPAPI_MIGRATION_INPUT_EVENT_CONVERSIONS_H_
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