| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/omnibox/browser/omnibox_controller.h" | 5 #include "components/omnibox/browser/omnibox_controller.h" |
| 6 | 6 |
| 7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
| 8 #include "components/omnibox/browser/autocomplete_classifier.h" | 8 #include "components/omnibox/browser/autocomplete_classifier.h" |
| 9 #include "components/omnibox/browser/autocomplete_match.h" | 9 #include "components/omnibox/browser/autocomplete_match.h" |
| 10 #include "components/omnibox/browser/omnibox_client.h" | 10 #include "components/omnibox/browser/omnibox_client.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 const AutocompleteInput& input) const { | 33 const AutocompleteInput& input) const { |
| 34 ClearPopupKeywordMode(); | 34 ClearPopupKeywordMode(); |
| 35 popup_->SetHoveredLine(OmniboxPopupModel::kNoMatch); | 35 popup_->SetHoveredLine(OmniboxPopupModel::kNoMatch); |
| 36 | 36 |
| 37 // We don't explicitly clear OmniboxPopupModel::manually_selected_match, as | 37 // We don't explicitly clear OmniboxPopupModel::manually_selected_match, as |
| 38 // Start ends up invoking OmniboxPopupModel::OnResultChanged which clears it. | 38 // Start ends up invoking OmniboxPopupModel::OnResultChanged which clears it. |
| 39 autocomplete_controller_->Start(input); | 39 autocomplete_controller_->Start(input); |
| 40 } | 40 } |
| 41 | 41 |
| 42 void OmniboxController::OnResultChanged(bool default_match_changed) { | 42 void OmniboxController::OnResultChanged(bool default_match_changed) { |
| 43 const bool was_open = popup_->IsOpen(); | 43 const bool was_open = popup_ && popup_->IsOpen(); |
| 44 if (default_match_changed) { | 44 if (default_match_changed) { |
| 45 // The default match has changed, we need to let the OmniboxEditModel know | 45 // The default match has changed, we need to let the OmniboxEditModel know |
| 46 // about new inline autocomplete text (blue highlight). | 46 // about new inline autocomplete text (blue highlight). |
| 47 const AutocompleteResult::const_iterator match(result().default_match()); | 47 const AutocompleteResult::const_iterator match(result().default_match()); |
| 48 if (match != result().end()) { | 48 if (match != result().end()) { |
| 49 current_match_ = *match; | 49 current_match_ = *match; |
| 50 omnibox_edit_model_->OnCurrentMatchChanged(); | 50 omnibox_edit_model_->OnCurrentMatchChanged(); |
| 51 } else { | 51 } else { |
| 52 InvalidateCurrentMatch(); | 52 InvalidateCurrentMatch(); |
| 53 popup_->OnResultChanged(); | 53 if (popup_) |
| 54 popup_->OnResultChanged(); |
| 54 omnibox_edit_model_->OnPopupDataChanged(base::string16(), nullptr, | 55 omnibox_edit_model_->OnPopupDataChanged(base::string16(), nullptr, |
| 55 base::string16(), false); | 56 base::string16(), false); |
| 56 } | 57 } |
| 57 } else { | 58 } else if (popup_) { |
| 58 popup_->OnResultChanged(); | 59 popup_->OnResultChanged(); |
| 59 } | 60 } |
| 60 | 61 |
| 61 if (!popup_->IsOpen() && was_open) { | 62 if (was_open && !popup_->IsOpen()) { |
| 62 // Accept the temporary text as the user text, because it makes little sense | 63 // Accept the temporary text as the user text, because it makes little sense |
| 63 // to have temporary text when the popup is closed. | 64 // to have temporary text when the popup is closed. |
| 64 omnibox_edit_model_->AcceptTemporaryTextAsUserText(); | 65 omnibox_edit_model_->AcceptTemporaryTextAsUserText(); |
| 65 } | 66 } |
| 66 | 67 |
| 67 // Note: The client outlives |this|, so bind a weak pointer to the callback | 68 // Note: The client outlives |this|, so bind a weak pointer to the callback |
| 68 // passed in to eliminate the potential for crashes on shutdown. | 69 // passed in to eliminate the potential for crashes on shutdown. |
| 69 client_->OnResultChanged(result(), default_match_changed, | 70 client_->OnResultChanged(result(), default_match_changed, |
| 70 base::Bind(&OmniboxController::SetAnswerBitmap, | 71 base::Bind(&OmniboxController::SetAnswerBitmap, |
| 71 weak_ptr_factory_.GetWeakPtr())); | 72 weak_ptr_factory_.GetWeakPtr())); |
| 72 } | 73 } |
| 73 | 74 |
| 74 void OmniboxController::InvalidateCurrentMatch() { | 75 void OmniboxController::InvalidateCurrentMatch() { |
| 75 current_match_ = AutocompleteMatch(); | 76 current_match_ = AutocompleteMatch(); |
| 76 } | 77 } |
| 77 | 78 |
| 78 void OmniboxController::ClearPopupKeywordMode() const { | 79 void OmniboxController::ClearPopupKeywordMode() const { |
| 79 if (popup_->IsOpen() && | 80 if (popup_->IsOpen() && |
| 80 popup_->selected_line_state() == OmniboxPopupModel::KEYWORD) | 81 popup_->selected_line_state() == OmniboxPopupModel::KEYWORD) |
| 81 popup_->SetSelectedLineState(OmniboxPopupModel::NORMAL); | 82 popup_->SetSelectedLineState(OmniboxPopupModel::NORMAL); |
| 82 } | 83 } |
| 83 | 84 |
| 84 void OmniboxController::SetAnswerBitmap(const SkBitmap& bitmap) { | 85 void OmniboxController::SetAnswerBitmap(const SkBitmap& bitmap) { |
| 85 popup_->SetAnswerBitmap(bitmap); | 86 popup_->SetAnswerBitmap(bitmap); |
| 86 } | 87 } |
| OLD | NEW |