Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 Google, Inc. |
| 3 | * Copyright (C) 1999 Lars Knoll (knoll@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 | |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 25 | #include "core/css/resolver/ElementResolveContext.h" |
| 26 | #include "core/dom/Element.h" |
| 27 | |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 28 | namespace WebCore { |
| 29 | |
| 30 | class Element; |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 31 | class Node; |
| 32 | class RenderStyle; |
| 33 | class RuleFeatureSet; |
| 34 | class RuleSet; |
| 35 | class SpaceSplitString; |
| 36 | class StyleResolver; |
| 37 | |
| 38 | class SharedStyleFinder { |
Ben Murdoch | aafa69c | 2014-04-03 12:30:15 +0100 | [diff] [blame] | 39 | STACK_ALLOCATED(); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 40 | public: |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 41 | // RuleSets are passed non-const as the act of matching against them can cause them |
| 42 | // to be compacted. :( |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 43 | SharedStyleFinder(const ElementResolveContext& context, |
| 44 | const RuleFeatureSet& features, RuleSet* siblingRuleSet, |
| 45 | RuleSet* uncommonAttributeRuleSet, StyleResolver& styleResolver) |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 46 | : m_elementAffectedByClassRules(false) |
| 47 | , m_features(features) |
| 48 | , m_siblingRuleSet(siblingRuleSet) |
| 49 | , m_uncommonAttributeRuleSet(uncommonAttributeRuleSet) |
| 50 | , m_styleResolver(styleResolver) |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 51 | , m_context(context) |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 52 | { } |
| 53 | |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 54 | RenderStyle* findSharedStyle(); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 55 | |
| 56 | private: |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 57 | Element* findElementForStyleSharing() const; |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 58 | |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 59 | // Only used when we're collecting stats on styles. |
| 60 | bool documentContainsValidCandidate() const; |
Ben Murdoch | 7757ec2 | 2013-07-23 11:17:36 +0100 | [diff] [blame] | 61 | |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 62 | bool classNamesAffectedByRules(const SpaceSplitString&) const; |
| 63 | |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 64 | bool canShareStyleWithElement(Element& candidate) const; |
| 65 | bool canShareStyleWithControl(Element& candidate) const; |
| 66 | bool sharingCandidateHasIdenticalStyleAffectingAttributes(Element& candidate) const; |
Ben Murdoch | 6f543c7 | 2014-04-16 11:17:22 +0100 | [diff] [blame] | 67 | bool sharingCandidateCanShareHostStyles(Element& candidate) const; |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 68 | bool sharingCandidateDistributedToSameInsertionPoint(Element& candidate) const; |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 69 | bool matchesRuleSet(RuleSet*); |
| 70 | |
| 71 | Element& element() const { return *m_context.element(); } |
| 72 | Document& document() const { return element().document(); } |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 73 | |
| 74 | bool m_elementAffectedByClassRules; |
| 75 | const RuleFeatureSet& m_features; |
Ben Murdoch | aafa69c | 2014-04-03 12:30:15 +0100 | [diff] [blame] | 76 | RawPtrWillBeMember<RuleSet> m_siblingRuleSet; |
| 77 | RawPtrWillBeMember<RuleSet> m_uncommonAttributeRuleSet; |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 78 | StyleResolver& m_styleResolver; |
| 79 | const ElementResolveContext& m_context; |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 80 | }; |
| 81 | |
| 82 | } // namespace WebCore |
| 83 | |
| 84 | #endif // SharedStyleFinder_h |