diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-05 19:41:46 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-05 19:41:46 +0000 |
commit | 731980c04db87643c41d6f8d6f594de1cf7b725d (patch) | |
tree | 32acaf7943e4555baea781e87155850a80db9fb7 /chrome | |
parent | 89904504a55525eebbba9b1c8519fdfbef667255 (diff) | |
download | chromium_src-731980c04db87643c41d6f8d6f594de1cf7b725d.zip chromium_src-731980c04db87643c41d6f8d6f594de1cf7b725d.tar.gz chromium_src-731980c04db87643c41d6f8d6f594de1cf7b725d.tar.bz2 |
Better behavior for ctrl-k: If we're already in forced_query mode, re-select the query text instead of clearing the box.
BUG=6985
TEST=Press ctrl-k, type "foo", press ctrl-k again. The omnibox should show "?foo" with "foo" selected.
Review URL: http://codereview.chromium.org/119135
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17757 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
10 files changed, 45 insertions, 4 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view.h b/chrome/browser/autocomplete/autocomplete_edit_view.h index 27c28e7..b8b438f 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view.h +++ b/chrome/browser/autocomplete/autocomplete_edit_view.h @@ -69,6 +69,15 @@ class AutocompleteEditView { virtual void SetWindowTextAndCaretPos(const std::wstring& text, size_t caret_pos) = 0; + // Sets the edit to forced query mode. Practically speaking, this means that + // if the edit is not in forced query mode, its text is set to "?" with the + // cursor at the end, and if the edit is in forced query mode (its first + // character is '?'), the text after the '?' is selected. + // + // In the future we should display the search engine UI for the default engine + // rather than '?'. + virtual void SetForcedQuery() = 0; + // Returns true if all text is selected. virtual bool IsSelectAll() = 0; diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc index 272e5ab..25e647f 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc +++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc @@ -226,6 +226,19 @@ void AutocompleteEditViewGtk::SetWindowTextAndCaretPos(const std::wstring& text, gtk_text_buffer_place_cursor(text_buffer_, &cur_pos); } +void AutocompleteEditViewGtk::SetForcedQuery() { + const std::wstring current_text(GetText()); + if (current_text.empty() || (current_text[0] != '?')) { + SetUserText(L"?"); + } else { + GtkTextIter start, end; + gtk_text_buffer_get_bounds(text_buffer_, &start, &end); + gtk_text_buffer_get_iter_at_offset(text_buffer_, &start, 1); + gtk_text_buffer_place_cursor(text_buffer_, &start); + gtk_text_buffer_select_range(text_buffer_, &start, &end); + } +} + bool AutocompleteEditViewGtk::IsSelectAll() { NOTIMPLEMENTED(); return false; diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h index 7ac02d9..65dcad9 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h +++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h @@ -67,6 +67,8 @@ class AutocompleteEditViewGtk : public AutocompleteEditView { virtual void SetWindowTextAndCaretPos(const std::wstring& text, size_t caret_pos); + virtual void SetForcedQuery(); + virtual bool IsSelectAll(); virtual void SelectAll(bool reversed); virtual void RevertAll(); diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_mac.h b/chrome/browser/autocomplete/autocomplete_edit_view_mac.h index 8f70070..5ec2d0f 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_mac.h +++ b/chrome/browser/autocomplete/autocomplete_edit_view_mac.h @@ -63,6 +63,8 @@ class AutocompleteEditViewMac : public AutocompleteEditView { virtual void SetWindowTextAndCaretPos(const std::wstring& text, size_t caret_pos); + virtual void SetForcedQuery() { NOTIMPLEMENTED(); } + virtual bool IsSelectAll() { NOTIMPLEMENTED(); return false; diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_win.cc b/chrome/browser/autocomplete/autocomplete_edit_view_win.cc index 67f7245..2a58b66 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_win.cc +++ b/chrome/browser/autocomplete/autocomplete_edit_view_win.cc @@ -666,6 +666,14 @@ void AutocompleteEditViewWin::SetWindowTextAndCaretPos(const std::wstring& text, PlaceCaretAt(caret_pos); } +void AutocompleteEditViewWin::SetForcedQuery() { + const std::wstring current_text(GetText()); + if (current_text.empty() || (current_text[0] != '?')) + SetUserText(L"?"); + else + SetSelection(current_text.length(), 1); +} + bool AutocompleteEditViewWin::IsSelectAll() { CHARRANGE selection; GetSel(selection); @@ -888,7 +896,7 @@ void AutocompleteEditViewWin::PasteAndGo(const std::wstring& text) { } bool AutocompleteEditViewWin::SkipDefaultKeyEventProcessing( - const views::KeyEvent& e) { + const views::KeyEvent& e) { int c = e.GetCharacter(); // We don't process ALT + numpad digit as accelerators, they are used for // entering special characters. We do translate alt-home. diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_win.h b/chrome/browser/autocomplete/autocomplete_edit_view_win.h index 9e677f6..822ebea 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_win.h +++ b/chrome/browser/autocomplete/autocomplete_edit_view_win.h @@ -100,6 +100,8 @@ class AutocompleteEditViewWin virtual void SetWindowTextAndCaretPos(const std::wstring& text, size_t caret_pos); + virtual void SetForcedQuery(); + virtual bool IsSelectAll(); virtual void SelectAll(bool reversed); virtual void RevertAll(); diff --git a/chrome/browser/cocoa/location_bar_view_mac.h b/chrome/browser/cocoa/location_bar_view_mac.h index ea51e3a..f863e51 100644 --- a/chrome/browser/cocoa/location_bar_view_mac.h +++ b/chrome/browser/cocoa/location_bar_view_mac.h @@ -36,7 +36,7 @@ class LocationBarViewMac : public AutocompleteEditController, virtual void AcceptInput(); virtual void AcceptInputWithDisposition(WindowOpenDisposition disposition); virtual void FocusLocation(); - virtual void FocusSearch() { NOTIMPLEMENTED(); } + virtual void FocusSearch(); virtual void UpdateFeedIcon() { /* http://crbug.com/8832 */ } virtual void UpdatePageActions() { /* http://crbug.com/12281 */ } virtual void SaveStateToContents(TabContents* contents); diff --git a/chrome/browser/cocoa/location_bar_view_mac.mm b/chrome/browser/cocoa/location_bar_view_mac.mm index 922dca5..c90be1a 100644 --- a/chrome/browser/cocoa/location_bar_view_mac.mm +++ b/chrome/browser/cocoa/location_bar_view_mac.mm @@ -60,6 +60,11 @@ void LocationBarViewMac::FocusLocation() { edit_view_->FocusLocation(); } +void LocationBarViewMac::FocusSearch() { + edit_view_->SetForcedQuery(); + // TODO(pkasting): Focus the edit a la Linux/Win +} + void LocationBarViewMac::SaveStateToContents(TabContents* contents) { // TODO(shess): Why SaveStateToContents vs SaveStateToTab? edit_view_->SaveStateToTab(contents); diff --git a/chrome/browser/gtk/location_bar_view_gtk.cc b/chrome/browser/gtk/location_bar_view_gtk.cc index 27dc3a0..beccd08 100644 --- a/chrome/browser/gtk/location_bar_view_gtk.cc +++ b/chrome/browser/gtk/location_bar_view_gtk.cc @@ -190,8 +190,8 @@ void LocationBarViewGtk::FocusLocation() { } void LocationBarViewGtk::FocusSearch() { - location_entry_->SetUserText(L"?"); location_entry_->SetFocus(); + location_entry_->SetForcedQuery(); } void LocationBarViewGtk::UpdatePageActions() { diff --git a/chrome/browser/views/location_bar_view.cc b/chrome/browser/views/location_bar_view.cc index a792b99..d41d254 100644 --- a/chrome/browser/views/location_bar_view.cc +++ b/chrome/browser/views/location_bar_view.cc @@ -1313,8 +1313,8 @@ void LocationBarView::FocusLocation() { } void LocationBarView::FocusSearch() { - location_entry_->SetUserText(L"?"); location_entry_->SetFocus(); + location_entry_->SetForcedQuery(); } void LocationBarView::SaveStateToContents(TabContents* contents) { |