File: completion_suggestion_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 (114 lines) | stat: -rw-r--r-- 4,244 bytes parent folder | download | duplicates (5)
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
// 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_COMPLETION_SUGGESTION_VIEW_H_
#define CHROME_BROWSER_UI_ASH_INPUT_METHOD_COMPLETION_SUGGESTION_VIEW_H_

#include "base/gtest_prod_util.h"
#include "base/memory/raw_ptr.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/chromeos/styles/cros_styles.h"
#include "ui/chromeos/ui_chromeos_export.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/controls/label.h"
#include "ui/views/controls/styled_label.h"
#include "ui/views/metadata/view_factory.h"
#include "ui/views/view.h"

namespace views {
class ImageView;
}  // namespace views

namespace ui {
namespace ime {

struct SuggestionDetails;
class CompletionSuggestionLabelView;

// Font-related constants
inline constexpr char kFontStyle[] = "Roboto";
inline constexpr int kAnnotationFontSize = 10;
inline constexpr int kIndexFontSize = 10;

// Style-related constants
inline constexpr int kAnnotationBorderThickness = 1;
inline constexpr int kAnnotationCornerRadius = 2;
inline constexpr int kPadding = 8;
inline constexpr int kAnnotationPaddingLeft = 12;
inline constexpr int kAnnotationPaddingBottom = 16;
inline constexpr int kAnnotationPaddingTop = 6;
inline constexpr char kTabKey[] = "tab";
inline constexpr cros_styles::ColorName kButtonHighlightColor =
    cros_styles::ColorName::kRippleColor;

// CompletionSuggestionView renders a suggestion.
class UI_CHROMEOS_EXPORT CompletionSuggestionView : public views::Button {
  METADATA_HEADER(CompletionSuggestionView, views::Button)

 public:
  explicit CompletionSuggestionView(PressedCallback callback);
  CompletionSuggestionView(const CompletionSuggestionView&) = delete;
  CompletionSuggestionView& operator=(const CompletionSuggestionView&) = delete;
  ~CompletionSuggestionView() override;

  void SetView(const SuggestionDetails& details);

  void SetHighlighted(bool highlighted);
  void SetMinWidth(int width);

  // When this view is being anchored to some other view, returns the point in
  // this view that this should be anchored to, in local coordinates.
  // For example, if this method returns the bottom left corner of this view,
  // then this view should be placed above the anchor so that the bottom left
  // corner of this view corresponds to the anchor.
  gfx::Point GetAnchorOrigin() const;

  std::u16string GetSuggestionForTesting();
  CompletionSuggestionLabelView* suggestion_label_for_testing() const;

 private:
  friend class SuggestionWindowViewTest;
  FRIEND_TEST_ALL_PREFIXES(SuggestionWindowViewTest, ShortcutSettingTest);

  void Layout(PassKey) override;
  gfx::Size CalculatePreferredSize(
      const views::SizeBounds& available_size) const override;
  void OnThemeChanged() override;

  std::unique_ptr<views::View> CreateAnnotationContainer();
  std::unique_ptr<views::View> CreateDownAndEnterAnnotationLabel();
  std::unique_ptr<views::View> CreateTabAnnotationLabel();

  // Views created in the class will be part of tree of |this|, so these
  // child views will be deleted when |this| is deleted.

  void SetSuggestionText(const std::u16string& text,
                         const size_t confirmed_length);

  // The suggestion label renders the suggestion text.
  raw_ptr<CompletionSuggestionLabelView> suggestion_label_ = nullptr;
  // The annotation view renders annotations.
  raw_ptr<views::View> annotation_container_ = nullptr;
  raw_ptr<views::View> down_and_enter_annotation_label_ = nullptr;
  raw_ptr<views::View> tab_annotation_label_ = nullptr;
  raw_ptr<views::ImageView> down_icon_ = nullptr;
  raw_ptr<views::ImageView> arrow_icon_ = nullptr;

  int suggestion_width_ = 0;
  int min_width_ = 0;
  bool highlighted_ = false;
};

BEGIN_VIEW_BUILDER(UI_CHROMEOS_EXPORT, CompletionSuggestionView, views::Button)
VIEW_BUILDER_PROPERTY(const SuggestionDetails&, View)
VIEW_BUILDER_PROPERTY(bool, Highlighted)
VIEW_BUILDER_PROPERTY(int, MinWidth)
END_VIEW_BUILDER

}  // namespace ime
}  // namespace ui

DEFINE_VIEW_BUILDER(UI_CHROMEOS_EXPORT, ui::ime::CompletionSuggestionView)

#endif  // CHROME_BROWSER_UI_ASH_INPUT_METHOD_COMPLETION_SUGGESTION_VIEW_H_