Source/WebCore/ChangeLog

 12015-03-05 sylvain-galineau <galineau@adobe.com>
 2
 3 Need support for :dir() pseudo-class
 4 https://bugs.webkit.org/show_bug.cgi?id=64861
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 No new tests (OOPS!).
 9
 10 * css/CSSSelector.cpp:
 11 (WebCore::CSSSelector::parseDirection): for :dir argument
 12 * css/CSSSelector.h:
 13 * css/SelectorChecker.cpp:
 14 (WebCore::SelectorChecker::checkOne): matching
 15 * dom/Element.cpp:
 16 (WebCore::Element::dir): current dir attribute state
 17 (WebCore::Element::computeInheritedDirection): where directionality is evaluated
 18 (WebCore::Element::evalContentDirectionality): where we find out directionality based on the element's content
 19 * dom/Element.h: new methods above
 20
1212015-03-05 Carlos Garcia Campos <cgarcia@igalia.com>
222
323 [SOUP] Check TLS errors as soon as they are set in the SoupMessage

Source/WebCore/css/CSSSelector.cpp

3030#include "CSSSelectorList.h"
3131#include "HTMLNames.h"
3232#include "SelectorPseudoTypeMap.h"
 33#include "TextDirection.h"
3334#include <wtf/Assertions.h>
3435#include <wtf/HashMap.h>
3536#include <wtf/NeverDestroyed.h>

@@CSSSelector::PseudoElementType CSSSelector::parsePseudoElementType(const String&
320321 return type;
321322}
322323
323 
 324bool CSSSelector::parseDirection(const String& name, TextDirection& dir)
 325{
 326 bool valid = false;
 327
 328 if (equalIgnoringCase(name, "ltr")) {
 329 valid = true;
 330 dir = LTR;
 331 }
 332 if (equalIgnoringCase(name, "rtl")) {
 333 valid = true;
 334 dir = RTL;
 335 }
 336
 337 return valid;
 338}
324339bool CSSSelector::operator==(const CSSSelector& other) const
325340{
326341 const CSSSelector* sel1 = this;

Source/WebCore/css/CSSSelector.h

2323#define CSSSelector_h
2424
2525#include "QualifiedName.h"
 26#include "TextDirection.h"
2627#include "RenderStyleConstants.h"
2728#include <wtf/Noncopyable.h>
2829

@@namespace WebCore {
211212
212213 static PseudoElementType parsePseudoElementType(const String&);
213214 static PseudoId pseudoId(PseudoElementType);
 215#if ENABLE(CSS_SELECTORS_LEVEL4)
 216 static bool parseDirection(const String&, TextDirection& dir);
 217#endif
214218
215219 // Selectors are kept in an array by CSSSelectorList. The next component of the selector is
216220 // the next item in the array.

Source/WebCore/css/SelectorChecker.cpp

5555#include "ShadowRoot.h"
5656#include "StyledElement.h"
5757#include "Text.h"
 58 #include "TextDirection.h"
5859
5960namespace WebCore {
6061

@@bool SelectorChecker::checkOne(const CheckingContextWithStatus& context, PseudoI
10101011#if ENABLE(CSS_SELECTORS_LEVEL4)
10111012 // FIXME: Implement :dir() selector.
10121013 case CSSSelector::PseudoClassDir:
1013  return false;
1014 
 1014 {
 1015 TextDirection dir;
 1016 if (!CSSSelector::parseDirection(selector->argument(), dir)) {
 1017 return false;
 1018 }
 1019 return (element->computeInheritedDirection() == dir);
 1020 }
 1021
10151022 // FIXME: Implement :role() selector.
10161023 case CSSSelector::PseudoClassRole:
10171024 return false;

Source/WebCore/dom/Element.cpp

4848#include "HTMLCollection.h"
4949#include "HTMLDocument.h"
5050#include "HTMLFormControlsCollection.h"
 51#include "HTMLInputElement.h"
5152#include "HTMLLabelElement.h"
5253#include "HTMLNameCollection.h"
5354#include "HTMLOptionsCollection.h"

@@Locale& Element::locale() const
23632364{
23642365 return document().getCachedLocale(computeInheritedLanguage());
23652366}
 2367
 2368Element::DirAttributeState Element::dir() const
 2369{
 2370 static NeverDestroyed<AtomicString> ltrValue("ltr", AtomicString::ConstructFromLiteral);
 2371 static NeverDestroyed<AtomicString> rtlValue("rtl", AtomicString::ConstructFromLiteral);
 2372 static NeverDestroyed<AtomicString> autoValue("auto", AtomicString::ConstructFromLiteral);
 2373 const AtomicString& value = fastGetAttribute(dirAttr);
 2374
 2375 if (equalIgnoringCase(value, ltrValue))
 2376 return DirLTR;
 2377 if (equalIgnoringCase(value, rtlValue))
 2378 return DirRTL;
 2379 if (equalIgnoringCase(value, autoValue))
 2380 return DirAuto;
 2381 return DirUnknown;
 2382}
 2383
 2384TextDirection Element::computeInheritedDirection() const
 2385{
 2386 DirAttributeState d = dir();
 2387 TextDirection td;
 2388
 2389 if (d == DirLTR)
 2390 return LTR;
 2391
 2392 if (d == DirRTL)
 2393 return RTL;
 2394
 2395 if (is<HTMLInputElement>(*this)) {
 2396 HTMLInputElement& input = downcast<HTMLInputElement>(const_cast<Element&>(*this));
 2397 if (d == DirUnknown && input.isTelephoneField())
 2398 return LTR;
 2399 if (d == DirAuto && (input.isTextField() ||
 2400 input.isSearchField() ||
 2401 input.isTelephoneField() ||
 2402 input.isURLField() ||
 2403 input.isEmailField())) {
 2404 if (evalContentDirectionality(td))
 2405 return td;
 2406
 2407 }
 2408
 2409 } else if (is<HTMLTextAreaElement>(*this)) {
 2410 if (d == DirAuto && evalContentDirectionality(td))
 2411 return td;
 2412 } else if (d == DirAuto || (d == DirUnknown && equalIgnoringCase(nodeName(), "bdi"))) {
 2413 if (evalContentDirectionality(td)) {
 2414 return td;
 2415 }
 2416
 2417 } else if (d == DirUnknown) {
 2418 if (isDocumentNode())
 2419 return LTR;
 2420 if (parentElement())
 2421 return parentElement()->computeInheritedDirection();
 2422 }
 2423
 2424 return LTR; // Must ASSERT we don't get here
 2425}
 2426
 2427bool Element::evalContentDirectionality(TextDirection& direction) const {
 2428 bool foundDirection = false;
 2429 UCharDirection charDirection;
 2430
 2431 if (is<HTMLTextFormControlElement>(*this)) {
 2432 HTMLTextFormControlElement& textElement = downcast<HTMLTextFormControlElement>(const_cast<Element&>(*this));
 2433 bool hasStrongDirectionality;
 2434 charDirection = textElement.value().defaultWritingDirection(&hasStrongDirectionality);
 2435 foundDirection = true;
 2436 } else {
 2437 Node* node = firstChild();
 2438 while (node) {
 2439 // Skip bdi, script, style and text form controls.
 2440 if (equalIgnoringCase(node->nodeName(), "bdi") || node->hasTagName(scriptTag) || node->hasTagName(styleTag)
 2441 || (is<Element>(*node) && downcast<Element>(*node).isTextFormControl())) {
 2442 node = NodeTraversal::nextSkippingChildren(*node, this);
 2443 continue;
 2444 }
 2445
 2446 // Skip elements with valid dir attribute
 2447 if (is<Element>(*node)) {
 2448 Element& e = downcast<Element>(*node);
 2449 if (e.dir() != DirUnknown) {
 2450 node = NodeTraversal::nextSkippingChildren(*node, this);
 2451 continue;
 2452 }
 2453 }
 2454
 2455 if (node->isTextNode()) {
 2456 bool hasStrongDirectionality;
 2457 charDirection = node->textContent(true).defaultWritingDirection(&hasStrongDirectionality);
 2458 foundDirection = true;
 2459 }
 2460 node = NodeTraversal::next(*node, this);
 2461 }
 2462 }
 2463
 2464 if (foundDirection) {
 2465 direction = (charDirection == U_LEFT_TO_RIGHT)? LTR : RTL;
 2466 return true;
 2467 }
 2468
 2469 return false;
 2470}
 2471
23662472
23672473void Element::cancelFocusAppearanceUpdate()
23682474{

Source/WebCore/dom/Element.h

3333#include "ScrollTypes.h"
3434#include "SimulatedClickOptions.h"
3535#include "StyleResolveTree.h"
 36#include "TextDirection.h"
3637
3738namespace WebCore {
3839

@@public:
377378
378379 AtomicString computeInheritedLanguage() const;
379380 Locale& locale() const;
 381
 382 enum DirAttributeState { DirLTR, DirRTL, DirAuto, DirUnknown };
 383 DirAttributeState dir() const;
 384 TextDirection computeInheritedDirection() const;
380385
381386 virtual void accessKeyAction(bool /*sendToAnyEvent*/) { }
382387

@@private:
653658 void unregisterNamedFlowContentElement();
654659
655660 void createUniqueElementData();
 661
 662 bool evalContentDirectionality(TextDirection& direction) const;
656663
657664 ElementRareData* elementRareData() const;
658665 ElementRareData& ensureElementRareData();