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

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

Issue 10384007: First stab at touch optimized omnibox auto-complete per sgabriel's mocks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments. Created 8 years, 7 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
index f5f3865147b5e22e077a862de3482697183325f8..d7aad3e7c6604e4bc2ae4fae210e59a3580cc5db 100644
--- a/chrome/browser/ui/views/autocomplete/touch_autocomplete_popup_contents_view.cc
+++ b/chrome/browser/ui/views/autocomplete/touch_autocomplete_popup_contents_view.cc
@@ -13,6 +13,40 @@
#include "ui/gfx/size.h"
#include "ui/views/view.h"
+namespace {
+
+SkColor GetDividerLineColor(bool top) {
+ bool initialized = false;
+ static SkColor top_color;
+ static SkColor bottom_color;
+ if (!initialized) {
+#if defined(OS_WIN)
+ top_color = color_utils::GetSysSkColor(COLOR_3DDKSHADOW);
Peter Kasting 2012/05/07 21:03:12 Make sure that the colors you choose are guarantee
Jói 2012/05/10 18:33:07 Done.
Jói 2012/05/10 18:33:07 Done.
+ bottom_color = color_utils::GetSysSkColor(COLOR_3DLIGHT);
+#elif defined(USE_AURA)
+ const gfx::NativeTheme* theme = gfx::NativeTheme::instance();
+ top_color = theme->GetSystemColor(gfx::NativeTheme::kColorId_ThreeDShadow);
+ bottom_color = theme->GetSystemColor(
+ gfx::NativeTheme::kColorId_ThreeDLightShadow);
+#else
+ top_color = SkColorSetRGB(0xe3, 0xe3, 0xe3);
+ bottom_color = SkColorSetRGB(0xfe, 0xfe, 0xfe);
+#endif
+ initialized = true;
+ }
+}
+
+SkColor GetDividerLineBottomColor {
+}
+
+// Colors for a light-gray 3D-looking divider made up of two lines.
Peter Kasting 2012/05/07 21:03:12 Nit: This can be removed
Jói 2012/05/10 18:33:07 Done.
+const SkColor kDividerLineTopColor =
+ SkColorSetARGBMacro(0xff, 0xe3, 0xe3, 0xe3);
+const SkColor kDividerLineBottomColor =
+ SkColorSetARGBMacro(0xff, 0xfe, 0xfe, 0xfe);
+
+} // namespace
+
// TouchAutocompleteResultView ------------------------------------------------
@@ -22,6 +56,9 @@ TouchAutocompleteResultView::TouchAutocompleteResultView(
const gfx::Font& font,
const gfx::Font& bold_font)
: AutocompleteResultView(model, model_index, font, bold_font) {
+ set_edge_item_padding(9);
+ set_item_padding_(9);
+ set_minimum_text_vertical_padding(10);
}
TouchAutocompleteResultView::~TouchAutocompleteResultView() {
@@ -30,24 +67,39 @@ TouchAutocompleteResultView::~TouchAutocompleteResultView() {
void TouchAutocompleteResultView::PaintMatch(gfx::Canvas* canvas,
const AutocompleteMatch& match,
int x) {
- DrawString(canvas, match.contents, match.contents_class, false, x,
- text_bounds().y());
+ int y = text_bounds().y();
if (!match.description.empty()) {
// We use our base class's GetTextHeight below because we need the height
// of a single line of text.
- DrawString(canvas, match.description, match.description_class, true, x,
- text_bounds().y() + AutocompleteResultView::GetTextHeight());
+ DrawString(canvas, match.description, match.description_class, true, x, y);
+ y += AutocompleteResultView::GetTextHeight();
+ } else {
+ // When we have only one line of content (no description), we center the
+ // single line vertically on our two-lines-tall results box.
+ y += AutocompleteResultView::GetTextHeight() / 2;
}
+
+ DrawString(canvas, match.contents, match.contents_class, false, x, y);
}
int TouchAutocompleteResultView::GetTextHeight() const {
- // In the touch version of the 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 twice the height of one line.
return AutocompleteResultView::GetTextHeight() * 2;
}
+void TouchAutocompleteResultView::AdjustIconBounds(
+ const AutocompleteMatch& match, gfx::Rect* bounds) {
+ // We show the icon centered on the first line of content, so we
Peter Kasting 2012/05/07 21:03:12 Nit: We show -> we want to show
+ // need to adjust the bounds when there are two lines. The default
+ // layout in the base class is to center on the whole results view,
+ // which places th eicon correctly when there are two lines.
Peter Kasting 2012/05/07 21:03:12 Nit: th eicon -> the icon; are two lines -> is one
+ if (!match.description.empty()) {
+ bounds->set_y(
+ (AutocompleteResultView::GetTextHeight() - bounds->height()) / 2 +
+ minimum_text_vertical_padding_);
+ }
+}
+
// TouchAutocompletePopupContentsView -----------------------------------------
@@ -68,19 +120,6 @@ void TouchAutocompletePopupContentsView::UpdatePopupAppearance() {
Layout();
}
-void TouchAutocompletePopupContentsView::LayoutChildren() {
- std::vector<View*> visible_children(GetVisibleChildren());
- gfx::Rect bounds(GetContentsBounds());
- double child_width =
- static_cast<double>(bounds.width()) / visible_children.size();
- int x = bounds.x();
- for (size_t i = 0; i < visible_children.size(); ++i) {
- int next_x = bounds.x() + static_cast<int>(((i + 1) * child_width) + 0.5);
- visible_children[i]->SetBounds(x, bounds.y(), next_x - x, bounds.height());
- x = next_x;
- }
-}
-
void TouchAutocompletePopupContentsView::PaintResultViews(gfx::Canvas* canvas) {
AutocompletePopupContentsView::PaintResultViews(canvas);
@@ -88,24 +127,22 @@ void TouchAutocompletePopupContentsView::PaintResultViews(gfx::Canvas* canvas) {
std::vector<View*> visible_children(GetVisibleChildren());
if (visible_children.size() < 2)
return;
- SkColor color = AutocompleteResultView::GetColor(
- AutocompleteResultView::NORMAL, AutocompleteResultView::DIMMED_TEXT);
gfx::Rect bounds(GetContentsBounds());
for (std::vector<View*>::const_iterator i(visible_children.begin() + 1);
Peter Kasting 2012/05/07 21:03:12 Nit: I think it would be slightly better to iterat
i != visible_children.end(); ++i) {
- canvas->DrawLine(gfx::Point((*i)->x(), bounds.y()),
- gfx::Point((*i)->x(), bounds.bottom()), color);
- }
-}
-
-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,
- child_at(i)->GetPreferredSize().height());
+ TouchAutocompleteResultView* child =
+ static_cast<TouchAutocompleteResultView*>(*i);
+ canvas->DrawLine(
+ gfx::Point(bounds.x(), child->y() - 1),
+ gfx::Point(bounds.right(), child->y() - 1),
+ kDividerLineTopColor);
+ if (child->GetState() == AutocompleteResultView::NORMAL) {
+ canvas->DrawLine(
+ gfx::Point(bounds.x(), child->y()),
+ gfx::Point(bounds.right(), child->y()),
+ kDividerLineBottomColor);
+ }
}
- return popup_height;
}
AutocompleteResultView* TouchAutocompletePopupContentsView::CreateResultView(

Powered by Google App Engine
This is Rietveld 408576698