OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2011 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 #include "touch_autocomplete_popup_contents_view.h" | |
6 | |
7 #include "chrome/browser/autocomplete/autocomplete_edit_view.h" | |
8 #include "chrome/browser/profiles/profile.h" | |
9 #include "ui/gfx/canvas.h" | |
10 #include "ui/gfx/canvas_skia.h" | |
11 #include "ui/gfx/font.h" | |
12 #include "ui/gfx/path.h" | |
13 #include "ui/gfx/rect.h" | |
14 #include "ui/gfx/size.h" | |
15 #include "third_party/skia/include/core/SkPaint.h" | |
16 #include "views/view.h" | |
17 | |
18 | |
19 // TouchAutocompleteResultView ------------------------------------------------ | |
20 | |
21 TouchAutocompleteResultView::TouchAutocompleteResultView( | |
22 AutocompleteResultViewModel* model, | |
23 int model_index, | |
24 const gfx::Font& font, | |
25 const gfx::Font& bold_font) | |
26 : AutocompleteResultView(model, model_index, font, bold_font) { | |
27 } | |
28 | |
29 TouchAutocompleteResultView::~TouchAutocompleteResultView() { | |
30 } | |
31 | |
32 void TouchAutocompleteResultView::Layout() { | |
33 AutocompleteResultView::Layout(); | |
34 | |
35 // In touch version of autocomplete popup, the text is displayed in two lines: | |
36 // First line is the title of the suggestion and second is the description. | |
37 // Hence, the total text height is 2 times the height of one line. | |
38 int text_height = 2 * GetFontHeight(); | |
39 set_text_bounds(gfx::Rect(text_bounds().x(), | |
40 std::max(0, (height() - text_height) / 2), | |
41 text_bounds().width(), | |
42 text_height)); | |
43 } | |
44 | |
45 gfx::Size TouchAutocompleteResultView::GetPreferredSize() { | |
46 int text_height = 2 * (GetFontHeight() + text_vertical_padding_); | |
47 int icon_height = AutocompleteResultView::icon_size_ + | |
48 (icon_vertical_padding_ * 2); | |
49 return gfx::Size(0, std::max(icon_height, text_height)); | |
50 } | |
51 | |
52 void TouchAutocompleteResultView::PaintMatch(gfx::Canvas* canvas, | |
53 const AutocompleteMatch& match, | |
54 int x) { | |
55 DrawString(canvas, match.contents, match.contents_class, false, x, | |
56 text_bounds().y()); | |
57 | |
58 if (!match.description.empty()) { | |
59 int y = text_bounds().y() + GetFontHeight(); | |
60 DrawString(canvas, match.description, match.description_class, true, x, y); | |
61 } | |
62 } | |
63 | |
64 const int TouchAutocompleteResultView::GetFontHeight() { | |
oshima
2011/02/16 23:51:19
I meant
int TouchAutocompleteResultView::GetFontHe
varunjain
2011/02/17 00:29:51
I meant that too... I think I need more coffee :)
| |
65 return std::max(normal_font().GetHeight(), bold_font().GetHeight()); | |
66 } | |
67 | |
68 | |
69 // TouchAutocompletePopupContentsView ----------------------------------------- | |
70 | |
71 TouchAutocompletePopupContentsView::TouchAutocompletePopupContentsView( | |
72 const gfx::Font& font, | |
73 AutocompleteEditView* edit_view, | |
74 AutocompleteEditModel* edit_model, | |
75 Profile* profile, | |
76 const views::View* location_bar) | |
77 : AutocompletePopupContentsView(font, edit_view, edit_model, profile, | |
78 location_bar) { | |
79 } | |
80 | |
81 TouchAutocompletePopupContentsView::~TouchAutocompletePopupContentsView() { | |
82 } | |
83 | |
84 void TouchAutocompletePopupContentsView::UpdatePopupAppearance() { | |
85 AutocompletePopupContentsView::UpdatePopupAppearance(); | |
86 Layout(); | |
87 } | |
88 | |
89 void TouchAutocompletePopupContentsView::PaintChildren( | |
90 gfx::CanvasSkia* canvas) { | |
91 AutocompletePopupContentsView::PaintChildren(canvas); | |
92 | |
93 // Draw divider lines. | |
94 int visible_child_count = GetVisibleChildCount(); | |
95 for (int i = 0, j = 0; i < child_count() && j < visible_child_count - 1; | |
96 ++i) { | |
97 View* v = GetChildViewAt(i); | |
98 if (v->IsVisible()) { | |
99 canvas->DrawLineInt(AutocompleteResultView::GetColor( | |
100 AutocompleteResultView::NORMAL, AutocompleteResultView::DIMMED_TEXT), | |
101 v->x() + v->width(), v->y(), | |
102 v->x() + v->width(), v->y() + v->height()); | |
103 ++j; | |
104 } | |
105 } | |
106 } | |
107 | |
108 void TouchAutocompletePopupContentsView::LayoutChildren() { | |
109 gfx::Rect contents_rect = GetContentsBounds(); | |
110 int visible_child_count = GetVisibleChildCount(); | |
111 int child_width = contents_rect.width() / visible_child_count; | |
112 | |
113 for (int i = 0, j = 0; i < child_count() && j < visible_child_count; ++i) { | |
114 View* v = GetChildViewAt(i); | |
115 if (v->IsVisible()) { | |
116 int child_height = v->GetPreferredSize().height(); | |
117 v->SetBounds(contents_rect.x() + (j++) * child_width, contents_rect.y(), | |
118 child_width, child_height); | |
119 } | |
120 } | |
121 } | |
122 | |
123 int TouchAutocompletePopupContentsView::CalculatePopupHeight() { | |
124 DCHECK_GE(static_cast<size_t>(child_count()), model_->result().size()); | |
125 int popup_height = 0; | |
126 for (size_t i = 0; i < model_->result().size(); ++i) { | |
127 popup_height = std::max(popup_height, | |
128 GetChildViewAt(i)->GetPreferredSize().height()); | |
129 } | |
130 if (opt_in_view_) { | |
131 popup_height = std::max(popup_height, | |
132 opt_in_view_->GetPreferredSize().height()); | |
133 } | |
134 return popup_height; | |
135 } | |
136 | |
137 AutocompleteResultView* TouchAutocompletePopupContentsView::CreateResultView( | |
138 AutocompleteResultViewModel* model, | |
139 int model_index, | |
140 const gfx::Font& font, | |
141 const gfx::Font& bold_font) { | |
142 return new TouchAutocompleteResultView(model, model_index, font, bold_font); | |
143 } | |
144 | |
145 const int TouchAutocompletePopupContentsView::GetVisibleChildCount() { | |
oshima
2011/02/16 23:51:19
I meant
int TouchAutocompletePopupContentsView::G
varunjain
2011/02/17 00:29:51
Done.
| |
146 int visible_child_count = 0; | |
147 for (int i = 0; i < child_count(); ++i) { | |
148 if (GetChildViewAt(i)->IsVisible()) | |
149 visible_child_count++; | |
150 } | |
151 return visible_child_count; | |
152 } | |
OLD | NEW |