void InspectorCSSAgent::getStylesForNode(long nodeId, RefPtr<InspectorValue>* result) { Element* element = elementForId(nodeId); if (!element) return; RefPtr<InspectorObject> resultObject = InspectorObject::create(); InspectorStyleSheetForInlineStyle* styleSheet = asInspectorStyleSheet(element); if (styleSheet) resultObject->setObject("inlineStyle", styleSheet->buildObjectForStyle(element->style())); RefPtr<CSSComputedStyleDeclaration> computedStyleInfo = computedStyle(element, true); // Support the viewing of :visited information in computed style. RefPtr<InspectorStyle> computedInspectorStyle = InspectorStyle::create(InspectorCSSId(), computedStyleInfo, 0); resultObject->setObject("computedStyle", computedInspectorStyle->buildObjectForStyle()); CSSStyleSelector* selector = element->ownerDocument()->styleSelector(); RefPtr<CSSRuleList> matchedRules = selector->styleRulesForElement(element, false, true); resultObject->setArray("matchedCSSRules", buildArrayForRuleList(matchedRules.get())); resultObject->setObject("styleAttributes", buildObjectForAttributeStyles(element)); RefPtr<InspectorArray> pseudoElements = InspectorArray::create(); for (PseudoId pseudoId = FIRST_PUBLIC_PSEUDOID; pseudoId < AFTER_LAST_INTERNAL_PSEUDOID; pseudoId = static_cast<PseudoId>(pseudoId + 1)) { RefPtr<CSSRuleList> matchedRules = selector->pseudoStyleRulesForElement(element, pseudoId, false, true); if (matchedRules && matchedRules->length()) { RefPtr<InspectorObject> pseudoStyles = InspectorObject::create(); pseudoStyles->setNumber("pseudoId", static_cast<int>(pseudoId)); pseudoStyles->setArray("rules", buildArrayForRuleList(matchedRules.get())); pseudoElements->pushObject(pseudoStyles.release()); } } resultObject->setArray("pseudoElements", pseudoElements.release()); RefPtr<InspectorArray> inheritedStyles = InspectorArray::create(); Element* parentElement = element->parentElement(); while (parentElement) { RefPtr<InspectorObject> parentStyle = InspectorObject::create(); if (parentElement->style() && parentElement->style()->length()) { InspectorStyleSheetForInlineStyle* styleSheet = asInspectorStyleSheet(parentElement); if (styleSheet) parentStyle->setObject("inlineStyle", styleSheet->buildObjectForStyle(styleSheet->styleForId(InspectorCSSId(styleSheet->id(), 0)))); } CSSStyleSelector* parentSelector = parentElement->ownerDocument()->styleSelector(); RefPtr<CSSRuleList> parentMatchedRules = parentSelector->styleRulesForElement(parentElement, false, true); parentStyle->setArray("matchedCSSRules", buildArrayForRuleList(parentMatchedRules.get())); inheritedStyles->pushObject(parentStyle.release()); parentElement = parentElement->parentElement(); } resultObject->setArray("inherited", inheritedStyles.release()); *result = resultObject.release(); }
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(); }