Skip to content

Commit

Permalink
Replace Textfield::Keystroke with views::KeyEvent.
Browse files Browse the repository at this point in the history
It looks big, but most of change is simple signature change.

 Note: I need your advice on how to deal with WM_CHAR event on Win. Please see my comment below.

BUG=none
TEST=no new functionality. All tests should still pass.

Review URL: http://codereview.chromium.org/6034002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@70553 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
oshima@chromium.org committed Jan 5, 2011
1 parent 7083326 commit 7110c89
Show file tree
Hide file tree
Showing 44 changed files with 156 additions and 187 deletions.
6 changes: 3 additions & 3 deletions chrome/browser/chromeos/login/captcha_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ void CaptchaView::ViewHierarchyChanged(bool is_add,
captcha_textfield_->RequestFocus();
}

bool CaptchaView::HandleKeystroke(views::Textfield* sender,
const views::Textfield::Keystroke& keystroke) {
bool CaptchaView::HandleKeyEvent(views::Textfield* sender,
const views::KeyEvent& key_event) {
if (sender == captcha_textfield_ &&
keystroke.GetKeyboardCode() == app::VKEY_RETURN) {
key_event.GetKeyCode() == app::VKEY_RETURN) {
if (is_standalone_) {
Accept();
} else {
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/chromeos/login/captcha_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ class CaptchaView : public views::View,
// views::Textfield::Controller implementation:
virtual void ContentsChanged(views::Textfield* sender,
const string16& new_contents) {}
virtual bool HandleKeystroke(views::Textfield* sender,
const views::Textfield::Keystroke& keystroke);
virtual bool HandleKeyEvent(views::Textfield* sender,
const views::KeyEvent& key_event);

// Overriden from ImageDownloader::Delegate:
virtual void OnImageDecoded(const SkBitmap& decoded_image);
Expand Down
7 changes: 3 additions & 4 deletions chrome/browser/chromeos/login/existing_user_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,9 @@ bool ExistingUserView::AcceleratorPressed(
return false;
}

bool ExistingUserView::HandleKeystroke(
views::Textfield* sender,
const views::Textfield::Keystroke& keystroke) {
if (keystroke.GetKeyboardCode() == app::VKEY_RETURN) {
bool ExistingUserView::HandleKeyEvent(views::Textfield* sender,
const views::KeyEvent& key_event) {
if (key_event.GetKeyCode() == app::VKEY_RETURN) {
if (!password_field_->text().empty())
user_controller_->OnLogin("", UTF16ToUTF8(password_field_->text()));
} else {
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/chromeos/login/existing_user_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class ExistingUserView : public ThrobberHostView,
// Overriden from Textfield::Controller:
virtual void ContentsChanged(views::Textfield* sender,
const string16& new_contents);
virtual bool HandleKeystroke(views::Textfield* sender,
const views::Textfield::Keystroke& keystroke);
virtual bool HandleKeyEvent(views::Textfield* sender,
const views::KeyEvent& keystroke);

// Overriden from UserInput:
virtual void EnableInputControls(bool enabled);
Expand Down
6 changes: 3 additions & 3 deletions chrome/browser/chromeos/login/new_user_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -522,12 +522,12 @@ gfx::Rect NewUserView::GetUsernameBounds() const {
return username_field_->GetScreenBounds();
}

bool NewUserView::HandleKeystroke(views::Textfield* s,
const views::Textfield::Keystroke& keystroke) {
bool NewUserView::HandleKeyEvent(views::Textfield* sender,
const views::KeyEvent& key_event) {
if (!CrosLibrary::Get()->EnsureLoaded() || login_in_process_)
return false;

if (keystroke.GetKeyboardCode() == app::VKEY_RETURN) {
if (key_event.GetKeyCode() == app::VKEY_RETURN) {
if (!username_field_->text().empty() && !password_field_->text().empty())
Login();
// Return true so that processing ends
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/chromeos/login/new_user_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ class NewUserView : public ThrobberHostView,

// Overridden from views::Textfield::Controller
// Not thread-safe, by virtue of using SetupSession().
virtual bool HandleKeystroke(views::Textfield* sender,
const views::Textfield::Keystroke& keystroke);
virtual bool HandleKeyEvent(views::Textfield* sender,
const views::KeyEvent& keystroke);
virtual void ContentsChanged(views::Textfield* sender,
const string16& new_contents);

Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/chromeos/login/password_changed_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ class PasswordChangedView : public views::View,
const views::Event& event);

// views::Textfield::Controller overrides:
virtual bool HandleKeystroke(views::Textfield* sender,
const views::Textfield::Keystroke& keystroke) {
virtual bool HandleKeyEvent(views::Textfield* sender,
const views::KeyEvent& keystroke) {
return false;
}
virtual void ContentsChanged(views::Textfield* sender,
Expand Down
6 changes: 3 additions & 3 deletions chrome/browser/chromeos/login/screen_lock_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,11 @@ void ScreenLockView::OnSignout() {
screen_locker_->Signout();
}

bool ScreenLockView::HandleKeystroke(
bool ScreenLockView::HandleKeyEvent(
views::Textfield* sender,
const views::Textfield::Keystroke& keystroke) {
const views::KeyEvent& key_event) {
screen_locker_->ClearErrors();
if (keystroke.GetKeyboardCode() == app::VKEY_RETURN) {
if (key_event.GetKeyCode() == app::VKEY_RETURN) {
screen_locker_->Authenticate(password_field_->text());
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/chromeos/login/screen_lock_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ class ScreenLockView : public ThrobberHostView,
// views::Textfield::Controller implementation:
virtual void ContentsChanged(views::Textfield* sender,
const string16& new_contents) {}
virtual bool HandleKeystroke(views::Textfield* sender,
const views::Textfield::Keystroke& keystroke);
virtual bool HandleKeyEvent(views::Textfield* sender,
const views::KeyEvent& keystroke);

// UserView::Delegate implementation:
virtual void OnSignout();
Expand Down
5 changes: 2 additions & 3 deletions chrome/browser/chromeos/login/screen_locker_tester.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ void ScreenLockerTester::EnterPassword(const char* password) {

event->key.keyval = GDK_Return;
views::KeyEvent key_event(&event->key);
views::Textfield::Keystroke ret(&key_event);
ScreenLocker::screen_locker_->screen_lock_view_->HandleKeystroke(pass, ret);

ScreenLocker::screen_locker_->screen_lock_view_->HandleKeyEvent(
pass, key_event);
gdk_event_free(event);
}

Expand Down
7 changes: 3 additions & 4 deletions chrome/browser/chromeos/options/wifi_config_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,10 @@ void WifiConfigView::ContentsChanged(views::Textfield* sender,
UpdateCanLogin();
}

bool WifiConfigView::HandleKeystroke(
views::Textfield* sender,
const views::Textfield::Keystroke& keystroke) {
bool WifiConfigView::HandleKeyEvent(views::Textfield* sender,
const views::KeyEvent& key_event) {
if (sender == passphrase_textfield_ &&
keystroke.GetKeyboardCode() == app::VKEY_RETURN) {
key_event.GetKeyCode() == app::VKEY_RETURN) {
parent_->GetDialogClientView()->AcceptWindow();
}
return false;
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/chromeos/options/wifi_config_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class WifiConfigView : public views::View,
// views::Textfield::Controller methods.
virtual void ContentsChanged(views::Textfield* sender,
const string16& new_contents);
virtual bool HandleKeystroke(views::Textfield* sender,
const views::Textfield::Keystroke& keystroke);
virtual bool HandleKeyEvent(views::Textfield* sender,
const views::KeyEvent& key_event);

// views::ButtonListener
virtual void ButtonPressed(views::Button* sender, const views::Event& event);
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/ui/input_window_dialog_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,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*,
const views::Textfield::Keystroke&) {
virtual bool HandleKeyEvent(views::Textfield*,
const views::KeyEvent&) {
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/ui/views/autofill_profiles_view_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -873,8 +873,8 @@ void AutoFillProfilesView::EditableSetViewContents::ContentsChanged(
}
}

bool AutoFillProfilesView::EditableSetViewContents::HandleKeystroke(
views::Textfield* sender, const views::Textfield::Keystroke& keystroke) {
bool AutoFillProfilesView::EditableSetViewContents::HandleKeyEvent(
views::Textfield* sender, const views::KeyEvent& key_event) {
if (sender == text_fields_[TEXT_CC_NUMBER] &&
!has_credit_card_number_been_edited_) {
// You cannot edit obfuscated number, you must retype it anew.
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/ui/views/autofill_profiles_view_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,8 @@ class AutoFillProfilesView : public views::View,
// views::Textfield::Controller methods:
virtual void ContentsChanged(views::Textfield* sender,
const string16& new_contents);
virtual bool HandleKeystroke(views::Textfield* sender,
const views::Textfield::Keystroke& keystroke);
virtual bool HandleKeyEvent(views::Textfield* sender,
const views::KeyEvent& keystroke);

// views::Combobox::Listener methods:
virtual void ItemChanged(views::Combobox* combo_box,
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/ui/views/bookmark_editor_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ class BookmarkEditorView : public BookmarkEditor,
// Textfield::Controller methods.
virtual void ContentsChanged(views::Textfield* sender,
const std::wstring& new_contents);
virtual bool HandleKeystroke(views::Textfield* sender,
const views::Textfield::Keystroke&) {
virtual bool HandleKeyEvent(views::Textfield* sender,
const views::KeyEvent& key_event) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/ui/views/dropdown_bar_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class DropdownBarHost : public views::AcceleratorTarget,
// Returns a keyboard event suitable for forwarding.
NativeWebKeyboardEvent GetKeyboardEvent(
const TabContents* contents,
const views::Textfield::Keystroke& key_stroke);
const views::KeyEvent& key_event);

// Returns the animation for the dropdown.
SlideAnimation* animation() {
Expand Down
11 changes: 5 additions & 6 deletions chrome/browser/ui/views/dropdown_bar_host_gtk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,22 @@ void DropdownBarHost::SetWidgetPositionNative(const gfx::Rect& new_pos,

NativeWebKeyboardEvent DropdownBarHost::GetKeyboardEvent(
const TabContents* contents,
const views::Textfield::Keystroke& key_stroke) {
const views::KeyEvent& key_event) {
#if defined(TOUCH_UI)
// TODO(oshima): This is a copy from
// RenderWidgetHostViewViews::OnKeyPressed().
// Refactor and eliminate the dup code.
const views::KeyEvent& e = key_stroke.key_event();
NativeWebKeyboardEvent wke;
wke.type = WebKit::WebInputEvent::KeyDown;
wke.windowsKeyCode = e.GetKeyCode();
wke.windowsKeyCode = key_event.GetKeyCode();
wke.setKeyIdentifierFromWindowsKeyCode();

wke.text[0] = wke.unmodifiedText[0] =
static_cast<unsigned short>(gdk_keyval_to_unicode(
app::GdkKeyCodeForWindowsKeyCode(e.GetKeyCode(),
e.IsShiftDown() ^ e.IsCapsLockDown())));
app::GdkKeyCodeForWindowsKeyCode(key_event.GetKeyCode(),
key_event.IsShiftDown() ^ key_event.IsCapsLockDown())));
return wke;
#else
return NativeWebKeyboardEvent(key_stroke.event());
return NativeWebKeyboardEvent(key_event.native_event());
#endif
}
8 changes: 5 additions & 3 deletions chrome/browser/ui/views/dropdown_bar_host_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "chrome/browser/views/dropdown_bar_host.h"

#include "app/keyboard_code_conversion_win.h"
#include "chrome/browser/renderer_host/render_view_host.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/tab_contents/tab_contents_view.h"
Expand All @@ -14,10 +15,11 @@

NativeWebKeyboardEvent DropdownBarHost::GetKeyboardEvent(
const TabContents* contents,
const views::Textfield::Keystroke& key_stroke) {
const views::KeyEvent& key_event) {
HWND hwnd = contents->GetContentNativeView();
return NativeWebKeyboardEvent(
hwnd, key_stroke.message(), key_stroke.key(), 0);
WORD key = WindowsKeyCodeForKeyboardCode(key_event.GetKeyCode());

return NativeWebKeyboardEvent(hwnd, key_event.message(), key, 0);
}

views::Widget* DropdownBarHost::CreateHost() {
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/ui/views/edit_search_engine_dialog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ void EditSearchEngineDialog::ContentsChanged(Textfield* sender,
UpdateImageViews();
}

bool EditSearchEngineDialog::HandleKeystroke(
bool EditSearchEngineDialog::HandleKeyEvent(
Textfield* sender,
const views::Textfield::Keystroke& key) {
const views::KeyEvent& key_event) {
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/ui/views/edit_search_engine_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ class EditSearchEngineDialog : public views::View,
// valid.
virtual void ContentsChanged(views::Textfield* sender,
const std::wstring& new_contents);
virtual bool HandleKeystroke(views::Textfield* sender,
const views::Textfield::Keystroke& key);
virtual bool HandleKeyEvent(views::Textfield* sender,
const views::KeyEvent& key_event);

private:
void Init();
Expand Down
12 changes: 6 additions & 6 deletions chrome/browser/ui/views/find_bar_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,22 @@ FindBarHost::FindBarHost(BrowserView* browser_view)
FindBarHost::~FindBarHost() {
}

bool FindBarHost::MaybeForwardKeystrokeToWebpage(
const views::Textfield::Keystroke& key_stroke) {
if (!ShouldForwardKeystrokeToWebpageNative(key_stroke)) {
bool FindBarHost::MaybeForwardKeyEventToWebpage(
const views::KeyEvent& key_event) {
if (!ShouldForwardKeyEventToWebpageNative(key_event)) {
// Native implementation says not to forward these events.
return false;
}

switch (key_stroke.GetKeyboardCode()) {
switch (key_event.GetKeyCode()) {
case app::VKEY_DOWN:
case app::VKEY_UP:
case app::VKEY_PRIOR:
case app::VKEY_NEXT:
break;
case app::VKEY_HOME:
case app::VKEY_END:
if (key_stroke.IsControlHeld())
if (key_event.IsControlDown())
break;
// Fall through.
default:
Expand All @@ -70,7 +70,7 @@ bool FindBarHost::MaybeForwardKeystrokeToWebpage(
// Make sure we don't have a text field element interfering with keyboard
// input. Otherwise Up and Down arrow key strokes get eaten. "Nom Nom Nom".
render_view_host->ClearFocusedNode();
NativeWebKeyboardEvent event = GetKeyboardEvent(contents, key_stroke);
NativeWebKeyboardEvent event = GetKeyboardEvent(contents, key_event);
render_view_host->ForwardKeyboardEvent(event);
return true;
}
Expand Down
11 changes: 5 additions & 6 deletions chrome/browser/ui/views/find_bar_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,11 @@ class FindBarHost : public DropdownBarHost,
explicit FindBarHost(BrowserView* browser_view);
virtual ~FindBarHost();

// Forwards selected keystrokes to the renderer. This is useful to make sure
// Forwards selected key events to the renderer. This is useful to make sure
// that arrow keys and PageUp and PageDown result in scrolling, instead of
// being eaten because the FindBar has focus. Returns true if the keystroke
// was forwarded, false if not.
bool MaybeForwardKeystrokeToWebpage(
const views::Textfield::Keystroke& key_stroke);
bool MaybeForwardKeyEventToWebpage(const views::KeyEvent& key_event);

// FindBar implementation:
virtual FindBarController* GetFindBarController() const;
Expand Down Expand Up @@ -116,9 +115,9 @@ class FindBarHost : public DropdownBarHost,
// Allows implementation to tweak widget position.
void GetWidgetPositionNative(gfx::Rect* avoid_overlapping_rect);

// Allows native implementation to prevent keystrokes from being forwarded.
bool ShouldForwardKeystrokeToWebpageNative(
const views::Textfield::Keystroke& key_stroke);
// Allows native implementation to prevent key events from being forwarded.
bool ShouldForwardKeyEventToWebpageNative(
const views::KeyEvent& key_event);

// Returns the FindBarView.
FindBarView* find_bar_view();
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/ui/views/find_bar_host_gtk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void FindBarHost::GetWidgetPositionNative(gfx::Rect* avoid_overlapping_rect) {
avoid_overlapping_rect->Offset(0, webcontents_rect.y() - frame_rect.y());
}

bool FindBarHost::ShouldForwardKeystrokeToWebpageNative(
const views::Textfield::Keystroke& key_stroke) {
bool FindBarHost::ShouldForwardKeyEventToWebpageNative(
const views::KeyEvent& key_event) {
return true;
}
6 changes: 3 additions & 3 deletions chrome/browser/ui/views/find_bar_host_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ void FindBarHost::GetWidgetPositionNative(gfx::Rect* avoid_overlapping_rect) {
avoid_overlapping_rect->Offset(0, webcontents_rect.top - frame_rect.top);
}

bool FindBarHost::ShouldForwardKeystrokeToWebpageNative(
const views::Textfield::Keystroke& key_stroke) {
bool FindBarHost::ShouldForwardKeyEventToWebpageNative(
const views::KeyEvent& key_event) {
// We specifically ignore WM_CHAR. See http://crbug.com/10509.
return key_stroke.message() == WM_KEYDOWN || key_stroke.message() == WM_KEYUP;
return key_event.message() == WM_KEYDOWN || key_event.message() == WM_KEYUP;
}
10 changes: 5 additions & 5 deletions chrome/browser/ui/views/find_bar_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -503,23 +503,23 @@ void FindBarView::ContentsChanged(views::Textfield* sender,
}
}

bool FindBarView::HandleKeystroke(views::Textfield* sender,
const views::Textfield::Keystroke& key) {
bool FindBarView::HandleKeyEvent(views::Textfield* sender,
const views::KeyEvent& key_event) {
// If the dialog is not visible, there is no reason to process keyboard input.
if (!host()->IsVisible())
return false;

if (find_bar_host()->MaybeForwardKeystrokeToWebpage(key))
if (find_bar_host()->MaybeForwardKeyEventToWebpage(key_event))
return true; // Handled, we are done!

if (key.GetKeyboardCode() == app::VKEY_RETURN) {
if (key_event.GetKeyCode() == app::VKEY_RETURN) {
// Pressing Return/Enter starts the search (unless text box is empty).
string16 find_string = find_text_->text();
if (!find_string.empty()) {
// Search forwards for enter, backwards for shift-enter.
find_bar_host()->GetFindBarController()->tab_contents()->StartFinding(
find_string,
!key.IsShiftHeld(),
!key_event.IsShiftDown(),
false); // Not case sensitive.
}
}
Expand Down
Loading

0 comments on commit 7110c89

Please sign in to comment.