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..f81ab859cf3c6dc5609397262c3f6e7d06479f29 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,7 +13,6 @@ |
| #include "ui/gfx/size.h" |
| #include "ui/views/view.h" |
| - |
| // TouchAutocompleteResultView ------------------------------------------------ |
| TouchAutocompleteResultView::TouchAutocompleteResultView( |
| @@ -22,6 +21,9 @@ TouchAutocompleteResultView::TouchAutocompleteResultView( |
| const gfx::Font& font, |
| const gfx::Font& bold_font) |
| : AutocompleteResultView(model, model_index, font, bold_font) { |
| + set_edge_item_padding(8); |
| + set_item_padding(8); |
| + set_minimum_text_vertical_padding(10); |
| } |
| TouchAutocompleteResultView::~TouchAutocompleteResultView() { |
| @@ -30,25 +32,26 @@ 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()); |
| + int y = text_bounds().y(); |
| if (!match.description.empty()) { |
| // 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(); |
| + } else { |
| + // When we have only one line of content (no description), we center the |
| + // single line vertically on our two-lines-tall results box. |
| + y += AutocompleteResultView::GetTextHeight() / 2; |
| } |
| + |
| + 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; |
| } |
| - |
| // TouchAutocompletePopupContentsView ----------------------------------------- |
| TouchAutocompletePopupContentsView::TouchAutocompletePopupContentsView( |
| @@ -68,19 +71,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 +78,45 @@ 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()); |
| + // Normally, we draw dividers at the top of each child. However, if |
| + // the current item is selected or hovered, the divider color needs |
| + // to blend with the background color of the current child, so we |
| + // draw at the top and bottom of the current child and skip the line |
| + // at the top of the next child. |
|
Peter Kasting
2012/05/11 23:01:41
Uff da.
Can we just do normal-colored dividers be
Jói
2012/05/11 23:09:24
I tried with normal-colored dividers regardless of
Jói
2012/05/14 18:29:45
I've changed this code as per your suggestion, it'
|
| + // |
| + // We also skip the top line of the first child since there is |
| + // already the dropdown border, and likewise we never draw a line at |
| + // the bottom of the last child. |
| + bool skip_next = true; |
| + for (std::vector<View*>::const_iterator i(visible_children.begin()); |
| + i != visible_children.end(); ++i) { |
| + TouchAutocompleteResultView* child = |
| + static_cast<TouchAutocompleteResultView*>(*i); |
| + SkColor divider_color = AutocompleteResultView::GetColor( |
| + child->GetState(), AutocompleteResultView::DIVIDER); |
| + |
| + if (!skip_next) { |
| + canvas->DrawLine( |
| + gfx::Point(bounds.x(), child->y()), |
| + gfx::Point(bounds.right(), child->y()), |
| + divider_color); |
| + } |
| + |
| + skip_next = false; |
| + |
| + if ((child->GetState() == AutocompleteResultView::SELECTED || |
| + child->GetState() == AutocompleteResultView::HOVERED) && |
| + i + 1 != visible_children.end()) { |
| + skip_next = true; |
| + |
| + canvas->DrawLine( |
| + gfx::Point(bounds.x(), child->y() + child->height() - 1), |
| + gfx::Point(bounds.right(), child->y() + child->height() - 1), |
| + divider_color); |
| + } |
| } |
| - return popup_height; |
| } |
| AutocompleteResultView* TouchAutocompletePopupContentsView::CreateResultView( |