Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(128)

Unified Diff: views/widget/widget_win.cc

Issue 6756043: Consolidate Widget Event code, other cleanup. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Consolidate Widget Event code, other cleanup. Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: views/widget/widget_win.cc
diff --git a/views/widget/widget_win.cc b/views/widget/widget_win.cc
index f50dfbc27664a02d1afa0ca81d7e363a31e8e720..74b8b4afc490a55e43191453e38e3424e58492cf 100644
--- a/views/widget/widget_win.cc
+++ b/views/widget/widget_win.cc
@@ -139,8 +139,6 @@ WidgetWin::WidgetWin()
ALLOW_THIS_IN_INITIALIZER_LIST(paint_layered_window_factory_(this)),
delete_on_destroy_(true),
can_update_layered_window_(true),
- last_mouse_event_was_move_(false),
- is_mouse_down_(false),
is_window_(false),
restore_focus_when_enabled_(false),
accessibility_view_events_index_(-1),
@@ -322,19 +320,23 @@ bool WidgetWin::IsScreenReaderActive() const {
return screen_reader_active_;
}
-void WidgetWin::SetNativeCapture() {
- DCHECK(!HasNativeCapture());
+void WidgetWin::SetMouseCapture() {
+ DCHECK(!HasMouseCapture());
SetCapture(hwnd());
}
-void WidgetWin::ReleaseNativeCapture() {
+void WidgetWin::ReleaseMouseCapture() {
ReleaseCapture();
}
-bool WidgetWin::HasNativeCapture() const {
+bool WidgetWin::HasMouseCapture() const {
return GetCapture() == hwnd();
}
+bool WidgetWin::ShouldReleaseCaptureOnMouseReleased() const {
+ return true;
+}
+
gfx::Rect WidgetWin::GetWindowScreenBounds() const {
RECT r;
GetWindowRect(&r);
@@ -566,9 +568,7 @@ void WidgetWin::OnCancelMode() {
}
void WidgetWin::OnCaptureChanged(HWND hwnd) {
- if (is_mouse_down_)
- GetRootView()->OnMouseCaptureLost();
- is_mouse_down_ = false;
+ ProcessMouseCaptureLost();
}
void WidgetWin::OnClose() {
@@ -750,32 +750,53 @@ LRESULT WidgetWin::OnMouseActivate(UINT message,
}
LRESULT WidgetWin::OnMouseLeave(UINT message, WPARAM w_param, LPARAM l_param) {
- tooltip_manager_->OnMouseLeave();
- ProcessMouseExited(message, w_param, l_param);
+ if (message != WM_NCMOUSELEAVE)
+ tooltip_manager_->OnMouseLeave();
+
+ MSG msg;
+ MakeMSG(&msg, message, w_param, l_param, 0, GET_X_LPARAM(l_param),
+ GET_Y_LPARAM(l_param));
+ last_mouse_event_was_move_ = false;
+ GetRootView()->OnMouseExited(MouseEvent(msg));
+ // Reset our tracking flag so that future mouse movement over this WidgetWin
+ // results in a new tracking session.
+ active_mouse_tracking_flags_ = 0;
return 0;
}
LRESULT WidgetWin::OnMouseMove(UINT message, WPARAM w_param, LPARAM l_param) {
- ProcessMouseMoved(message, w_param, l_param);
+ if (message == WM_NCMOUSEMOVE)
+ tooltip_manager_->OnMouse(message, w_param, l_param);
+
+ // Windows only fires WM_MOUSELEAVE events if the application begins
+ // "tracking" mouse events for a given HWND during WM_MOUSEMOVE events.
+ // We need to call |TrackMouseEvents| to listen for WM_MOUSELEAVE.
+ if (!HasMouseCapture())
+ TrackMouseEvents((message == WM_NCMOUSEMOVE) ?
+ TME_NONCLIENT | TME_LEAVE : TME_LEAVE);
+ MSG msg;
+ MakeMSG(&msg, message, w_param, l_param, 0, GET_X_LPARAM(l_param),
+ GET_Y_LPARAM(l_param));
+ ProcessMouseMoved(MouseEvent(msg));
return 0;
}
LRESULT WidgetWin::OnMouseRange(UINT message, WPARAM w_param, LPARAM l_param) {
- tooltip_manager_->OnMouse(message, w_param, l_param);
+ MSG msg;
+ MakeMSG(&msg, message, w_param, l_param, 0, GET_X_LPARAM(l_param),
+ GET_Y_LPARAM(l_param));
+ MouseEvent event(msg);
- switch (message) {
- case WM_LBUTTONDBLCLK:
- case WM_LBUTTONDOWN:
- case WM_MBUTTONDBLCLK:
- case WM_MBUTTONDOWN:
- case WM_RBUTTONDBLCLK:
- case WM_RBUTTONDOWN:
- SetMsgHandled(ProcessMousePressed(message, w_param, l_param));
+ if (!(event.flags() & ui::EF_IS_NON_CLIENT))
+ tooltip_manager_->OnMouse(message, w_param, l_param);
+
+ switch (event.type()) {
+ case ui::ET_MOUSE_PRESSED:
+ SetMsgHandled(ProcessMousePressed(event));
break;
- case WM_LBUTTONUP:
- case WM_MBUTTONUP:
- case WM_RBUTTONUP:
- SetMsgHandled(ProcessMouseReleased(message, w_param, l_param));
+ case ui::ET_MOUSE_RELEASED:
+ SetMsgHandled((event.flags() & ui::EF_IS_NON_CLIENT) ? FALSE :
+ ProcessMouseReleased(event));
Ben Goodger (Google) 2011/03/30 23:22:55 This is fine for now. I want you to eventually con
msw 2011/03/31 14:01:18 Done; I did some of this work now.
break;
default:
SetMsgHandled(FALSE);
@@ -824,45 +845,6 @@ LRESULT WidgetWin::OnNCHitTest(const CPoint& pt) {
return 0;
}
-LRESULT WidgetWin::OnNCMouseLeave(UINT message,
- WPARAM w_param,
- LPARAM l_param) {
- ProcessMouseExited(message, w_param, l_param);
- return 0;
-}
-
-LRESULT WidgetWin::OnNCMouseMove(UINT message, WPARAM w_param, LPARAM l_param) {
- tooltip_manager_->OnMouse(message, w_param, l_param);
- ProcessMouseMoved(message, w_param, l_param);
-
- // We need to process this message to stop Windows from drawing the window
- // controls as the mouse moves over the title bar area when the window is
- // maximized.
- return 0;
-}
-
-LRESULT WidgetWin::OnNCMouseRange(UINT message,
- WPARAM w_param,
- LPARAM l_param) {
- switch (message) {
- case WM_NCLBUTTONDBLCLK:
- case WM_NCLBUTTONDOWN:
- case WM_NCMBUTTONDBLCLK:
- case WM_NCMBUTTONDOWN:
- case WM_NCRBUTTONDBLCLK:
- case WM_NCRBUTTONDOWN:
- SetMsgHandled(ProcessMousePressed(message, w_param, l_param));
- break;
- case WM_NCLBUTTONUP:
- case WM_NCMBUTTONUP:
- case WM_NCRBUTTONUP:
- default:
- SetMsgHandled(FALSE);
- }
-
- return 0;
-}
-
void WidgetWin::OnNCPaint(HRGN rgn) {
SetMsgHandled(FALSE);
}
@@ -993,87 +975,10 @@ void WidgetWin::TrackMouseEvents(DWORD mouse_tracking_flags) {
}
}
-bool WidgetWin::ProcessMousePressed(UINT message,
- WPARAM w_param,
- LPARAM l_param) {
- last_mouse_event_was_move_ = false;
-
- MSG msg;
- MakeMSG(&msg, message, w_param, l_param, 0, GET_X_LPARAM(l_param),
- GET_Y_LPARAM(l_param));
- if (GetRootView()->OnMousePressed(MouseEvent(msg))) {
- is_mouse_down_ = true;
- if (!HasNativeCapture())
- SetNativeCapture();
- return true;
- }
- return false;
-}
-
-bool WidgetWin::ProcessMouseReleased(UINT message,
- WPARAM w_param,
- LPARAM l_param) {
- last_mouse_event_was_move_ = false;
- is_mouse_down_ = false;
-
- // Release the capture first, that way we don't get confused if
- // OnMouseReleased blocks.
- if (HasNativeCapture() && ReleaseCaptureOnMouseReleased())
- ReleaseNativeCapture();
-
- MSG msg;
- MakeMSG(&msg, message, w_param, l_param, 0, GET_X_LPARAM(l_param),
- GET_Y_LPARAM(l_param));
- GetRootView()->OnMouseReleased(MouseEvent(msg));
- return true;
-}
-
-bool WidgetWin::ProcessMouseMoved(UINT message,
- WPARAM w_param,
- LPARAM l_param) {
- // Windows only fires WM_MOUSELEAVE events if the application begins
- // "tracking" mouse events for a given HWND during WM_MOUSEMOVE events.
- // We need to call |TrackMouseEvents| to listen for WM_MOUSELEAVE.
- if (!HasNativeCapture())
- TrackMouseEvents((message == WM_NCMOUSEMOVE) ?
- TME_NONCLIENT | TME_LEAVE : TME_LEAVE);
- MSG msg;
- MakeMSG(&msg, message, w_param, l_param, 0, GET_X_LPARAM(l_param),
- GET_Y_LPARAM(l_param));
- if (HasNativeCapture() && is_mouse_down_)
- GetRootView()->OnMouseDragged(MouseEvent(msg));
- else if (!last_mouse_event_was_move_ ||
- (last_mouse_move_x_ != GET_X_LPARAM(l_param) ||
- last_mouse_move_y_ != GET_Y_LPARAM(l_param))) {
- last_mouse_move_x_ = GET_X_LPARAM(l_param);
- last_mouse_move_y_ = GET_Y_LPARAM(l_param);
- last_mouse_event_was_move_ = true;
- GetRootView()->OnMouseMoved(MouseEvent(msg));
- }
- return true;
-}
-
-void WidgetWin::ProcessMouseExited(UINT message,
- WPARAM w_param,
- LPARAM l_param) {
- last_mouse_event_was_move_ = false;
- MSG msg;
- MakeMSG(&msg, message, w_param, l_param, 0, GET_X_LPARAM(l_param),
- GET_Y_LPARAM(l_param));
- GetRootView()->OnMouseExited(MouseEvent(msg));
- // Reset our tracking flag so that future mouse movement over this WidgetWin
- // results in a new tracking session.
- active_mouse_tracking_flags_ = 0;
-}
-
void WidgetWin::OnScreenReaderDetected() {
screen_reader_active_ = true;
}
-bool WidgetWin::ReleaseCaptureOnMouseReleased() {
- return true;
-}
-
////////////////////////////////////////////////////////////////////////////////
// WidgetWin, private:

Powered by Google App Engine
This is Rietveld 408576698