Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(679)

Unified Diff: Source/core/html/HTMLElement.cpp

Issue 524593003: Resolve direction correctly when dir attribute is not in a defined state Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Added code for resolving direction Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/html/HTMLElement.h ('k') | Source/core/html/HTMLTextFormControlElement.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/HTMLElement.cpp
diff --git a/Source/core/html/HTMLElement.cpp b/Source/core/html/HTMLElement.cpp
index 2ae40944acbf5638ef602b02fe2ac16754ac0e08..cf8b85d1b0d2511603b50f59658554b97b3cf088 100644
--- a/Source/core/html/HTMLElement.cpp
+++ b/Source/core/html/HTMLElement.cpp
@@ -38,6 +38,7 @@
#include "core/dom/DocumentFragment.h"
#include "core/dom/ElementTraversal.h"
#include "core/dom/ExceptionCode.h"
+#include "core/dom/NodeRenderStyle.h"
#include "core/dom/NodeTraversal.h"
#include "core/dom/Text.h"
#include "core/dom/shadow/ElementShadow.h"
@@ -51,6 +52,7 @@
#include "core/html/HTMLInputElement.h"
#include "core/html/HTMLMenuElement.h"
#include "core/html/HTMLTemplateElement.h"
+#include "core/html/HTMLTextAreaElement.h"
#include "core/html/HTMLTextFormControlElement.h"
#include "core/html/parser/HTMLParserIdioms.h"
#include "core/rendering/RenderObject.h"
@@ -189,10 +191,11 @@ void HTMLElement::collectStyleForPresentationAttribute(const QualifiedName& name
if (equalIgnoringCase(value, "auto"))
addPropertyToPresentationAttributeStyle(style, CSSPropertyUnicodeBidi, unicodeBidiAttributeForDirAuto(this));
else {
- if (isValidDirAttribute(value))
+ if (!isValidDirAttribute(value)) {
+ addPropertyToPresentationAttributeStyle(style, CSSPropertyDirection, directionForFormData());
tkent 2014/09/09 01:42:28 |ForFormData| is an inappropriate name. FormData
Sunil Ratnu 2014/09/09 03:31:03 Done.
+ } else {
addPropertyToPresentationAttributeStyle(style, CSSPropertyDirection, value);
- else
- addPropertyToPresentationAttributeStyle(style, CSSPropertyDirection, "ltr");
+ }
if (!hasTagName(bdiTag) && !hasTagName(bdoTag) && !hasTagName(outputTag))
addPropertyToPresentationAttributeStyle(style, CSSPropertyUnicodeBidi, CSSValueEmbed);
}
@@ -684,14 +687,44 @@ TextDirection HTMLElement::directionalityIfhasDirAutoAttribute(bool& isAuto) con
return directionality();
}
+String HTMLElement::directionForFormData() const
+{
+ for (const HTMLElement* element = this; element; element = Traversal<HTMLElement>::firstAncestor(*element)) {
+ const AtomicString& dirAttributeValue = element->fastGetAttribute(dirAttr);
+ if (dirAttributeValue.isNull())
+ continue;
+
+ if (equalIgnoringCase(dirAttributeValue, "rtl") || equalIgnoringCase(dirAttributeValue, "ltr"))
+ return dirAttributeValue;
+
+ if (equalIgnoringCase(dirAttributeValue, "auto")) {
+ bool isAuto;
+ TextDirection textDirection = element->directionalityIfhasDirAutoAttribute(isAuto);
+ return textDirection == RTL ? "rtl" : "ltr";
+ }
+ }
+
+ return "ltr";
+}
+
TextDirection HTMLElement::directionality(Node** strongDirectionalityTextNode) const
{
if (isHTMLInputElement(*this)) {
HTMLInputElement* inputElement = toHTMLInputElement(const_cast<HTMLElement*>(this));
+ if (inputElement->isTextField() || inputElement->isSearchField()
+ || inputElement->isURLField() || inputElement->isEmailField()) {
+ bool hasStrongDirectionality;
+ TextDirection textDirection = determineDirectionality(inputElement->value(), hasStrongDirectionality);
+ if (strongDirectionalityTextNode)
+ *strongDirectionalityTextNode = hasStrongDirectionality ? inputElement : 0;
+ return textDirection;
+ }
+ } else if (isHTMLTextAreaElement(*this)) {
+ HTMLTextAreaElement* textAreaElement = toHTMLTextAreaElement(const_cast<HTMLElement*>(this));
bool hasStrongDirectionality;
- TextDirection textDirection = determineDirectionality(inputElement->value(), hasStrongDirectionality);
+ TextDirection textDirection = determineDirectionality(textAreaElement->value(), hasStrongDirectionality);
if (strongDirectionalityTextNode)
- *strongDirectionalityTextNode = hasStrongDirectionality ? inputElement : 0;
+ *strongDirectionalityTextNode = hasStrongDirectionality ? textAreaElement : 0;
return textDirection;
}
« no previous file with comments | « Source/core/html/HTMLElement.h ('k') | Source/core/html/HTMLTextFormControlElement.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698