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..63c4ebdb6becd7c92d9e3278e4791f1bd15bb4ab |
--- /dev/null |
+++ b/chrome/browser/ui/views/autocomplete/touch_autocomplete_popup_contents_view.cc |
@@ -0,0 +1,165 @@ |
+// 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" |
+ |
+const int kMaxResultViews = 4; |
+ |
+//////////////////////////////////////////////////////////////////////////////// |
Peter Kasting
2011/02/16 00:50:35
Nit: In new code, I ask people to avoid these big
varunjain
2011/02/16 18:48:10
Done.
|
+// TouchAutocompleteResultView public |
+ |
+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(); |
+ int text_height = |
+ 2 * std::max(normal_font().GetHeight(), bold_font().GetHeight()); |
Peter Kasting
2011/02/16 00:50:35
Why "2 *"?
varunjain
2011/02/16 18:48:10
added comment to explain.
|
+ 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 * (std::max(normal_font().GetHeight(), bold_font().GetHeight()) + |
+ text_vertical_padding_); |
+ int icon_height = AutocompleteResultView::icon_size_ + |
+ (icon_vertical_padding_ * 2); |
+ return gfx::Size(0, std::max(icon_height, text_height)); |
+} |
+ |
+//////////////////////////////////////////////////////////////////////////////// |
+// TouchAutocompleteResultView protected |
+ |
+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() |
+ + std::max(normal_font().GetHeight(), bold_font().GetHeight()); |
Peter Kasting
2011/02/16 00:50:35
Nit: + goes at end of previous line
varunjain
2011/02/16 18:48:10
not required anymore
|
+ DrawString(canvas, match.description, match.description_class, true, x, y); |
+ } |
+} |
+ |
+//////////////////////////////////////////////////////////////////////////////// |
+// TouchAutocompletePopupContentsView public. |
+ |
+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(); |
Peter Kasting
2011/02/16 00:50:35
Why is this necessary when it's not necessary in t
varunjain
2011/02/16 18:48:10
Layout happens in the base class implicitly becaus
Peter Kasting
2011/02/16 21:50:22
Then you're not doing things correctly in the Touc
varunjain
2011/02/16 23:12:37
Not quiet. The touch popup never changes size (unl
|
+} |
+ |
+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) { |
+ 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; |
+ 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); |
+ if (max_child_height < child_height) |
Peter Kasting
2011/02/16 00:50:35
Nit: How about just:
max_child_height = std::max(
varunjain
2011/02/16 18:48:10
Done.
|
+ max_child_height = child_height; |
+ } |
+ } |
+} |
+ |
+//////////////////////////////////////////////////////////////////////////////// |
+// TouchAutocompletePopupContentsView protected. |
+ |
+int TouchAutocompletePopupContentsView::CalculatePopupHeight() { |
+ int popup_height = 0; |
+ int result_size = model()->result().size(); |
Peter Kasting
2011/02/16 00:50:35
You'll want to update this function to look like t
varunjain
2011/02/16 18:48:10
Done.
|
+ for (int i = 0; i < result_size && i < child_count(); ++i) { |
+ AutocompleteResultView* result_view = |
+ static_cast<AutocompleteResultView*>(GetChildViewAt(i)); |
+ int child_height = result_view->GetPreferredSize().height(); |
+ if (popup_height < child_height) |
+ popup_height = child_height; |
+ } |
+ if (opt_in_view() && |
+ popup_height < opt_in_view()->GetPreferredSize().height()) |
+ popup_height = opt_in_view()->GetPreferredSize().height(); |
+ return popup_height; |
+} |
+ |
+AutocompleteResultView* TouchAutocompletePopupContentsView::CreateResultView( |
Peter Kasting
2011/02/16 00:50:35
So, how come we use a factory function in this cas
varunjain
2011/02/16 18:48:10
we cannot use a factory function in AutocompleteEd
oshima
2011/02/16 20:00:27
At some point, we need to merge touch and chromeos
varunjain
2011/02/16 23:12:37
Done.
|
+ AutocompleteResultViewModel* model, |
+ int model_index, |
+ const gfx::Font& font, |
+ const gfx::Font& bold_font) { |
+ return new TouchAutocompleteResultView(model, model_index, font, bold_font); |
+} |
+ |
+//////////////////////////////////////////////////////////////////////////////// |
+// TouchAutocompletePopupContentsView private. |
+ |
+int TouchAutocompletePopupContentsView::GetVisibleChildCount() { |
+ int visible_child_count = 0; |
+ for (int i = 0; i < child_count(); ++i) |
+ if (GetChildViewAt(i)->IsVisible()) |
+ visible_child_count++; |
+ if (visible_child_count > kMaxResultViews) |
Peter Kasting
2011/02/16 00:50:35
Whoah there. You don't want to be clamping the vi
varunjain
2011/02/16 18:48:10
yes... I realized that clamping here doesnot work
Peter Kasting
2011/02/16 21:50:22
No, you don't. In both cases, you can simply keep
varunjain
2011/02/16 23:12:37
Sry... I am really not getting this :(
as the widt
|
+ visible_child_count = kMaxResultViews; |
+ return visible_child_count; |
+} |