aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Hofmann <Johannes.Hofmann@gmx.de>2012-01-30 22:21:42 +0100
committerJohannes Hofmann <Johannes.Hofmann@gmx.de>2012-01-30 22:21:42 +0100
commit356f0d5a01f1ad7162152866a249d0891c51d647 (patch)
treef7480f07a93e1c74d408f67200cd39ce8dc23c50
parent67a65b186409fe9e30d10403a00db9b0fa1e9388 (diff)
rework image handling code
Properly separate common image handling functions in CSS relevant attribute parsing (a_Html_image_attrs) and image creation (a_Html_image_new()). This should also bring the code back a bit to what we had before 8214199c2703.
-rw-r--r--src/form.cc33
-rw-r--r--src/html.cc71
-rw-r--r--src/html_common.hh4
3 files changed, 51 insertions, 57 deletions
diff --git a/src/form.cc b/src/form.cc
index 2e1bde7d..8275c12b 100644
--- a/src/form.cc
+++ b/src/form.cc
@@ -1908,30 +1908,21 @@ DilloHtmlOption::~DilloHtmlOption ()
*/
static Embed *Html_input_image(DilloHtml *html, const char *tag, int tagsize)
{
- const char *attrbuf;
DilloImage *Image;
Embed *button = NULL;
- DilloUrl *url = NULL;
-
- if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "src")) &&
- (url = a_Html_url_new(html, attrbuf, NULL, 0))) {
-
- html->styleEngine->setPseudoLink ();
-
- /* create new image and add it to the button */
- a_Html_image_new(html, tag, tagsize);
- if ((Image = a_Html_image_add(html, url))) {
- IM2DW(Image)->setStyle (html->styleEngine->backgroundStyle ());
- ResourceFactory *factory = HT2LT(html)->getResourceFactory();
- ComplexButtonResource *complex_b_r =
- factory->createComplexButtonResource(IM2DW(Image), false);
- button = new Embed(complex_b_r);
- HT2TB(html)->addWidget (button, html->styleEngine->style ());
-// gtk_widget_set_sensitive(widget, FALSE); /* Until end of FORM! */
- } else {
- a_Url_free(url);
- }
+ html->styleEngine->setPseudoLink ();
+
+ /* create new image and add it to the button */
+ a_Html_image_attrs(html, tag, tagsize);
+ if ((Image = a_Html_image_new(html, tag, tagsize))) {
+ IM2DW(Image)->setStyle (html->styleEngine->backgroundStyle ());
+ ResourceFactory *factory = HT2LT(html)->getResourceFactory();
+ ComplexButtonResource *complex_b_r =
+ factory->createComplexButtonResource(IM2DW(Image), false);
+ button = new Embed(complex_b_r);
+ HT2TB(html)->addWidget (button, html->styleEngine->style ());
+// gtk_widget_set_sensitive(widget, FALSE); /* Until end of FORM! */
}
if (!button)
MSG("Html_input_image: unable to create image submit.\n");
diff --git a/src/html.cc b/src/html.cc
index f3d2bec0..ac7c86df 100644
--- a/src/html.cc
+++ b/src/html.cc
@@ -1963,10 +1963,9 @@ static void Html_tag_open_abbr(DilloHtml *html, const char *tag, int tagsize)
html->styleEngine->inheritBackgroundColor ();
* Read image-associated tag attributes and create new image.
*/
-void a_Html_image_new(DilloHtml *html, const char *tag, int tagsize)
+void a_Html_image_attrs(DilloHtml *html, const char *tag, int tagsize)
{
- DilloImage *Image;
- char *width_ptr, *height_ptr, *alt_ptr;
+ char *width_ptr, *height_ptr;
const char *attrbuf;
CssLength l_w = CSS_CREATE_LENGTH(0.0, CSS_LENGTH_TYPE_AUTO);
CssLength l_h = CSS_CREATE_LENGTH(0.0, CSS_LENGTH_TYPE_AUTO);
@@ -1977,11 +1976,6 @@ void a_Html_image_new(DilloHtml *html, const char *tag, int tagsize)
html->styleEngine->setNonCssHint(PROPERTY_X_TOOLTIP, CSS_TYPE_STRING,
attrbuf);
}
- alt_ptr = a_Html_get_attr_wdef(html, tag, tagsize, "alt", NULL);
- if ((!alt_ptr || !*alt_ptr) && !prefs.load_images) {
- dFree(alt_ptr);
- alt_ptr = dStrdup("[IMG]"); // Place holder for img_off mode
- }
width_ptr = a_Html_get_attr_wdef(html, tag, tagsize, "width", NULL);
height_ptr = a_Html_get_attr_wdef(html, tag, tagsize, "height", NULL);
// Check for malicious values
@@ -2011,7 +2005,7 @@ void a_Html_image_new(DilloHtml *html, const char *tag, int tagsize)
dFree(width_ptr);
dFree(height_ptr);
width_ptr = height_ptr = NULL;
- MSG("a_Html_image_new: suspicious image size request %d x %d\n", w, h);
+ MSG("a_Html_image_attrs: suspicious image size request %d x %d\n", w, h);
} else {
if (CSS_LENGTH_TYPE(l_w) != CSS_LENGTH_TYPE_AUTO)
html->styleEngine->setNonCssHint (CSS_PROPERTY_WIDTH,
@@ -2078,46 +2072,57 @@ void a_Html_image_new(DilloHtml *html, const char *tag, int tagsize)
}
/* x_img is an index to a list of {url,image} pairs.
- * We know Html_add_new_htmlimage() will use size() as its next index */
+ * We know a_Html_image_new() will use size() as its next index */
html->styleEngine->setNonCssHint (PROPERTY_X_IMG, CSS_TYPE_INTEGER,
html->images->size());
- Image = a_Image_new(alt_ptr, 0);
- if (HT2TB(html)->getBgColor())
- Image->bg_color = HT2TB(html)->getBgColor()->getColor();
-
- DilloHtmlImage *hi = dNew(DilloHtmlImage, 1);
- hi->url = NULL;
- hi->image = Image;
- a_Image_ref(Image);
-
- int n = html->images->size();
- html->images->increase();
- html->images->set(n, hi);
dFree(width_ptr);
dFree(height_ptr);
- dFree(alt_ptr);
}
-DilloImage *a_Html_image_add(DilloHtml *html, DilloUrl *url)
+DilloImage *a_Html_image_new(DilloHtml *html, const char *tag, int tagsize)
{
bool load_now;
- int image_index = html->styleEngine->style()->x_img;
- DilloHtmlImage *hi = html->images->get(image_index);
- DilloImage *image = hi->image;
+ char *alt_ptr;
+ const char *attrbuf;
+ DilloUrl *url;
+ DilloImage *image;
+
+ if (!(attrbuf = a_Html_get_attr(html, tag, tagsize, "src")) ||
+ !(url = a_Html_url_new(html, attrbuf, NULL, 0)))
+ return NULL;
+ alt_ptr = a_Html_get_attr_wdef(html, tag, tagsize, "alt", NULL);
+ if ((!alt_ptr || !*alt_ptr) && !prefs.load_images) {
+ dFree(alt_ptr);
+ alt_ptr = dStrdup("[IMG]"); // Place holder for img_off mode
+ }
+
+ image = a_Image_new(alt_ptr, 0);
+
+ if (HT2TB(html)->getBgColor())
+ image->bg_color = HT2TB(html)->getBgColor()->getColor();
+
+ DilloHtmlImage *hi = dNew(DilloHtmlImage, 1);
hi->url = url;
+ html->images->increase();
+ html->images->set(html->images->size() - 1, hi);
load_now = prefs.load_images ||
!dStrAsciiCasecmp(URL_SCHEME(url), "data") ||
(a_Capi_get_flags_with_redirection(url) & CAPI_IsCached);
if (load_now && Html_load_image(html->bw, url, html->page_url, image)) {
- a_Image_unref(hi->image);
+ // hi->image is NULL if dillo tries to load the image immediately
hi->image = NULL;
+ } else {
+ // otherwise a reference is kept in html->images
+ hi->image = image;
+ a_Image_ref(image);
}
+ dFree(alt_ptr);
return image;
}
@@ -2144,7 +2149,7 @@ static bool Html_load_image(BrowserWindow *bw, DilloUrl *url,
static void Html_tag_open_img(DilloHtml *html, const char *tag, int tagsize)
{
- a_Html_image_new(html, tag, tagsize);
+ a_Html_image_attrs(html, tag, tagsize);
}
/*
@@ -2155,15 +2160,15 @@ static void Html_tag_open_img(DilloHtml *html, const char *tag, int tagsize)
static void Html_tag_content_img(DilloHtml *html, const char *tag, int tagsize)
{
DilloImage *Image;
- DilloUrl *url, *usemap_url;
+ DilloUrl *usemap_url;
const char *attrbuf;
/* This avoids loading images. Useful for viewing suspicious HTML email. */
if (URL_FLAGS(html->base_url) & URL_SpamSafe)
return;
- if (!(attrbuf = a_Html_get_attr(html, tag, tagsize, "src")) ||
- !(url = a_Html_url_new(html, attrbuf, NULL, 0)))
+ Image = a_Html_image_new(html, tag, tagsize);
+ if (!Image)
return;
usemap_url = NULL;
@@ -2171,8 +2176,6 @@ static void Html_tag_content_img(DilloHtml *html, const char *tag, int tagsize)
/* TODO: usemap URLs outside of the document are not used. */
usemap_url = a_Html_url_new(html, attrbuf, NULL, 0);
- Image = a_Html_image_add(html, url);
-
HT2TB(html)->addWidget((Widget*)Image->dw, html->styleEngine->style());
/* Image maps */
diff --git a/src/html_common.hh b/src/html_common.hh
index 8eed11f3..52641f00 100644
--- a/src/html_common.hh
+++ b/src/html_common.hh
@@ -241,8 +241,8 @@ DilloUrl *a_Html_url_new(DilloHtml *html,
const char *url_str, const char *base_url,
int use_base_url);
-void a_Html_image_new(DilloHtml *html, const char *tag, int tagsize);
-DilloImage *a_Html_image_add(DilloHtml *html, DilloUrl *url);
+void a_Html_image_attrs(DilloHtml *html, const char *tag, int tagsize);
+DilloImage *a_Html_image_new(DilloHtml *html, const char *tag, int tagsize);
char *a_Html_parse_entities(DilloHtml *html, const char *token, int toksize);
void a_Html_pop_tag(DilloHtml *html, int TagIdx);