Chromium Code Reviews| 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 const int kMaxResultViews = 4; | |
| 19 | |
| 20 //////////////////////////////////////////////////////////////////////////////// | |
|
Peter Kasting
2011/02/16 00:50:35
Nit: In new code, I ask people to avoid these big
varunjain
2011/02/16 18:48:10
Done.
| |
| 21 // TouchAutocompleteResultView public | |
| 22 | |
| 23 TouchAutocompleteResultView::TouchAutocompleteResultView( | |
| 24 AutocompleteResultViewModel* model, | |
| 25 int model_index, | |
| 26 const gfx::Font& font, | |
| 27 const gfx::Font& bold_font) | |
| 28 : AutocompleteResultView(model, model_index, font, bold_font) { | |
| 29 } | |
| 30 | |
| 31 TouchAutocompleteResultView::~TouchAutocompleteResultView() { | |
| 32 } | |
| 33 | |
| 34 void TouchAutocompleteResultView::Layout() { | |
| 35 AutocompleteResultView::Layout(); | |
| 36 int text_height = | |
| 37 2 * std::max(normal_font().GetHeight(), bold_font().GetHeight()); | |
|
Peter Kasting
2011/02/16 00:50:35
Why "2 *"?
varunjain
2011/02/16 18:48:10
added comment to explain.
| |
| 38 set_text_bounds(gfx::Rect(text_bounds().x(), | |
| 39 std::max(0, (height() - text_height) / 2), | |
| 40 text_bounds().width(), | |
| 41 text_height)); | |
| 42 } | |
| 43 | |
| 44 gfx::Size TouchAutocompleteResultView::GetPreferredSize() { | |
| 45 int text_height = | |
| 46 2 * (std::max(normal_font().GetHeight(), bold_font().GetHeight()) + | |
| 47 text_vertical_padding_); | |
| 48 int icon_height = AutocompleteResultView::icon_size_ + | |
| 49 (icon_vertical_padding_ * 2); | |
| 50 return gfx::Size(0, std::max(icon_height, text_height)); | |
| 51 } | |
| 52 | |
| 53 //////////////////////////////////////////////////////////////////////////////// | |
| 54 // TouchAutocompleteResultView protected | |
| 55 | |
| 56 void TouchAutocompleteResultView::PaintMatch(gfx::Canvas* canvas, | |
| 57 const AutocompleteMatch& match, | |
| 58 int x) { | |
| 59 DrawString(canvas, match.contents, match.contents_class, false, x, | |
| 60 text_bounds().y()); | |
| 61 | |
| 62 if (!match.description.empty()) { | |
| 63 int y = text_bounds().y() | |
| 64 + std::max(normal_font().GetHeight(), bold_font().GetHeight()); | |
|
Peter Kasting
2011/02/16 00:50:35
Nit: + goes at end of previous line
varunjain
2011/02/16 18:48:10
not required anymore
| |
| 65 DrawString(canvas, match.description, match.description_class, true, x, y); | |
| 66 } | |
| 67 } | |
| 68 | |
| 69 //////////////////////////////////////////////////////////////////////////////// | |
| 70 // TouchAutocompletePopupContentsView public. | |
| 71 | |
| 72 TouchAutocompletePopupContentsView::TouchAutocompletePopupContentsView( | |
| 73 const gfx::Font& font, | |
| 74 AutocompleteEditView* edit_view, | |
| 75 AutocompleteEditModel* edit_model, | |
| 76 Profile* profile, | |
| 77 const views::View* location_bar) | |
| 78 : AutocompletePopupContentsView(font, edit_view, edit_model, profile, | |
| 79 location_bar) { | |
| 80 } | |
| 81 | |
| 82 TouchAutocompletePopupContentsView::~TouchAutocompletePopupContentsView() { | |
| 83 } | |
| 84 | |
| 85 void TouchAutocompletePopupContentsView::UpdatePopupAppearance() { | |
| 86 AutocompletePopupContentsView::UpdatePopupAppearance(); | |
| 87 Layout(); | |
|
Peter Kasting
2011/02/16 00:50:35
Why is this necessary when it's not necessary in t
varunjain
2011/02/16 18:48:10
Layout happens in the base class implicitly becaus
Peter Kasting
2011/02/16 21:50:22
Then you're not doing things correctly in the Touc
varunjain
2011/02/16 23:12:37
Not quiet. The touch popup never changes size (unl
| |
| 88 } | |
| 89 | |
| 90 void TouchAutocompletePopupContentsView::PaintChildren( | |
| 91 gfx::CanvasSkia* canvas) { | |
| 92 AutocompletePopupContentsView::PaintChildren(canvas); | |
| 93 | |
| 94 // Draw divider lines. | |
| 95 int visible_child_count = GetVisibleChildCount(); | |
| 96 for (int i = 0, j = 0; i < child_count() && j < visible_child_count - 1; | |
| 97 ++i) { | |
| 98 View* v = GetChildViewAt(i); | |
| 99 if (v->IsVisible()) { | |
| 100 canvas->DrawLineInt(AutocompleteResultView::GetColor( | |
| 101 AutocompleteResultView::NORMAL, AutocompleteResultView::DIMMED_TEXT), | |
| 102 v->x() + v->width(), v->y(), | |
| 103 v->x() + v->width(), v->y() + v->height()); | |
| 104 ++j; | |
| 105 } | |
| 106 } | |
| 107 } | |
| 108 | |
| 109 void TouchAutocompletePopupContentsView::LayoutChildren() { | |
| 110 gfx::Rect contents_rect = GetContentsBounds(); | |
| 111 int visible_child_count = GetVisibleChildCount(); | |
| 112 int child_width = contents_rect.width() / visible_child_count; | |
| 113 | |
| 114 int max_child_height = 0; | |
| 115 for (int i = 0, j = 0; i < child_count() && j < visible_child_count; ++i) { | |
| 116 View* v = GetChildViewAt(i); | |
| 117 if (v->IsVisible()) { | |
| 118 int child_height = v->GetPreferredSize().height(); | |
| 119 v->SetBounds(contents_rect.x() + (j++) * child_width, contents_rect.y(), | |
| 120 child_width, child_height); | |
| 121 if (max_child_height < child_height) | |
|
Peter Kasting
2011/02/16 00:50:35
Nit: How about just:
max_child_height = std::max(
varunjain
2011/02/16 18:48:10
Done.
| |
| 122 max_child_height = child_height; | |
| 123 } | |
| 124 } | |
| 125 } | |
| 126 | |
| 127 //////////////////////////////////////////////////////////////////////////////// | |
| 128 // TouchAutocompletePopupContentsView protected. | |
| 129 | |
| 130 int TouchAutocompletePopupContentsView::CalculatePopupHeight() { | |
| 131 int popup_height = 0; | |
| 132 int result_size = model()->result().size(); | |
|
Peter Kasting
2011/02/16 00:50:35
You'll want to update this function to look like t
varunjain
2011/02/16 18:48:10
Done.
| |
| 133 for (int i = 0; i < result_size && i < child_count(); ++i) { | |
| 134 AutocompleteResultView* result_view = | |
| 135 static_cast<AutocompleteResultView*>(GetChildViewAt(i)); | |
| 136 int child_height = result_view->GetPreferredSize().height(); | |
| 137 if (popup_height < child_height) | |
| 138 popup_height = child_height; | |
| 139 } | |
| 140 if (opt_in_view() && | |
| 141 popup_height < opt_in_view()->GetPreferredSize().height()) | |
| 142 popup_height = opt_in_view()->GetPreferredSize().height(); | |
| 143 return popup_height; | |
| 144 } | |
| 145 | |
| 146 AutocompleteResultView* TouchAutocompletePopupContentsView::CreateResultView( | |
|
Peter Kasting
2011/02/16 00:50:35
So, how come we use a factory function in this cas
varunjain
2011/02/16 18:48:10
we cannot use a factory function in AutocompleteEd
oshima
2011/02/16 20:00:27
At some point, we need to merge touch and chromeos
varunjain
2011/02/16 23:12:37
Done.
| |
| 147 AutocompleteResultViewModel* model, | |
| 148 int model_index, | |
| 149 const gfx::Font& font, | |
| 150 const gfx::Font& bold_font) { | |
| 151 return new TouchAutocompleteResultView(model, model_index, font, bold_font); | |
| 152 } | |
| 153 | |
| 154 //////////////////////////////////////////////////////////////////////////////// | |
| 155 // TouchAutocompletePopupContentsView private. | |
| 156 | |
| 157 int TouchAutocompletePopupContentsView::GetVisibleChildCount() { | |
| 158 int visible_child_count = 0; | |
| 159 for (int i = 0; i < child_count(); ++i) | |
| 160 if (GetChildViewAt(i)->IsVisible()) | |
| 161 visible_child_count++; | |
| 162 if (visible_child_count > kMaxResultViews) | |
|
Peter Kasting
2011/02/16 00:50:35
Whoah there. You don't want to be clamping the vi
varunjain
2011/02/16 18:48:10
yes... I realized that clamping here doesnot work
Peter Kasting
2011/02/16 21:50:22
No, you don't. In both cases, you can simply keep
varunjain
2011/02/16 23:12:37
Sry... I am really not getting this :(
as the widt
| |
| 163 visible_child_count = kMaxResultViews; | |
| 164 return visible_child_count; | |
| 165 } | |
| OLD | NEW |