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