| Index: content/browser/renderer_host/input/motion_event_android.cc
|
| diff --git a/content/browser/renderer_host/input/motion_event_android.cc b/content/browser/renderer_host/input/motion_event_android.cc
|
| index d5c3861134ffec4dd273083dc37322c5f637799f..95435495375feb1e701467655c4325d53bd73a24 100644
|
| --- a/content/browser/renderer_host/input/motion_event_android.cc
|
| +++ b/content/browser/renderer_host/input/motion_event_android.cc
|
| @@ -39,18 +39,54 @@ base::TimeTicks FromAndroidTime(int64 time_ms) {
|
|
|
| } // namespace
|
|
|
| -MotionEventAndroid::MotionEventAndroid(jobject event)
|
| - : should_recycle_(false) {
|
| - event_.Reset(AttachCurrentThread(), event);
|
| +MotionEventAndroid::MotionEventAndroid(JNIEnv* env,
|
| + jobject event,
|
| + bool should_recycle)
|
| + : cached_time_(FromAndroidTime(Java_MotionEvent_getEventTime(env, event))),
|
| + cached_action_(FromAndroidAction(
|
| + Java_MotionEvent_getActionMasked(env, event))),
|
| + cached_pointer_count_(Java_MotionEvent_getPointerCount(env, event)),
|
| + cached_history_size_(Java_MotionEvent_getHistorySize(env, event)),
|
| + cached_action_index_(Java_MotionEvent_getActionIndex(env, event)),
|
| + cached_x_(Java_MotionEvent_getXF(env, event)),
|
| + cached_y_(Java_MotionEvent_getYF(env, event)),
|
| + should_recycle_(should_recycle) {
|
| + event_.Reset(env, event);
|
| DCHECK(event_.obj());
|
| }
|
|
|
| -MotionEventAndroid::MotionEventAndroid(
|
| - const base::android::ScopedJavaLocalRef<jobject>& event,
|
| - bool should_recycle)
|
| - : event_(event),
|
| - should_recycle_(should_recycle) {
|
| - DCHECK(event_.obj());
|
| +MotionEventAndroid::MotionEventAndroid(const MotionEventAndroid& other)
|
| + : event_(other.event_),
|
| + cached_time_(other.cached_time_),
|
| + cached_action_(other.cached_action_),
|
| + cached_pointer_count_(other.cached_pointer_count_),
|
| + cached_history_size_(other.cached_history_size_),
|
| + cached_action_index_(other.cached_action_index_),
|
| + cached_x_(other.cached_x_),
|
| + cached_y_(other.cached_y_),
|
| + should_recycle_(false) {
|
| + // An event with a pending recycle should never be copied (only cloned).
|
| + // TODO(jdduke): Determine if we should support this, and if so, go ahead
|
| + // perform the implicit clone.
|
| + DCHECK(!other.should_recycle_);
|
| +}
|
| +
|
| +MotionEventAndroid& MotionEventAndroid::operator=(
|
| + const MotionEventAndroid& other) {
|
| + if (should_recycle_)
|
| + Java_MotionEvent_recycle(AttachCurrentThread(), event_.obj());
|
| +
|
| + DCHECK(!other.should_recycle_);
|
| + event_.Reset(other.event_);
|
| + cached_time_ = other.cached_time_;
|
| + cached_action_ = other.cached_action_;
|
| + cached_pointer_count_ = other.cached_pointer_count_;
|
| + cached_history_size_ = other.cached_history_size_;
|
| + cached_action_index_ = other.cached_action_index_;
|
| + cached_x_ = other.cached_x_;
|
| + cached_y_ = other.cached_y_;
|
| + should_recycle_ = false;
|
| + return *this;
|
| }
|
|
|
| MotionEventAndroid::~MotionEventAndroid() {
|
| @@ -59,16 +95,15 @@ MotionEventAndroid::~MotionEventAndroid() {
|
| }
|
|
|
| MotionEventAndroid::Action MotionEventAndroid::GetActionMasked() const {
|
| - return FromAndroidAction(
|
| - Java_MotionEvent_getActionMasked(AttachCurrentThread(), event_.obj()));
|
| + return cached_action_;
|
| }
|
|
|
| -size_t MotionEventAndroid::GetActionIndex() const {
|
| - return Java_MotionEvent_getActionIndex(AttachCurrentThread(), event_.obj());
|
| +int MotionEventAndroid::GetActionIndex() const {
|
| + return cached_action_index_;
|
| }
|
|
|
| size_t MotionEventAndroid::GetPointerCount() const {
|
| - return Java_MotionEvent_getPointerCount(AttachCurrentThread(), event_.obj());
|
| + return cached_pointer_count_;
|
| }
|
|
|
| int MotionEventAndroid::GetPointerId(size_t pointer_index) const {
|
| @@ -82,11 +117,15 @@ float MotionEventAndroid::GetPressure(size_t pointer_index) const {
|
| }
|
|
|
| float MotionEventAndroid::GetX(size_t pointer_index) const {
|
| + if (pointer_index == 0)
|
| + return cached_x_;
|
| return Java_MotionEvent_getXF_I(
|
| AttachCurrentThread(), event_.obj(), pointer_index);
|
| }
|
|
|
| float MotionEventAndroid::GetY(size_t pointer_index) const {
|
| + if (pointer_index == 0)
|
| + return cached_y_;
|
| return Java_MotionEvent_getYF_I(
|
| AttachCurrentThread(), event_.obj(), pointer_index);
|
| }
|
| @@ -106,8 +145,7 @@ float MotionEventAndroid::GetOrientation() const {
|
| }
|
|
|
| base::TimeTicks MotionEventAndroid::GetEventTime() const {
|
| - return FromAndroidTime(
|
| - Java_MotionEvent_getEventTime(AttachCurrentThread(), event_.obj()));
|
| + return cached_time_;
|
| }
|
|
|
| base::TimeTicks MotionEventAndroid::GetDownTime() const {
|
| @@ -116,7 +154,7 @@ base::TimeTicks MotionEventAndroid::GetDownTime() const {
|
| }
|
|
|
| size_t MotionEventAndroid::GetHistorySize() const {
|
| - return Java_MotionEvent_getHistorySize(AttachCurrentThread(), event_.obj());
|
| + return cached_history_size_;
|
| }
|
|
|
| base::TimeTicks MotionEventAndroid::GetHistoricalEventTime(
|
| @@ -150,30 +188,26 @@ bool MotionEventAndroid::RegisterMotionEventAndroid(JNIEnv* env) {
|
| }
|
|
|
| // static
|
| -scoped_ptr<MotionEventAndroid> MotionEventAndroid::Obtain(
|
| +base::android::ScopedJavaLocalRef<jobject> MotionEventAndroid::Obtain(
|
| const MotionEventAndroid& event) {
|
| - return make_scoped_ptr(new MotionEventAndroid(
|
| - Java_MotionEvent_obtainAVME_AVME(AttachCurrentThread(),
|
| - event.event_.obj()),
|
| - true));
|
| + return Java_MotionEvent_obtainAVME_AVME(AttachCurrentThread(),
|
| + event.event_.obj());
|
| }
|
|
|
| // static
|
| -scoped_ptr<MotionEventAndroid> MotionEventAndroid::Obtain(
|
| +base::android::ScopedJavaLocalRef<jobject> MotionEventAndroid::Obtain(
|
| base::TimeTicks down_time,
|
| base::TimeTicks event__time,
|
| Action action,
|
| float x,
|
| float y) {
|
| - return make_scoped_ptr(new MotionEventAndroid(
|
| - Java_MotionEvent_obtainAVME_J_J_I_F_F_I(AttachCurrentThread(),
|
| - ToAndroidTime(down_time),
|
| - ToAndroidTime(down_time),
|
| - action,
|
| - x,
|
| - y,
|
| - 0),
|
| - true));
|
| + return Java_MotionEvent_obtainAVME_J_J_I_F_F_I(AttachCurrentThread(),
|
| + ToAndroidTime(down_time),
|
| + ToAndroidTime(down_time),
|
| + action,
|
| + x,
|
| + y,
|
| + 0);
|
| }
|
|
|
| } // namespace content
|
|
|