diff options
author | mohsen <mohsen@chromium.org> | 2014-12-08 13:06:46 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-12-08 21:07:39 +0000 |
commit | 29fd405ca491a6fcf0dde6277d92d44300cb2926 (patch) | |
tree | 23c5800d7f015a9ed1c825f478c561119146db9a | |
parent | 57e80c70462acc1bea10385ee14c0bd31a3997bf (diff) | |
download | chromium_src-29fd405ca491a6fcf0dde6277d92d44300cb2926.zip chromium_src-29fd405ca491a6fcf0dde6277d92d44300cb2926.tar.gz chromium_src-29fd405ca491a6fcf0dde6277d92d44300cb2926.tar.bz2 |
Move TouchSelectionController from content to ui
This patch is only moving new unified touch selection files from
content/ to ui/touch_selection/. This is the first step to allow Aura
use the new unified TouchSelectionController.
The only change to TouchSelectionController needed for this move is
replacing use of cc::ViewportSelectionBound with ui::SelectionBound.
The actual use of the new touch selection for Aura will happen in future
CL(s). After that, we can remove current touch selection code from
ui/base/touch/.
BUG=399721
Review URL: https://codereview.chromium.org/759433002
Cr-Commit-Position: refs/heads/master@{#307336}
49 files changed, 703 insertions, 411 deletions
@@ -133,6 +133,7 @@ group("root") { "//ui/snapshot", "//ui/strings", "//ui/surface", + "//ui/touch_selection", "//ui/views", "//ui/views/controls/webview", "//ui/web_dialogs", @@ -297,6 +298,12 @@ group("root") { ] } + if (is_mac || is_ios) { + deps -= [ + "//ui/touch_selection", + ] + } + if (is_win) { deps -= [ "//apps", diff --git a/android_webview/java_library_common.mk b/android_webview/java_library_common.mk index 8ddc77e..2dc1a1f 100644 --- a/android_webview/java_library_common.mk +++ b/android_webview/java_library_common.mk @@ -57,7 +57,7 @@ $(call intermediates-dir-for,GYP,shared)/enums/popup_item_type_java/org/chromium $(call intermediates-dir-for,GYP,shared)/enums/private_key_types_java/org/chromium/net/PrivateKeyType.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/selection_event_type_java/org/chromium/content/browser/input/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/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 89b7d4d..8f5dbe9 100644 --- a/android_webview/libwebviewchromium.gypi +++ b/android_webview/libwebviewchromium.gypi @@ -21,7 +21,6 @@ '../content/content.gyp:popup_item_type_java', '../content/content.gyp:result_codes_java', '../content/content.gyp:screen_orientation_values_java', - '../content/content.gyp:selection_event_type_java', '../content/content.gyp:speech_recognition_error_java', '../content/content.gyp:top_controls_state_java', '../media/media.gyp:media_android_imageformat', @@ -37,6 +36,7 @@ '../ui/android/ui_android.gyp:touch_device_types_java', '../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', ], # Enable feedback-directed optimisation for the library when building in # android. diff --git a/build/all.gyp b/build/all.gyp index 9c325fb..4ab6cfb 100644 --- a/build/all.gyp +++ b/build/all.gyp @@ -36,6 +36,11 @@ '../url/url.gyp:*', ], 'conditions': [ + ['OS!="ios" and OS!="mac"', { + 'dependencies': [ + '../ui/touch_selection/ui_touch_selection.gyp:*', + ], + }], ['OS=="ios"', { 'dependencies': [ '../ios/ios.gyp:*', @@ -312,6 +317,11 @@ '../url/url.gyp:url_unittests', ], 'conditions': [ + ['OS!="ios" and OS!="mac"', { + 'dependencies': [ + '../ui/touch_selection/ui_touch_selection.gyp:ui_touch_selection_unittests', + ], + }], ['OS!="ios" and OS!="android"', { 'dependencies': [ '../cc/blink/cc_blink_tests.gyp:cc_blink_unittests', @@ -834,6 +844,7 @@ '../tools/android/findbugs_plugin/findbugs_plugin.gyp:findbugs_plugin_test', '../ui/base/ui_base_tests.gyp:ui_base_unittests', '../ui/events/events.gyp:events_unittests', + '../ui/touch_selection/ui_touch_selection.gyp:ui_touch_selection_unittests', # Unit test bundles packaged as an apk. '../android_webview/android_webview.gyp:android_webview_test_apk', '../android_webview/android_webview.gyp:android_webview_unittests_apk', @@ -862,6 +873,7 @@ '../ui/base/ui_base_tests.gyp:ui_base_unittests_apk', '../ui/events/events.gyp:events_unittests_apk', '../ui/gfx/gfx_tests.gyp:gfx_unittests_apk', + '../ui/touch_selection/ui_touch_selection.gyp:ui_touch_selection_unittests_apk', ], 'conditions': [ ['enable_webrtc==1 and "<(libpeer_target_type)"=="static_library"', { @@ -1075,6 +1087,7 @@ '../ui/base/ui_base_tests.gyp:ui_base_unittests', '../ui/events/events.gyp:events_unittests', '../ui/gfx/gfx_tests.gyp:gfx_unittests', + '../ui/touch_selection/ui_touch_selection.gyp:ui_touch_selection_unittests', '../ui/views/views.gyp:views_unittests', '../url/url.gyp:url_unittests', ], @@ -1179,6 +1192,7 @@ '../ui/events/events.gyp:events_unittests', '../ui/gfx/gfx_tests.gyp:gfx_unittests', '../ui/keyboard/keyboard.gyp:keyboard_unittests', + '../ui/touch_selection/ui_touch_selection.gyp:ui_touch_selection_unittests', '../url/url.gyp:url_unittests', ], }, @@ -1219,6 +1233,7 @@ '../third_party/widevine/cdm/widevine_cdm.gyp:widevinecdmadapter', '../ui/base/ui_base_tests.gyp:ui_base_unittests', '../ui/gfx/gfx_tests.gyp:gfx_unittests', + '../ui/touch_selection/ui_touch_selection.gyp:ui_touch_selection_unittests', '../ui/views/views.gyp:views_unittests', '../url/url.gyp:url_unittests', ], @@ -1267,6 +1282,7 @@ '../ui/keyboard/keyboard.gyp:*', '../ui/message_center/message_center.gyp:*', '../ui/snapshot/snapshot.gyp:snapshot_unittests', + '../ui/touch_selection/ui_touch_selection.gyp:ui_touch_selection_unittests', '../ui/views/examples/examples.gyp:views_examples_with_content_exe', '../ui/views/views.gyp:views', '../ui/views/views.gyp:views_unittests', diff --git a/build/android/pylib/gtest/gtest_config.py b/build/android/pylib/gtest/gtest_config.py index 0cb8b35..20aaf68 100644 --- a/build/android/pylib/gtest/gtest_config.py +++ b/build/android/pylib/gtest/gtest_config.py @@ -36,6 +36,7 @@ STABLE_TEST_SUITES = [ 'sql_unittests', 'sync_unit_tests', 'ui_base_unittests', + 'ui_touch_selection_unittests', 'unit_tests', 'webkit_unit_tests', ] diff --git a/content/DEPS b/content/DEPS index 04a5d60..ad6512e 100644 --- a/content/DEPS +++ b/content/DEPS @@ -95,6 +95,7 @@ include_rules = [ "+ui/snapshot", "+ui/strings/grit/ui_strings.h", "+ui/surface", + "+ui/touch_selection", "+ui/wm", # Content knows about grd files, but the specifics of how to get a resource # given its id is left to the embedder. diff --git a/content/browser/BUILD.gn b/content/browser/BUILD.gn index ade4a78..c47a9d9 100644 --- a/content/browser/BUILD.gn +++ b/content/browser/BUILD.gn @@ -113,6 +113,7 @@ source_set("browser") { "//third_party/libyuv", "//ui/resources", "//ui/surface", + "//ui/touch_selection", ] } diff --git a/content/browser/android/composited_touch_handle_drawable.cc b/content/browser/android/composited_touch_handle_drawable.cc index 4c37e381..ff734a1 100644 --- a/content/browser/android/composited_touch_handle_drawable.cc +++ b/content/browser/android/composited_touch_handle_drawable.cc @@ -50,16 +50,16 @@ class HandleResources { center_bitmap_.setImmutable(); } - const SkBitmap& GetBitmap(TouchHandleOrientation orientation) { + const SkBitmap& GetBitmap(ui::TouchHandleOrientation orientation) { DCHECK(loaded_); switch (orientation) { - case TOUCH_HANDLE_LEFT: + case ui::TOUCH_HANDLE_LEFT: return left_bitmap_; - case TOUCH_HANDLE_RIGHT: + case ui::TOUCH_HANDLE_RIGHT: return right_bitmap_; - case TOUCH_HANDLE_CENTER: + case ui::TOUCH_HANDLE_CENTER: return center_bitmap_; - case TOUCH_HANDLE_ORIENTATION_UNDEFINED: + case ui::TOUCH_HANDLE_ORIENTATION_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_(TOUCH_HANDLE_ORIENTATION_UNDEFINED), + orientation_(ui::TOUCH_HANDLE_ORIENTATION_UNDEFINED), layer_(cc::UIResourceLayer::Create()) { g_selection_resources.Get().LoadIfNecessary(context); DCHECK(root_layer); @@ -99,7 +99,7 @@ void CompositedTouchHandleDrawable::SetEnabled(bool enabled) { } void CompositedTouchHandleDrawable::SetOrientation( - TouchHandleOrientation orientation) { + ui::TouchHandleOrientation orientation) { DCHECK(layer_->parent()); orientation_ = orientation; @@ -108,16 +108,16 @@ void CompositedTouchHandleDrawable::SetOrientation( layer_->SetBounds(gfx::Size(bitmap.width(), bitmap.height())); switch (orientation_) { - case TOUCH_HANDLE_LEFT: + case ui::TOUCH_HANDLE_LEFT: focal_offset_from_origin_ = gfx::Vector2dF(bitmap.width() * 0.75f, 0); break; - case TOUCH_HANDLE_RIGHT: + case ui::TOUCH_HANDLE_RIGHT: focal_offset_from_origin_ = gfx::Vector2dF(bitmap.width() * 0.25f, 0); break; - case TOUCH_HANDLE_CENTER: + case ui::TOUCH_HANDLE_CENTER: focal_offset_from_origin_ = gfx::Vector2dF(bitmap.width() * 0.5f, 0); break; - case TOUCH_HANDLE_ORIENTATION_UNDEFINED: + case ui::TOUCH_HANDLE_ORIENTATION_UNDEFINED: NOTREACHED() << "Invalid touch handle orientation."; break; }; diff --git a/content/browser/android/composited_touch_handle_drawable.h b/content/browser/android/composited_touch_handle_drawable.h index 68c2a32..3f31d77 100644 --- a/content/browser/android/composited_touch_handle_drawable.h +++ b/content/browser/android/composited_touch_handle_drawable.h @@ -5,7 +5,7 @@ #ifndef CONTENT_BROWSER_ANDROID_COMPOSITED_TOUCH_HANDLE_DRAWABLE_H_ #define CONTENT_BROWSER_ANDROID_COMPOSITED_TOUCH_HANDLE_DRAWABLE_H_ -#include "content/browser/renderer_host/input/touch_handle.h" +#include "ui/touch_selection/touch_handle.h" #include "base/android/jni_android.h" #include "cc/layers/ui_resource_layer.h" @@ -13,16 +13,16 @@ namespace content { // Touch handle drawable implementation backed by a cc layer. -class CompositedTouchHandleDrawable : public TouchHandleDrawable { +class CompositedTouchHandleDrawable : public ui::TouchHandleDrawable { public: CompositedTouchHandleDrawable(cc::Layer* root_layer, float dpi_scale, jobject context); virtual ~CompositedTouchHandleDrawable(); - // TouchHandleDrawable implementation. + // ui::TouchHandleDrawable implementation. virtual void SetEnabled(bool enabled) override; - virtual void SetOrientation(TouchHandleOrientation orientation) override; + virtual void SetOrientation(ui::TouchHandleOrientation orientation) override; virtual void SetAlpha(float alpha) override; virtual void SetFocus(const gfx::PointF& position) override; virtual bool IntersectsWith(const gfx::RectF& rect) const override; @@ -34,7 +34,7 @@ class CompositedTouchHandleDrawable : public TouchHandleDrawable { gfx::RectF BoundingRect() const; const float dpi_scale_; - TouchHandleOrientation orientation_; + ui::TouchHandleOrientation orientation_; gfx::PointF focal_position_; gfx::Vector2dF focal_offset_from_origin_; scoped_refptr<cc::UIResourceLayer> layer_; diff --git a/content/browser/android/content_view_core_impl.cc b/content/browser/android/content_view_core_impl.cc index 69654ea..996cfbe 100644 --- a/content/browser/android/content_view_core_impl.cc +++ b/content/browser/android/content_view_core_impl.cc @@ -589,7 +589,7 @@ void ContentViewCoreImpl::OnSelectionChanged(const std::string& text) { Java_ContentViewCore_onSelectionChanged(env, obj.obj(), jtext.obj()); } -void ContentViewCoreImpl::OnSelectionEvent(SelectionEventType event, +void ContentViewCoreImpl::OnSelectionEvent(ui::SelectionEventType event, const gfx::PointF& position) { JNIEnv* env = AttachCurrentThread(); ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); @@ -599,15 +599,15 @@ void ContentViewCoreImpl::OnSelectionEvent(SelectionEventType event, env, j_obj.obj(), event, position.x(), position.y()); } -scoped_ptr<TouchHandleDrawable> +scoped_ptr<ui::TouchHandleDrawable> ContentViewCoreImpl::CreatePopupTouchHandleDrawable() { JNIEnv* env = AttachCurrentThread(); ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); if (obj.is_null()) { NOTREACHED(); - return scoped_ptr<TouchHandleDrawable>(); + return scoped_ptr<ui::TouchHandleDrawable>(); } - return scoped_ptr<TouchHandleDrawable>(new PopupTouchHandleDrawable( + return scoped_ptr<ui::TouchHandleDrawable>(new PopupTouchHandleDrawable( Java_ContentViewCore_createPopupTouchHandleDrawable(env, obj.obj()), dpi_scale_)); } diff --git a/content/browser/android/content_view_core_impl.h b/content/browser/android/content_view_core_impl.h index b924064..b5ac3da 100644 --- a/content/browser/android/content_view_core_impl.h +++ b/content/browser/android/content_view_core_impl.h @@ -229,9 +229,9 @@ class ContentViewCoreImpl : public ContentViewCore, InputEventAckState ack_result); bool FilterInputEvent(const blink::WebInputEvent& event); void OnSelectionChanged(const std::string& text); - void OnSelectionEvent(SelectionEventType event, + void OnSelectionEvent(ui::SelectionEventType event, const gfx::PointF& anchor_position); - scoped_ptr<TouchHandleDrawable> CreatePopupTouchHandleDrawable(); + scoped_ptr<ui::TouchHandleDrawable> CreatePopupTouchHandleDrawable(); void StartContentIntent(const GURL& content_url); diff --git a/content/browser/android/popup_touch_handle_drawable.cc b/content/browser/android/popup_touch_handle_drawable.cc index d4df077..42b7d7a 100644 --- a/content/browser/android/popup_touch_handle_drawable.cc +++ b/content/browser/android/popup_touch_handle_drawable.cc @@ -30,23 +30,23 @@ void PopupTouchHandleDrawable::SetEnabled(bool enabled) { } void PopupTouchHandleDrawable::SetOrientation( - TouchHandleOrientation orientation) { + ui::TouchHandleOrientation orientation) { JNIEnv* env = base::android::AttachCurrentThread(); jobject obj = drawable_.obj(); switch (orientation) { - case TOUCH_HANDLE_LEFT: + case ui::TOUCH_HANDLE_LEFT: Java_PopupTouchHandleDrawable_setLeftOrientation(env, obj); break; - case TOUCH_HANDLE_RIGHT: + case ui::TOUCH_HANDLE_RIGHT: Java_PopupTouchHandleDrawable_setRightOrientation(env, obj); break; - case TOUCH_HANDLE_CENTER: + case ui::TOUCH_HANDLE_CENTER: Java_PopupTouchHandleDrawable_setCenterOrientation(env, obj); break; - case TOUCH_HANDLE_ORIENTATION_UNDEFINED: + case ui::TOUCH_HANDLE_ORIENTATION_UNDEFINED: NOTREACHED() << "Invalid touch handle orientation."; }; } diff --git a/content/browser/android/popup_touch_handle_drawable.h b/content/browser/android/popup_touch_handle_drawable.h index 512a957..a991cac 100644 --- a/content/browser/android/popup_touch_handle_drawable.h +++ b/content/browser/android/popup_touch_handle_drawable.h @@ -5,22 +5,22 @@ #ifndef CONTENT_BROWSER_ANDROID_POPUP_TOUCH_HANDLE_DRAWABLE_H_ #define CONTENT_BROWSER_ANDROID_POPUP_TOUCH_HANDLE_DRAWABLE_H_ -#include "content/browser/renderer_host/input/touch_handle.h" +#include "ui/touch_selection/touch_handle.h" #include "base/android/jni_android.h" namespace content { // Touch handle drawable backed by an Android PopupWindow. -class PopupTouchHandleDrawable : public TouchHandleDrawable { +class PopupTouchHandleDrawable : public ui::TouchHandleDrawable { public: PopupTouchHandleDrawable(base::android::ScopedJavaLocalRef<jobject> drawable, float dpi_scale); virtual ~PopupTouchHandleDrawable(); - // TouchHandleDrawable implementation. + // ui::TouchHandleDrawable implementation. virtual void SetEnabled(bool enabled) override; - virtual void SetOrientation(TouchHandleOrientation orientation) override; + virtual void SetOrientation(ui::TouchHandleOrientation orientation) override; virtual void SetAlpha(float alpha) override; virtual void SetFocus(const gfx::PointF& position) override; virtual bool IntersectsWith(const gfx::RectF& rect) const override; diff --git a/content/browser/renderer_host/render_widget_host_view_android.cc b/content/browser/renderer_host/render_widget_host_view_android.cc index 7bed6a0..1e67890 100644 --- a/content/browser/renderer_host/render_widget_host_view_android.cc +++ b/content/browser/renderer_host/render_widget_host_view_android.cc @@ -45,7 +45,6 @@ #include "content/browser/renderer_host/compositor_impl_android.h" #include "content/browser/renderer_host/dip_util.h" #include "content/browser/renderer_host/input/synthetic_gesture_target_android.h" -#include "content/browser/renderer_host/input/touch_selection_controller.h" #include "content/browser/renderer_host/input/web_input_event_builders_android.h" #include "content/browser/renderer_host/input/web_input_event_util.h" #include "content/browser/renderer_host/render_process_host_impl.h" @@ -81,6 +80,7 @@ #include "ui/gfx/geometry/dip_util.h" #include "ui/gfx/screen.h" #include "ui/gfx/size_conversions.h" +#include "ui/touch_selection/touch_selection_controller.h" namespace content { @@ -257,14 +257,14 @@ ui::LatencyInfo CreateLatencyInfo(const blink::WebInputEvent& event) { return latency_info; } -scoped_ptr<TouchSelectionController> CreateSelectionController( - TouchSelectionControllerClient* client, +scoped_ptr<ui::TouchSelectionController> CreateSelectionController( + ui::TouchSelectionControllerClient* client, ContentViewCore* content_view_core) { DCHECK(client); DCHECK(content_view_core); int tap_timeout_ms = gfx::ViewConfiguration::GetTapTimeoutInMs(); int touch_slop_pixels = gfx::ViewConfiguration::GetTouchSlopInPixels(); - return make_scoped_ptr(new TouchSelectionController( + return make_scoped_ptr(new ui::TouchSelectionController( client, base::TimeDelta::FromMilliseconds(tap_timeout_ms), touch_slop_pixels / content_view_core->GetDpiScale())); @@ -1245,24 +1245,25 @@ void RenderWidgetHostViewAndroid::SelectBetweenCoordinates( } void RenderWidgetHostViewAndroid::OnSelectionEvent( - SelectionEventType event, + ui::SelectionEventType event, const gfx::PointF& position) { DCHECK(content_view_core_); // Showing the selection action bar can alter the current View coordinates in // such a way that the current MotionEvent stream is suddenly shifted in // space. Avoid the associated scroll jump by pre-emptively cancelling gesture // detection; scrolling after the selection is activated is unnecessary. - if (event == SelectionEventType::SELECTION_SHOWN) + if (event == ui::SelectionEventType::SELECTION_SHOWN) ResetGestureDetection(); content_view_core_->OnSelectionEvent(event, position); } -scoped_ptr<TouchHandleDrawable> RenderWidgetHostViewAndroid::CreateDrawable() { +scoped_ptr<ui::TouchHandleDrawable> +RenderWidgetHostViewAndroid::CreateDrawable() { DCHECK(content_view_core_); if (!using_browser_compositor_) return content_view_core_->CreatePopupTouchHandleDrawable(); - return scoped_ptr<TouchHandleDrawable>(new CompositedTouchHandleDrawable( + return scoped_ptr<ui::TouchHandleDrawable>(new CompositedTouchHandleDrawable( content_view_core_->GetLayer().get(), content_view_core_->GetDpiScale(), // Use the activity context (instead of the application context) to ensure @@ -1316,7 +1317,8 @@ void RenderWidgetHostViewAndroid::OnFrameMetadataUpdated( if (selection_controller_) { selection_controller_->OnSelectionBoundsChanged( - frame_metadata.selection_start, frame_metadata.selection_end); + ui::SelectionBound(frame_metadata.selection_start), + ui::SelectionBound(frame_metadata.selection_end)); } // All offsets and sizes are in CSS pixels. @@ -1627,11 +1629,10 @@ void RenderWidgetHostViewAndroid::OnShowingPastePopup( // of the region have been updated, explicitly set the properties now. // TODO(jdduke): Remove this workaround when auxiliary paste popup // notifications are no longer required, crbug.com/398170. - cc::ViewportSelectionBound insertion_bound; - insertion_bound.type = cc::SELECTION_BOUND_CENTER; - insertion_bound.visible = true; - insertion_bound.edge_top = point; - insertion_bound.edge_bottom = point; + ui::SelectionBound insertion_bound; + insertion_bound.set_type(ui::SelectionBound::CENTER); + insertion_bound.set_visible(true); + insertion_bound.SetEdge(point, point); selection_controller_->HideAndDisallowShowingAutomatically(); selection_controller_->OnSelectionEditable(true); selection_controller_->OnSelectionEmpty(true); diff --git a/content/browser/renderer_host/render_widget_host_view_android.h b/content/browser/renderer_host/render_widget_host_view_android.h index fb0c63c..0ac5171 100644 --- a/content/browser/renderer_host/render_widget_host_view_android.h +++ b/content/browser/renderer_host/render_widget_host_view_android.h @@ -20,7 +20,6 @@ #include "content/browser/renderer_host/delegated_frame_evictor.h" #include "content/browser/renderer_host/ime_adapter_android.h" #include "content/browser/renderer_host/input/stylus_text_selector.h" -#include "content/browser/renderer_host/input/touch_selection_controller.h" #include "content/browser/renderer_host/render_widget_host_view_base.h" #include "content/common/content_export.h" #include "content/public/browser/readback_types.h" @@ -31,6 +30,7 @@ #include "ui/events/gesture_detection/filtered_gesture_provider.h" #include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/vector2d_f.h" +#include "ui/touch_selection/touch_selection_controller.h" struct ViewHostMsg_TextInputState_Params; @@ -85,7 +85,7 @@ class CONTENT_EXPORT RenderWidgetHostViewAndroid public ui::WindowAndroidObserver, public DelegatedFrameEvictorClient, public StylusTextSelectorClient, - public TouchSelectionControllerClient { + public ui::TouchSelectionControllerClient { public: RenderWidgetHostViewAndroid(RenderWidgetHostImpl* widget, ContentViewCoreImpl* content_view_core); @@ -207,16 +207,16 @@ class CONTENT_EXPORT RenderWidgetHostViewAndroid void OnStylusSelectEnd() override; void OnStylusSelectTap(base::TimeTicks time, float x, float y) override; - // TouchSelectionControllerClient implementation. + // ui::TouchSelectionControllerClient implementation. virtual bool SupportsAnimation() const override; virtual void SetNeedsAnimate() override; virtual void MoveCaret(const gfx::PointF& position) override; virtual void MoveRangeSelectionExtent(const gfx::PointF& extent) override; virtual void SelectBetweenCoordinates(const gfx::PointF& base, const gfx::PointF& extent) override; - virtual void OnSelectionEvent(SelectionEventType event, + virtual void OnSelectionEvent(ui::SelectionEventType event, const gfx::PointF& anchor_position) override; - virtual scoped_ptr<TouchHandleDrawable> CreateDrawable() override; + virtual scoped_ptr<ui::TouchHandleDrawable> CreateDrawable() override; // Non-virtual methods void SetContentViewCore(ContentViewCoreImpl* content_view_core); @@ -382,7 +382,7 @@ class CONTENT_EXPORT RenderWidgetHostViewAndroid // Manages selection handle rendering and manipulation. // This will always be NULL if |content_view_core_| is NULL. - scoped_ptr<TouchSelectionController> selection_controller_; + scoped_ptr<ui::TouchSelectionController> selection_controller_; int accelerated_surface_route_id_; diff --git a/content/browser/renderer_host/render_widget_host_view_aura.cc b/content/browser/renderer_host/render_widget_host_view_aura.cc index 8db3fae..6730164 100644 --- a/content/browser/renderer_host/render_widget_host_view_aura.cc +++ b/content/browser/renderer_host/render_widget_host_view_aura.cc @@ -929,13 +929,14 @@ gfx::Size RenderWidgetHostViewAura::GetRequestedRendererSize() const { void RenderWidgetHostViewAura::SelectionBoundsChanged( const ViewHostMsg_SelectionBounds_Params& params) { ui::SelectionBound anchor_bound, focus_bound; - anchor_bound.edge_top = params.anchor_rect.origin(); - anchor_bound.edge_bottom = params.anchor_rect.bottom_left(); - focus_bound.edge_top = params.focus_rect.origin(); - focus_bound.edge_bottom = params.focus_rect.bottom_left(); + anchor_bound.SetEdge(params.anchor_rect.origin(), + params.anchor_rect.bottom_left()); + focus_bound.SetEdge(params.focus_rect.origin(), + params.focus_rect.bottom_left()); if (params.anchor_rect == params.focus_rect) { - anchor_bound.type = focus_bound.type = ui::SelectionBound::CENTER; + anchor_bound.set_type(ui::SelectionBound::CENTER); + focus_bound.set_type(ui::SelectionBound::CENTER); } else { // Whether text is LTR at the anchor handle. bool anchor_LTR = params.anchor_dir == blink::WebTextDirectionLeftToRight; @@ -944,15 +945,15 @@ void RenderWidgetHostViewAura::SelectionBoundsChanged( if ((params.is_anchor_first && anchor_LTR) || (!params.is_anchor_first && !anchor_LTR)) { - anchor_bound.type = ui::SelectionBound::LEFT; + anchor_bound.set_type(ui::SelectionBound::LEFT); } else { - anchor_bound.type = ui::SelectionBound::RIGHT; + anchor_bound.set_type(ui::SelectionBound::RIGHT); } if ((params.is_anchor_first && focus_LTR) || (!params.is_anchor_first && !focus_LTR)) { - focus_bound.type = ui::SelectionBound::RIGHT; + focus_bound.set_type(ui::SelectionBound::RIGHT); } else { - focus_bound.type = ui::SelectionBound::LEFT; + focus_bound.set_type(ui::SelectionBound::LEFT); } } diff --git a/content/browser/renderer_host/render_widget_host_view_aura.h b/content/browser/renderer_host/render_widget_host_view_aura.h index 3682c5f..47c15e8 100644 --- a/content/browser/renderer_host/render_widget_host_view_aura.h +++ b/content/browser/renderer_host/render_widget_host_view_aura.h @@ -29,6 +29,7 @@ #include "ui/aura/window_delegate.h" #include "ui/aura/window_tree_host_observer.h" #include "ui/base/ime/text_input_client.h" +#include "ui/base/touch/selection_bound.h" #include "ui/base/touch/touch_editing_controller.h" #include "ui/gfx/display_observer.h" #include "ui/gfx/insets.h" diff --git a/content/browser/web_contents/touch_editable_impl_aura.cc b/content/browser/web_contents/touch_editable_impl_aura.cc index 26c7e4f..1fabce6 100644 --- a/content/browser/web_contents/touch_editable_impl_aura.cc +++ b/content/browser/web_contents/touch_editable_impl_aura.cc @@ -14,6 +14,7 @@ #include "ui/aura/window.h" #include "ui/aura/window_tree_host.h" #include "ui/base/clipboard/clipboard.h" +#include "ui/base/touch/selection_bound.h" #include "ui/base/ui_base_switches_util.h" #include "ui/gfx/range/range.h" #include "ui/strings/grit/ui_strings.h" diff --git a/content/browser/web_contents/touch_editable_impl_aura_browsertest.cc b/content/browser/web_contents/touch_editable_impl_aura_browsertest.cc index dad49cd..b67aa55 100644 --- a/content/browser/web_contents/touch_editable_impl_aura_browsertest.cc +++ b/content/browser/web_contents/touch_editable_impl_aura_browsertest.cc @@ -204,8 +204,8 @@ IN_PROC_BROWSER_TEST_F(TouchEditableImplAuraTest, touch_editable->Reset(); ui::SelectionBound anchor, focus; touch_editable->GetSelectionEndPoints(&anchor, &focus); - int handle_grab_x = bounds.x() + anchor.edge_bottom.x(); - int handle_grab_y = bounds.y() + anchor.edge_bottom.y() + 1; + int handle_grab_x = bounds.x() + anchor.edge_bottom_rounded().x(); + int handle_grab_y = bounds.y() + anchor.edge_bottom_rounded().y() + 1; generator.GestureScrollSequence( gfx::Point(handle_grab_x, handle_grab_y), gfx::Point(handle_grab_x + 20, handle_grab_y), diff --git a/content/content.gyp b/content/content.gyp index cb10121..25b43e1 100644 --- a/content/content.gyp +++ b/content/content.gyp @@ -444,6 +444,7 @@ '../mojo/public/mojo_public.gyp:mojo_bindings_java', '../net/net.gyp:net', '../ui/android/ui_android.gyp:ui_java', + '../ui/touch_selection/ui_touch_selection.gyp:selection_event_type_java', 'common_aidl', 'content_common', 'content_strings_grd', @@ -451,7 +452,6 @@ 'gesture_event_type_java', 'popup_item_type_java', 'result_codes_java', - 'selection_event_type_java', 'speech_recognition_error_java', 'top_controls_state_java', 'screen_orientation_values_java', @@ -509,14 +509,6 @@ 'includes': [ '../build/android/java_cpp_enum.gypi' ], }, { - 'target_name': 'selection_event_type_java', - 'type': 'none', - 'variables': { - 'source_file': 'browser/renderer_host/input/selection_event_type.h', - }, - 'includes': [ '../build/android/java_cpp_enum.gypi' ], - }, - { 'target_name': 'speech_recognition_error_java', 'type': 'none', 'variables': { diff --git a/content/content_browser.gypi b/content/content_browser.gypi index 0f5cb30..61ee8d4 100644 --- a/content/content_browser.gypi +++ b/content/content_browser.gypi @@ -1018,8 +1018,6 @@ 'browser/renderer_host/input/motion_event_android.h', 'browser/renderer_host/input/motion_event_web.cc', 'browser/renderer_host/input/motion_event_web.h', - 'browser/renderer_host/input/selection_event_type.h', - 'browser/renderer_host/input/selection_event_type_list.h', 'browser/renderer_host/input/stylus_text_selector.cc', 'browser/renderer_host/input/stylus_text_selector.h', 'browser/renderer_host/input/synthetic_gesture.cc', @@ -1051,10 +1049,6 @@ 'browser/renderer_host/input/touch_event_queue.h', 'browser/renderer_host/input/touch_action_filter.cc', 'browser/renderer_host/input/touch_action_filter.h', - 'browser/renderer_host/input/touch_handle.cc', - 'browser/renderer_host/input/touch_handle.h', - 'browser/renderer_host/input/touch_selection_controller.cc', - 'browser/renderer_host/input/touch_selection_controller.h', 'browser/renderer_host/input/touchpad_tap_suppression_controller.cc', 'browser/renderer_host/input/touchpad_tap_suppression_controller.h', 'browser/renderer_host/input/touchscreen_tap_suppression_controller.cc', @@ -1667,6 +1661,7 @@ '../third_party/angle/src/angle.gyp:commit_id', '../third_party/leveldatabase/leveldatabase.gyp:leveldatabase', '../ui/surface/surface.gyp:surface', + '../ui/touch_selection/ui_touch_selection.gyp:ui_touch_selection', ], 'export_dependent_settings': [ '../mojo/public/mojo_public.gyp:mojo_cpp_bindings', diff --git a/content/content_tests.gypi b/content/content_tests.gypi index ac3d870..96b6def 100644 --- a/content/content_tests.gypi +++ b/content/content_tests.gypi @@ -590,8 +590,6 @@ 'browser/renderer_host/input/touch_action_filter_unittest.cc', 'browser/renderer_host/input/touch_emulator_unittest.cc', 'browser/renderer_host/input/touch_event_queue_unittest.cc', - 'browser/renderer_host/input/touch_handle_unittest.cc', - 'browser/renderer_host/input/touch_selection_controller_unittest.cc', 'browser/renderer_host/input/web_input_event_util_unittest.cc', 'browser/renderer_host/media/audio_input_device_manager_unittest.cc', 'browser/renderer_host/media/audio_renderer_host_unittest.cc', diff --git a/content/public/android/BUILD.gn b/content/public/android/BUILD.gn index f0e1515..f370cc1 100644 --- a/content/public/android/BUILD.gn +++ b/content/public/android/BUILD.gn @@ -46,6 +46,7 @@ android_library("content_java") { srcjar_deps = [ ":common_aidl", ":content_public_android_java_enums_srcjar", + "//ui/touch_selection:ui_touch_selection_enums_srcjar", ] DEPRECATED_java_in_dir = "java/src" @@ -105,7 +106,6 @@ java_cpp_enum("content_public_android_java_enums_srcjar") { sources = [ "//content/browser/android/content_view_core_impl.cc", "//content/browser/android/gesture_event_type.h", - "//content/browser/renderer_host/input/selection_event_type.h", "//content/browser/gamepad/gamepad_standard_mappings.h", "//content/public/common/result_codes.h", "//content/public/common/screen_orientation_values.h", @@ -117,7 +117,6 @@ java_cpp_enum("content_public_android_java_enums_srcjar") { "org/chromium/content/browser/input/CanonicalAxisIndex.java", "org/chromium/content/browser/input/CanonicalButtonIndex.java", "org/chromium/content/browser/input/PopupItemType.java", - "org/chromium/content/browser/input/SelectionEventType.java", "org/chromium/content_public/common/ResultCode.java", "org/chromium/content_public/common/ScreenOrientationValues.java", "org/chromium/content_public/common/SpeechRecognitionErrorCode.java", diff --git a/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java b/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java index 842f797..476e9bf 100644 --- a/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java +++ b/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java @@ -73,7 +73,6 @@ import org.chromium.content.browser.input.SelectPopup; import org.chromium.content.browser.input.SelectPopupDialog; import org.chromium.content.browser.input.SelectPopupDropdown; import org.chromium.content.browser.input.SelectPopupItem; -import org.chromium.content.browser.input.SelectionEventType; import org.chromium.content.common.ContentSwitches; import org.chromium.content_public.browser.GestureStateListener; import org.chromium.content_public.browser.WebContents; @@ -82,6 +81,7 @@ import org.chromium.ui.base.ViewAndroid; import org.chromium.ui.base.ViewAndroidDelegate; import org.chromium.ui.base.WindowAndroid; import org.chromium.ui.gfx.DeviceDisplayInfo; +import org.chromium.ui.touch_selection.SelectionEventType; import java.lang.annotation.Annotation; import java.lang.reflect.Field; diff --git a/ui/base/BUILD.gn b/ui/base/BUILD.gn index 5a139f3..45576a6 100644 --- a/ui/base/BUILD.gn +++ b/ui/base/BUILD.gn @@ -215,6 +215,8 @@ component("base") { "text/bytes_formatting.h", "theme_provider.cc", "theme_provider.h", + "touch/selection_bound.cc", + "touch/selection_bound.h", "touch/touch_device.h", "touch/touch_editing_controller.cc", "touch/touch_editing_controller.h", @@ -764,7 +766,7 @@ if (!is_android) { "models/tree_node_model_unittest.cc", "test/data/resource.h", "text/bytes_formatting_unittest.cc", - "touch/touch_editing_controller_unittest.cc", + "touch/selection_bound_unittest.cc", "view_prop_unittest.cc", "webui/web_ui_util_unittest.cc", "x/selection_requestor_unittest.cc", diff --git a/ui/base/touch/selection_bound.cc b/ui/base/touch/selection_bound.cc new file mode 100644 index 0000000..2102ef24 --- /dev/null +++ b/ui/base/touch/selection_bound.cc @@ -0,0 +1,93 @@ +// 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. + +#include <algorithm> + +#include "base/macros.h" +#include "cc/output/viewport_selection_bound.h" +#include "ui/base/touch/selection_bound.h" +#include "ui/gfx/geometry/point_conversions.h" +#include "ui/gfx/rect.h" + +namespace ui { + +namespace { + +SelectionBound::Type ConvertToSelectionBoundType(cc::SelectionBoundType type) { + switch (type) { + case cc::SELECTION_BOUND_LEFT: + return SelectionBound::LEFT; + case cc::SELECTION_BOUND_RIGHT: + return SelectionBound::RIGHT; + case cc::SELECTION_BOUND_CENTER: + return SelectionBound::CENTER; + case cc::SELECTION_BOUND_EMPTY: + return SelectionBound::EMPTY; + } + NOTREACHED() << "Unknown selection bound type"; + return SelectionBound::EMPTY; +} + +} // namespace + +SelectionBound::SelectionBound() : type_(EMPTY), visible_(false) { +} + +SelectionBound::SelectionBound(const cc::ViewportSelectionBound& bound) + : type_(ConvertToSelectionBoundType(bound.type)), + visible_(bound.visible) { + if (type_ != EMPTY) + SetEdge(bound.edge_top, bound.edge_bottom); +} + +SelectionBound::~SelectionBound() { +} + +void SelectionBound::SetEdgeTop(const gfx::PointF& value) { + edge_top_ = value; + edge_top_rounded_ = gfx::ToRoundedPoint(value); +} + +void SelectionBound::SetEdgeBottom(const gfx::PointF& value) { + edge_bottom_ = value; + edge_bottom_rounded_ = gfx::ToRoundedPoint(value); +} + +void SelectionBound::SetEdge(const gfx::PointF& top, + const gfx::PointF& bottom) { + SetEdgeTop(top); + SetEdgeBottom(bottom); +} + +int SelectionBound::GetHeight() const { + return edge_bottom_rounded_.y() - edge_top_rounded_.y(); +} + +bool operator==(const SelectionBound& lhs, const SelectionBound& rhs) { + return lhs.type() == rhs.type() && lhs.visible() == rhs.visible() && + lhs.edge_top() == rhs.edge_top() && + lhs.edge_bottom() == rhs.edge_bottom(); +} + +bool operator!=(const SelectionBound& lhs, const SelectionBound& rhs) { + return !(lhs == rhs); +} + +gfx::Rect RectBetweenSelectionBounds(const SelectionBound& b1, + const SelectionBound& b2) { + gfx::Point top_left(b1.edge_top_rounded()); + top_left.SetToMin(b1.edge_bottom_rounded()); + top_left.SetToMin(b2.edge_top_rounded()); + top_left.SetToMin(b2.edge_bottom_rounded()); + + gfx::Point bottom_right(b1.edge_top_rounded()); + bottom_right.SetToMax(b1.edge_bottom_rounded()); + bottom_right.SetToMax(b2.edge_top_rounded()); + bottom_right.SetToMax(b2.edge_bottom_rounded()); + + gfx::Vector2d diff = bottom_right - top_left; + return gfx::Rect(top_left, gfx::Size(diff.x(), diff.y())); +} + +} // namespace ui diff --git a/ui/base/touch/selection_bound.h b/ui/base/touch/selection_bound.h new file mode 100644 index 0000000..f7f0f97 --- /dev/null +++ b/ui/base/touch/selection_bound.h @@ -0,0 +1,75 @@ +// 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_BASE_TOUCH_SELECTION_BOUND_H_ +#define UI_BASE_TOUCH_SELECTION_BOUND_H_ + +#include "ui/base/ui_base_export.h" +#include "ui/gfx/point.h" +#include "ui/gfx/point_f.h" + +namespace cc { +struct ViewportSelectionBound; +} + +namespace gfx { +class Rect; +} + +namespace ui { + +// Bound of a selection end-point. +class UI_BASE_EXPORT SelectionBound { + public: + enum Type { + LEFT, + RIGHT, + CENTER, + EMPTY, + LAST = EMPTY + }; + + SelectionBound(); + explicit SelectionBound(const cc::ViewportSelectionBound& bound); + ~SelectionBound(); + + Type type() const { return type_; } + void set_type(Type value) { type_ = value; } + + const gfx::PointF& edge_top() const { return edge_top_; } + const gfx::Point& edge_top_rounded() const { return edge_top_rounded_; } + void SetEdgeTop(const gfx::PointF& value); + + const gfx::PointF& edge_bottom() const { return edge_bottom_; } + const gfx::Point& edge_bottom_rounded() const { return edge_bottom_rounded_; } + void SetEdgeBottom(const gfx::PointF& value); + + void SetEdge(const gfx::PointF& top, const gfx::PointF& bottom); + + bool visible() const { return visible_; } + void set_visible(bool value) { visible_ = value; } + + // Returns the vertical difference between rounded top and bottom. + int GetHeight() const; + + private: + Type type_; + gfx::PointF edge_top_; + gfx::PointF edge_bottom_; + gfx::Point edge_top_rounded_; + gfx::Point edge_bottom_rounded_; + bool visible_; +}; + +UI_BASE_EXPORT bool operator==(const SelectionBound& lhs, + const SelectionBound& rhs); +UI_BASE_EXPORT bool operator!=(const SelectionBound& lhs, + const SelectionBound& rhs); + +UI_BASE_EXPORT gfx::Rect RectBetweenSelectionBounds(const SelectionBound& b1, + const SelectionBound& b2); + +} // namespace ui + +#endif // UI_BASE_TOUCH_SELECTION_BOUND_H_ diff --git a/ui/base/touch/selection_bound_unittest.cc b/ui/base/touch/selection_bound_unittest.cc new file mode 100644 index 0000000..363338d --- /dev/null +++ b/ui/base/touch/selection_bound_unittest.cc @@ -0,0 +1,90 @@ +// 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. + +#include "ui/base/touch/selection_bound.h" + +#include "testing/gtest/include/gtest/gtest.h" +#include "ui/gfx/rect.h" + +namespace ui { + +TEST(SelectionBoundTest, RectBetweenSelectionBounds) { + SelectionBound b1, b2; + // Simple case of aligned vertical bounds of equal height + b1.SetEdge(gfx::Point(0, 20), gfx::Point(0, 25)); + b2.SetEdge(gfx::Point(110, 20), gfx::Point(110, 25)); + gfx::Rect expected_rect( + b1.edge_top_rounded().x(), + b1.edge_top_rounded().y(), + b2.edge_top_rounded().x() - b1.edge_top_rounded().x(), + b2.edge_bottom_rounded().y() - b2.edge_top_rounded().y()); + EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2)); + EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1)); + + // Parallel vertical bounds of different heights + b1.SetEdge(gfx::Point(10, 20), gfx::Point(10, 25)); + b2.SetEdge(gfx::Point(110, 0), gfx::Point(110, 35)); + expected_rect = gfx::Rect( + b1.edge_top_rounded().x(), + b2.edge_top_rounded().y(), + b2.edge_top_rounded().x() - b1.edge_top_rounded().x(), + b2.edge_bottom_rounded().y() - b2.edge_top_rounded().y()); + EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2)); + EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1)); + + b1.SetEdge(gfx::Point(10, 20), gfx::Point(10, 30)); + b2.SetEdge(gfx::Point(110, 25), gfx::Point(110, 45)); + expected_rect = gfx::Rect( + b1.edge_top_rounded().x(), + b1.edge_top_rounded().y(), + b2.edge_top_rounded().x() - b1.edge_top_rounded().x(), + b2.edge_bottom_rounded().y() - b1.edge_top_rounded().y()); + EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2)); + EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1)); + + b1.SetEdge(gfx::Point(10, 20), gfx::Point(10, 30)); + b2.SetEdge(gfx::Point(110, 40), gfx::Point(110, 60)); + expected_rect = gfx::Rect( + b1.edge_top_rounded().x(), + b1.edge_top_rounded().y(), + b2.edge_top_rounded().x() - b1.edge_top_rounded().x(), + b2.edge_bottom_rounded().y() - b1.edge_top_rounded().y()); + EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2)); + EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1)); + + // Overlapping vertical bounds + b1.SetEdge(gfx::Point(10, 20), gfx::Point(10, 30)); + b2.SetEdge(gfx::Point(10, 25), gfx::Point(10, 40)); + expected_rect = gfx::Rect( + b1.edge_top_rounded().x(), + b1.edge_top_rounded().y(), + 0, + b2.edge_bottom_rounded().y() - b1.edge_top_rounded().y()); + EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2)); + EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1)); + + // Non-vertical bounds: "\ \" + b1.SetEdge(gfx::Point(10, 20), gfx::Point(20, 30)); + b2.SetEdge(gfx::Point(110, 40), gfx::Point(120, 60)); + expected_rect = gfx::Rect( + b1.edge_top_rounded().x(), + b1.edge_top_rounded().y(), + b2.edge_bottom_rounded().x() - b1.edge_top_rounded().x(), + b2.edge_bottom_rounded().y() - b1.edge_top_rounded().y()); + EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2)); + EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1)); + + // Non-vertical bounds: "/ \" + b1.SetEdge(gfx::Point(20, 30), gfx::Point(0, 40)); + b2.SetEdge(gfx::Point(110, 30), gfx::Point(120, 40)); + expected_rect = gfx::Rect( + b1.edge_bottom_rounded().x(), + b1.edge_top_rounded().y(), + b2.edge_bottom_rounded().x() - b1.edge_bottom_rounded().x(), + b2.edge_bottom_rounded().y() - b2.edge_top_rounded().y()); + EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2)); + EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1)); +} + +} // namespace ui diff --git a/ui/base/touch/touch_editing_controller.cc b/ui/base/touch/touch_editing_controller.cc index f3c4c24..1b84ed9 100644 --- a/ui/base/touch/touch_editing_controller.cc +++ b/ui/base/touch/touch_editing_controller.cc @@ -10,45 +10,6 @@ namespace { TouchSelectionControllerFactory* g_shared_instance = NULL; } // namespace -SelectionBound::SelectionBound() - : type(ui::SelectionBound::EMPTY) { -} - -SelectionBound::~SelectionBound() { -} - -int SelectionBound::GetHeight() const { - return edge_bottom.y() - edge_top.y(); -} - -bool operator==(const SelectionBound& lhs, const SelectionBound& rhs) { - return lhs.type == rhs.type && lhs.edge_top == rhs.edge_top && - lhs.edge_bottom == rhs.edge_bottom; -} - -bool operator!=(const SelectionBound& lhs, const SelectionBound& rhs) { - return !(lhs == rhs); -} - -gfx::Rect RectBetweenSelectionBounds(const SelectionBound& b1, - const SelectionBound& b2) { - int all_x[] ={ - b1.edge_top.x(), b2.edge_top.x(), b1.edge_bottom.x(), b2.edge_bottom.x() - }; - int all_y[] = { - b1.edge_top.y(), b2.edge_top.y(), b1.edge_bottom.y(), b2.edge_bottom.y() - }; - const int num_elements = arraysize(all_x); - COMPILE_ASSERT(arraysize(all_y) == num_elements, array_size_mismatch); - - int left = *std::min_element(all_x, all_x + num_elements); - int top = *std::min_element(all_y, all_y + num_elements); - int right = *std::max_element(all_x, all_x + num_elements); - int bottom = *std::max_element(all_y, all_y + num_elements); - - return gfx::Rect(left, top, right - left, bottom - top); -} - TouchSelectionController* TouchSelectionController::create( TouchEditable* client_view) { if (g_shared_instance) diff --git a/ui/base/touch/touch_editing_controller.h b/ui/base/touch/touch_editing_controller.h index c8c531d..e4f5205 100644 --- a/ui/base/touch/touch_editing_controller.h +++ b/ui/base/touch/touch_editing_controller.h @@ -6,40 +6,14 @@ #define UI_BASE_TOUCH_TOUCH_EDITING_CONTROLLER_H_ #include "ui/base/models/simple_menu_model.h" -#include "ui/gfx/point.h" -#include "ui/gfx/rect.h" -namespace ui { - -// Bound of a selected region. -struct UI_BASE_EXPORT SelectionBound { - public: - enum Type { - LEFT, - RIGHT, - CENTER, - EMPTY, - LAST = EMPTY - }; - - SelectionBound(); - ~SelectionBound(); - - int GetHeight() const; +namespace gfx { +class Point; +class Rect; +} - Type type; - - gfx::Point edge_top; - gfx::Point edge_bottom; -}; - -UI_BASE_EXPORT bool operator==(const SelectionBound& lhs, - const SelectionBound& rhs); -UI_BASE_EXPORT bool operator!=(const SelectionBound& lhs, - const SelectionBound& rhs); - -UI_BASE_EXPORT gfx::Rect RectBetweenSelectionBounds(const SelectionBound& b1, - const SelectionBound& b2); +namespace ui { +class SelectionBound; // An interface implemented by widget that has text that can be selected/edited // using touch. diff --git a/ui/base/touch/touch_editing_controller_unittest.cc b/ui/base/touch/touch_editing_controller_unittest.cc deleted file mode 100644 index d6b047e..0000000 --- a/ui/base/touch/touch_editing_controller_unittest.cc +++ /dev/null @@ -1,99 +0,0 @@ -// 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. - -#include "ui/base/touch/touch_editing_controller.h" - -#include "testing/gtest/include/gtest/gtest.h" - -namespace ui { - -namespace { - -} - -TEST(TouchEditingControllerTest, SelectionBound) { - SelectionBound b1, b2; - // Simple case of aligned vertical bounds of equal height - b1.edge_top = gfx::Point(0, 20); - b1.edge_bottom = gfx::Point(0, 25); - b2.edge_top = gfx::Point(110, 20); - b2.edge_bottom = gfx::Point(110, 25); - EXPECT_EQ(gfx::Rect(b1.edge_top, - gfx::Size(b2.edge_top.x() - b1.edge_top.x(), - b2.edge_bottom.y() - b2.edge_top.y())), - RectBetweenSelectionBounds(b1, b2)); - EXPECT_EQ(RectBetweenSelectionBounds(b1, b2), - RectBetweenSelectionBounds(b2, b1)); - - // Parallel vertical bounds of different heights - b1.edge_top = gfx::Point(10, 20); - b1.edge_bottom = gfx::Point(10, 25); - b2.edge_top = gfx::Point(110, 0); - b2.edge_bottom = gfx::Point(110, 35); - EXPECT_EQ(gfx::Rect(gfx::Point(b1.edge_top.x(), b2.edge_top.y()), - gfx::Size(b2.edge_top.x() - b1.edge_top.x(), - b2.edge_bottom.y() - b2.edge_top.y())), - RectBetweenSelectionBounds(b1, b2)); - EXPECT_EQ(RectBetweenSelectionBounds(b1, b2), - RectBetweenSelectionBounds(b2, b1)); - - b1.edge_top = gfx::Point(10, 20); - b1.edge_bottom = gfx::Point(10, 30); - b2.edge_top = gfx::Point(110, 25); - b2.edge_bottom = gfx::Point(110, 45); - EXPECT_EQ(gfx::Rect(b1.edge_top, - gfx::Size(b2.edge_top.x() - b1.edge_top.x(), - b2.edge_bottom.y() - b1.edge_top.y())), - RectBetweenSelectionBounds(b1, b2)); - EXPECT_EQ(RectBetweenSelectionBounds(b1, b2), - RectBetweenSelectionBounds(b2, b1)); - - b1.edge_top = gfx::Point(10, 20); - b1.edge_bottom = gfx::Point(10, 30); - b2.edge_top = gfx::Point(110, 40); - b2.edge_bottom = gfx::Point(110, 60); - EXPECT_EQ(gfx::Rect(b1.edge_top, - gfx::Size(b2.edge_top.x() - b1.edge_top.x(), - b2.edge_bottom.y() - b1.edge_top.y())), - RectBetweenSelectionBounds(b1, b2)); - EXPECT_EQ(RectBetweenSelectionBounds(b1, b2), - RectBetweenSelectionBounds(b2, b1)); - - // Overlapping vertical bounds - b1.edge_top = gfx::Point(10, 20); - b1.edge_bottom = gfx::Point(10, 30); - b2.edge_top = gfx::Point(10, 25); - b2.edge_bottom = gfx::Point(10, 40); - EXPECT_EQ(gfx::Rect(b1.edge_top, - gfx::Size(0, b2.edge_bottom.y() - b1.edge_top.y())), - RectBetweenSelectionBounds(b1, b2)); - EXPECT_EQ(RectBetweenSelectionBounds(b1, b2), - RectBetweenSelectionBounds(b2, b1)); - - // Non-vertical bounds: "\ \" - b1.edge_top = gfx::Point(10, 20); - b1.edge_bottom = gfx::Point(20, 30); - b2.edge_top = gfx::Point(110, 40); - b2.edge_bottom = gfx::Point(120, 60); - EXPECT_EQ(gfx::Rect(b1.edge_top, - gfx::Size(b2.edge_bottom.x() - b1.edge_top.x(), - b2.edge_bottom.y() - b1.edge_top.y())), - RectBetweenSelectionBounds(b1, b2)); - EXPECT_EQ(RectBetweenSelectionBounds(b1, b2), - RectBetweenSelectionBounds(b2, b1)); - - // Non-vertical bounds: "/ \" - b1.edge_top = gfx::Point(20, 30); - b1.edge_bottom = gfx::Point(0, 40); - b2.edge_top = gfx::Point(110, 30); - b2.edge_bottom = gfx::Point(120, 40); - EXPECT_EQ(gfx::Rect(gfx::Point(b1.edge_bottom.x(), b1.edge_top.y()), - gfx::Size(b2.edge_bottom.x() - b1.edge_bottom.x(), - b2.edge_bottom.y() - b2.edge_top.y())), - RectBetweenSelectionBounds(b1, b2)); - EXPECT_EQ(RectBetweenSelectionBounds(b1, b2), - RectBetweenSelectionBounds(b2, b1)); -} - -} // namespace ui diff --git a/ui/base/ui_base.gyp b/ui/base/ui_base.gyp index 80e43e5..cf925d8 100644 --- a/ui/base/ui_base.gyp +++ b/ui/base/ui_base.gyp @@ -346,6 +346,8 @@ 'text/bytes_formatting.h', 'theme_provider.cc', 'theme_provider.h', + 'touch/selection_bound.cc', + 'touch/selection_bound.h', 'touch/touch_device.cc', 'touch/touch_device.h', 'touch/touch_device_android.cc', diff --git a/ui/base/ui_base_tests.gyp b/ui/base/ui_base_tests.gyp index 85626be..09a079d 100644 --- a/ui/base/ui_base_tests.gyp +++ b/ui/base/ui_base_tests.gyp @@ -78,7 +78,7 @@ 'test/test_clipboard_unittest.cc', 'test/data/resource.h', 'text/bytes_formatting_unittest.cc', - 'touch/touch_editing_controller_unittest.cc', + 'touch/selection_bound_unittest.cc', 'view_prop_unittest.cc', 'webui/web_ui_util_unittest.cc', 'x/selection_requestor_unittest.cc', @@ -142,7 +142,7 @@ '../../testing/android/native_test.gyp:native_test_native_code', ], 'sources!': [ - 'touch/touch_editing_controller_unittest.cc', + 'touch/selection_bound_unittest.cc', ], }], ['use_pango == 1', { diff --git a/ui/touch_selection/BUILD.gn b/ui/touch_selection/BUILD.gn new file mode 100644 index 0000000..3b477e4 --- /dev/null +++ b/ui/touch_selection/BUILD.gn @@ -0,0 +1,60 @@ +# 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. + +import("//build/config/ui.gni") + +if (is_android) { + import("//build/config/android/rules.gni") +} + +component("touch_selection") { + output_name = "ui_touch_selection" + + sources = [ + "selection_event_type.h", + "touch_handle.cc", + "touch_handle.h", + "touch_selection_controller.cc", + "touch_selection_controller.h", + "ui_touch_selection_export.h", + ] + + defines = [ "UI_TOUCH_SELECTION_IMPLEMENTATION" ] + + deps = [ + "//base:base", + "//ui/base:base", + "//ui/events:events", + "//ui/events:gesture_detection", + "//ui/gfx/geometry:geometry", + ] +} + +test("ui_touch_selection_unittests") { + sources = [ + "touch_handle_unittest.cc", + "touch_selection_controller_unittest.cc", + ] + + deps = [ + ":touch_selection", + "//base/test:run_all_unittests", + "//testing/gtest:gtest", + "//ui/base:base", + "//ui/events:test_support", + "//ui/gfx:gfx", + "//ui/gfx:test_support", + ] +} + +if (is_android) { + java_cpp_enum("ui_touch_selection_enums_srcjar") { + sources = [ + "selection_event_type.h", + ] + outputs = [ + "org/chromium/ui/touch_selection/SelectionEventType.java", + ] + } +} diff --git a/ui/touch_selection/DEPS b/ui/touch_selection/DEPS new file mode 100644 index 0000000..00a6bb4 --- /dev/null +++ b/ui/touch_selection/DEPS @@ -0,0 +1,5 @@ +include_rules = [ + "+ui/base", + "+ui/events", + "+ui/gfx/geometry" +] diff --git a/ui/touch_selection/OWNERS b/ui/touch_selection/OWNERS new file mode 100644 index 0000000..77debc1 --- /dev/null +++ b/ui/touch_selection/OWNERS @@ -0,0 +1 @@ +jdduke@chromium.org diff --git a/content/browser/renderer_host/input/selection_event_type.h b/ui/touch_selection/selection_event_type.h index 567259f..9525362 100644 --- a/content/browser/renderer_host/input/selection_event_type.h +++ b/ui/touch_selection/selection_event_type.h @@ -2,16 +2,16 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CONTENT_BROWSER_RENDERER_HOST_INPUT_SELECTION_EVENT_TYPE_ -#define CONTENT_BROWSER_RENDERER_HOST_INPUT_SELECTION_EVENT_TYPE_ +#ifndef UI_TOUCH_SELECTION_SELECTION_EVENT_TYPE_ +#define UI_TOUCH_SELECTION_SELECTION_EVENT_TYPE_ -namespace content { +namespace ui { // This file contains a list of events relating to selection and insertion, used // for notifying Java when the renderer selection has changed. -// + // A Java counterpart will be generated for this enum. -// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.content.browser.input +// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.ui.touch_selection enum SelectionEventType { SELECTION_SHOWN, SELECTION_CLEARED, @@ -24,6 +24,6 @@ enum SelectionEventType { INSERTION_DRAG_STARTED, }; -} // namespace content +} // namespace ui -#endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_SELECTION_EVENT_TYPE_ +#endif // UI_TOUCH_SELECTION_SELECTION_EVENT_TYPE_ diff --git a/content/browser/renderer_host/input/touch_handle.cc b/ui/touch_selection/touch_handle.cc index 2e247e6..91c2874 100644 --- a/content/browser/renderer_host/input/touch_handle.cc +++ b/ui/touch_selection/touch_handle.cc @@ -2,11 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "content/browser/renderer_host/input/touch_handle.h" +#include "ui/touch_selection/touch_handle.h" #include <cmath> -namespace content { +namespace ui { namespace { @@ -113,15 +113,15 @@ void TouchHandle::SetOrientation(TouchHandleOrientation orientation) { drawable_->SetOrientation(orientation); } -bool TouchHandle::WillHandleTouchEvent(const ui::MotionEvent& event) { +bool TouchHandle::WillHandleTouchEvent(const MotionEvent& event) { if (!enabled_) return false; - if (!is_dragging_ && event.GetAction() != ui::MotionEvent::ACTION_DOWN) + if (!is_dragging_ && event.GetAction() != MotionEvent::ACTION_DOWN) return false; switch (event.GetAction()) { - case ui::MotionEvent::ACTION_DOWN: { + case MotionEvent::ACTION_DOWN: { if (!is_visible_) return false; const float touch_size = std::max( @@ -139,7 +139,7 @@ bool TouchHandle::WillHandleTouchEvent(const ui::MotionEvent& event) { BeginDrag(); } break; - case ui::MotionEvent::ACTION_MOVE: { + case MotionEvent::ACTION_MOVE: { gfx::PointF touch_move_position(event.GetX(), event.GetY()); if (is_drag_within_tap_region_) { const float tap_slop = client_->GetTapSlop(); @@ -154,7 +154,7 @@ bool TouchHandle::WillHandleTouchEvent(const ui::MotionEvent& event) { touch_move_position + touch_to_focus_offset_); } break; - case ui::MotionEvent::ACTION_UP: { + case MotionEvent::ACTION_UP: { if (is_drag_within_tap_region_ && (event.GetEventTime() - touch_down_time_) < client_->GetTapTimeout()) { @@ -164,7 +164,7 @@ bool TouchHandle::WillHandleTouchEvent(const ui::MotionEvent& event) { EndDrag(); } break; - case ui::MotionEvent::ACTION_CANCEL: + case MotionEvent::ACTION_CANCEL: EndDrag(); break; @@ -261,4 +261,4 @@ void TouchHandle::SetAlpha(float alpha) { drawable_->SetAlpha(alpha); } -} // namespace content +} // namespace ui diff --git a/content/browser/renderer_host/input/touch_handle.h b/ui/touch_selection/touch_handle.h index 41e9fcd..1998f8e 100644 --- a/content/browser/renderer_host/input/touch_handle.h +++ b/ui/touch_selection/touch_handle.h @@ -2,19 +2,19 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_HANDLE_H_ -#define CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_HANDLE_H_ +#ifndef UI_TOUCH_SELECTION_TOUCH_HANDLE_H_ +#define UI_TOUCH_SELECTION_TOUCH_HANDLE_H_ #include "base/logging.h" #include "base/memory/scoped_ptr.h" #include "base/time/time.h" -#include "content/common/content_export.h" #include "ui/events/gesture_detection/motion_event.h" #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/ui_touch_selection_export.h" -namespace content { +namespace ui { class TouchHandle; @@ -26,7 +26,7 @@ enum TouchHandleOrientation { }; // Interface through which |TouchHandle| delegates rendering-specific duties. -class CONTENT_EXPORT TouchHandleDrawable { +class UI_TOUCH_SELECTION_EXPORT TouchHandleDrawable { public: virtual ~TouchHandleDrawable() {} virtual void SetEnabled(bool enabled) = 0; @@ -38,7 +38,7 @@ class CONTENT_EXPORT TouchHandleDrawable { // Interface through which |TouchHandle| communicates handle manipulation and // requests concrete drawable instances. -class CONTENT_EXPORT TouchHandleClient { +class UI_TOUCH_SELECTION_EXPORT TouchHandleClient { public: virtual ~TouchHandleClient() {} virtual void OnHandleDragBegin(const TouchHandle& handle) = 0; @@ -54,7 +54,7 @@ class CONTENT_EXPORT TouchHandleClient { // Responsible for displaying a selection or insertion handle for text // interaction. -class CONTENT_EXPORT TouchHandle { +class UI_TOUCH_SELECTION_EXPORT TouchHandle { public: // The drawable will be enabled but invisible until otherwise specified. TouchHandle(TouchHandleClient* client, TouchHandleOrientation orientation); @@ -84,7 +84,7 @@ class CONTENT_EXPORT TouchHandle { // Allows touch-dragging of the handle. Returns true if the event was // consumed, in which case the caller should cease further handling. - bool WillHandleTouchEvent(const ui::MotionEvent& event); + bool WillHandleTouchEvent(const MotionEvent& event); // Ticks an active animation, as requested to the client by |SetNeedsAnimate|. // Returns true if an animation is active and requires further ticking. @@ -129,6 +129,6 @@ class CONTENT_EXPORT TouchHandle { DISALLOW_COPY_AND_ASSIGN(TouchHandle); }; -} // namespace content +} // namespace ui -#endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_HANDLE_H_ +#endif // UI_TOUCH_SELECTION_TOUCH_HANDLE_H_ diff --git a/content/browser/renderer_host/input/touch_handle_unittest.cc b/ui/touch_selection/touch_handle_unittest.cc index b43aa17..fded0c5 100644 --- a/content/browser/renderer_host/input/touch_handle_unittest.cc +++ b/ui/touch_selection/touch_handle_unittest.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "content/browser/renderer_host/input/touch_handle.h" +#include "ui/touch_selection/touch_handle.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/events/test/motion_event_test_utils.h" @@ -10,7 +10,7 @@ using ui::test::MockMotionEvent; -namespace content { +namespace ui { namespace { const int kDefaultTapTimeoutMs = 200; @@ -489,4 +489,4 @@ TEST_F(TouchHandleTest, Tap) { EXPECT_FALSE(GetAndResetHandleTapped()); } -} // namespace content +} // namespace ui diff --git a/content/browser/renderer_host/input/touch_selection_controller.cc b/ui/touch_selection/touch_selection_controller.cc index bc913fd..f5a4bda 100644 --- a/content/browser/renderer_host/input/touch_selection_controller.cc +++ b/ui/touch_selection/touch_selection_controller.cc @@ -2,24 +2,23 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "content/browser/renderer_host/input/touch_selection_controller.h" +#include "ui/touch_selection/touch_selection_controller.h" #include "base/auto_reset.h" #include "base/logging.h" -#include "third_party/WebKit/public/web/WebInputEvent.h" -namespace content { +namespace ui { namespace { -TouchHandleOrientation ToTouchHandleOrientation(cc::SelectionBoundType type) { +TouchHandleOrientation ToTouchHandleOrientation(SelectionBound::Type type) { switch (type) { - case cc::SELECTION_BOUND_LEFT: + case SelectionBound::LEFT: return TOUCH_HANDLE_LEFT; - case cc::SELECTION_BOUND_RIGHT: + case SelectionBound::RIGHT: return TOUCH_HANDLE_RIGHT; - case cc::SELECTION_BOUND_CENTER: + case SelectionBound::CENTER: return TOUCH_HANDLE_CENTER; - case cc::SELECTION_BOUND_EMPTY: + case SelectionBound::EMPTY: return TOUCH_HANDLE_ORIENTATION_UNDEFINED; } NOTREACHED() << "Invalid selection bound type: " << type; @@ -53,15 +52,15 @@ TouchSelectionController::~TouchSelectionController() { } void TouchSelectionController::OnSelectionBoundsChanged( - const cc::ViewportSelectionBound& start, - const cc::ViewportSelectionBound& end) { + const SelectionBound& start, + const SelectionBound& end) { if (start == start_ && end_ == end) return; start_ = start; end_ = end; - start_orientation_ = ToTouchHandleOrientation(start_.type); - end_orientation_ = ToTouchHandleOrientation(end_.type); + start_orientation_ = ToTouchHandleOrientation(start_.type()); + end_orientation_ = ToTouchHandleOrientation(end_.type()); if (!activate_selection_automatically_ && !activate_insertion_automatically_) { @@ -110,8 +109,7 @@ void TouchSelectionController::OnSelectionBoundsChanged( HideAndDisallowShowingAutomatically(); } -bool TouchSelectionController::WillHandleTouchEvent( - const ui::MotionEvent& event) { +bool TouchSelectionController::WillHandleTouchEvent(const MotionEvent& event) { if (is_insertion_active_) { DCHECK(insertion_handle_); return insertion_handle_->WillHandleTouchEvent(event); @@ -395,34 +393,34 @@ void TouchSelectionController::DeactivateSelection() { void TouchSelectionController::ResetCachedValuesIfInactive() { if (is_selection_active_ || is_insertion_active_) return; - start_ = cc::ViewportSelectionBound(); - end_ = cc::ViewportSelectionBound(); + start_ = SelectionBound(); + end_ = SelectionBound(); start_orientation_ = TOUCH_HANDLE_ORIENTATION_UNDEFINED; end_orientation_ = TOUCH_HANDLE_ORIENTATION_UNDEFINED; } const gfx::PointF& TouchSelectionController::GetStartPosition() const { - return start_.edge_bottom; + return start_.edge_bottom(); } const gfx::PointF& TouchSelectionController::GetEndPosition() const { - return end_.edge_bottom; + return end_.edge_bottom(); } gfx::Vector2dF TouchSelectionController::GetStartLineOffset() const { - return gfx::ScaleVector2d(start_.edge_top - start_.edge_bottom, 0.5f); + return gfx::ScaleVector2d(start_.edge_top() - start_.edge_bottom(), 0.5f); } gfx::Vector2dF TouchSelectionController::GetEndLineOffset() const { - return gfx::ScaleVector2d(end_.edge_top - end_.edge_bottom, 0.5f); + return gfx::ScaleVector2d(end_.edge_top() - end_.edge_bottom(), 0.5f); } bool TouchSelectionController::GetStartVisible() const { - return start_.visible && !temporarily_hidden_; + return start_.visible() && !temporarily_hidden_; } bool TouchSelectionController::GetEndVisible() const { - return end_.visible && !temporarily_hidden_; + return end_.visible() && !temporarily_hidden_; } TouchHandle::AnimationStyle TouchSelectionController::GetAnimationStyle( @@ -432,4 +430,4 @@ TouchHandle::AnimationStyle TouchSelectionController::GetAnimationStyle( : TouchHandle::ANIMATION_NONE; } -} // namespace content +} // namespace ui diff --git a/content/browser/renderer_host/input/touch_selection_controller.h b/ui/touch_selection/touch_selection_controller.h index 13b0689..2bcefbd 100644 --- a/content/browser/renderer_host/input/touch_selection_controller.h +++ b/ui/touch_selection/touch_selection_controller.h @@ -2,29 +2,22 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_SELECTION_CONTROLLER_H_ -#define CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_SELECTION_CONTROLLER_H_ +#ifndef UI_TOUCH_SELECTION_TOUCH_SELECTION_CONTROLLER_H_ +#define UI_TOUCH_SELECTION_TOUCH_SELECTION_CONTROLLER_H_ -#include "cc/output/viewport_selection_bound.h" -#include "content/browser/renderer_host/input/selection_event_type.h" -#include "content/browser/renderer_host/input/touch_handle.h" -#include "content/common/content_export.h" +#include "ui/base/touch/selection_bound.h" #include "ui/gfx/geometry/point_f.h" #include "ui/gfx/geometry/rect_f.h" - -namespace blink { -class WebInputEvent; -} +#include "ui/touch_selection/selection_event_type.h" +#include "ui/touch_selection/touch_handle.h" +#include "ui/touch_selection/ui_touch_selection_export.h" namespace ui { class MotionEvent; -} - -namespace content { // Interface through which |TouchSelectionController| issues selection-related // commands, notifications and requests. -class CONTENT_EXPORT TouchSelectionControllerClient { +class UI_TOUCH_SELECTION_EXPORT TouchSelectionControllerClient { public: virtual ~TouchSelectionControllerClient() {} @@ -40,7 +33,8 @@ class CONTENT_EXPORT TouchSelectionControllerClient { }; // Controller for manipulating text selection via touch input. -class CONTENT_EXPORT TouchSelectionController : public TouchHandleClient { +class UI_TOUCH_SELECTION_EXPORT TouchSelectionController + : public TouchHandleClient { public: TouchSelectionController(TouchSelectionControllerClient* client, base::TimeDelta tap_timeout, @@ -50,13 +44,13 @@ class CONTENT_EXPORT TouchSelectionController : public TouchHandleClient { // To be called when the selection bounds have changed. // Note that such updates will trigger handle updates only if preceded // by an appropriate call to allow automatic showing. - void OnSelectionBoundsChanged(const cc::ViewportSelectionBound& start, - const cc::ViewportSelectionBound& end); + void OnSelectionBoundsChanged(const SelectionBound& start, + const SelectionBound& end); // Allows touch-dragging of the handle. // Returns true iff the event was consumed, in which case the caller should // cease further handling of the event. - bool WillHandleTouchEvent(const ui::MotionEvent& event); + bool WillHandleTouchEvent(const MotionEvent& event); // To be called before forwarding a tap event. This allows automatically // showing the insertion handle from subsequent bounds changes. @@ -127,8 +121,8 @@ class CONTENT_EXPORT TouchSelectionController : public TouchHandleClient { InputEventType response_pending_input_event_; - cc::ViewportSelectionBound start_; - cc::ViewportSelectionBound end_; + SelectionBound start_; + SelectionBound end_; TouchHandleOrientation start_orientation_; TouchHandleOrientation end_orientation_; @@ -149,6 +143,6 @@ class CONTENT_EXPORT TouchSelectionController : public TouchHandleClient { DISALLOW_COPY_AND_ASSIGN(TouchSelectionController); }; -} // namespace content +} // namespace ui -#endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_SELECTION_CONTROLLER_H_ +#endif // UI_TOUCH_SELECTION_TOUCH_SELECTION_CONTROLLER_H_ diff --git a/content/browser/renderer_host/input/touch_selection_controller_unittest.cc b/ui/touch_selection/touch_selection_controller_unittest.cc index 11d793d..5b1839a 100644 --- a/content/browser/renderer_host/input/touch_selection_controller_unittest.cc +++ b/ui/touch_selection/touch_selection_controller_unittest.cc @@ -2,14 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "content/browser/renderer_host/input/touch_selection_controller.h" +#include "ui/touch_selection/touch_selection_controller.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/events/test/motion_event_test_utils.h" using ui::test::MockMotionEvent; -namespace content { +namespace ui { namespace { const int kDefaultTapTimeoutMs = 200; @@ -98,18 +98,17 @@ class TouchSelectionControllerTest : public testing::Test, void SetDraggingEnabled(bool enabled) { dragging_enabled_ = enabled; } void ClearSelection() { - controller_->OnSelectionBoundsChanged(cc::ViewportSelectionBound(), - cc::ViewportSelectionBound()); + controller_->OnSelectionBoundsChanged(SelectionBound(), + SelectionBound()); } void ClearInsertion() { ClearSelection(); } void ChangeInsertion(const gfx::RectF& rect, bool visible) { - cc::ViewportSelectionBound bound; - bound.type = cc::SELECTION_BOUND_CENTER; - bound.edge_top = rect.origin(); - bound.edge_bottom = rect.bottom_left(); - bound.visible = visible; + SelectionBound bound; + bound.set_type(SelectionBound::CENTER); + bound.SetEdge(rect.origin(), rect.bottom_left()); + bound.set_visible(visible); controller_->OnSelectionBoundsChanged(bound, bound); } @@ -117,15 +116,13 @@ class TouchSelectionControllerTest : public testing::Test, bool start_visible, const gfx::RectF& end_rect, bool end_visible) { - cc::ViewportSelectionBound start_bound, end_bound; - start_bound.type = cc::SELECTION_BOUND_LEFT; - end_bound.type = cc::SELECTION_BOUND_RIGHT; - start_bound.edge_top = start_rect.origin(); - start_bound.edge_bottom = start_rect.bottom_left(); - end_bound.edge_top = end_rect.origin(); - end_bound.edge_bottom = end_rect.bottom_left(); - start_bound.visible = start_visible; - end_bound.visible = end_visible; + SelectionBound start_bound, end_bound; + start_bound.set_type(SelectionBound::LEFT); + end_bound.set_type(SelectionBound::RIGHT); + start_bound.SetEdge(start_rect.origin(), start_rect.bottom_left()); + end_bound.SetEdge(end_rect.origin(), end_rect.bottom_left()); + start_bound.set_visible(start_visible); + end_bound.set_visible(end_visible); controller_->OnSelectionBoundsChanged(start_bound, end_bound); } @@ -842,4 +839,4 @@ TEST_F(TouchSelectionControllerTest, AllowShowingFromCurrentSelection) { EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor()); } -} // namespace content +} // namespace ui diff --git a/ui/touch_selection/ui_touch_selection.gyp b/ui/touch_selection/ui_touch_selection.gyp new file mode 100644 index 0000000..5a2a5070 --- /dev/null +++ b/ui/touch_selection/ui_touch_selection.gyp @@ -0,0 +1,81 @@ +# 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. + +{ + 'variables': { + 'chromium_code': 1, + }, + 'targets': [ + { + 'target_name': 'ui_touch_selection', + 'type': '<(component)', + 'dependencies': [ + '../../base/base.gyp:base', + '../base/ui_base.gyp:ui_base', + '../events/events.gyp:events', + '../events/events.gyp:gesture_detection', + '../gfx/gfx.gyp:gfx_geometry', + ], + 'defines': [ + 'UI_TOUCH_SELECTION_IMPLEMENTATION', + ], + 'sources': [ + 'selection_event_type.h', + 'touch_handle.cc', + 'touch_handle.h', + 'touch_selection_controller.cc', + 'touch_selection_controller.h', + 'ui_touch_selection_export.h', + ], + 'include_dirs': [ + '../..', + ], + }, + { + 'target_name': 'ui_touch_selection_unittests', + 'type': '<(gtest_target_type)', + 'dependencies': [ + '../../base/base.gyp:run_all_unittests', + '../../testing/gtest.gyp:gtest', + '../base/ui_base.gyp:ui_base', + '../events/events.gyp:events_test_support', + '../gfx/gfx.gyp:gfx', + '../gfx/gfx.gyp:gfx_test_support', + 'ui_touch_selection', + ], + 'sources': [ + 'touch_handle_unittest.cc', + 'touch_selection_controller_unittest.cc', + ], + 'include_dirs': [ + '../..', + ], + }, + ], + 'conditions': [ + ['OS == "android"', { + 'targets': [ + { + 'target_name': 'selection_event_type_java', + 'type': 'none', + 'variables': { + 'source_file': 'selection_event_type.h', + }, + 'includes': [ '../../build/android/java_cpp_enum.gypi' ], + }, + { + 'target_name': 'ui_touch_selection_unittests_apk', + 'type': 'none', + 'dependencies': [ + 'ui_touch_selection_unittests', + ], + 'variables': { + 'test_suite_name': 'ui_touch_selection_unittests', + }, + 'includes': [ '../../build/apk_test.gypi' ], + }, + ], + }], # OS == "android" + ], +} diff --git a/ui/touch_selection/ui_touch_selection_export.h b/ui/touch_selection/ui_touch_selection_export.h new file mode 100644 index 0000000..e1f80bbc --- /dev/null +++ b/ui/touch_selection/ui_touch_selection_export.h @@ -0,0 +1,37 @@ +// 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_UI_TOUCH_SELECTION_EXPORT_H_ +#define UI_TOUCH_SELECTION_UI_TOUCH_SELECTION_EXPORT_H_ + +// Defines UI_TOUCH_SELECTION_EXPORT so that functionality implemented by the UI +// touch selection module can be exported to consumers. + +#if defined(COMPONENT_BUILD) + +#if defined(WIN32) + +#if defined(UI_TOUCH_SELECTION_IMPLEMENTATION) +#define UI_TOUCH_SELECTION_EXPORT __declspec(dllexport) +#else +#define UI_TOUCH_SELECTION_EXPORT __declspec(dllimport) +#endif + +#else // !defined(WIN32) + +#if defined(UI_TOUCH_SELECTION_IMPLEMENTATION) +#define UI_TOUCH_SELECTION_EXPORT __attribute__((visibility("default"))) +#else +#define UI_TOUCH_SELECTION_EXPORT +#endif + +#endif + +#else // !defined(COMPONENT_BUILD) + +#define UI_TOUCH_SELECTION_EXPORT + +#endif + +#endif // UI_TOUCH_SELECTION_UI_TOUCH_SELECTION_EXPORT_H_ diff --git a/ui/views/controls/textfield/textfield.cc b/ui/views/controls/textfield/textfield.cc index aa1ebfd..eb16306 100644 --- a/ui/views/controls/textfield/textfield.cc +++ b/ui/views/controls/textfield/textfield.cc @@ -12,6 +12,7 @@ #include "ui/base/cursor/cursor.h" #include "ui/base/dragdrop/drag_drop_types.h" #include "ui/base/dragdrop/drag_utils.h" +#include "ui/base/touch/selection_bound.h" #include "ui/base/ui_base_switches_util.h" #include "ui/compositor/scoped_animation_duration_scale_mode.h" #include "ui/events/event.h" @@ -1110,10 +1111,8 @@ void Textfield::GetSelectionEndPoints(ui::SelectionBound* anchor, gfx::Rect r1 = render_text->GetCursorBounds(start_sel, true); gfx::Rect r2 = render_text->GetCursorBounds(sel, true); - anchor->edge_top = r1.origin(); - anchor->edge_bottom = r1.bottom_left(); - focus->edge_top = r2.origin(); - focus->edge_bottom = r2.bottom_left(); + anchor->SetEdge(r1.origin(), r1.bottom_left()); + focus->SetEdge(r2.origin(), r2.bottom_left()); // Determine the SelectionBound's type for focus and anchor. // TODO(mfomitchev): Ideally we should have different logical directions for @@ -1123,14 +1122,15 @@ void Textfield::GetSelectionEndPoints(ui::SelectionBound* anchor, size_t focus_position_index = sel.selection().end(); if (anchor_position_index == focus_position_index) { - anchor->type = focus->type = ui::SelectionBound::CENTER; + anchor->set_type(ui::SelectionBound::CENTER); + focus->set_type(ui::SelectionBound::CENTER); } else if ((ltr && anchor_position_index < focus_position_index) || (!ltr && anchor_position_index > focus_position_index)) { - anchor->type = ui::SelectionBound::LEFT; - focus->type = ui::SelectionBound::RIGHT; + anchor->set_type(ui::SelectionBound::LEFT); + focus->set_type(ui::SelectionBound::RIGHT); } else { - anchor->type = ui::SelectionBound::RIGHT; - focus->type = ui::SelectionBound::LEFT; + anchor->set_type(ui::SelectionBound::RIGHT); + focus->set_type(ui::SelectionBound::LEFT); } } diff --git a/ui/views/touchui/touch_selection_controller_impl.cc b/ui/views/touchui/touch_selection_controller_impl.cc index 512a0bf..815ebc5 100644 --- a/ui/views/touchui/touch_selection_controller_impl.cc +++ b/ui/views/touchui/touch_selection_controller_impl.cc @@ -150,26 +150,26 @@ Alignment GetCursorAlignment(ui::SelectionBound::Type bound_type) { // Calculates the bounds of the widget containing the selection handle based // on the SelectionBound's type and location gfx::Rect GetSelectionWidgetBounds(const ui::SelectionBound& bound) { - Alignment cursor_alignment = GetCursorAlignment(bound.type); - gfx::Size image_size = GetHandleImage(bound.type)->Size(); + Alignment cursor_alignment = GetCursorAlignment(bound.type()); + gfx::Size image_size = GetHandleImage(bound.type())->Size(); int widget_width = image_size.width() + 2 * kSelectionHandleHorizPadding; int widget_height = bound.GetHeight() + image_size.height() + kSelectionHandleVertPadding; int widget_left = 0; switch (cursor_alignment) { case ALIGN_LEFT: - widget_left = bound.edge_top.x() - kSelectionHandleHorizPadding; + widget_left = bound.edge_top_rounded().x() - kSelectionHandleHorizPadding; break; case ALIGN_RIGHT: - widget_left = bound.edge_top.x() - image_size.width() - + widget_left = bound.edge_top_rounded().x() - image_size.width() - kSelectionHandleHorizPadding; break; case ALIGN_CENTER: - widget_left = bound.edge_top.x() - widget_width / 2; + widget_left = bound.edge_top_rounded().x() - widget_width / 2; break; }; return gfx::Rect( - widget_left, bound.edge_top.y(), widget_width, widget_height); + widget_left, bound.edge_top_rounded().y(), widget_width, widget_height); } gfx::Size GetMaxHandleImageSize() { @@ -190,29 +190,28 @@ gfx::Size GetMaxHandleImageSize() { ui::SelectionBound ConvertFromScreen(ui::TouchEditable* client, const ui::SelectionBound& bound) { ui::SelectionBound result = bound; - gfx::Point edge_bottom = bound.edge_bottom; - gfx::Point edge_top = bound.edge_top; + gfx::Point edge_bottom = bound.edge_bottom_rounded(); + gfx::Point edge_top = bound.edge_top_rounded(); client->ConvertPointFromScreen(&edge_bottom); client->ConvertPointFromScreen(&edge_top); - result.edge_bottom = edge_bottom; - result.edge_top = edge_top; + result.SetEdge(edge_top, edge_bottom); return result; } ui::SelectionBound ConvertToScreen(ui::TouchEditable* client, const ui::SelectionBound& bound) { ui::SelectionBound result = bound; - gfx::Point edge_bottom = bound.edge_bottom; - gfx::Point edge_top = bound.edge_top; + gfx::Point edge_bottom = bound.edge_bottom_rounded(); + gfx::Point edge_top = bound.edge_top_rounded(); client->ConvertPointToScreen(&edge_bottom); client->ConvertPointToScreen(&edge_top); - result.edge_bottom = edge_bottom; - result.edge_top = edge_top; + result.SetEdge(edge_top, edge_bottom); return result; } gfx::Rect BoundToRect(const ui::SelectionBound& bound) { - return gfx::BoundingRect(bound.edge_top, bound.edge_bottom); + return gfx::BoundingRect(bound.edge_top_rounded(), + bound.edge_bottom_rounded()); } } // namespace @@ -283,19 +282,19 @@ class TouchSelectionControllerImpl::EditingHandleView if (draw_invisible_) return; - Alignment cursor_alignment = GetCursorAlignment(selection_bound_.type); + Alignment cursor_alignment = GetCursorAlignment(selection_bound_.type()); int cursor_x = 0; switch (cursor_alignment) { case ALIGN_RIGHT: - cursor_x = - selection_bound_.edge_top.x() - kSelectionHandleLineWidth + 1; + cursor_x = selection_bound_.edge_top_rounded().x() - + kSelectionHandleLineWidth + 1; break; case ALIGN_LEFT: - cursor_x = selection_bound_.edge_top.x() - 1; + cursor_x = selection_bound_.edge_top_rounded().x() - 1; break; case ALIGN_CENTER: - cursor_x = - selection_bound_.edge_top.x() - kSelectionHandleLineWidth / 2; + cursor_x = selection_bound_.edge_top_rounded().x() - + kSelectionHandleLineWidth / 2; break; }; // Draw the cursor line. @@ -318,7 +317,7 @@ class TouchSelectionControllerImpl::EditingHandleView // Distance from the point which is |kSelectionHandleVerticalDragOffset| // pixels above the bottom of the handle's cursor line to the event // location (aka the touch-drag point). - drag_offset_ = selection_bound_.edge_bottom - + drag_offset_ = selection_bound_.edge_bottom_rounded() - gfx::Vector2d(0, kSelectionHandleVerticalDragOffset) - event->location(); break; @@ -363,31 +362,32 @@ class TouchSelectionControllerImpl::EditingHandleView void SetBoundInScreen(const ui::SelectionBound& bound) { bool update_bound_type = false; // Cursor handle should always have the bound type CENTER - DCHECK(!is_cursor_handle_ || bound.type == ui::SelectionBound::CENTER); + DCHECK(!is_cursor_handle_ || bound.type() == ui::SelectionBound::CENTER); - if (bound.type != selection_bound_.type) { + if (bound.type() != selection_bound_.type()) { // Unless this is a cursor handle, do not set the type to CENTER - // selection handles corresponding to a selection should always use left // or right handle image. If selection handles are dragged to be located // at the same spot, the |bound|'s type here will be CENTER for both of // them. In this case do not update the type of the |selection_bound_|. - if (bound.type != ui::SelectionBound::CENTER || is_cursor_handle_) + if (bound.type() != ui::SelectionBound::CENTER || is_cursor_handle_) update_bound_type = true; } if (update_bound_type) { - selection_bound_ = bound; - image_ = GetHandleImage(bound.type); + selection_bound_.set_type(bound.type()); + image_ = GetHandleImage(bound.type()); SchedulePaint(); - } else { - selection_bound_.edge_top = bound.edge_top; - selection_bound_.edge_bottom = bound.edge_bottom; } + selection_bound_.SetEdge(bound.edge_top(), bound.edge_bottom()); widget_->SetBounds(GetSelectionWidgetBounds(selection_bound_)); aura::Window* window = widget_->GetNativeView(); - wm::ConvertPointFromScreen(window, &selection_bound_.edge_top); - wm::ConvertPointFromScreen(window, &selection_bound_.edge_bottom); + gfx::Point edge_top = selection_bound_.edge_top_rounded(); + gfx::Point edge_bottom = selection_bound_.edge_bottom_rounded(); + wm::ConvertPointFromScreen(window, &edge_top); + wm::ConvertPointFromScreen(window, &edge_bottom); + selection_bound_.SetEdge(edge_top, edge_bottom); } void SetDrawInvisible(bool draw_invisible) { @@ -474,10 +474,16 @@ void TouchSelectionControllerImpl::SelectionChanged() { ConvertToScreen(client_view_, anchor); ui::SelectionBound screen_bound_focus = ConvertToScreen(client_view_, focus); gfx::Rect client_bounds = client_view_->GetBounds(); - if (anchor.edge_top.y() < client_bounds.y()) - anchor.edge_top.set_y(client_bounds.y()); - if (focus.edge_top.y() < client_bounds.y()) - focus.edge_top.set_y(client_bounds.y()); + if (anchor.edge_top().y() < client_bounds.y()) { + gfx::Point anchor_edge_top = anchor.edge_top_rounded(); + anchor_edge_top.set_y(client_bounds.y()); + anchor.SetEdgeTop(anchor_edge_top); + } + if (focus.edge_top().y() < client_bounds.y()) { + gfx::Point focus_edge_top = focus.edge_top_rounded(); + focus_edge_top.set_y(client_bounds.y()); + focus.SetEdgeTop(focus_edge_top); + } ui::SelectionBound screen_bound_anchor_clipped = ConvertToScreen(client_view_, anchor); ui::SelectionBound screen_bound_focus_clipped = @@ -531,8 +537,8 @@ void TouchSelectionControllerImpl::SelectionChanged() { UpdateContextMenu(); // Check if there is any selection at all. - if (screen_bound_anchor.edge_top == screen_bound_focus.edge_top && - screen_bound_anchor.edge_bottom == screen_bound_focus.edge_bottom) { + if (screen_bound_anchor.edge_top() == screen_bound_focus.edge_top() && + screen_bound_anchor.edge_bottom() == screen_bound_focus.edge_bottom()) { selection_handle_1_->SetWidgetVisible(false, false); selection_handle_2_->SetWidgetVisible(false, false); SetHandleBound(cursor_handle_.get(), anchor, screen_bound_anchor_clipped); @@ -583,7 +589,7 @@ void TouchSelectionControllerImpl::SelectionHandleDragged( : selection_bound_1_; // Find selection end points in client_view's coordinate system. - gfx::Point p2 = anchor_bound.edge_top; + gfx::Point p2 = anchor_bound.edge_top_rounded(); p2.Offset(0, anchor_bound.GetHeight() / 2); client_view_->ConvertPointFromScreen(&p2); diff --git a/ui/views/touchui/touch_selection_controller_impl.h b/ui/views/touchui/touch_selection_controller_impl.h index 0757f0d..62e5e14 100644 --- a/ui/views/touchui/touch_selection_controller_impl.h +++ b/ui/views/touchui/touch_selection_controller_impl.h @@ -7,6 +7,7 @@ #include "base/timer/timer.h" #include "ui/aura/window_observer.h" +#include "ui/base/touch/selection_bound.h" #include "ui/base/touch/touch_editing_controller.h" #include "ui/gfx/point.h" #include "ui/views/touchui/touch_editing_menu.h" diff --git a/ui/views/touchui/touch_selection_controller_impl_unittest.cc b/ui/views/touchui/touch_selection_controller_impl_unittest.cc index 5d0c693..8f9d8a6 100644 --- a/ui/views/touchui/touch_selection_controller_impl_unittest.cc +++ b/ui/views/touchui/touch_selection_controller_impl_unittest.cc @@ -46,12 +46,13 @@ const int kMenuCommandCount = 3; // the same location. int CompareTextSelectionBounds(const ui::SelectionBound& b1, const ui::SelectionBound& b2) { - if ((b1.edge_top.y() < b2.edge_top.y()) || b1.edge_top.x() < b2.edge_top.x()) + if (b1.edge_top().y() < b2.edge_top().y() || + b1.edge_top().x() < b2.edge_top().x()) { return -1; - else if (b1 == b2) + } + if (b1 == b2) return 0; - else - return 1; + return 1; } } // namespace @@ -258,14 +259,14 @@ class TouchSelectionControllerImplTest : public ViewsTestBase { } if (check_direction) { if (CompareTextSelectionBounds(anchor, focus) < 0) { - EXPECT_EQ(ui::SelectionBound::LEFT, anchor.type) << from_str; - EXPECT_EQ(ui::SelectionBound::RIGHT, focus.type) << from_str; + EXPECT_EQ(ui::SelectionBound::LEFT, anchor.type()) << from_str; + EXPECT_EQ(ui::SelectionBound::RIGHT, focus.type()) << from_str; } else if (CompareTextSelectionBounds(anchor, focus) > 0) { - EXPECT_EQ(ui::SelectionBound::LEFT, focus.type) << from_str; - EXPECT_EQ(ui::SelectionBound::RIGHT, anchor.type) << from_str; + EXPECT_EQ(ui::SelectionBound::LEFT, focus.type()) << from_str; + EXPECT_EQ(ui::SelectionBound::RIGHT, anchor.type()) << from_str; } else { - EXPECT_EQ(ui::SelectionBound::CENTER, focus.type) << from_str; - EXPECT_EQ(ui::SelectionBound::CENTER, anchor.type) << from_str; + EXPECT_EQ(ui::SelectionBound::CENTER, focus.type()) << from_str; + EXPECT_EQ(ui::SelectionBound::CENTER, anchor.type()) << from_str; } } } @@ -613,9 +614,8 @@ class TestTouchEditable : public ui::TouchEditable { } void set_cursor_rect(const gfx::Rect& cursor_rect) { - cursor_bound_.edge_top = cursor_rect.origin(); - cursor_bound_.edge_bottom = cursor_rect.bottom_left(); - cursor_bound_.type = ui::SelectionBound::Type::CENTER; + cursor_bound_.SetEdge(cursor_rect.origin(), cursor_rect.bottom_left()); + cursor_bound_.set_type(ui::SelectionBound::Type::CENTER); } ~TestTouchEditable() override {} |