Commit 083c38c0 authored by avi.nitk's avatar avi.nitk Committed by Commit bot

Separate out Touch Selection Orientation enum

Separate out Touch Selection Orientation so that it can
be used both on Java side and native side easily.

BUG=NONE

Review URL: https://codereview.chromium.org/701823002

Cr-Commit-Position: refs/heads/master@{#318657}
parent d841599f
...@@ -62,6 +62,7 @@ $(call intermediates-dir-for,GYP,shared)/enums/private_key_types_java/org/chromi ...@@ -62,6 +62,7 @@ $(call intermediates-dir-for,GYP,shared)/enums/private_key_types_java/org/chromi
$(call intermediates-dir-for,GYP,shared)/enums/result_codes_java/org/chromium/content_public/common/ResultCode.java \ $(call intermediates-dir-for,GYP,shared)/enums/result_codes_java/org/chromium/content_public/common/ResultCode.java \
$(call intermediates-dir-for,GYP,shared)/enums/screen_orientation_values_java/org/chromium/content_public/common/ScreenOrientationValues.java \ $(call intermediates-dir-for,GYP,shared)/enums/screen_orientation_values_java/org/chromium/content_public/common/ScreenOrientationValues.java \
$(call intermediates-dir-for,GYP,shared)/enums/selection_event_type_java/org/chromium/ui/touch_selection/SelectionEventType.java \ $(call intermediates-dir-for,GYP,shared)/enums/selection_event_type_java/org/chromium/ui/touch_selection/SelectionEventType.java \
$(call intermediates-dir-for,GYP,shared)/enums/touch_handle_orientation_java/org/chromium/ui/touch_selection/TouchHandleOrientation.java \
$(call intermediates-dir-for,GYP,shared)/enums/speech_recognition_error_java/org/chromium/content_public/common/SpeechRecognitionErrorCode.java \ $(call intermediates-dir-for,GYP,shared)/enums/speech_recognition_error_java/org/chromium/content_public/common/SpeechRecognitionErrorCode.java \
$(call intermediates-dir-for,GYP,shared)/enums/top_controls_state_java/org/chromium/content_public/common/TopControlsState.java \ $(call intermediates-dir-for,GYP,shared)/enums/top_controls_state_java/org/chromium/content_public/common/TopControlsState.java \
$(call intermediates-dir-for,GYP,shared)/enums/window_open_disposition_java/org/chromium/ui/WindowOpenDisposition.java \ $(call intermediates-dir-for,GYP,shared)/enums/window_open_disposition_java/org/chromium/ui/WindowOpenDisposition.java \
......
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
'../ui/android/ui_android.gyp:window_open_disposition_java', '../ui/android/ui_android.gyp:window_open_disposition_java',
'../ui/android/ui_android.gyp:text_input_type_java', '../ui/android/ui_android.gyp:text_input_type_java',
'../ui/touch_selection/ui_touch_selection.gyp:selection_event_type_java', '../ui/touch_selection/ui_touch_selection.gyp:selection_event_type_java',
'../ui/touch_selection/ui_touch_selection.gyp:touch_handle_orientation_java',
# We also need to depend on the Java bindings generated from the .mojom files. # We also need to depend on the Java bindings generated from the .mojom files.
'../device/battery/battery.gyp:device_battery_mojo_bindings_for_webview', '../device/battery/battery.gyp:device_battery_mojo_bindings_for_webview',
], ],
......
...@@ -53,13 +53,13 @@ class HandleResources { ...@@ -53,13 +53,13 @@ class HandleResources {
const SkBitmap& GetBitmap(ui::TouchHandleOrientation orientation) { const SkBitmap& GetBitmap(ui::TouchHandleOrientation orientation) {
DCHECK(loaded_); DCHECK(loaded_);
switch (orientation) { switch (orientation) {
case ui::TOUCH_HANDLE_LEFT: case ui::TouchHandleOrientation::LEFT:
return left_bitmap_; return left_bitmap_;
case ui::TOUCH_HANDLE_RIGHT: case ui::TouchHandleOrientation::RIGHT:
return right_bitmap_; return right_bitmap_;
case ui::TOUCH_HANDLE_CENTER: case ui::TouchHandleOrientation::CENTER:
return center_bitmap_; return center_bitmap_;
case ui::TOUCH_HANDLE_ORIENTATION_UNDEFINED: case ui::TouchHandleOrientation::UNDEFINED:
NOTREACHED() << "Invalid touch handle orientation."; NOTREACHED() << "Invalid touch handle orientation.";
}; };
return center_bitmap_; return center_bitmap_;
...@@ -83,7 +83,7 @@ CompositedTouchHandleDrawable::CompositedTouchHandleDrawable( ...@@ -83,7 +83,7 @@ CompositedTouchHandleDrawable::CompositedTouchHandleDrawable(
float dpi_scale, float dpi_scale,
jobject context) jobject context)
: dpi_scale_(dpi_scale), : dpi_scale_(dpi_scale),
orientation_(ui::TOUCH_HANDLE_ORIENTATION_UNDEFINED), orientation_(ui::TouchHandleOrientation::UNDEFINED),
layer_(cc::UIResourceLayer::Create()) { layer_(cc::UIResourceLayer::Create()) {
g_selection_resources.Get().LoadIfNecessary(context); g_selection_resources.Get().LoadIfNecessary(context);
DCHECK(root_layer); DCHECK(root_layer);
...@@ -111,16 +111,16 @@ void CompositedTouchHandleDrawable::SetOrientation( ...@@ -111,16 +111,16 @@ void CompositedTouchHandleDrawable::SetOrientation(
layer_->SetBounds(gfx::Size(bitmap.width(), bitmap.height())); layer_->SetBounds(gfx::Size(bitmap.width(), bitmap.height()));
switch (orientation_) { switch (orientation_) {
case ui::TOUCH_HANDLE_LEFT: case ui::TouchHandleOrientation::LEFT:
focal_offset_from_origin_ = gfx::Vector2dF(bitmap.width() * 0.75f, 0); focal_offset_from_origin_ = gfx::Vector2dF(bitmap.width() * 0.75f, 0);
break; break;
case ui::TOUCH_HANDLE_RIGHT: case ui::TouchHandleOrientation::RIGHT:
focal_offset_from_origin_ = gfx::Vector2dF(bitmap.width() * 0.25f, 0); focal_offset_from_origin_ = gfx::Vector2dF(bitmap.width() * 0.25f, 0);
break; break;
case ui::TOUCH_HANDLE_CENTER: case ui::TouchHandleOrientation::CENTER:
focal_offset_from_origin_ = gfx::Vector2dF(bitmap.width() * 0.5f, 0); focal_offset_from_origin_ = gfx::Vector2dF(bitmap.width() * 0.5f, 0);
break; break;
case ui::TOUCH_HANDLE_ORIENTATION_UNDEFINED: case ui::TouchHandleOrientation::UNDEFINED:
NOTREACHED() << "Invalid touch handle orientation."; NOTREACHED() << "Invalid touch handle orientation.";
break; break;
}; };
......
...@@ -33,22 +33,8 @@ void PopupTouchHandleDrawable::SetOrientation( ...@@ -33,22 +33,8 @@ void PopupTouchHandleDrawable::SetOrientation(
ui::TouchHandleOrientation orientation) { ui::TouchHandleOrientation orientation) {
JNIEnv* env = base::android::AttachCurrentThread(); JNIEnv* env = base::android::AttachCurrentThread();
jobject obj = drawable_.obj(); jobject obj = drawable_.obj();
switch (orientation) { Java_PopupTouchHandleDrawable_setOrientation(env, obj,
case ui::TOUCH_HANDLE_LEFT: static_cast<int>(orientation));
Java_PopupTouchHandleDrawable_setLeftOrientation(env, obj);
break;
case ui::TOUCH_HANDLE_RIGHT:
Java_PopupTouchHandleDrawable_setRightOrientation(env, obj);
break;
case ui::TOUCH_HANDLE_CENTER:
Java_PopupTouchHandleDrawable_setCenterOrientation(env, obj);
break;
case ui::TOUCH_HANDLE_ORIENTATION_UNDEFINED:
NOTREACHED() << "Invalid touch handle orientation.";
};
} }
void PopupTouchHandleDrawable::SetAlpha(float alpha) { void PopupTouchHandleDrawable::SetAlpha(float alpha) {
......
...@@ -436,6 +436,7 @@ ...@@ -436,6 +436,7 @@
'../third_party/mojo/mojo_public.gyp:mojo_bindings_java', '../third_party/mojo/mojo_public.gyp:mojo_bindings_java',
'../ui/android/ui_android.gyp:ui_java', '../ui/android/ui_android.gyp:ui_java',
'../ui/touch_selection/ui_touch_selection.gyp:selection_event_type_java', '../ui/touch_selection/ui_touch_selection.gyp:selection_event_type_java',
'../ui/touch_selection/ui_touch_selection.gyp:touch_handle_orientation_java',
'../third_party/WebKit/public/blink_headers.gyp:blink_headers_java', '../third_party/WebKit/public/blink_headers.gyp:blink_headers_java',
'common_aidl', 'common_aidl',
'console_message_level_java', 'console_message_level_java',
......
...@@ -50,6 +50,7 @@ android_library("content_java") { ...@@ -50,6 +50,7 @@ android_library("content_java") {
":common_aidl", ":common_aidl",
":content_public_android_java_enums_srcjar", ":content_public_android_java_enums_srcjar",
"//ui/touch_selection:ui_touch_selection_enums_srcjar", "//ui/touch_selection:ui_touch_selection_enums_srcjar",
"//ui/touch_selection:ui_touch_handle_orientation_srcjar",
] ]
DEPRECATED_java_in_dir = "java/src" DEPRECATED_java_in_dir = "java/src"
......
...@@ -17,6 +17,7 @@ import org.chromium.base.ApiCompatibilityUtils; ...@@ -17,6 +17,7 @@ import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.CalledByNative; import org.chromium.base.CalledByNative;
import org.chromium.base.JNINamespace; import org.chromium.base.JNINamespace;
import org.chromium.content.browser.PositionObserver; import org.chromium.content.browser.PositionObserver;
import org.chromium.ui.touch_selection.TouchHandleOrientation;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
...@@ -58,12 +59,7 @@ public class PopupTouchHandleDrawable extends View { ...@@ -58,12 +59,7 @@ public class PopupTouchHandleDrawable extends View {
private final int[] mTempScreenCoords = new int[2]; private final int[] mTempScreenCoords = new int[2];
@SuppressLint("RtlHardcoded") private int mOrientation = TouchHandleOrientation.UNDEFINED;
static final int LEFT = 0;
static final int CENTER = 1;
@SuppressLint("RtlHardcoded")
static final int RIGHT = 2;
private int mOrientation = -1;
// Length of the delay before fading in after the last page movement. // Length of the delay before fading in after the last page movement.
private static final int FADE_IN_DELAY_MS = 300; private static final int FADE_IN_DELAY_MS = 300;
...@@ -146,35 +142,40 @@ public class PopupTouchHandleDrawable extends View { ...@@ -146,35 +142,40 @@ public class PopupTouchHandleDrawable extends View {
return handled; return handled;
} }
@CalledByNative
private void setOrientation(int orientation) { private void setOrientation(int orientation) {
assert orientation >= LEFT && orientation <= RIGHT; assert (orientation >= TouchHandleOrientation.LEFT
&& orientation <= TouchHandleOrientation.UNDEFINED);
if (mOrientation == orientation) return; if (mOrientation == orientation) return;
final boolean hadValidOrientation = mOrientation != -1; final boolean hadValidOrientation = mOrientation != TouchHandleOrientation.UNDEFINED;
mOrientation = orientation; mOrientation = orientation;
final int oldAdjustedPositionX = getAdjustedPositionX(); final int oldAdjustedPositionX = getAdjustedPositionX();
final int oldAdjustedPositionY = getAdjustedPositionY(); final int oldAdjustedPositionY = getAdjustedPositionY();
switch (orientation) { switch (orientation) {
case LEFT: { case TouchHandleOrientation.LEFT: {
mDrawable = HandleViewResources.getLeftHandleDrawable(mContext); mDrawable = HandleViewResources.getLeftHandleDrawable(mContext);
mHotspotX = (mDrawable.getIntrinsicWidth() * 3) / 4f; mHotspotX = (mDrawable.getIntrinsicWidth() * 3) / 4f;
break; break;
} }
case RIGHT: { case TouchHandleOrientation.RIGHT: {
mDrawable = HandleViewResources.getRightHandleDrawable(mContext); mDrawable = HandleViewResources.getRightHandleDrawable(mContext);
mHotspotX = mDrawable.getIntrinsicWidth() / 4f; mHotspotX = mDrawable.getIntrinsicWidth() / 4f;
break; break;
} }
case CENTER: case TouchHandleOrientation.CENTER: {
default: {
mDrawable = HandleViewResources.getCenterHandleDrawable(mContext); mDrawable = HandleViewResources.getCenterHandleDrawable(mContext);
mHotspotX = mDrawable.getIntrinsicWidth() / 2f; mHotspotX = mDrawable.getIntrinsicWidth() / 2f;
break; break;
} }
case TouchHandleOrientation.UNDEFINED:
default:
break;
} }
mHotspotY = 0; mHotspotY = 0;
...@@ -346,21 +347,6 @@ public class PopupTouchHandleDrawable extends View { ...@@ -346,21 +347,6 @@ public class PopupTouchHandleDrawable extends View {
} }
} }
@CalledByNative
private void setRightOrientation() {
setOrientation(RIGHT);
}
@CalledByNative
private void setLeftOrientation() {
setOrientation(LEFT);
}
@CalledByNative
private void setCenterOrientation() {
setOrientation(CENTER);
}
@CalledByNative @CalledByNative
private void setFocus(float focusX, float focusY) { private void setFocus(float focusX, float focusY) {
int x = (int) focusX - Math.round(mHotspotX); int x = (int) focusX - Math.round(mHotspotX);
......
...@@ -16,6 +16,7 @@ component("touch_selection") { ...@@ -16,6 +16,7 @@ component("touch_selection") {
"selection_event_type.h", "selection_event_type.h",
"touch_handle.cc", "touch_handle.cc",
"touch_handle.h", "touch_handle.h",
"touch_handle_orientation.h",
"touch_selection_controller.cc", "touch_selection_controller.cc",
"touch_selection_controller.h", "touch_selection_controller.h",
"ui_touch_selection_export.h", "ui_touch_selection_export.h",
...@@ -59,4 +60,12 @@ if (is_android) { ...@@ -59,4 +60,12 @@ if (is_android) {
"org/chromium/ui/touch_selection/SelectionEventType.java", "org/chromium/ui/touch_selection/SelectionEventType.java",
] ]
} }
java_cpp_enum("ui_touch_handle_orientation_srcjar") {
sources = [
"touch_handle_orientation.h",
]
outputs = [
"org/chromium/ui/touch_selection/TouchHandleOrientation.java",
]
}
} }
...@@ -44,20 +44,37 @@ bool RectIntersectsCircle(const gfx::RectF& rect, ...@@ -44,20 +44,37 @@ bool RectIntersectsCircle(const gfx::RectF& rect,
} // namespace } // namespace
// TODO(AviD): Remove this once logging(DCHECK) supports enum class.
static std::ostream& operator<<(std::ostream& os,
const TouchHandleOrientation& orientation) {
switch (orientation) {
case TouchHandleOrientation::LEFT:
return os << "LEFT";
case TouchHandleOrientation::RIGHT:
return os << "RIGHT";
case TouchHandleOrientation::CENTER:
return os << "CENTER";
case TouchHandleOrientation::UNDEFINED:
return os << "UNDEFINED";
default:
return os << "INVALID: " << static_cast<int>(orientation);
}
}
// Responsible for rendering a selection or insertion handle for text editing. // Responsible for rendering a selection or insertion handle for text editing.
TouchHandle::TouchHandle(TouchHandleClient* client, TouchHandle::TouchHandle(TouchHandleClient* client,
TouchHandleOrientation orientation) TouchHandleOrientation orientation)
: drawable_(client->CreateDrawable()), : drawable_(client->CreateDrawable()),
client_(client), client_(client),
orientation_(orientation), orientation_(orientation),
deferred_orientation_(TOUCH_HANDLE_ORIENTATION_UNDEFINED), deferred_orientation_(TouchHandleOrientation::UNDEFINED),
alpha_(0.f), alpha_(0.f),
animate_deferred_fade_(false), animate_deferred_fade_(false),
enabled_(true), enabled_(true),
is_visible_(false), is_visible_(false),
is_dragging_(false), is_dragging_(false),
is_drag_within_tap_region_(false) { is_drag_within_tap_region_(false) {
DCHECK_NE(orientation, TOUCH_HANDLE_ORIENTATION_UNDEFINED); DCHECK_NE(orientation, TouchHandleOrientation::UNDEFINED);
drawable_->SetEnabled(enabled_); drawable_->SetEnabled(enabled_);
drawable_->SetOrientation(orientation_); drawable_->SetOrientation(orientation_);
drawable_->SetAlpha(alpha_); drawable_->SetAlpha(alpha_);
...@@ -115,12 +132,12 @@ void TouchHandle::SetPosition(const gfx::PointF& position) { ...@@ -115,12 +132,12 @@ void TouchHandle::SetPosition(const gfx::PointF& position) {
void TouchHandle::SetOrientation(TouchHandleOrientation orientation) { void TouchHandle::SetOrientation(TouchHandleOrientation orientation) {
DCHECK(enabled_); DCHECK(enabled_);
DCHECK_NE(orientation, TOUCH_HANDLE_ORIENTATION_UNDEFINED); DCHECK_NE(orientation, TouchHandleOrientation::UNDEFINED);
if (is_dragging_) { if (is_dragging_) {
deferred_orientation_ = orientation; deferred_orientation_ = orientation;
return; return;
} }
DCHECK_EQ(deferred_orientation_, TOUCH_HANDLE_ORIENTATION_UNDEFINED); DCHECK_EQ(deferred_orientation_, TouchHandleOrientation::UNDEFINED);
if (orientation_ == orientation) if (orientation_ == orientation)
return; return;
...@@ -230,9 +247,9 @@ void TouchHandle::EndDrag() { ...@@ -230,9 +247,9 @@ void TouchHandle::EndDrag() {
is_drag_within_tap_region_ = false; is_drag_within_tap_region_ = false;
client_->OnHandleDragEnd(*this); client_->OnHandleDragEnd(*this);
if (deferred_orientation_ != TOUCH_HANDLE_ORIENTATION_UNDEFINED) { if (deferred_orientation_ != TouchHandleOrientation::UNDEFINED) {
TouchHandleOrientation deferred_orientation = deferred_orientation_; TouchHandleOrientation deferred_orientation = deferred_orientation_;
deferred_orientation_ = TOUCH_HANDLE_ORIENTATION_UNDEFINED; deferred_orientation_ = TouchHandleOrientation::UNDEFINED;
SetOrientation(deferred_orientation); SetOrientation(deferred_orientation);
} }
......
...@@ -12,19 +12,13 @@ ...@@ -12,19 +12,13 @@
#include "ui/gfx/geometry/point_f.h" #include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/geometry/rect_f.h" #include "ui/gfx/geometry/rect_f.h"
#include "ui/gfx/geometry/vector2d_f.h" #include "ui/gfx/geometry/vector2d_f.h"
#include "ui/touch_selection/touch_handle_orientation.h"
#include "ui/touch_selection/ui_touch_selection_export.h" #include "ui/touch_selection/ui_touch_selection_export.h"
namespace ui { namespace ui {
class TouchHandle; class TouchHandle;
enum TouchHandleOrientation {
TOUCH_HANDLE_LEFT,
TOUCH_HANDLE_CENTER,
TOUCH_HANDLE_RIGHT,
TOUCH_HANDLE_ORIENTATION_UNDEFINED,
};
// Interface through which |TouchHandle| delegates rendering-specific duties. // Interface through which |TouchHandle| delegates rendering-specific duties.
class UI_TOUCH_SELECTION_EXPORT TouchHandleDrawable { class UI_TOUCH_SELECTION_EXPORT TouchHandleDrawable {
public: public:
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_TOUCH_SELECTION_TOUCH_HANDLE_ORIENTATION_
#define UI_TOUCH_SELECTION_TOUCH_HANDLE_ORIENTATION_
namespace ui {
// Orientation types for Touch handles, used for setting the type of
// handle orientation on java and native side.
// A Java counterpart will be generated for this enum.
// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.ui.touch_selection
enum class TouchHandleOrientation {
LEFT,
CENTER,
RIGHT,
UNDEFINED,
};
} // namespace ui
#endif // UI_TOUCH_SELECTION_TOUCH_HANDLE_ORIENTATION_
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/events/test/motion_event_test_utils.h" #include "ui/events/test/motion_event_test_utils.h"
#include "ui/gfx/geometry/rect_f.h" #include "ui/gfx/geometry/rect_f.h"
#include "ui/touch_selection/touch_handle_orientation.h"
using ui::test::MockMotionEvent; using ui::test::MockMotionEvent;
...@@ -19,7 +20,7 @@ const float kDefaultDrawableSize = 10.f; ...@@ -19,7 +20,7 @@ const float kDefaultDrawableSize = 10.f;
struct MockDrawableData { struct MockDrawableData {
MockDrawableData() MockDrawableData()
: orientation(TOUCH_HANDLE_ORIENTATION_UNDEFINED), : orientation(TouchHandleOrientation::UNDEFINED),
alpha(0.f), alpha(0.f),
enabled(false), enabled(false),
visible(false), visible(false),
...@@ -143,7 +144,7 @@ class TouchHandleTest : public testing::Test, public TouchHandleClient { ...@@ -143,7 +144,7 @@ class TouchHandleTest : public testing::Test, public TouchHandleClient {
}; };
TEST_F(TouchHandleTest, Visibility) { TEST_F(TouchHandleTest, Visibility) {
TouchHandle handle(this, TOUCH_HANDLE_CENTER); TouchHandle handle(this, TouchHandleOrientation::CENTER);
EXPECT_FALSE(drawable().visible); EXPECT_FALSE(drawable().visible);
handle.SetVisible(true, TouchHandle::ANIMATION_NONE); handle.SetVisible(true, TouchHandle::ANIMATION_NONE);
...@@ -159,7 +160,7 @@ TEST_F(TouchHandleTest, Visibility) { ...@@ -159,7 +160,7 @@ TEST_F(TouchHandleTest, Visibility) {
} }
TEST_F(TouchHandleTest, VisibilityAnimation) { TEST_F(TouchHandleTest, VisibilityAnimation) {
TouchHandle handle(this, TOUCH_HANDLE_CENTER); TouchHandle handle(this, TouchHandleOrientation::CENTER);
ASSERT_FALSE(NeedsAnimate()); ASSERT_FALSE(NeedsAnimate());
ASSERT_FALSE(drawable().visible); ASSERT_FALSE(drawable().visible);
ASSERT_EQ(0.f, drawable().alpha); ASSERT_EQ(0.f, drawable().alpha);
...@@ -195,21 +196,21 @@ TEST_F(TouchHandleTest, VisibilityAnimation) { ...@@ -195,21 +196,21 @@ TEST_F(TouchHandleTest, VisibilityAnimation) {
} }
TEST_F(TouchHandleTest, Orientation) { TEST_F(TouchHandleTest, Orientation) {
TouchHandle handle(this, TOUCH_HANDLE_CENTER); TouchHandle handle(this, TouchHandleOrientation::CENTER);
EXPECT_EQ(TOUCH_HANDLE_CENTER, drawable().orientation); EXPECT_EQ(TouchHandleOrientation::CENTER, drawable().orientation);
handle.SetOrientation(TOUCH_HANDLE_LEFT); handle.SetOrientation(TouchHandleOrientation::LEFT);
EXPECT_EQ(TOUCH_HANDLE_LEFT, drawable().orientation); EXPECT_EQ(TouchHandleOrientation::LEFT, drawable().orientation);
handle.SetOrientation(TOUCH_HANDLE_RIGHT); handle.SetOrientation(TouchHandleOrientation::RIGHT);
EXPECT_EQ(TOUCH_HANDLE_RIGHT, drawable().orientation); EXPECT_EQ(TouchHandleOrientation::RIGHT, drawable().orientation);
handle.SetOrientation(TOUCH_HANDLE_CENTER); handle.SetOrientation(TouchHandleOrientation::CENTER);
EXPECT_EQ(TOUCH_HANDLE_CENTER, drawable().orientation); EXPECT_EQ(TouchHandleOrientation::CENTER, drawable().orientation);
} }
TEST_F(TouchHandleTest, Position) { TEST_F(TouchHandleTest, Position) {
TouchHandle handle(this, TOUCH_HANDLE_CENTER); TouchHandle handle(this, TouchHandleOrientation::CENTER);
handle.SetVisible(true, TouchHandle::ANIMATION_NONE); handle.SetVisible(true, TouchHandle::ANIMATION_NONE);
gfx::PointF position; gfx::PointF position;
...@@ -225,7 +226,7 @@ TEST_F(TouchHandleTest, Position) { ...@@ -225,7 +226,7 @@ TEST_F(TouchHandleTest, Position) {
} }
TEST_F(TouchHandleTest, PositionNotUpdatedWhileFadingOrInvisible) { TEST_F(TouchHandleTest, PositionNotUpdatedWhileFadingOrInvisible) {
TouchHandle handle(this, TOUCH_HANDLE_CENTER); TouchHandle handle(this, TouchHandleOrientation::CENTER);
handle.SetVisible(true, TouchHandle::ANIMATION_NONE); handle.SetVisible(true, TouchHandle::ANIMATION_NONE);
ASSERT_TRUE(drawable().visible); ASSERT_TRUE(drawable().visible);
...@@ -260,7 +261,7 @@ TEST_F(TouchHandleTest, PositionNotUpdatedWhileFadingOrInvisible) { ...@@ -260,7 +261,7 @@ TEST_F(TouchHandleTest, PositionNotUpdatedWhileFadingOrInvisible) {
TEST_F(TouchHandleTest, Enabled) { TEST_F(TouchHandleTest, Enabled) {
// A newly created handle defaults to enabled. // A newly created handle defaults to enabled.
TouchHandle handle(this, TOUCH_HANDLE_CENTER); TouchHandle handle(this, TouchHandleOrientation::CENTER);
EXPECT_TRUE(drawable().enabled); EXPECT_TRUE(drawable().enabled);
handle.SetVisible(true, TouchHandle::ANIMATION_SMOOTH); handle.SetVisible(true, TouchHandle::ANIMATION_SMOOTH);
...@@ -297,7 +298,7 @@ TEST_F(TouchHandleTest, Enabled) { ...@@ -297,7 +298,7 @@ TEST_F(TouchHandleTest, Enabled) {
} }
TEST_F(TouchHandleTest, Drag) { TEST_F(TouchHandleTest, Drag) {
TouchHandle handle(this, TOUCH_HANDLE_CENTER); TouchHandle handle(this, TouchHandleOrientation::CENTER);
base::TimeTicks event_time = base::TimeTicks::Now(); base::TimeTicks event_time = base::TimeTicks::Now();
const float kOffset = kDefaultDrawableSize / 2.f; const float kOffset = kDefaultDrawableSize / 2.f;
...@@ -351,8 +352,8 @@ TEST_F(TouchHandleTest, Drag) { ...@@ -351,8 +352,8 @@ TEST_F(TouchHandleTest, Drag) {
} }
TEST_F(TouchHandleTest, DragDefersOrientationChange) { TEST_F(TouchHandleTest, DragDefersOrientationChange) {
TouchHandle handle(this, TOUCH_HANDLE_RIGHT); TouchHandle handle(this, TouchHandleOrientation::RIGHT);
ASSERT_EQ(drawable().orientation, TOUCH_HANDLE_RIGHT); ASSERT_EQ(drawable().orientation, TouchHandleOrientation::RIGHT);
handle.SetVisible(true, TouchHandle::ANIMATION_NONE); handle.SetVisible(true, TouchHandle::ANIMATION_NONE);
MockMotionEvent event(MockMotionEvent::ACTION_DOWN); MockMotionEvent event(MockMotionEvent::ACTION_DOWN);
...@@ -360,24 +361,24 @@ TEST_F(TouchHandleTest, DragDefersOrientationChange) { ...@@ -360,24 +361,24 @@ TEST_F(TouchHandleTest, DragDefersOrientationChange) {
EXPECT_TRUE(IsDragging()); EXPECT_TRUE(IsDragging());
// Orientation changes will be deferred until the drag ends. // Orientation changes will be deferred until the drag ends.
handle.SetOrientation(TOUCH_HANDLE_LEFT); handle.SetOrientation(TouchHandleOrientation::LEFT);
EXPECT_EQ(TOUCH_HANDLE_RIGHT, drawable().orientation); EXPECT_EQ(TouchHandleOrientation::RIGHT, drawable().orientation);
event = MockMotionEvent(MockMotionEvent::ACTION_MOVE); event = MockMotionEvent(MockMotionEvent::ACTION_MOVE);
EXPECT_TRUE(handle.WillHandleTouchEvent(event)); EXPECT_TRUE(handle.WillHandleTouchEvent(event));
EXPECT_TRUE(GetAndResetHandleDragged()); EXPECT_TRUE(GetAndResetHandleDragged());
EXPECT_TRUE(IsDragging()); EXPECT_TRUE(IsDragging());
EXPECT_EQ(TOUCH_HANDLE_RIGHT, drawable().orientation); EXPECT_EQ(TouchHandleOrientation::RIGHT, drawable().orientation);
event = MockMotionEvent(MockMotionEvent::ACTION_UP); event = MockMotionEvent(MockMotionEvent::ACTION_UP);
EXPECT_TRUE(handle.WillHandleTouchEvent(event)); EXPECT_TRUE(handle.WillHandleTouchEvent(event));
EXPECT_FALSE(GetAndResetHandleDragged()); EXPECT_FALSE(GetAndResetHandleDragged());
EXPECT_FALSE(IsDragging()); EXPECT_FALSE(IsDragging());
EXPECT_EQ(TOUCH_HANDLE_LEFT, drawable().orientation); EXPECT_EQ(TouchHandleOrientation::LEFT, drawable().orientation);
} }
TEST_F(TouchHandleTest, DragDefersFade) { TEST_F(TouchHandleTest, DragDefersFade) {
TouchHandle handle(this, TOUCH_HANDLE_CENTER); TouchHandle handle(this, TouchHandleOrientation::CENTER);
handle.SetVisible(true, TouchHandle::ANIMATION_NONE); handle.SetVisible(true, TouchHandle::ANIMATION_NONE);
MockMotionEvent event(MockMotionEvent::ACTION_DOWN); MockMotionEvent event(MockMotionEvent::ACTION_DOWN);
...@@ -406,7 +407,7 @@ TEST_F(TouchHandleTest, DragDefersFade) { ...@@ -406,7 +407,7 @@ TEST_F(TouchHandleTest, DragDefersFade) {
} }
TEST_F(TouchHandleTest, DragTargettingUsesTouchSize) { TEST_F(TouchHandleTest, DragTargettingUsesTouchSize) {
TouchHandle handle(this, TOUCH_HANDLE_CENTER); TouchHandle handle(this, TouchHandleOrientation::CENTER);
handle.SetVisible(true, TouchHandle::ANIMATION_NONE); handle.SetVisible(true, TouchHandle::ANIMATION_NONE);
base::TimeTicks event_time = base::TimeTicks::Now(); base::TimeTicks event_time = base::TimeTicks::Now();
...@@ -457,7 +458,7 @@ TEST_F(TouchHandleTest, DragTargettingUsesTouchSize) { ...@@ -457,7 +458,7 @@ TEST_F(TouchHandleTest, DragTargettingUsesTouchSize) {
} }
TEST_F(TouchHandleTest, Tap) { TEST_F(TouchHandleTest, Tap) {
TouchHandle handle(this, TOUCH_HANDLE_CENTER); TouchHandle handle(this, TouchHandleOrientation::CENTER);
handle.SetVisible(true, TouchHandle::ANIMATION_NONE); handle.SetVisible(true, TouchHandle::ANIMATION_NONE);
base::TimeTicks event_time = base::TimeTicks::Now(); base::TimeTicks event_time = base::TimeTicks::Now();
......
...@@ -26,16 +26,16 @@ gfx::Vector2dF ComputeLineOffsetFromBottom(const SelectionBound& bound) { ...@@ -26,16 +26,16 @@ gfx::Vector2dF ComputeLineOffsetFromBottom(const SelectionBound& bound) {
TouchHandleOrientation ToTouchHandleOrientation(SelectionBound::Type type) { TouchHandleOrientation ToTouchHandleOrientation(SelectionBound::Type type) {
switch (type) { switch (type) {
case SelectionBound::LEFT: case SelectionBound::LEFT:
return TOUCH_HANDLE_LEFT; return TouchHandleOrientation::LEFT;
case SelectionBound::RIGHT: case SelectionBound::RIGHT:
return TOUCH_HANDLE_RIGHT; return TouchHandleOrientation::RIGHT;
case SelectionBound::CENTER: case SelectionBound::CENTER:
return TOUCH_HANDLE_CENTER; return TouchHandleOrientation::CENTER;
case SelectionBound::EMPTY: case SelectionBound::EMPTY:
return TOUCH_HANDLE_ORIENTATION_UNDEFINED; return TouchHandleOrientation::UNDEFINED;
} }
NOTREACHED() << "Invalid selection bound type: " << type; NOTREACHED() << "Invalid selection bound type: " << type;
return TOUCH_HANDLE_ORIENTATION_UNDEFINED; return TouchHandleOrientation::UNDEFINED;
} }
} // namespace } // namespace
...@@ -50,8 +50,8 @@ TouchSelectionController::TouchSelectionController( ...@@ -50,8 +50,8 @@ TouchSelectionController::TouchSelectionController(
tap_slop_(tap_slop), tap_slop_(tap_slop),
show_on_tap_for_empty_editable_(show_on_tap_for_empty_editable), show_on_tap_for_empty_editable_(show_on_tap_for_empty_editable),
response_pending_input_event_(INPUT_EVENT_TYPE_NONE), response_pending_input_event_(INPUT_EVENT_TYPE_NONE),
start_orientation_(TOUCH_HANDLE_ORIENTATION_UNDEFINED), start_orientation_(TouchHandleOrientation::UNDEFINED),
end_orientation_(TOUCH_HANDLE_ORIENTATION_UNDEFINED), end_orientation_(TouchHandleOrientation::UNDEFINED),
is_insertion_active_(false), is_insertion_active_(false),
activate_insertion_automatically_(false), activate_insertion_automatically_(false),
is_selection_active_(false), is_selection_active_(false),
...@@ -102,21 +102,22 @@ void TouchSelectionController::OnSelectionBoundsChanged( ...@@ -102,21 +102,22 @@ void TouchSelectionController::OnSelectionBoundsChanged(
// Instead, prevent selection -> insertion transitions without an intervening // Instead, prevent selection -> insertion transitions without an intervening
// action or selection clearing of some sort, crbug.com/392696. // action or selection clearing of some sort, crbug.com/392696.
if (is_selection_dragging) { if (is_selection_dragging) {
if (start_orientation_ == TOUCH_HANDLE_CENTER) if (start_orientation_ == TouchHandleOrientation::CENTER)
start_orientation_ = start_selection_handle_->orientation(); start_orientation_ = start_selection_handle_->orientation();
if (end_orientation_ == TOUCH_HANDLE_CENTER) if (end_orientation_ == TouchHandleOrientation::CENTER)
end_orientation_ = end_selection_handle_->orientation(); end_orientation_ = end_selection_handle_->orientation();
} }
if (GetStartPosition() != GetEndPosition() || if (GetStartPosition() != GetEndPosition() ||
(is_selection_dragging && (is_selection_dragging &&
start_orientation_ != TOUCH_HANDLE_ORIENTATION_UNDEFINED && start_orientation_ != TouchHandleOrientation::UNDEFINED &&
end_orientation_ != TOUCH_HANDLE_ORIENTATION_UNDEFINED)) { end_orientation_ != TouchHandleOrientation::UNDEFINED)) {
OnSelectionChanged(); OnSelectionChanged();
return; return;
} }
if (start_orientation_ == TOUCH_HANDLE_CENTER && selection_editable_) { if (start_orientation_ == TouchHandleOrientation::CENTER &&
selection_editable_) {
OnInsertionChanged(); OnInsertionChanged();
return; return;
} }
...@@ -165,7 +166,8 @@ void TouchSelectionController::AllowShowingFromCurrentSelection() { ...@@ -165,7 +166,8 @@ void TouchSelectionController::AllowShowingFromCurrentSelection() {
activate_insertion_automatically_ = true; activate_insertion_automatically_ = true;
if (GetStartPosition() != GetEndPosition()) if (GetStartPosition() != GetEndPosition())
OnSelectionChanged(); OnSelectionChanged();
else if (start_orientation_ == TOUCH_HANDLE_CENTER && selection_editable_) else if (start_orientation_ == TouchHandleOrientation::CENTER &&
selection_editable_)
OnInsertionChanged(); OnInsertionChanged();
} }
...@@ -353,7 +355,8 @@ void TouchSelectionController::ActivateInsertion() { ...@@ -353,7 +355,8 @@ void TouchSelectionController::ActivateInsertion() {
DCHECK(!is_selection_active_); DCHECK(!is_selection_active_);
if (!insertion_handle_) if (!insertion_handle_)
insertion_handle_.reset(new TouchHandle(this, TOUCH_HANDLE_CENTER)); insertion_handle_.reset(
new TouchHandle(this, TouchHandleOrientation::CENTER));
if (!is_insertion_active_) { if (!is_insertion_active_) {
is_insertion_active_ = true; is_insertion_active_ = true;
...@@ -421,8 +424,8 @@ void TouchSelectionController::ResetCachedValuesIfInactive() { ...@@ -421,8 +424,8 @@ void TouchSelectionController::ResetCachedValuesIfInactive() {
return; return;
start_ = SelectionBound(); start_ = SelectionBound();
end_ = SelectionBound(); end_ = SelectionBound();
start_orientation_ = TOUCH_HANDLE_ORIENTATION_UNDEFINED; start_orientation_ = TouchHandleOrientation::UNDEFINED;
end_orientation_ = TOUCH_HANDLE_ORIENTATION_UNDEFINED; end_orientation_ = TouchHandleOrientation::UNDEFINED;
} }
const gfx::PointF& TouchSelectionController::GetStartPosition() const { const gfx::PointF& TouchSelectionController::GetStartPosition() const {
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "ui/gfx/geometry/rect_f.h" #include "ui/gfx/geometry/rect_f.h"
#include "ui/touch_selection/selection_event_type.h" #include "ui/touch_selection/selection_event_type.h"
#include "ui/touch_selection/touch_handle.h" #include "ui/touch_selection/touch_handle.h"
#include "ui/touch_selection/touch_handle_orientation.h"
#include "ui/touch_selection/ui_touch_selection_export.h" #include "ui/touch_selection/ui_touch_selection_export.h"
namespace ui { namespace ui {
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
'selection_event_type.h', 'selection_event_type.h',
'touch_handle.cc', 'touch_handle.cc',
'touch_handle.h', 'touch_handle.h',
'touch_handle_orientation.h',
'touch_selection_controller.cc', 'touch_selection_controller.cc',
'touch_selection_controller.h', 'touch_selection_controller.h',
'ui_touch_selection_export.h', 'ui_touch_selection_export.h',
...@@ -74,6 +75,14 @@ ...@@ -74,6 +75,14 @@
}, },
'includes': [ '../../build/android/java_cpp_enum.gypi' ], 'includes': [ '../../build/android/java_cpp_enum.gypi' ],
}, },
{
'target_name': 'touch_handle_orientation_java',
'type': 'none',
'variables': {
'source_file': 'touch_handle_orientation.h',
},
'includes': [ '../../build/android/java_cpp_enum.gypi' ],
},
{ {
'target_name': 'ui_touch_selection_unittests_apk', 'target_name': 'ui_touch_selection_unittests_apk',
'type': 'none', 'type': 'none',
......
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