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