Commit 0c63b63d authored by apavlov@chromium.org's avatar apavlov@chromium.org

2010-12-01 Alexander Pavlov <apavlov@chromium.org>

        Reviewed by Yury Semikhatsky.

        Web Inspector: Remove obsolete CSS backend API from InspectorDOMAgent
        https://bugs.webkit.org/show_bug.cgi?id=50318

        WebCore:
        * CMakeLists.txt:
        * GNUmakefile.am:
        * WebCore.gypi:
        * WebCore.order:
        * WebCore.pro:
        * WebCore.vcproj/WebCore.vcproj:
        * WebCore.xcodeproj/project.pbxproj:
        * inspector/Inspector.idl:
        * inspector/InspectorCSSAgent.h:
        * inspector/InspectorCSSStore.cpp: Removed.
        * inspector/InspectorCSSStore.h: Removed.
        * inspector/InspectorController.cpp:
        (WebCore::InspectorController::InspectorController):
        (WebCore::InspectorController::connectFrontend):
        (WebCore::InspectorController::didCommitLoad):
        * inspector/InspectorController.h:
        * inspector/InspectorDOMAgent.cpp:
        (WebCore::InspectorDOMAgent::InspectorDOMAgent):
        (WebCore::InspectorDOMAgent::unbind):
        * inspector/InspectorDOMAgent.h:
        (WebCore::InspectorDOMAgent::create):

        LayoutTests:
        * inspector/styles-iframe.html:
        * inspector/styles-source-lines.html:
        * inspector/styles-source-offsets-expected.txt:
        * inspector/styles-source-offsets.html:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@73121 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 4c3cb621
2010-12-01 Alexander Pavlov <apavlov@chromium.org>
Reviewed by Yury Semikhatsky.
Web Inspector: Remove obsolete CSS backend API from InspectorDOMAgent
https://bugs.webkit.org/show_bug.cgi?id=50318
* inspector/styles-iframe.html:
* inspector/styles-source-lines.html:
* inspector/styles-source-offsets-expected.txt:
* inspector/styles-source-offsets.html:
2010-12-02 Adam Barth <abarth@webkit.org>
Reviewed by Eric Seidel.
......@@ -46,7 +46,7 @@ function frontend_dumpStylesContinuation(testController)
mainStyles = styles;
}
InspectorBackend.getStyles(body.id, false, mainFrameCallback);
InspectorBackend.getStylesForNode2(body.id, mainFrameCallback);
// 2. Find iframe node
var innerMapping = WebInspector.domAgent._idToDOMNode;
......@@ -67,7 +67,7 @@ function frontend_dumpStylesContinuation(testController)
testController.notifyDone([mainStyles, styles]);
}
InspectorBackend.getStyles(iframeBody.id, false, iframeCallback);
InspectorBackend.getStylesForNode2(iframeBody.id, iframeCallback);
}
</script>
......
......@@ -63,6 +63,8 @@ function doit()
{
var matchedCSSRules = styles.matchedCSSRules;
for (var i = 0; i < matchedCSSRules.length; ++i) {
if (matchedCSSRules[i].origin !== "")
continue;
output("Line:" + (matchedCSSRules[i].sourceLine + 1) + "\t" + matchedCSSRules[i].selectorText);
}
notifyDone();
......@@ -85,7 +87,7 @@ function frontend_getRawStyles(testController)
{
testController.notifyDone(styles);
}
InspectorBackend.getStyles(WebInspector.domAgent.document.body.id, true, callback);
InspectorBackend.getStylesForNode2(WebInspector.domAgent.document.body.id, callback);
}
</script>
......
......@@ -7,7 +7,7 @@ body: [0-4] [6-266]
important /* !important property not recognized by WebCore */' !important non-parsed] @[26-104]
['height':'100% !important' !important] @[109-133]
['colorz':'"!important"' non-parsed] @[138-159]
['important':'' non-parsed] @[164-174]
['important':'!important' non-parsed] @[164-185]
['color':'"badcolor" ! important /* good property with strange value */' !important non-parsed] @[190-259]
body.main1: [298-336] [337-418]
['color':'#F00BAA'] @[13-28]
......@@ -17,7 +17,7 @@ body.main2: [434-444] [445-540]
body.mainpage: [2-15] [17-149]
['text-decoration':'none'] @[5-27]
['badproperty':'1badvalue1' non-parsed] @[107-131]
element.style: [0-0] [0-31]
element.style: [0-31]
['font-weight':'normal'] @[0-20]
['width':'80%'] @[21-31]
......@@ -26,27 +26,45 @@ function frontend_runTest(testController)
{
testController.waitUntilDone();
frontend_expandDOMSubtree(WebInspector.domAgent.document);
testController.runAfterPendingDispatches(function() {
function stylesCallback(testController, styles)
{
var matchedCSSRules = styles.matchedCSSRules;
for (var i = 0; i < matchedCSSRules.length; ++i) {
var rule = matchedCSSRules[i];
InspectorBackend.getStyleSourceData(rule.style.styleId, frontend_styleDataReceived.bind(null, testController, rule, false));
frontend_dumpStyleData(testController, rule, false);
}
InspectorBackend.getStyleSourceData(styles.inlineStyle.styleId, frontend_styleDataReceived.bind(null, testController, styles.inlineStyle, true));
frontend_dumpStyleData(testController, styles.inlineStyle, true);
}
InspectorBackend.getStyles(WebInspector.domAgent.document.body.id, true, stylesCallback.bind(null, testController));
InspectorBackend.getStylesForNode2(WebInspector.domAgent.document.body.id, stylesCallback.bind(null, testController));
});
}
function frontend_styleDataReceived(testController, ruleOrStyle, shouldBail, data)
function frontend_dumpStyleData(testController, ruleOrStyle, shouldBail)
{
var isRule = !!(ruleOrStyle.style);
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 + "]");
var style;
var header = "";
if (isRule) {
if (ruleOrStyle.origin !== "") {
if (shouldBail)
testController.notifyDone(testController.results);
return;
}
style = ruleOrStyle.style;
header = ruleOrStyle.selectorText + ": [" + (ruleOrStyle.selectorRange ? ruleOrStyle.selectorRange.start + "-" + ruleOrStyle.selectorRange.end : "") + "]";
} else {
style = ruleOrStyle;
header = "element.style:";
}
testController.results.push(header + " [" + style.properties.startOffset + "-" + style.properties.endOffset + "]");
var allProperties = style.cssProperties;
for (var i = 0; i < allProperties.length; ++i) {
var property = allProperties[i];
if (property.status === "style")
continue;
testController.results.push("['" + property.name + "':'" + property.value + "'" + (property.priority ? " !important" : "") + (property.parsedOk ? "" : " non-parsed") +"] @[" + property.startOffset + "-" + property.endOffset + "]");
}
if (shouldBail)
testController.notifyDone(testController.results);
......
......@@ -1124,7 +1124,6 @@ SET(WebCore_SOURCES
inspector/InspectorApplicationCacheAgent.cpp
inspector/InspectorBackend.cpp
inspector/InspectorCSSAgent.cpp
inspector/InspectorCSSStore.cpp
inspector/InspectorClient.cpp
inspector/InspectorController.cpp
inspector/InspectorDOMAgent.cpp
......
2010-12-01 Alexander Pavlov <apavlov@chromium.org>
Reviewed by Yury Semikhatsky.
Web Inspector: Remove obsolete CSS backend API from InspectorDOMAgent
https://bugs.webkit.org/show_bug.cgi?id=50318
* CMakeLists.txt:
* GNUmakefile.am:
* WebCore.gypi:
* WebCore.order:
* WebCore.pro:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:
* inspector/Inspector.idl:
* inspector/InspectorCSSAgent.h:
* inspector/InspectorCSSStore.cpp: Removed.
* inspector/InspectorCSSStore.h: Removed.
* inspector/InspectorController.cpp:
(WebCore::InspectorController::InspectorController):
(WebCore::InspectorController::connectFrontend):
(WebCore::InspectorController::didCommitLoad):
* inspector/InspectorController.h:
* inspector/InspectorDOMAgent.cpp:
(WebCore::InspectorDOMAgent::InspectorDOMAgent):
(WebCore::InspectorDOMAgent::unbind):
* inspector/InspectorDOMAgent.h:
(WebCore::InspectorDOMAgent::create):
2010-12-02 Csaba Osztrogonác <ossy@webkit.org>
Unreviewed trivial buildfix after r73117.
......@@ -1897,8 +1897,6 @@ webcore_sources += \
WebCore/inspector/InspectorController.h \
WebCore/inspector/InspectorCSSAgent.cpp \
WebCore/inspector/InspectorCSSAgent.h \
WebCore/inspector/InspectorCSSStore.cpp \
WebCore/inspector/InspectorCSSStore.h \
WebCore/inspector/InspectorDatabaseResource.cpp \
WebCore/inspector/InspectorDatabaseResource.h \
WebCore/inspector/InspectorDebuggerAgent.cpp \
......
......@@ -1967,8 +1967,6 @@
'inspector/InspectorController.h',
'inspector/InspectorCSSAgent.cpp',
'inspector/InspectorCSSAgent.h',
'inspector/InspectorCSSStore.cpp',
'inspector/InspectorCSSStore.h',
'inspector/InspectorDatabaseResource.cpp',
'inspector/InspectorDatabaseResource.h',
'inspector/InspectorDebuggerAgent.cpp',
......
No preview for this file type
......@@ -1018,7 +1018,6 @@ SOURCES += \
inspector/InspectorApplicationCacheAgent.cpp \
inspector/InspectorBackend.cpp \
inspector/InspectorCSSAgent.cpp \
inspector/InspectorCSSStore.cpp \
inspector/InspectorClient.cpp \
inspector/InspectorController.cpp \
inspector/InspectorDatabaseResource.cpp \
......
......@@ -64649,14 +64649,6 @@
RelativePath="..\inspector\InspectorCSSAgent.h"
>
</File>
<File
RelativePath="..\inspector\InspectorCSSStore.cpp"
>
</File>
<File
RelativePath="..\inspector\InspectorCSSStore.h"
>
</File>
<File
RelativePath="..\inspector\InspectorDatabaseResource.cpp"
>
......@@ -1609,8 +1609,6 @@
82AB1774125C826700C5069D /* InspectorStyleSheet.h in Headers */ = {isa = PBXBuildFile; fileRef = 82AB1770125C826700C5069D /* InspectorStyleSheet.h */; };
82AB1775125C826700C5069D /* InspectorResourceAgent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 82AB1771125C826700C5069D /* InspectorResourceAgent.cpp */; };
82AB1776125C826700C5069D /* InspectorResourceAgent.h in Headers */ = {isa = PBXBuildFile; fileRef = 82AB1772125C826700C5069D /* InspectorResourceAgent.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 */; };
82E3D8DF122EA0D1003AE5BC /* CSSPropertySourceData.h in Headers */ = {isa = PBXBuildFile; fileRef = 82E3D8DD122EA0D1003AE5BC /* CSSPropertySourceData.h */; settings = {ATTRIBUTES = (Private, ); }; };
8419D2A7120D92D000141F8F /* SVGPathByteStream.h in Headers */ = {isa = PBXBuildFile; fileRef = 8419D2A4120D92D000141F8F /* SVGPathByteStream.h */; };
......@@ -7800,8 +7798,6 @@
82AB1770125C826700C5069D /* InspectorStyleSheet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorStyleSheet.h; sourceTree = "<group>"; };
82AB1771125C826700C5069D /* InspectorResourceAgent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InspectorResourceAgent.cpp; sourceTree = "<group>"; };
82AB1772125C826700C5069D /* InspectorResourceAgent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorResourceAgent.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>"; };
82E3D8DD122EA0D1003AE5BC /* CSSPropertySourceData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSSPropertySourceData.h; sourceTree = "<group>"; };
8419D2A4120D92D000141F8F /* SVGPathByteStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGPathByteStream.h; sourceTree = "<group>"; };
......@@ -12387,8 +12383,6 @@
1C81B9560E97330800266E07 /* InspectorController.h */,
82AB1741124B99EC00C5069D /* InspectorCSSAgent.cpp */,
82AB1742124B99EC00C5069D /* InspectorCSSAgent.h */,
82B658991189E47600E052A1 /* InspectorCSSStore.cpp */,
82B658971189E39200E052A1 /* InspectorCSSStore.h */,
41F062130F5F192600A07EAC /* InspectorDatabaseResource.cpp */,
41F062120F5F192600A07EAC /* InspectorDatabaseResource.h */,
F33F053B120B0DA500E5743A /* InspectorDebuggerAgent.cpp */,
......@@ -19970,7 +19964,6 @@
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 */,
7A24587C1021EAF4000A00AA /* InspectorDOMAgent.h in Headers */,
......@@ -22599,7 +22592,6 @@
7A1F2B52126C61B20006A7E6 /* InspectorClient.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 */,
7A24587B1021EAF4000A00AA /* InspectorDOMAgent.cpp in Sources */,
......@@ -197,19 +197,6 @@ module core {
[handler=Controller] void highlightFrame(in unsigned long frameId);
[handler=Controller] void hideFrameHighlight();
[handler=DOM] void getStyles(in long nodeId, in boolean authOnly, out Value styles);
[handler=DOM] void getAllStyles(out Array styles);
[handler=DOM] void getInlineStyle(in long nodeId, out Value style);
[handler=DOM] void getComputedStyle(in long nodeId, out Value style);
[handler=DOM] void getStyleSheet(in long styleSheetId, out Object styleSheet);
[handler=DOM] void getStyleSourceData(in long styleSheetId, out Object styleSourceData);
[handler=DOM] void applyStyleText(in long styleId, in String styleText, in String propertyName, out boolean success, out Value style);
[handler=DOM] void setStyleText(in long styleId, in String styleText, out boolean success);
[handler=DOM] void setStyleProperty(in long styleId, in String name, in String value, out boolean success);
[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=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);
......
......@@ -46,6 +46,7 @@ class Element;
class InspectorFrontend;
class NameNodeMap;
class Node;
class StyleBase;
#if ENABLE(INSPECTOR)
......
/*
* 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.
* 3. Neither the name of Apple Computer, Inc. ("Apple") 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 APPLE 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 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 "InspectorCSSStore.h"
#if ENABLE(INSPECTOR)
#include "CSSMutableStyleDeclaration.h"
#include "CSSParser.h"
#include "CSSRuleList.h"
#include "CSSStyleDeclaration.h"
#include "CSSStyleRule.h"
#include "CSSStyleSheet.h"
#include "CachedResource.h"
#include "DocumentLoader.h"
#include "Element.h"
#include "Frame.h"
#include "HTMLHeadElement.h"
#include "InspectorController.h"
#include "InspectorResourceAgent.h"
#include "Node.h"
#include "PlatformString.h"
#include "SharedBuffer.h"
#include "StyleSheetList.h"
#include "TextEncoding.h"
namespace WebCore {
InspectorCSSStore::InspectorCSSStore(InspectorController* inspectorController)
: m_inspectorController(inspectorController)
, m_lastStyleId(1)
, m_lastStyleSheetId(1)
, m_lastRuleId(1)
{
}
InspectorCSSStore::~InspectorCSSStore()
{
}
void InspectorCSSStore::reset()
{
m_styleToId.clear();
m_idToStyle.clear();
m_ruleToId.clear();
m_idToRule.clear();
deleteAllValues(m_styleSheetToOffsets);
m_styleSheetToOffsets.clear();
m_styleSheetToId.clear();
m_idToStyleSheet.clear();
m_idToStyleSheetText.clear();
m_idToDisabledStyle.clear();
m_documentNodeToInspectorStyleSheetMap.clear();
m_lastStyleId = 1;
m_lastStyleSheetId = 1;
m_lastRuleId = 1;
}
void InspectorCSSStore::removeDocument(Document* doc)
{
m_documentNodeToInspectorStyleSheetMap.remove(doc);
}
CSSStyleSheet* InspectorCSSStore::inspectorStyleSheet(Document* ownerDocument, bool createIfAbsent)
{
DocumentToStyleSheetMap::iterator it = m_documentNodeToInspectorStyleSheetMap.find(ownerDocument);
if (it != m_documentNodeToInspectorStyleSheetMap.end())
return it->second.get();
if (!createIfAbsent)
return 0;
ExceptionCode ec = 0;
RefPtr<Element> styleElement = ownerDocument->createElement("style", ec);
if (!ec)
styleElement->setAttribute("type", "text/css", ec);
if (!ec)
ownerDocument->head()->appendChild(styleElement, ec);
if (ec)
return 0;
StyleSheetList* styleSheets = ownerDocument->styleSheets();
StyleSheet* styleSheet = styleSheets->item(styleSheets->length() - 1);
if (!styleSheet->isCSSStyleSheet())
return 0;
CSSStyleSheet* inspectorStyleSheet = static_cast<CSSStyleSheet*>(styleSheet);
m_documentNodeToInspectorStyleSheetMap.set(ownerDocument, inspectorStyleSheet);
return inspectorStyleSheet;
}
String InspectorCSSStore::styleSheetText(long styleSheetId)
{
IdToStyleSheetTextMap::iterator it = m_idToStyleSheetText.find(styleSheetId);
if (it != m_idToStyleSheetText.end())
return it->second;
CSSStyleSheet* styleSheet = styleSheetForId(styleSheetId);
if (!styleSheet)
return String();
String result;
bool success = false;
Node* ownerNode = styleSheet->ownerNode();
if (ownerNode && ownerNode->nodeType() == Node::ELEMENT_NODE) {
Element* ownerElement = static_cast<Element*>(ownerNode);
if (ownerElement->tagName().lower() == "style") {
result = inlineStyleSheetText(styleSheet);
success = true;
}
}
if (!success)
success = resourceStyleSheetText(styleSheet, &result);
if (success)
m_idToStyleSheetText.set(styleSheetId, result);
return result;
}
bool InspectorCSSStore::resourceStyleSheetText(CSSStyleSheet* styleSheet, String* result)
{
return InspectorResourceAgent::resourceContent(styleSheet->document()->frame(), styleSheet->finalURL(), result);
}
String InspectorCSSStore::inlineStyleSheetText(CSSStyleSheet* styleSheet)
{
Node* ownerNode = styleSheet->ownerNode();
if (!ownerNode || ownerNode->nodeType() != Node::ELEMENT_NODE || m_styleSheetToId.find(styleSheet) == m_styleSheetToId.end())
return String();
Element* ownerElement = static_cast<Element*>(ownerNode);
if (ownerElement->tagName().lower() != "style")
return String();
return ownerElement->innerText();
}
// All ranges are: [start; end) (start - inclusive, end - exclusive).
bool InspectorCSSStore::getRuleSourceData(CSSStyleDeclaration* style, RefPtr<CSSRuleSourceData>* result)
{
if (!style)
return false;
Element* element = inlineStyleElement(style);
if (element) {
// Inline: style="...".
RefPtr<CSSRuleSourceData> ruleSourceData = CSSRuleSourceData::create();
RefPtr<CSSStyleSourceData> styleSourceData = CSSStyleSourceData::create();
bool success = getStyleAttributeRanges(element, &styleSourceData);
if (!success)
return false;
ruleSourceData->styleSourceData = styleSourceData.release();
*result = ruleSourceData;
return true;
}
CSSStyleSheet* styleSheet = getParentStyleSheet(style);
if (!styleSheet)
return false;
Vector<RefPtr<CSSRuleSourceData> >* rangesVector = 0;
StyleSheetToOffsetsMap::iterator it = m_styleSheetToOffsets.find(styleSheet);
if (it == m_styleSheetToOffsets.end()) {
String text = styleSheetText(bindStyleSheet(styleSheet));
if (!text.isEmpty()) {
RefPtr<CSSStyleSheet> newStyleSheet = CSSStyleSheet::create(styleSheet->ownerNode());
CSSParser p;
StyleRuleRangeMap ruleRangeMap;
p.parseSheet(newStyleSheet.get(), text, 0, &ruleRangeMap);
rangesVector = new Vector<RefPtr<CSSRuleSourceData> >;
extractRanges(newStyleSheet.get(), ruleRangeMap, rangesVector);
m_styleSheetToOffsets.set(styleSheet, rangesVector);
}
} else
rangesVector = it->second;
if (!rangesVector)
return false;
unsigned ruleIndex = 0;
for (unsigned i = 0, length = styleSheet->length(); i < length; ++i) {
CSSStyleRule* rule = asCSSStyleRule(styleSheet->item(i));
if (!rule)
continue;
if (rule->style() == style) {
ASSERT(ruleIndex < rangesVector->size());
*result = rangesVector->at(ruleIndex);
return true;
}
ruleIndex++;
}
return false;
}
void InspectorCSSStore::extractRanges(CSSStyleSheet* styleSheet, const StyleRuleRangeMap& ruleRangeMap, Vector<RefPtr<CSSRuleSourceData> >* rangesVector)
{
for (unsigned i = 0, length = styleSheet->length(); i < length; ++i) {
CSSStyleRule* rule = asCSSStyleRule(styleSheet->item(i));
if (!rule)
continue;
StyleRuleRangeMap::const_iterator it = ruleRangeMap.find(rule);
if (it != ruleRangeMap.end())
rangesVector->append(it->second);
}
}
bool InspectorCSSStore::getStyleAttributeRanges(Node* node, RefPtr<CSSStyleSourceData>* result)
{
if (!node || !node->isStyledElement())
return false;
String styleText = static_cast<StyledElement*>(node)->getAttribute("style");
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;
}
CSSStyleSheet* InspectorCSSStore::getParentStyleSheet(CSSStyleDeclaration* style)
{
if (!style)
return 0;
StyleSheet* styleSheet = style->stylesheet();
if (styleSheet && styleSheet->isCSSStyleSheet())
return static_cast<CSSStyleSheet*>(styleSheet);
return 0;
}
CSSStyleRule* InspectorCSSStore::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);
}
DisabledStyleDeclaration* InspectorCSSStore::disabledStyleForId(long styleId, bool createIfAbsent)
{
IdToDisabledStyleMap::iterator it = m_idToDisabledStyle.find(styleId);
if (it == m_idToDisabledStyle.end() && createIfAbsent)
it = m_idToDisabledStyle.set(styleId, DisabledStyleDeclaration()).first;
return it == m_idToDisabledStyle.end() ? 0 : &(it->second);
}
CSSStyleDeclaration* InspectorCSSStore::styleForId(long styleId)
{
IdToStyleMap::iterator it = m_idToStyle.find(styleId);
return it == m_idToStyle.end() ? 0 : it->second.get();
}
CSSStyleSheet* InspectorCSSStore::styleSheetForId(long styleSheetId)
{
IdToStyleSheetMap::iterator it = m_idToStyleSheet.find(styleSheetId);
return it == m_idToStyleSheet.end() ? 0 : it->second.get();
}
CSSStyleRule* InspectorCSSStore::ruleForId(long ruleId)
{
IdToRuleMap::iterator it = m_idToRule.find(ruleId);
return it == m_idToRule.end() ? 0 : it->second.get();
}
long InspectorCSSStore::bindStyle(CSSStyleDeclaration* style)
{
long id = m_styleToId.get(style);
if (!id) {
id = m_lastStyleId++;
m_idToStyle.set(id, style);
m_styleToId.set(style, id);
}
return id;
}
long InspectorCSSStore::bindStyleSheet(CSSStyleSheet* styleSheet)
{
long id = m_styleSheetToId.get(styleSheet);
if (!id) {
id = m_lastStyleSheetId++;
m_idToStyleSheet.set(id, styleSheet);
m_styleSheetToId.set(styleSheet, id);
}
return id;
}
long InspectorCSSStore::bindRule(CSSStyleRule* rule)
{
long id = m_ruleToId.get(rule);
if (!id) {
id = m_lastRuleId++;
m_idToRule.set(id, rule);
m_ruleToId.set(rule, id);
}
return id;
}
// static
Elemen