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

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

Issue 6731036: Enabled pressing TAB to cycle through the Omnibox results. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 9 years, 8 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/autocomplete_result_view.cc
===================================================================
--- chrome/browser/ui/views/autocomplete/autocomplete_result_view.cc (revision 80868)
+++ chrome/browser/ui/views/autocomplete/autocomplete_result_view.cc (working copy)
@@ -14,6 +14,9 @@
#include <algorithm> // NOLINT
#include "base/i18n/bidi_line_iterator.h"
+#include "chrome/browser/extensions/extension_service.h"
+#include "chrome/browser/search_engines/template_url.h"
+#include "chrome/browser/search_engines/template_url_model.h"
#include "chrome/browser/ui/views/autocomplete/autocomplete_result_view_model.h"
#include "chrome/browser/ui/views/location_bar/location_bar_view.h"
#include "grit/generated_resources.h"
@@ -23,6 +26,8 @@
#include "ui/base/text/text_elider.h"
#include "ui/gfx/canvas_skia.h"
#include "ui/gfx/color_utils.h"
+#include "views/controls/image_view.h"
+#include "views/controls/label.h"
#if defined(OS_LINUX)
#include "chrome/browser/ui/gtk/gtk_util.h"
@@ -106,6 +111,101 @@
DISALLOW_COPY_AND_ASSIGN(MirroringContext);
};
+class AutocompleteResultView::IconLabelView : public views::View {
+ public:
+ explicit IconLabelView(gfx::Font font);
+
+ virtual void Layout();
+ virtual gfx::Size GetPreferredSize();
+ virtual void OnPaint(gfx::Canvas* canvas);
+
+ void SetLabelColor(SkColor color);
+ void SetLabelText(const string16& text);
+ void SetSelected(bool flag);
+
+ private:
+ views::ImageView* image_;
+ views::Label* label_;
+ bool selected_;
+
+ DISALLOW_COPY_AND_ASSIGN(IconLabelView);
+};
+
+AutocompleteResultView::IconLabelView::IconLabelView(gfx::Font font)
+ : selected_(false) {
+ image_ = new views::ImageView();
+ AddChildView(image_);
+ image_->SetImage(
+ ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_OMNIBOX_SEARCH));
+ label_ = new views::Label();
+ AddChildView(label_);
+ label_->SetFont(font);
+ label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
+}
+
+void AutocompleteResultView::IconLabelView::Layout() {
+ const int icon_width = image_->GetPreferredSize().width();
+ image_->SetBounds(LocationBarView::kItemPadding * 2,
+ (height() - icon_width) / 2, icon_width, icon_width);
+ const int label_padding = icon_width + LocationBarView::kItemPadding * 3;
+ const int label_height = label_->GetPreferredSize().height();
+ label_->SetBounds(label_padding, (height() - label_height) / 2, width() -
+ label_padding, label_height);
+}
+
+gfx::Size AutocompleteResultView::IconLabelView::GetPreferredSize() {
+ gfx::Size size(image_->GetPreferredSize());
+ size.Enlarge(label_->GetPreferredSize().width() +
+ LocationBarView::kExtensionItemPadding +
+ LocationBarView::kItemPadding * 3, 0);
+ return size;
+}
+
+void AutocompleteResultView::IconLabelView::OnPaint(gfx::Canvas* canvas) {
+ if (selected_) {
+ canvas->Save();
+ canvas->ClipRectInt(LocationBarView::kItemPadding, 0, width() -
+ LocationBarView::kItemPadding, height());
+ canvas->AsCanvasSkia()->drawColor(GetColor(SELECTED, BACKGROUND));
+ canvas->Restore();
+ } else {
+ canvas->AsCanvasSkia()->drawColor(GetColor(NORMAL, BACKGROUND));
+ }
+
+ SkPaint paint;
+ paint.setColor(GetColor(NORMAL, DIMMED_TEXT));
+ paint.setStrokeWidth(SkIntToScalar(1));
+ paint.setAntiAlias(true);
+
+ canvas->AsCanvasSkia()->drawLine(
+ SkIntToScalar(LocationBarView::kVerticalEdgeThickness),
+ SkIntToScalar(LocationBarView::kNormalHorizontalEdgeThickness),
+ SkIntToScalar(LocationBarView::kVerticalEdgeThickness),
+ SkIntToScalar(height() -
+ LocationBarView::kNormalHorizontalEdgeThickness * 2), paint);
+}
+
+void AutocompleteResultView::IconLabelView::SetLabelColor(SkColor color) {
+ label_->SetColor(color);
+}
+
+void AutocompleteResultView::IconLabelView::SetLabelText(const string16& text) {
+ label_->SetText(UTF16ToWide(text));
+}
+
+void AutocompleteResultView::IconLabelView::SetSelected(bool flag) {
+ selected_ = flag;
+
+ if (selected_)
+ image_->SetImage(ResourceBundle::GetSharedInstance().
+ GetBitmapNamed(IDR_OMNIBOX_SEARCH_SELECTED));
+ else
+ image_->SetImage(ResourceBundle::GetSharedInstance().
+ GetBitmapNamed(IDR_OMNIBOX_SEARCH));
+
+ SchedulePaint();
+}
+
AutocompleteResultView::AutocompleteResultView(
AutocompleteResultViewModel* model,
int model_index,
@@ -119,13 +219,20 @@
bold_font_(bold_font),
ellipsis_width_(font.GetStringWidth(string16(kEllipsis))),
mirroring_context_(new MirroringContext()),
- match_(NULL, 0, false, AutocompleteMatch::URL_WHAT_YOU_TYPED) {
+ match_(NULL, 0, false, AutocompleteMatch::URL_WHAT_YOU_TYPED),
+ search_view_(new IconLabelView(font)),
+ search_expanded_(false),
+ ALLOW_THIS_IN_INITIALIZER_LIST(animation_(new ui::SlideAnimation(this))) {
CHECK_GE(model_index, 0);
if (icon_size_ == 0) {
icon_size_ = ResourceBundle::GetSharedInstance().GetBitmapNamed(
AutocompleteMatch::TypeToIcon(AutocompleteMatch::URL_WHAT_YOU_TYPED))->
width();
}
+
+ animation_->SetSlideDuration(500);
+
+ AddChildView(search_view_.get());
}
AutocompleteResultView::~AutocompleteResultView() {
@@ -133,7 +240,7 @@
void AutocompleteResultView::OnPaint(gfx::Canvas* canvas) {
const ResultViewState state = GetState();
- if (state != NORMAL)
+ if (state != NORMAL && !search_expanded_)
canvas->AsCanvasSkia()->drawColor(GetColor(state, BACKGROUND));
// Paint the icon.
@@ -149,11 +256,29 @@
void AutocompleteResultView::Layout() {
icon_bounds_.SetRect(LocationBarView::kEdgeItemPadding,
(height() - icon_size_) / 2, icon_size_, icon_size_);
- int text_x = icon_bounds_.right() + LocationBarView::kItemPadding;
- int font_height = std::max(normal_font_.GetHeight(), bold_font_.GetHeight());
- text_bounds_.SetRect(text_x, std::max(0, (height() - font_height) / 2),
- std::max(bounds().width() - text_x - LocationBarView::kEdgeItemPadding,
- 0), font_height);
+ const int text_x = icon_bounds_.right() + LocationBarView::kItemPadding;
+ const int font_height = std::max(normal_font_.GetHeight(),
+ bold_font_.GetHeight());
+ const int text_y = std::max(0, (height() - font_height) / 2);
+
+ if (keyword_.get() && keyword_->is_keyword_hint) {
+ gfx::Size search_size = search_view_->GetPreferredSize();
+ const float expanded_x = static_cast<float>(text_x +
+ normal_font_.GetStringWidth(UTF8ToUTF16(ui::kEllipsis)) +
+ LocationBarView::kItemPadding);
+ const float collapsed_x = static_cast<float>(bounds().width() -
+ search_size.width());
+ const int search_x = static_cast<int>(collapsed_x - ((collapsed_x -
+ expanded_x) * animation_->GetCurrentValue()));
+
+ text_bounds_.SetRect(text_x, text_y, std::max(search_x - text_x, 0),
+ font_height);
+ search_view_->SetBounds(search_x, 0, std::max(bounds().width() -
+ search_x, 0), height());
+ } else {
+ text_bounds_.SetRect(text_x, text_y,
+ std::max(bounds().width() - text_x, 0), font_height);
+ }
}
gfx::Size AutocompleteResultView::GetPreferredSize() {
@@ -269,7 +394,7 @@
int icon = match_.starred ?
IDR_OMNIBOX_STAR : AutocompleteMatch::TypeToIcon(match_.type);
- if (model_->IsSelectedIndex(model_index_)) {
+ if (model_->IsSelectedIndex(model_index_) && !search_expanded_) {
switch (icon) {
case IDR_OMNIBOX_HTTP: icon = IDR_OMNIBOX_HTTP_SELECTED; break;
case IDR_OMNIBOX_HISTORY: icon = IDR_OMNIBOX_HISTORY_SELECTED; break;
@@ -354,7 +479,7 @@
const int style = classifications[i].style;
const bool use_bold_font = !!(style & ACMatchClassification::MATCH);
current_data->font = &(use_bold_font ? bold_font_ : normal_font_);
- const ResultViewState state = GetState();
+ const ResultViewState state = search_expanded_ ? NORMAL : GetState();
if (style & ACMatchClassification::URL)
current_data->color = GetColor(state, URL);
else if (style & ACMatchClassification::DIM)
@@ -510,3 +635,57 @@
// We couldn't draw anything.
runs->clear();
}
+
+void AutocompleteResultView::SetMatch(const AutocompleteMatch& match) {
+ const bool same_match = match.destination_url == match_.destination_url;
+ match_ = match;
+ keyword_ = match.keyword;
+
+ const bool keyword_mode = keyword_.get() && keyword_->is_keyword_hint &&
+ keyword_->is_keyword_mode;
+
+ if (keyword_mode && !search_expanded_)
+ animation_->Show();
+ else if (same_match && !keyword_mode && search_expanded_)
+ animation_->Hide();
+ else if (!same_match || (same_match && !animation_->is_animating())) {
Peter Kasting 2011/04/11 23:17:33 Nit: All arms of a conditional need {} if one has
+ animation_->Stop();
+ animation_->Reset();
+ }
+
+ search_expanded_ = keyword_mode;
+ search_view_->SetSelected(search_expanded_);
+ search_view_->SetVisible(keyword_.get() && keyword_->is_keyword_hint);
+
+ if (search_expanded_) {
+ int message_id = keyword_->template_url->IsExtensionKeyword() ?
+ IDS_EXTENSION_KEYWORD_COMMAND : IDS_KEYWORD_SEARCH;
+ string16 text = l10n_util::GetStringFUTF16(message_id,
+ keyword_->text, l10n_util::GetStringUTF16(IDS_EMPTY_KEYWORD_VALUE));
+ text.append(
+ l10n_util::GetStringUTF16(
+ IDS_AUTOCOMPLETE_MATCH_DESCRIPTION_SEPARATOR));
+ text.append(
+ l10n_util::GetStringFUTF16(IDS_AUTOCOMPLETE_KEYWORD_DESCRIPTION,
+ keyword_->text));
+ search_view_->SetLabelText(text);
+ search_view_->SetLabelColor(GetColor(SELECTED, DIMMED_TEXT));
+ } else {
+ search_view_->SetLabelText(UTF8ToUTF16(ui::kEllipsis));
+ search_view_->SetLabelColor(GetColor(NORMAL, DIMMED_TEXT));
+ }
+ Layout();
+}
+
+void AutocompleteResultView::AnimationProgressed(
+ const ui::Animation* animation) {
+ Layout();
+ SchedulePaint();
+}
+
+void AutocompleteResultView::AnimationCanceled(
+ const ui::Animation* animation) {
+ Layout();
+ SchedulePaint();
+}
+

Powered by Google App Engine
This is Rietveld 408576698