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,
84 const base::string16& text,
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;
115 virtual void Layout() OVERRIDE;
116 virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE;
117 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
119 // gfx::AnimationDelegate:
120 virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE;
122 static int default_icon_size_;
124 // Default values cached here, may be overridden using the setters above.
125 int edge_item_padding_;
127 int minimum_text_vertical_padding_;
129 // This row's model and model index.
130 OmniboxResultViewModel* model_;
133 LocationBarView* location_bar_view_;
135 const gfx::FontList font_list_;
138 // Width of the ellipsis in the normal font.
141 // A context used for mirroring regions.
142 class MirroringContext;
143 scoped_ptr<MirroringContext> mirroring_context_;
145 AutocompleteMatch match_;
147 gfx::Rect text_bounds_;
148 gfx::Rect icon_bounds_;
150 gfx::Rect keyword_text_bounds_;
151 scoped_ptr<views::ImageView> keyword_icon_;
153 scoped_ptr<gfx::SlideAnimation> animation_;
155 DISALLOW_COPY_AND_ASSIGN(OmniboxResultView);
158 #endif // CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_RESULT_VIEW_H_