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

Side by Side Diff: content/browser/renderer_host/legacy_render_widget_host_win.cc

Issue 159713012: Don't track mouse events in HWNDMessageHandler when they are forwarded by the LegacyRenderWidgetHost (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 6 years, 10 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/renderer_host/legacy_render_widget_host_win.h" 5 #include "content/browser/renderer_host/legacy_render_widget_host_win.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/win/windows_version.h" 9 #include "base/win/windows_version.h"
10 #include "base/win/win_util.h"
10 #include "content/browser/accessibility/browser_accessibility_manager_win.h" 11 #include "content/browser/accessibility/browser_accessibility_manager_win.h"
11 #include "content/browser/accessibility/browser_accessibility_win.h" 12 #include "content/browser/accessibility/browser_accessibility_win.h"
12 #include "content/public/common/content_switches.h" 13 #include "content/public/common/content_switches.h"
13 #include "ui/base/touch/touch_enabled.h" 14 #include "ui/base/touch/touch_enabled.h"
14 #include "ui/gfx/geometry/rect.h" 15 #include "ui/gfx/geometry/rect.h"
15 16
16 namespace content { 17 namespace content {
17 18
18 LegacyRenderWidgetHostHWND::~LegacyRenderWidgetHostHWND() { 19 LegacyRenderWidgetHostHWND::~LegacyRenderWidgetHostHWND() {
19 ::DestroyWindow(hwnd()); 20 ::DestroyWindow(hwnd());
20 } 21 }
21 22
22 // static 23 // static
23 scoped_ptr<LegacyRenderWidgetHostHWND> LegacyRenderWidgetHostHWND::Create( 24 scoped_ptr<LegacyRenderWidgetHostHWND> LegacyRenderWidgetHostHWND::Create(
24 HWND parent) { 25 HWND parent) {
26 if (CommandLine::ForCurrentProcess()->HasSwitch(
27 switches::kDisableLegacyIntermediateWindow))
28 return scoped_ptr<LegacyRenderWidgetHostHWND>();
29
25 scoped_ptr<LegacyRenderWidgetHostHWND> legacy_window_instance; 30 scoped_ptr<LegacyRenderWidgetHostHWND> legacy_window_instance;
26 legacy_window_instance.reset(new LegacyRenderWidgetHostHWND(parent)); 31 legacy_window_instance.reset(new LegacyRenderWidgetHostHWND(parent));
27 // If we failed to create the child, or if the switch to disable the legacy 32 // If we failed to create the child, or if the switch to disable the legacy
28 // window is passed in, then return NULL. 33 // window is passed in, then return NULL.
29 if (!::IsWindow(legacy_window_instance->hwnd()) || 34 if (!::IsWindow(legacy_window_instance->hwnd()))
30 CommandLine::ForCurrentProcess()->HasSwitch(
31 switches::kDisableLegacyIntermediateWindow))
32 return scoped_ptr<LegacyRenderWidgetHostHWND>(); 35 return scoped_ptr<LegacyRenderWidgetHostHWND>();
33 36
34 legacy_window_instance->Init(); 37 legacy_window_instance->Init();
35 return legacy_window_instance.Pass(); 38 return legacy_window_instance.Pass();
36 } 39 }
37 40
38 void LegacyRenderWidgetHostHWND::UpdateParent(HWND parent) { 41 void LegacyRenderWidgetHostHWND::UpdateParent(HWND parent) {
39 ::SetParent(hwnd(), parent); 42 ::SetParent(hwnd(), parent);
40 // If the new parent is the desktop Window, then we disable the child window 43 // If the new parent is the desktop Window, then we disable the child window
41 // to ensure that it does not receive any input events. It should not because 44 // to ensure that it does not receive any input events. It should not because
42 // of WS_EX_TRANSPARENT. This is only for safety. 45 // of WS_EX_TRANSPARENT. This is only for safety.
43 if (parent == ::GetDesktopWindow()) { 46 if (parent == ::GetDesktopWindow()) {
(...skipping 23 matching lines...) Expand all
67 ::SetWindowPos(hwnd(), NULL, bounds.x(), bounds.y(), bounds.width(), 70 ::SetWindowPos(hwnd(), NULL, bounds.x(), bounds.y(), bounds.width(),
68 bounds.height(), 0); 71 bounds.height(), 0);
69 } 72 }
70 73
71 void LegacyRenderWidgetHostHWND::OnFinalMessage(HWND hwnd) { 74 void LegacyRenderWidgetHostHWND::OnFinalMessage(HWND hwnd) {
72 if (manager_) 75 if (manager_)
73 manager_->OnAccessibleHwndDeleted(); 76 manager_->OnAccessibleHwndDeleted();
74 } 77 }
75 78
76 LegacyRenderWidgetHostHWND::LegacyRenderWidgetHostHWND(HWND parent) 79 LegacyRenderWidgetHostHWND::LegacyRenderWidgetHostHWND(HWND parent)
77 : manager_(NULL) { 80 : manager_(NULL),
81 mouse_tracking_enabled_(false) {
78 RECT rect = {0}; 82 RECT rect = {0};
79 Base::Create(parent, rect, L"Chrome Legacy Window", 83 Base::Create(parent, rect, L"Chrome Legacy Window",
80 WS_CHILDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, 84 WS_CHILDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
81 WS_EX_TRANSPARENT); 85 WS_EX_TRANSPARENT);
82 } 86 }
83 87
84 bool LegacyRenderWidgetHostHWND::Init() { 88 bool LegacyRenderWidgetHostHWND::Init() {
85 if (base::win::GetVersion() >= base::win::VERSION_WIN7 && 89 if (base::win::GetVersion() >= base::win::VERSION_WIN7 &&
86 ui::AreTouchEventsEnabled()) 90 ui::AreTouchEventsEnabled())
87 RegisterTouchWindow(hwnd(), TWF_WANTPALM); 91 RegisterTouchWindow(hwnd(), TWF_WANTPALM);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 WPARAM w_param, 127 WPARAM w_param,
124 LPARAM l_param, 128 LPARAM l_param,
125 BOOL& handled) { 129 BOOL& handled) {
126 return ::SendMessage(GetParent(), message, w_param, l_param); 130 return ::SendMessage(GetParent(), message, w_param, l_param);
127 } 131 }
128 132
129 LRESULT LegacyRenderWidgetHostHWND::OnMouseRange(UINT message, 133 LRESULT LegacyRenderWidgetHostHWND::OnMouseRange(UINT message,
130 WPARAM w_param, 134 WPARAM w_param,
131 LPARAM l_param, 135 LPARAM l_param,
132 BOOL& handled) { 136 BOOL& handled) {
133 POINT mouse_coords; 137 // Mark the WM_MOUSEMOVE message with a special flag in the high word of
134 mouse_coords.x = GET_X_LPARAM(l_param); 138 // the WPARAM.
135 mouse_coords.y = GET_Y_LPARAM(l_param); 139 // The parent window has code to track mouse events, i.e to detect if the
136 ::MapWindowPoints(hwnd(), GetParent(), &mouse_coords, 1); 140 // cursor left the bounds of the parent window. Technically entering a child
137 return ::SendMessage(GetParent(), message, w_param, 141 // window indicates that the cursor left the parent window.
138 MAKELPARAM(mouse_coords.x, mouse_coords.y)); 142 // To ensure that the parent does not turn on tracking for the WM_MOUSEMOVE
143 // messages sent from us, we flag this in the WPARAM and track the mouse for
144 // our window to send the WM_MOUSELEAVE if needed to the parent.
145 if (message == WM_MOUSEMOVE) {
146 if (!mouse_tracking_enabled_) {
147 mouse_tracking_enabled_ = true;
148 TRACKMOUSEEVENT tme;
149 tme.cbSize = sizeof(tme);
150 tme.dwFlags = TME_LEAVE;
151 tme.hwndTrack = hwnd();
152 tme.dwHoverTime = 0;
153 TrackMouseEvent(&tme);
154 }
155 w_param = MAKEWPARAM(LOWORD(w_param), SPECIAL_MOUSEMOVE_NOT_TO_BE_TRACKED);
156 }
157
158 // The offsets in mouse wheel messages are in screen coordinates. We should
159 // not be converting them to parent coordinates.
160 if (message != WM_MOUSEWHEEL && message != WM_MOUSEHWHEEL) {
161 POINT mouse_coords;
162 mouse_coords.x = GET_X_LPARAM(l_param);
163 mouse_coords.y = GET_Y_LPARAM(l_param);
164 ::MapWindowPoints(hwnd(), GetParent(), &mouse_coords, 1);
165 l_param = MAKELPARAM(mouse_coords.x, mouse_coords.y);
166 }
167 return ::SendMessage(GetParent(), message, w_param, l_param);
168 }
169
170 LRESULT LegacyRenderWidgetHostHWND::OnMouseLeave(UINT message,
171 WPARAM w_param,
172 LPARAM l_param) {
173 mouse_tracking_enabled_ = false;
174 // We should send a WM_MOUSELEAVE to the parent window only if the mouse has
175 // moved outside the bounds of the parent.
176 POINT cursor_pos;
177 ::GetCursorPos(&cursor_pos);
178 if (::WindowFromPoint(cursor_pos) != GetParent())
179 return ::SendMessage(GetParent(), message, w_param, l_param);
180 return 0;
139 } 181 }
140 182
141 LRESULT LegacyRenderWidgetHostHWND::OnMouseActivate(UINT message, 183 LRESULT LegacyRenderWidgetHostHWND::OnMouseActivate(UINT message,
142 WPARAM w_param, 184 WPARAM w_param,
143 LPARAM l_param) { 185 LPARAM l_param) {
144 // Don't pass this to DefWindowProc. That results in the WM_MOUSEACTIVATE 186 // Don't pass this to DefWindowProc. That results in the WM_MOUSEACTIVATE
145 // message going all the way to the parent which then messes up state 187 // message going all the way to the parent which then messes up state
146 // related to focused views, etc. This is because it treats this as if 188 // related to focused views, etc. This is because it treats this as if
147 // it lost activation. 189 // it lost activation.
148 // Our dummy window should not interfere with focus and activation in 190 // Our dummy window should not interfere with focus and activation in
(...skipping 26 matching lines...) Expand all
175 return 0; 217 return 0;
176 } 218 }
177 219
178 LRESULT LegacyRenderWidgetHostHWND::OnSetCursor(UINT message, 220 LRESULT LegacyRenderWidgetHostHWND::OnSetCursor(UINT message,
179 WPARAM w_param, 221 WPARAM w_param,
180 LPARAM l_param) { 222 LPARAM l_param) {
181 return 0; 223 return 0;
182 } 224 }
183 225
184 } // namespace content 226 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/legacy_render_widget_host_win.h ('k') | ui/views/controls/menu/menu_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698