[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 14:22:09 UTC 2010
The following commit has been merged in the debian/experimental branch:
commit 8d79d7f983e14c8c0ed70379448454ec3c08e106
Author: apavlov at chromium.org <apavlov at chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Thu Oct 7 09:53:40 2010 +0000
2010-10-06 Alexander Pavlov <apavlov at chromium.org>
Reviewed by Pavel Feldman.
Web Inspector: Implement handling of CSS operations in InspectorCSSAgent.
Property toggling not implemented yet. The code is not going live.
https://bugs.webkit.org/show_bug.cgi?id=45825
* CMakeLists.txt:
* GNUmakefile.am:
* WebCore.gypi:
* WebCore.pro:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:
* inspector/InspectorCSSAgent.cpp: Added.
(WebCore::InspectorCSSAgent::buildObjectForStyle):
(WebCore::InspectorCSSAgent::parentStyleSheet):
(WebCore::InspectorCSSAgent::asCSSStyleRule):
(WebCore::InspectorCSSAgent::InspectorCSSAgent):
(WebCore::InspectorCSSAgent::~InspectorCSSAgent):
(WebCore::InspectorCSSAgent::reset):
(WebCore::InspectorCSSAgent::getMatchedRulesForNode2):
(WebCore::InspectorCSSAgent::getMatchedPseudoRulesForNode2):
(WebCore::InspectorCSSAgent::getAttributeStylesForNode2):
(WebCore::InspectorCSSAgent::getInlineStyleForNode2):
(WebCore::InspectorCSSAgent::getComputedStyleForNode2):
(WebCore::InspectorCSSAgent::getInheritedStylesForNode2):
(WebCore::InspectorCSSAgent::getAllStyles2):
(WebCore::InspectorCSSAgent::getStyleSheet2):
(WebCore::InspectorCSSAgent::setStyleSheetText2):
(WebCore::InspectorCSSAgent::setStyleText2):
(WebCore::InspectorCSSAgent::toggleProperty2):
(WebCore::InspectorCSSAgent::setRuleSelector2):
(WebCore::InspectorCSSAgent::addRule2):
(WebCore::InspectorCSSAgent::getSupportedCSSProperties):
(WebCore::InspectorCSSAgent::inlineStyleElement):
(WebCore::InspectorCSSAgent::populateObjectWithStyleProperties):
(WebCore::InspectorCSSAgent::shorthandValue):
(WebCore::InspectorCSSAgent::shorthandPriority):
(WebCore::InspectorCSSAgent::longhandProperties):
(WebCore::InspectorCSSAgent::asInspectorStyleSheet):
(WebCore::InspectorCSSAgent::elementForId):
(WebCore::InspectorCSSAgent::bindStyleSheet):
(WebCore::InspectorCSSAgent::viaInspectorStyleSheet):
(WebCore::InspectorCSSAgent::styleSheetForId):
(WebCore::InspectorCSSAgent::detectOrigin):
(WebCore::InspectorCSSAgent::buildArrayForRuleList):
(WebCore::InspectorCSSAgent::buildObjectForAttributeStyles):
(WebCore::InspectorCSSAgent::didRemoveDocument):
(WebCore::InspectorCSSAgent::didRemoveDOMNode):
* inspector/InspectorCSSAgent.h: Added.
(WebCore::InspectorCSSAgent::create):
* inspector/InspectorDOMAgent.cpp:
(WebCore::InspectorDOMAgent::InspectorDOMAgent):
(WebCore::InspectorDOMAgent::setDOMListener):
(WebCore::InspectorDOMAgent::unbind):
(WebCore::InspectorDOMAgent::didRemoveDOMNode):
(WebCore::InspectorDOMAgent::getSupportedCSSProperties):
* inspector/InspectorDOMAgent.h:
(WebCore::InspectorDOMAgent::DOMListener::~DOMListener):
(WebCore::InspectorDOMAgent::documents):
* inspector/InspectorStyleSheet.cpp: Added.
(ParsedStyleSheet::cssStyleSheet):
(ParsedStyleSheet::text):
(ParsedStyleSheet::hasText):
(ParsedStyleSheet::sourceData):
(ParsedStyleSheet::hasSourceData):
(ParsedStyleSheet::ParsedStyleSheet):
(ParsedStyleSheet::setText):
(ParsedStyleSheet::setSourceData):
(ParsedStyleSheet::ruleSourceDataAt):
(WebCore::InspectorStyleSheet::InspectorStyleSheet):
(WebCore::InspectorStyleSheet::~InspectorStyleSheet):
(WebCore::InspectorStyleSheet::setText):
(WebCore::InspectorStyleSheet::setRuleSelector):
(WebCore::InspectorStyleSheet::addRule):
(WebCore::InspectorStyleSheet::ruleForId):
(WebCore::InspectorStyleSheet::buildObjectForStyleSheet):
(WebCore::InspectorStyleSheet::buildObjectForRule):
(WebCore::InspectorStyleSheet::buildObjectForStyle):
(WebCore::InspectorStyleSheet::styleForId):
(WebCore::InspectorStyleSheet::setStyleText):
(WebCore::InspectorStyleSheet::ownerDocument):
(WebCore::InspectorStyleSheet::ruleSourceDataFor):
(WebCore::InspectorStyleSheet::ruleIndexByStyle):
(WebCore::InspectorStyleSheet::ensureParsedDataReady):
(WebCore::InspectorStyleSheet::text):
(WebCore::InspectorStyleSheet::ensureText):
(WebCore::InspectorStyleSheet::ensureSourceData):
(WebCore::InspectorStyleSheet::innerSetStyleSheetText):
(WebCore::InspectorStyleSheet::innerSetStyleText):
(WebCore::InspectorStyleSheet::styleSheetTextWithChangedStyle):
(WebCore::InspectorStyleSheet::findPageRuleWithStyle):
(WebCore::InspectorStyleSheet::fullRuleId):
(WebCore::InspectorStyleSheet::revalidateStyle):
(WebCore::InspectorStyleSheet::styleSheetText):
(WebCore::InspectorStyleSheet::resourceStyleSheetText):
(WebCore::InspectorStyleSheet::inlineStyleSheetText):
(WebCore::InspectorStyleSheet::buildArrayForRuleList):
(WebCore::InspectorStyleSheetForInlineStyle::InspectorStyleSheetForInlineStyle):
(WebCore::InspectorStyleSheetForInlineStyle::setStyleText):
(WebCore::InspectorStyleSheetForInlineStyle::ownerDocument):
(WebCore::InspectorStyleSheetForInlineStyle::ensureParsedDataReady):
(WebCore::InspectorStyleSheetForInlineStyle::inlineStyle):
(WebCore::InspectorStyleSheetForInlineStyle::getStyleAttributeRanges):
* inspector/InspectorStyleSheet.h: Added.
(WebCore::InspectorStyleSheet::create):
(WebCore::InspectorStyleSheet::id):
(WebCore::InspectorStyleSheet::pageStyleSheet):
(WebCore::InspectorStyleSheet::canBind):
(WebCore::InspectorStyleSheet::fullRuleOrStyleId):
(WebCore::InspectorStyleSheet::ruleOrStyleId):
(WebCore::InspectorStyleSheet::fullStyleId):
(WebCore::InspectorStyleSheetForInlineStyle::create):
(WebCore::InspectorStyleSheetForInlineStyle::styleForId):
(WebCore::InspectorStyleSheetForInlineStyle::ruleSourceDataFor):
(WebCore::InspectorStyleSheetForInlineStyle::ruleIndexByStyle):
* inspector/InspectorUtilities.cpp: Added.
(WebCore::InspectorUtilities::resourceContentForURL):
* inspector/InspectorUtilities.h: Added.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@69284 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/CMakeLists.txt b/WebCore/CMakeLists.txt
index 8b4f0f6..5331eae 100644
--- a/WebCore/CMakeLists.txt
+++ b/WebCore/CMakeLists.txt
@@ -1099,6 +1099,7 @@ SET(WebCore_SOURCES
inspector/InjectedScriptHost.cpp
inspector/InspectorApplicationCacheAgent.cpp
inspector/InspectorBackend.cpp
+ inspector/InspectorCSSAgent.cpp
inspector/InspectorCSSStore.cpp
inspector/InspectorController.cpp
inspector/InspectorDOMAgent.cpp
@@ -1110,6 +1111,8 @@ SET(WebCore_SOURCES
inspector/InspectorInstrumentation.cpp
inspector/InspectorProfilerAgent.cpp
inspector/InspectorResource.cpp
+ inspector/InspectorStyleSheet.cpp
+ inspector/InspectorUtilities.cpp
inspector/InspectorValues.cpp
inspector/InspectorStorageAgent.cpp
inspector/InspectorTimelineAgent.cpp
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 92d30cd..2325cee 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,124 @@
+2010-10-06 Alexander Pavlov <apavlov at chromium.org>
+
+ Reviewed by Pavel Feldman.
+
+ Web Inspector: Implement handling of CSS operations in InspectorCSSAgent.
+ Property toggling not implemented yet. The code is not going live.
+ https://bugs.webkit.org/show_bug.cgi?id=45825
+
+ * CMakeLists.txt:
+ * GNUmakefile.am:
+ * WebCore.gypi:
+ * WebCore.pro:
+ * WebCore.vcproj/WebCore.vcproj:
+ * WebCore.xcodeproj/project.pbxproj:
+ * inspector/InspectorCSSAgent.cpp: Added.
+ (WebCore::InspectorCSSAgent::buildObjectForStyle):
+ (WebCore::InspectorCSSAgent::parentStyleSheet):
+ (WebCore::InspectorCSSAgent::asCSSStyleRule):
+ (WebCore::InspectorCSSAgent::InspectorCSSAgent):
+ (WebCore::InspectorCSSAgent::~InspectorCSSAgent):
+ (WebCore::InspectorCSSAgent::reset):
+ (WebCore::InspectorCSSAgent::getMatchedRulesForNode2):
+ (WebCore::InspectorCSSAgent::getMatchedPseudoRulesForNode2):
+ (WebCore::InspectorCSSAgent::getAttributeStylesForNode2):
+ (WebCore::InspectorCSSAgent::getInlineStyleForNode2):
+ (WebCore::InspectorCSSAgent::getComputedStyleForNode2):
+ (WebCore::InspectorCSSAgent::getInheritedStylesForNode2):
+ (WebCore::InspectorCSSAgent::getAllStyles2):
+ (WebCore::InspectorCSSAgent::getStyleSheet2):
+ (WebCore::InspectorCSSAgent::setStyleSheetText2):
+ (WebCore::InspectorCSSAgent::setStyleText2):
+ (WebCore::InspectorCSSAgent::toggleProperty2):
+ (WebCore::InspectorCSSAgent::setRuleSelector2):
+ (WebCore::InspectorCSSAgent::addRule2):
+ (WebCore::InspectorCSSAgent::getSupportedCSSProperties):
+ (WebCore::InspectorCSSAgent::inlineStyleElement):
+ (WebCore::InspectorCSSAgent::populateObjectWithStyleProperties):
+ (WebCore::InspectorCSSAgent::shorthandValue):
+ (WebCore::InspectorCSSAgent::shorthandPriority):
+ (WebCore::InspectorCSSAgent::longhandProperties):
+ (WebCore::InspectorCSSAgent::asInspectorStyleSheet):
+ (WebCore::InspectorCSSAgent::elementForId):
+ (WebCore::InspectorCSSAgent::bindStyleSheet):
+ (WebCore::InspectorCSSAgent::viaInspectorStyleSheet):
+ (WebCore::InspectorCSSAgent::styleSheetForId):
+ (WebCore::InspectorCSSAgent::detectOrigin):
+ (WebCore::InspectorCSSAgent::buildArrayForRuleList):
+ (WebCore::InspectorCSSAgent::buildObjectForAttributeStyles):
+ (WebCore::InspectorCSSAgent::didRemoveDocument):
+ (WebCore::InspectorCSSAgent::didRemoveDOMNode):
+ * inspector/InspectorCSSAgent.h: Added.
+ (WebCore::InspectorCSSAgent::create):
+ * inspector/InspectorDOMAgent.cpp:
+ (WebCore::InspectorDOMAgent::InspectorDOMAgent):
+ (WebCore::InspectorDOMAgent::setDOMListener):
+ (WebCore::InspectorDOMAgent::unbind):
+ (WebCore::InspectorDOMAgent::didRemoveDOMNode):
+ (WebCore::InspectorDOMAgent::getSupportedCSSProperties):
+ * inspector/InspectorDOMAgent.h:
+ (WebCore::InspectorDOMAgent::DOMListener::~DOMListener):
+ (WebCore::InspectorDOMAgent::documents):
+ * inspector/InspectorStyleSheet.cpp: Added.
+ (ParsedStyleSheet::cssStyleSheet):
+ (ParsedStyleSheet::text):
+ (ParsedStyleSheet::hasText):
+ (ParsedStyleSheet::sourceData):
+ (ParsedStyleSheet::hasSourceData):
+ (ParsedStyleSheet::ParsedStyleSheet):
+ (ParsedStyleSheet::setText):
+ (ParsedStyleSheet::setSourceData):
+ (ParsedStyleSheet::ruleSourceDataAt):
+ (WebCore::InspectorStyleSheet::InspectorStyleSheet):
+ (WebCore::InspectorStyleSheet::~InspectorStyleSheet):
+ (WebCore::InspectorStyleSheet::setText):
+ (WebCore::InspectorStyleSheet::setRuleSelector):
+ (WebCore::InspectorStyleSheet::addRule):
+ (WebCore::InspectorStyleSheet::ruleForId):
+ (WebCore::InspectorStyleSheet::buildObjectForStyleSheet):
+ (WebCore::InspectorStyleSheet::buildObjectForRule):
+ (WebCore::InspectorStyleSheet::buildObjectForStyle):
+ (WebCore::InspectorStyleSheet::styleForId):
+ (WebCore::InspectorStyleSheet::setStyleText):
+ (WebCore::InspectorStyleSheet::ownerDocument):
+ (WebCore::InspectorStyleSheet::ruleSourceDataFor):
+ (WebCore::InspectorStyleSheet::ruleIndexByStyle):
+ (WebCore::InspectorStyleSheet::ensureParsedDataReady):
+ (WebCore::InspectorStyleSheet::text):
+ (WebCore::InspectorStyleSheet::ensureText):
+ (WebCore::InspectorStyleSheet::ensureSourceData):
+ (WebCore::InspectorStyleSheet::innerSetStyleSheetText):
+ (WebCore::InspectorStyleSheet::innerSetStyleText):
+ (WebCore::InspectorStyleSheet::styleSheetTextWithChangedStyle):
+ (WebCore::InspectorStyleSheet::findPageRuleWithStyle):
+ (WebCore::InspectorStyleSheet::fullRuleId):
+ (WebCore::InspectorStyleSheet::revalidateStyle):
+ (WebCore::InspectorStyleSheet::styleSheetText):
+ (WebCore::InspectorStyleSheet::resourceStyleSheetText):
+ (WebCore::InspectorStyleSheet::inlineStyleSheetText):
+ (WebCore::InspectorStyleSheet::buildArrayForRuleList):
+ (WebCore::InspectorStyleSheetForInlineStyle::InspectorStyleSheetForInlineStyle):
+ (WebCore::InspectorStyleSheetForInlineStyle::setStyleText):
+ (WebCore::InspectorStyleSheetForInlineStyle::ownerDocument):
+ (WebCore::InspectorStyleSheetForInlineStyle::ensureParsedDataReady):
+ (WebCore::InspectorStyleSheetForInlineStyle::inlineStyle):
+ (WebCore::InspectorStyleSheetForInlineStyle::getStyleAttributeRanges):
+ * inspector/InspectorStyleSheet.h: Added.
+ (WebCore::InspectorStyleSheet::create):
+ (WebCore::InspectorStyleSheet::id):
+ (WebCore::InspectorStyleSheet::pageStyleSheet):
+ (WebCore::InspectorStyleSheet::canBind):
+ (WebCore::InspectorStyleSheet::fullRuleOrStyleId):
+ (WebCore::InspectorStyleSheet::ruleOrStyleId):
+ (WebCore::InspectorStyleSheet::fullStyleId):
+ (WebCore::InspectorStyleSheetForInlineStyle::create):
+ (WebCore::InspectorStyleSheetForInlineStyle::styleForId):
+ (WebCore::InspectorStyleSheetForInlineStyle::ruleSourceDataFor):
+ (WebCore::InspectorStyleSheetForInlineStyle::ruleIndexByStyle):
+ * inspector/InspectorUtilities.cpp: Added.
+ (WebCore::InspectorUtilities::resourceContentForURL):
+ * inspector/InspectorUtilities.h: Added.
+
2010-10-05 Pavel Podivilov <podivilov at chromium.org>
Reviewed by Pavel Feldman.
diff --git a/WebCore/GNUmakefile.am b/WebCore/GNUmakefile.am
index 4f614c8..72ab647 100644
--- a/WebCore/GNUmakefile.am
+++ b/WebCore/GNUmakefile.am
@@ -1806,6 +1806,8 @@ webcore_sources += \
WebCore/inspector/InspectorClient.h \
WebCore/inspector/InspectorController.cpp \
WebCore/inspector/InspectorController.h \
+ WebCore/inspector/InspectorCSSAgent.cpp \
+ WebCore/inspector/InspectorCSSAgent.h \
WebCore/inspector/InspectorCSSStore.cpp \
WebCore/inspector/InspectorCSSStore.h \
WebCore/inspector/InspectorDatabaseResource.cpp \
@@ -1829,8 +1831,12 @@ webcore_sources += \
WebCore/inspector/InspectorResource.h \
WebCore/inspector/InspectorStorageAgent.cpp \
WebCore/inspector/InspectorStorageAgent.h \
+ WebCore/inspector/InspectorStyleSheet.cpp \
+ WebCore/inspector/InspectorStyleSheet.h \
WebCore/inspector/InspectorTimelineAgent.cpp \
WebCore/inspector/InspectorTimelineAgent.h \
+ WebCore/inspector/InspectorUtilities.cpp \
+ WebCore/inspector/InspectorUtilities.h \
WebCore/inspector/InspectorValues.cpp \
WebCore/inspector/InspectorValues.h \
WebCore/inspector/InspectorWorkerResource.h \
diff --git a/WebCore/WebCore.gypi b/WebCore/WebCore.gypi
index fe6642a..3367cee 100644
--- a/WebCore/WebCore.gypi
+++ b/WebCore/WebCore.gypi
@@ -1916,6 +1916,8 @@
'inspector/InspectorBackend.h',
'inspector/InspectorController.cpp',
'inspector/InspectorController.h',
+ 'inspector/InspectorCSSAgent.cpp',
+ 'inspector/InspectorCSSAgent.h',
'inspector/InspectorCSSStore.cpp',
'inspector/InspectorCSSStore.h',
'inspector/InspectorDatabaseResource.cpp',
@@ -1937,8 +1939,12 @@
'inspector/InspectorResource.h',
'inspector/InspectorStorageAgent.cpp',
'inspector/InspectorStorageAgent.h',
+ 'inspector/InspectorStyleSheet.cpp',
+ 'inspector/InspectorStyleSheet.h',
'inspector/InspectorTimelineAgent.cpp',
'inspector/InspectorTimelineAgent.h',
+ 'inspector/InspectorUtilities.cpp',
+ 'inspector/InspectorUtilities.h',
'inspector/InspectorValues.cpp',
'inspector/InspectorValues.h',
'inspector/InspectorWorkerResource.h',
diff --git a/WebCore/WebCore.pro b/WebCore/WebCore.pro
index bf5b216..40921e4 100644
--- a/WebCore/WebCore.pro
+++ b/WebCore/WebCore.pro
@@ -990,6 +990,7 @@ SOURCES += \
inspector/InjectedScriptHost.cpp \
inspector/InspectorApplicationCacheAgent.cpp \
inspector/InspectorBackend.cpp \
+ inspector/InspectorCSSAgent.cpp \
inspector/InspectorCSSStore.cpp \
inspector/InspectorController.cpp \
inspector/InspectorDatabaseResource.cpp \
@@ -1002,7 +1003,9 @@ SOURCES += \
inspector/InspectorProfilerAgent.cpp \
inspector/InspectorResource.cpp \
inspector/InspectorStorageAgent.cpp \
+ inspector/InspectorStyleSheet.cpp \
inspector/InspectorTimelineAgent.cpp \
+ inspector/InspectorUtilities.cpp \
inspector/InspectorValues.cpp \
inspector/ScriptBreakpoint.cpp \
inspector/TimelineRecordFactory.cpp \
@@ -1869,6 +1872,7 @@ HEADERS += \
inspector/InspectorApplicationCacheAgent.h \
inspector/InspectorBackend.h \
inspector/InspectorController.h \
+ inspector/InspectorCSSAgent.h \
inspector/InspectorDatabaseResource.h \
inspector/InspectorDebuggerAgent.h \
inspector/InspectorDOMStorageResource.h \
@@ -1879,7 +1883,9 @@ HEADERS += \
inspector/InspectorProfilerAgent.h \
inspector/InspectorResource.h \
inspector/InspectorStorageAgent.h \
+ inspector/InspectorStyleSheet.h \
inspector/InspectorTimelineAgent.h \
+ inspector/InspectorUtilities.h \
inspector/ScriptGCEventListener.h \
inspector/TimelineRecordFactory.h \
loader/appcache/ApplicationCacheGroup.h \
diff --git a/WebCore/WebCore.vcproj/WebCore.vcproj b/WebCore/WebCore.vcproj/WebCore.vcproj
index 007dba6..f546a09 100644
--- a/WebCore/WebCore.vcproj/WebCore.vcproj
+++ b/WebCore/WebCore.vcproj/WebCore.vcproj
@@ -52743,6 +52743,14 @@
>
</File>
<File
+ RelativePath="..\inspector\InspectorCSSAgent.cpp"
+ >
+ </File>
+ <File
+ RelativePath="..\inspector\InspectorCSSAgent.h"
+ >
+ </File>
+ <File
RelativePath="..\inspector\InspectorCSSStore.cpp"
>
</File>
@@ -52835,6 +52843,14 @@
>
</File>
<File
+ RelativePath="..\inspector\InspectorStyleSheet.cpp"
+ >
+ </File>
+ <File
+ RelativePath="..\inspector\InspectorStyleSheet.h"
+ >
+ </File>
+ <File
RelativePath="..\inspector\InspectorTimelineAgent.cpp"
>
</File>
@@ -52843,6 +52859,14 @@
>
</File>
<File
+ RelativePath="..\inspector\InspectorUtilities.cpp"
+ >
+ </File>
+ <File
+ RelativePath="..\inspector\InspectorUtilities.h"
+ >
+ </File>
+ <File
RelativePath="..\inspector\InspectorValues.cpp"
>
</File>
diff --git a/WebCore/WebCore.xcodeproj/project.pbxproj b/WebCore/WebCore.xcodeproj/project.pbxproj
index c7dd686..94b3ca2 100644
--- a/WebCore/WebCore.xcodeproj/project.pbxproj
+++ b/WebCore/WebCore.xcodeproj/project.pbxproj
@@ -1519,6 +1519,12 @@
81BE209911F4AB8D00915DFA /* IDBCursorBackendInterface.h in Headers */ = {isa = PBXBuildFile; fileRef = 81BE209411F4AB8D00915DFA /* IDBCursorBackendInterface.h */; };
81BE20D211F4BC3200915DFA /* JSIDBCursor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 81BE20A711F4B66F00915DFA /* JSIDBCursor.cpp */; };
81BE20D311F4BC3200915DFA /* JSIDBCursor.h in Headers */ = {isa = PBXBuildFile; fileRef = 81BE20A811F4B66F00915DFA /* JSIDBCursor.h */; };
+ 82AB1743124B99EC00C5069D /* InspectorCSSAgent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 82AB1741124B99EC00C5069D /* InspectorCSSAgent.cpp */; };
+ 82AB1744124B99EC00C5069D /* InspectorCSSAgent.h in Headers */ = {isa = PBXBuildFile; fileRef = 82AB1742124B99EC00C5069D /* InspectorCSSAgent.h */; };
+ 82AB1773125C826700C5069D /* InspectorStyleSheet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 82AB176F125C826700C5069D /* InspectorStyleSheet.cpp */; };
+ 82AB1774125C826700C5069D /* InspectorStyleSheet.h in Headers */ = {isa = PBXBuildFile; fileRef = 82AB1770125C826700C5069D /* InspectorStyleSheet.h */; };
+ 82AB1775125C826700C5069D /* InspectorUtilities.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 82AB1771125C826700C5069D /* InspectorUtilities.cpp */; };
+ 82AB1776125C826700C5069D /* InspectorUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 82AB1772125C826700C5069D /* InspectorUtilities.h */; };
82B658981189E39200E052A1 /* InspectorCSSStore.h in Headers */ = {isa = PBXBuildFile; fileRef = 82B658971189E39200E052A1 /* InspectorCSSStore.h */; settings = {ATTRIBUTES = (Private, ); }; };
82B6589A1189E47600E052A1 /* InspectorCSSStore.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 82B658991189E47600E052A1 /* InspectorCSSStore.cpp */; };
82E3D8DE122EA0D1003AE5BC /* CSSPropertySourceData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 82E3D8DC122EA0D1003AE5BC /* CSSPropertySourceData.cpp */; };
@@ -7614,6 +7620,12 @@
81BE209C11F4ABBD00915DFA /* IDBCursor.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = IDBCursor.idl; sourceTree = "<group>"; };
81BE20A711F4B66F00915DFA /* JSIDBCursor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSIDBCursor.cpp; sourceTree = "<group>"; };
81BE20A811F4B66F00915DFA /* JSIDBCursor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSIDBCursor.h; sourceTree = "<group>"; };
+ 82AB1741124B99EC00C5069D /* InspectorCSSAgent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InspectorCSSAgent.cpp; sourceTree = "<group>"; };
+ 82AB1742124B99EC00C5069D /* InspectorCSSAgent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorCSSAgent.h; sourceTree = "<group>"; };
+ 82AB176F125C826700C5069D /* InspectorStyleSheet.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InspectorStyleSheet.cpp; sourceTree = "<group>"; };
+ 82AB1770125C826700C5069D /* InspectorStyleSheet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorStyleSheet.h; sourceTree = "<group>"; };
+ 82AB1771125C826700C5069D /* InspectorUtilities.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InspectorUtilities.cpp; sourceTree = "<group>"; };
+ 82AB1772125C826700C5069D /* InspectorUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorUtilities.h; sourceTree = "<group>"; };
82B658971189E39200E052A1 /* InspectorCSSStore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorCSSStore.h; sourceTree = "<group>"; };
82B658991189E47600E052A1 /* InspectorCSSStore.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InspectorCSSStore.cpp; sourceTree = "<group>"; };
82E3D8DC122EA0D1003AE5BC /* CSSPropertySourceData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CSSPropertySourceData.cpp; sourceTree = "<group>"; };
@@ -12168,6 +12180,8 @@
1C81B9580E97330800266E07 /* InspectorClient.h */,
1C81B9570E97330800266E07 /* InspectorController.cpp */,
1C81B9560E97330800266E07 /* InspectorController.h */,
+ 82AB1741124B99EC00C5069D /* InspectorCSSAgent.cpp */,
+ 82AB1742124B99EC00C5069D /* InspectorCSSAgent.h */,
82B658991189E47600E052A1 /* InspectorCSSStore.cpp */,
82B658971189E39200E052A1 /* InspectorCSSStore.h */,
41F062130F5F192600A07EAC /* InspectorDatabaseResource.cpp */,
@@ -12192,8 +12206,12 @@
41F061FF0F5F0B6600A07EAC /* InspectorResource.h */,
7AB0B1BE1211A62200A76940 /* InspectorStorageAgent.cpp */,
7AB0B1BF1211A62200A76940 /* InspectorStorageAgent.h */,
+ 82AB176F125C826700C5069D /* InspectorStyleSheet.cpp */,
+ 82AB1770125C826700C5069D /* InspectorStyleSheet.h */,
754133A9102E00F400075D00 /* InspectorTimelineAgent.cpp */,
754133A7102E00E800075D00 /* InspectorTimelineAgent.h */,
+ 82AB1771125C826700C5069D /* InspectorUtilities.cpp */,
+ 82AB1772125C826700C5069D /* InspectorUtilities.h */,
4F3289B311A42AAB005ABE7E /* InspectorValues.cpp */,
4F3289B411A42AAB005ABE7E /* InspectorValues.h */,
F375CC061150D300008DDB81 /* InspectorWorkerResource.h */,
@@ -19641,6 +19659,7 @@
4F707A9A11EF679400ACDA69 /* InspectorBackendDispatcher.h in Headers */,
1C81B95C0E97330800266E07 /* InspectorClient.h in Headers */,
1C81B95A0E97330800266E07 /* InspectorController.h in Headers */,
+ 82AB1744124B99EC00C5069D /* InspectorCSSAgent.h in Headers */,
82B658981189E39200E052A1 /* InspectorCSSStore.h in Headers */,
41F062140F5F192600A07EAC /* InspectorDatabaseResource.h in Headers */,
F33F053E120B0DA500E5743A /* InspectorDebuggerAgent.h in Headers */,
@@ -21070,6 +21089,8 @@
893C483B12495472002B3D86 /* JSEntrySync.h in Headers */,
893C483D12495472002B3D86 /* JSFileEntrySync.h in Headers */,
890AE0E11256A07900F5968C /* DirectoryReaderBase.h in Headers */,
+ 82AB1774125C826700C5069D /* InspectorStyleSheet.h in Headers */,
+ 82AB1776125C826700C5069D /* InspectorUtilities.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -22213,6 +22234,7 @@
7A74ECBA101839A600BF939E /* InspectorBackend.cpp in Sources */,
4F707A9911EF679400ACDA69 /* InspectorBackendDispatcher.cpp in Sources */,
1C81B95B0E97330800266E07 /* InspectorController.cpp in Sources */,
+ 82AB1743124B99EC00C5069D /* InspectorCSSAgent.cpp in Sources */,
82B6589A1189E47600E052A1 /* InspectorCSSStore.cpp in Sources */,
41F062150F5F192600A07EAC /* InspectorDatabaseResource.cpp in Sources */,
F33F053D120B0DA500E5743A /* InspectorDebuggerAgent.cpp in Sources */,
@@ -23616,6 +23638,8 @@
893C483A12495472002B3D86 /* JSEntrySync.cpp in Sources */,
893C483C12495472002B3D86 /* JSFileEntrySync.cpp in Sources */,
893C485312499B06002B3D86 /* JSEntrySyncCustom.cpp in Sources */,
+ 82AB1773125C826700C5069D /* InspectorStyleSheet.cpp in Sources */,
+ 82AB1775125C826700C5069D /* InspectorUtilities.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
diff --git a/WebCore/inspector/InspectorCSSAgent.cpp b/WebCore/inspector/InspectorCSSAgent.cpp
new file mode 100644
index 0000000..a6be896
--- /dev/null
+++ b/WebCore/inspector/InspectorCSSAgent.cpp
@@ -0,0 +1,650 @@
+/*
+ * Copyright (C) 2010, Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "InspectorCSSAgent.h"
+
+#if ENABLE(INSPECTOR)
+
+#include "CSSComputedStyleDeclaration.h"
+#include "CSSMutableStyleDeclaration.h"
+#include "CSSPropertyNames.h"
+#include "CSSPropertySourceData.h"
+#include "CSSRule.h"
+#include "CSSRuleList.h"
+#include "CSSStyleRule.h"
+#include "CSSStyleSelector.h"
+#include "CSSStyleSheet.h"
+#include "DOMWindow.h"
+#include "HTMLHeadElement.h"
+#include "InspectorDOMAgent.h"
+#include "InspectorFrontend.h"
+#include "InspectorUtilities.h"
+#include "InspectorValues.h"
+#include "Node.h"
+#include "StyleSheetList.h"
+
+#include <wtf/HashSet.h>
+#include <wtf/ListHashSet.h>
+#include <wtf/Vector.h>
+#include <wtf/text/CString.h>
+
+
+// cssProperty = {
+// name : <string>,
+// value : <string>,
+// priority : <string>, // "" for non-parsedOk properties
+// implicit : <boolean>,
+// parsedOk : <boolean>, // whether property is understood by WebCore
+// status : <string>, // "disabled" | "active" | "inactive" | "style"
+// shorthandName : <string>,
+// startOffset : <number>, // Optional - property text start offset in enclosing style declaration. Absent for computed styles and such.
+// endOffset : <number>, // Optional - property text end offset in enclosing style declaration. Absent for computed styles and such.
+// }
+//
+// status:
+// "disabled" == property disabled by user
+// "active" == property participates in the computed style calculation
+// "inactive" == property does no participate in the computed style calculation (i.e. overridden by a subsequent property with the same name)
+// "style" == property is active and originates from the WebCore CSSStyleDeclaration rather than CSS source code (e.g. implicit longhand properties)
+//
+//
+// cssStyle = {
+// styleId : <number>, // Optional
+// styleSheetId : <number>, // Parent: -1 for inline styles (<foo style="..">)
+// cssProperties : [
+// #cssProperty,
+// ...
+// #cssProperty
+// ],
+// shorthandValues : {
+// shorthandName1 : shorthandValue1,
+// shorthandName2 : shorthandValue2
+// },
+// cssText : <string>, // declaration text
+// properties : { } // ???
+// }
+//
+// // TODO:
+// // - convert disabledProperties to enabled flag.
+// // - convert width, height to properties
+//
+// cssRule = {
+// ruleId : <number>,
+// selectorText : <string>
+// sourceURL : <string>
+// sourceLine : <string>
+// styleSheetId : <number> // also found in style
+// origin : <string> // "" || "user-agent" || "user" || "inspector"
+// style : #cssStyle
+// }
+//
+// // TODO:
+// // - fix origin
+// // - add sourceURL
+// // - fix parentStyleSheetId
+//
+// cssStyleSheet = {
+// styleSheetId : <number>
+// href : <string>
+// title : <string>
+// disabled : <boolean>
+// documentNodeId : <number>
+// rules : [
+// #cssRule,
+// ...
+// #cssRule
+// ]
+// }
+
+namespace WebCore {
+
+// static
+PassRefPtr<InspectorObject> InspectorCSSAgent::buildObjectForStyle(CSSStyleDeclaration* style, const String& fullStyleId, CSSStyleSourceData* sourceData)
+{
+ RefPtr<InspectorObject> result = InspectorObject::create();
+ if (!fullStyleId.isEmpty())
+ result->setString("id", fullStyleId);
+
+ result->setString("width", style->getPropertyValue("width"));
+ result->setString("height", style->getPropertyValue("height"));
+ Vector<CSSPropertySourceData>* propertyData = 0;
+
+ if (sourceData) {
+ result->setNumber("startOffset", sourceData->styleBodyRange.start);
+ result->setNumber("endOffset", sourceData->styleBodyRange.end);
+ propertyData = &sourceData->propertyData;
+ }
+ populateObjectWithStyleProperties(style, result.get(), propertyData);
+
+ return result.release();
+}
+
+// static
+CSSStyleSheet* InspectorCSSAgent::parentStyleSheet(StyleBase* styleBase)
+{
+ if (!styleBase)
+ return 0;
+
+ StyleSheet* styleSheet = styleBase->stylesheet();
+ if (styleSheet && styleSheet->isCSSStyleSheet())
+ return static_cast<CSSStyleSheet*>(styleSheet);
+
+ return 0;
+}
+
+// static
+CSSStyleRule* InspectorCSSAgent::asCSSStyleRule(StyleBase* styleBase)
+{
+ if (!styleBase->isStyleRule())
+ return 0;
+ CSSRule* rule = static_cast<CSSRule*>(styleBase);
+ if (rule->type() != CSSRule::STYLE_RULE)
+ return 0;
+ return static_cast<CSSStyleRule*>(rule);
+}
+
+
+InspectorCSSAgent::InspectorCSSAgent(InspectorDOMAgent* domAgent, InspectorFrontend* frontend)
+ : m_domAgent(domAgent)
+ , m_frontend(frontend)
+ , m_lastStyleSheetId(1)
+ , m_lastRuleId(1)
+ , m_lastStyleId(1)
+{
+ m_domAgent->setDOMListener(this);
+}
+
+InspectorCSSAgent::~InspectorCSSAgent()
+{
+ reset();
+}
+
+void InspectorCSSAgent::reset()
+{
+ m_domAgent->setDOMListener(0);
+}
+
+void InspectorCSSAgent::getMatchedRulesForNode2(long nodeId, RefPtr<InspectorArray>* result)
+{
+ Element* element = elementForId(nodeId);
+ if (!element)
+ return;
+
+ CSSStyleSelector* selector = element->ownerDocument()->styleSelector();
+ RefPtr<CSSRuleList> matchedRules = selector->styleRulesForElement(element, false, true);
+ *result = buildArrayForRuleList(matchedRules.get());
+}
+
+void InspectorCSSAgent::getMatchedPseudoRulesForNode2(long nodeId, RefPtr<InspectorArray>* result)
+{
+ Element* element = elementForId(nodeId);
+ if (!element)
+ return;
+
+ CSSStyleSelector* selector = element->ownerDocument()->styleSelector();
+ 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());
+ }
+ }
+}
+
+void InspectorCSSAgent::getAttributeStylesForNode2(long nodeId, RefPtr<InspectorValue>* result)
+{
+ Element* element = elementForId(nodeId);
+ if (!element)
+ return;
+
+ *result = buildObjectForAttributeStyles(element);
+}
+
+void InspectorCSSAgent::getInlineStyleForNode2(long nodeId, RefPtr<InspectorValue>* style)
+{
+ Element* element = elementForId(nodeId);
+ if (!element)
+ return;
+
+ InspectorStyleSheetForInlineStyle* styleSheet = asInspectorStyleSheet(element);
+ if (!styleSheet)
+ return;
+
+ *style = styleSheet->buildObjectForStyle(element->style());
+}
+
+void InspectorCSSAgent::getComputedStyleForNode2(long nodeId, RefPtr<InspectorValue>* style)
+{
+ Element* element = elementForId(nodeId);
+ if (!element)
+ return;
+
+ DOMWindow* defaultView = element->ownerDocument()->defaultView();
+ if (!defaultView)
+ return;
+
+ *style = buildObjectForStyle(defaultView->getComputedStyle(element, "").get(), "");
+}
+
+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("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();
+ for (ListHashSet<RefPtr<Document> >::const_iterator it = documents.begin(); it != documents.end(); ++it) {
+ StyleSheetList* list = (*it)->styleSheets();
+ for (unsigned i = 0; i < list->length(); ++i) {
+ StyleSheet* styleSheet = list->item(i);
+ if (styleSheet->isCSSStyleSheet()) {
+ InspectorStyleSheet* inspectorStyleSheet = bindStyleSheet(static_cast<CSSStyleSheet*>(styleSheet));
+ (*styles)->pushString(inspectorStyleSheet->id());
+ }
+ }
+ }
+}
+
+void InspectorCSSAgent::getStyleSheet2(const String& styleSheetId, RefPtr<InspectorValue>* styleSheetObject)
+{
+ InspectorStyleSheet* inspectorStyleSheet = styleSheetForId(styleSheetId);
+ if (!inspectorStyleSheet)
+ return;
+
+ *styleSheetObject = inspectorStyleSheet->buildObjectForStyleSheet();
+}
+
+void InspectorCSSAgent::setStyleSheetText2(const String& styleSheetId, const String& text)
+{
+ InspectorStyleSheet* inspectorStyleSheet = styleSheetForId(styleSheetId);
+ if (!inspectorStyleSheet)
+ return;
+
+ inspectorStyleSheet->setText(text);
+}
+
+void InspectorCSSAgent::setStyleText2(const String& fullStyleId, const String& text, RefPtr<InspectorValue>* result)
+{
+ Vector<String> idParts;
+ fullStyleId.split(':', idParts);
+ ASSERT(idParts.size() == 2);
+
+ InspectorStyleSheet* inspectorStyleSheet = styleSheetForId(idParts.at(0));
+ if (!inspectorStyleSheet)
+ return;
+
+ if (!inspectorStyleSheet->setStyleText(idParts.at(1), text))
+ return;
+
+ *result = inspectorStyleSheet->buildObjectForStyle(inspectorStyleSheet->styleForId(idParts.at(1)));
+}
+
+void InspectorCSSAgent::toggleProperty2(const String&, long, bool)
+{
+ // FIXME(apavlov): implement
+}
+
+void InspectorCSSAgent::setRuleSelector2(const String& fullRuleId, const String& selector, RefPtr<InspectorValue>* result)
+{
+ Vector<String> idParts;
+ fullRuleId.split(':', idParts);
+ ASSERT(idParts.size() == 2);
+
+ InspectorStyleSheet* inspectorStyleSheet = styleSheetForId(idParts.at(0));
+ if (!inspectorStyleSheet)
+ return;
+
+ const String& ruleId = idParts.at(1);
+ bool success = inspectorStyleSheet->setRuleSelector(ruleId, selector);
+ if (!success)
+ return;
+
+ *result = inspectorStyleSheet->buildObjectForRule(inspectorStyleSheet->ruleForId(ruleId));
+}
+
+void InspectorCSSAgent::addRule2(const long contextNodeId, const String& selector, RefPtr<InspectorValue>* result)
+{
+ Node* node = m_domAgent->nodeForId(contextNodeId);
+ if (!node)
+ return;
+
+ InspectorStyleSheet* inspectorStyleSheet = viaInspectorStyleSheet(node->document(), true);
+ CSSStyleRule* newRule = inspectorStyleSheet->addRule(selector);
+ if (newRule)
+ *result = inspectorStyleSheet->buildObjectForRule(newRule);
+}
+
+void InspectorCSSAgent::getSupportedCSSProperties(RefPtr<InspectorArray>* cssProperties)
+{
+ RefPtr<InspectorArray> properties = InspectorArray::create();
+ for (int i = 0; i < numCSSProperties; ++i)
+ properties->pushString(propertyNameStrings[i]);
+
+ *cssProperties = properties.release();
+}
+
+// static
+Element* InspectorCSSAgent::inlineStyleElement(CSSStyleDeclaration* style)
+{
+ if (!style || !style->isMutableStyleDeclaration())
+ return 0;
+ Node* node = static_cast<CSSMutableStyleDeclaration*>(style)->node();
+ if (!node || !node->isStyledElement() || static_cast<StyledElement*>(node)->getInlineStyleDecl() != style)
+ return 0;
+ return static_cast<Element*>(node);
+}
+
+// static
+void InspectorCSSAgent::populateObjectWithStyleProperties(CSSStyleDeclaration* style, InspectorObject* result, Vector<CSSPropertySourceData>* propertyData)
+{
+ RefPtr<InspectorArray> properties = InspectorArray::create();
+ RefPtr<InspectorObject> shorthandValues = InspectorObject::create();
+ HashMap<String, RefPtr<InspectorObject> > propertyNameToPreviousActiveProperty;
+ HashSet<String> foundShorthands;
+ HashSet<String> sourcePropertyNames;
+ if (propertyData) {
+ for (Vector<CSSPropertySourceData>::const_iterator it = propertyData->begin(); it != propertyData->end(); ++it) {
+ const CSSPropertySourceData& propertyEntry = *it;
+ RefPtr<InspectorObject> property = InspectorObject::create();
+ properties->pushObject(property);
+ const String& name = propertyEntry.name;
+ sourcePropertyNames.add(name);
+ property->setString("name", name);
+ property->setString("value", propertyEntry.value);
+ property->setString("priority", propertyEntry.important ? "important" : "");
+ property->setString("status", "active");
+ property->setBoolean("parsedOk", propertyEntry.parsedOk);
+ property->setNumber("startOffset", propertyEntry.range.start);
+ property->setNumber("endOffset", propertyEntry.range.end);
+ if (propertyEntry.parsedOk) {
+ property->setBoolean("implicit", false);
+ String shorthand = style->getPropertyShorthand(name);
+ property->setString("shorthandName", shorthand);
+ if (!shorthand.isEmpty() && !foundShorthands.contains(shorthand)) {
+ foundShorthands.add(shorthand);
+ shorthandValues->setString(shorthand, shorthandValue(style, shorthand));
+ }
+ } else {
+ property->setBoolean("implicit", false);
+ property->setString("shorthandName", "");
+ }
+ HashMap<String, RefPtr<InspectorObject> >::iterator activeIt = propertyNameToPreviousActiveProperty.find(name);
+ if (activeIt != propertyNameToPreviousActiveProperty.end()) {
+ activeIt->second->setString("status", "inactive");
+ activeIt->second->setString("shorthandName", "");
+ }
+ propertyNameToPreviousActiveProperty.set(name, property);
+ }
+ }
+
+ for (int i = 0, size = style->length(); i < size; ++i) {
+ String name = style->item(i);
+ if (sourcePropertyNames.contains(name))
+ continue;
+
+ sourcePropertyNames.add(name);
+ RefPtr<InspectorObject> property = InspectorObject::create();
+ properties->pushObject(property);
+ property->setString("name", name);
+ property->setString("value", style->getPropertyValue(name));
+ property->setString("priority", style->getPropertyPriority("name"));
+ property->setBoolean("implicit", style->isPropertyImplicit(name));
+ property->setBoolean("parsedOk", true);
+ property->setString("status", "style");
+ String shorthand = style->getPropertyShorthand(name);
+ property->setString("shorthandName", shorthand);
+ if (!shorthand.isEmpty() && !foundShorthands.contains(shorthand)) {
+ foundShorthands.add(shorthand);
+ shorthandValues->setString(shorthand, shorthandValue(style, shorthand));
+ }
+ }
+
+ result->setArray("properties", properties);
+ result->setObject("shorthandValues", shorthandValues);
+}
+
+// static
+String InspectorCSSAgent::shorthandValue(CSSStyleDeclaration* style, const String& shorthandProperty)
+{
+ String value = style->getPropertyValue(shorthandProperty);
+ if (value.isEmpty()) {
+ for (unsigned i = 0; i < style->length(); ++i) {
+ String individualProperty = style->item(i);
+ if (style->getPropertyShorthand(individualProperty) != shorthandProperty)
+ continue;
+ if (style->isPropertyImplicit(individualProperty))
+ continue;
+ String individualValue = style->getPropertyValue(individualProperty);
+ if (individualValue == "initial")
+ continue;
+ if (value.length())
+ value.append(" ");
+ value.append(individualValue);
+ }
+ }
+ return value;
+}
+
+// static
+String InspectorCSSAgent::shorthandPriority(CSSStyleDeclaration* style, const String& shorthandProperty)
+{
+ String priority = style->getPropertyPriority(shorthandProperty);
+ if (priority.isEmpty()) {
+ for (unsigned i = 0; i < style->length(); ++i) {
+ String individualProperty = style->item(i);
+ if (style->getPropertyShorthand(individualProperty) != shorthandProperty)
+ continue;
+ priority = style->getPropertyPriority(individualProperty);
+ break;
+ }
+ }
+ return priority;
+}
+
+
+// static
+Vector<String> InspectorCSSAgent::longhandProperties(CSSStyleDeclaration* style, const String& shorthandProperty)
+{
+ Vector<String> properties;
+ HashSet<String> foundProperties;
+ for (unsigned i = 0; i < style->length(); ++i) {
+ String individualProperty = style->item(i);
+ if (foundProperties.contains(individualProperty) || style->getPropertyShorthand(individualProperty) != shorthandProperty)
+ continue;
+
+ foundProperties.add(individualProperty);
+ properties.append(individualProperty);
+ }
+ return properties;
+}
+
+InspectorStyleSheetForInlineStyle* InspectorCSSAgent::asInspectorStyleSheet(Element* element)
+{
+ NodeToInspectorStyleSheet::iterator it = m_nodeToInspectorStyleSheet.find(element);
+ if (it == m_nodeToInspectorStyleSheet.end()) {
+ CSSStyleDeclaration* style = element->isStyledElement() ? element->style() : 0;
+ if (!style)
+ return 0;
+
+ String newStyleSheetId = String::number(m_lastStyleSheetId++);
+ RefPtr<InspectorStyleSheetForInlineStyle> inspectorStyleSheet = InspectorStyleSheetForInlineStyle::create(newStyleSheetId, element, "");
+ m_idToInspectorStyleSheet.set(newStyleSheetId, inspectorStyleSheet);
+ m_nodeToInspectorStyleSheet.set(element, inspectorStyleSheet);
+ return inspectorStyleSheet.get();
+ }
+
+ return it->second.get();
+}
+
+Element* InspectorCSSAgent::elementForId(long nodeId)
+{
+ Node* node = m_domAgent->nodeForId(nodeId);
+ return (!node || node->nodeType() != Node::ELEMENT_NODE) ? 0 : static_cast<Element*>(node);
+}
+
+InspectorStyleSheet* InspectorCSSAgent::bindStyleSheet(CSSStyleSheet* styleSheet)
+{
+ RefPtr<InspectorStyleSheet> inspectorStyleSheet = m_cssStyleSheetToInspectorStyleSheet.get(styleSheet);
+ if (!inspectorStyleSheet) {
+ String id = String::number(m_lastStyleSheetId++);
+ inspectorStyleSheet = InspectorStyleSheet::create(id, styleSheet, detectOrigin(styleSheet, styleSheet->document()), m_domAgent->documentURLString(styleSheet->document()));
+ m_idToInspectorStyleSheet.set(id, inspectorStyleSheet);
+ m_cssStyleSheetToInspectorStyleSheet.set(styleSheet, inspectorStyleSheet);
+ }
+ return inspectorStyleSheet.get();
+}
+
+InspectorStyleSheet* InspectorCSSAgent::viaInspectorStyleSheet(Document* document, bool createIfAbsent)
+{
+ if (!document) {
+ ASSERT(!createIfAbsent);
+ return 0;
+ }
+
+ RefPtr<InspectorStyleSheet> inspectorStyleSheet = m_documentToInspectorStyleSheet.get(document);
+ if (inspectorStyleSheet || !createIfAbsent)
+ return inspectorStyleSheet.get();
+
+ ExceptionCode ec = 0;
+ RefPtr<Element> styleElement = document->createElement("style", ec);
+ if (!ec)
+ styleElement->setAttribute("type", "text/css", ec);
+ if (!ec)
+ document->head()->appendChild(styleElement, ec);
+ if (ec)
+ return 0;
+ StyleSheetList* styleSheets = document->styleSheets();
+ StyleSheet* styleSheet = styleSheets->item(styleSheets->length() - 1);
+ if (!styleSheet->isCSSStyleSheet())
+ return 0;
+ CSSStyleSheet* cssStyleSheet = static_cast<CSSStyleSheet*>(styleSheet);
+ String id = String::number(m_lastStyleSheetId++);
+ inspectorStyleSheet = InspectorStyleSheet::create(id, cssStyleSheet, "inspector", m_domAgent->documentURLString(document));
+ m_idToInspectorStyleSheet.set(id, inspectorStyleSheet);
+ m_cssStyleSheetToInspectorStyleSheet.set(cssStyleSheet, inspectorStyleSheet);
+ m_documentToInspectorStyleSheet.set(document, inspectorStyleSheet);
+ return inspectorStyleSheet.get();
+}
+
+InspectorStyleSheet* InspectorCSSAgent::styleSheetForId(const String& styleSheetId)
+{
+ IdToInspectorStyleSheet::iterator it = m_idToInspectorStyleSheet.find(styleSheetId);
+ return it == m_idToInspectorStyleSheet.end() ? 0 : it->second.get();
+}
+
+String InspectorCSSAgent::detectOrigin(CSSStyleSheet* pageStyleSheet, Document* ownerDocument)
+{
+ DEFINE_STATIC_LOCAL(String, userAgent, ("user-agent"));
+ DEFINE_STATIC_LOCAL(String, user, ("user"));
+ DEFINE_STATIC_LOCAL(String, inspector, ("inspector"));
+
+ String origin("");
+ if (pageStyleSheet && !pageStyleSheet->ownerNode() && pageStyleSheet->href().isEmpty())
+ origin = userAgent;
+ else if (pageStyleSheet && pageStyleSheet->ownerNode() && pageStyleSheet->ownerNode()->nodeName() == "#document")
+ origin = user;
+ else {
+ InspectorStyleSheet* viaInspectorStyleSheetForOwner = viaInspectorStyleSheet(ownerDocument, false);
+ if (viaInspectorStyleSheetForOwner && pageStyleSheet == viaInspectorStyleSheetForOwner->pageStyleSheet())
+ origin = inspector;
+ }
+ return origin;
+}
+
+PassRefPtr<InspectorArray> InspectorCSSAgent::buildArrayForRuleList(CSSRuleList* ruleList)
+{
+ RefPtr<InspectorArray> result = InspectorArray::create();
+ if (!ruleList)
+ return result.release();
+
+ for (unsigned i = 0, size = ruleList->length(); i < size; ++i) {
+ CSSStyleRule* rule = asCSSStyleRule(ruleList->item(i));
+ if (!rule)
+ continue;
+
+ InspectorStyleSheet* styleSheet = bindStyleSheet(parentStyleSheet(rule));
+ if (styleSheet)
+ result->pushObject(styleSheet->buildObjectForRule(rule));
+ }
+ return result.release();
+}
+
+PassRefPtr<InspectorObject> InspectorCSSAgent::buildObjectForAttributeStyles(Element* element)
+{
+ RefPtr<InspectorObject> styleAttributes = InspectorObject::create();
+ NamedNodeMap* attributes = element->attributes();
+ for (unsigned i = 0; attributes && i < attributes->length(); ++i) {
+ Attribute* attribute = attributes->attributeItem(i);
+ if (attribute->style()) {
+ String attributeName = attribute->localName();
+ styleAttributes->setObject(attributeName.utf8().data(), buildObjectForStyle(attribute->style(), ""));
+ }
+ }
+
+ return styleAttributes;
+}
+
+void InspectorCSSAgent::didRemoveDocument(Document* document)
+{
+ m_documentToInspectorStyleSheet.remove(document);
+}
+
+void InspectorCSSAgent::didRemoveDOMNode(Node* node)
+{
+ NodeToInspectorStyleSheet::iterator it = m_nodeToInspectorStyleSheet.find(node);
+ if (it == m_nodeToInspectorStyleSheet.end())
+ return;
+
+ m_idToInspectorStyleSheet.remove(it->second->id());
+ m_nodeToInspectorStyleSheet.remove(node);
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(INSPECTOR)
diff --git a/WebCore/inspector/InspectorCSSAgent.h b/WebCore/inspector/InspectorCSSAgent.h
new file mode 100644
index 0000000..eb6013b
--- /dev/null
+++ b/WebCore/inspector/InspectorCSSAgent.h
@@ -0,0 +1,126 @@
+/*
+ * Copyright (C) 2010, Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef InspectorCSSAgent_h
+#define InspectorCSSAgent_h
+
+#include "Document.h"
+#include "InspectorDOMAgent.h"
+#include "InspectorStyleSheet.h"
+#include "InspectorValues.h"
+#include "PlatformString.h"
+
+#include <wtf/HashMap.h>
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefPtr.h>
+
+namespace WebCore {
+
+class CSSRule;
+class CSSRuleList;
+class CSSStyleDeclaration;
+class CSSStyleRule;
+class CSSStyleSheet;
+class Element;
+class InspectorFrontend;
+class NameNodeMap;
+class Node;
+
+#if ENABLE(INSPECTOR)
+
+class InspectorCSSAgent : public RefCounted<InspectorCSSAgent>, public InspectorDOMAgent::DOMListener {
+public:
+ static PassRefPtr<InspectorCSSAgent> create(InspectorDOMAgent* domAgent, InspectorFrontend* frontend)
+ {
+ return adoptRef(new InspectorCSSAgent(domAgent, frontend));
+ }
+
+ static PassRefPtr<InspectorObject> buildObjectForStyle(CSSStyleDeclaration*, const String& fullStyleId, CSSStyleSourceData* = 0);
+ static CSSStyleSheet* parentStyleSheet(StyleBase*);
+ static CSSStyleRule* asCSSStyleRule(StyleBase*);
+
+ InspectorCSSAgent(InspectorDOMAgent* domAgent, InspectorFrontend* frontend);
+ ~InspectorCSSAgent();
+
+ void reset();
+ void getMatchedRulesForNode2(long nodeId, RefPtr<InspectorArray>* rules);
+ void getMatchedPseudoRulesForNode2(long nodeId, RefPtr<InspectorArray>* rules);
+ void getAttributeStylesForNode2(long nodeId, RefPtr<InspectorValue>* styles);
+ 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);
+ void setStyleText2(const String& styleId, const String& text, RefPtr<InspectorValue>* result);
+ void toggleProperty2(const String& styleId, long propertyOrdinal, bool disabled);
+ 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);
+
+private:
+ typedef HashMap<String, RefPtr<InspectorStyleSheet> > IdToInspectorStyleSheet;
+ typedef HashMap<CSSStyleSheet*, RefPtr<InspectorStyleSheet> > CSSStyleSheetToInspectorStyleSheet;
+ typedef HashMap<Node*, RefPtr<InspectorStyleSheetForInlineStyle> > NodeToInspectorStyleSheet; // for bogus "stylesheets" with inline node styles
+ typedef HashMap<RefPtr<Document>, RefPtr<InspectorStyleSheet> > DocumentToViaInspectorStyleSheet; // "via inspector" stylesheets
+
+ static Element* inlineStyleElement(CSSStyleDeclaration*);
+ static void populateObjectWithStyleProperties(CSSStyleDeclaration*, InspectorObject* result, Vector<CSSPropertySourceData>* propertyData);
+ static String shorthandValue(CSSStyleDeclaration*, const String& shorthandProperty);
+ static String shorthandPriority(CSSStyleDeclaration*, const String& shorthandProperty);
+ static Vector<String> longhandProperties(CSSStyleDeclaration*, const String& shorthandProperty);
+
+ InspectorStyleSheetForInlineStyle* asInspectorStyleSheet(Element* element);
+ Element* elementForId(long nodeId);
+
+ InspectorStyleSheet* bindStyleSheet(CSSStyleSheet*);
+ InspectorStyleSheet* viaInspectorStyleSheet(Document*, bool createIfAbsent);
+ InspectorStyleSheet* styleSheetForId(const String& styleSheetId);
+ String detectOrigin(CSSStyleSheet* pageStyleSheet, Document* ownerDocument);
+
+ PassRefPtr<InspectorArray> buildArrayForRuleList(CSSRuleList* ruleList);
+ PassRefPtr<InspectorObject> buildObjectForAttributeStyles(Element* element);
+
+ // InspectorDOMAgent::DOMListener interface
+ virtual void didRemoveDocument(Document*);
+ virtual void didRemoveDOMNode(Node*);
+
+ RefPtr<InspectorDOMAgent> m_domAgent;
+ InspectorFrontend* m_frontend;
+
+ IdToInspectorStyleSheet m_idToInspectorStyleSheet;
+ CSSStyleSheetToInspectorStyleSheet m_cssStyleSheetToInspectorStyleSheet;
+ NodeToInspectorStyleSheet m_nodeToInspectorStyleSheet;
+ DocumentToViaInspectorStyleSheet m_documentToInspectorStyleSheet;
+
+ long m_lastStyleSheetId;
+ long m_lastRuleId;
+ long m_lastStyleId;
+};
+
+#endif
+
+} // namespace WebCore
+
+#endif // !defined(InspectorCSSAgent_h)
diff --git a/WebCore/inspector/InspectorDOMAgent.cpp b/WebCore/inspector/InspectorDOMAgent.cpp
index 2316f04..a2a02d0 100644
--- a/WebCore/inspector/InspectorDOMAgent.cpp
+++ b/WebCore/inspector/InspectorDOMAgent.cpp
@@ -217,6 +217,7 @@ InspectorDOMAgent::InspectorDOMAgent(InspectorCSSStore* cssStore, InspectorFront
: EventListener(InspectorDOMAgentType)
, m_cssStore(cssStore)
, m_frontend(frontend)
+ , m_domListener(0)
, m_lastNodeId(1)
, m_matchJobsTimer(this, &InspectorDOMAgent::onMatchJobsTimer)
{
@@ -239,6 +240,11 @@ void InspectorDOMAgent::reset()
ASSERT(!m_documents.size());
}
+void InspectorDOMAgent::setDOMListener(DOMListener* listener)
+{
+ m_domListener = listener;
+}
+
void InspectorDOMAgent::setDocument(Document* doc)
{
if (doc == mainFrameDocument())
@@ -328,6 +334,8 @@ void InspectorDOMAgent::unbind(Node* node, NodeToIdMap* nodesMap)
if (node->isFrameOwnerElement()) {
const HTMLFrameOwnerElement* frameOwner = static_cast<const HTMLFrameOwnerElement*>(node);
stopListening(frameOwner->contentDocument());
+ if (m_domListener)
+ m_domListener->didRemoveDocument(frameOwner->contentDocument());
cssStore()->removeDocument(frameOwner->contentDocument());
}
@@ -1104,6 +1112,9 @@ void InspectorDOMAgent::didRemoveDOMNode(Node* node)
if (!parentId)
return;
+ if (m_domListener)
+ m_domListener->didRemoveDOMNode(node);
+
if (!m_childrenRequested.contains(parentId)) {
// No children are mapped yet -> only notify on changes of hasChildren.
if (innerChildNodeCount(parent) == 1)
@@ -1502,6 +1513,7 @@ void InspectorDOMAgent::getSupportedCSSProperties(RefPtr<InspectorArray>* cssPro
RefPtr<InspectorArray> properties = InspectorArray::create();
for (int i = 0; i < numCSSProperties; ++i)
properties->pushString(propertyNameStrings[i]);
+
*cssProperties = properties.release();
}
diff --git a/WebCore/inspector/InspectorDOMAgent.h b/WebCore/inspector/InspectorDOMAgent.h
index 89c6fd0..2727ac2 100644
--- a/WebCore/inspector/InspectorDOMAgent.h
+++ b/WebCore/inspector/InspectorDOMAgent.h
@@ -80,6 +80,14 @@ namespace WebCore {
class InspectorDOMAgent : public EventListener {
public:
+ struct DOMListener {
+ virtual ~DOMListener()
+ {
+ }
+ virtual void didRemoveDocument(Document*) = 0;
+ virtual void didRemoveDOMNode(Node*) = 0;
+ };
+
static PassRefPtr<InspectorDOMAgent> create(InspectorCSSStore* cssStore, InspectorFrontend* frontend)
{
return adoptRef(new InspectorDOMAgent(cssStore, frontend));
@@ -148,6 +156,10 @@ namespace WebCore {
void pushNodeByPathToFrontend(const String& path, long* nodeId);
long inspectedNode(unsigned long num);
void copyNode(long nodeId);
+ const ListHashSet<RefPtr<Document> >& documents() { return m_documents; }
+ void setDOMListener(DOMListener*);
+
+ String documentURLString(Document* document) const;
private:
void startListening(Document* document);
@@ -185,7 +197,6 @@ namespace WebCore {
bool isWhitespace(Node* node);
Document* mainFrameDocument() const;
- String documentURLString(Document* document) const;
InspectorCSSStore* cssStore() { return m_cssStore; }
void onMatchJobsTimer(Timer<InspectorDOMAgent>*);
@@ -207,6 +218,7 @@ namespace WebCore {
InspectorCSSStore* m_cssStore;
InspectorFrontend* m_frontend;
+ DOMListener* m_domListener;
NodeToIdMap m_documentNodeToIdMap;
// Owns node mappings for dangling nodes.
Vector<NodeToIdMap*> m_danglingNodeToIdMaps;
diff --git a/WebCore/inspector/InspectorStyleSheet.cpp b/WebCore/inspector/InspectorStyleSheet.cpp
new file mode 100644
index 0000000..77c7694
--- /dev/null
+++ b/WebCore/inspector/InspectorStyleSheet.cpp
@@ -0,0 +1,570 @@
+/*
+ * Copyright (C) 2010, Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "InspectorStyleSheet.h"
+
+#if ENABLE(INSPECTOR)
+
+#include "CSSParser.h"
+#include "CSSPropertySourceData.h"
+#include "CSSRule.h"
+#include "CSSRuleList.h"
+#include "CSSStyleRule.h"
+#include "CSSStyleSelector.h"
+#include "CSSStyleSheet.h"
+#include "Document.h"
+#include "Element.h"
+#include "HTMLHeadElement.h"
+#include "InspectorCSSAgent.h"
+#include "InspectorUtilities.h"
+#include "InspectorValues.h"
+#include "Node.h"
+#include "StyleSheetList.h"
+
+#include <wtf/OwnPtr.h>
+#include <wtf/PassOwnPtr.h>
+#include <wtf/Vector.h>
+
+class ParsedStyleSheet {
+public:
+ typedef Vector<RefPtr<WebCore::CSSRuleSourceData> > SourceData;
+ ParsedStyleSheet();
+
+ WebCore::CSSStyleSheet* cssStyleSheet() const { return m_parserOutput; }
+ const String& text() const { return m_text; }
+ void setText(const String& text);
+ bool hasText() const { return m_hasText; }
+ SourceData* sourceData() const { return m_sourceData.get(); }
+ void setSourceData(PassOwnPtr<SourceData> sourceData);
+ bool hasSourceData() const { return m_sourceData; }
+ RefPtr<WebCore::CSSRuleSourceData> ruleSourceDataAt(unsigned index) const;
+
+private:
+
+ // StyleSheet constructed while parsing m_text.
+ WebCore::CSSStyleSheet* m_parserOutput;
+ String m_text;
+ bool m_hasText;
+ OwnPtr<SourceData> m_sourceData;
+};
+
+ParsedStyleSheet::ParsedStyleSheet()
+ : m_parserOutput(0)
+ , m_hasText(false)
+{
+}
+
+void ParsedStyleSheet::setText(const String& text)
+{
+ m_hasText = true;
+ m_text = text;
+ setSourceData(0);
+}
+
+void ParsedStyleSheet::setSourceData(PassOwnPtr<SourceData> sourceData)
+{
+ m_sourceData = sourceData;
+}
+
+RefPtr<WebCore::CSSRuleSourceData> ParsedStyleSheet::ruleSourceDataAt(unsigned index) const
+{
+ if (!hasSourceData() || index >= m_sourceData->size())
+ return 0;
+
+ return m_sourceData->at(index);
+}
+
+namespace WebCore {
+
+InspectorStyleSheet::InspectorStyleSheet(const String& id, CSSStyleSheet* pageStyleSheet, const String& origin, const String& documentURL)
+ : m_id(id)
+ , m_pageStyleSheet(pageStyleSheet)
+ , m_origin(origin)
+ , m_documentURL(documentURL)
+ , m_isRevalidating(false)
+{
+ m_parsedStyleSheet = new ParsedStyleSheet();
+}
+
+InspectorStyleSheet::~InspectorStyleSheet()
+{
+ delete m_parsedStyleSheet;
+}
+
+bool InspectorStyleSheet::setText(const String& text)
+{
+ if (!m_parsedStyleSheet)
+ return false;
+
+ m_parsedStyleSheet->setText(text);
+ for (unsigned i = 0, size = m_pageStyleSheet->length(); i < size; ++i)
+ m_pageStyleSheet->remove(i);
+
+ m_pageStyleSheet->parseString(text, m_pageStyleSheet->useStrictParsing());
+ return true;
+}
+
+bool InspectorStyleSheet::setRuleSelector(const String& ruleId, const String& selector)
+{
+ CSSStyleRule* rule = ruleForId(ruleId);
+ if (!rule)
+ return false;
+ CSSStyleSheet* styleSheet = InspectorCSSAgent::parentStyleSheet(rule);
+ if (!styleSheet || !ensureParsedDataReady())
+ return false;
+
+ rule->setSelectorText(selector);
+ RefPtr<CSSRuleSourceData> sourceData = ruleSourceDataFor(rule->style());
+ if (!sourceData)
+ return false;
+
+ const String& sheetText = m_parsedStyleSheet->text();
+ String newStyleSheetText = sheetText.substring(0, sourceData->selectorListRange.start);
+ newStyleSheetText += selector;
+ newStyleSheetText += sheetText.right(sheetText.length() - sourceData->selectorListRange.end);
+ m_parsedStyleSheet->setText(newStyleSheetText);
+ return true;
+}
+
+CSSStyleRule* InspectorStyleSheet::addRule(const String& selector)
+{
+ String text;
+ bool success = styleSheetText(&text);
+ if (!success)
+ return 0;
+
+ ExceptionCode ec = 0;
+ m_pageStyleSheet->addRule(selector, "", ec);
+ if (ec)
+ return 0;
+ RefPtr<CSSRuleList> rules = m_pageStyleSheet->cssRules();
+ ASSERT(rules->length());
+ CSSStyleRule* rule = InspectorCSSAgent::asCSSStyleRule(rules->item(rules->length() - 1));
+ ASSERT(rule);
+
+ if (text.length())
+ text += "\n";
+
+ text += selector;
+ text += " {}";
+ m_parsedStyleSheet->setText(text);
+
+ return rule;
+}
+
+CSSStyleRule* InspectorStyleSheet::ruleForId(const String& id) const
+{
+ if (!m_pageStyleSheet)
+ return 0;
+
+ bool ok;
+ unsigned index = id.toUInt(&ok);
+ if (!ok)
+ return 0;
+
+ unsigned currentIndex = 0;
+ for (unsigned i = 0, size = m_pageStyleSheet->length(); i < size; ++i) {
+ CSSStyleRule* rule = InspectorCSSAgent::asCSSStyleRule(m_pageStyleSheet->item(i));
+ if (!rule)
+ continue;
+ if (index == currentIndex)
+ return rule;
+
+ ++currentIndex;
+ }
+ return 0;
+}
+
+PassRefPtr<InspectorObject> InspectorStyleSheet::buildObjectForStyleSheet()
+{
+ CSSStyleSheet* styleSheet = pageStyleSheet();
+ if (!styleSheet)
+ return 0;
+
+ RefPtr<InspectorObject> result = InspectorObject::create();
+ result->setString("id", id());
+ result->setBoolean("disabled", styleSheet->disabled());
+ result->setString("href", styleSheet->href());
+ result->setString("title", styleSheet->title());
+ RefPtr<CSSRuleList> cssRuleList = CSSRuleList::create(styleSheet, true);
+ RefPtr<InspectorArray> cssRules = buildArrayForRuleList(cssRuleList.get());
+ result->setArray("cssRules", cssRules.release());
+
+ String styleSheetText;
+ bool success = text(&styleSheetText);
+ if (success)
+ result->setString("text", styleSheetText);
+
+ return result.release();
+}
+
+PassRefPtr<InspectorObject> InspectorStyleSheet::buildObjectForRule(CSSStyleRule* rule)
+{
+ CSSStyleSheet* styleSheet = pageStyleSheet();
+ if (!styleSheet)
+ return 0;
+
+ RefPtr<InspectorObject> result = InspectorObject::create();
+ result->setString("selectorText", rule->selectorText());
+ result->setString("cssText", rule->cssText());
+ result->setNumber("sourceLine", rule->sourceLine());
+ result->setString("documentURL", m_documentURL);
+
+ RefPtr<InspectorObject> parentStyleSheetValue = InspectorObject::create();
+ parentStyleSheetValue->setString("id", id());
+ parentStyleSheetValue->setString("href", styleSheet->href());
+ result->setObject("parentStyleSheet", parentStyleSheetValue.release());
+ result->setString("origin", m_origin);
+
+ RefPtr<CSSRuleSourceData> sourceData;
+ if (ensureParsedDataReady())
+ sourceData = ruleSourceDataFor(rule->style());
+ if (sourceData) {
+ result->setNumber("selectorStartOffset", sourceData->selectorListRange.start);
+ result->setNumber("selectorEndOffset", sourceData->selectorListRange.end);
+ }
+
+ result->setObject("style", buildObjectForStyle(rule->style()));
+ if (canBind())
+ result->setString("id", fullRuleId(rule));
+
+ return result.release();
+}
+
+PassRefPtr<InspectorObject> InspectorStyleSheet::buildObjectForStyle(CSSStyleDeclaration* style)
+{
+ RefPtr<CSSRuleSourceData> sourceData;
+ if (ensureParsedDataReady())
+ sourceData = ruleSourceDataFor(style);
+
+ RefPtr<InspectorObject> result = InspectorCSSAgent::buildObjectForStyle(style, fullStyleId(style), sourceData ? sourceData->styleSourceData.get() : 0);
+ result->setString("parentStyleSheetId", id());
+ return result.release();
+}
+
+CSSStyleDeclaration* InspectorStyleSheet::styleForId(const String& id) const
+{
+ CSSStyleRule* rule = ruleForId(id);
+ if (!rule)
+ return 0;
+
+ return rule->style();
+}
+
+bool InspectorStyleSheet::setStyleText(const String& styleId, const String& newText)
+{
+ CSSStyleDeclaration* style = styleForId(styleId);
+ if (!style)
+ return false;
+
+ return innerSetStyleText(style, newText);
+}
+
+Document* InspectorStyleSheet::ownerDocument() const
+{
+ return m_pageStyleSheet->document();
+}
+
+RefPtr<CSSRuleSourceData> InspectorStyleSheet::ruleSourceDataFor(CSSStyleDeclaration* style) const
+{
+ return m_parsedStyleSheet->ruleSourceDataAt(ruleIndexByStyle(style));
+}
+
+unsigned InspectorStyleSheet::ruleIndexByStyle(CSSStyleDeclaration* pageStyle) const
+{
+ unsigned index = 0;
+ for (unsigned i = 0, size = m_pageStyleSheet->length(); i < size; ++i) {
+ CSSStyleRule* rule = InspectorCSSAgent::asCSSStyleRule(m_pageStyleSheet->item(i));
+ if (!rule)
+ continue;
+ if (rule->style() == pageStyle)
+ return index;
+
+ ++index;
+ }
+ return UINT_MAX;
+}
+
+bool InspectorStyleSheet::ensureParsedDataReady()
+{
+ return ensureText() && ensureSourceData(pageStyleSheet()->ownerNode());
+}
+
+bool InspectorStyleSheet::text(String* result) const
+{
+ if (!ensureText())
+ return false;
+ *result = m_parsedStyleSheet->text();
+ return true;
+}
+
+bool InspectorStyleSheet::ensureText() const
+{
+ if (!m_parsedStyleSheet)
+ return false;
+ if (m_parsedStyleSheet->hasText())
+ return true;
+
+ String text;
+ bool success = styleSheetText(&text);
+ if (success)
+ m_parsedStyleSheet->setText(text);
+
+ return success;
+}
+
+bool InspectorStyleSheet::ensureSourceData(Node* ownerNode)
+{
+ if (m_parsedStyleSheet->hasSourceData())
+ return true;
+
+ if (!m_parsedStyleSheet->hasText())
+ return false;
+
+ RefPtr<CSSStyleSheet> newStyleSheet = CSSStyleSheet::create(ownerNode);
+ CSSParser p;
+ StyleRuleRangeMap ruleRangeMap;
+ p.parseSheet(newStyleSheet.get(), m_parsedStyleSheet->text(), 0, &ruleRangeMap);
+ OwnPtr<ParsedStyleSheet::SourceData> rangesVector(new ParsedStyleSheet::SourceData());
+
+ for (unsigned i = 0, length = newStyleSheet->length(); i < length; ++i) {
+ CSSStyleRule* rule = InspectorCSSAgent::asCSSStyleRule(newStyleSheet->item(i));
+ if (!rule)
+ continue;
+ StyleRuleRangeMap::iterator it = ruleRangeMap.find(rule);
+ if (it != ruleRangeMap.end())
+ rangesVector->append(it->second);
+ }
+
+ m_parsedStyleSheet->setSourceData(rangesVector.release());
+ return m_parsedStyleSheet->hasSourceData();
+}
+
+void InspectorStyleSheet::innerSetStyleSheetText(const String& newText)
+{
+ m_parsedStyleSheet->setText(newText);
+}
+
+bool InspectorStyleSheet::innerSetStyleText(CSSStyleDeclaration* style, const String& text)
+{
+ if (!pageStyleSheet())
+ return false;
+ if (!ensureParsedDataReady())
+ return false;
+
+ String patchedStyleSheetText;
+ bool success = styleSheetTextWithChangedStyle(style, text, &patchedStyleSheetText);
+ if (!success)
+ return false;
+
+ String id = ruleOrStyleId(style);
+ if (id.isEmpty())
+ return false;
+
+ ExceptionCode ec = 0;
+ style->setCssText(text, ec);
+ if (!ec)
+ innerSetStyleSheetText(patchedStyleSheetText);
+
+ return !ec;
+}
+
+bool InspectorStyleSheet::styleSheetTextWithChangedStyle(CSSStyleDeclaration* style, const String& newStyleText, String* result)
+{
+ if (!style)
+ return false;
+
+ if (!ensureParsedDataReady())
+ return false;
+
+ RefPtr<CSSRuleSourceData> sourceData = ruleSourceDataFor(style);
+ unsigned bodyStart = sourceData->styleSourceData->styleBodyRange.start;
+ unsigned bodyEnd = sourceData->styleSourceData->styleBodyRange.end;
+ ASSERT(bodyStart <= bodyEnd);
+
+ String text = m_parsedStyleSheet->text();
+ ASSERT(bodyEnd <= text.length()); // bodyEnd is exclusive
+
+ String patchedText = text.substring(0, bodyStart);
+ patchedText += newStyleText;
+ patchedText += text.substring(bodyEnd, text.length());
+ *result = patchedText;
+ return true;
+}
+
+CSSStyleRule* InspectorStyleSheet::findPageRuleWithStyle(CSSStyleDeclaration* style)
+{
+ for (unsigned i = 0, size = m_pageStyleSheet->length(); i < size; ++i) {
+ CSSStyleRule* rule = InspectorCSSAgent::asCSSStyleRule(m_pageStyleSheet->item(i));
+ if (!rule)
+ continue;
+ if (rule->style() == style)
+ return rule;
+ }
+ return 0;
+}
+
+String InspectorStyleSheet::fullRuleId(CSSStyleRule* rule) const
+{
+ return fullRuleOrStyleId(rule->style());
+}
+
+void InspectorStyleSheet::revalidateStyle(CSSStyleDeclaration* pageStyle)
+{
+ if (m_isRevalidating)
+ return;
+
+ m_isRevalidating = true;
+ CSSStyleSheet* parsedSheet = m_parsedStyleSheet->cssStyleSheet();
+ for (unsigned i = 0, size = parsedSheet->length(); i < size; ++i) {
+ StyleBase* styleBase = parsedSheet->item(i);
+ CSSStyleRule* parsedRule = InspectorCSSAgent::asCSSStyleRule(styleBase);
+ if (!parsedRule)
+ continue;
+ if (parsedRule->style() == pageStyle) {
+ if (parsedRule->style()->cssText() != pageStyle->cssText())
+ innerSetStyleText(pageStyle, pageStyle->cssText());
+ break;
+ }
+ }
+ m_isRevalidating = false;
+}
+
+bool InspectorStyleSheet::styleSheetText(String* result) const
+{
+ String text;
+ bool success = inlineStyleSheetText(&text);
+ if (!success)
+ success = resourceStyleSheetText(&text);
+ if (success)
+ *result = text;
+ return success;
+}
+
+bool InspectorStyleSheet::resourceStyleSheetText(String* result) const
+{
+ if (!m_pageStyleSheet)
+ return false;
+
+ return InspectorUtilities::resourceContentForURL(m_pageStyleSheet->finalURL(), ownerDocument(), result);
+}
+
+bool InspectorStyleSheet::inlineStyleSheetText(String* result) const
+{
+ if (!m_pageStyleSheet)
+ return false;
+
+ Node* ownerNode = m_pageStyleSheet->ownerNode();
+ if (!ownerNode || ownerNode->nodeType() != Node::ELEMENT_NODE)
+ return false;
+ Element* ownerElement = static_cast<Element*>(ownerNode);
+ if (ownerElement->tagName().lower() != "style")
+ return false;
+ *result = ownerElement->innerText();
+ return true;
+}
+
+PassRefPtr<InspectorArray> InspectorStyleSheet::buildArrayForRuleList(CSSRuleList* ruleList)
+{
+ RefPtr<InspectorArray> result = InspectorArray::create();
+ if (!ruleList)
+ return result.release();
+
+ for (unsigned i = 0, size = ruleList->length(); i < size; ++i) {
+ CSSStyleRule* rule = InspectorCSSAgent::asCSSStyleRule(ruleList->item(i));
+ if (!rule)
+ continue;
+
+ result->pushObject(buildObjectForRule(rule));
+ }
+ return result.release();
+}
+
+
+InspectorStyleSheetForInlineStyle::InspectorStyleSheetForInlineStyle(const String& id, Element* element, const String& origin)
+ : InspectorStyleSheet(id, 0, origin, "")
+ , m_element(element)
+ , m_ruleSourceData(0)
+{
+ ASSERT(element);
+}
+
+bool InspectorStyleSheetForInlineStyle::setStyleText(const String& styleId, const String& text)
+{
+ ASSERT(styleId == "0");
+ ExceptionCode ec = 0;
+ m_element->setAttribute("style", text, ec);
+ m_ruleSourceData.clear();
+ return !ec;
+}
+
+Document* InspectorStyleSheetForInlineStyle::ownerDocument() const
+{
+ return m_element->document();
+}
+
+bool InspectorStyleSheetForInlineStyle::ensureParsedDataReady()
+{
+ if (m_ruleSourceData)
+ return true;
+
+ m_ruleSourceData = CSSRuleSourceData::create();
+ RefPtr<CSSStyleSourceData> sourceData = CSSStyleSourceData::create();
+ bool success = getStyleAttributeRanges(&sourceData);
+ if (!success)
+ return false;
+
+ m_ruleSourceData->styleSourceData = sourceData.release();
+ return true;
+}
+
+CSSStyleDeclaration* InspectorStyleSheetForInlineStyle::inlineStyle() const
+{
+ return m_element->style();
+}
+
+bool InspectorStyleSheetForInlineStyle::getStyleAttributeRanges(RefPtr<CSSStyleSourceData>* result)
+{
+ DEFINE_STATIC_LOCAL(String, styleAttributeName, ("style"));
+
+ if (!m_element->isStyledElement())
+ return false;
+
+ String styleText = static_cast<StyledElement*>(m_element)->getAttribute(styleAttributeName);
+ if (styleText.isEmpty()) {
+ (*result)->styleBodyRange.start = 0;
+ (*result)->styleBodyRange.end = 0;
+ return true;
+ }
+
+ RefPtr<CSSMutableStyleDeclaration> tempDeclaration = CSSMutableStyleDeclaration::create();
+ CSSParser p;
+ p.parseDeclaration(tempDeclaration.get(), styleText, result);
+ return true;
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(INSPECTOR)
diff --git a/WebCore/inspector/InspectorStyleSheet.h b/WebCore/inspector/InspectorStyleSheet.h
new file mode 100644
index 0000000..f070e2a
--- /dev/null
+++ b/WebCore/inspector/InspectorStyleSheet.h
@@ -0,0 +1,134 @@
+/*
+ * Copyright (C) 2010, Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef InspectorStyleSheet_h
+#define InspectorStyleSheet_h
+
+#include "CSSPropertySourceData.h"
+#include "Document.h"
+#include "InspectorValues.h"
+#include "PlatformString.h"
+
+#include <wtf/HashMap.h>
+#include <wtf/HashSet.h>
+#include <wtf/OwnPtr.h>
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefPtr.h>
+
+class ParsedStyleSheet;
+
+namespace WebCore {
+
+class CSSRuleList;
+class CSSStyleDeclaration;
+class Element;
+class Node;
+
+#if ENABLE(INSPECTOR)
+
+class InspectorStyleSheet : public RefCounted<InspectorStyleSheet> {
+public:
+ static PassRefPtr<InspectorStyleSheet> create(const String& id, CSSStyleSheet* pageStyleSheet, const String& origin, const String& documentURL)
+ {
+ return adoptRef(new InspectorStyleSheet(id, pageStyleSheet, origin, documentURL));
+ }
+
+ InspectorStyleSheet(const String& id, CSSStyleSheet* pageStyleSheet, const String& origin, const String& documentURL);
+ virtual ~InspectorStyleSheet();
+
+ const String& id() const { return m_id; }
+ CSSStyleSheet* pageStyleSheet() const { return m_pageStyleSheet; }
+ bool setText(const String&);
+ bool setRuleSelector(const String& ruleId, const String& selector);
+ CSSStyleRule* addRule(const String& selector);
+ CSSStyleRule* ruleForId(const String&) const;
+ PassRefPtr<InspectorObject> buildObjectForStyleSheet();
+ PassRefPtr<InspectorObject> buildObjectForRule(CSSStyleRule*);
+ PassRefPtr<InspectorObject> buildObjectForStyle(CSSStyleDeclaration*);
+ virtual CSSStyleDeclaration* styleForId(const String&) const;
+ virtual bool setStyleText(const String& styleId, const String& text);
+
+protected:
+ bool canBind() const { return m_origin != "userAgent" && m_origin != "user"; }
+ String fullRuleOrStyleId(CSSStyleDeclaration* style) const { return id() + ":" + ruleOrStyleId(style); }
+ String ruleOrStyleId(CSSStyleDeclaration* style) const { unsigned index = ruleIndexByStyle(style); return index == UINT_MAX ? "" : String::number(index); }
+ virtual Document* ownerDocument() const;
+ virtual RefPtr<CSSRuleSourceData> ruleSourceDataFor(CSSStyleDeclaration* style) const;
+ virtual unsigned ruleIndexByStyle(CSSStyleDeclaration*) const;
+ virtual bool ensureParsedDataReady();
+
+private:
+ bool text(String* result) const;
+ bool ensureText() const;
+ bool ensureSourceData(Node* ownerNode);
+ void innerSetStyleSheetText(const String& newText);
+ bool innerSetStyleText(CSSStyleDeclaration*, const String&);
+ bool styleSheetTextWithChangedStyle(CSSStyleDeclaration*, const String& newStyleText, String* result);
+ CSSStyleRule* findPageRuleWithStyle(CSSStyleDeclaration*);
+ String fullRuleId(CSSStyleRule* rule) const;
+ String fullStyleId(CSSStyleDeclaration* style) const { return fullRuleOrStyleId(style); }
+ void revalidateStyle(CSSStyleDeclaration*);
+ bool styleSheetText(String* result) const;
+ bool resourceStyleSheetText(String* result) const;
+ bool inlineStyleSheetText(String* result) const;
+ PassRefPtr<InspectorArray> buildArrayForRuleList(CSSRuleList*);
+
+ String m_id;
+ CSSStyleSheet* m_pageStyleSheet;
+ String m_origin;
+ String m_documentURL;
+ bool m_isRevalidating;
+ ParsedStyleSheet* m_parsedStyleSheet;
+};
+
+class InspectorStyleSheetForInlineStyle : public InspectorStyleSheet {
+public:
+ static PassRefPtr<InspectorStyleSheetForInlineStyle> create(const String& id, Element* element, const String& origin)
+ {
+ return adoptRef(new InspectorStyleSheetForInlineStyle(id, element, origin));
+ }
+
+ InspectorStyleSheetForInlineStyle(const String& id, Element* element, const String& origin);
+ virtual CSSStyleDeclaration* styleForId(const String& id) const { ASSERT(id == "0"); return inlineStyle(); }
+ virtual bool setStyleText(const String& styleId, const String& text);
+
+protected:
+ virtual Document* ownerDocument() const;
+ virtual RefPtr<CSSRuleSourceData> ruleSourceDataFor(CSSStyleDeclaration* style) const { ASSERT(style == inlineStyle()); return m_ruleSourceData; }
+ virtual unsigned ruleIndexByStyle(CSSStyleDeclaration*) const { return 0; }
+ virtual bool ensureParsedDataReady();
+
+private:
+ CSSStyleDeclaration* inlineStyle() const;
+ bool getStyleAttributeRanges(RefPtr<CSSStyleSourceData>* result);
+
+ Element* m_element;
+ RefPtr<CSSRuleSourceData> m_ruleSourceData;
+};
+
+#endif
+
+} // namespace WebCore
+
+#endif // !defined(InspectorStyleSheet_h)
diff --git a/WebCore/inspector/InspectorUtilities.cpp b/WebCore/inspector/InspectorUtilities.cpp
new file mode 100644
index 0000000..3d6b0d7
--- /dev/null
+++ b/WebCore/inspector/InspectorUtilities.cpp
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "InspectorUtilities.h"
+
+#include "Cache.h"
+#include "CachedResource.h"
+#include "CachedResourceLoader.h"
+#include "Document.h"
+#include "DocumentLoader.h"
+#include "Frame.h"
+#include "FrameLoader.h"
+#include "KURL.h"
+#include "SharedBuffer.h"
+#include "TextEncoding.h"
+
+#include <wtf/RefPtr.h>
+
+#if ENABLE(INSPECTOR)
+
+namespace WebCore {
+
+// static
+bool InspectorUtilities::resourceContentForURL(const KURL& url, Document* frameDocument, String* result)
+{
+ if (!frameDocument)
+ return false;
+
+ String textEncodingName;
+ RefPtr<SharedBuffer> buffer;
+ if (equalIgnoringFragmentIdentifier(url, frameDocument->frame()->loader()->documentLoader()->requestURL())) {
+ textEncodingName = frameDocument->inputEncoding();
+ buffer = frameDocument->frame()->loader()->provisionalDocumentLoader()->mainResourceData();
+ } else {
+ const String& urlString = url.string();
+ CachedResource* cachedResource = frameDocument->cachedResourceLoader()->cachedResource(urlString);
+ if (!cachedResource)
+ cachedResource = cache()->resourceForURL(urlString);
+
+ ASSERT(cachedResource); // FIXME(apavlov): This might be too aggressive.
+
+ bool isUnpurgeable = true;
+ if (cachedResource->isPurgeable()) {
+ // If the resource is purgeable then make it unpurgeable to get
+ // its data. This might fail, in which case we return an
+ // empty String.
+ if (!cachedResource->makePurgeable(false))
+ isUnpurgeable = false;
+ }
+ if (isUnpurgeable) {
+ textEncodingName = cachedResource->encoding();
+ buffer = cachedResource->data();
+ }
+ }
+
+ if (buffer) {
+ TextEncoding encoding(textEncodingName);
+ if (!encoding.isValid())
+ encoding = WindowsLatin1Encoding();
+ *result = encoding.decode(buffer->data(), buffer->size());
+ return true;
+ }
+
+ return false;
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(INSPECTOR)
diff --git a/WebCore/inspector/InspectorUtilities.h b/WebCore/inspector/InspectorUtilities.h
new file mode 100644
index 0000000..2837426
--- /dev/null
+++ b/WebCore/inspector/InspectorUtilities.h
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2009 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef InspectorUtilities_h
+#define InspectorUtilities_h
+
+#include "PlatformString.h"
+
+#if ENABLE(INSPECTOR)
+
+namespace WebCore {
+
+class CSSStyleDeclaration;
+class CSSStyleRule;
+class CSSStyleSheet;
+class Document;
+class KURL;
+class StyleBase;
+
+class InspectorUtilities {
+public:
+ static bool resourceContentForURL(const KURL& url, Document* frameDocument, String* result);
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(INSPECTOR)
+
+#endif // !defined(InspectorUtilities_h)
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list