diff options
author | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-03 20:58:01 +0000 |
---|---|---|
committer | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-03 20:58:01 +0000 |
commit | a071e653c8e2b9b77c412600c3d35de814541527 (patch) | |
tree | 4f6edf175b8090a8140d511b72ae0879fbacfec2 /views/controls | |
parent | d78f40f3543cd057d845625d1abce9cd79b0682c (diff) | |
download | chromium_src-a071e653c8e2b9b77c412600c3d35de814541527.zip chromium_src-a071e653c8e2b9b77c412600c3d35de814541527.tar.gz chromium_src-a071e653c8e2b9b77c412600c3d35de814541527.tar.bz2 |
Fix 9867: Activating the previous/next buttons with the keyboard in the find bar should not change the focus.
Add param const Event& event to ButtonPressed, so that recipients can find out more about the event that generated the ButtonPress message.
BUG=9687
TEST=Open www.google.com and open Find-in-page, search for 'e'. Press FindNext button with mouse and note that the focus should be on the textfield. Now press Tab twice to put focus on the FindNext button and press SpaceBar a few times. Note that the focus should stay on the FindNext button.
Review URL: http://codereview.chromium.org/188016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25367 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/controls')
-rw-r--r-- | views/controls/button/button.cc | 6 | ||||
-rw-r--r-- | views/controls/button/button.h | 5 | ||||
-rw-r--r-- | views/controls/button/custom_button.cc | 22 | ||||
-rw-r--r-- | views/controls/button/native_button.cc | 29 | ||||
-rw-r--r-- | views/controls/scrollbar/bitmap_scroll_bar.cc | 33 | ||||
-rw-r--r-- | views/controls/scrollbar/bitmap_scroll_bar.h | 2 |
6 files changed, 76 insertions, 21 deletions
diff --git a/views/controls/button/button.cc b/views/controls/button/button.cc index cbb42bf..504a2f5 100644 --- a/views/controls/button/button.cc +++ b/views/controls/button/button.cc @@ -66,12 +66,12 @@ Button::Button(ButtonListener* listener) mouse_event_flags_(0) { } -void Button::NotifyClick(int mouse_event_flags) { - mouse_event_flags_ = mouse_event_flags; +void Button::NotifyClick(const views::Event& event) { + mouse_event_flags_ = event.IsMouseEvent() ? event.GetFlags() : 0; // We can be called when there is no listener, in cases like double clicks on // menu buttons etc. if (listener_) - listener_->ButtonPressed(this); + listener_->ButtonPressed(this, event); // NOTE: don't attempt to reset mouse_event_flags_ as the listener may have // deleted us. } diff --git a/views/controls/button/button.h b/views/controls/button/button.h index 514758f..9dd8b13 100644 --- a/views/controls/button/button.h +++ b/views/controls/button/button.h @@ -10,12 +10,13 @@ namespace views { class Button; +class Event; // An interface implemented by an object to let it know that a button was // pressed. class ButtonListener { public: - virtual void ButtonPressed(Button* sender) = 0; + virtual void ButtonPressed(Button* sender, const views::Event& event) = 0; }; // A View representing a button. Depending on the specific type, the button @@ -46,7 +47,7 @@ class Button : public View { explicit Button(ButtonListener* listener); // Cause the button to notify the listener that a click occurred. - virtual void NotifyClick(int mouse_event_flags); + virtual void NotifyClick(const views::Event& event); // The button's listener. Notified when clicked. ButtonListener* listener_; diff --git a/views/controls/button/custom_button.cc b/views/controls/button/custom_button.cc index 45482b8..69ac840 100644 --- a/views/controls/button/custom_button.cc +++ b/views/controls/button/custom_button.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 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. @@ -89,7 +89,19 @@ bool CustomButton::IsTriggerableEvent(const MouseEvent& e) { bool CustomButton::AcceleratorPressed(const Accelerator& accelerator) { if (enabled_) { SetState(BS_NORMAL); - NotifyClick(0); +#if defined(OS_WIN) + KeyEvent key_event(Event::ET_KEY_RELEASED, accelerator.GetKeyCode(), 0, 0); +#elif defined(OS_LINUX) + GdkEventKey gdk_key; + memset(&gdk_key, 0, sizeof(GdkEventKey)); + gdk_key.type = GDK_KEY_RELEASE; + gdk_key.keyval = accelerator.GetKeyCode(); + gdk_key.state = accelerator.IsAltDown() << 3 + + accelerator.IsCtrlDown() << 2 + + accelerator.IsShiftDown(); + KeyEvent key_event(&gdk_key, false); +#endif + NotifyClick(key_event); return true; } return false; @@ -128,7 +140,7 @@ void CustomButton::OnMouseReleased(const MouseEvent& e, bool canceled) { } else { SetState(BS_HOT); if (IsTriggerableEvent(e)) { - NotifyClick(e.GetFlags()); + NotifyClick(e); // We may be deleted at this point (by the listener's notification // handler) so no more doing anything, just return. return; @@ -168,7 +180,7 @@ bool CustomButton::OnKeyPressed(const KeyEvent& e) { return true; } else if (e.GetCharacter() == base::VKEY_RETURN) { SetState(BS_NORMAL); - NotifyClick(0); + NotifyClick(e); return true; } } @@ -179,7 +191,7 @@ bool CustomButton::OnKeyReleased(const KeyEvent& e) { if (state_ != BS_DISABLED) { if (e.GetCharacter() == base::VKEY_SPACE) { SetState(BS_NORMAL); - NotifyClick(0); + NotifyClick(e); return true; } } diff --git a/views/controls/button/native_button.cc b/views/controls/button/native_button.cc index 8a90aaa..f631bd8 100644 --- a/views/controls/button/native_button.cc +++ b/views/controls/button/native_button.cc @@ -4,8 +4,14 @@ #include "views/controls/button/native_button.h" +#if defined(OS_WIN) +#include <atlbase.h> +#include <atlapp.h> // for GET_X/Y_LPARAM +#endif + #if defined(OS_LINUX) #include <gdk/gdkkeysyms.h> +#include "views/screen.h" #endif #include "app/l10n_util.h" @@ -95,7 +101,17 @@ void NativeButton::ButtonPressed() { RequestFocus(); // TODO(beng): obtain mouse event flags for native buttons someday. - NotifyClick(mouse_event_flags()); +#if defined(OS_WIN) + DWORD pos = GetMessagePos(); + gfx::Point cursor_point(GET_X_LPARAM(pos), GET_Y_LPARAM(pos)); +#elif defined(OS_LINUX) + gfx::Point cursor_point = Screen::GetCursorScreenPoint(); +#endif + + views::MouseEvent event(views::Event::ET_MOUSE_RELEASED, + cursor_point.x(), cursor_point.y(), + views::Event::EF_LEFT_BUTTON_DOWN); + NotifyClick(event); } //////////////////////////////////////////////////////////////////////////////// @@ -162,7 +178,16 @@ std::string NativeButton::GetClassName() const { bool NativeButton::AcceleratorPressed(const Accelerator& accelerator) { if (IsEnabled()) { - NotifyClick(mouse_event_flags()); +#if defined(OS_WIN) + DWORD pos = GetMessagePos(); + gfx::Point cursor_point(GET_X_LPARAM(pos), GET_Y_LPARAM(pos)); +#elif defined(OS_LINUX) + gfx::Point cursor_point = Screen::GetCursorScreenPoint(); +#endif + views::MouseEvent event(views::Event::ET_MOUSE_RELEASED, + cursor_point.x(), cursor_point.y(), + views::Event::EF_LEFT_BUTTON_DOWN); + NotifyClick(event); return true; } return false; diff --git a/views/controls/scrollbar/bitmap_scroll_bar.cc b/views/controls/scrollbar/bitmap_scroll_bar.cc index 0736501..54f35ab 100644 --- a/views/controls/scrollbar/bitmap_scroll_bar.cc +++ b/views/controls/scrollbar/bitmap_scroll_bar.cc @@ -1,9 +1,16 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 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. #include "views/controls/scrollbar/bitmap_scroll_bar.h" +#if defined(OS_WIN) +#include <atlbase.h> +#include <atlapp.h> // for GET_X/Y_LPARAM +#elif defined(OS_LINUX) +#include "views/screen.h" +#endif + #include "app/gfx/canvas.h" #include "app/l10n_util.h" #include "base/compiler_specific.h" @@ -13,6 +20,7 @@ #include "views/controls/menu/menu.h" #include "views/controls/scroll_view.h" #include "views/widget/widget.h" +#include "views/window/window.h" #undef min #undef max @@ -46,7 +54,7 @@ class AutorepeatButton : public ImageButton { protected: virtual bool OnMousePressed(const MouseEvent& event) { - Button::NotifyClick(event.GetFlags()); + Button::NotifyClick(event); repeater_.Start(); return true; } @@ -58,14 +66,23 @@ class AutorepeatButton : public ImageButton { private: void NotifyClick() { - Button::NotifyClick(0); +#if defined(OS_WIN) + DWORD pos = GetMessagePos(); + gfx::Point cursor_point(GET_X_LPARAM(pos), GET_Y_LPARAM(pos)); +#elif defined(OS_LINUX) + gfx::Point cursor_point = Screen::GetCursorScreenPoint(); +#endif + views::MouseEvent event(views::Event::ET_MOUSE_RELEASED, + cursor_point.x(), cursor_point.y(), + views::Event::EF_LEFT_BUTTON_DOWN); + Button::NotifyClick(event); } // The repeat controller that we use to repeatedly click the button when the // mouse button is down. RepeatController repeater_; - DISALLOW_EVIL_CONSTRUCTORS(AutorepeatButton); + DISALLOW_COPY_AND_ASSIGN(AutorepeatButton); }; /////////////////////////////////////////////////////////////////////////////// @@ -246,10 +263,10 @@ class BitmapScrollBarThumb : public View { // The current state of the thumb button. CustomButton::ButtonState state_; - DISALLOW_EVIL_CONSTRUCTORS(BitmapScrollBarThumb); + DISALLOW_COPY_AND_ASSIGN(BitmapScrollBarThumb); }; -} // anonymous namespace +} // anonymous namespace /////////////////////////////////////////////////////////////////////////////// // BitmapScrollBar, public: @@ -479,7 +496,7 @@ bool BitmapScrollBar::OnMouseWheel(const MouseWheelEvent& event) { bool BitmapScrollBar::OnKeyPressed(const KeyEvent& event) { ScrollAmount amount = SCROLL_NONE; - switch(event.GetCharacter()) { + switch (event.GetCharacter()) { case VK_UP: if (!IsHorizontal()) amount = SCROLL_PREV_LINE; @@ -629,7 +646,7 @@ void BitmapScrollBar::ExecuteCommand(int id) { /////////////////////////////////////////////////////////////////////////////// // BitmapScrollBar, ButtonListener implementation: -void BitmapScrollBar::ButtonPressed(Button* sender) { +void BitmapScrollBar::ButtonPressed(Button* sender, const views::Event& event) { if (sender == prev_button_) { ScrollByAmount(SCROLL_PREV_LINE); } else if (sender == next_button_) { diff --git a/views/controls/scrollbar/bitmap_scroll_bar.h b/views/controls/scrollbar/bitmap_scroll_bar.h index 904830e..1a3bc67 100644 --- a/views/controls/scrollbar/bitmap_scroll_bar.h +++ b/views/controls/scrollbar/bitmap_scroll_bar.h @@ -103,7 +103,7 @@ class BitmapScrollBar : public ScrollBar, virtual bool OnKeyPressed(const KeyEvent& event); // BaseButton::ButtonListener overrides: - virtual void ButtonPressed(Button* sender); + virtual void ButtonPressed(Button* sender, const views::Event& event); // ScrollBar overrides: virtual void Update(int viewport_size, |