diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-06 17:59:19 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-06 17:59:19 +0000 |
commit | 20ac3c34782bd506cd88e1ed8a354d05956b1063 (patch) | |
tree | bf86158d0846d0404d70b840d31b56d222c3e9bd /chrome | |
parent | 6f9eac9b410e41052a238eaa4da863572f1e86a4 (diff) | |
download | chromium_src-20ac3c34782bd506cd88e1ed8a354d05956b1063.zip chromium_src-20ac3c34782bd506cd88e1ed8a354d05956b1063.tar.gz chromium_src-20ac3c34782bd506cd88e1ed8a354d05956b1063.tar.bz2 |
Moves responsibility for updating InstantController to AutocompleteEditModel. This cuts down on a fair amount of duplicate code in the various platform specific files.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/6609030
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@77079 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
26 files changed, 264 insertions, 434 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit.cc b/chrome/browser/autocomplete/autocomplete_edit.cc index 859966b..9d22cab 100644 --- a/chrome/browser/autocomplete/autocomplete_edit.cc +++ b/chrome/browser/autocomplete/autocomplete_edit.cc @@ -29,6 +29,7 @@ #include "chrome/browser/profiles/profile.h" #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url_model.h" +#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/common/notification_service.h" #include "chrome/common/url_constants.h" #include "googleurl/src/gurl.h" @@ -77,7 +78,8 @@ AutocompleteEditModel::AutocompleteEditModel( control_key_state_(UP), is_keyword_hint_(false), paste_and_go_transition_(PageTransition::TYPED), - profile_(profile) { + profile_(profile), + update_instant_(true) { } AutocompleteEditModel::~AutocompleteEditModel() { @@ -170,6 +172,59 @@ void AutocompleteEditModel::FinalizeInstantQuery( } } +void AutocompleteEditModel::SetSuggestedText(const string16& text) { + // This method is internally invoked to reset suggest text, so we only do + // anything if the text isn't empty. + // TODO: if we keep autocomplete, make it so this isn't invoked with empty + // text. + if (!text.empty()) + FinalizeInstantQuery(view_->GetText(), text, false); +} + +bool AutocompleteEditModel::CommitSuggestedText(bool skip_inline_autocomplete) { + if (!controller_->GetInstant()) + return false; + + const string16 suggestion = view_->GetInstantSuggestion(); + if (suggestion.empty()) + return false; + + FinalizeInstantQuery(view_->GetText(), suggestion, skip_inline_autocomplete); + return true; +} + +bool AutocompleteEditModel::AcceptCurrentInstantPreview() { + return InstantController::CommitIfCurrent(controller_->GetInstant()); +} + +void AutocompleteEditModel::OnChanged() { + InstantController* instant = controller_->GetInstant(); + string16 suggested_text; + TabContentsWrapper* tab = controller_->GetTabContentsWrapper(); + if (update_instant_ && instant && tab) { + if (user_input_in_progress() && popup_->IsOpen()) { + AutocompleteMatch current_match = CurrentMatch(); + if (current_match.destination_url == PermanentURL()) { + // The destination is the same as the current url. This typically + // happens if the user presses the down error in the omnibox, in which + // case we don't want to load a preview. + instant->DestroyPreviewContentsAndLeaveActive(); + } else { + instant->Update(tab, CurrentMatch(), view_->GetText(), + UseVerbatimInstant(), &suggested_text); + } + } else { + instant->DestroyPreviewContents(); + } + if (!instant->MightSupportInstant()) + FinalizeInstantQuery(string16(), string16(), false); + } + + SetSuggestedText(suggested_text); + + controller_->OnChanged(); +} + void AutocompleteEditModel::GetDataForURLExport(GURL* url, string16* title, SkBitmap* favicon) { @@ -323,6 +378,12 @@ void AutocompleteEditModel::StartAutocomplete( } void AutocompleteEditModel::StopAutocomplete() { + if (popup_->IsOpen() && update_instant_) { + InstantController* instant = controller_->GetInstant(); + if (instant && !instant->commit_on_mouse_up()) + instant->DestroyPreviewContents(); + } + autocomplete_controller_->Stop(true); } @@ -453,11 +514,16 @@ void AutocompleteEditModel::OpenURL(const GURL& url, } if (disposition != NEW_BACKGROUND_TAB) { - controller_->OnAutocompleteWillAccept(); + update_instant_ = false; view_->RevertAll(); // Revert the box to its unedited state } controller_->OnAutocompleteAccept(url, disposition, transition, alternate_nav_url); + + InstantController* instant = controller_->GetInstant(); + if (instant && !popup_->IsOpen()) + instant->DestroyPreviewContents(); + update_instant_ = true; } bool AutocompleteEditModel::AcceptKeyword() { @@ -500,6 +566,15 @@ void AutocompleteEditModel::OnSetFocus(bool control_down) { NotificationService::NoDetails()); } +void AutocompleteEditModel::OnWillKillFocus( + gfx::NativeView view_gaining_focus) { + SetSuggestedText(string16()); + + InstantController* instant = controller_->GetInstant(); + if (instant) + instant->OnAutocompleteLostFocus(view_gaining_focus); +} + void AutocompleteEditModel::OnKillFocus() { has_focus_ = false; control_key_state_ = UP; @@ -638,7 +713,7 @@ void AutocompleteEditModel::OnPopupDataChanged( // We need to invoke OnChanged in case the destination url changed (as could // happen when control is toggled). if (call_controller_onchanged) - controller_->OnChanged(); + OnChanged(); } bool AutocompleteEditModel::OnAfterPossibleChange( @@ -694,7 +769,9 @@ bool AutocompleteEditModel::OnAfterPossibleChange( } void AutocompleteEditModel::PopupBoundsChangedTo(const gfx::Rect& bounds) { - controller_->OnPopupBoundsChanged(bounds); + InstantController* instant = controller_->GetInstant(); + if (instant) + instant->SetOmniboxBounds(bounds); } // Return true if the suggestion type warrants a TCP/IP preconnection. diff --git a/chrome/browser/autocomplete/autocomplete_edit.h b/chrome/browser/autocomplete/autocomplete_edit.h index 726ce4d..2ea41b8 100644 --- a/chrome/browser/autocomplete/autocomplete_edit.h +++ b/chrome/browser/autocomplete/autocomplete_edit.h @@ -21,8 +21,10 @@ class AutocompleteEditModel; class AutocompleteEditView; class AutocompletePopupModel; class AutocompleteResult; +class InstantController; class Profile; class SkBitmap; +class TabContentsWrapper; namespace gfx { class Rect; @@ -35,32 +37,6 @@ class Rect; // Embedders of an AutocompleteEdit widget must implement this class. class AutocompleteEditController { public: - // Sent when the autocomplete popup is about to close. - virtual void OnAutocompleteWillClosePopup() = 0; - - // Sent when the edit is losing focus. |view_gaining_focus| is the view - // gaining focus and may be null. - virtual void OnAutocompleteLosingFocus( - gfx::NativeView view_gaining_focus) = 0; - - // Sent prior to OnAutoCompleteAccept and before the model has been reverted. - // This is only invoked if the popup is closed before invoking - // OnAutoCompleteAccept. - virtual void OnAutocompleteWillAccept() = 0; - - // Commits the suggested text. If |skip_inline_autocomplete| is true then the - // suggested text will be committed as final text as if it's inputted by the - // user, rather than as inline autocomplete suggest. - // Returns true if the text was committed. - virtual bool OnCommitSuggestedText(bool skip_inline_autocomplete) = 0; - - // Accepts the currently showing instant preview, if any, and returns true. - // Returns false if there is no instant preview showing. - virtual bool AcceptCurrentInstantPreview() = 0; - - // Invoked when the popup is going to change its bounds to |bounds|. - virtual void OnPopupBoundsChanged(const gfx::Rect& bounds) = 0; - // When the user presses enter or selects a line with the mouse, this // function will get called synchronously with the url to open and // disposition and transition to use when opening it. @@ -98,6 +74,12 @@ class AutocompleteEditController { // Returns the title of the current page. virtual string16 GetTitle() const = 0; + // Returns the InstantController, or NULL if instant is not enabled. + virtual InstantController* GetInstant() = 0; + + // Returns the TabContentsWrapper of the currently selected tab. + virtual TabContentsWrapper* GetTabContentsWrapper() = 0; + protected: virtual ~AutocompleteEditController(); }; @@ -208,6 +190,24 @@ class AutocompleteEditModel : public AutocompleteControllerDelegate { const string16& suggest_text, bool skip_inline_autocomplete); + // Sets the suggestion text. + void SetSuggestedText(const string16& text); + + // Commits the suggested text. If |skip_inline_autocomplete| is true then the + // suggested text will be committed as final text as if it's inputted by the + // user, rather than as inline autocomplete suggest. + // Returns true if the text was committed. + // TODO: can the return type be void? + bool CommitSuggestedText(bool skip_inline_autocomplete); + + // Accepts the currently showing instant preview, if any, and returns true. + // Returns false if there is no instant preview showing. + bool AcceptCurrentInstantPreview(); + + // Invoked any time the text may have changed in the edit. Updates instant and + // notifies the controller. + void OnChanged(); + // Reverts the edit model back to its unedited state (permanent text showing, // no user input in progress). void Revert(); @@ -277,6 +277,9 @@ class AutocompleteEditModel : public AutocompleteControllerDelegate { // control key is down (at the time we're gaining focus). void OnSetFocus(bool control_down); + // Sent before |OnKillFocus| and before the popup is closed. + void OnWillKillFocus(gfx::NativeView view_gaining_focus); + // Called when the view is losing focus. Resets some state. void OnKillFocus(); @@ -514,6 +517,12 @@ class AutocompleteEditModel : public AutocompleteControllerDelegate { Profile* profile_; + // Should instant be updated? This is needed as prior to accepting the current + // text the model is reverted, which triggers resetting instant. We don't want + // to update instant in this case, so we use the flag to determine if this is + // happening. + bool update_instant_; + DISALLOW_COPY_AND_ASSIGN(AutocompleteEditModel); }; diff --git a/chrome/browser/autocomplete/autocomplete_edit_unittest.cc b/chrome/browser/autocomplete/autocomplete_edit_unittest.cc index 8c2fcdd..c915f751 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_unittest.cc +++ b/chrome/browser/autocomplete/autocomplete_edit_unittest.cc @@ -73,27 +73,21 @@ class TestingAutocompleteEditView : public AutocompleteEditView { class TestingAutocompleteEditController : public AutocompleteEditController { public: TestingAutocompleteEditController() {} - virtual void OnAutocompleteWillClosePopup() {} - virtual void OnAutocompleteLosingFocus(gfx::NativeView view_gaining_focus) {} - virtual void OnAutocompleteWillAccept() {} - virtual bool OnCommitSuggestedText(bool skip_inline_autocomplete) { - return false; - } - virtual bool AcceptCurrentInstantPreview() { - return false; - } - virtual void OnPopupBoundsChanged(const gfx::Rect& bounds) {} virtual void OnAutocompleteAccept(const GURL& url, WindowOpenDisposition disposition, PageTransition::Type transition, - const GURL& alternate_nav_url) {} - virtual void OnChanged() {} - virtual void OnSelectionBoundsChanged() {} - virtual void OnInputInProgress(bool in_progress) {} - virtual void OnKillFocus() {} - virtual void OnSetFocus() {} - virtual SkBitmap GetFavIcon() const { return SkBitmap(); } - virtual string16 GetTitle() const { return string16(); } + const GURL& alternate_nav_url) OVERRIDE {} + virtual void OnChanged() OVERRIDE {} + virtual void OnSelectionBoundsChanged() OVERRIDE {} + virtual void OnInputInProgress(bool in_progress) OVERRIDE {} + virtual void OnKillFocus() OVERRIDE {} + virtual void OnSetFocus() OVERRIDE {} + virtual SkBitmap GetFavIcon() const OVERRIDE { return SkBitmap(); } + virtual string16 GetTitle() const OVERRIDE { return string16(); } + virtual InstantController* GetInstant() OVERRIDE { return NULL; } + virtual TabContentsWrapper* GetTabContentsWrapper() OVERRIDE { + return NULL; + } private: DISALLOW_COPY_AND_ASSIGN(TestingAutocompleteEditController); diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc index e304418..29ba50f 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc +++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc @@ -621,9 +621,6 @@ void AutocompleteEditViewGtk::UpdatePopup() { } void AutocompleteEditViewGtk::ClosePopup() { - if (model_->popup_model()->IsOpen()) - controller_->OnAutocompleteWillClosePopup(); - model_->StopAutocomplete(); } @@ -749,7 +746,7 @@ bool AutocompleteEditViewGtk::OnAfterPossibleChange() { EmphasizeURLComponents(); } else if (delete_was_pressed_ && at_end_of_edit) { delete_at_end_pressed_ = true; - controller_->OnChanged(); + model_->OnChanged(); } delete_was_pressed_ = false; @@ -926,7 +923,7 @@ void AutocompleteEditViewGtk::Observe(NotificationType type, } void AutocompleteEditViewGtk::AnimationEnded(const ui::Animation* animation) { - controller_->OnCommitSuggestedText(false); + model_->CommitSuggestedText(false); } void AutocompleteEditViewGtk::AnimationProgressed( @@ -1351,7 +1348,7 @@ gboolean AutocompleteEditViewGtk::HandleViewFocusOut(GtkWidget* sender, view_getting_focus = going_to_focus_; // This must be invoked before ClosePopup. - controller_->OnAutocompleteLosingFocus(view_getting_focus); + model_->OnWillKillFocus(view_getting_focus); // Close the popup. ClosePopup(); @@ -1402,7 +1399,7 @@ void AutocompleteEditViewGtk::HandleViewMoveCursor( OnAfterPossibleChange(); handled = true; } else if (count == count_towards_end && !IsCaretAtEnd()) { - handled = controller_->OnCommitSuggestedText(true); + handled = model_->CommitSuggestedText(true); } } else if (step == GTK_MOVEMENT_PAGES) { // Page up and down. // Multiply by count for the direction (if we move too much that's ok). @@ -1695,7 +1692,7 @@ void AutocompleteEditViewGtk::HandleViewMoveFocus(GtkWidget* widget, #endif if (!handled && GTK_WIDGET_VISIBLE(instant_view_)) - handled = controller_->OnCommitSuggestedText(true); + handled = model_->CommitSuggestedText(true); if (!handled) { if (!IsCaretAtEnd()) { @@ -1707,7 +1704,7 @@ void AutocompleteEditViewGtk::HandleViewMoveFocus(GtkWidget* widget, } if (!handled) - handled = controller_->AcceptCurrentInstantPreview(); + handled = model_->AcceptCurrentInstantPreview(); if (handled) { static guint signal_id = g_signal_lookup("move-focus", GTK_TYPE_WIDGET); @@ -2066,7 +2063,7 @@ void AutocompleteEditViewGtk::StopAnimation() { void AutocompleteEditViewGtk::TextChanged() { EmphasizeURLComponents(); - controller_->OnChanged(); + model_->OnChanged(); } void AutocompleteEditViewGtk::SavePrimarySelection( diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm b/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm index 224f0ab..5e1de22 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm +++ b/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm @@ -329,7 +329,7 @@ void AutocompleteEditViewMac::SetUserText(const string16& text, if (update_popup) { UpdatePopup(); } - controller_->OnChanged(); + model_->OnChanged(); } NSRange AutocompleteEditViewMac::GetSelectedRange() const { @@ -415,7 +415,7 @@ void AutocompleteEditViewMac::SelectAll(bool reversed) { void AutocompleteEditViewMac::RevertAll() { ClosePopup(); model_->Revert(); - controller_->OnChanged(); + model_->OnChanged(); [field_ clearUndoChain]; } @@ -443,9 +443,6 @@ void AutocompleteEditViewMac::UpdatePopup() { } void AutocompleteEditViewMac::ClosePopup() { - if (model_->popup_model()->IsOpen()) - controller_->OnAutocompleteWillClosePopup(); - model_->StopAutocomplete(); } @@ -469,7 +466,7 @@ void AutocompleteEditViewMac::SetTextInternal( [field_ setAttributedStringValue:as]; // TODO(shess): This may be an appropriate place to call: - // controller_->OnChanged(); + // model_->OnChanged(); // In the current implementation, this tells LocationBarViewMac to // mess around with |model_| and update |field_|. Unfortunately, // when I look at our peer implementations, it's not entirely clear @@ -599,7 +596,7 @@ void AutocompleteEditViewMac::OnTemporaryTextMaybeChanged( suggest_text_length_ = 0; SetWindowTextAndCaretPos(display_text, display_text.size()); - controller_->OnChanged(); + model_->OnChanged(); [field_ clearUndoChain]; } @@ -622,7 +619,7 @@ bool AutocompleteEditViewMac::OnInlineAutocompleteTextMaybeChanged( const NSRange range = NSMakeRange(user_text_length, display_text.size() - user_text_length); SetTextAndSelectedRange(display_text, range); - controller_->OnChanged(); + model_->OnChanged(); [field_ clearUndoChain]; return true; @@ -690,7 +687,7 @@ bool AutocompleteEditViewMac::OnAfterPossibleChange() { // fails for us in case you copy the URL and paste the identical URL // back (we'll lose the styling). EmphasizeURLComponents(); - controller_->OnChanged(); + model_->OnChanged(); delete_was_pressed_ = false; @@ -795,7 +792,7 @@ bool AutocompleteEditViewMac::OnDoCommandBySelector(SEL cmd) { // Only commit suggested text if the cursor is all the way to the right and // there is no selection. if (suggest_text_length_ > 0 && IsCaretAtEnd()) { - controller_->OnCommitSuggestedText(true); + model_->CommitSuggestedText(true); return true; } } @@ -820,7 +817,7 @@ bool AutocompleteEditViewMac::OnDoCommandBySelector(SEL cmd) { return model_->AcceptKeyword(); if (suggest_text_length_ > 0) { - controller_->OnCommitSuggestedText(true); + model_->CommitSuggestedText(true); return true; } @@ -832,7 +829,7 @@ bool AutocompleteEditViewMac::OnDoCommandBySelector(SEL cmd) { return true; } - if (controller_->AcceptCurrentInstantPreview()) + if (model_->AcceptCurrentInstantPreview()) return true; } @@ -896,7 +893,7 @@ void AutocompleteEditViewMac::OnSetFocus(bool control_down) { void AutocompleteEditViewMac::OnKillFocus() { // Tell the model to reset itself. - controller_->OnAutocompleteLosingFocus(NULL); + model_->OnWillKillFocus(NULL); model_->OnKillFocus(); controller_->OnKillFocus(); } @@ -990,7 +987,7 @@ void AutocompleteEditViewMac::OnFrameChanged() { model_->PopupBoundsChangedTo(popup_view_->GetTargetBounds()); // Give controller a chance to rearrange decorations. - controller_->OnChanged(); + model_->OnChanged(); } bool AutocompleteEditViewMac::OnBackspacePressed() { diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_views.cc b/chrome/browser/autocomplete/autocomplete_edit_view_views.cc index 355d192..b4ae073 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_views.cc +++ b/chrome/browser/autocomplete/autocomplete_edit_view_views.cc @@ -242,7 +242,7 @@ void AutocompleteEditViewViews::HandleFocusIn() { void AutocompleteEditViewViews::HandleFocusOut() { // TODO(oshima): we don't have native view. This requires // further refactoring. - controller_->OnAutocompleteLosingFocus(NULL); + model_->OnWillKillFocus(NULL); // Close the popup. ClosePopup(); // Tell the model to reset itself. @@ -431,9 +431,6 @@ void AutocompleteEditViewViews::UpdatePopup() { } void AutocompleteEditViewViews::ClosePopup() { - if (model_->popup_model()->IsOpen()) - controller_->OnAutocompleteWillClosePopup(); - model_->StopAutocomplete(); } @@ -511,7 +508,7 @@ bool AutocompleteEditViewViews::OnAfterPossibleChange() { bool something_changed = model_->OnAfterPossibleChange(new_text, selection_differs, text_changed_, just_deleted_text, at_end_of_edit); - // If only selection was changed, we don't need to call |controller_|'s + // If only selection was changed, we don't need to call |model_|'s // OnChanged() method, which is called in TextChanged(). // But we still need to call EmphasizeURLComponents() to make sure the text // attributes are updated correctly. @@ -521,7 +518,7 @@ bool AutocompleteEditViewViews::OnAfterPossibleChange() { EmphasizeURLComponents(); } else if (delete_was_pressed_ && at_end_of_edit) { delete_at_end_pressed_ = true; - controller_->OnChanged(); + model_->OnChanged(); } delete_was_pressed_ = false; @@ -628,7 +625,7 @@ void AutocompleteEditViewViews::EmphasizeURLComponents() { void AutocompleteEditViewViews::TextChanged() { EmphasizeURLComponents(); - controller_->OnChanged(); + model_->OnChanged(); } void AutocompleteEditViewViews::SetTextAndSelectedRange( diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_win.cc b/chrome/browser/autocomplete/autocomplete_edit_view_win.cc index 26fd11d..9b32aeb 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_win.cc +++ b/chrome/browser/autocomplete/autocomplete_edit_view_win.cc @@ -400,7 +400,7 @@ AutocompleteEditViewWin::AutocompleteEditViewWin( const gfx::Font& font, AutocompleteEditController* controller, ToolbarModel* toolbar_model, - views::View* parent_view, + LocationBarView* parent_view, HWND hwnd, Profile* profile, CommandUpdater* command_updater, @@ -506,6 +506,10 @@ AutocompleteEditViewWin::~AutocompleteEditViewWin() { g_paint_patcher.Pointer()->DerefPatch(); } +views::View* AutocompleteEditViewWin::parent_view() const { + return parent_view_; +} + int AutocompleteEditViewWin::WidthOfTextAfterCursor() { CHARRANGE selection; GetSelection(selection); @@ -727,9 +731,6 @@ void AutocompleteEditViewWin::UpdatePopup() { } void AutocompleteEditViewWin::ClosePopup() { - if (model_->popup_model()->IsOpen()) - controller_->OnAutocompleteWillClosePopup(); - model_->StopAutocomplete(); } @@ -913,7 +914,7 @@ bool AutocompleteEditViewWin::OnAfterPossibleChangeInternal( parent_view_->NotifyAccessibilityEvent( AccessibilityTypes::EVENT_SELECTION_CHANGED); } else if (delete_at_end_pressed_) { - controller_->OnChanged(); + model_->OnChanged(); } return something_changed; @@ -932,16 +933,14 @@ void AutocompleteEditViewWin::SetInstantSuggestion(const string16& suggestion) { NOTREACHED(); } -string16 AutocompleteEditViewWin::GetInstantSuggestion() const { - // On Windows, we shows the suggestion in LocationBarView. - NOTREACHED(); - return string16(); -} - int AutocompleteEditViewWin::TextWidth() const { return WidthNeededToDisplay(GetText()); } +string16 AutocompleteEditViewWin::GetInstantSuggestion() const { + return parent_view_->GetInstantSuggestion(); +} + bool AutocompleteEditViewWin::IsImeComposing() const { bool ime_composing = false; HIMC context = ImmGetContext(m_hWnd); @@ -1440,7 +1439,7 @@ void AutocompleteEditViewWin::OnKillFocus(HWND focus_wnd) { } // This must be invoked before ClosePopup. - controller_->OnAutocompleteLosingFocus(focus_wnd); + model_->OnWillKillFocus(focus_wnd); // Close the popup. ClosePopup(); @@ -1895,7 +1894,7 @@ bool AutocompleteEditViewWin::OnKeyDownOnlyWritable(TCHAR key, GetSel(selection); return (selection.cpMin == selection.cpMax) && (selection.cpMin == GetTextLength()) && - controller_->OnCommitSuggestedText(true); + model_->CommitSuggestedText(true); } case VK_RETURN: @@ -2029,7 +2028,7 @@ bool AutocompleteEditViewWin::OnKeyDownOnlyWritable(TCHAR key, PlaceCaretAt(GetTextLength()); OnAfterPossibleChange(); } else { - controller_->OnCommitSuggestedText(true); + model_->CommitSuggestedText(true); } return true; } @@ -2368,7 +2367,7 @@ void AutocompleteEditViewWin::DrawDropHighlight(HDC hdc, void AutocompleteEditViewWin::TextChanged() { ScopedFreeze freeze(this, GetTextObjectModel()); EmphasizeURLComponents(); - controller_->OnChanged(); + model_->OnChanged(); } string16 AutocompleteEditViewWin::GetClipboardText() const { diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_win.h b/chrome/browser/autocomplete/autocomplete_edit_view_win.h index 2d5284b..fb6bfd5 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_win.h +++ b/chrome/browser/autocomplete/autocomplete_edit_view_win.h @@ -35,6 +35,7 @@ class AutocompleteEditController; class AutocompleteEditModel; class AutocompleteEditView; class AutocompletePopupView; +class LocationBarView; // Provides the implementation of an edit control with a drop-down // autocomplete box. The box itself is implemented in autocomplete_popup.cc @@ -64,7 +65,7 @@ class AutocompleteEditViewWin AutocompleteEditViewWin(const gfx::Font& font, AutocompleteEditController* controller, ToolbarModel* toolbar_model, - views::View* parent_view, + LocationBarView* parent_view, HWND hwnd, Profile* profile, CommandUpdater* command_updater, @@ -72,7 +73,7 @@ class AutocompleteEditViewWin const views::View* location_bar); ~AutocompleteEditViewWin(); - views::View* parent_view() const { return parent_view_; } + views::View* parent_view() const; // Returns the width in pixels needed to display the text from one character // before the caret to the end of the string. See comments in @@ -134,8 +135,8 @@ class AutocompleteEditViewWin virtual gfx::NativeView GetNativeView() const; virtual CommandUpdater* GetCommandUpdater(); virtual void SetInstantSuggestion(const string16& suggestion); - virtual string16 GetInstantSuggestion() const; virtual int TextWidth() const; + virtual string16 GetInstantSuggestion() const; virtual bool IsImeComposing() const; virtual views::View* AddToView(views::View* parent); @@ -427,7 +428,7 @@ class AutocompleteEditViewWin // The parent view for the edit, used to align the popup and for // accessibility. - views::View* parent_view_; + LocationBarView* parent_view_; ToolbarModel* toolbar_model_; diff --git a/chrome/browser/instant/instant_controller.cc b/chrome/browser/instant/instant_controller.cc index d99bd68..f0dbe53 100644 --- a/chrome/browser/instant/instant_controller.cc +++ b/chrome/browser/instant/instant_controller.cc @@ -249,6 +249,22 @@ bool InstantController::IsMouseDownFromActivate() { return loader_manager_->current_loader()->IsMouseDownFromActivate(); } +#if defined(OS_MACOSX) +void InstantController::OnAutocompleteLostFocus( + gfx::NativeView view_gaining_focus) { + // If |IsMouseDownFromActivate()| returns false, the RenderWidgetHostView did + // not receive a mouseDown event. Therefore, we should destroy the preview. + // Otherwise, the RWHV was clicked, so we commit the preview. + if (!is_displayable() || !GetPreviewContents() || + !IsMouseDownFromActivate()) { + DestroyPreviewContents(); + } else if (IsShowingInstant()) { + SetCommitOnMouseUp(); + } else { + CommitCurrentPreview(INSTANT_COMMIT_FOCUS_LOST); + } +} +#else void InstantController::OnAutocompleteLostFocus( gfx::NativeView view_gaining_focus) { if (!is_active() || !GetPreviewContents()) { @@ -305,6 +321,7 @@ void InstantController::OnAutocompleteLostFocus( DestroyPreviewContents(); } +#endif TabContentsWrapper* InstantController::ReleasePreviewContents( InstantCommitType type) { diff --git a/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h b/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h index 4fa41b2..4c1bd3c 100644 --- a/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h +++ b/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h @@ -125,12 +125,6 @@ class LocationBarViewMac : public AutocompleteEditController, NSRect GetBlockedPopupRect() const; // AutocompleteEditController implementation. - virtual void OnAutocompleteWillClosePopup(); - virtual void OnAutocompleteLosingFocus(gfx::NativeView unused); - virtual void OnAutocompleteWillAccept(); - virtual bool OnCommitSuggestedText(bool skip_inline_autocomplete); - virtual bool AcceptCurrentInstantPreview(); - virtual void OnPopupBoundsChanged(const gfx::Rect& bounds); virtual void OnAutocompleteAccept(const GURL& url, WindowOpenDisposition disposition, PageTransition::Type transition, @@ -142,6 +136,8 @@ class LocationBarViewMac : public AutocompleteEditController, virtual void OnSetFocus(); virtual SkBitmap GetFavIcon() const; virtual string16 GetTitle() const; + virtual InstantController* GetInstant(); + virtual TabContentsWrapper* GetTabContentsWrapper(); NSImage* GetKeywordImage(const string16& keyword); @@ -215,9 +211,6 @@ class LocationBarViewMac : public AutocompleteEditController, ToolbarModel* toolbar_model_; // Weak, owned by Browser. - // Whether or not to update the instant preview. - bool update_instant_; - // The transition type to use for the navigation. PageTransition::Type transition_; 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 bc580bc..2b82cfc 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 @@ -89,7 +89,6 @@ LocationBarViewMac::LocationBarViewMac( profile_(profile), browser_(browser), toolbar_model_(toolbar_model), - update_instant_(true), transition_(PageTransition::TYPED), first_run_bubble_(this) { for (size_t i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { @@ -139,14 +138,7 @@ std::wstring LocationBarViewMac::GetInputString() const { } void LocationBarViewMac::SetSuggestedText(const string16& text) { - // This method is internally invoked to reset suggest text, so we only do - // anything if the text isn't empty. - // TODO: if we keep autocomplete, make it so this isn't invoked with empty - // text. - if (!text.empty()) { - edit_view_->model()->FinalizeInstantQuery(edit_view_->GetText(), text, - false); - } + edit_view_->model()->SetSuggestedText(text); } WindowOpenDisposition LocationBarViewMac::GetWindowOpenDisposition() const { @@ -220,63 +212,6 @@ void LocationBarViewMac::Update(const TabContents* contents, OnChanged(); } -void LocationBarViewMac::OnAutocompleteWillClosePopup() { - if (!update_instant_) - return; - - InstantController* controller = browser_->instant(); - if (controller && !controller->commit_on_mouse_up()) - controller->DestroyPreviewContents(); - SetSuggestedText(string16()); -} - -void LocationBarViewMac::OnAutocompleteLosingFocus(gfx::NativeView unused) { - SetSuggestedText(string16()); - - InstantController* instant = browser_->instant(); - if (!instant) - return; - - // If |IsMouseDownFromActivate()| returns false, the RenderWidgetHostView did - // not receive a mouseDown event. Therefore, we should destroy the preview. - // Otherwise, the RWHV was clicked, so we commit the preview. - if (!instant->is_displayable() || !instant->GetPreviewContents() || - !instant->IsMouseDownFromActivate()) { - instant->DestroyPreviewContents(); - } else if (instant->IsShowingInstant()) { - instant->SetCommitOnMouseUp(); - } else { - instant->CommitCurrentPreview(INSTANT_COMMIT_FOCUS_LOST); - } -} - -void LocationBarViewMac::OnAutocompleteWillAccept() { - update_instant_ = false; -} - -bool LocationBarViewMac::OnCommitSuggestedText(bool skip_inline_autocomplete) { - if (!browser_->instant()) - return false; - - const string16 suggestion = edit_view_->GetInstantSuggestion(); - if (suggestion.empty()) - return false; - - edit_view_->model()->FinalizeInstantQuery( - edit_view_->GetText(), suggestion, skip_inline_autocomplete); - return true; -} - -bool LocationBarViewMac::AcceptCurrentInstantPreview() { - return InstantController::CommitIfCurrent(browser_->instant()); -} - -void LocationBarViewMac::OnPopupBoundsChanged(const gfx::Rect& bounds) { - InstantController* instant = browser_->instant(); - if (instant) - instant->SetOmniboxBounds(bounds); -} - void LocationBarViewMac::OnAutocompleteAccept(const GURL& url, WindowOpenDisposition disposition, PageTransition::Type transition, @@ -309,11 +244,6 @@ void LocationBarViewMac::OnAutocompleteAccept(const GURL& url, } } } - - if (browser_->instant() && !edit_view_->model()->popup_model()->IsOpen()) - browser_->instant()->DestroyPreviewContents(); - - update_instant_ = true; } void LocationBarViewMac::OnChanged() { @@ -323,15 +253,6 @@ void LocationBarViewMac::OnChanged() { location_icon_decoration_->SetImage(image); ev_bubble_decoration_->SetImage(image); Layout(); - - InstantController* instant = browser_->instant(); - string16 suggested_text; - if (update_instant_ && instant && GetTabContents()) { - UpdateInstant(instant, browser_->GetSelectedTabContentsWrapper(), - edit_view_.get(), &suggested_text); - } - - SetSuggestedText(suggested_text); } void LocationBarViewMac::OnSelectionBoundsChanged() { @@ -362,6 +283,14 @@ string16 LocationBarViewMac::GetTitle() const { return string16(); } +InstantController* LocationBarViewMac::GetInstant() { + return browser_->instant(); +} + +TabContentsWrapper* LocationBarViewMac::GetTabContentsWrapper() { + return browser_->GetSelectedTabContentsWrapper(); +} + void LocationBarViewMac::Revert() { edit_view_->RevertAll(); } diff --git a/chrome/browser/ui/gtk/location_bar_view_gtk.cc b/chrome/browser/ui/gtk/location_bar_view_gtk.cc index 29775ad..fdf83b8 100644 --- a/chrome/browser/ui/gtk/location_bar_view_gtk.cc +++ b/chrome/browser/ui/gtk/location_bar_view_gtk.cc @@ -166,8 +166,7 @@ LocationBarViewGtk::LocationBarViewGtk(Browser* browser) hbox_width_(0), entry_box_width_(0), show_selected_keyword_(false), - show_keyword_hint_(false), - update_instant_(true) { + show_keyword_hint_(false) { } LocationBarViewGtk::~LocationBarViewGtk() { @@ -460,51 +459,6 @@ void LocationBarViewGtk::Update(const TabContents* contents) { } } -void LocationBarViewGtk::OnAutocompleteWillClosePopup() { - if (!update_instant_) - return; - - InstantController* instant = browser_->instant(); - if (instant && !instant->commit_on_mouse_up()) - instant->DestroyPreviewContents(); -} - -void LocationBarViewGtk::OnAutocompleteLosingFocus( - gfx::NativeView view_gaining_focus) { - SetSuggestedText(string16()); - - InstantController* instant = browser_->instant(); - if (instant) - instant->OnAutocompleteLostFocus(view_gaining_focus); -} - -void LocationBarViewGtk::OnAutocompleteWillAccept() { - update_instant_ = false; -} - -bool LocationBarViewGtk::OnCommitSuggestedText(bool skip_inline_autocomplete) { - if (!browser_->instant()) - return false; - - const string16 suggestion = location_entry_->GetInstantSuggestion(); - if (suggestion.empty()) - return false; - - location_entry_->model()->FinalizeInstantQuery( - location_entry_->GetText(), suggestion, skip_inline_autocomplete); - return true; -} - -bool LocationBarViewGtk::AcceptCurrentInstantPreview() { - return InstantController::CommitIfCurrent(browser_->instant()); -} - -void LocationBarViewGtk::OnPopupBoundsChanged(const gfx::Rect& bounds) { - InstantController* instant = browser_->instant(); - if (instant) - instant->SetOmniboxBounds(bounds); -} - void LocationBarViewGtk::OnAutocompleteAccept(const GURL& url, WindowOpenDisposition disposition, PageTransition::Type transition, @@ -535,11 +489,6 @@ void LocationBarViewGtk::OnAutocompleteAccept(const GURL& url, } } } - - if (browser_->instant() && !location_entry_->model()->popup_model()->IsOpen()) - browser_->instant()->DestroyPreviewContents(); - - update_instant_ = true; } void LocationBarViewGtk::OnChanged() { @@ -557,15 +506,6 @@ void LocationBarViewGtk::OnChanged() { SetKeywordHintLabel(keyword); AdjustChildrenVisibility(); - - InstantController* instant = browser_->instant(); - string16 suggested_text; - if (update_instant_ && instant && GetTabContents()) { - UpdateInstant(instant, browser_->GetSelectedTabContentsWrapper(), - location_entry_.get(), &suggested_text); - } - - SetSuggestedText(suggested_text); } void LocationBarViewGtk::OnSelectionBoundsChanged() { @@ -627,6 +567,14 @@ string16 LocationBarViewGtk::GetTitle() const { return GetTabContents()->GetTitle(); } +InstantController* LocationBarViewGtk::GetInstant() { + return browser_->instant(); +} + +TabContentsWrapper* LocationBarViewGtk::GetTabContentsWrapper() { + return browser_->GetSelectedTabContentsWrapper(); +} + void LocationBarViewGtk::ShowFirstRunBubble(FirstRun::BubbleType bubble_type) { // We need the browser window to be shown before we can show the bubble, but // we get called before that's happened. @@ -636,14 +584,7 @@ void LocationBarViewGtk::ShowFirstRunBubble(FirstRun::BubbleType bubble_type) { } void LocationBarViewGtk::SetSuggestedText(const string16& text) { - // This method is internally invoked to reset suggest text, so we only do - // anything if the text isn't empty. - // TODO: if we keep autocomplete, make it so this isn't invoked with empty - // text. - if (!text.empty()) { - location_entry_->model()->FinalizeInstantQuery( - location_entry_->GetText(), text, false); - } + location_entry_->model()->SetSuggestedText(text); } std::wstring LocationBarViewGtk::GetInputString() const { diff --git a/chrome/browser/ui/gtk/location_bar_view_gtk.h b/chrome/browser/ui/gtk/location_bar_view_gtk.h index c7374f2..d1ab4d1 100644 --- a/chrome/browser/ui/gtk/location_bar_view_gtk.h +++ b/chrome/browser/ui/gtk/location_bar_view_gtk.h @@ -92,24 +92,19 @@ class LocationBarViewGtk : public AutocompleteEditController, void SetStarred(bool starred); // Implement the AutocompleteEditController interface. - virtual void OnAutocompleteWillClosePopup(); - virtual void OnAutocompleteLosingFocus(gfx::NativeView view_gaining_focus); - virtual void OnAutocompleteWillAccept(); - // For this implementation, the parameter is ignored. - virtual bool OnCommitSuggestedText(bool skip_inline_autocomplete); - virtual bool AcceptCurrentInstantPreview(); - virtual void OnPopupBoundsChanged(const gfx::Rect& bounds); virtual void OnAutocompleteAccept(const GURL& url, - WindowOpenDisposition disposition, - PageTransition::Type transition, - const GURL& alternate_nav_url); - virtual void OnChanged(); - virtual void OnSelectionBoundsChanged(); - virtual void OnKillFocus(); - virtual void OnSetFocus(); - virtual void OnInputInProgress(bool in_progress); - virtual SkBitmap GetFavIcon() const; - virtual string16 GetTitle() const; + WindowOpenDisposition disposition, + PageTransition::Type transition, + const GURL& alternate_nav_url) OVERRIDE; + virtual void OnChanged() OVERRIDE; + virtual void OnSelectionBoundsChanged() OVERRIDE; + virtual void OnKillFocus() OVERRIDE; + virtual void OnSetFocus() OVERRIDE; + virtual void OnInputInProgress(bool in_progress) OVERRIDE; + virtual SkBitmap GetFavIcon() const OVERRIDE; + virtual string16 GetTitle() const OVERRIDE; + virtual InstantController* GetInstant() OVERRIDE; + virtual TabContentsWrapper* GetTabContentsWrapper() OVERRIDE; // Implement the LocationBar interface. virtual void ShowFirstRunBubble(FirstRun::BubbleType bubble_type); @@ -454,9 +449,6 @@ class LocationBarViewGtk : public AutocompleteEditController, // The last search keyword that was shown via the |tab_to_search_box_|. string16 last_keyword_; - // True if we should update the instant controller when the edit text changes. - bool update_instant_; - DISALLOW_COPY_AND_ASSIGN(LocationBarViewGtk); }; diff --git a/chrome/browser/ui/omnibox/location_bar.cc b/chrome/browser/ui/omnibox/location_bar.cc deleted file mode 100644 index fbdfbca..0000000 --- a/chrome/browser/ui/omnibox/location_bar.cc +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (c) 2011 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/ui/omnibox/location_bar.h" - -#include "chrome/browser/autocomplete/autocomplete_edit.h" -#include "chrome/browser/autocomplete/autocomplete_edit_view.h" -#include "chrome/browser/autocomplete/autocomplete_popup_model.h" -#include "chrome/browser/instant/instant_controller.h" -#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" - -// static -void LocationBar::UpdateInstant(InstantController* instant, - TabContentsWrapper* tab, - AutocompleteEditView* edit, - string16* suggested_text) { - if (edit->model()->user_input_in_progress() && - edit->model()->popup_model()->IsOpen()) { - AutocompleteMatch current_match = edit->model()->CurrentMatch(); - if (current_match.destination_url == edit->model()->PermanentURL()) { - // The destination is the same as the current url. This typically happens - // if the user presses the down error in the omnibox, in which case we - // don't want to load a preview. - instant->DestroyPreviewContentsAndLeaveActive(); - } else { - instant->Update(tab, edit->model()->CurrentMatch(), edit->GetText(), - edit->model()->UseVerbatimInstant(), suggested_text); - } - } else { - instant->DestroyPreviewContents(); - } - if (!instant->MightSupportInstant()) - edit->model()->FinalizeInstantQuery(string16(), string16(), false); -} diff --git a/chrome/browser/ui/omnibox/location_bar.h b/chrome/browser/ui/omnibox/location_bar.h index 2ed7312..f88f4a6 100644 --- a/chrome/browser/ui/omnibox/location_bar.h +++ b/chrome/browser/ui/omnibox/location_bar.h @@ -82,12 +82,6 @@ class LocationBar { protected: virtual ~LocationBar() {} - - // Updates instant in response to the text possibly changing in the edit. - static void UpdateInstant(InstantController* instant, - TabContentsWrapper* tab, - AutocompleteEditView* edit, - string16* suggested_text); }; class LocationBarTesting { diff --git a/chrome/browser/ui/views/location_bar/click_handler.cc b/chrome/browser/ui/views/location_bar/click_handler.cc index 311e320..8833998 100644 --- a/chrome/browser/ui/views/location_bar/click_handler.cc +++ b/chrome/browser/ui/views/location_bar/click_handler.cc @@ -11,7 +11,7 @@ #include "views/view.h" ClickHandler::ClickHandler(const views::View* owner, - const LocationBarView* location_bar) + LocationBarView* location_bar) : owner_(owner), location_bar_(location_bar) { } diff --git a/chrome/browser/ui/views/location_bar/click_handler.h b/chrome/browser/ui/views/location_bar/click_handler.h index 9854de8..a4395c4 100644 --- a/chrome/browser/ui/views/location_bar/click_handler.h +++ b/chrome/browser/ui/views/location_bar/click_handler.h @@ -19,13 +19,13 @@ class View; // Info dialog on click, to encapsulate that logic in one place. class ClickHandler { public: - ClickHandler(const views::View* owner, const LocationBarView* location_bar); + ClickHandler(const views::View* owner, LocationBarView* location_bar); void OnMouseReleased(const views::MouseEvent& event, bool canceled); private: const views::View* owner_; - const LocationBarView* location_bar_; + LocationBarView* location_bar_; DISALLOW_IMPLICIT_CONSTRUCTORS(ClickHandler); }; diff --git a/chrome/browser/ui/views/location_bar/ev_bubble_view.cc b/chrome/browser/ui/views/location_bar/ev_bubble_view.cc index 4687c63..577210a 100644 --- a/chrome/browser/ui/views/location_bar/ev_bubble_view.cc +++ b/chrome/browser/ui/views/location_bar/ev_bubble_view.cc @@ -7,7 +7,7 @@ EVBubbleView::EVBubbleView(const int background_images[], int contained_image, const SkColor& color, - const LocationBarView* location_bar) + LocationBarView* location_bar) : IconLabelBubbleView(background_images, contained_image, color), ALLOW_THIS_IN_INITIALIZER_LIST(click_handler_(this, location_bar)) { SetElideInMiddle(true); diff --git a/chrome/browser/ui/views/location_bar/ev_bubble_view.h b/chrome/browser/ui/views/location_bar/ev_bubble_view.h index 0dc33cc..e577313 100644 --- a/chrome/browser/ui/views/location_bar/ev_bubble_view.h +++ b/chrome/browser/ui/views/location_bar/ev_bubble_view.h @@ -21,7 +21,7 @@ class EVBubbleView : public IconLabelBubbleView { EVBubbleView(const int background_images[], int contained_image, const SkColor& color, - const LocationBarView* location_bar); + LocationBarView* location_bar); virtual ~EVBubbleView(); // Overridden from view. diff --git a/chrome/browser/ui/views/location_bar/location_bar_view.cc b/chrome/browser/ui/views/location_bar/location_bar_view.cc index 9b461e3..0fe18a3 100644 --- a/chrome/browser/ui/views/location_bar/location_bar_view.cc +++ b/chrome/browser/ui/views/location_bar/location_bar_view.cc @@ -114,8 +114,7 @@ LocationBarView::LocationBarView(Profile* profile, mode_(mode), show_focus_rect_(false), bubble_type_(FirstRun::MINIMAL_BUBBLE), - template_url_model_(NULL), - update_instant_(true) { + template_url_model_(NULL) { DCHECK(profile_); SetID(VIEW_ID_LOCATION_BAR); SetFocusable(true); @@ -331,10 +330,6 @@ void LocationBarView::SetProfile(Profile* profile) { } } -TabContentsWrapper* LocationBarView::GetTabContentsWrapper() const { - return delegate_->GetTabContentsWrapper(); -} - void LocationBarView::SetPreviewEnabledPageAction(ExtensionAction* page_action, bool preview_enabled) { if (mode_ != NORMAL) @@ -395,6 +390,16 @@ gfx::Point LocationBarView::GetLocationEntryOrigin() const { return origin; } +string16 LocationBarView::GetInstantSuggestion() const { +#if defined(OS_WIN) + return HasValidSuggestText() ? suggested_text_view_->GetText() : string16(); +#else + // On linux the edit shows the suggested text. + NOTREACHED(); + return string16(); +#endif +} + gfx::Size LocationBarView::GetPreferredSize() { return gfx::Size(0, GetThemeProvider()->GetBitmapNamed(mode_ == POPUP ? IDR_LOCATIONBG_POPUPMODE_CENTER : IDR_LOCATIONBG_C)->height()); @@ -731,58 +736,6 @@ void LocationBarView::OnMouseReleased(const views::MouseEvent& event, } #endif -void LocationBarView::OnAutocompleteWillClosePopup() { - if (!update_instant_) - return; - - InstantController* instant = delegate_->GetInstant(); - if (instant && !instant->commit_on_mouse_up()) - instant->DestroyPreviewContents(); -} - -void LocationBarView::OnAutocompleteLosingFocus( - gfx::NativeView view_gaining_focus) { - SetSuggestedText(string16()); - - InstantController* instant = delegate_->GetInstant(); - if (instant) - instant->OnAutocompleteLostFocus(view_gaining_focus); -} - -void LocationBarView::OnAutocompleteWillAccept() { - update_instant_ = false; -} - -bool LocationBarView::OnCommitSuggestedText(bool skip_inline_autocomplete) { - if (!delegate_->GetInstant()) - return false; - - string16 suggestion; -#if defined(OS_WIN) - if (HasValidSuggestText()) - suggestion = suggested_text_view_->GetText(); -#else - suggestion = location_entry_->GetInstantSuggestion(); -#endif - - if (suggestion.empty()) - return false; - - location_entry_->model()->FinalizeInstantQuery( - location_entry_->GetText(), suggestion, skip_inline_autocomplete); - return true; -} - -bool LocationBarView::AcceptCurrentInstantPreview() { - return InstantController::CommitIfCurrent(delegate_->GetInstant()); -} - -void LocationBarView::OnPopupBoundsChanged(const gfx::Rect& bounds) { - InstantController* instant = delegate_->GetInstant(); - if (instant) - instant->SetOmniboxBounds(bounds); -} - void LocationBarView::OnAutocompleteAccept( const GURL& url, WindowOpenDisposition disposition, @@ -816,12 +769,6 @@ void LocationBarView::OnAutocompleteAccept( } } } - - if (delegate_->GetInstant() && - !location_entry_->model()->popup_model()->IsOpen()) - delegate_->GetInstant()->DestroyPreviewContents(); - - update_instant_ = true; } void LocationBarView::OnChanged() { @@ -832,15 +779,6 @@ void LocationBarView::OnChanged() { Layout(); SchedulePaint(); - - InstantController* instant = delegate_->GetInstant(); - string16 suggested_text; - if (update_instant_ && instant && GetTabContentsWrapper()) { - UpdateInstant(instant, GetTabContentsWrapper(), location_entry_.get(), - &suggested_text); - } - - SetSuggestedText(suggested_text); } void LocationBarView::OnSelectionBoundsChanged() { @@ -876,6 +814,14 @@ string16 LocationBarView::GetTitle() const { return GetTabContentsFromDelegate(delegate_)->GetTitle(); } +InstantController* LocationBarView::GetInstant() { + return delegate_->GetInstant(); +} + +TabContentsWrapper* LocationBarView::GetTabContentsWrapper() { + return delegate_->GetTabContentsWrapper(); +} + int LocationBarView::AvailableWidth(int location_bar_width) { return location_bar_width - location_entry_->TextWidth(); } @@ -1043,7 +989,7 @@ bool LocationBarView::SkipDefaultKeyEventProcessing(const views::KeyEvent& e) { // Tab while showing instant commits instant immediately. // Return true so that focus traversal isn't attempted. The edit ends // up doing nothing in this case. - if (AcceptCurrentInstantPreview()) + if (location_entry_->model()->AcceptCurrentInstantPreview()) return true; } @@ -1103,15 +1049,8 @@ void LocationBarView::ShowFirstRunBubble(FirstRun::BubbleType bubble_type) { ShowFirstRunBubbleInternal(bubble_type); } -void LocationBarView::SetSuggestedText(const string16& input) { - // This method is internally invoked to reset suggest text, so we only do - // anything if the text isn't empty. - // TODO: if we keep autocomplete, make it so this isn't invoked with empty - // text. - if (!input.empty()) { - location_entry_->model()->FinalizeInstantQuery(location_entry_->GetText(), - input, false); - } +void LocationBarView::SetSuggestedText(const string16& text) { + location_entry_->model()->SetSuggestedText(text); } std::wstring LocationBarView::GetInputString() const { @@ -1221,7 +1160,7 @@ void LocationBarView::OnTemplateURLModelChanged() { } #if defined(OS_WIN) -bool LocationBarView::HasValidSuggestText() { +bool LocationBarView::HasValidSuggestText() const { return suggested_text_view_ && !suggested_text_view_->size().IsEmpty() && !suggested_text_view_->GetText().empty(); } diff --git a/chrome/browser/ui/views/location_bar/location_bar_view.h b/chrome/browser/ui/views/location_bar/location_bar_view.h index 44e3f11..2ea6efa 100644 --- a/chrome/browser/ui/views/location_bar/location_bar_view.h +++ b/chrome/browser/ui/views/location_bar/location_bar_view.h @@ -131,9 +131,6 @@ class LocationBarView : public LocationBar, void SetProfile(Profile* profile); Profile* profile() const { return profile_; } - // Returns the current TabContentsWrapper. - TabContentsWrapper* GetTabContentsWrapper() const; - // Sets |preview_enabled| for the PageAction View associated with this // |page_action|. If |preview_enabled| is true, the view will display the // PageActions icon even though it has not been activated by the extension. @@ -155,6 +152,9 @@ class LocationBarView : public LocationBar, // appears, not where the icons are shown). gfx::Point GetLocationEntryOrigin() const; + // Returns the current instant suggestion text. + string16 GetInstantSuggestion() const; + // Sizing functions virtual gfx::Size GetPreferredSize() OVERRIDE; @@ -187,13 +187,6 @@ class LocationBarView : public LocationBar, } // AutocompleteEditController - virtual void OnAutocompleteWillClosePopup() OVERRIDE; - virtual void OnAutocompleteLosingFocus( - gfx::NativeView view_gaining_focus) OVERRIDE; - virtual void OnAutocompleteWillAccept() OVERRIDE; - virtual bool OnCommitSuggestedText(bool skip_inline_autocomplete) OVERRIDE; - virtual bool AcceptCurrentInstantPreview() OVERRIDE; - virtual void OnPopupBoundsChanged(const gfx::Rect& bounds) OVERRIDE; virtual void OnAutocompleteAccept(const GURL& url, WindowOpenDisposition disposition, PageTransition::Type transition, @@ -205,6 +198,8 @@ class LocationBarView : public LocationBar, virtual void OnSetFocus() OVERRIDE; virtual SkBitmap GetFavIcon() const OVERRIDE; virtual string16 GetTitle() const OVERRIDE; + virtual InstantController* GetInstant() OVERRIDE; + virtual TabContentsWrapper* GetTabContentsWrapper() OVERRIDE; // Overridden from views::View: virtual std::string GetClassName() const OVERRIDE; @@ -223,7 +218,7 @@ class LocationBarView : public LocationBar, // Overridden from LocationBar: virtual void ShowFirstRunBubble(FirstRun::BubbleType bubble_type) OVERRIDE; - virtual void SetSuggestedText(const string16& input) OVERRIDE; + virtual void SetSuggestedText(const string16& text) OVERRIDE; virtual std::wstring GetInputString() const OVERRIDE; virtual WindowOpenDisposition GetWindowOpenDisposition() const OVERRIDE; virtual PageTransition::Type GetPageTransition() const OVERRIDE; @@ -308,7 +303,7 @@ class LocationBarView : public LocationBar, void OnMouseEvent(const views::MouseEvent& event, UINT msg); // Returns true if the suggest text is valid. - bool HasValidSuggestText(); + bool HasValidSuggestText() const; #endif // Helper to show the first run info bubble. @@ -400,12 +395,6 @@ class LocationBarView : public LocationBar, // crash. TemplateURLModel* template_url_model_; - // Should instant be updated? This is set to false in OnAutocompleteWillAccept - // and true in OnAutocompleteAccept. This is needed as prior to accepting an - // autocomplete suggestion the model is reverted which triggers resetting - // instant. - bool update_instant_; - DISALLOW_IMPLICIT_CONSTRUCTORS(LocationBarView); }; diff --git a/chrome/browser/ui/views/location_bar/location_icon_view.cc b/chrome/browser/ui/views/location_bar/location_icon_view.cc index 66aad67..328537d 100644 --- a/chrome/browser/ui/views/location_bar/location_icon_view.cc +++ b/chrome/browser/ui/views/location_bar/location_icon_view.cc @@ -8,7 +8,7 @@ #include "grit/generated_resources.h" #include "ui/base/l10n/l10n_util.h" -LocationIconView::LocationIconView(const LocationBarView* location_bar) +LocationIconView::LocationIconView(LocationBarView* location_bar) : ALLOW_THIS_IN_INITIALIZER_LIST(click_handler_(this, location_bar)) { SetTooltipText(UTF16ToWide(l10n_util::GetStringUTF16( IDS_TOOLTIP_LOCATION_ICON))); diff --git a/chrome/browser/ui/views/location_bar/location_icon_view.h b/chrome/browser/ui/views/location_bar/location_icon_view.h index 55303ed..3bb80c7 100644 --- a/chrome/browser/ui/views/location_bar/location_icon_view.h +++ b/chrome/browser/ui/views/location_bar/location_icon_view.h @@ -19,7 +19,7 @@ class MouseEvent; // status on https pages, or a globe for other URLs. class LocationIconView : public views::ImageView { public: - explicit LocationIconView(const LocationBarView* location_bar); + explicit LocationIconView(LocationBarView* location_bar); virtual ~LocationIconView(); // Overridden from views::ImageView: diff --git a/chrome/browser/ui/views/location_bar/suggested_text_view.cc b/chrome/browser/ui/views/location_bar/suggested_text_view.cc index d694182..e6956ed 100644 --- a/chrome/browser/ui/views/location_bar/suggested_text_view.cc +++ b/chrome/browser/ui/views/location_bar/suggested_text_view.cc @@ -4,14 +4,15 @@ #include "chrome/browser/ui/views/location_bar/suggested_text_view.h" +#include "chrome/browser/autocomplete/autocomplete_edit.h" #include "chrome/browser/instant/instant_controller.h" #include "chrome/browser/ui/views/location_bar/location_bar_view.h" #include "ui/base/animation/multi_animation.h" #include "ui/gfx/canvas.h" #include "ui/gfx/color_utils.h" -SuggestedTextView::SuggestedTextView(LocationBarView* location_bar) - : location_bar_(location_bar), +SuggestedTextView::SuggestedTextView(AutocompleteEditModel* edit_model) + : edit_model_(edit_model), bg_color_(0) { } @@ -46,7 +47,7 @@ void SuggestedTextView::OnPaintBackground(gfx::Canvas* canvas) { } void SuggestedTextView::AnimationEnded(const ui::Animation* animation) { - location_bar_->OnCommitSuggestedText(false); + edit_model_->CommitSuggestedText(false); } void SuggestedTextView::AnimationProgressed(const ui::Animation* animation) { diff --git a/chrome/browser/ui/views/location_bar/suggested_text_view.h b/chrome/browser/ui/views/location_bar/suggested_text_view.h index 9f706b2..c64af82 100644 --- a/chrome/browser/ui/views/location_bar/suggested_text_view.h +++ b/chrome/browser/ui/views/location_bar/suggested_text_view.h @@ -9,15 +9,15 @@ #include "ui/base/animation/animation_delegate.h" #include "views/controls/label.h" -class LocationBarView; +class AutocompleteEditModel; // SuggestedTextView is used to show the suggest text in the LocationBar. // Invoke |StartAnimation| to start an animation that when done invokes -// |OnCommitSuggestedText| on the LocationBar to commit the suggested text. +// |CommitSuggestedText| on the AutocompleteEdit to commit the suggested text. class SuggestedTextView : public views::Label, public ui::AnimationDelegate { public: - explicit SuggestedTextView(LocationBarView* location_bar); + explicit SuggestedTextView(AutocompleteEditModel* edit_model); virtual ~SuggestedTextView(); // Starts the animation. If the animation is currently running it is stopped @@ -44,7 +44,7 @@ class SuggestedTextView : public views::Label, // Resets the background color. void UpdateBackgroundColor(); - LocationBarView* location_bar_; + AutocompleteEditModel* edit_model_; scoped_ptr<ui::Animation> animation_; diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index d4f9f15..d6cb3d1 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -2772,7 +2772,6 @@ 'browser/ui/login/login_prompt_mac.h', 'browser/ui/login/login_prompt_mac.mm', 'browser/ui/login/login_prompt_win.cc', - 'browser/ui/omnibox/location_bar.cc', 'browser/ui/omnibox/location_bar.h', 'browser/ui/omnibox/location_bar_util.cc', 'browser/ui/omnibox/location_bar_util.h', |