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,173 @@ |
+// 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_(parent) { |
+ RECT rect = {0}; |
+ Create(parent, rect, NULL, WS_CHILDWINDOW, WS_EX_TRANSPARENT); |
scottmg
2014/01/31 21:52:01
could you change the title to "Legacy Helper" or s
ananta
2014/01/31 23:56:26
Changed to Chrome Legacy Helper
|
+ |
+ if (base::win::GetVersion() >= base::win::VERSION_WIN7 && |
+ ui::AreTouchEventsEnabled()) |
+ RegisterTouchWindow(hwnd(), TWF_WANTPALM); |
+ |
+ HRESULT hr = ::CreateStdAccessibleObject( |
+ hwnd(), OBJID_WINDOW, IID_IAccessible, |
+ reinterpret_cast<void **>(window_accessible_.Receive())); |
+ if (::IsWindow(hwnd())) { |
+ mouse_window_bounds_tracker_.set_tracking_window(m_hWnd); |
+ mouse_window_bounds_tracker_.SubclassWindow(parent_); |
+ } |
+} |
+ |
+LegacyRenderWidgetHostHWND::~LegacyRenderWidgetHostHWND() { |
+} |
+ |
+void LegacyRenderWidgetHostHWND::OnManagerDeleted() { |
+ manager_ = NULL; |
+} |
+ |
+void LegacyRenderWidgetHostHWND::Show() { |
+ ::ShowWindow(hwnd(), SW_SHOW); |
+} |
+ |
+void LegacyRenderWidgetHostHWND::Hide() { |
+ ::ShowWindow(hwnd(), SW_HIDE); |
+} |
+ |
+void LegacyRenderWidgetHostHWND::OnFinalMessage(HWND hwnd) { |
+ if (manager_) |
+ manager_->OnAccessibleHwndDeleted(); |
+ delete this; |
+} |
+ |
+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())); |
+} |
+ |
+LRESULT LegacyRenderWidgetHostHWND::OnKeyboardRange(UINT message, |
+ WPARAM w_param, |
+ LPARAM l_param, |
+ BOOL& handled) { |
+ ::PostMessage(parent_, message, w_param, l_param); |
+ return 0; |
+} |
+ |
+LRESULT LegacyRenderWidgetHostHWND::OnMouseRange(UINT message, |
+ WPARAM w_param, |
+ LPARAM l_param, |
+ BOOL& handled) { |
+ // We won't receive mouse messages when capture is with the parent window. |
+ // If we receive a mouse move then it means that parent capture was released. |
+ // This would happen if we lost focus or if the mouse left our window bounds |
+ // and we released capture. |
+ if (message == WM_MOUSEMOVE) { |
+ if (::GetCapture() != parent_) |
+ ::SetCapture(parent_); |
+ } |
+ // TODO(ananta) |
+ // This code should be restored/deleted prior to landing this, based on |
+ // decisions as to whether capturing the parent window to ensure that all |
+ // mouse messages go to it and the ensuing complexity with the same is worth |
+ // the effort. Posting the message to the parent seems much simpler with |
+ // the caveat of converting mouse messages into posted mouse messages which |
+ // may lead to performance issues with the message pump and the fact that |
+ // we need to peeks for every mouse event. |
+#if 0 |
+ 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); |
+ ::PostMessage(parent_, message, w_param, |
+ MAKELPARAM(mouse_coords.x, mouse_coords.y)); |
+#endif |
+ return 0; |
+} |
+ |
+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; |
+} |
+ |
+LRESULT LegacyRenderWidgetHostHWND::OnTouch(UINT message, |
+ WPARAM w_param, |
+ LPARAM l_param) { |
+ ::PostMessage(parent_, message, w_param, l_param); |
+ return 0; |
+} |
+ |
+LegacyRenderWidgetHostHWND:: |
+ MouseWindowBoundsTracker::MouseWindowBoundsTracker() |
+ : tracking_window_(NULL) { |
+} |
+ |
+LegacyRenderWidgetHostHWND:: |
+ MouseWindowBoundsTracker::~MouseWindowBoundsTracker() { |
+ UnsubclassWindow(); |
+} |
+ |
+LRESULT LegacyRenderWidgetHostHWND::MouseWindowBoundsTracker::OnMouseMove( |
+ UINT message, WPARAM w_param, LPARAM l_param) { |
+ SetMsgHandled(FALSE); |
+ // Don't mess with the capture if mouse buttons are down. |
+ const int mouse_down_flags = |
+ MK_LBUTTON | MK_MBUTTON | MK_RBUTTON | MK_XBUTTON1 | MK_XBUTTON2; |
+ if (::GetCapture() == m_hWnd && !(w_param & mouse_down_flags)) { |
+ DCHECK(::IsWindow(tracking_window_)); |
+ POINT pt = {0}; |
+ pt.x = GET_X_LPARAM(l_param); |
+ pt.y = GET_Y_LPARAM(l_param); |
+ ::ClientToScreen(m_hWnd, &pt); |
+ |
+ RECT window_rect = {0}; |
+ ::GetWindowRect(tracking_window_, &window_rect); |
+ if (!::PtInRect(&window_rect, pt) || |
+ ::WindowFromPoint(pt) != tracking_window_) { |
+ ::ReleaseCapture(); |
+ } |
+ } |
+ return 0; |
+} |
+ |
+} // namespace content |