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 #ifndef CONTENT_BROWSER_RENDERER_HOST_LEGACY_RENDER_WIDGET_HOST_WIN_H_ 6 #define CONTENT_BROWSER_RENDERER_HOST_LEGACY_RENDER_WIDGET_HOST_WIN_H_ 7 8 #include <atlbase.h> 9 #include <atlwin.h> 10 #include <atlcrack.h> 11 #include <oleacc.h> 12 13 #include "base/basictypes.h" 14 #include "base/memory/scoped_ptr.h" 15 #include "base/win/scoped_comptr.h" 16 #include "content/common/content_export.h" 17 #include "ui/gfx/rect.h" 18 19 namespace ui { 20 class WindowEventTarget; 21 } 22 23 namespace content { 24 class BrowserAccessibilityManagerWin; 25 26 // Reasons for the existence of this class outlined below:- 27 // 1. Some screen readers expect every tab / every unique web content container 28 // to be in its own HWND with class name Chrome_RenderWidgetHostHWND. 29 // With Aura there is one main HWND which comprises the whole browser window 30 // or the whole desktop. So, we need a fake HWND with the window class as 31 // Chrome_RenderWidgetHostHWND as the root of the accessibility tree for 32 // each tab. 33 // 2. There are legacy drivers for trackpads/trackpoints which have special 34 // code for sending mouse wheel and scroll events to the 35 // Chrome_RenderWidgetHostHWND window. 36 // 3. Windowless NPAPI plugins like Flash and Silverlight which expect the 37 // container window to have the same bounds as the web page. In Aura, the 38 // default container window is the whole window which includes the web page 39 // WebContents, etc. This causes the plugin mouse event calculations to 40 // fail. 41 // We should look to get rid of this code when all of the above are fixed. 42 43 // This class implements a child HWND with the same size as the content area, 44 // that delegates its accessibility implementation to the root of the 45 // BrowserAccessibilityManager tree. This HWND is hooked up as the parent of 46 // the root object in the BrowserAccessibilityManager tree, so when any 47 // accessibility client calls ::WindowFromAccessibleObject, they get this 48 // HWND instead of the DesktopWindowTreeHostWin. 49 class CONTENT_EXPORT LegacyRenderWidgetHostHWND 50 : public ATL::CWindowImpl<LegacyRenderWidgetHostHWND, 51 NON_EXPORTED_BASE(ATL::CWindow), 52 ATL::CWinTraits<WS_CHILD> > { 53 public: 54 DECLARE_WND_CLASS_EX(L"Chrome_RenderWidgetHostHWND", CS_DBLCLKS, 0); 55 56 typedef ATL::CWindowImpl<LegacyRenderWidgetHostHWND, 57 NON_EXPORTED_BASE(ATL::CWindow), 58 ATL::CWinTraits<WS_CHILD> > Base; 59 60 ~LegacyRenderWidgetHostHWND(); 61 62 // Creates and returns an instance of the LegacyRenderWidgetHostHWND class on 63 // successful creation of a child window parented to the parent window passed 64 // in. 65 static scoped_ptr<LegacyRenderWidgetHostHWND> Create(HWND parent); 66 67 BEGIN_MSG_MAP_EX(LegacyRenderWidgetHostHWND) 68 MESSAGE_HANDLER_EX(WM_GETOBJECT, OnGetObject) 69 MESSAGE_RANGE_HANDLER(WM_KEYFIRST, WM_KEYLAST, OnKeyboardRange) 70 MESSAGE_HANDLER_EX(WM_PAINT, OnPaint) 71 MESSAGE_HANDLER_EX(WM_NCPAINT, OnNCPaint) 72 MESSAGE_HANDLER_EX(WM_ERASEBKGND, OnEraseBkGnd) 73 MESSAGE_RANGE_HANDLER(WM_MOUSEFIRST, WM_MOUSELAST, OnMouseRange) 74 MESSAGE_HANDLER_EX(WM_MOUSELEAVE, OnMouseLeave) 75 MESSAGE_HANDLER_EX(WM_MOUSEACTIVATE, OnMouseActivate) 76 MESSAGE_HANDLER_EX(WM_SETCURSOR, OnSetCursor) 77 MESSAGE_HANDLER_EX(WM_TOUCH, OnTouch) 78 MESSAGE_HANDLER_EX(WM_HSCROLL, OnScroll) 79 MESSAGE_HANDLER_EX(WM_VSCROLL, OnScroll) 80 MESSAGE_HANDLER_EX(WM_NCHITTEST, OnNCHitTest) 81 MESSAGE_RANGE_HANDLER(WM_NCMOUSEMOVE, WM_NCXBUTTONDBLCLK, 82 OnMouseRange) 83 MESSAGE_HANDLER_EX(WM_NCCALCSIZE, OnNCCalcSize) 84 MESSAGE_HANDLER_EX(WM_SIZE, OnSize) 85 END_MSG_MAP() 86 87 HWND hwnd() { return m_hWnd; } 88 89 // Called when the child window is to be reparented to a new window. 90 // The |parent| parameter contains the new parent window. 91 void UpdateParent(HWND parent); 92 HWND GetParent(); 93 94 IAccessible* window_accessible() { return window_accessible_; } 95 96 void set_browser_accessibility_manager( 97 content::BrowserAccessibilityManagerWin* manager) { 98 manager_ = manager; 99 } 100 101 void OnManagerDeleted(); 102 103 // Functions to show and hide the window. 104 void Show(); 105 void Hide(); 106 107 // Resizes the window to the bounds passed in. 108 void SetBounds(const gfx::Rect& bounds); 109 110 protected: 111 virtual void OnFinalMessage(HWND hwnd) OVERRIDE; 112 113 private: 114 LegacyRenderWidgetHostHWND(HWND parent); 115 116 bool Init(); 117 118 // Returns the target to which the windows input events are forwarded. 119 static ui::WindowEventTarget* GetWindowEventTarget(HWND parent); 120 121 LRESULT OnEraseBkGnd(UINT message, WPARAM w_param, LPARAM l_param); 122 LRESULT OnGetObject(UINT message, WPARAM w_param, LPARAM l_param); 123 LRESULT OnKeyboardRange(UINT message, WPARAM w_param, LPARAM l_param, 124 BOOL& handled); 125 LRESULT OnMouseLeave(UINT message, WPARAM w_param, LPARAM l_param); 126 LRESULT OnMouseRange(UINT message, WPARAM w_param, LPARAM l_param, 127 BOOL& handled); 128 LRESULT OnMouseActivate(UINT message, WPARAM w_param, LPARAM l_param); 129 LRESULT OnTouch(UINT message, WPARAM w_param, LPARAM l_param); 130 LRESULT OnScroll(UINT message, WPARAM w_param, LPARAM l_param); 131 LRESULT OnNCHitTest(UINT message, WPARAM w_param, LPARAM l_param); 132 133 LRESULT OnNCPaint(UINT message, WPARAM w_param, LPARAM l_param); 134 LRESULT OnPaint(UINT message, WPARAM w_param, LPARAM l_param); 135 LRESULT OnSetCursor(UINT message, WPARAM w_param, LPARAM l_param); 136 LRESULT OnNCCalcSize(UINT message, WPARAM w_param, LPARAM l_param); 137 LRESULT OnSize(UINT message, WPARAM w_param, LPARAM l_param); 138 139 content::BrowserAccessibilityManagerWin* manager_; 140 base::win::ScopedComPtr<IAccessible> window_accessible_; 141 142 // Set to true if we turned on mouse tracking. 143 bool mouse_tracking_enabled_; 144 145 DISALLOW_COPY_AND_ASSIGN(LegacyRenderWidgetHostHWND); 146 }; 147 148 } // namespace content 149 150 #endif // CONTENT_BROWSER_RENDERER_HOST_LEGACY_RENDER_WIDGET_HOST_WIN_H_ 151 152