chromium/ash/webui/shortcut_customization_ui/backend/search/search.mojom

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

module ash.shortcut_customization.mojom;

import "ash/public/mojom/accelerator_info.mojom";
import "mojo/public/mojom/base/string16.mojom";

// Search result metadata. Used by clients (e.g. the Shortcuts app) to render
// an individual search result in the UI.
struct SearchResult {
  // The shortcut's AcceleratorLayoutInfo contains the description and other
  // fields that are necessary to display the shortcuts correctly + route to the
  // shortcuts on selection.
  ash.mojom.AcceleratorLayoutInfo accelerator_layout_info;
  // A list of all accelerator_infos for this shortcut.
  array<ash.mojom.AcceleratorInfo> accelerator_infos;
  // Relevance score, in the range [0, 1]. A score of 1 indicates a perfect
  // string match.
  double relevance_score;
};

// Used to observe changes to search results.
interface SearchResultsAvailabilityObserver {
  // Called when the availability of one or more search results has changed. In
  // this context, "availability" refers to whether a search result can be
  // returned based on the user's current state. E.g. some results might only be
  // shown if an external keyboard is plugged in. Clients can use this function
  // to ensure that they do not show "stale" results which are no longer
  // actionable by the user. Note that the observer doesn't provide the new
  // search results, so clients will have to redo the SearchHandler.Search()
  // call to retrieve new results.
  OnSearchResultsAvailabilityChanged();
};

// Provides search results. Implemented in the browser process;
// intended to be called from the Shortcuts app TS and Launcher C++.
interface SearchHandler {
  // Searches for the given query and returns a list of results, sorted
  // from most relevant to least relevant. An empty array indicates no relevant
  // results.
  //
  // The search query will match against shortcut descriptions and shortcut
  // keys. For example, searching for "tab" might show results for both
  // "New Tab [Ctrl+T]" and "Switch windows [Ctrl+Tab]".
  //
  // This function returns an array with a maximum size of |max_num_results|,
  // but the array may contain fewer elements if there are fewer results.
  // Clients should never pass a value of 0 for |max_num_results|, since that
  // would return an empty result array.
  Search(mojo_base.mojom.String16 query,
         uint32 max_num_results) => (array<SearchResult> results);

  // Adds an observer of search result availability. Disconnected observers are
  // discarded; to stop observing, close the connection.
  AddSearchResultsAvailabilityObserver(
    pending_remote<SearchResultsAvailabilityObserver> observer);
};