Chromium Code Reviews| Index: chrome/browser/ui/views/autocomplete/autocomplete_result_view.cc |
| =================================================================== |
| --- chrome/browser/ui/views/autocomplete/autocomplete_result_view.cc (revision 108642) |
| +++ chrome/browser/ui/views/autocomplete/autocomplete_result_view.cc (working copy) |
| @@ -14,6 +14,7 @@ |
| #include <algorithm> // NOLINT |
| #include "base/i18n/bidi_line_iterator.h" |
| +#include "chrome/browser/autocomplete/autocomplete_popup_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" |
| @@ -116,13 +117,16 @@ |
| normal_font_(font), |
| bold_font_(bold_font), |
| ellipsis_width_(font.GetStringWidth(string16(kEllipsis))), |
| - mirroring_context_(new MirroringContext()) { |
| + mirroring_context_(new MirroringContext()), |
| + ALLOW_THIS_IN_INITIALIZER_LIST(animation_(new ui::SlideAnimation(this))) { |
| CHECK_GE(model_index, 0); |
| if (default_icon_size_ == 0) { |
| default_icon_size_ = ResourceBundle::GetSharedInstance().GetBitmapNamed( |
| AutocompleteMatch::TypeToIcon(AutocompleteMatch::URL_WHAT_YOU_TYPED))-> |
| width(); |
| } |
| + |
| + animation_->SetDuration(500); |
| } |
| AutocompleteResultView::~AutocompleteResultView() { |
| @@ -178,9 +182,44 @@ |
| void AutocompleteResultView::SetMatch(const AutocompleteMatch& match) { |
| match_ = match; |
| + animation_->Reset(); |
| + |
| + if (!match.associated_keyword.get() && keyword_button_.get()) { |
| + RemoveChildView(keyword_button_.get()); |
| + keyword_button_.reset(NULL); |
| + } else if (match.associated_keyword.get() && !keyword_button_.get()) { |
| + ResourceBundle& resources = ResourceBundle::GetSharedInstance(); |
| + keyword_button_.reset(new views::ImageButton(this)); |
|
Peter Kasting
2011/12/15 22:56:04
After talking with Glen some more we agreed that i
|
| + keyword_button_->set_id(VIEW_ID_KEYWORD); |
| + keyword_button_->SetTooltipText(match_.associated_keyword->description); |
| + keyword_button_->SetImage(views::CustomButton::BS_NORMAL, |
| + resources.GetBitmapNamed(IDR_OMNIBOX_KEYWORD_SEARCH)); |
| + keyword_button_->SetImage(views::CustomButton::BS_HOT, |
| + resources.GetBitmapNamed(IDR_OMNIBOX_KEYWORD_SEARCH_H)); |
| + keyword_button_->SetImage(views::CustomButton::BS_PUSHED, |
| + resources.GetBitmapNamed(IDR_OMNIBOX_KEYWORD_SEARCH_P)); |
| + AddChildView(keyword_button_.get()); |
| + } |
| + |
| Layout(); |
| } |
| +void AutocompleteResultView::ShowKeyword(bool show_keyword) { |
| + if (show_keyword) { |
| + keyword_button_->SetTooltipText(match_.description); |
| + animation_->Show(); |
| + } else { |
| + keyword_button_->SetTooltipText(match_.associated_keyword->description); |
| + animation_->Hide(); |
| + } |
| +} |
| + |
| +gfx::Size AutocompleteResultView::GetPreferredSize() { |
| + return gfx::Size(0, std::max( |
| + default_icon_size_ + (kMinimumIconVerticalPadding * 2), |
| + GetTextHeight() + (kMinimumTextVerticalPadding * 2))); |
| +} |
| + |
| //////////////////////////////////////////////////////////////////////////////// |
| // AutocompleteResultView, protected: |
| @@ -498,12 +537,6 @@ |
| runs->clear(); |
| } |
| -gfx::Size AutocompleteResultView::GetPreferredSize() { |
| - return gfx::Size(0, std::max( |
| - default_icon_size_ + (kMinimumIconVerticalPadding * 2), |
| - GetTextHeight() + (kMinimumTextVerticalPadding * 2))); |
| -} |
| - |
| void AutocompleteResultView::Layout() { |
| const SkBitmap* icon = GetIcon(); |
| icon_bounds_.SetRect(LocationBarView::kEdgeItemPadding + |
| @@ -514,9 +547,31 @@ |
| int text_x = LocationBarView::kEdgeItemPadding + default_icon_size_ + |
| LocationBarView::kItemPadding; |
| int text_height = GetTextHeight(); |
| + int text_width; |
| + |
| + if (match_.associated_keyword.get()) { |
| + gfx::Size kw_icon_size = keyword_button_->GetPreferredSize(); |
| + const int kw_collapsed_size = kw_icon_size.width() + |
| + LocationBarView::kEdgeItemPadding; |
| + const int max_kw_x = bounds().width() - kw_collapsed_size; |
| + const int kw_x = animation_->CurrentValueBetween(max_kw_x, |
| + LocationBarView::kEdgeItemPadding); |
| + const int kw_text_x = kw_x + kw_icon_size.width() + |
| + LocationBarView::kItemPadding; |
| + |
| + text_width = kw_x - text_x - LocationBarView::kItemPadding; |
| + keyword_text_bounds_.SetRect(kw_text_x, 0, std::max( |
| + bounds().width() - kw_text_x - LocationBarView::kEdgeItemPadding, 0), |
| + text_height); |
| + keyword_button_->SetBounds(GetMirroredXInView(kw_x), |
| + (height() - kw_icon_size.height()) / 2, |
| + kw_icon_size.width(), kw_icon_size.height()); |
| + } else { |
| + text_width = bounds().width() - text_x - LocationBarView::kEdgeItemPadding; |
| + } |
| + |
| text_bounds_.SetRect(text_x, std::max(0, (height() - text_height) / 2), |
| - std::max(bounds().width() - text_x - LocationBarView::kEdgeItemPadding, |
| - 0), text_height); |
| + std::max(text_width, 0), text_height); |
| } |
| void AutocompleteResultView::OnPaint(gfx::Canvas* canvas) { |
| @@ -524,12 +579,39 @@ |
| if (state != NORMAL) |
| canvas->GetSkCanvas()->drawColor(GetColor(state, BACKGROUND)); |
| - // Paint the icon. |
| - canvas->DrawBitmapInt(*GetIcon(), GetMirroredXForRect(icon_bounds_), |
| - icon_bounds_.y()); |
| + if (!keyword_button_.get() || keyword_button_->x() > icon_bounds_.right()) { |
| + // Paint the icon. |
| + canvas->DrawBitmapInt(*GetIcon(), GetMirroredXForRect(icon_bounds_), |
| + icon_bounds_.y()); |
| - // Paint the text. |
| - int x = GetMirroredXForRect(text_bounds_); |
| - mirroring_context_->Initialize(x, text_bounds_.width()); |
| - PaintMatch(canvas, match_, x); |
| + // Paint the text. |
| + int x = GetMirroredXForRect(text_bounds_); |
| + mirroring_context_->Initialize(x, text_bounds_.width()); |
| + PaintMatch(canvas, match_, x); |
| + } |
| + |
| + // Paint the keyword text |
| + if (match_.associated_keyword.get()) { |
| + int x = GetMirroredXForRect(keyword_text_bounds_); |
| + mirroring_context_->Initialize(x, keyword_text_bounds_.width()); |
| + PaintMatch(canvas, *match_.associated_keyword.get(), x); |
| + } |
| } |
| + |
| +void AutocompleteResultView::AnimationProgressed( |
| + const ui::Animation* animation) { |
| + Layout(); |
| + SchedulePaint(); |
| +} |
| + |
| +void AutocompleteResultView::ButtonPressed(views::Button* sender, |
| + const views::Event& event) { |
| + popup_model_->SetSelectedLine(model_index_, false, false); |
| + |
| + if (popup_model_->selected_line_state() == AutocompletePopupModel::NORMAL) |
| + popup_model_->edit_model()->AcceptKeyword(); |
| + else |
| + popup_model_->edit_model()->ClearKeyword( |
|
Peter Kasting
2011/12/15 22:56:04
Nit: If one arm of a conditional spans more than o
|
| + popup_model_->edit_model()->view()->GetText()); |
| +} |
| + |