OLD | NEW |
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 "content/browser/accessibility/browser_accessibility_manager_win.h" | 10 #include "content/browser/renderer_host/legacy_render_widget_host_win_delegate.h
" |
11 #include "content/browser/accessibility/browser_accessibility_win.h" | |
12 #include "content/browser/renderer_host/render_widget_host_impl.h" | 11 #include "content/browser/renderer_host/render_widget_host_impl.h" |
13 #include "content/browser/renderer_host/render_widget_host_view_aura.h" | 12 #include "content/browser/renderer_host/render_widget_host_view_aura.h" |
14 #include "content/public/browser/browser_accessibility_state.h" | 13 #include "content/public/browser/browser_accessibility_state.h" |
15 #include "content/public/common/content_switches.h" | 14 #include "content/public/common/content_switches.h" |
16 #include "ui/base/touch/touch_enabled.h" | 15 #include "ui/base/touch/touch_enabled.h" |
17 #include "ui/base/view_prop.h" | 16 #include "ui/base/view_prop.h" |
18 #include "ui/base/win/internal_constants.h" | 17 #include "ui/base/win/internal_constants.h" |
19 #include "ui/base/win/window_event_target.h" | 18 #include "ui/base/win/window_event_target.h" |
20 #include "ui/gfx/geometry/rect.h" | 19 #include "ui/gfx/geometry/rect.h" |
21 #include "ui/gfx/win/dpi.h" | 20 #include "ui/gfx/win/dpi.h" |
22 | 21 |
23 namespace content { | 22 namespace content { |
24 | 23 |
| 24 namespace { |
| 25 |
25 // A custom MSAA object id used to determine if a screen reader or some | 26 // A custom MSAA object id used to determine if a screen reader or some |
26 // other client is listening on MSAA events - if so, we enable full web | 27 // other client is listening on MSAA events - if so, we enable full web |
27 // accessibility support. | 28 // accessibility support. |
28 const int kIdScreenReaderHoneyPot = 1; | 29 const int kIdScreenReaderHoneyPot = 1; |
29 | 30 |
| 31 } // namespace |
| 32 |
| 33 LegacyRenderWidgetHostHWND::~LegacyRenderWidgetHostHWND() { |
| 34 if (::IsWindow(hwnd())) |
| 35 ::DestroyWindow(hwnd()); |
| 36 } |
| 37 |
30 // static | 38 // static |
31 LegacyRenderWidgetHostHWND* LegacyRenderWidgetHostHWND::Create( | 39 LegacyRenderWidgetHostHWND* LegacyRenderWidgetHostHWND::Create( |
32 HWND parent) { | 40 HWND parent, |
33 // content_unittests passes in the desktop window as the parent. We allow | 41 LegacyRenderWidgetHostHWNDDelegate* delegate) { |
34 // the LegacyRenderWidgetHostHWND instance to be created in this case for | |
35 // these tests to pass. | |
36 if (CommandLine::ForCurrentProcess()->HasSwitch( | 42 if (CommandLine::ForCurrentProcess()->HasSwitch( |
37 switches::kDisableLegacyIntermediateWindow) || | 43 switches::kDisableLegacyIntermediateWindow)) { |
38 (!GetWindowEventTarget(parent) && parent != ::GetDesktopWindow())) | 44 return nullptr; |
39 return NULL; | 45 } |
40 | 46 |
41 LegacyRenderWidgetHostHWND* legacy_window_instance = | 47 LegacyRenderWidgetHostHWND* legacy_window_instance = |
42 new LegacyRenderWidgetHostHWND(parent); | 48 new LegacyRenderWidgetHostHWND(parent, delegate); |
43 // If we failed to create the child, or if the switch to disable the legacy | 49 // If we failed to create the child, return NULL. |
44 // window is passed in, then return NULL. | |
45 if (!::IsWindow(legacy_window_instance->hwnd())) { | 50 if (!::IsWindow(legacy_window_instance->hwnd())) { |
46 delete legacy_window_instance; | 51 delete legacy_window_instance; |
47 return NULL; | 52 return nullptr; |
48 } | 53 } |
49 legacy_window_instance->Init(); | 54 legacy_window_instance->Init(); |
50 return legacy_window_instance; | 55 return legacy_window_instance; |
51 } | 56 } |
52 | 57 |
53 void LegacyRenderWidgetHostHWND::Destroy() { | 58 void LegacyRenderWidgetHostHWND::UpdateParent(HWND parent) { |
54 if (::IsWindow(hwnd())) | 59 if (!::IsWindow(hwnd())) |
55 ::DestroyWindow(hwnd()); | 60 return; |
56 } | |
57 | 61 |
58 void LegacyRenderWidgetHostHWND::UpdateParent(HWND parent) { | |
59 ::SetParent(hwnd(), parent); | 62 ::SetParent(hwnd(), parent); |
60 // If the new parent is the desktop Window, then we disable the child window | 63 // If the new parent is the desktop Window, then we disable the child window |
61 // to ensure that it does not receive any input events. It should not because | 64 // to ensure that it does not receive any input events. It should not because |
62 // of WS_EX_TRANSPARENT. This is only for safety. | 65 // of WS_EX_TRANSPARENT. This is only for safety. |
63 if (parent == ::GetDesktopWindow()) { | 66 if (parent == ::GetDesktopWindow()) { |
64 ::EnableWindow(hwnd(), FALSE); | 67 ::EnableWindow(hwnd(), FALSE); |
65 } else { | 68 } else { |
66 ::EnableWindow(hwnd(), TRUE); | 69 ::EnableWindow(hwnd(), TRUE); |
67 } | 70 } |
68 } | 71 } |
69 | 72 |
70 HWND LegacyRenderWidgetHostHWND::GetParent() { | 73 HWND LegacyRenderWidgetHostHWND::GetParent() { |
| 74 if (!::IsWindow(hwnd())) |
| 75 return NULL; |
| 76 |
71 return ::GetParent(hwnd()); | 77 return ::GetParent(hwnd()); |
72 } | 78 } |
73 | 79 |
74 void LegacyRenderWidgetHostHWND::Show() { | 80 void LegacyRenderWidgetHostHWND::Show() { |
75 ::ShowWindow(hwnd(), SW_SHOW); | 81 if (::IsWindow(hwnd())) |
| 82 ::ShowWindow(hwnd(), SW_SHOW); |
76 } | 83 } |
77 | 84 |
78 void LegacyRenderWidgetHostHWND::Hide() { | 85 void LegacyRenderWidgetHostHWND::Hide() { |
79 ::ShowWindow(hwnd(), SW_HIDE); | 86 if (::IsWindow(hwnd())) |
| 87 ::ShowWindow(hwnd(), SW_HIDE); |
80 } | 88 } |
81 | 89 |
82 void LegacyRenderWidgetHostHWND::SetBounds(const gfx::Rect& bounds) { | 90 void LegacyRenderWidgetHostHWND::SetBounds(const gfx::Rect& bounds) { |
| 91 if (!::IsWindow(hwnd())) |
| 92 return; |
| 93 |
83 gfx::Rect bounds_in_pixel = gfx::win::DIPToScreenRect(bounds); | 94 gfx::Rect bounds_in_pixel = gfx::win::DIPToScreenRect(bounds); |
84 ::SetWindowPos(hwnd(), NULL, bounds_in_pixel.x(), bounds_in_pixel.y(), | 95 ::SetWindowPos(hwnd(), NULL, bounds_in_pixel.x(), bounds_in_pixel.y(), |
85 bounds_in_pixel.width(), bounds_in_pixel.height(), | 96 bounds_in_pixel.width(), bounds_in_pixel.height(), |
86 SWP_NOREDRAW); | 97 SWP_NOREDRAW); |
87 } | 98 } |
88 | 99 |
89 void LegacyRenderWidgetHostHWND::OnFinalMessage(HWND hwnd) { | 100 LegacyRenderWidgetHostHWND::LegacyRenderWidgetHostHWND( |
90 if (host_) { | 101 HWND parent, |
91 host_->OnLegacyWindowDestroyed(); | 102 LegacyRenderWidgetHostHWNDDelegate* delegate) |
92 host_ = NULL; | |
93 } | |
94 delete this; | |
95 } | |
96 | |
97 LegacyRenderWidgetHostHWND::LegacyRenderWidgetHostHWND(HWND parent) | |
98 : mouse_tracking_enabled_(false), | 103 : mouse_tracking_enabled_(false), |
99 host_(NULL) { | 104 delegate_(delegate) { |
| 105 DCHECK(delegate_); |
100 RECT rect = {0}; | 106 RECT rect = {0}; |
101 Base::Create(parent, rect, L"Chrome Legacy Window", | 107 Base::Create(parent, rect, L"Chrome Legacy Window", |
102 WS_CHILDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, | 108 WS_CHILDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, |
103 WS_EX_TRANSPARENT); | 109 WS_EX_TRANSPARENT); |
104 } | 110 } |
105 | 111 |
106 LegacyRenderWidgetHostHWND::~LegacyRenderWidgetHostHWND() { | |
107 DCHECK(!::IsWindow(hwnd())); | |
108 } | |
109 | |
110 bool LegacyRenderWidgetHostHWND::Init() { | 112 bool LegacyRenderWidgetHostHWND::Init() { |
111 if (base::win::GetVersion() >= base::win::VERSION_WIN7 && | 113 if (base::win::GetVersion() >= base::win::VERSION_WIN7 && |
112 ui::AreTouchEventsEnabled()) | 114 ui::AreTouchEventsEnabled()) { |
113 RegisterTouchWindow(hwnd(), TWF_WANTPALM); | 115 RegisterTouchWindow(hwnd(), TWF_WANTPALM); |
| 116 } |
114 | 117 |
115 HRESULT hr = ::CreateStdAccessibleObject( | 118 HRESULT hr = ::CreateStdAccessibleObject( |
116 hwnd(), OBJID_WINDOW, IID_IAccessible, | 119 hwnd(), OBJID_WINDOW, IID_IAccessible, |
117 reinterpret_cast<void **>(window_accessible_.Receive())); | 120 reinterpret_cast<void **>(window_accessible_.Receive())); |
118 DCHECK(SUCCEEDED(hr)); | 121 DCHECK(SUCCEEDED(hr)); |
119 | 122 |
120 if (!BrowserAccessibilityState::GetInstance()->IsAccessibleBrowser()) { | 123 if (!BrowserAccessibilityState::GetInstance()->IsAccessibleBrowser()) { |
121 // Attempt to detect screen readers or other clients who want full | 124 // Attempt to detect screen readers or other clients who want full |
122 // accessibility support, by seeing if they respond to this event. | 125 // accessibility support, by seeing if they respond to this event. |
123 NotifyWinEvent(EVENT_SYSTEM_ALERT, hwnd(), kIdScreenReaderHoneyPot, | 126 NotifyWinEvent(EVENT_SYSTEM_ALERT, hwnd(), kIdScreenReaderHoneyPot, |
(...skipping 23 matching lines...) Expand all Loading... |
147 // because it sometimes gets sign-extended incorrectly (but not always). | 150 // because it sometimes gets sign-extended incorrectly (but not always). |
148 DWORD obj_id = static_cast<DWORD>(static_cast<DWORD_PTR>(l_param)); | 151 DWORD obj_id = static_cast<DWORD>(static_cast<DWORD_PTR>(l_param)); |
149 | 152 |
150 if (kIdScreenReaderHoneyPot == obj_id) { | 153 if (kIdScreenReaderHoneyPot == obj_id) { |
151 // When an MSAA client has responded to our fake event on this id, | 154 // When an MSAA client has responded to our fake event on this id, |
152 // enable screen reader support. | 155 // enable screen reader support. |
153 BrowserAccessibilityState::GetInstance()->OnScreenReaderDetected(); | 156 BrowserAccessibilityState::GetInstance()->OnScreenReaderDetected(); |
154 return static_cast<LRESULT>(0L); | 157 return static_cast<LRESULT>(0L); |
155 } | 158 } |
156 | 159 |
157 if (OBJID_CLIENT != obj_id || !host_) | 160 if (OBJID_CLIENT != obj_id) |
158 return static_cast<LRESULT>(0L); | 161 return static_cast<LRESULT>(0L); |
159 | 162 |
160 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From( | 163 base::win::ScopedComPtr<IAccessible> native_accessible( |
161 host_->GetRenderWidgetHost()); | 164 delegate_->GetNativeViewAccessible()); |
162 if (!rwhi) | 165 if (!native_accessible) |
163 return static_cast<LRESULT>(0L); | 166 return static_cast<LRESULT>(0L); |
164 | 167 |
165 BrowserAccessibilityManagerWin* manager = | |
166 static_cast<BrowserAccessibilityManagerWin*>( | |
167 rwhi->GetRootBrowserAccessibilityManager()); | |
168 if (!manager) | |
169 return static_cast<LRESULT>(0L); | |
170 | |
171 base::win::ScopedComPtr<IAccessible> root( | |
172 manager->GetRoot()->ToBrowserAccessibilityWin()); | |
173 return LresultFromObject(IID_IAccessible, w_param, | 168 return LresultFromObject(IID_IAccessible, w_param, |
174 static_cast<IAccessible*>(root.Detach())); | 169 static_cast<IAccessible*>(native_accessible.Detach())); |
175 } | 170 } |
176 | 171 |
177 // We send keyboard/mouse/touch messages to the parent window via SendMessage. | 172 // We send keyboard/mouse/touch messages to the parent window via SendMessage. |
178 // While this works, this has the side effect of converting input messages into | 173 // While this works, this has the side effect of converting input messages into |
179 // sent messages which changes their priority and could technically result | 174 // sent messages which changes their priority and could technically result |
180 // in these messages starving other messages in the queue. Additionally | 175 // in these messages starving other messages in the queue. Additionally |
181 // keyboard/mouse hooks would not see these messages. The alternative approach | 176 // keyboard/mouse hooks would not see these messages. The alternative approach |
182 // is to set and release capture as needed on the parent to ensure that it | 177 // is to set and release capture as needed on the parent to ensure that it |
183 // receives all mouse events. However that was shelved due to possible issues | 178 // receives all mouse events. However that was shelved due to possible issues |
184 // with capture changes. | 179 // with capture changes. |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 // generate the legacy WM_VSCROLL/WM_HSCROLL messages. | 366 // generate the legacy WM_VSCROLL/WM_HSCROLL messages. |
372 // We add these styles to ensure that trackpad/trackpoint scrolling | 367 // We add these styles to ensure that trackpad/trackpoint scrolling |
373 // work. | 368 // work. |
374 long current_style = ::GetWindowLong(hwnd(), GWL_STYLE); | 369 long current_style = ::GetWindowLong(hwnd(), GWL_STYLE); |
375 ::SetWindowLong(hwnd(), GWL_STYLE, | 370 ::SetWindowLong(hwnd(), GWL_STYLE, |
376 current_style | WS_VSCROLL | WS_HSCROLL); | 371 current_style | WS_VSCROLL | WS_HSCROLL); |
377 return 0; | 372 return 0; |
378 } | 373 } |
379 | 374 |
380 } // namespace content | 375 } // namespace content |
OLD | NEW |