summaryrefslogtreecommitdiffstats
path: root/views
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-11 20:16:45 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-11 20:16:45 +0000
commit861f238313d2b2842dc90415e3b394addd5c3872 (patch)
tree3c56336f4b41876b8b5c4e4827c1c2d64dd2a412 /views
parent6a1ae6cdf8f1edfb89f5f2ce823af937f7f43aa9 (diff)
downloadchromium_src-861f238313d2b2842dc90415e3b394addd5c3872.zip
chromium_src-861f238313d2b2842dc90415e3b394addd5c3872.tar.gz
chromium_src-861f238313d2b2842dc90415e3b394addd5c3872.tar.bz2
Safer KeyEvent construction using synthetic MSGs.
After talking to jar, it seems impossible to reliably get a reasonable MSG from Windows given native nested message loops etc. So I am making this do what my prototype did and just generate a synthetic MSG from the information supplied to the WndProc. It turns out this is what ATL does too for its GetCurrentMessage implementation. BUG=none TEST=none Review URL: http://codereview.chromium.org/6500003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@74654 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r--views/widget/widget_win.cc28
-rw-r--r--views/widget/widget_win.h20
2 files changed, 31 insertions, 17 deletions
diff --git a/views/widget/widget_win.cc b/views/widget/widget_win.cc
index 69d0b81..162d69f 100644
--- a/views/widget/widget_win.cc
+++ b/views/widget/widget_win.cc
@@ -523,13 +523,11 @@ bool WidgetWin::ContainsNativeView(gfx::NativeView native_view) {
// MessageLoop::Observer
void WidgetWin::WillProcessMessage(const MSG& msg) {
- current_messages_.push_back(msg);
}
void WidgetWin::DidProcessMessage(const MSG& msg) {
if (root_view_->NeedsPainting(true))
PaintNow(root_view_->GetScheduledPaintRect());
- current_messages_.pop_back();
}
////////////////////////////////////////////////////////////////////////////////
@@ -691,22 +689,26 @@ void WidgetWin::OnInitMenuPopup(HMENU menu,
SetMsgHandled(FALSE);
}
-void WidgetWin::OnKeyDown(TCHAR c, UINT rep_cnt, UINT flags) {
- KeyEvent event(current_messages_.back());
+LRESULT WidgetWin::OnKeyDown(UINT message, WPARAM w_param, LPARAM l_param) {
RootView* root_view = GetFocusedViewRootView();
if (!root_view)
root_view = root_view_.get();
- SetMsgHandled(root_view->ProcessKeyEvent(event));
+ MSG msg;
+ MakeMSG(&msg, message, w_param, l_param);
+ SetMsgHandled(root_view->ProcessKeyEvent(KeyEvent(msg)));
+ return 0;
}
-void WidgetWin::OnKeyUp(TCHAR c, UINT rep_cnt, UINT flags) {
- KeyEvent event(current_messages_.back());
+LRESULT WidgetWin::OnKeyUp(UINT message, WPARAM w_param, LPARAM l_param) {
RootView* root_view = GetFocusedViewRootView();
if (!root_view)
root_view = root_view_.get();
- SetMsgHandled(root_view->ProcessKeyEvent(event));
+ MSG msg;
+ MakeMSG(&msg, message, w_param, l_param);
+ SetMsgHandled(root_view->ProcessKeyEvent(KeyEvent(msg)));
+ return 0;
}
void WidgetWin::OnKillFocus(HWND focused_window) {
@@ -1298,6 +1300,16 @@ void WidgetWin::PostProcessActivateMessage(WidgetWin* widget,
}
}
+void WidgetWin::MakeMSG(MSG* msg, UINT message, WPARAM w_param,
+ LPARAM l_param) const {
+ msg->hwnd = hwnd();
+ msg->message = message;
+ msg->wParam = w_param;
+ msg->lParam = l_param;
+ msg->time = 0;
+ msg->pt.x = msg->pt.y = 0;
+}
+
////////////////////////////////////////////////////////////////////////////////
// Widget, public:
diff --git a/views/widget/widget_win.h b/views/widget/widget_win.h
index 1f99f96..c93db90 100644
--- a/views/widget/widget_win.h
+++ b/views/widget/widget_win.h
@@ -141,6 +141,12 @@ class WidgetWin : public ui::WindowImpl,
MESSAGE_HANDLER_EX(WM_MOUSELEAVE, OnMouseLeave)
MESSAGE_HANDLER_EX(WM_MOUSEWHEEL, OnMouseWheel)
+ // Key events.
+ MESSAGE_HANDLER_EX(WM_KEYDOWN, OnKeyDown)
+ MESSAGE_HANDLER_EX(WM_KEYUP, OnKeyUp)
+ MESSAGE_HANDLER_EX(WM_SYSKEYDOWN, OnKeyDown);
+ MESSAGE_HANDLER_EX(WM_SYSKEYUP, OnKeyUp);
+
// This list is in _ALPHABETICAL_ order! OR I WILL HURT YOU.
MSG_WM_ACTIVATE(OnActivate)
MSG_WM_ACTIVATEAPP(OnActivateApp)
@@ -161,11 +167,7 @@ class WidgetWin : public ui::WindowImpl,
MSG_WM_HSCROLL(OnHScroll)
MSG_WM_INITMENU(OnInitMenu)
MSG_WM_INITMENUPOPUP(OnInitMenuPopup)
- MSG_WM_KEYDOWN(OnKeyDown)
- MSG_WM_KEYUP(OnKeyUp)
MSG_WM_KILLFOCUS(OnKillFocus)
- MSG_WM_SYSKEYDOWN(OnKeyDown)
- MSG_WM_SYSKEYUP(OnKeyUp)
MSG_WM_LBUTTONDBLCLK(OnLButtonDblClk)
MSG_WM_LBUTTONDOWN(OnLButtonDown)
MSG_WM_LBUTTONUP(OnLButtonUp)
@@ -367,8 +369,8 @@ class WidgetWin : public ui::WindowImpl,
virtual void OnHScroll(int scroll_type, short position, HWND scrollbar);
virtual void OnInitMenu(HMENU menu);
virtual void OnInitMenuPopup(HMENU menu, UINT position, BOOL is_system_menu);
- virtual void OnKeyDown(TCHAR c, UINT rep_cnt, UINT flags);
- virtual void OnKeyUp(TCHAR c, UINT rep_cnt, UINT flags);
+ virtual LRESULT OnKeyDown(UINT message, WPARAM w_param, LPARAM l_param);
+ virtual LRESULT OnKeyUp(UINT message, WPARAM w_param, LPARAM l_param);
virtual void OnKillFocus(HWND focused_window);
virtual void OnLButtonDblClk(UINT flags, const CPoint& point);
virtual void OnLButtonDown(UINT flags, const CPoint& point);
@@ -519,6 +521,9 @@ class WidgetWin : public ui::WindowImpl,
static void PostProcessActivateMessage(WidgetWin* widget,
int activation_state);
+ // Fills out a MSG struct with the supplied values.
+ void MakeMSG(MSG* msg, UINT message, WPARAM w_param, LPARAM l_param) const;
+
// The following factory is used for calls to close the WidgetWin
// instance.
ScopedRunnableMethodFactory<WidgetWin> close_widget_factory_;
@@ -599,9 +604,6 @@ class WidgetWin : public ui::WindowImpl,
ViewProps props_;
- // Keeps track of the current message.
- std::vector<MSG> current_messages_;
-
DISALLOW_COPY_AND_ASSIGN(WidgetWin);
};