Changeset 87317 in webkit


Ignore:
Timestamp:
May 25, 2011 1:32:37 PM (13 years ago)
Author:
rniwa@webkit.org
Message:

2011-05-25 Ryosuke Niwa <rniwa@webkit.org>

Reviewed by James Robinson.

CSSStyleSelector should provide a way to obtain rules from non-author stylesheets
https://bugs.webkit.org/show_bug.cgi?id=61454

Replaced bool and enum arguments of styleRulesForElement and pseudoStyleRulesForElement
by one enum, and provided a way to obtain rules from UA/user stylesheets.

  • css/CSSRule.h: Removed CSSRuleFilter.
  • css/CSSStyleSelector.cpp: (WebCore::CSSStyleSelector::styleRulesForElement): See above. (WebCore::CSSStyleSelector::pseudoStyleRulesForElement): Ditto.
  • css/CSSStyleSelector.h: Moved CSSRuleFilter here.
  • editing/markup.cpp: (WebCore::styleFromMatchedRulesForElement): Calls styleRulesForElement.
  • inspector/InspectorCSSAgent.cpp: (WebCore::InspectorCSSAgent::getStylesForNode): Ditto.
  • page/DOMWindow.cpp: (WebCore::DOMWindow::getMatchedCSSRules): Ditto.
Location:
trunk/Source/WebCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r87315 r87317  
     12011-05-25  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Reviewed by James Robinson.
     4
     5        CSSStyleSelector should provide a way to obtain rules from non-author stylesheets
     6        https://bugs.webkit.org/show_bug.cgi?id=61454
     7
     8        Replaced bool and enum arguments of styleRulesForElement and pseudoStyleRulesForElement
     9        by one enum, and provided a way to obtain rules from UA/user stylesheets.
     10
     11        * css/CSSRule.h: Removed CSSRuleFilter.
     12        * css/CSSStyleSelector.cpp:
     13        (WebCore::CSSStyleSelector::styleRulesForElement): See above.
     14        (WebCore::CSSStyleSelector::pseudoStyleRulesForElement): Ditto.
     15        * css/CSSStyleSelector.h: Moved CSSRuleFilter here.
     16        * editing/markup.cpp:
     17        (WebCore::styleFromMatchedRulesForElement): Calls styleRulesForElement.
     18        * inspector/InspectorCSSAgent.cpp:
     19        (WebCore::InspectorCSSAgent::getStylesForNode): Ditto.
     20        * page/DOMWindow.cpp:
     21        (WebCore::DOMWindow::getMatchedCSSRules): Ditto.
     22
    1232011-05-25  Caio Marcelo de Oliveira Filho  <caio.oliveira@openbossa.org>
    224
  • trunk/Source/WebCore/css/CSSRule.h

    r72116 r87317  
    3030
    3131typedef int ExceptionCode;
    32 
    33 enum CSSRuleFilter {
    34     AllCSSRules,
    35     SameOriginCSSRulesOnly
    36 };
    3732
    3833class CSSRule : public StyleBase {
  • trunk/Source/WebCore/css/CSSStyleSelector.cpp

    r87309 r87317  
    19921992}
    19931993
    1994 PassRefPtr<CSSRuleList> CSSStyleSelector::styleRulesForElement(Element* e, bool authorOnly, bool includeEmptyRules, CSSRuleFilter filter)
    1995 {
    1996     return pseudoStyleRulesForElement(e, NOPSEUDO, authorOnly, includeEmptyRules, filter);
    1997 }
    1998 
    1999 PassRefPtr<CSSRuleList> CSSStyleSelector::pseudoStyleRulesForElement(Element* e, PseudoId pseudoId, bool authorOnly, bool includeEmptyRules, CSSRuleFilter filter)
     1994PassRefPtr<CSSRuleList> CSSStyleSelector::styleRulesForElement(Element* e, unsigned rulesToInclude)
     1995{
     1996    return pseudoStyleRulesForElement(e, NOPSEUDO, rulesToInclude);
     1997}
     1998
     1999PassRefPtr<CSSRuleList> CSSStyleSelector::pseudoStyleRulesForElement(Element* e, PseudoId pseudoId, unsigned rulesToInclude)
    20002000{
    20012001    if (!e || !e->document()->haveStylesheetsLoaded())
     
    20072007    initForStyleResolve(e, 0, pseudoId);
    20082008
    2009     if (!authorOnly) {
     2009    if (rulesToInclude & UAAndUserCSSRules) {
    20102010        int firstUARule = -1, lastUARule = -1;
    20112011        // First we match rules from the user agent sheet.
     
    20152015        if (m_matchAuthorAndUserStyles) {
    20162016            int firstUserRule = -1, lastUserRule = -1;
    2017             matchRules(m_userStyle.get(), firstUserRule, lastUserRule, includeEmptyRules);
     2017            matchRules(m_userStyle.get(), firstUserRule, lastUserRule, rulesToInclude & EmptyCSSRules);
    20182018        }
    20192019    }
    20202020
    20212021    if (m_matchAuthorAndUserStyles) {
    2022         m_checker.m_sameOriginOnly = (filter == SameOriginCSSRulesOnly);
     2022        m_checker.m_sameOriginOnly = !(rulesToInclude & CrossOriginCSSRules);
    20232023
    20242024        // Check the rules in author sheets.
    20252025        int firstAuthorRule = -1, lastAuthorRule = -1;
    2026         matchRules(m_authorStyle.get(), firstAuthorRule, lastAuthorRule, includeEmptyRules);
     2026        matchRules(m_authorStyle.get(), firstAuthorRule, lastAuthorRule, rulesToInclude & EmptyCSSRules);
    20272027
    20282028        m_checker.m_sameOriginOnly = false;
  • trunk/Source/WebCore/css/CSSStyleSelector.h

    r86135 r87317  
    129129    public:
    130130        // These methods will give back the set of rules that matched for a given element (or a pseudo-element).
    131         PassRefPtr<CSSRuleList> styleRulesForElement(Element*, bool authorOnly, bool includeEmptyRules = false, CSSRuleFilter filter = AllCSSRules);
    132         PassRefPtr<CSSRuleList> pseudoStyleRulesForElement(Element*, PseudoId, bool authorOnly, bool includeEmptyRules = false, CSSRuleFilter filter = AllCSSRules);
     131        enum CSSRuleFilter {
     132            UAAndUserCSSRules   = 1 << 1,
     133            AuthorCSSRules      = 1 << 2,
     134            EmptyCSSRules       = 1 << 3,
     135            CrossOriginCSSRules = 1 << 4,
     136            AllButEmptyCSSRules = UAAndUserCSSRules | AuthorCSSRules | CrossOriginCSSRules,
     137            AllCSSRules         = AllButEmptyCSSRules | EmptyCSSRules,
     138        };
     139        PassRefPtr<CSSRuleList> styleRulesForElement(Element*, unsigned rulesToInclude = AllButEmptyCSSRules);
     140        PassRefPtr<CSSRuleList> pseudoStyleRulesForElement(Element*, PseudoId, unsigned rulesToInclude = AllButEmptyCSSRules);
    133141
    134142        // Given a CSS keyword in the range (xx-small to -webkit-xxx-large), this function will return
  • trunk/Source/WebCore/editing/markup.cpp

    r87082 r87317  
    240240}
    241241
    242 static PassRefPtr<CSSMutableStyleDeclaration> styleFromMatchedRulesForElement(Element* element, bool authorOnly = true)
     242static PassRefPtr<CSSMutableStyleDeclaration> styleFromMatchedRulesForElement(Element* element)
    243243{
    244244    RefPtr<CSSMutableStyleDeclaration> style = CSSMutableStyleDeclaration::create();
    245     RefPtr<CSSRuleList> matchedRules = element->document()->styleSelector()->styleRulesForElement(element, authorOnly);
     245    RefPtr<CSSRuleList> matchedRules = element->document()->styleSelector()->styleRulesForElement(element,
     246        CSSStyleSelector::AuthorCSSRules | CSSStyleSelector::CrossOriginCSSRules);
    246247    if (matchedRules) {
    247248        for (unsigned i = 0; i < matchedRules->length(); i++) {
  • trunk/Source/WebCore/inspector/InspectorCSSAgent.cpp

    r86754 r87317  
    200200
    201201    CSSStyleSelector* selector = element->ownerDocument()->styleSelector();
    202     RefPtr<CSSRuleList> matchedRules = selector->styleRulesForElement(element, false, true);
     202    RefPtr<CSSRuleList> matchedRules = selector->styleRulesForElement(element, CSSStyleSelector::AllCSSRules);
    203203    resultObject->setArray("matchedCSSRules", buildArrayForRuleList(matchedRules.get()));
    204204
     
    207207    RefPtr<InspectorArray> pseudoElements = InspectorArray::create();
    208208    for (PseudoId pseudoId = FIRST_PUBLIC_PSEUDOID; pseudoId < AFTER_LAST_INTERNAL_PSEUDOID; pseudoId = static_cast<PseudoId>(pseudoId + 1)) {
    209         RefPtr<CSSRuleList> matchedRules = selector->pseudoStyleRulesForElement(element, pseudoId, false, true);
     209        RefPtr<CSSRuleList> matchedRules = selector->pseudoStyleRulesForElement(element, pseudoId, CSSStyleSelector::AllCSSRules);
    210210        if (matchedRules && matchedRules->length()) {
    211211            RefPtr<InspectorObject> pseudoStyles = InspectorObject::create();
     
    228228
    229229        CSSStyleSelector* parentSelector = parentElement->ownerDocument()->styleSelector();
    230         RefPtr<CSSRuleList> parentMatchedRules = parentSelector->styleRulesForElement(parentElement, false, true);
     230        RefPtr<CSSRuleList> parentMatchedRules = parentSelector->styleRulesForElement(parentElement, CSSStyleSelector::AllCSSRules);
    231231        parentStyle->setArray("matchedCSSRules", buildArrayForRuleList(parentMatchedRules.get()));
    232232        inheritedStyles->pushObject(parentStyle.release());
  • trunk/Source/WebCore/page/DOMWindow.cpp

    r86542 r87317  
    12921292}
    12931293
    1294 PassRefPtr<CSSRuleList> DOMWindow::getMatchedCSSRules(Element* elt, const String&, bool authorOnly) const
    1295 {
    1296     if (!m_frame)
    1297         return 0;
    1298 
    1299     Settings* settings = m_frame->settings();
    1300     return m_frame->document()->styleSelector()->styleRulesForElement(elt, authorOnly, false, settings && settings->crossOriginCheckInGetMatchedCSSRulesDisabled() ? AllCSSRules : SameOriginCSSRulesOnly);
     1294PassRefPtr<CSSRuleList> DOMWindow::getMatchedCSSRules(Element* element, const String&, bool authorOnly) const
     1295{
     1296    if (!m_frame)
     1297        return 0;
     1298
     1299    unsigned rulesToInclude = CSSStyleSelector::AuthorCSSRules;
     1300    if (!authorOnly)
     1301        rulesToInclude |= CSSStyleSelector::UAAndUserCSSRules;
     1302    if (Settings* settings = m_frame->settings()) {
     1303        if (settings->crossOriginCheckInGetMatchedCSSRulesDisabled())
     1304            rulesToInclude |= CSSStyleSelector::CrossOriginCSSRules;
     1305    }
     1306
     1307    return m_frame->document()->styleSelector()->styleRulesForElement(element, rulesToInclude);
    13011308}
    13021309
Note: See TracChangeset for help on using the changeset viewer.