Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

768 lines
30 KiB

  1. //=========== Copyright Valve Corporation, All rights reserved. ===============//
  2. //
  3. // Purpose:
  4. //=============================================================================//
  5. #ifndef PANORAMA_HTML_H
  6. #define PANORAMA_HTML_H
  7. #ifdef _WIN32
  8. #pragma once
  9. #endif
  10. #include "panel2d.h"
  11. #include "tier1/utlmap.h"
  12. #include "tier1/utlstring.h"
  13. #include "../uievent.h"
  14. #include "mathlib/beziercurve.h"
  15. #include "../textinput/textinput.h"
  16. #if !defined( SOURCE2_PANORAMA ) && !defined( PANORAMA_PUBLIC_STEAM_SDK )
  17. #include "html/ihtmlchrome.h"
  18. #include "tier1/shared_memory.h"
  19. #endif
  20. class CTexturePanel;
  21. namespace panorama
  22. {
  23. class CTextTooltip;
  24. class CHTML;
  25. class CFileOpenDialog;
  26. struct HtmlFormHasFocus_t
  27. {
  28. HtmlFormHasFocus_t() :
  29. m_bInput( false ),
  30. m_bInputHasMultiplePeers( false ),
  31. m_bUserInputThisPage( false ),
  32. m_bFocusedElementChanged( true )
  33. {
  34. }
  35. void Reset()
  36. {
  37. m_bInput = false;
  38. m_bUserInputThisPage = false;
  39. m_bInputHasMultiplePeers = false;
  40. m_bFocusedElementChanged = true;
  41. }
  42. bool operator==(const HtmlFormHasFocus_t &rhs) const
  43. {
  44. return rhs.m_bInput == m_bInput &&
  45. rhs.m_sName == m_sName &&
  46. rhs.m_sSearchLabel == m_sSearchLabel &&
  47. rhs.m_sInputType == m_sInputType;
  48. }
  49. bool m_bInput;
  50. CUtlString m_sName;
  51. CUtlString m_sSearchLabel;
  52. bool m_bInputHasMultiplePeers;
  53. bool m_bUserInputThisPage;
  54. CUtlString m_sInputType;
  55. bool m_bFocusedElementChanged;
  56. };
  57. DECLARE_PANEL_EVENT2( HTMLURLChanged, const char *, const char * )
  58. DECLARE_PANEL_EVENT1( HTMLLoadPage, const char * )
  59. DECLARE_PANEL_EVENT2( HTMLFinishRequest, const char *, const char * )
  60. DECLARE_PANEL_EVENT1( HTMLTitle, const char * )
  61. DECLARE_PANEL_EVENT1( HTMLStatusText, const char * )
  62. DECLARE_PANEL_EVENT2( HTMLJSAlert, const char *, bool * )
  63. DECLARE_PANEL_EVENT2( HTMLJSConfirm, const char *, bool * )
  64. DECLARE_PANEL_EVENT2( HMTLLinkAtPosition, const char *, bool )
  65. DECLARE_PANEL_EVENT4( HMTLThumbNailImage, int, CUtlBuffer *, uint32, uint32 )
  66. DECLARE_PANEL_EVENT1( HTMLOpenLinkInNewTab, const char * )
  67. DECLARE_PANEL_EVENT2( HTMLOpenPopupTab, CHTML *, const char * )
  68. DECLARE_PANEL_EVENT2( HTMLBackForwardState, bool, bool )
  69. DECLARE_PANEL_EVENT2( HTMLUpdatePageSize, int, int )
  70. DECLARE_PANEL_EVENT5( HTMLSecurityStatus, const char *, bool, bool, bool, const char * )
  71. DECLARE_PANEL_EVENT1( HTMLFullScreen, bool )
  72. DECLARE_PANEL_EVENT2( HTMLStartMousePanning, int, int )
  73. DECLARE_PANEL_EVENT0( HTMLStopMousePanning )
  74. DECLARE_PANEL_EVENT0( HTMLCloseWindow )
  75. DECLARE_PANEL_EVENT2( HTMLFormHasFocus, HtmlFormHasFocus_t, const char * /* URL */ )
  76. DECLARE_PANEL_EVENT2( HTMLScreenShotTaken, const char *, const char * )
  77. DECLARE_PANEL_EVENT1( HTMLFocusedNodeValue, const char * )
  78. DECLARE_PANEL_EVENT0( HTMLSteamRightPadMoving );
  79. DECLARE_PANEL_EVENT2( HTMLStartRequest, const char *, bool * );
  80. class CImagePanel;
  81. enum CursorCode
  82. {
  83. eCursorNone,
  84. eCursorArrow
  85. };
  86. class IUIDoubleBufferedTexture;
  87. class CTransform3D;
  88. extern const int k_nExtraScrollRoom; // max number of padding pixels to use if needed
  89. //-----------------------------------------------------------------------------
  90. // Purpose:
  91. //-----------------------------------------------------------------------------
  92. class CHTML : public CPanel2D, public ITextInputControl
  93. #if !defined( SOURCE2_PANORAMA ) && !defined( PANORAMA_PUBLIC_STEAM_SDK )
  94. , public IHTMLResponses
  95. #endif
  96. {
  97. DECLARE_PANEL2D( CHTML, CPanel2D );
  98. public:
  99. CHTML( CPanel2D *parent, const char * pchPanelID, bool bPopup = false );
  100. virtual ~CHTML();
  101. void Shutdown();
  102. // panel2d overrides
  103. virtual void Paint();
  104. virtual bool BSetProperty( CPanoramaSymbol symName, const char *pchValue ) OVERRIDE;
  105. virtual void OnLayoutTraverse( float flFinalWidth, float flFinalHeight );
  106. virtual void OnStylesChanged();
  107. virtual bool BRequiresContentClipLayer() OVERRIDE { return true; } // BUGBUG Alfred - fix ::Paint to scale u/v offsets rather than requiring a clipping
  108. // simple browser management
  109. void OpenURL(const char *);
  110. void PostURL( const char *pchURL, const char *pchPostData );
  111. void AddHeader( const char *pchHeader, const char *pchValue );
  112. void StopLoading();
  113. void Refresh();
  114. void GoBack();
  115. void GoForward();
  116. bool BCanGoBack();
  117. bool BCanGoForward();
  118. // kb/mouse management
  119. virtual bool OnKeyDown( const KeyData_t &code ) OVERRIDE;
  120. virtual bool OnKeyUp( const KeyData_t & code ) OVERRIDE;
  121. virtual bool OnKeyTyped( const KeyData_t &unichar ) OVERRIDE;
  122. virtual bool OnGamePadDown( const GamePadData_t &code ) OVERRIDE;
  123. virtual bool OnGamePadUp( const GamePadData_t &code ) OVERRIDE;
  124. virtual bool OnGamePadAnalog( const GamePadData_t &code ) OVERRIDE;
  125. virtual bool OnMouseButtonDown( const MouseData_t &code ) OVERRIDE;
  126. virtual bool OnMouseButtonUp( const MouseData_t &code ) OVERRIDE;
  127. virtual bool OnMouseButtonDoubleClick( const MouseData_t &code ) OVERRIDE;
  128. virtual bool OnMouseWheel( const MouseData_t &code ) OVERRIDE;
  129. virtual void OnMouseMove( float flMouseX, float flMouseY ) OVERRIDE;
  130. virtual void SetupJavascriptObjectTemplate() OVERRIDE;
  131. // run input event processing for something that may not be a real input event, so don't bubble to parents, etc.
  132. bool OnGamePadDownImpl( const GamePadData_t &code, bool *out_pbOptionalResult = nullptr );
  133. bool OnGamePadAnalogImpl( const GamePadData_t &code, bool *out_pbOptionalResult = nullptr );
  134. bool ProcessAnalogScroll( float fValueX, float fValueY, double fTimeDelta, float fDeadzoneValue );
  135. bool ProcessAnalogZoom( float fValueX, float fValueY, double fTimeDelta, float fDeadzoneValue );
  136. void ProcessRawScroll( bool bFingerDown );
  137. void ProcessRawZoom( float fValueRaw );
  138. // browser helpers
  139. void Copy();
  140. void Paste();
  141. void RequestLinkUnderGamepad() { RequestLinkAtPosition( GetActualLayoutWidth()/2 - GetHScrollOffset(), GetActualLayoutHeight()/2 - GetVScrollOffset() ); }
  142. void RequestLinkUnderMouse() { RequestLinkAtPosition( m_flCursorX - GetHScrollOffset(), m_flCursorY - GetVScrollOffset() ); }
  143. void ZoomToElementUnderPanelCenter();
  144. void ZoomToElementUnderMouse();
  145. const char *PchLastLinkAtPosition() { return m_LinkAtPos.m_sURL; }
  146. void RunJavascript( const char *pchScript );
  147. void ViewSource();
  148. void SetHorizontalScroll( int scroll );
  149. void SetVerticalScroll( int scroll );
  150. void OnHTMLCursorMove( float flMouseX, float flMouseY );
  151. // finding text on the page
  152. void Find( const char *pchSubStr );
  153. void StopFind();
  154. void FindNext();
  155. void FindPrevious();
  156. void SetFileDialogChoice( const char *pchFileName ); // callback if cef wanted us to pick a file
  157. bool BAcceptMouseInput(); // returns true if the control is listening to mouse input right now, false if gamepad input mode is on
  158. virtual bool BRequiresFocus() OVERRIDE { return true; }
  159. bool BIgnoreMouseBackForwardButtons() { return m_bIgnoreMouseBackForwardButtons; }
  160. void SetIgnoreMouseBackForwardButtons( bool bIgnore ) { m_bIgnoreMouseBackForwardButtons = bIgnore; }
  161. const char *PchCurrentURL() { return m_sCurrentURL; } // the current URL the browser has loaded
  162. const char *PchCurrentPageTitle() { return m_sHTMLTitle; } // the title of the currently loaded page
  163. void SaveCurrentPageToJPEG( const char *pchFileName, int nWide, int nTall ); // save this current page to a jpeg
  164. // results for JS alert popups
  165. void DismissJSDialog( bool bRetVal );
  166. static uint32 GetAndResetPaintCounter();
  167. void ReleaseTextureMemory( bool bSuppressTextureLoads = false );
  168. void RefreshTextureMemory();
  169. void CaptureThumbNailImage( CPanel2D *pEventTarget, int iUserData );
  170. void IncrementPageScale( float flScaleIncrement, bool bZoomFromOrigin = false );
  171. void ExitFullScreen();
  172. void ExecuteJavaScript( const char *pchScript );
  173. // SSL/security state for the loaded html page
  174. bool BIsSecure() const { return m_bIsSecure; }
  175. bool BIsCertError() const { return m_bIsCertError; }
  176. bool BIsEVCert() const { return m_bIsEVCert; }
  177. const char *PchCertName() const { return m_sCertName; }
  178. // if true don't allow the page to scroll beyond the page edges
  179. void SetDontAllowOverScroll( bool bState );
  180. void SetEmbeddedMode( bool bState );
  181. void ZoomPageToFocusedElement( int nLeftOffset, int nTopOffset );
  182. // ITextInputControl helpers
  183. virtual int32 GetCursorOffset() const { return 0; }
  184. virtual uint GetCharCount() const { return 0; }
  185. virtual const char *PchGetText() const { return ""; }
  186. virtual const wchar_t *PwchGetText() const { return L""; }
  187. virtual void InsertCharacterAtCursor( const wchar_t &unichar );
  188. virtual void InsertCharactersAtCursor( const wchar_t *pwch, size_t cwch )
  189. {
  190. for ( uint i = 0; i < cwch; i++ )
  191. InsertCharacterAtCursor( pwch[i] );
  192. }
  193. bool BSupportsImmediateTextReturn() { return false; }
  194. void RequestControlString() { RequestFocusedNodeValue(); }
  195. virtual CPanel2D *GetAssociatedPanel() { return this; }
  196. void PauseFlashVideoIfVisible();
  197. void ResetScrollbarsAndClearOverflow();
  198. void SetPopupChild(CHTML *pChild) { m_pPopupChild = pChild; }
  199. #ifdef DBGFLAG_VALIDATE
  200. virtual void ValidateClientPanel( CValidator &validator, const char *pchName ) OVERRIDE;
  201. static void ValidateStatics( CValidator &validator, const char *pchName );
  202. #endif
  203. class CHTMLVerticalScrollBar : public CScrollBar
  204. {
  205. DECLARE_PANEL2D( CHTMLVerticalScrollBar, CScrollBar );
  206. public:
  207. CHTMLVerticalScrollBar( CPanel2D *parent, const char * pchPanelID ) : CScrollBar( parent, pchPanelID )
  208. {
  209. m_pScrollThumb->AddClass( "VerticalScrollThumb" );
  210. }
  211. void ScrollToMousePos()
  212. {
  213. float flHeight = GetActualLayoutHeight();
  214. if ( flHeight > 0.00001f )
  215. {
  216. if ( m_bMouseWentDownOnThumb )
  217. {
  218. float flPercentDiff = (m_flMouseY - m_flMouseStartY) / flHeight;
  219. float flPositionOffset = flPercentDiff * GetRangeSize();
  220. float flPosition = m_flScrollStartPosition + flPositionOffset;
  221. SetScrollWindowPosition( clamp( flPosition, 0.0f, GetRangeSize() - GetScrollWindowSize() ), true );
  222. }
  223. else
  224. {
  225. float flPercent = m_flMouseY / flHeight;
  226. float flPos = GetRangeSize() * flPercent;
  227. SetScrollWindowPosition( clamp( flPos, 0.0f, GetRangeSize() - GetScrollWindowSize() ), true );
  228. }
  229. }
  230. }
  231. virtual ~CHTMLVerticalScrollBar() {}
  232. protected:
  233. virtual void UpdateLayout( bool bImmediateMove )
  234. {
  235. CUILength zero;
  236. zero.SetLength( 0.0f );
  237. if ( GetRangeSize() < 0.001f )
  238. return;
  239. CUILength length;
  240. float flXPosPercent = (GetScrollWindowPosition() - GetRangeMin()) / GetRangeSize();
  241. length.SetPercent( flXPosPercent * 100.0f );
  242. if ( bImmediateMove )
  243. m_pScrollThumb->SetPositionWithoutTransition( zero, length, zero );
  244. else
  245. m_pScrollThumb->SetPosition( zero, length, zero );
  246. float flWidthPercent = GetScrollWindowSize() / GetRangeSize();
  247. length.SetPercent( flWidthPercent*100.0f );
  248. m_pScrollThumb->AccessStyleDirty()->SetHeight( length );
  249. length.SetPercent( 100.0f );
  250. m_pScrollThumb->AccessStyleDirty()->SetWidth( length );
  251. m_bLastMoveImmediate = bImmediateMove;
  252. }
  253. };
  254. class CHTMLHorizontalScrollBar : public CScrollBar
  255. {
  256. DECLARE_PANEL2D( CHTMLHorizontalScrollBar, CScrollBar );
  257. public:
  258. CHTMLHorizontalScrollBar( CPanel2D *parent, const char * pchPanelID ) : CScrollBar( parent, pchPanelID )
  259. {
  260. m_pScrollThumb->AddClass( "HorizontalScrollThumb" );
  261. }
  262. void ScrollToMousePos()
  263. {
  264. float flWidth = GetActualLayoutWidth();
  265. if ( flWidth > 0.00001f )
  266. {
  267. if ( m_bMouseWentDownOnThumb )
  268. {
  269. float flPercentDiff = (m_flMouseX - m_flMouseStartX) / flWidth;
  270. float flPositionOffset = flPercentDiff * GetRangeSize();
  271. float flPosition = m_flScrollStartPosition + flPositionOffset;
  272. SetScrollWindowPosition( clamp( flPosition, 0.0f, GetRangeSize() - GetScrollWindowSize() ), true );
  273. }
  274. else
  275. {
  276. float flPercent = m_flMouseX / flWidth;
  277. float flPos = GetRangeSize() * flPercent;
  278. SetScrollWindowPosition( clamp( flPos, 0.0f, GetRangeSize() - GetScrollWindowSize() ), true );
  279. }
  280. }
  281. }
  282. virtual ~CHTMLHorizontalScrollBar() {}
  283. protected:
  284. virtual void UpdateLayout( bool bImmediateMove )
  285. {
  286. CUILength zero;
  287. zero.SetLength( 0.0f );
  288. if ( GetRangeSize() < 0.001f )
  289. return;
  290. CUILength length;
  291. float flXPosPercent = (GetScrollWindowPosition() - GetRangeMin()) / GetRangeSize();
  292. length.SetPercent( flXPosPercent * 100.0f );
  293. if ( bImmediateMove )
  294. m_pScrollThumb->SetPositionWithoutTransition( length, zero, zero );
  295. else
  296. m_pScrollThumb->SetPosition( length, zero, zero );
  297. float flWidthPercent = GetScrollWindowSize() / GetRangeSize();
  298. length.SetPercent( flWidthPercent*100.0f );
  299. m_pScrollThumb->AccessStyleDirty()->SetWidth( length );
  300. length.SetPercent( 100.0f );
  301. m_pScrollThumb->AccessStyleDirty()->SetHeight( length );
  302. m_bLastMoveImmediate = bImmediateMove;
  303. }
  304. };
  305. enum EHTMLScrollDirection
  306. {
  307. kHTMLScrollDirection_Up,
  308. kHTMLScrollDirection_Down,
  309. kHTMLScrollDirection_Left,
  310. kHTMLScrollDirection_Right
  311. };
  312. bool BCanScrollInDirection( EHTMLScrollDirection eDirection ) const;
  313. static float GetScrollDeadzoneScale() { return s_fScrollDeadzoneScale; }
  314. protected:
  315. // functions you can override to specialize html behavior
  316. virtual void OnURLChanged( const char *url, const char *pchPostData, bool bIsRedirect );
  317. virtual void OnFinishRequest(const char *url, const char *pageTitle);
  318. virtual void OnPageLoaded( const char *url, const char *pageTitle, const CUtlMap < CUtlString, CUtlString > &headers );
  319. virtual bool OnStartRequestInternal( const char *url, const char *target, const char *pchPostData, bool bIsRedirect );
  320. virtual void ShowPopup();
  321. virtual void HidePopup();
  322. virtual bool OnOpenNewTab( const char *pchURL, bool bForeground );
  323. virtual bool OnPopupHTMLWindow( const char *pchURL, int x, int y, int wide, int tall );
  324. virtual void SetHTMLTitle( const char *pchTitle );
  325. virtual void OnLoadingResource( const char *pchURL );
  326. virtual void OnSetStatusText(const char *text);
  327. virtual void OnSetCursor( CursorCode cursor );
  328. virtual void OnFileLoadDialog( const char *pchTitle, const char *pchInitialFile );
  329. virtual void OnShowToolTip( const char *pchText );
  330. virtual void OnUpdateToolTip( const char *pchText );
  331. virtual void OnHideToolTip();
  332. virtual void OnSearchResults( int iActiveMatch, int nResults );
  333. friend class ::CTexturePanel;
  334. IUIDoubleBufferedTexture *m_pDoubleBufferedTexture;
  335. IUIDoubleBufferedTexture *m_pDoubleBufferedTexturePending;
  336. IUIDoubleBufferedTexture *m_pDoubleBufferedTextureComboBox;
  337. int32 m_nTextureSerial; // serial number of the last texture we uploaded
  338. void RequestFocusedNodeValue();
  339. // if true then our html control overrides scrolling and scrollbars, if false we
  340. // let the web control scroll itself
  341. void SetManualHTMLScroll( bool bControlScroll ) { m_bControlPageScrolling = bControlScroll; }
  342. private:
  343. typedef void (CHTML::* ScrollFunc_t)( float, bool );
  344. bool ProcessAnalogScrollAxis( float fValue, float fDeadzoneValue, double fTimeDelta, ScrollFunc_t ScrollFunc );
  345. // we used to create the virtual mouse in our constructor, but now we don't know enough information at
  346. // construction time to know whether we want one (ie., if we're wrapped by CHTMLSimpleNavigationWrapper
  347. // we disable touchpad navigation). Instead we just try to lazy-create one at first use.
  348. void LazyCreateVirtualMouseIfNecessary();
  349. // getters/setters for html cef object
  350. void SetHTMLFocus();
  351. void KillHTMLFocus();
  352. int HorizontalScroll();
  353. int VerticalScroll();
  354. bool IsHorizontalScrollBarVisible();
  355. bool IsVeritcalScrollBarVisible();
  356. void RequestLinkAtPosition( int x, int y );
  357. void GetCookiesForURL( const char *pchURL );
  358. void UpdatePanoramaScrollBars();
  359. bool BHandleKeyPressPageScroll() const;
  360. #if defined( SOURCE2_PANORAMA ) || defined( PANORAMA_PUBLIC_STEAM_SDK )
  361. STEAM_CALLBACK( CHTML, OnLinkAtPositionResponse, HTML_LinkAtPosition_t, m_LinkAtPosRespose );
  362. STEAM_CALLBACK( CHTML, OnHTMLNeedsPaint, HTML_NeedsPaint_t, m_HTML_NeedsPaint );
  363. STEAM_CALLBACK( CHTML, OnHTMLStartRequest, HTML_StartRequest_t, m_HTML_StartRequest );
  364. STEAM_CALLBACK( CHTML, OnHTMLCloseBrowser, HTML_CloseBrowser_t, m_HTML_CloseBrowser );
  365. STEAM_CALLBACK( CHTML, OnHTMLURLChanged, HTML_URLChanged_t, m_HTML_URLChanged );
  366. STEAM_CALLBACK( CHTML, OnHTMLFinishedRequest, HTML_FinishedRequest_t, m_HTML_FinishedRequest );
  367. STEAM_CALLBACK( CHTML, OnHTMLOpenLinkInNewTab, HTML_OpenLinkInNewTab_t, m_HTML_OpenLinkInNewTab );
  368. STEAM_CALLBACK( CHTML, OnHTMLChangedTitle, HTML_ChangedTitle_t, m_HTML_ChangedTitle );
  369. STEAM_CALLBACK( CHTML, OnHTMLSearchResults, HTML_SearchResults_t, m_HTML_SearchResults );
  370. STEAM_CALLBACK( CHTML, OnHTMLCanGoBackAndForward, HTML_CanGoBackAndForward_t, m_HTML_CanGoBackAndForward );
  371. STEAM_CALLBACK( CHTML, OnHTMLHorizontalScroll, HTML_HorizontalScroll_t, m_HTML_HorizontalScroll );
  372. STEAM_CALLBACK( CHTML, OnHTMLVerticalScroll, HTML_VerticalScroll_t, m_HTML_VerticalScroll );
  373. STEAM_CALLBACK( CHTML, OnHTMLJSAlert, HTML_JSAlert_t, m_HTML_JSAlert );
  374. STEAM_CALLBACK( CHTML, OnHTMLJSConfirm, HTML_JSConfirm_t, m_HTML_JSConfirm );
  375. STEAM_CALLBACK( CHTML, OnHTMLFileOpenDialog, HTML_FileOpenDialog_t, m_HTML_FileOpenDialog );
  376. STEAM_CALLBACK( CHTML, OnHTMLNewWindow, HTML_NewWindow_t, m_HTML_NewWindow );
  377. STEAM_CALLBACK( CHTML, OnHTMLSetCursor, HTML_SetCursor_t, m_HTML_SetCursor );
  378. STEAM_CALLBACK( CHTML, OnHTMLStatusText, HTML_StatusText_t, m_HTML_StatusText );
  379. STEAM_CALLBACK( CHTML, OnHTMLShowToolTip, HTML_ShowToolTip_t, m_HTML_ShowToolTip );
  380. STEAM_CALLBACK( CHTML, OnHTMLUpdateToolTip, HTML_UpdateToolTip_t, m_HTML_UpdateToolTip );
  381. STEAM_CALLBACK( CHTML, OnHTMLHideToolTip, HTML_HideToolTip_t, m_HTML_HideToolTip );
  382. #else
  383. // message handlers for ipc thread
  384. void BrowserSetIndex( int idx ) { m_iBrowser = idx; SendPendingHTMLMessages(); }
  385. int BrowserGetIndex() { return m_iBrowser; }
  386. void BrowserReady( const CMsgBrowserReady *pCmd );
  387. void BrowserSetSharedPaintBuffers( const CMsgSetSharedPaintBuffers *pCmd );
  388. void BrowserNeedsPaint( const CMsgNeedsPaint *pCmd );
  389. void BrowserStartRequest( const CMsgStartRequest *pCmd );
  390. void BrowserURLChanged( const CMsgURLChanged *pCmd );
  391. void BrowserLoadedRequest( const CMsgLoadedRequest *pCmd );
  392. void BrowserFinishedRequest(const CMsgFinishedRequest *pCmd);
  393. void BrowserPageSecurity( const CMsgPageSecurity *pCmd );
  394. void BrowserShowPopup( const CMsgShowPopup *pCmd );
  395. void BrowserHidePopup( const CMsgHidePopup *pCmd );
  396. void BrowserOpenNewTab( const CMsgOpenNewTab *pCmd );
  397. IHTMLResponses *BrowserPopupHTMLWindow( const CMsgPopupHTMLWindow *pCmd );
  398. void BrowserSetHTMLTitle( const CMsgSetHTMLTitle *pCmd );
  399. void BrowserLoadingResource( const CMsgLoadingResource *pCmd );
  400. void BrowserStatusText( const CMsgStatusText *pCmd );
  401. void BrowserSetCursor( const CMsgSetCursor *pCmd );
  402. void BrowserFileLoadDialog( const CMsgFileLoadDialog *pCmd );
  403. void BrowserShowToolTip( const CMsgShowToolTip *pCmd );
  404. void BrowserUpdateToolTip( const CMsgUpdateToolTip *pCmd );
  405. void BrowserHideToolTip( const CMsgHideToolTip *pCmd );
  406. void BrowserSearchResults( const CMsgSearchResults *pCmd );
  407. void BrowserClose( const CMsgClose *pCmd );
  408. void BrowserHorizontalScrollBarSizeResponse( const CMsgHorizontalScrollBarSizeResponse *pCmd );
  409. void BrowserVerticalScrollBarSizeResponse( const CMsgVerticalScrollBarSizeResponse *pCmd );
  410. void BrowserGetZoomResponse( const CMsgGetZoomResponse *pCmd ) {}
  411. void BrowserLinkAtPositionResponse( const CMsgLinkAtPositionResponse *pCmd );
  412. void BrowserZoomToElementAtPositionResponse( const CMsgZoomToElementAtPositionResponse *pCmd );
  413. void BrowserJSAlert( const CMsgJSAlert *pCmd );
  414. void BrowserJSConfirm( const CMsgJSConfirm *pCmd );
  415. void BrowserCanGoBackandForward( const CMsgCanGoBackAndForward *pCmd );
  416. void BrowserOpenSteamURL( const CMsgOpenSteamURL *pCmd );
  417. void BrowserSizePopup( const CMsgSizePopup *pCmd );
  418. void BrowserScalePageToValueResponse( const CMsgScalePageToValueResponse *pCmd );
  419. void BrowserRequestFullScreen( const CMsgRequestFullScreen *pCmd );
  420. void BrowserExitFullScreen( const CMsgExitFullScreen *pCmd );
  421. void BrowserGetCookiesForURLResponse( const CMsgGetCookiesForURLResponse *pCmd );
  422. void BrowserNodeGotFocus( const CMsgNodeHasFocus *pCmd );
  423. void BrowserSavePageToJPEGResponse( const CMsgSavePageToJPEGResponse *pCmd );
  424. void BrowserFocusedNodeValueResponse( const CMsgFocusedNodeTextResponse *pCmd );
  425. void BrowserComboNeedsPaint(const CMsgComboNeedsPaint *pCmd);
  426. bool BSupportsOffMainThreadPaints();
  427. void ThreadNotifyPendingPaints();
  428. #endif
  429. // helpers to control browser side, pos and textures
  430. void SetBrowserSize( int wide, int tall );
  431. void SendPendingHTMLMessages();
  432. // helpers to move the html page around inside the control
  433. void ScrollPageUp( float flScrollValue, bool bApplyBezier );
  434. void ScrollPageDown( float flScrollValue, bool bApplyBezier );
  435. void ScrollPageLeft( float flScrollValue, bool bApplyBezier );
  436. void ScrollPageRight( float flScrollValue, bool bApplyBezier );
  437. // Overrides for scroll bar to call back to us rather than normal panel2d call
  438. virtual void ScrollToXPercent( float flXPercent );
  439. virtual void ScrollToYPercent( float flXPercent );
  440. // event handlers
  441. bool OnGamepadInput();
  442. bool OnPropertyTransitionEnd( const CPanelPtr< IUIPanel > &pPanel, CStyleSymbol prop );
  443. bool OnSetBrowserSize( const CPanelPtr< IUIPanel > &pPanel, int nWide, int nTall );
  444. bool OnHTMLFormFocusPending( const CPanelPtr< IUIPanel > &pPanel );
  445. bool OnInputFocusSet( const panorama::CPanelPtr< panorama::IUIPanel > &ptrPanel );
  446. bool OnInputFocusLost( const panorama::CPanelPtr< panorama::IUIPanel > &ptrPanel );
  447. bool OnHTMLScreenShotCaptured( const panorama::CPanelPtr< panorama::IUIPanel > &ptrPanel, int nThumbNailWidth, int nThumbNailHeight );
  448. bool OnHTMLCommitZoom( const panorama::CPanelPtr< panorama::IUIPanel > &ptrPanel, float flZoom );
  449. bool OnHTMLRequestRepaint( const panorama::CPanelPtr< panorama::IUIPanel > &ptrPanel );
  450. #if defined( SOURCE2_PANORAMA ) || defined( PANORAMA_PUBLIC_STEAM_SDK )
  451. bool OnFileOpenDialogFilesSelected( const panorama::CPanelPtr< panorama::IUIPanel > &ptrPanel, const char *pszFiles );
  452. #endif
  453. // moving the html texture around
  454. void ResizeBrowserTextureIfNeeded();
  455. int AdjustPageScrollForTextureOffset( int &nTargetValue, const int nCurScroll, const int nMaxScroll, float &flOffsetTextureScroll, const float flMaxTextureScroll );
  456. int GetHScrollOffset()
  457. {
  458. return m_ScrollLeft.m_flOffsetTextureScroll;
  459. }
  460. int GetVScrollOffset()
  461. {
  462. return m_ScrollUp.m_flOffsetTextureScroll;
  463. }
  464. void ClampTextureScroll( bool bAllowScrollBorder = true );
  465. bool m_bInitialized; // used to prevent double shutdown
  466. bool m_bReady; // When we are ready to load a url
  467. CTexturePanel *m_pTexurePanel;
  468. int m_nWindowWide, m_nWindowTall; // how big the html texture should be
  469. int m_nTextureWide, m_nTextureTall;
  470. // find in page state
  471. bool m_bInFind;
  472. CUtlString m_sLastSearchString;
  473. CUtlString m_sURLToLoad; // url to load once the browser is created
  474. CUtlString m_sURLPostData; // post data for url to load
  475. CUtlString m_sCurrentURL; // the current url we have loaded
  476. CUtlString m_sHTMLTitle; // the title of the page we are on
  477. int m_iBrowser; // our browser handle
  478. float m_flZoom; // what zoom level we are at
  479. bool m_bLastKeyFocus; // tracking for when key focus changes in style application
  480. struct ScrollControl_t
  481. {
  482. ScrollControl_t()
  483. {
  484. Reset();
  485. }
  486. void Reset()
  487. {
  488. m_flOffsetTextureScroll = 0.0f;
  489. m_bScrollingUp = false;
  490. m_flLastScrollTime = 0.0f;
  491. }
  492. float m_flOffsetTextureScroll; // amount the html texture is scrolled around the panel itself
  493. bool m_bScrollingUp; // we are scrolling up (or left) on the page last?
  494. double m_flLastScrollTime; // when did we scroll in this direction last, used for accel curve
  495. };
  496. ScrollControl_t m_ScrollUp;
  497. ScrollControl_t m_ScrollLeft;
  498. struct ScrollData_t
  499. {
  500. ScrollData_t()
  501. {
  502. m_bVisible = false;
  503. m_nMaxScroll = m_nScroll = m_nPageSize = m_nWebScroll = 0;
  504. }
  505. bool operator==( const ScrollData_t &rhs ) const
  506. {
  507. return rhs.m_bVisible == m_bVisible &&
  508. rhs.m_nScroll == m_nScroll &&
  509. rhs.m_nPageSize == m_nPageSize &&
  510. rhs.m_nMaxScroll == m_nMaxScroll;
  511. }
  512. bool operator!=( const ScrollData_t &rhs ) const
  513. {
  514. return !operator==(rhs);
  515. }
  516. bool m_bVisible; // is the scroll bar visible
  517. int m_nMaxScroll; // most amount of pixels we can scroll
  518. int m_nPageSize; // the underlying size of the page itself in pixels
  519. int m_nScroll; // currently scrolled amount of pixels
  520. int m_nWebScroll; // last scrolled return value from cef, not updated locally
  521. };
  522. bool ScrollHelper( ScrollControl_t &scrollControl, float flScrollDelta, int iMaxScrollOffset, ScrollData_t &scrollBar, float &flScrollHTMLAmount, bool bApplyBezier ); // shared code when scrolling around the page
  523. bool SetupScrollBar( const ScrollData_t & scrollData, bool bHorizontal, float flContentSize, float flMaxSize );
  524. CScrollBar *MakeScrollBar( bool bHorizontal);
  525. ScrollData_t m_scrollHorizontal; // details of horizontal scroll bar
  526. ScrollData_t m_scrollVertical; // details of vertical scroll bar
  527. CCubicBezierCurve< Vector2D > m_ScrollBezier; // the curve to scale scroll accel by
  528. struct LinkAtPos_t
  529. {
  530. LinkAtPos_t() { m_bLiveLink = false; }
  531. CUtlString m_sURL;
  532. bool m_bLiveLink;
  533. bool m_bInput;
  534. };
  535. LinkAtPos_t m_LinkAtPos; // cache for link at pos requests, because the request is async
  536. // last position we saw the mouse at
  537. float m_flCursorX;
  538. float m_flCursorY;
  539. double m_flGamePadInputTime; // last time we saw input from the gamepad
  540. bool m_bPopupVisible; // true if a popup menu is visible on the client
  541. bool m_bCanGoBack;
  542. bool m_bCanGoForward;
  543. bool m_bIgnoreMouseBackForwardButtons;
  544. int m_nHTMLPageWide; // last size we told CEF the page should be
  545. int m_nHTMLPageTall;
  546. CHTMLVerticalScrollBar *m_pVerticalScrollBar; // our own copy of the scroll bars that we control manually
  547. CHTMLHorizontalScrollBar *m_pHorizontalScrollBar;
  548. float m_flLastVeritcalScrollPos;
  549. float m_flLastHorizontalScrollPos;
  550. static uint32 sm_PaintCount;
  551. uint32 m_PageLoadCount; // the number of posturl calls we have made
  552. #if !defined( SOURCE2_PANORAMA ) && !defined( PANORAMA_PUBLIC_STEAM_SDK )
  553. CUtlVector<HTMLCommandBuffer_t *> m_vecPendingMessages;
  554. #endif
  555. bool m_bSuppressTextureLoads;
  556. bool m_bCaptureThumbNailThisFrame;
  557. CPanel2D *m_pCaptureEventTarget;
  558. int m_nCaptureUserData;
  559. bool m_bCommenceZoomOperationOnTextureUpload; // when the next texture upload is ready, should we apply scale/offset transforms we have saved above
  560. float m_flHorizScrollOffset; // the offset between page scroll and texture scroll we had at the start of a zoom
  561. float m_flVertScrollOffset; // the offset between page scroll and texture scroll we had at the start of a zoom
  562. bool m_bFullScreen; // are we in fullscreen right now?
  563. bool m_bConfigureYouTubeHTML5OptIn; // are we doing the forcefully opt into youtube html5 beta path
  564. bool m_bMousePanningActive; // true if the mouse is in panning mode
  565. Vector2D m_vecMousePanningPos; // the x,y pos of the mouse over the panel when middle panning started
  566. CImagePanel *m_pMousePanningImage; // the image to show when panning
  567. CCubicBezierCurve< Vector2D > m_MousePanBezier; // the curve to scale panning accel by
  568. bool m_bIsSecure; // is this page ssl secure?
  569. bool m_bIsCertError; // did we have a cert error when loading?
  570. bool m_bIsEVCert; // is it an EV cert?
  571. CUtlString m_sCertName; // who was the cert issued to?
  572. bool m_bEmbedded; // if true we are embedded instance, just show html pages and simple scrolling, not complex interactions
  573. bool m_bAllowOverScroll; // if true allow scrolling the edge of the texture beyond the edge of the screen (i.e so you can hover the recticle at any point)
  574. bool m_bLastScrollbarSetupAllowedOverScroll;
  575. float m_flMouseLastX;
  576. float m_flMouseLastY;
  577. float m_flLastSteamPadScroll;
  578. uint32 m_unSteamPadScrollRepeats;
  579. panorama::HtmlFormHasFocus_t m_evtFocus; // used for saving state of controls that have focus info dispatched
  580. bool m_bPendingInputZoom; // true if we are zooming into an input element
  581. bool m_bFocusEventSentForClick; // time we sent a focus event to the browser
  582. bool m_bDidMousePanWhileMouseDown; // did we do panning with the mouse held down
  583. bool m_bWaitingForZoomResponse;
  584. Vector2D m_LastSteamRightPad;
  585. panorama::CTextTooltip *m_pTooltip;
  586. bool m_bGotKeyDown;
  587. #if defined( SOURCE2_PANORAMA ) || defined( PANORAMA_PUBLIC_STEAM_SDK )
  588. HHTMLBrowser m_HTMLBrowser;
  589. void OnBrowserReady( HTML_BrowserReady_t *pBrowserReady, bool bIOFailure );
  590. CCallResult< CHTML, HTML_BrowserReady_t > m_SteamCallResultBrowserReady;
  591. CPanelPtr< CFileOpenDialog > m_pFileOpenDialog;
  592. CUtlVector<HHTMLBrowser> m_vecDenyNewBrowserWindows;
  593. #else
  594. CChromePaintBufferClient m_SharedPaintBuffer;
  595. #endif
  596. int m_nPopupX;
  597. int m_nPopupY;
  598. int m_nPopupWide;
  599. int m_nPopupTall;
  600. int m_nTextureSerialCombo;
  601. CUtlBuffer m_ComboTexture;
  602. CHTML *m_pPopupChild;
  603. CThreadMutex m_mutexHTMLTexture;
  604. CThreadMutex m_mutexScreenShot;
  605. CUtlBuffer m_bufScreenshotTexture;
  606. float m_flScrollRemainder;
  607. int m_nTargetHorizontalScrollValue;
  608. int m_nTargetVerticalScrollValue;
  609. bool m_bControlPageScrolling;
  610. // virtual mouse used when steam controller is connected
  611. IVirtualMouse *m_pLeftMousePad;
  612. Vector2D m_vecVirtualScrollPrev;
  613. Vector2D m_vecVirtualScrollOrigin;
  614. bool m_bVerticalAxisSnap;
  615. bool m_bClickingLeftPad;
  616. bool m_bMarkZoomStart;
  617. float m_flInitialZoomLevel;
  618. float m_flZoomSwipeOriginPosition;
  619. static const float s_fScrollDeadzoneScale;
  620. };
  621. //-----------------------------------------------------------------------------
  622. // Purpose:
  623. //-----------------------------------------------------------------------------
  624. class CHTMLSimpleNavigationWrapper : public CPanel2D
  625. {
  626. DECLARE_PANEL2D( CHTMLSimpleNavigationWrapper, CPanel2D );
  627. public:
  628. CHTMLSimpleNavigationWrapper( CPanel2D *pParent, const char *pchPanelID );
  629. virtual bool BSetProperty( CPanoramaSymbol symName, const char *pchValue ) OVERRIDE;
  630. virtual bool OnGamePadDown( const GamePadData_t &code ) OVERRIDE;
  631. virtual bool OnGamePadAnalog( const GamePadData_t &code ) OVERRIDE;
  632. virtual bool OnMouseWheel( const MouseData_t &code ) OVERRIDE;
  633. private:
  634. void EnsureHTMLPanelReference();
  635. private:
  636. CHTML *m_pHTML;
  637. CPanoramaSymbol m_symWrappedHTMLID;
  638. bool m_bInEventProcessing;
  639. };
  640. } // namespace panorama
  641. #endif // PANORAMA_HTML_H