Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view. h" | 5 #include "chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view. h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/autocomplete/autocomplete_edit_view.h" | 9 #include "chrome/browser/autocomplete/autocomplete_edit_view.h" |
| 10 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" | 10 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 259 } | 259 } |
| 260 | 260 |
| 261 //////////////////////////////////////////////////////////////////////////////// | 261 //////////////////////////////////////////////////////////////////////////////// |
| 262 // AutocompletePopupContentsView, AutocompletePopupView overrides: | 262 // AutocompletePopupContentsView, AutocompletePopupView overrides: |
| 263 | 263 |
| 264 bool AutocompletePopupContentsView::IsOpen() const { | 264 bool AutocompletePopupContentsView::IsOpen() const { |
| 265 return (popup_ != NULL); | 265 return (popup_ != NULL); |
| 266 } | 266 } |
| 267 | 267 |
| 268 void AutocompletePopupContentsView::InvalidateLine(size_t line) { | 268 void AutocompletePopupContentsView::InvalidateLine(size_t line) { |
| 269 GetChildViewAt(static_cast<int>(line))->SchedulePaint(); | 269 if (line < model_->result().size()) { |
| 270 AutocompleteResultView* result_view = | |
| 271 static_cast<AutocompleteResultView*>(GetChildViewAt( | |
| 272 static_cast<int>(line))); | |
| 273 | |
| 274 result_view->SetMatch(GetMatchAtIndex(line)); | |
| 275 result_view->SchedulePaint(); | |
| 276 } | |
| 270 } | 277 } |
| 271 | 278 |
| 272 void AutocompletePopupContentsView::UpdatePopupAppearance() { | 279 void AutocompletePopupContentsView::UpdatePopupAppearance() { |
| 273 if (model_->result().empty()) { | 280 if (model_->result().empty()) { |
| 274 // No matches, close any existing popup. | 281 // No matches, close any existing popup. |
| 275 if (popup_ != NULL) { | 282 if (popup_ != NULL) { |
| 276 size_animation_.Stop(); | 283 size_animation_.Stop(); |
| 277 // NOTE: Do NOT use CloseNow() here, as we may be deep in a callstack | 284 // NOTE: Do NOT use CloseNow() here, as we may be deep in a callstack |
| 278 // triggered by the popup receiving a message (e.g. LBUTTONUP), and | 285 // triggered by the popup receiving a message (e.g. LBUTTONUP), and |
| 279 // destroying the popup would cause us to read garbage when we unwind back | 286 // destroying the popup would cause us to read garbage when we unwind back |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 294 for (size_t i = 0; i < model_->result().size(); ++i) { | 301 for (size_t i = 0; i < model_->result().size(); ++i) { |
| 295 AutocompleteResultView* result_view; | 302 AutocompleteResultView* result_view; |
| 296 if (i >= child_rv_count) { | 303 if (i >= child_rv_count) { |
| 297 result_view = | 304 result_view = |
| 298 CreateResultView(this, i, result_font_, result_bold_font_); | 305 CreateResultView(this, i, result_font_, result_bold_font_); |
| 299 AddChildViewAt(result_view, static_cast<int>(i)); | 306 AddChildViewAt(result_view, static_cast<int>(i)); |
| 300 } else { | 307 } else { |
| 301 result_view = static_cast<AutocompleteResultView*>(GetChildViewAt(i)); | 308 result_view = static_cast<AutocompleteResultView*>(GetChildViewAt(i)); |
| 302 result_view->SetVisible(true); | 309 result_view->SetVisible(true); |
| 303 } | 310 } |
| 304 result_view->set_match(GetMatchAtIndex(i)); | 311 result_view->SetMatch(GetMatchAtIndex(i)); |
| 305 } | 312 } |
| 306 for (size_t i = model_->result().size(); i < child_rv_count; ++i) | 313 for (size_t i = model_->result().size(); i < child_rv_count; ++i) |
| 307 GetChildViewAt(i)->SetVisible(false); | 314 GetChildViewAt(i)->SetVisible(false); |
| 308 | 315 |
| 309 PromoCounter* counter = model_->profile()->GetInstantPromoCounter(); | 316 PromoCounter* counter = model_->profile()->GetInstantPromoCounter(); |
| 310 if (!opt_in_view_ && counter && counter->ShouldShow(base::Time::Now())) { | 317 if (!opt_in_view_ && counter && counter->ShouldShow(base::Time::Now())) { |
| 311 opt_in_view_ = new InstantOptInView(this, result_bold_font_, result_font_); | 318 opt_in_view_ = new InstantOptInView(this, result_bold_font_, result_font_); |
| 312 AddChildView(opt_in_view_); | 319 AddChildView(opt_in_view_); |
| 313 } else if (opt_in_view_ && (!counter || | 320 } else if (opt_in_view_ && (!counter || |
| 314 !counter->ShouldShow(base::Time::Now()))) { | 321 !counter->ShouldShow(base::Time::Now()))) { |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 616 void AutocompletePopupContentsView::OpenIndex( | 623 void AutocompletePopupContentsView::OpenIndex( |
| 617 size_t index, | 624 size_t index, |
| 618 WindowOpenDisposition disposition) { | 625 WindowOpenDisposition disposition) { |
| 619 if (!HasMatchAt(index)) | 626 if (!HasMatchAt(index)) |
| 620 return; | 627 return; |
| 621 | 628 |
| 622 const AutocompleteMatch& match = model_->result().match_at(index); | 629 const AutocompleteMatch& match = model_->result().match_at(index); |
| 623 // OpenURL() may close the popup, which will clear the result set and, by | 630 // OpenURL() may close the popup, which will clear the result set and, by |
| 624 // extension, |match| and its contents. So copy the relevant strings out to | 631 // extension, |match| and its contents. So copy the relevant strings out to |
| 625 // make sure they stay alive until the call completes. | 632 // make sure they stay alive until the call completes. |
| 633 string16 keyword; | |
| 634 if (match.has_keyword_hint()) | |
| 635 keyword.assign(match.keyword); | |
|
Peter Kasting
2011/04/13 21:06:59
Nit: Eliminate the temp and do this with a ?: insi
| |
| 636 | |
| 626 const GURL url(match.destination_url); | 637 const GURL url(match.destination_url); |
| 627 string16 keyword; | |
| 628 const bool is_keyword_hint = model_->GetKeywordForMatch(match, &keyword); | |
| 629 edit_view_->OpenURL(url, disposition, match.transition, GURL(), index, | 638 edit_view_->OpenURL(url, disposition, match.transition, GURL(), index, |
| 630 is_keyword_hint ? string16() : keyword); | 639 keyword); |
| 631 } | 640 } |
| 632 | 641 |
| 633 size_t AutocompletePopupContentsView::GetIndexForPoint( | 642 size_t AutocompletePopupContentsView::GetIndexForPoint( |
| 634 const gfx::Point& point) { | 643 const gfx::Point& point) { |
| 635 if (!HitTest(point)) | 644 if (!HitTest(point)) |
| 636 return AutocompletePopupModel::kNoMatch; | 645 return AutocompletePopupModel::kNoMatch; |
| 637 | 646 |
| 638 int nb_match = model_->result().size(); | 647 int nb_match = model_->result().size(); |
| 639 DCHECK(nb_match <= child_count()); | 648 DCHECK(nb_match <= child_count()); |
| 640 for (int i = 0; i < nb_match; ++i) { | 649 for (int i = 0; i < nb_match; ++i) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 675 opt_in_view_ = NULL; | 684 opt_in_view_ = NULL; |
| 676 PromoCounter* counter = model_->profile()->GetInstantPromoCounter(); | 685 PromoCounter* counter = model_->profile()->GetInstantPromoCounter(); |
| 677 DCHECK(counter); | 686 DCHECK(counter); |
| 678 counter->Hide(); | 687 counter->Hide(); |
| 679 if (opt_in) { | 688 if (opt_in) { |
| 680 browser::ShowInstantConfirmDialogIfNecessary( | 689 browser::ShowInstantConfirmDialogIfNecessary( |
| 681 location_bar_->GetWindow()->GetNativeWindow(), model_->profile()); | 690 location_bar_->GetWindow()->GetNativeWindow(), model_->profile()); |
| 682 } | 691 } |
| 683 UpdatePopupAppearance(); | 692 UpdatePopupAppearance(); |
| 684 } | 693 } |
| OLD | NEW |