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

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

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

Powered by Google App Engine
This is Rietveld 408576698