1 Star 0 Fork 0

yoyojacky/CSMoE

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
HTML.cpp 64.44 KB
一键复制 编辑 原始数据 按行查看 历史
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
// This class is a message box that has two buttons, ok and cancel instead of
// just the ok button of a message box. We use a message box class for the ok button
// and implement another button here.
//
// $NoKeywords: $
//=============================================================================//
#include <vgui/IPanel.h>
#include <vgui/IInputInternal.h>
#include <vgui/ISurface.h>
#include <vgui/IBorder.h>
#include <vgui/IVGui.h>
#include <tier1/KeyValues.h>
#include "AnimationController.h"
#include "EditablePanel.h"
#include "Menu.h"
#include "MessageBox.h"
#include "QueryBox.h"
#include "ScrollBar.h"
#include "HTML.h"
//#include <tier0/memdbgoff.h>
//#include "htmlmessages.pb.h"
//#include <tier0/memdbgon.h>
#include "steam/steamtypes.h"
#include "html/ihtmlserializer.h"
#include "html/ipainthtml.h"
#include "html/ihtmlchrome.h"
#include "html/ichromehtmlwrapper.h"
#include "FileSystem.h"
#include "../vgui2/src/vgui_key_translation.h"
#undef PostMessage
#undef MessageBox
#include "OfflineMode.h"
// memdbgon must be the last include file in a .cpp file
#include "tier0/memdbgon.h"
using namespace vgui2;
const int k_nMaxCustomCursors = 2; // the max number of custom cursors we keep cached PER html control
//-----------------------------------------------------------------------------
// Purpose: A simple passthrough panel to render the border onto the HTML widget
//-----------------------------------------------------------------------------
class HTMLInterior : public Panel
{
DECLARE_CLASS_SIMPLE( HTMLInterior, Panel );
public:
HTMLInterior( HTML *parent ) : BaseClass( parent, "HTMLInterior" )
{
m_pHTML = parent;
SetPaintBackgroundEnabled( false );
SetKeyBoardInputEnabled( false );
SetMouseInputEnabled( false );
}
private:
HTML *m_pHTML;
};
//-----------------------------------------------------------------------------
// Purpose: a vgui container for popup menus displayed by a control, only 1 menu for any control can be visible at a time
//-----------------------------------------------------------------------------
class HTMLComboBoxHost : public vgui2::EditablePanel
{
DECLARE_CLASS_SIMPLE( HTMLComboBoxHost, EditablePanel );
public:
HTMLComboBoxHost( HTML *parent, const char *panelName ) : EditablePanel( parent, panelName )
{
m_pParent = parent;
MakePopup(false);
}
~HTMLComboBoxHost() {}
virtual void PaintBackground();
virtual void OnMousePressed(MouseCode code);
virtual void OnMouseReleased(MouseCode code);
virtual void OnCursorMoved(int x,int y);
virtual void OnMouseDoublePressed(MouseCode code);
virtual void OnKeyTyped(wchar_t unichar);
virtual void OnKeyCodeTyped(KeyCode code);
virtual void OnKeyCodeReleased(KeyCode code);
virtual void OnMouseWheeled(int delta);
virtual void OnKillFocus()
{
if ( vgui2::input()->GetFocus() != m_pParent->GetVPanel() ) // if its not our parent trying to steal focus
{
BaseClass::OnKillFocus();
if ( m_pParent )
m_pParent->HidePopup();
}
}
virtual void PerformLayout()
{
// no op the perform layout as we just render the html controls popup texture into it
// we don't want the menu logic trying to play with its size
}
private:
HTML *m_pParent;
CUtlVector<HTMLCommandBuffer_t *> m_vecPendingMessages;
};
//-----------------------------------------------------------------------------
// Purpose: container class for any external popup windows the browser requests
//-----------------------------------------------------------------------------
class HTMLPopup : public vgui2::Frame
{
DECLARE_CLASS_SIMPLE( HTMLPopup, vgui2::Frame );
class PopupHTML : public vgui2::HTML
{
DECLARE_CLASS_SIMPLE( PopupHTML, vgui2::HTML );
public:
PopupHTML( Frame *parent, const char *pchName, bool allowJavaScript , bool bPopupWindow ) : HTML( parent, pchName, allowJavaScript, bPopupWindow ) { m_pParent = parent; }
virtual void OnSetHTMLTitle( const char *pchTitle )
{
BaseClass::OnSetHTMLTitle( pchTitle );
m_pParent->SetTitle( pchTitle, true );
}
private:
Frame *m_pParent;
};
public:
HTMLPopup( Panel *parent, const char *pchURL, const char *pchTitle ) : Frame( NULL, "HtmlPopup", true )
{
m_pHTML = new PopupHTML( this, "htmlpopupchild", true, true );
m_pHTML->OpenURL( pchURL, NULL, false );
SetTitle( pchTitle, true );
}
~HTMLPopup()
{
}
enum
{
vert_inset = 40,
horiz_inset = 6
};
void PerformLayout()
{
BaseClass::PerformLayout();
int wide, tall;
GetSize( wide, tall );
m_pHTML->SetPos( horiz_inset, vert_inset );
m_pHTML->SetSize( wide - horiz_inset*2, tall - vert_inset*2 );
}
void SetBounds( int x, int y, int wide, int tall )
{
BaseClass::SetBounds( x, y, wide + horiz_inset*2, tall + vert_inset*2 );
}
MESSAGE_FUNC( OnCloseWindow, "OnCloseWindow" )
{
Close();
}
private:
PopupHTML *m_pHTML;
};
//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
HTML::HTML(Panel *parent, const char *name, bool allowJavaScript, bool bPopupWindow) : Panel(parent, name)
{
m_iHTMLTextureID = 0;
m_iComboBoxTextureID = 0;
m_bCanGoBack = false;
m_bCanGoForward = false;
m_bInFind = false;
m_bRequestingDragURL = false;
m_bRequestingCopyLink = false;
m_flZoom = 100.0f;
m_bNeedsFullTextureUpload = false;
m_pInteriorPanel = new HTMLInterior( this );
SetPostChildPaintEnabled( true );
if (surface() && surface()->AccessChromeHTMLController())
{
IHTMLChromeController* pController = surface()->AccessChromeHTMLController();
m_Serializer = pController->CreateSerializer( this );
pController->CreateBrowser( m_Serializer->GetResponseTarget(), bPopupWindow, "Valve Half-Life" );
}
else
{
Warning("Unable to access ChromeHTMLController");
}
m_iScrollBorderX=m_iScrollBorderY=0;
m_bScrollBarEnabled = true;
m_bContextMenuEnabled = true;
m_bNewWindowsOnly = false;
m_iMouseX = m_iMouseY = 0;
m_iDragStartX = m_iDragStartY = 0;
m_nViewSourceAllowedIndex = -1;
m_iWideLastHTMLSize = m_iTalLastHTMLSize = 0;
_hbar = new ScrollBar(this, "HorizScrollBar", false);
_hbar->SetVisible(false);
_hbar->AddActionSignalTarget(this);
_vbar = new ScrollBar(this, "VertScrollBar", true);
_vbar->SetVisible(false);
_vbar->AddActionSignalTarget(this);
m_pFindBar = new HTML::CHTMLFindBar( this );
m_pFindBar->SetZPos( 2 );
m_pFindBar->SetVisible( false );
m_pComboBoxHost = new HTMLComboBoxHost( this, "ComboBoxHost" );
m_pComboBoxHost->SetPaintBackgroundEnabled( true );
m_pComboBoxHost->SetVisible( false );
m_pContextMenu = new Menu( this, "contextmenu" );
m_pContextMenu->AddMenuItem( "#vgui_HTMLBack", new KeyValues( "Command", "command", "back" ), this );
m_pContextMenu->AddMenuItem( "#vgui_HTMLForward", new KeyValues( "Command", "command", "forward" ), this );
m_pContextMenu->AddMenuItem( "#vgui_HTMLReload", new KeyValues( "Command", "command", "reload" ), this );
m_pContextMenu->AddMenuItem( "#vgui_HTMLStop", new KeyValues( "Command", "command", "stop" ), this );
m_pContextMenu->AddSeparator();
m_pContextMenu->AddMenuItem( "#vgui_HTMLCopyUrl", new KeyValues( "Command", "command", "copyurl" ), this );
m_iCopyLinkMenuItemID = m_pContextMenu->AddMenuItem( "#vgui_HTMLCopyLink", new KeyValues( "Command", "command", "copylink" ), this );
m_pContextMenu->AddMenuItem( "#TextEntry_Copy", new KeyValues( "Command", "command", "copy" ), this );
m_pContextMenu->AddMenuItem( "#TextEntry_Paste", new KeyValues( "Command", "command", "paste" ), this );
m_pContextMenu->AddSeparator();
m_nViewSourceAllowedIndex = m_pContextMenu->AddMenuItem( "#vgui_HTMLViewSource", new KeyValues( "Command", "command", "viewsource" ), this );
}
//-----------------------------------------------------------------------------
// Purpose: Destructor
//-----------------------------------------------------------------------------
HTML::~HTML()
{
m_pContextMenu->MarkForDeletion();
if (surface()->AccessChromeHTMLController())
{
surface()->AccessChromeHTMLController()->RemoveBrowser( m_Serializer->GetResponseTarget() );
m_Serializer = NULL;
}
/*
FOR_EACH_VEC( m_vecHCursor, i )
{
// BR FIXME!
// surface()->DeleteCursor( m_vecHCursor[i].m_Cursor );
}
m_vecHCursor.RemoveAll();
*/
}
//-----------------------------------------------------------------------------
// Purpose: Handle message to change our cursor
//-----------------------------------------------------------------------------
void HTML::OnSetCursorVGUI( int cursor )
{
SetCursor( (HCursor)cursor );
}
//-----------------------------------------------------------------------------
// Purpose: sets up colors/fonts/borders
//-----------------------------------------------------------------------------
void HTML::ApplySchemeSettings(IScheme *pScheme)
{
BaseClass::ApplySchemeSettings(pScheme);
BrowserResize();
}
//-----------------------------------------------------------------------------
// Purpose: overrides panel class, paints a texture of the HTML window as a background
//-----------------------------------------------------------------------------
void HTML::Paint()
{
//VPROF_BUDGET( "HTML::Paint()", VPROF_BUDGETGROUP_OTHER_VGUI );
BaseClass::Paint();
if ( m_iHTMLTextureID != 0 )
{
surface()->DrawSetTexture( m_iHTMLTextureID );
int tw = 0, tt = 0;
surface()->DrawSetColor( Color( 255, 255, 255, 255 ) );
GetSize( tw, tt );
surface()->DrawTexturedRect( 0, 0, tw, tt );
}
// If we have scrollbars, we need to draw the bg color under them, since the browser
// bitmap is a checkerboard under them, and they are transparent in the in-game client
if ( m_iScrollBorderX > 0 || m_iScrollBorderY > 0 )
{
int w, h;
GetSize( w, h );
IBorder *border = GetBorder();
int left = 0, top = 0, right = 0, bottom = 0;
if ( border )
{
border->GetInset( left, top, right, bottom );
}
surface()->DrawSetColor( GetBgColor() );
if ( m_iScrollBorderX )
{
surface()->DrawFilledRect( w-m_iScrollBorderX - right, top, w, h - bottom );
}
if ( m_iScrollBorderY )
{
surface()->DrawFilledRect( left, h-m_iScrollBorderY - bottom, w-m_iScrollBorderX - right, h );
}
}
}
//-----------------------------------------------------------------------------
// Purpose: paint the combo box texture if we have one
//-----------------------------------------------------------------------------
void HTML::PaintComboBox()
{
BaseClass::Paint();
if ( m_iComboBoxTextureID != 0 )
{
surface()->DrawSetTexture( m_iComboBoxTextureID );
surface()->DrawSetColor( Color( 255, 255, 255, 255 ) );
int tw = m_allocedComboBoxWidth;
int tt = m_allocedComboBoxHeight;
surface()->DrawTexturedRect( 0, 0, tw, tt );
}
}
//-----------------------------------------------------------------------------
// Purpose: overrides panel class, paints a texture of the HTML window as a background
//-----------------------------------------------------------------------------
void HTMLComboBoxHost::PaintBackground()
{
BaseClass::PaintBackground();
m_pParent->PaintComboBox();
}
//-----------------------------------------------------------------------------
// Purpose: causes a repaint when the layout changes
//-----------------------------------------------------------------------------
void HTML::PerformLayout()
{
BaseClass::PerformLayout();
Repaint();
int vbarInset = _vbar->IsVisible() ? _vbar->GetWide() : 0;
int maxw = GetWide() - vbarInset;
m_pInteriorPanel->SetBounds( 0, 0, maxw, GetTall() );
IScheme *pClientScheme = vgui2::scheme()->GetIScheme( vgui2::scheme()->GetScheme( "ClientScheme" ) );
int iSearchInsetY = 5;
int iSearchInsetX = 5;
int iSearchTall = 24;
int iSearchWide = 150;
const char *resourceString = pClientScheme->GetResourceString( "HTML.SearchInsetY");
if ( resourceString )
{
iSearchInsetY = atoi(resourceString);
}
resourceString = pClientScheme->GetResourceString( "HTML.SearchInsetX");
if ( resourceString )
{
iSearchInsetX = atoi(resourceString);
}
resourceString = pClientScheme->GetResourceString( "HTML.SearchTall");
if ( resourceString )
{
iSearchTall = atoi(resourceString);
}
resourceString = pClientScheme->GetResourceString( "HTML.SearchWide");
if ( resourceString )
{
iSearchWide = atoi(resourceString);
}
m_pFindBar->SetBounds( GetWide() - iSearchWide - iSearchInsetX - vbarInset, m_pFindBar->BIsHidden() ? -1*iSearchTall-5: iSearchInsetY, iSearchWide, iSearchTall );
}
//-----------------------------------------------------------------------------
// Purpose: updates the underlying HTML surface widgets position
//-----------------------------------------------------------------------------
void HTML::OnMove()
{
BaseClass::OnMove();
// tell cef where we are on the screen so plugins can correctly render
int nPanelAbsX, nPanelAbsY;
ipanel()->GetAbsPos( GetVPanel(), nPanelAbsX, nPanelAbsY );
m_Serializer->BrowserPosition( nPanelAbsX, nPanelAbsY );
if ( m_pComboBoxHost && m_pComboBoxHost->IsVisible() )
{
m_pComboBoxHost->SetVisible( false );
}
}
//-----------------------------------------------------------------------------
// Purpose: calculates the need for and position of both horizontal and vertical scroll bars
//-----------------------------------------------------------------------------
void HTML::CalcScrollBars(int w, int h)
{
bool bScrollbarVisible = _vbar->IsVisible();
if ( m_bScrollBarEnabled )
{
for ( int i = 0; i < 2; i++ )
{
int /*scrollx, scrolly,*/ scrollwide, scrolltall;
bool bVisible = false;
if ( i==0 )
{
//scrollx = m_scrollHorizontal.m_nX;
//scrolly = m_scrollHorizontal.m_nY;
scrollwide = m_scrollHorizontal.m_nWide;
scrolltall = m_scrollHorizontal.m_nTall;
bVisible = m_scrollHorizontal.m_bVisible;
// scrollbar positioning tweaks - should be moved into a resource file
scrollwide += 14;
scrolltall += 5;
}
else
{
//scrollx = m_scrollVertical.m_nX;
//scrolly = m_scrollVertical.m_nY;
scrollwide = m_scrollVertical.m_nWide;
scrolltall = m_scrollVertical.m_nTall;
bVisible = m_scrollVertical.m_bVisible;
// scrollbar positioning tweaks - should be moved into a resource file
//scrollx -= 3;
if ( m_scrollHorizontal.m_bVisible )
scrolltall += 16;
else
scrolltall -= 2;
scrollwide += 5;
}
if ( bVisible && scrollwide && scrolltall )
{
int panelWide, panelTall;
GetSize( panelWide, panelTall );
ScrollBar *bar = _vbar;
if ( i == 0 )
bar = _hbar;
if (!bar->IsVisible())
{
bar->SetVisible(true);
// displayable area has changed, need to force an update
PostMessage(this, new KeyValues("OnSliderMoved"), 0.02f);
}
int rangeWindow = panelTall - scrollwide;
if ( i==0 )
rangeWindow = panelWide - scrolltall;
int range = m_scrollVertical.m_nMax + m_scrollVertical.m_nTall;
if ( i == 0 )
range = m_scrollHorizontal.m_nMax + m_scrollVertical.m_nWide;
int curValue = m_scrollVertical.m_nScroll;
if ( i == 0 )
curValue = m_scrollHorizontal.m_nScroll;
bar->SetEnabled(false);
bar->SetRangeWindow( rangeWindow );
bar->SetRange( 0, range ); // we want the range [0.. (img_h - h)], but the scrollbar actually returns [0..(range-rangeWindow)] so make sure -h gets deducted from the max range value
bar->SetButtonPressedScrollValue( 5 );
if ( curValue > ( bar->GetValue() + 5 ) || curValue < (bar->GetValue() - 5 ) )
bar->SetValue( curValue );
if ( i == 0 )
{
bar->SetPos( 0, h - scrolltall - 1 );
bar->SetWide( scrollwide );
bar->SetTall( scrolltall );
}
else
{
bar->SetPos( w - scrollwide, 0 );
bar->SetTall( scrolltall );
bar->SetWide( scrollwide );
}
if ( i == 0 )
m_iScrollBorderY=scrolltall;
else
m_iScrollBorderX=scrollwide;
}
else
{
if ( i == 0 )
{
m_iScrollBorderY=0;
_hbar->SetVisible( false );
}
else
{
m_iScrollBorderX=0;
_vbar->SetVisible( false );
}
}
}
}
else
{
m_iScrollBorderX = 0;
m_iScrollBorderY=0;
_vbar->SetVisible(false);
_hbar->SetVisible(false);
}
if ( bScrollbarVisible != _vbar->IsVisible() )
InvalidateLayout();
}
//-----------------------------------------------------------------------------
// Purpose: opens the URL, will accept any URL that IE accepts
//-----------------------------------------------------------------------------
void HTML::OpenURL(const char *URL, const char *postData, bool force)
{
PostURL( URL, postData/*, force*/ );
}
//-----------------------------------------------------------------------------
// Purpose: opens the URL, will accept any URL that IE accepts
//-----------------------------------------------------------------------------
void HTML::PostURL(const char *URL, const char *pchPostData/*, bool force*/)
{
if ( m_Serializer->BrowserGetIndex() < 0 )
{
m_sPendingURLLoad = URL;
m_sPendingPostData = pchPostData;
return;
}
/*
if ( IsSteamInOfflineMode() && !force )
{
const char *baseDir = getenv("HTML_OFFLINE_DIR");
if ( baseDir )
{
// get the app we need to run
char htmlLocation[_MAX_PATH];
char otherName[128];
char fileLocation[_MAX_PATH];
if ( ! filesystem()->FileExists( baseDir ) )
{
Q_snprintf( otherName, sizeof(otherName), "%senglish.html", OFFLINE_FILE );
baseDir = otherName;
}
filesystem()->GetLocalCopy( baseDir ); // put this file on disk for IE to load
filesystem()->GetLocalPath( baseDir, fileLocation, sizeof(fileLocation) );
Q_snprintf(htmlLocation, sizeof(htmlLocation), "file://%s", fileLocation);
CHTMLProtoBufMsg<CMsgPostURL> cmd( eHTMLCommands_PostURL );
cmd.Body().set_url( htmlLocation );
DISPATCH_MESSAGE( eHTMLCommands_PostURL );
}
else
{
CHTMLProtoBufMsg<CMsgPostURL> cmd( eHTMLCommands_PostURL );
cmd.Body().set_url( URL );
DISPATCH_MESSAGE( eHTMLCommands_PostURL );
}
}
else
{
*/
if ( pchPostData && Q_strlen(pchPostData) > 0 )
{
m_Serializer->PostURL( URL, pchPostData );
}
else
{
m_Serializer->PostURL( URL, NULL );
}
/*
}
*/
}
//-----------------------------------------------------------------------------
// Purpose: opens the URL, will accept any URL that IE accepts
//-----------------------------------------------------------------------------
bool HTML::StopLoading()
{
m_Serializer->StopLoad();
return true;
}
//-----------------------------------------------------------------------------
// Purpose: refreshes the current page
//-----------------------------------------------------------------------------
bool HTML::Refresh()
{
m_Serializer->Reload();
return true;
}
//-----------------------------------------------------------------------------
// Purpose: Tells the browser control to go back
//-----------------------------------------------------------------------------
void HTML::GoBack()
{
m_Serializer->GoBack();
}
//-----------------------------------------------------------------------------
// Purpose: Tells the browser control to go forward
//-----------------------------------------------------------------------------
void HTML::GoForward()
{
m_Serializer->GoForward();
}
//-----------------------------------------------------------------------------
// Purpose: Checks if the browser can go back further
//-----------------------------------------------------------------------------
bool HTML::BCanGoBack()
{
return m_bCanGoBack;
}
//-----------------------------------------------------------------------------
// Purpose: Checks if the browser can go forward further
//-----------------------------------------------------------------------------
bool HTML::BCanGoFoward()
{
return m_bCanGoForward;
}
//-----------------------------------------------------------------------------
// Purpose: handle resizing
//-----------------------------------------------------------------------------
void HTML::OnSizeChanged(int wide,int tall)
{
BaseClass::OnSizeChanged(wide,tall);
UpdateSizeAndScrollBars();
UpdateCachedHTMLValues();
//#ifdef WIN32
// // under windows we get stuck in the windows message loop pushing out WM_WINDOWPOSCHANGED without returning in the windproc loop
// // so we need to manually pump the html dispatching of messages here
// if ( surface() && surface()->AccessChromeHTMLController() )
// {
// surface()->AccessChromeHTMLController()->RunFrame();
// }
//#endif
int newWide = wide;
int newTall = tall;
GetSize( wide, tall );
CalcScrollBars( newWide, newTall );
InvalidateLayout();
m_Serializer->RequestBrowserSizes();
}
//-----------------------------------------------------------------------------
// Purpose: Run javascript in the page
//-----------------------------------------------------------------------------
void HTML::RunJavascript( const char *pchScript )
{
m_Serializer->RunJavaScript( pchScript );
}
//-----------------------------------------------------------------------------
// Purpose: helper to convert UI mouse codes to CEF ones
//-----------------------------------------------------------------------------
int ConvertMouseCodeToCEFCode( MouseCode code )
{
switch( code )
{
case MOUSE_LEFT:
return IInputEventHTML::eButtonLeft;
break;
case MOUSE_RIGHT:
return IInputEventHTML::eButtonRight;
break;
case MOUSE_MIDDLE:
return IInputEventHTML::eButtonMiddle;
break;
default:
return IInputEventHTML::eButtonLeft;
break;
}
}
//-----------------------------------------------------------------------------
// Purpose: passes mouse clicks to the control
//-----------------------------------------------------------------------------
void HTML::OnMousePressed(MouseCode code)
{
m_sDragURL = NULL;
// mouse4 = back button
if ( code == MOUSE_4 )
{
PostActionSignal( new KeyValues( "HTMLBackRequested" ) );
return;
}
if ( code == MOUSE_5 )
{
PostActionSignal( new KeyValues( "HTMLForwardRequested" ) );
return;
}
if ( code == MOUSE_RIGHT && m_bContextMenuEnabled )
{
GetLinkAtPosition( m_iMouseX, m_iMouseY );
Menu::PlaceContextMenu( this, m_pContextMenu );
return;
}
// ask for the focus to come to this window
RequestFocus();
// now tell the browser about the click
// ignore right clicks if context menu has been disabled
if ( code != MOUSE_RIGHT )
{
m_Serializer->MouseDown( ConvertMouseCodeToCEFCode( code ) );
}
if ( code == MOUSE_LEFT )
{
input()->GetCursorPos( m_iDragStartX, m_iDragStartY );
int htmlx, htmly;
ipanel()->GetAbsPos( GetVPanel(), htmlx, htmly );
GetLinkAtPosition( m_iDragStartX - htmlx, m_iDragStartY - htmly );
m_bRequestingDragURL = true;
// make sure we get notified when the mouse gets released
if ( !m_sDragURL.IsEmpty() )
{
input()->SetMouseCapture( GetVPanel() );
}
}
}
//-----------------------------------------------------------------------------
// Purpose: passes mouse up events
//-----------------------------------------------------------------------------
void HTML::OnMouseReleased(MouseCode code)
{
if ( code == MOUSE_LEFT )
{
input()->SetMouseCapture( NULL_HANDLE );
input()->SetCursorOveride( 0 );
if ( !m_sDragURL.IsEmpty() && input()->GetMouseOver() != GetVPanel() && input()->GetMouseOver() != NULL_HANDLE )
{
// post the text as a drag drop to the target panel
KeyValues* kv = new KeyValues( "DragDrop" );
if ( ipanel()->RequestInfo( input()->GetMouseOver(), kv )
&& kv->GetPtr( "AcceptPanel" ) != NULL )
{
VPANEL vpanel = (VPANEL)kv->GetPtr( "AcceptPanel" );
ivgui()->PostMessage( vpanel, new KeyValues( "DragDrop", "text", m_sDragURL.Get() ), GetVPanel() );
}
kv->deleteThis();
}
m_sDragURL = NULL;
}
m_Serializer->MouseUp( ConvertMouseCodeToCEFCode( code ) );
}
//-----------------------------------------------------------------------------
// Purpose: keeps track of where the cursor is
//-----------------------------------------------------------------------------
void HTML::OnCursorMoved(int x,int y)
{
// Only do this when we are over the current panel
if ( vgui2::input()->GetMouseOver() == GetVPanel() )
{
m_iMouseX = x;
m_iMouseY = y;
m_Serializer->MouseMove( m_iMouseX, m_iMouseY );
}
else if ( !m_sDragURL.IsEmpty() )
{
if ( input()->GetMouseOver() == NULL_HANDLE )
{
// we're not over any vgui window, switch to the OS implementation of drag/drop
// BR FIXME
// surface()->StartDragDropText( m_sDragURL );
m_sDragURL = NULL;
}
}
if ( !m_sDragURL.IsEmpty() && !input()->GetCursorOveride() )
{
// if we've dragged far enough (in global coordinates), set to use the drag cursor
int gx, gy;
input()->GetCursorPos( gx, gy );
if ( abs(m_iDragStartX-gx) + abs(m_iDragStartY-gy) > 3 )
{
// input()->SetCursorOveride( dc_alias );
}
}
}
//-----------------------------------------------------------------------------
// Purpose: passes double click events to the browser
//-----------------------------------------------------------------------------
void HTML::OnMouseDoublePressed(MouseCode code)
{
m_Serializer->MouseDoubleClick( ConvertMouseCodeToCEFCode( code ) );
}
//-----------------------------------------------------------------------------
// Purpose: passes key presses to the browser (we don't current do this)
//-----------------------------------------------------------------------------
void HTML::OnKeyTyped(wchar_t unichar)
{
m_Serializer->KeyChar( unichar );
}
//-----------------------------------------------------------------------------
// Purpose: pop up the find dialog
//-----------------------------------------------------------------------------
void HTML::ShowFindDialog()
{
IScheme *pClientScheme = vgui2::scheme()->GetIScheme( vgui2::scheme()->GetScheme( "ClientScheme" ) );
if ( !pClientScheme )
return;
m_pFindBar->SetVisible( true );
m_pFindBar->RequestFocus();
m_pFindBar->SetText( "" );
m_pFindBar->HideCountLabel();
m_pFindBar->SetHidden( false );
int x = 0, y = 0, h = 0, w = 0;
m_pFindBar->GetBounds( x, y, w, h );
m_pFindBar->SetPos( x, -1*h );
int iSearchInsetY = 0;
const char *resourceString = pClientScheme->GetResourceString( "HTML.SearchInsetY");
if ( resourceString )
{
iSearchInsetY = atoi(resourceString);
}
float flAnimationTime = 0.0f;
resourceString = pClientScheme->GetResourceString( "HTML.SearchAnimationTime");
if ( resourceString )
{
flAnimationTime = atof(resourceString);
}
GetAnimationController()->RunAnimationCommand( m_pFindBar, "ypos", iSearchInsetY, 0.0f, flAnimationTime, AnimationController::INTERPOLATOR_LINEAR );
}
//-----------------------------------------------------------------------------
// Purpose: hide the find dialog
//-----------------------------------------------------------------------------
void HTML::HideFindDialog()
{
IScheme *pClientScheme = vgui2::scheme()->GetIScheme( vgui2::scheme()->GetScheme( "ClientScheme" ) );
if ( !pClientScheme )
return;
int x = 0, y = 0, h = 0, w = 0;
m_pFindBar->GetBounds( x, y, w, h );
float flAnimationTime = 0.0f;
const char *resourceString = pClientScheme->GetResourceString( "HTML.SearchAnimationTime");
if ( resourceString )
{
flAnimationTime = atof(resourceString);
}
GetAnimationController()->RunAnimationCommand( m_pFindBar, "ypos", -1*h-5, 0.0f, flAnimationTime, AnimationController::INTERPOLATOR_LINEAR );
m_pFindBar->SetHidden( true );
StopFind();
}
//-----------------------------------------------------------------------------
// Purpose: is the find dialog visible?
//-----------------------------------------------------------------------------
bool HTML::FindDialogVisible()
{
return m_pFindBar->IsVisible() && !m_pFindBar->BIsHidden();
}
//-----------------------------------------------------------------------------
// Purpose: return the bitmask of any modifier keys that are currently down
//-----------------------------------------------------------------------------
int GetKeyModifiers()
{
// Any time a key is pressed reset modifier list as well
int nModifierCodes = 0;
if( vgui2::input()->IsKeyDown( KEY_LCONTROL ) || vgui2::input()->IsKeyDown( KEY_RCONTROL ) )
nModifierCodes |= IInputEventHTML::CrtlDown;
if( vgui2::input()->IsKeyDown( KEY_LALT ) || vgui2::input()->IsKeyDown( KEY_RALT ) )
nModifierCodes |= IInputEventHTML::AltDown;
if( vgui2::input()->IsKeyDown( KEY_LSHIFT ) || vgui2::input()->IsKeyDown( KEY_RSHIFT ) )
nModifierCodes |= IInputEventHTML::ShiftDown;
#ifdef OSX
// for now pipe through the cmd-key to be like the control key so we get copy/paste
if( vgui2::input()->IsKeyDown( KEY_LWIN ) || vgui2::input()->IsKeyDown( KEY_RWIN ) )
nModifierCodes |= IInputEventHTML::CrtlDown;
#endif
return nModifierCodes;
}
//-----------------------------------------------------------------------------
// Purpose: passes key presses to the browser
//-----------------------------------------------------------------------------
void HTML::OnKeyCodeTyped(KeyCode code)
{
switch( code )
{
case KEY_PAGEDOWN:
{
int val = _vbar->GetValue();
val += 200;
_vbar->SetValue(val);
break;
}
case KEY_PAGEUP:
{
int val = _vbar->GetValue();
val -= 200;
_vbar->SetValue(val);
break;
}
case KEY_F5:
{
Refresh();
break;
}
case KEY_F:
{
if ( (input()->IsKeyDown(KEY_LCONTROL) || input()->IsKeyDown(KEY_RCONTROL) )
|| ( IsOSX() && ( input()->IsKeyDown(KEY_LWIN) || input()->IsKeyDown(KEY_RWIN) ) ) )
{
if ( !FindDialogVisible() )
{
ShowFindDialog();
}
else
{
HideFindDialog();
}
break;
}
}
case KEY_ESCAPE:
{
if ( FindDialogVisible() )
{
HideFindDialog();
break;
}
}
case KEY_TAB:
{
if ( input()->IsKeyDown(KEY_LCONTROL) || input()->IsKeyDown(KEY_RCONTROL) )
{
// pass control-tab to parent (through baseclass)
BaseClass::OnKeyTyped( code );
return;
}
break;
}
default: break;
}
m_Serializer->KeyDown( KeyCode_VGUIToVirtualKey( code ), GetKeyModifiers() );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void HTML::OnKeyCodeReleased(KeyCode code)
{
m_Serializer->KeyUp( KeyCode_VGUIToVirtualKey( code ), GetKeyModifiers() );
}
//-----------------------------------------------------------------------------
// Purpose: scrolls the vertical scroll bar on a web page
//-----------------------------------------------------------------------------
void HTML::OnMouseWheeled(int delta)
{
if (_vbar && ( ( m_pComboBoxHost && !m_pComboBoxHost->IsVisible() ) ) )
{
int val = _vbar->GetValue();
val -= (delta * 100.0/3.0 ); // 100 for every 3 lines matches chromes code
_vbar->SetValue(val);
}
m_Serializer->MouseWheel( delta );
}
//-----------------------------------------------------------------------------
// Purpose: Inserts a custom URL handler
//-----------------------------------------------------------------------------
void HTML::AddCustomURLHandler(const char *customProtocolName, vgui2::Panel *target)
{
int index = m_CustomURLHandlers.AddToTail();
m_CustomURLHandlers[index].hPanel = target;
Q_strncpy(m_CustomURLHandlers[index].url, customProtocolName, sizeof(m_CustomURLHandlers[index].url));
}
//-----------------------------------------------------------------------------
// Purpose: shared code for sizing the HTML surface window
//-----------------------------------------------------------------------------
void HTML::BrowserResize()
{
int w,h;
GetSize( w, h );
int right = 0, bottom = 0;
// TODO::STYLE
/*
IAppearance *pAppearance = GetAppearance();
int left = 0, top = 0;
if ( pAppearance )
{
pAppearance->GetInset( left, top, right, bottom );
}
*/
if ( m_iWideLastHTMLSize != ( w - m_iScrollBorderX - right ) || m_iTalLastHTMLSize != ( h - m_iScrollBorderY - bottom ) )
{
m_iWideLastHTMLSize = w - m_iScrollBorderX - right;
m_iTalLastHTMLSize = h - m_iScrollBorderY - bottom;
if ( m_iTalLastHTMLSize <= 0 )
{
SetTall( 64 );
m_iTalLastHTMLSize = 64 - bottom;
}
m_Serializer->BrowserSize( m_iWideLastHTMLSize, m_iTalLastHTMLSize );
// webkit forgets the scroll offset when you resize (it saves the scroll in a DC and a resize throws away the DC)
// so just tell it after the resize
int scrollV = _vbar->GetValue();
int scrollH = _hbar->GetValue();
m_Serializer->SetHorizontalScroll( scrollH );
m_Serializer->SetVerticalScroll( scrollV );
}
}
//-----------------------------------------------------------------------------
// Purpose: when a slider moves causes the IE images to re-render itself
//-----------------------------------------------------------------------------
void HTML::OnSliderMoved()
{
if(_hbar->IsVisible())
{
int scrollX =_hbar->GetValue();
m_Serializer->SetHorizontalScroll( scrollX );
}
if(_vbar->IsVisible())
{
int scrollY=_vbar->GetValue();
m_Serializer->SetVerticalScroll( scrollY );
}
// post a message that the slider has moved
PostActionSignal( new KeyValues( "HTMLSliderMoved" ) );
}
//-----------------------------------------------------------------------------
// Purpose: data accessor
//-----------------------------------------------------------------------------
bool HTML::IsScrolledToBottom()
{
if ( !_vbar->IsVisible() )
return true;
return m_scrollVertical.m_nScroll >= m_scrollVertical.m_nMax;
}
//-----------------------------------------------------------------------------
// Purpose: data accessor
//-----------------------------------------------------------------------------
bool HTML::IsScrollbarVisible()
{
return _vbar->IsVisible();
}
//-----------------------------------------------------------------------------
// Purpose: data accessor
//-----------------------------------------------------------------------------
void HTML::SetScrollbarsEnabled(bool state)
{
m_bScrollBarEnabled = state;
}
//-----------------------------------------------------------------------------
// Purpose: data accessor
//-----------------------------------------------------------------------------
void HTML::SetContextMenuEnabled(bool state)
{
m_bContextMenuEnabled = state;
}
//-----------------------------------------------------------------------------
// Purpose: data accessor
//-----------------------------------------------------------------------------
void HTML::SetViewSourceEnabled(bool state)
{
m_pContextMenu->SetItemVisible( m_nViewSourceAllowedIndex, state );
}
//-----------------------------------------------------------------------------
// Purpose: data accessor
//-----------------------------------------------------------------------------
void HTML::NewWindowsOnly( bool state )
{
m_bNewWindowsOnly = state;
}
//-----------------------------------------------------------------------------
// Purpose: called when our children have finished painting
//-----------------------------------------------------------------------------
void HTML::PostChildPaint()
{
BaseClass::PostChildPaint();
// TODO::STYLE
//m_pInteriorPanel->SetPaintAppearanceEnabled( true ); // turn painting back on so the IE hwnd can render this border
}
//-----------------------------------------------------------------------------
// Purpose: Adds a custom header to all requests
//-----------------------------------------------------------------------------
void HTML::AddHeader( const char *pchHeader, const char *pchValue )
{
m_Serializer->AddHeader( pchHeader, pchValue );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void HTML::OnSetFocus()
{
BaseClass::OnSetFocus();
m_Serializer->SetFocus( true );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void HTML::OnKillFocus()
{
if ( vgui2::input()->GetFocus() != m_pComboBoxHost->GetVPanel() ) // if its not the menu stealing our focus
BaseClass::OnKillFocus();
// Don't clear the actual html focus if a context menu is what took focus
if ( m_pContextMenu->HasFocus() )
return;
if ( m_pComboBoxHost->HasFocus() )
return;
m_Serializer->SetFocus( false );
}
//-----------------------------------------------------------------------------
// Purpose: webkit is telling us to use this cursor type
//-----------------------------------------------------------------------------
void HTML::OnCommand( const char *pchCommand )
{
if ( !Q_stricmp( pchCommand, "back" ) )
{
PostActionSignal( new KeyValues( "HTMLBackRequested" ) );
}
else if ( !Q_stricmp( pchCommand, "forward" ) )
{
PostActionSignal( new KeyValues( "HTMLForwardRequested" ) );
}
else if ( !Q_stricmp( pchCommand, "reload" ) )
{
Refresh();
}
else if ( !Q_stricmp( pchCommand, "stop" ) )
{
StopLoading();
}
else if ( !Q_stricmp( pchCommand, "viewsource" ) )
{
//CHTMLProtoBufMsg<CMsgViewSource> cmd( eHTMLCommands_ViewSource );
//DISPATCH_MESSAGE( eHTMLCommands_ViewSource );
}
else if ( !Q_stricmp( pchCommand, "copy" ) )
{
//CHTMLProtoBufMsg<CMsgCopy> cmd( eHTMLCommands_Copy );
//DISPATCH_MESSAGE( eHTMLCommands_Copy );
}
else if ( !Q_stricmp( pchCommand, "paste" ) )
{
//CHTMLProtoBufMsg<CMsgPaste> cmd( eHTMLCommands_Paste );
//DISPATCH_MESSAGE( eHTMLCommands_Paste );
}
else if ( !Q_stricmp( pchCommand, "copyurl" ) )
{
system()->SetClipboardText( m_sCurrentURL, m_sCurrentURL.Length() );
}
else if ( !Q_stricmp( pchCommand, "copylink" ) )
{
int x, y;
m_pContextMenu->GetPos( x, y );
int htmlx, htmly;
ipanel()->GetAbsPos( GetVPanel(), htmlx, htmly );
m_bRequestingCopyLink = true;
GetLinkAtPosition( x - htmlx, y - htmly );
}
else
BaseClass::OnCommand( pchCommand );
}
//-----------------------------------------------------------------------------
// Purpose: the control wants us to ask the user what file to load
//-----------------------------------------------------------------------------
void HTML::OnFileSelected( const char *pchSelectedFile )
{
//CHTMLProtoBufMsg<CMsgFileLoadDialogResponse> cmd( eHTMLCommands_FileLoadDialogResponse );
//cmd.Body().add_files( pchSelectedFile );
//DISPATCH_MESSAGE( eHTMLCommands_FileLoadDialogResponse );
m_hFileOpenDialog->Close();
}
//-----------------------------------------------------------------------------
// Purpose: called when the user dismissed the file dialog with no selection
//-----------------------------------------------------------------------------
void HTML::OnFileSelectionCancelled()
{
//CHTMLProtoBufMsg<CMsgFileLoadDialogResponse> cmd( eHTMLCommands_FileLoadDialogResponse );
//DISPATCH_MESSAGE( eHTMLCommands_FileLoadDialogResponse );
m_hFileOpenDialog->Close();
}
//-----------------------------------------------------------------------------
// Purpose: find any text on the html page with this sub string
//-----------------------------------------------------------------------------
void HTML::Find( const char *pchSubStr )
{
m_bInFind = false;
if ( m_sLastSearchString == pchSubStr ) // same string as last time, lets fine next
m_bInFind = true;
m_sLastSearchString = pchSubStr;
//CHTMLProtoBufMsg<CMsgFind> cmd( eHTMLCommands_Find );
//cmd.Body().set_find( pchSubStr );
//cmd.Body().set_infind( m_bInFind );
//DISPATCH_MESSAGE( eHTMLCommands_Find );
}
//-----------------------------------------------------------------------------
// Purpose: find any text on the html page with this sub string
//-----------------------------------------------------------------------------
void HTML::FindPrevious()
{
//CHTMLProtoBufMsg<CMsgFind> cmd( eHTMLCommands_Find );
//cmd.Body().set_find( m_sLastSearchString );
//cmd.Body().set_infind( m_bInFind );
//cmd.Body().set_reverse( true );
//DISPATCH_MESSAGE( eHTMLCommands_Find );
}
//-----------------------------------------------------------------------------
// Purpose: find any text on the html page with this sub string
//-----------------------------------------------------------------------------
void HTML::FindNext()
{
Find( m_sLastSearchString );
}
//-----------------------------------------------------------------------------
// Purpose: stop an outstanding find request
//-----------------------------------------------------------------------------
void HTML::StopFind( )
{
//CHTMLProtoBufMsg<CMsgStopFind> cmd( eHTMLCommands_StopFind );
//DISPATCH_MESSAGE( eHTMLCommands_StopFind );
m_bInFind = false;
}
//-----------------------------------------------------------------------------
// Purpose: input handler
//-----------------------------------------------------------------------------
void HTML::OnEditNewLine( Panel *pPanel )
{
OnTextChanged( pPanel );
}
//-----------------------h------------------------------------------------------
// Purpose: input handler
//-----------------------------------------------------------------------------
void HTML::OnTextChanged( Panel *pPanel )
{
char rgchText[2048];
m_pFindBar->GetText( rgchText, sizeof( rgchText ) );
Find( rgchText );
}
//-----------------------------------------------------------------------------
// Purpose: passes mouse clicks to the control
//-----------------------------------------------------------------------------
void HTMLComboBoxHost::OnMousePressed(MouseCode code)
{
m_pParent->OnMousePressed(code);
}
//-----------------------------------------------------------------------------
// Purpose: passes mouse up events
//-----------------------------------------------------------------------------
void HTMLComboBoxHost::OnMouseReleased(MouseCode code)
{
m_pParent->OnMouseReleased(code);
}
//-----------------------------------------------------------------------------
// Purpose: keeps track of where the cursor is
//-----------------------------------------------------------------------------
void HTMLComboBoxHost::OnCursorMoved(int x,int y)
{
// Only do this when we are over the current panel
if ( vgui2::input()->GetMouseOver() == GetVPanel() )
{
m_pParent->m_Serializer->MouseMove( x, y );
}
}
//-----------------------------------------------------------------------------
// Purpose: passes double click events to the browser
//-----------------------------------------------------------------------------
void HTMLComboBoxHost::OnMouseDoublePressed(MouseCode code)
{
m_pParent->OnMouseDoublePressed(code);
}
//-----------------------------------------------------------------------------
// Purpose: passes key presses to the browser (we don't current do this)
//-----------------------------------------------------------------------------
void HTMLComboBoxHost::OnKeyTyped(wchar_t unichar)
{
m_pParent->OnKeyTyped(unichar);
}
//-----------------------------------------------------------------------------
// Purpose: passes key presses to the browser
//-----------------------------------------------------------------------------
void HTMLComboBoxHost::OnKeyCodeTyped(KeyCode code)
{
m_pParent->OnKeyCodeTyped(code);
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void HTMLComboBoxHost::OnKeyCodeReleased(KeyCode code)
{
m_pParent->OnKeyCodeReleased(code);
}
//-----------------------------------------------------------------------------
// Purpose: scrolls the vertical scroll bar on a web page
//-----------------------------------------------------------------------------
void HTMLComboBoxHost::OnMouseWheeled(int delta)
{
m_pParent->OnMouseWheeled( delta );
}
//-----------------------------------------------------------------------------
// Purpose: helper class for the find bar
//-----------------------------------------------------------------------------
HTML::CHTMLFindBar::CHTMLFindBar( HTML *parent ) : EditablePanel( parent, "FindBar" )
{
m_pParent = parent;
m_bHidden = false;
m_pFindBar = new TextEntry( this, "FindEntry" );
m_pFindBar->AddActionSignalTarget( parent );
m_pFindBar->SendNewLine( true );
m_pFindCountLabel = new Label( this, "FindCount", "" );
m_pFindCountLabel->SetVisible( false );
LoadControlSettings( "resource/layout/htmlfindbar.layout" );
}
//-----------------------------------------------------------------------------
// Purpose: button input into the find bar
//-----------------------------------------------------------------------------
void HTML::CHTMLFindBar::OnCommand( const char *pchCmd )
{
if ( !Q_stricmp( pchCmd, "close" ) )
{
m_pParent->HideFindDialog();
}
else if ( !Q_stricmp( pchCmd, "previous" ) )
{
m_pParent->FindPrevious();
}
else if ( !Q_stricmp( pchCmd, "next" ) )
{
m_pParent->FindNext();
}
else
BaseClass::OnCommand( pchCmd );
}
//-----------------------------------------------------------------------------
// Purpose: browser has been constructed on the cef thread, lets use it
//-----------------------------------------------------------------------------
void HTML::BrowserReady()
{
/*
const char *pchTitle = g_pVGuiLocalize->FindAsUTF8( "#cef_error_title" );
const char *pchHeader = g_pVGuiLocalize->FindAsUTF8( "#cef_error_header" );
const char *pchDetailCacheMiss = g_pVGuiLocalize->FindAsUTF8( "#cef_cachemiss" );
const char *pchDetailBadUURL = g_pVGuiLocalize->FindAsUTF8( "#cef_badurl" );
const char *pchDetailConnectionProblem = g_pVGuiLocalize->FindAsUTF8( "#cef_connectionproblem" );
const char *pchDetailProxyProblem = g_pVGuiLocalize->FindAsUTF8( "#cef_proxyconnectionproblem" );
const char *pchDetailUnknown = g_pVGuiLocalize->FindAsUTF8( "#cef_unknown" );
// tell it utf8 loc strings to use
CHTMLProtoBufMsg<CMsgBrowserErrorStrings> cmd( eHTMLCommands_BrowserErrorStrings );
cmd.Body().set_title( pchTitle );
cmd.Body().set_header( pchHeader );
cmd.Body().set_cache_miss( pchDetailCacheMiss );
cmd.Body().set_bad_url( pchDetailBadUURL );
cmd.Body().set_connection_problem( pchDetailConnectionProblem );
cmd.Body().set_proxy_problem( pchDetailProxyProblem );
cmd.Body().set_unknown( pchDetailUnknown );
DISPATCH_MESSAGE( eHTMLCommands_BrowserErrorStrings );
*/
if ( !m_sPendingURLLoad.IsEmpty() )
{
PostURL( m_sPendingURLLoad, m_sPendingPostData/*, false*/ );
m_sPendingURLLoad.Clear();
}
}
//-----------------------------------------------------------------------------
// Purpose: we have a new texture to update
//-----------------------------------------------------------------------------
void HTML::BrowserNeedsPaint( int textureid,
int wide, int tall, const unsigned char* rgba,
int updatex, int updatey, int updatewide, int updatetall,
int combobox_wide, int combobox_tall, const unsigned char* combobox_rgba )
{
int tw = 0, tt = 0;
if ( m_iHTMLTextureID != 0 )
{
tw = m_allocedTextureWidth;
tt = m_allocedTextureHeight;
}
/*
if ( m_iHTMLTextureID != 0 &&
(
( _vbar->IsVisible() &&
pCmd->scrolly() > 0 &&
abs( (int)pCmd->scrolly() - m_scrollVertical.m_nScroll) > 5 ) ||
( _hbar->IsVisible() &&
pCmd->scrollx() > 0 &&
abs( (int)pCmd->scrollx() - m_scrollHorizontal.m_nScroll ) > 5 )
)
)
{
// this isn't an update from a scroll position we expect, ignore it and ask for a refresh of our update pos2
CHTMLProtoBufMsg<CMsgNeedsPaintResponse> cmd( eHTMLCommands_NeedsPaintResponse );
cmd.Body().set_textureid( pCmd->textureid() );
DISPATCH_MESSAGE( eHTMLCommands_NeedsPaintResponse );
m_bNeedsFullTextureUpload = true;
return;
}
*/
// update the vgui texture
if ( m_bNeedsFullTextureUpload || m_iHTMLTextureID == 0 || tw != (int)wide || tt != (int)tall )
{
m_bNeedsFullTextureUpload = false;
if ( m_iHTMLTextureID != 0 )
surface()->DeleteTextureByID( m_iHTMLTextureID );
// if the dimensions changed we also need to re-create the texture ID to support the overlay properly (it won't resize a texture on the fly, this is the only control that needs
// to so lets have a tiny bit more code here to support that)
m_iHTMLTextureID = surface()->CreateNewTextureID( true );
surface()->DrawSetTextureBGRA( m_iHTMLTextureID, (const unsigned char *)rgba, wide, tall );// BR FIXME - this call seems to shift by some number of pixels?
m_allocedTextureWidth = wide;
m_allocedTextureHeight = tall;
}
else if ( (int)updatewide > 0 && (int)updatetall > 0 )
{
// same size texture, just bits changing in it, lets twiddle
surface()->DrawUpdateRegionTextureBGRA( m_iHTMLTextureID, updatex, updatey, (const unsigned char *)rgba, updatewide, updatetall );
}
else
{
surface()->DrawSetTextureBGRA( m_iHTMLTextureID, (const unsigned char *)rgba, wide, tall );
}
if ( m_pComboBoxHost->IsVisible() )
{
// update the combo box texture also
if ( m_iComboBoxTextureID != 0 )
{
tw = m_allocedComboBoxWidth;
tt = m_allocedComboBoxHeight;
}
if ( m_iComboBoxTextureID == 0 || tw != (int)combobox_wide || tt != (int)combobox_tall )
{
if ( m_iComboBoxTextureID != 0 )
surface()->DeleteTextureByID( m_iComboBoxTextureID );
// if the dimensions changed we also need to re-create the texture ID to support the overlay properly (it won't resize a texture on the fly, this is the only control that needs
// to so lets have a tiny bit more code here to support that)
m_iComboBoxTextureID = surface()->CreateNewTextureID( true );
surface()->DrawSetTextureBGRA( m_iComboBoxTextureID, (const unsigned char *)combobox_rgba, combobox_wide, combobox_tall );
m_allocedComboBoxWidth = (int)combobox_wide;
m_allocedComboBoxHeight = (int)combobox_tall;
}
else
{
// same size texture, just bits changing in it, lets twiddle
surface()->DrawUpdateRegionTextureBGRA( m_iComboBoxTextureID, 0, 0, (const unsigned char *)combobox_rgba, combobox_wide, combobox_tall );
}
}
// need a paint next time
Repaint();
m_Serializer->NeedsPaintResponse( textureid );
}
//-----------------------------------------------------------------------------
// Purpose: browser wants to start loading this url, do we let it?
//-----------------------------------------------------------------------------
bool HTML::OnStartRequest( const char *url, const char *target, const char *pchPostData, bool bIsRedirect )
{
if ( !url || !Q_stricmp( url, "about:blank") )
return true ; // this is just webkit loading a new frames contents inside an existing page
HideFindDialog();
// see if we have a custom handler for this
bool bURLHandled = false;
for (int i = 0; i < m_CustomURLHandlers.Count(); i++)
{
if (!Q_strnicmp(m_CustomURLHandlers[i].url,url, Q_strlen(m_CustomURLHandlers[i].url)))
{
// we have a custom handler
Panel *targetPanel = m_CustomURLHandlers[i].hPanel;
if (targetPanel)
{
PostMessage(targetPanel, new KeyValues("CustomURL", "url", m_CustomURLHandlers[i].url ) );
}
bURLHandled = true;
}
}
if (bURLHandled)
return false;
if ( m_bNewWindowsOnly && bIsRedirect )
{
if ( target && ( !Q_stricmp( target, "_blank" ) || !Q_stricmp( target, "_new" ) ) ) // only allow NEW windows (_blank ones)
{
return true;
}
else
{
return false;
}
}
if ( target && !Q_strlen( target ) )
{
m_sCurrentURL = url;
KeyValues *pMessage = new KeyValues( "OnURLChanged" );
pMessage->SetString( "url", url );
pMessage->SetString( "postdata", pchPostData );
pMessage->SetInt( "isredirect", bIsRedirect ? 1 : 0 );
PostActionSignal( pMessage );
}
return true;
}
//-----------------------------------------------------------------------------
// Purpose: callback from cef thread, load a url please
//-----------------------------------------------------------------------------
void HTML::BrowserStartRequest( const char *url, const char *target, const char *postdata, bool isredirect )
{
bool bRes = OnStartRequest( url, target, postdata, isredirect );
m_Serializer->StartRequestResponse( bRes );
UpdateCachedHTMLValues();
}
//-----------------------------------------------------------------------------
// Purpose: browser went to a new url
//-----------------------------------------------------------------------------
void HTML::BrowserURLChanged( const char *url, const char *postdata, bool isredirect )
{
m_sCurrentURL = url;
KeyValues *pMessage = new KeyValues( "OnURLChanged" );
pMessage->SetString( "url", url );
pMessage->SetString( "postdata", postdata );
pMessage->SetInt( "isredirect", isredirect ? 1 : 0 );
PostActionSignal( pMessage );
OnURLChanged( m_sCurrentURL, postdata, isredirect );
}
//-----------------------------------------------------------------------------
// Purpose: finished loading this page
//-----------------------------------------------------------------------------
void HTML::BrowserFinishedRequest( const char *url, const char *pagetitle )
{
PostActionSignal( new KeyValues( "OnFinishRequest", "url", url ) );
if ( *pagetitle )
PostActionSignal( new KeyValues( "PageTitleChange", "title", pagetitle ) );
/*
KeyValues *pKVSecure = new KeyValues( "SecurityStatus" );
pKVSecure->SetString( "url", url );
pKVSecure->SetInt( "secure", pCmd->security_info().bissecure() );
pKVSecure->SetInt( "certerror", pCmd->security_info().bhascerterror() );
pKVSecure->SetInt( "isevcert", pCmd->security_info().bisevcert() );
pKVSecure->SetString( "certname", pCmd->security_info().certname().c_str() );
PostActionSignal( pKVSecure );
*/
/*
CUtlMap < CUtlString, CUtlString > mapHeaders;
SetDefLessFunc( mapHeaders );
for ( int i = 0; i < pCmd->headers_size(); i++ )
{
const CHTMLHeader &header = pCmd->headers(i);
mapHeaders.Insert( header.key().c_str(), header.value().c_str() );
}
*/
OnFinishRequest( url, pagetitle/*, mapHeaders*/ );
//UpdateCachedHTMLValues();
}
//-----------------------------------------------------------------------------
// Purpose: show a popup dialog
//-----------------------------------------------------------------------------
void HTML::BrowserShowPopup()
{
m_pComboBoxHost->SetVisible( true );
}
//-----------------------------------------------------------------------------
// Purpose: hide the popup
//-----------------------------------------------------------------------------
void HTML::HidePopup()
{
m_pComboBoxHost->SetVisible( false );
}
//-----------------------------------------------------------------------------
// Purpose: browser wants us to hide a popup
//-----------------------------------------------------------------------------
void HTML::BrowserHidePopup()
{
HidePopup();
}
//-----------------------------------------------------------------------------
// Purpose: browser wants us to position a popup
//-----------------------------------------------------------------------------
void HTML::BrowserSizePopup( int x, int y, int wide, int tall )
{
int nAbsX, nAbsY;
ipanel()->GetAbsPos( GetVPanel(), nAbsX, nAbsY );
m_pComboBoxHost->SetBounds( x + 1 + nAbsX, y + nAbsY, wide, tall );
}
//-----------------------------------------------------------------------------
// Purpose: browser telling us the size of the horizontal scrollbars
//-----------------------------------------------------------------------------
void HTML::BrowserHorizontalScrollBarSizeResponse( int x, int y, int wide, int tall, int scroll, int scroll_max, float zoom )
{
ScrollData_t scrollHorizontal;
scrollHorizontal.m_nX = x;
scrollHorizontal.m_nY = y;
scrollHorizontal.m_nWide = wide;
scrollHorizontal.m_nTall = tall;
scrollHorizontal.m_nScroll = scroll;
scrollHorizontal.m_nMax = scroll_max;
scrollHorizontal.m_bVisible = ( m_scrollHorizontal.m_nTall > 0 );
scrollHorizontal.m_flZoom = zoom;
if( scrollHorizontal != m_scrollHorizontal )
{
m_scrollHorizontal = scrollHorizontal;
UpdateSizeAndScrollBars();
m_bNeedsFullTextureUpload = true;
}
else
m_scrollHorizontal = scrollHorizontal;
}
//-----------------------------------------------------------------------------
// Purpose: browser telling us the size of the vertical scrollbars
//-----------------------------------------------------------------------------
void HTML::BrowserVerticalScrollBarSizeResponse( int x, int y, int wide, int tall, int scroll, int scroll_max, float zoom )
{
ScrollData_t scrollVertical;
scrollVertical.m_nX = x;
scrollVertical.m_nY = y;
scrollVertical.m_nWide = wide;
scrollVertical.m_nTall = tall;
scrollVertical.m_nScroll = scroll;
scrollVertical.m_nMax = scroll_max;
scrollVertical.m_bVisible = ( m_scrollVertical.m_nTall > 0 );
scrollVertical.m_flZoom = zoom;
if( scrollVertical != m_scrollVertical )
{
m_scrollVertical = scrollVertical;
UpdateSizeAndScrollBars();
m_bNeedsFullTextureUpload = true;
}
else
m_scrollVertical = scrollVertical;
}
//-----------------------------------------------------------------------------
// Purpose: browser telling us the current page zoom
//-----------------------------------------------------------------------------
void HTML::BrowserGetZoomResponse( float flZoom )
{
m_flZoom = flZoom;
if( m_flZoom == 0.0f )
m_flZoom = 100.0f;
m_flZoom /= 100; // scale zoom to 1.0 being 100%, webkit gives us 100 for normal scale
}
//-----------------------------------------------------------------------------
// Purpose: browser telling us the state of back and forward buttons
//-----------------------------------------------------------------------------
void HTML::BrowserCanGoBackandForward( bool bgoback, bool bgoforward )
{
m_bCanGoBack = bgoback;
m_bCanGoForward = bgoforward;
}
//-----------------------------------------------------------------------------
// Purpose: browser telling us to pop a javascript alert dialog
//-----------------------------------------------------------------------------
void HTML::BrowserJSAlert( const char *message )
{
MessageBox *pDlg = new MessageBox( m_sCurrentURL, message, this );
pDlg->AddActionSignalTarget( this );
pDlg->SetCommand( new KeyValues( "DismissJSDialog", "result", false ) );
pDlg->DoModal();
}
//-----------------------------------------------------------------------------
// Purpose: browser telling us to pop a js confirm dialog
//-----------------------------------------------------------------------------
void HTML::BrowserJSConfirm( const char *message )
{
QueryBox *pDlg = new QueryBox( m_sCurrentURL, message, this );
pDlg->AddActionSignalTarget( this );
pDlg->SetOKCommand( new KeyValues( "DismissJSDialog", "result", true ) );
pDlg->SetCancelCommand( new KeyValues( "DismissJSDialog", "result", false ) );
pDlg->DoModal();
}
//-----------------------------------------------------------------------------
// Purpose: display a new html window
//-----------------------------------------------------------------------------
void HTML::BrowserPopupHTMLWindow( const char *url, int wide, int tall, int x, int y )
{
HTMLPopup *p = new HTMLPopup( this, url, "" );
//int wide = pCmd->wide();
//int tall = pCmd->tall();
if( wide == 0 || tall == 0 )
{
wide = max( 640, GetWide() );
tall = max( 480, GetTall() );
}
p->SetBounds( x, y, wide, tall );
p->SetDeleteSelfOnClose( true );
if( x == 0 || y == 0 )
p->MoveToCenterOfScreen();
p->Activate();
}
//-----------------------------------------------------------------------------
// Purpose: browser telling us the page title
//-----------------------------------------------------------------------------
void HTML::BrowserSetHTMLTitle( const char *title )
{
PostMessage( GetParent(), new KeyValues( "OnSetHTMLTitle", "title", title ) );
OnSetHTMLTitle( title );
}
//-----------------------------------------------------------------------------
// Purpose: still loading stuff for this page
//-----------------------------------------------------------------------------
void HTML::BrowserLoadingResource()
{
UpdateCachedHTMLValues();
}
//-----------------------------------------------------------------------------
// Purpose: status bar details
//-----------------------------------------------------------------------------
void HTML::BrowserStatusText( const char *text )
{
PostActionSignal( new KeyValues( "OnSetStatusText", "status", text ) );
}
//-----------------------------------------------------------------------------
// Purpose: browser telling us to use this cursor
//-----------------------------------------------------------------------------
void HTML::BrowserSetCursor( int in_cursor )
{
// Mouse cursor value in CMsgSetCursor is set to one of EMouseCursor,
// by CChromePainter::OnSetCursor in html_chrome.cpp
// Code below relies on start of EMouseCursor being exactly same as vgui2::CursorCode
uint32 msgCursor = in_cursor;
vgui2::CursorCode cursor;
if ( msgCursor >= (uint32)(dc_last) )
{
cursor = dc_arrow;
}
else
{
cursor = (CursorCode)msgCursor;
}
SetCursor( cursor );
}
//-----------------------------------------------------------------------------
// Purpose: browser telling to show the file loading dialog
//-----------------------------------------------------------------------------
void HTML::BrowserFileLoadDialog()
{
/*
// try and use the OS-specific file dialog first
char rgchFileName[MAX_UNICODE_PATH_IN_UTF8];
if ( surface()->OpenOSFileOpenDialog( pCmd->title().c_str(), pCmd->initialfile().c_str(), NULL, rgchFileName, sizeof(rgchFileName) ) )
{
CHTMLProtoBufMsg<CMsgFileLoadDialogResponse> cmd( eHTMLCommands_FileLoadDialogResponse );
cmd.Body().add_files( rgchFileName );
DISPATCH_MESSAGE( eHTMLCommands_FileLoadDialogResponse );
}
else*/
/*
{
// couldn't access an OS-specific dialog, use the internal one
if ( m_hFileOpenDialog.Get() )
{
delete m_hFileOpenDialog.Get();
m_hFileOpenDialog = NULL;
}
m_hFileOpenDialog = new FileOpenDialog( this, pCmd->title().c_str(), true );
m_hFileOpenDialog->SetStartDirectory( pCmd->initialfile().c_str() );
m_hFileOpenDialog->AddActionSignalTarget( this );
m_hFileOpenDialog->SetAutoDelete( true );
m_hFileOpenDialog->DoModal(false);
}
*/
}
//-----------------------------------------------------------------------------
// Purpose: browser asking to show a tooltip
//-----------------------------------------------------------------------------
void HTML::BrowserShowToolTip( const char *text )
{
/*
BR FIXME
Tooltip *tip = GetTooltip();
tip->SetText( text );
tip->SetTooltipFormatToMultiLine();
tip->SetTooltipDelayMS( 250 );
tip->SetMaxToolTipWidth( MAX( 200, GetWide()/2 ) );
tip->ShowTooltip( this );
*/
}
//-----------------------------------------------------------------------------
// Purpose: browser telling us to update tool tip text
//-----------------------------------------------------------------------------
void HTML::BrowserUpdateToolTip( const char *text )
{
// GetTooltip()->SetText( text );
}
//-----------------------------------------------------------------------------
// Purpose: browser telling that it is done with the tip
//-----------------------------------------------------------------------------
void HTML::BrowserHideToolTip()
{
// GetTooltip()->HideTooltip();
// DeleteToolTip();
}
//-----------------------------------------------------------------------------
// Purpose: browser telling us it had a close requested
//-----------------------------------------------------------------------------
void HTML::BrowserClose()
{
PostActionSignal( new KeyValues( "OnCloseWindow" ) );
}
//-----------------------------------------------------------------------------
// Purpose: browser telling us what is at this location on the page
//-----------------------------------------------------------------------------
void HTML::BrowserLinkAtPositionResponse( const char *url, int x, int y )
{
m_LinkAtPos.m_sURL = url;
m_LinkAtPos.m_nX = x;
m_LinkAtPos.m_nY = y;
m_pContextMenu->SetItemVisible( m_iCopyLinkMenuItemID, !m_LinkAtPos.m_sURL.IsEmpty() ? true : false );
if ( m_bRequestingDragURL )
{
m_bRequestingDragURL = false;
m_sDragURL = m_LinkAtPos.m_sURL;
// make sure we get notified when the mouse gets released
if ( !m_sDragURL.IsEmpty() )
{
input()->SetMouseCapture( GetVPanel() );
}
}
if ( m_bRequestingCopyLink )
{
m_bRequestingCopyLink = false;
if ( !m_LinkAtPos.m_sURL.IsEmpty() )
system()->SetClipboardText( m_LinkAtPos.m_sURL, m_LinkAtPos.m_sURL.Length() );
else
system()->SetClipboardText( "", 1 );
}
OnLinkAtPosition( m_LinkAtPos.m_sURL );
}
//-----------------------------------------------------------------------------
// Purpose: got an answer from the dialog, tell cef
//-----------------------------------------------------------------------------
void HTML::DismissJSDialog( int bResult )
{
m_Serializer->JSDialogResponse( bResult == 1 );
}
//-----------------------------------------------------------------------------
// Purpose: update the value of the cached variables we keep
//-----------------------------------------------------------------------------
void HTML::UpdateCachedHTMLValues()
{
// request scroll bar sizes
m_Serializer->RequestBrowserSizes();
}
//-----------------------------------------------------------------------------
// Purpose: ask the browser for what is at this x,y
//-----------------------------------------------------------------------------
void HTML::GetLinkAtPosition( int x, int y )
{
m_Serializer->GetLinkAtPosition( x, y );
}
//-----------------------------------------------------------------------------
// Purpose: update the size of the browser itself and scrollbars it shows
//-----------------------------------------------------------------------------
void HTML::UpdateSizeAndScrollBars()
{
// Tell IE
BrowserResize();
// Do this after we tell IE!
int w,h;
GetSize( w, h );
CalcScrollBars(w,h);
InvalidateLayout();
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/yoyojacky/CSMoE.git
git@gitee.com:yoyojacky/CSMoE.git
yoyojacky
CSMoE
CSMoE
master

搜索帮助