Title: [161041] trunk/Source/WebCore
Revision
161041
Author
[email protected]
Date
2013-12-23 17:22:49 -0800 (Mon, 23 Dec 2013)

Log Message

Add the pseudo class :focus to the Selector Code Generator
https://bugs.webkit.org/show_bug.cgi?id=126189

Reviewed by Ryosuke Niwa.

* cssjit/SelectorCompiler.cpp:
(WebCore::SelectorCompiler::addPseudoType):
(WebCore::SelectorCompiler::SelectorCodeGenerator::SelectorCodeGenerator):
(WebCore::SelectorCompiler::SelectorCodeGenerator::generateElementMatching):
(WebCore::SelectorCompiler::SelectorCodeGenerator::generateElementIsFocused):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (161040 => 161041)


--- trunk/Source/WebCore/ChangeLog	2013-12-24 01:17:07 UTC (rev 161040)
+++ trunk/Source/WebCore/ChangeLog	2013-12-24 01:22:49 UTC (rev 161041)
@@ -1,3 +1,16 @@
+2013-12-23  Benjamin Poulain  <[email protected]>
+
+        Add the pseudo class :focus to the Selector Code Generator
+        https://bugs.webkit.org/show_bug.cgi?id=126189
+
+        Reviewed by Ryosuke Niwa.
+
+        * cssjit/SelectorCompiler.cpp:
+        (WebCore::SelectorCompiler::addPseudoType):
+        (WebCore::SelectorCompiler::SelectorCodeGenerator::SelectorCodeGenerator):
+        (WebCore::SelectorCompiler::SelectorCodeGenerator::generateElementMatching):
+        (WebCore::SelectorCompiler::SelectorCodeGenerator::generateElementIsFocused):
+
 2013-12-23  Ryosuke Niwa  <[email protected]>
 
         Remove boolean argument from Element::setChildrenAffectBy* methods

Modified: trunk/Source/WebCore/cssjit/SelectorCompiler.cpp (161040 => 161041)


--- trunk/Source/WebCore/cssjit/SelectorCompiler.cpp	2013-12-24 01:17:07 UTC (rev 161040)
+++ trunk/Source/WebCore/cssjit/SelectorCompiler.cpp	2013-12-24 01:22:49 UTC (rev 161041)
@@ -79,7 +79,8 @@
 
 enum class FunctionType {
     SimpleSelectorChecker,
-    SelectorCheckerWithCheckingContext
+    SelectorCheckerWithCheckingContext,
+    CannotCompile
 };
 
 struct SelectorFragment {
@@ -101,6 +102,7 @@
     const QualifiedName* tagName;
     const AtomicString* id;
     Vector<const AtomicStringImpl*, 1> classNames;
+    HashSet<unsigned> pseudoClasses;
 };
 
 typedef JSC::MacroAssembler Assembler;
@@ -140,6 +142,7 @@
     void generateElementHasTagName(Assembler::JumpList& failureCases, const QualifiedName& nameToMatch);
     void generateElementHasId(Assembler::JumpList& failureCases, const LocalRegister& elementDataAddress, const AtomicString& idToMatch);
     void generateElementHasClasses(Assembler::JumpList& failureCases, const LocalRegister& elementDataAddress, const Vector<const AtomicStringImpl*>& classNames);
+    void generateElementIsFocused(Assembler::JumpList& failureCases);
 
     Assembler m_assembler;
     RegisterAllocator m_registerAllocator;
@@ -193,6 +196,23 @@
     return FragmentRelation::Descendant;
 }
 
+static inline FunctionType mostRestrictiveFunctionType(FunctionType a, FunctionType b)
+{
+    return std::max(a, b);
+}
+
+static inline FunctionType addPseudoType(CSSSelector::PseudoType type, HashSet<unsigned>& pseudoClasses)
+{
+    switch (type) {
+    case CSSSelector::PseudoFocus:
+        pseudoClasses.add(CSSSelector::PseudoFocus);
+        return FunctionType::SimpleSelectorChecker;
+    default:
+        break;
+    }
+    return FunctionType::CannotCompile;
+}
+
 inline SelectorCodeGenerator::SelectorCodeGenerator(const CSSSelector* rootSelector)
     : m_stackAllocator(m_assembler)
     , m_functionType(FunctionType::SimpleSelectorChecker)
@@ -225,12 +245,16 @@
         case CSSSelector::Class:
             fragment.classNames.append(selector->value().impl());
             break;
+        case CSSSelector::PseudoClass:
+            m_functionType = mostRestrictiveFunctionType(m_functionType, addPseudoType(selector->pseudoType(), fragment.pseudoClasses));
+            if (m_functionType == FunctionType::CannotCompile)
+                goto CannotHandleSelector;
+            break;
         case CSSSelector::Unknown:
         case CSSSelector::Exact:
         case CSSSelector::Set:
         case CSSSelector::List:
         case CSSSelector::Hyphen:
-        case CSSSelector::PseudoClass:
         case CSSSelector::PseudoElement:
         case CSSSelector::Contain:
         case CSSSelector::Begin:
@@ -746,6 +770,10 @@
 {
     if (fragment.tagName)
         generateElementHasTagName(failureCases, *(fragment.tagName));
+
+    if (fragment.pseudoClasses.contains(CSSSelector::PseudoFocus))
+        generateElementIsFocused(failureCases);
+
     generateElementDataMatching(failureCases, fragment);
 }
 
@@ -837,6 +865,15 @@
     }
 }
 
+void SelectorCodeGenerator::generateElementIsFocused(Assembler::JumpList& failureCases)
+{
+    Assembler::RegisterID elementAddress = elementAddressRegister;
+    FunctionCall functionCall(m_assembler, m_registerAllocator, m_stackAllocator, m_functionCalls);
+    functionCall.setFunctionAddress(SelectorChecker::matchesFocusPseudoClass);
+    functionCall.setFirstArgument(elementAddress);
+    failureCases.append(functionCall.callAndBranchOnCondition(Assembler::Zero));
+}
+
 }; // namespace SelectorCompiler.
 }; // namespace WebCore.
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to