| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 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 "chrome/browser/ui/views/autocomplete/touch_autocomplete_popup_contents
_view.h" | |
| 6 | |
| 7 #include "chrome/browser/ui/omnibox/omnibox_view.h" | |
| 8 #include "third_party/skia/include/core/SkPaint.h" | |
| 9 #include "ui/gfx/canvas.h" | |
| 10 #include "ui/gfx/font.h" | |
| 11 #include "ui/gfx/path.h" | |
| 12 #include "ui/gfx/rect.h" | |
| 13 #include "ui/gfx/size.h" | |
| 14 #include "ui/views/view.h" | |
| 15 | |
| 16 // TouchAutocompleteResultView ------------------------------------------------ | |
| 17 | |
| 18 TouchAutocompleteResultView::TouchAutocompleteResultView( | |
| 19 AutocompleteResultViewModel* model, | |
| 20 int model_index, | |
| 21 const gfx::Font& font, | |
| 22 const gfx::Font& bold_font) | |
| 23 : AutocompleteResultView(model, model_index, font, bold_font) { | |
| 24 set_edge_item_padding(8); | |
| 25 set_item_padding(8); | |
| 26 set_minimum_text_vertical_padding(10); | |
| 27 } | |
| 28 | |
| 29 TouchAutocompleteResultView::~TouchAutocompleteResultView() { | |
| 30 } | |
| 31 | |
| 32 void TouchAutocompleteResultView::PaintMatch(gfx::Canvas* canvas, | |
| 33 const AutocompleteMatch& match, | |
| 34 int x) { | |
| 35 int y = text_bounds().y(); | |
| 36 | |
| 37 if (!match.description.empty()) { | |
| 38 // We use our base class's GetTextHeight below because we need the height | |
| 39 // of a single line of text. | |
| 40 DrawString(canvas, match.description, match.description_class, true, x, y); | |
| 41 y += AutocompleteResultView::GetTextHeight(); | |
| 42 } else { | |
| 43 // When we have only one line of content (no description), we center the | |
| 44 // single line vertically on our two-lines-tall results box. | |
| 45 y += AutocompleteResultView::GetTextHeight() / 2; | |
| 46 } | |
| 47 | |
| 48 DrawString(canvas, match.contents, match.contents_class, false, x, y); | |
| 49 } | |
| 50 | |
| 51 int TouchAutocompleteResultView::GetTextHeight() const { | |
| 52 return AutocompleteResultView::GetTextHeight() * 2; | |
| 53 } | |
| 54 | |
| 55 // TouchAutocompletePopupContentsView ----------------------------------------- | |
| 56 | |
| 57 TouchAutocompletePopupContentsView::TouchAutocompletePopupContentsView( | |
| 58 const gfx::Font& font, | |
| 59 OmniboxView* omnibox_view, | |
| 60 AutocompleteEditModel* edit_model, | |
| 61 views::View* location_bar) | |
| 62 : AutocompletePopupContentsView(font, omnibox_view, edit_model, | |
| 63 location_bar) { | |
| 64 } | |
| 65 | |
| 66 TouchAutocompletePopupContentsView::~TouchAutocompletePopupContentsView() { | |
| 67 } | |
| 68 | |
| 69 void TouchAutocompletePopupContentsView::UpdatePopupAppearance() { | |
| 70 AutocompletePopupContentsView::UpdatePopupAppearance(); | |
| 71 Layout(); | |
| 72 } | |
| 73 | |
| 74 void TouchAutocompletePopupContentsView::PaintResultViews(gfx::Canvas* canvas) { | |
| 75 AutocompletePopupContentsView::PaintResultViews(canvas); | |
| 76 | |
| 77 // Draw divider lines. | |
| 78 std::vector<View*> visible_children(GetVisibleChildren()); | |
| 79 if (visible_children.size() < 2) | |
| 80 return; | |
| 81 gfx::Rect bounds(GetContentsBounds()); | |
| 82 | |
| 83 // Draw a line at the bottom of each child except the last. The | |
| 84 // color of the line is determined to blend appropriately with the | |
| 85 // most dominant of the two surrounding cells, in precedence order, | |
| 86 // i.e. selected > hovered > normal. | |
| 87 for (std::vector<View*>::const_iterator i(visible_children.begin()); | |
| 88 i + 1 != visible_children.end(); ++i) { | |
| 89 TouchAutocompleteResultView* child = | |
| 90 static_cast<TouchAutocompleteResultView*>(*i); | |
| 91 TouchAutocompleteResultView* next_child = | |
| 92 static_cast<TouchAutocompleteResultView*>(*(i + 1)); | |
| 93 SkColor divider_color = AutocompleteResultView::GetColor( | |
| 94 std::max(child->GetState(), next_child->GetState()), | |
| 95 AutocompleteResultView::DIVIDER); | |
| 96 int line_y = child->y() + child->height() - 1; | |
| 97 canvas->DrawLine(gfx::Point(bounds.x(), line_y), | |
| 98 gfx::Point(bounds.right(), line_y), divider_color); | |
| 99 } | |
| 100 } | |
| 101 | |
| 102 AutocompleteResultView* TouchAutocompletePopupContentsView::CreateResultView( | |
| 103 AutocompleteResultViewModel* model, | |
| 104 int model_index, | |
| 105 const gfx::Font& font, | |
| 106 const gfx::Font& bold_font) { | |
| 107 return new TouchAutocompleteResultView(model, model_index, font, bold_font); | |
| 108 } | |
| 109 | |
| 110 std::vector<views::View*> | |
| 111 TouchAutocompletePopupContentsView::GetVisibleChildren() { | |
| 112 std::vector<View*> visible_children; | |
| 113 for (int i = 0; i < child_count(); ++i) { | |
| 114 View* v = child_at(i); | |
| 115 if (child_at(i)->visible()) | |
| 116 visible_children.push_back(v); | |
| 117 } | |
| 118 return visible_children; | |
| 119 } | |
| OLD | NEW |