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

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: Check legacy_hwnd_ before using Created 6 years, 2 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 11 matching lines...) Expand all
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(), 79 bounds_in_pixel.width(), bounds_in_pixel.height(),
86 SWP_NOREDRAW); 80 SWP_NOREDRAW);
87 } 81 }
88 82
89 void LegacyRenderWidgetHostHWND::OnFinalMessage(HWND hwnd) { 83 LegacyRenderWidgetHostHWND::LegacyRenderWidgetHostHWND(
sky 2014/10/27 15:21:33 If you're going to allow this class to exist after
dmazzoni 2014/10/27 20:32:32 Good idea, added.
90 if (host_) { 84 HWND parent,
91 host_->OnLegacyWindowDestroyed(); 85 LegacyRenderWidgetHostHWNDDelegate* delegate)
92 host_ = NULL;
93 }
94 delete this;
95 }
96
97 LegacyRenderWidgetHostHWND::LegacyRenderWidgetHostHWND(HWND parent)
98 : mouse_tracking_enabled_(false), 86 : mouse_tracking_enabled_(false),
99 host_(NULL) { 87 delegate_(delegate) {
100 RECT rect = {0}; 88 RECT rect = {0};
101 Base::Create(parent, rect, L"Chrome Legacy Window", 89 Base::Create(parent, rect, L"Chrome Legacy Window",
102 WS_CHILDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, 90 WS_CHILDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
103 WS_EX_TRANSPARENT); 91 WS_EX_TRANSPARENT);
104 } 92 }
105 93
106 LegacyRenderWidgetHostHWND::~LegacyRenderWidgetHostHWND() { 94 LegacyRenderWidgetHostHWND::~LegacyRenderWidgetHostHWND() {
107 DCHECK(!::IsWindow(hwnd())); 95 if (::IsWindow(hwnd()))
96 ::DestroyWindow(hwnd());
108 } 97 }
109 98
110 bool LegacyRenderWidgetHostHWND::Init() { 99 bool LegacyRenderWidgetHostHWND::Init() {
111 if (base::win::GetVersion() >= base::win::VERSION_WIN7 && 100 if (base::win::GetVersion() >= base::win::VERSION_WIN7 &&
112 ui::AreTouchEventsEnabled()) 101 ui::AreTouchEventsEnabled()) {
113 RegisterTouchWindow(hwnd(), TWF_WANTPALM); 102 RegisterTouchWindow(hwnd(), TWF_WANTPALM);
103 }
114 104
115 HRESULT hr = ::CreateStdAccessibleObject( 105 HRESULT hr = ::CreateStdAccessibleObject(
116 hwnd(), OBJID_WINDOW, IID_IAccessible, 106 hwnd(), OBJID_WINDOW, IID_IAccessible,
117 reinterpret_cast<void **>(window_accessible_.Receive())); 107 reinterpret_cast<void **>(window_accessible_.Receive()));
118 DCHECK(SUCCEEDED(hr)); 108 DCHECK(SUCCEEDED(hr));
119 109
120 if (!BrowserAccessibilityState::GetInstance()->IsAccessibleBrowser()) { 110 if (!BrowserAccessibilityState::GetInstance()->IsAccessibleBrowser()) {
121 // Attempt to detect screen readers or other clients who want full 111 // Attempt to detect screen readers or other clients who want full
122 // accessibility support, by seeing if they respond to this event. 112 // accessibility support, by seeing if they respond to this event.
123 NotifyWinEvent(EVENT_SYSTEM_ALERT, hwnd(), kIdScreenReaderHoneyPot, 113 NotifyWinEvent(EVENT_SYSTEM_ALERT, hwnd(), kIdScreenReaderHoneyPot,
(...skipping 23 matching lines...) Expand all
147 // because it sometimes gets sign-extended incorrectly (but not always). 137 // because it sometimes gets sign-extended incorrectly (but not always).
148 DWORD obj_id = static_cast<DWORD>(static_cast<DWORD_PTR>(l_param)); 138 DWORD obj_id = static_cast<DWORD>(static_cast<DWORD_PTR>(l_param));
149 139
150 if (kIdScreenReaderHoneyPot == obj_id) { 140 if (kIdScreenReaderHoneyPot == obj_id) {
151 // When an MSAA client has responded to our fake event on this id, 141 // When an MSAA client has responded to our fake event on this id,
152 // enable screen reader support. 142 // enable screen reader support.
153 BrowserAccessibilityState::GetInstance()->OnScreenReaderDetected(); 143 BrowserAccessibilityState::GetInstance()->OnScreenReaderDetected();
154 return static_cast<LRESULT>(0L); 144 return static_cast<LRESULT>(0L);
155 } 145 }
156 146
157 if (OBJID_CLIENT != obj_id || !host_) 147 if (OBJID_CLIENT != obj_id)
158 return static_cast<LRESULT>(0L); 148 return static_cast<LRESULT>(0L);
159 149
160 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From( 150 DCHECK(delegate_);
sky 2014/10/27 15:21:33 Move to constructor.
dmazzoni 2014/10/27 20:32:32 Done.
161 host_->GetRenderWidgetHost()); 151 base::win::ScopedComPtr<IAccessible> native_accessible(
162 if (!rwhi) 152 delegate_->GetNativeViewAccessible());
153 if (!native_accessible)
163 return static_cast<LRESULT>(0L); 154 return static_cast<LRESULT>(0L);
164 155
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, 156 return LresultFromObject(IID_IAccessible, w_param,
174 static_cast<IAccessible*>(root.Detach())); 157 static_cast<IAccessible*>(native_accessible.Detach()));
175 } 158 }
176 159
177 // We send keyboard/mouse/touch messages to the parent window via SendMessage. 160 // 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 161 // While this works, this has the side effect of converting input messages into
179 // sent messages which changes their priority and could technically result 162 // sent messages which changes their priority and could technically result
180 // in these messages starving other messages in the queue. Additionally 163 // in these messages starving other messages in the queue. Additionally
181 // keyboard/mouse hooks would not see these messages. The alternative approach 164 // 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 165 // 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 166 // receives all mouse events. However that was shelved due to possible issues
184 // with capture changes. 167 // with capture changes.
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 // generate the legacy WM_VSCROLL/WM_HSCROLL messages. 354 // generate the legacy WM_VSCROLL/WM_HSCROLL messages.
372 // We add these styles to ensure that trackpad/trackpoint scrolling 355 // We add these styles to ensure that trackpad/trackpoint scrolling
373 // work. 356 // work.
374 long current_style = ::GetWindowLong(hwnd(), GWL_STYLE); 357 long current_style = ::GetWindowLong(hwnd(), GWL_STYLE);
375 ::SetWindowLong(hwnd(), GWL_STYLE, 358 ::SetWindowLong(hwnd(), GWL_STYLE,
376 current_style | WS_VSCROLL | WS_HSCROLL); 359 current_style | WS_VSCROLL | WS_HSCROLL);
377 return 0; 360 return 0;
378 } 361 }
379 362
380 } // namespace content 363 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698