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 ------------------------------------------------ | |
oshima
2011/02/16 20:00:27
nit:
////////////////////
// TouchAutocompl..
is
Peter Kasting
2011/02/16 21:50:22
I explicitly directed this syntax because it is wh
oshima
2011/02/16 23:51:19
Good to know. Thanks for explanation.
| |
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 int TouchAutocompleteResultView::GetFontHeight() { | |
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) { | |
oshima
2011/02/16 20:00:27
indent
varunjain
2011/02/16 23:12:37
its already indented 4 spaces. Do you want to inde
oshima
2011/02/16 23:51:19
indent for "for" should be
for (...;
...) {
}
varunjain
2011/02/17 00:29:51
Done.
| |
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 int max_child_height = 0; | |
oshima
2011/02/16 20:00:27
is this used?
varunjain
2011/02/16 23:12:37
it is now :)
varunjain
2011/02/16 23:21:20
you are right... this is not required. the change
| |
114 for (int i = 0, j = 0; i < child_count() && j < visible_child_count; ++i) { | |
115 View* v = GetChildViewAt(i); | |
116 if (v->IsVisible()) { | |
117 int child_height = v->GetPreferredSize().height(); | |
118 v->SetBounds(contents_rect.x() + (j++) * child_width, contents_rect.y(), | |
119 child_width, child_height); | |
120 max_child_height = std::max(max_child_height, child_height); | |
121 } | |
122 } | |
123 } | |
124 | |
125 int TouchAutocompletePopupContentsView::CalculatePopupHeight() { | |
126 DCHECK_GE(static_cast<size_t>(child_count()), model_->result().size()); | |
127 int popup_height = 0; | |
128 for (size_t i = 0; i < model_->result().size(); ++i) { | |
129 popup_height = std::max(popup_height, | |
130 GetChildViewAt(i)->GetPreferredSize().height()); | |
131 } | |
132 if (opt_in_view_) | |
133 popup_height = std::max(popup_height, | |
134 opt_in_view_->GetPreferredSize().height()); | |
oshima
2011/02/16 20:00:27
{} for two or more lines
varunjain
2011/02/16 23:12:37
Done.
| |
135 return popup_height; | |
136 } | |
137 | |
138 AutocompleteResultView* TouchAutocompletePopupContentsView::CreateResultView( | |
139 AutocompleteResultViewModel* model, | |
140 int model_index, | |
141 const gfx::Font& font, | |
142 const gfx::Font& bold_font) { | |
143 return new TouchAutocompleteResultView(model, model_index, font, bold_font); | |
144 } | |
145 | |
146 int TouchAutocompletePopupContentsView::GetVisibleChildCount() { | |
147 int visible_child_count = 0; | |
148 for (int i = 0; i < child_count(); ++i) | |
oshima
2011/02/16 20:00:27
i think you need {} in this case.
varunjain
2011/02/16 23:12:37
Done.
| |
149 if (GetChildViewAt(i)->IsVisible()) | |
150 visible_child_count++; | |
151 return visible_child_count; | |
152 } | |
OLD | NEW |