Chromium Code Reviews| Index: chrome/browser/ui/views/autocomplete/touch_autocomplete_popup_contents_view.cc |
| diff --git a/chrome/browser/ui/views/autocomplete/touch_autocomplete_popup_contents_view.cc b/chrome/browser/ui/views/autocomplete/touch_autocomplete_popup_contents_view.cc |
| index f5f3865147b5e22e077a862de3482697183325f8..9b731da01f15905316bf867ee66555b213df96c6 100644 |
| --- a/chrome/browser/ui/views/autocomplete/touch_autocomplete_popup_contents_view.cc |
| +++ b/chrome/browser/ui/views/autocomplete/touch_autocomplete_popup_contents_view.cc |
| @@ -13,6 +13,16 @@ |
| #include "ui/gfx/size.h" |
| #include "ui/views/view.h" |
| +namespace { |
| + |
| +// Colors for a light-gray 3D-looking divider made up of two lines. |
|
Peter Kasting
2012/05/04 23:33:31
It's not safe to use hardcoded colors because ever
Jói
2012/05/04 23:52:19
Good point, will look into using the system colors
Jói
2012/05/07 16:26:18
I've switched to using system colors, am waiting t
|
| +const SkColor kDividerLineTopColor = |
| + SkColorSetARGBMacro(0xff, 0xe3, 0xe3, 0xe3); |
| +const SkColor kDividerLineBottomColor = |
| + SkColorSetARGBMacro(0xff, 0xfe, 0xfe, 0xfe); |
| + |
| +} // namespace |
| + |
| // TouchAutocompleteResultView ------------------------------------------------ |
| @@ -22,6 +32,9 @@ TouchAutocompleteResultView::TouchAutocompleteResultView( |
| const gfx::Font& font, |
| const gfx::Font& bold_font) |
| : AutocompleteResultView(model, model_index, font, bold_font) { |
| + edge_item_padding_ *= 3; |
| + item_padding_ *= 3; |
| + minimum_text_vertical_padding_ = 10; |
| } |
| TouchAutocompleteResultView::~TouchAutocompleteResultView() { |
| @@ -30,24 +43,38 @@ TouchAutocompleteResultView::~TouchAutocompleteResultView() { |
| void TouchAutocompleteResultView::PaintMatch(gfx::Canvas* canvas, |
| const AutocompleteMatch& match, |
| int x) { |
| - DrawString(canvas, match.contents, match.contents_class, false, x, |
| - text_bounds().y()); |
| + bool description = !match.description.empty(); |
| + int y = text_bounds().y(); |
| - if (!match.description.empty()) { |
| + // When we have only one line of content (no description), we center the |
| + // single line vertically on our two-lines-tall results box. |
| + if (!description) |
|
Peter Kasting
2012/05/04 23:33:31
Nit: if (match.description.empty()) { ... } else {
Jói
2012/05/07 16:26:18
Done.
|
| + y += AutocompleteResultView::GetTextHeight() / 2; |
| + |
| + if (description) { |
| // We use our base class's GetTextHeight below because we need the height |
| // of a single line of text. |
| - DrawString(canvas, match.description, match.description_class, true, x, |
| - text_bounds().y() + AutocompleteResultView::GetTextHeight()); |
| + DrawString(canvas, match.description, match.description_class, true, x, y); |
| + y += AutocompleteResultView::GetTextHeight(); |
| } |
| + |
| + DrawString(canvas, match.contents, match.contents_class, false, x, y); |
| } |
| int TouchAutocompleteResultView::GetTextHeight() const { |
| - // In the touch version of the autocomplete popup, the text is displayed in |
| - // two lines: First line is the title of the suggestion and second is the |
| - // description. Hence, the total text height is twice the height of one line. |
| return AutocompleteResultView::GetTextHeight() * 2; |
| } |
| +void TouchAutocompleteResultView::AdjustIconBounds( |
| + const AutocompleteMatch& match, gfx::Rect* bounds) { |
| + // We show the icon centered on the first line of content, so we |
| + // need to adjust the bounds when there are two lines. |
|
Peter Kasting
2012/05/04 23:33:31
Don't we need to do this all the time, not just wh
Jói
2012/05/04 23:52:19
The default case is that it's centered on the whol
Jói
2012/05/07 16:26:18
Added to the comment to explain why we don't need
|
| + if (!match.description.empty()) { |
| + bounds->set_y((AutocompleteResultView::GetTextHeight() - bounds->height()) / |
| + 2 + minimum_text_vertical_padding_); |
|
Peter Kasting
2012/05/04 23:33:31
Nit: The linebreak makes it look as if you're divi
Jói
2012/05/07 16:26:18
Done.
|
| + } |
| +} |
| + |
| // TouchAutocompletePopupContentsView ----------------------------------------- |
| @@ -68,19 +95,6 @@ void TouchAutocompletePopupContentsView::UpdatePopupAppearance() { |
| Layout(); |
| } |
| -void TouchAutocompletePopupContentsView::LayoutChildren() { |
| - std::vector<View*> visible_children(GetVisibleChildren()); |
| - gfx::Rect bounds(GetContentsBounds()); |
| - double child_width = |
| - static_cast<double>(bounds.width()) / visible_children.size(); |
| - int x = bounds.x(); |
| - for (size_t i = 0; i < visible_children.size(); ++i) { |
| - int next_x = bounds.x() + static_cast<int>(((i + 1) * child_width) + 0.5); |
| - visible_children[i]->SetBounds(x, bounds.y(), next_x - x, bounds.height()); |
| - x = next_x; |
| - } |
| -} |
| - |
| void TouchAutocompletePopupContentsView::PaintResultViews(gfx::Canvas* canvas) { |
| AutocompletePopupContentsView::PaintResultViews(canvas); |
| @@ -88,24 +102,22 @@ void TouchAutocompletePopupContentsView::PaintResultViews(gfx::Canvas* canvas) { |
| std::vector<View*> visible_children(GetVisibleChildren()); |
| if (visible_children.size() < 2) |
| return; |
| - SkColor color = AutocompleteResultView::GetColor( |
| - AutocompleteResultView::NORMAL, AutocompleteResultView::DIMMED_TEXT); |
| gfx::Rect bounds(GetContentsBounds()); |
| for (std::vector<View*>::const_iterator i(visible_children.begin() + 1); |
| i != visible_children.end(); ++i) { |
| - canvas->DrawLine(gfx::Point((*i)->x(), bounds.y()), |
| - gfx::Point((*i)->x(), bounds.bottom()), color); |
| - } |
| -} |
| - |
| -int TouchAutocompletePopupContentsView::CalculatePopupHeight() { |
| - DCHECK_GE(static_cast<size_t>(child_count()), model_->result().size()); |
| - int popup_height = 0; |
| - for (size_t i = 0; i < model_->result().size(); ++i) { |
| - popup_height = std::max(popup_height, |
| - child_at(i)->GetPreferredSize().height()); |
| + TouchAutocompleteResultView* child = |
| + static_cast<TouchAutocompleteResultView*>(*i); |
| + canvas->DrawLine( |
| + gfx::Point(bounds.x(), child->y() - 1), |
| + gfx::Point(bounds.right(), child->y() - 1), |
| + kDividerLineTopColor); |
| + if (child->GetState() == AutocompleteResultView::NORMAL) { |
| + canvas->DrawLine( |
| + gfx::Point(bounds.x(), child->y()), |
| + gfx::Point(bounds.right(), child->y()), |
| + kDividerLineBottomColor); |
| + } |
| } |
| - return popup_height; |
| } |
| AutocompleteResultView* TouchAutocompletePopupContentsView::CreateResultView( |