15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright (c) 2014 The Chromium Authors. All rights reserved. 25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// found in the LICENSE file. 45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#ifndef CONTENT_BROWSER_RENDERER_HOST_LEGACY_RENDER_WIDGET_HOST_WIN_H_ 65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#define CONTENT_BROWSER_RENDERER_HOST_LEGACY_RENDER_WIDGET_HOST_WIN_H_ 75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include <atlbase.h> 95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include <atlwin.h> 105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include <atlcrack.h> 115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include <oleacc.h> 125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/basictypes.h" 145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/win/scoped_comptr.h" 155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "content/common/content_export.h" 165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/gfx/rect.h" 175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 18a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)namespace ui { 19a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class WindowEventTarget; 20a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 21a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace content { 23116680a4aac90f2aa7413d9095a592090648e557Ben Murdochclass RenderWidgetHostViewAura; 245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Reasons for the existence of this class outlined below:- 265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// 1. Some screen readers expect every tab / every unique web content container 275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// to be in its own HWND with class name Chrome_RenderWidgetHostHWND. 285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// With Aura there is one main HWND which comprises the whole browser window 295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// or the whole desktop. So, we need a fake HWND with the window class as 305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Chrome_RenderWidgetHostHWND as the root of the accessibility tree for 315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// each tab. 325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// 2. There are legacy drivers for trackpads/trackpoints which have special 335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// code for sending mouse wheel and scroll events to the 345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Chrome_RenderWidgetHostHWND window. 355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// 3. Windowless NPAPI plugins like Flash and Silverlight which expect the 365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// container window to have the same bounds as the web page. In Aura, the 375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// default container window is the whole window which includes the web page 385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// WebContents, etc. This causes the plugin mouse event calculations to 395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// fail. 405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// We should look to get rid of this code when all of the above are fixed. 415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// This class implements a child HWND with the same size as the content area, 435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// that delegates its accessibility implementation to the root of the 445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// BrowserAccessibilityManager tree. This HWND is hooked up as the parent of 455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// the root object in the BrowserAccessibilityManager tree, so when any 465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// accessibility client calls ::WindowFromAccessibleObject, they get this 475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// HWND instead of the DesktopWindowTreeHostWin. 485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class CONTENT_EXPORT LegacyRenderWidgetHostHWND 495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) : public ATL::CWindowImpl<LegacyRenderWidgetHostHWND, 505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NON_EXPORTED_BASE(ATL::CWindow), 515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ATL::CWinTraits<WS_CHILD> > { 525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) public: 535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DECLARE_WND_CLASS_EX(L"Chrome_RenderWidgetHostHWND", CS_DBLCLKS, 0); 545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) typedef ATL::CWindowImpl<LegacyRenderWidgetHostHWND, 565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NON_EXPORTED_BASE(ATL::CWindow), 575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ATL::CWinTraits<WS_CHILD> > Base; 585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Creates and returns an instance of the LegacyRenderWidgetHostHWND class on 605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // successful creation of a child window parented to the parent window passed 615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // in. 62116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch static LegacyRenderWidgetHostHWND* Create(HWND parent); 63116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 64116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // Destroys the HWND managed by this class. 65116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch void Destroy(); 665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) BEGIN_MSG_MAP_EX(LegacyRenderWidgetHostHWND) 685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MESSAGE_HANDLER_EX(WM_GETOBJECT, OnGetObject) 695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MESSAGE_RANGE_HANDLER(WM_KEYFIRST, WM_KEYLAST, OnKeyboardRange) 705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MESSAGE_HANDLER_EX(WM_PAINT, OnPaint) 715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MESSAGE_HANDLER_EX(WM_NCPAINT, OnNCPaint) 725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MESSAGE_HANDLER_EX(WM_ERASEBKGND, OnEraseBkGnd) 735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MESSAGE_RANGE_HANDLER(WM_MOUSEFIRST, WM_MOUSELAST, OnMouseRange) 745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MESSAGE_HANDLER_EX(WM_MOUSELEAVE, OnMouseLeave) 755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MESSAGE_HANDLER_EX(WM_MOUSEACTIVATE, OnMouseActivate) 765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MESSAGE_HANDLER_EX(WM_SETCURSOR, OnSetCursor) 775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MESSAGE_HANDLER_EX(WM_TOUCH, OnTouch) 785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MESSAGE_HANDLER_EX(WM_HSCROLL, OnScroll) 79a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) MESSAGE_HANDLER_EX(WM_VSCROLL, OnScroll) 80a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) MESSAGE_HANDLER_EX(WM_NCHITTEST, OnNCHitTest) 81a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) MESSAGE_RANGE_HANDLER(WM_NCMOUSEMOVE, WM_NCXBUTTONDBLCLK, 82a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) OnMouseRange) 83a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) MESSAGE_HANDLER_EX(WM_NCCALCSIZE, OnNCCalcSize) 84a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) MESSAGE_HANDLER_EX(WM_SIZE, OnSize) 855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) END_MSG_MAP() 865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) HWND hwnd() { return m_hWnd; } 885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Called when the child window is to be reparented to a new window. 905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // The |parent| parameter contains the new parent window. 915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void UpdateParent(HWND parent); 925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) HWND GetParent(); 935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) IAccessible* window_accessible() { return window_accessible_; } 955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Functions to show and hide the window. 975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void Show(); 985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void Hide(); 995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Resizes the window to the bounds passed in. 1015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void SetBounds(const gfx::Rect& bounds); 1025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 103116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // The pointer to the containing RenderWidgetHostViewAura instance is passed 104116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // here. 105116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch void set_host(RenderWidgetHostViewAura* host) { 106116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch host_ = host; 107116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch } 108116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 1095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) protected: 1105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual void OnFinalMessage(HWND hwnd) OVERRIDE; 1115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) private: 1135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) LegacyRenderWidgetHostHWND(HWND parent); 114116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch ~LegacyRenderWidgetHostHWND(); 1155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool Init(); 1175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 118a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Returns the target to which the windows input events are forwarded. 119a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) static ui::WindowEventTarget* GetWindowEventTarget(HWND parent); 120a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 1215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) LRESULT OnEraseBkGnd(UINT message, WPARAM w_param, LPARAM l_param); 1225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) LRESULT OnGetObject(UINT message, WPARAM w_param, LPARAM l_param); 1235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) LRESULT OnKeyboardRange(UINT message, WPARAM w_param, LPARAM l_param, 1245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) BOOL& handled); 1255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) LRESULT OnMouseLeave(UINT message, WPARAM w_param, LPARAM l_param); 1265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) LRESULT OnMouseRange(UINT message, WPARAM w_param, LPARAM l_param, 1275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) BOOL& handled); 1285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) LRESULT OnMouseActivate(UINT message, WPARAM w_param, LPARAM l_param); 1295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) LRESULT OnTouch(UINT message, WPARAM w_param, LPARAM l_param); 1305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) LRESULT OnScroll(UINT message, WPARAM w_param, LPARAM l_param); 131a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) LRESULT OnNCHitTest(UINT message, WPARAM w_param, LPARAM l_param); 1325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) LRESULT OnNCPaint(UINT message, WPARAM w_param, LPARAM l_param); 1345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) LRESULT OnPaint(UINT message, WPARAM w_param, LPARAM l_param); 1355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) LRESULT OnSetCursor(UINT message, WPARAM w_param, LPARAM l_param); 136a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) LRESULT OnNCCalcSize(UINT message, WPARAM w_param, LPARAM l_param); 137a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) LRESULT OnSize(UINT message, WPARAM w_param, LPARAM l_param); 1385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::win::ScopedComPtr<IAccessible> window_accessible_; 1405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Set to true if we turned on mouse tracking. 1425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool mouse_tracking_enabled_; 1435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 144116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch RenderWidgetHostViewAura* host_; 145116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 1465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(LegacyRenderWidgetHostHWND); 1475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}; 1485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} // namespace content 1505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#endif // CONTENT_BROWSER_RENDERER_HOST_LEGACY_RENDER_WIDGET_HOST_WIN_H_ 1525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 153