[elm] Web now inheritable.
authorGustavo Lima Chaves <glima@profusion.mobi>
Tue, 31 Jul 2012 22:04:45 +0000 (22:04 +0000)
committerGustavo Lima Chaves <glima@profusion.mobi>
Tue, 31 Jul 2012 22:04:45 +0000 (22:04 +0000)
We still gotta find a way to use our scrolling infra with it.

SVN revision: 74668

src/lib/elm_web.c
src/lib/elm_widget_web.h [new file with mode: 0644]

index 70f64e9..0793b4e 100644 (file)
@@ -1,9 +1,11 @@
 #include <Elementary.h>
 #include "elm_priv.h"
+#include "elm_widget_web.h"
 
 // TODO:
 //  1 - easy to use zoom like elm_photocam API
-//  2 - review scrolling to match elm_scroller. Maybe in future use elm_scroller
+//  2 - review scrolling to match elm_scroller. Maybe in future use
+//  elm_interface_scroller
 
 #ifdef HAVE_ELEMENTARY_WEB
 #include <EWebKit.h>
   " Safari/419.3 " PACKAGE_NAME "/" PACKAGE_VERSION
 #endif
 
-static const char WEB_SMART_NAME[] = "elm_web";
-
-#define ELM_WEB_DATA_GET(o, sd) \
-  Elm_Web_Smart_Data * sd = evas_object_smart_data_get(o)
-
-#define ELM_WEB_DATA_GET_OR_RETURN(o, ptr)           \
-  ELM_WEB_DATA_GET(o, ptr);                          \
-  if (!ptr)                                          \
-    {                                                \
-       CRITICAL("No widget data for object %p (%s)", \
-                o, evas_object_type_get(o));         \
-       return;                                       \
-    }
-
-#define ELM_WEB_DATA_GET_OR_RETURN_VAL(o, ptr, val)  \
-  ELM_WEB_DATA_GET(o, ptr);                          \
-  if (!ptr)                                          \
-    {                                                \
-       CRITICAL("No widget data for object %p (%s)", \
-                o, evas_object_type_get(o));         \
-       return val;                                   \
-    }
-
-#define ELM_WEB_CHECK(obj)                                             \
-  if (!obj || !elm_widget_type_check((obj), WEB_SMART_NAME, __func__)) \
-    return
+EAPI const char ELM_WEB_SMART_NAME[] = "elm_web";
 
 #ifdef HAVE_ELEMENTARY_WEB
 static Ewk_View_Smart_Class _ewk_view_parent_sc =
   EWK_VIEW_SMART_CLASS_INIT_NULL;
 
-typedef struct _View_Smart_Data View_Smart_Data;
-struct _View_Smart_Data
-{
-   Ewk_View_Smart_Data base;
-   struct
-   {
-      Evas_Event_Mouse_Down event;
-      Evas_Coord            x, y;
-      unsigned int          move_count;
-      Ecore_Timer          *longpress_timer;
-      Ecore_Animator       *pan_anim;
-   } mouse;
-};
 #endif
 
-typedef struct _Elm_Web_Smart_Data Elm_Web_Smart_Data;
-struct _Elm_Web_Smart_Data
-{
-   Elm_Widget_Smart_Data base;    /* base widget smart data as
-                                   * first member obligatory, as
-                                   * we're inheriting from it */
-
-#ifdef HAVE_ELEMENTARY_WEB
-   struct
-   {
-      Elm_Web_Window_Open          window_create;
-      void                        *window_create_data;
-      Elm_Web_Dialog_Alert         alert;
-      void                        *alert_data;
-      Elm_Web_Dialog_Confirm       confirm;
-      void                        *confirm_data;
-      Elm_Web_Dialog_Prompt        prompt;
-      void                        *prompt_data;
-      Elm_Web_Dialog_File_Selector file_selector;
-      void                        *file_selector_data;
-      Elm_Web_Console_Message      console_message;
-      void                        *console_message_data;
-   } hook;
-
-   Elm_Win_Keyboard_Mode input_method;
-
-   struct
-   {
-      Elm_Web_Zoom_Mode mode;
-      float             current;
-      float             min, max;
-      Eina_Bool         no_anim;
-      Ecore_Timer      *timer;
-   } zoom;
-
-   struct
-   {
-      struct
-      {
-         int x, y;
-      } start, end;
-      Ecore_Animator *animator;
-   } bring_in;
-
-   Eina_Bool tab_propagate : 1;
-   Eina_Bool inwin_mode : 1;
-#endif
-};
-
-enum Dialog_Type
-{
-   DIALOG_ALERT,
-   DIALOG_CONFIRM,
-   DIALOG_PROMPT,
-   DIALOG_FILE_SELECTOR
-};
-
-typedef struct _Dialog_Data Dialog_Data;
-struct _Dialog_Data
-{
-   enum Dialog_Type type;
-
-   Evas_Object     *dialog;
-   Evas_Object     *box;
-   Evas_Object     *bt_ok, *bt_cancel;
-   Evas_Object     *entry;
-   Evas_Object     *file_sel;
-
-   Eina_Bool       *response;
-   char           **entry_value;
-   Eina_List      **selected_files;
-};
-
-struct _Elm_Web_Callback_Proxy_Context
-{
-   const char  *name;
-   Evas_Object *obj;
-};
-typedef struct _Elm_Web_Callback_Proxy_Context Elm_Web_Callback_Proxy_Context;
-
 static const Evas_Smart_Cb_Description _elm_web_smart_callbacks[] = {
    { "download,request", "p" },
    { "editorclient,contents,changed", "" },
@@ -183,7 +67,7 @@ static const Evas_Smart_Cb_Description _elm_web_smart_callbacks[] = {
 };
 
 EVAS_SMART_SUBCLASS_NEW
-  (WEB_SMART_NAME, _elm_web, Elm_Widget_Smart_Class, Elm_Widget_Smart_Class,
+  (ELM_WEB_SMART_NAME, _elm_web, Elm_Web_Smart_Class, Elm_Widget_Smart_Class,
   elm_widget_smart_class_get, _elm_web_smart_callbacks);
 
 #ifdef HAVE_ELEMENTARY_WEB
@@ -1303,14 +1187,31 @@ _elm_web_smart_del(Evas_Object *obj)
 }
 
 static void
-_elm_web_smart_set_user(Elm_Widget_Smart_Class *sc)
+_elm_web_smart_set_user(Elm_Web_Smart_Class *sc)
 {
-   sc->base.add = _elm_web_smart_add;
-   sc->base.del = _elm_web_smart_del;
+   ELM_WIDGET_CLASS(sc)->base.add = _elm_web_smart_add;
+   ELM_WIDGET_CLASS(sc)->base.del = _elm_web_smart_del;
+
+   ELM_WIDGET_CLASS(sc)->on_focus = _elm_web_smart_on_focus;
+   ELM_WIDGET_CLASS(sc)->theme = _elm_web_smart_theme;
+   ELM_WIDGET_CLASS(sc)->event = _elm_web_smart_event;
+}
+
+EAPI const Elm_Web_Smart_Class *
+elm_web_smart_class_get(void)
+{
+   static Elm_Web_Smart_Class _sc =
+     ELM_WEB_SMART_CLASS_INIT_NAME_VERSION(ELM_WEB_SMART_NAME);
+   static const Elm_Web_Smart_Class *class = NULL;
+   Evas_Smart_Class *esc = (Evas_Smart_Class *)&_sc;
+
+   if (class) return class;
+
+   _elm_web_smart_set(&_sc);
+   esc->callbacks = _elm_web_smart_callbacks;
+   class = &_sc;
 
-   sc->on_focus = _elm_web_smart_on_focus;
-   sc->theme = _elm_web_smart_theme;
-   sc->event = _elm_web_smart_event;
+   return class;
 }
 
 EAPI Evas_Object *
diff --git a/src/lib/elm_widget_web.h b/src/lib/elm_widget_web.h
new file mode 100644 (file)
index 0000000..a22bd59
--- /dev/null
@@ -0,0 +1,252 @@
+#ifndef ELM_WIDGET_WEB_H
+#define ELM_WIDGET_WEB_H
+
+#ifdef HAVE_ELEMENTARY_WEB
+#include <EWebKit.h>
+#endif
+
+/**
+ * @addtogroup Widget
+ * @{
+ *
+ * @section elm-web-class The Elementary Web Class
+ *
+ * Elementary, besides having the @ref Web widget, exposes its
+ * foundation -- the Elementary Web Class -- in order to create other
+ * widgets which are a web view with some more logic on top.
+ */
+
+/**
+ * @def ELM_WEB_CLASS
+ *
+ * Use this macro to cast whichever subclass of
+ * #Elm_Web_Smart_Class into it, so to access its fields.
+ *
+ * @ingroup Widget
+ */
+#define ELM_WEB_CLASS(x) ((Elm_Web_Smart_Class *) x)
+
+/**
+ * @def ELM_WEB_DATA
+ *
+ * Use this macro to cast whichever subdata of
+ * #Elm_Web_Smart_Data into it, so to access its fields.
+ *
+ * @ingroup Widget
+ */
+#define ELM_WEB_DATA(x) ((Elm_Web_Smart_Data *) x)
+
+/**
+ * @def ELM_WEB_SMART_CLASS_VERSION
+ *
+ * Current version for Elementary web @b base smart class, a value
+ * which goes to _Elm_Web_Smart_Class::version.
+ *
+ * @ingroup Widget
+ */
+#define ELM_WEB_SMART_CLASS_VERSION 1
+
+/**
+ * @def ELM_WEB_SMART_CLASS_INIT
+ *
+ * Initializer for a whole #Elm_Web_Smart_Class structure, with
+ * @c NULL values on its specific fields.
+ *
+ * @param smart_class_init initializer to use for the "base" field
+ * (#Evas_Smart_Class).
+ *
+ * @see EVAS_SMART_CLASS_INIT_NULL
+ * @see EVAS_SMART_CLASS_INIT_NAME_VERSION
+ * @see ELM_WEB_SMART_CLASS_INIT_NULL
+ * @see ELM_WEB_SMART_CLASS_INIT_NAME_VERSION
+ *
+ * @ingroup Widget
+ */
+#define ELM_WEB_SMART_CLASS_INIT(smart_class_init)                        \
+  {smart_class_init, ELM_WEB_SMART_CLASS_VERSION}
+
+/**
+ * @def ELM_WEB_SMART_CLASS_INIT_NULL
+ *
+ * Initializer to zero out a whole #Elm_Web_Smart_Class structure.
+ *
+ * @see ELM_WEB_SMART_CLASS_INIT_NAME_VERSION
+ * @see ELM_WEB_SMART_CLASS_INIT
+ *
+ * @ingroup Widget
+ */
+#define ELM_WEB_SMART_CLASS_INIT_NULL \
+  ELM_WEB_SMART_CLASS_INIT(EVAS_SMART_CLASS_INIT_NULL)
+
+/**
+ * @def ELM_WEB_SMART_CLASS_INIT_NAME_VERSION
+ *
+ * Initializer to zero out a whole #Elm_Web_Smart_Class structure and
+ * set its name and version.
+ *
+ * This is similar to #ELM_WEB_SMART_CLASS_INIT_NULL, but it will
+ * also set the version field of #Elm_Web_Smart_Class (base field)
+ * to the latest #ELM_WEB_SMART_CLASS_VERSION and name it to the
+ * specific value.
+ *
+ * It will keep a reference to the name field as a <c>"const char *"</c>,
+ * i.e., the name must be available while the structure is
+ * used (hint: static or global variable!) and must not be modified.
+ *
+ * @see ELM_WEB_SMART_CLASS_INIT_NULL
+ * @see ELM_WEB_SMART_CLASS_INIT
+ *
+ * @ingroup Widget
+ */
+#define ELM_WEB_SMART_CLASS_INIT_NAME_VERSION(name) \
+  ELM_WEB_SMART_CLASS_INIT(ELM_WIDGET_SMART_CLASS_INIT_NAME_VERSION(name))
+
+/**
+ * Elementary web base smart class. This inherits directly from
+ * #Elm_Widget_Smart_Class and is meant to build widgets extending the
+ * behavior of a web.
+ *
+ * All of the functions listed on @ref Web namespace will work for
+ * objects deriving from #Elm_Web_Smart_Class.
+ */
+typedef struct _Elm_Web_Smart_Class
+{
+   Elm_Widget_Smart_Class base;
+
+   int                    version; /**< Version of this smart class definition */
+} Elm_Web_Smart_Class;
+
+/**
+ * Base widget smart data extended with web instance data.
+ */
+typedef struct _Elm_Web_Smart_Data Elm_Web_Smart_Data;
+struct _Elm_Web_Smart_Data
+{
+   Elm_Widget_Smart_Data base;    /* base widget smart data as
+                                   * first member obligatory, as
+                                   * we're inheriting from it */
+
+#ifdef HAVE_ELEMENTARY_WEB
+   struct
+   {
+      Elm_Web_Window_Open          window_create;
+      void                        *window_create_data;
+      Elm_Web_Dialog_Alert         alert;
+      void                        *alert_data;
+      Elm_Web_Dialog_Confirm       confirm;
+      void                        *confirm_data;
+      Elm_Web_Dialog_Prompt        prompt;
+      void                        *prompt_data;
+      Elm_Web_Dialog_File_Selector file_selector;
+      void                        *file_selector_data;
+      Elm_Web_Console_Message      console_message;
+      void                        *console_message_data;
+   } hook;
+
+   Elm_Win_Keyboard_Mode input_method;
+
+   struct
+   {
+      Elm_Web_Zoom_Mode mode;
+      float             current;
+      float             min, max;
+      Eina_Bool         no_anim;
+      Ecore_Timer      *timer;
+   } zoom;
+
+   struct
+   {
+      struct
+      {
+         int x, y;
+      } start, end;
+      Ecore_Animator *animator;
+   } bring_in;
+
+   Eina_Bool tab_propagate : 1;
+   Eina_Bool inwin_mode : 1;
+#endif
+};
+
+enum Dialog_Type
+{
+   DIALOG_ALERT,
+   DIALOG_CONFIRM,
+   DIALOG_PROMPT,
+   DIALOG_FILE_SELECTOR
+};
+
+typedef struct _Dialog_Data Dialog_Data;
+struct _Dialog_Data
+{
+   enum Dialog_Type type;
+
+   Evas_Object     *dialog;
+   Evas_Object     *box;
+   Evas_Object     *bt_ok, *bt_cancel;
+   Evas_Object     *entry;
+   Evas_Object     *file_sel;
+
+   Eina_Bool       *response;
+   char           **entry_value;
+   Eina_List      **selected_files;
+};
+
+struct _Elm_Web_Callback_Proxy_Context
+{
+   const char  *name;
+   Evas_Object *obj;
+};
+typedef struct _Elm_Web_Callback_Proxy_Context Elm_Web_Callback_Proxy_Context;
+
+#ifdef HAVE_ELEMENTARY_WEB
+
+typedef struct _View_Smart_Data View_Smart_Data;
+struct _View_Smart_Data
+{
+   Ewk_View_Smart_Data base;
+   struct
+   {
+      Evas_Event_Mouse_Down event;
+      Evas_Coord            x, y;
+      unsigned int          move_count;
+      Ecore_Timer          *longpress_timer;
+      Ecore_Animator       *pan_anim;
+   } mouse;
+};
+
+#endif
+
+/**
+ * @}
+ */
+
+EAPI extern const char ELM_WEB_SMART_NAME[];
+EAPI const Elm_Web_Smart_Class *elm_web_smart_class_get(void);
+
+#define ELM_WEB_DATA_GET(o, sd) \
+  Elm_Web_Smart_Data * sd = evas_object_smart_data_get(o)
+
+#define ELM_WEB_DATA_GET_OR_RETURN(o, ptr)           \
+  ELM_WEB_DATA_GET(o, ptr);                          \
+  if (!ptr)                                          \
+    {                                                \
+       CRITICAL("No widget data for object %p (%s)", \
+                o, evas_object_type_get(o));         \
+       return;                                       \
+    }
+
+#define ELM_WEB_DATA_GET_OR_RETURN_VAL(o, ptr, val)  \
+  ELM_WEB_DATA_GET(o, ptr);                          \
+  if (!ptr)                                          \
+    {                                                \
+       CRITICAL("No widget data for object %p (%s)", \
+                o, evas_object_type_get(o));         \
+       return val;                                   \
+    }
+
+#define ELM_WEB_CHECK(obj)                                                 \
+  if (!obj || !elm_widget_type_check((obj), ELM_WEB_SMART_NAME, __func__)) \
+    return
+
+#endif