Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: content/browser/renderer_host/legacy_render_widget_host_win.cc

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

Powered by Google App Engine
This is Rietveld 408576698