summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-19 20:21:22 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-19 20:21:22 +0000
commitb93b79ecb040bc0563dec1b5e8e8cea3eed04e75 (patch)
tree48eaf3dc50cea53f2798713ad84b12e1947694c3 /chrome
parentbb30c93d17e1232c4e7a6c4d0d0ac9047cee190b (diff)
downloadchromium_src-b93b79ecb040bc0563dec1b5e8e8cea3eed04e75.zip
chromium_src-b93b79ecb040bc0563dec1b5e8e8cea3eed04e75.tar.gz
chromium_src-b93b79ecb040bc0563dec1b5e8e8cea3eed04e75.tar.bz2
Adds support for proper handling of verbatim queries. That is, if the
user enabled predictive instant we switch to verbatim in certain situations. BUG=59217 TEST=see bug Review URL: http://codereview.chromium.org/5225003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@66805 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/autocomplete/autocomplete.cc2
-rw-r--r--chrome/browser/autocomplete/autocomplete.h8
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit.cc12
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit.h7
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_unittest.cc1
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view.h3
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc20
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_gtk.h7
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_mac.h1
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_mac.mm5
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_win.cc23
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_win.h4
-rw-r--r--chrome/browser/cocoa/location_bar/location_bar_view_mac.mm11
-rw-r--r--chrome/browser/gtk/location_bar_view_gtk.cc11
-rw-r--r--chrome/browser/ui/views/location_bar/location_bar_view.cc4
15 files changed, 97 insertions, 22 deletions
diff --git a/chrome/browser/autocomplete/autocomplete.cc b/chrome/browser/autocomplete/autocomplete.cc
index 8c47a69..6dafeaf 100644
--- a/chrome/browser/autocomplete/autocomplete.cc
+++ b/chrome/browser/autocomplete/autocomplete.cc
@@ -44,6 +44,7 @@ using base::TimeDelta;
AutocompleteInput::AutocompleteInput()
: type_(INVALID),
+ initial_prevent_inline_autocomplete_(false),
prevent_inline_autocomplete_(false),
prefer_keyword_(false),
allow_exact_keyword_match_(true),
@@ -57,6 +58,7 @@ AutocompleteInput::AutocompleteInput(const std::wstring& text,
bool allow_exact_keyword_match,
bool synchronous_only)
: desired_tld_(desired_tld),
+ initial_prevent_inline_autocomplete_(prevent_inline_autocomplete),
prevent_inline_autocomplete_(prevent_inline_autocomplete),
prefer_keyword_(prefer_keyword),
allow_exact_keyword_match_(allow_exact_keyword_match),
diff --git a/chrome/browser/autocomplete/autocomplete.h b/chrome/browser/autocomplete/autocomplete.h
index 53fd392..02dac74 100644
--- a/chrome/browser/autocomplete/autocomplete.h
+++ b/chrome/browser/autocomplete/autocomplete.h
@@ -249,6 +249,13 @@ class AutocompleteInput {
return prevent_inline_autocomplete_;
}
+ // Returns the value of |prevent_inline_autocomplete| supplied to the
+ // constructor. This differs from the value returned by
+ // |prevent_inline_autocomplete()| if the input contained trailing whitespace.
+ bool initial_prevent_inline_autocomplete() const {
+ return initial_prevent_inline_autocomplete_;
+ }
+
// Returns whether, given an input string consisting solely of a substituting
// keyword, we should score it like a non-substituting keyword.
bool prefer_keyword() const { return prefer_keyword_; }
@@ -277,6 +284,7 @@ class AutocompleteInput {
url_parse::Parsed parts_;
std::wstring scheme_;
GURL canonicalized_url_;
+ bool initial_prevent_inline_autocomplete_;
bool prevent_inline_autocomplete_;
bool prefer_keyword_;
bool allow_exact_keyword_match_;
diff --git a/chrome/browser/autocomplete/autocomplete_edit.cc b/chrome/browser/autocomplete/autocomplete_edit.cc
index adf5985..d64a231 100644
--- a/chrome/browser/autocomplete/autocomplete_edit.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit.cc
@@ -171,9 +171,15 @@ void AutocompleteEditModel::GetDataForURLExport(GURL* url,
}
}
-bool AutocompleteEditModel::PreventInlineAutocomplete() {
- return
- popup_->autocomplete_controller()->input().prevent_inline_autocomplete();
+bool AutocompleteEditModel::UseVerbatimInstant() {
+ const AutocompleteInput& input = popup_->autocomplete_controller()->input();
+ if (input.initial_prevent_inline_autocomplete() ||
+ view_->DeleteAtEndPressed() || (popup_->selected_line() != 0))
+ return true;
+
+ std::wstring::size_type start, end;
+ view_->GetSelectionBounds(&start, &end);
+ return (start != end) || (start != view_->GetText().size());
}
std::wstring AutocompleteEditModel::GetDesiredTLD() const {
diff --git a/chrome/browser/autocomplete/autocomplete_edit.h b/chrome/browser/autocomplete/autocomplete_edit.h
index 1b4f4a1..7123b36 100644
--- a/chrome/browser/autocomplete/autocomplete_edit.h
+++ b/chrome/browser/autocomplete/autocomplete_edit.h
@@ -157,9 +157,10 @@ class AutocompleteEditModel : public NotificationObserver {
// Sets the url, and if known, the title and favicon.
void GetDataForURLExport(GURL* url, std::wstring* title, SkBitmap* favicon);
- // Returns true if inline autocomplete was prevented the last time
- // autocomplete was run.
- bool PreventInlineAutocomplete();
+ // Returns true if a verbatim query should be used for instant. A verbatim
+ // query is forced in certain situations, such as pressing delete at the end
+ // of the edit.
+ bool UseVerbatimInstant();
// If the user presses ctrl-enter, it means "add .com to the the end". The
// desired TLD is the TLD the user desires to add to the end of the current
diff --git a/chrome/browser/autocomplete/autocomplete_edit_unittest.cc b/chrome/browser/autocomplete/autocomplete_edit_unittest.cc
index d2b93c5..d8a503b 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_unittest.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit_unittest.cc
@@ -36,6 +36,7 @@ class TestingAutocompleteEditView : public AutocompleteEditView {
virtual void ReplaceSelection(const string16& text) {}
virtual void SetForcedQuery() {}
virtual bool IsSelectAll() { return false; }
+ virtual bool DeleteAtEndPressed() { return false; }
virtual void GetSelectionBounds(std::wstring::size_type* start,
std::wstring::size_type* end) {}
virtual void SelectAll(bool reversed) {}
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view.h b/chrome/browser/autocomplete/autocomplete_edit_view.h
index 51224f8..dc35912 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view.h
+++ b/chrome/browser/autocomplete/autocomplete_edit_view.h
@@ -95,6 +95,9 @@ class AutocompleteEditView {
// Returns true if all text is selected or there is no text at all.
virtual bool IsSelectAll() = 0;
+ // Returns true if the user deleted the suggested text.
+ virtual bool DeleteAtEndPressed() = 0;
+
// Fills |start| and |end| with the indexes of the current selection's bounds.
// It is not guaranteed that |*start < *end|, as the selection can be
// directed. If there is no selection, |start| and |end| will both be equal
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
index 9204f8f..6a0396a 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
@@ -182,6 +182,8 @@ AutocompleteEditViewGtk::AutocompleteEditViewGtk(
enter_was_inserted_(false),
enable_tab_to_search_(true),
selection_suggested_(false),
+ delete_was_pressed_(false),
+ delete_at_end_pressed_(false),
going_to_focus_(NULL) {
model_->SetPopupModel(popup_view_->GetModel());
}
@@ -587,6 +589,10 @@ bool AutocompleteEditViewGtk::IsSelectAll() {
gtk_text_iter_equal(&end, &sel_end);
}
+bool AutocompleteEditViewGtk::DeleteAtEndPressed() {
+ return delete_at_end_pressed_;
+}
+
void AutocompleteEditViewGtk::GetSelectionBounds(std::wstring::size_type* start,
std::wstring::size_type* end) {
CharRange selection = GetSelection();
@@ -714,6 +720,8 @@ bool AutocompleteEditViewGtk::OnAfterPossibleChange() {
(new_sel.cp_min <= std::min(sel_before_change_.cp_min,
sel_before_change_.cp_max));
+ delete_at_end_pressed_ = false;
+
bool something_changed = model_->OnAfterPossibleChange(new_text,
selection_differs, text_changed_, just_deleted_text, at_end_of_edit);
@@ -721,10 +729,15 @@ bool AutocompleteEditViewGtk::OnAfterPossibleChange() {
// OnChanged() method, which is called in TextChanged().
// But we still need to call EmphasizeURLComponents() to make sure the text
// attributes are updated correctly.
- if (something_changed && text_changed_)
+ if (something_changed && text_changed_) {
TextChanged();
- else if (selection_differs)
+ } else if (selection_differs) {
EmphasizeURLComponents();
+ } else if (delete_was_pressed_ && at_end_of_edit) {
+ delete_at_end_pressed_ = true;
+ controller_->OnChanged();
+ }
+ delete_was_pressed_ = false;
return something_changed;
}
@@ -909,6 +922,9 @@ gboolean AutocompleteEditViewGtk::HandleKeyPress(GtkWidget* widget,
event->keyval == GDK_KP_Tab) &&
!(event->state & GDK_CONTROL_MASK));
+ delete_was_pressed_ = (event->keyval == GDK_Delete ||
+ event->keyval == GDK_KP_Delete);
+
// Reset |enter_was_inserted_|, which may be set in the "insert-text" signal
// handler, so that we'll know if an Enter key event was handled by IME.
enter_was_inserted_ = false;
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h
index 06ef3f4..c2ade1b 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h
@@ -122,6 +122,7 @@ class AutocompleteEditViewGtk : public AutocompleteEditView,
virtual void SetForcedQuery();
virtual bool IsSelectAll();
+ virtual bool DeleteAtEndPressed();
virtual void GetSelectionBounds(std::wstring::size_type* start,
std::wstring::size_type* end);
virtual void SelectAll(bool reversed);
@@ -465,6 +466,12 @@ class AutocompleteEditViewGtk : public AutocompleteEditView,
// is not suggested text, that means the user manually made the selection.
bool selection_suggested_;
+ // Was delete pressed?
+ bool delete_was_pressed_;
+
+ // Was the delete key pressed with an empty selection at the end of the edit?
+ bool delete_at_end_pressed_;
+
#if GTK_CHECK_VERSION(2, 20, 0)
// Stores the text being composed by the input method.
std::wstring preedit_;
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_mac.h b/chrome/browser/autocomplete/autocomplete_edit_view_mac.h
index 3bc3eff..3ae8fe7 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_mac.h
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_mac.h
@@ -62,6 +62,7 @@ class AutocompleteEditViewMac : public AutocompleteEditView,
virtual void SetForcedQuery();
virtual bool IsSelectAll();
+ virtual bool DeleteAtEndPressed();
virtual void GetSelectionBounds(std::wstring::size_type* start,
std::wstring::size_type* end);
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm b/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm
index 12aeeb8..e2ba9cc 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm
@@ -373,6 +373,11 @@ bool AutocompleteEditViewMac::IsSelectAll() {
return NSEqualRanges(all_range, GetSelectedRange());
}
+bool AutocompleteEditViewMac::DeleteAtEndPressed() {
+ // TODO: implement me.
+ return false;
+}
+
void AutocompleteEditViewMac::GetSelectionBounds(std::wstring::size_type* start,
std::wstring::size_type* end) {
if (![field_ currentEditor]) {
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_win.cc b/chrome/browser/autocomplete/autocomplete_edit_view_win.cc
index 75e96d5..05d149e 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_win.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_win.cc
@@ -410,6 +410,7 @@ AutocompleteEditViewWin::AutocompleteEditViewWin(
double_click_time_(0),
can_discard_mousemove_(false),
ignore_ime_messages_(false),
+ delete_at_end_pressed_(false),
font_(font),
possible_drag_(false),
in_drag_(false),
@@ -681,6 +682,10 @@ bool AutocompleteEditViewWin::IsSelectAll() {
return IsSelectAllForRange(selection);
}
+bool AutocompleteEditViewWin::DeleteAtEndPressed() {
+ return delete_at_end_pressed_;
+}
+
void AutocompleteEditViewWin::GetSelectionBounds(std::wstring::size_type* start,
std::wstring::size_type* end) {
CHARRANGE selection;
@@ -915,6 +920,8 @@ bool AutocompleteEditViewWin::OnAfterPossibleChange() {
// Notify assistive technology that the cursor or selection changed.
parent_view_->NotifyAccessibilityEvent(
AccessibilityTypes::EVENT_SELECTION_CHANGED);
+ } else if (delete_at_end_pressed_) {
+ controller_->OnChanged();
}
return something_changed;
@@ -1363,6 +1370,8 @@ LRESULT AutocompleteEditViewWin::OnImeNotify(UINT message,
void AutocompleteEditViewWin::OnKeyDown(TCHAR key,
UINT repeat_count,
UINT flags) {
+ delete_at_end_pressed_ = false;
+
if (OnKeyDownAllModes(key, repeat_count, flags))
return;
@@ -1912,7 +1921,8 @@ bool AutocompleteEditViewWin::OnKeyDownOnlyWritable(TCHAR key,
//
// Cut: Shift-Delete and Ctrl-x are treated as cut. Ctrl-Shift-Delete and
// Ctrl-Shift-x are not treated as cut even though the underlying
- // CRichTextEdit would treat them as such.
+ // CRichTextEdit would treat them as such. Also note that we bring
+ // up 'clear browsing data' on control-shift-delete.
// Copy: Ctrl-Insert and Ctrl-c is treated as copy. Shift-Ctrl-c is not.
// (This is handled in OnKeyDownAllModes().)
// Paste: Shift-Insert and Ctrl-v are treated as paste. Ctrl-Shift-Insert
@@ -1922,8 +1932,17 @@ bool AutocompleteEditViewWin::OnKeyDownOnlyWritable(TCHAR key,
// conforms to what users expect.
case VK_DELETE:
- if ((flags & KF_ALTDOWN) || GetKeyState(VK_SHIFT) >= 0)
+ if (flags & KF_ALTDOWN)
return false;
+ if (GetKeyState(VK_SHIFT) >= 0) {
+ if (GetKeyState(VK_CONTROL) >= 0) {
+ CHARRANGE selection;
+ GetSel(selection);
+ delete_at_end_pressed_ = ((selection.cpMin == selection.cpMax) &&
+ (selection.cpMin == GetTextLength()));
+ }
+ return false;
+ }
if (GetKeyState(VK_CONTROL) >= 0) {
// Cut text if possible.
CHARRANGE selection;
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_win.h b/chrome/browser/autocomplete/autocomplete_edit_view_win.h
index fbe103f..c78565f 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_win.h
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_win.h
@@ -119,6 +119,7 @@ class AutocompleteEditViewWin
virtual void SetForcedQuery();
virtual bool IsSelectAll();
+ virtual bool DeleteAtEndPressed();
virtual void GetSelectionBounds(std::wstring::size_type* start,
std::wstring::size_type* end);
virtual void SelectAll(bool reversed);
@@ -477,6 +478,9 @@ class AutocompleteEditViewWin
// there is no saved selection.
CHARRANGE saved_selection_for_focus_change_;
+ // Was the delete key pressed with an empty selection at the end of the edit?
+ bool delete_at_end_pressed_;
+
// The context menu for the edit.
scoped_ptr<menus::SimpleMenuModel> context_menu_contents_;
scoped_ptr<views::Menu2> context_menu_;
diff --git a/chrome/browser/cocoa/location_bar/location_bar_view_mac.mm b/chrome/browser/cocoa/location_bar/location_bar_view_mac.mm
index 95edc30..b19f01c 100644
--- a/chrome/browser/cocoa/location_bar/location_bar_view_mac.mm
+++ b/chrome/browser/cocoa/location_bar/location_bar_view_mac.mm
@@ -314,11 +314,12 @@ void LocationBarViewMac::OnChanged() {
if (update_instant_ && instant && GetTabContents()) {
if (edit_view_->model()->user_input_in_progress() &&
edit_view_->model()->popup_model()->IsOpen()) {
- instant->Update(browser_->GetSelectedTabContentsWrapper(),
- edit_view_->model()->CurrentMatch(),
- WideToUTF16(edit_view_->GetText()),
- false, // TODO: make this real
- &suggested_text);
+ instant->Update
+ (browser_->GetSelectedTabContentsWrapper(),
+ edit_view_->model()->CurrentMatch(),
+ WideToUTF16(edit_view_->GetText()),
+ edit_view_->model()->UseVerbatimInstant(),
+ &suggested_text);
} else {
if (instant->is_active())
instant->DestroyPreviewContents();
diff --git a/chrome/browser/gtk/location_bar_view_gtk.cc b/chrome/browser/gtk/location_bar_view_gtk.cc
index 65d749d..dcd5925 100644
--- a/chrome/browser/gtk/location_bar_view_gtk.cc
+++ b/chrome/browser/gtk/location_bar_view_gtk.cc
@@ -536,11 +536,12 @@ void LocationBarViewGtk::OnChanged() {
if (update_instant_ && instant && GetTabContents()) {
if (location_entry_->model()->user_input_in_progress() &&
location_entry_->model()->popup_model()->IsOpen()) {
- instant->Update(browser_->GetSelectedTabContentsWrapper(),
- location_entry_->model()->CurrentMatch(),
- WideToUTF16(location_entry_->GetText()),
- false, // TODO: make this real
- &suggested_text);
+ instant->Update(
+ browser_->GetSelectedTabContentsWrapper(),
+ location_entry_->model()->CurrentMatch(),
+ WideToUTF16(location_entry_->GetText()),
+ location_entry_->model()->UseVerbatimInstant(),
+ &suggested_text);
} else {
instant->DestroyPreviewContents();
}
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 655a7b2..0b42f32 100644
--- a/chrome/browser/ui/views/location_bar/location_bar_view.cc
+++ b/chrome/browser/ui/views/location_bar/location_bar_view.cc
@@ -853,7 +853,7 @@ void LocationBarView::OnChanged() {
instant->Update(GetTabContentsWrapper(),
location_entry_->model()->CurrentMatch(),
WideToUTF16(location_entry_->GetText()),
- false, // TODO: make this real
+ location_entry_->model()->UseVerbatimInstant(),
&suggested_text);
} else {
instant->DestroyPreviewContents();
@@ -1111,7 +1111,7 @@ void LocationBarView::ShowFirstRunBubble(FirstRun::BubbleType bubble_type) {
void LocationBarView::SetSuggestedText(const string16& input) {
// Don't show the suggested text if inline autocomplete is prevented.
- string16 text = location_entry_->model()->PreventInlineAutocomplete() ?
+ string16 text = location_entry_->model()->UseVerbatimInstant() ?
string16() : input;
if (!text.empty()) {
if (!suggested_text_view_) {