chromium/third_party/blink/public/mojom/link_to_text/link_to_text.mojom

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

[JavaPackage="org.chromium.blink.mojom"]
module blink.mojom;

import "ui/gfx/geometry/mojom/geometry.mojom";

// See shared_highlighting::LinkGenerationReadyStatus
enum LinkGenerationReadyStatus {
  kRequestedBeforeReady = 0,
  kRequestedAfterReady = 1
};

// See shared_highlighting::LinkGenerationError
enum LinkGenerationError {
  kNone = -1,
  kIncorrectSelector = 0,
  kNoRange = 1,
  kNoContext = 2,
  kContextExhausted = 3,
  kContextLimitReached = 4,
  kEmptySelection = 5,
  kTabHidden = 6,
  kOmniboxNavigation = 7,
  kTabCrash = 8,
  kUnknown = 9,
  kIFrame = 10,
  kTimeout = 11,
  kBlockList = 12,
  kNoRemoteConnection = 13,
  kNotGenerated = 14
};

// TextFragmentReceiver is used for requesting renderer to perform text fragment
// operations on the frame that interacts with the link-to-text/shared-highlighting
// feature, mainly generating and removing fragments. A text fragment receiver is
// associated with exactly one frame but a frame will only create its receiver
// lazily when needed.
interface TextFragmentReceiver {
  // Cancel text fragment generation if in progress.
  Cancel();

  // Request the text fragment selector for currently selected text on the page.
  // Returns the selector, the error code and whether the generated selector was
  // ready at the time of the request.
  // See specs: https://github.com/WICG/scroll-to-text-fragment.
  RequestSelector() => (string selector,
                        LinkGenerationError error,
                        LinkGenerationReadyStatus ready_status);

  // Dismiss all text fragments from this frame at the time the
  // context menu was invoked.
  RemoveFragments();

  // Retrieves the text fragments matches from the fragment directive.
  ExtractTextFragmentsMatches() => (array<string> text);

  // Request text fragment selectors for existing highlights.
  GetExistingSelectors() => (array<string> selectors);

  // Request the bounding rectangle, relative to the viewport, of the first
  // found match. Returns an empty rectangle if no matches are found.
  ExtractFirstFragmentRect() => (gfx.mojom.Rect bounds);
};