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