aboutsummaryrefslogtreecommitdiffstats
path: root/embed
diff options
context:
space:
mode:
authorChristian Persch <chpe@cvs.gnome.org>2004-06-09 02:47:00 +0800
committerChristian Persch <chpe@src.gnome.org>2004-06-09 02:47:00 +0800
commit433c44cb19de1d0d40579155380fd435140b59fb (patch)
treeae996f66be079dd5037589e5a6aa38af094e98b6 /embed
parent547e14396402130368dfa0b744b81e00cb726861 (diff)
downloadgsoc2013-epiphany-433c44cb19de1d0d40579155380fd435140b59fb.tar
gsoc2013-epiphany-433c44cb19de1d0d40579155380fd435140b59fb.tar.gz
gsoc2013-epiphany-433c44cb19de1d0d40579155380fd435140b59fb.tar.bz2
gsoc2013-epiphany-433c44cb19de1d0d40579155380fd435140b59fb.tar.lz
gsoc2013-epiphany-433c44cb19de1d0d40579155380fd435140b59fb.tar.xz
gsoc2013-epiphany-433c44cb19de1d0d40579155380fd435140b59fb.tar.zst
gsoc2013-epiphany-433c44cb19de1d0d40579155380fd435140b59fb.zip
Fix CSS background detection, based on a galeon patch by Crispin
2004-06-08 Christian Persch <chpe@cvs.gnome.org> * embed/mozilla/EventContext.cpp: Fix CSS background detection, based on a galeon patch by Crispin Flowerday. Fixed bug #143602.
Diffstat (limited to 'embed')
-rw-r--r--embed/mozilla/EventContext.cpp119
1 files changed, 66 insertions, 53 deletions
diff --git a/embed/mozilla/EventContext.cpp b/embed/mozilla/EventContext.cpp
index 1ad257010..5b815a756 100644
--- a/embed/mozilla/EventContext.cpp
+++ b/embed/mozilla/EventContext.cpp
@@ -1,6 +1,7 @@
/*
* Copyright (C) 2000-2004 Marco Pesenti Gritti
* Copyright (C) 2003, 2004 Christian Persch
+ * Copyright (C) 2004 Crispin Flowerday
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -45,11 +46,15 @@
#include <nsIDOMCSSStyleDeclaration.h>
#include <nsIDOM3Node.h>
#include <nsIDOMCSSPrimitiveValue.h>
+#include <nsIDOMNodeList.h>
+#include <nsIDOMDocumentView.h>
+#include <nsIDOMAbstractView.h>
#ifdef ALLOW_PRIVATE_API
#include <nsIDOMXULDocument.h>
#include <nsIDOMNSEvent.h>
#include <nsIDOMNSHTMLElement.h>
+#include <nsIDOMViewCSS.h>
#endif
#define KEY_CODE 256
@@ -180,6 +185,7 @@ nsresult EventContext::GetEventContext (nsIDOMEventTarget *EventTarget,
'w', 'w', '.', 'w', '3', '.', 'o', 'r',
'g', '/', '1', '9', '9', '9', '/', 'x',
'l', 'i', 'n', 'k', '\0'};
+ const PRUnichar bodyLiteral[] = { 'b', 'o', 'd', 'y', '\0' };
mEmbedEvent = info;
@@ -214,6 +220,8 @@ nsresult EventContext::GetEventContext (nsIDOMEventTarget *EventTarget,
rv = node->GetNodeType(&type);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
+ PRBool has_background = PR_FALSE;
+
nsCOMPtr<nsIDOMHTMLElement> element = do_QueryInterface(node);
if ((nsIDOMNode::ELEMENT_NODE == type) && element)
{
@@ -313,6 +321,35 @@ nsresult EventContext::GetEventContext (nsIDOMEventTarget *EventTarget,
return NS_OK;
}
}
+ else if (g_ascii_strcasecmp (tag.get(), "html") == 0)
+ {
+ /* Clicked on part of the page without a <body>, so
+ * look for a background image in the body tag */
+ nsCOMPtr<nsIDOMNodeList> nodeList;
+
+ rv = mDOMDocument->GetElementsByTagName (nsEmbedString(bodyLiteral),
+ getter_AddRefs (nodeList));
+ if (NS_SUCCEEDED (rv) && nodeList)
+ {
+ nsCOMPtr<nsIDOMNode> bodyNode;
+ nodeList->Item (0, getter_AddRefs (bodyNode));
+
+ nsEmbedString cssurl;
+ rv = GetCSSBackground (bodyNode, cssurl);
+ if (NS_SUCCEEDED (rv))
+ {
+ nsEmbedCString bgimg;
+ rv = ResolveBaseURL (cssurl, bgimg);
+ if (NS_FAILED (rv))
+ return NS_ERROR_FAILURE;
+
+ SetStringProperty ("background_image",
+ bgimg.get());
+
+ has_background = PR_TRUE;
+ }
+ }
+ }
}
/* Is page framed ? */
@@ -465,48 +502,6 @@ nsresult EventContext::GetEventContext (nsIDOMEventTarget *EventTarget,
info->context |= EMBED_CONTEXT_INPUT;
}
- nsCOMPtr<nsIDOMElement> domelement;
- domelement = do_QueryInterface (node);
- if (!domelement) return NS_ERROR_FAILURE;
-
- PRBool has_background = PR_FALSE;
-
- nsEmbedString value;
- domelement->GetAttribute (nsEmbedString(bgLiteral), value);
-
- if (value.Length())
- {
- nsEmbedCString bgimg;
-
- rv = ResolveBaseURL (value, bgimg);
- if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
-
- SetStringProperty ("background_image", bgimg.get());
- }
- else
- {
- nsCOMPtr<nsIDOMHTMLBodyElement> bgelement;
- bgelement = do_QueryInterface (node);
- if (bgelement)
- {
- nsEmbedString value;
- bgelement->GetBackground (value);
-
- if (value.Length())
- {
- nsEmbedCString bgimg;
-
- rv = ResolveBaseURL (value, bgimg);
- if (NS_FAILED(rv))
- return NS_ERROR_FAILURE;
-
- SetStringProperty ("background_image",
- bgimg.get());
- has_background = PR_TRUE;
- }
- }
- }
-
if (!has_background)
{
nsEmbedString cssurl;
@@ -522,6 +517,8 @@ nsresult EventContext::GetEventContext (nsIDOMEventTarget *EventTarget,
bgimg.get());
if (NS_FAILED (rv))
return NS_ERROR_FAILURE;
+
+ has_background = PR_TRUE;
}
}
}
@@ -536,28 +533,44 @@ nsresult EventContext::GetEventContext (nsIDOMEventTarget *EventTarget,
nsresult EventContext::GetCSSBackground (nsIDOMNode *node, nsAString& url)
{
- nsresult result;
+ nsresult rv;
const PRUnichar bgimage[] = {'b', 'a', 'c', 'k', 'g', 'r', 'o', 'u', 'n', 'd',
'-', 'i', 'm', 'a', 'g', 'e', '\0'};
- nsCOMPtr<nsIDOMElementCSSInlineStyle> style;
- style = do_QueryInterface (node);
- if (!style) return NS_ERROR_FAILURE;
+ nsCOMPtr<nsIDOMElement> element = do_QueryInterface (node);
+ NS_ENSURE_TRUE (element, NS_ERROR_FAILURE);
+
+ nsCOMPtr<nsIDOMDocumentView> docView = do_QueryInterface (mDOMDocument);
+ NS_ENSURE_TRUE (docView, NS_ERROR_FAILURE);
+
+ nsCOMPtr<nsIDOMAbstractView> abstractView;
+ docView->GetDefaultView (getter_AddRefs (abstractView));
+
+ nsCOMPtr<nsIDOMViewCSS> viewCSS = do_QueryInterface (abstractView);
+ NS_ENSURE_TRUE (viewCSS, NS_ERROR_FAILURE);
nsCOMPtr<nsIDOMCSSStyleDeclaration> decl;
- result = style->GetStyle (getter_AddRefs(decl));
- if (NS_FAILED(result)) return NS_ERROR_FAILURE;
+ viewCSS->GetComputedStyle (element, nsEmbedString(),
+ getter_AddRefs (decl));
+ NS_ENSURE_TRUE (decl, NS_ERROR_FAILURE);
- nsCOMPtr<nsIDOMCSSValue> cssValue;
+ nsCOMPtr<nsIDOMCSSValue> CSSValue;
decl->GetPropertyCSSValue (nsEmbedString(bgimage),
- getter_AddRefs(cssValue));
- nsCOMPtr<nsIDOMCSSPrimitiveValue> primitiveValue;
+ getter_AddRefs (CSSValue));
- primitiveValue = do_QueryInterface(cssValue);
+ nsCOMPtr<nsIDOMCSSPrimitiveValue> primitiveValue =
+ do_QueryInterface (CSSValue);
if (!primitiveValue) return NS_ERROR_FAILURE;
+
+ PRUint16 type;
+ rv = primitiveValue->GetPrimitiveType (&type);
+ NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE);
+
+ if (type != nsIDOMCSSPrimitiveValue::CSS_URI) return NS_ERROR_FAILURE;
- primitiveValue->GetStringValue(url);
+ rv = primitiveValue->GetStringValue (url);
+ NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE);
return NS_OK;
}