1 // Copyright (c) 2018 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_MATCH_CELL_VIEW_H_
6 #define CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_MATCH_CELL_VIEW_H_
7 
8 #include "ui/views/view.h"
9 
10 namespace views {
11 class ImageView;
12 }
13 
14 struct AutocompleteMatch;
15 class OmniboxResultView;
16 class OmniboxTextView;
17 
18 class OmniboxMatchCellView : public views::View {
19  public:
20   // Constants used in layout. Exposed so other views can coordinate margins.
21   static constexpr int kMarginLeft = 4;
22   static constexpr int kMarginRight = 8;
23   static constexpr int kImageBoundsWidth = 40;
24 
25   explicit OmniboxMatchCellView(OmniboxResultView* result_view);
26   ~OmniboxMatchCellView() override;
27 
icon()28   views::ImageView* icon() { return icon_view_; }
content()29   OmniboxTextView* content() { return content_view_; }
description()30   OmniboxTextView* description() { return description_view_; }
separator()31   OmniboxTextView* separator() { return separator_view_; }
32 
33   static int GetTextIndent();
34 
35   void OnMatchUpdate(const OmniboxResultView* result_view,
36                      const AutocompleteMatch& match);
37 
38   // Sets the answer image and, if the image is not square, sets the answer size
39   // proportional to the image size to preserve its aspect ratio.
40   void SetImage(const gfx::ImageSkia& image);
41 
42   // views::View:
43   const char* GetClassName() const override;
44   gfx::Insets GetInsets() const override;
45   void Layout() override;
46   bool GetCanProcessEventsWithinSubtree() const override;
47   gfx::Size CalculatePreferredSize() const override;
48 
49  private:
50   enum class LayoutStyle {
51     ONE_LINE_SUGGESTION,
52     TWO_LINE_SUGGESTION,
53   };
54 
55   void SetTailSuggestCommonPrefixWidth(const base::string16& common_prefix);
56 
57   bool is_rich_suggestion_ = false;
58   bool is_search_type_ = false;
59   LayoutStyle layout_style_ = LayoutStyle::ONE_LINE_SUGGESTION;
60 
61   // Weak pointers for easy reference.
62   // An icon representing the type or content.
63   views::ImageView* icon_view_;
64   // The image for answers in suggest and rich entity suggestions.
65   views::ImageView* answer_image_view_;
66   OmniboxTextView* content_view_;
67   OmniboxTextView* description_view_;
68   OmniboxTextView* separator_view_;
69 
70   // This (permanently) holds the rendered width of
71   // AutocompleteMatch::kEllipsis so that we don't have to keep calculating
72   // it.
73   int ellipsis_width_ = 0;
74 
75   // This holds the rendered width of the common prefix of a set of tail
76   // suggestions so that it doesn't have to be re-calculated if the prefix
77   // doesn't change.
78   int tail_suggest_common_prefix_width_ = 0;
79 
80   DISALLOW_COPY_AND_ASSIGN(OmniboxMatchCellView);
81 };
82 
83 #endif  // CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_MATCH_CELL_VIEW_H_
84