Title: [128254] trunk/Source/WebCore
- Revision
- 128254
- Author
- [email protected]
- Date
- 2012-09-11 18:42:19 -0700 (Tue, 11 Sep 2012)
Log Message
Refactor ValidationMessage class
https://bugs.webkit.org/show_bug.cgi?id=96365
Reviewed by Hajime Morita.
- Move some code from HTMLFormControlElement to ValidationMessage
- ValidationMessage class holds an element pointer as
HTMLFormControlElement, not FormAssociatedElement.
No new tests because of no behavior changes.
* html/HTMLFormControlElement.cpp:
(WebCore::HTMLFormControlElement::updateVisibleValidationMessage):
Moved some code to ValidationMessage::updateValidationMessage().
(WebCore::HTMLFormControlElement::setNeedsValidityCheck):
Ask ValidationMessage whether it is visible or not.
* html/HTMLFormControlElement.h:
(HTMLFormControlElement): Removed visibleValidationMessage().
* html/ValidationMessage.cpp:
(WebCore::ValidationMessage::ValidationMessage):
Change the argument type: FormAssociatedElement -> HTMLFormControlElement
(WebCore::ValidationMessage::create): ditto.
(WebCore::ValidationMessage::updateValidationMessage):
Added. Moved some code from
HTMLFormControlElement::updateVisibleValidationMessage().
(WebCore::ValidationMessage::buildBubbleTree): toHTMLElement() is not needed.
(WebCore::ValidationMessage::deleteBubbleTree): ditto.
(WebCore::ValidationMessage::isVisible): Added.
* html/ValidationMessage.h:
(ValidationMessage):
- Change some instance of FormAssociatedElement to HTMLFormControlElement
- Remove message().
- Added updateValidationMessage() and isVisible()
- Made setMessage() private.
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (128253 => 128254)
--- trunk/Source/WebCore/ChangeLog 2012-09-12 01:35:47 UTC (rev 128253)
+++ trunk/Source/WebCore/ChangeLog 2012-09-12 01:42:19 UTC (rev 128254)
@@ -1,3 +1,41 @@
+2012-09-11 Kent Tamura <[email protected]>
+
+ Refactor ValidationMessage class
+ https://bugs.webkit.org/show_bug.cgi?id=96365
+
+ Reviewed by Hajime Morita.
+
+ - Move some code from HTMLFormControlElement to ValidationMessage
+ - ValidationMessage class holds an element pointer as
+ HTMLFormControlElement, not FormAssociatedElement.
+
+ No new tests because of no behavior changes.
+
+ * html/HTMLFormControlElement.cpp:
+ (WebCore::HTMLFormControlElement::updateVisibleValidationMessage):
+ Moved some code to ValidationMessage::updateValidationMessage().
+ (WebCore::HTMLFormControlElement::setNeedsValidityCheck):
+ Ask ValidationMessage whether it is visible or not.
+ * html/HTMLFormControlElement.h:
+ (HTMLFormControlElement): Removed visibleValidationMessage().
+
+ * html/ValidationMessage.cpp:
+ (WebCore::ValidationMessage::ValidationMessage):
+ Change the argument type: FormAssociatedElement -> HTMLFormControlElement
+ (WebCore::ValidationMessage::create): ditto.
+ (WebCore::ValidationMessage::updateValidationMessage):
+ Added. Moved some code from
+ HTMLFormControlElement::updateVisibleValidationMessage().
+ (WebCore::ValidationMessage::buildBubbleTree): toHTMLElement() is not needed.
+ (WebCore::ValidationMessage::deleteBubbleTree): ditto.
+ (WebCore::ValidationMessage::isVisible): Added.
+ * html/ValidationMessage.h:
+ (ValidationMessage):
+ - Change some instance of FormAssociatedElement to HTMLFormControlElement
+ - Remove message().
+ - Added updateValidationMessage() and isVisible()
+ - Made setMessage() private.
+
2012-09-11 Christopher Cameron <[email protected]>
[chromium] Make prioritized texture manager not touch backings array on the main thread
Modified: trunk/Source/WebCore/html/HTMLFormControlElement.cpp (128253 => 128254)
--- trunk/Source/WebCore/html/HTMLFormControlElement.cpp 2012-09-12 01:35:47 UTC (rev 128253)
+++ trunk/Source/WebCore/html/HTMLFormControlElement.cpp 2012-09-12 01:42:19 UTC (rev 128254)
@@ -402,29 +402,11 @@
if (!page)
return;
String message;
- if (renderer() && willValidate()) {
+ if (renderer() && willValidate())
message = validationMessage().stripWhiteSpace();
- // HTML5 specification doesn't ask UA to show the title attribute value
- // with the validationMessage. However, this behavior is same as Opera
- // and the specification describes such behavior as an example.
- const AtomicString& title = getAttribute(titleAttr);
- if (!message.isEmpty() && !title.isEmpty()) {
- message.append('\n');
- message.append(title);
- }
- }
- if (message.isEmpty()) {
- hideVisibleValidationMessage();
- return;
- }
- if (!m_validationMessage) {
+ if (!m_validationMessage)
m_validationMessage = ValidationMessage::create(this);
- m_validationMessage->setMessage(message);
- } else {
- // Call setMessage() even if m_validationMesage->message() == message
- // because the existing message might be to be hidden.
- m_validationMessage->setMessage(message);
- }
+ m_validationMessage->updateValidationMessage(message);
}
void HTMLFormControlElement::hideVisibleValidationMessage()
@@ -433,11 +415,6 @@
m_validationMessage->requestToHideMessage();
}
-String HTMLFormControlElement::visibleValidationMessage() const
-{
- return m_validationMessage ? m_validationMessage->message() : String();
-}
-
bool HTMLFormControlElement::checkValidity(Vector<RefPtr<FormAssociatedElement> >* unhandledInvalidControls)
{
if (!willValidate() || isValidFormControlElement())
@@ -469,7 +446,7 @@
m_isValid = newIsValid;
// Updates only if this control already has a validtion message.
- if (!visibleValidationMessage().isEmpty()) {
+ if (m_validationMessage && m_validationMessage->isVisible()) {
// Calls updateVisibleValidationMessage() even if m_isValid is not
// changed because a validation message can be chagned.
updateVisibleValidationMessage();
Modified: trunk/Source/WebCore/html/HTMLFormControlElement.h (128253 => 128254)
--- trunk/Source/WebCore/html/HTMLFormControlElement.h 2012-09-12 01:35:47 UTC (rev 128253)
+++ trunk/Source/WebCore/html/HTMLFormControlElement.h 2012-09-12 01:42:19 UTC (rev 128254)
@@ -148,7 +148,6 @@
virtual HTMLFormElement* virtualForm() const;
virtual bool isDefaultButtonForForm() const;
virtual bool isValidFormControlElement();
- String visibleValidationMessage() const;
void updateAncestorDisabledState() const;
OwnPtr<ValidationMessage> m_validationMessage;
Modified: trunk/Source/WebCore/html/ValidationMessage.cpp (128253 => 128254)
--- trunk/Source/WebCore/html/ValidationMessage.cpp 2012-09-12 01:35:47 UTC (rev 128253)
+++ trunk/Source/WebCore/html/ValidationMessage.cpp 2012-09-12 01:42:19 UTC (rev 128254)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010 Google Inc. All rights reserved.
+ * Copyright (C) 2010, 2012 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -35,9 +35,9 @@
#include "CSSValueKeywords.h"
#include "ElementShadow.h"
#include "ExceptionCodePlaceholder.h"
-#include "FormAssociatedElement.h"
#include "HTMLBRElement.h"
#include "HTMLDivElement.h"
+#include "HTMLFormControlElement.h"
#include "HTMLNames.h"
#include "Page.h"
#include "RenderBlock.h"
@@ -52,9 +52,10 @@
using namespace HTMLNames;
-ALWAYS_INLINE ValidationMessage::ValidationMessage(FormAssociatedElement* element)
+ALWAYS_INLINE ValidationMessage::ValidationMessage(HTMLFormControlElement* element)
: m_element(element)
{
+ ASSERT(m_element);
}
ValidationMessage::~ValidationMessage()
@@ -62,11 +63,30 @@
deleteBubbleTree();
}
-PassOwnPtr<ValidationMessage> ValidationMessage::create(FormAssociatedElement* element)
+PassOwnPtr<ValidationMessage> ValidationMessage::create(HTMLFormControlElement* element)
{
return adoptPtr(new ValidationMessage(element));
}
+void ValidationMessage::updateValidationMessage(const String& message)
+{
+ String updatedMessage = message;
+ // HTML5 specification doesn't ask UA to show the title attribute value
+ // with the validationMessage. However, this behavior is same as Opera
+ // and the specification describes such behavior as an example.
+ const AtomicString& title = m_element->fastGetAttribute(titleAttr);
+ if (!updatedMessage.isEmpty() && !title.isEmpty()) {
+ updatedMessage.append('\n');
+ updatedMessage.append(title);
+ }
+
+ if (updatedMessage.isEmpty()) {
+ requestToHideMessage();
+ return;
+ }
+ setMessage(updatedMessage);
+}
+
void ValidationMessage::setMessage(const String& message)
{
// Don't modify the DOM tree in this context.
@@ -133,10 +153,9 @@
void ValidationMessage::buildBubbleTree(Timer<ValidationMessage>*)
{
- HTMLElement* host = toHTMLElement(m_element);
ShadowRoot* shadowRoot = m_element->ensureUserAgentShadowRoot();
- Document* doc = host->document();
+ Document* doc = m_element->document();
m_bubble = HTMLDivElement::create(doc);
m_bubble->setShadowPseudoId("-webkit-validation-bubble");
// Need to force position:absolute because RenderMenuList doesn't assume it
@@ -145,8 +164,8 @@
ExceptionCode ec = 0;
shadowRoot->appendChild(m_bubble.get(), ec);
ASSERT(!ec);
- host->document()->updateLayout();
- adjustBubblePosition(host->boundingBox(), m_bubble.get());
+ m_element->document()->updateLayout();
+ adjustBubblePosition(m_element->boundingBox(), m_bubble.get());
RefPtr<HTMLDivElement> clipper = HTMLDivElement::create(doc);
clipper->setShadowPseudoId("-webkit-validation-bubble-arrow-clipper");
@@ -197,12 +216,15 @@
if (m_bubble) {
m_messageHeading = 0;
m_messageBody = 0;
- HTMLElement* host = toHTMLElement(m_element);
- ExceptionCode ec;
- host->userAgentShadowRoot()->removeChild(m_bubble.get(), ec);
+ m_element->userAgentShadowRoot()->removeChild(m_bubble.get(), ASSERT_NO_EXCEPTION);
m_bubble = 0;
}
m_message = String();
}
+bool ValidationMessage::isVisible() const
+{
+ return !m_message.isEmpty();
+}
+
} // namespace WebCore
Modified: trunk/Source/WebCore/html/ValidationMessage.h (128253 => 128254)
--- trunk/Source/WebCore/html/ValidationMessage.h 2012-09-12 01:35:47 UTC (rev 128253)
+++ trunk/Source/WebCore/html/ValidationMessage.h 2012-09-12 01:42:19 UTC (rev 128254)
@@ -39,27 +39,28 @@
namespace WebCore {
-class FormAssociatedElement;
class HTMLElement;
+class HTMLFormControlElement;
class Node;
class ValidationMessage {
WTF_MAKE_NONCOPYABLE(ValidationMessage);
public:
- static PassOwnPtr<ValidationMessage> create(FormAssociatedElement*);
+ static PassOwnPtr<ValidationMessage> create(HTMLFormControlElement*);
~ValidationMessage();
- String message() const { return m_message; }
- void setMessage(const String&);
+ void updateValidationMessage(const String&);
void requestToHideMessage();
+ bool isVisible() const;
bool shadowTreeContains(Node*) const;
private:
- ValidationMessage(FormAssociatedElement*);
+ ValidationMessage(HTMLFormControlElement*);
+ void setMessage(const String&);
void setMessageDOMAndStartTimer(Timer<ValidationMessage>* = 0);
void buildBubbleTree(Timer<ValidationMessage>*);
void deleteBubbleTree(Timer<ValidationMessage>* = 0);
- FormAssociatedElement* m_element;
+ HTMLFormControlElement* m_element;
String m_message;
OwnPtr<Timer<ValidationMessage> > m_timer;
RefPtr<HTMLElement> m_bubble;
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes