diff options
author | Crispin Flowerday <gnome@flowerday.cx> | 2006-01-17 05:29:40 +0800 |
---|---|---|
committer | Crispin Flowerday <crispin@src.gnome.org> | 2006-01-17 05:29:40 +0800 |
commit | 5564037c48257090d774f2c654e208b617f756a8 (patch) | |
tree | e5c03042e2808b95a1fcbedce0a368035a086c41 /embed | |
parent | 10696dfdc72198fa1e3c05c86a9b6cae0bc704ae (diff) | |
download | gsoc2013-epiphany-5564037c48257090d774f2c654e208b617f756a8.tar gsoc2013-epiphany-5564037c48257090d774f2c654e208b617f756a8.tar.gz gsoc2013-epiphany-5564037c48257090d774f2c654e208b617f756a8.tar.bz2 gsoc2013-epiphany-5564037c48257090d774f2c654e208b617f756a8.tar.lz gsoc2013-epiphany-5564037c48257090d774f2c654e208b617f756a8.tar.xz gsoc2013-epiphany-5564037c48257090d774f2c654e208b617f756a8.tar.zst gsoc2013-epiphany-5564037c48257090d774f2c654e208b617f756a8.zip |
When looking at modified text areas and forms, don't look at disabled or
2006-01-16 Crispin Flowerday <gnome@flowerday.cx>
* embed/mozilla/EphyBrowser.cpp:
When looking at modified text areas and forms, don't
look at disabled or invisible elements. Patch by
chpe, part of bug #155603
Diffstat (limited to 'embed')
-rw-r--r-- | embed/mozilla/EphyBrowser.cpp | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/embed/mozilla/EphyBrowser.cpp b/embed/mozilla/EphyBrowser.cpp index 0f49127cf..b097ec33a 100644 --- a/embed/mozilla/EphyBrowser.cpp +++ b/embed/mozilla/EphyBrowser.cpp @@ -84,6 +84,13 @@ #include "nsIInterfaceRequestor.h" #include "nsIDOMHTMLDocument.h" #include "nsIDOMXMLDocument.h" +#include <nsIDOMCSSStyleDeclaration.h> +#include <nsIDOMCSSStyleDeclaration.h> +#include <nsIDOMCSSPrimitiveValue.h> +#include <nsIDOMCSSValue.h> +#include <nsIDOMViewCSS.h> +#include <nsIDOMDocumentView.h> +#include <nsIDOMAbstractView.h> #ifdef ALLOW_PRIVATE_API #include "nsIImageDocument.h" @@ -1241,6 +1248,24 @@ nsresult EphyBrowser::GetDocumentHasModifiedForms (nsIDOMDocument *aDomDoc, PRUi nsCOMPtr<nsIDOMHTMLCollection> forms; htmlDoc->GetForms (getter_AddRefs (forms)); if (!forms) return NS_OK; /* it's ok not to have any forms */ + + nsCOMPtr<nsIDOMDocumentView> docView (do_QueryInterface (aDomDoc)); + nsCOMPtr<nsIDOMViewCSS> defaultCSSView; + if (docView) + { + nsCOMPtr<nsIDOMAbstractView> defaultView; + docView->GetDefaultView (getter_AddRefs (defaultView)); + defaultCSSView = do_QueryInterface (defaultView); + } + + const PRUnichar visibilityLiteral[] = { 'v', 'i', 's', 'i', 'b', 'i', 'l', 'i', 't', 'y', '\0' }; + const PRUnichar visibleLiteral[] = { 'v', 'i', 's', 'i', 'b', 'l', 'e', '\0' }; + nsEmbedString visibilityAttr(visibilityLiteral); + nsEmbedString visibleAttr(visibleLiteral); + nsEmbedString EmptyString; + nsCOMPtr<nsIDOMCSSStyleDeclaration> computedStyle; + nsCOMPtr<nsIDOMCSSValue> cssValue; + nsCOMPtr<nsIDOMCSSPrimitiveValue> primitiveValue; PRUint32 formNum; forms->GetLength (&formNum); @@ -1255,6 +1280,32 @@ nsresult EphyBrowser::GetDocumentHasModifiedForms (nsIDOMDocument *aDomDoc, PRUi nsCOMPtr<nsIDOMHTMLFormElement> formElement = do_QueryInterface (formNode); if (!formElement) continue; + PRBool isVisible = PR_FALSE; + nsresult rv; + computedStyle = nsnull; + rv = defaultCSSView->GetComputedStyle (formElement, EmptyString, + getter_AddRefs (computedStyle)); + if (NS_SUCCEEDED (rv) && computedStyle) + { + rv = computedStyle->GetPropertyCSSValue(visibilityAttr, getter_AddRefs (cssValue)); + if (NS_SUCCEEDED (rv) && cssValue) + { + nsEmbedString value; + rv = cssValue->GetCssText (value); + if (NS_SUCCEEDED (rv) && value.Length ()) + { + /* what to do for "collapse" and "inherit" values? */ + isVisible = CompareFormsText (value, visibleAttr); + } + } + } + + if (!isVisible) + { + LOG ("Form node %p is invisible\n", formNode.get()); + continue; + } + nsCOMPtr<nsIDOMHTMLCollection> formElements; formElement->GetElements (getter_AddRefs (formElements)); if (!formElements) continue; @@ -1269,9 +1320,45 @@ nsresult EphyBrowser::GetDocumentHasModifiedForms (nsIDOMDocument *aDomDoc, PRUi formElements->Item (elementIndex, getter_AddRefs (domNode)); if (!domNode) continue; + nsCOMPtr<nsIDOMElement> domElement (do_QueryInterface (domNode)); + if (!domElement) continue; + + isVisible = PR_FALSE; + computedStyle = nsnull; + rv = defaultCSSView->GetComputedStyle (domElement, EmptyString, + getter_AddRefs (computedStyle)); + if (NS_SUCCEEDED (rv) && computedStyle) + { + rv = computedStyle->GetPropertyCSSValue(visibilityAttr, getter_AddRefs (cssValue)); + if (NS_SUCCEEDED (rv) && cssValue) + { + nsEmbedString value; + rv = cssValue->GetCssText (value); + if (NS_SUCCEEDED (rv) && value.Length ()) + { + /* what to do for "collapse" and "inherit" values? */ + isVisible = CompareFormsText (value, visibleAttr); + } + } + } + + if (!isVisible) + { + LOG("Form node %p element %p is invisible\n", formNode.get(), domNode.get()); + continue; + } + nsCOMPtr<nsIDOMHTMLTextAreaElement> areaElement = do_QueryInterface (domNode); if (areaElement) { + PRBool isDisabled = PR_TRUE; + areaElement->GetDisabled (&isDisabled); + if (isDisabled) + { + LOG ("Form node %p element %p [textarea] is disabled\n", formNode.get(), areaElement.get()); + continue; + } + nsEmbedString defaultText, userText; areaElement->GetDefaultValue (defaultText); areaElement->GetValue (userText); @@ -1288,6 +1375,14 @@ nsresult EphyBrowser::GetDocumentHasModifiedForms (nsIDOMDocument *aDomDoc, PRUi nsCOMPtr<nsIDOMHTMLInputElement> inputElement = do_QueryInterface(domNode); if (!inputElement) continue; + PRBool isDisabled = PR_TRUE; + inputElement->GetDisabled (&isDisabled); + if (isDisabled) + { + LOG ("Form node %p element %p [input] is disabled\n", formNode.get(), inputElement.get()); + continue; + } + nsEmbedString type; inputElement->GetType(type); |