summaryrefslogtreecommitdiff
path: root/efl/elementary/efl.elementary_web.pxi
blob: bdd1c62fd5efaf7f78544e179c0c315a2b0223e2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# Copyright (c) 2012 Joost Albers
# Copyright (c) 2012 Gustavo Sverzut Barbieri <barbieri@profusion.mobi>
#
# This file is part of python-elementary.
#
# python-elementary is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# python-elementary is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with python-elementary.  If not, see <http://www.gnu.org/licenses/>.
#

def _web_double_conv(long addr):
    cdef double *info = <double *>addr
    if info == NULL:
        return None
    return info[0]

def _web_load_frame_error_conv(long addr):
    cdef Elm_Web_Frame_Load_Error *err = <Elm_Web_Frame_Load_Error *>addr
    if err == NULL:
        return None
    ret = {
        "code": err.code,
        "is_cancellation": bool(err.is_cancellation),
        }
    if err.domain:
        ret["domain"] = err.domain
    else:
        ret["domain"] = None

    if err.description:
        ret["description"] = err.description
    else:
        ret["description"] = None

    if err.failing_url:
        ret["failing_url"] = err.failing_url
    else:
        ret["failing_url"] = None

    if err.frame:
        ret["frame"] = object_from_instance(err.frame)
    else:
        ret["frame"] = None

    return ret


def _web_link_hover_in_conv(long addr):
    cdef char **info = <char **>addr
    if info == NULL:
        url = title = None
    else:
        if info[0] == NULL:
           url = None
        else:
           url = info[0]

        if info[1] == NULL:
           title = None
        else:
           title = info[1]
    return (url, title)


cdef void _web_console_message_hook(void *data, Evas_Object *obj, const_char_ptr message, unsigned int line_number, const_char_ptr source_id) with gil:
    cdef Web self = <Web>data

    if message == NULL:
        m = None
    else:
        m = message

    if source_id == NULL:
        s = None
    else:
        s = source_id

    try:
        self._console_message_hook(self, m, line_number, s)
    except Exception, e:
        traceback.print_exc()


cdef class Web(Object):
    cdef object _console_message_hook

    def __init__(self,evasObject parent):
#         Object.__init__(self, parent.evas)
        self._set_obj(elm_web_add(parent.obj))

    # XXX TODO: complete all callbacks from elm_web.h
    def callback_uri_changed_add(self, func, *args, **kwargs):
        self._callback_add_full("uri,changed", _cb_string_conv,
                                func, *args, **kwargs)

    def callback_uri_changed_del(self, func):
        self._callback_del_full("uri,changed", _cb_string_conv, func)

    def callback_title_changed_add(self, func, *args, **kwargs):
        self._callback_add_full("title,changed", _cb_string_conv,
                                func, *args, **kwargs)

    def callback_title_changed_del(self, func):
        self._callback_del_full("title,changed", _cb_string_conv, func)

    def callback_link_hover_in_add(self, func, *args, **kwargs):
        self._callback_add_full("link,hover,in", _web_link_hover_in_conv,
                                func, *args, **kwargs)

    def callback_link_hover_in_del(self, func):
        self._callback_del_full("link,hover,in", _web_link_hover_in_conv, func)

    def callback_link_hover_out_add(self, func, *args, **kwargs):
        self._callback_add("link,hover,out", func, *args, **kwargs)

    def callback_link_hover_out_del(self, func):
        self._callback_del("link,hover,out", func)

    def callback_load_error_add(self, func, *args, **kwargs):
        self._callback_add_full("load,error", _web_load_frame_error_conv,
                                func, *args, **kwargs)

    def callback_load_error_del(self, func):
        self._callback_del_full("load,error", _web_load_frame_error_conv, func)

    def callback_load_finished_add(self, func, *args, **kwargs):
        self._callback_add_full("load,finished", _web_load_frame_error_conv,
                                func, *args, **kwargs)

    def callback_load_finished_del(self, func):
        self._callback_del_full("load,finished",
                                _web_load_frame_error_conv, func)

    def callback_load_progress_add(self, func, *args, **kwargs):
        self._callback_add_full("load,progress", _web_double_conv,
                                func, *args, **kwargs)

    def callback_load_progress_del(self, func):
        self._callback_del_full("load,progress", _web_double_conv, func)

    def callback_load_provisional_add(self, func, *args, **kwargs):
        self._callback_add("load,provisional", func, *args, **kwargs)

    def callback_load_provisional_del(self, func):
        self._callback_del("load,provisional", func)

    def callback_load_started_add(self, func, *args, **kwargs):
        self._callback_add("load,started", func, *args, **kwargs)

    def callback_load_started_del(self, func):
        self._callback_del("load,started", func)

    def history_enabled_get(self):
        return bool(elm_web_history_enabled_get(self.obj))

    def webkit_view_get(self):
        cdef Evas_Object *obj = elm_web_webkit_view_get(self.obj)
        return object_from_instance(obj)

    def uri_set(self, uri):
        return bool(elm_web_uri_set(self.obj, uri))

    def uri_get(self):
        cdef const_char_ptr l
        l = elm_web_uri_get(self.obj)
        if l == NULL:
            return None
        return l

    property uri:
        def __get__(self):
            return self.uri_get()

        def __set__(self, value):
            self.uri_set(value)

    def useragent_get(self):
        cdef const_char_ptr l
        l = elm_web_useragent_get(self.obj)
        if l == NULL:
            return None
        return l

    def zoom_get(self):
        return elm_web_zoom_get(self.obj)

    def zoom_mode_get(self):
        return elm_web_zoom_mode_get(self.obj)

    def back(self):
        return bool(elm_web_back(self.obj))

    def console_message_hook_set(self, func):
        self._console_message_hook = func
        if func:
            elm_web_console_message_hook_set(self.obj,
                                             _web_console_message_hook,
                                             <void *>self)
        else:
            elm_web_console_message_hook_set(self.obj, NULL, NULL)


_object_mapping_register("elm_web", Web)