Пример #1
0
void PrintContext::outputLinkedDestinations(GraphicsContext& context,
                                            const IntRect& pageRect) {
  if (!m_linkedDestinationsValid) {
    // Collect anchors in the top-level frame only because our PrintContext
    // supports only one namespace for the anchors.
    collectLinkedDestinations(frame()->document());
    m_linkedDestinationsValid = true;
  }

  for (const auto& entry : m_linkedDestinations) {
    LayoutObject* layoutObject = entry.value->layoutObject();
    if (!layoutObject || !layoutObject->frameView())
      continue;
    IntRect boundingBox = layoutObject->absoluteBoundingBoxRect();
    // TODO(bokan): boundingBox looks to be in content coordinates but
    // convertToRootFrame doesn't apply scroll offsets when converting up to
    // the root frame.
    IntPoint point =
        layoutObject->frameView()->convertToRootFrame(boundingBox.location());
    if (!pageRect.contains(point))
      continue;
    point.clampNegativeToZero();
    context.setURLDestinationLocation(entry.key, point);
  }
}
Пример #2
0
void PrintContext::outputLinkedDestinations(GraphicsContext& graphicsContext, Node* node, const IntRect& pageRect)
{
    if (!m_linkedDestinationsValid) {
        collectLinkedDestinations(node);
        m_linkedDestinationsValid = true;
    }

    WillBeHeapHashMap<String, RawPtrWillBeMember<Element> >::const_iterator end = m_linkedDestinations.end();
    for (WillBeHeapHashMap<String, RawPtrWillBeMember<Element> >::const_iterator it = m_linkedDestinations.begin(); it != end; ++it) {
        RenderObject* renderer = it->value->renderer();
        if (renderer) {
            IntRect boundingBox = renderer->absoluteBoundingBoxRect();
            if (pageRect.intersects(boundingBox)) {
                IntPoint point = boundingBox.minXMinYCorner();
                point.clampNegativeToZero();
                graphicsContext.addURLTargetAtPoint(it->key, point);
            }
        }
    }
}
Пример #3
0
void PrintContext::collectLinkedDestinations(Node* node)
{
    for (Node* i = node->firstChild(); i; i = i->nextSibling())
        collectLinkedDestinations(i);

    if (!node->isLink() || !node->isElementNode())
        return;
    const AtomicString& href = toElement(node)->getAttribute(HTMLNames::hrefAttr);
    if (href.isNull())
        return;
    KURL url = node->document().completeURL(href);
    if (!url.isValid())
        return;
    if (url.hasFragmentIdentifier() && equalIgnoringFragmentIdentifier(url, node->document().baseURL())) {
        String name = url.fragmentIdentifier();
        Element* element = node->document().findAnchor(name);
        if (element)
            m_linkedDestinations.set(name, element);
    }
}
Пример #4
0
void PrintContext::outputLinkedDestinations(SkCanvas* canvas, const IntRect& pageRect)
{
    if (!m_linkedDestinationsValid) {
        // Collect anchors in the top-level frame only because our PrintContext
        // supports only one namespace for the anchors.
        collectLinkedDestinations(frame()->document());
        m_linkedDestinationsValid = true;
    }

    for (const auto& entry : m_linkedDestinations) {
        LayoutObject* layoutObject = entry.value->layoutObject();
        if (!layoutObject || !layoutObject->frameView())
            continue;
        IntRect boundingBox = layoutObject->absoluteBoundingBoxRect();
        boundingBox = layoutObject->frameView()->convertToContainingWindow(boundingBox);
        if (!pageRect.intersects(boundingBox))
            continue;
        IntPoint point = boundingBox.minXMinYCorner();
        point.clampNegativeToZero();
        SkAutoDataUnref nameData(SkData::NewWithCString(entry.key.utf8().data()));
        SkAnnotateNamedDestination(canvas, SkPoint::Make(point.x(), point.y()), nameData);
    }
}