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 <memory> | 7 #include <memory> |
8 #include <utility> | |
9 | 8 |
10 #include "base/command_line.h" | 9 #include "base/command_line.h" |
11 #include "base/win/win_util.h" | 10 #include "base/win/win_util.h" |
12 #include "base/win/windows_version.h" | 11 #include "base/win/windows_version.h" |
13 #include "content/browser/accessibility/browser_accessibility_manager_win.h" | 12 #include "content/browser/accessibility/browser_accessibility_manager_win.h" |
14 #include "content/browser/accessibility/browser_accessibility_state_impl.h" | 13 #include "content/browser/accessibility/browser_accessibility_state_impl.h" |
15 #include "content/browser/accessibility/browser_accessibility_win.h" | 14 #include "content/browser/accessibility/browser_accessibility_win.h" |
16 #include "content/browser/renderer_host/render_widget_host_impl.h" | 15 #include "content/browser/renderer_host/render_widget_host_impl.h" |
17 #include "content/browser/renderer_host/render_widget_host_view_aura.h" | 16 #include "content/browser/renderer_host/render_widget_host_view_aura.h" |
18 #include "content/public/common/content_switches.h" | 17 #include "content/public/common/content_switches.h" |
19 #include "ui/accessibility/platform/ax_fake_caret_win.h" | |
20 #include "ui/base/view_prop.h" | 18 #include "ui/base/view_prop.h" |
21 #include "ui/base/win/internal_constants.h" | 19 #include "ui/base/win/internal_constants.h" |
22 #include "ui/base/win/window_event_target.h" | 20 #include "ui/base/win/window_event_target.h" |
23 #include "ui/display/win/screen_win.h" | 21 #include "ui/display/win/screen_win.h" |
24 #include "ui/gfx/geometry/rect.h" | 22 #include "ui/gfx/geometry/rect.h" |
25 #include "ui/gfx/win/direct_manipulation.h" | 23 #include "ui/gfx/win/direct_manipulation.h" |
26 | 24 |
27 namespace content { | 25 namespace content { |
28 | 26 |
29 // A custom MSAA object id used to determine if a screen reader or some | 27 // A custom MSAA object id used to determine if a screen reader or some |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 void LegacyRenderWidgetHostHWND::SetBounds(const gfx::Rect& bounds) { | 78 void LegacyRenderWidgetHostHWND::SetBounds(const gfx::Rect& bounds) { |
81 gfx::Rect bounds_in_pixel = display::win::ScreenWin::DIPToClientRect(hwnd(), | 79 gfx::Rect bounds_in_pixel = display::win::ScreenWin::DIPToClientRect(hwnd(), |
82 bounds); | 80 bounds); |
83 ::SetWindowPos(hwnd(), NULL, bounds_in_pixel.x(), bounds_in_pixel.y(), | 81 ::SetWindowPos(hwnd(), NULL, bounds_in_pixel.x(), bounds_in_pixel.y(), |
84 bounds_in_pixel.width(), bounds_in_pixel.height(), | 82 bounds_in_pixel.width(), bounds_in_pixel.height(), |
85 SWP_NOREDRAW); | 83 SWP_NOREDRAW); |
86 if (direct_manipulation_helper_) | 84 if (direct_manipulation_helper_) |
87 direct_manipulation_helper_->SetBounds(bounds_in_pixel); | 85 direct_manipulation_helper_->SetBounds(bounds_in_pixel); |
88 } | 86 } |
89 | 87 |
90 void LegacyRenderWidgetHostHWND::MoveCaretTo(const gfx::Rect& bounds) { | |
91 DCHECK(ax_fake_caret_); | |
92 ax_fake_caret_->MoveCaretTo(bounds); | |
93 } | |
94 | |
95 void LegacyRenderWidgetHostHWND::OnFinalMessage(HWND hwnd) { | 88 void LegacyRenderWidgetHostHWND::OnFinalMessage(HWND hwnd) { |
96 if (host_) { | 89 if (host_) { |
97 host_->OnLegacyWindowDestroyed(); | 90 host_->OnLegacyWindowDestroyed(); |
98 host_ = NULL; | 91 host_ = NULL; |
99 } | 92 } |
100 | 93 |
101 // Re-enable flicks for just a moment | 94 // Re-enable flicks for just a moment |
102 base::win::EnableFlicks(hwnd); | 95 base::win::EnableFlicks(hwnd); |
103 | 96 |
104 delete this; | 97 delete this; |
105 } | 98 } |
106 | 99 |
107 LegacyRenderWidgetHostHWND::LegacyRenderWidgetHostHWND(HWND parent) | 100 LegacyRenderWidgetHostHWND::LegacyRenderWidgetHostHWND(HWND parent) |
108 : mouse_tracking_enabled_(false), host_(nullptr) { | 101 : mouse_tracking_enabled_(false), host_(NULL) { |
109 RECT rect = {0}; | 102 RECT rect = {0}; |
110 Base::Create(parent, rect, L"Chrome Legacy Window", | 103 Base::Create(parent, rect, L"Chrome Legacy Window", |
111 WS_CHILDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, | 104 WS_CHILDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, |
112 WS_EX_TRANSPARENT); | 105 WS_EX_TRANSPARENT); |
113 // We create the fake caret regardless of accessibility mode since not all | |
114 // assistive software that makes use of a fake caret is classified as a screen | |
115 // reader, e.g. the built-in Windows Magnifier. | |
116 ax_fake_caret_ = std::make_unique<ui::AXFakeCaretWin>(hwnd()); | |
117 } | 106 } |
118 | 107 |
119 LegacyRenderWidgetHostHWND::~LegacyRenderWidgetHostHWND() { | 108 LegacyRenderWidgetHostHWND::~LegacyRenderWidgetHostHWND() { |
120 DCHECK(!::IsWindow(hwnd())); | 109 DCHECK(!::IsWindow(hwnd())); |
121 } | 110 } |
122 | 111 |
123 bool LegacyRenderWidgetHostHWND::Init() { | 112 bool LegacyRenderWidgetHostHWND::Init() { |
124 if (base::win::GetVersion() >= base::win::VERSION_WIN7) | 113 if (base::win::GetVersion() >= base::win::VERSION_WIN7) |
125 RegisterTouchWindow(hwnd(), TWF_WANTPALM); | 114 RegisterTouchWindow(hwnd(), TWF_WANTPALM); |
126 | 115 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 | 162 |
174 if (kIdScreenReaderHoneyPot == obj_id) { | 163 if (kIdScreenReaderHoneyPot == obj_id) { |
175 // When an MSAA client has responded to our fake event on this id, | 164 // When an MSAA client has responded to our fake event on this id, |
176 // enable basic accessibility support. (Full screen reader support is | 165 // enable basic accessibility support. (Full screen reader support is |
177 // detected later when specific more advanced APIs are accessed.) | 166 // detected later when specific more advanced APIs are accessed.) |
178 BrowserAccessibilityStateImpl::GetInstance()->AddAccessibilityModeFlags( | 167 BrowserAccessibilityStateImpl::GetInstance()->AddAccessibilityModeFlags( |
179 AccessibilityMode::kNativeAPIs | AccessibilityMode::kWebContents); | 168 AccessibilityMode::kNativeAPIs | AccessibilityMode::kWebContents); |
180 return static_cast<LRESULT>(0L); | 169 return static_cast<LRESULT>(0L); |
181 } | 170 } |
182 | 171 |
183 if (!host_) | 172 if (static_cast<DWORD>(OBJID_CLIENT) != obj_id || !host_) |
184 return static_cast<LRESULT>(0L); | 173 return static_cast<LRESULT>(0L); |
185 | 174 |
186 if (static_cast<DWORD>(OBJID_CLIENT) == obj_id) { | 175 RenderWidgetHostImpl* rwhi = |
187 RenderWidgetHostImpl* rwhi = | 176 RenderWidgetHostImpl::From(host_->GetRenderWidgetHost()); |
188 RenderWidgetHostImpl::From(host_->GetRenderWidgetHost()); | 177 if (!rwhi) |
189 if (!rwhi) | 178 return static_cast<LRESULT>(0L); |
190 return static_cast<LRESULT>(0L); | |
191 | 179 |
192 BrowserAccessibilityManagerWin* manager = | 180 BrowserAccessibilityManagerWin* manager = |
193 static_cast<BrowserAccessibilityManagerWin*>( | 181 static_cast<BrowserAccessibilityManagerWin*>( |
194 rwhi->GetRootBrowserAccessibilityManager()); | 182 rwhi->GetRootBrowserAccessibilityManager()); |
195 if (!manager) | 183 if (!manager) |
196 return static_cast<LRESULT>(0L); | 184 return static_cast<LRESULT>(0L); |
197 | 185 |
198 base::win::ScopedComPtr<IAccessible> root( | 186 base::win::ScopedComPtr<IAccessible> root( |
199 ToBrowserAccessibilityWin(manager->GetRoot())); | 187 ToBrowserAccessibilityWin(manager->GetRoot())); |
200 return LresultFromObject(IID_IAccessible, w_param, | 188 return LresultFromObject(IID_IAccessible, w_param, |
201 static_cast<IAccessible*>(root.Detach())); | 189 static_cast<IAccessible*>(root.Detach())); |
202 } | |
203 | |
204 if (static_cast<DWORD>(OBJID_CARET) == obj_id && host_->HasFocus()) { | |
205 DCHECK(ax_fake_caret_); | |
206 base::win::ScopedComPtr<IAccessible> fake_caret_accessible = | |
207 ax_fake_caret_->GetCaret(); | |
208 return LresultFromObject(IID_IAccessible, w_param, | |
209 fake_caret_accessible.Detach()); | |
210 } | |
211 | |
212 return static_cast<LRESULT>(0L); | |
213 } | 190 } |
214 | 191 |
215 // We send keyboard/mouse/touch messages to the parent window via SendMessage. | 192 // We send keyboard/mouse/touch messages to the parent window via SendMessage. |
216 // While this works, this has the side effect of converting input messages into | 193 // While this works, this has the side effect of converting input messages into |
217 // sent messages which changes their priority and could technically result | 194 // sent messages which changes their priority and could technically result |
218 // in these messages starving other messages in the queue. Additionally | 195 // in these messages starving other messages in the queue. Additionally |
219 // keyboard/mouse hooks would not see these messages. The alternative approach | 196 // keyboard/mouse hooks would not see these messages. The alternative approach |
220 // is to set and release capture as needed on the parent to ensure that it | 197 // is to set and release capture as needed on the parent to ensure that it |
221 // receives all mouse events. However that was shelved due to possible issues | 198 // receives all mouse events. However that was shelved due to possible issues |
222 // with capture changes. | 199 // with capture changes. |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 direct_manipulation_helper_->Activate(hwnd()); | 420 direct_manipulation_helper_->Activate(hwnd()); |
444 } else if (window_pos->flags & SWP_HIDEWINDOW) { | 421 } else if (window_pos->flags & SWP_HIDEWINDOW) { |
445 direct_manipulation_helper_->Deactivate(hwnd()); | 422 direct_manipulation_helper_->Deactivate(hwnd()); |
446 } | 423 } |
447 } | 424 } |
448 SetMsgHandled(FALSE); | 425 SetMsgHandled(FALSE); |
449 return 0; | 426 return 0; |
450 } | 427 } |
451 | 428 |
452 } // namespace content | 429 } // namespace content |
OLD | NEW |