Index: embed/mozilla/EphyBrowser.cpp
===================================================================
RCS file: /cvs/gnome/epiphany/embed/mozilla/EphyBrowser.cpp,v
retrieving revision 1.97
diff -p -u -u -p -r1.97 EphyBrowser.cpp
--- embed/mozilla/EphyBrowser.cpp	1 Sep 2005 12:49:06 -0000	1.97
+++ embed/mozilla/EphyBrowser.cpp	27 Sep 2005 19:53:00 -0000
@@ -1073,6 +1073,13 @@ EphyBrowser::CompareFormsText (nsAString
 		        aUserText.BeginReading(),
 		        aUserText.Length() * sizeof (PRUnichar)) == 0);
 }
+#include <nsIDOMCSSStyleDeclaration.h>
+#include <nsIDOMCSSStyleDeclaration.h>
+#include <nsIDOMCSSPrimitiveValue.h>
+#include <nsIDOMCSSValue.h>
+#include <nsIDOMViewCSS.h>
+#include <nsIDOMDocumentView.h>
+#include <nsIDOMAbstractView.h>
 
 nsresult EphyBrowser::GetDocumentHasModifiedForms (nsIDOMDocument *aDomDoc, PRUint32 *aNumTextFields, PRBool *aHasTextArea)
 {
@@ -1083,6 +1090,24 @@ nsresult EphyBrowser::GetDocumentHasModi
 	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);
@@ -1097,6 +1122,30 @@ nsresult EphyBrowser::GetDocumentHasModi
 		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) g_print ("Form node %p is invisible\n", formNode.get());
+		
+		if (!isVisible) continue;
+
 		nsCOMPtr<nsIDOMHTMLCollection> formElements;
 		formElement->GetElements (getter_AddRefs (formElements));
 		if (!formElements) continue;
@@ -1111,15 +1160,50 @@ nsresult EphyBrowser::GetDocumentHasModi
 			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) g_print ("Form node %p element %p is invisible\n", formNode.get(), domNode.get());
+	
+			if (!isVisible) continue;
+
 			nsCOMPtr<nsIDOMHTMLTextAreaElement> areaElement = do_QueryInterface (domNode);
 			if (areaElement)
 			{
+				PRBool isDisabled = PR_TRUE;
+				areaElement->GetDisabled (&isDisabled);
+				if (isDisabled) g_print ("Form node %p element %p [textarea] is disabled\n", formNode.get(), areaElement.get());
+				if (isDisabled) continue;
+
 				nsEmbedString defaultText, userText;
 				areaElement->GetDefaultValue (defaultText);
 				areaElement->GetValue (userText);
 
 				if (!CompareFormsText (defaultText, userText))
 				{
+					nsEmbedCString cDefault, cText;
+					NS_UTF16ToCString(defaultText, NS_CSTRING_ENCODING_UTF8, cDefault);
+					NS_UTF16ToCString(userText, NS_CSTRING_ENCODING_UTF8, cText);
+					g_print ("Textarea default '%s' has '%s'\n", cDefault.get(), cText.get());
 					*aHasTextArea = PR_TRUE;
 					return NS_OK;
 				}
@@ -1130,6 +1214,11 @@ nsresult EphyBrowser::GetDocumentHasModi
 			nsCOMPtr<nsIDOMHTMLInputElement> inputElement = do_QueryInterface(domNode);
 			if (!inputElement) continue;
 	
+			PRBool isDisabled = PR_TRUE;
+			inputElement->GetDisabled (&isDisabled);
+			if (isDisabled) g_print ("Form node %p element %p [input] is disabled\n", formNode.get(), inputElement.get());
+			if (isDisabled) continue;
+
 			nsEmbedString type;
 			inputElement->GetType(type);
 
@@ -1155,6 +1244,10 @@ nsresult EphyBrowser::GetDocumentHasModi
 
 				if (!CompareFormsText (defaultText, userText))
 				{
+					nsEmbedCString cDefault, cText;
+					NS_UTF16ToCString(defaultText, NS_CSTRING_ENCODING_UTF8, cDefault);
+					NS_UTF16ToCString(userText, NS_CSTRING_ENCODING_UTF8, cText);
+					g_print ("Input element default '%s' has '%s'\n", cDefault.get(), cText.get());
 					(*aNumTextFields)++;
 					if (*aNumTextFields >= NUM_MODIFIED_TEXTFIELDS_REQUIRED)
 					{
