diff options
author | avi.nitk <avi.nitk@samsung.com> | 2015-03-01 22:47:36 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-03-02 06:48:16 +0000 |
commit | 083c38c02fad2d8537eb46b8cfd92f353f05801f (patch) | |
tree | 47f7fb3d60c9af28f939407094501812ce32f5a3 | |
parent | d841599fbec3dcfa9028b285ea845303d4704008 (diff) | |
download | chromium_src-083c38c02fad2d8537eb46b8cfd92f353f05801f.zip chromium_src-083c38c02fad2d8537eb46b8cfd92f353f05801f.tar.gz chromium_src-083c38c02fad2d8537eb46b8cfd92f353f05801f.tar.bz2 |
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}
-rw-r--r-- | android_webview/java_library_common.mk | 1 | ||||
-rw-r--r-- | android_webview/libwebviewchromium.gypi | 1 | ||||
-rw-r--r-- | content/browser/android/composited_touch_handle_drawable.cc | 18 | ||||
-rw-r--r-- | content/browser/android/popup_touch_handle_drawable.cc | 18 | ||||
-rw-r--r-- | content/content.gyp | 1 | ||||
-rw-r--r-- | content/public/android/BUILD.gn | 1 | ||||
-rw-r--r-- | content/public/android/java/src/org/chromium/content/browser/input/PopupTouchHandleDrawable.java | 40 | ||||
-rw-r--r-- | ui/touch_selection/BUILD.gn | 9 | ||||
-rw-r--r-- | ui/touch_selection/touch_handle.cc | 29 | ||||
-rw-r--r-- | ui/touch_selection/touch_handle.h | 8 | ||||
-rw-r--r-- | ui/touch_selection/touch_handle_orientation.h | 24 | ||||
-rw-r--r-- | ui/touch_selection/touch_handle_unittest.cc | 49 | ||||
-rw-r--r-- | ui/touch_selection/touch_selection_controller.cc | 35 | ||||
-rw-r--r-- | ui/touch_selection/touch_selection_controller.h | 1 | ||||
-rw-r--r-- | ui/touch_selection/ui_touch_selection.gyp | 9 |
15 files changed, 139 insertions, 105 deletions
diff --git a/android_webview/java_library_common.mk b/android_webview/java_library_common.mk index 9353cb4..36da45d 100644 --- a/android_webview/java_library_common.mk +++ b/android_webview/java_library_common.mk @@ -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/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/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/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 \ diff --git a/android_webview/libwebviewchromium.gypi b/android_webview/libwebviewchromium.gypi index feff124..d5da2f0 100644 --- a/android_webview/libwebviewchromium.gypi +++ b/android_webview/libwebviewchromium.gypi @@ -45,6 +45,7 @@ '../ui/android/ui_android.gyp:window_open_disposition_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:touch_handle_orientation_java', # We also need to depend on the Java bindings generated from the .mojom files. '../device/battery/battery.gyp:device_battery_mojo_bindings_for_webview', ], diff --git a/content/browser/android/composited_touch_handle_drawable.cc b/content/browser/android/composited_touch_handle_drawable.cc index f480f55..91a019e 100644 --- a/content/browser/android/composited_touch_handle_drawable.cc +++ b/content/browser/android/composited_touch_handle_drawable.cc @@ -53,13 +53,13 @@ class HandleResources { const SkBitmap& GetBitmap(ui::TouchHandleOrientation orientation) { DCHECK(loaded_); switch (orientation) { - case ui::TOUCH_HANDLE_LEFT: + case ui::TouchHandleOrientation::LEFT: return left_bitmap_; - case ui::TOUCH_HANDLE_RIGHT: + case ui::TouchHandleOrientation::RIGHT: return right_bitmap_; - case ui::TOUCH_HANDLE_CENTER: + case ui::TouchHandleOrientation::CENTER: return center_bitmap_; - case ui::TOUCH_HANDLE_ORIENTATION_UNDEFINED: + case ui::TouchHandleOrientation::UNDEFINED: NOTREACHED() << "Invalid touch handle orientation."; }; return center_bitmap_; @@ -83,7 +83,7 @@ CompositedTouchHandleDrawable::CompositedTouchHandleDrawable( float dpi_scale, jobject context) : dpi_scale_(dpi_scale), - orientation_(ui::TOUCH_HANDLE_ORIENTATION_UNDEFINED), + orientation_(ui::TouchHandleOrientation::UNDEFINED), layer_(cc::UIResourceLayer::Create()) { g_selection_resources.Get().LoadIfNecessary(context); DCHECK(root_layer); @@ -111,16 +111,16 @@ void CompositedTouchHandleDrawable::SetOrientation( layer_->SetBounds(gfx::Size(bitmap.width(), bitmap.height())); switch (orientation_) { - case ui::TOUCH_HANDLE_LEFT: + case ui::TouchHandleOrientation::LEFT: focal_offset_from_origin_ = gfx::Vector2dF(bitmap.width() * 0.75f, 0); break; - case ui::TOUCH_HANDLE_RIGHT: + case ui::TouchHandleOrientation::RIGHT: focal_offset_from_origin_ = gfx::Vector2dF(bitmap.width() * 0.25f, 0); break; - case ui::TOUCH_HANDLE_CENTER: + case ui::TouchHandleOrientation::CENTER: focal_offset_from_origin_ = gfx::Vector2dF(bitmap.width() * 0.5f, 0); break; - case ui::TOUCH_HANDLE_ORIENTATION_UNDEFINED: + case ui::TouchHandleOrientation::UNDEFINED: NOTREACHED() << "Invalid touch handle orientation."; break; }; diff --git a/content/browser/android/popup_touch_handle_drawable.cc b/content/browser/android/popup_touch_handle_drawable.cc index 0ab3935..aef23f8 100644 --- a/content/browser/android/popup_touch_handle_drawable.cc +++ b/content/browser/android/popup_touch_handle_drawable.cc @@ -33,22 +33,8 @@ void PopupTouchHandleDrawable::SetOrientation( ui::TouchHandleOrientation orientation) { JNIEnv* env = base::android::AttachCurrentThread(); jobject obj = drawable_.obj(); - switch (orientation) { - case ui::TOUCH_HANDLE_LEFT: - 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."; - }; + Java_PopupTouchHandleDrawable_setOrientation(env, obj, + static_cast<int>(orientation)); } void PopupTouchHandleDrawable::SetAlpha(float alpha) { diff --git a/content/content.gyp b/content/content.gyp index 7bc40bf..ef9d21a 100644 --- a/content/content.gyp +++ b/content/content.gyp @@ -436,6 +436,7 @@ '../third_party/mojo/mojo_public.gyp:mojo_bindings_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:touch_handle_orientation_java', '../third_party/WebKit/public/blink_headers.gyp:blink_headers_java', 'common_aidl', 'console_message_level_java', diff --git a/content/public/android/BUILD.gn b/content/public/android/BUILD.gn index 9dc5007..74b47ed 100644 --- a/content/public/android/BUILD.gn +++ b/content/public/android/BUILD.gn @@ -50,6 +50,7 @@ android_library("content_java") { ":common_aidl", ":content_public_android_java_enums_srcjar", "//ui/touch_selection:ui_touch_selection_enums_srcjar", + "//ui/touch_selection:ui_touch_handle_orientation_srcjar", ] DEPRECATED_java_in_dir = "java/src" diff --git a/content/public/android/java/src/org/chromium/content/browser/input/PopupTouchHandleDrawable.java b/content/public/android/java/src/org/chromium/content/browser/input/PopupTouchHandleDrawable.java index b05b3c7..56a74a8 100644 --- a/content/public/android/java/src/org/chromium/content/browser/input/PopupTouchHandleDrawable.java +++ b/content/public/android/java/src/org/chromium/content/browser/input/PopupTouchHandleDrawable.java @@ -17,6 +17,7 @@ import org.chromium.base.ApiCompatibilityUtils; import org.chromium.base.CalledByNative; import org.chromium.base.JNINamespace; import org.chromium.content.browser.PositionObserver; +import org.chromium.ui.touch_selection.TouchHandleOrientation; import java.lang.ref.WeakReference; @@ -58,12 +59,7 @@ public class PopupTouchHandleDrawable extends View { private final int[] mTempScreenCoords = new int[2]; - @SuppressLint("RtlHardcoded") - static final int LEFT = 0; - static final int CENTER = 1; - @SuppressLint("RtlHardcoded") - static final int RIGHT = 2; - private int mOrientation = -1; + private int mOrientation = TouchHandleOrientation.UNDEFINED; // Length of the delay before fading in after the last page movement. private static final int FADE_IN_DELAY_MS = 300; @@ -146,35 +142,40 @@ public class PopupTouchHandleDrawable extends View { return handled; } + @CalledByNative private void setOrientation(int orientation) { - assert orientation >= LEFT && orientation <= RIGHT; + assert (orientation >= TouchHandleOrientation.LEFT + && orientation <= TouchHandleOrientation.UNDEFINED); if (mOrientation == orientation) return; - final boolean hadValidOrientation = mOrientation != -1; + final boolean hadValidOrientation = mOrientation != TouchHandleOrientation.UNDEFINED; mOrientation = orientation; final int oldAdjustedPositionX = getAdjustedPositionX(); final int oldAdjustedPositionY = getAdjustedPositionY(); switch (orientation) { - case LEFT: { + case TouchHandleOrientation.LEFT: { mDrawable = HandleViewResources.getLeftHandleDrawable(mContext); mHotspotX = (mDrawable.getIntrinsicWidth() * 3) / 4f; break; } - case RIGHT: { + case TouchHandleOrientation.RIGHT: { mDrawable = HandleViewResources.getRightHandleDrawable(mContext); mHotspotX = mDrawable.getIntrinsicWidth() / 4f; break; } - case CENTER: - default: { + case TouchHandleOrientation.CENTER: { mDrawable = HandleViewResources.getCenterHandleDrawable(mContext); mHotspotX = mDrawable.getIntrinsicWidth() / 2f; break; } + + case TouchHandleOrientation.UNDEFINED: + default: + break; } mHotspotY = 0; @@ -347,21 +348,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 private void setFocus(float focusX, float focusY) { int x = (int) focusX - Math.round(mHotspotX); int y = (int) focusY - Math.round(mHotspotY); diff --git a/ui/touch_selection/BUILD.gn b/ui/touch_selection/BUILD.gn index 23ff624..ede552f 100644 --- a/ui/touch_selection/BUILD.gn +++ b/ui/touch_selection/BUILD.gn @@ -16,6 +16,7 @@ component("touch_selection") { "selection_event_type.h", "touch_handle.cc", "touch_handle.h", + "touch_handle_orientation.h", "touch_selection_controller.cc", "touch_selection_controller.h", "ui_touch_selection_export.h", @@ -59,4 +60,12 @@ if (is_android) { "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", + ] + } } diff --git a/ui/touch_selection/touch_handle.cc b/ui/touch_selection/touch_handle.cc index 0680e6d..0f28c3f 100644 --- a/ui/touch_selection/touch_handle.cc +++ b/ui/touch_selection/touch_handle.cc @@ -44,20 +44,37 @@ bool RectIntersectsCircle(const gfx::RectF& rect, } // 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. TouchHandle::TouchHandle(TouchHandleClient* client, TouchHandleOrientation orientation) : drawable_(client->CreateDrawable()), client_(client), orientation_(orientation), - deferred_orientation_(TOUCH_HANDLE_ORIENTATION_UNDEFINED), + deferred_orientation_(TouchHandleOrientation::UNDEFINED), alpha_(0.f), animate_deferred_fade_(false), enabled_(true), is_visible_(false), is_dragging_(false), is_drag_within_tap_region_(false) { - DCHECK_NE(orientation, TOUCH_HANDLE_ORIENTATION_UNDEFINED); + DCHECK_NE(orientation, TouchHandleOrientation::UNDEFINED); drawable_->SetEnabled(enabled_); drawable_->SetOrientation(orientation_); drawable_->SetAlpha(alpha_); @@ -115,12 +132,12 @@ void TouchHandle::SetPosition(const gfx::PointF& position) { void TouchHandle::SetOrientation(TouchHandleOrientation orientation) { DCHECK(enabled_); - DCHECK_NE(orientation, TOUCH_HANDLE_ORIENTATION_UNDEFINED); + DCHECK_NE(orientation, TouchHandleOrientation::UNDEFINED); if (is_dragging_) { deferred_orientation_ = orientation; return; } - DCHECK_EQ(deferred_orientation_, TOUCH_HANDLE_ORIENTATION_UNDEFINED); + DCHECK_EQ(deferred_orientation_, TouchHandleOrientation::UNDEFINED); if (orientation_ == orientation) return; @@ -230,9 +247,9 @@ void TouchHandle::EndDrag() { is_drag_within_tap_region_ = false; client_->OnHandleDragEnd(*this); - if (deferred_orientation_ != TOUCH_HANDLE_ORIENTATION_UNDEFINED) { + if (deferred_orientation_ != TouchHandleOrientation::UNDEFINED) { TouchHandleOrientation deferred_orientation = deferred_orientation_; - deferred_orientation_ = TOUCH_HANDLE_ORIENTATION_UNDEFINED; + deferred_orientation_ = TouchHandleOrientation::UNDEFINED; SetOrientation(deferred_orientation); } diff --git a/ui/touch_selection/touch_handle.h b/ui/touch_selection/touch_handle.h index f6863a2..12c66d0 100644 --- a/ui/touch_selection/touch_handle.h +++ b/ui/touch_selection/touch_handle.h @@ -12,19 +12,13 @@ #include "ui/gfx/geometry/point_f.h" #include "ui/gfx/geometry/rect_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" namespace ui { 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. class UI_TOUCH_SELECTION_EXPORT TouchHandleDrawable { public: diff --git a/ui/touch_selection/touch_handle_orientation.h b/ui/touch_selection/touch_handle_orientation.h new file mode 100644 index 0000000..e76e73e --- /dev/null +++ b/ui/touch_selection/touch_handle_orientation.h @@ -0,0 +1,24 @@ +// 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_ diff --git a/ui/touch_selection/touch_handle_unittest.cc b/ui/touch_selection/touch_handle_unittest.cc index d90c94b..e86c3d3 100644 --- a/ui/touch_selection/touch_handle_unittest.cc +++ b/ui/touch_selection/touch_handle_unittest.cc @@ -7,6 +7,7 @@ #include "testing/gtest/include/gtest/gtest.h" #include "ui/events/test/motion_event_test_utils.h" #include "ui/gfx/geometry/rect_f.h" +#include "ui/touch_selection/touch_handle_orientation.h" using ui::test::MockMotionEvent; @@ -19,7 +20,7 @@ const float kDefaultDrawableSize = 10.f; struct MockDrawableData { MockDrawableData() - : orientation(TOUCH_HANDLE_ORIENTATION_UNDEFINED), + : orientation(TouchHandleOrientation::UNDEFINED), alpha(0.f), enabled(false), visible(false), @@ -143,7 +144,7 @@ class TouchHandleTest : public testing::Test, public TouchHandleClient { }; TEST_F(TouchHandleTest, Visibility) { - TouchHandle handle(this, TOUCH_HANDLE_CENTER); + TouchHandle handle(this, TouchHandleOrientation::CENTER); EXPECT_FALSE(drawable().visible); handle.SetVisible(true, TouchHandle::ANIMATION_NONE); @@ -159,7 +160,7 @@ TEST_F(TouchHandleTest, Visibility) { } TEST_F(TouchHandleTest, VisibilityAnimation) { - TouchHandle handle(this, TOUCH_HANDLE_CENTER); + TouchHandle handle(this, TouchHandleOrientation::CENTER); ASSERT_FALSE(NeedsAnimate()); ASSERT_FALSE(drawable().visible); ASSERT_EQ(0.f, drawable().alpha); @@ -195,21 +196,21 @@ TEST_F(TouchHandleTest, VisibilityAnimation) { } TEST_F(TouchHandleTest, Orientation) { - TouchHandle handle(this, TOUCH_HANDLE_CENTER); - EXPECT_EQ(TOUCH_HANDLE_CENTER, drawable().orientation); + TouchHandle handle(this, TouchHandleOrientation::CENTER); + EXPECT_EQ(TouchHandleOrientation::CENTER, drawable().orientation); - handle.SetOrientation(TOUCH_HANDLE_LEFT); - EXPECT_EQ(TOUCH_HANDLE_LEFT, drawable().orientation); + handle.SetOrientation(TouchHandleOrientation::LEFT); + EXPECT_EQ(TouchHandleOrientation::LEFT, drawable().orientation); - handle.SetOrientation(TOUCH_HANDLE_RIGHT); - EXPECT_EQ(TOUCH_HANDLE_RIGHT, drawable().orientation); + handle.SetOrientation(TouchHandleOrientation::RIGHT); + EXPECT_EQ(TouchHandleOrientation::RIGHT, drawable().orientation); - handle.SetOrientation(TOUCH_HANDLE_CENTER); - EXPECT_EQ(TOUCH_HANDLE_CENTER, drawable().orientation); + handle.SetOrientation(TouchHandleOrientation::CENTER); + EXPECT_EQ(TouchHandleOrientation::CENTER, drawable().orientation); } TEST_F(TouchHandleTest, Position) { - TouchHandle handle(this, TOUCH_HANDLE_CENTER); + TouchHandle handle(this, TouchHandleOrientation::CENTER); handle.SetVisible(true, TouchHandle::ANIMATION_NONE); gfx::PointF position; @@ -225,7 +226,7 @@ TEST_F(TouchHandleTest, Position) { } TEST_F(TouchHandleTest, PositionNotUpdatedWhileFadingOrInvisible) { - TouchHandle handle(this, TOUCH_HANDLE_CENTER); + TouchHandle handle(this, TouchHandleOrientation::CENTER); handle.SetVisible(true, TouchHandle::ANIMATION_NONE); ASSERT_TRUE(drawable().visible); @@ -260,7 +261,7 @@ TEST_F(TouchHandleTest, PositionNotUpdatedWhileFadingOrInvisible) { TEST_F(TouchHandleTest, Enabled) { // A newly created handle defaults to enabled. - TouchHandle handle(this, TOUCH_HANDLE_CENTER); + TouchHandle handle(this, TouchHandleOrientation::CENTER); EXPECT_TRUE(drawable().enabled); handle.SetVisible(true, TouchHandle::ANIMATION_SMOOTH); @@ -297,7 +298,7 @@ TEST_F(TouchHandleTest, Enabled) { } TEST_F(TouchHandleTest, Drag) { - TouchHandle handle(this, TOUCH_HANDLE_CENTER); + TouchHandle handle(this, TouchHandleOrientation::CENTER); base::TimeTicks event_time = base::TimeTicks::Now(); const float kOffset = kDefaultDrawableSize / 2.f; @@ -351,8 +352,8 @@ TEST_F(TouchHandleTest, Drag) { } TEST_F(TouchHandleTest, DragDefersOrientationChange) { - TouchHandle handle(this, TOUCH_HANDLE_RIGHT); - ASSERT_EQ(drawable().orientation, TOUCH_HANDLE_RIGHT); + TouchHandle handle(this, TouchHandleOrientation::RIGHT); + ASSERT_EQ(drawable().orientation, TouchHandleOrientation::RIGHT); handle.SetVisible(true, TouchHandle::ANIMATION_NONE); MockMotionEvent event(MockMotionEvent::ACTION_DOWN); @@ -360,24 +361,24 @@ TEST_F(TouchHandleTest, DragDefersOrientationChange) { EXPECT_TRUE(IsDragging()); // Orientation changes will be deferred until the drag ends. - handle.SetOrientation(TOUCH_HANDLE_LEFT); - EXPECT_EQ(TOUCH_HANDLE_RIGHT, drawable().orientation); + handle.SetOrientation(TouchHandleOrientation::LEFT); + EXPECT_EQ(TouchHandleOrientation::RIGHT, drawable().orientation); event = MockMotionEvent(MockMotionEvent::ACTION_MOVE); EXPECT_TRUE(handle.WillHandleTouchEvent(event)); EXPECT_TRUE(GetAndResetHandleDragged()); EXPECT_TRUE(IsDragging()); - EXPECT_EQ(TOUCH_HANDLE_RIGHT, drawable().orientation); + EXPECT_EQ(TouchHandleOrientation::RIGHT, drawable().orientation); event = MockMotionEvent(MockMotionEvent::ACTION_UP); EXPECT_TRUE(handle.WillHandleTouchEvent(event)); EXPECT_FALSE(GetAndResetHandleDragged()); EXPECT_FALSE(IsDragging()); - EXPECT_EQ(TOUCH_HANDLE_LEFT, drawable().orientation); + EXPECT_EQ(TouchHandleOrientation::LEFT, drawable().orientation); } TEST_F(TouchHandleTest, DragDefersFade) { - TouchHandle handle(this, TOUCH_HANDLE_CENTER); + TouchHandle handle(this, TouchHandleOrientation::CENTER); handle.SetVisible(true, TouchHandle::ANIMATION_NONE); MockMotionEvent event(MockMotionEvent::ACTION_DOWN); @@ -406,7 +407,7 @@ TEST_F(TouchHandleTest, DragDefersFade) { } TEST_F(TouchHandleTest, DragTargettingUsesTouchSize) { - TouchHandle handle(this, TOUCH_HANDLE_CENTER); + TouchHandle handle(this, TouchHandleOrientation::CENTER); handle.SetVisible(true, TouchHandle::ANIMATION_NONE); base::TimeTicks event_time = base::TimeTicks::Now(); @@ -457,7 +458,7 @@ TEST_F(TouchHandleTest, DragTargettingUsesTouchSize) { } TEST_F(TouchHandleTest, Tap) { - TouchHandle handle(this, TOUCH_HANDLE_CENTER); + TouchHandle handle(this, TouchHandleOrientation::CENTER); handle.SetVisible(true, TouchHandle::ANIMATION_NONE); base::TimeTicks event_time = base::TimeTicks::Now(); diff --git a/ui/touch_selection/touch_selection_controller.cc b/ui/touch_selection/touch_selection_controller.cc index 9ec5d58..71dcce8 100644 --- a/ui/touch_selection/touch_selection_controller.cc +++ b/ui/touch_selection/touch_selection_controller.cc @@ -26,16 +26,16 @@ gfx::Vector2dF ComputeLineOffsetFromBottom(const SelectionBound& bound) { TouchHandleOrientation ToTouchHandleOrientation(SelectionBound::Type type) { switch (type) { case SelectionBound::LEFT: - return TOUCH_HANDLE_LEFT; + return TouchHandleOrientation::LEFT; case SelectionBound::RIGHT: - return TOUCH_HANDLE_RIGHT; + return TouchHandleOrientation::RIGHT; case SelectionBound::CENTER: - return TOUCH_HANDLE_CENTER; + return TouchHandleOrientation::CENTER; case SelectionBound::EMPTY: - return TOUCH_HANDLE_ORIENTATION_UNDEFINED; + return TouchHandleOrientation::UNDEFINED; } NOTREACHED() << "Invalid selection bound type: " << type; - return TOUCH_HANDLE_ORIENTATION_UNDEFINED; + return TouchHandleOrientation::UNDEFINED; } } // namespace @@ -50,8 +50,8 @@ TouchSelectionController::TouchSelectionController( tap_slop_(tap_slop), show_on_tap_for_empty_editable_(show_on_tap_for_empty_editable), response_pending_input_event_(INPUT_EVENT_TYPE_NONE), - start_orientation_(TOUCH_HANDLE_ORIENTATION_UNDEFINED), - end_orientation_(TOUCH_HANDLE_ORIENTATION_UNDEFINED), + start_orientation_(TouchHandleOrientation::UNDEFINED), + end_orientation_(TouchHandleOrientation::UNDEFINED), is_insertion_active_(false), activate_insertion_automatically_(false), is_selection_active_(false), @@ -102,21 +102,22 @@ void TouchSelectionController::OnSelectionBoundsChanged( // Instead, prevent selection -> insertion transitions without an intervening // action or selection clearing of some sort, crbug.com/392696. if (is_selection_dragging) { - if (start_orientation_ == TOUCH_HANDLE_CENTER) + if (start_orientation_ == TouchHandleOrientation::CENTER) start_orientation_ = start_selection_handle_->orientation(); - if (end_orientation_ == TOUCH_HANDLE_CENTER) + if (end_orientation_ == TouchHandleOrientation::CENTER) end_orientation_ = end_selection_handle_->orientation(); } if (GetStartPosition() != GetEndPosition() || (is_selection_dragging && - start_orientation_ != TOUCH_HANDLE_ORIENTATION_UNDEFINED && - end_orientation_ != TOUCH_HANDLE_ORIENTATION_UNDEFINED)) { + start_orientation_ != TouchHandleOrientation::UNDEFINED && + end_orientation_ != TouchHandleOrientation::UNDEFINED)) { OnSelectionChanged(); return; } - if (start_orientation_ == TOUCH_HANDLE_CENTER && selection_editable_) { + if (start_orientation_ == TouchHandleOrientation::CENTER && + selection_editable_) { OnInsertionChanged(); return; } @@ -165,7 +166,8 @@ void TouchSelectionController::AllowShowingFromCurrentSelection() { activate_insertion_automatically_ = true; if (GetStartPosition() != GetEndPosition()) OnSelectionChanged(); - else if (start_orientation_ == TOUCH_HANDLE_CENTER && selection_editable_) + else if (start_orientation_ == TouchHandleOrientation::CENTER && + selection_editable_) OnInsertionChanged(); } @@ -353,7 +355,8 @@ void TouchSelectionController::ActivateInsertion() { DCHECK(!is_selection_active_); if (!insertion_handle_) - insertion_handle_.reset(new TouchHandle(this, TOUCH_HANDLE_CENTER)); + insertion_handle_.reset( + new TouchHandle(this, TouchHandleOrientation::CENTER)); if (!is_insertion_active_) { is_insertion_active_ = true; @@ -421,8 +424,8 @@ void TouchSelectionController::ResetCachedValuesIfInactive() { return; start_ = SelectionBound(); end_ = SelectionBound(); - start_orientation_ = TOUCH_HANDLE_ORIENTATION_UNDEFINED; - end_orientation_ = TOUCH_HANDLE_ORIENTATION_UNDEFINED; + start_orientation_ = TouchHandleOrientation::UNDEFINED; + end_orientation_ = TouchHandleOrientation::UNDEFINED; } const gfx::PointF& TouchSelectionController::GetStartPosition() const { diff --git a/ui/touch_selection/touch_selection_controller.h b/ui/touch_selection/touch_selection_controller.h index 68edee0..abc75b5 100644 --- a/ui/touch_selection/touch_selection_controller.h +++ b/ui/touch_selection/touch_selection_controller.h @@ -10,6 +10,7 @@ #include "ui/gfx/geometry/rect_f.h" #include "ui/touch_selection/selection_event_type.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" namespace ui { diff --git a/ui/touch_selection/ui_touch_selection.gyp b/ui/touch_selection/ui_touch_selection.gyp index f19d51b..851c26f 100644 --- a/ui/touch_selection/ui_touch_selection.gyp +++ b/ui/touch_selection/ui_touch_selection.gyp @@ -24,6 +24,7 @@ 'selection_event_type.h', 'touch_handle.cc', 'touch_handle.h', + 'touch_handle_orientation.h', 'touch_selection_controller.cc', 'touch_selection_controller.h', 'ui_touch_selection_export.h', @@ -75,6 +76,14 @@ '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', 'type': 'none', 'dependencies': [ |