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