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 |
new file mode 100644 |
index 0000000000000000000000000000000000000000..f997bb592d5f8c02abd515c4b5fb2882223cff10 |
--- /dev/null |
+++ b/chrome/browser/ui/views/autocomplete/touch_autocomplete_popup_contents_view.cc |
@@ -0,0 +1,152 @@ |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "touch_autocomplete_popup_contents_view.h" |
+ |
+#include "chrome/browser/autocomplete/autocomplete_edit_view.h" |
+#include "chrome/browser/profiles/profile.h" |
+#include "ui/gfx/canvas.h" |
+#include "ui/gfx/canvas_skia.h" |
+#include "ui/gfx/font.h" |
+#include "ui/gfx/path.h" |
+#include "ui/gfx/rect.h" |
+#include "ui/gfx/size.h" |
+#include "third_party/skia/include/core/SkPaint.h" |
+#include "views/view.h" |
+ |
+ |
+// TouchAutocompleteResultView ------------------------------------------------ |
oshima
2011/02/16 20:00:27
nit:
////////////////////
// TouchAutocompl..
is
Peter Kasting
2011/02/16 21:50:22
I explicitly directed this syntax because it is wh
oshima
2011/02/16 23:51:19
Good to know. Thanks for explanation.
|
+ |
+TouchAutocompleteResultView::TouchAutocompleteResultView( |
+ AutocompleteResultViewModel* model, |
+ int model_index, |
+ const gfx::Font& font, |
+ const gfx::Font& bold_font) |
+ : AutocompleteResultView(model, model_index, font, bold_font) { |
+} |
+ |
+TouchAutocompleteResultView::~TouchAutocompleteResultView() { |
+} |
+ |
+void TouchAutocompleteResultView::Layout() { |
+ AutocompleteResultView::Layout(); |
+ |
+ // In touch version of 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 2 times the height of one line. |
+ int text_height = 2 * GetFontHeight(); |
+ set_text_bounds(gfx::Rect(text_bounds().x(), |
+ std::max(0, (height() - text_height) / 2), |
+ text_bounds().width(), |
+ text_height)); |
+} |
+ |
+gfx::Size TouchAutocompleteResultView::GetPreferredSize() { |
+ int text_height = 2 * (GetFontHeight() + text_vertical_padding_); |
+ int icon_height = AutocompleteResultView::icon_size_ + |
+ (icon_vertical_padding_ * 2); |
+ return gfx::Size(0, std::max(icon_height, text_height)); |
+} |
+ |
+void TouchAutocompleteResultView::PaintMatch(gfx::Canvas* canvas, |
+ const AutocompleteMatch& match, |
+ int x) { |
+ DrawString(canvas, match.contents, match.contents_class, false, x, |
+ text_bounds().y()); |
+ |
+ if (!match.description.empty()) { |
+ int y = text_bounds().y() + GetFontHeight(); |
+ DrawString(canvas, match.description, match.description_class, true, x, y); |
+ } |
+} |
+ |
+int TouchAutocompleteResultView::GetFontHeight() { |
+ return std::max(normal_font().GetHeight(), bold_font().GetHeight()); |
+} |
+ |
+ |
+// TouchAutocompletePopupContentsView ----------------------------------------- |
+ |
+TouchAutocompletePopupContentsView::TouchAutocompletePopupContentsView( |
+ const gfx::Font& font, |
+ AutocompleteEditView* edit_view, |
+ AutocompleteEditModel* edit_model, |
+ Profile* profile, |
+ const views::View* location_bar) |
+ : AutocompletePopupContentsView(font, edit_view, edit_model, profile, |
+ location_bar) { |
+} |
+ |
+TouchAutocompletePopupContentsView::~TouchAutocompletePopupContentsView() { |
+} |
+ |
+void TouchAutocompletePopupContentsView::UpdatePopupAppearance() { |
+ AutocompletePopupContentsView::UpdatePopupAppearance(); |
+ Layout(); |
+} |
+ |
+void TouchAutocompletePopupContentsView::PaintChildren( |
+ gfx::CanvasSkia* canvas) { |
+ AutocompletePopupContentsView::PaintChildren(canvas); |
+ |
+ // Draw divider lines. |
+ int visible_child_count = GetVisibleChildCount(); |
+ for (int i = 0, j = 0; i < child_count() && j < visible_child_count - 1; |
+ ++i) { |
oshima
2011/02/16 20:00:27
indent
varunjain
2011/02/16 23:12:37
its already indented 4 spaces. Do you want to inde
oshima
2011/02/16 23:51:19
indent for "for" should be
for (...;
...) {
}
varunjain
2011/02/17 00:29:51
Done.
|
+ View* v = GetChildViewAt(i); |
+ if (v->IsVisible()) { |
+ canvas->DrawLineInt(AutocompleteResultView::GetColor( |
+ AutocompleteResultView::NORMAL, AutocompleteResultView::DIMMED_TEXT), |
+ v->x() + v->width(), v->y(), |
+ v->x() + v->width(), v->y() + v->height()); |
+ ++j; |
+ } |
+ } |
+} |
+ |
+void TouchAutocompletePopupContentsView::LayoutChildren() { |
+ gfx::Rect contents_rect = GetContentsBounds(); |
+ int visible_child_count = GetVisibleChildCount(); |
+ int child_width = contents_rect.width() / visible_child_count; |
+ |
+ int max_child_height = 0; |
oshima
2011/02/16 20:00:27
is this used?
varunjain
2011/02/16 23:12:37
it is now :)
varunjain
2011/02/16 23:21:20
you are right... this is not required. the change
|
+ for (int i = 0, j = 0; i < child_count() && j < visible_child_count; ++i) { |
+ View* v = GetChildViewAt(i); |
+ if (v->IsVisible()) { |
+ int child_height = v->GetPreferredSize().height(); |
+ v->SetBounds(contents_rect.x() + (j++) * child_width, contents_rect.y(), |
+ child_width, child_height); |
+ max_child_height = std::max(max_child_height, child_height); |
+ } |
+ } |
+} |
+ |
+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, |
+ GetChildViewAt(i)->GetPreferredSize().height()); |
+ } |
+ if (opt_in_view_) |
+ popup_height = std::max(popup_height, |
+ opt_in_view_->GetPreferredSize().height()); |
oshima
2011/02/16 20:00:27
{} for two or more lines
varunjain
2011/02/16 23:12:37
Done.
|
+ return popup_height; |
+} |
+ |
+AutocompleteResultView* TouchAutocompletePopupContentsView::CreateResultView( |
+ AutocompleteResultViewModel* model, |
+ int model_index, |
+ const gfx::Font& font, |
+ const gfx::Font& bold_font) { |
+ return new TouchAutocompleteResultView(model, model_index, font, bold_font); |
+} |
+ |
+int TouchAutocompletePopupContentsView::GetVisibleChildCount() { |
+ int visible_child_count = 0; |
+ for (int i = 0; i < child_count(); ++i) |
oshima
2011/02/16 20:00:27
i think you need {} in this case.
varunjain
2011/02/16 23:12:37
Done.
|
+ if (GetChildViewAt(i)->IsVisible()) |
+ visible_child_count++; |
+ return visible_child_count; |
+} |