This source file includes following definitions.
- comparePageRules
- isLeftPage
- isFirstPage
- pageName
- m_pageName
- matchPageRules
- checkPageSelectorComponents
- matchPageRulesForList
#include "config.h"
#include "core/css/PageRuleCollector.h"
#include "core/css/StylePropertySet.h"
#include "core/css/StyleRule.h"
#include "core/css/resolver/StyleResolverState.h"
namespace WebCore {
static inline bool comparePageRules(const StyleRulePage* r1, const StyleRulePage* r2)
{
return r1->selector()->specificity() < r2->selector()->specificity();
}
bool PageRuleCollector::isLeftPage(const RenderStyle* rootElementStyle, int pageIndex) const
{
bool isFirstPageLeft = false;
ASSERT(rootElementStyle);
if (!rootElementStyle->isLeftToRightDirection())
isFirstPageLeft = true;
return (pageIndex + (isFirstPageLeft ? 1 : 0)) % 2;
}
bool PageRuleCollector::isFirstPage(int pageIndex) const
{
return (!pageIndex);
}
String PageRuleCollector::pageName(int ) const
{
return "";
}
PageRuleCollector::PageRuleCollector(const RenderStyle* rootElementStyle, int pageIndex)
: m_isLeftPage(isLeftPage(rootElementStyle, pageIndex))
, m_isFirstPage(isFirstPage(pageIndex))
, m_pageName(pageName(pageIndex)) { }
void PageRuleCollector::matchPageRules(RuleSet* rules)
{
if (!rules)
return;
rules->compactRulesIfNeeded();
WillBeHeapVector<RawPtrWillBeMember<StyleRulePage> > matchedPageRules;
matchPageRulesForList(matchedPageRules, rules->pageRules(), m_isLeftPage, m_isFirstPage, m_pageName);
if (matchedPageRules.isEmpty())
return;
std::stable_sort(matchedPageRules.begin(), matchedPageRules.end(), comparePageRules);
for (unsigned i = 0; i < matchedPageRules.size(); i++)
m_result.addMatchedProperties(&matchedPageRules[i]->properties());
}
static bool checkPageSelectorComponents(const CSSSelector* selector, bool isLeftPage, bool isFirstPage, const String& pageName)
{
for (const CSSSelector* component = selector; component; component = component->tagHistory()) {
if (component->m_match == CSSSelector::Tag) {
const AtomicString& localName = component->tagQName().localName();
if (localName != starAtom && localName != pageName)
return false;
}
CSSSelector::PseudoType pseudoType = component->pseudoType();
if ((pseudoType == CSSSelector::PseudoLeftPage && !isLeftPage)
|| (pseudoType == CSSSelector::PseudoRightPage && isLeftPage)
|| (pseudoType == CSSSelector::PseudoFirstPage && !isFirstPage))
{
return false;
}
}
return true;
}
void PageRuleCollector::matchPageRulesForList(WillBeHeapVector<RawPtrWillBeMember<StyleRulePage> >& matchedRules, const WillBeHeapVector<RawPtrWillBeMember<StyleRulePage> >& rules, bool isLeftPage, bool isFirstPage, const String& pageName)
{
for (unsigned i = 0; i < rules.size(); ++i) {
StyleRulePage* rule = rules[i];
if (!checkPageSelectorComponents(rule->selector(), isLeftPage, isFirstPage, pageName))
continue;
const StylePropertySet& properties = rule->properties();
if (properties.isEmpty())
continue;
matchedRules.append(rule);
}
}
}