XWalk WebView patchset, README and LICENSE files.
[platform/framework/web/xwalk_webview.git] / patchset / 0011-Cleanup-example.-Call-Xlib-directly.-Add-URL-entry.patch
1 From 4de7656080a7f132dd17194362ae37e9b2e764bd Mon Sep 17 00:00:00 2001
2 From: Raphael Kubo da Costa <raphael.kubo.da.costa@intel.com>
3 Date: Tue, 30 Jul 2013 12:15:45 +0300
4 Subject: [PATCH 11/33] Cleanup example. Call Xlib directly. Add URL entry.
5
6 example: Do not enable focus highlighting.
7 Default focus highlighting works in a very silly and confusing way in
8 Elementary: it just puts a sad emoticon over the widget that has focus.
9
10 example: Do not call xwalk_view_url_set() by default.
11 Doing this would always try to load the same hard-coded URL regardless of
12 the URL passed on the command line.
13
14 Add url entry field
15
16 Call Xlib directly instead of hacking around elm_win.
17
18 Use Ecore_X and Xlib calls instead of elm_win_add(.., ELM_WIN_DOCK) and
19 ecore_x_window_reparent().
20 The previous approach was very hackish and relied on EWMH (or NetWM hints)
21 to work as expected in order to create a separate X Window that is embedded
22 into the main one we export to API users.
23 We now use ecore_x_window_new() directly and just relay events to the parent
24 X Window with XChangeWindowAttributes(), and it works much better.
25 Integration with Wayland is still a big unknown, both due to the way Wayland
26 works and the way we implement PreserveWindow in EFL.
27
28 Rename PreserveWindow::EvasWindow() to EmbeddedXWindow().
29 EvasWindow() stopped making much sense after 5da472c, so use a name that
30 better conveys what we are returning.
31 ---
32  .../renderer_host/render_widget_host_view_efl.cc   | 20 +++++-
33  efl_webview/examples/main.cc                       | 72 ++++++++++++++--------
34  ui/gfx/preserve_window_efl.cc                      | 48 +++++++--------
35  ui/gfx/preserve_window_efl.h                       |  3 +-
36  4 files changed, 88 insertions(+), 55 deletions(-)
37
38 diff --git a/content/browser/renderer_host/render_widget_host_view_efl.cc b/content/browser/renderer_host/render_widget_host_view_efl.cc
39 index 22b1967..1e12159 100644
40 --- a/content/browser/renderer_host/render_widget_host_view_efl.cc
41 +++ b/content/browser/renderer_host/render_widget_host_view_efl.cc
42 @@ -103,14 +103,32 @@ RenderWidgetHostViewEfl::~RenderWidgetHostViewEfl() {
43  }
44  
45  void RenderWidgetHostViewEfl::PreserveWindowMouseDown(Evas_Event_Mouse_Down* mouse_down) {
46 +  // The coordinates must be relative to the view, not the root window.
47 +  int view_x, view_y;
48 +  evas_object_geometry_get(preserve_window_->SmartObject(),
49 +                           &view_x, &view_y, NULL, NULL);
50 +  mouse_down->canvas.x = mouse_down->canvas.x - view_x;
51 +  mouse_down->canvas.y = mouse_down->canvas.y - view_y;
52    host_->ForwardMouseEvent(content::mouseEvent(mouse_down));
53  }
54  
55  void RenderWidgetHostViewEfl::PreserveWindowMouseUp(Evas_Event_Mouse_Up* mouse_up) {
56 +  // The coordinates must be relative to the view, not the root window.
57 +  int view_x, view_y;
58 +  evas_object_geometry_get(preserve_window_->SmartObject(),
59 +                           &view_x, &view_y, NULL, NULL);
60 +  mouse_up->canvas.x = mouse_up->canvas.x - view_x;
61 +  mouse_up->canvas.y = mouse_up->canvas.y - view_y;
62    host_->ForwardMouseEvent(content::mouseEvent(mouse_up));
63  }
64  
65  void RenderWidgetHostViewEfl::PreserveWindowMouseMove(Evas_Event_Mouse_Move* mouse_move) {
66 +  // The coordinates must be relative to the view, not the root window.
67 +  int view_x, view_y;
68 +  evas_object_geometry_get(preserve_window_->SmartObject(),
69 +                           &view_x, &view_y, NULL, NULL);
70 +  mouse_move->cur.canvas.x = mouse_move->cur.canvas.x - view_x;
71 +  mouse_move->cur.canvas.y = mouse_move->cur.canvas.y - view_y;
72    host_->ForwardMouseEvent(content::mouseEvent(mouse_move));
73  }
74  
75 @@ -187,7 +205,7 @@ void RenderWidgetHostViewEfl::InitAsChild(
76    evas_object_size_hint_weight_set(preserve_window_->SmartObject(), EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
77    elm_box_pack_end(parent_view, preserve_window_->SmartObject());
78    evas_object_show(preserve_window_->SmartObject());
79 -  compositing_surface_ = elm_win_xwindow_get(preserve_window_->EvasWindow());
80 +  compositing_surface_ = preserve_window_->EmbeddedXWindow();
81  }
82  
83  void RenderWidgetHostViewEfl::InitAsPopup(
84 diff --git a/efl_webview/examples/main.cc b/efl_webview/examples/main.cc
85 index db3a6dc..6dac4e8 100644
86 --- a/efl_webview/examples/main.cc
87 +++ b/efl_webview/examples/main.cc
88 @@ -17,40 +17,52 @@ static int window_width = 800;
89  static int window_height = 600;
90  
91  static void
92 -on_back_button_clicked(void *user_data, Evas_Object *back_button, void *event_info)
93 +on_back_button_clicked(void *user_data, Evas_Object *back_button,
94 +                       void *event_info)
95  {
96    xwalk_view_back((Evas_Object*)user_data);
97  }
98  
99  static void
100 -on_forward_button_clicked(void *user_data, Evas_Object *forward_button, void *event_info)
101 +on_forward_button_clicked(void *user_data, Evas_Object *forward_button,
102 +                          void *event_info)
103  {
104    xwalk_view_forward((Evas_Object*)user_data);
105  }
106  
107  static void
108 -on_reload_button_clicked(void *user_data,
109 -                         Evas_Object *forward_button, void *event_info)
110 +on_reload_button_clicked(void *user_data, Evas_Object *forward_button,
111 +                         void *event_info)
112  {
113    xwalk_view_reload((Evas_Object*)user_data);
114  }
115  
116 -static void window_create(int argc)
117 +static void
118 +on_url_entry_activated(void *user_data, Evas_Object *url_entry,
119 +                       void *event_info)
120  {
121 -  /* Create window */
122 -  Evas_Object* elm_window = elm_win_util_standard_add("efl-webview-window", APP_NAME);
123 +    const char* url = elm_entry_entry_get(url_entry);
124 +    xwalk_view_url_set((Evas_Object*)user_data, url);
125 +}
126 +
127 +
128 +static void window_create()
129 +{
130 +  /* Create elementary window */
131 +  Evas_Object* elm_window = elm_win_util_standard_add("efl-webview-window",
132 +                                                      APP_NAME);
133    elm_win_autodel_set(elm_window, EINA_TRUE);
134    elm_object_focus_allow_set(elm_window, EINA_TRUE);
135 -  elm_win_focus_highlight_enabled_set(elm_window, EINA_TRUE);
136  
137 -  /* Create vertical layout */
138 +  /* Create vertical layout that holds navigation bar and webview area */
139    Evas_Object* vertical_layout = elm_box_add(elm_window);
140 -  elm_box_padding_set(vertical_layout, 0, 2);
141 -  evas_object_size_hint_weight_set(vertical_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
142 +  elm_box_padding_set(vertical_layout, 0, 4);
143 +  evas_object_size_hint_weight_set(vertical_layout, EVAS_HINT_EXPAND,
144 +                                   EVAS_HINT_EXPAND);
145    elm_win_resize_object_add(elm_window, vertical_layout);
146    evas_object_show(vertical_layout);
147  
148 -  /* Create horizontal layout for top bar */
149 +  /* Create horizontal layout for navigation bar */
150    Evas_Object* horizontal_layout = elm_box_add(elm_window);
151    elm_box_horizontal_set(horizontal_layout, EINA_TRUE);
152    evas_object_size_hint_weight_set(horizontal_layout, EVAS_HINT_EXPAND, 0.0);
153 @@ -58,33 +70,42 @@ static void window_create(int argc)
154    elm_box_pack_end(vertical_layout, horizontal_layout);
155    evas_object_show(horizontal_layout);
156  
157 -  /* Create Back button */
158 +  /* Create back button */
159    Evas_Object* back_button = elm_button_add(elm_window);
160    elm_object_text_set(back_button, "BACK");
161 -  evas_object_size_hint_weight_set(back_button, 0.0, EVAS_HINT_EXPAND);
162 -  evas_object_size_hint_align_set(back_button, 0.0, 0.5);
163    elm_box_pack_end(horizontal_layout, back_button);
164    evas_object_show(back_button);
165  
166 -  /* Create Forward button */
167 +  /* Create forward button */
168    Evas_Object* forward_button = elm_button_add(elm_window);
169    elm_object_text_set(forward_button, "FORWARD");
170 -  evas_object_size_hint_weight_set(forward_button, 0.0, EVAS_HINT_EXPAND);
171 -  evas_object_size_hint_align_set(forward_button, 0.0, 0.5);
172    elm_box_pack_end(horizontal_layout, forward_button);
173    evas_object_show(forward_button);
174  
175 -  /* Create Reload button */
176 +  /* Create reload button */
177    Evas_Object* reload_button = elm_button_add(elm_window);
178    elm_object_text_set(reload_button, "RELOAD");
179 -  evas_object_size_hint_weight_set(reload_button, 0.0, EVAS_HINT_EXPAND);
180 -  evas_object_size_hint_align_set(reload_button, 0.0, 0.5);
181    elm_box_pack_end(horizontal_layout, reload_button);
182    evas_object_show(reload_button);
183  
184 +  /* Create url entry widget */
185 +  Evas_Object* url_entry = elm_entry_add(elm_window);
186 +  elm_entry_single_line_set(url_entry, EINA_TRUE);
187 +  elm_entry_scrollable_set(url_entry, EINA_TRUE);
188 +  elm_entry_cnp_mode_set(url_entry, ELM_CNP_MODE_PLAINTEXT);
189 +  elm_entry_scrollbar_policy_set(url_entry, ELM_SCROLLER_POLICY_OFF,
190 +                                 ELM_SCROLLER_POLICY_OFF);
191 +  elm_entry_text_style_user_push(url_entry, "DEFAULT='font_size=16'");
192 +  evas_object_size_hint_weight_set(url_entry, EVAS_HINT_EXPAND,
193 +                                   EVAS_HINT_EXPAND);
194 +  evas_object_size_hint_align_set(url_entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
195 +  elm_box_pack_end(horizontal_layout, url_entry);
196 +  evas_object_show(url_entry);
197 +
198    /* Create WebView */
199    Evas_Object* web_view = xwalk_view_add(elm_window);
200 -  evas_object_size_hint_weight_set(web_view, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
201 +  evas_object_size_hint_weight_set(web_view, EVAS_HINT_EXPAND,
202 +                                   EVAS_HINT_EXPAND);
203    evas_object_size_hint_align_set(web_view, EVAS_HINT_FILL, EVAS_HINT_FILL);
204    elm_box_pack_end(vertical_layout, web_view);
205    elm_object_focus_set(web_view, EINA_TRUE);
206 @@ -96,12 +117,11 @@ static void window_create(int argc)
207                                   on_forward_button_clicked, web_view);
208    evas_object_smart_callback_add(reload_button, "clicked",
209                                   on_reload_button_clicked, web_view);
210 +  evas_object_smart_callback_add(url_entry, "activated",
211 +                                 on_url_entry_activated, web_view);
212  
213    evas_object_resize(elm_window, window_width, window_height);
214    evas_object_show(elm_window);
215 -
216 -  if (argc <= 1)
217 -    xwalk_view_url_set(web_view, "http://google.com");
218  }
219  
220  int main(int argc, char *argv[])
221 @@ -114,7 +134,7 @@ int main(int argc, char *argv[])
222  
223    elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
224  
225 -  window_create(argc);
226 +  window_create();
227  
228    elm_run();
229    elm_shutdown();
230 diff --git a/ui/gfx/preserve_window_efl.cc b/ui/gfx/preserve_window_efl.cc
231 index 4601099..9c3fe3a 100644
232 --- a/ui/gfx/preserve_window_efl.cc
233 +++ b/ui/gfx/preserve_window_efl.cc
234 @@ -8,6 +8,7 @@
235  #include <Ecore_Evas.h>
236  #include <Ecore_X.h>
237  #include <Elementary.h>
238 +#include <X11/Xlib.h>
239  
240  #include "base/logging.h"
241  #include "ui/gfx/point.h"
242 @@ -51,11 +52,9 @@ const char* PreserveWindowSmartEvent(PreserveWindowSmartEventType type) {
243  }
244  
245  struct PreserveWindowData {
246 -  Evas_Object_Smart_Clipped_Data base;
247 -  Evas_Object* window_;
248 -  // FIXME (alexshalamov): It is dummy to receive input events.
249 -  // We must find proper event handling way.
250 -  Evas_Object* background_;
251 +   Evas_Object_Smart_Clipped_Data base;
252 +   Ecore_X_Window window_;
253 +   Evas_Object* background_;
254  };
255  
256  bool IsPreserveWindowEvasObject(const Evas_Object* evas_object) {
257 @@ -111,44 +110,40 @@ void evas_smart_preserve_window_smart_add(Evas_Object* o) {
258      evas_object_smart_data_set(o, smart_data);
259    }
260  
261 -  int x, y, w, h = 0;
262 -  evas_object_geometry_get(o, &x, &y, &w, &h);
263 +  smart_data->window_ = ecore_x_window_new(elm_win_xwindow_get(o), 0, 0, 1, 1);
264  
265 -  smart_data->window_ = elm_win_add(o, "preserve-window", ELM_WIN_DOCK);
266 -  evas_object_resize(smart_data->window_, w, h);
267 -  evas_object_show(smart_data->window_);
268 +  // Do not listen to any events in this new window, otherwise they will not be
269 +  // propagated to the parent X window (the one which is actually interested in
270 +  // them).
271 +  XSetWindowAttributes attributes;
272 +  attributes.event_mask = NoEventMask;
273 +  XChangeWindowAttributes(static_cast<Display*>(ecore_x_display_get()),
274 +                          smart_data->window_, CWEventMask, &attributes);
275  
276 -  Ecore_X_Window x_window = elm_win_xwindow_get(smart_data->window_);
277 -  Ecore_X_Window root_x_window = elm_win_xwindow_get(o);
278 -  ecore_x_window_reparent(x_window, root_x_window, x, y);
279 -
280 -  smart_data->background_ = evas_object_rectangle_add(evas_object_evas_get(smart_data->window_));
281 +  smart_data->background_ = evas_object_rectangle_add(evas_object_evas_get(o));
282    evas_object_color_set(smart_data->background_, 0, 0, 0, 0);
283    evas_object_size_hint_weight_set(smart_data->background_, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
284 -  elm_win_resize_object_add(smart_data->window_, smart_data->background_);
285    evas_object_focus_set(smart_data->background_, EINA_TRUE);
286    evas_smart_preserve_window_parent_sc->add(o);
287  }
288  
289  void evas_smart_preserve_window_smart_del(Evas_Object* o) {
290    PreserveWindowData* smart_data = ToSmartData(o);
291 -  Ecore_X_Window x_window = elm_win_xwindow_get(smart_data->window_);
292 -  ecore_x_window_reparent(x_window, 0 /* default root window */, 0 /* x */, 0 /* y */);
293    evas_object_del(smart_data->background_);
294 -  evas_object_del(smart_data->window_);
295 +  ecore_x_window_free(smart_data->window_);
296    evas_smart_preserve_window_parent_sc->del(o);
297  }
298  
299  void evas_smart_preserve_window_smart_show(Evas_Object* o) {
300    PreserveWindowData* smart_data = ToSmartData(o);
301 -  evas_object_show(smart_data->window_);
302 +  ecore_x_window_show(smart_data->window_);
303    evas_object_show(smart_data->background_);
304    evas_smart_preserve_window_parent_sc->show(o);
305  }
306  
307  void evas_smart_preserve_window_smart_hide(Evas_Object* o) {
308    PreserveWindowData* smart_data = ToSmartData(o);
309 -  evas_object_hide(smart_data->window_);
310 +  ecore_x_window_hide(smart_data->window_);
311    evas_object_hide(smart_data->background_);
312    evas_smart_preserve_window_parent_sc->hide(o);
313  }
314 @@ -162,9 +157,8 @@ void evas_smart_preserve_window_smart_move(Evas_Object* o,
315      return;
316  
317    PreserveWindowData* smart_data = ToSmartData(o);
318 -  Ecore_X_Window x_window = elm_win_xwindow_get(smart_data->window_);
319 -  Ecore_X_Window root_x_window = elm_win_xwindow_get(o);
320 -  ecore_x_window_reparent(x_window, root_x_window, x, y);
321 +  ecore_x_window_move(smart_data->window_, x, y);
322 +  evas_object_move(smart_data->background_, x, y);
323  
324    int position[2] = {x, y};
325    evas_object_smart_callback_call(
326 @@ -183,7 +177,8 @@ void evas_smart_preserve_window_smart_resize(Evas_Object* o,
327      return;
328  
329    PreserveWindowData* smart_data = ToSmartData(o);
330 -  evas_object_resize(smart_data->window_, w, h);
331 +  ecore_x_window_resize(smart_data->window_, w, h);
332 +  evas_object_resize(smart_data->background_, w, h);
333  
334    int size[2] = {w, h};
335    evas_object_smart_callback_call(
336 @@ -412,8 +407,7 @@ PreserveWindow::~PreserveWindow() {
337    evas_object_del(smart_object_);
338  }
339  
340 -
341 -Evas_Object* PreserveWindow::EvasWindow() {
342 +gfx::PluginWindowHandle PreserveWindow::EmbeddedXWindow() {
343    PreserveWindowData* smart_data = ToSmartData(smart_object_);
344    return smart_data->window_;
345  }
346 diff --git a/ui/gfx/preserve_window_efl.h b/ui/gfx/preserve_window_efl.h
347 index 56a0b78..1097072 100644
348 --- a/ui/gfx/preserve_window_efl.h
349 +++ b/ui/gfx/preserve_window_efl.h
350 @@ -11,6 +11,7 @@
351  #include "base/memory/scoped_ptr.h"
352  #include "ui/base/ui_export.h"
353  #include "ui/gfx/preserve_window_delegate_efl.h"
354 +#include "ui/gfx/native_widget_types.h"
355  
356  namespace gfx {
357  
358 @@ -21,7 +22,7 @@ class UI_EXPORT PreserveWindow {
359    ~PreserveWindow();
360  
361    Evas_Object* SmartObject() const { return smart_object_; }
362 -  Evas_Object* EvasWindow();
363 +  PluginWindowHandle EmbeddedXWindow();
364  
365   private:
366    PreserveWindow(PreserveWindowDelegate*, Evas*);
367 -- 
368 1.8.1.2
369