[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc
apavlov at chromium.org
apavlov at chromium.org
Wed Dec 22 15:41:55 UTC 2010
The following commit has been merged in the debian/experimental branch:
commit 6dbb39d61da5c9f031532d511866997d1b10d7e6
Author: apavlov at chromium.org <apavlov at chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Wed Nov 10 17:12:45 2010 +0000
2010-11-02 Alexander Pavlov <apavlov at chromium.org>
Reviewed by Pavel Feldman.
Web Inspector: Enable InspectorCSSAgent (not used by frontend for CSS editing yet)
https://bugs.webkit.org/show_bug.cgi?id=48834
Drive-by fix: use a single API method to retrieve all node-related styles instead of a bunch of separate calls.
Test: inspector/styles-new-API.html
WebCore:
* inspector/CodeGeneratorInspector.pm:
* inspector/Inspector.idl:
* inspector/InspectorCSSAgent.cpp:
(WebCore::InspectorCSSAgent::InspectorCSSAgent):
(WebCore::InspectorCSSAgent::setDOMAgent):
(WebCore::InspectorCSSAgent::reset):
(WebCore::InspectorCSSAgent::getStylesForNode2):
(WebCore::InspectorCSSAgent::getComputedStyleForNode2):
(WebCore::InspectorCSSAgent::addRule2):
(WebCore::InspectorCSSAgent::querySelectorAll):
* inspector/InspectorCSSAgent.h:
* inspector/InspectorController.cpp:
(WebCore::InspectorController::InspectorController):
(WebCore::InspectorController::connectFrontend):
(WebCore::InspectorController::releaseFrontendLifetimeAgents):
(WebCore::InspectorController::didCommitLoad):
* inspector/InspectorController.h:
(WebCore::InspectorController::cssAgent):
* inspector/InspectorDOMAgent.cpp:
* inspector/InspectorDOMAgent.h:
* inspector/InspectorStyleSheet.cpp:
(WebCore::InspectorStyle::setPropertyText):
(WebCore::InspectorStyle::styleText):
(WebCore::InspectorStyle::disableProperty):
(WebCore::InspectorStyle::populateAllProperties):
(WebCore::InspectorStyle::populateObjectWithStyleProperties):
(WebCore::InspectorStyleSheet::buildObjectForRule):
(WebCore::InspectorStyleSheet::fixUnparsedPropertyRanges):
(WebCore::InspectorStyleSheet::ensureSourceData):
(WebCore::InspectorStyleSheetForInlineStyle::text):
* inspector/InspectorStyleSheet.h:
(WebCore::InspectorStyleProperty::setRawTextFromStyleDeclaration):
(WebCore::InspectorStyleProperty::hasRawText):
LayoutTests:
* inspector/resources/styles-new-API.css: Added.
(html):
(body):
(/* comment before selector */body.main1/* comment after selector */):
(body.main2):
(body::after):
(h1):
* inspector/styles-new-API-expected.txt: Added.
* inspector/styles-new-API.html: Added.
* inspector/styles-source-offsets-expected.txt:
* inspector/styles-source-offsets.html:
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@71745 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index 382f1d7..7cd17d5 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,22 @@
+2010-11-02 Alexander Pavlov <apavlov at chromium.org>
+
+ Reviewed by Pavel Feldman.
+
+ Web Inspector: Enable InspectorCSSAgent (not used by frontend for CSS editing yet)
+ https://bugs.webkit.org/show_bug.cgi?id=48834
+
+ * inspector/resources/styles-new-API.css: Added.
+ (html):
+ (body):
+ (/* comment before selector */body.main1/* comment after selector */):
+ (body.main2):
+ (body::after):
+ (h1):
+ * inspector/styles-new-API-expected.txt: Added.
+ * inspector/styles-new-API.html: Added.
+ * inspector/styles-source-offsets-expected.txt:
+ * inspector/styles-source-offsets.html:
+
2010-11-10 Mihai Parparita <mihaip at chromium.org>
Unreviwed, updating Chromium GPU test expectations.
diff --git a/LayoutTests/inspector/styles-source-offsets-expected.txt b/LayoutTests/inspector/styles-source-offsets-expected.txt
index e4d33d8..beec728 100644
--- a/LayoutTests/inspector/styles-source-offsets-expected.txt
+++ b/LayoutTests/inspector/styles-source-offsets-expected.txt
@@ -1,6 +1,6 @@
Tests that proper data and start/end offset positions are reported for CSS style declarations and properties.
-body: [6-266]
+body: [0-4] [6-266]
['font-size':'12px'] @[5-21]
['foo':'bar !
@@ -9,15 +9,15 @@ body: [6-266]
['colorz':'"!important"' non-parsed] @[138-159]
['important':'' non-parsed] @[164-174]
['color':'"badcolor" ! important /* good property with strange value */' !important] @[190-259]
-body.main1: [337-418]
+body.main1: [298-336] [337-418]
['color':'#F00BAA'] @[13-28]
['zoo':'moo /* not an !important unrecognized property */' non-parsed] @[28-81]
-body.main2: [445-540]
+body.main2: [434-444] [445-540]
['background':'green /* value !important comment */ !important /* no semicolon, very !important */' !important] @[0-95]
-body.mainpage: [17-149]
+body.mainpage: [2-15] [17-149]
['text-decoration':'none'] @[5-27]
['badproperty':'1badvalue1' non-parsed] @[107-131]
-element.style: [0-31]
+element.style: [0-0] [0-31]
['font-weight':'normal'] @[0-20]
['width':'80%'] @[21-31]
diff --git a/LayoutTests/inspector/styles-source-offsets.html b/LayoutTests/inspector/styles-source-offsets.html
index 15a3727..979d02b 100644
--- a/LayoutTests/inspector/styles-source-offsets.html
+++ b/LayoutTests/inspector/styles-source-offsets.html
@@ -43,7 +43,7 @@ function frontend_runTest(testController)
function frontend_styleDataReceived(testController, ruleOrStyle, shouldBail, data)
{
var isRule = !!(ruleOrStyle.style);
- testController.results.push((isRule ? ruleOrStyle.selectorText : "element.style") + ": [" + data.bodyRange.start + "-" + data.bodyRange.end + "]");
+ testController.results.push((isRule ? ruleOrStyle.selectorText : "element.style") + ": [" + data.selectorRange.start + "-" + data.selectorRange.end + "] [" + data.bodyRange.start + "-" + data.bodyRange.end + "]");
for (var i = 0; i < data.propertyData.length; ++i) {
var propertyDatum = data.propertyData[i];
testController.results.push("['" + propertyDatum.name + "':'" + propertyDatum.value + "'" + (propertyDatum.important ? " !important" : "") + (propertyDatum.parsed ? "" : " non-parsed") +"] @[" + propertyDatum.start + "-" + propertyDatum.end + "]");
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 04a8f3f..d2149ec 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,48 @@
+2010-11-02 Alexander Pavlov <apavlov at chromium.org>
+
+ Reviewed by Pavel Feldman.
+
+ Web Inspector: Enable InspectorCSSAgent (not used by frontend for CSS editing yet)
+ https://bugs.webkit.org/show_bug.cgi?id=48834
+
+ Drive-by fix: use a single API method to retrieve all node-related styles instead of a bunch of separate calls.
+
+ Test: inspector/styles-new-API.html
+
+ * inspector/CodeGeneratorInspector.pm:
+ * inspector/Inspector.idl:
+ * inspector/InspectorCSSAgent.cpp:
+ (WebCore::InspectorCSSAgent::InspectorCSSAgent):
+ (WebCore::InspectorCSSAgent::setDOMAgent):
+ (WebCore::InspectorCSSAgent::reset):
+ (WebCore::InspectorCSSAgent::getStylesForNode2):
+ (WebCore::InspectorCSSAgent::getComputedStyleForNode2):
+ (WebCore::InspectorCSSAgent::addRule2):
+ (WebCore::InspectorCSSAgent::querySelectorAll):
+ * inspector/InspectorCSSAgent.h:
+ * inspector/InspectorController.cpp:
+ (WebCore::InspectorController::InspectorController):
+ (WebCore::InspectorController::connectFrontend):
+ (WebCore::InspectorController::releaseFrontendLifetimeAgents):
+ (WebCore::InspectorController::didCommitLoad):
+ * inspector/InspectorController.h:
+ (WebCore::InspectorController::cssAgent):
+ * inspector/InspectorDOMAgent.cpp:
+ * inspector/InspectorDOMAgent.h:
+ * inspector/InspectorStyleSheet.cpp:
+ (WebCore::InspectorStyle::setPropertyText):
+ (WebCore::InspectorStyle::styleText):
+ (WebCore::InspectorStyle::disableProperty):
+ (WebCore::InspectorStyle::populateAllProperties):
+ (WebCore::InspectorStyle::populateObjectWithStyleProperties):
+ (WebCore::InspectorStyleSheet::buildObjectForRule):
+ (WebCore::InspectorStyleSheet::fixUnparsedPropertyRanges):
+ (WebCore::InspectorStyleSheet::ensureSourceData):
+ (WebCore::InspectorStyleSheetForInlineStyle::text):
+ * inspector/InspectorStyleSheet.h:
+ (WebCore::InspectorStyleProperty::setRawTextFromStyleDeclaration):
+ (WebCore::InspectorStyleProperty::hasRawText):
+
2010-11-10 Alexander Pavlov <apavlov at chromium.org>
Reviewed by Yury Semikhatsky.
diff --git a/WebCore/inspector/CodeGeneratorInspector.pm b/WebCore/inspector/CodeGeneratorInspector.pm
index 3a8a6cb..f5f2453 100644
--- a/WebCore/inspector/CodeGeneratorInspector.pm
+++ b/WebCore/inspector/CodeGeneratorInspector.pm
@@ -38,6 +38,11 @@ $typeTransform{"DOM"} = {
"header" => "InspectorDOMAgent.h",
"domainAccessor" => "m_inspectorController->domAgent()",
};
+$typeTransform{"CSS"} = {
+ "forward" => "InspectorCSSAgent",
+ "header" => "InspectorCSSAgent.h",
+ "domainAccessor" => "m_inspectorController->cssAgent()",
+};
$typeTransform{"ApplicationCache"} = {
"forward" => "InspectorApplicationCacheAgent",
"header" => "InspectorApplicationCacheAgent.h",
diff --git a/WebCore/inspector/Inspector.idl b/WebCore/inspector/Inspector.idl
index 93d5396..29a3ba0 100644
--- a/WebCore/inspector/Inspector.idl
+++ b/WebCore/inspector/Inspector.idl
@@ -207,7 +207,19 @@ module core {
[handler=DOM] void toggleStyleEnabled(in long styleId, in String propertyName, in boolean disabled, out Value style);
[handler=DOM] void setRuleSelector(in long ruleId, in String selector, in long selectedNodeId, out Value rule, out boolean selectorAffectsNode);
[handler=DOM] void addRule(in String selector, in long selectedNodeId, out Value rule, out boolean selectorAffectsNode);
- [handler=DOM] void getSupportedCSSProperties(out Array cssProperties);
+
+ [handler=CSS] void getStylesForNode2(in long nodeId, out Value styles);
+ [handler=CSS] void getComputedStyleForNode2(in long nodeId, out Value style);
+ [handler=CSS] void getInlineStyleForNode2(in long nodeId, out Value style);
+ [handler=CSS] void getAllStyles2(out Array styleSheetIds);
+ [handler=CSS] void getStyleSheet2(in String styleSheetId, out Value styleSheet);
+ [handler=CSS] void setStyleSheetText2(in String styleSheetId, in String text);
+ [handler=CSS] void setPropertyText2(in String styleId, in long propertyIndex, in String text, in boolean overwrite, out Value style);
+ [handler=CSS] void toggleProperty2(in String styleId, in long propertyIndex, in boolean disable, out Value style);
+ [handler=CSS] void setRuleSelector2(in String ruleId, in String selector, out Value rule);
+ [handler=CSS] void addRule2(in long contextNodeId, in String selector, out Value rule);
+ [handler=CSS] void getSupportedCSSProperties(out Array cssProperties);
+ [handler=CSS] void querySelectorAll(in long documentId, in String selector, out Array result);
[handler=Controller] void getCookies(out Array cookies, out String cookiesString);
[handler=Controller] void deleteCookie(in String cookieName, in String domain);
diff --git a/WebCore/inspector/InspectorCSSAgent.cpp b/WebCore/inspector/InspectorCSSAgent.cpp
index d1f7412..37bf2b3 100644
--- a/WebCore/inspector/InspectorCSSAgent.cpp
+++ b/WebCore/inspector/InspectorCSSAgent.cpp
@@ -86,7 +86,12 @@
// shorthandName2 : shorthandValue2
// },
// cssText : <string>, // Optional - declaration text
-// properties : { width, height }
+// properties : {
+// width,
+// height,
+// startOffset, // Optional - for source-based styles only
+// endOffset, // Optional - for source-based styles only
+// }
// }
//
// cssRule = {
@@ -95,7 +100,8 @@
// sourceURL : <string>,
// sourceLine : <string>,
// origin : <string>, // "" || "user-agent" || "user" || "inspector"
-// style : #cssStyle
+// style : #cssStyle,
+// selectorRange: { start: <number>, end: <number> } // Optional - for source-based rules only
// }
//
// cssStyleSheet = {
@@ -137,14 +143,12 @@ CSSStyleRule* InspectorCSSAgent::asCSSStyleRule(StyleBase* styleBase)
return static_cast<CSSStyleRule*>(rule);
}
-InspectorCSSAgent::InspectorCSSAgent(InspectorDOMAgent* domAgent, InspectorFrontend* frontend)
- : m_domAgent(domAgent)
- , m_frontend(frontend)
+InspectorCSSAgent::InspectorCSSAgent()
+ : m_domAgent(0)
, m_lastStyleSheetId(1)
, m_lastRuleId(1)
, m_lastStyleId(1)
{
- m_domAgent->setDOMListener(this);
}
InspectorCSSAgent::~InspectorCSSAgent()
@@ -152,47 +156,76 @@ InspectorCSSAgent::~InspectorCSSAgent()
reset();
}
+void InspectorCSSAgent::setDOMAgent(InspectorDOMAgent* domAgent)
+{
+ if (m_domAgent)
+ m_domAgent->setDOMListener(0);
+ m_domAgent = domAgent;
+ if (m_domAgent)
+ m_domAgent->setDOMListener(this);
+}
+
void InspectorCSSAgent::reset()
{
- m_domAgent->setDOMListener(0);
+ m_idToInspectorStyleSheet.clear();
+ m_cssStyleSheetToInspectorStyleSheet.clear();
+ m_nodeToInspectorStyleSheet.clear();
+ m_documentToInspectorStyleSheet.clear();
}
-void InspectorCSSAgent::getMatchedRulesForNode2(long nodeId, RefPtr<InspectorArray>* result)
+void InspectorCSSAgent::getStylesForNode2(long nodeId, RefPtr<InspectorValue>* result)
{
Element* element = elementForId(nodeId);
if (!element)
return;
+ RefPtr<InspectorObject> resultObject = InspectorObject::create();
+
+ InspectorStyleSheetForInlineStyle* styleSheet = asInspectorStyleSheet(element);
+ if (styleSheet)
+ resultObject->setObject("inlineStyle", styleSheet->buildObjectForStyle(element->style()));
+
+ RefPtr<CSSComputedStyleDeclaration> computedStyleInfo = computedStyle(element, true); // Support the viewing of :visited information in computed style.
+ RefPtr<InspectorStyle> computedInspectorStyle = InspectorStyle::create(InspectorCSSId(), computedStyleInfo.get(), 0);
+ resultObject->setObject("computedStyle", computedInspectorStyle->buildObjectForStyle());
+
CSSStyleSelector* selector = element->ownerDocument()->styleSelector();
RefPtr<CSSRuleList> matchedRules = selector->styleRulesForElement(element, false, true);
- *result = buildArrayForRuleList(matchedRules.get());
-}
+ resultObject->setArray("matchedCSSRules", buildArrayForRuleList(matchedRules.get()));
-void InspectorCSSAgent::getMatchedPseudoRulesForNode2(long nodeId, RefPtr<InspectorArray>* result)
-{
- Element* element = elementForId(nodeId);
- if (!element)
- return;
+ resultObject->setObject("styleAttributes", buildObjectForAttributeStyles(element));
- CSSStyleSelector* selector = element->ownerDocument()->styleSelector();
+ RefPtr<InspectorArray> pseudoElements = InspectorArray::create();
for (PseudoId pseudoId = FIRST_PUBLIC_PSEUDOID; pseudoId < AFTER_LAST_INTERNAL_PSEUDOID; pseudoId = static_cast<PseudoId>(pseudoId + 1)) {
RefPtr<CSSRuleList> matchedRules = selector->pseudoStyleRulesForElement(element, pseudoId, false, true);
if (matchedRules && matchedRules->length()) {
RefPtr<InspectorObject> pseudoStyles = InspectorObject::create();
pseudoStyles->setNumber("pseudoId", static_cast<int>(pseudoId));
pseudoStyles->setArray("rules", buildArrayForRuleList(matchedRules.get()));
- (*result)->pushObject(pseudoStyles.release());
+ pseudoElements->pushObject(pseudoStyles.release());
}
}
-}
+ resultObject->setArray("pseudoElements", pseudoElements.release());
-void InspectorCSSAgent::getAttributeStylesForNode2(long nodeId, RefPtr<InspectorValue>* result)
-{
- Element* element = elementForId(nodeId);
- if (!element)
- return;
+ RefPtr<InspectorArray> inheritedStyles = InspectorArray::create();
+ Element* parentElement = element->parentElement();
+ while (parentElement) {
+ RefPtr<InspectorObject> parentStyle = InspectorObject::create();
+ if (parentElement->style() && parentElement->style()->length()) {
+ InspectorStyleSheetForInlineStyle* styleSheet = asInspectorStyleSheet(parentElement);
+ if (styleSheet)
+ parentStyle->setObject("inlineStyle", styleSheet->buildObjectForStyle(styleSheet->styleForId(InspectorCSSId::createFromParts(styleSheet->id(), "0"))));
+ }
+
+ CSSStyleSelector* parentSelector = parentElement->ownerDocument()->styleSelector();
+ RefPtr<CSSRuleList> parentMatchedRules = parentSelector->styleRulesForElement(parentElement, false, true);
+ parentStyle->setArray("matchedCSSRules", buildArrayForRuleList(parentMatchedRules.get()));
+ inheritedStyles->pushObject(parentStyle.release());
+ parentElement = parentElement->parentElement();
+ }
+ resultObject->setArray("inherited", inheritedStyles.release());
- *result = buildObjectForAttributeStyles(element);
+ *result = resultObject.release();
}
void InspectorCSSAgent::getInlineStyleForNode2(long nodeId, RefPtr<InspectorValue>* style)
@@ -214,42 +247,11 @@ void InspectorCSSAgent::getComputedStyleForNode2(long nodeId, RefPtr<InspectorVa
if (!element)
return;
- DOMWindow* defaultView = element->ownerDocument()->defaultView();
- if (!defaultView)
- return;
-
- RefPtr<CSSStyleDeclaration> computedStyle = defaultView->getComputedStyle(element, "");
- Vector<InspectorStyleProperty> properties;
- RefPtr<InspectorStyle> inspectorStyle = InspectorStyle::create(InspectorCSSId(), computedStyle.get(), 0);
+ RefPtr<CSSComputedStyleDeclaration> computedStyleInfo = computedStyle(element, true);
+ RefPtr<InspectorStyle> inspectorStyle = InspectorStyle::create(InspectorCSSId(), computedStyleInfo.get(), 0);
*style = inspectorStyle->buildObjectForStyle();
}
-void InspectorCSSAgent::getInheritedStylesForNode2(long nodeId, RefPtr<InspectorArray>* style)
-{
- Element* element = elementForId(nodeId);
- if (!element) {
- *style = InspectorArray::create();
- return;
- }
- RefPtr<InspectorArray> inheritedStyles = InspectorArray::create();
- Element* parentElement = element->parentElement();
- while (parentElement) {
- RefPtr<InspectorObject> parentStyle = InspectorObject::create();
- if (parentElement->style() && parentElement->style()->length()) {
- InspectorStyleSheetForInlineStyle* styleSheet = asInspectorStyleSheet(element);
- if (styleSheet)
- parentStyle->setObject("inlineStyle", styleSheet->buildObjectForStyle(styleSheet->styleForId(InspectorCSSId::createFromParts(styleSheet->id(), "0"))));
- }
-
- CSSStyleSelector* parentSelector = parentElement->ownerDocument()->styleSelector();
- RefPtr<CSSRuleList> parentMatchedRules = parentSelector->styleRulesForElement(parentElement, false, true);
- parentStyle->setArray("matchedCSSRules", buildArrayForRuleList(parentMatchedRules.get()));
- inheritedStyles->pushObject(parentStyle.release());
- parentElement = parentElement->parentElement();
- }
- *style = inheritedStyles.release();
-}
-
void InspectorCSSAgent::getAllStyles2(RefPtr<InspectorArray>* styles)
{
const ListHashSet<RefPtr<Document> >& documents = m_domAgent->documents();
@@ -335,8 +337,10 @@ void InspectorCSSAgent::addRule2(const long contextNodeId, const String& selecto
InspectorStyleSheet* inspectorStyleSheet = viaInspectorStyleSheet(node->document(), true);
CSSStyleRule* newRule = inspectorStyleSheet->addRule(selector);
- if (newRule)
- *result = inspectorStyleSheet->buildObjectForRule(newRule);
+ if (!newRule)
+ return;
+
+ *result = inspectorStyleSheet->buildObjectForRule(newRule);
}
void InspectorCSSAgent::getSupportedCSSProperties(RefPtr<InspectorArray>* cssProperties)
@@ -348,6 +352,26 @@ void InspectorCSSAgent::getSupportedCSSProperties(RefPtr<InspectorArray>* cssPro
*cssProperties = properties.release();
}
+void InspectorCSSAgent::querySelectorAll(const long nodeId, const String& selector, RefPtr<InspectorArray>* result)
+{
+ Node* node = m_domAgent->nodeForId(nodeId);
+ if (!node)
+ return;
+ if (!node->isDocumentNode())
+ node = node->ownerDocument();
+ if (!node)
+ return;
+ ExceptionCode ec = 0;
+ RefPtr<NodeList> nodes = static_cast<Document*>(node)->querySelectorAll(selector, ec);
+ if (ec)
+ return;
+ for (unsigned i = 0; i < nodes->length(); ++i) {
+ Node* affectedNode = nodes->item(i);
+ long id = m_domAgent->pushNodePathToFrontend(affectedNode);
+ (*result)->pushNumber(id);
+ }
+}
+
// static
Element* InspectorCSSAgent::inlineStyleElement(CSSStyleDeclaration* style)
{
@@ -488,11 +512,15 @@ PassRefPtr<InspectorObject> InspectorCSSAgent::buildObjectForAttributeStyles(Ele
void InspectorCSSAgent::didRemoveDocument(Document* document)
{
- m_documentToInspectorStyleSheet.remove(document);
+ if (document)
+ m_documentToInspectorStyleSheet.remove(document);
}
void InspectorCSSAgent::didRemoveDOMNode(Node* node)
{
+ if (!node)
+ return;
+
NodeToInspectorStyleSheet::iterator it = m_nodeToInspectorStyleSheet.find(node);
if (it == m_nodeToInspectorStyleSheet.end())
return;
diff --git a/WebCore/inspector/InspectorCSSAgent.h b/WebCore/inspector/InspectorCSSAgent.h
index 341d09a..71ca580 100644
--- a/WebCore/inspector/InspectorCSSAgent.h
+++ b/WebCore/inspector/InspectorCSSAgent.h
@@ -49,26 +49,20 @@ class Node;
#if ENABLE(INSPECTOR)
-class InspectorCSSAgent : public RefCounted<InspectorCSSAgent>, public InspectorDOMAgent::DOMListener {
+class InspectorCSSAgent : public InspectorDOMAgent::DOMListener {
public:
- static PassRefPtr<InspectorCSSAgent> create(InspectorDOMAgent* domAgent, InspectorFrontend* frontend)
- {
- return adoptRef(new InspectorCSSAgent(domAgent, frontend));
- }
-
static CSSStyleSheet* parentStyleSheet(StyleBase*);
static CSSStyleRule* asCSSStyleRule(StyleBase*);
- InspectorCSSAgent(InspectorDOMAgent* domAgent, InspectorFrontend* frontend);
+ InspectorCSSAgent();
~InspectorCSSAgent();
+ void setDOMAgent(InspectorDOMAgent* domAgent);
+
void reset();
- void getMatchedRulesForNode2(long nodeId, RefPtr<InspectorArray>* rules);
- void getMatchedPseudoRulesForNode2(long nodeId, RefPtr<InspectorArray>* rules);
- void getAttributeStylesForNode2(long nodeId, RefPtr<InspectorValue>* styles);
+ void getStylesForNode2(long nodeId, RefPtr<InspectorValue>* result);
void getInlineStyleForNode2(long nodeId, RefPtr<InspectorValue>* style);
void getComputedStyleForNode2(long nodeId, RefPtr<InspectorValue>* style);
- void getInheritedStylesForNode2(long nodeId, RefPtr<InspectorArray>* result);
void getAllStyles2(RefPtr<InspectorArray>* styles);
void getStyleSheet2(const String& styleSheetId, RefPtr<InspectorValue>* result);
void setStyleSheetText2(const String& styleSheetId, const String& text);
@@ -77,6 +71,7 @@ public:
void setRuleSelector2(const String& ruleId, const String& selector, RefPtr<InspectorValue>* result);
void addRule2(const long contextNodeId, const String& selector, RefPtr<InspectorValue>* result);
void getSupportedCSSProperties(RefPtr<InspectorArray>* result);
+ void querySelectorAll(const long nodeId, const String& selector, RefPtr<InspectorArray>* result);
private:
typedef HashMap<String, RefPtr<InspectorStyleSheet> > IdToInspectorStyleSheet;
@@ -101,8 +96,7 @@ private:
virtual void didRemoveDocument(Document*);
virtual void didRemoveDOMNode(Node*);
- RefPtr<InspectorDOMAgent> m_domAgent;
- InspectorFrontend* m_frontend;
+ InspectorDOMAgent* m_domAgent;
IdToInspectorStyleSheet m_idToInspectorStyleSheet;
CSSStyleSheetToInspectorStyleSheet m_cssStyleSheetToInspectorStyleSheet;
diff --git a/WebCore/inspector/InspectorController.cpp b/WebCore/inspector/InspectorController.cpp
index c34130e..cda3972 100644
--- a/WebCore/inspector/InspectorController.cpp
+++ b/WebCore/inspector/InspectorController.cpp
@@ -58,6 +58,7 @@
#include "InjectedScriptHost.h"
#include "InspectorBackend.h"
#include "InspectorBackendDispatcher.h"
+#include "InspectorCSSAgent.h"
#include "InspectorCSSStore.h"
#include "InspectorClient.h"
#include "InspectorDOMAgent.h"
@@ -142,6 +143,7 @@ InspectorController::InspectorController(Page* page, InspectorClient* client)
: m_inspectedPage(page)
, m_client(client)
, m_openingFrontend(false)
+ , m_cssAgent(new InspectorCSSAgent())
, m_cssStore(new InspectorCSSStore(this))
, m_mainResourceIdentifier(0)
, m_expiredConsoleMessageCount(0)
@@ -485,6 +487,8 @@ void InspectorController::connectFrontend()
m_domAgent = InspectorDOMAgent::create(m_cssStore.get(), m_frontend.get());
m_resourceAgent = InspectorResourceAgent::create(m_inspectedPage, m_frontend.get());
+ m_cssAgent->setDOMAgent(m_domAgent.get());
+
#if ENABLE(DATABASE)
m_storageAgent = InspectorStorageAgent::create(m_frontend.get());
#endif
@@ -592,6 +596,9 @@ void InspectorController::releaseFrontendLifetimeAgents()
{
m_resourceAgent.clear();
+ // This should be invoked prior to m_domAgent destruction.
+ m_cssAgent->setDOMAgent(0);
+
// m_domAgent is RefPtr. Remove DOM listeners first to ensure that there are
// no references to the DOM agent from the DOM tree.
if (m_domAgent)
@@ -744,6 +751,7 @@ void InspectorController::didCommitLoad(DocumentLoader* loader)
if (m_frontend) {
m_frontend->reset();
m_domAgent->reset();
+ m_cssAgent->reset();
}
#if ENABLE(WORKERS)
m_workers.clear();
diff --git a/WebCore/inspector/InspectorController.h b/WebCore/inspector/InspectorController.h
index 7dadaa9..ca5a9d9 100644
--- a/WebCore/inspector/InspectorController.h
+++ b/WebCore/inspector/InspectorController.h
@@ -58,6 +58,7 @@ class InspectorArray;
class InspectorBackend;
class InspectorBackendDispatcher;
class InspectorClient;
+class InspectorCSSAgent;
class InspectorCSSStore;
class InspectorDOMAgent;
class InspectorDOMStorageResource;
@@ -298,6 +299,7 @@ private:
void setSearchingForNode(bool enabled, bool* newState);
void setMonitoringXHREnabled(bool enabled, bool* newState);
+ InspectorCSSAgent* cssAgent() { return m_cssAgent.get(); }
InspectorDOMAgent* domAgent() { return m_domAgent.get(); }
void releaseFrontendLifetimeAgents();
@@ -340,6 +342,7 @@ private:
OwnPtr<InspectorFrontendClient> m_inspectorFrontendClient;
bool m_openingFrontend;
OwnPtr<InspectorFrontend> m_frontend;
+ OwnPtr<InspectorCSSAgent> m_cssAgent;
RefPtr<InspectorDOMAgent> m_domAgent;
RefPtr<InspectorStorageAgent> m_storageAgent;
OwnPtr<InspectorCSSStore> m_cssStore;
diff --git a/WebCore/inspector/InspectorDOMAgent.cpp b/WebCore/inspector/InspectorDOMAgent.cpp
index 9316296..39aecf1 100644
--- a/WebCore/inspector/InspectorDOMAgent.cpp
+++ b/WebCore/inspector/InspectorDOMAgent.cpp
@@ -1538,15 +1538,6 @@ void InspectorDOMAgent::addRule(const String& selector, long selectedNodeId, Ref
*ruleObject = buildObjectForRule(node->ownerDocument(), newRule);
}
-void InspectorDOMAgent::getSupportedCSSProperties(RefPtr<InspectorArray>* cssProperties)
-{
- RefPtr<InspectorArray> properties = InspectorArray::create();
- for (int i = 0; i < numCSSProperties; ++i)
- properties->pushString(propertyNameStrings[i]);
-
- *cssProperties = properties.release();
-}
-
PassRefPtr<InspectorObject> InspectorDOMAgent::buildObjectForStyle(CSSStyleDeclaration* style, bool bind)
{
RefPtr<InspectorObject> result = InspectorObject::create();
diff --git a/WebCore/inspector/InspectorDOMAgent.h b/WebCore/inspector/InspectorDOMAgent.h
index 6c5fd4b..84ca027 100644
--- a/WebCore/inspector/InspectorDOMAgent.h
+++ b/WebCore/inspector/InspectorDOMAgent.h
@@ -137,7 +137,6 @@ namespace WebCore {
void toggleStyleEnabled(long styleId, const String& propertyName, bool disabled, RefPtr<InspectorValue>* styleObject);
void setRuleSelector(long ruleId, const String& selector, long selectedNodeId, RefPtr<InspectorValue>* ruleObject, bool* selectorAffectsNode);
void addRule(const String& selector, long selectedNodeId, RefPtr<InspectorValue>* ruleObject, bool* selectorAffectsNode);
- void getSupportedCSSProperties(RefPtr<InspectorArray>* cssProperties);
// Methods called from the InspectorController.
void setDocument(Document* document);
diff --git a/WebCore/inspector/InspectorStyleSheet.cpp b/WebCore/inspector/InspectorStyleSheet.cpp
index dc2a47a..ef20675 100644
--- a/WebCore/inspector/InspectorStyleSheet.cpp
+++ b/WebCore/inspector/InspectorStyleSheet.cpp
@@ -37,6 +37,7 @@
#include "Document.h"
#include "Element.h"
#include "HTMLHeadElement.h"
+#include "HTMLParserIdioms.h"
#include "InspectorCSSAgent.h"
#include "InspectorResourceAgent.h"
#include "InspectorValues.h"
@@ -120,6 +121,12 @@ PassRefPtr<InspectorObject> InspectorStyle::buildObjectForStyle() const
return result.release();
}
+// This method does the following preprocessing of |propertyText| with |overwrite| == false and |index| past the last active property:
+// - If the last property (if present) has no subsequent whitespace in the style declaration, a space is prepended to |propertyText|.
+// - If the last property (if present) has no closing ";", the ";" is prepended to the current |propertyText| value.
+//
+// The propertyText (if not empty) is checked to be a valid style declaration (containing at least one property). If not,
+// the method returns false (denoting an error).
bool InspectorStyle::setPropertyText(unsigned index, const String& propertyText, bool overwrite)
{
ASSERT(m_parentStyleSheet);
@@ -132,6 +139,16 @@ bool InspectorStyle::setPropertyText(unsigned index, const String& propertyText,
unsigned propertyStart = 0; // Need to initialize to make the compiler happy.
long propertyLengthDelta;
+ if (propertyText.stripWhiteSpace().length()) {
+ RefPtr<CSSMutableStyleDeclaration> tempMutableStyle = CSSMutableStyleDeclaration::create();
+ tempMutableStyle->parseDeclaration(propertyText);
+ CSSStyleDeclaration* tempStyle = static_cast<CSSStyleDeclaration*>(tempMutableStyle.get());
+
+ // Bail out early if the property text did not parse.
+ if (!tempStyle->length())
+ return false;
+ }
+
if (overwrite) {
ASSERT(index < allProperties.size());
InspectorStyleProperty& property = allProperties.at(index);
@@ -146,11 +163,17 @@ bool InspectorStyle::setPropertyText(unsigned index, const String& propertyText,
if (!success)
return false;
} else {
- property.rawText = propertyText;
- if (!propertyText.length()) {
- bool success = enableProperty(index, allProperties);
- return success;
+ unsigned textLength = propertyText.length();
+ if (!textLength) {
+ // Delete disabled property.
+ m_disabledProperties.remove(disabledIndexByOrdinal(index, false, allProperties));
+ return true;
}
+
+ // Patch disabled property text and range.
+ property.rawText = propertyText;
+ if (property.sourceData.range.end)
+ property.sourceData.range.end = property.sourceData.range.start + textLength;
}
} else {
// Insert at index.
@@ -172,10 +195,28 @@ bool InspectorStyle::setPropertyText(unsigned index, const String& propertyText,
insertLast = false;
}
}
- if (insertLast)
- propertyStart = sourceData->styleSourceData->styleBodyRange.end;
- text.insert(propertyText, propertyStart);
+ String textToSet = propertyText;
+ if (insertLast) {
+ propertyStart = sourceData->styleSourceData->styleBodyRange.end - sourceData->styleSourceData->styleBodyRange.start;
+ if (propertyStart > 0 && propertyText.length()) {
+ const UChar* characters = text.characters();
+
+ unsigned curPos = propertyStart - 1; // The last position of style declaration, since propertyStart points past one.
+ while (curPos && isHTMLSpace(characters[curPos]))
+ --curPos;
+ if (curPos && characters[curPos] != ';') {
+ // Prepend a ";" to the property text if appending to a style declaration where
+ // the last property has no trailing ";".
+ textToSet.insert("; ", 0);
+ } else if (!isHTMLSpace(characters[propertyStart - 1])) {
+ // Prepend a " " if the last declaration character is not an HTML space.
+ textToSet.insert(" ", 0);
+ }
+ }
+ }
+
+ text.insert(textToSet, propertyStart);
m_parentStyleSheet->setStyleText(m_style, text);
}
@@ -228,7 +269,7 @@ unsigned InspectorStyle::disabledIndexByOrdinal(unsigned ordinal, bool canUseSub
return UINT_MAX;
}
-bool InspectorStyle::styleText(String* result)
+bool InspectorStyle::styleText(String* result) const
{
// Precondition: m_parentStyleSheet->ensureParsedDataReady() has been called successfully.
RefPtr<CSSRuleSourceData> sourceData = m_parentStyleSheet->ruleSourceDataFor(m_style);
@@ -249,17 +290,17 @@ bool InspectorStyle::disableProperty(unsigned indexToDisable, Vector<InspectorSt
{
// Precondition: |indexToEnable| points to an enabled property.
const InspectorStyleProperty& property = allProperties.at(indexToDisable);
- InspectorStyleProperty disabledProperty(property);
- disabledProperty.disabled = true;
unsigned propertyStart = property.sourceData.range.start;
- // This may have to be negated below.
- long propertyLength = property.sourceData.range.end - propertyStart;
- disabledProperty.sourceData.range.end = propertyStart;
+ InspectorStyleProperty disabledProperty(property);
String oldStyleText;
bool success = styleText(&oldStyleText);
if (!success)
return false;
- disabledProperty.rawText = oldStyleText.substring(propertyStart, propertyLength);
+ disabledProperty.setRawTextFromStyleDeclaration(oldStyleText);
+ disabledProperty.disabled = true;
+ disabledProperty.sourceData.range.end = propertyStart;
+ // This may have to be negated below.
+ long propertyLength = property.sourceData.range.end - propertyStart;
success = replacePropertyInStyleText(property, "");
if (!success)
return false;
@@ -303,13 +344,18 @@ bool InspectorStyle::populateAllProperties(Vector<InspectorStyleProperty>* resul
RefPtr<CSSRuleSourceData> sourceData = (m_parentStyleSheet && m_parentStyleSheet->ensureParsedDataReady()) ? m_parentStyleSheet->ruleSourceDataFor(m_style) : 0;
Vector<CSSPropertySourceData>* sourcePropertyData = sourceData ? &(sourceData->styleSourceData->propertyData) : 0;
if (sourcePropertyData) {
+ String styleDeclaration;
+ bool isStyleTextKnown = styleText(&styleDeclaration);
+ ASSERT_UNUSED(isStyleTextKnown, isStyleTextKnown);
for (Vector<CSSPropertySourceData>::const_iterator it = sourcePropertyData->begin(); it != sourcePropertyData->end(); ++it) {
while (disabledIndex < disabledLength && disabledProperty.sourceData.range.start <= it->range.start) {
result->append(disabledProperty);
if (++disabledIndex < disabledLength)
disabledProperty = m_disabledProperties.at(disabledIndex);
}
- result->append(InspectorStyleProperty(*it, true, false));
+ InspectorStyleProperty p(*it, true, false);
+ p.setRawTextFromStyleDeclaration(styleDeclaration);
+ result->append(p);
sourcePropertyNames.add(it->name);
}
}
@@ -349,10 +395,12 @@ void InspectorStyle::populateObjectWithStyleProperties(InspectorObject* result)
propertiesObject->pushObject(property);
property->setString("status", it->disabled ? "disabled" : "active");
property->setBoolean("parsedOk", propertyEntry.parsedOk);
+ if (it->hasRawText())
+ property->setString("text", it->rawText);
+ property->setString("name", name);
+ property->setString("value", propertyEntry.value);
+ property->setString("priority", propertyEntry.important ? "important" : "");
if (!it->disabled) {
- property->setString("name", name);
- property->setString("value", propertyEntry.value);
- property->setString("priority", propertyEntry.important ? "important" : "");
if (it->hasSource) {
property->setBoolean("implicit", false);
property->setNumber("startOffset", propertyEntry.range.start);
@@ -368,8 +416,7 @@ void InspectorStyle::populateObjectWithStyleProperties(InspectorObject* result)
property->setBoolean("implicit", m_style->isPropertyImplicit(name));
property->setString("status", "style");
}
- } else
- property->setString("text", it->rawText);
+ }
if (propertyEntry.parsedOk) {
// Both for style-originated and parsed source properties.
@@ -592,7 +639,9 @@ PassRefPtr<InspectorObject> InspectorStyleSheet::buildObjectForRule(CSSStyleRule
RefPtr<InspectorObject> result = InspectorObject::create();
result->setString("selectorText", rule->selectorText());
- result->setString("sourceURL", !styleSheet->href().isEmpty() ? styleSheet->href() : m_documentURL);
+ // "sourceURL" is present only for regular rules, otherwise "origin" should be used in the frontend.
+ if (!m_origin.length())
+ result->setString("sourceURL", !styleSheet->href().isEmpty() ? styleSheet->href() : m_documentURL);
result->setNumber("sourceLine", rule->sourceLine());
result->setString("origin", m_origin);
@@ -600,6 +649,16 @@ PassRefPtr<InspectorObject> InspectorStyleSheet::buildObjectForRule(CSSStyleRule
if (canBind())
result->setString("ruleId", ruleId(rule).asString());
+ RefPtr<CSSRuleSourceData> sourceData;
+ if (ensureParsedDataReady())
+ sourceData = ruleSourceDataFor(rule->style());
+ if (sourceData) {
+ RefPtr<InspectorObject> selectorRange = InspectorObject::create();
+ selectorRange->setNumber("start", sourceData->selectorListRange.start);
+ selectorRange->setNumber("end", sourceData->selectorListRange.end);
+ result->setObject("selectorRange", selectorRange.release());
+ }
+
return result.release();
}
@@ -691,6 +750,51 @@ InspectorCSSId InspectorStyleSheet::ruleOrStyleId(CSSStyleDeclaration* style) co
return InspectorCSSId();
}
+void InspectorStyleSheet::fixUnparsedPropertyRanges(CSSRuleSourceData* ruleData, const String& styleSheetText)
+{
+ Vector<CSSPropertySourceData>& propertyData = ruleData->styleSourceData->propertyData;
+ unsigned size = propertyData.size();
+ if (!size)
+ return;
+
+ unsigned styleStart = ruleData->styleSourceData->styleBodyRange.start;
+ const UChar* characters = styleSheetText.characters();
+ CSSPropertySourceData* nextData = &(propertyData.at(0));
+ for (unsigned i = 0; i < size; ++i) {
+ CSSPropertySourceData* currentData = nextData;
+ nextData = i < size - 1 ? &(propertyData.at(i + 1)) : 0;
+
+ if (currentData->parsedOk)
+ continue;
+ if (currentData->range.end > 0 && characters[styleStart + currentData->range.end - 1] == ';')
+ continue;
+
+ unsigned propertyEndInStyleSheet;
+ if (!nextData)
+ propertyEndInStyleSheet = ruleData->styleSourceData->styleBodyRange.end - 1;
+ else
+ propertyEndInStyleSheet = styleStart + nextData->range.start - 1;
+
+ while (isHTMLSpace(characters[propertyEndInStyleSheet]))
+ --propertyEndInStyleSheet;
+
+ // propertyEndInStyleSheet points at the last property text character.
+ unsigned newPropertyEnd = propertyEndInStyleSheet - styleStart + 1; // Exclusive of the last property text character.
+ if (currentData->range.end != newPropertyEnd) {
+ currentData->range.end = newPropertyEnd;
+ unsigned valueStartInStyleSheet = styleStart + currentData->range.start + currentData->name.length();
+ while (valueStartInStyleSheet < propertyEndInStyleSheet && characters[valueStartInStyleSheet] != ':')
+ ++valueStartInStyleSheet;
+ if (valueStartInStyleSheet < propertyEndInStyleSheet)
+ ++valueStartInStyleSheet; // Shift past the ':'.
+ while (valueStartInStyleSheet < propertyEndInStyleSheet && isHTMLSpace(characters[valueStartInStyleSheet]))
+ ++valueStartInStyleSheet;
+ // Need to exclude the trailing ';' from the property value.
+ currentData->value = styleSheetText.substring(valueStartInStyleSheet, propertyEndInStyleSheet - valueStartInStyleSheet + (characters[propertyEndInStyleSheet] == ';' ? 0 : 1));
+ }
+ }
+}
+
Document* InspectorStyleSheet::ownerDocument() const
{
return m_pageStyleSheet->document();
@@ -763,8 +867,10 @@ bool InspectorStyleSheet::ensureSourceData(Node* ownerNode)
if (!rule)
continue;
StyleRuleRangeMap::iterator it = ruleRangeMap.find(rule);
- if (it != ruleRangeMap.end())
+ if (it != ruleRangeMap.end()) {
+ fixUnparsedPropertyRanges(it->second.get(), m_parsedStyleSheet->text());
rangesVector->append(it->second);
+ }
}
m_parsedStyleSheet->setSourceData(rangesVector.release());
@@ -926,6 +1032,12 @@ bool InspectorStyleSheetForInlineStyle::setStyleText(CSSStyleDeclaration* style,
return !ec;
}
+bool InspectorStyleSheetForInlineStyle::text(String* result) const
+{
+ *result = m_element->getAttribute("style");
+ return true;
+}
+
Document* InspectorStyleSheetForInlineStyle::ownerDocument() const
{
return m_element->document();
diff --git a/WebCore/inspector/InspectorStyleSheet.h b/WebCore/inspector/InspectorStyleSheet.h
index 06c4093..e671834 100644
--- a/WebCore/inspector/InspectorStyleSheet.h
+++ b/WebCore/inspector/InspectorStyleSheet.h
@@ -87,6 +87,17 @@ struct InspectorStyleProperty {
{
}
+ void setRawTextFromStyleDeclaration(const String& styleDeclaration)
+ {
+ unsigned start = sourceData.range.start;
+ unsigned end = sourceData.range.end;
+ ASSERT(start < end);
+ ASSERT(end <= styleDeclaration.length());
+ rawText = styleDeclaration.substring(start, end - start);
+ }
+
+ bool hasRawText() const { return !rawText.isEmpty(); }
+
CSSPropertySourceData sourceData;
bool hasSource;
bool disabled;
@@ -117,7 +128,7 @@ public:
private:
static unsigned disabledIndexByOrdinal(unsigned ordinal, bool canUseSubsequent, Vector<InspectorStyleProperty>& allProperties);
- bool styleText(String* result);
+ bool styleText(String* result) const;
bool disableProperty(unsigned indexToDisable, Vector<InspectorStyleProperty>& allProperties);
bool enableProperty(unsigned indexToEnable, Vector<InspectorStyleProperty>& allProperties);
bool populateAllProperties(Vector<InspectorStyleProperty>* result) const;
@@ -162,6 +173,8 @@ public:
protected:
bool canBind() const { return m_origin != "userAgent" && m_origin != "user"; }
InspectorCSSId ruleOrStyleId(CSSStyleDeclaration* style) const;
+ void fixUnparsedPropertyRanges(CSSRuleSourceData* ruleData, const String& styleSheetText);
+ virtual bool text(String* result) const;
virtual Document* ownerDocument() const;
virtual RefPtr<CSSRuleSourceData> ruleSourceDataFor(CSSStyleDeclaration* style) const;
virtual unsigned ruleIndexByStyle(CSSStyleDeclaration*) const;
@@ -174,7 +187,6 @@ protected:
virtual bool setStyleText(CSSStyleDeclaration*, const String&);
private:
- bool text(String* result) const;
bool ensureText() const;
bool ensureSourceData(Node* ownerNode);
bool styleSheetTextWithChangedStyle(CSSStyleDeclaration*, const String& newStyleText, String* result);
@@ -210,6 +222,7 @@ public:
virtual CSSStyleDeclaration* styleForId(const InspectorCSSId& id) const { ASSERT_UNUSED(id, id.ordinal() == "0"); return inlineStyle(); }
protected:
+ virtual bool text(String* result) const;
virtual Document* ownerDocument() const;
virtual RefPtr<CSSRuleSourceData> ruleSourceDataFor(CSSStyleDeclaration* style) const { ASSERT_UNUSED(style, style == inlineStyle()); return m_ruleSourceData; }
virtual unsigned ruleIndexByStyle(CSSStyleDeclaration*) const { return 0; }
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list