Bringup Text selection.
authorKarol Furmaniak <k.furmaniak@samsung.com>
Wed, 22 Apr 2015 13:56:26 +0000 (15:56 +0200)
committerYoungsoo Choi <kenshin.choi@samsung.com>
Tue, 10 Jul 2018 06:57:09 +0000 (06:57 +0000)
Text selection was refactored.
Selection handles and controller was moved to chromium_impl.

Whole change contains 3 patches(chromium-efl, s-blink, s-chromium)

Together with: Id00120d7f4cec49d16a110baa74a58e86d95cd37

Bug: http://web.sec.samsung.net/bugzilla/show_bug.cgi?id=12549
Reviewed by: Antonio Gomes, Hyunhak Kim, Piotr Grad, SeungSeop Park

Change-Id: Id62ff99f1aff9deeb72bc989a139ca9214ae092a
Signed-off-by: Karol Furmaniak <k.furmaniak@samsung.com>
Signed-off-by: Arnaud Renevier <a.renevier@samsung.com>
20 files changed:
tizen_src/chromium_impl/content/browser/renderer_host/render_widget_host_view_efl.cc
tizen_src/chromium_impl/content/browser/renderer_host/render_widget_host_view_efl.h
tizen_src/chromium_impl/content/browser/web_contents/web_contents_view_efl.cc
tizen_src/chromium_impl/content/browser/web_contents/web_contents_view_efl.h
tizen_src/chromium_impl/content/public/browser/web_contents_view_efl_delegate.h
tizen_src/chromium_impl/ui/base/selection/selection_box_efl.cc [moved from tizen_src/ewk/efl_integration/selection_box_efl.cc with 82% similarity]
tizen_src/chromium_impl/ui/base/selection/selection_box_efl.h [moved from tizen_src/ewk/efl_integration/selection_box_efl.h with 91% similarity]
tizen_src/chromium_impl/ui/base/selection/selection_controller_efl.cc [moved from tizen_src/ewk/efl_integration/selection_controller_efl.cc with 68% similarity]
tizen_src/chromium_impl/ui/base/selection/selection_controller_efl.h [moved from tizen_src/ewk/efl_integration/selection_controller_efl.h with 75% similarity]
tizen_src/chromium_impl/ui/base/selection/selection_handle_efl.cc [moved from tizen_src/ewk/efl_integration/selection_handle_efl.cc with 95% similarity]
tizen_src/chromium_impl/ui/base/selection/selection_handle_efl.h [moved from tizen_src/ewk/efl_integration/selection_handle_efl.h with 98% similarity]
tizen_src/chromium_impl/ui/base/selection/selection_magnifier_efl.cc [moved from tizen_src/ewk/efl_integration/selection_magnifier_efl.cc with 83% similarity]
tizen_src/chromium_impl/ui/base/selection/selection_magnifier_efl.h [moved from tizen_src/ewk/efl_integration/selection_magnifier_efl.h with 91% similarity]
tizen_src/chromium_impl/ui/ui_efl.gypi
tizen_src/ewk/efl_integration/context_menu_controller_efl.cc
tizen_src/ewk/efl_integration/efl_integration.gypi
tizen_src/ewk/efl_integration/eweb_view.cc
tizen_src/ewk/efl_integration/eweb_view.h
tizen_src/ewk/efl_integration/web_contents_view_efl_delegate_ewk.cc
tizen_src/ewk/efl_integration/web_contents_view_efl_delegate_ewk.h

index ce1e712..793607d 100644 (file)
@@ -33,6 +33,7 @@
 #include "content/browser/renderer_host/disambiguation_popup_efl.h"
 #include "content/browser/renderer_host/web_event_factory_efl.h"
 #include "content/browser/renderer_host/input/web_input_event_util.h"
+#include "content/browser/renderer_host/render_view_host_impl.h"
 #include "content/browser/gpu/gpu_process_host.h"
 #include "content/common/gpu/client/gl_helper.h"
 #include "content/common/input/did_overscroll_params.h"
@@ -99,7 +100,8 @@ void RenderWidgetHostViewBase::GetDefaultScreenInfo(
   results->depthPerComponent = 8;
 }
 
-RenderWidgetHostViewEfl::RenderWidgetHostViewEfl(RenderWidgetHost* widget)
+RenderWidgetHostViewEfl::RenderWidgetHostViewEfl(RenderWidgetHost* widget,
+    WebContents& web_contents)
   : host_(RenderWidgetHostImpl::From(widget)),
     im_context_(NULL),
     evas_(NULL),
@@ -127,7 +129,9 @@ RenderWidgetHostViewEfl::RenderWidgetHostViewEfl(RenderWidgetHost* widget)
     touch_events_enabled_(false),
     should_restore_selection_menu_(false),
     selection_acked_on_tap_(false),
-    was_scrolled_(false) {
+    was_scrolled_(false),
+    web_contents_(web_contents),
+    single_tap_performed_(false) {
 
   SetDoubleTapSupportEnabled(touch_events_enabled_);
 
@@ -497,6 +501,7 @@ bool RenderWidgetHostViewEfl::OnMessageReceived(const IPC::Message& message) {
   IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostViewEfl, message)
     IPC_MESSAGE_HANDLER(ViewHostMsg_TextInputStateChanged, OnTextInputStateChanged)
     IPC_MESSAGE_HANDLER(ViewHostMsg_TextInputInFormStateChanged, OnTextInputInFormStateChanged)
+    IPC_MESSAGE_HANDLER(ViewHostMsg_HitTestAsyncReply, OnHitTestAsyncReply)
     IPC_MESSAGE_UNHANDLED(handled = false)
   IPC_END_MESSAGE_MAP()
   return handled;
@@ -506,6 +511,15 @@ bool RenderWidgetHostViewEfl::Send(IPC::Message* message) {
   return host_->Send(message);
 }
 
+void RenderWidgetHostViewEfl::OnHitTestAsyncReply(
+    const ViewHostMsg_HitTestAsyncReply_Params& params,
+    int64_t request_id) {
+
+  if (GetSelectionController())
+    GetSelectionController()->OnHitTestAsyncReply(
+          params, request_id);
+}
+
 void RenderWidgetHostViewEfl::InitAsPopup(RenderWidgetHostView*, const gfx::Rect&) {
   NOTIMPLEMENTED();
 }
@@ -714,16 +728,18 @@ void RenderWidgetHostViewEfl::TextInputTypeChanged(ui::TextInputType type,
                                                    ui::TextInputMode input_mode,
                                                    bool can_compose_inline,
                                                    int flags) {
-#if defined(EWK_REFACTOR)
   if (GetSelectionController()) {
     GetSelectionController()->SetSelectionEditable(
         type != ui::TEXT_INPUT_TYPE_NONE);
   }
-#endif
 }
 
 void RenderWidgetHostViewEfl::OnTextInputStateChanged(
     const ViewHostMsg_TextInputState_Params& params) {
+  if (GetSelectionController()) {
+    GetSelectionController()->SetSelectionEditable(
+        params.type != ui::TEXT_INPUT_TYPE_NONE);
+  }
   if (!params.show_ime_if_needed
 #if defined(EWK_REFACTOR)
         && !eweb_view()->GetSettings()->useKeyPadWithoutUserAction()
@@ -740,12 +756,6 @@ void RenderWidgetHostViewEfl::OnTextInputStateChanged(
     // is turned on
     host_->ScrollFocusedEditableNodeIntoRect(gfx::Rect(0, 0, 0, 0));
   }
-#if defined(EWK_REFACTOR)
-  if (GetSelectionController()) {
-    GetSelectionController()->SetSelectionEditable(
-        params.type != ui::TEXT_INPUT_TYPE_NONE);
-  }
-#endif
 }
 
 void RenderWidgetHostViewEfl::OnTextInputInFormStateChanged(bool is_in_form_tag) {
@@ -761,32 +771,22 @@ void RenderWidgetHostViewEfl::ImeCancelComposition() {
 void RenderWidgetHostViewEfl::ImeCompositionRangeChanged(
   const gfx::Range& range,
   const std::vector<gfx::Rect>& character_bounds) {
-  NOTIMPLEMENTED();
-#if defined(EWK_REFACTOR)
-  if (web_view_) {
-    SelectionControllerEfl* controller = web_view_->GetSelectionController();
-    if (controller) {
-      controller->SetCaretSelectionStatus(false);
-      controller->HideHandleAndContextMenu();
-    }
+
+  if (GetSelectionController()) {
+    GetSelectionController()->SetCaretSelectionStatus(false);
+    GetSelectionController()->HideHandleAndContextMenu();
   }
-#endif
 }
 
 void RenderWidgetHostViewEfl::FocusedNodeChanged(bool is_editable_node) {
-#if defined(EWK_REFACTOR)
-  if (web_view_) {
-    SelectionControllerEfl* controller = web_view_->GetSelectionController();
-    if (controller) {
-      controller->SetCaretSelectionStatus(false);
-      controller->HideHandleAndContextMenu();
-    }
-    if (im_context_ && im_context_->IsShow() &&
-      ClipboardHelperEfl::GetInstance()->IsClipboardWindowOpened()) {
-      ClipboardHelperEfl::GetInstance()->CloseClipboardWindow();
-    }
+  if (GetSelectionController()) {
+    GetSelectionController()->SetCaretSelectionStatus(false);
+    GetSelectionController()->HideHandleAndContextMenu();
+  }
+  if (im_context_ && im_context_->IsShow() &&
+    ClipboardHelperEfl::GetInstance()->IsClipboardWindowOpened()) {
+    ClipboardHelperEfl::GetInstance()->CloseClipboardWindow();
   }
-#endif
 }
 
 void RenderWidgetHostViewEfl::Destroy() {
@@ -800,20 +800,15 @@ void RenderWidgetHostViewEfl::SelectionChanged(const base::string16& text,
   size_t offset,
   const gfx::Range& range) {
   RenderWidgetHostViewBase::SelectionChanged(text, offset, range);
-#if defined(EWK_REFACTOR)
-  if (!web_view_)
-    return;
 
-  SelectionControllerEfl* controller = web_view_->GetSelectionController();
-  if (!controller)
+  if (!GetSelectionController())
     return;
 
   base::string16 selectedText;
   if (!text.empty() && !range.is_empty())
     selectedText = GetSelectedText();
 
-  controller->UpdateSelectionData(selectedText);
-#endif
+  GetSelectionController()->UpdateSelectionData(selectedText);
 }
 
 void RenderWidgetHostViewEfl::SelectionBoundsChanged(
@@ -824,7 +819,7 @@ void RenderWidgetHostViewEfl::SelectionBoundsChanged(
 
   if (im_context_)
     im_context_->UpdateCaretBounds(gfx::UnionRects(guest_params.anchor_rect, guest_params.focus_rect));
-#if defined(EWK_REFACTOR)
+
   if (GetSelectionController()) {
     GetSelectionController()->UpdateSelectionDataAndShow(
         guest_params.anchor_rect,
@@ -832,12 +827,40 @@ void RenderWidgetHostViewEfl::SelectionBoundsChanged(
         guest_params.is_anchor_first,
         false);
   }
+}
+
+void RenderWidgetHostViewEfl::SelectionRootBoundsChanged(const gfx::Rect& rect) {
+  if (GetSelectionController()) {
+    GetSelectionController()->SetVisibilityBounds(
+        ConvertRectToPixel(device_scale_factor_, rect));
+  }
+}
+
+void RenderWidgetHostViewEfl::ExecuteEditCommand(const char* command, const char* value) {
+  EINA_SAFETY_ON_NULL_RETURN(command);
+
+  value = (value == NULL) ? "" : value;
+
+  RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(web_contents_.GetRenderViewHost());
+
+  rvhi->ExecuteEditCommand(command, value);
+
+#if defined(EWK_REFACTOR)
+  // This is workaround for rich text toolbar buttons in email application
+  if ( !strcmp(command, "InsertOrderedList")
+    || !strcmp(command, "InsertUnorderedList")
+    || !strcmp(command, "AlignCenter")
+    || !strcmp(command, "AlignJustified")
+    || !strcmp(command, "AlignLeft")
+    || !strcmp(command, "AlignRight") ) {
+    QuerySelectionStyle();
+  }
 #endif
 }
 
 void RenderWidgetHostViewEfl::DidStopFlinging() {
   edge_effect_->Hide();
-#if defined(EWK_REFACTOR)
+
   SelectionControllerEfl* controller = GetSelectionController();
   if (!controller)
     return;
@@ -851,7 +874,29 @@ void RenderWidgetHostViewEfl::DidStopFlinging() {
       controller->GetRightRect(),
       false,
       false);
-#endif
+}
+
+void RenderWidgetHostViewEfl::EvasToBlinkCords(int x, int y, int* view_x, int* view_y) {
+  Evas_Coord tmpX, tmpY;
+  evas_object_geometry_get(smart_parent(), &tmpX, &tmpY, NULL, NULL);
+
+  if (view_x) {
+    *view_x = x - tmpX;
+    *view_x /= device_scale_factor_;
+  }
+
+  if (view_y) {
+    *view_y = y - tmpY;
+    *view_y /= device_scale_factor_;
+  }
+}
+
+void RenderWidgetHostViewEfl::SelectClosestWord(const gfx::Point& touch_point) {
+  int view_x, view_y;
+  EvasToBlinkCords(touch_point.x(), touch_point.y(), &view_x, &view_y);
+
+  Send(new ViewMsg_SelectClosestWord(
+      host_->GetRoutingID(), view_x, view_y));
 }
 
 void RenderWidgetHostViewEfl::ShowDisambiguationPopup(const gfx::Rect& rect_pixels, const SkBitmap& zoomed_bitmap) {
@@ -1385,53 +1430,53 @@ void RenderWidgetHostViewEfl::SendGestureEvent(
 
 void RenderWidgetHostViewEfl::HandleGestureBegin() {
   edge_effect_->Enable();
-#if defined(EWK_REFACTOR)
   selection_acked_on_tap_ = false;
+  single_tap_performed_ = false;
   was_scrolled_ = false;
   if (GetSelectionController()) {
     should_restore_selection_menu_ =
         GetSelectionController()->IsAnyHandleVisible();
+    // There can be multiple GestureBegin, but we need
+    // only state of showing large handle at first time
+    if (!restore_showing_large_handle_on_gesture_end_) {
+      restore_showing_large_handle_on_gesture_end_.reset(
+          new bool(GetSelectionController()->GetShowOnlyLargeHandle()));
+      GetSelectionController()->SetShowOnlyLargeHandle(false);
+    }
   }
-#endif
 }
 
 void RenderWidgetHostViewEfl::HandleGestureEnd() {
-  edge_effect_->Disable();
-#if defined(EWK_REFACTOR)
   if (GetSelectionController()) {
-    if (GetSelectionController()->GetScrollStatus())
-      GetSelectionController()->SetScrollStatus(false);
-
     if (should_restore_selection_menu_ && !was_scrolled_ &&
-        !selection_acked_on_tap_) {
+        !selection_acked_on_tap_ &&
+        !(single_tap_performed_ &&
+          GetSelectionController()->GetSelectionEditable())) {
       should_restore_selection_menu_ = false;
       GetSelectionController()->HideHandleAndContextMenu();
-    } else if (GetSelectionController()->GetSelectionStatus()) {
-      GetSelectionController()->UpdateSelectionDataAndShow(
-          GetSelectionController()->GetLeftRect(),
-          GetSelectionController()->GetRightRect(),
-          false /* unused */,
-          should_restore_selection_menu_);
+    }
+
+    if (restore_showing_large_handle_on_gesture_end_) {
+      GetSelectionController()->SetShowOnlyLargeHandle(
+          *restore_showing_large_handle_on_gesture_end_);
+      restore_showing_large_handle_on_gesture_end_.reset();
     }
   }
+  single_tap_performed_ = false;
   // Edge effect should be disabled upon scroll end/fling start.
   // Gesture end comes just after those events, so it's disabled here.
-#endif
+  edge_effect_->Disable();
 }
 
 void RenderWidgetHostViewEfl::HandleGesture(
     blink::WebGestureEvent& event) {
-#if defined(EWK_REFACTOR)
-  if (event.type == blink::WebInputEvent::GestureTap) {
-    eweb_view()->HandlePostponedGesture(event.x, event.y, ui::ET_GESTURE_TAP);
-  } else if (event.type == blink::WebInputEvent::GestureShowPress) {
-    eweb_view()->HandlePostponedGesture(
-        event.x, event.y, ui::ET_GESTURE_SHOW_PRESS);
-  } else if (event.type == blink::WebInputEvent::GestureLongPress) {
-    eweb_view()->HandlePostponedGesture(
-        event.x, event.y, ui::ET_GESTURE_LONG_PRESS);
-  }
+  SelectionControllerEfl* controller = GetSelectionController();
+  if (controller)
+    controller->HandleGesture(event,
+        restore_showing_large_handle_on_gesture_end_,
+        should_restore_selection_menu_);
 
+#if defined(EWK_REFACTOR)
   if ((event.type == blink::WebInputEvent::GesturePinchBegin ||
       event.type == blink::WebInputEvent::GesturePinchUpdate ||
       event.type == blink::WebInputEvent::GesturePinchEnd) &&
@@ -1447,6 +1492,7 @@ void RenderWidgetHostViewEfl::HandleGesture(
       event.type == blink::WebInputEvent::GesturePinchEnd) {
     eweb_view()->SmartCallback<EWebViewCallbacks::ZoomFinished>().call();
   }
+#endif
 
   if (event.type == blink::WebInputEvent::GestureTap ||
       event.type == blink::WebInputEvent::GestureTapCancel) {
@@ -1465,17 +1511,15 @@ void RenderWidgetHostViewEfl::HandleGesture(
     fling_cancel.type = blink::WebInputEvent::GestureFlingCancel;
     fling_cancel.sourceDevice = blink::WebGestureDeviceTouchscreen;
     SendGestureEvent(fling_cancel);
+    single_tap_performed_ = true;
   } else if (event.type == blink::WebInputEvent::GestureTapCancel ||
       event.type == blink::WebInputEvent::GestureTapUnconfirmed) {
     selection_acked_on_tap_ = should_restore_selection_menu_;
+    single_tap_performed_ = false;
   } else if (event.type == blink::WebInputEvent::GestureScrollBegin) {
     was_scrolled_ = true;
-    if (GetSelectionController())
-      GetSelectionController()->SetScrollStatus(true);
-  } else
-#endif
-  DCHECK(edge_effect_.get());
-  if (event.type == blink::WebInputEvent::GestureScrollUpdate) {
+  } else if (event.type == blink::WebInputEvent::GestureScrollUpdate) {
+    DCHECK(edge_effect_.get());
     if (event.data.scrollUpdate.deltaX < 0)
       edge_effect_->Hide("edge,left");
     else if (event.data.scrollUpdate.deltaX > 0)
@@ -1579,13 +1623,13 @@ void RenderWidgetHostViewEfl::OnOrientationChangeEvent(int orientation) {
   current_orientation_ = orientation;
 }
 
-#if defined(EWK_REFACTOR)
 SelectionControllerEfl* RenderWidgetHostViewEfl::GetSelectionController() {
-  if (web_view_)
-    return web_view_->GetSelectionController();
-  return NULL;
+  WebContentsImpl* wci = static_cast<WebContentsImpl*>(&web_contents_);
+  DCHECK(wci);
+  WebContentsViewEfl* wcve = static_cast<WebContentsViewEfl*>(wci->GetView());
+  DCHECK(wcve);
+  return wcve->GetSelectionController();
 }
-#endif
 
 void RenderWidgetHostViewEfl::MoveCaret(const gfx::Point& point) {
   host_->MoveCaret(gfx::Point(point.x() / device_scale_factor_, point.y() / device_scale_factor_));
index fd795fc..81cf4b0 100644 (file)
@@ -15,6 +15,8 @@
 #include "base/format_macros.h"
 #include "content/browser/renderer_host/render_widget_host_view_base.h"
 #include "content/browser/renderer_host/evas_event_handler.h"
+#include "content/browser/web_contents/web_contents_impl.h"
+#include "content/browser/web_contents/web_contents_view_efl.h"
 #include "content/common/content_export.h"
 #include "cc/layers/delegated_frame_provider.h"
 #include "cc/layers/delegated_frame_resource_collection.h"
@@ -30,6 +32,7 @@
 #include "gpu/command_buffer/common/mailbox.h"
 #include "ui/base/ime/composition_text.h"
 #include "ui/base/ime/text_input_client.h"
+#include "ui/base/selection/selection_controller_efl.h"
 #include "ui/events/gestures/gesture_types.h"
 #include "ui/events/gestures/gesture_recognizer.h"
 #include "ui/events/gestures/motion_event_aura.h"
@@ -47,6 +50,7 @@ typedef EvasGLuint64         GLuint64;
 #endif
 
 struct ViewHostMsg_TextInputState_Params;
+struct ViewHostMsg_HitTestAsyncReply_Params;
 
 namespace ui {
 class GestureEvent;
@@ -65,6 +69,7 @@ class IMContextEfl;
 class RenderWidgetHostImpl;
 class RenderWidgetHostView;
 class ReadbackYUVInterface;
+class WebContents;
 
 // RenderWidgetHostView class hierarchy described in render_widget_host_view.h.
 class RenderWidgetHostViewEfl
@@ -74,7 +79,7 @@ class RenderWidgetHostViewEfl
     public base::SupportsWeakPtr<RenderWidgetHostViewEfl>,
     public IPC::Sender {
  public:
-  explicit RenderWidgetHostViewEfl(RenderWidgetHost*);
+  explicit RenderWidgetHostViewEfl(RenderWidgetHost*, WebContents& web_contents);
 
   // RenderWidgetHostViewBase implementation.
   void InitAsChild(gfx::NativeView) override;
@@ -105,6 +110,9 @@ class RenderWidgetHostViewEfl
 
   void OnTextInputInFormStateChanged(bool is_in_form_tag);
   void OnTextInputStateChanged(const ViewHostMsg_TextInputState_Params& params);
+  void OnHitTestAsyncReply(const
+      ViewHostMsg_HitTestAsyncReply_Params& params,
+      int64_t request_id);
 
   void TextInputTypeChanged(ui::TextInputType type,
                             ui::TextInputMode mode,
@@ -119,6 +127,7 @@ class RenderWidgetHostViewEfl
   void SetTooltipText(const base::string16&) override;
   void SelectionChanged(const base::string16&, size_t, const gfx::Range&) override;
   void SelectionBoundsChanged(const ViewHostMsg_SelectionBounds_Params&) override;
+  void SelectionRootBoundsChanged(const gfx::Rect&) override;
   void CopyFromCompositingSurface(
     const gfx::Rect&,
     const gfx::Size& /* dst_size */,
@@ -165,6 +174,9 @@ class RenderWidgetHostViewEfl
 
   void FilterInputMotion(const blink::WebGestureEvent& gesture_event);
 
+  void EvasToBlinkCords(int x, int y, int* view_x, int* view_y);
+  void SelectClosestWord(const gfx::Point& touch_point);
+
   Evas* evas() const {
     DCHECK(evas_);
     return evas_;
@@ -202,6 +214,7 @@ class RenderWidgetHostViewEfl
 
   bool IsIMEShow() const;
   gfx::Rect GetIMERect() const;
+  void ExecuteEditCommand(const char* command, const char* value);
 
  protected:
   friend class RenderWidgetHostView;
@@ -232,9 +245,7 @@ class RenderWidgetHostViewEfl
 
   void OnOrientationChangeEvent(int);
 
-#if 0
   SelectionControllerEfl* GetSelectionController();
-#endif
 
   static void CopyFromCompositingSurfaceHasResultForVideo(
       base::WeakPtr<RenderWidgetHostViewEfl> rwhvefl,
@@ -256,6 +267,11 @@ class RenderWidgetHostViewEfl
   static void EvasObjectImagePixelsGetCallback(void*, Evas_Object*);
   void initializeProgram();
 
+  void HandleLongPressGesture(int x, int y,
+    const ViewHostMsg_HitTestAsyncReply_Params& params);
+  void HandleTapGesture(int x, int y,
+    const ViewHostMsg_HitTestAsyncReply_Params& params);
+
 #if defined(USE_WAYLAND)
   Ecore_Wl_Window* GetEcoreWlWindow() const;
 #else
@@ -343,6 +359,13 @@ class RenderWidgetHostViewEfl
 
   gpu::Mailbox pending_mailbox_;
 
+  WebContents& web_contents_;
+
+  bool single_tap_performed_;
+  // when gesture start, state of showing large handle
+  // is saved and restored when gesture will end.
+  scoped_ptr<bool> restore_showing_large_handle_on_gesture_end_;
+
   DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewEfl);
 };
 
index 3227caa..0f2a14b 100644 (file)
@@ -86,9 +86,12 @@ RenderWidgetHostViewBase* WebContentsViewEfl::CreateViewForWidget(
     RenderWidgetHost* render_widget_host, bool is_guest_view_hack) {
 
   RenderWidgetHostViewEfl* view =
-      new RenderWidgetHostViewEfl(render_widget_host);
+      new RenderWidgetHostViewEfl(render_widget_host, *web_contents_);
   view->InitAsChild(native_view_);
 
+  selection_controller_.reset(new SelectionControllerEfl(
+      view->smart_parent(), *web_contents_));
+
   elm_naviframe_item_pop(native_view_);
   Evas_Object* content_view = static_cast<Evas_Object*>(view->GetNativeView());
   Elm_Object_Item* item = elm_naviframe_item_push(native_view_,
@@ -99,13 +102,12 @@ RenderWidgetHostViewBase* WebContentsViewEfl::CreateViewForWidget(
   view->Show();
 
   SetOrientation(orientation_);
-
   return view;
 }
 
 RenderWidgetHostViewBase* WebContentsViewEfl::CreateViewForPopupWidget(
     RenderWidgetHost* render_widget_host) {
-  return new RenderWidgetHostViewEfl(render_widget_host);
+  return new RenderWidgetHostViewEfl(render_widget_host, *web_contents_);
 }
 
 void WebContentsViewEfl::SetPageTitle(const base::string16& title) {
@@ -113,6 +115,11 @@ void WebContentsViewEfl::SetPageTitle(const base::string16& title) {
     efl_delegate_->SetPageTitle(title);
 }
 
+void WebContentsViewEfl::CancelContextMenu(int request_id) {
+  if (efl_delegate_)
+    efl_delegate_->CancelContextMenu(request_id);
+}
+
 void WebContentsViewEfl::UpdateDragDest(RenderViewHost* host) {
   // Drag-and-drop is entirely managed by BrowserPluginGuest for guest
   // processes in a largely platform independent way. WebDragDestEfl
index 43cbd4f..f816903 100644 (file)
@@ -10,6 +10,7 @@
 
 #include "content/browser/renderer_host/render_view_host_delegate_view.h"
 #include "content/browser/web_contents/web_contents_view.h"
+#include "ui/base/selection/selection_controller_efl.h"
 
 namespace content {
 
@@ -70,11 +71,15 @@ class WebContentsViewEfl
                      const gfx::ImageSkia& image,
                      const gfx::Vector2d& image_offset,
                      const DragEventSourceInfo& event_info) override;
+  void CancelContextMenu(int request_id);
   bool IsDragging() const;
 
   void SetOrientation(int orientation);
   void SetTouchEventsEnabled(bool);
   void SetPageScaleFactor(float);
+  SelectionControllerEfl* GetSelectionController() const {
+    return selection_controller_.get();
+  }
 
 private:
   // Our optional, generic views wrapper.
@@ -97,6 +102,7 @@ private:
   float page_scale_factor_;
 
   WebContents* web_contents_;
+  scoped_ptr<SelectionControllerEfl> selection_controller_;
 
   DISALLOW_COPY_AND_ASSIGN(WebContentsViewEfl);
 };
index d6f4655..72f3004 100644 (file)
@@ -32,6 +32,7 @@ class WebContentsViewEflDelegate {
   virtual void HidePopupMenu() = 0;
 
   virtual void SetPageTitle(const base::string16& title) = 0;
+  virtual void CancelContextMenu(int request_id) = 0;
 };
 
 } // namespace content
@@ -2,15 +2,16 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "eweb_view.h"
-#include "selection_box_efl.h"
+#include "base/trace_event/trace_event.h"
+#include "ui/base/selection/selection_box_efl.h"
 
 namespace content {
 
-SelectionBoxEfl::SelectionBoxEfl(EWebView* parent_view)
+SelectionBoxEfl::SelectionBoxEfl(Evas_Object* parent_view)
   : status_(false),
     editable_(false),
     is_caret_selection_(false),
+    is_anchor_first_(false),
     context_params_(new ContextMenuParams()),
     parent_view_(parent_view) {
       context_params_->has_image_contents = false;
@@ -36,16 +37,18 @@ bool SelectionBoxEfl::UpdateRectData(const gfx::Rect& left_rect, const gfx::Rect
       ret = true;
     left_rect_ = left_rect;
     right_rect_ = right_rect;
+    is_anchor_first_ = true;
   } else {
     if (left_rect_ != right_rect || right_rect_ != left_rect)
       ret = true;
     right_rect_ = left_rect;
     left_rect_ = right_rect;
+    is_anchor_first_ = false;
   }
 
   // Display point of context Menu
   Evas_Coord x, y;
-  evas_object_geometry_get(parent_view_->evas_object(), &x, &y, 0, 0);
+  evas_object_geometry_get(parent_view_, &x, &y, 0, 0);
   //context params suppose to be global - related to evas not the web view
   ret |= (context_params_->x != (left_rect_.x() + x));
   ret |= (context_params_->y != (left_rect_.y() + y));
@@ -64,8 +67,8 @@ void SelectionBoxEfl::SetStatus(bool enable) {
   status_ = enable;
 
   // invoke CB only if mode actually changed
-  if (invokeCbAtEnd)
-    parent_view_->SmartCallback<EWebViewCallbacks::TextSelectionMode>().call(&status_);
+  if (invokeCbAtEnd && parent_view_)
+      evas_object_smart_callback_call(parent_view_, "textselection,mode", &status_);
 }
 
 }
@@ -5,6 +5,8 @@
 #ifndef selection_box_efl_h
 #define selection_box_efl_h
 
+#include <Evas.h>
+
 #include "base/memory/scoped_ptr.h"
 #include "content/public/common/context_menu_params.h"
 #include "content/public/common/menu_item.h"
@@ -20,7 +22,7 @@ namespace content {
 // controlling
 class SelectionBoxEfl {
  public:
-  SelectionBoxEfl(EWebView* parent_view);
+  SelectionBoxEfl(Evas_Object* parent_view);
 
   void SetStatus(bool enable);
   bool GetStatus() const { return status_; }
@@ -35,6 +37,7 @@ class SelectionBoxEfl {
   bool GetCaretSelectionStatus() const { return is_caret_selection_; }
   gfx::Rect GetLeftRect() const { return left_rect_; }
   gfx::Rect GetRightRect() const { return right_rect_; }
+  bool GetIsAnchorFirst() const { return is_anchor_first_; }
   ContextMenuParams* GetContextMenuParams() const { return context_params_.get(); }
 
  private:
@@ -53,10 +56,12 @@ class SelectionBoxEfl {
   // End of selection
   gfx::Rect right_rect_;
 
+  bool is_anchor_first_;
+
   // Contains the menu item data for which context needs to be populated
   scoped_ptr<ContextMenuParams> context_params_;
 
-  EWebView* parent_view_;
+  Evas_Object* parent_view_;
 };
 
 }
@@ -6,14 +6,62 @@
 
 #include <Edje.h>
 
+#include "base/trace_event/trace_event.h"
 #include "content/browser/renderer_host/render_widget_host_view_efl.h"
+#include "content/browser/renderer_host/render_widget_host_impl.h"
+#include "content/browser/renderer_host/render_view_host_impl.h"
+#include "content/browser/web_contents/web_contents_impl.h"
+#include "content/browser/web_contents/web_contents_impl_efl.h"
+#include "content/common/view_messages.h"
 #include "content/public/browser/web_contents.h"
-#include "eweb_view.h"
-#include "public/ewk_hit_test.h"
+#include "content/public/browser/render_view_host.h"
+#include "content/public/common/context_menu_params.h"
 #include "ui/gfx/screen.h"
 
 namespace content {
 
+class ScAsyncRequestHitTestDataCallback
+{
+ public:
+  ScAsyncRequestHitTestDataCallback(const gfx::Point& point)
+      : point_(point) {
+  }
+  virtual ~ScAsyncRequestHitTestDataCallback() {};
+
+  virtual void Run(const ViewHostMsg_HitTestAsyncReply_Params& params,
+      SelectionControllerEfl* controller) = 0;
+
+ protected:
+  const gfx::Point& GetPoint() const { return point_; }
+
+ private:
+  const gfx::Point& point_;
+};
+
+class RwhvAsyncRequestHitTestDataInternalCallback
+  : public ScAsyncRequestHitTestDataCallback
+{
+ public:
+  typedef void (SelectionControllerEfl::*Callback)(const gfx::Point&,
+      const ViewHostMsg_HitTestAsyncReply_Params& params);
+
+ public:
+  RwhvAsyncRequestHitTestDataInternalCallback(const gfx::Point& point,
+                                              Callback cb)
+      : ScAsyncRequestHitTestDataCallback(point)
+      , callback_(cb) {
+  }
+
+  void Run(const ViewHostMsg_HitTestAsyncReply_Params& params,
+      SelectionControllerEfl* controller) override {
+    DCHECK(callback_);
+    (controller->*callback_)(GetPoint(), params);
+  }
+
+ private:
+  Callback callback_;
+};
+
 static const int menuHeight = 140;// The Height fo the context menu.
 static const int menuPadding = 60;// This is padding for deciding when to modify context menu position.
 static const int spacePadding = 0; // 24;// This is for making context menu closer to the handles.
@@ -23,7 +71,7 @@ static bool IsRectEmpty(const gfx::Rect& rect) {
   return (rect.x() == 0 && rect.y() == 0 && rect.height() == 0 && rect.width() == 0);
 }
 
-SelectionControllerEfl::SelectionControllerEfl(EWebView* parent_view, WebContents& web_contents)
+SelectionControllerEfl::SelectionControllerEfl(Evas_Object* parent_view, WebContents& web_contents)
     :  parent_view_(parent_view),
        mouse_press_(false),
        scrolling_(false),
@@ -33,21 +81,30 @@ SelectionControllerEfl::SelectionControllerEfl(EWebView* parent_view, WebContent
        long_mouse_press_(false),
        caret_selection_(true),
        selection_data_(new SelectionBoxEfl(parent_view)),
-       start_handle_(new SelectionHandleEfl(*this, SelectionHandleEfl::HANDLE_TYPE_LEFT, parent_view->evas_object())),
-       end_handle_(new SelectionHandleEfl(*this, SelectionHandleEfl::HANDLE_TYPE_RIGHT, parent_view->evas_object())),
-       input_handle_(new SelectionHandleEfl(*this, SelectionHandleEfl::HANDLE_TYPE_INPUT, parent_view->evas_object())),
+       start_handle_(new SelectionHandleEfl(*this, SelectionHandleEfl::HANDLE_TYPE_LEFT, parent_view)),
+       end_handle_(new SelectionHandleEfl(*this, SelectionHandleEfl::HANDLE_TYPE_RIGHT, parent_view)),
+       input_handle_(new SelectionHandleEfl(*this, SelectionHandleEfl::HANDLE_TYPE_INPUT, parent_view)),
 
-       magnifier_(new SelectionMagnifierEfl(this)),
+       magnifier_(new SelectionMagnifierEfl(this, web_contents)),
        is_selection_visible_(false),
-       show_only_large_handler_(false),
+       show_only_large_handle_(false),
        web_contents_(web_contents) {
-  evas_object_event_callback_add(parent_view_->evas_object(), EVAS_CALLBACK_MOVE, &EvasParentViewMoveCallback, this);
+  evas_object_event_callback_add(parent_view_, EVAS_CALLBACK_MOVE, &EvasParentViewMoveCallback, this);
 
 #if defined(OS_TIZEN)
   vconf_notify_key_changed(VCONFKEY_LANGSET, PlatformLanguageChanged, this);
 #endif
 }
 
+SelectionControllerEfl::~SelectionControllerEfl() {
+  std::map<int64_t, ScAsyncRequestHitTestDataCallback*>::iterator hit_test_callback_iterator;
+  for (hit_test_callback_iterator = hit_test_callback_.begin();
+      hit_test_callback_iterator != hit_test_callback_.end();
+      hit_test_callback_iterator++)
+    delete hit_test_callback_iterator->second;
+  hit_test_callback_.clear();
+}
+
 void SelectionControllerEfl::SetSelectionStatus(bool enable) {
   TRACE_EVENT1("selection,efl", __PRETTY_FUNCTION__, "enable", enable);
   selection_data_->SetStatus(enable);
@@ -95,10 +152,13 @@ bool SelectionControllerEfl::GetCaretSelectionStatus() const {
 
 void SelectionControllerEfl::SetScrollStatus(const bool enable) {
   TRACE_EVENT1("selection,efl", __PRETTY_FUNCTION__, "scroll status", enable);
+  if (scrolling_ && enable)
+    return;
+
   scrolling_ = enable;
   if (enable) {
     Clear(IsAnyHandleVisible() || postponed_);
-    parent_view_->CancelContextMenu(0);
+    CancelContextMenu(0);
   } else if (show_after_scroll_ || postponed_) {
     ShowHandleAndContextMenuIfRequired();
   }
@@ -114,8 +174,11 @@ void SelectionControllerEfl::UpdateSelectionData(const base::string16& text) {
 }
 
 bool SelectionControllerEfl::ClearSelectionViaEWebView() {
+  RenderWidgetHostViewEfl* rwhv =
+      static_cast<RenderWidgetHostViewEfl*>(web_contents_.GetRenderWidgetHostView());
   if (GetSelectionStatus()) {
-    parent_view_->ExecuteEditCommand("Unselect", NULL);
+    if (rwhv)
+      rwhv->ExecuteEditCommand("Unselect", NULL);
     return true;
   }
 
@@ -128,71 +191,31 @@ bool SelectionControllerEfl::UpdateSelectionDataAndShow(
     bool,
     bool show) {
   TRACE_EVENT0("selection,efl", __PRETTY_FUNCTION__);
-
   if (!show && !IsSelectionValid(left_rect, right_rect)) {
     if (!GetCaretSelectionStatus())
       ClearSelection();
     selection_data_->UpdateRectData(left_rect, right_rect);
     return false;
   }
-
-  RenderWidgetHostViewEfl* rwhv = static_cast<RenderWidgetHostViewEfl*>(web_contents_.GetRenderWidgetHostView());
-  if (show_only_large_handler_ && GetCaretSelectionStatus() &&
+  RenderWidgetHostViewEfl* rwhv =
+      static_cast<RenderWidgetHostViewEfl*>(web_contents_.GetRenderWidgetHostView());
+  if (show_only_large_handle_ && GetCaretSelectionStatus() &&
       (rwhv && !rwhv->IsLastAvailableTextEmpty())) {
     selection_data_->UpdateRectData(left_rect, right_rect);
     ShowHandleAndContextMenuIfRequired();
     return true;
   }
-
   if ((selection_data_->UpdateRectData(left_rect, right_rect) &&
       IsAnyHandleVisible()) || show || postponed_) {
-    show_only_large_handler_ = false;
-    if (selection_data_->GetEditable()) {
-      // In case we're selecting text in editable text field we've already sent
-      // swapped coordinates from OnMouseMove. No need to do it for the second
-      // time.
-      ShowHandleAndContextMenuIfRequired();
-    } else {
-      ShowHandleAndContextMenuIfRequired(left_rect < right_rect);
-    }
+    show_only_large_handle_ = false;
+    ShowHandleAndContextMenuIfRequired();
   }
-
   expecting_update_ = false;
   return true;
 }
 
-namespace {
-class HitTestContext
-{
-public:
-  HitTestContext(SelectionControllerEfl* ctrl, bool anchor)
-    : owner(ctrl)
-    , anchor_first(anchor) {
-  }
-
-  SelectionControllerEfl* GetOwner() const { return owner; }
-  bool GetAnchorFirst() const { return anchor_first; }
-
-private:
-  SelectionControllerEfl* owner;
-  bool anchor_first;
-};
-} // namespace
-
-void SelectionControllerEfl::ShowHandleAndContextMenuIfRequiredCallback(
-    Evas_Object* o, int x, int y, int mode, _Ewk_Hit_Test* hit_test,
-    void* data) {
-  HitTestContext* context = static_cast<HitTestContext*>(data);
-  DCHECK(context);
-  DCHECK(context->GetOwner());
-  context->GetOwner()->ShowHandleAndContextMenuIfRequired(
-      o, x, y, mode, hit_test, context->GetAnchorFirst());
-  delete context;
-}
-
 void SelectionControllerEfl::ShowHandleAndContextMenuIfRequired(
-    Evas_Object* o, int x, int y, int /* mode*/,
-    _Ewk_Hit_Test* hit_test, bool anchor_first) {
+    int x, int y) {
   if (scrolling_)
     return;
 
@@ -200,20 +223,17 @@ void SelectionControllerEfl::ShowHandleAndContextMenuIfRequired(
     return;
 
   gfx::Rect left, right;
-  if (anchor_first) {
+  if (selection_data_->GetIsAnchorFirst()) {
     left = selection_data_->GetLeftRect();
     right = selection_data_->GetRightRect();
   } else {
     right = selection_data_->GetLeftRect();
     left = selection_data_->GetRightRect();
   }
-
   postponed_ = false;
   // Is in edit field and no text is selected. show only single handle
   if (selection_data_->IsInEditField() && left == right) {
-
-    if (hit_test &&
-        !(hit_test->GetResultContext() & EWK_HIT_TEST_RESULT_CONTEXT_EDITABLE)) {
+    if (!GetSelectionEditable()) {
       postponed_ = true;
       return;
     }
@@ -226,12 +246,12 @@ void SelectionControllerEfl::ShowHandleAndContextMenuIfRequired(
     }
     start_handle_->Hide();
     end_handle_->Hide();
+#if defined(EWK_REFACTOR)
     parent_view_->QuerySelectionStyle();
+#endif
 
-    if (!mouse_press_ && !show_only_large_handler_) {
-      parent_view_->ShowContextMenu(*(selection_data_->GetContextMenuParams()),
-         MENU_TYPE_SELECTION, false);
-    }
+    if (!mouse_press_ && !show_only_large_handle_)
+      ShowContextMenu();
 
     return;
   } else {
@@ -242,7 +262,6 @@ void SelectionControllerEfl::ShowHandleAndContextMenuIfRequired(
     selection_data_->ClearRectData();
     return;
   }
-
   // The base position of start_handle should be set to the middle of the left
   // rectangle. Otherwise the start_handle may be shifted up when the
   // right_handle is moving
@@ -270,18 +289,39 @@ void SelectionControllerEfl::ShowHandleAndContextMenuIfRequired(
   }
 
   // Do not show the context menu during selection extend
-  if (!mouse_press_) {
-    parent_view_->ShowContextMenu(
-        *(selection_data_->GetContextMenuParams()),
-        MENU_TYPE_SELECTION,
-        false);
-  }
+  if (!mouse_press_)
+    ShowContextMenu();
 
+#if defined(EWK_REFACTOR)
   parent_view_->QuerySelectionStyle();
+#endif
 }
 
-void SelectionControllerEfl::ShowHandleAndContextMenuIfRequired(
-    bool anchor_first) {
+void SelectionControllerEfl::ShowContextMenu() {
+  WebContentsImpl* wci = static_cast<WebContentsImpl*>(&web_contents_);
+  WebContentsViewEfl* wcve = static_cast<WebContentsViewEfl*>(wci->GetView());
+  RenderWidgetHostViewEfl* rwhv =
+      static_cast<RenderWidgetHostViewEfl*>(web_contents_.GetRenderWidgetHostView());
+  RenderViewHost* rvh = static_cast<RenderViewHost*>(wci->GetRenderViewHost());
+
+  content::ContextMenuParams convertedParams = *(selection_data_->GetContextMenuParams());
+
+  int blinkX, blinkY;
+  if (rwhv)
+    rwhv->EvasToBlinkCords(convertedParams.x, convertedParams.y, &blinkX, &blinkY);
+  convertedParams.x = blinkX;
+  convertedParams.y = blinkY;
+  wcve->ShowContextMenu(rvh->GetMainFrame(), convertedParams);
+}
+
+void SelectionControllerEfl::CancelContextMenu(int request_id) {
+  WebContentsImpl* wci = static_cast<WebContentsImpl*>(&web_contents_);
+  WebContentsViewEfl* wcve = static_cast<WebContentsViewEfl*>(wci->GetView());
+
+  wcve->CancelContextMenu(request_id);
+}
+
+void SelectionControllerEfl::ShowHandleAndContextMenuIfRequired() {
   TRACE_EVENT0("selection,efl", __PRETTY_FUNCTION__);
 
   if (!selection_data_->GetStatus()) {
@@ -292,19 +332,13 @@ void SelectionControllerEfl::ShowHandleAndContextMenuIfRequired(
   if (scrolling_)
     return;
 
-  HitTestContext* ctx = new HitTestContext(this, anchor_first);
-
   int hitX, hitY;
   hitX = selection_data_->GetContextMenuParams()->x;
   hitY = selection_data_->GetContextMenuParams()->y;
 
   postponed_ = true;
-  parent_view_->AsyncRequestHitTestDataAt(
-      hitX,
-      hitY,
-      EWK_HIT_TEST_MODE_DEFAULT,
-      ShowHandleAndContextMenuIfRequiredCallback,
-      ctx);
+
+  ShowHandleAndContextMenuIfRequired(hitX, hitY);
 }
 
 void SelectionControllerEfl::HideHandles() {
@@ -313,7 +347,7 @@ void SelectionControllerEfl::HideHandles() {
 }
 
 void SelectionControllerEfl::HideHandleAndContextMenu() {
-  parent_view_->CancelContextMenu(0);
+  CancelContextMenu(0);
   HideHandles();
 }
 
@@ -340,12 +374,13 @@ bool SelectionControllerEfl::IsShowingMagnifier() {
 void SelectionControllerEfl::OnMouseDown(const gfx::Point& touch_point,
     SelectionHandleEfl::HandleType handle) {
   // Hide context menu on mouse down
-  show_only_large_handler_ = false;
-  parent_view_->CancelContextMenu(0);
+  show_only_large_handle_ = false;
+  CancelContextMenu(0);
+
   mouse_press_ = true;
 
   Evas_Coord x, y;
-  evas_object_geometry_get(parent_view_->evas_object(), &x, &y, 0, 0);
+  evas_object_geometry_get(parent_view_, &x, &y, 0, 0);
   gfx::Point magnifier_point;
 
   switch (handle) {
@@ -374,14 +409,16 @@ void SelectionControllerEfl::OnMouseDown(const gfx::Point& touch_point,
 
 void SelectionControllerEfl::OnMouseMove(const gfx::Point& touch_point,
     SelectionHandleEfl::HandleType handle) {
-  show_only_large_handler_ = false;
+  show_only_large_handle_ = false;
   // FIXME : Check the text Direction later
   Evas_Coord x, y;
-  evas_object_geometry_get(parent_view_->evas_object(), &x, &y, 0, 0);
+  evas_object_geometry_get(parent_view_, &x, &y, 0, 0);
   expecting_update_ = true;
   gfx::Point magnifier_point;
   gfx::Point start_point, end_point;
   WebContentsImpl* wci = static_cast<WebContentsImpl*>(&web_contents_);
+  RenderWidgetHostViewEfl* rwhv =
+      static_cast<RenderWidgetHostViewEfl*>(web_contents_.GetRenderWidgetHostView());
   float device_scale_factor =
       gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().device_scale_factor();
 
@@ -391,7 +428,8 @@ void SelectionControllerEfl::OnMouseMove(const gfx::Point& touch_point,
       magnifier_point.set_y(input_handle_->GetBasePosition().y() + y);
       magnifier_->UpdateLocation(magnifier_point);
       magnifier_->Move(magnifier_point);
-      parent_view_->MoveCaret(input_handle_->GetBasePosition());
+      if (rwhv)
+        rwhv->MoveCaret(input_handle_->GetBasePosition());
       return;
     case SelectionHandleEfl::HANDLE_TYPE_LEFT:
       magnifier_point.set_x(start_handle_->GetBasePosition().x() + x);
@@ -403,16 +441,8 @@ void SelectionControllerEfl::OnMouseMove(const gfx::Point& touch_point,
       start_point.set_y(start_handle_->GetBasePosition().y() / device_scale_factor);
       end_point.set_x(end_handle_->GetBasePosition().x() / device_scale_factor);
       end_point.set_y(end_handle_->GetBasePosition().y() / device_scale_factor);
-      if (GetSelectionEditable()) {
-        // Form elements only support scrolling of extent/end caret. To
-        // move the start element we need to swap the coordinates provided
-        // to SelectRange function.
-        wci->SelectRange(end_point, start_point);
-        return;
-      } else {
-        wci->SelectRange(start_point, end_point);
-        return;
-      }
+      wci->SelectRange(start_point, end_point);
+      return;
     case SelectionHandleEfl::HANDLE_TYPE_RIGHT:
       magnifier_point.set_x(end_handle_->GetBasePosition().x() + x);
       magnifier_point.set_y(end_handle_->GetBasePosition().y() + y);
@@ -429,7 +459,7 @@ void SelectionControllerEfl::OnMouseMove(const gfx::Point& touch_point,
 }
 
 void SelectionControllerEfl::OnMouseUp(const gfx::Point& touch_point) {
-  show_only_large_handler_ = false;
+  show_only_large_handle_ = false;
   mouse_press_ = false;
   magnifier_->Hide();
   start_handle_->SetBasePosition(selection_data_->GetLeftRect().bottom_left());
@@ -445,33 +475,162 @@ void SelectionControllerEfl::GetSelectionBounds(gfx::Rect* left,
     *right = selection_data_->GetRightRect();
 }
 
+void SelectionControllerEfl::OnHitTestAsyncReply(
+    const ViewHostMsg_HitTestAsyncReply_Params& params,
+    int64_t request_id) {
+
+  std::map<int64_t, ScAsyncRequestHitTestDataCallback*>::iterator it =
+      hit_test_callback_.find(request_id);
+
+  if (it == hit_test_callback_.end())
+    return;
+
+  it->second->Run(params, this);
+  delete it->second;
+  hit_test_callback_.erase(it);
+}
+
+
+bool SelectionControllerEfl::AsyncRequestHitTestDataAt(int x, int y,
+    ScAsyncRequestHitTestDataCallback *cb) {
+  RenderWidgetHostViewEfl* rwhv =
+      static_cast<RenderWidgetHostViewEfl*>(web_contents_.GetRenderWidgetHostView());
+  int view_x, view_y;
+  if (rwhv)
+    rwhv->EvasToBlinkCords(x, y, &view_x, &view_y);
+  return AsyncRequestHitTestDataAtBlinkCords(
+      view_x,
+      view_y,
+      cb);
+}
+
+bool SelectionControllerEfl::AsyncRequestHitTestDataAtBlinkCords(int x, int y,
+    ScAsyncRequestHitTestDataCallback *cb) {
+  DCHECK(cb);
+
+  RenderWidgetHostViewEfl* rwhv =
+      static_cast<RenderWidgetHostViewEfl*>(web_contents_.GetRenderWidgetHostView());
+  if (!rwhv)
+    return false;
+
+  static int64_t request_id = 1;
+
+  if (cb) {
+      rwhv->Send(new ViewMsg_DoHitTestAsync(
+          rwhv->GetRenderWidgetHost()->GetRoutingID(), x, y, request_id));
+      hit_test_callback_[request_id] = cb;
+      ++request_id;
+      return true;
+  }
+
+  // if failed we delete callback as it is not needed anymore
+  delete cb;
+  return false;
+}
+
+void SelectionControllerEfl::HandleGesture(blink::WebGestureEvent& event,
+    scoped_ptr<bool>& restore_showing_large_handle_on_gesture_end,
+    bool should_restore_selection_menu) {
+  if (event.type == blink::WebInputEvent::GestureTap) {
+    if (GetCaretSelectionStatus())
+      restore_showing_large_handle_on_gesture_end.reset();
+    HandlePostponedGesture(event.x, event.y, ui::ET_GESTURE_TAP);
+  } else if (event.type == blink::WebInputEvent::GestureShowPress) {
+    HandlePostponedGesture(
+        event.x, event.y, ui::ET_GESTURE_SHOW_PRESS);
+  } else if (event.type == blink::WebInputEvent::GestureLongPress) {
+    restore_showing_large_handle_on_gesture_end.reset();
+    HandlePostponedGesture(
+        event.x, event.y, ui::ET_GESTURE_LONG_PRESS);
+  }
+
+  if (event.type == blink::WebInputEvent::GestureScrollBegin) {
+    SetScrollStatus(true);
+  } else if (event.type == blink::WebInputEvent::GestureScrollEnd) {
+    if (GetScrollStatus())
+      SetScrollStatus(false);
+
+    if (GetSelectionStatus()) {
+      if (restore_showing_large_handle_on_gesture_end) {
+        SetShowOnlyLargeHandle(
+            *restore_showing_large_handle_on_gesture_end);
+        restore_showing_large_handle_on_gesture_end.reset();
+      }
+      UpdateSelectionDataAndShow(
+          GetLeftRect(),
+          GetRightRect(),
+          false /* unused */,
+          should_restore_selection_menu);
+    }
+  }
+}
+
+void SelectionControllerEfl::HandlePostponedGesture(int x, int y, ui::EventType type) {
+  DVLOG(0) << "HandlePostponedGesture :: " << type;
+  RenderWidgetHostViewEfl* rwhv =
+      static_cast<RenderWidgetHostViewEfl*>(web_contents_.GetRenderWidgetHostView());
+
+  gfx::Point point = gfx::Point(x, y);
+  if (rwhv)
+    point = rwhv->ConvertPointInViewPix(point);
+
+  switch (type) {
+    case ui::ET_GESTURE_LONG_PRESS: {
+      ClearSelectionViaEWebView();
+      HideHandleAndContextMenu();
+      RwhvAsyncRequestHitTestDataInternalCallback* cb =
+          new RwhvAsyncRequestHitTestDataInternalCallback(point,
+              &SelectionControllerEfl::HandleLongPressEvent);
+      // below call takes full ownership of cb.
+      AsyncRequestHitTestDataAtBlinkCords(x, y, cb);
+      break;
+    }
+    case ui::ET_GESTURE_TAP: {
+      ClearSelectionViaEWebView();
+      HideHandleAndContextMenu();
+      if (GetSelectionStatus())
+        SetShowOnlyLargeHandle(true);
+    }
+    case ui::ET_GESTURE_SHOW_PRESS: {
+      RwhvAsyncRequestHitTestDataInternalCallback* cb =
+          new RwhvAsyncRequestHitTestDataInternalCallback(point,
+              &SelectionControllerEfl::HandleTapEvent);
+      // below call takes full ownership of cb.
+      AsyncRequestHitTestDataAtBlinkCords(x, y, cb);
+      break;
+    }
+    default:
+      ClearSelectionViaEWebView();
+      break;
+  }
+}
+
 void SelectionControllerEfl::HandleLongPressEvent(
-    const gfx::Point& touch_point, Ewk_Hit_Test_Result_Context context) {
-  if (context & EWK_HIT_TEST_RESULT_CONTEXT_EDITABLE) {
+    const gfx::Point& touch_point,
+    const ViewHostMsg_HitTestAsyncReply_Params& params) {
+
+  if (params.isEditable) {
     SetSelectionStatus(true);
     SetSelectionEditable(true);
     HandleLongPressEventPrivate(touch_point);
-  } else if (!(context & EWK_HIT_TEST_RESULT_CONTEXT_LINK)
-      && !(context & EWK_HIT_TEST_RESULT_CONTEXT_IMAGE)
-      && !(context & EWK_HIT_TEST_RESULT_CONTEXT_MEDIA)
-      && context & EWK_HIT_TEST_RESULT_CONTEXT_TEXT) {
+  } else if (params.linkURI.empty()
+      && params.imageURI.empty()
+      && params.mediaURI.empty()
+      && params.isTextNode) {
     SetSelectionStatus(true);
     HandleLongPressEventPrivate(touch_point);
-    LOG(INFO) << __PRETTY_FUNCTION__ << ":: link, !image, !media, text";
-  } else if (context & EWK_HIT_TEST_RESULT_CONTEXT_DOCUMENT) {
-    LOG(INFO) << __PRETTY_FUNCTION__ << ":: EWK_HIT_TEST_RESULT_CONTEXT_DOCUMENT";
-  } else if (context & EWK_HIT_TEST_RESULT_CONTEXT_IMAGE) {
-    LOG(INFO) << __PRETTY_FUNCTION__ << ":: EWK_HIT_TEST_RESULT_CONTEXT_IMAGE";
-  } else if (context & EWK_HIT_TEST_RESULT_CONTEXT_LINK) {
+    DVLOG(1) << __PRETTY_FUNCTION__ << ":: link, !image, !media, text";
+  } else if (!params.imageURI.empty()) {
+    DVLOG(1) << __PRETTY_FUNCTION__ << ":: IMAGE";
+  } else if (!params.linkURI.empty()) {
     ClearSelectionViaEWebView();
-    LOG(INFO) << __PRETTY_FUNCTION__ << ":: EWK_HIT_TEST_RESULT_CONTEXT_LINK";
-  } else {
-    LOG(INFO) << __PRETTY_FUNCTION__ << ":: hit_test = " << context;
+    DVLOG(1) << __PRETTY_FUNCTION__ << ":: LINK";
   }
+
 }
 
 void SelectionControllerEfl::HandleLongPressEventPrivate(const gfx::Point& touch_point) {
-  show_only_large_handler_ = false;
+  show_only_large_handle_ = false;
   long_mouse_press_ = true;
   Clear();
   caret_selection_ = true;
@@ -479,7 +638,7 @@ void SelectionControllerEfl::HandleLongPressEventPrivate(const gfx::Point& touch
     SetCaretSelectionStatus(true);
   if (caret_selection_) {
     Evas_Coord x, y;
-    evas_object_geometry_get(parent_view_->evas_object(), &x, &y, 0, 0);
+    evas_object_geometry_get(parent_view_, &x, &y, 0, 0);
     magnifier_->HandleLongPress(gfx::Point(touch_point.x() + x,
                                            touch_point.y() + y));
   } else {
@@ -488,18 +647,24 @@ void SelectionControllerEfl::HandleLongPressEventPrivate(const gfx::Point& touch
 }
 
 void SelectionControllerEfl::HandleLongPressMoveEvent(const gfx::Point& touch_point) {
+  RenderWidgetHostViewEfl* rwhv =
+      static_cast<RenderWidgetHostViewEfl*>(web_contents_.GetRenderWidgetHostView());
   Clear();
   if (selection_data_->IsInEditField()) {
     Evas_Coord x, y;
-    evas_object_geometry_get(parent_view_->evas_object(), &x, &y, 0, 0);
-    parent_view_->MoveCaret(gfx::Point(touch_point.x() - x, touch_point.y() - y));
+    evas_object_geometry_get(parent_view_, &x, &y, 0, 0);
+    if (rwhv)
+      rwhv->MoveCaret(gfx::Point(touch_point.x() - x, touch_point.y() - y));
     SetSelectionStatus(true);
+    SetCaretSelectionStatus(true);
   } else{
-    parent_view_->SelectClosestWord(touch_point);
+    if (rwhv)
+      rwhv->SelectClosestWord(touch_point);
   }
 }
 
 void SelectionControllerEfl::HandleLongPressEndEvent() {
+  show_only_large_handle_ = false;
   long_mouse_press_ = false;
   if (scrolling_)
     show_after_scroll_ = true;
@@ -511,9 +676,10 @@ void SelectionControllerEfl::HandleLongPressEndEvent() {
 }
 
 void SelectionControllerEfl::HandleTapEvent(
-    const gfx::Point& touch_point, Ewk_Hit_Test_Result_Context context) {
-  if (context & EWK_HIT_TEST_RESULT_CONTEXT_EDITABLE) {
-    LOG(INFO) << "DispatchPostponedGestureEvent :: EWK_HIT_TEST_RESULT_CONTEXT_EDITABLE";
+    const gfx::Point& touch_point,
+    const ViewHostMsg_HitTestAsyncReply_Params& params) {
+  if (params.isEditable) {
+    DVLOG(1) << "DispatchPostponedGestureEvent :: Editable";
     SetSelectionStatus(true);
     if (GetSelectionEditable()){
       SetCaretSelectionStatus(true);
@@ -523,12 +689,8 @@ void SelectionControllerEfl::HandleTapEvent(
       SetSelectionEditable(true);
     }
   } else {
-    if (context & EWK_HIT_TEST_RESULT_CONTEXT_DOCUMENT)
-      LOG(INFO) << __PRETTY_FUNCTION__ << " DOCUMENT";
-    if (context & EWK_HIT_TEST_RESULT_CONTEXT_TEXT)
-      LOG(INFO) << __PRETTY_FUNCTION__ << " TEXT";
-
     SetSelectionEditable(false);
+    SetCaretSelectionStatus(true);
   }
 }
 
@@ -596,7 +758,7 @@ void SelectionControllerEfl::ChangeContextMenuPosition(gfx::Point& position, int
   int handleHeight, webViewX, webViewY, webViewWidth, webViewHeight;
   gfx::Rect imeRect;
   edje_object_part_geometry_get(input_handle_->evas_object(), "handle", 0, 0, 0, &handleHeight);
-  evas_object_geometry_get(GetParentView()->evas_object(), &webViewX, &webViewY, &webViewWidth, &webViewHeight);
+  evas_object_geometry_get(GetParentView(), &webViewX, &webViewY, &webViewWidth, &webViewHeight);
   gfx::Rect viewportRect = gfx::Rect(webViewX, webViewY, webViewWidth, webViewHeight);
 
   RenderWidgetHostViewEfl* rwhv =
@@ -5,12 +5,15 @@
 #ifndef selection_controller_h
 #define selection_controller_h
 
+#include <map>
+
 #include "base/memory/scoped_ptr.h"
 #include "base/strings/string16.h"
-#include "public/ewk_hit_test.h"
-#include "selection_box_efl.h"
-#include "selection_handle_efl.h"
-#include "selection_magnifier_efl.h"
+#include "third_party/WebKit/public/web/WebInputEvent.h"
+#include "ui/base/selection/selection_box_efl.h"
+#include "ui/base/selection/selection_handle_efl.h"
+#include "ui/base/selection/selection_magnifier_efl.h"
+#include "ui/events/event_constants.h"
 #include "ui/gfx/range/range.h"
 #include "ui/gfx/geometry/rect.h"
 
 
 #include <libintl.h>
 
-class EWebView;
+struct ViewHostMsg_HitTestAsyncReply_Params;
 
 namespace content {
 class WebContents;
+class WebContentsImpl;
+class ScAsyncRequestHitTestDataCallback;
 
 // Controls the selection after long tap.
 // This handles long tap down, long tap move, long tap up.
@@ -43,14 +48,17 @@ class SelectionControllerEfl {
   };
 
  public:
-  explicit SelectionControllerEfl(EWebView* parent_view, WebContents& web_contents);
+  explicit SelectionControllerEfl(Evas_Object* parent_view, WebContents& web_contents);
+  ~SelectionControllerEfl();
 
   // Functions that handle long press, long press move and release
-  void HandleLongPressEvent(const gfx::Point& touch_point, Ewk_Hit_Test_Result_Context);
+  void HandleLongPressEvent(const gfx::Point& touch_point,
+      const ViewHostMsg_HitTestAsyncReply_Params& params);
   void HandleLongPressMoveEvent(const gfx::Point& touch_point);
   void HandleLongPressEndEvent();
 
-  void HandleTapEvent(const gfx::Point& touch_point, Ewk_Hit_Test_Result_Context);
+  void HandleTapEvent(const gfx::Point& touch_point,
+      const ViewHostMsg_HitTestAsyncReply_Params& params);
 
   // Set if selection is valid
   void SetSelectionStatus(bool enable);
@@ -78,7 +86,7 @@ class SelectionControllerEfl {
   // Clears the selection and hides context menu and handles
   void ClearSelection();
   bool ClearSelectionViaEWebView();
-  EWebView* GetParentView() { return parent_view_; }
+  Evas_Object* GetParentView() { return parent_view_; }
   void HideHandles();
   void HideHandleAndContextMenu();
   bool IsAnyHandleVisible() const;
@@ -103,9 +111,22 @@ class SelectionControllerEfl {
 
   bool GetIsSelectionVisible() const { return is_selection_visible_; }
   void SetIsSelectionVisible(const bool isVisible) { is_selection_visible_ = isVisible; }
-  void SetShowOnlyLargeHandler(const bool show_only_large_handler)
-  { show_only_large_handler_ = show_only_large_handler; }
-  bool GetShowOnlyLargeHandler() const { return show_only_large_handler_; }
+  void SetShowOnlyLargeHandle(const bool show_only_large_handle)
+  { show_only_large_handle_ = show_only_large_handle; }
+  bool GetShowOnlyLargeHandle() const { return show_only_large_handle_; }
+  void HandlePostponedGesture(int x, int y, ui::EventType type);
+  void HandleGesture(blink::WebGestureEvent& event,
+      scoped_ptr<bool>& restore_showing_large_handle_on_gesture_end,
+      bool should_restore_selection_menu);
+
+  bool AsyncRequestHitTestDataAt(int x, int y,
+      ScAsyncRequestHitTestDataCallback *cb);
+
+  bool AsyncRequestHitTestDataAtBlinkCords(int x, int y,
+      ScAsyncRequestHitTestDataCallback *cb);
+  void OnHitTestAsyncReply(const
+      ViewHostMsg_HitTestAsyncReply_Params& params,
+      int64_t request_id);
 
  private:
   void HandleLongPressEventPrivate(const gfx::Point& touch_point);
@@ -113,15 +134,16 @@ class SelectionControllerEfl {
   // TODO: This method should be renamed to ScheduleShowHandleAndContextMenuIfNeeded
   // as it now performs an asyncrhonous hit test passing the method that actually
   // updates the selection handles and context menu as a registered callback.
-  void ShowHandleAndContextMenuIfRequired(bool anchor_first = true);
-  void ShowHandleAndContextMenuIfRequired(Evas_Object*,
-      int x, int y, int mode, _Ewk_Hit_Test*, bool anchor_first);
-  static void ShowHandleAndContextMenuIfRequiredCallback(Evas_Object*,
-      int x, int y, int mode, _Ewk_Hit_Test*, void* data);
+  void ShowHandleAndContextMenuIfRequired();
+  void ShowHandleAndContextMenuIfRequired(
+      int x, int y);
 
   void Clear(bool show_after_scroll = false);
   bool IsSelectionValid(const gfx::Rect& left_rect, const gfx::Rect& right_rect);
 
+  void ShowContextMenu();
+  void CancelContextMenu(int request_id);
+
   static void EvasParentViewMoveCallback(void *data, Evas *e, Evas_Object *obj, void *event_info)
   { reinterpret_cast<SelectionControllerEfl*>(data)->OnParentParentViewMove(); }
 
@@ -131,8 +153,8 @@ class SelectionControllerEfl {
 
   void OnParentParentViewMove();
 
+  Evas_Object* parent_view_;
   // Is required to send back selction points and range extenstion co-ordinates
-  EWebView* parent_view_;
 
   // Saves state so that context menu is not displayed during extending selection
   bool mouse_press_;
@@ -177,9 +199,10 @@ class SelectionControllerEfl {
   gfx::Rect visibility_rect_;
 
   bool is_selection_visible_;
-  bool show_only_large_handler_;
+  bool show_only_large_handle_;
 
   WebContents& web_contents_;
+  std::map<int64_t, ScAsyncRequestHitTestDataCallback*> hit_test_callback_;
 };
 
 } // namespace content
@@ -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 "eweb_view.h"
-#include "selection_handle_efl.h"
-#include "selection_controller_efl.h"
-
 #include <Edje.h>
 #include <Eina.h>
 #include <Elementary.h>
 
+#include "base/trace_event/trace_event.h"
+#include "ui/base/selection/selection_handle_efl.h"
+#include "ui/base/selection/selection_controller_efl.h"
+
 namespace content {
 
 // Size of the left/right margin which causes selection handles to be rotated
@@ -119,7 +119,7 @@ void SelectionHandleEfl::OnMouseUp(void* data, Evas*, Evas_Object*, void* event_
   evas_object_event_callback_del(handle->handle_, EVAS_CALLBACK_MOUSE_MOVE, OnMouseMove);
 
   Evas_Coord x, y;
-  evas_object_geometry_get(handle->controller_.GetParentView()->evas_object(), &x, &y, 0, 0);
+  evas_object_geometry_get(handle->controller_.GetParentView(), &x, &y, 0, 0);
   handle->controller_.OnMouseUp(gfx::Point(event->canvas.x - x, event->canvas.y - y));
 }
 
@@ -141,7 +141,7 @@ SelectionHandleEfl::HandleDirection SelectionHandleEfl::CalculateDirection(
   int handleHeight;
 
   edje_object_part_geometry_get(handle_, "handle", 0, 0, 0, &handleHeight);
-  evas_object_geometry_get(controller_.GetParentView()->evas_object(),
+  evas_object_geometry_get(controller_.GetParentView(),
       &x, &y, &deviceWidth, &deviceHeight);
   gfx::Point conv_point(point.x() + x, point.y() + y);
 
@@ -220,15 +220,15 @@ void SelectionHandleEfl::ChangeObjectDirection(HandleDirection direction) {
 
   switch (handle_type_) {
     case HANDLE_TYPE_LEFT:
-      evas_object_smart_callback_call(controller_.GetParentView()->evas_object(),
+      evas_object_smart_callback_call(controller_.GetParentView(),
         "selection,handle,left,direction", &direction);
       break;
     case HANDLE_TYPE_RIGHT:
-      evas_object_smart_callback_call(controller_.GetParentView()->evas_object(),
+      evas_object_smart_callback_call(controller_.GetParentView(),
         "selection,handle,right,direction", &direction);
       break;
     case HANDLE_TYPE_INPUT:
-      evas_object_smart_callback_call(controller_.GetParentView()->evas_object(),
+      evas_object_smart_callback_call(controller_.GetParentView(),
         "selection,handle,large,direction", &direction);
       break;
   }
@@ -252,7 +252,7 @@ gfx::Rect SelectionHandleEfl::GetSelectionRect() const {
 
 void SelectionHandleEfl::MoveObject(const gfx::Point& point) {
   Evas_Coord x, y;
-  evas_object_geometry_get(controller_.GetParentView()->evas_object(), &x, &y,
+  evas_object_geometry_get(controller_.GetParentView(), &x, &y,
       0, 0);
   if (handle_type_ == HANDLE_TYPE_INPUT && IsTop()) {
     evas_object_move(handle_, point.x() + x,
@@ -2,16 +2,17 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "selection_magnifier_efl.h"
+#include "ui/base/selection/selection_magnifier_efl.h"
 
 #include <Elementary.h>
 
 #include "base/path_service.h"
 #include "base/files/file_path.h"
+#include "content/browser/renderer_host/render_widget_host_view_efl.h"
 #include "content/common/paths_efl.h"
 #include "content/public/browser/browser_thread.h"
-#include "eweb_view.h"
-#include "selection_controller_efl.h"
+#include "content/public/browser/web_contents.h"
+#include "ui/base/selection/selection_controller_efl.h"
 
 namespace content {
 
@@ -19,13 +20,16 @@ namespace content {
 const int kHeightOffset = 60;
 const float kZoomScale = 0.66;
 
-SelectionMagnifierEfl::SelectionMagnifierEfl(content::SelectionControllerEfl* controller)
+SelectionMagnifierEfl::SelectionMagnifierEfl(
+    content::SelectionControllerEfl* controller,
+    content::WebContents& web_contents)
   : controller_(controller),
+    web_contents_(web_contents),
     content_image_(0),
     animator_(0),
     shown_(false) {
   Evas_Object* top_widget = static_cast<Evas_Object*>(controller->
-      GetParentView()->web_contents().GetNativeView());
+      GetParentView());
 
   base::FilePath edj_dir;
   base::FilePath magnifier_edj;
@@ -53,7 +57,7 @@ SelectionMagnifierEfl::~SelectionMagnifierEfl() {
 }
 
 void SelectionMagnifierEfl::HandleLongPress(const gfx::Point& touch_point) {
-  evas_object_event_callback_add(controller_->GetParentView()->evas_object(),
+  evas_object_event_callback_add(controller_->GetParentView(),
                                  EVAS_CALLBACK_MOUSE_UP,
                                  OnAnimatorUp,
                                  this);
@@ -71,7 +75,7 @@ void SelectionMagnifierEfl::DestroyAnimator() {
     animator_ = 0;
   }
 
-  evas_object_event_callback_del(controller_->GetParentView()->evas_object(),
+  evas_object_event_callback_del(controller_->GetParentView(),
                                  EVAS_CALLBACK_MOUSE_UP,
                                  OnAnimatorUp);
 }
@@ -80,7 +84,7 @@ Eina_Bool SelectionMagnifierEfl::MoveAnimatorCallback(void* data) {
   SelectionMagnifierEfl* magnifier_data = static_cast<SelectionMagnifierEfl*>(data);
 
   Evas_Coord_Point point;
-  evas_pointer_canvas_xy_get(evas_object_evas_get(magnifier_data->controller_->GetParentView()->evas_object()),
+  evas_pointer_canvas_xy_get(evas_object_evas_get(magnifier_data->controller_->GetParentView()),
                              &point.x,
                              &point.y);
   gfx::Point display_point(point.x, point.y);
@@ -130,7 +134,7 @@ void SelectionMagnifierEfl::MagnifierGetSnapshotCb(Evas_Object* image,
 
 void SelectionMagnifierEfl::UpdateLocation(const gfx::Point& location) {
   int device_x, device_y, device_width, device_height;
-  evas_object_geometry_get(controller_->GetParentView()->evas_object(),
+  evas_object_geometry_get(controller_->GetParentView(),
                            &device_x,
                            &device_y,
                            &device_width,
@@ -165,14 +169,16 @@ void SelectionMagnifierEfl::UpdateLocation(const gfx::Point& location) {
   rect.w = content_rect.width();
   rect.h = content_rect.height();
 
+#if defined(EWK_REFACTOR)
   controller_->GetParentView()->GetSnapshotAsync(rect,
       evas_object_evas_get(controller_->GetParentView()->evas_object()),
       MagnifierGetSnapshotCb, this);
+#endif
 }
 
 void SelectionMagnifierEfl::Move(const gfx::Point& location) {
   int device_x, device_y, device_width, device_height;
-  evas_object_geometry_get(controller_->GetParentView()->evas_object(),
+  evas_object_geometry_get(controller_->GetParentView(),
                            &device_x,
                            &device_y,
                            &device_width,
@@ -197,16 +203,26 @@ void SelectionMagnifierEfl::Move(const gfx::Point& location) {
 void SelectionMagnifierEfl::Show() {
   shown_ = true;
   evas_object_show(container_);
-  controller_->GetParentView()->SmartCallback<EWebViewCallbacks::MagnifierShow>().call();
-  controller_->GetParentView()->set_magnifier(true);
+
+  RenderWidgetHostViewEfl* rwhv =
+      static_cast<RenderWidgetHostViewEfl*>(web_contents_.GetRenderWidgetHostView());
+  if (rwhv)
+    rwhv->set_magnifier(true);
+  if (controller_->GetParentView())
+    evas_object_smart_callback_call(controller_->GetParentView(), "magnifier,show", NULL);
 }
 
 void SelectionMagnifierEfl::Hide() {
   shown_ = false;
   evas_object_hide(content_image_);
   evas_object_hide(container_);
-  controller_->GetParentView()->SmartCallback<EWebViewCallbacks::MagnifierHide>().call();
-  controller_->GetParentView()->set_magnifier(false);
+
+  RenderWidgetHostViewEfl* rwhv =
+      static_cast<RenderWidgetHostViewEfl*>(web_contents_.GetRenderWidgetHostView());
+  if (rwhv)
+    rwhv->set_magnifier(false);
+  if (controller_->GetParentView())
+    evas_object_smart_callback_call(controller_->GetParentView(), "magnifier,hide", NULL);
 }
 
 }
 namespace content {
 
 class SelectionControllerEfl;
+class WebContents;
 
 class SelectionMagnifierEfl {
  public:
-  SelectionMagnifierEfl(content::SelectionControllerEfl* controller);
+  SelectionMagnifierEfl(content::SelectionControllerEfl* controller,
+      WebContents& web_contents);
   ~SelectionMagnifierEfl();
 
   void HandleLongPress(const gfx::Point& touch_point);
@@ -37,7 +39,9 @@ class SelectionMagnifierEfl {
   static void MagnifierGetSnapshotCb(Evas_Object* image, void* user_data);
 
   // Parent to send back mouse events
-  content::SelectionControllerEfl* controller_;
+  SelectionControllerEfl* controller_;
+
+  WebContents& web_contents_;
 
   // Magnifier
   Evas_Object* container_;
index f78b4a7..11bf29b 100644 (file)
@@ -91,6 +91,9 @@
       }],
 
       ['_target_name=="ui_base"', {
+        'include_dirs': [
+          '<(DEPTH)/third_party/mojo/src/',
+        ],
         'sources': [
           '<(DEPTH)/ui/base/cursor/cursor.h',
           '<(DEPTH)/ui/base/cursor/cursor.cc',
           'base/clipboard/clipboard_efl.h',
           'base/clipboard/clipboard_helper_efl.cc',
           'base/clipboard/clipboard_helper_efl.h',
+          'base/selection/selection_controller_efl.h',
+          'base/selection/selection_controller_efl.cc',
+          'base/selection/selection_handle_efl.h',
+          'base/selection/selection_handle_efl.cc',
+          'base/selection/selection_box_efl.h',
+          'base/selection/selection_box_efl.cc',
+          'base/selection/selection_magnifier_efl.h',
+          'base/selection/selection_magnifier_efl.cc',
         ],
       }],
 
index c86a377..6fe94ec 100644 (file)
 #include "content/common/paths_efl.h"
 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h"
 #include "ui/base/clipboard/clipboard.h"
+#include "ui/base/selection/selection_controller_efl.h"
 #include "private/ewk_context_menu_private.h"
 
-#include "selection_controller_efl.h"
-
 #if defined(OS_TIZEN_MOBILE)
 #include <efl_assist.h>
 #endif
@@ -234,6 +233,11 @@ bool ContextMenuControllerEfl::CreateContextMenu() {
       if (appended_item)
         _appended_item_size++;
     }
+    // Workaround
+    // Need to set "copypaste" style, to let moving handles
+    // when ctxpopup is visible
+    // http://107.108.218.239/bugzilla/show_bug.cgi?id=11613
+    elm_object_style_set(popup_, "copypaste");
   } else {
     GURL url = web_contents_.GetVisibleURL();
     std::string selected_link (url.host().c_str());
index e14c13c..78367e2 100644 (file)
       'scroll_detector.h',
       'text_encoding_map_efl.cc',
       'text_encoding_map_efl.h',
-      'selection_box_efl.cc',
-      'selection_box_efl.h',
-      'selection_controller_efl.cc',
-      'selection_controller_efl.h',
-      'selection_handle_efl.cc',
-      'selection_handle_efl.h',
-      'selection_magnifier_efl.cc',
-      'selection_magnifier_efl.h',
       'url_request_context_getter_efl.cc',
       'url_request_context_getter_efl.h',
       'web_contents_efl_delegate_ewk.cc',
index 3692a32..42ae64d 100644 (file)
@@ -284,7 +284,6 @@ void EWebView::Initialize() {
 
   InitializeContent();
 
-  selection_controller_.reset(new content::SelectionControllerEfl(this, *web_contents_.get()));
   evas_event_handler_ = new WebViewEvasEventHandler(this);
 
   scroll_detector_.reset(new ScrollDetector(this));
@@ -667,129 +666,11 @@ void EWebView::HandleTouchEvents(Ewk_Touch_Event_Type type, const Eina_List *poi
   }
 }
 
-/* FIXME: Figure out wher this code should be placed.
-void EWebView::DispatchPostponedGestureEvent(ui::GestureEvent* event) {
-  Ewk_Settings* settings = GetSettings();
-  LOG(INFO) << "DispatchPostponedGestureEvent :: " << event->details().type();
-  if (event->details().type() == ui::ET_GESTURE_LONG_PRESS) {
-    if (selection_controller_->GetSelectionEditable())
-      ClearSelection();
-
-    if (settings && settings->textSelectionEnabled()) {
-      _Ewk_Hit_Test* hit_test = RequestHitTestDataAtBlinkCoords(event->x(), event->y(), EWK_HIT_TEST_MODE_DEFAULT);
-      if (hit_test && hit_test->GetResultContext() & EWK_HIT_TEST_RESULT_CONTEXT_EDITABLE) {
-        selection_controller_->SetSelectionStatus(true);
-        selection_controller_->SetCaretSelectionStatus(true);
-        selection_controller_->SetSelectionEditable(true);
-        selection_controller_->HandleLongPressEvent(rwhv()->ConvertPointInViewPix(gfx::Point(event->x(), event->y())));
-      } else if (hit_test
-          && !(hit_test->GetResultContext() & EWK_HIT_TEST_RESULT_CONTEXT_LINK)
-          && !(hit_test->GetResultContext() & EWK_HIT_TEST_RESULT_CONTEXT_IMAGE)
-          && !(hit_test->GetResultContext() & EWK_HIT_TEST_RESULT_CONTEXT_MEDIA)
-          && hit_test->GetResultContext() & EWK_HIT_TEST_RESULT_CONTEXT_TEXT) {
-        selection_controller_->SetSelectionStatus(true);
-        selection_controller_->HandleLongPressEvent(rwhv()->ConvertPointInViewPix(gfx::Point(event->x(), event->y())));
-        LOG(INFO) << __PRETTY_FUNCTION__ << ":: link, !image, !media, text";
-      } else if (hit_test && hit_test->GetResultContext() & EWK_HIT_TEST_RESULT_CONTEXT_DOCUMENT) {
-        LOG(INFO) << __PRETTY_FUNCTION__ << ":: EWK_HIT_TEST_RESULT_CONTEXT_DOCUMENT";
-      } else if (hit_test && hit_test->GetResultContext() & EWK_HIT_TEST_RESULT_CONTEXT_IMAGE) {
-        LOG(INFO) << __PRETTY_FUNCTION__ << ":: EWK_HIT_TEST_RESULT_CONTEXT_IMAGE";
-      } else if (hit_test && hit_test->GetResultContext() & EWK_HIT_TEST_RESULT_CONTEXT_LINK) {
-        ClearSelection();
-        LOG(INFO) << __PRETTY_FUNCTION__ << ":: EWK_HIT_TEST_RESULT_CONTEXT_LINK";
-      } else {
-        LOG(INFO) << __PRETTY_FUNCTION__ << ":: hit_test = " << hit_test->GetResultContext();
-      }
-      delete hit_test;
-      rwhv()->HandleGesture(event);
-    }
-  } else if ((event->details().type() == ui::ET_GESTURE_TAP) || (event->details().type() == ui::ET_GESTURE_SHOW_PRESS))  {
-    _Ewk_Hit_Test* hit_test = RequestHitTestDataAtBlinkCoords(event->x(), event->y(), EWK_HIT_TEST_MODE_DEFAULT);
-    LOG(INFO) << __PRETTY_FUNCTION__ << " hit_test = " << hit_test;
-    if (hit_test && hit_test->GetResultContext() & EWK_HIT_TEST_RESULT_CONTEXT_EDITABLE) {
-      LOG(INFO) << "DispatchPostponedGestureEvent :: EWK_HIT_TEST_RESULT_CONTEXT_EDITABLE";
-      selection_controller_->SetSelectionStatus(true);
-      if (selection_controller_->GetSelectionEditable()) {
-        selection_controller_->HideHandles();
-        selection_controller_->SetCaretSelectionStatus(true);
-      } else
-        selection_controller_->SetSelectionEditable(true);
-    } else {
-      if (hit_test && hit_test->GetResultContext() & EWK_HIT_TEST_RESULT_CONTEXT_DOCUMENT)
-        LOG(INFO) << __PRETTY_FUNCTION__ << " DOCUMENT";
-      if (hit_test && hit_test->GetResultContext() & EWK_HIT_TEST_RESULT_CONTEXT_TEXT)
-        LOG(INFO) << __PRETTY_FUNCTION__ << " TEXT";
-
-      selection_controller_->SetSelectionEditable(false);
-      //ClearSelection();
-    }
-    delete hit_test;
-    rwhv()->HandleGesture(event);
-  } else {
-    ClearSelection();
-    rwhv()->HandleGesture(event);
-  }
-  // FIXME:As there is only single window currently, and even there are no
-  // other evas objects, adding focus in event here for display of key board.
-  //Once added build with proper apps to be removed
-  rwhv()->HandleFocusIn();
-}
-*/
-
-void EWebView::HandleLongPressGesture(int x, int y,
-                                      Ewk_Hit_Test_Mode,
-                                      _Ewk_Hit_Test* hit_test) {
-  if (!hit_test)
-    return;
-
-  selection_controller_->HandleLongPressEvent(
-      rwhv()->ConvertPointInViewPix(gfx::Point(x, y)), hit_test->GetResultContext());
-}
-
-void EWebView::HandleTapGesture(int x, int y,
-                                Ewk_Hit_Test_Mode,
-                                _Ewk_Hit_Test* hit_test) {
-  if (!hit_test)
-    return;
-
-  selection_controller_->HandleTapEvent(
-      rwhv()->ConvertPointInViewPix(gfx::Point(x, y)), hit_test->GetResultContext());
-}
-
 content::WebContentsViewEfl* EWebView::GetWebContentsViewEfl() const {
   WebContentsImpl* wc = static_cast<WebContentsImpl*>(web_contents_.get());
   return static_cast<WebContentsViewEfl*>(wc->GetView());
 }
 
-void EWebView::HandlePostponedGesture(int x, int y, ui::EventType type) {
-  LOG(INFO) << "HandlePostponedGesture :: " << type;
-  switch (type) {
-    case ui::ET_GESTURE_LONG_PRESS: {
-      selection_controller_->ClearSelectionViaEWebView();
-      if (settings_->textSelectionEnabled()) {
-        WebViewAsyncRequestHitTestDataInternalCallback* cb =
-            new WebViewAsyncRequestHitTestDataInternalCallback(x,y,
-                EWK_HIT_TEST_MODE_DEFAULT, &EWebView::HandleLongPressGesture);
-        // below call takes full ownership of cb.
-        AsyncRequestHitTestDataAtBlinkCords(x, y, EWK_HIT_TEST_MODE_DEFAULT, cb);
-      }
-      break;
-    }
-    case ui::ET_GESTURE_TAP:
-    case ui::ET_GESTURE_SHOW_PRESS: {
-      WebViewAsyncRequestHitTestDataInternalCallback* cb =
-          new WebViewAsyncRequestHitTestDataInternalCallback(x, y,
-              EWK_HIT_TEST_MODE_DEFAULT, &EWebView::HandleTapGesture);
-      // below call takes full ownership of cb.
-      AsyncRequestHitTestDataAtBlinkCords(x, y, EWK_HIT_TEST_MODE_DEFAULT, cb);
-      break;
-      }
-    default:
-      selection_controller_->ClearSelectionViaEWebView();
-      break;
-  }
-}
-
 bool EWebView::TouchEventsEnabled() const {
   return touch_events_enabled_;
 }
@@ -1210,8 +1091,7 @@ Eina_Bool EWebView::PopupMenuClose() {
 
 void EWebView::ShowContextMenu(
     const content::ContextMenuParams& params,
-    content::ContextMenuType type,
-    bool show_selection) {
+    content::ContextMenuType type) {
   // fix for context menu coordinates type: MENU_TYPE_LINK (introduced by CBGRAPHICS-235),
   // this menu is created in renderer process and it does not now anything about
   // view scaling factor and it has another calling sequence, so coordinates is not updated
@@ -1231,16 +1111,14 @@ void EWebView::ShowContextMenu(
 
   context_menu_position_ = gfx::Point(convertedParams.x, convertedParams.y);
 
-  if (!selection_controller_->IsShowingMagnifier() &&
-      selection_controller_->IsCaretSelection()) {
-    if(!context_menu_->PopulateAndShowContextMenu(convertedParams))
-      context_menu_.reset();
-    if (show_selection)
-      selection_controller_->UpdateSelectionDataAndShow(
-          selection_controller_->GetLeftRect(),
-          selection_controller_->GetRightRect(),
-          false /* unused */,
-          true);
+  if (GetSelectionController()) {
+    if (!GetSelectionController()->IsShowingMagnifier() &&
+        GetSelectionController()->IsCaretSelection()) {
+      if(!context_menu_->PopulateAndShowContextMenu(convertedParams)) {
+        context_menu_.reset();
+        GetSelectionController()->HideHandles();
+      }
+    }
   }
 }
 
@@ -1355,9 +1233,15 @@ void EWebView::QuerySelectionStyle() {
 
 void EWebView::OnQuerySelectionStyleReply(const SelectionStylePrams& params) {
   gfx::Rect left_rect, right_rect;
-  selection_controller_->GetSelectionBounds(&left_rect, &right_rect);
-  _Ewk_Text_Style style_data(params, left_rect.origin(), right_rect.bottom_right());
-  SmartCallback<EWebViewCallbacks::TextStyleState>().call(&style_data);
+  if (GetSelectionController()) {
+    GetSelectionController()->GetSelectionBounds(&left_rect, &right_rect);
+    _Ewk_Text_Style style_data(params, left_rect.origin(), right_rect.bottom_right());
+    SmartCallback<EWebViewCallbacks::TextStyleState>().call(&style_data);
+  }
+}
+
+SelectionControllerEfl* EWebView::GetSelectionController() const {
+  return GetWebContentsViewEfl()->GetSelectionController();
 }
 
 void EWebView::SelectClosestWord(const gfx::Point& touch_point) {
@@ -1382,10 +1266,12 @@ void EWebView::SelectLinkText(const gfx::Point& touch_point) {
 bool EWebView::GetSelectionRange(Eina_Rectangle* left_rect, Eina_Rectangle* right_rect) {
   if (left_rect && right_rect) {
     gfx::Rect left, right;
-    selection_controller_->GetSelectionBounds(&left, &right);
-    GetEinaRectFromGfxRect(left, left_rect);
-    GetEinaRectFromGfxRect(right, right_rect);
-    return true;
+    if (GetSelectionController()) {
+      GetSelectionController()->GetSelectionBounds(&left, &right);
+      GetEinaRectFromGfxRect(left, left_rect);
+      GetEinaRectFromGfxRect(right, right_rect);
+      return true;
+    }
   }
   return false;
 }
@@ -2312,15 +2198,15 @@ bool EWebView::HandleResize(int width, int height) {
 }
 
 bool EWebView::HandleTextSelectionDown(int x, int y) {
-  if (!selection_controller_)
+  if (!GetSelectionController())
     return false;
-  return selection_controller_->TextSelectionDown(x, y);
+  return GetSelectionController()->TextSelectionDown(x, y);
 }
 
 bool EWebView::HandleTextSelectionUp(int x, int y) {
-  if (!selection_controller_)
+  if (!GetSelectionController())
     return false;
-  return selection_controller_->TextSelectionUp(x, y);
+  return GetSelectionController()->TextSelectionUp(x, y);
 }
 
 void EWebView::SendDelayedMessages(RenderViewHost* render_view_host) {
index bbbe852..0394ea3 100644 (file)
@@ -44,7 +44,7 @@
 #include "public/ewk_view.h"
 #include "eweb_view_callbacks.h"
 #include "scroll_detector.h"
-#include "selection_controller_efl.h"
+#include "ui/base/selection/selection_controller_efl.h"
 #include "web_contents_delegate_efl.h"
 #include "context_menu_controller_efl.h"
 #include "file_chooser_controller_efl.h"
@@ -311,8 +311,7 @@ class EWebView {
   Eina_Bool PopupMenuClose();
   void ShowContextMenu(
       const content::ContextMenuParams& params,
-      content::ContextMenuType type = content::MENU_TYPE_LINK,
-      bool show_selection = true);
+      content::ContextMenuType type = content::MENU_TYPE_LINK);
   void CancelContextMenu(int request_id);
   void SetScale(double scale_factor, int x, int y);
   bool GetScrollPosition(int* x, int* y) const;
@@ -322,7 +321,7 @@ class EWebView {
       Eina_Hash* headers,
       const char* body);
 
-  content::SelectionControllerEfl* GetSelectionController() const { return selection_controller_.get(); }
+  content::SelectionControllerEfl* GetSelectionController() const;
   content::PopupControllerEfl* GetPopupController() const { return popup_controller_.get(); }
   ScrollDetector* GetScrollDetector() const { return scroll_detector_.get(); }
   void MoveCaret(const gfx::Point& point);
@@ -467,7 +466,7 @@ class EWebView {
 
   void HandleRendererProcessCrash();
   void InvokeWebProcessCrashedCallback();
-  void HandlePostponedGesture(int x, int y, ui::EventType type);
+
  private:
   void InitializeContent();
   void SendDelayedMessages(content::RenderViewHost* render_view_host);
@@ -476,10 +475,7 @@ class EWebView {
   Eina_Bool AsyncRequestHitTestDataAtBlinkCords(int x, int y,
       Ewk_Hit_Test_Mode mode,
       WebViewAsyncRequestHitTestDataCallback* cb);
-  void HandleLongPressGesture(int x, int y, Ewk_Hit_Test_Mode mode,
-      _Ewk_Hit_Test*);
-  void HandleTapGesture(int x, int y, Ewk_Hit_Test_Mode mode,
-      _Ewk_Hit_Test*);
+
   content::WebContentsViewEfl* GetWebContentsViewEfl() const;
 
 #if defined(OS_TIZEN_MOBILE) && !defined(EWK_BRINGUP)
@@ -527,7 +523,6 @@ class EWebView {
   scoped_ptr<content::ContextMenuControllerEfl> context_menu_;
   scoped_ptr<content::FileChooserControllerEfl> file_chooser_;
   scoped_ptr<content::PopupControllerEfl> popup_controller_;
-  scoped_ptr<content::SelectionControllerEfl> selection_controller_;
   base::string16 previous_text_;
   int current_find_request_id_;
   static int find_request_id_counter_;
index ac7e341..5db002a 100644 (file)
@@ -30,3 +30,7 @@ void WebContentsViewEflDelegateEwk::SetPageTitle(const base::string16& title) {
   web_view_->SmartCallback<EWebViewCallbacks::TitleChange>().
       call(base::UTF16ToUTF8(title).c_str());
 }
+
+void WebContentsViewEflDelegateEwk::CancelContextMenu(int request_id) {
+  web_view_->CancelContextMenu(request_id);
+}
index 7c49cb4..b4700c5 100644 (file)
@@ -33,6 +33,8 @@ class WebContentsViewEflDelegateEwk
 
   void SetPageTitle(const base::string16& title) override;
 
+  void CancelContextMenu(int request_id) override;
+
  private:
   EWebView* web_view_;
 };