OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010, Google Inc. All rights reserved. | 2 * Copyright (C) 2010, Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 #include "NamedFlow.h" | 47 #include "NamedFlow.h" |
48 #include "NamedFlowCollection.h" | 48 #include "NamedFlowCollection.h" |
49 #include "Node.h" | 49 #include "Node.h" |
50 #include "NodeList.h" | 50 #include "NodeList.h" |
51 #include "RenderRegion.h" | 51 #include "RenderRegion.h" |
52 #include "SVGStyleElement.h" | 52 #include "SVGStyleElement.h" |
53 #include "StylePropertySet.h" | 53 #include "StylePropertySet.h" |
54 #include "StylePropertyShorthand.h" | 54 #include "StylePropertyShorthand.h" |
55 #include "StyleResolver.h" | 55 #include "StyleResolver.h" |
56 #include "StyleRule.h" | 56 #include "StyleRule.h" |
| 57 #include "StyleSheet.h" |
57 #include "StyleSheetList.h" | 58 #include "StyleSheetList.h" |
58 | 59 |
59 #include <wtf/CurrentTime.h> | 60 #include <wtf/CurrentTime.h> |
60 #include <wtf/HashSet.h> | 61 #include <wtf/HashSet.h> |
61 #include <wtf/Vector.h> | 62 #include <wtf/Vector.h> |
62 #include <wtf/text/CString.h> | 63 #include <wtf/text/CString.h> |
63 #include <wtf/text/StringConcatenate.h> | 64 #include <wtf/text/StringConcatenate.h> |
64 | 65 |
65 namespace CSSAgentState { | 66 namespace CSSAgentState { |
66 static const char cssAgentEnabled[] = "cssAgentEnabled"; | 67 static const char cssAgentEnabled[] = "cssAgentEnabled"; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 private: | 125 private: |
125 | 126 |
126 // Key is "selector?url:line". | 127 // Key is "selector?url:line". |
127 typedef HashMap<String, RuleMatchingStats> RuleMatchingStatsMap; | 128 typedef HashMap<String, RuleMatchingStats> RuleMatchingStatsMap; |
128 | 129 |
129 double m_totalMatchingTimeMs; | 130 double m_totalMatchingTimeMs; |
130 RuleMatchingStatsMap m_ruleMatchingStats; | 131 RuleMatchingStatsMap m_ruleMatchingStats; |
131 RuleMatchData m_currentMatchData; | 132 RuleMatchData m_currentMatchData; |
132 }; | 133 }; |
133 | 134 |
| 135 class StyleSheetVisitor { |
| 136 public: |
| 137 StyleSheetVisitor(CSSStyleSheet* styleSheet) |
| 138 : m_styleSheet(styleSheet) { } |
| 139 virtual ~StyleSheetVisitor() { } |
| 140 void run(); |
| 141 virtual void visit(CSSStyleSheet*) = 0; |
| 142 |
| 143 private: |
| 144 void run(CSSStyleSheet*); |
| 145 CSSStyleSheet* m_styleSheet; |
| 146 }; |
| 147 |
| 148 void StyleSheetVisitor::run() |
| 149 { |
| 150 run(m_styleSheet); |
| 151 } |
| 152 |
| 153 void StyleSheetVisitor::run(CSSStyleSheet* styleSheet) |
| 154 { |
| 155 visit(styleSheet); |
| 156 for (unsigned i = 0, size = styleSheet->length(); i < size; ++i) { |
| 157 CSSRule* rule = styleSheet->item(i); |
| 158 if (rule->type() == CSSRule::IMPORT_RULE) { |
| 159 CSSStyleSheet* importedStyleSheet = static_cast<CSSImportRule*>(rule
)->styleSheet(); |
| 160 if (importedStyleSheet) |
| 161 run(importedStyleSheet); |
| 162 } |
| 163 } |
| 164 } |
| 165 |
| 166 class StyleSheetAppender : public StyleSheetVisitor { |
| 167 public: |
| 168 StyleSheetAppender(CSSStyleSheet* styleSheet, Vector<CSSStyleSheet*>& result
) |
| 169 : StyleSheetVisitor(styleSheet) |
| 170 , m_result(result) { } |
| 171 |
| 172 private: |
| 173 virtual void visit(CSSStyleSheet* styleSheet) OVERRIDE |
| 174 { |
| 175 m_result.append(styleSheet); |
| 176 } |
| 177 |
| 178 Vector<CSSStyleSheet*>& m_result; |
| 179 }; |
| 180 |
| 181 class StyleSheetBinder : public StyleSheetVisitor { |
| 182 public: |
| 183 StyleSheetBinder(InspectorCSSAgent* agent, CSSStyleSheet* styleSheet) |
| 184 : StyleSheetVisitor(styleSheet) |
| 185 , m_agent(agent) { } |
| 186 |
| 187 private: |
| 188 virtual void visit(CSSStyleSheet* styleSheet) OVERRIDE |
| 189 { |
| 190 if (!m_agent->m_cssStyleSheetToInspectorStyleSheet.contains(styleSheet)) |
| 191 m_agent->m_frontend->styleSheetAdded(m_agent->bindStyleSheet(static_
cast<CSSStyleSheet*>(styleSheet))->buildObjectForStyleSheetInfo()); |
| 192 } |
| 193 |
| 194 InspectorCSSAgent* m_agent; |
| 195 }; |
| 196 |
134 | 197 |
135 static unsigned computePseudoClassMask(InspectorArray* pseudoClassArray) | 198 static unsigned computePseudoClassMask(InspectorArray* pseudoClassArray) |
136 { | 199 { |
137 DEFINE_STATIC_LOCAL(String, active, (ASCIILiteral("active"))); | 200 DEFINE_STATIC_LOCAL(String, active, (ASCIILiteral("active"))); |
138 DEFINE_STATIC_LOCAL(String, hover, (ASCIILiteral("hover"))); | 201 DEFINE_STATIC_LOCAL(String, hover, (ASCIILiteral("hover"))); |
139 DEFINE_STATIC_LOCAL(String, focus, (ASCIILiteral("focus"))); | 202 DEFINE_STATIC_LOCAL(String, focus, (ASCIILiteral("focus"))); |
140 DEFINE_STATIC_LOCAL(String, visited, (ASCIILiteral("visited"))); | 203 DEFINE_STATIC_LOCAL(String, visited, (ASCIILiteral("visited"))); |
141 if (!pseudoClassArray || !pseudoClassArray->length()) | 204 if (!pseudoClassArray || !pseudoClassArray->length()) |
142 return PseudoNone; | 205 return PseudoNone; |
143 | 206 |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 if (rule->type() != CSSRule::STYLE_RULE) | 634 if (rule->type() != CSSRule::STYLE_RULE) |
572 return 0; | 635 return 0; |
573 return static_cast<CSSStyleRule*>(rule); | 636 return static_cast<CSSStyleRule*>(rule); |
574 } | 637 } |
575 | 638 |
576 InspectorCSSAgent::InspectorCSSAgent(InstrumentingAgents* instrumentingAgents, I
nspectorCompositeState* state, InspectorDOMAgent* domAgent) | 639 InspectorCSSAgent::InspectorCSSAgent(InstrumentingAgents* instrumentingAgents, I
nspectorCompositeState* state, InspectorDOMAgent* domAgent) |
577 : InspectorBaseAgent<InspectorCSSAgent>("CSS", instrumentingAgents, state) | 640 : InspectorBaseAgent<InspectorCSSAgent>("CSS", instrumentingAgents, state) |
578 , m_frontend(0) | 641 , m_frontend(0) |
579 , m_domAgent(domAgent) | 642 , m_domAgent(domAgent) |
580 , m_lastStyleSheetId(1) | 643 , m_lastStyleSheetId(1) |
| 644 , m_creatingViaInspectorStyleSheet(false) |
581 { | 645 { |
582 m_domAgent->setDOMListener(this); | 646 m_domAgent->setDOMListener(this); |
583 } | 647 } |
584 | 648 |
585 InspectorCSSAgent::~InspectorCSSAgent() | 649 InspectorCSSAgent::~InspectorCSSAgent() |
586 { | 650 { |
587 ASSERT(!m_domAgent); | 651 ASSERT(!m_domAgent); |
588 reset(); | 652 reset(); |
589 } | 653 } |
590 | 654 |
591 void InspectorCSSAgent::setFrontend(InspectorFrontend* frontend) | 655 void InspectorCSSAgent::setFrontend(InspectorFrontend* frontend) |
592 { | 656 { |
593 ASSERT(!m_frontend); | 657 ASSERT(!m_frontend); |
594 m_frontend = frontend->css(); | 658 m_frontend = frontend->css(); |
595 } | 659 } |
596 | 660 |
597 void InspectorCSSAgent::clearFrontend() | 661 void InspectorCSSAgent::clearFrontend() |
598 { | 662 { |
599 ASSERT(m_frontend); | 663 ASSERT(m_frontend); |
600 m_frontend = 0; | 664 m_frontend = 0; |
601 resetNonPersistentData(); | 665 resetNonPersistentData(); |
602 String errorString; | 666 stopSelectorProfilerImpl(0, false); |
603 stopSelectorProfilerImpl(&errorString, false); | |
604 } | 667 } |
605 | 668 |
606 void InspectorCSSAgent::discardAgent() | 669 void InspectorCSSAgent::discardAgent() |
607 { | 670 { |
608 m_domAgent->setDOMListener(0); | 671 m_domAgent->setDOMListener(0); |
609 m_domAgent = 0; | 672 m_domAgent = 0; |
610 } | 673 } |
611 | 674 |
612 void InspectorCSSAgent::restore() | 675 void InspectorCSSAgent::restore() |
613 { | 676 { |
(...skipping 21 matching lines...) Expand all Loading... |
635 m_namedFlowCollectionsRequested.clear(); | 698 m_namedFlowCollectionsRequested.clear(); |
636 if (m_updateRegionLayoutTask) | 699 if (m_updateRegionLayoutTask) |
637 m_updateRegionLayoutTask->reset(); | 700 m_updateRegionLayoutTask->reset(); |
638 resetPseudoStates(); | 701 resetPseudoStates(); |
639 } | 702 } |
640 | 703 |
641 void InspectorCSSAgent::enable(ErrorString*) | 704 void InspectorCSSAgent::enable(ErrorString*) |
642 { | 705 { |
643 m_state->setBoolean(CSSAgentState::cssAgentEnabled, true); | 706 m_state->setBoolean(CSSAgentState::cssAgentEnabled, true); |
644 m_instrumentingAgents->setInspectorCSSAgent(this); | 707 m_instrumentingAgents->setInspectorCSSAgent(this); |
| 708 |
| 709 RefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSStyleSheetHeader> > styleInfo
s = TypeBuilder::Array<TypeBuilder::CSS::CSSStyleSheetHeader>::create(); |
| 710 Vector<InspectorStyleSheet*> styleSheets; |
| 711 collectAllStyleSheets(styleSheets); |
| 712 for (size_t i = 0; i < styleSheets.size(); ++i) |
| 713 m_frontend->styleSheetAdded(styleSheets.at(i)->buildObjectForStyleSheetI
nfo()); |
645 } | 714 } |
646 | 715 |
647 void InspectorCSSAgent::disable(ErrorString*) | 716 void InspectorCSSAgent::disable(ErrorString*) |
648 { | 717 { |
649 m_instrumentingAgents->setInspectorCSSAgent(0); | 718 m_instrumentingAgents->setInspectorCSSAgent(0); |
650 m_state->setBoolean(CSSAgentState::cssAgentEnabled, false); | 719 m_state->setBoolean(CSSAgentState::cssAgentEnabled, false); |
651 } | 720 } |
652 | 721 |
653 void InspectorCSSAgent::mediaQueryResultChanged() | 722 void InspectorCSSAgent::mediaQueryResultChanged() |
654 { | 723 { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
693 { | 762 { |
694 if (namedFlow->flowState() == NamedFlow::FlowStateNull) | 763 if (namedFlow->flowState() == NamedFlow::FlowStateNull) |
695 return; | 764 return; |
696 | 765 |
697 ErrorString errorString; | 766 ErrorString errorString; |
698 RefPtr<NamedFlow> protector(namedFlow); | 767 RefPtr<NamedFlow> protector(namedFlow); |
699 | 768 |
700 m_frontend->regionLayoutUpdated(buildObjectForNamedFlow(&errorString, namedF
low, documentNodeId)); | 769 m_frontend->regionLayoutUpdated(buildObjectForNamedFlow(&errorString, namedF
low, documentNodeId)); |
701 } | 770 } |
702 | 771 |
| 772 void InspectorCSSAgent::activeStyleSheetsUpdated(const Vector<RefPtr<StyleSheet>
>& newSheets) |
| 773 { |
| 774 HashSet<CSSStyleSheet*> removedSheets; |
| 775 for (CSSStyleSheetToInspectorStyleSheet::iterator it = m_cssStyleSheetToInsp
ectorStyleSheet.begin(); it != m_cssStyleSheetToInspectorStyleSheet.end(); ++it)
{ |
| 776 if (it->value->canBind()) |
| 777 removedSheets.add(it->key); |
| 778 } |
| 779 |
| 780 Vector<CSSStyleSheet*> newSheetsVector; |
| 781 for (size_t i = 0, size = newSheets.size(); i < size; ++i) { |
| 782 StyleSheet* newSheet = newSheets.at(i).get(); |
| 783 if (newSheet->isCSSStyleSheet()) { |
| 784 StyleSheetAppender appender(static_cast<CSSStyleSheet*>(newSheet), n
ewSheetsVector); |
| 785 appender.run(); |
| 786 } |
| 787 } |
| 788 |
| 789 HashSet<CSSStyleSheet*> addedSheets; |
| 790 for (size_t i = 0; i < newSheetsVector.size(); ++i) { |
| 791 CSSStyleSheet* newCSSSheet = newSheetsVector.at(i); |
| 792 if (removedSheets.contains(newCSSSheet)) |
| 793 removedSheets.remove(newCSSSheet); |
| 794 else |
| 795 addedSheets.add(newCSSSheet); |
| 796 } |
| 797 |
| 798 RefPtr<TypeBuilder::Array<TypeBuilder::CSS::StyleSheetId> > removedIds = Typ
eBuilder::Array<TypeBuilder::CSS::StyleSheetId>::create(); |
| 799 for (HashSet<CSSStyleSheet*>::iterator it = removedSheets.begin(); it != rem
ovedSheets.end(); ++it) { |
| 800 RefPtr<InspectorStyleSheet> inspectorStyleSheet = m_cssStyleSheetToInspe
ctorStyleSheet.get(*it); |
| 801 ASSERT(inspectorStyleSheet); |
| 802 unbindStyleSheetRecursively(inspectorStyleSheet.get()); |
| 803 } |
| 804 RefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSStyleSheetHeader> > addedHead
ers = TypeBuilder::Array<TypeBuilder::CSS::CSSStyleSheetHeader>::create(); |
| 805 for (HashSet<CSSStyleSheet*>::iterator it = addedSheets.begin(); it != added
Sheets.end(); ++it) |
| 806 bindStyleSheetRecursively(static_cast<CSSStyleSheet*>(*it)); |
| 807 } |
| 808 |
703 bool InspectorCSSAgent::forcePseudoState(Element* element, CSSSelector::PseudoTy
pe pseudoType) | 809 bool InspectorCSSAgent::forcePseudoState(Element* element, CSSSelector::PseudoTy
pe pseudoType) |
704 { | 810 { |
705 if (m_nodeIdToForcedPseudoState.isEmpty()) | 811 if (m_nodeIdToForcedPseudoState.isEmpty()) |
706 return false; | 812 return false; |
707 | 813 |
708 int nodeId = m_domAgent->boundNodeId(element); | 814 int nodeId = m_domAgent->boundNodeId(element); |
709 if (!nodeId) | 815 if (!nodeId) |
710 return false; | 816 return false; |
711 | 817 |
712 NodeIdToForcedPseudoState::iterator it = m_nodeIdToForcedPseudoState.find(no
deId); | 818 NodeIdToForcedPseudoState::iterator it = m_nodeIdToForcedPseudoState.find(no
deId); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
800 return; | 906 return; |
801 | 907 |
802 RefPtr<CSSComputedStyleDeclaration> computedStyleInfo = CSSComputedStyleDecl
aration::create(element, true); | 908 RefPtr<CSSComputedStyleDeclaration> computedStyleInfo = CSSComputedStyleDecl
aration::create(element, true); |
803 RefPtr<InspectorStyle> inspectorStyle = InspectorStyle::create(InspectorCSSI
d(), computedStyleInfo, 0); | 909 RefPtr<InspectorStyle> inspectorStyle = InspectorStyle::create(InspectorCSSI
d(), computedStyleInfo, 0); |
804 style = inspectorStyle->buildArrayForComputedStyle(); | 910 style = inspectorStyle->buildArrayForComputedStyle(); |
805 } | 911 } |
806 | 912 |
807 void InspectorCSSAgent::getAllStyleSheets(ErrorString*, RefPtr<TypeBuilder::Arra
y<TypeBuilder::CSS::CSSStyleSheetHeader> >& styleInfos) | 913 void InspectorCSSAgent::getAllStyleSheets(ErrorString*, RefPtr<TypeBuilder::Arra
y<TypeBuilder::CSS::CSSStyleSheetHeader> >& styleInfos) |
808 { | 914 { |
809 styleInfos = TypeBuilder::Array<TypeBuilder::CSS::CSSStyleSheetHeader>::crea
te(); | 915 styleInfos = TypeBuilder::Array<TypeBuilder::CSS::CSSStyleSheetHeader>::crea
te(); |
810 Vector<Document*> documents = m_domAgent->documents(); | 916 Vector<InspectorStyleSheet*> styleSheets; |
811 for (Vector<Document*>::iterator it = documents.begin(); it != documents.end
(); ++it) { | 917 collectAllStyleSheets(styleSheets); |
812 StyleSheetList* list = (*it)->styleSheets(); | 918 for (size_t i = 0; i < styleSheets.size(); ++i) |
813 for (unsigned i = 0; i < list->length(); ++i) { | 919 styleInfos->addItem(styleSheets.at(i)->buildObjectForStyleSheetInfo()); |
814 StyleSheet* styleSheet = list->item(i); | |
815 if (styleSheet->isCSSStyleSheet()) | |
816 collectStyleSheets(static_cast<CSSStyleSheet*>(styleSheet), styl
eInfos.get()); | |
817 } | |
818 } | |
819 } | 920 } |
820 | 921 |
821 void InspectorCSSAgent::getStyleSheet(ErrorString* errorString, const String& st
yleSheetId, RefPtr<TypeBuilder::CSS::CSSStyleSheetBody>& styleSheetObject) | 922 void InspectorCSSAgent::getStyleSheet(ErrorString* errorString, const String& st
yleSheetId, RefPtr<TypeBuilder::CSS::CSSStyleSheetBody>& styleSheetObject) |
822 { | 923 { |
823 InspectorStyleSheet* inspectorStyleSheet = assertStyleSheetForId(errorString
, styleSheetId); | 924 InspectorStyleSheet* inspectorStyleSheet = assertStyleSheetForId(errorString
, styleSheetId); |
824 if (!inspectorStyleSheet) | 925 if (!inspectorStyleSheet) |
825 return; | 926 return; |
826 | 927 |
827 styleSheetObject = inspectorStyleSheet->buildObjectForStyleSheet(); | 928 styleSheetObject = inspectorStyleSheet->buildObjectForStyleSheet(); |
828 } | 929 } |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1081 | 1182 |
1082 int InspectorCSSAgent::documentNodeWithRequestedFlowsId(Document* document) | 1183 int InspectorCSSAgent::documentNodeWithRequestedFlowsId(Document* document) |
1083 { | 1184 { |
1084 int documentNodeId = m_domAgent->boundNodeId(document); | 1185 int documentNodeId = m_domAgent->boundNodeId(document); |
1085 if (!documentNodeId || !m_namedFlowCollectionsRequested.contains(documentNod
eId)) | 1186 if (!documentNodeId || !m_namedFlowCollectionsRequested.contains(documentNod
eId)) |
1086 return 0; | 1187 return 0; |
1087 | 1188 |
1088 return documentNodeId; | 1189 return documentNodeId; |
1089 } | 1190 } |
1090 | 1191 |
1091 void InspectorCSSAgent::collectStyleSheets(CSSStyleSheet* styleSheet, TypeBuilde
r::Array<TypeBuilder::CSS::CSSStyleSheetHeader>* result) | 1192 void InspectorCSSAgent::collectAllStyleSheets(Vector<InspectorStyleSheet*>& resu
lt) |
| 1193 { |
| 1194 Vector<Document*> documents = m_domAgent->documents(); |
| 1195 for (Vector<Document*>::iterator it = documents.begin(); it != documents.end
(); ++it) { |
| 1196 StyleSheetList* list = (*it)->styleSheets(); |
| 1197 for (unsigned i = 0; i < list->length(); ++i) { |
| 1198 StyleSheet* styleSheet = list->item(i); |
| 1199 if (styleSheet->isCSSStyleSheet()) |
| 1200 collectStyleSheets(static_cast<CSSStyleSheet*>(styleSheet), resu
lt); |
| 1201 } |
| 1202 } |
| 1203 } |
| 1204 |
| 1205 void InspectorCSSAgent::collectStyleSheets(CSSStyleSheet* styleSheet, Vector<Ins
pectorStyleSheet*>& result) |
1092 { | 1206 { |
1093 InspectorStyleSheet* inspectorStyleSheet = bindStyleSheet(static_cast<CSSSty
leSheet*>(styleSheet)); | 1207 InspectorStyleSheet* inspectorStyleSheet = bindStyleSheet(static_cast<CSSSty
leSheet*>(styleSheet)); |
1094 result->addItem(inspectorStyleSheet->buildObjectForStyleSheetInfo()); | 1208 result.append(inspectorStyleSheet); |
1095 for (unsigned i = 0, size = styleSheet->length(); i < size; ++i) { | 1209 for (unsigned i = 0, size = styleSheet->length(); i < size; ++i) { |
1096 CSSRule* rule = styleSheet->item(i); | 1210 CSSRule* rule = styleSheet->item(i); |
1097 if (rule->type() == CSSRule::IMPORT_RULE) { | 1211 if (rule->type() == CSSRule::IMPORT_RULE) { |
1098 CSSStyleSheet* importedStyleSheet = static_cast<CSSImportRule*>(rule
)->styleSheet(); | 1212 CSSStyleSheet* importedStyleSheet = static_cast<CSSImportRule*>(rule
)->styleSheet(); |
1099 if (importedStyleSheet) | 1213 if (importedStyleSheet) |
1100 collectStyleSheets(importedStyleSheet, result); | 1214 collectStyleSheets(importedStyleSheet, result); |
1101 } | 1215 } |
1102 } | 1216 } |
1103 } | 1217 } |
1104 | 1218 |
| 1219 void InspectorCSSAgent::bindStyleSheetRecursively(CSSStyleSheet* styleSheet) |
| 1220 { |
| 1221 StyleSheetBinder binder(this, styleSheet); |
| 1222 binder.run(); |
| 1223 } |
| 1224 |
1105 InspectorStyleSheet* InspectorCSSAgent::bindStyleSheet(CSSStyleSheet* styleSheet
) | 1225 InspectorStyleSheet* InspectorCSSAgent::bindStyleSheet(CSSStyleSheet* styleSheet
) |
1106 { | 1226 { |
1107 RefPtr<InspectorStyleSheet> inspectorStyleSheet = m_cssStyleSheetToInspector
StyleSheet.get(styleSheet); | 1227 RefPtr<InspectorStyleSheet> inspectorStyleSheet = m_cssStyleSheetToInspector
StyleSheet.get(styleSheet); |
1108 if (!inspectorStyleSheet) { | 1228 if (!inspectorStyleSheet) { |
1109 String id = String::number(m_lastStyleSheetId++); | 1229 String id = String::number(m_lastStyleSheetId++); |
1110 Document* document = styleSheet->ownerDocument(); | 1230 Document* document = styleSheet->ownerDocument(); |
1111 inspectorStyleSheet = InspectorStyleSheet::create(m_domAgent->pageAgent(
), id, styleSheet, detectOrigin(styleSheet, document), InspectorDOMAgent::docume
ntURLString(document), this); | 1231 inspectorStyleSheet = InspectorStyleSheet::create(m_domAgent->pageAgent(
), id, styleSheet, detectOrigin(styleSheet, document), InspectorDOMAgent::docume
ntURLString(document), this); |
1112 m_idToInspectorStyleSheet.set(id, inspectorStyleSheet); | 1232 m_idToInspectorStyleSheet.set(id, inspectorStyleSheet); |
1113 m_cssStyleSheetToInspectorStyleSheet.set(styleSheet, inspectorStyleSheet
); | 1233 m_cssStyleSheetToInspectorStyleSheet.set(styleSheet, inspectorStyleSheet
); |
| 1234 if (m_creatingViaInspectorStyleSheet) |
| 1235 m_documentToInspectorStyleSheet.add(document, inspectorStyleSheet); |
1114 } | 1236 } |
1115 return inspectorStyleSheet.get(); | 1237 return inspectorStyleSheet.get(); |
1116 } | 1238 } |
1117 | 1239 |
| 1240 String InspectorCSSAgent::unbindStyleSheet(InspectorStyleSheet* inspectorStyleSh
eet) |
| 1241 { |
| 1242 String id = inspectorStyleSheet->id(); |
| 1243 m_idToInspectorStyleSheet.remove(id); |
| 1244 if (inspectorStyleSheet->pageStyleSheet()) |
| 1245 m_cssStyleSheetToInspectorStyleSheet.remove(inspectorStyleSheet->pageSty
leSheet()); |
| 1246 return id; |
| 1247 } |
| 1248 |
| 1249 void InspectorCSSAgent::unbindStyleSheetRecursively(InspectorStyleSheet* inspect
orStyleSheet) |
| 1250 { |
| 1251 if (!inspectorStyleSheet) |
| 1252 return; |
| 1253 CSSStyleSheet* styleSheet = inspectorStyleSheet->pageStyleSheet(); |
| 1254 if (!styleSheet) |
| 1255 return; |
| 1256 for (unsigned i = 0, size = styleSheet->length(); i < size; ++i) { |
| 1257 CSSRule* rule = styleSheet->item(i); |
| 1258 if (rule->type() == CSSRule::IMPORT_RULE) { |
| 1259 CSSStyleSheet* importedStyleSheet = static_cast<CSSImportRule*>(rule
)->styleSheet(); |
| 1260 if (importedStyleSheet) { |
| 1261 RefPtr<InspectorStyleSheet> importedChild = m_cssStyleSheetToIns
pectorStyleSheet.get(importedStyleSheet); |
| 1262 unbindStyleSheetRecursively(importedChild.get()); |
| 1263 } |
| 1264 } |
| 1265 } |
| 1266 if (m_idToInspectorStyleSheet.contains(inspectorStyleSheet->id())) |
| 1267 m_frontend->styleSheetRemoved(unbindStyleSheet(inspectorStyleSheet)); |
| 1268 } |
| 1269 |
1118 InspectorStyleSheet* InspectorCSSAgent::viaInspectorStyleSheet(Document* documen
t, bool createIfAbsent) | 1270 InspectorStyleSheet* InspectorCSSAgent::viaInspectorStyleSheet(Document* documen
t, bool createIfAbsent) |
1119 { | 1271 { |
1120 if (!document) { | 1272 if (!document) { |
1121 ASSERT(!createIfAbsent); | 1273 ASSERT(!createIfAbsent); |
1122 return 0; | 1274 return 0; |
1123 } | 1275 } |
1124 | 1276 |
1125 if (!document->isHTMLDocument() && !document->isSVGDocument()) | 1277 if (!document->isHTMLDocument() && !document->isSVGDocument()) |
1126 return 0; | 1278 return 0; |
1127 | 1279 |
1128 RefPtr<InspectorStyleSheet> inspectorStyleSheet = m_documentToInspectorStyle
Sheet.get(document); | 1280 RefPtr<InspectorStyleSheet> inspectorStyleSheet = m_documentToInspectorStyle
Sheet.get(document); |
1129 if (inspectorStyleSheet || !createIfAbsent) | 1281 if (inspectorStyleSheet || !createIfAbsent) |
1130 return inspectorStyleSheet.get(); | 1282 return inspectorStyleSheet.get(); |
1131 | 1283 |
1132 ExceptionCode ec = 0; | 1284 ExceptionCode ec = 0; |
1133 RefPtr<Element> styleElement = document->createElement("style", ec); | 1285 RefPtr<Element> styleElement = document->createElement("style", ec); |
1134 if (!ec) | 1286 if (!ec) |
1135 styleElement->setAttribute("type", "text/css", ec); | 1287 styleElement->setAttribute("type", "text/css", ec); |
1136 if (!ec) { | 1288 if (!ec) { |
1137 ContainerNode* targetNode; | 1289 ContainerNode* targetNode; |
1138 // HEAD is absent in ImageDocuments, for example. | 1290 // HEAD is absent in ImageDocuments, for example. |
1139 if (document->head()) | 1291 if (document->head()) |
1140 targetNode = document->head(); | 1292 targetNode = document->head(); |
1141 else if (document->body()) | 1293 else if (document->body()) |
1142 targetNode = document->body(); | 1294 targetNode = document->body(); |
1143 else | 1295 else |
1144 return 0; | 1296 return 0; |
1145 | 1297 |
1146 InlineStyleOverrideScope overrideScope(document); | 1298 InlineStyleOverrideScope overrideScope(document); |
| 1299 m_creatingViaInspectorStyleSheet = true; |
1147 targetNode->appendChild(styleElement, ec); | 1300 targetNode->appendChild(styleElement, ec); |
| 1301 // At this point the added stylesheet will get bound through the updateA
ctiveStyleSheets() invocation. |
| 1302 // We just need to pick the respective InspectorStyleSheet from m_docume
ntToInspectorStyleSheet. |
| 1303 m_creatingViaInspectorStyleSheet = false; |
1148 } | 1304 } |
1149 if (ec) | 1305 if (ec) |
1150 return 0; | 1306 return 0; |
1151 | 1307 |
1152 CSSStyleSheet* cssStyleSheet = 0; | 1308 return m_documentToInspectorStyleSheet.get(document).get(); |
1153 if (styleElement->isHTMLElement()) | |
1154 cssStyleSheet = static_cast<HTMLStyleElement*>(styleElement.get())->shee
t(); | |
1155 #if ENABLE(SVG) | |
1156 else if (styleElement->isSVGElement()) | |
1157 cssStyleSheet = static_cast<SVGStyleElement*>(styleElement.get())->sheet
(); | |
1158 #endif | |
1159 | |
1160 if (!cssStyleSheet) | |
1161 return 0; | |
1162 | |
1163 String id = String::number(m_lastStyleSheetId++); | |
1164 inspectorStyleSheet = InspectorStyleSheet::create(m_domAgent->pageAgent(), i
d, cssStyleSheet, TypeBuilder::CSS::StyleSheetOrigin::Inspector, InspectorDOMAge
nt::documentURLString(document), this); | |
1165 m_idToInspectorStyleSheet.set(id, inspectorStyleSheet); | |
1166 m_cssStyleSheetToInspectorStyleSheet.set(cssStyleSheet, inspectorStyleSheet)
; | |
1167 m_documentToInspectorStyleSheet.set(document, inspectorStyleSheet); | |
1168 return inspectorStyleSheet.get(); | |
1169 } | 1309 } |
1170 | 1310 |
1171 InspectorStyleSheet* InspectorCSSAgent::assertStyleSheetForId(ErrorString* error
String, const String& styleSheetId) | 1311 InspectorStyleSheet* InspectorCSSAgent::assertStyleSheetForId(ErrorString* error
String, const String& styleSheetId) |
1172 { | 1312 { |
1173 IdToInspectorStyleSheet::iterator it = m_idToInspectorStyleSheet.find(styleS
heetId); | 1313 IdToInspectorStyleSheet::iterator it = m_idToInspectorStyleSheet.find(styleS
heetId); |
1174 if (it == m_idToInspectorStyleSheet.end()) { | 1314 if (it == m_idToInspectorStyleSheet.end()) { |
1175 *errorString = "No style sheet with given id found"; | 1315 *errorString = "No style sheet with given id found"; |
1176 return 0; | 1316 return 0; |
1177 } | 1317 } |
1178 return it->value.get(); | 1318 return it->value.get(); |
1179 } | 1319 } |
1180 | 1320 |
1181 TypeBuilder::CSS::StyleSheetOrigin::Enum InspectorCSSAgent::detectOrigin(CSSStyl
eSheet* pageStyleSheet, Document* ownerDocument) | 1321 TypeBuilder::CSS::StyleSheetOrigin::Enum InspectorCSSAgent::detectOrigin(CSSStyl
eSheet* pageStyleSheet, Document* ownerDocument) |
1182 { | 1322 { |
| 1323 if (m_creatingViaInspectorStyleSheet) |
| 1324 return TypeBuilder::CSS::StyleSheetOrigin::Inspector; |
| 1325 |
1183 TypeBuilder::CSS::StyleSheetOrigin::Enum origin = TypeBuilder::CSS::StyleShe
etOrigin::Regular; | 1326 TypeBuilder::CSS::StyleSheetOrigin::Enum origin = TypeBuilder::CSS::StyleShe
etOrigin::Regular; |
1184 if (pageStyleSheet && !pageStyleSheet->ownerNode() && pageStyleSheet->href()
.isEmpty()) | 1327 if (pageStyleSheet && !pageStyleSheet->ownerNode() && pageStyleSheet->href()
.isEmpty()) |
1185 origin = TypeBuilder::CSS::StyleSheetOrigin::User_agent; | 1328 origin = TypeBuilder::CSS::StyleSheetOrigin::User_agent; |
1186 else if (pageStyleSheet && pageStyleSheet->ownerNode() && pageStyleSheet->ow
nerNode()->nodeName() == "#document") | 1329 else if (pageStyleSheet && pageStyleSheet->ownerNode() && pageStyleSheet->ow
nerNode()->nodeName() == "#document") |
1187 origin = TypeBuilder::CSS::StyleSheetOrigin::User; | 1330 origin = TypeBuilder::CSS::StyleSheetOrigin::User; |
1188 else { | 1331 else { |
1189 InspectorStyleSheet* viaInspectorStyleSheetForOwner = viaInspectorStyleS
heet(ownerDocument, false); | 1332 InspectorStyleSheet* viaInspectorStyleSheetForOwner = viaInspectorStyleS
heet(ownerDocument, false); |
1190 if (viaInspectorStyleSheetForOwner && pageStyleSheet == viaInspectorStyl
eSheetForOwner->pageStyleSheet()) | 1333 if (viaInspectorStyleSheetForOwner && pageStyleSheet == viaInspectorStyl
eSheetForOwner->pageStyleSheet()) |
1191 origin = TypeBuilder::CSS::StyleSheetOrigin::Inspector; | 1334 origin = TypeBuilder::CSS::StyleSheetOrigin::Inspector; |
1192 } | 1335 } |
1193 return origin; | 1336 return origin; |
1194 } | 1337 } |
1195 | 1338 |
1196 PassRefPtr<TypeBuilder::CSS::CSSRule> InspectorCSSAgent::buildObjectForRule(CSSS
tyleRule* rule, StyleResolver* styleResolver) | 1339 PassRefPtr<TypeBuilder::CSS::CSSRule> InspectorCSSAgent::buildObjectForRule(CSSS
tyleRule* rule, StyleResolver* styleResolver) |
1197 { | 1340 { |
1198 if (!rule) | 1341 if (!rule) |
1199 return 0; | 1342 return 0; |
1200 | 1343 |
1201 // CSSRules returned by StyleResolver::styleRulesForElement lack parent poin
ters since that infomation is not cheaply available. | 1344 // CSSRules returned by StyleResolver::styleRulesForElement lack parent poin
ters since that infomation is not cheaply available. |
1202 // Since the inspector wants to walk the parent chain, we construct the full
wrappers here. | 1345 // Since the inspector wants to walk the parent chain, we construct the full
wrappers here. |
1203 // FIXME: This could be factored better. StyleResolver::styleRulesForElement
should return a StyleRule vector, not a CSSRuleList. | 1346 // FIXME: This could be factored better. StyleResolver::styleRulesForElement
should return a StyleRule vector, not a CSSRuleList. |
1204 if (!rule->parentStyleSheet()) { | 1347 if (!rule->parentStyleSheet()) { |
1205 rule = styleResolver->inspectorCSSOMWrappers().getWrapperForRuleInSheets
(rule->styleRule(), styleResolver->document()->styleSheetCollection()); | 1348 rule = styleResolver->inspectorCSSOMWrappers().getWrapperForRuleInSheets
(rule->styleRule(), styleResolver->document()->styleSheetCollection()); |
1206 if (!rule) | 1349 if (!rule) |
1207 return 0; | 1350 return 0; |
1208 } | 1351 } |
1209 InspectorStyleSheet* inspectorStyleSheet = bindStyleSheet(rule->parentStyleS
heet()); | 1352 return bindStyleSheet(rule->parentStyleSheet())->buildObjectForRule(rule); |
1210 return inspectorStyleSheet ? inspectorStyleSheet->buildObjectForRule(rule) :
0; | |
1211 } | 1353 } |
1212 | 1354 |
1213 PassRefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSRule> > InspectorCSSAgent::bu
ildArrayForRuleList(CSSRuleList* ruleList, StyleResolver* styleResolver) | 1355 PassRefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSRule> > InspectorCSSAgent::bu
ildArrayForRuleList(CSSRuleList* ruleList, StyleResolver* styleResolver) |
1214 { | 1356 { |
1215 RefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSRule> > result = TypeBuilder:
:Array<TypeBuilder::CSS::CSSRule>::create(); | 1357 RefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSRule> > result = TypeBuilder:
:Array<TypeBuilder::CSS::CSSRule>::create(); |
1216 if (!ruleList) | 1358 if (!ruleList) |
1217 return result.release(); | 1359 return result.release(); |
1218 | 1360 |
1219 for (unsigned i = 0, size = ruleList->length(); i < size; ++i) { | 1361 for (unsigned i = 0, size = ruleList->length(); i < size; ++i) { |
1220 CSSStyleRule* rule = asCSSStyleRule(ruleList->item(i)); | 1362 CSSStyleRule* rule = asCSSStyleRule(ruleList->item(i)); |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1373 documentsToChange.add(element->ownerDocument()); | 1515 documentsToChange.add(element->ownerDocument()); |
1374 } | 1516 } |
1375 | 1517 |
1376 m_nodeIdToForcedPseudoState.clear(); | 1518 m_nodeIdToForcedPseudoState.clear(); |
1377 for (HashSet<Document*>::iterator it = documentsToChange.begin(), end = docu
mentsToChange.end(); it != end; ++it) | 1519 for (HashSet<Document*>::iterator it = documentsToChange.begin(), end = docu
mentsToChange.end(); it != end; ++it) |
1378 (*it)->styleResolverChanged(RecalcStyleImmediately); | 1520 (*it)->styleResolverChanged(RecalcStyleImmediately); |
1379 } | 1521 } |
1380 | 1522 |
1381 } // namespace WebCore | 1523 } // namespace WebCore |
1382 | 1524 |
OLD | NEW |