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