1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ |
---|
2 | /* This file is part of the GtkHTML library. |
---|
3 | |
---|
4 | Copyright (C) 2000 Helix Code, Inc. |
---|
5 | |
---|
6 | This library is free software; you can redistribute it and/or |
---|
7 | modify it under the terms of the GNU Library General Public |
---|
8 | License as published by the Free Software Foundation; either |
---|
9 | version 2 of the License, or (at your option) any later version. |
---|
10 | |
---|
11 | This library is distributed in the hope that it will be useful, |
---|
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
14 | Library General Public License for more details. |
---|
15 | |
---|
16 | You should have received a copy of the GNU Library General Public License |
---|
17 | along with this library; see the file COPYING.LIB. If not, write to |
---|
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
---|
19 | Boston, MA 02111-1307, USA. |
---|
20 | */ |
---|
21 | |
---|
22 | #include <config.h> |
---|
23 | #include <gtk/gtk.h> |
---|
24 | #include <string.h> |
---|
25 | #include "gtkhtml.h" |
---|
26 | #include "gtkhtml-private.h" |
---|
27 | #include "gtkhtml-stream.h" |
---|
28 | #include "htmlcolorset.h" |
---|
29 | #include "htmlgdkpainter.h" |
---|
30 | #include "htmlprinter.h" |
---|
31 | #include "htmliframe.h" |
---|
32 | #include "htmlengine.h" |
---|
33 | #include "htmlengine-search.h" |
---|
34 | #include "htmlengine-save.h" |
---|
35 | #include "htmlsearch.h" |
---|
36 | #include "htmlselection.h" |
---|
37 | #include "htmlsettings.h" |
---|
38 | #include "htmltokenizer.h" |
---|
39 | #include "htmlembedded.h" |
---|
40 | |
---|
41 | |
---|
42 | HTMLIFrameClass html_iframe_class; |
---|
43 | static HTMLEmbeddedClass *parent_class = NULL; |
---|
44 | |
---|
45 | static void |
---|
46 | iframe_set_base (GtkHTML *html, const char *url, gpointer data) |
---|
47 | { |
---|
48 | char *new_url = gtk_html_get_url_base_relative (html, url); |
---|
49 | |
---|
50 | gtk_html_set_base (html, new_url); |
---|
51 | g_free (new_url); |
---|
52 | } |
---|
53 | |
---|
54 | static void |
---|
55 | iframe_url_requested (GtkHTML *html, const char *url, GtkHTMLStream *handle, gpointer data) |
---|
56 | { |
---|
57 | HTMLIFrame *iframe = HTML_IFRAME (data); |
---|
58 | GtkHTML *parent = GTK_HTML (HTML_EMBEDDED(iframe)->parent); |
---|
59 | |
---|
60 | if (!html->engine->stopped) |
---|
61 | g_signal_emit_by_name (parent->engine, "url_requested", url, handle); |
---|
62 | } |
---|
63 | |
---|
64 | static void |
---|
65 | iframe_size_changed (GtkHTML *html, gpointer data) |
---|
66 | { |
---|
67 | HTMLIFrame *iframe = HTML_IFRAME (data); |
---|
68 | GtkHTML *parent = GTK_HTML (HTML_EMBEDDED(iframe)->parent); |
---|
69 | |
---|
70 | html_engine_schedule_update (parent->engine); |
---|
71 | } |
---|
72 | |
---|
73 | static gboolean |
---|
74 | iframe_object_requested (GtkHTML *html, GtkHTMLEmbedded *eb, gpointer data) |
---|
75 | { |
---|
76 | HTMLIFrame *iframe = HTML_IFRAME (data); |
---|
77 | GtkHTML *parent = GTK_HTML (HTML_EMBEDDED(iframe)->parent); |
---|
78 | gboolean ret_val; |
---|
79 | |
---|
80 | ret_val = FALSE; |
---|
81 | g_signal_emit_by_name (parent, "object_requested", eb, &ret_val); |
---|
82 | return ret_val; |
---|
83 | } |
---|
84 | |
---|
85 | static void |
---|
86 | iframe_set_gdk_painter (HTMLIFrame *iframe, HTMLPainter *painter) |
---|
87 | { |
---|
88 | if (painter) |
---|
89 | g_object_ref (G_OBJECT (painter)); |
---|
90 | |
---|
91 | if (iframe->gdk_painter) |
---|
92 | g_object_unref (G_OBJECT (iframe->gdk_painter)); |
---|
93 | |
---|
94 | iframe->gdk_painter = painter; |
---|
95 | } |
---|
96 | |
---|
97 | HTMLObject * |
---|
98 | html_iframe_new (GtkWidget *parent, |
---|
99 | char *src, |
---|
100 | gint width, |
---|
101 | gint height, |
---|
102 | gboolean border) |
---|
103 | { |
---|
104 | HTMLIFrame *iframe; |
---|
105 | |
---|
106 | iframe = g_new (HTMLIFrame, 1); |
---|
107 | |
---|
108 | html_iframe_init (iframe, |
---|
109 | &html_iframe_class, |
---|
110 | parent, |
---|
111 | src, |
---|
112 | width, |
---|
113 | height, |
---|
114 | border); |
---|
115 | |
---|
116 | return HTML_OBJECT (iframe); |
---|
117 | } |
---|
118 | |
---|
119 | static gboolean |
---|
120 | html_iframe_grab_cursor(GtkWidget *iframe, GdkEvent *event) |
---|
121 | { |
---|
122 | /* Keep the focus! Fight the power */ |
---|
123 | return TRUE; |
---|
124 | } |
---|
125 | |
---|
126 | static gint |
---|
127 | calc_min_width (HTMLObject *o, |
---|
128 | HTMLPainter *painter) |
---|
129 | { |
---|
130 | HTMLIFrame *iframe; |
---|
131 | |
---|
132 | iframe = HTML_IFRAME (o); |
---|
133 | if (iframe->width < 0) |
---|
134 | return html_engine_calc_min_width (GTK_HTML (HTML_IFRAME (o)->html)->engine); |
---|
135 | else |
---|
136 | return iframe->width; |
---|
137 | } |
---|
138 | |
---|
139 | static void |
---|
140 | set_max_width (HTMLObject *o, HTMLPainter *painter, gint max_width) |
---|
141 | { |
---|
142 | HTMLEngine *e = GTK_HTML (HTML_IFRAME (o)->html)->engine; |
---|
143 | |
---|
144 | if (o->max_width != max_width) { |
---|
145 | o->max_width = max_width; |
---|
146 | html_object_set_max_width (e->clue, e->painter, max_width - (html_engine_get_left_border (e) + html_engine_get_right_border (e))); |
---|
147 | } |
---|
148 | } |
---|
149 | |
---|
150 | static void |
---|
151 | reset (HTMLObject *o) |
---|
152 | { |
---|
153 | HTMLIFrame *iframe; |
---|
154 | |
---|
155 | (* HTML_OBJECT_CLASS (parent_class)->reset) (o); |
---|
156 | iframe = HTML_IFRAME (o); |
---|
157 | html_object_reset (GTK_HTML (iframe->html)->engine->clue); |
---|
158 | } |
---|
159 | |
---|
160 | /* FIXME rodo - draw + set_painter is not much clean now, needs refactoring */ |
---|
161 | |
---|
162 | static void |
---|
163 | draw (HTMLObject *o, |
---|
164 | HTMLPainter *p, |
---|
165 | gint x, gint y, |
---|
166 | gint width, gint height, |
---|
167 | gint tx, gint ty) |
---|
168 | { |
---|
169 | HTMLIFrame *iframe = HTML_IFRAME (o); |
---|
170 | HTMLEngine *e = GTK_HTML (iframe->html)->engine; |
---|
171 | GdkRectangle paint; |
---|
172 | |
---|
173 | if (GTK_OBJECT_TYPE (e->painter) == HTML_TYPE_PRINTER) { |
---|
174 | gint pixel_size = html_painter_get_pixel_size (e->painter); |
---|
175 | |
---|
176 | if (!html_object_intersect (o, &paint, x, y, width, height)) |
---|
177 | return; |
---|
178 | |
---|
179 | html_object_draw (e->clue, e->painter, |
---|
180 | x, y, |
---|
181 | width - pixel_size * (html_engine_get_left_border (e) + html_engine_get_right_border (e)), |
---|
182 | height - pixel_size * (html_engine_get_top_border (e) + html_engine_get_bottom_border (e)), |
---|
183 | tx + pixel_size * html_engine_get_left_border (e), ty + pixel_size * html_engine_get_top_border (e)); |
---|
184 | } else |
---|
185 | (*HTML_OBJECT_CLASS (parent_class)->draw) (o, p, x, y, width, height, tx, ty); |
---|
186 | } |
---|
187 | |
---|
188 | static void |
---|
189 | set_painter (HTMLObject *o, HTMLPainter *painter) |
---|
190 | { |
---|
191 | HTMLIFrame *iframe; |
---|
192 | |
---|
193 | iframe = HTML_IFRAME (o); |
---|
194 | if (G_OBJECT_TYPE (GTK_HTML (iframe->html)->engine->painter) != HTML_TYPE_PRINTER) { |
---|
195 | iframe_set_gdk_painter (iframe, GTK_HTML (iframe->html)->engine->painter); |
---|
196 | } |
---|
197 | |
---|
198 | html_engine_set_painter (GTK_HTML (iframe->html)->engine, |
---|
199 | G_OBJECT_TYPE (painter) != HTML_TYPE_PRINTER ? iframe->gdk_painter : painter); |
---|
200 | } |
---|
201 | |
---|
202 | static void |
---|
203 | forall (HTMLObject *self, |
---|
204 | HTMLEngine *e, |
---|
205 | HTMLObjectForallFunc func, |
---|
206 | gpointer data) |
---|
207 | { |
---|
208 | HTMLIFrame *iframe; |
---|
209 | |
---|
210 | iframe = HTML_IFRAME (self); |
---|
211 | (* func) (self, html_object_get_engine (self, e), data); |
---|
212 | html_object_forall (GTK_HTML (iframe->html)->engine->clue, html_object_get_engine (self, e), func, data); |
---|
213 | } |
---|
214 | |
---|
215 | static gint |
---|
216 | check_page_split (HTMLObject *self, HTMLPainter *p, gint y) |
---|
217 | { |
---|
218 | HTMLEngine *e = GTK_HTML (HTML_IFRAME (self)->html)->engine; |
---|
219 | int y1, y2, pixel_size = html_painter_get_pixel_size (p); |
---|
220 | |
---|
221 | y1 = self->y - self->ascent + pixel_size*html_engine_get_top_border (e); |
---|
222 | y2 = self->y + self->descent + pixel_size*html_engine_get_bottom_border (e); |
---|
223 | |
---|
224 | if (y1 > y) |
---|
225 | return 0; |
---|
226 | |
---|
227 | if (y >= y1 && y < y2) |
---|
228 | return html_object_check_page_split (e->clue, p, y - y1) + y1; |
---|
229 | |
---|
230 | return y; |
---|
231 | } |
---|
232 | |
---|
233 | static void |
---|
234 | copy (HTMLObject *self, |
---|
235 | HTMLObject *dest) |
---|
236 | { |
---|
237 | HTMLIFrame *s = HTML_IFRAME (self); |
---|
238 | HTMLIFrame *d = HTML_IFRAME (dest); |
---|
239 | |
---|
240 | (* HTML_OBJECT_CLASS (parent_class)->copy) (self, dest); |
---|
241 | /* |
---|
242 | html_iframe_init (d, &html_iframe_class, |
---|
243 | HTML_EMBEDDED (dest)->parent, |
---|
244 | s->url, |
---|
245 | s->width, |
---|
246 | s->height, |
---|
247 | s->frameborder); |
---|
248 | */ |
---|
249 | d->scroll = s->scroll; |
---|
250 | d->html = gtk_html_new (); |
---|
251 | |
---|
252 | d->gdk_painter = NULL; |
---|
253 | |
---|
254 | d->url = g_strdup (s->url); |
---|
255 | d->width = s->width; |
---|
256 | d->height = s->height; |
---|
257 | d->frameborder = s->frameborder; |
---|
258 | } |
---|
259 | |
---|
260 | static HTMLObject * |
---|
261 | op_copy (HTMLObject *self, HTMLObject *parent, HTMLEngine *e, GList *from, GList *to, guint *len) |
---|
262 | { |
---|
263 | HTMLObject *dup, *clue; |
---|
264 | GtkHTML *html; |
---|
265 | |
---|
266 | dup = html_object_dup (self); |
---|
267 | html = GTK_HTML (HTML_IFRAME (dup)->html); |
---|
268 | clue = GTK_HTML (HTML_IFRAME (self)->html)->engine->clue; |
---|
269 | GTK_HTML (HTML_IFRAME (dup)->html)->engine->clue = |
---|
270 | html_object_op_copy (clue, dup, GTK_HTML (HTML_IFRAME (self)->html)->engine, |
---|
271 | html_object_get_bound_list (clue, from), |
---|
272 | html_object_get_bound_list (clue, to), len); |
---|
273 | GTK_HTML (HTML_IFRAME (dup)->html)->engine->clue->parent = parent; |
---|
274 | |
---|
275 | return dup; |
---|
276 | } |
---|
277 | |
---|
278 | void |
---|
279 | html_iframe_set_margin_width (HTMLIFrame *iframe, gint margin_width) |
---|
280 | { |
---|
281 | HTMLEngine *e; |
---|
282 | |
---|
283 | e = GTK_HTML (iframe->html)->engine; |
---|
284 | |
---|
285 | e->leftBorder = e->rightBorder = margin_width; |
---|
286 | html_engine_schedule_redraw (e); |
---|
287 | } |
---|
288 | |
---|
289 | void |
---|
290 | html_iframe_set_margin_height (HTMLIFrame *iframe, gint margin_height) |
---|
291 | { |
---|
292 | HTMLEngine *e; |
---|
293 | |
---|
294 | e = GTK_HTML (iframe->html)->engine; |
---|
295 | |
---|
296 | e->bottomBorder = e->topBorder = margin_height; |
---|
297 | html_engine_schedule_redraw (e); |
---|
298 | } |
---|
299 | |
---|
300 | void |
---|
301 | html_iframe_set_scrolling (HTMLIFrame *iframe, GtkPolicyType scroll) |
---|
302 | { |
---|
303 | gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (iframe->scroll), |
---|
304 | scroll, scroll); |
---|
305 | } |
---|
306 | |
---|
307 | static gboolean |
---|
308 | html_iframe_real_calc_size (HTMLObject *o, HTMLPainter *painter, GList **changed_objs) |
---|
309 | { |
---|
310 | HTMLIFrame *iframe; |
---|
311 | HTMLEngine *e; |
---|
312 | gint old_width, old_ascent, old_descent; |
---|
313 | |
---|
314 | old_width = o->width; |
---|
315 | old_ascent = o->ascent; |
---|
316 | old_descent = o->descent; |
---|
317 | |
---|
318 | iframe = HTML_IFRAME (o); |
---|
319 | e = GTK_HTML (iframe->html)->engine; |
---|
320 | |
---|
321 | if (HTML_EMBEDDED (o)->widget == NULL) |
---|
322 | return TRUE; |
---|
323 | |
---|
324 | if ((iframe->width < 0) && (iframe->height < 0)) { |
---|
325 | if (e->clue) { |
---|
326 | html_engine_calc_size (e, changed_objs); |
---|
327 | e->width = html_engine_get_doc_width (e); |
---|
328 | e->height = html_engine_get_doc_height (e); |
---|
329 | } |
---|
330 | html_iframe_set_scrolling (iframe, GTK_POLICY_NEVER); |
---|
331 | |
---|
332 | o->width = e->width; |
---|
333 | o->ascent = e->height; |
---|
334 | o->descent = 0; |
---|
335 | } else |
---|
336 | return (* HTML_OBJECT_CLASS (parent_class)->calc_size) (o, painter, changed_objs); |
---|
337 | |
---|
338 | if (o->descent != old_descent |
---|
339 | || o->ascent != old_ascent |
---|
340 | || o->width != old_width) |
---|
341 | return TRUE; |
---|
342 | |
---|
343 | return FALSE; |
---|
344 | } |
---|
345 | |
---|
346 | static gboolean |
---|
347 | search (HTMLObject *self, HTMLSearch *info) |
---|
348 | { |
---|
349 | HTMLEngine *e = GTK_HTML (HTML_IFRAME (self)->html)->engine; |
---|
350 | |
---|
351 | /* printf ("search\n"); */ |
---|
352 | |
---|
353 | /* search_next? */ |
---|
354 | if (info->stack && HTML_OBJECT (info->stack->data) == e->clue) { |
---|
355 | /* printf ("next\n"); */ |
---|
356 | info->engine = GTK_HTML (GTK_HTML (HTML_IFRAME (self)->html)->iframe_parent)->engine; |
---|
357 | html_search_pop (info); |
---|
358 | html_engine_unselect_all (e); |
---|
359 | return html_search_next_parent (info); |
---|
360 | } |
---|
361 | |
---|
362 | info->engine = e; |
---|
363 | html_search_push (info, e->clue); |
---|
364 | if (html_object_search (e->clue, info)) |
---|
365 | return TRUE; |
---|
366 | html_search_pop (info); |
---|
367 | |
---|
368 | info->engine = GTK_HTML (GTK_HTML (HTML_IFRAME (self)->html)->iframe_parent)->engine; |
---|
369 | /* printf ("FALSE\n"); */ |
---|
370 | |
---|
371 | return FALSE; |
---|
372 | } |
---|
373 | |
---|
374 | static HTMLObject * |
---|
375 | head (HTMLObject *self) |
---|
376 | { |
---|
377 | return GTK_HTML (HTML_IFRAME (self)->html)->engine->clue; |
---|
378 | } |
---|
379 | |
---|
380 | static HTMLObject * |
---|
381 | tail (HTMLObject *self) |
---|
382 | { |
---|
383 | return GTK_HTML (HTML_IFRAME (self)->html)->engine->clue; |
---|
384 | } |
---|
385 | |
---|
386 | static HTMLEngine * |
---|
387 | get_engine (HTMLObject *self, HTMLEngine *e) |
---|
388 | { |
---|
389 | return GTK_HTML (HTML_IFRAME (self)->html)->engine; |
---|
390 | } |
---|
391 | |
---|
392 | static HTMLObject* |
---|
393 | check_point (HTMLObject *self, |
---|
394 | HTMLPainter *painter, |
---|
395 | gint x, gint y, |
---|
396 | guint *offset_return, |
---|
397 | gboolean for_cursor) |
---|
398 | { |
---|
399 | HTMLEngine *e = GTK_HTML (HTML_IFRAME (self)->html)->engine; |
---|
400 | |
---|
401 | if (x < self->x || x >= self->x + self->width |
---|
402 | || y >= self->y + self->descent || y < self->y - self->ascent) |
---|
403 | return NULL; |
---|
404 | |
---|
405 | x -= self->x - e->x_offset; |
---|
406 | y -= self->y - self->ascent - e->y_offset; |
---|
407 | |
---|
408 | return html_engine_get_object_at (e, x, y, offset_return, for_cursor); |
---|
409 | } |
---|
410 | |
---|
411 | static gboolean |
---|
412 | is_container (HTMLObject *self) |
---|
413 | { |
---|
414 | return TRUE; |
---|
415 | } |
---|
416 | |
---|
417 | static void |
---|
418 | append_selection_string (HTMLObject *self, |
---|
419 | GString *buffer) |
---|
420 | { |
---|
421 | html_object_append_selection_string (GTK_HTML (HTML_IFRAME (self)->html)->engine->clue, buffer); |
---|
422 | } |
---|
423 | |
---|
424 | static void |
---|
425 | reparent (HTMLEmbedded *emb, GtkWidget *html) |
---|
426 | { |
---|
427 | HTMLIFrame *iframe = HTML_IFRAME (emb); |
---|
428 | |
---|
429 | gtk_html_set_iframe_parent (GTK_HTML (iframe->html), |
---|
430 | html, |
---|
431 | GTK_HTML (iframe->html)->frame); |
---|
432 | (* HTML_EMBEDDED_CLASS (parent_class)->reparent) (emb, html); |
---|
433 | } |
---|
434 | |
---|
435 | /* static gboolean |
---|
436 | select_range (HTMLObject *self, |
---|
437 | HTMLEngine *engine, |
---|
438 | guint start, |
---|
439 | gint length, |
---|
440 | gboolean queue_draw) |
---|
441 | { |
---|
442 | return html_object_select_range (GTK_HTML (HTML_IFRAME (self)->html)->engine->clue, |
---|
443 | GTK_HTML (HTML_IFRAME (self)->html)->engine, |
---|
444 | start, length, queue_draw); |
---|
445 | } */ |
---|
446 | |
---|
447 | static gboolean |
---|
448 | save (HTMLObject *s, |
---|
449 | HTMLEngineSaveState *state) |
---|
450 | { |
---|
451 | HTMLIFrame *iframe = HTML_IFRAME (s); |
---|
452 | HTMLEngineSaveState *buffer; |
---|
453 | HTMLEngine *e; |
---|
454 | |
---|
455 | e = GTK_HTML (iframe->html)->engine; |
---|
456 | |
---|
457 | /* |
---|
458 | * FIXME: we should actually save the iframe definition if inline_frames is not |
---|
459 | * set, but that is a feature and not critical for release. We should also probably |
---|
460 | * wrap the body in a <table> tag with a bg etc. |
---|
461 | */ |
---|
462 | if (state->inline_frames && e->clue) { |
---|
463 | buffer = html_engine_save_buffer_new (e, state->inline_frames); |
---|
464 | html_object_save (e->clue, buffer); |
---|
465 | |
---|
466 | if (state->error || |
---|
467 | !html_engine_save_output_buffer (state, |
---|
468 | html_engine_save_buffer_peek_text (buffer), |
---|
469 | html_engine_save_buffer_peek_text_bytes (buffer))) { |
---|
470 | html_engine_save_buffer_free (buffer); |
---|
471 | return FALSE; |
---|
472 | } |
---|
473 | html_engine_save_buffer_free (buffer); |
---|
474 | } else { |
---|
475 | HTMLEngine *e = GTK_HTML (iframe->html)->engine; |
---|
476 | |
---|
477 | if (!html_engine_save_output_string (state, "<IFRAME SRC=\"%s\"", iframe->url)) |
---|
478 | return FALSE; |
---|
479 | |
---|
480 | if (iframe->width >= 0) |
---|
481 | if (!html_engine_save_output_string (state, " WIDTH=\"%d\"", iframe->width)) |
---|
482 | return FALSE; |
---|
483 | |
---|
484 | if (iframe->width >= 0) |
---|
485 | if (!html_engine_save_output_string (state, " WIDTH=\"%d\"", iframe->width)) |
---|
486 | return FALSE; |
---|
487 | |
---|
488 | if (e->topBorder != TOP_BORDER || e->bottomBorder != BOTTOM_BORDER) |
---|
489 | if (!html_engine_save_output_string (state, " MARGINHEIGHT=\"%d\"", e->topBorder)) |
---|
490 | return FALSE; |
---|
491 | |
---|
492 | if (e->leftBorder != LEFT_BORDER || e->rightBorder != RIGHT_BORDER) |
---|
493 | if (!html_engine_save_output_string (state, " MARGINWIDTH=\"%d\"", e->leftBorder)) |
---|
494 | return FALSE; |
---|
495 | |
---|
496 | if (!html_engine_save_output_string (state, " FRAMEBORDER=\"%d\"", iframe->frameborder)) |
---|
497 | return FALSE; |
---|
498 | |
---|
499 | if (!html_engine_save_output_string (state, "></IFRAME>")) |
---|
500 | return FALSE; |
---|
501 | } |
---|
502 | return TRUE; |
---|
503 | } |
---|
504 | |
---|
505 | static gboolean |
---|
506 | save_plain (HTMLObject *s, |
---|
507 | HTMLEngineSaveState *state, |
---|
508 | gint requested_width) |
---|
509 | { |
---|
510 | HTMLIFrame *iframe = HTML_IFRAME (s); |
---|
511 | HTMLEngineSaveState *buffer; |
---|
512 | HTMLEngine *e; |
---|
513 | |
---|
514 | e = GTK_HTML (iframe->html)->engine; |
---|
515 | |
---|
516 | if (state->inline_frames && e->clue) { |
---|
517 | buffer = html_engine_save_buffer_new (e, state->inline_frames); |
---|
518 | html_object_save_plain (e->clue, buffer, requested_width); |
---|
519 | if (state->error || |
---|
520 | !html_engine_save_output_buffer (state, |
---|
521 | html_engine_save_buffer_peek_text (buffer), |
---|
522 | html_engine_save_buffer_peek_text_bytes (buffer))) { |
---|
523 | html_engine_save_buffer_free (buffer); |
---|
524 | return FALSE; |
---|
525 | } |
---|
526 | html_engine_save_buffer_free (buffer); |
---|
527 | } |
---|
528 | |
---|
529 | return TRUE; |
---|
530 | } |
---|
531 | |
---|
532 | static void |
---|
533 | destroy (HTMLObject *o) |
---|
534 | { |
---|
535 | HTMLIFrame *iframe = HTML_IFRAME (o); |
---|
536 | |
---|
537 | iframe_set_gdk_painter (iframe, NULL); |
---|
538 | |
---|
539 | g_free (iframe->url); |
---|
540 | |
---|
541 | if (iframe->html) { |
---|
542 | g_signal_handlers_disconnect_matched (iframe->html, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, o); |
---|
543 | iframe->html = NULL; |
---|
544 | } |
---|
545 | |
---|
546 | HTML_OBJECT_CLASS (parent_class)->destroy (o); |
---|
547 | } |
---|
548 | |
---|
549 | void |
---|
550 | html_iframe_init (HTMLIFrame *iframe, |
---|
551 | HTMLIFrameClass *klass, |
---|
552 | GtkWidget *parent, |
---|
553 | char *src, |
---|
554 | gint width, |
---|
555 | gint height, |
---|
556 | gboolean border) |
---|
557 | { |
---|
558 | HTMLEmbedded *em = HTML_EMBEDDED (iframe); |
---|
559 | HTMLTokenizer *new_tokenizer; |
---|
560 | GtkWidget *new_widget; |
---|
561 | GtkHTML *new_html; |
---|
562 | GtkHTML *parent_html; |
---|
563 | GtkWidget *scrolled_window; |
---|
564 | gint depth; |
---|
565 | |
---|
566 | g_assert (GTK_IS_HTML (parent)); |
---|
567 | parent_html = GTK_HTML (parent); |
---|
568 | |
---|
569 | html_embedded_init (em, HTML_EMBEDDED_CLASS (klass), |
---|
570 | parent, NULL, NULL); |
---|
571 | |
---|
572 | scrolled_window = gtk_scrolled_window_new (NULL, NULL); |
---|
573 | gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window), |
---|
574 | border ? GTK_SHADOW_IN : GTK_SHADOW_NONE); |
---|
575 | /* |
---|
576 | * FIXME |
---|
577 | * are we missing: |
---|
578 | * gtk_widget_show (scrolled_window); here? |
---|
579 | */ |
---|
580 | |
---|
581 | iframe->scroll = scrolled_window; |
---|
582 | html_iframe_set_scrolling (iframe, GTK_POLICY_AUTOMATIC); |
---|
583 | |
---|
584 | new_widget = gtk_html_new (); |
---|
585 | new_html = GTK_HTML (new_widget); |
---|
586 | new_html->engine->cursor_hide_count = 0; |
---|
587 | |
---|
588 | new_tokenizer = html_tokenizer_clone (parent_html->engine->ht); |
---|
589 | |
---|
590 | html_engine_set_tokenizer (new_html->engine, new_tokenizer); |
---|
591 | g_object_unref (G_OBJECT (new_tokenizer)); |
---|
592 | new_tokenizer = NULL; |
---|
593 | |
---|
594 | gtk_html_set_default_content_type (new_html, |
---|
595 | parent_html->priv->content_type); |
---|
596 | iframe->html = new_widget; |
---|
597 | iframe->url = g_strdup (src); |
---|
598 | iframe->width = width; |
---|
599 | iframe->height = height; |
---|
600 | iframe->gdk_painter = NULL; |
---|
601 | iframe->frameborder = border; |
---|
602 | gtk_html_set_base (new_html, src); |
---|
603 | depth = gtk_html_set_iframe_parent (new_html, parent, HTML_OBJECT (iframe)); |
---|
604 | gtk_container_add (GTK_CONTAINER (scrolled_window), new_widget); |
---|
605 | gtk_widget_show (new_widget); |
---|
606 | |
---|
607 | g_signal_connect (new_html, "url_requested", G_CALLBACK (iframe_url_requested), iframe); |
---|
608 | |
---|
609 | if (depth < 10) { |
---|
610 | if (parent_html->engine->stopped) { |
---|
611 | gtk_html_stop (new_html); |
---|
612 | gtk_html_load_empty (new_html); |
---|
613 | } else { |
---|
614 | GtkHTMLStream *handle; |
---|
615 | |
---|
616 | handle = gtk_html_begin (new_html); |
---|
617 | g_signal_emit_by_name (parent_html->engine, "url_requested", src, handle); |
---|
618 | } |
---|
619 | } else |
---|
620 | gtk_html_load_empty (new_html); |
---|
621 | |
---|
622 | new_html->engine->clue->parent = HTML_OBJECT (iframe); |
---|
623 | |
---|
624 | #if 0 |
---|
625 | /* NOTE: because of peculiarities of the frame/gtkhtml relationship |
---|
626 | * on_url and link_clicked are emitted from the toplevel widget not |
---|
627 | * proxied like url_requested is. |
---|
628 | */ |
---|
629 | gtk_signal_connect (GTK_OBJECT (new_html), "on_url", |
---|
630 | GTK_SIGNAL_FUNC (iframe_on_url), |
---|
631 | (gpointer)iframe); |
---|
632 | gtk_signal_connect (GTK_OBJECT (new_html), "link_clicked", |
---|
633 | GTK_SIGNAL_FUNC (iframe_link_clicked), |
---|
634 | (gpointer)iframe); |
---|
635 | #endif |
---|
636 | g_signal_connect (new_html, "size_changed", G_CALLBACK (iframe_size_changed), iframe); |
---|
637 | g_signal_connect (new_html, "set_base", G_CALLBACK (iframe_set_base), iframe); |
---|
638 | g_signal_connect (new_html, "object_requested", G_CALLBACK (iframe_object_requested), iframe); |
---|
639 | |
---|
640 | /* |
---|
641 | gtk_signal_connect (GTK_OBJECT (html), "button_press_event", |
---|
642 | GTK_SIGNAL_FUNC (iframe_button_press_event), iframe); |
---|
643 | */ |
---|
644 | |
---|
645 | gtk_widget_set_size_request (scrolled_window, width, height); |
---|
646 | |
---|
647 | gtk_widget_show (scrolled_window); |
---|
648 | |
---|
649 | html_embedded_set_widget (em, scrolled_window); |
---|
650 | |
---|
651 | g_signal_connect (scrolled_window, "button_press_event", G_CALLBACK (html_iframe_grab_cursor), NULL); |
---|
652 | |
---|
653 | /* inherit the current colors from our parent */ |
---|
654 | html_colorset_set_unchanged (new_html->engine->defaultSettings->color_set, |
---|
655 | parent_html->engine->settings->color_set); |
---|
656 | html_colorset_set_unchanged (new_html->engine->settings->color_set, |
---|
657 | parent_html->engine->settings->color_set); |
---|
658 | html_painter_set_focus (new_html->engine->painter, parent_html->engine->have_focus); |
---|
659 | /* |
---|
660 | gtk_signal_connect (GTK_OBJECT (html), "title_changed", |
---|
661 | GTK_SIGNAL_FUNC (title_changed_cb), (gpointer)app); |
---|
662 | gtk_signal_connect (GTK_OBJECT (html), "button_press_event", |
---|
663 | GTK_SIGNAL_FUNC (on_button_press_event), popup_menu); |
---|
664 | gtk_signal_connect (GTK_OBJECT (html), "redirect", |
---|
665 | GTK_SIGNAL_FUNC (on_redirect), NULL); |
---|
666 | gtk_signal_connect (GTK_OBJECT (html), "object_requested", |
---|
667 | GTK_SIGNAL_FUNC (object_requested_cmd), NULL); |
---|
668 | */ |
---|
669 | } |
---|
670 | |
---|
671 | void |
---|
672 | html_iframe_type_init (void) |
---|
673 | { |
---|
674 | html_iframe_class_init (&html_iframe_class, HTML_TYPE_IFRAME, sizeof (HTMLIFrame)); |
---|
675 | } |
---|
676 | |
---|
677 | void |
---|
678 | html_iframe_class_init (HTMLIFrameClass *klass, |
---|
679 | HTMLType type, |
---|
680 | guint size) |
---|
681 | { |
---|
682 | HTMLEmbeddedClass *embedded_class; |
---|
683 | HTMLObjectClass *object_class; |
---|
684 | |
---|
685 | g_return_if_fail (klass != NULL); |
---|
686 | |
---|
687 | embedded_class = HTML_EMBEDDED_CLASS (klass); |
---|
688 | object_class = HTML_OBJECT_CLASS (klass); |
---|
689 | |
---|
690 | html_embedded_class_init (embedded_class, type, size); |
---|
691 | parent_class = &html_embedded_class; |
---|
692 | |
---|
693 | object_class->destroy = destroy; |
---|
694 | object_class->save = save; |
---|
695 | object_class->save_plain = save_plain; |
---|
696 | object_class->calc_size = html_iframe_real_calc_size; |
---|
697 | object_class->calc_min_width = calc_min_width; |
---|
698 | object_class->set_painter = set_painter; |
---|
699 | object_class->reset = reset; |
---|
700 | object_class->draw = draw; |
---|
701 | object_class->copy = copy; |
---|
702 | object_class->op_copy = op_copy; |
---|
703 | object_class->set_max_width = set_max_width; |
---|
704 | object_class->forall = forall; |
---|
705 | object_class->check_page_split = check_page_split; |
---|
706 | object_class->search = search; |
---|
707 | object_class->head = head; |
---|
708 | object_class->tail = tail; |
---|
709 | object_class->get_engine = get_engine; |
---|
710 | object_class->check_point = check_point; |
---|
711 | object_class->is_container = is_container; |
---|
712 | object_class->append_selection_string = append_selection_string; |
---|
713 | |
---|
714 | embedded_class->reparent = reparent; |
---|
715 | } |
---|