diff options
author | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-25 00:11:44 +0000 |
---|---|---|
committer | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-25 00:11:44 +0000 |
commit | 3a21be61ee6d17f5c6c06bfcddd881bd76b42e9a (patch) | |
tree | f1057057c7d81495dc177b2c4302701d65420d3b /chrome | |
parent | 7cf4621942f87e87a3e101a9cfadb8309a5e59b7 (diff) | |
download | chromium_src-3a21be61ee6d17f5c6c06bfcddd881bd76b42e9a.zip chromium_src-3a21be61ee6d17f5c6c06bfcddd881bd76b42e9a.tar.gz chromium_src-3a21be61ee6d17f5c6c06bfcddd881bd76b42e9a.tar.bz2 |
Focusing a native button through a RequestFocus call would not result in the actual button showing as focused.
This is because the NativeButton is the one getting focused not the NativeControl wrapper.
This CL adds forwarding the focus to the NativeControl so the HWND really gets focused.
It also associates the NativeButton view with the NativeControl, so that when the HWND is focused (through a click for example), the focus manager has the NativeButton as the focused view (not the NativeControl wrapper).
BUG=9253
TEST=Open the option panel. Press tab several times. The focus should move as expected to the different buttons and views in the page.
Review URL: http://codereview.chromium.org/45042
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@12420 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/views/controls/button/native_button.cc | 7 | ||||
-rw-r--r-- | chrome/views/controls/button/native_button.h | 1 | ||||
-rw-r--r-- | chrome/views/controls/button/native_button_win.cc | 15 | ||||
-rw-r--r-- | chrome/views/controls/button/native_button_win.h | 2 | ||||
-rw-r--r-- | chrome/views/controls/button/native_button_wrapper.h | 7 |
5 files changed, 29 insertions, 3 deletions
diff --git a/chrome/views/controls/button/native_button.cc b/chrome/views/controls/button/native_button.cc index 3175c9a..f8c7c5d 100644 --- a/chrome/views/controls/button/native_button.cc +++ b/chrome/views/controls/button/native_button.cc @@ -138,6 +138,13 @@ bool NativeButton::AcceleratorPressed(const Accelerator& accelerator) { return false; } +void NativeButton::Focus() { + Button::Focus(); + // Forward the focus to the wrapper. + if (native_wrapper_) + native_wrapper_->SetFocus(); +} + //////////////////////////////////////////////////////////////////////////////// // NativeButton, protected: diff --git a/chrome/views/controls/button/native_button.h b/chrome/views/controls/button/native_button.h index 566038b..ccbf125 100644 --- a/chrome/views/controls/button/native_button.h +++ b/chrome/views/controls/button/native_button.h @@ -48,6 +48,7 @@ class NativeButton : public Button { // Overridden from View: virtual gfx::Size GetPreferredSize(); virtual void Layout(); + virtual void Focus(); protected: virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child); diff --git a/chrome/views/controls/button/native_button_win.cc b/chrome/views/controls/button/native_button_win.cc index aa664ba..e044c75 100644 --- a/chrome/views/controls/button/native_button_win.cc +++ b/chrome/views/controls/button/native_button_win.cc @@ -18,6 +18,10 @@ namespace views { NativeButtonWin::NativeButtonWin(NativeButton* native_button) : NativeControlWin(), native_button_(native_button) { + // Associates the actual HWND with the native_button so the native_button is + // the one considered as having the focus (not the wrapper) when the HWND is + // focused directly (with a click for example). + SetAssociatedFocusView(native_button); } NativeButtonWin::~NativeButtonWin() { @@ -48,6 +52,11 @@ View* NativeButtonWin::GetView() { return this; } +void NativeButtonWin::SetFocus() { + // Focus the associated HWND. + Focus(); +} + //////////////////////////////////////////////////////////////////////////////// // NativeButtonWin, View overrides: @@ -135,6 +144,11 @@ void NativeCheckboxWin::SetPushed(bool pushed) { SendMessage(GetHWND(), BM_SETSTATE, pushed, 0); } +void NativeCheckboxWin::SetFocus() { + // The focus should stay on the views::Checkbox (more precisely, on the + // label, which is a view). +} + //////////////////////////////////////////////////////////////////////////////// // NativeCheckboxWin, NativeButtonWin overrides: @@ -216,4 +230,3 @@ NativeButtonWrapper* NativeButtonWrapper::CreateRadioButtonWrapper( } } // namespace views - diff --git a/chrome/views/controls/button/native_button_win.h b/chrome/views/controls/button/native_button_win.h index 501ae0d..4bb0065 100644 --- a/chrome/views/controls/button/native_button_win.h +++ b/chrome/views/controls/button/native_button_win.h @@ -22,6 +22,7 @@ class NativeButtonWin : public NativeControlWin, virtual void UpdateFont(); virtual void UpdateDefault(); virtual View* GetView(); + virtual void SetFocus(); // Overridden from View: virtual gfx::Size GetPreferredSize(); @@ -61,6 +62,7 @@ class NativeCheckboxWin : public NativeButtonWin { virtual void SetPushed(bool pushed); // Overridden from NativeControlWin: + virtual void SetFocus(); virtual LRESULT ProcessMessage(UINT message, WPARAM w_param, LPARAM l_param); diff --git a/chrome/views/controls/button/native_button_wrapper.h b/chrome/views/controls/button/native_button_wrapper.h index 79cca23..95ad634 100644 --- a/chrome/views/controls/button/native_button_wrapper.h +++ b/chrome/views/controls/button/native_button_wrapper.h @@ -31,13 +31,16 @@ class NativeButtonWrapper { // Updates the native button's checked state from the state stored in its // associated NativeCheckbox. Valid only for checkboxes and radio buttons. virtual void UpdateChecked() {} - + // Shows the pushed state for the button if |pushed| is true. virtual void SetPushed(bool pushed) {}; - // Retrieves the views::View that hosts the native control. + // Retrieves the views::View that hosts the native control. virtual View* GetView() = 0; + // Sets the focus to the button. + virtual void SetFocus() = 0; + // Return the width of the button. Used for fixed size buttons (checkboxes and // radio buttons) only. static int GetFixedWidth(); |