diff options
author | saintlou@chromium.org <saintlou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-05 21:16:24 +0000 |
---|---|---|
committer | saintlou@chromium.org <saintlou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-05 21:16:24 +0000 |
commit | 6cf30ba0b41b9f0abd19fd82789e127ff3fd81fe (patch) | |
tree | 710824bb97c75b7064bbc8b74154a864ab43212f /views | |
parent | 8b0a7b0ab95dc4c25ba143560df45cefd0fc0d73 (diff) | |
download | chromium_src-6cf30ba0b41b9f0abd19fd82789e127ff3fd81fe.zip chromium_src-6cf30ba0b41b9f0abd19fd82789e127ff3fd81fe.tar.gz chromium_src-6cf30ba0b41b9f0abd19fd82789e127ff3fd81fe.tar.bz2 |
Added Key event forwarding and handlking (not yet tested for GTK or Windows)
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/6931033
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@84314 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r-- | views/controls/combobox/combobox.cc | 27 | ||||
-rw-r--r-- | views/controls/combobox/combobox.h | 5 | ||||
-rw-r--r-- | views/controls/combobox/native_combobox_gtk.cc | 14 | ||||
-rw-r--r-- | views/controls/combobox/native_combobox_gtk.h | 28 | ||||
-rw-r--r-- | views/controls/combobox/native_combobox_views.cc | 79 | ||||
-rw-r--r-- | views/controls/combobox/native_combobox_views.h | 12 | ||||
-rw-r--r-- | views/controls/combobox/native_combobox_win.cc | 14 | ||||
-rw-r--r-- | views/controls/combobox/native_combobox_win.h | 30 | ||||
-rw-r--r-- | views/controls/combobox/native_combobox_wrapper.h | 15 |
9 files changed, 175 insertions, 49 deletions
diff --git a/views/controls/combobox/combobox.cc b/views/controls/combobox/combobox.cc index e7c1700..fefa36a 100644 --- a/views/controls/combobox/combobox.cc +++ b/views/controls/combobox/combobox.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -99,12 +99,12 @@ void Combobox::OnPaintFocusBorder(gfx::Canvas* canvas) { View::OnPaintFocusBorder(canvas); } -void Combobox::GetAccessibleState(ui::AccessibleViewState* state) { - state->role = ui::AccessibilityTypes::ROLE_COMBOBOX; - state->name = accessible_name_; - state->value = model_->GetItemAt(selected_item_); - state->index = selected_item(); - state->count = model()->GetItemCount(); +bool Combobox::OnKeyPressed(const views::KeyEvent& e) { + return native_wrapper_ && native_wrapper_->HandleKeyPressed(e); +} + +bool Combobox::OnKeyReleased(const views::KeyEvent& e) { + return native_wrapper_ && native_wrapper_->HandleKeyReleased(e); } void Combobox::OnFocus() { @@ -116,6 +116,19 @@ void Combobox::OnFocus() { // keyboard messages). } +void Combobox::OnBlur() { + if (native_wrapper_) + native_wrapper_->HandleBlur(); +} + +void Combobox::GetAccessibleState(ui::AccessibleViewState* state) { + state->role = ui::AccessibilityTypes::ROLE_COMBOBOX; + state->name = accessible_name_; + state->value = model_->GetItemAt(selected_item_); + state->index = selected_item(); + state->count = model()->GetItemCount(); +} + void Combobox::ViewHierarchyChanged(bool is_add, View* parent, View* child) { if (is_add && !native_wrapper_ && GetWidget()) { diff --git a/views/controls/combobox/combobox.h b/views/controls/combobox/combobox.h index 693eb4f..222d202 100644 --- a/views/controls/combobox/combobox.h +++ b/views/controls/combobox/combobox.h @@ -67,11 +67,14 @@ class Combobox : public View { virtual void SetEnabled(bool enabled) OVERRIDE; virtual bool SkipDefaultKeyEventProcessing(const KeyEvent& e) OVERRIDE; virtual void OnPaintFocusBorder(gfx::Canvas* canvas) OVERRIDE; + virtual bool OnKeyPressed(const views::KeyEvent& e) OVERRIDE; + virtual bool OnKeyReleased(const views::KeyEvent& e) OVERRIDE; + virtual void OnFocus() OVERRIDE; + virtual void OnBlur() OVERRIDE; virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; protected: // Overridden from View: - virtual void OnFocus() OVERRIDE; virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child) OVERRIDE; virtual std::string GetClassName() const OVERRIDE; diff --git a/views/controls/combobox/native_combobox_gtk.cc b/views/controls/combobox/native_combobox_gtk.cc index 01b9762..2706e69 100644 --- a/views/controls/combobox/native_combobox_gtk.cc +++ b/views/controls/combobox/native_combobox_gtk.cc @@ -101,6 +101,20 @@ void NativeComboboxGtk::SetFocus() { OnFocus(); } +bool NativeComboboxGtk::HandleKeyPressed(const views::KeyEvent& event) { + return false; +} + +bool NativeComboboxGtk::HandleKeyReleased(const views::KeyEvent& event) { + return false; +} + +void NativeComboboxGtk::HandleFocus() { +} + +void NativeComboboxGtk::HandleBlur() { +} + gfx::NativeView NativeComboboxGtk::GetTestingHandle() const { return native_view(); } diff --git a/views/controls/combobox/native_combobox_gtk.h b/views/controls/combobox/native_combobox_gtk.h index 9a0e8de..19b96c7 100644 --- a/views/controls/combobox/native_combobox_gtk.h +++ b/views/controls/combobox/native_combobox_gtk.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -19,20 +19,24 @@ class NativeComboboxGtk : public NativeControlGtk, virtual ~NativeComboboxGtk(); // Overridden from NativeComboboxWrapper: - virtual void UpdateFromModel(); - virtual void UpdateSelectedItem(); - virtual void UpdateEnabled(); - virtual int GetSelectedItem() const; - virtual bool IsDropdownOpen() const; - virtual gfx::Size GetPreferredSize(); - virtual View* GetView(); - virtual void SetFocus(); - virtual gfx::NativeView GetTestingHandle() const; + virtual void UpdateFromModel() OVERRIDE; + virtual void UpdateSelectedItem() OVERRIDE; + virtual void UpdateEnabled() OVERRIDE; + virtual int GetSelectedItem() const OVERRIDE; + virtual bool IsDropdownOpen() const OVERRIDE; + virtual gfx::Size GetPreferredSize() OVERRIDE; + virtual View* GetView() OVERRIDE; + virtual void SetFocus() OVERRIDE; + virtual bool HandleKeyPressed(const views::KeyEvent& event) OVERRIDE; + virtual bool HandleKeyReleased(const views::KeyEvent& event) OVERRIDE; + virtual void HandleFocus() OVERRIDE; + virtual void HandleBlur() OVERRIDE; + virtual gfx::NativeView GetTestingHandle() const OVERRIDE; protected: // Overridden from NativeControlGtk: - virtual void CreateNativeControl(); - virtual void NativeControlCreated(GtkWidget* widget); + virtual void CreateNativeControl() OVERRIDE; + virtual void NativeControlCreated(GtkWidget* widget) OVERRIDE; private: void SelectionChanged(); diff --git a/views/controls/combobox/native_combobox_views.cc b/views/controls/combobox/native_combobox_views.cc index 9d46687..fb16d84 100644 --- a/views/controls/combobox/native_combobox_views.cc +++ b/views/controls/combobox/native_combobox_views.cc @@ -7,6 +7,7 @@ #include <algorithm> #include "base/command_line.h" +#include "ui/base/keycodes/keyboard_codes.h" #include "ui/base/models/combobox_model.h" #include "ui/base/resource/resource_bundle.h" #include "ui/gfx/canvas.h" @@ -75,9 +76,9 @@ NativeComboboxViews::~NativeComboboxViews() { //////////////////////////////////////////////////////////////////////////////// // NativeComboboxViews, View overrides: -bool NativeComboboxViews::OnMousePressed(const views::MouseEvent& e) { +bool NativeComboboxViews::OnMousePressed(const views::MouseEvent& mouse_event) { combobox_->RequestFocus(); - if (e.IsLeftMouseButton()) { + if (mouse_event.IsLeftMouseButton()) { UpdateFromModel(); ShowDropDownMenu(); } @@ -85,20 +86,61 @@ bool NativeComboboxViews::OnMousePressed(const views::MouseEvent& e) { return true; } -bool NativeComboboxViews::OnMouseDragged(const views::MouseEvent& event) { +bool NativeComboboxViews::OnMouseDragged(const views::MouseEvent& mouse_event) { return true; } -bool NativeComboboxViews::OnKeyPressed(const views::KeyEvent& event) { - // OnKeyPressed/OnKeyReleased/OnFocus/OnBlur will never be invoked on - // NativeComboboxViews as it will never gain focus. - NOTREACHED(); - return false; +bool NativeComboboxViews::OnKeyPressed(const views::KeyEvent& key_event) { + // TODO(oshima): handle IME. + DCHECK(key_event.type() == ui::ET_KEY_PRESSED); + + // Check if we are in the default state (-1) and set to first item. + if(selected_item_ == -1) + selected_item_ = 0; + + int new_item = selected_item_; + switch(key_event.key_code()){ + + // move to the next element if any + case ui::VKEY_DOWN: + if (new_item < (combobox_->model()->GetItemCount() - 1)) + new_item++; + break; + + // move to the end of the list + case ui::VKEY_END: + case ui::VKEY_NEXT: + new_item = combobox_->model()->GetItemCount() - 1; + break; + + // move to the top of the list + case ui::VKEY_HOME: + case ui::VKEY_PRIOR: + new_item = 0; + break; + + // move to the previous element if any + case ui::VKEY_UP: + if (new_item > 0) + new_item--; + break; + + default: + return false; + + } + + if(new_item != selected_item_) { + selected_item_ = new_item; + combobox_->SelectionChanged(); + SchedulePaint(); + } + + return true; } -bool NativeComboboxViews::OnKeyReleased(const views::KeyEvent& event) { - NOTREACHED(); - return false; +bool NativeComboboxViews::OnKeyReleased(const views::KeyEvent& key_event) { + return true; } void NativeComboboxViews::OnPaint(gfx::Canvas* canvas) { @@ -178,6 +220,21 @@ void NativeComboboxViews::SetFocus() { text_border_->set_has_focus(true); } +bool NativeComboboxViews::HandleKeyPressed(const KeyEvent& e) { + return OnKeyPressed(e); +} + +bool NativeComboboxViews::HandleKeyReleased(const KeyEvent& e) { + return true; +} + +void NativeComboboxViews::HandleFocus() { + SchedulePaint(); +} + +void NativeComboboxViews::HandleBlur() { +} + gfx::NativeView NativeComboboxViews::GetTestingHandle() const { NOTREACHED(); return NULL; diff --git a/views/controls/combobox/native_combobox_views.h b/views/controls/combobox/native_combobox_views.h index 18d4023..3a19ab8 100644 --- a/views/controls/combobox/native_combobox_views.h +++ b/views/controls/combobox/native_combobox_views.h @@ -31,10 +31,10 @@ class NativeComboboxViews : public views::View, virtual ~NativeComboboxViews(); // views::View overrides: - virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE; - virtual bool OnMouseDragged(const views::MouseEvent& event) OVERRIDE; - virtual bool OnKeyPressed(const views::KeyEvent& event) OVERRIDE; - virtual bool OnKeyReleased(const views::KeyEvent& event) OVERRIDE; + virtual bool OnMousePressed(const views::MouseEvent& mouse_event) OVERRIDE; + virtual bool OnMouseDragged(const views::MouseEvent& mouse_event) OVERRIDE; + virtual bool OnKeyPressed(const views::KeyEvent& key_event) OVERRIDE; + virtual bool OnKeyReleased(const views::KeyEvent& key_event) OVERRIDE; virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; virtual void OnFocus() OVERRIDE; virtual void OnBlur() OVERRIDE; @@ -48,6 +48,10 @@ class NativeComboboxViews : public views::View, virtual gfx::Size GetPreferredSize() OVERRIDE; virtual View* GetView() OVERRIDE; virtual void SetFocus() OVERRIDE; + virtual bool HandleKeyPressed(const views::KeyEvent& event) OVERRIDE; + virtual bool HandleKeyReleased(const views::KeyEvent& event) OVERRIDE; + virtual void HandleFocus() OVERRIDE; + virtual void HandleBlur() OVERRIDE; virtual gfx::NativeView GetTestingHandle() const OVERRIDE; // MenuDelegate overrides: diff --git a/views/controls/combobox/native_combobox_win.cc b/views/controls/combobox/native_combobox_win.cc index dc5ef09..4a02274 100644 --- a/views/controls/combobox/native_combobox_win.cc +++ b/views/controls/combobox/native_combobox_win.cc @@ -139,6 +139,20 @@ void NativeComboboxWin::SetFocus() { OnFocus(); } +bool NativeComboboxWin::HandleKeyPressed(const views::KeyEvent& event) { + return false; +} + +bool NativeComboboxWin::HandleKeyReleased(const views::KeyEvent& event) { + return false; +} + +void NativeComboboxWin::HandleFocus() { +} + +void NativeComboboxWin::HandleBlur() { +} + gfx::NativeView NativeComboboxWin::GetTestingHandle() const { return native_view(); } diff --git a/views/controls/combobox/native_combobox_win.h b/views/controls/combobox/native_combobox_win.h index 287fdb0..640d3e1 100644 --- a/views/controls/combobox/native_combobox_win.h +++ b/views/controls/combobox/native_combobox_win.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -18,24 +18,28 @@ class NativeComboboxWin : public NativeControlWin, virtual ~NativeComboboxWin(); // Overridden from NativeComboboxWrapper: - virtual void UpdateFromModel(); - virtual void UpdateSelectedItem(); - virtual void UpdateEnabled(); - virtual int GetSelectedItem() const; - virtual bool IsDropdownOpen() const; - virtual gfx::Size GetPreferredSize(); - virtual View* GetView(); - virtual void SetFocus(); - virtual gfx::NativeView GetTestingHandle() const; + virtual void UpdateFromModel() OVERRIDE; + virtual void UpdateSelectedItem() OVERRIDE; + virtual void UpdateEnabled() OVERRIDE; + virtual int GetSelectedItem() const OVERRIDE; + virtual bool IsDropdownOpen() const OVERRIDE; + virtual gfx::Size GetPreferredSize() OVERRIDE; + virtual View* GetView() OVERRIDE; + virtual void SetFocus() OVERRIDE; + virtual bool HandleKeyPressed(const views::KeyEvent& event) OVERRIDE; + virtual bool HandleKeyReleased(const views::KeyEvent& event) OVERRIDE; + virtual void HandleFocus() OVERRIDE; + virtual void HandleBlur() OVERRIDE; + virtual gfx::NativeView GetTestingHandle() const OVERRIDE; protected: // Overridden from NativeControlWin: virtual bool ProcessMessage(UINT message, WPARAM w_param, LPARAM l_param, - LRESULT* result); - virtual void CreateNativeControl(); - virtual void NativeControlCreated(HWND native_control); + LRESULT* result) OVERRIDE; + virtual void CreateNativeControl() OVERRIDE; + virtual void NativeControlCreated(HWND native_control) OVERRIDE; private: void UpdateFont(); diff --git a/views/controls/combobox/native_combobox_wrapper.h b/views/controls/combobox/native_combobox_wrapper.h index 9de1167..7d88563a 100644 --- a/views/controls/combobox/native_combobox_wrapper.h +++ b/views/controls/combobox/native_combobox_wrapper.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -15,6 +15,7 @@ class Size; namespace views { class Combobox; +class KeyEvent; class View; class NativeComboboxWrapper { @@ -43,6 +44,18 @@ class NativeComboboxWrapper { // Sets the focus to the button. virtual void SetFocus() = 0; + // Invoked when a key is pressed/release on Combobox. Subclasser + // should return true if the event has been processed and false + // otherwise. + // See also View::OnKeyPressed/OnKeyReleased. + virtual bool HandleKeyPressed(const views::KeyEvent& e) = 0; + virtual bool HandleKeyReleased(const views::KeyEvent& e) = 0; + + // Invoked when focus is being moved from or to the Combobox. + // See also View::OnFocus/OnBlur. + virtual void HandleFocus() = 0; + virtual void HandleBlur() = 0; + // Returns a handle to the underlying native view for testing. virtual gfx::NativeView GetTestingHandle() const = 0; |