Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7315)

Unified Diff: chrome/browser/ui/views/autocomplete/touch_autocomplete_popup_contents_view.cc

Issue 6349101: Create a new autocomplete popup for touch. This CL depends on (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: minor changes Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..25d2d77d969de380a6d4e627d066bd6c3f39ddc7
--- /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 ------------------------------------------------
+
+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);
+ }
+}
+
+const int TouchAutocompleteResultView::GetFontHeight() {
oshima 2011/02/16 23:51:19 I meant int TouchAutocompleteResultView::GetFontHe
varunjain 2011/02/17 00:29:51 I meant that too... I think I need more coffee :)
+ 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) {
+ 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;
+
+ 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);
+ }
+ }
+}
+
+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());
+ }
+ 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);
+}
+
+const int TouchAutocompletePopupContentsView::GetVisibleChildCount() {
oshima 2011/02/16 23:51:19 I meant int TouchAutocompletePopupContentsView::G
varunjain 2011/02/17 00:29:51 Done.
+ int visible_child_count = 0;
+ for (int i = 0; i < child_count(); ++i) {
+ if (GetChildViewAt(i)->IsVisible())
+ visible_child_count++;
+ }
+ return visible_child_count;
+}

Powered by Google App Engine
This is Rietveld 408576698