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

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

Issue 240243004: Update HTMLElement.dir / Document.dir to return only known values (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Use fastGetAttribute Created 6 years, 8 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/HTMLElement.idl » ('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 1c451cff4c3b76e7a0880e86a8f605642aaca74b..7fae6b26659288df365a9880d03686660af221b9 100644
--- a/Source/core/html/HTMLElement.cpp
+++ b/Source/core/html/HTMLElement.cpp
@@ -629,6 +629,35 @@ void HTMLElement::setTranslate(bool enable)
setAttribute(translateAttr, enable ? "yes" : "no");
}
+// Returns the conforming 'dir' value associated with the state the attribute is in (in its canonical case), if any,
+// or the empty string if the attribute is in a state that has no associated keyword value or if the attribute is
+// not in a defined state (e.g. the attribute is missing and there is no missing value default).
+// http://www.whatwg.org/specs/web-apps/current-work/multipage/common-dom-interfaces.html#limited-to-only-known-values
+static inline const AtomicString& toValidDirValue(const AtomicString& value)
+{
+ DEFINE_STATIC_LOCAL(const AtomicString, ltrValue, ("ltr", AtomicString::ConstructFromLiteral));
+ DEFINE_STATIC_LOCAL(const AtomicString, rtlValue, ("rtl", AtomicString::ConstructFromLiteral));
+ DEFINE_STATIC_LOCAL(const AtomicString, autoValue, ("auto", AtomicString::ConstructFromLiteral));
+
+ if (equalIgnoringCase(value, ltrValue))
+ return ltrValue;
+ if (equalIgnoringCase(value, rtlValue))
+ return rtlValue;
+ if (equalIgnoringCase(value, autoValue))
+ return autoValue;
+ return nullAtom;
+}
+
+const AtomicString& HTMLElement::dir()
+{
+ return toValidDirValue(fastGetAttribute(dirAttr));
+}
+
+void HTMLElement::setDir(const AtomicString& value)
+{
+ setAttribute(dirAttr, value);
+}
+
HTMLFormElement* HTMLElement::findFormAncestor() const
{
return Traversal<HTMLFormElement>::firstAncestor(*this);
« no previous file with comments | « Source/core/html/HTMLElement.h ('k') | Source/core/html/HTMLElement.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698