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

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/memory/scoped_ptr.h"
8 #include "base/win/windows_version.h"
9 #include "content/browser/accessibility/browser_accessibility_manager_win.h"
10 #include "content/browser/accessibility/browser_accessibility_win.h"
11 #include "ui/base/touch/touch_enabled.h"
12 #include "ui/gfx/geometry/rect.h"
13
14 namespace content {
15
16 // static
17 LegacyRenderWidgetHostHWND* LegacyRenderWidgetHostHWND::Create(HWND parent) {
18 scoped_ptr<LegacyRenderWidgetHostHWND> legacy_window_instance(
19 new LegacyRenderWidgetHostHWND(parent));
20 // If we failed to create the child, then return NULL. The
21 // LegacyRenderWidgetHostHWND instance will be destroyed by the scoped_ptr.
22 if (!::IsWindow(legacy_window_instance->hwnd()))
23 return NULL;
24 legacy_window_instance->Init();
25 return legacy_window_instance.release();
26 }
27
28 LegacyRenderWidgetHostHWND::~LegacyRenderWidgetHostHWND() {
29 ::DestroyWindow(hwnd());
30 }
31
32 void LegacyRenderWidgetHostHWND::UpdateParent(HWND parent) {
33 ::SetParent(hwnd(), parent);
34 }
35
36 HWND LegacyRenderWidgetHostHWND::GetParent() {
37 return ::GetParent(hwnd());
38 }
39
40 void LegacyRenderWidgetHostHWND::OnManagerDeleted() {
41 manager_ = NULL;
42 }
43
44 void LegacyRenderWidgetHostHWND::Show() {
45 ::ShowWindow(hwnd(), SW_SHOW);
46 }
47
48 void LegacyRenderWidgetHostHWND::Hide() {
49 ::ShowWindow(hwnd(), SW_HIDE);
50 }
51
52 void LegacyRenderWidgetHostHWND::SetBounds(const gfx::Rect& bounds) {
53 ::SetWindowPos(hwnd(), NULL, bounds.x(), bounds.y(), bounds.width(),
54 bounds.height(), 0);
55 }
56
57 void LegacyRenderWidgetHostHWND::OnFinalMessage(HWND hwnd) {
58 if (manager_)
59 manager_->OnAccessibleHwndDeleted();
60 }
61
62 LegacyRenderWidgetHostHWND::LegacyRenderWidgetHostHWND(HWND parent)
63 : manager_(NULL) {
64 RECT rect = {0};
65 Base::Create(parent, rect, L"Chrome Legacy Window", WS_CHILDWINDOW,
66 WS_EX_TRANSPARENT);
67 }
68
69 bool LegacyRenderWidgetHostHWND::Init() {
70 if (base::win::GetVersion() >= base::win::VERSION_WIN7 &&
71 ui::AreTouchEventsEnabled())
72 RegisterTouchWindow(hwnd(), TWF_WANTPALM);
73
74 HRESULT hr = ::CreateStdAccessibleObject(
75 hwnd(), OBJID_WINDOW, IID_IAccessible,
76 reinterpret_cast<void **>(window_accessible_.Receive()));
77 DCHECK(SUCCEEDED(hr));
78 return !!SUCCEEDED(hr);
79 }
80
81 LRESULT LegacyRenderWidgetHostHWND::OnEraseBkGnd(UINT message,
82 WPARAM w_param,
83 LPARAM l_param) {
84 return 1;
85 }
86
87 LRESULT LegacyRenderWidgetHostHWND::OnGetObject(UINT message,
88 WPARAM w_param,
89 LPARAM l_param) {
90 if (OBJID_CLIENT != l_param || !manager_)
91 return static_cast<LRESULT>(0L);
92
93 base::win::ScopedComPtr<IAccessible> root(
94 manager_->GetRoot()->ToBrowserAccessibilityWin());
95 return LresultFromObject(IID_IAccessible, w_param,
96 static_cast<IAccessible*>(root.Detach()));
97 }
98
99 // We send keyboard/mouse/touch messages to the parent window via SendMessage.
100 // While this works, this has the side effect of converting input messages into
101 // sent messages which changes their priority and could technically result
102 // in these messages starving other messages in the queue. Additionally
103 // keyboard/mouse hooks would not see these messages. The alternative approach
104 // is to set and release capture as needed on the parent to ensure that it
105 // receives all mouse events. However that was shelved due to possible issues
106 // with capture changes.
107 LRESULT LegacyRenderWidgetHostHWND::OnKeyboardRange(UINT message,
108 WPARAM w_param,
109 LPARAM l_param,
110 BOOL& handled) {
111 return ::SendMessage(GetParent(), message, w_param, l_param);
112 }
113
114 LRESULT LegacyRenderWidgetHostHWND::OnMouseRange(UINT message,
115 WPARAM w_param,
116 LPARAM l_param,
117 BOOL& handled) {
118 POINT mouse_coords;
119 mouse_coords.x = GET_X_LPARAM(l_param);
120 mouse_coords.y = GET_Y_LPARAM(l_param);
121 ::MapWindowPoints(hwnd(), GetParent(), &mouse_coords, 1);
122 return ::SendMessage(GetParent(), message, w_param,
123 MAKELPARAM(mouse_coords.x, mouse_coords.y));
124 }
125
126 LRESULT LegacyRenderWidgetHostHWND::OnMouseActivate(UINT message,
127 WPARAM w_param,
128 LPARAM l_param) {
129 // Don't pass this to DefWindowProc. That results in the WM_MOUSEACTIVATE
130 // message going all the way to the parent which then messes up state
131 // related to focused views, etc. This is because it treats this as if
132 // it lost activation.
133 // Our dummy window should not interfere with focus and activation in
134 // the parent. Return MA_ACTIVATE here ensures that focus state in the parent
135 // is preserved.
136 return MA_ACTIVATE;
137 }
138
139 LRESULT LegacyRenderWidgetHostHWND::OnTouch(UINT message,
140 WPARAM w_param,
141 LPARAM l_param) {
142 return ::SendMessage(GetParent(), message, w_param, l_param);
143 }
144
145 LRESULT LegacyRenderWidgetHostHWND::OnNCPaint(UINT message,
146 WPARAM w_param,
147 LPARAM l_param) {
148 return 0;
149 }
150
151 LRESULT LegacyRenderWidgetHostHWND::OnPaint(UINT message,
152 WPARAM w_param,
153 LPARAM l_param) {
154 PAINTSTRUCT ps = {0};
155 ::BeginPaint(hwnd(), &ps);
156 ::EndPaint(hwnd(), &ps);
157 return 0;
158 }
159
160 LRESULT LegacyRenderWidgetHostHWND::OnSetCursor(UINT message,
161 WPARAM w_param,
162 LPARAM l_param) {
163 return 0;
164 }
165
166 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698