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/memory/scoped_ptr.h" | |
8 #include "base/win/windows_version.h" | |
9 #include "content/browser/accessibility/browser_accessibility_manager_win.h" | |
10 #include "content/browser/accessibility/browser_accessibility_win.h" | |
11 #include "ui/base/touch/touch_enabled.h" | |
12 #include "ui/gfx/geometry/rect.h" | |
13 | |
14 namespace content { | |
15 | |
16 // static | |
17 scoped_ptr<LegacyRenderWidgetHostHWND> LegacyRenderWidgetHostHWND::Create(HWND p arent) { | |
sky
2014/02/06 00:58:41
nit: > 80
ananta
2014/02/06 01:15:58
Done
| |
18 scoped_ptr<LegacyRenderWidgetHostHWND> legacy_window_instance; | |
19 legacy_window_instance.reset(new LegacyRenderWidgetHostHWND(parent)); | |
20 // If we failed to create the child, then return NULL. | |
21 if (!::IsWindow(legacy_window_instance->hwnd())) | |
22 return scoped_ptr<LegacyRenderWidgetHostHWND>(); | |
23 | |
24 legacy_window_instance->Init(); | |
25 return legacy_window_instance.Pass(); | |
26 } | |
27 | |
28 LegacyRenderWidgetHostHWND::~LegacyRenderWidgetHostHWND() { | |
29 ::DestroyWindow(hwnd()); | |
30 } | |
31 | |
32 void LegacyRenderWidgetHostHWND::UpdateParent(HWND parent) { | |
33 ::SetParent(hwnd(), parent); | |
34 // If the new parent is the desktop Window, then we disable the child window | |
35 // to ensure that it does not receive any input events. It should not because | |
36 // of WS_EX_TRANSPARENT. This is only for safety. | |
37 if (parent == ::GetDesktopWindow()) { | |
38 ::EnableWindow(hwnd(), FALSE); | |
39 } else { | |
40 ::EnableWindow(hwnd(), TRUE); | |
41 } | |
42 } | |
43 | |
44 HWND LegacyRenderWidgetHostHWND::GetParent() { | |
45 return ::GetParent(hwnd()); | |
46 } | |
47 | |
48 void LegacyRenderWidgetHostHWND::OnManagerDeleted() { | |
49 manager_ = NULL; | |
50 } | |
51 | |
52 void LegacyRenderWidgetHostHWND::Show() { | |
53 ::ShowWindow(hwnd(), SW_SHOW); | |
54 } | |
55 | |
56 void LegacyRenderWidgetHostHWND::Hide() { | |
57 ::ShowWindow(hwnd(), SW_HIDE); | |
58 } | |
59 | |
60 void LegacyRenderWidgetHostHWND::SetBounds(const gfx::Rect& bounds) { | |
61 ::SetWindowPos(hwnd(), NULL, bounds.x(), bounds.y(), bounds.width(), | |
62 bounds.height(), 0); | |
63 } | |
64 | |
65 void LegacyRenderWidgetHostHWND::OnFinalMessage(HWND hwnd) { | |
66 if (manager_) | |
67 manager_->OnAccessibleHwndDeleted(); | |
68 } | |
69 | |
70 LegacyRenderWidgetHostHWND::LegacyRenderWidgetHostHWND(HWND parent) | |
71 : manager_(NULL) { | |
72 RECT rect = {0}; | |
73 Base::Create(parent, rect, L"Chrome Legacy Window", WS_CHILDWINDOW, | |
74 WS_EX_TRANSPARENT); | |
75 } | |
76 | |
77 bool LegacyRenderWidgetHostHWND::Init() { | |
78 if (base::win::GetVersion() >= base::win::VERSION_WIN7 && | |
79 ui::AreTouchEventsEnabled()) | |
80 RegisterTouchWindow(hwnd(), TWF_WANTPALM); | |
81 | |
82 HRESULT hr = ::CreateStdAccessibleObject( | |
83 hwnd(), OBJID_WINDOW, IID_IAccessible, | |
84 reinterpret_cast<void **>(window_accessible_.Receive())); | |
85 DCHECK(SUCCEEDED(hr)); | |
86 return !!SUCCEEDED(hr); | |
87 } | |
88 | |
89 LRESULT LegacyRenderWidgetHostHWND::OnEraseBkGnd(UINT message, | |
90 WPARAM w_param, | |
91 LPARAM l_param) { | |
92 return 1; | |
93 } | |
94 | |
95 LRESULT LegacyRenderWidgetHostHWND::OnGetObject(UINT message, | |
96 WPARAM w_param, | |
97 LPARAM l_param) { | |
98 if (OBJID_CLIENT != l_param || !manager_) | |
99 return static_cast<LRESULT>(0L); | |
100 | |
101 base::win::ScopedComPtr<IAccessible> root( | |
102 manager_->GetRoot()->ToBrowserAccessibilityWin()); | |
103 return LresultFromObject(IID_IAccessible, w_param, | |
104 static_cast<IAccessible*>(root.Detach())); | |
105 } | |
106 | |
107 // We send keyboard/mouse/touch messages to the parent window via SendMessage. | |
108 // While this works, this has the side effect of converting input messages into | |
109 // sent messages which changes their priority and could technically result | |
110 // in these messages starving other messages in the queue. Additionally | |
111 // keyboard/mouse hooks would not see these messages. The alternative approach | |
112 // is to set and release capture as needed on the parent to ensure that it | |
113 // receives all mouse events. However that was shelved due to possible issues | |
114 // with capture changes. | |
115 LRESULT LegacyRenderWidgetHostHWND::OnKeyboardRange(UINT message, | |
116 WPARAM w_param, | |
117 LPARAM l_param, | |
118 BOOL& handled) { | |
119 return ::SendMessage(GetParent(), message, w_param, l_param); | |
120 } | |
121 | |
122 LRESULT LegacyRenderWidgetHostHWND::OnMouseRange(UINT message, | |
123 WPARAM w_param, | |
124 LPARAM l_param, | |
125 BOOL& handled) { | |
126 POINT mouse_coords; | |
127 mouse_coords.x = GET_X_LPARAM(l_param); | |
128 mouse_coords.y = GET_Y_LPARAM(l_param); | |
129 ::MapWindowPoints(hwnd(), GetParent(), &mouse_coords, 1); | |
130 return ::SendMessage(GetParent(), message, w_param, | |
131 MAKELPARAM(mouse_coords.x, mouse_coords.y)); | |
132 } | |
133 | |
134 LRESULT LegacyRenderWidgetHostHWND::OnMouseActivate(UINT message, | |
135 WPARAM w_param, | |
136 LPARAM l_param) { | |
137 // Don't pass this to DefWindowProc. That results in the WM_MOUSEACTIVATE | |
138 // message going all the way to the parent which then messes up state | |
139 // related to focused views, etc. This is because it treats this as if | |
140 // it lost activation. | |
141 // Our dummy window should not interfere with focus and activation in | |
142 // the parent. Return MA_ACTIVATE here ensures that focus state in the parent | |
143 // is preserved. | |
144 return MA_ACTIVATE; | |
145 } | |
146 | |
147 LRESULT LegacyRenderWidgetHostHWND::OnTouch(UINT message, | |
148 WPARAM w_param, | |
149 LPARAM l_param) { | |
150 return ::SendMessage(GetParent(), message, w_param, l_param); | |
151 } | |
152 | |
153 LRESULT LegacyRenderWidgetHostHWND::OnNCPaint(UINT message, | |
154 WPARAM w_param, | |
155 LPARAM l_param) { | |
156 return 0; | |
157 } | |
158 | |
159 LRESULT LegacyRenderWidgetHostHWND::OnPaint(UINT message, | |
160 WPARAM w_param, | |
161 LPARAM l_param) { | |
162 PAINTSTRUCT ps = {0}; | |
163 ::BeginPaint(hwnd(), &ps); | |
164 ::EndPaint(hwnd(), &ps); | |
165 return 0; | |
166 } | |
167 | |
168 LRESULT LegacyRenderWidgetHostHWND::OnSetCursor(UINT message, | |
169 WPARAM w_param, | |
170 LPARAM l_param) { | |
171 return 0; | |
172 } | |
173 | |
174 } // namespace content | |
OLD | NEW |