コード例 #1
0
void InspectorOverlay::drawNodeHighlight()
{
    if (!m_highlightNode)
        return;

    String selectors = m_nodeHighlightConfig.selectorList;
    StaticElementList* elements = nullptr;
    TrackExceptionState exceptionState;
    ContainerNode* queryBase = m_highlightNode->containingShadowRoot();
    if (!queryBase)
        queryBase = m_highlightNode->ownerDocument();
    if (selectors.length())
        elements = queryBase->querySelectorAll(AtomicString(selectors), exceptionState);
    if (elements && !exceptionState.hadException()) {
        for (unsigned i = 0; i < elements->length(); ++i) {
            Element* element = elements->item(i);
            InspectorHighlight highlight(element, m_nodeHighlightConfig, false);
            std::unique_ptr<protocol::DictionaryValue> highlightJSON = highlight.asProtocolValue();
            evaluateInOverlay("drawHighlight", std::move(highlightJSON));
        }
    }

    bool appendElementInfo = m_highlightNode->isElementNode() && !m_omitTooltip && m_nodeHighlightConfig.showInfo && m_highlightNode->layoutObject() && m_highlightNode->document().frame();
    InspectorHighlight highlight(m_highlightNode.get(), m_nodeHighlightConfig, appendElementInfo);
    if (m_eventTargetNode)
        highlight.appendEventTargetQuads(m_eventTargetNode.get(), m_nodeHighlightConfig);

    std::unique_ptr<protocol::DictionaryValue> highlightJSON = highlight.asProtocolValue();
    evaluateInOverlay("drawHighlight", std::move(highlightJSON));
}
コード例 #2
0
void MainThreadDebugger::querySelectorAllCallback(
    const v8::FunctionCallbackInfo<v8::Value>& info) {
  if (info.Length() < 1)
    return;
  String selector = toCoreStringWithUndefinedOrNullCheck(info[0]);
  if (selector.isEmpty())
    return;
  Node* node = secondArgumentAsNode(info);
  if (!node || !node->isContainerNode())
    return;
  ExceptionState exceptionState(ExceptionState::ExecutionContext, "$$",
                                "CommandLineAPI", info.Holder(),
                                info.GetIsolate());
  // toV8(elementList) doesn't work here, since we need a proper Array instance,
  // not NodeList.
  StaticElementList* elementList = toContainerNode(node)->querySelectorAll(
      AtomicString(selector), exceptionState);
  if (exceptionState.hadException() || !elementList)
    return;
  v8::Isolate* isolate = info.GetIsolate();
  v8::Local<v8::Context> context = isolate->GetCurrentContext();
  v8::Local<v8::Array> nodes = v8::Array::New(isolate, elementList->length());
  for (size_t i = 0; i < elementList->length(); ++i) {
    Element* element = elementList->item(i);
    if (!createDataPropertyInArray(
             context, nodes, i, toV8(element, info.Holder(), info.GetIsolate()))
             .FromMaybe(false))
      return;
  }
  info.GetReturnValue().Set(nodes);
}
コード例 #3
0
ファイル: LayoutEditor.cpp プロジェクト: mirror/chromium
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;
}