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