summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-21 03:43:45 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-21 03:43:45 +0000
commiteea372e5ae883c1a9853086e54b43896aa72df36 (patch)
treef8345aa56206a072496d69554f805fe189483011
parentb343f1c73ce201d34fe41037734f57f68dffe2f6 (diff)
downloadchromium_src-eea372e5ae883c1a9853086e54b43896aa72df36.zip
chromium_src-eea372e5ae883c1a9853086e54b43896aa72df36.tar.gz
chromium_src-eea372e5ae883c1a9853086e54b43896aa72df36.tar.bz2
Try to make TextField::Controller implementors cross-platform by abstracting
away the keystroke message that is passed. It turns out implementoars only ever check for enter and escape messages, so I wrote two functions in TextField that will decode the new Keyboard event. This design is not optimal. Ideally we would have something more like the WebInputEvent so that callers can check for anything in a cross-platform way. This was branched off from the original review: http://codereview.chromium.org/113639 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16577 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/input_window_dialog_win.cc11
-rw-r--r--chrome/browser/views/bookmark_editor_view.h5
-rw-r--r--chrome/browser/views/bookmark_manager_view.cc9
-rw-r--r--chrome/browser/views/bookmark_manager_view.h3
-rw-r--r--chrome/browser/views/bug_report_view.cc3
-rw-r--r--chrome/browser/views/bug_report_view.h3
-rw-r--r--chrome/browser/views/edit_keyword_controller.cc8
-rw-r--r--chrome/browser/views/edit_keyword_controller.h5
-rw-r--r--chrome/browser/views/find_bar_view.cc28
-rw-r--r--chrome/browser/views/find_bar_view.h4
-rw-r--r--chrome/browser/views/frame/browser_view.h1
-rw-r--r--chrome/browser/views/new_profile_dialog.h5
-rw-r--r--chrome/browser/views/options/cookies_view.cc17
-rw-r--r--chrome/browser/views/options/cookies_view.h3
-rw-r--r--chrome/browser/views/options/general_page_view.cc3
-rw-r--r--chrome/browser/views/options/general_page_view.h5
-rw-r--r--chrome/browser/views/shelf_item_dialog.h5
17 files changed, 53 insertions, 65 deletions
diff --git a/chrome/browser/input_window_dialog_win.cc b/chrome/browser/input_window_dialog_win.cc
index 2da360a..3f7b641 100644
--- a/chrome/browser/input_window_dialog_win.cc
+++ b/chrome/browser/input_window_dialog_win.cc
@@ -78,7 +78,8 @@ class ContentView : public views::View,
// views::TextField::Controller overrides:
virtual void ContentsChanged(views::TextField* sender,
const std::wstring& new_contents);
- virtual bool HandleKeystroke(views::TextField*, UINT, TCHAR, UINT, UINT) {
+ virtual bool HandleKeystroke(views::TextField*,
+ const views::TextField::Keystroke&) {
return false;
}
@@ -197,10 +198,10 @@ void ContentView::FocusFirstFocusableControl() {
}
WinInputWindowDialog::WinInputWindowDialog(HWND parent,
- const std::wstring& window_title,
- const std::wstring& label,
- const std::wstring& contents,
- Delegate* delegate)
+ const std::wstring& window_title,
+ const std::wstring& label,
+ const std::wstring& contents,
+ Delegate* delegate)
: window_title_(window_title),
label_(label),
contents_(contents),
diff --git a/chrome/browser/views/bookmark_editor_view.h b/chrome/browser/views/bookmark_editor_view.h
index 754e5f8..055b1a8 100644
--- a/chrome/browser/views/bookmark_editor_view.h
+++ b/chrome/browser/views/bookmark_editor_view.h
@@ -84,8 +84,9 @@ class BookmarkEditorView : public BookmarkEditor,
virtual void ContentsChanged(views::TextField* sender,
const std::wstring& new_contents);
virtual bool HandleKeystroke(views::TextField* sender,
- UINT message, TCHAR key, UINT repeat_count,
- UINT flags) { return false; }
+ const views::TextField::Keystroke&) {
+ return false;
+ }
// NativeButton.
virtual void ButtonPressed(views::Button* sender);
diff --git a/chrome/browser/views/bookmark_manager_view.cc b/chrome/browser/views/bookmark_manager_view.cc
index 8a0b019..25cddc0 100644
--- a/chrome/browser/views/bookmark_manager_view.cc
+++ b/chrome/browser/views/bookmark_manager_view.cc
@@ -455,11 +455,10 @@ void BookmarkManagerView::ContentsChanged(views::TextField* sender,
kSearchDelayMS);
}
-bool BookmarkManagerView::HandleKeystroke(views::TextField* sender,
- UINT message, TCHAR key,
- UINT repeat_count,
- UINT flags) {
- if (key == VK_RETURN) {
+bool BookmarkManagerView::HandleKeystroke(
+ views::TextField* sender,
+ const views::TextField::Keystroke& key) {
+ if (views::TextField::IsKeystrokeEnter(key)) {
PerformSearch();
search_tf_->SelectAll();
}
diff --git a/chrome/browser/views/bookmark_manager_view.h b/chrome/browser/views/bookmark_manager_view.h
index 9c17571..3c73375 100644
--- a/chrome/browser/views/bookmark_manager_view.h
+++ b/chrome/browser/views/bookmark_manager_view.h
@@ -137,8 +137,7 @@ class BookmarkManagerView : public views::View,
const std::wstring& new_contents);
// If return has been pressed this performs an immediate search.
virtual bool HandleKeystroke(views::TextField* sender,
- UINT message, TCHAR key, UINT repeat_count,
- UINT flags);
+ const views::TextField::Keystroke& key);
// ContextMenuController.
virtual void ShowContextMenu(views::View* source,
diff --git a/chrome/browser/views/bug_report_view.cc b/chrome/browser/views/bug_report_view.cc
index 3af66f4..e4bdd7d 100644
--- a/chrome/browser/views/bug_report_view.cc
+++ b/chrome/browser/views/bug_report_view.cc
@@ -261,8 +261,7 @@ void BugReportView::ContentsChanged(views::TextField* sender,
}
bool BugReportView::HandleKeystroke(views::TextField* sender,
- UINT message, TCHAR key,
- UINT repeat_count, UINT flags) {
+ const views::TextField::Keystroke& key) {
return false;
}
diff --git a/chrome/browser/views/bug_report_view.h b/chrome/browser/views/bug_report_view.h
index 0688a1dc..9edf1f0 100644
--- a/chrome/browser/views/bug_report_view.h
+++ b/chrome/browser/views/bug_report_view.h
@@ -53,8 +53,7 @@ class BugReportView : public views::View,
virtual void ContentsChanged(views::TextField* sender,
const std::wstring& new_contents);
virtual bool HandleKeystroke(views::TextField* sender,
- UINT message, TCHAR key,
- UINT repeat_count, UINT flags);
+ const views::TextField::Keystroke& key);
// views::ComboBox::Listener implementation:
virtual void ItemChanged(views::ComboBox* combo_box, int prev_index,
diff --git a/chrome/browser/views/edit_keyword_controller.cc b/chrome/browser/views/edit_keyword_controller.cc
index 2774379..78434e5 100644
--- a/chrome/browser/views/edit_keyword_controller.cc
+++ b/chrome/browser/views/edit_keyword_controller.cc
@@ -158,11 +158,9 @@ void EditKeywordController::ContentsChanged(TextField* sender,
UpdateImageViews();
}
-bool EditKeywordController::HandleKeystroke(TextField* sender,
- UINT message,
- TCHAR key,
- UINT repeat_count,
- UINT flags) {
+bool EditKeywordController::HandleKeystroke(
+ TextField* sender,
+ const views::TextField::Keystroke& key) {
return false;
}
diff --git a/chrome/browser/views/edit_keyword_controller.h b/chrome/browser/views/edit_keyword_controller.h
index 36e9370..baf7efd 100644
--- a/chrome/browser/views/edit_keyword_controller.h
+++ b/chrome/browser/views/edit_keyword_controller.h
@@ -57,10 +57,7 @@ class EditKeywordController : public views::TextField::Controller,
virtual void ContentsChanged(views::TextField* sender,
const std::wstring& new_contents);
virtual bool HandleKeystroke(views::TextField* sender,
- UINT message,
- TCHAR key,
- UINT repeat_count,
- UINT flags);
+ const views::TextField::Keystroke& key);
private:
void Init();
diff --git a/chrome/browser/views/find_bar_view.cc b/chrome/browser/views/find_bar_view.cc
index ededa28..063ea63 100644
--- a/chrome/browser/views/find_bar_view.cc
+++ b/chrome/browser/views/find_bar_view.cc
@@ -456,31 +456,29 @@ void FindBarView::ContentsChanged(views::TextField* sender,
}
}
-bool FindBarView::HandleKeystroke(views::TextField* sender, UINT message,
- TCHAR key, UINT repeat_count, UINT flags) {
+bool FindBarView::HandleKeystroke(views::TextField* sender,
+ const views::TextField::Keystroke& key) {
// If the dialog is not visible, there is no reason to process keyboard input.
if (!container_->IsVisible())
return false;
// TODO(port): Handle this for other platforms.
#if defined(OS_WIN)
- if (container_->MaybeForwardKeystrokeToWebpage(message, key, flags))
+ if (container_->MaybeForwardKeystrokeToWebpage(key.message, key.key,
+ key.flags))
return true; // Handled, we are done!
- #endif
- switch (key) {
- case VK_RETURN: {
- // Pressing Return/Enter starts the search (unless text box is empty).
- std::wstring find_string = find_text_->GetText();
- if (!find_string.empty()) {
- // Search forwards for enter, backwards for shift-enter.
- container_->GetFindBarController()->tab_contents()->StartFinding(
- find_string,
- GetKeyState(VK_SHIFT) >= 0);
- }
- break;
+ if (views::TextField::IsKeystrokeEnter(key)) {
+ // Pressing Return/Enter starts the search (unless text box is empty).
+ std::wstring find_string = find_text_->GetText();
+ if (!find_string.empty()) {
+ // Search forwards for enter, backwards for shift-enter.
+ container_->GetFindBarController()->tab_contents()->StartFinding(
+ find_string,
+ GetKeyState(VK_SHIFT) >= 0);
}
}
+ #endif
return false;
}
diff --git a/chrome/browser/views/find_bar_view.h b/chrome/browser/views/find_bar_view.h
index e56af0e..00ba8fe1 100644
--- a/chrome/browser/views/find_bar_view.h
+++ b/chrome/browser/views/find_bar_view.h
@@ -67,8 +67,8 @@ class FindBarView : public views::View,
// Overridden from views::TextField::Controller:
virtual void ContentsChanged(views::TextField* sender,
const std::wstring& new_contents);
- virtual bool HandleKeystroke(views::TextField* sender, UINT message,
- TCHAR key, UINT repeat_count, UINT flags);
+ virtual bool HandleKeystroke(views::TextField* sender,
+ const views::TextField::Keystroke& key);
// Set whether or not we're attempting to blend with the toolbar.
void set_toolbar_blend(bool toolbar_blend) { toolbar_blend_ = toolbar_blend; }
diff --git a/chrome/browser/views/frame/browser_view.h b/chrome/browser/views/frame/browser_view.h
index fcb7b4d..e1f71f6 100644
--- a/chrome/browser/views/frame/browser_view.h
+++ b/chrome/browser/views/frame/browser_view.h
@@ -7,6 +7,7 @@
#include <set>
+#include "build/build_config.h"
#include "chrome/browser/browser.h"
#include "chrome/browser/browser_window.h"
#include "chrome/browser/tabs/tab_strip_model.h"
diff --git a/chrome/browser/views/new_profile_dialog.h b/chrome/browser/views/new_profile_dialog.h
index 863b2ad..a06729d 100644
--- a/chrome/browser/views/new_profile_dialog.h
+++ b/chrome/browser/views/new_profile_dialog.h
@@ -40,8 +40,9 @@ class NewProfileDialog : public views::DialogDelegate,
virtual void ContentsChanged(views::TextField* sender,
const std::wstring& new_contents);
virtual bool HandleKeystroke(views::TextField* sender,
- UINT message, TCHAR key, UINT repeat_count,
- UINT flags) { return false; }
+ const views::TextField::Keystroke& key) {
+ return false;
+ }
// views::WindowDelegate methods.
virtual views::View* GetContentsView();
diff --git a/chrome/browser/views/options/cookies_view.cc b/chrome/browser/views/options/cookies_view.cc
index f937c6d..ac5e495 100644
--- a/chrome/browser/views/options/cookies_view.cc
+++ b/chrome/browser/views/options/cookies_view.cc
@@ -620,16 +620,13 @@ void CookiesView::ContentsChanged(views::TextField* sender,
&CookiesView::UpdateSearchResults), kSearchFilterDelayMs);
}
-bool CookiesView::HandleKeystroke(views::TextField* sender, UINT message,
- TCHAR key, UINT repeat_count, UINT flags) {
- switch (key) {
- case VK_ESCAPE:
- ResetSearchQuery();
- break;
- case VK_RETURN:
- search_update_factory_.RevokeAll();
- UpdateSearchResults();
- break;
+bool CookiesView::HandleKeystroke(views::TextField* sender,
+ const views::TextField::Keystroke& key) {
+ if (views::TextField::IsKeystrokeEscape(key)) {
+ ResetSearchQuery();
+ } else if (views::TextField::IsKeystrokeEnter(key)) {
+ search_update_factory_.RevokeAll();
+ UpdateSearchResults();
}
return false;
}
diff --git a/chrome/browser/views/options/cookies_view.h b/chrome/browser/views/options/cookies_view.h
index f2bc98a..7de565d 100644
--- a/chrome/browser/views/options/cookies_view.h
+++ b/chrome/browser/views/options/cookies_view.h
@@ -51,8 +51,7 @@ class CookiesView : public views::View,
virtual void ContentsChanged(views::TextField* sender,
const std::wstring& new_contents);
virtual bool HandleKeystroke(views::TextField* sender,
- UINT message, TCHAR key, UINT repeat_count,
- UINT flags);
+ const views::TextField::Keystroke& key);
// views::WindowDelegate implementation:
virtual int GetDialogButtons() const {
diff --git a/chrome/browser/views/options/general_page_view.cc b/chrome/browser/views/options/general_page_view.cc
index 7c54d5c..35af571 100644
--- a/chrome/browser/views/options/general_page_view.cc
+++ b/chrome/browser/views/options/general_page_view.cc
@@ -619,8 +619,7 @@ void GeneralPageView::ContentsChanged(views::TextField* sender,
}
bool GeneralPageView::HandleKeystroke(views::TextField* sender,
- UINT message, TCHAR key,
- UINT repeat_count, UINT flags) {
+ const views::TextField::Keystroke&) {
return false;
}
diff --git a/chrome/browser/views/options/general_page_view.h b/chrome/browser/views/options/general_page_view.h
index 800cd04..1e2d72f 100644
--- a/chrome/browser/views/options/general_page_view.h
+++ b/chrome/browser/views/options/general_page_view.h
@@ -50,10 +50,9 @@ class GeneralPageView : public OptionsPageView,
// views::TextField::Controller implementation:
virtual void ContentsChanged(views::TextField* sender,
- const std::wstring& new_contents);
+ const std::wstring& new_contents);
virtual bool HandleKeystroke(views::TextField* sender,
- UINT message, TCHAR key, UINT repeat_count,
- UINT flags);
+ const views::TextField::Keystroke& key);
// OptionsPageView implementation:
virtual void InitControlLayout();
diff --git a/chrome/browser/views/shelf_item_dialog.h b/chrome/browser/views/shelf_item_dialog.h
index 5e49625..9ac740d 100644
--- a/chrome/browser/views/shelf_item_dialog.h
+++ b/chrome/browser/views/shelf_item_dialog.h
@@ -69,8 +69,9 @@ class ShelfItemDialog : public views::View,
virtual void ContentsChanged(views::TextField* sender,
const std::wstring& new_contents);
virtual bool HandleKeystroke(views::TextField* sender,
- UINT message, TCHAR key, UINT repeat_count,
- UINT flags) { return false; }
+ const views::TextField::Keystroke& key) {
+ return false;
+ }
// Overridden from View.
virtual gfx::Size GetPreferredSize();