[webkit-changes] cvs commit: WebCore/kwq DOM-CSS.mm DOMCSS.h
David
hyatt at opensource.apple.com
Thu Nov 17 13:28:14 PST 2005
hyatt 05/11/17 13:28:14
Modified: . ChangeLog
khtml/css cssparser.cpp cssstyleselector.cpp
cssstyleselector.h parser.y
khtml/ecma kjs_views.cpp kjs_views.h
khtml/xml dom2_viewsimpl.cpp dom2_viewsimpl.h
kwq DOM-CSS.mm DOMCSS.h
Log:
Add support for getMatchedCSSRules, an API that can be used to
inspect the set of rules that match on an element. From Obj-C
you see all rules (user agent, author, user). From JS you just
see author rules.
Reviewed by darin
* khtml/css/cssparser.cpp:
* khtml/css/cssstyleselector.cpp:
(khtml::CSSStyleSelector::matchRules):
(khtml::CSSStyleSelector::matchRulesForList):
(khtml::CSSStyleSelector::initForStyleResolve):
(khtml::CSSStyleSelector::styleRulesForElement):
(khtml::CSSStyleSelector::pseudoStyleRulesForElement):
* khtml/css/cssstyleselector.h:
* khtml/css/parser.y:
* khtml/ecma/kjs_views.cpp:
(KJS::DOMAbstractViewProtoFunc::callAsFunction):
* khtml/ecma/kjs_views.h:
(KJS::DOMAbstractView::):
* khtml/xml/dom2_viewsimpl.cpp:
(DOM::AbstractViewImpl::getComputedStyle):
(DOM::AbstractViewImpl::getMatchedCSSRules):
* khtml/xml/dom2_viewsimpl.h:
* kwq/DOM-CSS.mm:
(-[DOMDocument getMatchedCSSRules::]):
* kwq/DOMCSS.h:
Revision Changes Path
1.377 +30 -0 WebCore/ChangeLog
Index: ChangeLog
===================================================================
RCS file: /cvs/root/WebCore/ChangeLog,v
retrieving revision 1.376
retrieving revision 1.377
diff -u -r1.376 -r1.377
--- ChangeLog 17 Nov 2005 18:44:50 -0000 1.376
+++ ChangeLog 17 Nov 2005 21:28:07 -0000 1.377
@@ -1,3 +1,33 @@
+2005-11-17 David Hyatt <hyatt at apple.com>
+
+ Add support for getMatchedCSSRules, an API that can be used to
+ inspect the set of rules that match on an element. From Obj-C
+ you see all rules (user agent, author, user). From JS you just
+ see author rules.
+
+ Reviewed by darin
+
+ * khtml/css/cssparser.cpp:
+ * khtml/css/cssstyleselector.cpp:
+ (khtml::CSSStyleSelector::matchRules):
+ (khtml::CSSStyleSelector::matchRulesForList):
+ (khtml::CSSStyleSelector::initForStyleResolve):
+ (khtml::CSSStyleSelector::styleRulesForElement):
+ (khtml::CSSStyleSelector::pseudoStyleRulesForElement):
+ * khtml/css/cssstyleselector.h:
+ * khtml/css/parser.y:
+ * khtml/ecma/kjs_views.cpp:
+ (KJS::DOMAbstractViewProtoFunc::callAsFunction):
+ * khtml/ecma/kjs_views.h:
+ (KJS::DOMAbstractView::):
+ * khtml/xml/dom2_viewsimpl.cpp:
+ (DOM::AbstractViewImpl::getComputedStyle):
+ (DOM::AbstractViewImpl::getMatchedCSSRules):
+ * khtml/xml/dom2_viewsimpl.h:
+ * kwq/DOM-CSS.mm:
+ (-[DOMDocument getMatchedCSSRules::]):
+ * kwq/DOMCSS.h:
+
2005-11-17 Beth Dakin <bdakin at apple.com>
Reviewed by Darin
1.110 +2 -1 WebCore/khtml/css/cssparser.cpp
Index: cssparser.cpp
===================================================================
RCS file: /cvs/root/WebCore/khtml/css/cssparser.cpp,v
retrieving revision 1.109
retrieving revision 1.110
diff -u -r1.109 -r1.110
--- cssparser.cpp 2 Nov 2005 08:52:39 -0000 1.109
+++ cssparser.cpp 17 Nov 2005 21:28:10 -0000 1.110
@@ -2,7 +2,8 @@
* This file is part of the DOM implementation for KDE.
*
* Copyright (C) 2003 Lars Knoll (knoll at kde.org)
- * Copyright (C) 2004 Apple Computer, Inc.
+ * Copyright (C) 2005 Allan Sandfeld Jensen (kde at carewolf.com)
+ * Copyright (C) 2004, 2005 Apple Computer, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
1.221 +54 -5 WebCore/khtml/css/cssstyleselector.cpp
Index: cssstyleselector.cpp
===================================================================
RCS file: /cvs/root/WebCore/khtml/css/cssstyleselector.cpp,v
retrieving revision 1.220
retrieving revision 1.221
diff -u -r1.220 -r1.221
--- cssstyleselector.cpp 2 Nov 2005 08:52:40 -0000 1.220
+++ cssstyleselector.cpp 17 Nov 2005 21:28:10 -0000 1.221
@@ -2,7 +2,8 @@
* This file is part of the CSS implementation for KDE.
*
* Copyright (C) 1999 Lars Knoll (knoll at kde.org)
- * Copyright (C) 2004 Apple Computer, Inc.
+ * (C) 2004-2005 Allan Sandfeld Jensen (kde at carewolf.com)
+ * Copyright (C) 2005 Apple Computer, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -377,8 +378,16 @@
sortMatchedRules(0, m_matchedRuleCount);
// Now transfer the set of matched rules over to our list of decls.
- for (unsigned i = 0; i < m_matchedRuleCount; i++)
- addMatchedDeclaration(m_matchedRules[i]->rule()->declaration());
+ if (style) {
+ for (unsigned i = 0; i < m_matchedRuleCount; i++)
+ addMatchedDeclaration(m_matchedRules[i]->rule()->declaration());
+ } else {
+ for (unsigned i = 0; i < m_matchedRuleCount; i++) {
+ if (!m_ruleList)
+ m_ruleList = new CSSRuleListImpl();
+ m_ruleList->append(m_matchedRules[i]->rule());
+ }
+ }
}
void CSSStyleSelector::matchRulesForList(CSSRuleDataList* rules,
@@ -396,7 +405,7 @@
// If we're matching normal rules, set a pseudo bit if
// we really just matched a pseudo-element.
- if (dynamicPseudo != RenderStyle::NOPSEUDO && pseudoStyle == RenderStyle::NOPSEUDO)
+ if (style && dynamicPseudo != RenderStyle::NOPSEUDO && pseudoStyle == RenderStyle::NOPSEUDO)
style->setHasPseudoStyle(dynamicPseudo);
else {
// Update our first/last rule indices in the matched rules array.
@@ -520,7 +529,8 @@
m_matchedRuleCount = 0;
m_matchedDeclCount = 0;
m_tmpRuleCount = 0;
-
+ m_ruleList = 0;
+
fontDirty = false;
}
@@ -1035,6 +1045,45 @@
view->useSlowRepaints();
}
+SharedPtr<CSSRuleListImpl> CSSStyleSelector::styleRulesForElement(ElementImpl* e, bool authorOnly)
+{
+ if (!e->getDocument()->haveStylesheetsLoaded())
+ return 0;
+
+ initElementAndPseudoState(e);
+ initForStyleResolve(e, 0);
+
+ if (!authorOnly) {
+ // First we match rules from the user agent sheet.
+ int firstUARule = -1, lastUARule = -1;
+ matchRules(defaultStyle, firstUARule, lastUARule);
+
+ // In quirks mode, we match rules from the quirks user agent sheet.
+ if (!strictParsing)
+ matchRules(defaultQuirksStyle, firstUARule, lastUARule);
+
+ // If our medium is print, then we match rules from the print sheet.
+ if (m_medium == "print")
+ matchRules(defaultPrintStyle, firstUARule, lastUARule);
+
+ // Now we check user sheet rules.
+ int firstUserRule = -1, lastUserRule = -1;
+ matchRules(m_userStyle, firstUserRule, lastUserRule);
+ }
+
+ // Check the rules in author sheets.
+ int firstAuthorRule = -1, lastAuthorRule = -1;
+ matchRules(m_authorStyle, firstAuthorRule, lastAuthorRule);
+
+ return m_ruleList;
+}
+
+SharedPtr<CSSRuleListImpl> CSSStyleSelector::pseudoStyleRulesForElement(ElementImpl* e, DOMStringImpl* pseudoStyle, bool authorOnly)
+{
+ // FIXME: Implement this.
+ return 0;
+}
+
static bool subject;
bool CSSStyleSelector::checkSelector(CSSSelector* sel, ElementImpl *e)
1.43 +6 -1 WebCore/khtml/css/cssstyleselector.h
Index: cssstyleselector.h
===================================================================
RCS file: /cvs/root/WebCore/khtml/css/cssstyleselector.h,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -r1.42 -r1.43
--- cssstyleselector.h 30 Oct 2005 05:26:26 -0000 1.42
+++ cssstyleselector.h 17 Nov 2005 21:28:10 -0000 1.43
@@ -114,6 +114,10 @@
DOM::NodeImpl* locateCousinList(DOM::ElementImpl* parent);
bool canShareStyleWithElement(DOM::NodeImpl* n);
+ // These methods will give back the set of rules that matched for a given element (or a pseudo-element).
+ SharedPtr<DOM::CSSRuleListImpl> styleRulesForElement(DOM::ElementImpl* e, bool authorOnly);
+ SharedPtr<DOM::CSSRuleListImpl> pseudoStyleRulesForElement(DOM::ElementImpl* e, DOM::DOMStringImpl* pseudoStyle, bool authorOnly);
+
bool strictParsing;
struct Encodedurl {
@@ -209,7 +213,8 @@
unsigned m_matchedRuleCount;
QMemArray<CSSRuleData*> m_tmpRules;
unsigned m_tmpRuleCount;
-
+ DOM::CSSRuleListImpl* m_ruleList;
+
QString m_medium;
RenderStyle::PseudoId dynamicPseudo;
1.46 +1 -1 WebCore/khtml/css/parser.y
Index: parser.y
===================================================================
RCS file: /cvs/root/WebCore/khtml/css/parser.y,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -r1.45 -r1.46
--- parser.y 3 Oct 2005 21:12:08 -0000 1.45
+++ parser.y 17 Nov 2005 21:28:10 -0000 1.46
@@ -38,7 +38,7 @@
// #define CSS_DEBUG
using namespace DOM;
- using namespace HTMLNames;
+using namespace HTMLNames;
//
// The following file defines the function
1.16 +12 -1 WebCore/khtml/ecma/kjs_views.cpp
Index: kjs_views.cpp
===================================================================
RCS file: /cvs/root/WebCore/khtml/ecma/kjs_views.cpp,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- kjs_views.cpp 4 Oct 2005 06:11:35 -0000 1.15
+++ kjs_views.cpp 17 Nov 2005 21:28:12 -0000 1.16
@@ -32,7 +32,7 @@
using DOM::DocumentImpl;
using DOM::ElementImpl;
using DOM::NodeImpl;
-
+using DOM::CSSRuleListImpl;
#include "kjs_views.lut.h"
@@ -47,6 +47,7 @@
@end
@begin DOMAbstractViewProtoTable 1
getComputedStyle DOMAbstractView::GetComputedStyle DontDelete|Function 2
+ getMatchedCSSRules DOMAbstractView::GetMatchedCSSRules DontDelete|Function 2
@end
*/
@@ -92,6 +93,16 @@
return getDOMCSSStyleDeclaration(exec, abstractView.getComputedStyle(arg0, args[1]->toString(exec).domString().impl()));
}
}
+ case DOMAbstractView::GetMatchedCSSRules: {
+ ElementImpl *arg0 = toElement(args[0]);
+ if (!arg0)
+ return Undefined(); // throw exception?
+ else {
+ // No need to update layout, since we just want the back-end rules.
+ return getDOMCSSRuleList(exec, abstractView.getMatchedCSSRules(arg0, args[1]->toString(exec).domString().impl()).get());
+ }
+ }
+
}
return Undefined();
}
1.11 +1 -1 WebCore/khtml/ecma/kjs_views.h
Index: kjs_views.h
===================================================================
RCS file: /cvs/root/WebCore/khtml/ecma/kjs_views.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- kjs_views.h 4 Oct 2005 06:11:36 -0000 1.10
+++ kjs_views.h 17 Nov 2005 21:28:12 -0000 1.11
@@ -39,7 +39,7 @@
virtual const ClassInfo* classInfo() const { return &info; }
static const ClassInfo info;
DOM::AbstractViewImpl *impl() const { return m_impl.get(); }
- enum { Document, GetComputedStyle };
+ enum { Document, GetComputedStyle, GetMatchedCSSRules };
private:
SharedPtr<DOM::AbstractViewImpl> m_impl;
};
1.7 +10 -1 WebCore/khtml/xml/dom2_viewsimpl.cpp
Index: dom2_viewsimpl.cpp
===================================================================
RCS file: /cvs/root/WebCore/khtml/xml/dom2_viewsimpl.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- dom2_viewsimpl.cpp 3 Oct 2005 21:12:51 -0000 1.6
+++ dom2_viewsimpl.cpp 17 Nov 2005 21:28:13 -0000 1.7
@@ -26,6 +26,8 @@
#include "css/css_computedstyle.h"
#include "dom_elementimpl.h"
+#include "dom_docimpl.h"
+#include "cssstyleselector.h"
namespace DOM {
@@ -41,11 +43,18 @@
CSSStyleDeclarationImpl *AbstractViewImpl::getComputedStyle(ElementImpl *elt, DOMStringImpl *pseudoElt)
{
// FIXME: This should work even if we do not have a renderer.
-
+ // FIXME: This needs to work with pseudo elements.
if (!elt || !elt->renderer())
return 0;
return new CSSComputedStyleDeclarationImpl(elt);
}
+SharedPtr<CSSRuleListImpl> AbstractViewImpl::getMatchedCSSRules(ElementImpl* elt, DOMStringImpl* pseudoElt, bool authorOnly)
+{
+ if (pseudoElt && pseudoElt->l)
+ return m_document->styleSelector()->pseudoStyleRulesForElement(elt, pseudoElt, authorOnly);
+ return m_document->styleSelector()->styleRulesForElement(elt, authorOnly);
+}
+
}
1.9 +3 -0 WebCore/khtml/xml/dom2_viewsimpl.h
Index: dom2_viewsimpl.h
===================================================================
RCS file: /cvs/root/WebCore/khtml/xml/dom2_viewsimpl.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- dom2_viewsimpl.h 3 Oct 2005 21:12:51 -0000 1.8
+++ dom2_viewsimpl.h 17 Nov 2005 21:28:13 -0000 1.9
@@ -30,6 +30,7 @@
class DocumentImpl;
class CSSStyleDeclarationImpl;
+class CSSRuleListImpl;
class ElementImpl;
class DOMStringImpl;
@@ -42,6 +43,8 @@
DocumentImpl *document() const { return m_document; }
CSSStyleDeclarationImpl *getComputedStyle(ElementImpl *elt, DOMStringImpl *pseudoElt);
+ SharedPtr<CSSRuleListImpl> getMatchedCSSRules(ElementImpl* elt, DOMStringImpl* pseudoElt, bool authorOnly = true);
+
protected:
DocumentImpl *m_document;
};
1.30 +7 -0 WebCore/kwq/DOM-CSS.mm
Index: DOM-CSS.mm
===================================================================
RCS file: /cvs/root/WebCore/kwq/DOM-CSS.mm,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- DOM-CSS.mm 3 Oct 2005 21:12:59 -0000 1.29
+++ DOM-CSS.mm 17 Nov 2005 21:28:13 -0000 1.30
@@ -2538,4 +2538,11 @@
AbstractViewImpl([self _documentImpl]).getComputedStyle([elt _elementImpl], DOMString(pseudoElt).impl())];
}
+- (DOMCSSRuleList *)getMatchedCSSRules:(DOMElement *)elt :(NSString *)pseudoElt
+{
+ // The parameter of "false" is handy for the DOM inspector and lets us see user agent and user rules.
+ return [DOMCSSRuleList _ruleListWithImpl:
+ AbstractViewImpl([self _documentImpl]).getMatchedCSSRules([elt _elementImpl], DOMString(pseudoElt).impl(), false).get()];
+}
+
@end
1.6 +1 -0 WebCore/kwq/DOMCSS.h
Index: DOMCSS.h
===================================================================
RCS file: /cvs/root/WebCore/kwq/DOMCSS.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DOMCSS.h 16 Sep 2005 22:42:23 -0000 1.5
+++ DOMCSS.h 17 Nov 2005 21:28:13 -0000 1.6
@@ -456,6 +456,7 @@
@interface DOMDocument (DOMViewCSS)
- (DOMCSSStyleDeclaration *)getComputedStyle:(DOMElement *)elt :(NSString *)pseudoElt;
+- (DOMCSSRuleList *)getMatchedCSSRules:(DOMElement *)elt :(NSString *)pseudoElt;
@end
@interface DOMDocument (DOMDocumentCSS)
More information about the webkit-changes
mailing list