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