summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorshess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-28 19:01:34 +0000
committershess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-28 19:01:34 +0000
commit45b09b9a37236dea6325227a159a0311ff7de85c (patch)
treeffe6159441cd19c5ebbf83aaf6c4cba8884d6346 /chrome
parentc3b9c4b69ee265c59a40d0708ed469ff0fc2c102 (diff)
downloadchromium_src-45b09b9a37236dea6325227a159a0311ff7de85c.zip
chromium_src-45b09b9a37236dea6325227a159a0311ff7de85c.tar.gz
chromium_src-45b09b9a37236dea6325227a159a0311ff7de85c.tar.bz2
[Mac] Handle backspacing out of keyword search.
When the user hits backspace with the caret on the LHS in a keyword search, should exit keyword search. [Apple keyboards may label what I'm calling "backspace" as "delete". The wide key above |\ key.] http://crbug.com/20286 TEST=Type www.google.com, then tab to enter keyword search. Type some text. Select-all and hit backspace, should stay in keyword mode. Type some text, backspace should work as normal. Type some text, position caret at LHS, backspace should take you out of keyword mode. Review URL: http://codereview.chromium.org/180009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@24767 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_mac.h6
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_mac.mm25
2 files changed, 31 insertions, 0 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_mac.h b/chrome/browser/autocomplete/autocomplete_edit_view_mac.h
index 0c0cb2b..e3c6372 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_mac.h
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_mac.h
@@ -116,6 +116,12 @@ class AutocompleteEditViewMac : public AutocompleteEditView {
// if so. Returns true if the tab should be eaten.
bool OnTabPressed();
+ // Called when the user hits backspace in |field_|. Checks whether
+ // keyword search is being terminated. Returns true if the
+ // backspace should be intercepted (not forwarded on to the standard
+ // machinery).
+ bool OnBackspacePressed();
+
void AcceptInput(WindowOpenDisposition disposition, bool for_drop);
// Helper for LocationBarViewMac. 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 9ca8a6b..69a1b4e 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm
@@ -630,6 +630,25 @@ bool AutocompleteEditViewMac::OnTabPressed() {
return false;
}
+bool AutocompleteEditViewMac::OnBackspacePressed() {
+ // Don't intercept if not in keyword search mode.
+ if (model_->is_keyword_hint() || model_->keyword().empty()) {
+ return false;
+ }
+
+ // Don't intercept if there is a selection, or the cursor isn't at
+ // the leftmost position.
+ const NSRange selection = GetSelectedRange();
+ if (selection.length > 0 || selection.location > 0) {
+ return false;
+ }
+
+ // We're showing a keyword and the user pressed backspace at the
+ // beginning of the text. Delete the selected keyword.
+ model_->ClearKeyword(GetText());
+ return true;
+}
+
bool AutocompleteEditViewMac::IsPopupOpen() const {
return popup_view_->IsOpen();
}
@@ -757,6 +776,12 @@ std::wstring AutocompleteEditViewMac::GetClipboardText(Clipboard* clipboard) {
return YES;
}
+ if (cmd == @selector(deleteBackward:)) {
+ if (edit_view_->OnBackspacePressed()) {
+ return YES;
+ }
+ }
+
// Capture the state before the operation changes the content.
// TODO(shess): Determine if this is always redundent WRT the call
// in -controlTextDidChange:.