summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_unittest.cc4
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view.h14
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc89
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_gtk.h5
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_mac.h4
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_mac.mm53
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_win.cc18
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_win.h4
-rw-r--r--chrome/browser/gtk/location_bar_view_gtk.cc8
-rw-r--r--chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm2
10 files changed, 99 insertions, 102 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit_unittest.cc b/chrome/browser/autocomplete/autocomplete_edit_unittest.cc
index 73c8ae9..fe4c23b 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_unittest.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit_unittest.cc
@@ -54,14 +54,14 @@ class TestingAutocompleteEditView : public AutocompleteEditView {
virtual bool OnAfterPossibleChange() { return false; }
virtual gfx::NativeView GetNativeView() const { return 0; }
virtual CommandUpdater* GetCommandUpdater() { return NULL; }
+ virtual void SetInstantSuggestion(const string16& input) {}
+ virtual int TextWidth() const { return 0; }
#if defined(TOOLKIT_VIEWS)
virtual views::View* AddToView(views::View* parent) { return NULL; }
- virtual int TextWidth() const { return 0; }
virtual bool CommitInstantSuggestion(
const std::wstring& typed_text,
const std::wstring& suggested_text) { return false;}
- virtual void SetInstantSuggestion(const string16& input) {}
#endif
private:
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view.h b/chrome/browser/autocomplete/autocomplete_edit_view.h
index 12c42a2..3fe7c48 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view.h
+++ b/chrome/browser/autocomplete/autocomplete_edit_view.h
@@ -158,6 +158,13 @@ class AutocompleteEditView {
// Returns the command updater for this view.
virtual CommandUpdater* GetCommandUpdater() = 0;
+ // Shows the instant suggestion text.
+ virtual void SetInstantSuggestion(const string16& input) = 0;
+
+ // Returns the width in pixels needed to display the current text. The
+ // returned value includes margins.
+ virtual int TextWidth() const = 0;
+
#if defined(TOOLKIT_VIEWS)
// Adds the autocomplete edit view to view hierarchy and
// returns the views::View of the edit view.
@@ -166,13 +173,6 @@ class AutocompleteEditView {
// Commits the suggested text.
virtual bool CommitInstantSuggestion(const std::wstring& typed_text,
const std::wstring& suggested_text) = 0;
-
- // Shows the instant suggestion text.
- virtual void SetInstantSuggestion(const string16& input) = 0;
-
- // Returns the width in pixels needed to display the current text. The
- // returned value includes margins.
- virtual int TextWidth() const = 0;
#endif
virtual ~AutocompleteEditView() {}
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
index 4de3d2c..576638b 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
@@ -754,32 +754,31 @@ CommandUpdater* AutocompleteEditViewGtk::GetCommandUpdater() {
return command_updater_;
}
-#if defined(TOOLKIT_VIEWS)
-views::View* AutocompleteEditViewGtk::AddToView(views::View* parent) {
- views::NativeViewHost* host = new views::NativeViewHost;
- parent->AddChildView(host);
- host->set_focus_view(parent);
- host->Attach(GetNativeView());
- return host;
-}
+void AutocompleteEditViewGtk::SetInstantSuggestion(const string16& suggestion) {
+ std::string suggestion_utf8 = UTF16ToUTF8(suggestion);
-bool AutocompleteEditViewGtk::CommitInstantSuggestion(
- const std::wstring& typed_text,
- const std::wstring& suggestion) {
- return CommitInstantSuggestion();
-}
+ gtk_label_set_text(GTK_LABEL(instant_view_), suggestion_utf8.c_str());
-void AutocompleteEditViewGtk::EnableAccessibility() {
- accessible_widget_helper_.reset(
- new AccessibleWidgetHelper(text_view(), model_->profile()));
- accessible_widget_helper_->SetWidgetName(
- text_view(), l10n_util::GetStringUTF8(IDS_ACCNAME_LOCATION));
-}
+ StopAnimation();
-void AutocompleteEditViewGtk::SetInstantSuggestion(const string16& suggestion) {
- SetInstantSuggestion(UTF16ToUTF8(suggestion));
-}
+ if (suggestion.empty()) {
+ gtk_widget_hide(instant_view_);
+ return;
+ }
+ if (InstantController::IsEnabled(model_->profile(),
+ InstantController::PREDICTIVE_TYPE)
+#if GTK_CHECK_VERSION(2, 20, 0)
+ && preedit_.empty()
#endif
+ ) {
+ instant_animation_->set_delegate(this);
+ instant_animation_->Start();
+ }
+
+ gtk_widget_show(instant_view_);
+ AdjustVerticalAlignmentOfInstantView();
+ UpdateInstantViewColors();
+}
int AutocompleteEditViewGtk::TextWidth() const {
int horizontal_border_size =
@@ -820,6 +819,27 @@ int AutocompleteEditViewGtk::TextWidth() const {
}
#if defined(TOOLKIT_VIEWS)
+views::View* AutocompleteEditViewGtk::AddToView(views::View* parent) {
+ views::NativeViewHost* host = new views::NativeViewHost;
+ parent->AddChildView(host);
+ host->set_focus_view(parent);
+ host->Attach(GetNativeView());
+ return host;
+}
+
+bool AutocompleteEditViewGtk::CommitInstantSuggestion(
+ const std::wstring& typed_text,
+ const std::wstring& suggestion) {
+ return CommitInstantSuggestion();
+}
+
+void AutocompleteEditViewGtk::EnableAccessibility() {
+ accessible_widget_helper_.reset(
+ new AccessibleWidgetHelper(text_view(), model_->profile()));
+ accessible_widget_helper_->SetWidgetName(
+ text_view(), l10n_util::GetStringUTF8(IDS_ACCNAME_LOCATION));
+}
+
// static
AutocompleteEditView* AutocompleteEditViewGtk::Create(
AutocompleteEditController* controller,
@@ -1908,31 +1928,6 @@ void AutocompleteEditViewGtk::EmphasizeURLComponents() {
}
}
-void AutocompleteEditViewGtk::SetInstantSuggestion(
- const std::string& suggestion) {
- gtk_label_set_text(GTK_LABEL(instant_view_), suggestion.c_str());
-
- StopAnimation();
-
- if (suggestion.empty()) {
- gtk_widget_hide(instant_view_);
- } else {
- if (InstantController::IsEnabled(model_->profile(),
- InstantController::PREDICTIVE_TYPE)
-#if GTK_CHECK_VERSION(2, 20, 0)
- && preedit_.empty()
-#endif
- ) {
- instant_animation_->set_delegate(this);
- instant_animation_->Start();
- }
-
- gtk_widget_show(instant_view_);
- AdjustVerticalAlignmentOfInstantView();
- UpdateInstantViewColors();
- }
-}
-
void AutocompleteEditViewGtk::StopAnimation() {
// Clear the animation delegate so we don't get an AnimationEnded() callback.
instant_animation_->set_delegate(NULL);
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h
index 2397d26..e03ff1d 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h
@@ -143,11 +143,12 @@ class AutocompleteEditViewGtk : public AutocompleteEditView,
virtual bool OnAfterPossibleChange();
virtual gfx::NativeView GetNativeView() const;
virtual CommandUpdater* GetCommandUpdater();
+ virtual void SetInstantSuggestion(const string16& suggestion);
+ virtual int TextWidth() const;
#if defined(TOOLKIT_VIEWS)
virtual views::View* AddToView(views::View* parent);
virtual bool CommitInstantSuggestion(const std::wstring& typed_text,
const std::wstring& suggested_text);
- virtual void SetInstantSuggestion(const string16& suggestion);
// Enables accessibility on AutocompleteEditView.
void EnableAccessibility();
@@ -163,7 +164,6 @@ class AutocompleteEditViewGtk : public AutocompleteEditView,
bool popup_window_mode,
const views::View* location_bar);
#endif
- virtual int TextWidth() const;
// Overridden from NotificationObserver:
virtual void Observe(NotificationType type,
@@ -181,7 +181,6 @@ class AutocompleteEditViewGtk : public AutocompleteEditView,
// the animation state.
void UpdateInstantViewColors();
- void SetInstantSuggestion(const std::string& suggestion);
bool CommitInstantSuggestion();
// Used by LocationBarViewGtk to inform AutocompleteEditViewGtk if the tab to
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_mac.h b/chrome/browser/autocomplete/autocomplete_edit_view_mac.h
index fc974ad..05a6158 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_mac.h
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_mac.h
@@ -83,6 +83,8 @@ class AutocompleteEditViewMac : public AutocompleteEditView,
virtual bool OnAfterPossibleChange();
virtual gfx::NativeView GetNativeView() const;
virtual CommandUpdater* GetCommandUpdater();
+ virtual void SetInstantSuggestion(const string16& input);
+ virtual int TextWidth() const;
// Implement the AutocompleteTextFieldObserver interface.
virtual NSRange SelectionRangeForProposedRange(NSRange proposed_range);
@@ -101,8 +103,6 @@ class AutocompleteEditViewMac : public AutocompleteEditView,
virtual void OnSetFocus(bool control_down);
virtual void OnKillFocus();
- // Suggest text should be in the model, but for now, it's here.
- void SetSuggestText(const string16& suggest_text);
bool CommitSuggestText();
// Helper for LocationBarViewMac. Optionally selects all in |field_|.
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm b/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm
index c19d5727..261a823 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm
@@ -450,28 +450,6 @@ void AutocompleteEditViewMac::ClosePopup() {
void AutocompleteEditViewMac::SetFocus() {
}
-void AutocompleteEditViewMac::SetSuggestText(const string16& suggest_text) {
- NSString* text = GetNonSuggestTextSubstring();
- bool needs_update = (suggest_text_length_ > 0);
-
- // Append the new suggest text.
- suggest_text_length_ = suggest_text.length();
- if (suggest_text_length_ > 0) {
- text = [text stringByAppendingString:base::SysUTF16ToNSString(
- suggest_text)];
- needs_update = true;
- }
-
- if (needs_update) {
- NSRange current_range = GetSelectedRange();
- SetTextInternal(base::SysNSStringToWide(text));
- if (NSMaxRange(current_range) <= [text length] - suggest_text_length_)
- SetSelectedRange(current_range);
- else
- SetSelectedRange(NSMakeRange([text length] - suggest_text_length_, 0));
- }
-}
-
bool AutocompleteEditViewMac::CommitSuggestText() {
if (suggest_text_length_ == 0)
return false;
@@ -722,6 +700,35 @@ CommandUpdater* AutocompleteEditViewMac::GetCommandUpdater() {
return command_updater_;
}
+void AutocompleteEditViewMac::SetInstantSuggestion(
+ const string16& suggest_text) {
+ NSString* text = GetNonSuggestTextSubstring();
+ bool needs_update = (suggest_text_length_ > 0);
+
+ // Append the new suggest text.
+ suggest_text_length_ = suggest_text.length();
+ if (suggest_text_length_ > 0) {
+ text = [text stringByAppendingString:base::SysUTF16ToNSString(
+ suggest_text)];
+ needs_update = true;
+ }
+
+ if (needs_update) {
+ NSRange current_range = GetSelectedRange();
+ SetTextInternal(base::SysNSStringToWide(text));
+ if (NSMaxRange(current_range) <= [text length] - suggest_text_length_)
+ SetSelectedRange(current_range);
+ else
+ SetSelectedRange(NSMakeRange([text length] - suggest_text_length_, 0));
+ }
+}
+
+int AutocompleteEditViewMac::TextWidth() const {
+ // Not used on mac.
+ NOTREACHED();
+ return 0;
+}
+
void AutocompleteEditViewMac::OnDidBeginEditing() {
// We should only arrive here when the field is focussed.
DCHECK([field_ currentEditor]);
@@ -752,7 +759,7 @@ bool AutocompleteEditViewMac::OnDoCommandBySelector(SEL cmd) {
// Reset the suggest text for any change other than key right or tab.
// TODO(rohitrao): This is here to prevent complications when editing text.
// See if this can be removed.
- SetSuggestText(string16());
+ SetInstantSuggestion(string16());
}
if (cmd == @selector(deleteForward:))
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_win.cc b/chrome/browser/autocomplete/autocomplete_edit_view_win.cc
index f262ef4..41ea7a9 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_win.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_win.cc
@@ -909,6 +909,15 @@ CommandUpdater* AutocompleteEditViewWin::GetCommandUpdater() {
return command_updater_;
}
+void AutocompleteEditViewWin::SetInstantSuggestion(const string16& suggestion) {
+ // On Windows, we shows the suggestion in LocationBarView.
+ NOTREACHED();
+}
+
+int AutocompleteEditViewWin::TextWidth() const {
+ return WidthNeededToDisplay(GetText());
+}
+
views::View* AutocompleteEditViewWin::AddToView(views::View* parent) {
views::NativeViewHost* host = new views::NativeViewHost;
parent->AddChildView(host);
@@ -924,15 +933,6 @@ bool AutocompleteEditViewWin::CommitInstantSuggestion(
return true;
}
-void AutocompleteEditViewWin::SetInstantSuggestion(const string16& suggestion) {
- // Win shows the suggestion in LocationBarView.
- NOTREACHED();
-}
-
-int AutocompleteEditViewWin::TextWidth() const {
- return WidthNeededToDisplay(GetText());
-}
-
void AutocompleteEditViewWin::PasteAndGo(const std::wstring& text) {
if (CanPasteAndGo(text))
model_->PasteAndGo();
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_win.h b/chrome/browser/autocomplete/autocomplete_edit_view_win.h
index 4cfa4dc..b551862 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_win.h
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_win.h
@@ -133,11 +133,11 @@ class AutocompleteEditViewWin
virtual bool OnAfterPossibleChange();
virtual gfx::NativeView GetNativeView() const;
virtual CommandUpdater* GetCommandUpdater();
+ virtual void SetInstantSuggestion(const string16& suggestion);
+ virtual int TextWidth() const;
virtual views::View* AddToView(views::View* parent);
virtual bool CommitInstantSuggestion(const std::wstring& typed_text,
const std::wstring& suggested_text);
- virtual void SetInstantSuggestion(const string16& suggestion);
- virtual int TextWidth() const;
int GetPopupMaxYCoordinate();
diff --git a/chrome/browser/gtk/location_bar_view_gtk.cc b/chrome/browser/gtk/location_bar_view_gtk.cc
index 30279ca..5f95daa 100644
--- a/chrome/browser/gtk/location_bar_view_gtk.cc
+++ b/chrome/browser/gtk/location_bar_view_gtk.cc
@@ -458,11 +458,7 @@ void LocationBarViewGtk::OnAutocompleteWillAccept() {
bool LocationBarViewGtk::OnCommitSuggestedText(
const std::wstring& typed_text) {
- InstantController* instant = browser_->instant();
- if (!instant)
- return false;
-
- return location_entry_->CommitInstantSuggestion();
+ return browser_->instant() && location_entry_->CommitInstantSuggestion();
}
bool LocationBarViewGtk::AcceptCurrentInstantPreview() {
@@ -638,7 +634,7 @@ void LocationBarViewGtk::SetSuggestedText(const string16& text) {
UTF16ToWide(text));
}
} else {
- location_entry_->SetInstantSuggestion(UTF16ToUTF8(text));
+ location_entry_->SetInstantSuggestion(text);
}
}
diff --git a/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm b/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm
index 91753c3..8b9e83d 100644
--- a/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm
+++ b/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm
@@ -140,7 +140,7 @@ std::wstring LocationBarViewMac::GetInputString() const {
}
void LocationBarViewMac::SetSuggestedText(const string16& text) {
- edit_view_->SetSuggestText(
+ edit_view_->SetInstantSuggestion(
edit_view_->model()->UseVerbatimInstant() ? string16() : text);
}