summaryrefslogtreecommitdiffstats
path: root/chrome/browser/autocomplete
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-11 00:37:15 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-11 00:37:15 +0000
commit553aabb40b432ecdc2c289c935ba77874928dfcc (patch)
tree7ecabde66cc28677bc092a715c2a1228cac80ba5 /chrome/browser/autocomplete
parent2ca83cd871de1a2c322a48b80d06f4d3c8bb6923 (diff)
downloadchromium_src-553aabb40b432ecdc2c289c935ba77874928dfcc.zip
chromium_src-553aabb40b432ecdc2c289c935ba77874928dfcc.tar.gz
chromium_src-553aabb40b432ecdc2c289c935ba77874928dfcc.tar.bz2
Makes the instant suggested text autocomplete after 1.3 seconds. There
are a number of parts of this patch that need work, but it should be good enough for us to decide if we want to pursue it. BUG=none TEST=none Review URL: http://codereview.chromium.org/4385001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@65741 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autocomplete')
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit.cc5
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit.h7
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_unittest.cc2
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view.h4
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc20
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_gtk.h5
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_mac.h2
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_mac.mm4
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_win.cc42
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_win.h20
10 files changed, 66 insertions, 45 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit.cc b/chrome/browser/autocomplete/autocomplete_edit.cc
index 25a59e4..011fee7 100644
--- a/chrome/browser/autocomplete/autocomplete_edit.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit.cc
@@ -171,6 +171,11 @@ void AutocompleteEditModel::GetDataForURLExport(GURL* url,
}
}
+bool AutocompleteEditModel::PreventInlineAutocomplete() {
+ return
+ popup_->autocomplete_controller()->input().prevent_inline_autocomplete();
+}
+
std::wstring AutocompleteEditModel::GetDesiredTLD() const {
// Tricky corner case: The user has typed "foo" and currently sees an inline
// autocomplete suggestion of "foo.net". He now presses ctrl-a (e.g. to
diff --git a/chrome/browser/autocomplete/autocomplete_edit.h b/chrome/browser/autocomplete/autocomplete_edit.h
index 9e94172..021c88d 100644
--- a/chrome/browser/autocomplete/autocomplete_edit.h
+++ b/chrome/browser/autocomplete/autocomplete_edit.h
@@ -73,6 +73,9 @@ class AutocompleteEditController {
// status of any keyword- or hint-related state.
virtual void OnChanged() = 0;
+ // Called when the selection of the AutocompleteEditView changes.
+ virtual void OnSelectionBoundsChanged() = 0;
+
// Called whenever the user starts or stops an input session (typing,
// interacting with the edit, etc.). When user input is not in progress,
// the edit is guaranteed to be showing the permanent text.
@@ -154,6 +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();
+
// 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
// input, if any, based on their control key state and any other actions
diff --git a/chrome/browser/autocomplete/autocomplete_edit_unittest.cc b/chrome/browser/autocomplete/autocomplete_edit_unittest.cc
index b0941ad..d2b93c5 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_unittest.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit_unittest.cc
@@ -33,6 +33,7 @@ class TestingAutocompleteEditView : public AutocompleteEditView {
bool update_popup) {}
virtual void SetWindowTextAndCaretPos(const std::wstring& text,
size_t caret_pos) {}
+ virtual void ReplaceSelection(const string16& text) {}
virtual void SetForcedQuery() {}
virtual bool IsSelectAll() { return false; }
virtual void GetSelectionBounds(std::wstring::size_type* start,
@@ -74,6 +75,7 @@ class TestingAutocompleteEditController : public AutocompleteEditController {
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() {}
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view.h b/chrome/browser/autocomplete/autocomplete_edit_view.h
index ce9a227..51224f8 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view.h
+++ b/chrome/browser/autocomplete/autocomplete_edit_view.h
@@ -14,6 +14,7 @@
#include <string>
+#include "base/string16.h"
#include "chrome/common/page_transition_types.h"
#include "gfx/native_widget_types.h"
#include "webkit/glue/window_open_disposition.h"
@@ -79,6 +80,9 @@ class AutocompleteEditView {
virtual void SetWindowTextAndCaretPos(const std::wstring& text,
size_t caret_pos) = 0;
+ // Replaces the selection with the specified text and selects it.
+ virtual void ReplaceSelection(const string16& text) = 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
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
index 8c627bf..9204f8f 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
@@ -545,6 +545,24 @@ void AutocompleteEditViewGtk::SetWindowTextAndCaretPos(const std::wstring& text,
SetTextAndSelectedRange(text, range);
}
+void AutocompleteEditViewGtk::ReplaceSelection(const string16& text) {
+ CharRange selection = GetSelection();
+ if (selection.selection_min() == selection.selection_max() &&
+ text.empty()) {
+ return;
+ }
+ std::wstring current_text(GetText());
+ std::wstring result = current_text.substr(0, selection.selection_min()) +
+ UTF16ToWide(text) + current_text.substr(selection.selection_max());
+ selection.cp_min = selection.selection_min();
+ selection.cp_max = UTF16ToWide(text).size() + selection.cp_min;
+ StartUpdatingHighlightedText();
+ OnBeforePossibleChange();
+ SetTextAndSelectedRange(result, selection);
+ OnAfterPossibleChange();
+ FinishUpdatingHighlightedText();
+}
+
void AutocompleteEditViewGtk::SetForcedQuery() {
const std::wstring current_text(GetText());
const size_t start = current_text.find_first_not_of(kWhitespaceWide);
@@ -1312,7 +1330,7 @@ void AutocompleteEditViewGtk::HandleInsertText(
enter_was_inserted_ = true;
const gchar* p = text;
- while(*p) {
+ while (*p) {
gunichar c = g_utf8_get_char(p);
const gchar* next = g_utf8_next_char(p);
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h
index b63c2f2..06ef3f4 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h
@@ -53,8 +53,9 @@ class AutocompleteEditViewGtk : public AutocompleteEditView,
CharRange() : cp_min(0), cp_max(0) { }
CharRange(int n, int x) : cp_min(n), cp_max(x) { }
- // Returns the start of the selection.
+ // Returns the start/end of the selection.
int selection_min() const { return std::min(cp_min, cp_max); }
+ int selection_max() const { return std::max(cp_min, cp_max); }
// Work in integers to match the gint GTK APIs.
int cp_min; // For a selection: Represents the start.
@@ -116,6 +117,8 @@ class AutocompleteEditViewGtk : public AutocompleteEditView,
virtual void SetWindowTextAndCaretPos(const std::wstring& text,
size_t caret_pos);
+ virtual void ReplaceSelection(const string16& text);
+
virtual void SetForcedQuery();
virtual bool IsSelectAll();
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_mac.h b/chrome/browser/autocomplete/autocomplete_edit_view_mac.h
index a474ce0..3bc3eff 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_mac.h
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_mac.h
@@ -57,6 +57,8 @@ class AutocompleteEditViewMac : public AutocompleteEditView,
virtual void SetWindowTextAndCaretPos(const std::wstring& text,
size_t caret_pos);
+ virtual void ReplaceSelection(const string16& text);
+
virtual void SetForcedQuery();
virtual bool IsSelectAll();
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm b/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm
index aa4b9a6..12aeeb8 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm
@@ -348,6 +348,10 @@ void AutocompleteEditViewMac::SetWindowTextAndCaretPos(const std::wstring& text,
SetTextAndSelectedRange(text, NSMakeRange(caret_pos, caret_pos));
}
+void AutocompleteEditViewMac::ReplaceSelection(const string16& text) {
+ NOTIMPLEMENTED();
+}
+
void AutocompleteEditViewMac::SetForcedQuery() {
// We need to do this first, else |SetSelectedRange()| won't work.
FocusLocation(true);
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_win.cc b/chrome/browser/autocomplete/autocomplete_edit_view_win.cc
index b76a2b5..75e96d5 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_win.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_win.cc
@@ -22,7 +22,6 @@
#include "app/win/drag_source.h"
#include "app/win/drop_target.h"
#include "app/win/iat_patch_function.h"
-#include "app/win/scoped_prop.h"
#include "base/auto_reset.h"
#include "base/basictypes.h"
#include "base/i18n/rtl.h"
@@ -439,10 +438,6 @@ AutocompleteEditViewWin::AutocompleteEditViewWin(
SendMessage(m_hWnd, EM_SETWORDBREAKPROC, 0,
reinterpret_cast<LPARAM>(&WordBreakProc));
- // Makes it EN_SELCHANGE is sent to our parent window and back to us by way of
- // ProcessWindowMessage.
- SetEventMask(ENM_SELCHANGE);
-
// Get the metrics for the font.
HDC dc = ::GetDC(NULL);
SelectObject(dc, font_.GetNativeFont());
@@ -473,9 +468,6 @@ AutocompleteEditViewWin::AutocompleteEditViewWin(
SetBackgroundColor(background_color_);
- message_handler_prop_.reset(
- views::ChildWindowMessageProcessor::Register(m_hWnd, this));
-
// By default RichEdit has a drop target. Revoke it so that we can install our
// own. Revoke takes care of deleting the existing one.
RevokeDragDrop(m_hWnd);
@@ -660,6 +652,20 @@ void AutocompleteEditViewWin::SetWindowTextAndCaretPos(const std::wstring& text,
PlaceCaretAt(caret_pos);
}
+void AutocompleteEditViewWin::ReplaceSelection(const string16& text) {
+ CHARRANGE selection;
+ GetSel(selection);
+ if (selection.cpMin == selection.cpMax && text.empty())
+ return;
+
+ const std::wstring w_text(UTF16ToWide(text));
+ ScopedFreeze freeze(this, GetTextObjectModel());
+ OnBeforePossibleChange();
+ ReplaceSel(w_text.c_str(), TRUE);
+ SetSelection(selection.cpMin, selection.cpMin + w_text.size());
+ OnAfterPossibleChange();
+}
+
void AutocompleteEditViewWin::SetForcedQuery() {
const std::wstring current_text(GetText());
const size_t start = current_text.find_first_not_of(kWhitespaceWide);
@@ -894,6 +900,9 @@ bool AutocompleteEditViewWin::OnAfterPossibleChange() {
const bool something_changed = model_->OnAfterPossibleChange(new_text,
selection_differs, text_differs, just_deleted_text, at_end_of_edit);
+ if (selection_differs)
+ controller_->OnSelectionBoundsChanged();
+
if (something_changed && text_differs)
TextChanged();
@@ -1064,19 +1073,6 @@ void AutocompleteEditViewWin::ExecuteCommand(int command_id) {
OnAfterPossibleChange();
}
-bool AutocompleteEditViewWin::ProcessMessage(UINT message,
- WPARAM w_param,
- LPARAM l_param,
- LRESULT* result) {
- if (message == WM_NOTIFY) {
- NMHDR* header = reinterpret_cast<NMHDR*>(l_param);
- if (header->code == EN_SELCHANGE) {
- // TODO(sky): wire this up.
- }
- }
- return false;
-}
-
// static
int CALLBACK AutocompleteEditViewWin::WordBreakProc(LPTSTR edit_text,
int current_pos,
@@ -1267,10 +1263,6 @@ void AutocompleteEditViewWin::OnCut() {
ReplaceSel(L"", true);
}
-void AutocompleteEditViewWin::OnDestroy() {
- message_handler_prop_.reset();
-}
-
LRESULT AutocompleteEditViewWin::OnGetObject(UINT uMsg,
WPARAM wparam,
LPARAM lparam) {
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_win.h b/chrome/browser/autocomplete/autocomplete_edit_view_win.h
index fdeaca6..fbe103f 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_win.h
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_win.h
@@ -23,7 +23,6 @@
#include "chrome/common/page_transition_types.h"
#include "gfx/font.h"
#include "views/controls/menu/menu_2.h"
-#include "views/widget/child_window_message_processor.h"
#include "webkit/glue/window_open_disposition.h"
class Profile;
@@ -32,12 +31,6 @@ namespace views {
class View;
}
-namespace app {
-namespace win {
-class ScopedProp;
-}
-}
-
class AutocompleteEditController;
class AutocompleteEditModel;
class AutocompleteEditView;
@@ -53,7 +46,6 @@ class AutocompleteEditViewWin
ES_NOHIDESEL> >,
public CRichEditCommands<AutocompleteEditViewWin>,
public menus::SimpleMenuModel::Delegate,
- public views::ChildWindowMessageProcessor,
public AutocompleteEditView {
public:
struct State {
@@ -122,6 +114,8 @@ class AutocompleteEditViewWin
virtual void SetWindowTextAndCaretPos(const std::wstring& text,
size_t caret_pos);
+ virtual void ReplaceSelection(const string16& text);
+
virtual void SetForcedQuery();
virtual bool IsSelectAll();
@@ -182,7 +176,6 @@ class AutocompleteEditViewWin
MSG_WM_CONTEXTMENU(OnContextMenu)
MSG_WM_COPY(OnCopy)
MSG_WM_CUT(OnCut)
- MSG_WM_DESTROY(OnDestroy)
MESSAGE_HANDLER_EX(WM_GETOBJECT, OnGetObject)
MESSAGE_HANDLER_EX(WM_IME_COMPOSITION, OnImeComposition)
MESSAGE_HANDLER_EX(WM_IME_NOTIFY, OnImeNotify)
@@ -221,11 +214,6 @@ class AutocompleteEditViewWin
virtual std::wstring GetLabelForCommandId(int command_id) const;
virtual void ExecuteCommand(int command_id);
- // views::ChildWindowMessageProcessor
- virtual bool ProcessMessage(UINT message,
- WPARAM w_param,
- LPARAM l_param,
- LRESULT* result);
private:
enum MouseButton {
kLeft = 0,
@@ -281,7 +269,6 @@ class AutocompleteEditViewWin
void OnContextMenu(HWND window, const CPoint& point);
void OnCopy();
void OnCut();
- void OnDestroy();
LRESULT OnGetObject(UINT uMsg, WPARAM wparam, LPARAM lparam);
LRESULT OnImeComposition(UINT message, WPARAM wparam, LPARAM lparam);
LRESULT OnImeNotify(UINT message, WPARAM wparam, LPARAM lparam);
@@ -534,9 +521,6 @@ class AutocompleteEditViewWin
// Instance of accessibility information and handling.
mutable ScopedComPtr<IAccessible> autocomplete_accessibility_;
- // ScopedProp returned from registering as a ChildWindowMessageProcessor.
- scoped_ptr<app::win::ScopedProp> message_handler_prop_;
-
DISALLOW_COPY_AND_ASSIGN(AutocompleteEditViewWin);
};