yuzu-emu
/
yuzu-android
Archived
1
0
Fork 0

Merge pull request #6671 from jls47/master

applets/web: Addressing QT Navigation issues in Linux
This commit is contained in:
Morph 2021-07-27 22:46:27 -04:00 committed by GitHub
commit 5593a3716e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 1 deletions

View File

@ -107,6 +107,7 @@ void QtNXWebEngineView::LoadLocalWebPage(const std::string& main_url,
is_local = true; is_local = true;
LoadExtractedFonts(); LoadExtractedFonts();
FocusFirstLinkElement();
SetUserAgent(UserAgent::WebApplet); SetUserAgent(UserAgent::WebApplet);
SetFinished(false); SetFinished(false);
SetExitReason(Service::AM::Applets::WebExitReason::EndButtonPressed); SetExitReason(Service::AM::Applets::WebExitReason::EndButtonPressed);
@ -121,6 +122,7 @@ void QtNXWebEngineView::LoadExternalWebPage(const std::string& main_url,
const std::string& additional_args) { const std::string& additional_args) {
is_local = false; is_local = false;
FocusFirstLinkElement();
SetUserAgent(UserAgent::WebApplet); SetUserAgent(UserAgent::WebApplet);
SetFinished(false); SetFinished(false);
SetExitReason(Service::AM::Applets::WebExitReason::EndButtonPressed); SetExitReason(Service::AM::Applets::WebExitReason::EndButtonPressed);
@ -208,7 +210,7 @@ void QtNXWebEngineView::HandleWindowFooterButtonPressedOnce() {
if (input_interpreter->IsButtonPressedOnce(button)) { if (input_interpreter->IsButtonPressedOnce(button)) {
page()->runJavaScript( page()->runJavaScript(
QStringLiteral("yuzu_key_callbacks[%1] == null;").arg(static_cast<u8>(button)), QStringLiteral("yuzu_key_callbacks[%1] == null;").arg(static_cast<u8>(button)),
[&](const QVariant& variant) { [this, button](const QVariant& variant) {
if (variant.toBool()) { if (variant.toBool()) {
switch (button) { switch (button) {
case HIDButton::A: case HIDButton::A:
@ -364,6 +366,17 @@ void QtNXWebEngineView::LoadExtractedFonts() {
Qt::QueuedConnection); 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 #endif
QtWebBrowser::QtWebBrowser(GMainWindow& main_window) { QtWebBrowser::QtWebBrowser(GMainWindow& main_window) {

View File

@ -161,6 +161,9 @@ private:
/// Loads the extracted fonts using JavaScript. /// Loads the extracted fonts using JavaScript.
void LoadExtractedFonts(); void LoadExtractedFonts();
/// Brings focus to the first available link element.
void FocusFirstLinkElement();
InputCommon::InputSubsystem* input_subsystem; InputCommon::InputSubsystem* input_subsystem;
std::unique_ptr<UrlRequestInterceptor> url_interceptor; std::unique_ptr<UrlRequestInterceptor> url_interceptor;

View File

@ -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"( constexpr char GAMEPAD_SCRIPT[] = R"(
window.addEventListener("gamepadconnected", function(e) { window.addEventListener("gamepadconnected", function(e) {
console.log("Gamepad connected at index %d: %s. %d buttons, %d axes.", console.log("Gamepad connected at index %d: %s. %d buttons, %d axes.",