Chromium Code Reviews| Index: chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.cc |
| =================================================================== |
| --- chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.cc (revision 117356) |
| +++ chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.cc (working copy) |
| @@ -49,6 +49,7 @@ |
| const SkAlpha kGlassPopupAlpha = 240; |
| const SkAlpha kOpaquePopupAlpha = 255; |
| + |
| // The size delta between the font used for the edit and the result rows. Passed |
| // to gfx::Font::DeriveFont. |
| #if defined(OS_CHROMEOS) |
| @@ -232,6 +233,13 @@ |
| set_border(bubble_border); |
| // The contents is owned by the LocationBarView. |
| set_parent_owned(false); |
| + |
| + for (size_t i = 0; i < AutocompleteResult::kMaxMatches; ++i) { |
| + AutocompleteResultView* result_view = |
| + CreateResultView(this, i, result_font_, result_bold_font_); |
| + result_view->SetVisible(false); |
| + AddChildViewAt(result_view, static_cast<int>(i)); |
| + } |
| } |
| AutocompletePopupContentsView::~AutocompletePopupContentsView() { |
| @@ -277,7 +285,14 @@ |
| } |
| void AutocompletePopupContentsView::InvalidateLine(size_t line) { |
| - child_at(static_cast<int>(line))->SchedulePaint(); |
| + AutocompleteResultView* result = static_cast<AutocompleteResultView*>( |
| + child_at(static_cast<int>(line))); |
| + result->Invalidate(); |
| + |
| + if (HasMatchAt(line) && GetMatchAtIndex(line).associated_keyword.get()) { |
| + result->ShowKeyword( |
| + model_->selected_line_state() == AutocompletePopupModel::KEYWORD); |
|
Peter Kasting
2012/01/12 22:59:59
Don't we need to add "IsSelectedIndex(line) &&" in
aaron.randolph
2012/01/13 03:08:07
Yes, it's a bug, but not for any line. To flip sta
|
| + } |
| } |
| void AutocompletePopupContentsView::UpdatePopupAppearance() { |
| @@ -285,6 +300,7 @@ |
| // No matches, close any existing popup. |
| if (popup_ != NULL) { |
| size_animation_.Stop(); |
| + |
| // NOTE: Do NOT use CloseNow() here, as we may be deep in a callstack |
| // triggered by the popup receiving a message (e.g. LBUTTONUP), and |
| // destroying the popup would cause us to read garbage when we unwind back |
| @@ -302,19 +318,14 @@ |
| DCHECK_GT(child_rv_count, 0u); |
| child_rv_count--; |
| } |
| - for (size_t i = 0; i < model_->result().size(); ++i) { |
| - AutocompleteResultView* result_view; |
| - if (i >= child_rv_count) { |
| - result_view = |
| - CreateResultView(this, i, result_font_, result_bold_font_); |
| - AddChildViewAt(result_view, static_cast<int>(i)); |
| - } else { |
| - result_view = static_cast<AutocompleteResultView*>(child_at(i)); |
| - result_view->SetVisible(true); |
| - } |
| - result_view->SetMatch(GetMatchAtIndex(i)); |
| + const size_t result_size = model_->result().size(); |
| + for (size_t i = 0; i < result_size; ++i) { |
| + AutocompleteResultView* view = static_cast<AutocompleteResultView*>( |
| + child_at(i)); |
| + view->SetMatch(GetMatchAtIndex(i)); |
| + view->SetVisible(true); |
| } |
| - for (size_t i = model_->result().size(); i < child_rv_count; ++i) |
| + for (size_t i = result_size; i < child_rv_count; ++i) |
| child_at(i)->SetVisible(false); |
| PromoCounter* counter = profile_->GetInstantPromoCounter(); |
| @@ -386,11 +397,11 @@ |
| // AutocompletePopupContentsView, AutocompleteResultViewModel implementation: |
| bool AutocompletePopupContentsView::IsSelectedIndex(size_t index) const { |
| - return HasMatchAt(index) ? index == model_->selected_line() : false; |
| + return index == model_->selected_line(); |
| } |
| bool AutocompletePopupContentsView::IsHoveredIndex(size_t index) const { |
| - return HasMatchAt(index) ? index == model_->hovered_line() : false; |
| + return index == model_->hovered_line(); |
| } |
| const SkBitmap* AutocompletePopupContentsView::GetIconIfExtensionMatch( |
| @@ -426,7 +437,7 @@ |
| views::View* AutocompletePopupContentsView::GetEventHandlerForPoint( |
| const gfx::Point& point) { |
| - // If there is no opt in view, then we want all mouse events. Otherwise let |
| + // If there is no opt in view then we want all mouse events. Otherwise, let |
| // any descendants of the opt-in view get mouse events. |
| if (!opt_in_view_) |
| return this; |
| @@ -637,10 +648,8 @@ |
| // extension, |match| and its contents. So copy the relevant match out to |
| // make sure it stays alive until the call completes. |
| AutocompleteMatch match = model_->result().match_at(index); |
| - string16 keyword; |
| - const bool is_keyword_hint = model_->GetKeywordForMatch(match, &keyword); |
| omnibox_view_->OpenMatch(match, disposition, GURL(), index, |
| - is_keyword_hint ? string16() : keyword); |
| + match.keyword); |
| } |
| size_t AutocompletePopupContentsView::GetIndexForPoint( |