| // 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 "chrome/browser/ui/ash/input_method/suggestion_details.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 { |
| |
| 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_ |