OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "content/browser/renderer_host/legacy_render_widget_host_win.h" | |
6 | |
7 #include "base/win/windows_version.h" | |
8 #include "content/browser/accessibility/browser_accessibility_manager_win.h" | |
9 #include "content/browser/accessibility/browser_accessibility_win.h" | |
10 #include "ui/base/touch/touch_enabled.h" | |
11 #include "ui/gfx/geometry/rect.h" | |
12 | |
13 namespace content { | |
14 | |
15 LegacyRenderWidgetHostHWND::LegacyRenderWidgetHostHWND(HWND parent) | |
16 : manager_(NULL), | |
17 parent_(parent) { | |
18 RECT rect = {0}; | |
19 Create(parent, rect, NULL, WS_CHILDWINDOW, WS_EX_TRANSPARENT); | |
scottmg
2014/01/31 21:52:01
could you change the title to "Legacy Helper" or s
ananta
2014/01/31 23:56:26
Changed to Chrome Legacy Helper
| |
20 | |
21 if (base::win::GetVersion() >= base::win::VERSION_WIN7 && | |
22 ui::AreTouchEventsEnabled()) | |
23 RegisterTouchWindow(hwnd(), TWF_WANTPALM); | |
24 | |
25 HRESULT hr = ::CreateStdAccessibleObject( | |
26 hwnd(), OBJID_WINDOW, IID_IAccessible, | |
27 reinterpret_cast<void **>(window_accessible_.Receive())); | |
28 if (::IsWindow(hwnd())) { | |
29 mouse_window_bounds_tracker_.set_tracking_window(m_hWnd); | |
30 mouse_window_bounds_tracker_.SubclassWindow(parent_); | |
31 } | |
32 } | |
33 | |
34 LegacyRenderWidgetHostHWND::~LegacyRenderWidgetHostHWND() { | |
35 } | |
36 | |
37 void LegacyRenderWidgetHostHWND::OnManagerDeleted() { | |
38 manager_ = NULL; | |
39 } | |
40 | |
41 void LegacyRenderWidgetHostHWND::Show() { | |
42 ::ShowWindow(hwnd(), SW_SHOW); | |
43 } | |
44 | |
45 void LegacyRenderWidgetHostHWND::Hide() { | |
46 ::ShowWindow(hwnd(), SW_HIDE); | |
47 } | |
48 | |
49 void LegacyRenderWidgetHostHWND::OnFinalMessage(HWND hwnd) { | |
50 if (manager_) | |
51 manager_->OnAccessibleHwndDeleted(); | |
52 delete this; | |
53 } | |
54 | |
55 LRESULT LegacyRenderWidgetHostHWND::OnEraseBkGnd(UINT message, | |
56 WPARAM w_param, | |
57 LPARAM l_param) { | |
58 return 1; | |
59 } | |
60 | |
61 LRESULT LegacyRenderWidgetHostHWND::OnGetObject(UINT message, | |
62 WPARAM w_param, | |
63 LPARAM l_param) { | |
64 if (OBJID_CLIENT != l_param || !manager_) | |
65 return static_cast<LRESULT>(0L); | |
66 | |
67 base::win::ScopedComPtr<IAccessible> root( | |
68 manager_->GetRoot()->ToBrowserAccessibilityWin()); | |
69 return LresultFromObject(IID_IAccessible, w_param, | |
70 static_cast<IAccessible*>(root.Detach())); | |
71 } | |
72 | |
73 LRESULT LegacyRenderWidgetHostHWND::OnKeyboardRange(UINT message, | |
74 WPARAM w_param, | |
75 LPARAM l_param, | |
76 BOOL& handled) { | |
77 ::PostMessage(parent_, message, w_param, l_param); | |
78 return 0; | |
79 } | |
80 | |
81 LRESULT LegacyRenderWidgetHostHWND::OnMouseRange(UINT message, | |
82 WPARAM w_param, | |
83 LPARAM l_param, | |
84 BOOL& handled) { | |
85 // We won't receive mouse messages when capture is with the parent window. | |
86 // If we receive a mouse move then it means that parent capture was released. | |
87 // This would happen if we lost focus or if the mouse left our window bounds | |
88 // and we released capture. | |
89 if (message == WM_MOUSEMOVE) { | |
90 if (::GetCapture() != parent_) | |
91 ::SetCapture(parent_); | |
92 } | |
93 // TODO(ananta) | |
94 // This code should be restored/deleted prior to landing this, based on | |
95 // decisions as to whether capturing the parent window to ensure that all | |
96 // mouse messages go to it and the ensuing complexity with the same is worth | |
97 // the effort. Posting the message to the parent seems much simpler with | |
98 // the caveat of converting mouse messages into posted mouse messages which | |
99 // may lead to performance issues with the message pump and the fact that | |
100 // we need to peeks for every mouse event. | |
101 #if 0 | |
102 POINT mouse_coords; | |
103 mouse_coords.x = GET_X_LPARAM(l_param); | |
104 mouse_coords.y = GET_Y_LPARAM(l_param); | |
105 ::MapWindowPoints(hwnd(), parent_, &mouse_coords, 1); | |
106 ::PostMessage(parent_, message, w_param, | |
107 MAKELPARAM(mouse_coords.x, mouse_coords.y)); | |
108 #endif | |
109 return 0; | |
110 } | |
111 | |
112 LRESULT LegacyRenderWidgetHostHWND::OnNCPaint(UINT message, | |
113 WPARAM w_param, | |
114 LPARAM l_param) { | |
115 return 0; | |
116 } | |
117 | |
118 LRESULT LegacyRenderWidgetHostHWND::OnPaint(UINT message, | |
119 WPARAM w_param, | |
120 LPARAM l_param) { | |
121 PAINTSTRUCT ps = {0}; | |
122 ::BeginPaint(hwnd(), &ps); | |
123 ::EndPaint(hwnd(), &ps); | |
124 return 0; | |
125 } | |
126 | |
127 LRESULT LegacyRenderWidgetHostHWND::OnSetCursor(UINT message, | |
128 WPARAM w_param, | |
129 LPARAM l_param) { | |
130 return 0; | |
131 } | |
132 | |
133 LRESULT LegacyRenderWidgetHostHWND::OnTouch(UINT message, | |
134 WPARAM w_param, | |
135 LPARAM l_param) { | |
136 ::PostMessage(parent_, message, w_param, l_param); | |
137 return 0; | |
138 } | |
139 | |
140 LegacyRenderWidgetHostHWND:: | |
141 MouseWindowBoundsTracker::MouseWindowBoundsTracker() | |
142 : tracking_window_(NULL) { | |
143 } | |
144 | |
145 LegacyRenderWidgetHostHWND:: | |
146 MouseWindowBoundsTracker::~MouseWindowBoundsTracker() { | |
147 UnsubclassWindow(); | |
148 } | |
149 | |
150 LRESULT LegacyRenderWidgetHostHWND::MouseWindowBoundsTracker::OnMouseMove( | |
151 UINT message, WPARAM w_param, LPARAM l_param) { | |
152 SetMsgHandled(FALSE); | |
153 // Don't mess with the capture if mouse buttons are down. | |
154 const int mouse_down_flags = | |
155 MK_LBUTTON | MK_MBUTTON | MK_RBUTTON | MK_XBUTTON1 | MK_XBUTTON2; | |
156 if (::GetCapture() == m_hWnd && !(w_param & mouse_down_flags)) { | |
157 DCHECK(::IsWindow(tracking_window_)); | |
158 POINT pt = {0}; | |
159 pt.x = GET_X_LPARAM(l_param); | |
160 pt.y = GET_Y_LPARAM(l_param); | |
161 ::ClientToScreen(m_hWnd, &pt); | |
162 | |
163 RECT window_rect = {0}; | |
164 ::GetWindowRect(tracking_window_, &window_rect); | |
165 if (!::PtInRect(&window_rect, pt) || | |
166 ::WindowFromPoint(pt) != tracking_window_) { | |
167 ::ReleaseCapture(); | |
168 } | |
169 } | |
170 return 0; | |
171 } | |
172 | |
173 } // namespace content | |
OLD | NEW |