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 108642) |
| +++ 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) |
| @@ -231,6 +232,14 @@ |
| 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); |
| + result_view->set_popup_model(model_.get()); |
| + AddChildViewAt(result_view, static_cast<int>(i)); |
| + } |
| } |
| AutocompletePopupContentsView::~AutocompletePopupContentsView() { |
| @@ -262,7 +271,7 @@ |
| View* v = child_at(i); |
| if (v->IsVisible()) { |
| v->SetBounds(contents_rect.x(), top, contents_rect.width(), |
| - v->GetPreferredSize().height()); |
|
Peter Kasting
2011/12/15 22:56:04
Nit: This indentation was fine.
|
| + v->GetPreferredSize().height()); |
| top = v->bounds().bottom(); |
| } |
| } |
| @@ -276,7 +285,13 @@ |
| } |
| 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->SchedulePaint(); |
| + |
| + if (HasMatchAt(line) && GetMatchAtIndex(line).associated_keyword.get()) |
| + result->ShowKeyword( |
| + model_->selected_line_state() == AutocompletePopupModel::KEYWORD); |
| } |
| void AutocompletePopupContentsView::UpdatePopupAppearance() { |
| @@ -284,6 +299,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 |
| @@ -301,19 +317,15 @@ |
| 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) { |
| + const AutocompleteMatch& match = GetMatchAtIndex(i); |
| + AutocompleteResultView* view = static_cast<AutocompleteResultView*>( |
| + child_at(i)); |
| + view->SetMatch(match); |
| + 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(); |
| @@ -385,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( |
| @@ -425,12 +437,16 @@ |
| views::View* AutocompletePopupContentsView::GetEventHandlerForPoint( |
| const gfx::Point& point) { |
| - // 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_) |
| + views::View* child = views::View::GetEventHandlerForPoint(point); |
| + |
| + // If there is no opt in view, and the mouse isn't over a keyword button, |
| + // then we want all mouse events. Otherwise let any descendants of the |
| + // opt-in view get mouse events. |
| + if (child->id() == AutocompleteResultView::VIEW_ID_KEYWORD) |
| + return child; |
| + else if (!opt_in_view_) |
|
Peter Kasting
2011/12/15 22:56:04
Nit: No else after return
|
| return this; |
| - views::View* child = views::View::GetEventHandlerForPoint(point); |
| views::View* ancestor = child; |
| while (ancestor && ancestor != opt_in_view_) |
| ancestor = ancestor->parent(); |
| @@ -636,10 +652,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( |