1 // Copyright (c) 2012 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.
5 #ifndef CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_RESULT_VIEW_H_
6 #define CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_RESULT_VIEW_H_
10 #include "chrome/browser/autocomplete/autocomplete_match.h"
11 #include "third_party/skia/include/core/SkColor.h"
12 #include "ui/gfx/animation/animation_delegate.h"
13 #include "ui/gfx/animation/slide_animation.h"
14 #include "ui/gfx/font_list.h"
15 #include "ui/gfx/rect.h"
16 #include "ui/views/controls/image_view.h"
17 #include "ui/views/view.h"
19 class LocationBarView;
20 class OmniboxResultViewModel;
27 class OmniboxResultView : public views::View,
28 private gfx::AnimationDelegate {
30 // Keep these ordered from least dominant (normal) to most dominant
32 enum ResultViewState {
48 OmniboxResultView(OmniboxResultViewModel* model,
50 LocationBarView* location_bar_view,
51 const gfx::FontList& font_list);
52 virtual ~OmniboxResultView();
54 SkColor GetColor(ResultViewState state, ColorKind kind) const;
56 // Updates the match used to paint the contents of this result view. We copy
57 // the match so that we can continue to paint the last result even after the
59 void SetMatch(const AutocompleteMatch& match);
61 void ShowKeyword(bool show_keyword);
66 virtual gfx::Size GetPreferredSize() OVERRIDE;
68 ResultViewState GetState() const;
70 // Returns the height of the text portion of the result view. In the base
71 // class, this is the height of one line of text.
72 virtual int GetTextHeight() const;
75 virtual void PaintMatch(gfx::Canvas* canvas,
76 const AutocompleteMatch& match,
79 // Draws the specified |text| into the canvas, using highlighting provided by
80 // |classifications|. If |force_dim| is true, ACMatchClassification::DIM is
81 // added to all of the classifications. Returns the x position to the right
83 int DrawString(gfx::Canvas* canvas,
85 const ACMatchClassifications& classifications,
90 const gfx::Rect& text_bounds() const { return text_bounds_; }
92 void set_edge_item_padding(int value) { edge_item_padding_ = value; }
93 void set_item_padding(int value) { item_padding_ = value; }
94 void set_minimum_text_vertical_padding(int value) {
95 minimum_text_vertical_padding_ = value;
100 typedef std::vector<RunData> Runs;
101 typedef std::vector<gfx::RenderText*> Classifications;
103 // Common initialization code of the colors returned by GetColors().
104 static void CommonInitColors(const ui::NativeTheme* theme,
105 SkColor colors[][NUM_KINDS]);
107 // Predicate functions for use when sorting the runs.
108 static bool SortRunsLogically(const RunData& lhs, const RunData& rhs);
109 static bool SortRunsVisually(const RunData& lhs, const RunData& rhs);
111 gfx::ImageSkia GetIcon() const;
112 const gfx::ImageSkia* GetKeywordIcon() const;
114 // Elides |runs| to fit in |remaining_width|. The runs in |runs| should be in
117 // When we need to elide a run, the ellipsis will be placed at the end of that
118 // run. This means that if we elide a run whose visual direction is opposite
119 // that of the drawing context, the ellipsis will not be at the "end" of the
120 // drawn string. For example, if in an LTR context we have the LTR run
121 // "LTR_STRING" and the RTL run "RTL_STRING", the unelided text would be drawn
123 // LTR_STRING GNIRTS_LTR
124 // If we need to elide the RTL run, then it will be drawn like:
125 // LTR_STRING ...RTS_LTR
127 // LTR_STRING RTS_LTR...
128 void Elide(Runs* runs, int remaining_width) const;
131 virtual void Layout() OVERRIDE;
132 virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE;
133 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
135 // gfx::AnimationDelegate:
136 virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE;
138 static int default_icon_size_;
140 // Default values cached here, may be overridden using the setters above.
141 int edge_item_padding_;
143 int minimum_text_vertical_padding_;
145 // This row's model and model index.
146 OmniboxResultViewModel* model_;
149 LocationBarView* location_bar_view_;
151 const gfx::FontList font_list_;
154 // Width of the ellipsis in the normal font.
157 // A context used for mirroring regions.
158 class MirroringContext;
159 scoped_ptr<MirroringContext> mirroring_context_;
161 AutocompleteMatch match_;
163 gfx::Rect text_bounds_;
164 gfx::Rect icon_bounds_;
166 gfx::Rect keyword_text_bounds_;
167 scoped_ptr<views::ImageView> keyword_icon_;
169 scoped_ptr<gfx::SlideAnimation> animation_;
171 DISALLOW_COPY_AND_ASSIGN(OmniboxResultView);
174 #endif // CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_RESULT_VIEW_H_