Bug 595922 - tooltips should not show form validation message if the form element has @novalidate. r+a=sicking
authorMounir Lamouri <mounir.lamouri@gmail.com>
Fri, 17 Dec 2010 09:47:30 -0800
changeset 59449 0ae68f7446c014ecd951156c70f1ddb197e66ee4
parent 59448 5370d662ae51a18c353546e7e8b19e3ad663f4db
child 59450 14ca1420a81d0e7571acf2600c9c76d1068e0172
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
bugs595922
milestone2.0b9pre
Bug 595922 - tooltips should not show form validation message if the form element has @novalidate. r+a=sicking
browser/base/content/browser.js
browser/base/content/test/browser_bug581947.js
embedding/browser/webBrowser/nsDocShellTreeOwner.cpp
layout/reftests/bugs/557087-1.html
layout/reftests/bugs/557087-2.html
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -2811,17 +2811,18 @@ function FillInHTMLTooltip(tipElement)
   var direction = tipElement.ownerDocument.dir;
 
   // If the element is invalid per HTML5 Forms specifications and has no title,
   // show the constraint validation error message.
   if ((tipElement instanceof HTMLInputElement ||
        tipElement instanceof HTMLTextAreaElement ||
        tipElement instanceof HTMLSelectElement ||
        tipElement instanceof HTMLButtonElement) &&
-      !tipElement.hasAttribute('title')) {
+      !tipElement.hasAttribute('title') &&
+      (!tipElement.form || !tipElement.form.noValidate)) {
     // If the element is barred from constraint validation or valid,
     // the validation message will be the empty string.
     titleText = tipElement.validationMessage;
   }
 
   while (!titleText && !XLinkTitleText && !SVGTitleText && tipElement) {
     if (tipElement.nodeType == Node.ELEMENT_NODE) {
       titleText = tipElement.getAttribute("title");
--- a/browser/base/content/test/browser_bug581947.js
+++ b/browser/base/content/test/browser_bug581947.js
@@ -21,16 +21,22 @@ function check(aElementName, aBarred, aT
     ok(FillInHTMLTooltip(e),
        "A tooltip should be shown when the element isn't valid");
   }
 
   e.setAttribute('title', '');
   ok (!FillInHTMLTooltip(e),
       "No tooltip should be shown if the title attribute is set");
 
+  e.removeAttribute('title');
+  content.setAttribute('novalidate', '');
+  ok (!FillInHTMLTooltip(e),
+      "No tooltip should be shown if the novalidate attribute is set on the form owner");
+  content.removeAttribute('novalidate');
+
   content.removeChild(e);
 }
 
 function todo_check(aElementName, aBarred) {
   let doc = gBrowser.contentDocument;
   let tooltip = document.getElementById("aHTMLTooltip");
   let content = doc.getElementById('content');
 
@@ -79,11 +85,11 @@ function test () {
       todo_check(data[0], data[1]);
     }
 
     gBrowser.removeCurrentTab();
     finish();
   }, true);
 
   content.location = 
-    "data:text/html,<!DOCTYPE html><html><body><div id='content'></div></body></html>";
+    "data:text/html,<!DOCTYPE html><html><body><form id='content'></form></body></html>";
 }
 
--- a/embedding/browser/webBrowser/nsDocShellTreeOwner.cpp
+++ b/embedding/browser/webBrowser/nsDocShellTreeOwner.cpp
@@ -1106,17 +1106,27 @@ DefaultTooltipTextProvider::GetNodeText(
   nsCOMPtr<nsIDOMNode> current ( aNode );
 
   // If the element implement the constraint validation API and has no title,
   // show the validation message, if any.
   nsCOMPtr<nsIConstraintValidation> cvElement = do_QueryInterface(current);
   if (cvElement) {
     nsCOMPtr<nsIContent> content = do_QueryInterface(cvElement);
     nsCOMPtr<nsIAtom> titleAtom = do_GetAtom("title");
-    if (content->HasAttr(kNameSpaceID_None, titleAtom)) {
+
+    nsCOMPtr<nsIFormControl> formControl = do_QueryInterface(content);
+    PRBool formHasNoValidate = PR_FALSE;
+    mozilla::dom::Element* form = formControl->GetFormElement();
+    if (form) {
+      nsCOMPtr<nsIAtom> noValidateAtom = do_GetAtom("novalidate");
+      formHasNoValidate = form->HasAttr(kNameSpaceID_None, noValidateAtom);
+    }
+
+    if (!content->HasAttr(kNameSpaceID_None, titleAtom) &&
+        !formHasNoValidate) {
       cvElement->GetValidationMessage(outText);
       found = !outText.IsEmpty();
     }
   }
 
   while ( !found && current ) {
     nsCOMPtr<nsIDOMElement> currElement ( do_QueryInterface(current) );
     if ( currElement ) {