1 // Copyright 2013 Samsung Electronics. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef selection_controller_h
6 #define selection_controller_h
8 #include "base/memory/scoped_ptr.h"
9 #include "base/strings/string16.h"
10 #include "public/ewk_hit_test.h"
11 #include "selection_box_efl.h"
12 #include "selection_handle_efl.h"
13 #include "selection_magnifier_efl.h"
14 #include "ui/gfx/range/range.h"
15 #include "ui/gfx/geometry/rect.h"
18 #include "vconf/vconf.h"
28 // Controls the selection after long tap.
29 // This handles long tap down, long tap move, long tap up.
30 // On long tap down touch point is sent to engine by SendGestureEvent and magnifier is shown.
31 // On long tap move touch events are sent to engine by SelectClosestWord and magnifier is shown.
32 // On long tap up selection handlers are shown and context menu event is sent.
33 // Hnadlers are shown to extent selection, On handler move touch points are sent to engine
34 // by SelectRange to extend the selection
35 class SelectionControllerEfl {
37 enum ContextMenuDirection {
46 explicit SelectionControllerEfl(EWebView* parent_view, WebContents& web_contents);
48 // Functions that handle long press, long press move and release
49 void HandleLongPressEvent(const gfx::Point& touch_point, Ewk_Hit_Test_Result_Context);
50 void HandleLongPressMoveEvent(const gfx::Point& touch_point);
51 void HandleLongPressEndEvent();
53 void HandleTapEvent(const gfx::Point& touch_point, Ewk_Hit_Test_Result_Context);
55 // Set if selection is valid
56 void SetSelectionStatus(bool enable);
57 bool GetSelectionStatus() const;
58 // Set if selection is in edit field
59 void SetSelectionEditable(bool enable);
60 bool GetSelectionEditable() const;
62 // To update the selection string
63 void UpdateSelectionData(const base::string16& text);
65 // To update the selection bounds
66 // returns false if rects are invalid, otherwise true
67 bool UpdateSelectionDataAndShow(const gfx::Rect& left_rect,
68 const gfx::Rect& right_rect, bool is_anchor_first, bool show = true);
69 void GetSelectionBounds(gfx::Rect* left, gfx::Rect* right);
70 // Handles the mouse press,move and relase events on selection handles
71 void OnMouseDown(const gfx::Point& touch_point, SelectionHandleEfl::HandleType);
72 void OnMouseMove(const gfx::Point& touch_point, SelectionHandleEfl::HandleType);
73 void OnMouseUp(const gfx::Point& touch_point);
75 void SetCaretSelectionStatus(const bool enable);
76 bool GetCaretSelectionStatus() const;
78 // Clears the selection and hides context menu and handles
79 void ClearSelection();
80 bool ClearSelectionViaEWebView();
81 EWebView* GetParentView() { return parent_view_; }
83 void HideHandleAndContextMenu();
84 bool IsAnyHandleVisible() const;
86 void SetScrollStatus(const bool enable);
87 bool GetScrollStatus();
89 gfx::Rect GetLeftRect();
90 gfx::Rect GetRightRect();
92 void SetVisibilityBounds(const gfx::Rect& rect) { visibility_rect_ = rect; }
94 void ChangeContextMenuPosition(gfx::Point& position, int& drawDirection);
96 bool GetLongPressed() { return long_mouse_press_; }
97 bool IsCaretSelection() { return caret_selection_; }
99 bool IsShowingMagnifier();
101 bool TextSelectionDown(int x, int y);
102 bool TextSelectionUp(int x, int y);
104 bool GetIsSelectionVisible() const { return is_selection_visible_; }
105 void SetIsSelectionVisible(const bool isVisible) { is_selection_visible_ = isVisible; }
106 void SetShowOnlyLargeHandler(const bool show_only_large_handler)
107 { show_only_large_handler_ = show_only_large_handler; }
108 bool GetShowOnlyLargeHandler() const { return show_only_large_handler_; }
111 void HandleLongPressEventPrivate(const gfx::Point& touch_point);
113 // TODO: This method should be renamed to ScheduleShowHandleAndContextMenuIfNeeded
114 // as it now performs an asyncrhonous hit test passing the method that actually
115 // updates the selection handles and context menu as a registered callback.
116 void ShowHandleAndContextMenuIfRequired(bool anchor_first = true);
117 void ShowHandleAndContextMenuIfRequired(Evas_Object*,
118 int x, int y, int mode, _Ewk_Hit_Test*, bool anchor_first);
119 static void ShowHandleAndContextMenuIfRequiredCallback(Evas_Object*,
120 int x, int y, int mode, _Ewk_Hit_Test*, void* data);
122 void Clear(bool show_after_scroll = false);
123 bool IsSelectionValid(const gfx::Rect& left_rect, const gfx::Rect& right_rect);
125 static void EvasParentViewMoveCallback(void *data, Evas *e, Evas_Object *obj, void *event_info)
126 { reinterpret_cast<SelectionControllerEfl*>(data)->OnParentParentViewMove(); }
128 #if defined(OS_TIZEN)
129 static void PlatformLanguageChanged(keynode_t* keynode, void* data);
132 void OnParentParentViewMove();
134 // Is required to send back selction points and range extenstion co-ordinates
135 EWebView* parent_view_;
137 // Saves state so that context menu is not displayed during extending selection
140 // Saves state so that context menu is not displayed during page scrolling
143 // Saves state of context popup menu and handlers before scroll
144 bool show_after_scroll_;
146 // Flag which indicates if showing handlers and popup menu was prevented due to selection
147 // behind other layer.
150 // True when new caret/selection position was sent to chromium,
151 // but no reply was received, yet
152 bool expecting_update_;
154 // Saves state so that handlers and context menu is not shown when seletion change event occurs.
155 bool long_mouse_press_;
157 // Saves state so that magnifier and context menu is not shown when
158 // long pressing should work like tap, e.g. press into editable field
159 bool caret_selection_;
161 // Saves the data that are required to draw handle and context menu
162 scoped_ptr<SelectionBoxEfl> selection_data_;
164 // Points to start of the selection for extending selection
165 scoped_ptr<SelectionHandleEfl> start_handle_;
167 // Points to the end of the selection for extending selection
168 scoped_ptr<SelectionHandleEfl> end_handle_;
170 // Points to the caret in edit box where cursor is present
171 scoped_ptr<SelectionHandleEfl> input_handle_;
173 // Points to show the contents magnified
174 scoped_ptr<SelectionMagnifierEfl> magnifier_;
176 // Rectangle inside of which selection handles should be visible.
177 gfx::Rect visibility_rect_;
179 bool is_selection_visible_;
180 bool show_only_large_handler_;
182 WebContents& web_contents_;
185 } // namespace content