summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjls47 <lukeschaefer@gmail.com>2021-07-18 01:10:15 +0200
committerMorph <39850852+Morph1984@users.noreply.github.com>2021-07-27 17:31:11 +0200
commit3109d1c3db496e05558ddd836c63dbbc3dab1b98 (patch)
tree3cbff9442f111b101535f79d44edfa9f2e8dacd8
parentMerge pull request #6696 from ameerj/speed-limit-rename (diff)
downloadyuzu-3109d1c3db496e05558ddd836c63dbbc3dab1b98.tar
yuzu-3109d1c3db496e05558ddd836c63dbbc3dab1b98.tar.gz
yuzu-3109d1c3db496e05558ddd836c63dbbc3dab1b98.tar.bz2
yuzu-3109d1c3db496e05558ddd836c63dbbc3dab1b98.tar.lz
yuzu-3109d1c3db496e05558ddd836c63dbbc3dab1b98.tar.xz
yuzu-3109d1c3db496e05558ddd836c63dbbc3dab1b98.tar.zst
yuzu-3109d1c3db496e05558ddd836c63dbbc3dab1b98.zip
-rw-r--r--src/yuzu/applets/qt_web_browser.cpp13
-rw-r--r--src/yuzu/applets/qt_web_browser.h3
-rw-r--r--src/yuzu/applets/qt_web_browser_scripts.h6
3 files changed, 22 insertions, 0 deletions
diff --git a/src/yuzu/applets/qt_web_browser.cpp b/src/yuzu/applets/qt_web_browser.cpp
index b112dd7b0..cc1a42f74 100644
--- a/src/yuzu/applets/qt_web_browser.cpp
+++ b/src/yuzu/applets/qt_web_browser.cpp
@@ -107,6 +107,7 @@ void QtNXWebEngineView::LoadLocalWebPage(const std::string& main_url,
is_local = true;
LoadExtractedFonts();
+ FocusFirstLinkElement();
SetUserAgent(UserAgent::WebApplet);
SetFinished(false);
SetExitReason(Service::AM::Applets::WebExitReason::EndButtonPressed);
@@ -121,6 +122,7 @@ void QtNXWebEngineView::LoadExternalWebPage(const std::string& main_url,
const std::string& additional_args) {
is_local = false;
+ FocusFirstLinkElement();
SetUserAgent(UserAgent::WebApplet);
SetFinished(false);
SetExitReason(Service::AM::Applets::WebExitReason::EndButtonPressed);
@@ -364,6 +366,17 @@ void QtNXWebEngineView::LoadExtractedFonts() {
Qt::QueuedConnection);
}
+void QtNXWebEngineView::FocusFirstLinkElement() {
+ QWebEngineScript focus_link_element;
+
+ focus_link_element.setName(QStringLiteral("focus_link_element.js"));
+ focus_link_element.setSourceCode(QString::fromStdString(FOCUS_LINK_ELEMENT_SCRIPT));
+ focus_link_element.setWorldId(QWebEngineScript::MainWorld);
+ focus_link_element.setInjectionPoint(QWebEngineScript::Deferred);
+ focus_link_element.setRunsOnSubFrames(true);
+ default_profile->scripts()->insert(focus_link_element);
+}
+
#endif
QtWebBrowser::QtWebBrowser(GMainWindow& main_window) {
diff --git a/src/yuzu/applets/qt_web_browser.h b/src/yuzu/applets/qt_web_browser.h
index 7ad07409f..7e9f703fc 100644
--- a/src/yuzu/applets/qt_web_browser.h
+++ b/src/yuzu/applets/qt_web_browser.h
@@ -161,6 +161,9 @@ private:
/// Loads the extracted fonts using JavaScript.
void LoadExtractedFonts();
+ /// Brings focus to the first available link element.
+ void FocusFirstLinkElement();
+
InputCommon::InputSubsystem* input_subsystem;
std::unique_ptr<UrlRequestInterceptor> url_interceptor;
diff --git a/src/yuzu/applets/qt_web_browser_scripts.h b/src/yuzu/applets/qt_web_browser_scripts.h
index 992837a85..c4ba8d40f 100644
--- a/src/yuzu/applets/qt_web_browser_scripts.h
+++ b/src/yuzu/applets/qt_web_browser_scripts.h
@@ -73,6 +73,12 @@ constexpr char LOAD_NX_FONT[] = R"(
})();
)";
+constexpr char FOCUS_LINK_ELEMENT_SCRIPT[] = R"(
+if (document.getElementsByTagName("a").length > 0) {
+ document.getElementsByTagName("a")[0].focus();
+}
+)";
+
constexpr char GAMEPAD_SCRIPT[] = R"(
window.addEventListener("gamepadconnected", function(e) {
console.log("Gamepad connected at index %d: %s. %d buttons, %d axes.",