summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/autocomplete/autocomplete.cc64
-rw-r--r--chrome/browser/autocomplete/autocomplete.h36
-rw-r--r--chrome/browser/autocomplete/autocomplete_classifier.cc34
-rw-r--r--chrome/browser/autocomplete/autocomplete_classifier.h43
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit.cc111
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit.h36
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view.h3
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc6
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_gtk.h2
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_mac.h3
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_mac.mm6
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_win.cc6
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_win.h2
-rw-r--r--chrome/browser/autocomplete/autocomplete_popup_model.cc52
-rw-r--r--chrome/browser/autocomplete/autocomplete_popup_model.h20
-rw-r--r--chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc52
-rw-r--r--chrome/browser/autocomplete/autocomplete_popup_view_mac.mm43
-rw-r--r--chrome/browser/autocomplete/search_provider.cc4
-rw-r--r--chrome/browser/cocoa/autocomplete_text_field_cell.h15
-rw-r--r--chrome/browser/cocoa/autocomplete_text_field_cell.mm22
-rw-r--r--chrome/browser/cocoa/autocomplete_text_field_cell_unittest.mm45
-rw-r--r--chrome/browser/cocoa/autocomplete_text_field_unittest.mm47
-rw-r--r--chrome/browser/cocoa/location_bar_view_mac.h37
-rw-r--r--chrome/browser/cocoa/location_bar_view_mac.mm80
-rw-r--r--chrome/browser/cocoa/tab_strip_controller_unittest.mm6
-rw-r--r--chrome/browser/gtk/location_bar_view_gtk.cc103
-rw-r--r--chrome/browser/gtk/location_bar_view_gtk.h21
-rw-r--r--chrome/browser/profile.cc17
-rw-r--r--chrome/browser/profile.h15
-rw-r--r--chrome/browser/search_versus_navigate_classifier.cc56
-rw-r--r--chrome/browser/search_versus_navigate_classifier.h52
-rw-r--r--chrome/browser/tab_contents/render_view_context_menu.cc20
-rw-r--r--chrome/browser/toolbar_model.cc4
-rw-r--r--chrome/browser/toolbar_model.h6
-rw-r--r--chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc84
-rw-r--r--chrome/browser/views/frame/browser_root_view.cc15
-rw-r--r--chrome/browser/views/location_bar_view.cc336
-rw-r--r--chrome/browser/views/location_bar_view.h41
-rwxr-xr-xchrome/chrome_browser.gypi4
-rw-r--r--chrome/test/testing_profile.cc6
-rw-r--r--chrome/test/testing_profile.h15
41 files changed, 678 insertions, 892 deletions
diff --git a/chrome/browser/autocomplete/autocomplete.cc b/chrome/browser/autocomplete/autocomplete.cc
index 2167ea2..db1655b 100644
--- a/chrome/browser/autocomplete/autocomplete.cc
+++ b/chrome/browser/autocomplete/autocomplete.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 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.
@@ -27,6 +27,7 @@
#include "googleurl/src/url_canon_ip.h"
#include "googleurl/src/url_util.h"
#include "grit/generated_resources.h"
+#include "grit/theme_resources.h"
#include "net/base/net_util.h"
#include "net/base/registry_controlled_domain.h"
#include "net/url_request/url_request.h"
@@ -367,6 +368,18 @@ void AutocompleteInput::Clear() {
// AutocompleteMatch ----------------------------------------------------------
+AutocompleteMatch::AutocompleteMatch()
+ : provider(NULL),
+ relevance(0),
+ deletable(false),
+ inline_autocomplete_offset(std::wstring::npos),
+ transition(PageTransition::GENERATED),
+ is_history_what_you_typed_match(false),
+ type(SEARCH_WHAT_YOU_TYPED),
+ template_url(NULL),
+ starred(false) {
+}
+
AutocompleteMatch::AutocompleteMatch(AutocompleteProvider* provider,
int relevance,
bool deletable,
@@ -384,23 +397,40 @@ AutocompleteMatch::AutocompleteMatch(AutocompleteProvider* provider,
// static
std::string AutocompleteMatch::TypeToString(Type type) {
- switch (type) {
- case URL_WHAT_YOU_TYPED: return "url-what-you-typed";
- case HISTORY_URL: return "history-url";
- case HISTORY_TITLE: return "history-title";
- case HISTORY_BODY: return "history-body";
- case HISTORY_KEYWORD: return "history-keyword";
- case NAVSUGGEST: return "navsuggest";
- case SEARCH_WHAT_YOU_TYPED: return "search-what-you-typed";
- case SEARCH_HISTORY: return "search-history";
- case SEARCH_SUGGEST: return "search-suggest";
- case SEARCH_OTHER_ENGINE: return "search-other-engine";
- case OPEN_HISTORY_PAGE: return "open-history-page";
+ const char* strings[NUM_TYPES] = {
+ "url-what-you-typed",
+ "history-url",
+ "history-title",
+ "history-body",
+ "history-keyword",
+ "navsuggest",
+ "search-what-you-typed",
+ "search-history",
+ "search-suggest",
+ "search-other-engine",
+ "open-history-page",
+ };
+ DCHECK(arraysize(strings) == NUM_TYPES);
+ return strings[type];
+}
- default:
- NOTREACHED();
- return std::string();
- }
+// static
+int AutocompleteMatch::TypeToIcon(Type type) {
+ int icons[NUM_TYPES] = {
+ IDR_O2_GLOBE,
+ IDR_O2_GLOBE,
+ IDR_O2_HISTORY,
+ IDR_O2_HISTORY,
+ IDR_O2_HISTORY,
+ IDR_O2_GLOBE,
+ IDR_O2_SEARCH,
+ IDR_O2_SEARCH,
+ IDR_O2_SEARCH,
+ IDR_O2_SEARCH,
+ IDR_O2_MORE,
+ };
+ DCHECK(arraysize(icons) == NUM_TYPES);
+ return icons[type];
}
// static
diff --git a/chrome/browser/autocomplete/autocomplete.h b/chrome/browser/autocomplete/autocomplete.h
index d64fd6c..124783f1 100644
--- a/chrome/browser/autocomplete/autocomplete.h
+++ b/chrome/browser/autocomplete/autocomplete.h
@@ -314,22 +314,24 @@ struct AutocompleteMatch {
// The type of this match.
enum Type {
- URL_WHAT_YOU_TYPED, // The input as a URL.
- HISTORY_URL, // A past page whose URL contains the input.
- HISTORY_TITLE, // A past page whose title contains the input.
- HISTORY_BODY, // A past page whose body contains the input.
- HISTORY_KEYWORD, // A past page whose keyword contains the input.
- NAVSUGGEST, // A suggested URL.
- SEARCH_WHAT_YOU_TYPED, // The input as a search query (with the default
- // engine).
- SEARCH_HISTORY, // A past search (with the default engine)
- // containing the input.
- SEARCH_SUGGEST, // A suggested search (with the default engine).
- SEARCH_OTHER_ENGINE, // A search with a non-default engine.
- OPEN_HISTORY_PAGE, // A synthetic result that opens the history page to
- // search for the input.
+ URL_WHAT_YOU_TYPED = 0, // The input as a URL.
+ HISTORY_URL, // A past page whose URL contains the input.
+ HISTORY_TITLE, // A past page whose title contains the input.
+ HISTORY_BODY, // A past page whose body contains the input.
+ HISTORY_KEYWORD, // A past page whose keyword contains the input.
+ NAVSUGGEST, // A suggested URL.
+ SEARCH_WHAT_YOU_TYPED, // The input as a search query (with the default
+ // engine).
+ SEARCH_HISTORY, // A past search (with the default engine)
+ // containing the input.
+ SEARCH_SUGGEST, // A suggested search (with the default engine).
+ SEARCH_OTHER_ENGINE, // A search with a non-default engine.
+ OPEN_HISTORY_PAGE, // A synthetic result that opens the history page
+ // to search for the input.
+ NUM_TYPES,
};
+ AutocompleteMatch();
AutocompleteMatch(AutocompleteProvider* provider,
int relevance,
bool deletable,
@@ -338,6 +340,10 @@ struct AutocompleteMatch {
// Converts |type| to a string representation. Used in logging.
static std::string TypeToString(Type type);
+ // Converts |type| to a resource identifier for the appropriate icon for this
+ // type.
+ static int TypeToIcon(Type type);
+
// Comparison function for determining when one match is better than another.
static bool MoreRelevant(const AutocompleteMatch& elem1,
const AutocompleteMatch& elem2);
@@ -776,7 +782,7 @@ class AutocompleteController : public ACProviderListener {
const AutocompleteInput& input() const { return input_; }
const AutocompleteResult& result() const { return result_; }
// This next is temporary and should go away when
- // AutocompletePopup::URLsForCurrentSelection() moves to the controller.
+ // AutocompletePopup::InfoForCurrentSelection() moves to the controller.
const AutocompleteResult& latest_result() const { return latest_result_; }
bool done() const { return done_ && !update_delay_timer_.IsRunning(); }
diff --git a/chrome/browser/autocomplete/autocomplete_classifier.cc b/chrome/browser/autocomplete/autocomplete_classifier.cc
new file mode 100644
index 0000000..3e96ff5
--- /dev/null
+++ b/chrome/browser/autocomplete/autocomplete_classifier.cc
@@ -0,0 +1,34 @@
+// Copyright (c) 2010 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_classifier.h"
+
+#include "chrome/browser/autocomplete/autocomplete.h"
+#include "googleurl/src/gurl.h"
+
+AutocompleteClassifier::AutocompleteClassifier(Profile* profile)
+ : controller_(new AutocompleteController(profile)) {
+}
+
+AutocompleteClassifier::~AutocompleteClassifier() {
+}
+
+void AutocompleteClassifier::Classify(const std::wstring& text,
+ const std::wstring& desired_tld,
+ AutocompleteMatch* match,
+ GURL* alternate_nav_url) {
+ controller_->Start(text, desired_tld, true, false, true);
+ DCHECK(controller_->done());
+ const AutocompleteResult& result = controller_->result();
+ if (result.empty()) {
+ if (alternate_nav_url)
+ *alternate_nav_url = GURL();
+ return;
+ }
+
+ DCHECK(result.default_match() != result.end());
+ *match = *result.default_match();
+ if (alternate_nav_url)
+ *alternate_nav_url = result.alternate_nav_url();
+}
diff --git a/chrome/browser/autocomplete/autocomplete_classifier.h b/chrome/browser/autocomplete/autocomplete_classifier.h
new file mode 100644
index 0000000..3588c27
--- /dev/null
+++ b/chrome/browser/autocomplete/autocomplete_classifier.h
@@ -0,0 +1,43 @@
+// Copyright (c) 2010 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_CLASSIFIER_H_
+#define CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_CLASSIFIER_H_
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/scoped_ptr.h"
+
+class AutocompleteController;
+struct AutocompleteMatch;
+class GURL;
+class Profile;
+
+class AutocompleteClassifier {
+ public:
+ explicit AutocompleteClassifier(Profile* profile);
+ virtual ~AutocompleteClassifier();
+
+ // Given some string |text| that the user wants to use for navigation,
+ // determines how it should be interpreted. |desired_tld| is the user's
+ // desired TLD, if any; see AutocompleteInput::desired_tld(). |match| should
+ // be a non-NULL outparam that will be set to the default match for this
+ // input, if any (for invalid input, there will be no default match, and
+ // |match| will be left unchanged). |alternate_nav_url| is a possibly-NULL
+ // outparam that, if non-NULL, will be set to the navigational URL (if any) in
+ // case of an accidental search; see comments on
+ // AutocompleteResult::alternate_nav_url_ in autocomplete.h.
+ void Classify(const std::wstring& text,
+ const std::wstring& desired_tld,
+ AutocompleteMatch* match,
+ GURL* alternate_nav_url);
+
+ private:
+ scoped_ptr<AutocompleteController> controller_;
+
+ DISALLOW_IMPLICIT_CONSTRUCTORS(AutocompleteClassifier);
+};
+
+#endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_CLASSIFIER_H_
diff --git a/chrome/browser/autocomplete/autocomplete_edit.cc b/chrome/browser/autocomplete/autocomplete_edit.cc
index f4c2583..22c6802 100644
--- a/chrome/browser/autocomplete/autocomplete_edit.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 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.
@@ -9,6 +9,7 @@
#include "base/basictypes.h"
#include "base/utf_string_conversions.h"
#include "chrome/app/chrome_dll_resource.h"
+#include "chrome/browser/autocomplete/autocomplete_classifier.h"
#include "chrome/browser/autocomplete/autocomplete_edit_view.h"
#include "chrome/browser/autocomplete/autocomplete_popup_model.h"
#include "chrome/browser/autocomplete/keyword_provider.h"
@@ -19,7 +20,6 @@
#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/search_versus_navigate_classifier.h"
#include "chrome/common/notification_service.h"
#include "googleurl/src/gurl.h"
#include "googleurl/src/url_util.h"
@@ -122,7 +122,9 @@ void AutocompleteEditModel::SetUserText(const std::wstring& text) {
void AutocompleteEditModel::GetDataForURLExport(GURL* url,
std::wstring* title,
SkBitmap* favicon) {
- *url = GetURLForCurrentText(NULL, NULL, NULL);
+ AutocompleteMatch match;
+ GetInfoForCurrentText(&match, NULL);
+ *url = match.destination_url;
if (UTF8ToWide(url->possibly_invalid_spec()) == permanent_text_) {
*title = controller_->GetTitle();
*favicon = controller_->GetFavIcon();
@@ -134,7 +136,7 @@ std::wstring AutocompleteEditModel::GetDesiredTLD() const {
std::wstring(L"com") : std::wstring();
}
-bool AutocompleteEditModel::CurrentTextIsURL() {
+bool AutocompleteEditModel::CurrentTextIsURL() const {
// If !user_input_in_progress_, the permanent text is showing, which should
// always be a URL, so no further checking is needed. By avoiding checking in
// this case, we avoid calling into the autocomplete providers, and thus
@@ -142,9 +144,15 @@ bool AutocompleteEditModel::CurrentTextIsURL() {
if (!user_input_in_progress_)
return true;
- PageTransition::Type transition = PageTransition::LINK;
- GetURLForCurrentText(&transition, NULL, NULL);
- return transition == PageTransition::TYPED;
+ AutocompleteMatch match;
+ GetInfoForCurrentText(&match, NULL);
+ return match.transition == PageTransition::TYPED;
+}
+
+AutocompleteMatch::Type AutocompleteEditModel::CurrentTextType() const {
+ AutocompleteMatch match;
+ GetInfoForCurrentText(&match, NULL);
+ return match.type;
}
bool AutocompleteEditModel::GetURLForText(const std::wstring& text,
@@ -191,14 +199,11 @@ bool AutocompleteEditModel::CanPasteAndGo(const std::wstring& text) const {
if (!view_->GetCommandUpdater()->IsCommandEnabled(IDC_OPEN_CURRENT_URL))
return false;
- paste_and_go_url_ = GURL();
- paste_and_go_transition_ = PageTransition::TYPED;
- paste_and_go_alternate_nav_url_ = GURL();
-
- profile_->GetSearchVersusNavigateClassifier()->Classify(text, std::wstring(),
- NULL, &paste_and_go_url_, &paste_and_go_transition_, NULL,
- &paste_and_go_alternate_nav_url_);
-
+ AutocompleteMatch match;
+ profile_->GetAutocompleteClassifier()->Classify(text, std::wstring(),
+ &match, &paste_and_go_alternate_nav_url_);
+ paste_and_go_url_ = match.destination_url;
+ paste_and_go_transition_ = match.transition;
return paste_and_go_url_.is_valid();
}
@@ -215,33 +220,30 @@ void AutocompleteEditModel::PasteAndGo() {
void AutocompleteEditModel::AcceptInput(WindowOpenDisposition disposition,
bool for_drop) {
// Get the URL and transition type for the selected entry.
- PageTransition::Type transition;
- bool is_history_what_you_typed_match;
+ AutocompleteMatch match;
GURL alternate_nav_url;
- const GURL url(GetURLForCurrentText(&transition,
- &is_history_what_you_typed_match,
- &alternate_nav_url));
- if (!url.is_valid())
+ GetInfoForCurrentText(&match, &alternate_nav_url);
+ if (!match.destination_url.is_valid())
return;
- if (UTF8ToWide(url.spec()) == permanent_text_) {
+ if (UTF8ToWide(match.destination_url.spec()) == permanent_text_) {
// When the user hit enter on the existing permanent URL, treat it like a
// reload for scoring purposes. We could detect this by just checking
// user_input_in_progress_, but it seems better to treat "edits" that end
// up leaving the URL unchanged (e.g. deleting the last character and then
// retyping it) as reloads too.
- transition = PageTransition::RELOAD;
+ match.transition = PageTransition::RELOAD;
} else if (for_drop || ((paste_state_ != NONE) &&
- is_history_what_you_typed_match)) {
+ match.is_history_what_you_typed_match)) {
// When the user pasted in a URL and hit enter, score it like a link click
// rather than a normal typed URL, so it doesn't get inline autocompleted
// as aggressively later.
- transition = PageTransition::LINK;
+ match.transition = PageTransition::LINK;
}
- view_->OpenURL(url, disposition, transition, alternate_nav_url,
- AutocompletePopupModel::kNoMatch,
- is_keyword_hint_ ? std::wstring() : keyword_);
+ view_->OpenURL(match.destination_url, disposition, match.transition,
+ alternate_nav_url, AutocompletePopupModel::kNoMatch,
+ is_keyword_hint_ ? std::wstring() : keyword_);
}
void AutocompleteEditModel::SendOpenNotification(size_t selected_line,
@@ -325,17 +327,20 @@ void AutocompleteEditModel::OnKillFocus() {
}
bool AutocompleteEditModel::OnEscapeKeyPressed() {
- if (has_temporary_text_ &&
- (popup_->URLsForCurrentSelection(NULL, NULL, NULL) != original_url_)) {
- // The user typed something, then selected a different item. Restore the
- // text they typed and change back to the default item.
- // NOTE: This purposefully does not reset paste_state_.
- just_deleted_text_ = false;
- has_temporary_text_ = false;
- keyword_ui_state_ = original_keyword_ui_state_;
- popup_->ResetToDefaultMatch();
- view_->OnRevertTemporaryText();
- return true;
+ if (has_temporary_text_) {
+ AutocompleteMatch match;
+ popup_->InfoForCurrentSelection(&match, NULL);
+ if (match.destination_url != original_url_) {
+ // The user typed something, then selected a different item. Restore the
+ // text they typed and change back to the default item.
+ // NOTE: This purposefully does not reset paste_state_.
+ just_deleted_text_ = false;
+ has_temporary_text_ = false;
+ keyword_ui_state_ = original_keyword_ui_state_;
+ popup_->ResetToDefaultMatch();
+ view_->OnRevertTemporaryText();
+ return true;
+ }
}
// If the user wasn't editing, but merely had focus in the edit, allow <esc>
@@ -405,7 +410,7 @@ void AutocompleteEditModel::OnUpOrDownKeyPressed(int count) {
void AutocompleteEditModel::OnPopupDataChanged(
const std::wstring& text,
- bool is_temporary_text,
+ GURL* destination_for_temporary_text_change,
const std::wstring& keyword,
bool is_keyword_hint,
AutocompleteMatch::Type type) {
@@ -428,12 +433,12 @@ void AutocompleteEditModel::OnPopupDataChanged(
}
// Handle changes to temporary text.
- if (is_temporary_text) {
+ if (destination_for_temporary_text_change != NULL) {
const bool save_original_selection = !has_temporary_text_;
if (save_original_selection) {
// Save the original selection and URL so it can be reverted later.
has_temporary_text_ = true;
- original_url_ = popup_->URLsForCurrentSelection(NULL, NULL, NULL);
+ original_url_ = *destination_for_temporary_text_change;
original_keyword_ui_state_ = keyword_ui_state_;
}
if (control_key_state_ == DOWN_WITHOUT_CHANGE) {
@@ -562,7 +567,7 @@ void AutocompleteEditModel::Observe(NotificationType type,
match_type = match->type;
}
- OnPopupDataChanged(inline_autocomplete_text, false, keyword, is_keyword_hint,
+ OnPopupDataChanged(inline_autocomplete_text, NULL, keyword, is_keyword_hint,
match_type);
}
@@ -586,20 +591,14 @@ std::wstring AutocompleteEditModel::UserTextFromDisplayText(
text : (keyword_ + L" " + text);
}
-GURL AutocompleteEditModel::GetURLForCurrentText(
- PageTransition::Type* transition,
- bool* is_history_what_you_typed_match,
+void AutocompleteEditModel::GetInfoForCurrentText(
+ AutocompleteMatch* match,
GURL* alternate_nav_url) const {
if (popup_->IsOpen() || query_in_progress()) {
- return popup_->URLsForCurrentSelection(transition,
- is_history_what_you_typed_match,
- alternate_nav_url);
+ popup_->InfoForCurrentSelection(match, alternate_nav_url);
+ } else {
+ profile_->GetAutocompleteClassifier()->Classify(
+ UserTextFromDisplayText(view_->GetText()), GetDesiredTLD(), match,
+ alternate_nav_url);
}
-
- GURL destination_url;
- profile_->GetSearchVersusNavigateClassifier()->Classify(
- UserTextFromDisplayText(view_->GetText()), GetDesiredTLD(), NULL,
- &destination_url, transition, is_history_what_you_typed_match,
- alternate_nav_url);
- return destination_url;
}
diff --git a/chrome/browser/autocomplete/autocomplete_edit.h b/chrome/browser/autocomplete/autocomplete_edit.h
index 1a0386c..96a86c7 100644
--- a/chrome/browser/autocomplete/autocomplete_edit.h
+++ b/chrome/browser/autocomplete/autocomplete_edit.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 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.
@@ -137,7 +137,10 @@ class AutocompleteEditModel : public NotificationObserver {
// Returns true if the current edit contents will be treated as a
// URL/navigation, as opposed to a search.
- bool CurrentTextIsURL();
+ bool CurrentTextIsURL() const;
+
+ // Returns the match type for the current edit contents.
+ AutocompleteMatch::Type CurrentTextType() const;
// Returns true if |text| (which is display text in the current context)
// parses as a URL, and in that case sets |url| to the calculated URL.
@@ -208,7 +211,7 @@ class AutocompleteEditModel : public NotificationObserver {
// Accessors for keyword-related state (see comments on keyword_ and
// is_keyword_hint_).
std::wstring keyword() const {
- return (is_keyword_hint_ ? has_focus_ : (keyword_ui_state_ != NO_KEYWORD)) ?
+ return (is_keyword_hint_ || (keyword_ui_state_ != NO_KEYWORD)) ?
keyword_ : std::wstring();
}
bool is_keyword_hint() const { return is_keyword_hint_; }
@@ -222,7 +225,7 @@ class AutocompleteEditModel : public NotificationObserver {
// True if we should show the "Type to search" hint (see comments on
// show_search_hint_).
- bool show_search_hint() const { return has_focus_ && show_search_hint_; }
+ bool show_search_hint() const { return show_search_hint_; }
// Returns true if a query to an autocomplete provider is currently
// in progress. This logic should in the future live in
@@ -260,9 +263,12 @@ class AutocompleteEditModel : public NotificationObserver {
// Called when any relevant data changes. This rolls together several
// separate pieces of data into one call so we can update all the UI
// efficiently:
- // |text| is either the new temporary text (if |is_temporary_text| is true)
- // from the user manually selecting a different match, or the inline
- // autocomplete text (if |is_temporary_text| is false).
+ // |text| is either the new temporary text from the user manually selecting
+ // a different match, or the inline autocomplete text. We distinguish by
+ // checking if |destination_for_temporary_text_change| is NULL.
+ // |destination_for_temporary_text_change| is NULL (if temporary text should
+ // not change) or the pre-change desitnation URL (if temporary text should
+ // change) so we can save it off to restore later.
// |keyword| is the keyword to show a hint for if |is_keyword_hint| is true,
// or the currently selected keyword if |is_keyword_hint| is false (see
// comments on keyword_ and is_keyword_hint_).
@@ -271,7 +277,7 @@ class AutocompleteEditModel : public NotificationObserver {
// show_search_hint_).
void OnPopupDataChanged(
const std::wstring& text,
- bool is_temporary_text,
+ GURL* destination_for_temporary_text_change,
const std::wstring& keyword,
bool is_keyword_hint,
AutocompleteMatch::Type type);
@@ -326,16 +332,10 @@ class AutocompleteEditModel : public NotificationObserver {
std::wstring DisplayTextFromUserText(const std::wstring& text) const;
std::wstring UserTextFromDisplayText(const std::wstring& text) const;
- // Returns the URL. If the user has not edited the text, this returns the
- // permanent text. If the user has edited the text, this returns the default
- // match based on the current text, which may be a search URL, or keyword
- // generated URL.
- //
- // See AutocompleteEdit for a description of the args (they may be null if
- // not needed).
- GURL GetURLForCurrentText(PageTransition::Type* transition,
- bool* is_history_what_you_typed_match,
- GURL* alternate_nav_url) const;
+ // Returns the default match for the current text, as well as the alternate
+ // nav URL, if |alternate_nav_url| is non-NULL and there is such a URL.
+ void GetInfoForCurrentText(AutocompleteMatch* match,
+ GURL* alternate_nav_url) const;
AutocompleteEditView* view_;
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view.h b/chrome/browser/autocomplete/autocomplete_edit_view.h
index 63c2524..e29b19b 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view.h
+++ b/chrome/browser/autocomplete/autocomplete_edit_view.h
@@ -59,6 +59,9 @@ class AutocompleteEditView {
// browser, or just whatever the user has currently typed.
virtual std::wstring GetText() const = 0;
+ // Returns the resource ID of the icon to show for the current text.
+ virtual int GetIcon() const = 0;
+
// The user text is the text the user has manually keyed in. When present,
// this is shown in preference to the permanent text; hitting escape will
// revert to the permanent text.
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
index 1c7d4bd..0afafd2 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
@@ -387,6 +387,12 @@ std::wstring AutocompleteEditViewGtk::GetText() const {
return out;
}
+int AutocompleteEditViewGtk::GetIcon() const {
+ return (model_->user_input_in_progress() || model_->show_search_hint()) ?
+ AutocompleteMatch::TypeToIcon(model_->CurrentTextType()) :
+ toolbar_model_->GetIcon();
+}
+
void AutocompleteEditViewGtk::SetUserText(const std::wstring& text,
const std::wstring& display_text,
bool update_popup) {
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h
index 3632e0b..7065a8e 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h
@@ -79,6 +79,8 @@ class AutocompleteEditViewGtk : public AutocompleteEditView,
virtual std::wstring GetText() const;
+ virtual int GetIcon() const;
+
virtual void SetUserText(const std::wstring& text) {
SetUserText(text, text, true);
}
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_mac.h b/chrome/browser/autocomplete/autocomplete_edit_view_mac.h
index 11bb62f..8539cae 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_mac.h
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_mac.h
@@ -48,6 +48,9 @@ class AutocompleteEditViewMac : public AutocompleteEditView,
const std::wstring& keyword);
virtual std::wstring GetText() const;
+
+ virtual int GetIcon() const;
+
virtual void SetUserText(const std::wstring& text) {
SetUserText(text, text, true);
}
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm b/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm
index 55b6f3f..1c49e43 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm
@@ -266,6 +266,12 @@ std::wstring AutocompleteEditViewMac::GetText() const {
return base::SysNSStringToWide([field_ stringValue]);
}
+int AutocompleteEditViewMac::GetIcon() const {
+ return (model_->user_input_in_progress() || model_->show_search_hint()) ?
+ AutocompleteMatch::TypeToIcon(model_->CurrentTextType()) :
+ toolbar_model_->GetIcon();
+}
+
void AutocompleteEditViewMac::SetUserText(const std::wstring& text,
const std::wstring& display_text,
bool update_popup) {
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_win.cc b/chrome/browser/autocomplete/autocomplete_edit_view_win.cc
index 3bed00a..87c41f9 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_win.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_win.cc
@@ -599,6 +599,12 @@ std::wstring AutocompleteEditViewWin::GetText() const {
return str;
}
+int AutocompleteEditViewWin::GetIcon() const {
+ return (model_->user_input_in_progress() || model_->show_search_hint()) ?
+ AutocompleteMatch::TypeToIcon(model_->CurrentTextType()) :
+ toolbar_model_->GetIcon();
+}
+
void AutocompleteEditViewWin::SetUserText(const std::wstring& text,
const std::wstring& display_text,
bool update_popup) {
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_win.h b/chrome/browser/autocomplete/autocomplete_edit_view_win.h
index 42e1a35..718ba2a 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_win.h
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_win.h
@@ -91,6 +91,8 @@ class AutocompleteEditViewWin
virtual std::wstring GetText() const;
+ virtual int GetIcon() const;
+
virtual void SetUserText(const std::wstring& text) {
SetUserText(text, text, true);
}
diff --git a/chrome/browser/autocomplete/autocomplete_popup_model.cc b/chrome/browser/autocomplete/autocomplete_popup_model.cc
index eeca0d2..f769937 100644
--- a/chrome/browser/autocomplete/autocomplete_popup_model.cc
+++ b/chrome/browser/autocomplete/autocomplete_popup_model.cc
@@ -104,12 +104,24 @@ void AutocompletePopupModel::SetSelectedLine(size_t line,
if (line == selected_line_)
return; // Nothing else to do.
+ // We need to update |selected_line_| before calling OnPopupDataChanged(), so
+ // that when the edit notifies its controller that something has changed, the
+ // controller can get the correct updated data.
+ //
+ // NOTE: We should never reach here with no selected line; the same code that
+ // opened the popup and made it possible to get here should have also set a
+ // selected line.
+ CHECK(selected_line_ != kNoMatch);
+ GURL current_destination(result.match_at(selected_line_).destination_url);
+ view_->InvalidateLine(selected_line_);
+ selected_line_ = line;
+ view_->InvalidateLine(selected_line_);
+
// Update the edit with the new data for this match.
// TODO(pkasting): If |selected_line_| moves to the controller, this can be
// eliminated and just become a call to the observer on the edit.
std::wstring keyword;
const bool is_keyword_hint = GetKeywordForMatch(match, &keyword);
-
if (reset_to_default) {
std::wstring inline_autocomplete_text;
if ((match.inline_autocomplete_offset != std::wstring::npos) &&
@@ -117,27 +129,15 @@ void AutocompletePopupModel::SetSelectedLine(size_t line,
inline_autocomplete_text =
match.fill_into_edit.substr(match.inline_autocomplete_offset);
}
- edit_model_->OnPopupDataChanged(inline_autocomplete_text, false,
+ edit_model_->OnPopupDataChanged(inline_autocomplete_text, NULL,
keyword, is_keyword_hint, match.type);
} else {
- edit_model_->OnPopupDataChanged(match.fill_into_edit, true,
+ edit_model_->OnPopupDataChanged(match.fill_into_edit, &current_destination,
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).
- //
- // NOTE: We should never reach here with no selected line; the same code that
- // opened the popup and made it possible to get here should have also set a
- // selected line.
- CHECK(selected_line_ != kNoMatch);
- view_->InvalidateLine(selected_line_);
- selected_line_ = line;
- view_->InvalidateLine(selected_line_);
+ // appear to update [much] faster than the popup.
view_->PaintUpdatesNow();
}
@@ -148,22 +148,21 @@ void AutocompletePopupModel::ResetToDefaultMatch() {
view_->OnDragCanceled();
}
-GURL AutocompletePopupModel::URLsForCurrentSelection(
- PageTransition::Type* transition,
- bool* is_history_what_you_typed_match,
+void AutocompletePopupModel::InfoForCurrentSelection(
+ AutocompleteMatch* match,
GURL* alternate_nav_url) const {
+ DCHECK(match != NULL);
const AutocompleteResult* result;
- AutocompleteResult::const_iterator match;
if (!controller_->done()) {
result = &controller_->latest_result();
// It's technically possible for |result| to be empty if no provider returns
// a synchronous result but the query has not completed synchronously;
// pratically, however, that should never actually happen.
if (result->empty())
- return GURL();
+ return;
// 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();
+ *match = *result->default_match();
} else {
CHECK(IsOpen());
// The query isn't running, so the standard result set can't possibly be out
@@ -178,15 +177,10 @@ GURL AutocompletePopupModel::URLsForCurrentSelection(
// called instead.
CHECK(!result->empty());
CHECK(selected_line_ < result->size());
- match = result->begin() + selected_line_;
+ *match = result->match_at(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->alternate_nav_url();
- return match->destination_url;
}
bool AutocompletePopupModel::GetKeywordForMatch(const AutocompleteMatch& match,
@@ -240,7 +234,7 @@ void AutocompletePopupModel::Move(int count) {
}
void AutocompletePopupModel::TryDeletingCurrentItem() {
- // We could use URLsForCurrentSelection() here, but it seems better to try
+ // We could use InfoForCurrentSelection() 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)
diff --git a/chrome/browser/autocomplete/autocomplete_popup_model.h b/chrome/browser/autocomplete/autocomplete_popup_model.h
index 166a238..a986419 100644
--- a/chrome/browser/autocomplete/autocomplete_popup_model.h
+++ b/chrome/browser/autocomplete/autocomplete_popup_model.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 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.
@@ -73,15 +73,9 @@ class AutocompletePopupModel : public NotificationObserver {
// 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.
+ // Copies the selected match into |match|. If an update is in progress,
+ // "selected" means "default in the latest matches". If there are no matches,
+ // does not update |match|.
//
// 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
@@ -89,10 +83,8 @@ class AutocompletePopupModel : public NotificationObserver {
//
// TODO(pkasting): When manually_selected_match_ moves to the controller, this
// can move too.
- GURL URLsForCurrentSelection(
- PageTransition::Type* transition,
- bool* is_history_what_you_typed_match,
- GURL* alternate_nav_url) const;
+ void InfoForCurrentSelection(AutocompleteMatch* match,
+ GURL* alternate_nav_url) const;
// Gets the selected keyword or keyword hint for the given match. Returns
// true if |keyword| represents a keyword hint, or false if |keyword|
diff --git a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc
index 84538e0f..024d7d0 100644
--- a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc
+++ b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc
@@ -165,47 +165,21 @@ void SetupLayoutForMatch(PangoLayout* layout,
}
GdkPixbuf* IconForMatch(const AutocompleteMatch& match, bool selected) {
+ int icon = match.starred ?
+ IDR_O2_STAR : AutocompleteMatch::TypeToIcon(match.type);
+ if (selected) {
+ switch (icon) {
+ case IDR_O2_GLOBE: icon = IDR_O2_GLOBE_SELECTED; break;
+ case IDR_O2_HISTORY: icon = IDR_O2_HISTORY_SELECTED; break;
+ case IDR_O2_SEARCH: icon = IDR_O2_SEARCH_SELECTED; break;
+ case IDR_O2_MORE: icon = IDR_O2_MORE_SELECTED; break;
+ case IDR_O2_STAR: icon = IDR_O2_STAR_SELECTED; break;
+ default: NOTREACHED(); break;
+ }
+ }
// TODO(deanm): These would be better as pixmaps someday.
// TODO(estade): Do we want to flip these for RTL? (Windows doesn't).
- ResourceBundle& rb = ResourceBundle::GetSharedInstance();
- static GdkPixbuf* o2_globe = rb.GetPixbufNamed(IDR_O2_GLOBE);
- static GdkPixbuf* o2_globe_s = rb.GetPixbufNamed(IDR_O2_GLOBE_SELECTED_DARK);
- static GdkPixbuf* o2_history = rb.GetPixbufNamed(IDR_O2_HISTORY);
- static GdkPixbuf* o2_history_s =
- rb.GetPixbufNamed(IDR_O2_HISTORY_SELECTED_DARK);
- static GdkPixbuf* o2_more = rb.GetPixbufNamed(IDR_O2_MORE);
- static GdkPixbuf* o2_more_s = rb.GetPixbufNamed(IDR_O2_MORE_SELECTED_DARK);
- static GdkPixbuf* o2_search = rb.GetPixbufNamed(IDR_O2_SEARCH);
- static GdkPixbuf* o2_search_s =
- rb.GetPixbufNamed(IDR_O2_SEARCH_SELECTED_DARK);
- static GdkPixbuf* o2_star = rb.GetPixbufNamed(IDR_O2_STAR);
- static GdkPixbuf* o2_star_s = rb.GetPixbufNamed(IDR_O2_STAR_SELECTED_DARK);
-
- if (match.starred)
- return selected ? o2_star_s : o2_star;
-
- switch (match.type) {
- case AutocompleteMatch::URL_WHAT_YOU_TYPED:
- case AutocompleteMatch::NAVSUGGEST:
- return selected ? o2_globe_s : o2_globe;
- case AutocompleteMatch::HISTORY_URL:
- case AutocompleteMatch::HISTORY_TITLE:
- case AutocompleteMatch::HISTORY_BODY:
- case AutocompleteMatch::HISTORY_KEYWORD:
- return selected ? o2_history_s : o2_history;
- case AutocompleteMatch::SEARCH_WHAT_YOU_TYPED:
- case AutocompleteMatch::SEARCH_HISTORY:
- case AutocompleteMatch::SEARCH_SUGGEST:
- case AutocompleteMatch::SEARCH_OTHER_ENGINE:
- return selected ? o2_search_s : o2_search;
- case AutocompleteMatch::OPEN_HISTORY_PAGE:
- return selected ? o2_more_s : o2_more;
- default:
- NOTREACHED();
- break;
- }
-
- return NULL;
+ return ResourceBundle::GetSharedInstance().GetPixbufNamed(icon);
}
} // namespace
diff --git a/chrome/browser/autocomplete/autocomplete_popup_view_mac.mm b/chrome/browser/autocomplete/autocomplete_popup_view_mac.mm
index a25c381..6407475 100644
--- a/chrome/browser/autocomplete/autocomplete_popup_view_mac.mm
+++ b/chrome/browser/autocomplete/autocomplete_popup_view_mac.mm
@@ -86,46 +86,6 @@ NSImage* RetainedResourceImage(int resource_id) {
return [image retain];
}
-// Return the appropriate icon for the given match. Derived from the
-// gtk code.
-NSImage* MatchIcon(const AutocompleteMatch& match) {
- if (match.starred) {
- static NSImage* starImage = RetainedResourceImage(IDR_O2_STAR);
- return starImage;
- }
-
- switch (match.type) {
- case AutocompleteMatch::URL_WHAT_YOU_TYPED:
- case AutocompleteMatch::NAVSUGGEST: {
- static NSImage* globeImage = RetainedResourceImage(IDR_O2_GLOBE);
- return globeImage;
- }
- case AutocompleteMatch::HISTORY_URL:
- case AutocompleteMatch::HISTORY_TITLE:
- case AutocompleteMatch::HISTORY_BODY:
- case AutocompleteMatch::HISTORY_KEYWORD: {
- static NSImage* historyImage = RetainedResourceImage(IDR_O2_HISTORY);
- return historyImage;
- }
- case AutocompleteMatch::SEARCH_WHAT_YOU_TYPED:
- case AutocompleteMatch::SEARCH_HISTORY:
- case AutocompleteMatch::SEARCH_SUGGEST:
- case AutocompleteMatch::SEARCH_OTHER_ENGINE: {
- static NSImage* searchImage = RetainedResourceImage(IDR_O2_SEARCH);
- return searchImage;
- }
- case AutocompleteMatch::OPEN_HISTORY_PAGE: {
- static NSImage* moreImage = RetainedResourceImage(IDR_O2_MORE);
- return moreImage;
- }
- default:
- NOTREACHED();
- break;
- }
-
- return nil;
-}
-
} // namespace
// Helper for MatchText() to allow sharing code between the contents
@@ -386,7 +346,8 @@ void AutocompletePopupViewMac::UpdatePopupAppearance() {
for (size_t ii = 0; ii < rows; ++ii) {
AutocompleteButtonCell* cell = [matrix cellAtRow:ii column:0];
const AutocompleteMatch& match = model_->result().match_at(ii);
- [cell setImage:MatchIcon(match)];
+ [cell setImage:RetainedResourceImage(match.starred ?
+ IDR_O2_STAR : AutocompleteMatch::TypeToIcon(match.type))];
[cell setAttributedTitle:MatchText(match, resultFont, r.size.width)];
}
diff --git a/chrome/browser/autocomplete/search_provider.cc b/chrome/browser/autocomplete/search_provider.cc
index 044431b..ba33df0 100644
--- a/chrome/browser/autocomplete/search_provider.cc
+++ b/chrome/browser/autocomplete/search_provider.cc
@@ -98,8 +98,8 @@ void SearchProvider::Start(const AutocompleteInput& input,
// User typed "?" alone. Give them a placeholder result indicating what
// this syntax does.
if (default_provider) {
- AutocompleteMatch match(this, 0, false,
- AutocompleteMatch::SEARCH_WHAT_YOU_TYPED);
+ AutocompleteMatch match;
+ match.provider = this;
match.contents.assign(l10n_util::GetString(IDS_EMPTY_KEYWORD_VALUE));
match.contents_class.push_back(
ACMatchClassification(0, ACMatchClassification::NONE));
diff --git a/chrome/browser/cocoa/autocomplete_text_field_cell.h b/chrome/browser/cocoa/autocomplete_text_field_cell.h
index 32f0590..6b2f156 100644
--- a/chrome/browser/cocoa/autocomplete_text_field_cell.h
+++ b/chrome/browser/cocoa/autocomplete_text_field_cell.h
@@ -44,10 +44,9 @@ class ExtensionAction;
// side of the field. Exclusive WRT |keywordString_|;
scoped_nsobject<NSAttributedString> hintString_;
- // View showing the state of the SSL connection. Owned by the location bar.
- // Display is exclusive WRT the |hintString_| and |keywordString_|.
- // This may be NULL during testing.
- LocationBarViewMac::SecurityImageView* security_image_view_;
+ // View showing an icon matching the current text. Owned by the location bar.
+ // Exclusive WRT |keywordString_|. This may be NULL during testing.
+ LocationBarViewMac::LocationIconView* location_icon_view_;
// List of views showing visible Page Actions. Owned by the location bar.
// Display is exclusive WRT the |hintString_| and |keywordString_|.
@@ -77,7 +76,7 @@ class ExtensionAction;
availableWidth:(CGFloat)width;
- (void)clearKeywordAndHint;
-- (void)setSecurityImageView:(LocationBarViewMac::SecurityImageView*)view;
+- (void)setLocationIconView:(LocationBarViewMac::LocationIconView*)view;
- (void)setPageActionViewList:(LocationBarViewMac::PageActionViewList*)list;
- (void)setContentSettingViewsList:
(LocationBarViewMac::ContentSettingViews*)views;
@@ -113,8 +112,8 @@ class ExtensionAction;
// Returns the total number of installed Page Actions, visible or not.
- (size_t)pageActionCount;
-// Returns the portion of the cell to use for displaying the security (SSL lock)
-// icon, leaving space for its label if any.
-- (NSRect)securityImageFrameForFrame:(NSRect)cellFrame;
+// Returns the portion of the cell to use for displaying the location icon,
+// leaving space for its label if any.
+- (NSRect)locationIconFrameForFrame:(NSRect)cellFrame;
@end
diff --git a/chrome/browser/cocoa/autocomplete_text_field_cell.mm b/chrome/browser/cocoa/autocomplete_text_field_cell.mm
index ecc00b8..5fb7b16 100644
--- a/chrome/browser/cocoa/autocomplete_text_field_cell.mm
+++ b/chrome/browser/cocoa/autocomplete_text_field_cell.mm
@@ -213,8 +213,8 @@ CGFloat WidthForKeyword(NSAttributedString* keywordString) {
page_action_views_ = list;
}
-- (void)setSecurityImageView:(LocationBarViewMac::SecurityImageView*)view {
- security_image_view_ = view;
+- (void)setLocationIconView:(LocationBarViewMac::LocationIconView*)view {
+ location_icon_view_ = view;
}
- (void)setContentSettingViewsList:
@@ -273,15 +273,15 @@ CGFloat WidthForKeyword(NSAttributedString* keywordString) {
return box;
}
-- (NSRect)securityImageFrameForFrame:(NSRect)cellFrame {
- if (!security_image_view_ || !security_image_view_->IsVisible()) {
+- (NSRect)locationIconFrameForFrame:(NSRect)cellFrame {
+ if (!location_icon_view_ || !location_icon_view_->IsVisible()) {
return NSZeroRect;
}
// Calculate the total width occupied by the image, label, and padding.
- NSSize imageSize = [security_image_view_->GetImage() size];
+ NSSize imageSize = [location_icon_view_->GetImage() size];
CGFloat widthUsed = imageSize.width + kIconHorizontalPad;
- NSAttributedString* label = security_image_view_->GetLabel();
+ NSAttributedString* label = location_icon_view_->GetLabel();
if (label) {
widthUsed += ceil([label size].width) + kHintXOffset;
}
@@ -404,12 +404,12 @@ CGFloat WidthForKeyword(NSAttributedString* keywordString) {
- (NSArray*)layedOutIcons:(NSRect)cellFrame {
NSMutableArray* result = [NSMutableArray arrayWithCapacity:0];
NSRect iconFrame = cellFrame;
- if (security_image_view_ && security_image_view_->IsVisible()) {
- NSRect securityImageFrame = [self securityImageFrameForFrame:iconFrame];
+ if (location_icon_view_ && location_icon_view_->IsVisible()) {
+ NSRect locationIconFrame = [self locationIconFrameForFrame:iconFrame];
[result addObject:
- [AutocompleteTextFieldIcon iconWithRect:securityImageFrame
- view:security_image_view_]];
- iconFrame.size.width -= NSMaxX(iconFrame) - NSMinX(securityImageFrame);
+ [AutocompleteTextFieldIcon iconWithRect:locationIconFrame
+ view:location_icon_view_]];
+ iconFrame.size.width -= NSMaxX(iconFrame) - NSMinX(locationIconFrame);
}
const size_t pageActionCount = [self pageActionCount];
diff --git a/chrome/browser/cocoa/autocomplete_text_field_cell_unittest.mm b/chrome/browser/cocoa/autocomplete_text_field_cell_unittest.mm
index c400162..60418a0 100644
--- a/chrome/browser/cocoa/autocomplete_text_field_cell_unittest.mm
+++ b/chrome/browser/cocoa/autocomplete_text_field_cell_unittest.mm
@@ -4,6 +4,7 @@
#import <Cocoa/Cocoa.h>
+#include "app/resource_bundle.h"
#include "base/scoped_nsobject.h"
#import "chrome/browser/cocoa/autocomplete_text_field_cell.h"
#import "chrome/browser/cocoa/cocoa_test_helper.h"
@@ -44,7 +45,7 @@ class TestPageActionViewList : public LocationBarViewMac::PageActionViewList {
class AutocompleteTextFieldCellTest : public CocoaTest {
public:
- AutocompleteTextFieldCellTest() : security_image_view_(NULL, NULL, NULL),
+ AutocompleteTextFieldCellTest() : location_icon_view_(NULL),
page_action_views_() {
// Make sure this is wide enough to play games with the cell
// decorations.
@@ -58,7 +59,7 @@ class AutocompleteTextFieldCellTest : public CocoaTest {
[[AutocompleteTextFieldCell alloc] initTextCell:@"Testing"]);
[cell setEditable:YES];
[cell setBordered:YES];
- [cell setSecurityImageView:&security_image_view_];
+ [cell setLocationIconView:&location_icon_view_];
[cell setPageActionViewList:&page_action_views_];
[view_ setCell:cell.get()];
@@ -66,7 +67,7 @@ class AutocompleteTextFieldCellTest : public CocoaTest {
}
NSTextField* view_;
- LocationBarViewMac::SecurityImageView security_image_view_;
+ LocationBarViewMac::LocationIconView location_icon_view_;
TestPageActionViewList page_action_views_;
};
@@ -200,9 +201,10 @@ TEST_F(AutocompleteTextFieldCellTest, TextFrame) {
EXPECT_EQ(NSMaxX(bounds), NSMaxX(textFrame));
EXPECT_TRUE(NSContainsRect(cursorFrame, textFrame));
- // Security icon takes up space on the right
- security_image_view_.SetImageShown(IDR_SECURE);
- security_image_view_.SetVisible(true);
+ // Location icon takes up space on the right
+ location_icon_view_.SetImage(
+ ResourceBundle::GetSharedInstance().GetNSImageNamed(IDR_SECURE));
+ location_icon_view_.SetVisible(true);
textFrame = [cell textFrameForFrame:bounds];
EXPECT_FALSE(NSIsEmptyRect(textFrame));
@@ -265,8 +267,9 @@ TEST_F(AutocompleteTextFieldCellTest, DrawingRectForBounds) {
EXPECT_TRUE(NSContainsRect(NSInsetRect(textFrame, 1, 1), drawingRect));
EXPECT_TRUE(NSEqualRects(drawingRect, originalDrawingRect));
- security_image_view_.SetImageShown(IDR_SECURE);
- security_image_view_.SetVisible(true);
+ location_icon_view_.SetImage(
+ ResourceBundle::GetSharedInstance().GetNSImageNamed(IDR_SECURE));
+ location_icon_view_.SetVisible(true);
textFrame = [cell textFrameForFrame:bounds];
drawingRect = [cell drawingRectForBounds:bounds];
@@ -274,17 +277,18 @@ TEST_F(AutocompleteTextFieldCellTest, DrawingRectForBounds) {
EXPECT_TRUE(NSContainsRect(NSInsetRect(textFrame, 1, 1), drawingRect));
}
-// Test that the security icon is at the right side of the cell.
-TEST_F(AutocompleteTextFieldCellTest, SecurityImageFrame) {
+// Test that the location icon is at the right side of the cell.
+TEST_F(AutocompleteTextFieldCellTest, LocationIconFrame) {
AutocompleteTextFieldCell* cell =
static_cast<AutocompleteTextFieldCell*>([view_ cell]);
const NSRect bounds([view_ bounds]);
- security_image_view_.SetImageShown(IDR_SECURE);
+ location_icon_view_.SetImage(
+ ResourceBundle::GetSharedInstance().GetNSImageNamed(IDR_SECURE));
- security_image_view_.SetVisible(false);
+ location_icon_view_.SetVisible(false);
EXPECT_EQ(0u, [[cell layedOutIcons:bounds] count]);
- security_image_view_.SetVisible(true);
+ location_icon_view_.SetVisible(true);
NSArray* icons = [cell layedOutIcons:bounds];
ASSERT_EQ(1u, [icons count]);
NSRect iconRect = [[icons objectAtIndex:0] rect];
@@ -303,7 +307,7 @@ TEST_F(AutocompleteTextFieldCellTest, SecurityImageFrame) {
// Now add a label.
NSFont* font = [NSFont controlContentFontOfSize:12.0];
NSColor* color = [NSColor blackColor];
- security_image_view_.SetLabel(@"Label", font, color);
+ location_icon_view_.SetLabel(@"Label", font, color);
icons = [cell layedOutIcons:bounds];
ASSERT_EQ(1u, [icons count]);
iconRect = [[icons objectAtIndex:0] rect];
@@ -320,7 +324,7 @@ TEST_F(AutocompleteTextFieldCellTest, SecurityImageFrame) {
EXPECT_LE(NSMaxX(textFrame), NSMinX(iconRect));
// Make sure we clear correctly.
- security_image_view_.SetVisible(false);
+ location_icon_view_.SetVisible(false);
EXPECT_EQ(0u, [[cell layedOutIcons:bounds] count]);
}
@@ -347,7 +351,8 @@ TEST_F(AutocompleteTextFieldCellTest, PageActionImageFrame) {
AutocompleteTextFieldCell* cell =
static_cast<AutocompleteTextFieldCell*>([view_ cell]);
const NSRect bounds([view_ bounds]);
- security_image_view_.SetImageShown(IDR_SECURE);
+ location_icon_view_.SetImage(
+ ResourceBundle::GetSharedInstance().GetNSImageNamed(IDR_SECURE));
TestPageActionImageView page_action_view;
// We'll assume that the extensions code enforces icons smaller than the
@@ -365,13 +370,13 @@ TEST_F(AutocompleteTextFieldCellTest, PageActionImageFrame) {
list.Add(&page_action_view2);
[cell setPageActionViewList:&list];
- security_image_view_.SetVisible(false);
+ location_icon_view_.SetVisible(false);
page_action_view.SetVisible(false);
page_action_view2.SetVisible(false);
EXPECT_TRUE(NSIsEmptyRect([cell pageActionFrameForIndex:0 inFrame:bounds]));
EXPECT_TRUE(NSIsEmptyRect([cell pageActionFrameForIndex:1 inFrame:bounds]));
- // One page action, no security icon.
+ // One page action, no lock icon.
page_action_view.SetVisible(true);
NSRect iconRect0 = [cell pageActionFrameForIndex:0 inFrame:bounds];
@@ -386,9 +391,9 @@ TEST_F(AutocompleteTextFieldCellTest, PageActionImageFrame) {
NSRect textFrame = [cell textFrameForFrame:bounds];
EXPECT_LE(NSMaxX(textFrame), NSMinX(iconRect0));
- // Two page actions plus a security icon.
+ // Two page actions plus a lock icon.
page_action_view2.SetVisible(true);
- security_image_view_.SetVisible(true);
+ location_icon_view_.SetVisible(true);
NSArray* icons = [cell layedOutIcons:bounds];
EXPECT_EQ(3u, [icons count]);
iconRect0 = [cell pageActionFrameForIndex:0 inFrame:bounds];
diff --git a/chrome/browser/cocoa/autocomplete_text_field_unittest.mm b/chrome/browser/cocoa/autocomplete_text_field_unittest.mm
index c5ad20f..826dfbe 100644
--- a/chrome/browser/cocoa/autocomplete_text_field_unittest.mm
+++ b/chrome/browser/cocoa/autocomplete_text_field_unittest.mm
@@ -4,6 +4,7 @@
#import <Cocoa/Cocoa.h>
+#include "app/resource_bundle.h"
#import "base/cocoa_protocols_mac.h"
#include "base/scoped_nsobject.h"
#import "chrome/browser/cocoa/autocomplete_text_field.h"
@@ -21,12 +22,10 @@ using ::testing::Return;
using ::testing::StrictMock;
namespace {
-class MockSecurityImageView : public LocationBarViewMac::SecurityImageView {
+class MockLocationIconView : public LocationBarViewMac::LocationIconView {
public:
- MockSecurityImageView(LocationBarViewMac* owner,
- Profile* profile,
- ToolbarModel* model)
- : LocationBarViewMac::SecurityImageView(owner, profile, model) {}
+ MockLocationIconView(LocationBarViewMac* owner)
+ : LocationBarViewMac::LocationIconView(owner) {}
// We can't use gmock's MOCK_METHOD macro, because it doesn't like the
// NSRect argument to OnMousePressed.
@@ -582,30 +581,32 @@ TEST_F(AutocompleteTextFieldTest, TripleClickSelectsAll) {
EXPECT_EQ(selectedRange.length, [[field_ stringValue] length]);
}
-// Clicking the security icon should call its OnMousePressed.
-TEST_F(AutocompleteTextFieldObserverTest, SecurityIconMouseDown) {
+// Clicking the location icon should call its OnMousePressed.
+TEST_F(AutocompleteTextFieldObserverTest, LocationIconMouseDown) {
AutocompleteTextFieldCell* cell = [field_ autocompleteTextFieldCell];
- MockSecurityImageView security_image_view(NULL, NULL, NULL);
- [cell setSecurityImageView:&security_image_view];
- security_image_view.SetImageShown(IDR_SECURE);
- security_image_view.SetVisible(true);
+ MockLocationIconView location_icon_view(NULL);
+ [cell setLocationIconView:&location_icon_view];
+ location_icon_view.SetImage(
+ ResourceBundle::GetSharedInstance().GetNSImageNamed(IDR_SECURE));
+ location_icon_view.SetVisible(true);
- NSRect iconFrame([cell securityImageFrameForFrame:[field_ bounds]]);
+ NSRect iconFrame([cell locationIconFrameForFrame:[field_ bounds]]);
NSPoint location(NSMakePoint(NSMidX(iconFrame), NSMidY(iconFrame)));
NSEvent* event(Event(field_, location, NSLeftMouseDown, 1));
[field_ mouseDown:event];
- EXPECT_TRUE(security_image_view.mouse_was_pressed_);
+ EXPECT_TRUE(location_icon_view.mouse_was_pressed_);
}
// Clicking a Page Action icon should call its OnMousePressed.
TEST_F(AutocompleteTextFieldObserverTest, PageActionMouseDown) {
AutocompleteTextFieldCell* cell = [field_ autocompleteTextFieldCell];
- MockSecurityImageView security_image_view(NULL, NULL, NULL);
- security_image_view.SetImageShown(IDR_SECURE);
- [cell setSecurityImageView:&security_image_view];
+ MockLocationIconView location_icon_view(NULL);
+ location_icon_view.SetImage(
+ ResourceBundle::GetSharedInstance().GetNSImageNamed(IDR_SECURE));
+ [cell setLocationIconView:&location_icon_view];
MockPageActionImageView page_action_view;
NSImage* image = [NSImage imageNamed:@"NSApplicationIcon"];
@@ -619,8 +620,8 @@ TEST_F(AutocompleteTextFieldObserverTest, PageActionMouseDown) {
list.Add(&page_action_view2);
[cell setPageActionViewList:&list];
- // One page action, no security lock.
- security_image_view.SetVisible(false);
+ // One page action, no lock.
+ location_icon_view.SetVisible(false);
page_action_view.SetVisible(true);
page_action_view2.SetVisible(false);
NSRect iconFrame([cell pageActionFrameForIndex:0 inFrame:[field_ bounds]]);
@@ -630,7 +631,7 @@ TEST_F(AutocompleteTextFieldObserverTest, PageActionMouseDown) {
[field_ mouseDown:event];
EXPECT_TRUE(page_action_view.MouseWasPressed());
- // Two page actions, no security lock.
+ // Two page actions, no lock.
page_action_view2.SetVisible(true);
iconFrame = [cell pageActionFrameForIndex:0 inFrame:[field_ bounds]];
location = NSMakePoint(NSMidX(iconFrame), NSMidY(iconFrame));
@@ -646,8 +647,8 @@ TEST_F(AutocompleteTextFieldObserverTest, PageActionMouseDown) {
[field_ mouseDown:event];
EXPECT_TRUE(page_action_view.MouseWasPressed());
- // Two page actions plus security lock.
- security_image_view.SetVisible(true);
+ // Two page actions plus lock.
+ location_icon_view.SetVisible(true);
iconFrame = [cell pageActionFrameForIndex:0 inFrame:[field_ bounds]];
location = NSMakePoint(NSMidX(iconFrame), NSMidY(iconFrame));
event = Event(field_, location, NSLeftMouseDown, 1);
@@ -662,12 +663,12 @@ TEST_F(AutocompleteTextFieldObserverTest, PageActionMouseDown) {
[field_ mouseDown:event];
EXPECT_TRUE(page_action_view.MouseWasPressed());
- iconFrame = [cell securityImageFrameForFrame:[field_ bounds]];
+ iconFrame = [cell locationIconFrameForFrame:[field_ bounds]];
location = NSMakePoint(NSMidX(iconFrame), NSMidY(iconFrame));
event = Event(field_, location, NSLeftMouseDown, 1);
[field_ mouseDown:event];
- EXPECT_TRUE(security_image_view.mouse_was_pressed_);
+ EXPECT_TRUE(location_icon_view.mouse_was_pressed_);
}
// Test that page action menus are properly returned.
diff --git a/chrome/browser/cocoa/location_bar_view_mac.h b/chrome/browser/cocoa/location_bar_view_mac.h
index b7f5187..afa4aec 100644
--- a/chrome/browser/cocoa/location_bar_view_mac.h
+++ b/chrome/browser/cocoa/location_bar_view_mac.h
@@ -173,35 +173,20 @@ class LocationBarViewMac : public AutocompleteEditController,
DISALLOW_COPY_AND_ASSIGN(LocationBarImageView);
};
- // SecurityImageView is used to display the lock or warning icon when the
- // current URL's scheme is https.
- class SecurityImageView : public LocationBarImageView {
+ // LocationIconView is used to display an icon to the left of the address.
+ class LocationIconView : public LocationBarImageView {
public:
- SecurityImageView(LocationBarViewMac* owner,
- Profile* profile,
- ToolbarModel* model);
- virtual ~SecurityImageView();
-
- // Sets the image to the appropriate icon.
- void SetImageShown(int resource_id);
+ explicit LocationIconView(LocationBarViewMac* owner);
+ virtual ~LocationIconView();
// Shows the page info dialog.
virtual void OnMousePressed(NSRect bounds);
private:
- // Icons for various states. Lazily loaded the first time they're needed.
- scoped_nsobject<NSImage> ev_secure_icon_;
- scoped_nsobject<NSImage> secure_icon_;
- scoped_nsobject<NSImage> security_warning_icon_;
- scoped_nsobject<NSImage> security_error_icon_;
-
// The location bar view that owns us.
LocationBarViewMac* owner_;
- Profile* profile_;
- ToolbarModel* model_;
-
- DISALLOW_COPY_AND_ASSIGN(SecurityImageView);
+ DISALLOW_COPY_AND_ASSIGN(LocationIconView);
};
// PageActionImageView is used to display the icon for a given Page Action
@@ -374,11 +359,11 @@ class LocationBarViewMac : public AutocompleteEditController,
};
private:
- // Sets the SSL icon we should be showing.
- void SetSecurityIcon(int resource_id);
+ // Sets the location icon we should be showing.
+ void SetIcon(int resource_id);
- // Sets the label for the SSL icon.
- void SetSecurityIconLabel();
+ // Sets the label for the SSL state.
+ void SetSecurityLabel();
// Posts |notification| to the default notification center.
void PostNotification(const NSString* notification);
@@ -401,8 +386,8 @@ class LocationBarViewMac : public AutocompleteEditController,
// The user's desired disposition for how their input should be opened.
WindowOpenDisposition disposition_;
- // The view that shows the lock/warning when in HTTPS mode.
- SecurityImageView security_image_view_;
+ // A view that shows an icon to the left of the address.
+ LocationIconView location_icon_view_;
// Any installed Page Actions.
PageActionViewList page_action_views_;
diff --git a/chrome/browser/cocoa/location_bar_view_mac.mm b/chrome/browser/cocoa/location_bar_view_mac.mm
index 0035101..4660001 100644
--- a/chrome/browser/cocoa/location_bar_view_mac.mm
+++ b/chrome/browser/cocoa/location_bar_view_mac.mm
@@ -103,7 +103,7 @@ LocationBarViewMac::LocationBarViewMac(
command_updater_(command_updater),
field_(field),
disposition_(CURRENT_TAB),
- security_image_view_(this, profile, toolbar_model),
+ location_icon_view_(this),
page_action_views_(this, profile, toolbar_model),
profile_(profile),
browser_(browser),
@@ -118,7 +118,7 @@ LocationBarViewMac::LocationBarViewMac(
}
AutocompleteTextFieldCell* cell = [field_ autocompleteTextFieldCell];
- [cell setSecurityImageView:&security_image_view_];
+ [cell setLocationIconView:&location_icon_view_];
[cell setPageActionViewList:&page_action_views_];
[cell setContentSettingViewsList:&content_setting_views_];
@@ -131,7 +131,7 @@ LocationBarViewMac::~LocationBarViewMac() {
// Disconnect from cell in case it outlives us.
AutocompleteTextFieldCell* cell = [field_ autocompleteTextFieldCell];
[cell setPageActionViewList:NULL];
- [cell setSecurityImageView:NULL];
+ [cell setLocationIconView:NULL];
}
std::wstring LocationBarViewMac::GetInputString() const {
@@ -208,7 +208,7 @@ void LocationBarViewMac::SaveStateToContents(TabContents* contents) {
void LocationBarViewMac::Update(const TabContents* contents,
bool should_restore_state) {
- SetSecurityIcon(toolbar_model_->GetSecurityIcon());
+ SetIcon(edit_view_->GetIcon());
page_action_views_.RefreshViews();
RefreshContentSettingsViews();
// AutocompleteEditView restores state if the tab is non-NULL.
@@ -457,11 +457,27 @@ NSImage* LocationBarViewMac::GetTabButtonImage() {
return tab_button_image_;
}
-void LocationBarViewMac::SetSecurityIconLabel() {
- // TODO(shess): Separate from security icon and move icon to left of address.
+void LocationBarViewMac::SetIcon(int resource_id) {
+ DCHECK(resource_id != 0);
+
+ // The icon is always visible except when there is a keyword hint.
+ if (!edit_view_->model()->keyword().empty() &&
+ !edit_view_->model()->is_keyword_hint()) {
+ location_icon_view_.SetVisible(false);
+ } else {
+ location_icon_view_.SetImage(
+ ResourceBundle::GetSharedInstance().GetNSImageNamed(resource_id));
+ location_icon_view_.SetVisible(true);
+ SetSecurityLabel();
+ }
+ [field_ resetFieldEditorFrameIfNeeded];
+}
+
+void LocationBarViewMac::SetSecurityLabel() {
+ // TODO(shess): Separate from location icon and move icon to left of address.
std::wstring security_info_text(toolbar_model_->GetSecurityInfoText());
if (security_info_text.empty()) {
- security_image_view_.SetLabel(nil, nil, nil);
+ location_icon_view_.SetLabel(nil, nil, nil);
} else {
NSString* icon_label = base::SysWideToNSString(security_info_text);
NSColor* color;
@@ -477,21 +493,10 @@ void LocationBarViewMac::SetSecurityIconLabel() {
blue:kSecurityErrorTextColorBlueComponent
alpha:1.0];
}
- security_image_view_.SetLabel(icon_label, [field_ font], color);
+ location_icon_view_.SetLabel(icon_label, [field_ font], color);
}
}
-void LocationBarViewMac::SetSecurityIcon(int resource_id) {
- if (resource_id == 0) {
- security_image_view_.SetVisible(false);
- } else {
- security_image_view_.SetImageShown(resource_id);
- security_image_view_.SetVisible(true);
- SetSecurityIconLabel();
- }
- [field_ resetFieldEditorFrameIfNeeded];
-}
-
void LocationBarViewMac::Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
@@ -561,39 +566,16 @@ void LocationBarViewMac::LocationBarImageView::SetVisible(bool visible) {
visible_ = visible;
}
-// SecurityImageView------------------------------------------------------------
+// LocationIconView ------------------------------------------------------------
-LocationBarViewMac::SecurityImageView::SecurityImageView(
- LocationBarViewMac* owner,
- Profile* profile,
- ToolbarModel* model)
- : ev_secure_icon_(nil),
- secure_icon_(nil),
- security_warning_icon_(nil),
- security_error_icon_(nil),
- owner_(owner),
- profile_(profile),
- model_(model) {}
-
-LocationBarViewMac::SecurityImageView::~SecurityImageView() {}
-
-void LocationBarViewMac::SecurityImageView::SetImageShown(int resource_id) {
- scoped_nsobject<NSImage>* icon;
- switch (resource_id) {
- case IDR_EV_SECURE: icon = &ev_secure_icon_; break;
- case IDR_SECURE: icon = &secure_icon_; break;
- case IDR_SECURITY_WARNING: icon = &security_warning_icon_; break;
- case IDR_SECURITY_ERROR: icon = &security_error_icon_; break;
- default: NOTREACHED(); return;
- }
- if (!icon->get()) {
- ResourceBundle& rb = ResourceBundle::GetSharedInstance();
- icon->reset([rb.GetNSImageNamed(resource_id) retain]);
- }
- SetImage(*icon);
+LocationBarViewMac::LocationIconView::LocationIconView(
+ LocationBarViewMac* owner)
+ : owner_(owner) {
}
-void LocationBarViewMac::SecurityImageView::OnMousePressed(NSRect bounds) {
+LocationBarViewMac::LocationIconView::~LocationIconView() {}
+
+void LocationBarViewMac::LocationIconView::OnMousePressed(NSRect bounds) {
TabContents* tab = owner_->GetTabContents();
NavigationEntry* nav_entry = tab->controller().GetActiveEntry();
if (!nav_entry) {
diff --git a/chrome/browser/cocoa/tab_strip_controller_unittest.mm b/chrome/browser/cocoa/tab_strip_controller_unittest.mm
index 0967ae4..7cbe16e 100644
--- a/chrome/browser/cocoa/tab_strip_controller_unittest.mm
+++ b/chrome/browser/cocoa/tab_strip_controller_unittest.mm
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 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.
@@ -120,6 +120,10 @@ class TabStripControllerTest : public CocoaTest {
// Test adding and removing tabs and making sure that views get added to
// the tab strip.
TEST_F(TabStripControllerTest, AddRemoveTabs) {
+ // Create the objects we need, since we have a real location bar.
+ browser_helper_.profile()->CreateAutocompleteClassifier();
+ browser_helper_.profile()->CreateTemplateURLModel();
+
EXPECT_TRUE(model_->empty());
SiteInstance* instance =
SiteInstance::CreateSiteInstance(browser_helper_.profile());
diff --git a/chrome/browser/gtk/location_bar_view_gtk.cc b/chrome/browser/gtk/location_bar_view_gtk.cc
index bab7259..af98cfa 100644
--- a/chrome/browser/gtk/location_bar_view_gtk.cc
+++ b/chrome/browser/gtk/location_bar_view_gtk.cc
@@ -138,11 +138,8 @@ const GdkColor LocationBarViewGtk::kBackgroundColor =
LocationBarViewGtk::LocationBarViewGtk(
const BubblePositioner* bubble_positioner,
Browser* browser)
- : security_icon_event_box_(NULL),
- ev_secure_icon_image_(NULL),
- secure_icon_image_(NULL),
- security_warning_icon_image_(NULL),
- security_error_icon_image_(NULL),
+ : location_icon_event_box_(NULL),
+ location_icon_image_(NULL),
security_info_label_(NULL),
tab_to_search_box_(NULL),
tab_to_search_full_label_(NULL),
@@ -193,20 +190,9 @@ void LocationBarViewGtk::Init(bool popup_window_mode) {
// the home button on/off.
gtk_widget_set_redraw_on_allocate(hbox_.get(), TRUE);
- ResourceBundle& rb = ResourceBundle::GetSharedInstance();
- ev_secure_icon_image_ =
- gtk_image_new_from_pixbuf(rb.GetPixbufNamed(IDR_EV_SECURE));
- gtk_widget_set_name(ev_secure_icon_image_, "chrome-ev-secure-icon");
- secure_icon_image_ = gtk_image_new_from_pixbuf(rb.GetPixbufNamed(IDR_SECURE));
- gtk_widget_set_name(secure_icon_image_, "chrome-secure-icon");
- security_warning_icon_image_ =
- gtk_image_new_from_pixbuf(rb.GetPixbufNamed(IDR_SECURITY_WARNING));
- gtk_widget_set_name(security_warning_icon_image_,
- "chrome-security-warning-icon");
- security_error_icon_image_ =
- gtk_image_new_from_pixbuf(rb.GetPixbufNamed(IDR_SECURITY_ERROR));
- gtk_widget_set_name(security_error_icon_image_,
- "chrome-security-error-icon");
+ location_icon_image_ = gtk_image_new();
+ gtk_widget_set_name(location_icon_image_, "chrome-location-icon");
+ gtk_widget_show(location_icon_image_);
security_info_label_ = gtk_label_new(NULL);
gtk_widget_modify_base(security_info_label_, GTK_STATE_NORMAL,
@@ -282,7 +268,8 @@ void LocationBarViewGtk::Init(bool popup_window_mode) {
tab_to_search_hint_leading_label_ = gtk_label_new(NULL);
gtk_widget_set_sensitive(tab_to_search_hint_leading_label_, FALSE);
tab_to_search_hint_icon_ = gtk_image_new_from_pixbuf(
- rb.GetPixbufNamed(IDR_LOCATION_BAR_KEYWORD_HINT_TAB));
+ ResourceBundle::GetSharedInstance().GetPixbufNamed(
+ IDR_LOCATION_BAR_KEYWORD_HINT_TAB));
tab_to_search_hint_trailing_label_ = gtk_label_new(NULL);
gtk_widget_set_sensitive(tab_to_search_hint_trailing_label_, FALSE);
gtk_box_pack_start(GTK_BOX(tab_to_search_hint_),
@@ -311,29 +298,20 @@ void LocationBarViewGtk::Init(bool popup_window_mode) {
// by SetSecurityIcon() and SetInfoText().
gtk_box_pack_end(GTK_BOX(hbox_.get()), security_info_label_, FALSE, FALSE, 0);
- GtkWidget* security_icon_box = gtk_hbox_new(FALSE, 0);
- gtk_box_pack_start(GTK_BOX(security_icon_box),
- ev_secure_icon_image_, FALSE, FALSE, 0);
- gtk_box_pack_start(GTK_BOX(security_icon_box),
- secure_icon_image_, FALSE, FALSE, 0);
- gtk_box_pack_start(GTK_BOX(security_icon_box),
- security_warning_icon_image_, FALSE, FALSE, 0);
- gtk_box_pack_start(GTK_BOX(security_icon_box),
- security_error_icon_image_, FALSE, FALSE, 0);
-
// GtkImage is a "no window" widget and requires a GtkEventBox to receive
// events.
- security_icon_event_box_ = gtk_event_box_new();
+ location_icon_event_box_ = gtk_event_box_new();
// Make the event box not visible so it does not paint a background.
- gtk_event_box_set_visible_window(GTK_EVENT_BOX(security_icon_event_box_),
+ gtk_event_box_set_visible_window(GTK_EVENT_BOX(location_icon_event_box_),
FALSE);
- g_signal_connect(security_icon_event_box_, "button-press-event",
- G_CALLBACK(&OnSecurityIconPressed), this);
-
- gtk_container_add(GTK_CONTAINER(security_icon_event_box_), security_icon_box);
- gtk_widget_set_name(security_icon_event_box_,
- "chrome-security-icon-eventbox");
- gtk_box_pack_end(GTK_BOX(hbox_.get()), security_icon_event_box_,
+ g_signal_connect(location_icon_event_box_, "button-press-event",
+ G_CALLBACK(&OnIconPressed), this);
+
+ gtk_container_add(GTK_CONTAINER(location_icon_event_box_),
+ location_icon_image_);
+ gtk_widget_set_name(location_icon_event_box_,
+ "chrome-location-icon-eventbox");
+ gtk_box_pack_end(GTK_BOX(hbox_.get()), location_icon_event_box_,
FALSE, FALSE, 0);
content_setting_hbox_.Own(gtk_hbox_new(FALSE, kInnerPadding));
@@ -418,7 +396,7 @@ GtkWidget* LocationBarViewGtk::GetPageActionWidget(
}
void LocationBarViewGtk::Update(const TabContents* contents) {
- SetSecurityIcon(toolbar_model_->GetSecurityIcon());
+ UpdateIcon();
UpdateContentSettingsIcons();
UpdatePageActions();
SetInfoText();
@@ -469,6 +447,8 @@ void LocationBarViewGtk::OnAutocompleteAccept(const GURL& url,
}
void LocationBarViewGtk::OnChanged() {
+ UpdateIcon();
+
const std::wstring keyword(location_entry_->model()->keyword());
const bool is_keyword_hint = location_entry_->model()->is_keyword_hint();
show_selected_keyword_ = !keyword.empty() && !is_keyword_hint;
@@ -754,33 +734,19 @@ gboolean LocationBarViewGtk::HandleExpose(GtkWidget* widget,
return FALSE; // Continue propagating the expose.
}
-void LocationBarViewGtk::SetSecurityIcon(int resource_id) {
- gtk_widget_hide(GTK_WIDGET(ev_secure_icon_image_));
- gtk_widget_hide(GTK_WIDGET(secure_icon_image_));
- gtk_widget_hide(GTK_WIDGET(security_warning_icon_image_));
- gtk_widget_hide(GTK_WIDGET(security_error_icon_image_));
- if (resource_id == 0) {
- gtk_widget_hide(GTK_WIDGET(security_icon_event_box_));
+void LocationBarViewGtk::UpdateIcon() {
+ // The icon is always visible except when the |tab_to_search_box_| is visible.
+ if (!location_entry_->model()->keyword().empty() &&
+ !location_entry_->model()->is_keyword_hint()) {
+ gtk_widget_hide(location_icon_event_box_);
return;
}
- gtk_widget_show(GTK_WIDGET(security_icon_event_box_));
- switch (resource_id) {
- case IDR_EV_SECURE:
- gtk_widget_show(GTK_WIDGET(ev_secure_icon_image_));
- break;
- case IDR_SECURE:
- gtk_widget_show(GTK_WIDGET(secure_icon_image_));
- break;
- case IDR_SECURITY_WARNING:
- gtk_widget_show(GTK_WIDGET(security_warning_icon_image_));
- break;
- case IDR_SECURITY_ERROR:
- gtk_widget_show(GTK_WIDGET(security_error_icon_image_));
- break;
- default:
- NOTREACHED();
- break;
- }
+
+ int resource_id = location_entry_->GetIcon();
+ ResourceBundle& rb = ResourceBundle::GetSharedInstance();
+ gtk_image_set_from_pixbuf(GTK_IMAGE(location_icon_image_),
+ rb.GetPixbufNamed(resource_id));
+ gtk_widget_show(location_icon_event_box_);
}
void LocationBarViewGtk::SetInfoText() {
@@ -870,10 +836,9 @@ void LocationBarViewGtk::ShowFirstRunBubbleInternal(bool use_OEM_bubble) {
}
// static
-gboolean LocationBarViewGtk::OnSecurityIconPressed(
- GtkWidget* sender,
- GdkEventButton* event,
- LocationBarViewGtk* location_bar) {
+gboolean LocationBarViewGtk::OnIconPressed(GtkWidget* sender,
+ GdkEventButton* event,
+ LocationBarViewGtk* location_bar) {
TabContents* tab = location_bar->GetTabContents();
NavigationEntry* nav_entry = tab->controller().GetActiveEntry();
if (!nav_entry) {
diff --git a/chrome/browser/gtk/location_bar_view_gtk.h b/chrome/browser/gtk/location_bar_view_gtk.h
index 6f8b708..12e384f 100644
--- a/chrome/browser/gtk/location_bar_view_gtk.h
+++ b/chrome/browser/gtk/location_bar_view_gtk.h
@@ -270,12 +270,12 @@ class LocationBarViewGtk : public AutocompleteEditController,
gboolean HandleExpose(GtkWidget* widget, GdkEventExpose* event);
- static gboolean OnSecurityIconPressed(GtkWidget* sender,
- GdkEventButton* event,
- LocationBarViewGtk* location_bar);
+ static gboolean OnIconPressed(GtkWidget* sender,
+ GdkEventButton* event,
+ LocationBarViewGtk* location_bar);
- // Set the SSL icon we should be showing.
- void SetSecurityIcon(int resource_id);
+ // Updates the location_icon_box_'s icon.
+ void UpdateIcon();
// Sets the text that should be displayed in the info label and its associated
// tooltip text. Call with an empty string if the info label should be
@@ -307,12 +307,11 @@ class LocationBarViewGtk : public AutocompleteEditController,
// The outermost widget we want to be hosted.
OwnedWidgetGtk hbox_;
- // SSL state.
- GtkWidget* security_icon_event_box_;
- GtkWidget* ev_secure_icon_image_;
- GtkWidget* secure_icon_image_;
- GtkWidget* security_warning_icon_image_;
- GtkWidget* security_error_icon_image_;
+ // An icon to the left of the address bar.
+ GtkWidget* location_icon_event_box_;
+ GtkWidget* location_icon_image_;
+ // TODO(pkasting): Split this label off and move the rest of the items to the
+ // left of the address bar.
GtkWidget* security_info_label_;
// Content setting icons.
diff --git a/chrome/browser/profile.cc b/chrome/browser/profile.cc
index b6a8716..7287f26 100644
--- a/chrome/browser/profile.cc
+++ b/chrome/browser/profile.cc
@@ -13,6 +13,7 @@
#include "base/scoped_ptr.h"
#include "base/string_util.h"
#include "chrome/browser/appcache/chrome_appcache_service.h"
+#include "chrome/browser/autocomplete/autocomplete_classifier.h"
#include "chrome/browser/autofill/personal_data_manager.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/browser_list.h"
@@ -42,7 +43,6 @@
#include "chrome/browser/privacy_blacklist/blacklist.h"
#include "chrome/browser/profile_manager.h"
#include "chrome/browser/renderer_host/render_process_host.h"
-#include "chrome/browser/search_versus_navigate_classifier.h"
#include "chrome/browser/search_engines/template_url_fetcher.h"
#include "chrome/browser/search_engines/template_url_model.h"
#include "chrome/browser/sessions/session_service.h"
@@ -308,8 +308,8 @@ class OffTheRecordProfileImpl : public Profile,
return NULL;
}
- virtual SearchVersusNavigateClassifier* GetSearchVersusNavigateClassifier() {
- return profile_->GetSearchVersusNavigateClassifier();
+ virtual AutocompleteClassifier* GetAutocompleteClassifier() {
+ return profile_->GetAutocompleteClassifier();
}
virtual WebDataService* GetWebDataService(ServiceAccessType sat) {
@@ -1048,13 +1048,10 @@ TemplateURLFetcher* ProfileImpl::GetTemplateURLFetcher() {
return template_url_fetcher_.get();
}
-SearchVersusNavigateClassifier*
-ProfileImpl::GetSearchVersusNavigateClassifier() {
- if (!search_versus_navigate_classifier_.get()) {
- search_versus_navigate_classifier_.reset(
- new SearchVersusNavigateClassifier(this));
- }
- return search_versus_navigate_classifier_.get();
+AutocompleteClassifier* ProfileImpl::GetAutocompleteClassifier() {
+ if (!autocomplete_classifier_.get())
+ autocomplete_classifier_.reset(new AutocompleteClassifier(this));
+ return autocomplete_classifier_.get();
}
WebDataService* ProfileImpl::GetWebDataService(ServiceAccessType sat) {
diff --git a/chrome/browser/profile.h b/chrome/browser/profile.h
index 9db5374..91faad0 100644
--- a/chrome/browser/profile.h
+++ b/chrome/browser/profile.h
@@ -30,6 +30,7 @@ namespace webkit_database {
class DatabaseTracker;
}
+class AutocompleteClassifier;
class Blacklist;
class BookmarkModel;
class BrowserThemeProvider;
@@ -54,7 +55,6 @@ class PinnedTabService;
class PrefService;
class ProfileSyncService;
class ProfileSyncFactory;
-class SearchVersusNavigateClassifier;
class SessionService;
class SpellCheckHost;
class SSLConfigServiceManager;
@@ -215,11 +215,10 @@ class Profile {
// doesn't already exist.
virtual HistoryService* GetHistoryServiceWithoutCreating() = 0;
- // Retrieves a pointer to the SearchVersusNavigateClassifier associated with
- // this profile. The SearchVersusNavigateClassifier is lazily created the
- // first time that this method is called.
- virtual SearchVersusNavigateClassifier*
- GetSearchVersusNavigateClassifier() = 0;
+ // Retrieves a pointer to the AutocompleteClassifier associated with this
+ // profile. The AutocompleteClassifier is lazily created the first time that
+ // this method is called.
+ virtual AutocompleteClassifier* GetAutocompleteClassifier() = 0;
// Returns the WebDataService for this profile. This is owned by
// the Profile. Callers that outlive the life of this profile need to be
@@ -452,7 +451,7 @@ class ProfileImpl : public Profile,
virtual FaviconService* GetFaviconService(ServiceAccessType sat);
virtual HistoryService* GetHistoryService(ServiceAccessType sat);
virtual HistoryService* GetHistoryServiceWithoutCreating();
- virtual SearchVersusNavigateClassifier* GetSearchVersusNavigateClassifier();
+ virtual AutocompleteClassifier* GetAutocompleteClassifier();
virtual WebDataService* GetWebDataService(ServiceAccessType sat);
virtual WebDataService* GetWebDataServiceWithoutCreating();
virtual PasswordStore* GetPasswordStore(ServiceAccessType sat);
@@ -570,7 +569,7 @@ class ProfileImpl : public Profile,
scoped_refptr<DownloadManager> download_manager_;
scoped_refptr<HistoryService> history_service_;
scoped_refptr<FaviconService> favicon_service_;
- scoped_ptr<SearchVersusNavigateClassifier> search_versus_navigate_classifier_;
+ scoped_ptr<AutocompleteClassifier> autocomplete_classifier_;
scoped_refptr<WebDataService> web_data_service_;
scoped_refptr<PasswordStore> password_store_;
scoped_refptr<SessionService> session_service_;
diff --git a/chrome/browser/search_versus_navigate_classifier.cc b/chrome/browser/search_versus_navigate_classifier.cc
deleted file mode 100644
index b32b92b..0000000
--- a/chrome/browser/search_versus_navigate_classifier.cc
+++ /dev/null
@@ -1,56 +0,0 @@
-// Copyright (c) 2009 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/search_versus_navigate_classifier.h"
-
-#include "chrome/browser/autocomplete/autocomplete.h"
-#include "googleurl/src/gurl.h"
-
-SearchVersusNavigateClassifier::SearchVersusNavigateClassifier(Profile* profile)
- : controller_(new AutocompleteController(profile)) {
-}
-
-SearchVersusNavigateClassifier::~SearchVersusNavigateClassifier() {
-}
-
-void SearchVersusNavigateClassifier::Classify(const std::wstring& text,
- const std::wstring& desired_tld,
- bool* is_search,
- GURL* destination_url,
- PageTransition::Type* transition,
- bool* is_history_what_you_typed_match,
- GURL* alternate_nav_url) {
- controller_->Start(text, desired_tld, true, false, true);
- DCHECK(controller_->done());
- const AutocompleteResult& result = controller_->result();
- if (result.empty()) {
- if (is_search)
- *is_search = false;
- if (destination_url)
- *destination_url = GURL();
- if (transition)
- *transition = PageTransition::TYPED;
- if (is_history_what_you_typed_match)
- *is_history_what_you_typed_match = false;
- if (alternate_nav_url)
- *alternate_nav_url = GURL();
- return;
- }
-
- const AutocompleteResult::const_iterator match(result.default_match());
- DCHECK(match != result.end());
-
- // If this is a search, the page transition will be GENERATED rather than
- // TYPED.
- if (is_search)
- *is_search = (match->transition != PageTransition::TYPED);
- if (destination_url)
- *destination_url = match->destination_url;
- 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.alternate_nav_url();
-}
diff --git a/chrome/browser/search_versus_navigate_classifier.h b/chrome/browser/search_versus_navigate_classifier.h
deleted file mode 100644
index 94471b8..0000000
--- a/chrome/browser/search_versus_navigate_classifier.h
+++ /dev/null
@@ -1,52 +0,0 @@
-// Copyright (c) 2009 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_SEARCH_VERSUS_NAVIGATE_CLASSIFIER_H_
-#define CHROME_BROWSER_SEARCH_VERSUS_NAVIGATE_CLASSIFIER_H_
-
-#include <string>
-
-#include "base/scoped_ptr.h"
-#include "chrome/common/page_transition_types.h"
-
-class AutocompleteController;
-class GURL;
-class Profile;
-
-class SearchVersusNavigateClassifier {
- public:
- explicit SearchVersusNavigateClassifier(Profile* profile);
- virtual ~SearchVersusNavigateClassifier();
-
- // Given some string |text| that the user wants to use for navigation,
- // determines whether to treat it as a search query or a URL, and returns the
- // details of the resulting navigation.
- // NOTE: After |desired_tld|, all parameters are potentially-NULL outparams.
- // |desired_tld| - User's desired TLD.
- // See AutocompleteInput::desired_tld().
- // |is_search| - Set to true if this is to be treated as a
- // query rather than URL.
- // |destination_url| - The URL to load. It may be empty if there is no
- // possible navigation (when |text| is empty).
- // |transition| - The transition type.
- // |is_history_what_you_typed_match|
- // - Set to true when the default match is the
- // "what you typed" match from the history.
- // |alternate_nav_url| - The navigational URL in case of an accidental
- // search; see comments on
- // AutocompleteResult::alternate_nav_url_ in
- // autocomplete.h.
- void Classify(const std::wstring& text,
- const std::wstring& desired_tld,
- bool* is_search,
- GURL* destination_url,
- PageTransition::Type* transition,
- bool* is_history_what_you_typed_match,
- GURL* alternate_nav_url);
-
- private:
- scoped_ptr<AutocompleteController> controller_;
-};
-
-#endif // CHROME_BROWSER_SEARCH_VERSUS_NAVIGATE_CLASSIFIER_H_
diff --git a/chrome/browser/tab_contents/render_view_context_menu.cc b/chrome/browser/tab_contents/render_view_context_menu.cc
index 137311d..c44ca8b 100644
--- a/chrome/browser/tab_contents/render_view_context_menu.cc
+++ b/chrome/browser/tab_contents/render_view_context_menu.cc
@@ -12,6 +12,7 @@
#include "base/command_line.h"
#include "base/logging.h"
#include "chrome/app/chrome_dll_resource.h"
+#include "chrome/browser/autocomplete/autocomplete_classifier.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/debugger/devtools_manager.h"
#include "chrome/browser/debugger/devtools_window.h"
@@ -26,7 +27,6 @@
#include "chrome/browser/profile.h"
#include "chrome/browser/renderer_host/render_view_host.h"
#include "chrome/browser/renderer_host/translation_service.h"
-#include "chrome/browser/search_versus_navigate_classifier.h"
#include "chrome/browser/search_engines/template_url_model.h"
#include "chrome/browser/spellcheck_host.h"
#include "chrome/browser/spellchecker_platform_engine.h"
@@ -444,10 +444,10 @@ void RenderViewContextMenu::AppendSearchProvider() {
if (params_.selection_text.empty())
return;
- bool is_search;
- profile_->GetSearchVersusNavigateClassifier()->Classify(
- params_.selection_text, std::wstring(), &is_search,
- &selection_navigation_url_, NULL, NULL, NULL);
+ AutocompleteMatch match;
+ profile_->GetAutocompleteClassifier()->Classify(params_.selection_text,
+ std::wstring(), &match, NULL);
+ selection_navigation_url_ = match.destination_url;
if (!selection_navigation_url_.is_valid())
return;
@@ -457,7 +457,11 @@ void RenderViewContextMenu::AppendSearchProvider() {
i = printable_selection_text.find('&', i + 2))
printable_selection_text.insert(i, 1, '&');
- if (is_search) {
+ if (match.transition == PageTransition::TYPED) {
+ AppendMenuItem(IDS_CONTENT_CONTEXT_GOTOURL,
+ l10n_util::GetStringFUTF16(IDS_CONTENT_CONTEXT_GOTOURL,
+ printable_selection_text));
+ } else {
const TemplateURL* const default_provider =
profile_->GetTemplateURLModel()->GetDefaultSearchProvider();
if (!default_provider)
@@ -466,10 +470,6 @@ void RenderViewContextMenu::AppendSearchProvider() {
l10n_util::GetStringFUTF16(IDS_CONTENT_CONTEXT_SEARCHWEBFOR,
WideToUTF16(default_provider->short_name()),
printable_selection_text));
- } else {
- AppendMenuItem(IDS_CONTENT_CONTEXT_GOTOURL,
- l10n_util::GetStringFUTF16(IDS_CONTENT_CONTEXT_GOTOURL,
- printable_selection_text));
}
}
diff --git a/chrome/browser/toolbar_model.cc b/chrome/browser/toolbar_model.cc
index d93edae..184055f 100644
--- a/chrome/browser/toolbar_model.cc
+++ b/chrome/browser/toolbar_model.cc
@@ -84,9 +84,9 @@ ToolbarModel::SecurityLevel ToolbarModel::GetSecurityLevel() const {
}
}
-int ToolbarModel::GetSecurityIcon() const {
+int ToolbarModel::GetIcon() const {
static int icon_ids[NUM_SECURITY_LEVELS] = {
- 0,
+ IDR_O2_GLOBE,
IDR_EV_SECURE,
IDR_SECURE,
IDR_SECURITY_WARNING,
diff --git a/chrome/browser/toolbar_model.h b/chrome/browser/toolbar_model.h
index 7827e41..865d39d 100644
--- a/chrome/browser/toolbar_model.h
+++ b/chrome/browser/toolbar_model.h
@@ -36,8 +36,10 @@ class ToolbarModel {
// Returns the security level that the toolbar should display.
SecurityLevel GetSecurityLevel() const;
- // Returns the resource_id of the icon to show to the left of the address.
- int GetSecurityIcon() const;
+ // Returns the resource_id of the icon to show to the left of the address,
+ // based on the current URL. This doesn't cover specialized icons while the
+ // user is editing; see AutocompleteEditView::GetIcon().
+ int GetIcon() const;
// Sets the text displayed in the info bubble that appears when the user
// hovers the mouse over the icon.
diff --git a/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc b/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc
index 72f551d..fe8acb3 100644
--- a/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc
+++ b/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc
@@ -170,40 +170,15 @@ class AutocompleteResultView : public views::View {
gfx::Rect icon_bounds_;
gfx::Rect text_bounds_;
- // Icons for rows.
- static SkBitmap* icon_url_;
- static SkBitmap* icon_url_selected_;
- static SkBitmap* icon_history_;
- static SkBitmap* icon_history_selected_;
- static SkBitmap* icon_search_;
- static SkBitmap* icon_search_selected_;
- static SkBitmap* icon_more_;
- static SkBitmap* icon_more_selected_;
- static SkBitmap* icon_star_;
- static SkBitmap* icon_star_selected_;
static int icon_size_;
AutocompleteMatch match_;
- static bool initialized_;
- static void InitClass();
-
DISALLOW_COPY_AND_ASSIGN(AutocompleteResultView);
};
// static
-SkBitmap* AutocompleteResultView::icon_url_ = NULL;
-SkBitmap* AutocompleteResultView::icon_url_selected_ = NULL;
-SkBitmap* AutocompleteResultView::icon_history_ = NULL;
-SkBitmap* AutocompleteResultView::icon_history_selected_ = NULL;
-SkBitmap* AutocompleteResultView::icon_search_ = NULL;
-SkBitmap* AutocompleteResultView::icon_search_selected_ = NULL;
-SkBitmap* AutocompleteResultView::icon_star_ = NULL;
-SkBitmap* AutocompleteResultView::icon_star_selected_ = NULL;
-SkBitmap* AutocompleteResultView::icon_more_ = NULL;
-SkBitmap* AutocompleteResultView::icon_more_selected_ = NULL;
int AutocompleteResultView::icon_size_ = 0;
-bool AutocompleteResultView::initialized_ = false;
// This class is a utility class which mirrors an x position, calculates the
// index of the i-th run of a text, and calculates the index of the i-th
@@ -322,7 +297,11 @@ AutocompleteResultView::AutocompleteResultView(
mirroring_context_(new MirroringContext()),
match_(NULL, 0, false, AutocompleteMatch::URL_WHAT_YOU_TYPED) {
CHECK(model_index >= 0);
- InitClass();
+ if (icon_size_ == 0) {
+ icon_size_ = ResourceBundle::GetSharedInstance().GetBitmapNamed(
+ AutocompleteMatch::TypeToIcon(AutocompleteMatch::URL_WHAT_YOU_TYPED))->
+ width();
+ }
}
AutocompleteResultView::~AutocompleteResultView() {
@@ -389,29 +368,19 @@ ResultViewState AutocompleteResultView::GetState() const {
}
SkBitmap* AutocompleteResultView::GetIcon() const {
- bool selected = model_->IsSelectedIndex(model_index_);
- if (match_.starred)
- return selected ? icon_star_selected_ : icon_star_;
- switch (match_.type) {
- case AutocompleteMatch::URL_WHAT_YOU_TYPED:
- case AutocompleteMatch::HISTORY_URL:
- case AutocompleteMatch::NAVSUGGEST:
- return selected ? icon_url_selected_ : icon_url_;
- case AutocompleteMatch::HISTORY_TITLE:
- case AutocompleteMatch::HISTORY_BODY:
- case AutocompleteMatch::HISTORY_KEYWORD:
- return selected ? icon_history_selected_ : icon_history_;
- case AutocompleteMatch::SEARCH_WHAT_YOU_TYPED:
- case AutocompleteMatch::SEARCH_HISTORY:
- case AutocompleteMatch::SEARCH_SUGGEST:
- case AutocompleteMatch::SEARCH_OTHER_ENGINE:
- return selected ? icon_search_selected_ : icon_search_;
- case AutocompleteMatch::OPEN_HISTORY_PAGE:
- return selected ? icon_more_selected_ : icon_more_;
- default:
- NOTREACHED();
- return NULL;
+ int icon = match_.starred ?
+ IDR_O2_STAR : AutocompleteMatch::TypeToIcon(match_.type);
+ if (model_->IsSelectedIndex(model_index_)) {
+ switch (icon) {
+ case IDR_O2_GLOBE: icon = IDR_O2_GLOBE_SELECTED; break;
+ case IDR_O2_HISTORY: icon = IDR_O2_HISTORY_SELECTED; break;
+ case IDR_O2_SEARCH: icon = IDR_O2_SEARCH_SELECTED; break;
+ case IDR_O2_MORE: icon = IDR_O2_MORE_SELECTED; break;
+ case IDR_O2_STAR: icon = IDR_O2_STAR_SELECTED; break;
+ default: NOTREACHED(); break;
+ }
}
+ return ResourceBundle::GetSharedInstance().GetBitmapNamed(icon);
}
int AutocompleteResultView::DrawString(
@@ -531,25 +500,6 @@ SkColor AutocompleteResultView::GetFragmentTextColor(int style) const {
(style & ACMatchClassification::DIM) ? DIMMED_TEXT : TEXT);
}
-void AutocompleteResultView::InitClass() {
- if (!initialized_) {
- ResourceBundle& rb = ResourceBundle::GetSharedInstance();
- icon_url_ = rb.GetBitmapNamed(IDR_O2_GLOBE);
- icon_url_selected_ = rb.GetBitmapNamed(IDR_O2_GLOBE_SELECTED);
- icon_history_ = rb.GetBitmapNamed(IDR_O2_HISTORY);
- icon_history_selected_ = rb.GetBitmapNamed(IDR_O2_HISTORY_SELECTED);
- icon_search_ = rb.GetBitmapNamed(IDR_O2_SEARCH);
- icon_search_selected_ = rb.GetBitmapNamed(IDR_O2_SEARCH_SELECTED);
- icon_star_ = rb.GetBitmapNamed(IDR_O2_STAR);
- icon_star_selected_ = rb.GetBitmapNamed(IDR_O2_STAR_SELECTED);
- icon_more_ = rb.GetBitmapNamed(IDR_O2_MORE);
- icon_more_selected_ = rb.GetBitmapNamed(IDR_O2_MORE_SELECTED);
- // All icons are assumed to be square, and the same size.
- icon_size_ = icon_url_->width();
- initialized_ = true;
- }
-}
-
////////////////////////////////////////////////////////////////////////////////
// AutocompletePopupContentsView, public:
diff --git a/chrome/browser/views/frame/browser_root_view.cc b/chrome/browser/views/frame/browser_root_view.cc
index d789b94..d2985dd 100644
--- a/chrome/browser/views/frame/browser_root_view.cc
+++ b/chrome/browser/views/frame/browser_root_view.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 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.
@@ -7,9 +7,10 @@
#include "app/drag_drop_types.h"
#include "app/l10n_util.h"
#include "app/os_exchange_data.h"
+#include "chrome/browser/autocomplete/autocomplete.h"
+#include "chrome/browser/autocomplete/autocomplete_classifier.h"
#include "chrome/browser/location_bar.h"
#include "chrome/browser/profile.h"
-#include "chrome/browser/search_versus_navigate_classifier.h"
#include "chrome/browser/views/frame/browser_view.h"
#include "chrome/browser/views/frame/browser_frame.h"
#include "chrome/browser/views/tabs/tab_strip.h"
@@ -141,13 +142,13 @@ bool BrowserRootView::GetPasteAndGoURL(const OSExchangeData& data, GURL* url) {
if (!data.GetString(&text) || text.empty())
return false;
- GURL destination_url;
- browser_view_->browser()->profile()->GetSearchVersusNavigateClassifier()->
- Classify(text, std::wstring(), NULL, &destination_url, NULL, NULL, NULL);
- if (!destination_url.is_valid())
+ AutocompleteMatch match;
+ browser_view_->browser()->profile()->GetAutocompleteClassifier()->Classify(
+ text, std::wstring(), &match, NULL);
+ if (!match.destination_url.is_valid())
return false;
if (url)
- *url = destination_url;
+ *url = match.destination_url;
return true;
}
diff --git a/chrome/browser/views/location_bar_view.cc b/chrome/browser/views/location_bar_view.cc
index 1d9ced9..4c2fe3e 100644
--- a/chrome/browser/views/location_bar_view.cc
+++ b/chrome/browser/views/location_bar_view.cc
@@ -135,7 +135,7 @@ LocationBarView::LocationBarView(Profile* profile,
model_(model),
delegate_(delegate),
disposition_(CURRENT_TAB),
- security_image_view_(this),
+ location_icon_view_(this),
location_entry_view_(NULL),
selected_keyword_view_(profile),
keyword_hint_view_(profile),
@@ -166,9 +166,9 @@ void LocationBarView::Init() {
font_ = font_.DeriveFont(3);
}
- AddChildView(&security_image_view_);
- security_image_view_.SetVisible(false);
- security_image_view_.set_parent_owned(false);
+ AddChildView(&location_icon_view_);
+ location_icon_view_.SetVisible(true);
+ location_icon_view_.set_parent_owned(false);
// URL edit field.
// View container for URL edit field.
@@ -290,7 +290,6 @@ SkColor LocationBarView::GetColor(ToolbarModel::SecurityLevel security_level,
}
void LocationBarView::Update(const TabContents* tab_for_state_restoring) {
- security_image_view_.SetSecurityIcon(model_->GetSecurityIcon());
// The visibility of the |security_info_label_| will be set during layout.
std::wstring security_info_text(model_->GetSecurityInfoText());
security_info_label_.SetText(security_info_text);
@@ -302,8 +301,7 @@ void LocationBarView::Update(const TabContents* tab_for_state_restoring) {
RefreshContentSettingViews();
RefreshPageActionViews();
location_entry_->Update(tab_for_state_restoring);
- Layout();
- SchedulePaint();
+ OnChanged();
}
void LocationBarView::UpdateContentSettingsIcons() {
@@ -396,7 +394,136 @@ gfx::Size LocationBarView::GetPreferredSize() {
}
void LocationBarView::Layout() {
- DoLayout(true);
+ if (!location_entry_.get())
+ return;
+
+ int entry_width = width() - (kEntryPadding * 2);
+
+ // |location_icon_view_| is always visible except when
+ // |selected_keyword_view_| is visible.
+ int location_icon_width = 0;
+ const std::wstring keyword(location_entry_->model()->keyword());
+ const bool is_keyword_hint(location_entry_->model()->is_keyword_hint());
+ const bool show_selected_keyword = !keyword.empty() && !is_keyword_hint;
+ if (show_selected_keyword) {
+ location_icon_view_.SetVisible(false);
+ } else {
+ location_icon_view_.SetVisible(true);
+ location_icon_width = location_icon_view_.GetPreferredSize().width();
+ entry_width -= location_icon_width + kInnerPadding;
+ }
+
+ for (PageActionViews::const_iterator i(page_action_views_.begin());
+ i != page_action_views_.end(); ++i) {
+ if ((*i)->IsVisible())
+ entry_width -= (*i)->GetPreferredSize().width() + kInnerPadding;
+ }
+ for (ContentSettingViews::const_iterator i(content_setting_views_.begin());
+ i != content_setting_views_.end(); ++i) {
+ if ((*i)->IsVisible())
+ entry_width -= (*i)->GetPreferredSize().width() + kInnerPadding;
+ }
+
+#if defined(OS_WIN)
+ RECT formatting_rect;
+ location_entry_->GetRect(&formatting_rect);
+ RECT edit_bounds;
+ location_entry_->GetClientRect(&edit_bounds);
+ int max_edit_width = entry_width - formatting_rect.left -
+ (edit_bounds.right - formatting_rect.right);
+#else
+ int max_edit_width = entry_width;
+#endif
+
+ if (max_edit_width < 0)
+ return;
+ const int available_width = AvailableWidth(max_edit_width);
+
+ const bool show_keyword_hint = !keyword.empty() && is_keyword_hint;
+ bool show_search_hint(location_entry_->model()->show_search_hint());
+ DCHECK(keyword.empty() || !show_search_hint);
+
+ if (show_search_hint) {
+ // Only show type to search if all the text fits.
+ gfx::Size preferred_size = type_to_search_view_.GetPreferredSize();
+ show_search_hint = UsePref(preferred_size.width(), available_width);
+ }
+
+ bool show_security_info_label = !security_info_label_.GetText().empty();
+ if (show_security_info_label) {
+ // Only show the security info label if all the text fits.
+ gfx::Size preferred_size = security_info_label_.GetPreferredSize();
+ show_security_info_label = UsePref(preferred_size.width(), available_width);
+ }
+
+ selected_keyword_view_.SetVisible(show_selected_keyword);
+ keyword_hint_view_.SetVisible(show_keyword_hint);
+ type_to_search_view_.SetVisible(show_search_hint);
+ security_info_label_.SetVisible(show_security_info_label);
+ if (show_selected_keyword) {
+ if (selected_keyword_view_.keyword() != keyword)
+ selected_keyword_view_.SetKeyword(keyword);
+ } else if (show_keyword_hint) {
+ if (keyword_hint_view_.keyword() != keyword)
+ keyword_hint_view_.SetKeyword(keyword);
+ }
+
+ // TODO(sky): baseline layout.
+ int location_y = TopMargin();
+ int location_height = std::max(height() - location_y - kVertMargin, 0);
+
+ // Lay out items to the right of the edit field.
+ int offset = width() - kEntryPadding;
+ for (PageActionViews::const_iterator i(page_action_views_.begin());
+ i != page_action_views_.end(); ++i) {
+ if ((*i)->IsVisible()) {
+ int page_action_width = (*i)->GetPreferredSize().width();
+ offset -= page_action_width;
+ (*i)->SetBounds(offset, location_y, page_action_width, location_height);
+ offset -= kInnerPadding;
+ }
+ }
+ // We use a reverse_iterator here because we're laying out the views from
+ // right to left but in the vector they're ordered left to right.
+ for (ContentSettingViews::const_reverse_iterator
+ i(content_setting_views_.rbegin()); i != content_setting_views_.rend();
+ ++i) {
+ if ((*i)->IsVisible()) {
+ int content_blocked_width = (*i)->GetPreferredSize().width();
+ offset -= content_blocked_width;
+ (*i)->SetBounds(offset, location_y, content_blocked_width,
+ location_height);
+ offset -= kInnerPadding;
+ }
+ }
+
+ // Now lay out items to the left of the edit field.
+ offset = kEntryPadding;
+ if (location_icon_view_.IsVisible()) {
+ location_icon_view_.SetBounds(offset, location_y, location_icon_width,
+ location_height);
+ offset = location_icon_view_.bounds().right() + kInnerPadding;
+ }
+
+ // Now lay out the edit field and views that autocollapse to give it more
+ // room.
+ gfx::Rect location_bounds(offset, location_y, entry_width, location_height);
+ if (show_selected_keyword) {
+ LayoutView(true, &selected_keyword_view_, available_width,
+ &location_bounds);
+ } else if (show_keyword_hint) {
+ LayoutView(false, &keyword_hint_view_, available_width,
+ &location_bounds);
+ } else if (show_search_hint) {
+ LayoutView(false, &type_to_search_view_, available_width,
+ &location_bounds);
+ }
+ if (show_security_info_label) {
+ LayoutView(false, &security_info_label_, available_width,
+ &location_bounds);
+ }
+
+ location_entry_view_->SetBounds(location_bounds);
}
void LocationBarView::Paint(gfx::Canvas* canvas) {
@@ -498,7 +625,11 @@ void LocationBarView::OnAutocompleteAccept(
}
void LocationBarView::OnChanged() {
- DoLayout(false);
+ location_icon_view_.SetImage(
+ ResourceBundle::GetSharedInstance().GetBitmapNamed(
+ location_entry_->GetIcon()));
+ Layout();
+ SchedulePaint();
}
void LocationBarView::OnInputInProgress(bool in_progress) {
@@ -529,112 +660,6 @@ std::wstring LocationBarView::GetTitle() const {
return UTF16ToWideHack(delegate_->GetTabContents()->GetTitle());
}
-void LocationBarView::DoLayout(const bool force_layout) {
- if (!location_entry_.get())
- return;
-
- int entry_width = width() - (kEntryPadding * 2);
-
- gfx::Size security_image_size;
- if (security_image_view_.IsVisible()) {
- security_image_size = security_image_view_.GetPreferredSize();
- entry_width -= security_image_size.width() + kInnerPadding;
- }
- for (PageActionViews::const_iterator i(page_action_views_.begin());
- i != page_action_views_.end(); ++i) {
- if ((*i)->IsVisible())
- entry_width -= (*i)->GetPreferredSize().width() + kInnerPadding;
- }
- for (ContentSettingViews::const_iterator i(content_setting_views_.begin());
- i != content_setting_views_.end(); ++i) {
- if ((*i)->IsVisible())
- entry_width -= (*i)->GetPreferredSize().width() + kInnerPadding;
- }
-
-#if defined(OS_WIN)
- RECT formatting_rect;
- location_entry_->GetRect(&formatting_rect);
- RECT edit_bounds;
- location_entry_->GetClientRect(&edit_bounds);
- int max_edit_width = entry_width - formatting_rect.left -
- (edit_bounds.right - formatting_rect.right);
-#else
- int max_edit_width = entry_width;
-#endif
-
- if (max_edit_width < 0)
- return;
- const int available_width = AvailableWidth(max_edit_width);
- bool needs_layout = force_layout;
- needs_layout |= AdjustAutocollapseViews(available_width);
-
- if (!needs_layout)
- return;
-
- // TODO(sky): baseline layout.
- int location_y = TopMargin();
- int location_height = std::max(height() - location_y - kVertMargin, 0);
-
- // Lay out items to the right of the edit field.
- int offset = width() - kEntryPadding;
- for (PageActionViews::const_iterator i(page_action_views_.begin());
- i != page_action_views_.end(); ++i) {
- if ((*i)->IsVisible()) {
- int page_action_width = (*i)->GetPreferredSize().width();
- offset -= page_action_width;
- (*i)->SetBounds(offset, location_y, page_action_width, location_height);
- offset -= kInnerPadding;
- }
- }
- // We use a reverse_iterator here because we're laying out the views from
- // right to left but in the vector they're ordered left to right.
- for (ContentSettingViews::const_reverse_iterator
- i(content_setting_views_.rbegin()); i != content_setting_views_.rend();
- ++i) {
- if ((*i)->IsVisible()) {
- int content_blocked_width = (*i)->GetPreferredSize().width();
- offset -= content_blocked_width;
- (*i)->SetBounds(offset, location_y, content_blocked_width,
- location_height);
- offset -= kInnerPadding;
- }
- }
-
- // Now lay out items to the left of the edit field.
- offset = kEntryPadding;
- if (security_image_view_.IsVisible()) {
- security_image_view_.SetBounds(offset, location_y,
- security_image_size.width(),
- location_height);
- offset = security_image_view_.bounds().right() + kInnerPadding;
- }
-
- // Now lay out the edit field and views that autocollapse to give it more
- // room.
- gfx::Rect location_bounds(offset, location_y, entry_width, location_height);
- if (selected_keyword_view_.IsVisible()) {
- LayoutView(true, &selected_keyword_view_, available_width,
- &location_bounds);
- } else if (keyword_hint_view_.IsVisible()) {
- LayoutView(false, &keyword_hint_view_, available_width,
- &location_bounds);
- } else if (type_to_search_view_.IsVisible()) {
- LayoutView(false, &type_to_search_view_, available_width,
- &location_bounds);
- }
- if (security_info_label_.IsVisible()) {
- LayoutView(false, &security_info_label_, available_width,
- &location_bounds);
- }
-
- location_entry_view_->SetBounds(location_bounds);
- if (!force_layout) {
- // If force_layout is false and we got this far it means one of the views
- // was added/removed or changed in size. We need to paint ourselves.
- SchedulePaint();
- }
-}
-
int LocationBarView::TopMargin() const {
return std::min(kVertMargin, height());
}
@@ -656,60 +681,6 @@ bool LocationBarView::UsePref(int pref_width, int available_width) {
return (pref_width + kInnerPadding <= available_width);
}
-bool LocationBarView::NeedsResize(View* view, int available_width) {
- gfx::Size size = view->GetPreferredSize();
- if (!UsePref(size.width(), available_width))
- size = view->GetMinimumSize();
- return (view->width() != size.width());
-}
-
-bool LocationBarView::AdjustAutocollapseViews(int available_width) {
- const std::wstring keyword(location_entry_->model()->keyword());
- const bool is_keyword_hint(location_entry_->model()->is_keyword_hint());
- const bool show_selected_keyword = !keyword.empty() && !is_keyword_hint;
- const bool show_keyword_hint = !keyword.empty() && is_keyword_hint;
- bool show_search_hint(location_entry_->model()->show_search_hint());
- DCHECK(keyword.empty() || !show_search_hint);
-
- if (show_search_hint) {
- // Only show type to search if all the text fits.
- gfx::Size preferred_size = type_to_search_view_.GetPreferredSize();
- show_search_hint = UsePref(preferred_size.width(), available_width);
- }
-
- bool show_security_info_label = !security_info_label_.GetText().empty();
- if (show_security_info_label) {
- // Only show the security info label if all the text fits.
- gfx::Size preferred_size = security_info_label_.GetPreferredSize();
- show_security_info_label = UsePref(preferred_size.width(), available_width);
- }
-
- // NOTE: This isn't just one big || statement as ToggleVisibility MUST be
- // invoked for each view.
- bool needs_layout = false;
- needs_layout |= ToggleVisibility(show_selected_keyword,
- &selected_keyword_view_);
- needs_layout |= ToggleVisibility(show_keyword_hint, &keyword_hint_view_);
- needs_layout |= ToggleVisibility(show_search_hint, &type_to_search_view_);
- needs_layout |= ToggleVisibility(show_security_info_label,
- &security_info_label_);
- if (show_selected_keyword) {
- if (selected_keyword_view_.keyword() != keyword) {
- needs_layout = true;
- selected_keyword_view_.SetKeyword(keyword);
- }
- needs_layout |= NeedsResize(&selected_keyword_view_, available_width);
- } else if (show_keyword_hint) {
- if (keyword_hint_view_.keyword() != keyword) {
- needs_layout = true;
- keyword_hint_view_.SetKeyword(keyword);
- }
- needs_layout |= NeedsResize(&keyword_hint_view_, available_width);
- }
-
- return needs_layout;
-}
-
void LocationBarView::LayoutView(bool leading,
views::View* view,
int available_width,
@@ -804,14 +775,6 @@ void LocationBarView::RefreshPageActionViews() {
}
}
-bool LocationBarView::ToggleVisibility(bool new_vis, View* view) {
- DCHECK(view);
- if (view->IsVisible() == new_vis)
- return false;
- view->SetVisible(new_vis);
- return true;
-}
-
#if defined(OS_WIN)
void LocationBarView::OnMouseEvent(const views::MouseEvent& event, UINT msg) {
UINT flags = 0;
@@ -888,28 +851,17 @@ void LocationBarView::SetAccessibleName(const std::wstring& name) {
accessible_name_.assign(name);
}
-// SecurityImageView------------------------------------------------------------
+// LocationIconView-------------------------------------------------------------
-LocationBarView::SecurityImageView::SecurityImageView(
+LocationBarView::LocationIconView::LocationIconView(
const LocationBarView* parent)
: parent_(parent) {
- SetSecurityIcon(0);
}
-LocationBarView::SecurityImageView::~SecurityImageView() {
-}
-
-void LocationBarView::SecurityImageView::SetSecurityIcon(int icon_id) {
- if (icon_id == 0) {
- SetVisible(false);
- return;
- }
-
- SetImage(ResourceBundle::GetSharedInstance().GetBitmapNamed(icon_id));
- SetVisible(true);
+LocationBarView::LocationIconView::~LocationIconView() {
}
-bool LocationBarView::SecurityImageView::OnMousePressed(
+bool LocationBarView::LocationIconView::OnMousePressed(
const views::MouseEvent& event) {
TabContents* tab = parent_->GetTabContents();
NavigationEntry* nav_entry = tab->controller().GetActiveEntry();
diff --git a/chrome/browser/views/location_bar_view.h b/chrome/browser/views/location_bar_view.h
index e2b5720..750983c 100644
--- a/chrome/browser/views/location_bar_view.h
+++ b/chrome/browser/views/location_bar_view.h
@@ -189,15 +189,13 @@ class LocationBarView : public LocationBar,
void Focus();
private:
- // SecurityImageView is used to display the appropriate status icon when the
- // current URL's scheme is https.
- class SecurityImageView : public views::ImageView {
+ // LocationIconView is used to display an icon to the left of the edit field.
+ // This shows the user's current action while editing, the page security
+ // status on https pages, or a globe for other URLs.
+ class LocationIconView : public views::ImageView {
public:
- explicit SecurityImageView(const LocationBarView* parent);
- virtual ~SecurityImageView();
-
- // Sets the image that should be displayed.
- void SetSecurityIcon(int resource_id);
+ explicit LocationIconView(const LocationBarView* parent);
+ virtual ~LocationIconView();
// Overridden from view.
virtual bool OnMousePressed(const views::MouseEvent& event);
@@ -206,7 +204,7 @@ class LocationBarView : public LocationBar,
// The owning LocationBarView.
const LocationBarView* parent_;
- DISALLOW_COPY_AND_ASSIGN(SecurityImageView);
+ DISALLOW_COPY_AND_ASSIGN(LocationIconView);
};
// View used when the user has selected a keyword.
@@ -430,12 +428,6 @@ class LocationBarView : public LocationBar,
friend class PageActionWithBadgeView;
typedef std::vector<PageActionWithBadgeView*> PageActionViews;
- // Both Layout and OnChanged call into this. This updates the contents
- // of the 3 views: selected_keyword, keyword_hint and type_search_view. If
- // force_layout is true, or one of these views has changed in such a way as
- // to necessitate a layout, layout occurs as well.
- void DoLayout(bool force_layout);
-
// Returns the height in pixels of the margin at the top of the bar.
int TopMargin() const;
@@ -450,16 +442,6 @@ class LocationBarView : public LocationBar,
// minimum size of the view should be used.
bool UsePref(int pref_width, int available_width);
- // Returns true if the view needs to be resized. This determines whether the
- // min or pref should be used, and returns true if the view is not at that
- // size.
- bool NeedsResize(View* view, int available_width);
-
- // Adjusts the keyword hint, selected keyword view, type to search label, and
- // security info label based on the contents of the edit. Returns true if
- // something changed that necessitates a layout.
- bool AdjustAutocollapseViews(int available_width);
-
// If View fits in the specified region, it is made visible and the
// bounds are adjusted appropriately. If the View does not fit, it is
// made invisible.
@@ -477,9 +459,8 @@ class LocationBarView : public LocationBar,
// PageActions.
void RefreshPageActionViews();
- // Sets the visibility of view to new_vis. Returns whether the visibility
- // changed.
- bool ToggleVisibility(bool new_vis, views::View* view);
+ // Sets the visibility of view to new_vis.
+ void ToggleVisibility(bool new_vis, views::View* view);
#if defined(OS_WIN)
// Helper for the Mouse event handlers that does all the real work.
@@ -524,8 +505,8 @@ class LocationBarView : public LocationBar,
// Font used by edit and some of the hints.
gfx::Font font_;
- // The view that shows the lock/warning when in HTTPS mode.
- SecurityImageView security_image_view_;
+ // An icon to the left of the edit field.
+ LocationIconView location_icon_view_;
// Location_entry view wrapper
views::NativeViewHost* location_entry_view_;
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 37a8d46..cbd819bc 100755
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -79,6 +79,8 @@
'browser/autocomplete/autocomplete.h',
'browser/autocomplete/autocomplete_accessibility.cc',
'browser/autocomplete/autocomplete_accessibility.h',
+ 'browser/autocomplete/autocomplete_classifier.cc',
+ 'browser/autocomplete/autocomplete_classifier.h',
'browser/autocomplete/autocomplete_edit.cc',
'browser/autocomplete/autocomplete_edit.h',
'browser/autocomplete/autocomplete_edit_view.h',
@@ -1836,8 +1838,6 @@
'browser/safe_browsing/safe_browsing_store_sqlite.h',
'browser/safe_browsing/safe_browsing_util.cc',
'browser/safe_browsing/safe_browsing_util.h',
- 'browser/search_versus_navigate_classifier.cc',
- 'browser/search_versus_navigate_classifier.h',
'browser/search_engines/edit_search_engine_controller.cc',
'browser/search_engines/edit_search_engine_controller.h',
'browser/search_engines/keyword_editor_controller.cc',
diff --git a/chrome/test/testing_profile.cc b/chrome/test/testing_profile.cc
index b0be809..4a7484e 100644
--- a/chrome/test/testing_profile.cc
+++ b/chrome/test/testing_profile.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 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.
@@ -237,6 +237,10 @@ void TestingProfile::CreateBookmarkModel(bool delete_file) {
bookmark_bar_model_->Load();
}
+void TestingProfile::CreateAutocompleteClassifier() {
+ autocomplete_classifier_.reset(new AutocompleteClassifier(this));
+}
+
void TestingProfile::CreateWebDataService(bool delete_file) {
if (web_data_service_.get())
web_data_service_->Shutdown();
diff --git a/chrome/test/testing_profile.h b/chrome/test/testing_profile.h
index ce1603d..02cf1fd 100644
--- a/chrome/test/testing_profile.h
+++ b/chrome/test/testing_profile.h
@@ -8,6 +8,7 @@
#include "base/base_paths.h"
#include "base/file_util.h"
#include "base/path_service.h"
+#include "chrome/browser/autocomplete/autocomplete_classifier.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/browser_prefs.h"
#include "chrome/browser/browser_theme_provider.h"
@@ -58,14 +59,16 @@ class TestingProfile : public Profile {
// BlockUntilBookmarkModelLoaded.
void CreateBookmarkModel(bool delete_file);
+ // Creates an AutocompleteClassifier. If not invoked the
+ // AutocompleteClassifier is NULL.
+ void CreateAutocompleteClassifier();
+
// Creates the webdata service. If |delete_file| is true, the webdata file is
// deleted first, then the WebDataService is created. As TestingProfile
// deletes the directory containing the files used by WebDataService, this
// only matters if you're recreating the WebDataService.
void CreateWebDataService(bool delete_file);
- // Destroys
-
// Blocks until the BookmarkModel finishes loaded. This is NOT invoked from
// CreateBookmarkModel.
void BlockUntilBookmarkModelLoaded();
@@ -127,8 +130,8 @@ class TestingProfile : public Profile {
return NULL;
return GetRequestContext()->GetCookieStore()->GetCookieMonster();
}
- virtual SearchVersusNavigateClassifier* GetSearchVersusNavigateClassifier() {
- return NULL;
+ virtual AutocompleteClassifier* GetAutocompleteClassifier() {
+ return autocomplete_classifier_.get();
}
virtual WebDataService* GetWebDataService(ServiceAccessType access) {
return web_data_service_.get();
@@ -283,6 +286,10 @@ class TestingProfile : public Profile {
// The ProfileSyncService. Created by CreateProfileSyncService.
scoped_ptr<ProfileSyncService> profile_sync_service_;
+ // The AutocompleteClassifier. Only created if CreateAutocompleteClassifier
+ // is invoked.
+ scoped_ptr<AutocompleteClassifier> autocomplete_classifier_;
+
// The WebDataService. Only created if CreateWebDataService is invoked.
scoped_refptr<WebDataService> web_data_service_;