CSSStyleDeclaration* InspectorStyleSheet::styleForId(const String& id) const { CSSStyleRule* rule = ruleForId(id); if (!rule) return 0; return rule->style(); }
QString QWebElement::styleProperty(const QString &name, StyleResolveStrategy strategy) const { if (!m_element || !m_element->isStyledElement()) return QString(); int propID = cssPropertyID(name); if (!propID) return QString(); CSSStyleDeclaration* style = static_cast<StyledElement*>(m_element)->style(); if (strategy == InlineStyle) return style->getPropertyValue(propID); if (strategy == CascadedStyle) { if (style->getPropertyPriority(propID)) return style->getPropertyValue(propID); // We are going to resolve the style property by walking through the // list of non-inline matched CSS rules for the element, looking for // the highest priority definition. // Get an array of matched CSS rules for the given element sorted // by importance and inheritance order. This include external CSS // declarations, as well as embedded and inline style declarations. DOMWindow* domWindow = m_element->document()->frame()->domWindow(); if (RefPtr<CSSRuleList> rules = domWindow->getMatchedCSSRules(m_element, "")) { for (int i = rules->length(); i > 0; --i) { CSSStyleRule* rule = static_cast<CSSStyleRule*>(rules->item(i - 1)); if (rule->style()->getPropertyPriority(propID)) return rule->style()->getPropertyValue(propID); if (style->getPropertyValue(propID).isEmpty()) style = rule->style(); } } return style->getPropertyValue(propID); } if (strategy == ComputedStyle) { if (!m_element || !m_element->isStyledElement()) return QString(); int propID = cssPropertyID(name); RefPtr<CSSComputedStyleDeclaration> style = computedStyle(m_element); if (!propID || !style) return QString(); return style->getPropertyValue(propID); } return QString(); }
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; }
void V8CSSStyleRule::visitDOMWrapper(v8::Isolate* isolate, ScriptWrappable* scriptWrappable, const v8::Persistent<v8::Object>& wrapper) { CSSStyleRule* impl = scriptWrappable->toImpl<CSSStyleRule>(); CSSRule* parentRule = impl->parentRule(); if (parentRule) { DOMWrapperWorld::setWrapperReferencesInAllWorlds(wrapper, parentRule, isolate); } CSSStyleSheet* parentStyleSheet = impl->parentStyleSheet(); if (parentStyleSheet) { DOMWrapperWorld::setWrapperReferencesInAllWorlds(wrapper, parentStyleSheet, isolate); } }
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; }
static CSSStyleSheet* findStyleSheet(StyleEngine* styleEngine, StyleRule* rule) { // FIXME: StyleEngine has a bunch of different accessors for StyleSheet lists, is this the only one we need to care about? const Vector<RefPtr<CSSStyleSheet> >& stylesheets = styleEngine->activeAuthorStyleSheets(); for (size_t i = 0; i < stylesheets.size(); ++i) { CSSStyleSheet* sheet = stylesheets[i].get(); for (unsigned j = 0; j < sheet->length(); ++j) { CSSRule* cssRule = sheet->item(j); if (cssRule->type() != CSSRule::STYLE_RULE) continue; CSSStyleRule* cssStyleRule = toCSSStyleRule(cssRule); if (cssStyleRule->styleRule() == rule) return sheet; } } return 0; }
CSSRule* ElementRuleCollector::findStyleRule(CSSRuleCollection* cssRules, StyleRule* styleRule) { if (!cssRules) return 0; CSSRule* result = 0; for (unsigned i = 0; i < cssRules->length() && !result; ++i) { CSSRule* cssRule = cssRules->item(i); CSSRule::Type cssRuleType = cssRule->type(); if (cssRuleType == CSSRule::STYLE_RULE) { CSSStyleRule* cssStyleRule = toCSSStyleRule(cssRule); if (cssStyleRule->styleRule() == styleRule) result = cssRule; } else { result = findStyleRule(nestedRuleList(cssRule), styleRule); } } return result; }
std::unique_ptr<protocol::DictionaryValue> LayoutEditor::currentSelectorInfo( CSSStyleDeclaration* style) const { std::unique_ptr<protocol::DictionaryValue> object = protocol::DictionaryValue::create(); CSSStyleRule* rule = style->parentRule() ? toCSSStyleRule(style->parentRule()) : nullptr; String currentSelectorText = rule ? rule->selectorText() : "element.style"; object->setString("selector", currentSelectorText); Document* ownerDocument = m_element->ownerDocument(); if (!ownerDocument->isActive() || !rule) return object; Vector<String> medias; buildMediaListChain(rule, medias); std::unique_ptr<protocol::ListValue> mediaListValue = protocol::ListValue::create(); for (size_t i = 0; i < medias.size(); ++i) mediaListValue->pushValue(protocol::StringValue::create(medias[i])); object->setArray("medias", std::move(mediaListValue)); TrackExceptionState exceptionState; StaticElementList* elements = ownerDocument->querySelectorAll( AtomicString(currentSelectorText), exceptionState); if (!elements || exceptionState.hadException()) return object; std::unique_ptr<protocol::ListValue> highlights = protocol::ListValue::create(); InspectorHighlightConfig config = affectedNodesHighlightConfig(); for (unsigned i = 0; i < elements->length(); ++i) { Element* element = elements->item(i); if (element == m_element) continue; InspectorHighlight highlight(element, config, false); highlights->pushValue(highlight.asProtocolValue()); } object->setArray("nodes", std::move(highlights)); return object; }
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; }
CSSRule* ElementRuleCollector::findStyleRule(CSSRuleCollection* cssRules, StyleRule* styleRule) { if (!cssRules) return nullptr; CSSRule* result = 0; for (unsigned i = 0; i < cssRules->length() && !result; ++i) { CSSRule* cssRule = cssRules->item(i); CSSRule::Type cssRuleType = cssRule->type(); if (cssRuleType == CSSRule::kStyleRule) { CSSStyleRule* cssStyleRule = toCSSStyleRule(cssRule); if (cssStyleRule->styleRule() == styleRule) result = cssRule; } else if (cssRuleType == CSSRule::kImportRule) { CSSImportRule* cssImportRule = toCSSImportRule(cssRule); result = findStyleRule(cssImportRule->styleSheet(), styleRule); } else { result = findStyleRule(cssRule->cssRules(), styleRule); } } return result; }
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; }
PassRefPtr<JSONObject> LayoutEditor::currentSelectorInfo(CSSStyleDeclaration* style) const { RefPtr<JSONObject> object = JSONObject::create(); CSSStyleRule* rule = style->parentRule() ? toCSSStyleRule(style->parentRule()) : nullptr; String currentSelectorText = rule ? rule->selectorText() : "element.style"; object->setString("selector", currentSelectorText); Document* ownerDocument = m_element->ownerDocument(); if (!ownerDocument->isActive() || !rule) return object.release(); Vector<String> medias; buildMediaListChain(rule, medias); RefPtr<JSONArray> mediasJSONArray = JSONArray::create(); for (size_t i = 0; i < medias.size(); ++i) mediasJSONArray->pushString(medias[i]); object->setArray("medias", mediasJSONArray.release()); TrackExceptionState exceptionState; RefPtrWillBeRawPtr<StaticElementList> elements = ownerDocument->querySelectorAll(AtomicString(currentSelectorText), exceptionState); if (!elements || exceptionState.hadException()) return object.release(); RefPtr<JSONArray> highlights = JSONArray::create(); InspectorHighlightConfig config = affectedNodesHighlightConfig(); for (unsigned i = 0; i < elements->length(); ++i) { Element* element = elements->item(i); if (element == m_element) continue; InspectorHighlight highlight(element, config, false); highlights->pushObject(highlight.asJSONObject()); } object->setArray("nodes", highlights.release()); return object.release(); }