Chromium Code Reviews| Index: content/browser/renderer_host/legacy_render_widget_host_win.cc |
| =================================================================== |
| --- content/browser/renderer_host/legacy_render_widget_host_win.cc (revision 0) |
| +++ content/browser/renderer_host/legacy_render_widget_host_win.cc (revision 0) |
| @@ -0,0 +1,157 @@ |
| +// Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/browser/renderer_host/legacy_render_widget_host_win.h" |
| + |
| +#include "base/win/windows_version.h" |
| +#include "content/browser/accessibility/browser_accessibility_manager_win.h" |
| +#include "content/browser/accessibility/browser_accessibility_win.h" |
| +#include "ui/base/touch/touch_enabled.h" |
| +#include "ui/gfx/geometry/rect.h" |
| + |
| +namespace content { |
| + |
| +LegacyRenderWidgetHostHWND::LegacyRenderWidgetHostHWND(HWND parent) |
| + : manager_(NULL), |
| + parent_(NULL) { |
| + RECT rect = {0}; |
| + Create(parent, rect, L"Chrome Legacy Window", |
| + WS_CHILDWINDOW, WS_EX_TRANSPARENT); |
| + |
|
sky
2014/02/05 15:22:44
CheckWindowCreated(hwnd())
ananta
2014/02/05 16:35:51
Cannot use that as this code would also run for Wi
|
| + if (base::win::GetVersion() >= base::win::VERSION_WIN7 && |
| + ui::AreTouchEventsEnabled()) |
| + RegisterTouchWindow(hwnd(), TWF_WANTPALM); |
| + |
| + HRESULT hr = ::CreateStdAccessibleObject( |
|
sky
2014/02/05 15:22:44
Did you intend to check the result? If not, no nee
ananta
2014/02/05 16:35:51
Added a DCHECK for hr.
|
| + hwnd(), OBJID_WINDOW, IID_IAccessible, |
| + reinterpret_cast<void **>(window_accessible_.Receive())); |
| + |
| + if (::IsWindow(hwnd())) |
|
sky
2014/02/05 15:22:44
I don't think this if should be necessary.
ananta
2014/02/05 16:35:51
Done.
|
| + SetParentWindow(parent); |
| +} |
| + |
| +LegacyRenderWidgetHostHWND::~LegacyRenderWidgetHostHWND() { |
| +} |
| + |
| +void LegacyRenderWidgetHostHWND::SetParentWindow(HWND parent) { |
| + ::SetParent(hwnd(), parent); |
| + parent_ = parent; |
| +} |
| + |
| +void LegacyRenderWidgetHostHWND::OnManagerDeleted() { |
| + manager_ = NULL; |
| +} |
| + |
| +void LegacyRenderWidgetHostHWND::Show() { |
| + ::ShowWindow(hwnd(), SW_SHOW); |
| +} |
| + |
| +void LegacyRenderWidgetHostHWND::Hide() { |
| + ::ShowWindow(hwnd(), SW_HIDE); |
| +} |
| + |
| +void LegacyRenderWidgetHostHWND::SetBounds(const gfx::Rect& bounds) { |
| + if (::IsWindow(hwnd())) { |
| + ::SetWindowPos(hwnd(), NULL, bounds.x(), bounds.y(), bounds.width(), |
| + bounds.height(), 0); |
| + } |
| +} |
| + |
| +void LegacyRenderWidgetHostHWND::Destroy() { |
| + if (::IsWindow(hwnd())) |
|
sky
2014/02/05 15:22:44
Can this be moved to the destructor instead? That
ananta
2014/02/05 16:35:51
Done.
|
| + ::DestroyWindow(hwnd()); |
| + delete this; |
| +} |
| + |
| +void LegacyRenderWidgetHostHWND::OnFinalMessage(HWND hwnd) { |
| + if (manager_) |
| + manager_->OnAccessibleHwndDeleted(); |
| +} |
| + |
| +LRESULT LegacyRenderWidgetHostHWND::OnEraseBkGnd(UINT message, |
| + WPARAM w_param, |
| + LPARAM l_param) { |
| + return 1; |
| +} |
| + |
| +LRESULT LegacyRenderWidgetHostHWND::OnGetObject(UINT message, |
| + WPARAM w_param, |
| + LPARAM l_param) { |
| + if (OBJID_CLIENT != l_param || !manager_) |
| + return static_cast<LRESULT>(0L); |
| + |
| + base::win::ScopedComPtr<IAccessible> root( |
| + manager_->GetRoot()->ToBrowserAccessibilityWin()); |
| + return LresultFromObject(IID_IAccessible, w_param, |
| + static_cast<IAccessible*>(root.Detach())); |
| +} |
| + |
| +// We send keyboard/mouse/touch messages to the parent window via SendMessage. |
| +// While this works, this has the side effect of converting input messages into |
| +// sent messages which changes their priority and could technically result |
| +// in these messages starving other messages in the queue. Additionally |
| +// keyboard/mouse hooks would not see these messages. The alternative approach |
| +// is to set and release capture as needed on the parent to ensure that it |
| +// receives all mouse events. However that was shelved due to possible issues |
| +// with capture changes. |
| +LRESULT LegacyRenderWidgetHostHWND::OnKeyboardRange(UINT message, |
| + WPARAM w_param, |
| + LPARAM l_param, |
| + BOOL& handled) { |
| + return ::SendMessage(parent_, message, w_param, l_param); |
| +} |
| + |
| +LRESULT LegacyRenderWidgetHostHWND::OnMouseRange(UINT message, |
| + WPARAM w_param, |
| + LPARAM l_param, |
| + BOOL& handled) { |
| + POINT mouse_coords; |
| + mouse_coords.x = GET_X_LPARAM(l_param); |
| + mouse_coords.y = GET_Y_LPARAM(l_param); |
| + ::MapWindowPoints(hwnd(), parent_, &mouse_coords, 1); |
| + return ::SendMessage(parent_, message, w_param, |
| + MAKELPARAM(mouse_coords.x, mouse_coords.y)); |
| +} |
| + |
| +LRESULT LegacyRenderWidgetHostHWND::OnMouseActivate(UINT message, |
| + WPARAM w_param, |
| + LPARAM l_param) { |
| + // Don't pass this to DefWindowProc. That results in the WM_MOUSEACTIVATE |
| + // message going all the way to the parent which then messes up state |
| + // related to focused views, etc. This is because it treats this as if |
| + // it lost activation. |
| + // Our dummy window should not interfere with focus and activation in |
| + // the parent. Return MA_ACTIVATE here ensures that focus state in the parent |
| + // is preserved. |
| + return MA_ACTIVATE; |
| +} |
| + |
| +LRESULT LegacyRenderWidgetHostHWND::OnTouch(UINT message, |
| + WPARAM w_param, |
| + LPARAM l_param) { |
| + return ::SendMessage(parent_, message, w_param, l_param); |
| +} |
| + |
| +LRESULT LegacyRenderWidgetHostHWND::OnNCPaint(UINT message, |
| + WPARAM w_param, |
| + LPARAM l_param) { |
| + return 0; |
| +} |
| + |
| +LRESULT LegacyRenderWidgetHostHWND::OnPaint(UINT message, |
| + WPARAM w_param, |
| + LPARAM l_param) { |
| + PAINTSTRUCT ps = {0}; |
| + ::BeginPaint(hwnd(), &ps); |
| + ::EndPaint(hwnd(), &ps); |
| + return 0; |
| +} |
| + |
| +LRESULT LegacyRenderWidgetHostHWND::OnSetCursor(UINT message, |
| + WPARAM w_param, |
| + LPARAM l_param) { |
| + return 0; |
| +} |
| + |
| +} // namespace content |