chromium/third_party/blink/renderer/core/html/anchor_element_metrics.cc

// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "third_party/blink/renderer/core/html/anchor_element_metrics.h"

#include "base/containers/span.h"
#include "base/hash/hash.h"
#include "base/metrics/histogram_macros.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/mojom/loader/navigation_predictor.mojom-blink.h"
#include "third_party/blink/renderer/core/dom/element_traversal.h"
#include "third_party/blink/renderer/core/dom/flat_tree_traversal.h"
#include "third_party/blink/renderer/core/dom/node_computed_style.h"
#include "third_party/blink/renderer/core/dom/text.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/html/anchor_element_metrics_sender.h"
#include "third_party/blink/renderer/core/html/html_anchor_element.h"
#include "third_party/blink/renderer/core/html/html_frame_owner_element.h"
#include "third_party/blink/renderer/core/html/html_image_element.h"
#include "third_party/blink/renderer/core/layout/layout_object.h"
#include "third_party/blink/renderer/core/layout/layout_view.h"
#include "third_party/blink/renderer/core/paint/paint_layer.h"
#include "third_party/blink/renderer/core/paint/paint_layer_scrollable_area.h"
#include "third_party/blink/renderer/platform/wtf/hash_functions.h"
#include "third_party/blink/renderer/platform/wtf/text/string_to_number.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"
#include "ui/gfx/geometry/size.h"

namespace blink {

namespace {

// Returns the document of the main frame of the frame tree containing `anchor`.
// This could be null if `anchor` is in an out-of-process iframe.
Document* GetTopDocument(const HTMLAnchorElement& anchor) {}

// Whether the element is inside an iframe.
bool IsInIFrame(const HTMLAnchorElement& anchor_element) {}

// Whether the anchor element contains an image element.
bool ContainsImage(const HTMLAnchorElement& anchor_element) {}

// Whether the link target has the same host as the root document.
bool IsSameHost(const HTMLAnchorElement& anchor_element,
                const KURL& anchor_href) {}

// Returns true if the two strings only differ by one number, and
// the second number equals the first number plus one. Examples:
// example.com/page9/cat5, example.com/page10/cat5 => true
// example.com/page9/cat5, example.com/page10/cat10 => false
// Note that this may give an incorrect result if the strings differ at
// percent-encoded characters. For example:
//   "example.com/%20page", "example.com/%21page"
//       (false positive -- these are " " and "!")
//   "example.com/%39page", "example.com/%31%30page"
//       (false negative -- these are "9" and "10")
bool IsStringIncrementedByOne(const String& source, const String& target) {}

// Extract source and target link url, and return IsStringIncrementedByOne().
bool IsUrlIncrementedByOne(const HTMLAnchorElement& anchor_element,
                           const KURL& anchor_href) {}

// Returns the bounding box rect of a layout object, including visual
// overflows. Overflow is included as part of the clickable area of an anchor,
// so we account for it as well.
gfx::Rect AbsoluteElementBoundingBoxRect(const LayoutObject& layout_object) {}

bool HasTextSibling(const HTMLAnchorElement& anchor_element) {}

}  // anonymous namespace

// Computes a unique ID for the anchor. We hash the pointer address of the
// object. Note that this implementation can lead to collisions if an element is
// destroyed and a new one is created with the same address. We don't mind this
// issue as the anchor ID is only used for metric collection.
uint32_t AnchorElementId(const HTMLAnchorElement& element) {}

mojom::blink::AnchorElementMetricsPtr CreateAnchorElementMetrics(
    const HTMLAnchorElement& anchor_element) {}

}  // namespace blink