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;
}
Exemplo n.º 2
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;
}
Exemplo n.º 3
0
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;
}
Exemplo n.º 4
0
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;
}
Exemplo n.º 5
0
String InspectorAnimationAgent::createCSSId(blink::Animation& animation) {
  String type =
      m_idToAnimationType.get(String::number(animation.sequenceNumber()));
  ASSERT(type != AnimationType::WebAnimation);

  KeyframeEffect* effect = toKeyframeEffect(animation.effect());
  Vector<CSSPropertyID> cssProperties;
  if (type == AnimationType::CSSAnimation) {
    for (CSSPropertyID property : animationProperties)
      cssProperties.append(property);
  } else {
    for (CSSPropertyID property : transitionProperties)
      cssProperties.append(property);
    cssProperties.append(cssPropertyID(animation.id()));
  }

  Element* element = effect->target();
  HeapVector<Member<CSSStyleDeclaration>> styles =
      m_cssAgent->matchingStyles(element);
  std::unique_ptr<WebCryptoDigestor> digestor =
      createDigestor(HashAlgorithmSha1);
  addStringToDigestor(digestor.get(), type);
  addStringToDigestor(digestor.get(), animation.id());
  for (CSSPropertyID property : cssProperties) {
    CSSStyleDeclaration* style =
        m_cssAgent->findEffectiveDeclaration(property, styles);
    // Ignore inline styles.
    if (!style || !style->parentStyleSheet() || !style->parentRule() ||
        style->parentRule()->type() != CSSRule::kStyleRule)
      continue;
    addStringToDigestor(digestor.get(), getPropertyNameString(property));
    addStringToDigestor(digestor.get(),
                        m_cssAgent->styleSheetId(style->parentStyleSheet()));
    addStringToDigestor(digestor.get(),
                        toCSSStyleRule(style->parentRule())->selectorText());
  }
  DigestValue digestResult;
  finishDigestor(digestor.get(), digestResult);
  return base64Encode(reinterpret_cast<const char*>(digestResult.data()), 10);
}
Exemplo n.º 6
0
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();
}
Exemplo n.º 7
0
void CSSStyleSheet::extraCSSOMWrapperIndices(Vector<unsigned>& indices)
{
    indices.grow(m_extraChildRuleCSSOMWrappers.size());

    for (unsigned i = 0; i < m_extraChildRuleCSSOMWrappers.size(); ++i) {
        CSSRule* cssRule = m_extraChildRuleCSSOMWrappers[i].get();
        ASSERT(cssRule->type() == CSSRule::STYLE_RULE);
        StyleRule* styleRule = toCSSStyleRule(cssRule)->styleRule();

        bool didFindIndex = false;
        for (unsigned j = 0; j < m_contents->ruleCount(); ++j) {
            if (m_contents->ruleAt(j) == styleRule) {
                didFindIndex = true;
                indices[i] = j;
                break;
            }
        }
        ASSERT(didFindIndex);
        if (!didFindIndex)
            indices[i] = 0;
    }
}
Exemplo n.º 8
0
void PageSerializer::serializeCSSStyleSheet(CSSStyleSheet* styleSheet, const URL& url)
{
    StringBuilder cssText;
    for (unsigned i = 0; i < styleSheet->length(); ++i) {
        CSSRule* rule = styleSheet->item(i);
        String itemText = rule->cssText();
        if (!itemText.isEmpty()) {
            cssText.append(itemText);
            if (i < styleSheet->length() - 1)
                cssText.append("\n\n");
        }
        Document* document = styleSheet->ownerDocument();
        // Some rules have resources associated with them that we need to retrieve.
        if (rule->type() == CSSRule::IMPORT_RULE) {
            CSSImportRule* importRule = toCSSImportRule(rule);
            URL importURL = document->completeURL(importRule->href());
            if (m_resourceURLs.contains(importURL))
                continue;
            serializeCSSStyleSheet(importRule->styleSheet(), importURL);
        } else if (rule->type() == CSSRule::FONT_FACE_RULE) {
            // FIXME: Add support for font face rule. It is not clear to me at this point if the actual otf/eot file can
            // be retrieved from the CSSFontFaceRule object.
        } else if (rule->type() == CSSRule::STYLE_RULE)
            retrieveResourcesForRule(toCSSStyleRule(rule)->styleRule(), document);
    }

    if (url.isValid() && !m_resourceURLs.contains(url)) {
        // FIXME: We should check whether a charset has been specified and if none was found add one.
        TextEncoding textEncoding(styleSheet->contents().charset());
        ASSERT(textEncoding.isValid());
        String textString = cssText.toString();
        CString text = textEncoding.encode(textString, EntitiesForUnencodables);
        m_resources->append(Resource(url, String("text/css"), SharedBuffer::create(text.data(), text.length())));
        m_resourceURLs.add(url);
    }
}