Changeset 87317 in webkit
- Timestamp:
- May 25, 2011 1:32:37 PM (13 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r87315 r87317 1 2011-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 1 23 2011-05-25 Caio Marcelo de Oliveira Filho <caio.oliveira@openbossa.org> 2 24 -
trunk/Source/WebCore/css/CSSRule.h
r72116 r87317 30 30 31 31 typedef int ExceptionCode; 32 33 enum CSSRuleFilter {34 AllCSSRules,35 SameOriginCSSRulesOnly36 };37 32 38 33 class CSSRule : public StyleBase { -
trunk/Source/WebCore/css/CSSStyleSelector.cpp
r87309 r87317 1992 1992 } 1993 1993 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)1994 PassRefPtr<CSSRuleList> CSSStyleSelector::styleRulesForElement(Element* e, unsigned rulesToInclude) 1995 { 1996 return pseudoStyleRulesForElement(e, NOPSEUDO, rulesToInclude); 1997 } 1998 1999 PassRefPtr<CSSRuleList> CSSStyleSelector::pseudoStyleRulesForElement(Element* e, PseudoId pseudoId, unsigned rulesToInclude) 2000 2000 { 2001 2001 if (!e || !e->document()->haveStylesheetsLoaded()) … … 2007 2007 initForStyleResolve(e, 0, pseudoId); 2008 2008 2009 if ( !authorOnly) {2009 if (rulesToInclude & UAAndUserCSSRules) { 2010 2010 int firstUARule = -1, lastUARule = -1; 2011 2011 // First we match rules from the user agent sheet. … … 2015 2015 if (m_matchAuthorAndUserStyles) { 2016 2016 int firstUserRule = -1, lastUserRule = -1; 2017 matchRules(m_userStyle.get(), firstUserRule, lastUserRule, includeEmptyRules);2017 matchRules(m_userStyle.get(), firstUserRule, lastUserRule, rulesToInclude & EmptyCSSRules); 2018 2018 } 2019 2019 } 2020 2020 2021 2021 if (m_matchAuthorAndUserStyles) { 2022 m_checker.m_sameOriginOnly = (filter == SameOriginCSSRulesOnly);2022 m_checker.m_sameOriginOnly = !(rulesToInclude & CrossOriginCSSRules); 2023 2023 2024 2024 // Check the rules in author sheets. 2025 2025 int firstAuthorRule = -1, lastAuthorRule = -1; 2026 matchRules(m_authorStyle.get(), firstAuthorRule, lastAuthorRule, includeEmptyRules);2026 matchRules(m_authorStyle.get(), firstAuthorRule, lastAuthorRule, rulesToInclude & EmptyCSSRules); 2027 2027 2028 2028 m_checker.m_sameOriginOnly = false; -
trunk/Source/WebCore/css/CSSStyleSelector.h
r86135 r87317 129 129 public: 130 130 // 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); 133 141 134 142 // 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 240 240 } 241 241 242 static PassRefPtr<CSSMutableStyleDeclaration> styleFromMatchedRulesForElement(Element* element , bool authorOnly = true)242 static PassRefPtr<CSSMutableStyleDeclaration> styleFromMatchedRulesForElement(Element* element) 243 243 { 244 244 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); 246 247 if (matchedRules) { 247 248 for (unsigned i = 0; i < matchedRules->length(); i++) { -
trunk/Source/WebCore/inspector/InspectorCSSAgent.cpp
r86754 r87317 200 200 201 201 CSSStyleSelector* selector = element->ownerDocument()->styleSelector(); 202 RefPtr<CSSRuleList> matchedRules = selector->styleRulesForElement(element, false, true);202 RefPtr<CSSRuleList> matchedRules = selector->styleRulesForElement(element, CSSStyleSelector::AllCSSRules); 203 203 resultObject->setArray("matchedCSSRules", buildArrayForRuleList(matchedRules.get())); 204 204 … … 207 207 RefPtr<InspectorArray> pseudoElements = InspectorArray::create(); 208 208 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); 210 210 if (matchedRules && matchedRules->length()) { 211 211 RefPtr<InspectorObject> pseudoStyles = InspectorObject::create(); … … 228 228 229 229 CSSStyleSelector* parentSelector = parentElement->ownerDocument()->styleSelector(); 230 RefPtr<CSSRuleList> parentMatchedRules = parentSelector->styleRulesForElement(parentElement, false, true);230 RefPtr<CSSRuleList> parentMatchedRules = parentSelector->styleRulesForElement(parentElement, CSSStyleSelector::AllCSSRules); 231 231 parentStyle->setArray("matchedCSSRules", buildArrayForRuleList(parentMatchedRules.get())); 232 232 inheritedStyles->pushObject(parentStyle.release()); -
trunk/Source/WebCore/page/DOMWindow.cpp
r86542 r87317 1292 1292 } 1293 1293 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); 1294 PassRefPtr<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); 1301 1308 } 1302 1309
Note: See TracChangeset
for help on using the changeset viewer.