summaryrefslogtreecommitdiffstats
path: root/views
diff options
context:
space:
mode:
authorfinnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-03 20:58:01 +0000
committerfinnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-03 20:58:01 +0000
commita071e653c8e2b9b77c412600c3d35de814541527 (patch)
tree4f6edf175b8090a8140d511b72ae0879fbacfec2 /views
parentd78f40f3543cd057d845625d1abce9cd79b0682c (diff)
downloadchromium_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')
-rw-r--r--views/controls/button/button.cc6
-rw-r--r--views/controls/button/button.h5
-rw-r--r--views/controls/button/custom_button.cc22
-rw-r--r--views/controls/button/native_button.cc29
-rw-r--r--views/controls/scrollbar/bitmap_scroll_bar.cc33
-rw-r--r--views/controls/scrollbar/bitmap_scroll_bar.h2
-rw-r--r--views/event.h10
-rw-r--r--views/view_unittest.cc2
-rw-r--r--views/window/custom_frame_view.cc2
-rw-r--r--views/window/custom_frame_view.h2
-rw-r--r--views/window/dialog_client_view.cc3
-rw-r--r--views/window/dialog_client_view.h2
12 files changed, 92 insertions, 26 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,
diff --git a/views/event.h b/views/event.h
index ee9a838..882f558 100644
--- a/views/event.h
+++ b/views/event.h
@@ -87,6 +87,16 @@ class Event {
return (flags_ & EF_ALT_DOWN) != 0;
}
+ bool IsMouseEvent() const {
+ return type_ == ET_MOUSE_PRESSED ||
+ type_ == ET_MOUSE_DRAGGED ||
+ type_ == ET_MOUSE_RELEASED ||
+ type_ == ET_MOUSE_MOVED ||
+ type_ == ET_MOUSE_ENTERED ||
+ type_ == ET_MOUSE_EXITED ||
+ type_ == ET_MOUSEWHEEL;
+ }
+
#if defined(OS_WIN)
// Returns the EventFlags in terms of windows flags.
int GetWindowsFlags() const;
diff --git a/views/view_unittest.cc b/views/view_unittest.cc
index 9d2fa87..e02afd73a 100644
--- a/views/view_unittest.cc
+++ b/views/view_unittest.cc
@@ -1045,7 +1045,7 @@ class TestDialogView : public views::View,
}
// views::ButtonListener implementation.
- virtual void ButtonPressed(Button* sender) {
+ virtual void ButtonPressed(Button* sender, const views::Event& event) {
last_pressed_button_ = sender;
}
diff --git a/views/window/custom_frame_view.cc b/views/window/custom_frame_view.cc
index 3434485..d3fd085 100644
--- a/views/window/custom_frame_view.cc
+++ b/views/window/custom_frame_view.cc
@@ -236,7 +236,7 @@ gfx::Size CustomFrameView::GetPreferredSize() {
///////////////////////////////////////////////////////////////////////////////
// CustomFrameView, ButtonListener implementation:
-void CustomFrameView::ButtonPressed(Button* sender) {
+void CustomFrameView::ButtonPressed(Button* sender, const views::Event& event) {
if (sender == close_button_)
frame_->Close();
else if (sender == minimize_button_)
diff --git a/views/window/custom_frame_view.h b/views/window/custom_frame_view.h
index bee9e62..0ae0050 100644
--- a/views/window/custom_frame_view.h
+++ b/views/window/custom_frame_view.h
@@ -50,7 +50,7 @@ class CustomFrameView : public NonClientFrameView,
virtual gfx::Size GetPreferredSize();
// ButtonListener implementation:
- virtual void ButtonPressed(Button* sender);
+ virtual void ButtonPressed(Button* sender, const views::Event& event);
private:
// Returns the thickness of the border that makes up the window frame edges.
diff --git a/views/window/dialog_client_view.cc b/views/window/dialog_client_view.cc
index 9c40b7f..98482a0 100644
--- a/views/window/dialog_client_view.cc
+++ b/views/window/dialog_client_view.cc
@@ -367,7 +367,8 @@ bool DialogClientView::AcceleratorPressed(const Accelerator& accelerator) {
////////////////////////////////////////////////////////////////////////////////
// DialogClientView, ButtonListener implementation:
-void DialogClientView::ButtonPressed(Button* sender) {
+void DialogClientView::ButtonPressed(
+ Button* sender, const views::Event& event) {
// We NULL check the delegate here since the buttons can receive WM_COMMAND
// messages even after they (and the window containing us) are destroyed.
if (!GetDialogDelegate())
diff --git a/views/window/dialog_client_view.h b/views/window/dialog_client_view.h
index 5d1fa33..1c3d19f 100644
--- a/views/window/dialog_client_view.h
+++ b/views/window/dialog_client_view.h
@@ -69,7 +69,7 @@ class DialogClientView : public ClientView,
virtual bool AcceleratorPressed(const Accelerator& accelerator);
// ButtonListener implementation:
- virtual void ButtonPressed(Button* sender);
+ virtual void ButtonPressed(Button* sender, const views::Event& event);
private:
// Paint the size box in the bottom right corner of the window if it is