From 88c0df7c8c8a3917a74510cca62d3c76955fedcb Mon Sep 17 00:00:00 2001
From: Svornost <11434-svornost@users.noreply.gitgud.io>
Date: Tue, 6 Aug 2019 21:12:48 -0700
Subject: [PATCH] Apparently Chrome's ENTIRE javascript debugger is exposed in
 CEF, so we can just...use it.  Cool.

---
 FCHost/fchost/fchost_handler.cc | 32 ++++++++++++++++++++++++++++++++
 FCHost/fchost/fchost_handler.h  | 12 ++++++++++--
 2 files changed, 42 insertions(+), 2 deletions(-)

diff --git a/FCHost/fchost/fchost_handler.cc b/FCHost/fchost/fchost_handler.cc
index 20ca8967434..33586d050ea 100644
--- a/FCHost/fchost/fchost_handler.cc
+++ b/FCHost/fchost/fchost_handler.cc
@@ -151,6 +151,38 @@ void FCHostHandler::OnBeforeDownload(CefRefPtr<CefBrowser> browser,
 	callback->Continue(suggested_name, true);
 }
 
+bool FCHostHandler::OnPreKeyEvent(CefRefPtr<CefBrowser> browser,
+	const CefKeyEvent& event,
+	CefEventHandle os_event,
+	bool* is_keyboard_shortcut)
+{
+	CEF_REQUIRE_UI_THREAD();
+
+	if (event.type == cef_key_event_type_t::KEYEVENT_CHAR)
+	{
+		// CTRL+SHIFT+J - bring up the Javascript debugger
+		if ((event.modifiers == (cef_event_flags_t::EVENTFLAG_CONTROL_DOWN | cef_event_flags_t::EVENTFLAG_SHIFT_DOWN)) && event.unmodified_character == 10 /* j? maybe only on windows? whatever */)
+		{
+			CefWindowInfo windowInfo;
+			CefBrowserSettings settings;
+			CefPoint point;
+			windowInfo.SetAsPopup(browser->GetHost()->GetWindowHandle(), "DevTools");
+			browser->GetHost()->ShowDevTools(windowInfo, browser->GetHost()->GetClient(), settings, point);
+
+			return true;
+		}
+		// CTRL+F - bring up Find In Page
+		else if (event.modifiers == cef_event_flags_t::EVENTFLAG_CONTROL_DOWN && event.unmodified_character == 6 /* f? maybe only on windows? whatever */)
+		{
+			// probably can do this at some point by ripping off code from the full-fat cefclient, but damn there's a lot of it...
+			// return true;
+		}
+	}
+
+	return false;
+}
+
+
 void FCHostHandler::CloseAllBrowsers(bool force_close) {
   if (!CefCurrentlyOn(TID_UI)) {
     // Execute on the UI thread.
diff --git a/FCHost/fchost/fchost_handler.h b/FCHost/fchost/fchost_handler.h
index c4288392505..940d0348458 100644
--- a/FCHost/fchost/fchost_handler.h
+++ b/FCHost/fchost/fchost_handler.h
@@ -12,7 +12,8 @@ class FCHostHandler : public CefClient,
                       public CefDisplayHandler,
                       public CefLifeSpanHandler,
                       public CefLoadHandler,
-					  public CefDownloadHandler {
+					  public CefDownloadHandler,
+					  public CefKeyboardHandler {
  public:
   explicit FCHostHandler(bool use_views);
   ~FCHostHandler();
@@ -29,6 +30,7 @@ class FCHostHandler : public CefClient,
   }
   virtual CefRefPtr<CefLoadHandler> GetLoadHandler() OVERRIDE { return this; }
   virtual CefRefPtr<CefDownloadHandler> GetDownloadHandler() OVERRIDE { return this; }
+  virtual CefRefPtr<CefKeyboardHandler> GetKeyboardHandler() OVERRIDE { return this; }
 
 
   // CefDisplayHandler methods:
@@ -57,7 +59,13 @@ class FCHostHandler : public CefClient,
 								CefRefPtr<CefDownloadItem> download_item,
 								const CefString& suggested_name,
 								CefRefPtr< CefBeforeDownloadCallback > callback) OVERRIDE;
-    
+
+  // CefKeyboardHandler methods:
+  virtual bool OnPreKeyEvent(CefRefPtr<CefBrowser> browser,
+							const CefKeyEvent& event,
+							CefEventHandle os_event,
+							bool* is_keyboard_shortcut) OVERRIDE;
+
   // Request that all existing browser windows close.
   void CloseAllBrowsers(bool force_close);
 
-- 
GitLab