void OnHTML_FileOpenDialog(HTML_FileOpenDialog_t pCallback) { Debug.Log("[" + HTML_FileOpenDialog_t.k_iCallback + " - HTML_FileOpenDialog] - " + pCallback.unBrowserHandle + " -- " + pCallback.pchTitle + " -- " + pCallback.pchInitialFile); // TODO: Valve has no example usage of this. SteamHTMLSurface.FileLoadDialogResponse(pCallback.unBrowserHandle, System.IntPtr.Zero); }
void OnHTML_StartRequest(HTML_StartRequest_t pCallback) { Debug.Log("[" + HTML_StartRequest_t.k_iCallback + " - HTML_StartRequest] - " + pCallback.unBrowserHandle + " -- " + pCallback.pchURL + " -- " + pCallback.pchTarget + " -- " + pCallback.pchPostData + " -- " + pCallback.bIsRedirect); SteamHTMLSurface.AllowStartRequest(pCallback.unBrowserHandle, true); print("SteamHTMLSurface.AllowStartRequest(pCallback.unBrowserHandle, true)"); }
void OnHTML_JSConfirm(HTML_JSConfirm_t pCallback) { Debug.Log("[" + HTML_JSConfirm_t.k_iCallback + " - HTML_JSConfirm] - " + pCallback.unBrowserHandle + " -- " + pCallback.pchMessage); SteamHTMLSurface.JSDialogResponse(pCallback.unBrowserHandle, true); print("SteamHTMLSurface.JSDialogResponse(pCallback.unBrowserHandle, true)"); }
public void OnEnable() { m_HTML_NeedsPaint = Callback <HTML_NeedsPaint_t> .Create(OnHTML_NeedsPaint); m_HTML_StartRequest = Callback <HTML_StartRequest_t> .Create(OnHTML_StartRequest); m_HTML_CloseBrowser = Callback <HTML_CloseBrowser_t> .Create(OnHTML_CloseBrowser); m_HTML_URLChanged = Callback <HTML_URLChanged_t> .Create(OnHTML_URLChanged); m_HTML_FinishedRequest = Callback <HTML_FinishedRequest_t> .Create(OnHTML_FinishedRequest); m_HTML_OpenLinkInNewTab = Callback <HTML_OpenLinkInNewTab_t> .Create(OnHTML_OpenLinkInNewTab); m_HTML_ChangedTitle = Callback <HTML_ChangedTitle_t> .Create(OnHTML_ChangedTitle); m_HTML_SearchResults = Callback <HTML_SearchResults_t> .Create(OnHTML_SearchResults); m_HTML_CanGoBackAndForward = Callback <HTML_CanGoBackAndForward_t> .Create(OnHTML_CanGoBackAndForward); m_HTML_HorizontalScroll = Callback <HTML_HorizontalScroll_t> .Create(OnHTML_HorizontalScroll); m_HTML_VerticalScroll = Callback <HTML_VerticalScroll_t> .Create(OnHTML_VerticalScroll); m_HTML_LinkAtPosition = Callback <HTML_LinkAtPosition_t> .Create(OnHTML_LinkAtPosition); m_HTML_JSAlert = Callback <HTML_JSAlert_t> .Create(OnHTML_JSAlert); m_HTML_JSConfirm = Callback <HTML_JSConfirm_t> .Create(OnHTML_JSConfirm); m_HTML_FileOpenDialog = Callback <HTML_FileOpenDialog_t> .Create(OnHTML_FileOpenDialog); m_HTML_ComboNeedsPaint = Callback <HTML_ComboNeedsPaint_t> .Create(OnHTML_ComboNeedsPaint); m_HTML_ShowPopup = Callback <HTML_ShowPopup_t> .Create(OnHTML_ShowPopup); m_HTML_HidePopup = Callback <HTML_HidePopup_t> .Create(OnHTML_HidePopup); m_HTML_SizePopup = Callback <HTML_SizePopup_t> .Create(OnHTML_SizePopup); m_HTML_NewWindow = Callback <HTML_NewWindow_t> .Create(OnHTML_NewWindow); m_HTML_SetCursor = Callback <HTML_SetCursor_t> .Create(OnHTML_SetCursor); m_HTML_StatusText = Callback <HTML_StatusText_t> .Create(OnHTML_StatusText); m_HTML_ShowToolTip = Callback <HTML_ShowToolTip_t> .Create(OnHTML_ShowToolTip); m_HTML_UpdateToolTip = Callback <HTML_UpdateToolTip_t> .Create(OnHTML_UpdateToolTip); m_HTML_HideToolTip = Callback <HTML_HideToolTip_t> .Create(OnHTML_HideToolTip); m_HTML_BrowserReadyResult = CallResult <HTML_BrowserReady_t> .Create(OnHTML_BrowserReady); m_Init = SteamHTMLSurface.Init(); print("SteamHTMLSurface.Init() : " + m_Init); m_Texture = null; }
public void OnEnable() { m_HHTMLBrowser = HHTMLBrowser.Invalid; m_URL = "http://steamworks.github.io"; m_Texture = null; m_Find = "Steamworks"; m_CurrentlyInFind = false; m_ScaleFactor = 0f; m_BackgroundMode = false; m_Init = SteamHTMLSurface.Init(); print("SteamHTMLSurface.Init() : " + m_Init); m_HTML_NeedsPaint = Callback <HTML_NeedsPaint_t> .Create(OnHTML_NeedsPaint); m_HTML_StartRequest = Callback <HTML_StartRequest_t> .Create(OnHTML_StartRequest); m_HTML_CloseBrowser = Callback <HTML_CloseBrowser_t> .Create(OnHTML_CloseBrowser); m_HTML_URLChanged = Callback <HTML_URLChanged_t> .Create(OnHTML_URLChanged); m_HTML_FinishedRequest = Callback <HTML_FinishedRequest_t> .Create(OnHTML_FinishedRequest); m_HTML_OpenLinkInNewTab = Callback <HTML_OpenLinkInNewTab_t> .Create(OnHTML_OpenLinkInNewTab); m_HTML_ChangedTitle = Callback <HTML_ChangedTitle_t> .Create(OnHTML_ChangedTitle); m_HTML_SearchResults = Callback <HTML_SearchResults_t> .Create(OnHTML_SearchResults); m_HTML_CanGoBackAndForward = Callback <HTML_CanGoBackAndForward_t> .Create(OnHTML_CanGoBackAndForward); m_HTML_HorizontalScroll = Callback <HTML_HorizontalScroll_t> .Create(OnHTML_HorizontalScroll); m_HTML_VerticalScroll = Callback <HTML_VerticalScroll_t> .Create(OnHTML_VerticalScroll); m_HTML_LinkAtPosition = Callback <HTML_LinkAtPosition_t> .Create(OnHTML_LinkAtPosition); m_HTML_JSAlert = Callback <HTML_JSAlert_t> .Create(OnHTML_JSAlert); m_HTML_JSConfirm = Callback <HTML_JSConfirm_t> .Create(OnHTML_JSConfirm); m_HTML_FileOpenDialog = Callback <HTML_FileOpenDialog_t> .Create(OnHTML_FileOpenDialog); m_HTML_NewWindow = Callback <HTML_NewWindow_t> .Create(OnHTML_NewWindow); m_HTML_SetCursor = Callback <HTML_SetCursor_t> .Create(OnHTML_SetCursor); m_HTML_StatusText = Callback <HTML_StatusText_t> .Create(OnHTML_StatusText); m_HTML_ShowToolTip = Callback <HTML_ShowToolTip_t> .Create(OnHTML_ShowToolTip); m_HTML_UpdateToolTip = Callback <HTML_UpdateToolTip_t> .Create(OnHTML_UpdateToolTip); m_HTML_HideToolTip = Callback <HTML_HideToolTip_t> .Create(OnHTML_HideToolTip); m_HTML_BrowserRestarted = Callback <HTML_BrowserRestarted_t> .Create(OnHTML_BrowserRestarted); OnHTML_BrowserReadyCallResult = CallResult <HTML_BrowserReady_t> .Create(OnHTML_BrowserReady); }
void RemoveBrowser() { if (m_HHTMLBrowser != HHTMLBrowser.Invalid) { print("SteamHTMLSurface.RemoveBrowser(" + m_HHTMLBrowser + ")"); SteamHTMLSurface.RemoveBrowser(m_HHTMLBrowser); m_HHTMLBrowser = HHTMLBrowser.Invalid; } m_Texture = null; }
public static void ExecuteJS(string code) { if (Browser == null) { return; } //Console.WriteLine($"Executing js {code}"); SteamHTMLSurface.ExecuteJavascript(Browser, code); }
public static void Update() { if (Browser == null) { return; } if (Input.LeftMousePressed) { SteamHTMLSurface.MouseDown(Browser, EHTMLMouseButton.eHTMLMouseButton_Left); } if (Input.LeftMouseReleased) { SteamHTMLSurface.MouseUp(Browser, EHTMLMouseButton.eHTMLMouseButton_Left); } SteamHTMLSurface.MouseMove(Browser, (int)Input.CurMousePos.x, (int)Input.CurMousePos.y); lastPressedKeys = currentPressedKeys; currentPressedKeys = Keyboard.GetState().GetPressedKeys(); // Key Down foreach (var key in currentPressedKeys) { if (!lastPressedKeys.Contains(key)) { uint code = (uint)key; var mod = Keys.LeftShift.Down() || Keys.RightShift.Down() ? EHTMLKeyModifiers.k_eHTMLKeyModifier_ShiftDown : EHTMLKeyModifiers.k_eHTMLKeyModifier_None; SteamHTMLSurface.KeyDown(Browser, code, mod); if (KeyToChar(key) != (char)0) { SteamHTMLSurface.KeyChar(Browser, (uint)KeyToChar(key), EHTMLKeyModifiers.k_eHTMLKeyModifier_None); } } } // Key Up foreach (var key in lastPressedKeys) { if (!currentPressedKeys.Contains(key)) { uint code = (uint)key; SteamHTMLSurface.KeyUp(Browser, code, EHTMLKeyModifiers.k_eHTMLKeyModifier_None); } } }
public static void OnBrowserReady(HTML_BrowserReady_t pBrowserReady, bool bIOFailure) { if (bIOFailure) { return; } Browser = pBrowserReady.unBrowserHandle; SteamHTMLSurface.SetSize(Browser, Width, Height); var data = "file://" + Environment.CurrentDirectory + @"/html/index.html"; SteamHTMLSurface.LoadURL(Browser, data, null); }
public static void Initialize(uint _Width, uint _Height) { Width = _Width; Height = _Height; bool result = SteamHTMLSurface.Init(); SteamHTMLSurface.SetSize(HHTMLBrowser.Invalid, Width, Height); Texture = new Texture2D(Game.GameClass.Graphics, (int)Width, (int)Height); pixels = new byte[Width * Height * 4]; var hSteamAPICall = SteamHTMLSurface.CreateBrowser("WAL", null); g_CallResultBrowserReady = new CallResult <HTML_BrowserReady_t>(OnBrowserReady); g_CallResultBrowserReady.Set(hSteamAPICall); Event_CloseBrowser = new Callback <HTML_CloseBrowser_t>(OnCloseBrowser); Event_StartRequest = new Callback <HTML_StartRequest_t>(OnStartRequest); Event_FinishedRequest = new Callback <HTML_FinishedRequest_t>(OnFinishedRequest); Event_NeedsPaint = new Callback <HTML_NeedsPaint_t>(OnNeedsPaint); Event_URLChanged = new Callback <HTML_URLChanged_t>(OnURLChange); }
public void RenderOnGUI() { GUILayout.BeginArea(new Rect(Screen.width - 200, 0, 200, Screen.height)); GUILayout.Label("Variables:"); GUILayout.Label("m_Init: " + m_Init); GUILayout.Label("m_HHTMLBrowser: " + m_HHTMLBrowser); GUILayout.EndArea(); if (m_Texture) { GUI.DrawTexture(m_Rect, m_Texture); } if (!m_Init) { GUILayout.Label("SteamHTMLSurface.Init() returned false"); return; } if (GUILayout.Button("CreateBrowser(\"SpaceWars Test\", null)")) { RemoveBrowser(); // Remove an old browser if it exists. SteamAPICall_t handle = SteamHTMLSurface.CreateBrowser("SpaceWars Test", null); m_HTML_BrowserReadyResult.Set(handle); print("SteamHTMLSurface.CreateBrowser(\"SpaceWars Test\", null) - " + handle); } if (GUILayout.Button("RemoveBrowser(m_HHTMLBrowser)")) { RemoveBrowser(); } m_URL = GUILayout.TextField(m_URL); if (GUILayout.Button("LoadURL(m_HHTMLBrowser, m_URL, null)")) { SteamHTMLSurface.LoadURL(m_HHTMLBrowser, m_URL, null); print("SteamHTMLSurface.LoadURL(m_HHTMLBrowser," + m_URL + ", null)"); } if (GUILayout.Button("SetSize(m_HHTMLBrowser, m_Width, m_Height)")) { m_Width = (uint)Screen.width - WidthOffset; m_Height = (uint)Screen.height - HeightOffset; m_Rect = new Rect(WidthOffset, m_Height + HeightOffset, m_Width, -m_Height); // This flips the viewport since Unity renders textures upside down. m_Texture = null; SteamHTMLSurface.SetSize(m_HHTMLBrowser, m_Width, m_Height); print("SteamHTMLSurface.SetSize(m_HHTMLBrowser, " + m_Width + ", " + m_Height + ")"); } if (GUILayout.Button("StopLoad(m_HHTMLBrowser)")) { SteamHTMLSurface.StopLoad(m_HHTMLBrowser); print("SteamHTMLSurface.StopLoad(m_HHTMLBrowser)"); } if (GUILayout.Button("Reload(m_HHTMLBrowser)")) { SteamHTMLSurface.Reload(m_HHTMLBrowser); print("SteamHTMLSurface.Reload(m_HHTMLBrowser)"); } GUI.enabled = m_CanGoBack; if (GUILayout.Button("GoBack(m_HHTMLBrowser)")) { SteamHTMLSurface.GoBack(m_HHTMLBrowser); print("SteamHTMLSurface.GoBack(m_HHTMLBrowser)"); } GUI.enabled = m_CanGoForward; if (GUILayout.Button("GoForward(m_HHTMLBrowser)")) { SteamHTMLSurface.GoForward(m_HHTMLBrowser); print("SteamHTMLSurface.GoForward(m_HHTMLBrowser)"); } GUI.enabled = true; if (GUILayout.Button("AddHeader(m_HHTMLBrowser, \"From\", \"[email protected]\")")) { SteamHTMLSurface.AddHeader(m_HHTMLBrowser, "From", "*****@*****.**"); print("SteamHTMLSurface.AddHeader(m_HHTMLBrowser, \"From\", \"[email protected]\")"); } if (GUILayout.Button("ExecuteJavascript(m_HHTMLBrowser, \"window.alert('Test');\")")) { SteamHTMLSurface.ExecuteJavascript(m_HHTMLBrowser, "window.alert('Test');"); print("SteamHTMLSurface.ExecuteJavascript(m_HHTMLBrowser, \"window.alert('Test');\")"); } if (GUILayout.Button("SetKeyFocus(m_HHTMLBrowser, " + !m_SetKeyFocus + ")")) { SteamHTMLSurface.SetKeyFocus(m_HHTMLBrowser, !m_SetKeyFocus); m_SetKeyFocus = !m_SetKeyFocus; print("SteamHTMLSurface.SetKeyFocus(m_HHTMLBrowser, " + !m_SetKeyFocus + ")"); } if (GUILayout.Button("ViewSource(m_HHTMLBrowser)")) { SteamHTMLSurface.ViewSource(m_HHTMLBrowser); print("SteamHTMLSurface.ViewSource(m_HHTMLBrowser)"); } if (GUILayout.Button("CopyToClipboard(m_HHTMLBrowser)")) { SteamHTMLSurface.CopyToClipboard(m_HHTMLBrowser); print("SteamHTMLSurface.CopyToClipboard(m_HHTMLBrowser)"); } if (GUILayout.Button("PasteFromClipboard(m_HHTMLBrowser)")) { SteamHTMLSurface.PasteFromClipboard(m_HHTMLBrowser); print("SteamHTMLSurface.PasteFromClipboard(m_HHTMLBrowser)"); } m_Find = GUILayout.TextField(m_Find); if (GUILayout.Button("Find(m_HHTMLBrowser, m_Find, m_CurrentlyInFind, false)")) { SteamHTMLSurface.Find(m_HHTMLBrowser, m_Find, m_CurrentlyInFind, bReverse: false); print("SteamHTMLSurface.Find(m_HHTMLBrowser," + m_Find + ", " + m_CurrentlyInFind + ", false)"); m_CurrentlyInFind = true; } if (GUILayout.Button("StopFind(m_HHTMLBrowser)")) { SteamHTMLSurface.StopFind(m_HHTMLBrowser); print("SteamHTMLSurface.StopFind(m_HHTMLBrowser)"); m_CurrentlyInFind = false; } if (GUILayout.Button("GetLinkAtPosition(m_HHTMLBrowser, 500, 120)")) { SteamHTMLSurface.GetLinkAtPosition(m_HHTMLBrowser, 500 - WidthOffset, 120 - HeightOffset); print("SteamHTMLSurface.GetLinkAtPosition(m_HHTMLBrowser, 500, 120)"); } // Use with http://html-kit.com/tools/cookietester/ if (GUILayout.Button("SetCookie(\"html-kit.com\", \"testcookiekey\", \"testcookievalue\")")) { SteamHTMLSurface.SetCookie("html-kit.com", "testcookiekey", "testcookievalue"); print("SteamHTMLSurface.SetCookie(\"html-kit.com\", \"testcookiekey\", \"testcookievalue\")"); } m_ScaleFactor = GUILayout.HorizontalScrollbar(m_ScaleFactor, 0.25f, 0f, 2f); if (GUILayout.Button("SetPageScaleFactor(m_HHTMLBrowser, " + m_ScaleFactor + ", 0, 0)")) { SteamHTMLSurface.SetPageScaleFactor(m_HHTMLBrowser, m_ScaleFactor, 0, 0); print("SteamHTMLSurface.SetPageScaleFactor(m_HHTMLBrowser, " + m_ScaleFactor + ", 0, 0)"); } if (m_HHTMLBrowser == HHTMLBrowser.Invalid) { return; } // We set the moust position before checking for mouse presses just incase the mouse moved in the same OnGUI frame as a mouse press. Event e = Event.current; if (e.mousePosition != m_LastMousePos) { if ((e.mousePosition.x >= WidthOffset && e.mousePosition.x <= m_Width + WidthOffset) && (e.mousePosition.y >= HeightOffset && e.mousePosition.y <= m_Height + HeightOffset)) { m_LastMousePos = e.mousePosition; SteamHTMLSurface.MouseMove(m_HHTMLBrowser, (int)(e.mousePosition.x - WidthOffset), (int)(e.mousePosition.y - HeightOffset)); } } //virtual void MouseDoubleClick( HHTMLBrowser unBrowserHandle, EHTMLMouseButton eMouseButton ) = 0; //TODO switch (e.type) { case EventType.MouseDown: SteamHTMLSurface.MouseDown(m_HHTMLBrowser, (EHTMLMouseButton)e.button); break; case EventType.MouseUp: SteamHTMLSurface.MouseUp(m_HHTMLBrowser, (EHTMLMouseButton)e.button); break; case EventType.ScrollWheel: SteamHTMLSurface.MouseWheel(m_HHTMLBrowser, (int)(-e.delta.y * 100)); break; case EventType.KeyDown: //print("KeyDown: " + e.keyCode + " - " + (int)e.character + " - " + e.character); EHTMLKeyModifiers modifiers = EHTMLKeyModifiers.k_eHTMLKeyModifier_None; if (e.alt) { modifiers = modifiers | EHTMLKeyModifiers.k_eHTMLKeyModifier_AltDown; } if (e.shift) { modifiers = modifiers | EHTMLKeyModifiers.k_eHTMLKeyModifier_ShiftDown; } if (e.control) { modifiers = modifiers | EHTMLKeyModifiers.k_eHTMLKeyModifier_CtrlDown; } if (e.keyCode != KeyCode.None) { SteamHTMLSurface.KeyDown(m_HHTMLBrowser, (uint)e.keyCode, modifiers); } if (e.character != 0) { SteamHTMLSurface.KeyChar(m_HHTMLBrowser, (uint)e.character, modifiers); } if (e.keyCode == KeyCode.DownArrow) { m_VeritcalScrollCurrent = System.Math.Min(m_VeritcalScrollCurrent + 100, m_VerticalScrollMax); SteamHTMLSurface.SetVerticalScroll(m_HHTMLBrowser, m_VeritcalScrollCurrent); } else if (e.keyCode == KeyCode.UpArrow) { if (m_VeritcalScrollCurrent - 100 > m_VeritcalScrollCurrent) // Underflow { m_VeritcalScrollCurrent = 0; } else { m_VeritcalScrollCurrent -= 100; } SteamHTMLSurface.SetVerticalScroll(m_HHTMLBrowser, m_VeritcalScrollCurrent); } else if (e.keyCode == KeyCode.RightArrow) { m_HorizontalScrollCurrent = System.Math.Min(m_HorizontalScrollCurrent + 100, m_HorizontalScrollMax); SteamHTMLSurface.SetHorizontalScroll(m_HHTMLBrowser, m_HorizontalScrollCurrent); } else if (e.keyCode == KeyCode.LeftArrow) { if (m_HorizontalScrollCurrent - 100 > m_HorizontalScrollCurrent) // Underflow { m_HorizontalScrollCurrent = 0; } else { m_HorizontalScrollCurrent -= 100; } SteamHTMLSurface.SetHorizontalScroll(m_HHTMLBrowser, m_HorizontalScrollCurrent); } break; case EventType.KeyUp: //print("KeyUp: " + e.keyCode + " - " + (int)e.character + " - " + e.character); modifiers = EHTMLKeyModifiers.k_eHTMLKeyModifier_None; if (e.alt) { modifiers = modifiers | EHTMLKeyModifiers.k_eHTMLKeyModifier_AltDown; } if (e.shift) { modifiers = modifiers | EHTMLKeyModifiers.k_eHTMLKeyModifier_ShiftDown; } if (e.control) { modifiers = modifiers | EHTMLKeyModifiers.k_eHTMLKeyModifier_CtrlDown; } if (e.keyCode != KeyCode.None) { SteamHTMLSurface.KeyUp(m_HHTMLBrowser, (uint)e.keyCode, modifiers); } break; } }
public void OnDisable() { RemoveBrowser(); SteamHTMLSurface.Shutdown(); }
public static void OnStartRequest(HTML_StartRequest_t pParam) { Console.WriteLine("Browser request initiated."); SteamHTMLSurface.AllowStartRequest(Browser, true); }