File: suggestion_window_view.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (141 lines) | stat: -rw-r--r-- 4,976 bytes parent folder | download | duplicates (6)
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// 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.

#ifndef CHROME_BROWSER_UI_ASH_INPUT_METHOD_SUGGESTION_WINDOW_VIEW_H_
#define CHROME_BROWSER_UI_ASH_INPUT_METHOD_SUGGESTION_WINDOW_VIEW_H_

#include <stddef.h>

#include <memory>

#include "base/containers/flat_map.h"
#include "base/memory/raw_ptr.h"
#include "chrome/browser/ui/ash/input_method/announcement_label.h"
#include "chrome/browser/ui/ash/input_method/indexed_suggestion_candidate_button.h"
#include "chromeos/ash/services/ime/public/cpp/assistive_suggestions.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/chromeos/ui_chromeos_export.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/views/bubble/bubble_dialog_delegate_view.h"
#include "ui/views/view.h"

namespace ash {
namespace input_method {
struct AssistiveWindowProperties;
}  // namespace input_method
}  // namespace ash

namespace views {
class ImageButton;
class Link;
}  // namespace views

namespace ui {
namespace ime {

class AssistiveDelegate;
struct AssistiveWindowButton;
struct SuggestionDetails;
class CompletionSuggestionView;

// SuggestionWindowView is the main container of the suggestion window UI.
class UI_CHROMEOS_EXPORT SuggestionWindowView
    : public views::BubbleDialogDelegateView {
  METADATA_HEADER(SuggestionWindowView, views::BubbleDialogDelegateView)

 public:
  enum Orientation {
    kHorizontal =
        0,  // TODO(b/215292569): Orientation needs to follow UI specs.
            // Currently only rotates the candidates horizontally.
    kVertical,
  };

  // Creates a bubble widget containing a SuggestionWindowView.  Returns a
  // pointer to the contained view.
  static SuggestionWindowView* Create(gfx::NativeView parent,
                                      AssistiveDelegate* delegate,
                                      Orientation orientation);

  // views::BubbleDialogDelegateView:
  std::unique_ptr<views::NonClientFrameView> CreateNonClientFrameView(
      views::Widget* widget) override;

  void Show(const SuggestionDetails& details);

  void ShowMultipleCandidates(
      const ash::input_method::AssistiveWindowProperties& properties,
      Orientation orientation);

  // Sets |button|'s highlight state to |highlighted|. At most one button with
  // the same id will be highlighted at any given time.
  void SetButtonHighlighted(const AssistiveWindowButton& button,
                            bool highlighted);

  views::View* multiple_candidate_area_for_testing() {
    return multiple_candidate_area_;
  }
  views::Link* setting_link_for_testing() { return setting_link_; }
  views::ImageButton* learn_more_button_for_testing() {
    return learn_more_button_;
  }

 protected:
  // views::BubbleDialogDelegateView:
  gfx::Rect GetBubbleBounds() override;
  void OnThemeChanged() override;
  void LearnMoreClicked();
  raw_ptr<views::ImageButton> getLearnMoreButton();

 private:
  SuggestionWindowView(gfx::NativeView parent,
                       AssistiveDelegate* delegate,
                       Orientation orientation);
  SuggestionWindowView(const SuggestionWindowView&) = delete;
  SuggestionWindowView& operator=(const SuggestionWindowView&) = delete;
  ~SuggestionWindowView() override;

  // Sets the number of candidates (i.e. the number of children of
  // |candidate_area_|) to |size|.
  void ResizeCandidateArea(const std::vector<std::u16string>& new_candidates,
                           bool use_legacy_candidate = false);

  void Reorient(Orientation orientation, bool extra_padding_on_right = true);

  void MakeVisible();

  // Sets |candidate|'s highlight state to |highlighted|. At most one candidate
  // will be highlighted at any given time.
  void SetCandidateHighlighted(IndexedSuggestionCandidateButton* candidate,
                               bool highlighted);

  // The delegate to handle events from this class.
  const raw_ptr<AssistiveDelegate, DanglingUntriaged> delegate_;

  // The view containing all the suggestions if multiple candidates are
  // visible.
  raw_ptr<views::View> multiple_candidate_area_;

  // The view containing the completion view. If this is visible then there is
  // only one suggestion to show.
  raw_ptr<CompletionSuggestionView> completion_view_;

  // The setting link, positioned below candidate_area_.
  // TODO(crbug.com/40138671): Rename setting to settings since there can be
  // multiple things to set.
  raw_ptr<views::Link> setting_link_;

  raw_ptr<views::ImageButton> learn_more_button_;

  // TODO(crbug.com/40137305): Add tests for mouse hovered and pressed.
  base::flat_map<views::View*, base::CallbackListSubscription> subscriptions_;

  std::unique_ptr<base::OneShotTimer> delay_timer_;
  ash::ime::AssistiveWindowType type_ = ash::ime::AssistiveWindowType::kNone;
};

}  // namespace ime
}  // namespace ui

#endif  // CHROME_BROWSER_UI_ASH_INPUT_METHOD_SUGGESTION_WINDOW_VIEW_H_