1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97
   98
   99
  100
  101
  102
  103
  104
  105
  106
  107
  108

ash / quick_insert / views / quick_insert_view_delegate.h [blame]

// 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.

#ifndef ASH_QUICK_INSERT_VIEWS_QUICK_INSERT_VIEW_DELEGATE_H_
#define ASH_QUICK_INSERT_VIEWS_QUICK_INSERT_VIEW_DELEGATE_H_

#include <memory>
#include <optional>
#include <string_view>
#include <vector>

#include "ash/ash_export.h"
#include "ash/quick_insert/model/quick_insert_mode_type.h"
#include "ash/quick_insert/quick_insert_category.h"
#include "ash/quick_insert/quick_insert_search_result.h"
#include "ui/base/emoji/emoji_panel_helper.h"

namespace ash {

enum class QuickInsertActionType;
enum class QuickInsertCapsLockPosition;
class QuickInsertAssetFetcher;
class QuickInsertSearchResultsSection;
class QuickInsertSessionMetrics;

// Delegate for `QuickInsertView`.
class ASH_EXPORT QuickInsertViewDelegate {
 public:
  using SearchResultsCallback = base::RepeatingCallback<void(
      std::vector<QuickInsertSearchResultsSection> results)>;
  using EmojiSearchResultsCallback =
      base::OnceCallback<void(std::vector<QuickInsertEmojiResult> results)>;
  using SuggestedEditorResultsCallback =
      base::OnceCallback<void(std::vector<QuickInsertSearchResult> results)>;
  using SuggestedResultsCallback = base::RepeatingCallback<void(
      std::vector<QuickInsertSearchResult> results)>;

  virtual ~QuickInsertViewDelegate() {}

  virtual std::vector<QuickInsertCategory> GetAvailableCategories() = 0;

  // Gets suggested results for the zero-state. Results will be returned via
  // `callback`, which may be called multiples times to update the results.
  virtual void GetZeroStateSuggestedResults(
      SuggestedResultsCallback callback) = 0;

  // Gets initially suggested results for category. Results will be returned via
  // `callback`, which may be called multiples times to update the results.
  virtual void GetResultsForCategory(QuickInsertCategory category,
                                     SearchResultsCallback callback) = 0;

  // Starts a search for `query`. Results will be returned via `callback`,
  // which may be called multiples times to update the results.
  // If `callback` is called with empty results, then it will never be called
  // again (i.e. all search results have been returned).
  virtual void StartSearch(std::u16string_view query,
                           std::optional<QuickInsertCategory> category,
                           SearchResultsCallback callback) = 0;

  // Stops the previous search, if any.
  virtual void StopSearch() = 0;

  // Starts a emoji search for `query`. Results will be returned via `callback`.
  virtual void StartEmojiSearch(std::u16string_view query,
                                EmojiSearchResultsCallback callback) = 0;

  // Closes the Widget and inserts `result` into the next focused input field.
  // If there's no focus event within some timeout after the widget is closed,
  // the result is dropped silently.
  virtual void CloseWidgetThenInsertResultOnNextFocus(
      const QuickInsertSearchResult& result) = 0;

  // Opens `result`. The exact behavior varies on the type of result.
  virtual void OpenResult(const QuickInsertSearchResult& result) = 0;

  // Shows the Emoji Picker with `category`.
  virtual void ShowEmojiPicker(ui::EmojiPickerCategory category,
                               std::u16string_view query) = 0;

  // Shows the Editor.
  virtual void ShowEditor(std::optional<std::string> preset_query_id,
                          std::optional<std::string> freeform_text) = 0;

  virtual void ShowLobster(std::optional<std::string> freeform_text) = 0;

  // Returns the current action for `result`.
  virtual QuickInsertActionType GetActionForResult(
      const QuickInsertSearchResult& result) = 0;

  virtual QuickInsertAssetFetcher* GetAssetFetcher() = 0;

  virtual QuickInsertSessionMetrics& GetSessionMetrics() = 0;

  // Gets suggested emoji results.
  virtual std::vector<QuickInsertEmojiResult> GetSuggestedEmoji() = 0;

  // Whether GIFs are enabled or not.
  virtual bool IsGifsEnabled() = 0;

  virtual QuickInsertModeType GetMode() = 0;

  virtual QuickInsertCapsLockPosition GetCapsLockPosition() = 0;
};

}  // namespace ash

#endif  // ASH_QUICK_INSERT_VIEWS_QUICK_INSERT_VIEW_DELEGATE_H_