WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
[patch]
Work In Progress
WIP.patch (text/plain), 9.66 KB, created by
Sylvain Galineau
on 2015-03-08 18:13:21 PDT
(
hide
)
Description:
Work In Progress
Filename:
MIME Type:
Creator:
Sylvain Galineau
Created:
2015-03-08 18:13:21 PDT
Size:
9.66 KB
patch
obsolete
>diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 640ccd7..831f4c8 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,28 @@ >+2015-03-08 sylvain-galineau <galineau@adobe.com> >+ >+ Need support for :dir() pseudo-class >+ https://bugs.webkit.org/show_bug.cgi?id=64861 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Add :dir() pseudo-class support as defined by CSS, HTML >+ http://dev.w3.org/csswg/selectors-4/#the-dir-pseudo >+ https://html.spec.whatwg.org/multipage/scripting.html#selectors >+ https://html.spec.whatwg.org/multipage/dom.html#the-directionality >+ >+ No new tests (OOPS!). >+ >+ * css/CSSSelector.cpp: >+ (WebCore::CSSSelector::parseDirection): for :dir argument >+ * css/CSSSelector.h: >+ * css/SelectorChecker.cpp: >+ (WebCore::SelectorChecker::checkOne): matching >+ * dom/Element.cpp: >+ (WebCore::Element::dir): current dir attribute state >+ (WebCore::Element::computeInheritedDirection): where directionality is evaluated >+ (WebCore::Element::evalContentDirectionality): where we find out directionality based on the element's content >+ * dom/Element.h: new methods above >+ > 2015-03-05 Carlos Garcia Campos <cgarcia@igalia.com> > > [SOUP] Check TLS errors as soon as they are set in the SoupMessage >diff --git a/Source/WebCore/css/CSSSelector.cpp b/Source/WebCore/css/CSSSelector.cpp >index 47ea071..bc89717 100644 >--- a/Source/WebCore/css/CSSSelector.cpp >+++ b/Source/WebCore/css/CSSSelector.cpp >@@ -30,6 +30,7 @@ > #include "CSSSelectorList.h" > #include "HTMLNames.h" > #include "SelectorPseudoTypeMap.h" >+#include "TextDirection.h" > #include <wtf/Assertions.h> > #include <wtf/HashMap.h> > #include <wtf/NeverDestroyed.h> >@@ -320,7 +321,19 @@ CSSSelector::PseudoElementType CSSSelector::parsePseudoElementType(const String& > return type; > } > >- >+bool CSSSelector::parseDirection(const String& name, TextDirection& dir) >+{ >+ if (equalIgnoringCase(name, "ltr")) { >+ dir = LTR; >+ return true; >+ } else if (equalIgnoringCase(name, "rtl")) { >+ dir = RTL; >+ return true; >+ } >+ >+ return false; >+} >+ > bool CSSSelector::operator==(const CSSSelector& other) const > { > const CSSSelector* sel1 = this; >diff --git a/Source/WebCore/css/CSSSelector.h b/Source/WebCore/css/CSSSelector.h >index bd231b4..927a22b 100644 >--- a/Source/WebCore/css/CSSSelector.h >+++ b/Source/WebCore/css/CSSSelector.h >@@ -23,6 +23,7 @@ > #define CSSSelector_h > > #include "QualifiedName.h" >+#include "TextDirection.h" > #include "RenderStyleConstants.h" > #include <wtf/Noncopyable.h> > >@@ -211,6 +212,9 @@ namespace WebCore { > > static PseudoElementType parsePseudoElementType(const String&); > static PseudoId pseudoId(PseudoElementType); >+#if ENABLE(CSS_SELECTORS_LEVEL4) >+ static bool parseDirection(const String&, TextDirection& dir); >+#endif > > // Selectors are kept in an array by CSSSelectorList. The next component of the selector is > // the next item in the array. >diff --git a/Source/WebCore/css/SelectorChecker.cpp b/Source/WebCore/css/SelectorChecker.cpp >index 20894a5..b6b346a 100644 >--- a/Source/WebCore/css/SelectorChecker.cpp >+++ b/Source/WebCore/css/SelectorChecker.cpp >@@ -55,6 +55,7 @@ > #include "ShadowRoot.h" > #include "StyledElement.h" > #include "Text.h" >+#include "TextDirection.h" > > namespace WebCore { > >@@ -1008,10 +1009,15 @@ bool SelectorChecker::checkOne(const CheckingContextWithStatus& context, PseudoI > return false; > > #if ENABLE(CSS_SELECTORS_LEVEL4) >- // FIXME: Implement :dir() selector. > case CSSSelector::PseudoClassDir: >- return false; >- >+ { >+ TextDirection dir; >+ if (!CSSSelector::parseDirection(selector->argument(), dir)) >+ return false; >+ >+ return element->computeInheritedDirectionality() == dir; >+ } >+ > // FIXME: Implement :role() selector. > case CSSSelector::PseudoClassRole: > return false; >diff --git a/Source/WebCore/dom/Element.cpp b/Source/WebCore/dom/Element.cpp >index 7dfecbd..6b319eb 100644 >--- a/Source/WebCore/dom/Element.cpp >+++ b/Source/WebCore/dom/Element.cpp >@@ -48,6 +48,7 @@ > #include "HTMLCollection.h" > #include "HTMLDocument.h" > #include "HTMLFormControlsCollection.h" >+#include "HTMLInputElement.h" > #include "HTMLLabelElement.h" > #include "HTMLNameCollection.h" > #include "HTMLOptionsCollection.h" >@@ -2363,6 +2364,109 @@ Locale& Element::locale() const > { > return document().getCachedLocale(computeInheritedLanguage()); > } >+ >+Element::SelfDirectionality Element::selfDirectionality() const >+{ >+ static NeverDestroyed<AtomicString> ltrValue("ltr", AtomicString::ConstructFromLiteral); >+ static NeverDestroyed<AtomicString> rtlValue("rtl", AtomicString::ConstructFromLiteral); >+ static NeverDestroyed<AtomicString> autoValue("auto", AtomicString::ConstructFromLiteral); >+ const AtomicString& value = fastGetAttribute(dirAttr); >+ >+ if (equalIgnoringCase(value, ltrValue)) >+ return SelfDirectionality::DirLTR; >+ if (equalIgnoringCase(value, rtlValue)) >+ return SelfDirectionality::DirRTL; >+ if (equalIgnoringCase(value, autoValue)) >+ return SelfDirectionality::DirAuto; >+ >+ return SelfDirectionality::DirUnknown; >+} >+ >+TextDirection Element::computeInheritedDirectionality() const >+{ >+ SelfDirectionality directionality = selfDirectionality(); >+ TextDirection textDirection; >+ >+ if (directionality == SelfDirectionality::DirLTR) >+ return LTR; >+ >+ if (directionality == SelfDirectionality::DirRTL) >+ return RTL; >+ >+ if (is<HTMLInputElement>(*this)) { >+ HTMLInputElement& input = downcast<HTMLInputElement>(const_cast<Element&>(*this)); >+ if (directionality == SelfDirectionality::DirUnknown && input.isTelephoneField()) >+ return LTR; >+ if (directionality == SelfDirectionality::DirAuto && >+ (input.isTextField() || >+ input.isSearchField() || >+ input.isTelephoneField() || >+ input.isURLField() || >+ input.isEmailField())) { >+ if (evalContentDirectionality(textDirection)) >+ return textDirection; >+ >+ } >+ >+ } else if (is<HTMLTextAreaElement>(*this)) { >+ if (directionality == SelfDirectionality::DirAuto && evalContentDirectionality(textDirection)) >+ return textDirection; >+ } else if (directionality == SelfDirectionality::DirAuto || (directionality == SelfDirectionality::DirUnknown && hasTagName(bdiTag))) { >+ if (evalContentDirectionality(textDirection)) >+ return textDirection; >+ } >+ >+ if (Element* parentElement = this->parentElement()) >+ return parentElement->computeInheritedDirectionality(); >+ >+ return LTR; >+} >+ >+bool Element::evalContentDirectionality(TextDirection& direction) const { >+ bool foundDirection = false; >+ UCharDirection charDirection; >+ >+ if (is<HTMLTextFormControlElement>(*this)) { >+ HTMLTextFormControlElement& textElement = downcast<HTMLTextFormControlElement>(const_cast<Element&>(*this)); >+ bool hasStrongDirectionality; >+ charDirection = textElement.value().defaultWritingDirection(&hasStrongDirectionality); >+ foundDirection = true; >+ } else { >+ Node* node = firstChild(); >+ while (node) { >+ // Skip bdi, script, style and text form controls. >+ if (equalIgnoringCase(node->nodeName(), "bdi") || node->hasTagName(scriptTag) || node->hasTagName(styleTag) >+ || (is<Element>(*node) && downcast<Element>(*node).isTextFormControl())) { >+ node = NodeTraversal::nextSkippingChildren(*node, this); >+ continue; >+ } >+ >+ // Skip elements with valid dir attribute >+ if (is<Element>(*node)) { >+ Element& e = downcast<Element>(*node); >+ if (e.selfDirectionality() != SelfDirectionality::DirUnknown) { >+ node = NodeTraversal::nextSkippingChildren(*node, this); >+ continue; >+ } >+ } >+ >+ if (node->isTextNode()) { >+ bool hasStrongDirectionality; >+ charDirection = node->textContent(true).defaultWritingDirection(&hasStrongDirectionality); >+ foundDirection = true; >+ } >+ node = NodeTraversal::next(*node, this); >+ } >+ } >+ >+ if (foundDirection) { >+ direction = (charDirection == U_LEFT_TO_RIGHT)? LTR : RTL; >+ return true; >+ } >+ >+ return false; >+} >+ > > void Element::cancelFocusAppearanceUpdate() > { >diff --git a/Source/WebCore/dom/Element.h b/Source/WebCore/dom/Element.h >index f9115bfd4..698ce0a 100644 >--- a/Source/WebCore/dom/Element.h >+++ b/Source/WebCore/dom/Element.h >@@ -33,6 +33,7 @@ > #include "ScrollTypes.h" > #include "SimulatedClickOptions.h" > #include "StyleResolveTree.h" >+#include "TextDirection.h" > > namespace WebCore { > >@@ -377,6 +378,10 @@ public: > > AtomicString computeInheritedLanguage() const; > Locale& locale() const; >+ >+ enum class SelfDirectionality { DirLTR, DirRTL, DirAuto, DirUnknown }; >+ SelfDirectionality selfDirectionality() const; >+ TextDirection computeInheritedDirectionality() const; > > virtual void accessKeyAction(bool /*sendToAnyEvent*/) { } > >@@ -653,6 +658,8 @@ private: > void unregisterNamedFlowContentElement(); > > void createUniqueElementData(); >+ >+ bool evalContentDirectionality(TextDirection& direction) const; > > ElementRareData* elementRareData() const; > ElementRareData& ensureElementRareData();
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 64861
:
242777
|
242815
|
248025
|
248159
|
248160
|
248164
|
248222
|
251902