WebViewEvasEventHandler does not rely on tizen_webview::WebView anymore
[platform/framework/web/chromium-efl.git] / tizen_src / ewk / efl_integration / selection_controller_efl.h
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.
4
5 #ifndef selection_controller_h
6 #define selection_controller_h
7
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"
16
17 #if defined(OS_TIZEN)
18 #include "vconf/vconf.h"
19 #endif
20
21 #include <libintl.h>
22
23 class EWebView;
24
25 namespace content {
26 class WebContents;
27
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 {
36
37   enum ContextMenuDirection {
38     DirectionDown = 0,
39     DirectionUp,
40     DirectionLeft,
41     DirectionRight,
42     DirectionNone,
43   };
44
45  public:
46   explicit SelectionControllerEfl(EWebView* parent_view, WebContents& web_contents);
47
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();
52
53   void HandleTapEvent(const gfx::Point& touch_point, Ewk_Hit_Test_Result_Context);
54
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;
61
62   // To update the selection string
63   void UpdateSelectionData(const base::string16& text);
64
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);
74
75   void SetCaretSelectionStatus(const bool enable);
76   bool GetCaretSelectionStatus() const;
77
78   // Clears the selection and hides context menu and handles
79   void ClearSelection();
80   bool ClearSelectionViaEWebView();
81   EWebView* GetParentView() { return parent_view_; }
82   void HideHandles();
83   void HideHandleAndContextMenu();
84   bool IsAnyHandleVisible() const;
85
86   void SetScrollStatus(const bool enable);
87   bool GetScrollStatus();
88
89   gfx::Rect GetLeftRect();
90   gfx::Rect GetRightRect();
91
92   void SetVisibilityBounds(const gfx::Rect& rect) { visibility_rect_ = rect; }
93
94   void ChangeContextMenuPosition(gfx::Point& position, int& drawDirection);
95
96   bool GetLongPressed() { return long_mouse_press_; }
97   bool IsCaretSelection() { return caret_selection_; }
98
99   bool IsShowingMagnifier();
100
101   bool TextSelectionDown(int x, int y);
102   bool TextSelectionUp(int x, int y);
103
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_; }
109
110  private:
111   void HandleLongPressEventPrivate(const gfx::Point& touch_point);
112
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);
121
122   void Clear(bool show_after_scroll = false);
123   bool IsSelectionValid(const gfx::Rect& left_rect, const gfx::Rect& right_rect);
124
125   static void EvasParentViewMoveCallback(void *data, Evas *e, Evas_Object *obj, void *event_info)
126   { reinterpret_cast<SelectionControllerEfl*>(data)->OnParentParentViewMove(); }
127
128 #if defined(OS_TIZEN)
129   static void PlatformLanguageChanged(keynode_t* keynode, void* data);
130 #endif
131
132   void OnParentParentViewMove();
133
134   // Is required to send back selction points and range extenstion co-ordinates
135   EWebView* parent_view_;
136
137   // Saves state so that context menu is not displayed during extending selection
138   bool mouse_press_;
139
140   // Saves state so that context menu is not displayed during page scrolling
141   bool scrolling_;
142
143   // Saves state of context popup menu and handlers before scroll
144   bool show_after_scroll_;
145
146   // Flag which indicates if showing handlers and popup menu was prevented due to selection
147   // behind other layer.
148   bool postponed_;
149
150   // True when new caret/selection position was sent to chromium,
151   // but no reply was received, yet
152   bool expecting_update_;
153
154   // Saves state so that handlers and context menu is not shown when seletion change event occurs.
155   bool long_mouse_press_;
156
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_;
160
161   // Saves the data that are required to draw handle and context menu
162   scoped_ptr<SelectionBoxEfl> selection_data_;
163
164   // Points to start of the selection for extending selection
165   scoped_ptr<SelectionHandleEfl> start_handle_;
166
167   // Points to the end of the selection for extending selection
168   scoped_ptr<SelectionHandleEfl> end_handle_;
169
170   // Points to the caret in edit box where cursor is present
171   scoped_ptr<SelectionHandleEfl> input_handle_;
172
173   // Points to show the contents magnified
174   scoped_ptr<SelectionMagnifierEfl> magnifier_;
175
176   // Rectangle inside of which selection handles should be visible.
177   gfx::Rect visibility_rect_;
178
179   bool is_selection_visible_;
180   bool show_only_large_handler_;
181
182   WebContents& web_contents_;
183 };
184
185 } // namespace content
186 #endif