summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authordeanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-27 14:49:51 +0000
committerdeanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-27 14:49:51 +0000
commitf387f1b80dc74fd2d77820e23b885e7984455763 (patch)
tree1f3ee3729aec8dc4468adcd1de54298f9e1586b5 /chrome
parent5e689362e7c6f7b2535aa5ae6dbb198e03a372fb (diff)
downloadchromium_src-f387f1b80dc74fd2d77820e23b885e7984455763.zip
chromium_src-f387f1b80dc74fd2d77820e23b885e7984455763.tar.gz
chromium_src-f387f1b80dc74fd2d77820e23b885e7984455763.tar.bz2
Pull the autocomplete popup into separate model and view files.
- autocomplete_popup.h is now autocomplete_popup_{model,view}.h. - autocomplete_popup.cc is now autocomplete_popup_{model,view_win}.cc - The view header is still Windows specific, but this will be addressed soon. - Rename is_open to IsOpen, in preparation for making a interface for the view. - Update the project files. Review URL: http://codereview.chromium.org/27272 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10606 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit.cc14
-rw-r--r--chrome/browser/autocomplete/autocomplete_popup_model.cc361
-rw-r--r--chrome/browser/autocomplete/autocomplete_popup_model.h176
-rw-r--r--chrome/browser/autocomplete/autocomplete_popup_view.h (renamed from chrome/browser/autocomplete/autocomplete_popup.h)170
-rwxr-xr-x[-rw-r--r--]chrome/browser/autocomplete/autocomplete_popup_view_win.cc (renamed from chrome/browser/autocomplete/autocomplete_popup.cc)348
-rw-r--r--chrome/browser/browser.scons9
-rw-r--r--chrome/browser/browser.vcproj12
-rw-r--r--chrome/chrome.gyp9
8 files changed, 584 insertions, 515 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit.cc b/chrome/browser/autocomplete/autocomplete_edit.cc
index 862c2ed..35f7dad 100644
--- a/chrome/browser/autocomplete/autocomplete_edit.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit.cc
@@ -16,7 +16,7 @@
#include "base/string_util.h"
#include "chrome/app/chrome_dll_resource.h"
#include "chrome/browser/autocomplete/autocomplete_accessibility.h"
-#include "chrome/browser/autocomplete/autocomplete_popup.h"
+#include "chrome/browser/autocomplete/autocomplete_popup_model.h"
#include "chrome/browser/autocomplete/edit_drop_target.h"
#include "chrome/browser/autocomplete/keyword_provider.h"
#include "chrome/browser/browser_process.h"
@@ -280,7 +280,7 @@ void AutocompleteEditModel::SendOpenNotification(size_t selected_line,
const std::wstring& keyword) {
// We only care about cases where there is a selection (i.e. the popup is
// open).
- if (popup_->is_open()) {
+ if (popup_->IsOpen()) {
scoped_ptr<AutocompleteLog> log(popup_->GetAutocompleteLog());
if (selected_line != AutocompletePopupModel::kNoMatch)
log->selected_index = selected_line;
@@ -391,7 +391,7 @@ void AutocompleteEditModel::OnControlKeyChanged(bool pressed) {
// Don't change anything unless the key state is actually toggling.
if (pressed == (control_key_state_ == UP)) {
control_key_state_ = pressed ? DOWN_WITHOUT_CHANGE : UP;
- if (popup_->is_open()) {
+ if (popup_->IsOpen()) {
// Autocomplete history provider results may change, so refresh the
// popup. This will force user_input_in_progress_ to true, but if the
// popup is open, that should have already been the case.
@@ -403,7 +403,7 @@ void AutocompleteEditModel::OnControlKeyChanged(bool pressed) {
void AutocompleteEditModel::OnUpOrDownKeyPressed(int count) {
// NOTE: This purposefully don't trigger any code that resets paste_state_.
- if (!popup_->is_open()) {
+ if (!popup_->IsOpen()) {
if (popup_->autocomplete_controller()->done()) {
// The popup is neither open nor working on a query already. So, start an
// autocomplete query for the current text. This also sets
@@ -508,7 +508,7 @@ bool AutocompleteEditModel::OnAfterPossibleChange(const std::wstring& new_text,
if ((text_differs || selection_differs) &&
(control_key_state_ == DOWN_WITHOUT_CHANGE)) {
control_key_state_ = DOWN_WITH_CHANGE;
- if (!text_differs && !popup_->is_open())
+ if (!text_differs && !popup_->IsOpen())
return false; // Don't open the popup for no reason.
} else if (!text_differs &&
(inline_autocomplete_text_.empty() || !selection_differs)) {
@@ -571,7 +571,7 @@ GURL AutocompleteEditModel::GetURLForCurrentText(
PageTransition::Type* transition,
bool* is_history_what_you_typed_match,
GURL* alternate_nav_url) {
- return (popup_->is_open() || !popup_->autocomplete_controller()->done()) ?
+ return (popup_->IsOpen() || !popup_->autocomplete_controller()->done()) ?
popup_->URLsForCurrentSelection(transition,
is_history_what_you_typed_match,
alternate_nav_url) :
@@ -1954,7 +1954,7 @@ bool AutocompleteEditView::OnKeyDownOnlyWritable(TCHAR key,
OnBeforePossibleChange();
Cut();
OnAfterPossibleChange();
- } else if (popup_model_->is_open()) {
+ } else if (popup_model_->IsOpen()) {
// This is a bit overloaded, but we hijack Shift-Delete in this
// case to delete the current item from the pop-up. We prefer cutting
// to this when possible since that's the behavior more people expect
diff --git a/chrome/browser/autocomplete/autocomplete_popup_model.cc b/chrome/browser/autocomplete/autocomplete_popup_model.cc
new file mode 100644
index 0000000..1e2f21f
--- /dev/null
+++ b/chrome/browser/autocomplete/autocomplete_popup_model.cc
@@ -0,0 +1,361 @@
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/autocomplete/autocomplete_popup_model.h"
+
+// TODO(deanm): Clean up these includes, not going to fight it now.
+#include <cmath>
+
+#include "base/scoped_ptr.h"
+#include "base/string_util.h"
+#include "chrome/browser/autocomplete/autocomplete_edit.h"
+#include "chrome/browser/autocomplete/autocomplete_popup_view.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/net/dns_global.h"
+#include "chrome/browser/profile.h"
+#include "chrome/browser/search_engines/template_url.h"
+#include "chrome/browser/search_engines/template_url_model.h"
+#include "chrome/browser/views/location_bar_view.h"
+#include "chrome/common/gfx/chrome_canvas.h"
+#include "chrome/common/l10n_util.h"
+#include "chrome/common/notification_service.h"
+#include "chrome/common/resource_bundle.h"
+#include "grit/theme_resources.h"
+#include "third_party/icu38/public/common/unicode/ubidi.h"
+
+AutocompletePopupModel::AutocompletePopupModel(
+ const ChromeFont& font,
+ AutocompleteEditView* edit_view,
+ AutocompleteEditModel* edit_model,
+ Profile* profile)
+ : view_(new AutocompletePopupView(this, font, edit_view)),
+ edit_model_(edit_model),
+ controller_(new AutocompleteController(profile)),
+ profile_(profile),
+ hovered_line_(kNoMatch),
+ selected_line_(kNoMatch),
+ inside_synchronous_query_(false) {
+ registrar_.Add(
+ this,
+ NotificationType::AUTOCOMPLETE_CONTROLLER_RESULT_UPDATED,
+ Source<AutocompleteController>(controller_.get()));
+ registrar_.Add(
+ this,
+ NotificationType::AUTOCOMPLETE_CONTROLLER_SYNCHRONOUS_MATCHES_AVAILABLE,
+ Source<AutocompleteController>(controller_.get()));
+}
+
+AutocompletePopupModel::~AutocompletePopupModel() {
+ StopAutocomplete();
+}
+
+void AutocompletePopupModel::SetProfile(Profile* profile) {
+ DCHECK(profile);
+ profile_ = profile;
+ controller_->SetProfile(profile);
+}
+
+void AutocompletePopupModel::StartAutocomplete(
+ const std::wstring& text,
+ const std::wstring& desired_tld,
+ bool prevent_inline_autocomplete,
+ bool prefer_keyword) {
+ // The user is interacting with the edit, so stop tracking hover.
+ SetHoveredLine(kNoMatch);
+
+ manually_selected_match_.Clear();
+
+ controller_->Start(text, desired_tld, prevent_inline_autocomplete,
+ prefer_keyword, false);
+}
+
+void AutocompletePopupModel::StopAutocomplete() {
+ controller_->Stop(true);
+ SetHoveredLine(kNoMatch);
+ selected_line_ = kNoMatch;
+ view_->UpdatePopupAppearance();
+}
+
+bool AutocompletePopupModel::IsOpen() const {
+ return view_->IsOpen();
+}
+
+void AutocompletePopupModel::SetHoveredLine(size_t line) {
+ const bool is_disabling = (line == kNoMatch);
+ DCHECK(is_disabling || (line < controller_->result().size()));
+
+ if (line == hovered_line_)
+ return; // Nothing to do
+
+ // Make sure the old hovered line is redrawn. No need to redraw the selected
+ // line since selection overrides hover so the appearance won't change.
+ const bool is_enabling = (hovered_line_ == kNoMatch);
+ if (!is_enabling && (hovered_line_ != selected_line_))
+ view_->InvalidateLine(hovered_line_);
+
+ // Change the hover to the new line and make sure it's redrawn.
+ hovered_line_ = line;
+ if (!is_disabling && (hovered_line_ != selected_line_))
+ view_->InvalidateLine(hovered_line_);
+
+ if (is_enabling || is_disabling)
+ view_->OnHoverEnabledOrDisabled(is_disabling);
+}
+
+void AutocompletePopupModel::SetSelectedLine(size_t line,
+ bool reset_to_default) {
+ const AutocompleteResult& result = controller_->result();
+ DCHECK(line < result.size());
+ if (result.empty())
+ return;
+
+ // Cancel the query so the matches don't change on the user.
+ controller_->Stop(false);
+
+ const AutocompleteMatch& match = result.match_at(line);
+ if (reset_to_default) {
+ manually_selected_match_.Clear();
+ } else {
+ // Track the user's selection until they cancel it.
+ manually_selected_match_.destination_url = match.destination_url;
+ manually_selected_match_.provider_affinity = match.provider;
+ manually_selected_match_.is_history_what_you_typed_match =
+ match.is_history_what_you_typed_match;
+ }
+
+ if (line == selected_line_)
+ return; // Nothing else to do.
+
+ // Update the edit with the new data for this match.
+ std::wstring keyword;
+ const bool is_keyword_hint = GetKeywordForMatch(match, &keyword);
+ edit_model_->OnPopupDataChanged(
+ reset_to_default ? std::wstring() : match.fill_into_edit,
+ !reset_to_default, keyword, is_keyword_hint, match.type);
+
+ // Repaint old and new selected lines immediately, so that the edit doesn't
+ // appear to update [much] faster than the popup. We must not update
+ // |selected_line_| before calling OnPopupDataChanged() (since the edit may
+ // call us back to get data about the old selection), and we must not call
+ // UpdateWindow() before updating |selected_line_| (since the paint routine
+ // relies on knowing the correct selected line).
+ view_->InvalidateLine(selected_line_);
+ selected_line_ = line;
+ view_->InvalidateLine(selected_line_);
+ view_->UpdateWindow();
+}
+
+void AutocompletePopupModel::ResetToDefaultMatch() {
+ const AutocompleteResult& result = controller_->result();
+ DCHECK(!result.empty());
+ SetSelectedLine(result.default_match() - result.begin(), true);
+}
+
+GURL AutocompletePopupModel::URLsForCurrentSelection(
+ PageTransition::Type* transition,
+ bool* is_history_what_you_typed_match,
+ GURL* alternate_nav_url) const {
+ // We need to use the result on the controller, because if the popup is open,
+ // the user changes the contents of the edit, and then presses enter before
+ // any results have been displayed, results_ will be nonempty but wrong. (In
+ // most other cases, the controller's results will match the popup's.)
+ // TODO(pkasting): If manually_selected_match_ moves to the controller, this
+ // can move to the edit.
+ if (controller_->result().empty())
+ return GURL();
+
+ const AutocompleteResult& result = controller_->result();
+ AutocompleteResult::const_iterator match;
+ if (!controller_->done()) {
+ // The user cannot have manually selected a match, or the query would have
+ // stopped. So the default match must be the desired selection.
+ match = result.default_match();
+ } else {
+ // The query isn't running, so the popup can't possibly be out of date.
+ DCHECK(selected_line_ < result.size());
+ match = result.begin() + selected_line_;
+ }
+ if (transition)
+ *transition = match->transition;
+ if (is_history_what_you_typed_match)
+ *is_history_what_you_typed_match = match->is_history_what_you_typed_match;
+ if (alternate_nav_url && manually_selected_match_.empty())
+ *alternate_nav_url = result.GetAlternateNavURL(controller_->input(), match);
+ return match->destination_url;
+}
+
+GURL AutocompletePopupModel::URLsForDefaultMatch(
+ const std::wstring& text,
+ const std::wstring& desired_tld,
+ PageTransition::Type* transition,
+ bool* is_history_what_you_typed_match,
+ GURL* alternate_nav_url) {
+ // We had better not already be doing anything, or this call will blow it
+ // away.
+ DCHECK(!IsOpen());
+ DCHECK(controller_->done());
+
+ // Run the new query and get only the synchronously available matches.
+ inside_synchronous_query_ = true; // Tell Observe() not to notify the edit or
+ // update our appearance.
+ controller_->Start(text, desired_tld, true, false, true);
+ inside_synchronous_query_ = false;
+ DCHECK(controller_->done());
+ const AutocompleteResult& result = controller_->result();
+ if (result.empty())
+ return GURL();
+
+ // Get the URLs for the default match.
+ const AutocompleteResult::const_iterator match = result.default_match();
+ if (transition)
+ *transition = match->transition;
+ if (is_history_what_you_typed_match)
+ *is_history_what_you_typed_match = match->is_history_what_you_typed_match;
+ if (alternate_nav_url)
+ *alternate_nav_url = result.GetAlternateNavURL(controller_->input(), match);
+ return match->destination_url;
+}
+
+bool AutocompletePopupModel::GetKeywordForMatch(const AutocompleteMatch& match,
+ std::wstring* keyword) const {
+ // Assume we have no keyword until we find otherwise.
+ keyword->clear();
+
+ // If the current match is a keyword, return that as the selected keyword.
+ if (match.template_url && match.template_url->url() &&
+ match.template_url->url()->SupportsReplacement()) {
+ keyword->assign(match.template_url->keyword());
+ return false;
+ }
+
+ // See if the current match's fill_into_edit corresponds to a keyword.
+ if (!profile_->GetTemplateURLModel())
+ return false;
+ profile_->GetTemplateURLModel()->Load();
+ const std::wstring keyword_hint(
+ TemplateURLModel::CleanUserInputKeyword(match.fill_into_edit));
+ if (keyword_hint.empty())
+ return false;
+
+ // Don't provide a hint if this keyword doesn't support replacement.
+ const TemplateURL* const template_url =
+ profile_->GetTemplateURLModel()->GetTemplateURLForKeyword(keyword_hint);
+ if (!template_url || !template_url->url() ||
+ !template_url->url()->SupportsReplacement())
+ return false;
+
+ keyword->assign(keyword_hint);
+ return true;
+}
+
+AutocompleteLog* AutocompletePopupModel::GetAutocompleteLog() {
+ return new AutocompleteLog(controller_->input().text(),
+ controller_->input().type(), selected_line_, 0, controller_->result());
+}
+
+void AutocompletePopupModel::Move(int count) {
+ // TODO(pkasting): Temporary hack. If the query is running while the popup is
+ // open, we might be showing the results of the previous query still. Force
+ // the popup to display the latest results so the popup and the controller
+ // aren't out of sync. The better fix here is to roll the controller back to
+ // be in sync with what the popup is showing.
+ if (IsOpen() && !controller_->done()) {
+ Observe(NotificationType::AUTOCOMPLETE_CONTROLLER_RESULT_UPDATED,
+ Source<AutocompleteController>(controller_.get()),
+ NotificationService::NoDetails());
+ }
+
+ const AutocompleteResult& result = controller_->result();
+ if (result.empty())
+ return;
+
+ // The user is using the keyboard to change the selection, so stop tracking
+ // hover.
+ SetHoveredLine(kNoMatch);
+
+ // Clamp the new line to [0, result_.count() - 1].
+ const size_t new_line = selected_line_ + count;
+ SetSelectedLine((((count < 0) && (new_line >= selected_line_)) ?
+ 0 : std::min(new_line, result.size() - 1)), false);
+}
+
+void AutocompletePopupModel::TryDeletingCurrentItem() {
+ // We could use URLsForCurrentSelection() here, but it seems better to try
+ // and shift-delete the actual selection, rather than any "in progress, not
+ // yet visible" one.
+ if (selected_line_ == kNoMatch)
+ return;
+ const AutocompleteMatch& match =
+ controller_->result().match_at(selected_line_);
+ if (match.deletable) {
+ const size_t selected_line = selected_line_;
+ controller_->DeleteMatch(match); // This will synchronously notify us that
+ // the results have changed.
+ const AutocompleteResult& result = controller_->result();
+ if (!result.empty()) {
+ // Move the selection to the next choice after the deleted one.
+ // TODO(pkasting): Eventually the controller should take care of this
+ // before notifying us, reducing flicker. At that point the check for
+ // deletability can move there too.
+ SetSelectedLine(std::min(result.size() - 1, selected_line), false);
+ }
+ }
+}
+
+void AutocompletePopupModel::Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ if (inside_synchronous_query_)
+ return;
+
+ const AutocompleteResult& result = controller_->result();
+ switch (type.value) {
+ case NotificationType::AUTOCOMPLETE_CONTROLLER_RESULT_UPDATED: {
+ selected_line_ = (result.default_match() == result.end()) ?
+ kNoMatch : (result.default_match() - result.begin());
+ // If we're going to trim the window size to no longer include the hovered
+ // line, turn hover off. Practically, this shouldn't happen, but it
+ // doesn't hurt to be defensive.
+ if ((hovered_line_ != kNoMatch) && (result.size() <= hovered_line_))
+ SetHoveredLine(kNoMatch);
+
+ view_->UpdatePopupAppearance();
+ }
+ // FALL THROUGH
+
+ case NotificationType::AUTOCOMPLETE_CONTROLLER_SYNCHRONOUS_MATCHES_AVAILABLE: {
+ // Update the edit with the possibly new data for this match.
+ // NOTE: This must be done after the code above, so that our internal
+ // state will be consistent when the edit calls back to
+ // URLsForCurrentSelection().
+ std::wstring inline_autocomplete_text;
+ std::wstring keyword;
+ bool is_keyword_hint = false;
+ AutocompleteMatch::Type type = AutocompleteMatch::SEARCH_WHAT_YOU_TYPED;
+ const AutocompleteResult::const_iterator match(result.default_match());
+ if (match != result.end()) {
+ if ((match->inline_autocomplete_offset != std::wstring::npos) &&
+ (match->inline_autocomplete_offset <
+ match->fill_into_edit.length())) {
+ inline_autocomplete_text =
+ match->fill_into_edit.substr(match->inline_autocomplete_offset);
+ }
+ // Warm up DNS Prefetch Cache.
+ chrome_browser_net::DnsPrefetchUrl(match->destination_url);
+ // We could prefetch the alternate nav URL, if any, but because there
+ // can be many of these as a user types an initial series of characters,
+ // the OS DNS cache could suffer eviction problems for minimal gain.
+
+ is_keyword_hint = GetKeywordForMatch(*match, &keyword);
+ type = match->type;
+ }
+ edit_model_->OnPopupDataChanged(inline_autocomplete_text, false, keyword,
+ is_keyword_hint, type);
+ return;
+ }
+
+ default:
+ NOTREACHED();
+ }
+}
diff --git a/chrome/browser/autocomplete/autocomplete_popup_model.h b/chrome/browser/autocomplete/autocomplete_popup_model.h
new file mode 100644
index 0000000..bab0c0a
--- /dev/null
+++ b/chrome/browser/autocomplete/autocomplete_popup_model.h
@@ -0,0 +1,176 @@
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_POPUP_MODEL_H_
+#define CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_POPUP_MODEL_H_
+
+#include "chrome/browser/autocomplete/autocomplete.h"
+#include "chrome/common/notification_registrar.h"
+
+class AutocompleteEditModel;
+class AutocompleteEditView;
+class ChromeFont;
+class Profile;
+
+class AutocompletePopupView;
+
+class AutocompletePopupModel : public NotificationObserver {
+ public:
+ AutocompletePopupModel(const ChromeFont& font,
+ AutocompleteEditView* edit_view,
+ AutocompleteEditModel* edit_model,
+ Profile* profile);
+ ~AutocompletePopupModel();
+
+ // Invoked when the profile has changed.
+ void SetProfile(Profile* profile);
+
+ // Starts a new query running. These parameters are passed through to the
+ // autocomplete controller; see comments there.
+ void StartAutocomplete(const std::wstring& text,
+ const std::wstring& desired_tld,
+ bool prevent_inline_autocomplete,
+ bool prefer_keyword);
+
+ // Closes the window and cancels any pending asynchronous queries.
+ void StopAutocomplete();
+
+ // Returns true if the popup is currently open.
+ bool IsOpen() const;
+
+ // Returns the AutocompleteController used by this popup.
+ AutocompleteController* autocomplete_controller() const {
+ return controller_.get();
+ }
+
+ const AutocompleteResult& result() const {
+ return controller_->result();
+ }
+
+ size_t hovered_line() const {
+ return hovered_line_;
+ }
+
+ // Call to change the hovered line. |line| should be within the range of
+ // valid lines (to enable hover) or kNoMatch (to disable hover).
+ void SetHoveredLine(size_t line);
+
+ size_t selected_line() const {
+ return selected_line_;
+ }
+
+ // Call to change the selected line. This will update all state and repaint
+ // the necessary parts of the window, as well as updating the edit with the
+ // new temporary text. |line| should be within the range of valid lines.
+ // |reset_to_default| is true when the selection is being reset back to the
+ // default match, and thus there is no temporary text (and no
+ // |manually_selected_match_|).
+ // NOTE: This assumes the popup is open, and thus both old and new values for
+ // the selected line should not be kNoMatch.
+ void SetSelectedLine(size_t line, bool reset_to_default);
+
+ // Called when the user hits escape after arrowing around the popup. This
+ // will change the selected line back to the default match and redraw.
+ void ResetToDefaultMatch();
+
+ // Returns the URL for the selected match. If an update is in progress,
+ // "selected" means "default in the latest matches". If there are no
+ // matches, returns the empty string.
+ //
+ // If |transition_type| is non-NULL, it will be set to the appropriate
+ // transition type for the selected entry (TYPED or GENERATED).
+ //
+ // If |is_history_what_you_typed_match| is non-NULL, it will be set based on
+ // the selected entry's is_history_what_you_typed value.
+ //
+ // If |alternate_nav_url| is non-NULL, it will be set to the alternate
+ // navigation URL for |url| if one exists, or left unchanged otherwise. See
+ // comments on AutocompleteResult::GetAlternateNavURL().
+ GURL URLsForCurrentSelection(
+ PageTransition::Type* transition,
+ bool* is_history_what_you_typed_match,
+ GURL* alternate_nav_url) const;
+
+ // This is sort of a hybrid between StartAutocomplete() and
+ // URLForCurrentSelection(). When the popup isn't open and the user hits
+ // enter, we want to get the default match for the user's input immediately,
+ // and not open the popup, continue running autocomplete, etc. Therefore,
+ // this does a query for only the synchronously available matches for the
+ // provided input parameters, sets |transition|,
+ // |is_history_what_you_typed_match|, and |alternate_nav_url| (if applicable)
+ // based on the default match, and returns its url. |transition|,
+ // |is_history_what_you_typed_match| and/or |alternate_nav_url| may be null,
+ // in which case they are not updated.
+ //
+ // If there are no matches for |text|, leaves the outparams unset and returns
+ // the empty string.
+ GURL URLsForDefaultMatch(const std::wstring& text,
+ const std::wstring& desired_tld,
+ PageTransition::Type* transition,
+ bool* is_history_what_you_typed_match,
+ GURL* alternate_nav_url);
+
+ // Gets the selected keyword or keyword hint for the given match. Returns
+ // true if |keyword| represents a keyword hint, or false if |keyword|
+ // represents a selected keyword. (|keyword| will always be set [though
+ // possibly to the empty string], and you cannot have both a selected keyword
+ // and a keyword hint simultaneously.)
+ bool GetKeywordForMatch(const AutocompleteMatch& match,
+ std::wstring* keyword) const;
+
+ // Returns a pointer to a heap-allocated AutocompleteLog containing the
+ // current input text, selected match, and result set. The caller is
+ // responsible for deleting the object.
+ AutocompleteLog* GetAutocompleteLog();
+
+ // Immediately updates and opens the popup if necessary, then moves the
+ // current selection down (|count| > 0) or up (|count| < 0), clamping to the
+ // first or last result if necessary. If |count| == 0, the selection will be
+ // unchanged, but the popup will still redraw and modify the text in the
+ // AutocompleteEditModel.
+ void Move(int count);
+
+ // Called when the user hits shift-delete. This should determine if the item
+ // can be removed from history, and if so, remove it and update the popup.
+ void TryDeletingCurrentItem();
+
+ // The token value for selected_line_, hover_line_ and functions dealing with
+ // a "line number" that indicates "no line".
+ static const size_t kNoMatch = -1;
+
+ private:
+ // NotificationObserver
+ virtual void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details);
+
+ scoped_ptr<AutocompletePopupView> view_;
+
+ AutocompleteEditModel* edit_model_;
+ scoped_ptr<AutocompleteController> controller_;
+
+ NotificationRegistrar registrar_;
+
+ // Profile for current tab.
+ Profile* profile_;
+
+ // The line that's currently hovered. If we're not drawing a hover rect,
+ // this will be kNoMatch, even if the cursor is over the popup contents.
+ size_t hovered_line_;
+
+ // The currently selected line. This is kNoMatch when nothing is selected,
+ // which should only be true when the popup is closed.
+ size_t selected_line_;
+
+ // The match the user has manually chosen, if any.
+ AutocompleteResult::Selection manually_selected_match_;
+
+ // A hack for URLsForDefaultMatch() that makes the code in Observe() do
+ // nothing.
+ bool inside_synchronous_query_;
+
+ DISALLOW_COPY_AND_ASSIGN(AutocompletePopupModel);
+};
+
+#endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_POPUP_MODEL_H_
diff --git a/chrome/browser/autocomplete/autocomplete_popup.h b/chrome/browser/autocomplete/autocomplete_popup_view.h
index 980198c..235e342 100644
--- a/chrome/browser/autocomplete/autocomplete_popup.h
+++ b/chrome/browser/autocomplete/autocomplete_popup_view.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_POPUP_H_
-#define CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_POPUP_H_
+#ifndef CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_POPUP_VIEW_H_
+#define CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_POPUP_VIEW_H_
#include <atlbase.h>
#include <atlapp.h>
@@ -13,17 +13,13 @@
#include "base/win_util.h"
#include "chrome/browser/autocomplete/autocomplete.h"
#include "chrome/common/gfx/chrome_font.h"
-#include "chrome/common/notification_registrar.h"
#include "chrome/views/view.h"
-class AutocompleteEditModel;
class AutocompleteEditView;
-class Profile;
class MirroringContext;
class SkBitmap;
class AutocompletePopupModel;
-class AutocompletePopupView;
// TODO(pkasting): http://b/1343512 The names and contents of the classes in
// this file are temporary. I am in hack-and-slash mode right now.
@@ -55,7 +51,7 @@ class AutocompletePopupView
AutocompleteEditView* edit_view);
// Returns true if the popup is currently open.
- bool is_open() const { return m_hWnd != NULL; }
+ bool IsOpen() const { return m_hWnd != NULL; }
// Invalidates one line of the autocomplete popup.
void InvalidateLine(size_t line);
@@ -202,162 +198,4 @@ class AutocompletePopupView
DISALLOW_COPY_AND_ASSIGN(AutocompletePopupView);
};
-class AutocompletePopupModel : public NotificationObserver {
- public:
- AutocompletePopupModel(const ChromeFont& font,
- AutocompleteEditView* edit_view,
- AutocompleteEditModel* edit_model,
- Profile* profile);
- ~AutocompletePopupModel();
-
- // Invoked when the profile has changed.
- void SetProfile(Profile* profile);
-
- // Starts a new query running. These parameters are passed through to the
- // autocomplete controller; see comments there.
- void StartAutocomplete(const std::wstring& text,
- const std::wstring& desired_tld,
- bool prevent_inline_autocomplete,
- bool prefer_keyword);
-
- // Closes the window and cancels any pending asynchronous queries.
- void StopAutocomplete();
-
- // Returns true if the popup is currently open.
- bool is_open() const { return view_->is_open(); }
-
- // Returns the AutocompleteController used by this popup.
- AutocompleteController* autocomplete_controller() const {
- return controller_.get();
- }
-
- const AutocompleteResult& result() const {
- return controller_->result();
- }
-
- size_t hovered_line() const {
- return hovered_line_;
- }
-
- // Call to change the hovered line. |line| should be within the range of
- // valid lines (to enable hover) or kNoMatch (to disable hover).
- void SetHoveredLine(size_t line);
-
- size_t selected_line() const {
- return selected_line_;
- }
-
- // Call to change the selected line. This will update all state and repaint
- // the necessary parts of the window, as well as updating the edit with the
- // new temporary text. |line| should be within the range of valid lines.
- // |reset_to_default| is true when the selection is being reset back to the
- // default match, and thus there is no temporary text (and no
- // |manually_selected_match_|).
- // NOTE: This assumes the popup is open, and thus both old and new values for
- // the selected line should not be kNoMatch.
- void SetSelectedLine(size_t line, bool reset_to_default);
-
- // Called when the user hits escape after arrowing around the popup. This
- // will change the selected line back to the default match and redraw.
- void ResetToDefaultMatch();
-
- // Returns the URL for the selected match. If an update is in progress,
- // "selected" means "default in the latest matches". If there are no
- // matches, returns the empty string.
- //
- // If |transition_type| is non-NULL, it will be set to the appropriate
- // transition type for the selected entry (TYPED or GENERATED).
- //
- // If |is_history_what_you_typed_match| is non-NULL, it will be set based on
- // the selected entry's is_history_what_you_typed value.
- //
- // If |alternate_nav_url| is non-NULL, it will be set to the alternate
- // navigation URL for |url| if one exists, or left unchanged otherwise. See
- // comments on AutocompleteResult::GetAlternateNavURL().
- GURL URLsForCurrentSelection(
- PageTransition::Type* transition,
- bool* is_history_what_you_typed_match,
- GURL* alternate_nav_url) const;
-
- // This is sort of a hybrid between StartAutocomplete() and
- // URLForCurrentSelection(). When the popup isn't open and the user hits
- // enter, we want to get the default match for the user's input immediately,
- // and not open the popup, continue running autocomplete, etc. Therefore,
- // this does a query for only the synchronously available matches for the
- // provided input parameters, sets |transition|,
- // |is_history_what_you_typed_match|, and |alternate_nav_url| (if applicable)
- // based on the default match, and returns its url. |transition|,
- // |is_history_what_you_typed_match| and/or |alternate_nav_url| may be null,
- // in which case they are not updated.
- //
- // If there are no matches for |text|, leaves the outparams unset and returns
- // the empty string.
- GURL URLsForDefaultMatch(const std::wstring& text,
- const std::wstring& desired_tld,
- PageTransition::Type* transition,
- bool* is_history_what_you_typed_match,
- GURL* alternate_nav_url);
-
- // Gets the selected keyword or keyword hint for the given match. Returns
- // true if |keyword| represents a keyword hint, or false if |keyword|
- // represents a selected keyword. (|keyword| will always be set [though
- // possibly to the empty string], and you cannot have both a selected keyword
- // and a keyword hint simultaneously.)
- bool GetKeywordForMatch(const AutocompleteMatch& match,
- std::wstring* keyword) const;
-
- // Returns a pointer to a heap-allocated AutocompleteLog containing the
- // current input text, selected match, and result set. The caller is
- // responsible for deleting the object.
- AutocompleteLog* GetAutocompleteLog();
-
- // Immediately updates and opens the popup if necessary, then moves the
- // current selection down (|count| > 0) or up (|count| < 0), clamping to the
- // first or last result if necessary. If |count| == 0, the selection will be
- // unchanged, but the popup will still redraw and modify the text in the
- // AutocompleteEditModel.
- void Move(int count);
-
- // Called when the user hits shift-delete. This should determine if the item
- // can be removed from history, and if so, remove it and update the popup.
- void TryDeletingCurrentItem();
-
- // The token value for selected_line_, hover_line_ and functions dealing with
- // a "line number" that indicates "no line".
- static const size_t kNoMatch = -1;
-
- private:
- // NotificationObserver
- virtual void Observe(NotificationType type,
- const NotificationSource& source,
- const NotificationDetails& details);
-
- scoped_ptr<AutocompletePopupView> view_;
-
- AutocompleteEditModel* edit_model_;
- scoped_ptr<AutocompleteController> controller_;
-
- NotificationRegistrar registrar_;
-
- // Profile for current tab.
- Profile* profile_;
-
- // The line that's currently hovered. If we're not drawing a hover rect,
- // this will be kNoMatch, even if the cursor is over the popup contents.
- size_t hovered_line_;
-
- // The currently selected line. This is kNoMatch when nothing is selected,
- // which should only be true when the popup is closed.
- size_t selected_line_;
-
- // The match the user has manually chosen, if any.
- AutocompleteResult::Selection manually_selected_match_;
-
- // A hack for URLsForDefaultMatch() that makes the code in Observe() do
- // nothing.
- bool inside_synchronous_query_;
-
- DISALLOW_COPY_AND_ASSIGN(AutocompletePopupModel);
-};
-
-#endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_POPUP_H_
+#endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_POPUP_VIEW_H_
diff --git a/chrome/browser/autocomplete/autocomplete_popup.cc b/chrome/browser/autocomplete/autocomplete_popup_view_win.cc
index ecf29fd..dd122ee 100644..100755
--- a/chrome/browser/autocomplete/autocomplete_popup.cc
+++ b/chrome/browser/autocomplete/autocomplete_popup_view_win.cc
@@ -2,13 +2,21 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/autocomplete/autocomplete_popup.h"
+#include "chrome/browser/autocomplete/autocomplete_popup_view.h"
+// TODO(deanm): Clean up these includes, not going to fight it now.
+#include <atlbase.h>
+#include <atlapp.h>
+#include <atlcrack.h>
+#include <atlmisc.h>
#include <cmath>
#include "base/scoped_ptr.h"
#include "base/string_util.h"
+#include "base/win_util.h"
+#include "chrome/browser/autocomplete/autocomplete.h"
#include "chrome/browser/autocomplete/autocomplete_edit.h"
+#include "chrome/browser/autocomplete/autocomplete_popup_model.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/net/dns_global.h"
#include "chrome/browser/profile.h"
@@ -16,16 +24,20 @@
#include "chrome/browser/search_engines/template_url_model.h"
#include "chrome/browser/views/location_bar_view.h"
#include "chrome/common/gfx/chrome_canvas.h"
+#include "chrome/common/gfx/chrome_font.h"
#include "chrome/common/l10n_util.h"
#include "chrome/common/notification_service.h"
#include "chrome/common/resource_bundle.h"
+#include "chrome/views/view.h"
#include "grit/theme_resources.h"
#include "third_party/icu38/public/common/unicode/ubidi.h"
namespace {
+
// Padding between text and the star indicator, in pixels.
const int kStarPadding = 4;
-};
+
+} // namespace
// This class implements a utility used for mirroring x-coordinates when the
// application language is a right-to-left one.
@@ -650,335 +662,3 @@ COLORREF AutocompletePopupView::DrawLineInfo::AlphaBlend(COLORREF foreground,
((GetBValue(foreground) * alpha) +
(GetBValue(background) * (0xff - alpha))) / 0xff);
}
-
-AutocompletePopupModel::AutocompletePopupModel(
- const ChromeFont& font,
- AutocompleteEditView* edit_view,
- AutocompleteEditModel* edit_model,
- Profile* profile)
- : view_(new AutocompletePopupView(this, font, edit_view)),
- edit_model_(edit_model),
- controller_(new AutocompleteController(profile)),
- profile_(profile),
- hovered_line_(kNoMatch),
- selected_line_(kNoMatch),
- inside_synchronous_query_(false) {
- registrar_.Add(
- this,
- NotificationType::AUTOCOMPLETE_CONTROLLER_RESULT_UPDATED,
- Source<AutocompleteController>(controller_.get()));
- registrar_.Add(
- this,
- NotificationType::AUTOCOMPLETE_CONTROLLER_SYNCHRONOUS_MATCHES_AVAILABLE,
- Source<AutocompleteController>(controller_.get()));
-}
-
-AutocompletePopupModel::~AutocompletePopupModel() {
- StopAutocomplete();
-}
-
-void AutocompletePopupModel::SetProfile(Profile* profile) {
- DCHECK(profile);
- profile_ = profile;
- controller_->SetProfile(profile);
-}
-
-void AutocompletePopupModel::StartAutocomplete(
- const std::wstring& text,
- const std::wstring& desired_tld,
- bool prevent_inline_autocomplete,
- bool prefer_keyword) {
- // The user is interacting with the edit, so stop tracking hover.
- SetHoveredLine(kNoMatch);
-
- manually_selected_match_.Clear();
-
- controller_->Start(text, desired_tld, prevent_inline_autocomplete,
- prefer_keyword, false);
-}
-
-void AutocompletePopupModel::StopAutocomplete() {
- controller_->Stop(true);
- SetHoveredLine(kNoMatch);
- selected_line_ = kNoMatch;
- view_->UpdatePopupAppearance();
-}
-
-void AutocompletePopupModel::SetHoveredLine(size_t line) {
- const bool is_disabling = (line == kNoMatch);
- DCHECK(is_disabling || (line < controller_->result().size()));
-
- if (line == hovered_line_)
- return; // Nothing to do
-
- // Make sure the old hovered line is redrawn. No need to redraw the selected
- // line since selection overrides hover so the appearance won't change.
- const bool is_enabling = (hovered_line_ == kNoMatch);
- if (!is_enabling && (hovered_line_ != selected_line_))
- view_->InvalidateLine(hovered_line_);
-
- // Change the hover to the new line and make sure it's redrawn.
- hovered_line_ = line;
- if (!is_disabling && (hovered_line_ != selected_line_))
- view_->InvalidateLine(hovered_line_);
-
- if (is_enabling || is_disabling)
- view_->OnHoverEnabledOrDisabled(is_disabling);
-}
-
-void AutocompletePopupModel::SetSelectedLine(size_t line,
- bool reset_to_default) {
- const AutocompleteResult& result = controller_->result();
- DCHECK(line < result.size());
- if (result.empty())
- return;
-
- // Cancel the query so the matches don't change on the user.
- controller_->Stop(false);
-
- const AutocompleteMatch& match = result.match_at(line);
- if (reset_to_default) {
- manually_selected_match_.Clear();
- } else {
- // Track the user's selection until they cancel it.
- manually_selected_match_.destination_url = match.destination_url;
- manually_selected_match_.provider_affinity = match.provider;
- manually_selected_match_.is_history_what_you_typed_match =
- match.is_history_what_you_typed_match;
- }
-
- if (line == selected_line_)
- return; // Nothing else to do.
-
- // Update the edit with the new data for this match.
- std::wstring keyword;
- const bool is_keyword_hint = GetKeywordForMatch(match, &keyword);
- edit_model_->OnPopupDataChanged(
- reset_to_default ? std::wstring() : match.fill_into_edit,
- !reset_to_default, keyword, is_keyword_hint, match.type);
-
- // Repaint old and new selected lines immediately, so that the edit doesn't
- // appear to update [much] faster than the popup. We must not update
- // |selected_line_| before calling OnPopupDataChanged() (since the edit may
- // call us back to get data about the old selection), and we must not call
- // UpdateWindow() before updating |selected_line_| (since the paint routine
- // relies on knowing the correct selected line).
- view_->InvalidateLine(selected_line_);
- selected_line_ = line;
- view_->InvalidateLine(selected_line_);
- view_->UpdateWindow();
-}
-
-void AutocompletePopupModel::ResetToDefaultMatch() {
- const AutocompleteResult& result = controller_->result();
- DCHECK(!result.empty());
- SetSelectedLine(result.default_match() - result.begin(), true);
-}
-
-GURL AutocompletePopupModel::URLsForCurrentSelection(
- PageTransition::Type* transition,
- bool* is_history_what_you_typed_match,
- GURL* alternate_nav_url) const {
- // We need to use the result on the controller, because if the popup is open,
- // the user changes the contents of the edit, and then presses enter before
- // any results have been displayed, results_ will be nonempty but wrong. (In
- // most other cases, the controller's results will match the popup's.)
- // TODO(pkasting): If manually_selected_match_ moves to the controller, this
- // can move to the edit.
- if (controller_->result().empty())
- return GURL();
-
- const AutocompleteResult& result = controller_->result();
- AutocompleteResult::const_iterator match;
- if (!controller_->done()) {
- // The user cannot have manually selected a match, or the query would have
- // stopped. So the default match must be the desired selection.
- match = result.default_match();
- } else {
- // The query isn't running, so the popup can't possibly be out of date.
- DCHECK(selected_line_ < result.size());
- match = result.begin() + selected_line_;
- }
- if (transition)
- *transition = match->transition;
- if (is_history_what_you_typed_match)
- *is_history_what_you_typed_match = match->is_history_what_you_typed_match;
- if (alternate_nav_url && manually_selected_match_.empty())
- *alternate_nav_url = result.GetAlternateNavURL(controller_->input(), match);
- return match->destination_url;
-}
-
-GURL AutocompletePopupModel::URLsForDefaultMatch(
- const std::wstring& text,
- const std::wstring& desired_tld,
- PageTransition::Type* transition,
- bool* is_history_what_you_typed_match,
- GURL* alternate_nav_url) {
- // We had better not already be doing anything, or this call will blow it
- // away.
- DCHECK(!is_open());
- DCHECK(controller_->done());
-
- // Run the new query and get only the synchronously available matches.
- inside_synchronous_query_ = true; // Tell Observe() not to notify the edit or
- // update our appearance.
- controller_->Start(text, desired_tld, true, false, true);
- inside_synchronous_query_ = false;
- DCHECK(controller_->done());
- const AutocompleteResult& result = controller_->result();
- if (result.empty())
- return GURL();
-
- // Get the URLs for the default match.
- const AutocompleteResult::const_iterator match = result.default_match();
- if (transition)
- *transition = match->transition;
- if (is_history_what_you_typed_match)
- *is_history_what_you_typed_match = match->is_history_what_you_typed_match;
- if (alternate_nav_url)
- *alternate_nav_url = result.GetAlternateNavURL(controller_->input(), match);
- return match->destination_url;
-}
-
-bool AutocompletePopupModel::GetKeywordForMatch(const AutocompleteMatch& match,
- std::wstring* keyword) const {
- // Assume we have no keyword until we find otherwise.
- keyword->clear();
-
- // If the current match is a keyword, return that as the selected keyword.
- if (match.template_url && match.template_url->url() &&
- match.template_url->url()->SupportsReplacement()) {
- keyword->assign(match.template_url->keyword());
- return false;
- }
-
- // See if the current match's fill_into_edit corresponds to a keyword.
- if (!profile_->GetTemplateURLModel())
- return false;
- profile_->GetTemplateURLModel()->Load();
- const std::wstring keyword_hint(
- TemplateURLModel::CleanUserInputKeyword(match.fill_into_edit));
- if (keyword_hint.empty())
- return false;
-
- // Don't provide a hint if this keyword doesn't support replacement.
- const TemplateURL* const template_url =
- profile_->GetTemplateURLModel()->GetTemplateURLForKeyword(keyword_hint);
- if (!template_url || !template_url->url() ||
- !template_url->url()->SupportsReplacement())
- return false;
-
- keyword->assign(keyword_hint);
- return true;
-}
-
-AutocompleteLog* AutocompletePopupModel::GetAutocompleteLog() {
- return new AutocompleteLog(controller_->input().text(),
- controller_->input().type(), selected_line_, 0, controller_->result());
-}
-
-void AutocompletePopupModel::Move(int count) {
- // TODO(pkasting): Temporary hack. If the query is running while the popup is
- // open, we might be showing the results of the previous query still. Force
- // the popup to display the latest results so the popup and the controller
- // aren't out of sync. The better fix here is to roll the controller back to
- // be in sync with what the popup is showing.
- if (is_open() && !controller_->done()) {
- Observe(NotificationType::AUTOCOMPLETE_CONTROLLER_RESULT_UPDATED,
- Source<AutocompleteController>(controller_.get()),
- NotificationService::NoDetails());
- }
-
- const AutocompleteResult& result = controller_->result();
- if (result.empty())
- return;
-
- // The user is using the keyboard to change the selection, so stop tracking
- // hover.
- SetHoveredLine(kNoMatch);
-
- // Clamp the new line to [0, result_.count() - 1].
- const size_t new_line = selected_line_ + count;
- SetSelectedLine((((count < 0) && (new_line >= selected_line_)) ?
- 0 : std::min(new_line, result.size() - 1)), false);
-}
-
-void AutocompletePopupModel::TryDeletingCurrentItem() {
- // We could use URLsForCurrentSelection() here, but it seems better to try
- // and shift-delete the actual selection, rather than any "in progress, not
- // yet visible" one.
- if (selected_line_ == kNoMatch)
- return;
- const AutocompleteMatch& match =
- controller_->result().match_at(selected_line_);
- if (match.deletable) {
- const size_t selected_line = selected_line_;
- controller_->DeleteMatch(match); // This will synchronously notify us that
- // the results have changed.
- const AutocompleteResult& result = controller_->result();
- if (!result.empty()) {
- // Move the selection to the next choice after the deleted one.
- // TODO(pkasting): Eventually the controller should take care of this
- // before notifying us, reducing flicker. At that point the check for
- // deletability can move there too.
- SetSelectedLine(std::min(result.size() - 1, selected_line), false);
- }
- }
-}
-
-void AutocompletePopupModel::Observe(NotificationType type,
- const NotificationSource& source,
- const NotificationDetails& details) {
- if (inside_synchronous_query_)
- return;
-
- const AutocompleteResult& result = controller_->result();
- switch (type.value) {
- case NotificationType::AUTOCOMPLETE_CONTROLLER_RESULT_UPDATED: {
- selected_line_ = (result.default_match() == result.end()) ?
- kNoMatch : (result.default_match() - result.begin());
- // If we're going to trim the window size to no longer include the hovered
- // line, turn hover off. Practically, this shouldn't happen, but it
- // doesn't hurt to be defensive.
- if ((hovered_line_ != kNoMatch) && (result.size() <= hovered_line_))
- SetHoveredLine(kNoMatch);
-
- view_->UpdatePopupAppearance();
- }
- // FALL THROUGH
-
- case NotificationType::AUTOCOMPLETE_CONTROLLER_SYNCHRONOUS_MATCHES_AVAILABLE: {
- // Update the edit with the possibly new data for this match.
- // NOTE: This must be done after the code above, so that our internal
- // state will be consistent when the edit calls back to
- // URLsForCurrentSelection().
- std::wstring inline_autocomplete_text;
- std::wstring keyword;
- bool is_keyword_hint = false;
- AutocompleteMatch::Type type = AutocompleteMatch::SEARCH_WHAT_YOU_TYPED;
- const AutocompleteResult::const_iterator match(result.default_match());
- if (match != result.end()) {
- if ((match->inline_autocomplete_offset != std::wstring::npos) &&
- (match->inline_autocomplete_offset <
- match->fill_into_edit.length())) {
- inline_autocomplete_text =
- match->fill_into_edit.substr(match->inline_autocomplete_offset);
- }
- // Warm up DNS Prefetch Cache.
- chrome_browser_net::DnsPrefetchUrl(match->destination_url);
- // We could prefetch the alternate nav URL, if any, but because there
- // can be many of these as a user types an initial series of characters,
- // the OS DNS cache could suffer eviction problems for minimal gain.
-
- is_keyword_hint = GetKeywordForMatch(*match, &keyword);
- type = match->type;
- }
- edit_model_->OnPopupDataChanged(inline_autocomplete_text, false, keyword,
- is_keyword_hint, type);
- return;
- }
-
- default:
- NOTREACHED();
- }
-} \ No newline at end of file
diff --git a/chrome/browser/browser.scons b/chrome/browser/browser.scons
index 1110e62..6bce4d9 100644
--- a/chrome/browser/browser.scons
+++ b/chrome/browser/browser.scons
@@ -58,8 +58,10 @@ input_files = ChromeFileList([
'autocomplete/autocomplete_accessibility.h',
'autocomplete/autocomplete_edit.cc',
'autocomplete/autocomplete_edit.h',
- 'autocomplete/autocomplete_popup.cc',
- 'autocomplete/autocomplete_popup.h',
+ 'autocomplete/autocomplete_popup_model.cc',
+ 'autocomplete/autocomplete_popup_model.h',
+ 'autocomplete/autocomplete_popup_view_win.cc',
+ 'autocomplete/autocomplete_popup_view.h',
'autocomplete/edit_drop_target.cc',
'autocomplete/edit_drop_target.h',
'autocomplete/history_contents_provider.cc',
@@ -664,7 +666,8 @@ if not env.Bit('windows'):
'app_modal_dialog_queue.cc',
'autocomplete/autocomplete_accessibility.cc',
'autocomplete/autocomplete_edit.cc',
- 'autocomplete/autocomplete_popup.cc',
+ 'autocomplete/autocomplete_popup_model.cc',
+ 'autocomplete/autocomplete_popup_view_win.cc',
'autocomplete/edit_drop_target.cc',
'automation/ui_controls.cc',
'browser_accessibility.cc',
diff --git a/chrome/browser/browser.vcproj b/chrome/browser/browser.vcproj
index f618fbe..1325f66 100644
--- a/chrome/browser/browser.vcproj
+++ b/chrome/browser/browser.vcproj
@@ -158,11 +158,19 @@
>
</File>
<File
- RelativePath=".\autocomplete\autocomplete_popup.cc"
+ RelativePath=".\autocomplete\autocomplete_popup_model.cc"
>
</File>
<File
- RelativePath=".\autocomplete\autocomplete_popup.h"
+ RelativePath=".\autocomplete\autocomplete_popup_model.h"
+ >
+ </File>
+ <File
+ RelativePath=".\autocomplete\autocomplete_popup_view_win.cc"
+ >
+ </File>
+ <File
+ RelativePath=".\autocomplete\autocomplete_popup_view.h"
>
</File>
<File
diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp
index ebaef18..c0dc19c 100644
--- a/chrome/chrome.gyp
+++ b/chrome/chrome.gyp
@@ -329,8 +329,10 @@
'browser/autocomplete/autocomplete_accessibility.h',
'browser/autocomplete/autocomplete_edit.cc',
'browser/autocomplete/autocomplete_edit.h',
- 'browser/autocomplete/autocomplete_popup.cc',
- 'browser/autocomplete/autocomplete_popup.h',
+ 'browser/autocomplete/autocomplete_popup_model.cc',
+ 'browser/autocomplete/autocomplete_popup_model.h',
+ 'browser/autocomplete/autocomplete_popup_view_win.cc',
+ 'browser/autocomplete/autocomplete_popup_view.h',
'browser/autocomplete/edit_drop_target.cc',
'browser/autocomplete/edit_drop_target.h',
'browser/autocomplete/history_contents_provider.cc',
@@ -1160,7 +1162,8 @@
'sources!': [
'browser/autocomplete/autocomplete_accessibility.cc',
'browser/autocomplete/autocomplete_edit.cc',
- 'browser/autocomplete/autocomplete_popup.cc',
+ 'browser/autocomplete/autocomplete_popup_model.cc',
+ 'browser/autocomplete/autocomplete_popup_view_win.cc',
'browser/autocomplete/edit_drop_target.cc',
'browser/bookmarks/bookmark_context_menu.cc',
'browser/bookmarks/bookmark_drop_info.cc',