Home | History | Annotate | Download | only in resolver
      1 /*
      2  * Copyright (C) 2013 Google, Inc.
      3  * Copyright (C) 1999 Lars Knoll (knoll (at) kde.org)
      4  * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
      5  *
      6  * This library is free software; you can redistribute it and/or
      7  * modify it under the terms of the GNU Library General Public
      8  * License as published by the Free Software Foundation; either
      9  * version 2 of the License, or (at your option) any later version.
     10  *
     11  * This library is distributed in the hope that it will be useful,
     12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     14  * Library General Public License for more details.
     15  *
     16  * You should have received a copy of the GNU Library General Public License
     17  * along with this library; see the file COPYING.LIB.  If not, write to
     18  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     19  * Boston, MA 02110-1301, USA.
     20  */
     21 
     22 #ifndef SharedStyleFinder_h
     23 #define SharedStyleFinder_h
     24 
     25 namespace WebCore {
     26 
     27 class Element;
     28 class ElementResolveContext;
     29 class Node;
     30 class RenderStyle;
     31 class RuleFeatureSet;
     32 class RuleSet;
     33 class SpaceSplitString;
     34 class StyleResolver;
     35 
     36 class SharedStyleFinder {
     37 public:
     38     // FIXME: StyleResolver* only used for calling styleSharingCandidateMatchesRuleSet.
     39     // RuleSets are passed non-const as the act of matching against them can cause them
     40     // to be compacted. :(
     41     SharedStyleFinder(const RuleFeatureSet& features, RuleSet* siblingRuleSet,
     42         RuleSet* uncommonAttributeRuleSet, StyleResolver* styleResolver)
     43         : m_elementAffectedByClassRules(false)
     44         , m_features(features)
     45         , m_siblingRuleSet(siblingRuleSet)
     46         , m_uncommonAttributeRuleSet(uncommonAttributeRuleSet)
     47         , m_styleResolver(styleResolver)
     48     { }
     49 
     50     // FIXME: It is not necessarily safe to call this method more than once.
     51     RenderStyle* locateSharedStyle(const ElementResolveContext&, RenderStyle* newStyle);
     52 
     53 private:
     54     Node* locateCousinList(Element* parent, unsigned& visitedNodeCount) const;
     55     Element* findSiblingForStyleSharing(const ElementResolveContext&, Node*, unsigned& count) const;
     56 
     57     // Only used when we're collecting stats on styles
     58     Element* searchDocumentForSharedStyle(const ElementResolveContext&) const;
     59 
     60     bool classNamesAffectedByRules(const SpaceSplitString&) const;
     61 
     62     bool canShareStyleWithElement(const ElementResolveContext&, Element*) const;
     63     bool canShareStyleWithControl(const ElementResolveContext&, Element*) const;
     64     bool sharingCandidateHasIdenticalStyleAffectingAttributes(const ElementResolveContext&, Element*) const;
     65 
     66     bool m_elementAffectedByClassRules;
     67     const RuleFeatureSet& m_features;
     68     RuleSet* m_siblingRuleSet;
     69     RuleSet* m_uncommonAttributeRuleSet;
     70     StyleResolver* m_styleResolver;
     71 };
     72 
     73 } // namespace WebCore
     74 
     75 #endif // SharedStyleFinder_h
     76