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