Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(790)

Side by Side Diff: content/browser/renderer_host/legacy_render_widget_host_win.h

Issue 387353004: Create only a single LegacyRenderWidgetHostHWND per WebContentsViewAura. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@render_frame_ax_3
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/rect.h" 16 #include "ui/gfx/rect.h"
17 17
18 namespace ui { 18 namespace ui {
19 class WindowEventTarget; 19 class WindowEventTarget;
20 } 20 }
21 21
22 namespace content { 22 namespace content {
23 class BrowserAccessibilityManagerWin; 23 class BrowserAccessibilityManager;
24 class LegacyRenderWidgetHostHWND;
24 class RenderWidgetHostViewAura; 25 class RenderWidgetHostViewAura;
25 26
26 // Reasons for the existence of this class outlined below:- 27 // Reasons for the existence of this class outlined below:-
27 // 1. Some screen readers expect every tab / every unique web content container 28 // 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 // 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 // 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 // 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 // Chrome_RenderWidgetHostHWND as the root of the accessibility tree for
32 // each tab. 33 // each tab.
33 // 2. There are legacy drivers for trackpads/trackpoints which have special 34 // 2. There are legacy drivers for trackpads/trackpoints which have special
34 // code for sending mouse wheel and scroll events to the 35 // code for sending mouse wheel and scroll events to the
35 // Chrome_RenderWidgetHostHWND window. 36 // Chrome_RenderWidgetHostHWND window.
36 // 3. Windowless NPAPI plugins like Flash and Silverlight which expect the 37 // 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 // 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 // default container window is the whole window which includes the web page
39 // WebContents, etc. This causes the plugin mouse event calculations to 40 // WebContents, etc. This causes the plugin mouse event calculations to
40 // fail. 41 // fail.
41 // We should look to get rid of this code when all of the above are fixed. 42 // We should look to get rid of this code when all of the above are fixed.
42 43
44 // A delegate interface for LegacyRenderWidgetHostHWND to query its owner.
ananta 2014/07/14 18:51:08 The comment here needs to be reworded?. query its
dmazzoni 2014/07/29 23:03:05 Done.
45 class CONTENT_EXPORT LegacyRenderWidgetHostHWNDDelegate {
46 public:
47 // Get the root BrowserAccessibilityManager representing the accessible
48 // state of this WebContents. This should always return a valid object,
49 // but the object may change as the user navigates.
50 virtual BrowserAccessibilityManager* GetRootBrowserAccessibilityManager() = 0;
51
52 // This will be called when the HWND is destroyed.
53 virtual void OnLegacyHwndDestroyed(LegacyRenderWidgetHostHWND* owner) = 0;
54 };
55
43 // This class implements a child HWND with the same size as the content area, 56 // 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 57 // that delegates its accessibility implementation to the root of the
45 // BrowserAccessibilityManager tree. This HWND is hooked up as the parent of 58 // BrowserAccessibilityManager tree. This HWND is hooked up as the parent of
46 // the root object in the BrowserAccessibilityManager tree, so when any 59 // the root object in the BrowserAccessibilityManager tree, so when any
47 // accessibility client calls ::WindowFromAccessibleObject, they get this 60 // accessibility client calls ::WindowFromAccessibleObject, they get this
48 // HWND instead of the DesktopWindowTreeHostWin. 61 // HWND instead of the DesktopWindowTreeHostWin.
49 class CONTENT_EXPORT LegacyRenderWidgetHostHWND 62 class CONTENT_EXPORT LegacyRenderWidgetHostHWND
50 : public ATL::CWindowImpl<LegacyRenderWidgetHostHWND, 63 : public ATL::CWindowImpl<LegacyRenderWidgetHostHWND,
51 NON_EXPORTED_BASE(ATL::CWindow), 64 NON_EXPORTED_BASE(ATL::CWindow),
52 ATL::CWinTraits<WS_CHILD> > { 65 ATL::CWinTraits<WS_CHILD> > {
53 public: 66 public:
67 virtual ~LegacyRenderWidgetHostHWND();
68
54 DECLARE_WND_CLASS_EX(L"Chrome_RenderWidgetHostHWND", CS_DBLCLKS, 0); 69 DECLARE_WND_CLASS_EX(L"Chrome_RenderWidgetHostHWND", CS_DBLCLKS, 0);
55 70
56 typedef ATL::CWindowImpl<LegacyRenderWidgetHostHWND, 71 typedef ATL::CWindowImpl<LegacyRenderWidgetHostHWND,
57 NON_EXPORTED_BASE(ATL::CWindow), 72 NON_EXPORTED_BASE(ATL::CWindow),
58 ATL::CWinTraits<WS_CHILD> > Base; 73 ATL::CWinTraits<WS_CHILD> > Base;
59 74
60 // Creates and returns an instance of the LegacyRenderWidgetHostHWND class on 75 // Creates and returns an instance of the LegacyRenderWidgetHostHWND class on
61 // successful creation of a child window parented to the parent window passed 76 // successful creation of a child window parented to the parent window passed
62 // in. 77 // in.
63 static LegacyRenderWidgetHostHWND* Create(HWND parent); 78 static LegacyRenderWidgetHostHWND* Create(
79 HWND parent,
80 LegacyRenderWidgetHostHWNDDelegate* delegate);
64 81
65 // Destroys the HWND managed by this class. 82 // Create an instance of LegacyRenderWidgetHostHWND purely for testing.
66 void Destroy(); 83 // Its parent is the desktop window and it always delegates to one
84 // BrowserAccessibilityManager. It deletes itself when the HWND is
85 // destroyed.
86 static LegacyRenderWidgetHostHWND* CreateForTesting(
87 BrowserAccessibilityManager* manager);
67 88
68 BEGIN_MSG_MAP_EX(LegacyRenderWidgetHostHWND) 89 BEGIN_MSG_MAP_EX(LegacyRenderWidgetHostHWND)
69 MESSAGE_HANDLER_EX(WM_GETOBJECT, OnGetObject) 90 MESSAGE_HANDLER_EX(WM_GETOBJECT, OnGetObject)
70 MESSAGE_RANGE_HANDLER(WM_KEYFIRST, WM_KEYLAST, OnKeyboardRange) 91 MESSAGE_RANGE_HANDLER(WM_KEYFIRST, WM_KEYLAST, OnKeyboardRange)
71 MESSAGE_HANDLER_EX(WM_PAINT, OnPaint) 92 MESSAGE_HANDLER_EX(WM_PAINT, OnPaint)
72 MESSAGE_HANDLER_EX(WM_NCPAINT, OnNCPaint) 93 MESSAGE_HANDLER_EX(WM_NCPAINT, OnNCPaint)
73 MESSAGE_HANDLER_EX(WM_ERASEBKGND, OnEraseBkGnd) 94 MESSAGE_HANDLER_EX(WM_ERASEBKGND, OnEraseBkGnd)
74 MESSAGE_RANGE_HANDLER(WM_MOUSEFIRST, WM_MOUSELAST, OnMouseRange) 95 MESSAGE_RANGE_HANDLER(WM_MOUSEFIRST, WM_MOUSELAST, OnMouseRange)
75 MESSAGE_HANDLER_EX(WM_MOUSELEAVE, OnMouseLeave) 96 MESSAGE_HANDLER_EX(WM_MOUSELEAVE, OnMouseLeave)
76 MESSAGE_HANDLER_EX(WM_MOUSEACTIVATE, OnMouseActivate) 97 MESSAGE_HANDLER_EX(WM_MOUSEACTIVATE, OnMouseActivate)
77 MESSAGE_HANDLER_EX(WM_SETCURSOR, OnSetCursor) 98 MESSAGE_HANDLER_EX(WM_SETCURSOR, OnSetCursor)
78 MESSAGE_HANDLER_EX(WM_TOUCH, OnTouch) 99 MESSAGE_HANDLER_EX(WM_TOUCH, OnTouch)
79 MESSAGE_HANDLER_EX(WM_HSCROLL, OnScroll) 100 MESSAGE_HANDLER_EX(WM_HSCROLL, OnScroll)
80 MESSAGE_HANDLER_EX(WM_VSCROLL, OnScroll) 101 MESSAGE_HANDLER_EX(WM_VSCROLL, OnScroll)
81 MESSAGE_HANDLER_EX(WM_NCHITTEST, OnNCHitTest) 102 MESSAGE_HANDLER_EX(WM_NCHITTEST, OnNCHitTest)
82 MESSAGE_RANGE_HANDLER(WM_NCMOUSEMOVE, WM_NCXBUTTONDBLCLK, 103 MESSAGE_RANGE_HANDLER(WM_NCMOUSEMOVE, WM_NCXBUTTONDBLCLK,
83 OnMouseRange) 104 OnMouseRange)
84 MESSAGE_HANDLER_EX(WM_NCCALCSIZE, OnNCCalcSize) 105 MESSAGE_HANDLER_EX(WM_NCCALCSIZE, OnNCCalcSize)
85 MESSAGE_HANDLER_EX(WM_SIZE, OnSize) 106 MESSAGE_HANDLER_EX(WM_SIZE, OnSize)
86 END_MSG_MAP() 107 END_MSG_MAP()
87 108
109 // May be deleted at any time by Windows! Other classes should never store
110 // this value.
88 HWND hwnd() { return m_hWnd; } 111 HWND hwnd() { return m_hWnd; }
89 112
90 // Called when the child window is to be reparented to a new window. 113 // Called when the child window is to be reparented to a new window.
91 // The |parent| parameter contains the new parent window. 114 // The |parent| parameter contains the new parent window.
92 void UpdateParent(HWND parent); 115 void UpdateParent(HWND parent);
93 HWND GetParent(); 116 HWND GetParent();
94 117
95 IAccessible* window_accessible() { return window_accessible_; } 118 IAccessible* window_accessible() { return window_accessible_; }
96 119
97 void set_browser_accessibility_manager(
98 content::BrowserAccessibilityManagerWin* manager) {
99 manager_ = manager;
100 }
101
102 void OnManagerDeleted(content::BrowserAccessibilityManagerWin* manager);
103
104 // Functions to show and hide the window. 120 // Functions to show and hide the window.
105 void Show(); 121 void Show();
106 void Hide(); 122 void Hide();
107 123
108 // Resizes the window to the bounds passed in. 124 // Resizes the window to the bounds passed in.
109 void SetBounds(const gfx::Rect& bounds); 125 void SetBounds(const gfx::Rect& bounds);
110 126
111 // The pointer to the containing RenderWidgetHostViewAura instance is passed
112 // here.
113 void set_host(RenderWidgetHostViewAura* host) {
114 host_ = host;
115 }
116
117 protected: 127 protected:
118 virtual void OnFinalMessage(HWND hwnd) OVERRIDE; 128 virtual void OnFinalMessage(HWND hwnd) OVERRIDE;
119 129
120 private: 130 private:
121 LegacyRenderWidgetHostHWND(HWND parent); 131 LegacyRenderWidgetHostHWND(HWND parent,
122 ~LegacyRenderWidgetHostHWND(); 132 LegacyRenderWidgetHostHWNDDelegate* delegate);
123 133
124 bool Init(); 134 bool Init();
125 135
126 // Returns the target to which the windows input events are forwarded. 136 // Returns the target to which the windows input events are forwarded.
127 static ui::WindowEventTarget* GetWindowEventTarget(HWND parent); 137 static ui::WindowEventTarget* GetWindowEventTarget(HWND parent);
128 138
129 LRESULT OnEraseBkGnd(UINT message, WPARAM w_param, LPARAM l_param); 139 LRESULT OnEraseBkGnd(UINT message, WPARAM w_param, LPARAM l_param);
130 LRESULT OnGetObject(UINT message, WPARAM w_param, LPARAM l_param); 140 LRESULT OnGetObject(UINT message, WPARAM w_param, LPARAM l_param);
131 LRESULT OnKeyboardRange(UINT message, WPARAM w_param, LPARAM l_param, 141 LRESULT OnKeyboardRange(UINT message, WPARAM w_param, LPARAM l_param,
132 BOOL& handled); 142 BOOL& handled);
133 LRESULT OnMouseLeave(UINT message, WPARAM w_param, LPARAM l_param); 143 LRESULT OnMouseLeave(UINT message, WPARAM w_param, LPARAM l_param);
134 LRESULT OnMouseRange(UINT message, WPARAM w_param, LPARAM l_param, 144 LRESULT OnMouseRange(UINT message, WPARAM w_param, LPARAM l_param,
135 BOOL& handled); 145 BOOL& handled);
136 LRESULT OnMouseActivate(UINT message, WPARAM w_param, LPARAM l_param); 146 LRESULT OnMouseActivate(UINT message, WPARAM w_param, LPARAM l_param);
137 LRESULT OnTouch(UINT message, WPARAM w_param, LPARAM l_param); 147 LRESULT OnTouch(UINT message, WPARAM w_param, LPARAM l_param);
138 LRESULT OnScroll(UINT message, WPARAM w_param, LPARAM l_param); 148 LRESULT OnScroll(UINT message, WPARAM w_param, LPARAM l_param);
139 LRESULT OnNCHitTest(UINT message, WPARAM w_param, LPARAM l_param); 149 LRESULT OnNCHitTest(UINT message, WPARAM w_param, LPARAM l_param);
140 150
141 LRESULT OnNCPaint(UINT message, WPARAM w_param, LPARAM l_param); 151 LRESULT OnNCPaint(UINT message, WPARAM w_param, LPARAM l_param);
142 LRESULT OnPaint(UINT message, WPARAM w_param, LPARAM l_param); 152 LRESULT OnPaint(UINT message, WPARAM w_param, LPARAM l_param);
143 LRESULT OnSetCursor(UINT message, WPARAM w_param, LPARAM l_param); 153 LRESULT OnSetCursor(UINT message, WPARAM w_param, LPARAM l_param);
144 LRESULT OnNCCalcSize(UINT message, WPARAM w_param, LPARAM l_param); 154 LRESULT OnNCCalcSize(UINT message, WPARAM w_param, LPARAM l_param);
145 LRESULT OnSize(UINT message, WPARAM w_param, LPARAM l_param); 155 LRESULT OnSize(UINT message, WPARAM w_param, LPARAM l_param);
146 LRESULT OnSysCommand(UINT message, WPARAM w_param, LPARAM l_param); 156 LRESULT OnSysCommand(UINT message, WPARAM w_param, LPARAM l_param);
147 157
148 content::BrowserAccessibilityManagerWin* manager_; 158 LegacyRenderWidgetHostHWNDDelegate* delegate_;
159 BrowserAccessibilityManager* manager_for_testing_;
149 base::win::ScopedComPtr<IAccessible> window_accessible_; 160 base::win::ScopedComPtr<IAccessible> window_accessible_;
150 161
151 // Set to true if we turned on mouse tracking. 162 // Set to true if we turned on mouse tracking.
152 bool mouse_tracking_enabled_; 163 bool mouse_tracking_enabled_;
153 164
154 RenderWidgetHostViewAura* host_;
155
156 DISALLOW_COPY_AND_ASSIGN(LegacyRenderWidgetHostHWND); 165 DISALLOW_COPY_AND_ASSIGN(LegacyRenderWidgetHostHWND);
157 }; 166 };
158 167
159 } // namespace content 168 } // namespace content
160 169
161 #endif // CONTENT_BROWSER_RENDERER_HOST_LEGACY_RENDER_WIDGET_HOST_WIN_H_ 170 #endif // CONTENT_BROWSER_RENDERER_HOST_LEGACY_RENDER_WIDGET_HOST_WIN_H_
162
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698