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

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

Issue 151083002: Create a visible window with class name Chrome_RenderWidgetHostHWND which corresponds to the bounds… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 6 years, 10 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "content/browser/renderer_host/legacy_render_widget_host_win.h"
6
7 #include "base/command_line.h"
8 #include "base/memory/scoped_ptr.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/public/common/content_switches.h"
13 #include "ui/base/touch/touch_enabled.h"
14 #include "ui/gfx/geometry/rect.h"
15
16 namespace content {
17
18 LegacyRenderWidgetHostHWND::~LegacyRenderWidgetHostHWND() {
19 ::DestroyWindow(hwnd());
20 }
21
22 // static
23 scoped_ptr<LegacyRenderWidgetHostHWND> LegacyRenderWidgetHostHWND::Create(
24 HWND parent) {
25 scoped_ptr<LegacyRenderWidgetHostHWND> legacy_window_instance;
26 legacy_window_instance.reset(new LegacyRenderWidgetHostHWND(parent));
27 // If we failed to create the child, or if the switch to disable the legacy
28 // window is passed in, then return NULL.
29 if (!::IsWindow(legacy_window_instance->hwnd()) ||
30 CommandLine::ForCurrentProcess()->HasSwitch(
31 switches::kDisableLegacyIntermediateWindow))
32 return scoped_ptr<LegacyRenderWidgetHostHWND>();
33
34 legacy_window_instance->Init();
35 return legacy_window_instance.Pass();
36 }
37
38 void LegacyRenderWidgetHostHWND::UpdateParent(HWND parent) {
39 ::SetParent(hwnd(), parent);
40 // If the new parent is the desktop Window, then we disable the child window
41 // to ensure that it does not receive any input events. It should not because
42 // of WS_EX_TRANSPARENT. This is only for safety.
43 if (parent == ::GetDesktopWindow()) {
44 ::EnableWindow(hwnd(), FALSE);
45 } else {
46 ::EnableWindow(hwnd(), TRUE);
47 }
48 }
49
50 HWND LegacyRenderWidgetHostHWND::GetParent() {
51 return ::GetParent(hwnd());
52 }
53
54 void LegacyRenderWidgetHostHWND::OnManagerDeleted() {
55 manager_ = NULL;
56 }
57
58 void LegacyRenderWidgetHostHWND::Show() {
59 ::ShowWindow(hwnd(), SW_SHOW);
60 }
61
62 void LegacyRenderWidgetHostHWND::Hide() {
63 ::ShowWindow(hwnd(), SW_HIDE);
64 }
65
66 void LegacyRenderWidgetHostHWND::SetBounds(const gfx::Rect& bounds) {
67 ::SetWindowPos(hwnd(), NULL, bounds.x(), bounds.y(), bounds.width(),
68 bounds.height(), 0);
69 }
70
71 void LegacyRenderWidgetHostHWND::OnFinalMessage(HWND hwnd) {
72 if (manager_)
73 manager_->OnAccessibleHwndDeleted();
74 }
75
76 LegacyRenderWidgetHostHWND::LegacyRenderWidgetHostHWND(HWND parent)
77 : manager_(NULL) {
78 RECT rect = {0};
79 Base::Create(parent, rect, L"Chrome Legacy Window",
80 WS_CHILDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
81 WS_EX_TRANSPARENT);
82 }
83
84 bool LegacyRenderWidgetHostHWND::Init() {
85 if (base::win::GetVersion() >= base::win::VERSION_WIN7 &&
86 ui::AreTouchEventsEnabled())
87 RegisterTouchWindow(hwnd(), TWF_WANTPALM);
88
89 HRESULT hr = ::CreateStdAccessibleObject(
90 hwnd(), OBJID_WINDOW, IID_IAccessible,
91 reinterpret_cast<void **>(window_accessible_.Receive()));
92 DCHECK(SUCCEEDED(hr));
93 return !!SUCCEEDED(hr);
94 }
95
96 LRESULT LegacyRenderWidgetHostHWND::OnEraseBkGnd(UINT message,
97 WPARAM w_param,
98 LPARAM l_param) {
99 return 1;
100 }
101
102 LRESULT LegacyRenderWidgetHostHWND::OnGetObject(UINT message,
103 WPARAM w_param,
104 LPARAM l_param) {
105 if (OBJID_CLIENT != l_param || !manager_)
106 return static_cast<LRESULT>(0L);
107
108 base::win::ScopedComPtr<IAccessible> root(
109 manager_->GetRoot()->ToBrowserAccessibilityWin());
110 return LresultFromObject(IID_IAccessible, w_param,
111 static_cast<IAccessible*>(root.Detach()));
112 }
113
114 // We send keyboard/mouse/touch messages to the parent window via SendMessage.
115 // While this works, this has the side effect of converting input messages into
116 // sent messages which changes their priority and could technically result
117 // in these messages starving other messages in the queue. Additionally
118 // keyboard/mouse hooks would not see these messages. The alternative approach
119 // is to set and release capture as needed on the parent to ensure that it
120 // receives all mouse events. However that was shelved due to possible issues
121 // with capture changes.
122 LRESULT LegacyRenderWidgetHostHWND::OnKeyboardRange(UINT message,
123 WPARAM w_param,
124 LPARAM l_param,
125 BOOL& handled) {
126 return ::SendMessage(GetParent(), message, w_param, l_param);
127 }
128
129 LRESULT LegacyRenderWidgetHostHWND::OnMouseRange(UINT message,
130 WPARAM w_param,
131 LPARAM l_param,
132 BOOL& handled) {
133 POINT mouse_coords;
134 mouse_coords.x = GET_X_LPARAM(l_param);
135 mouse_coords.y = GET_Y_LPARAM(l_param);
136 ::MapWindowPoints(hwnd(), GetParent(), &mouse_coords, 1);
137 return ::SendMessage(GetParent(), message, w_param,
138 MAKELPARAM(mouse_coords.x, mouse_coords.y));
139 }
140
141 LRESULT LegacyRenderWidgetHostHWND::OnMouseActivate(UINT message,
142 WPARAM w_param,
143 LPARAM l_param) {
144 // Don't pass this to DefWindowProc. That results in the WM_MOUSEACTIVATE
145 // message going all the way to the parent which then messes up state
146 // related to focused views, etc. This is because it treats this as if
147 // it lost activation.
148 // Our dummy window should not interfere with focus and activation in
149 // the parent. Return MA_ACTIVATE here ensures that focus state in the parent
150 // is preserved.
151 return MA_ACTIVATE;
152 }
153
154 LRESULT LegacyRenderWidgetHostHWND::OnTouch(UINT message,
155 WPARAM w_param,
156 LPARAM l_param) {
157 return ::SendMessage(GetParent(), message, w_param, l_param);
158 }
159
160 LRESULT LegacyRenderWidgetHostHWND::OnNCPaint(UINT message,
161 WPARAM w_param,
162 LPARAM l_param) {
163 return 0;
164 }
165
166 LRESULT LegacyRenderWidgetHostHWND::OnPaint(UINT message,
167 WPARAM w_param,
168 LPARAM l_param) {
169 PAINTSTRUCT ps = {0};
170 ::BeginPaint(hwnd(), &ps);
171 ::EndPaint(hwnd(), &ps);
172 return 0;
173 }
174
175 LRESULT LegacyRenderWidgetHostHWND::OnSetCursor(UINT message,
176 WPARAM w_param,
177 LPARAM l_param) {
178 return 0;
179 }
180
181 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/legacy_render_widget_host_win.h ('k') | content/browser/renderer_host/render_widget_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698