Skip to content

Commit

Permalink
Add link from a11y settings to trackpad system settings on Mac
Browse files Browse the repository at this point in the history
Adds a link row in chrome://settings/accessibility that opens the
trackpad pane in Mac's system settings. This is only shown when the
OverscrollHistoryNavigationSetting feature is enabled.

Screenshot: https://screenshot.googleplex.com/9zu9Qa9zwRgWyLY

Low-Coverage-Reason: Handler does not have any business logic, only used to respond to a call from settings webui.
Bug: 1473415
Change-Id: Ic56d5e1a23578b45a132ef89441dc33bc0467872
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4786249
Reviewed-by: Francois Pierre Doray <fdoray@chromium.org>
Commit-Queue: Charles Meng <charlesmeng@chromium.org>
Reviewed-by: Avi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1184945}
  • Loading branch information
Charles Meng authored and Chromium LUCI CQ committed Aug 17, 2023
1 parent 365895c commit 4a9eff0
Show file tree
Hide file tree
Showing 13 changed files with 145 additions and 5 deletions.
3 changes: 3 additions & 0 deletions base/mac/mac_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ enum class SystemSettingsPane {

// Privacy & Security > Screen Recording
kPrivacySecurity_ScreenRecording,

// Trackpad
kTrackpad,
};

// Opens the specified System Settings pane. If the specified subpane does not
Expand Down
8 changes: 8 additions & 0 deletions base/mac/mac_util.mm
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,14 @@ void OpenSystemSettingsPane(SystemSettingsPane pane) {
@"Privacy_ScreenCapture";
}
break;
case SystemSettingsPane::kTrackpad:
if (IsAtLeastOS13()) {
url = @"x-apple.systempreferences:com.apple.Trackpad-Settings."
@"extension";
} else {
url = @"x-apple.systempreferences:com.apple.preference.trackpad";
}
break;
}

DCHECK(url != nil ^ pane_file != nil);
Expand Down
9 changes: 8 additions & 1 deletion chrome/app/settings_strings.grdp
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,21 @@
Manage accessibility features
</message>
</if>
<if expr="is_win or is_linux">
<if expr="is_win or is_linux or is_macosx">
<message name="IDS_SETTINGS_OVERSCROLL_HISTORY_NAVIGATION_TITLE" desc="Title for the overscroll history navigation setting, which allows you to navigate back and forward by swiping left or right with a touch device.">
Swipe between pages
</message>
</if>
<if expr="is_win or is_linux">
<message name="IDS_SETTINGS_OVERSCROLL_HISTORY_NAVIGATION_SUBTITLE" desc="Subtitle for the overscroll history navigation setting, which allows you to navigate back and forward by swiping left or right with a touch device.">
Navigate back and forward with swipe gesture
</message>
</if>
<if expr="is_macosx">
<message name="IDS_SETTINGS_OVERSCROLL_HISTORY_NAVIGATION_SUBTITLE" desc="Subtitle for the overscroll history navigation setting, which allows you to navigate back and forward by swiping left or right with a touch device.">
Turn on to navigate back and forward
</message>
</if>

<!-- Appearance Page -->
<message name="IDS_SETTINGS_APPEARANCE" desc="Name of the settings page which displays appearance preferences.">
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
cdebeaa249f8a57f557a5bdeac45413fdd1beff6
94a1d4d14c96739eeabac4f467f60d8b34692c13
11 changes: 11 additions & 0 deletions chrome/browser/resources/settings/a11y_page/a11y_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,17 @@
label="$i18n{overscrollHistoryNavigationTitle}"
sub-label="$i18n{overscrollHistoryNavigationSubtitle}">
</settings-toggle-button>
</if>
<if expr="is_macosx">
<cr-link-row
class="hr"
hidden$="[[!showOverscrollHistoryNavigationToggle_]]"
on-click="onMacTrackpadGesturesLinkClick_"
button-aria-description="$i18n{opensInNewTab}"
label="$i18n{overscrollHistoryNavigationTitle}"
sub-label="$i18n{overscrollHistoryNavigationSubtitle}"
external>
</cr-link-row>
</if>
<cr-link-row class="hr" label="$i18n{moreFeaturesLink}"
on-click="onMoreFeaturesLinkClick_" sub-label="$i18n{a11yWebStore}"
Expand Down
13 changes: 11 additions & 2 deletions chrome/browser/resources/settings/a11y_page/a11y_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import './live_caption_section.js';

import {CaptionsBrowserProxyImpl} from '/shared/settings/a11y_page/captions_browser_proxy.js';
// </if>
// <if expr="is_macosx">
import {MacSystemSettingsBrowserProxyImpl} from '/shared/settings/mac_system_settings_browser_proxy.js';
// </if>
// clang-format on
import {SettingsToggleButtonElement} from '/shared/settings/controls/settings_toggle_button.js';
import {WebUiListenerMixin} from 'chrome://resources/cr_elements/web_ui_listener_mixin.js';
Expand All @@ -41,7 +44,6 @@ import {LanguageHelper, LanguagesModel} from '../languages_page/languages_types.
// </if>
// clang-format on


const SettingsA11yPageElementBase =
WebUiListenerMixin(BaseMixin(PolymerElement));

Expand Down Expand Up @@ -162,7 +164,7 @@ class SettingsA11yPageElement extends SettingsA11yPageElementBase {
type: Boolean,
value: function() {
let showOverscroll = false;
// <if expr="is_win or is_linux">
// <if expr="is_win or is_linux or is_macosx">
showOverscroll = loadTimeData.getBoolean(
'overscrollHistoryNavigationSettingEnabled');
// </if>
Expand Down Expand Up @@ -262,6 +264,13 @@ class SettingsA11yPageElement extends SettingsA11yPageElementBase {
Router.getInstance().navigateTo(routes.CAPTIONS);
}
}

// <if expr="is_macosx">
private onMacTrackpadGesturesLinkClick_() {
MacSystemSettingsBrowserProxyImpl.getInstance()
.openTrackpadGesturesSettings();
}
// </if>
}

customElements.define(SettingsA11yPageElement.is, SettingsA11yPageElement);
4 changes: 4 additions & 0 deletions chrome/browser/resources/settings_shared/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ build_webui("build") {
"privacy_page/privacy_page_browser_proxy.ts",
]

if (is_mac) {
non_web_component_files += [ "mac_system_settings_browser_proxy.ts" ]
}

ts_composite = true
ts_definitions = [
"//tools/typescript/definitions/chrome_send.d.ts",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

export interface MacSystemSettingsBrowserProxy {
openTrackpadGesturesSettings(): void;
}

export class MacSystemSettingsBrowserProxyImpl implements
MacSystemSettingsBrowserProxy {
openTrackpadGesturesSettings() {
chrome.send('openTrackpadGesturesSettings');
}

static getInstance(): MacSystemSettingsBrowserProxy {
return instance || (instance = new MacSystemSettingsBrowserProxyImpl());
}

static setInstance(obj: MacSystemSettingsBrowserProxy) {
instance = obj;
}
}

let instance: MacSystemSettingsBrowserProxy|null = null;
2 changes: 2 additions & 0 deletions chrome/browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -4173,6 +4173,8 @@ static_library("ui") {
"views/tab_contents/chrome_web_contents_view_delegate_views_mac.mm",
"webui/help/version_updater_mac.h",
"webui/help/version_updater_mac.mm",
"webui/settings/mac_system_settings_handler.cc",
"webui/settings/mac_system_settings_handler.h",
"webui/settings/settings_utils_mac.mm",
"window_sizer/window_sizer_mac.mm",
]
Expand Down
32 changes: 32 additions & 0 deletions chrome/browser/ui/webui/settings/mac_system_settings_handler.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ui/webui/settings/mac_system_settings_handler.h"

#include "base/mac/mac_util.h"

using content::WebContents;

namespace settings {

MacSystemSettingsHandler::MacSystemSettingsHandler() = default;
MacSystemSettingsHandler::~MacSystemSettingsHandler() = default;

void MacSystemSettingsHandler::RegisterMessages() {
web_ui()->RegisterMessageCallback(
"openTrackpadGesturesSettings",
base::BindRepeating(
&MacSystemSettingsHandler::HandleOpenTrackpadGesturesSettings,
base::Unretained(this)));
}

void MacSystemSettingsHandler::HandleOpenTrackpadGesturesSettings(
const base::Value::List& args) {
DCHECK(IsJavascriptAllowed());
// TODO(crbug.com/1473415): Figure out how to directly open the more gestures
// subpane. Currently this only opens the first subpane of trackpad settings.
base::mac::OpenSystemSettingsPane(base::mac::SystemSettingsPane::kTrackpad);
}

} // namespace settings
32 changes: 32 additions & 0 deletions chrome/browser/ui/webui/settings/mac_system_settings_handler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_UI_WEBUI_SETTINGS_MAC_SYSTEM_SETTINGS_HANDLER_H_
#define CHROME_BROWSER_UI_WEBUI_SETTINGS_MAC_SYSTEM_SETTINGS_HANDLER_H_

#include "chrome/browser/ui/webui/settings/settings_page_ui_handler.h"

namespace settings {

class MacSystemSettingsHandler : public SettingsPageUIHandler {
public:
MacSystemSettingsHandler();

MacSystemSettingsHandler(const MacSystemSettingsHandler&) = delete;
MacSystemSettingsHandler& operator=(const MacSystemSettingsHandler&) = delete;

~MacSystemSettingsHandler() override;

// SettingsPageUIHandler implementation.
void RegisterMessages() override;
void OnJavascriptAllowed() override {}
void OnJavascriptDisallowed() override {}

private:
void HandleOpenTrackpadGesturesSettings(const base::Value::List& args);
};

} // namespace settings

#endif // CHROME_BROWSER_UI_WEBUI_SETTINGS_MAC_SYSTEM_SETTINGS_HANDLER_H_
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ void AddA11yStrings(content::WebUIDataSource* html_source) {
{"focusHighlightLabel",
IDS_SETTINGS_ACCESSIBILITY_FOCUS_HIGHLIGHT_DESCRIPTION},
#endif
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX)
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_MAC)
{"overscrollHistoryNavigationTitle",
IDS_SETTINGS_OVERSCROLL_HISTORY_NAVIGATION_TITLE},
{"overscrollHistoryNavigationSubtitle",
Expand Down
8 changes: 8 additions & 0 deletions chrome/browser/ui/webui/settings/settings_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@
#include "components/password_manager/core/common/password_manager_pref_names.h"
#endif

#if BUILDFLAG(IS_MAC)
#include "chrome/browser/ui/webui/settings/mac_system_settings_handler.h"
#endif

namespace settings {

// static
Expand Down Expand Up @@ -269,6 +273,10 @@ SettingsUI::SettingsUI(content::WebUI* web_ui)

#endif

#if BUILDFLAG(IS_MAC)
AddSettingsPageUIHandler(std::make_unique<MacSystemSettingsHandler>());
#endif

#if BUILDFLAG(IS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
bool has_incompatible_applications =
IncompatibleApplicationsUpdater::HasCachedApplications();
Expand Down

0 comments on commit 4a9eff0

Please sign in to comment.