From beca2d26f3d797ea532dd6ef522352a7469ed05b Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Mon, 1 Aug 2016 11:26:51 +0800 Subject: [PATCH 1/2] Swipe back/forward should respect system preferences --- atom/browser/native_window_mac.mm | 4 ++++ atom/common/platform_util.h | 7 +++++++ atom/common/platform_util_mac.mm | 7 +++++++ 3 files changed, 18 insertions(+) diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index 743e308d594a..5b2f30040d33 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -10,6 +10,7 @@ #include "atom/common/color_util.h" #include "atom/common/draggable_region.h" #include "atom/common/options_switches.h" +#include "atom/common/platform_util.h" #include "base/mac/mac_util.h" #include "base/mac/scoped_cftyperef.h" #include "base/strings/sys_string_conversions.h" @@ -577,6 +578,9 @@ NativeWindowMac::NativeWindowMac( if (!web_contents) return event; + if (!platform_util::IsSwipeTrackingFromScrollEventsEnabled()) + return event; + if (!began && (([event phase] == NSEventPhaseMayBegin) || ([event phase] == NSEventPhaseBegan))) { this->NotifyWindowScrollTouchBegin(); diff --git a/atom/common/platform_util.h b/atom/common/platform_util.h index 262f0a2e6e49..5c65ec77468e 100644 --- a/atom/common/platform_util.h +++ b/atom/common/platform_util.h @@ -42,6 +42,13 @@ bool MoveItemToTrash(const base::FilePath& full_path); void Beep(); +#if defined(OS_MACOSX) +// On 10.7+, back and forward swipe gestures can be triggered using a scroll +// gesture, if enabled in System Preferences. This function returns true if +// the feature is supported and enabled, and false otherwise. +bool IsSwipeTrackingFromScrollEventsEnabled(); +#endif + } // namespace platform_util #endif // ATOM_COMMON_PLATFORM_UTIL_H_ diff --git a/atom/common/platform_util_mac.mm b/atom/common/platform_util_mac.mm index d0146b11e085..2768230f0f95 100644 --- a/atom/common/platform_util_mac.mm +++ b/atom/common/platform_util_mac.mm @@ -11,6 +11,7 @@ #include "base/files/file_util.h" #include "base/logging.h" #include "base/mac/mac_logging.h" +#import "base/mac/sdk_forward_declarations.h" #include "base/mac/scoped_aedesc.h" #include "base/strings/sys_string_conversions.h" #include "net/base/mac/url_conversions.h" @@ -168,4 +169,10 @@ void Beep() { NSBeep(); } +bool IsSwipeTrackingFromScrollEventsEnabled() { + SEL selector = @selector(isSwipeTrackingFromScrollEventsEnabled); + return [NSEvent respondsToSelector:selector] + && [NSEvent performSelector:selector]; +} + } // namespace platform_util From e0c0e3e5f7d9aeabf9c7a9e374777975859b8e23 Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Wed, 3 Aug 2016 10:27:56 +0800 Subject: [PATCH 2/2] Add IsSwipeTrackingFromScrollEventsEnabled in system prefs --- atom/browser/api/atom_api_system_preferences.cc | 2 ++ atom/browser/api/atom_api_system_preferences.h | 4 ++++ atom/browser/api/atom_api_system_preferences_mac.mm | 7 +++++++ atom/browser/native_window_mac.mm | 4 ---- atom/common/platform_util.h | 7 ------- atom/common/platform_util_mac.mm | 7 ------- docs/api/system-preferences.md | 4 ++++ 7 files changed, 17 insertions(+), 18 deletions(-) diff --git a/atom/browser/api/atom_api_system_preferences.cc b/atom/browser/api/atom_api_system_preferences.cc index c3421365f0c8..c530f6ccf181 100644 --- a/atom/browser/api/atom_api_system_preferences.cc +++ b/atom/browser/api/atom_api_system_preferences.cc @@ -58,6 +58,8 @@ void SystemPreferences::BuildPrototype( .SetMethod("unsubscribeLocalNotification", &SystemPreferences::UnsubscribeLocalNotification) .SetMethod("getUserDefault", &SystemPreferences::GetUserDefault) + .SetMethod("isSwipeTrackingFromScrollEventsEnabled", + &SystemPreferences::IsSwipeTrackingFromScrollEventsEnabled) #endif .SetMethod("isDarkMode", &SystemPreferences::IsDarkMode); } diff --git a/atom/browser/api/atom_api_system_preferences.h b/atom/browser/api/atom_api_system_preferences.h index 9a5cf990357a..5438ca729e81 100644 --- a/atom/browser/api/atom_api_system_preferences.h +++ b/atom/browser/api/atom_api_system_preferences.h @@ -40,6 +40,10 @@ class SystemPreferences : public mate::EventEmitter { void UnsubscribeLocalNotification(int request_id); v8::Local GetUserDefault(const std::string& name, const std::string& type); + // On 10.7+, back and forward swipe gestures can be triggered using a scroll + // gesture, if enabled in System Preferences. This function returns true if + // the feature is supported and enabled, and false otherwise. + bool IsSwipeTrackingFromScrollEventsEnabled(); #endif bool IsDarkMode(); diff --git a/atom/browser/api/atom_api_system_preferences_mac.mm b/atom/browser/api/atom_api_system_preferences_mac.mm index 6f7055ab9135..3fe109cc8646 100644 --- a/atom/browser/api/atom_api_system_preferences_mac.mm +++ b/atom/browser/api/atom_api_system_preferences_mac.mm @@ -11,6 +11,7 @@ #include "atom/browser/mac/dict_util.h" #include "atom/common/native_mate_converters/value_converter.h" #include "atom/common/native_mate_converters/gurl_converter.h" +#import "base/mac/sdk_forward_declarations.h" #include "base/strings/sys_string_conversions.h" #include "base/values.h" #include "net/base/mac/url_conversions.h" @@ -122,6 +123,12 @@ bool SystemPreferences::IsDarkMode() { return [mode isEqualToString:@"Dark"]; } +bool SystemPreferences::IsSwipeTrackingFromScrollEventsEnabled() { + SEL selector = @selector(isSwipeTrackingFromScrollEventsEnabled); + return [NSEvent respondsToSelector:selector] + && [NSEvent performSelector:selector]; +} + } // namespace api } // namespace atom diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index 5b2f30040d33..743e308d594a 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -10,7 +10,6 @@ #include "atom/common/color_util.h" #include "atom/common/draggable_region.h" #include "atom/common/options_switches.h" -#include "atom/common/platform_util.h" #include "base/mac/mac_util.h" #include "base/mac/scoped_cftyperef.h" #include "base/strings/sys_string_conversions.h" @@ -578,9 +577,6 @@ NativeWindowMac::NativeWindowMac( if (!web_contents) return event; - if (!platform_util::IsSwipeTrackingFromScrollEventsEnabled()) - return event; - if (!began && (([event phase] == NSEventPhaseMayBegin) || ([event phase] == NSEventPhaseBegan))) { this->NotifyWindowScrollTouchBegin(); diff --git a/atom/common/platform_util.h b/atom/common/platform_util.h index 5c65ec77468e..262f0a2e6e49 100644 --- a/atom/common/platform_util.h +++ b/atom/common/platform_util.h @@ -42,13 +42,6 @@ bool MoveItemToTrash(const base::FilePath& full_path); void Beep(); -#if defined(OS_MACOSX) -// On 10.7+, back and forward swipe gestures can be triggered using a scroll -// gesture, if enabled in System Preferences. This function returns true if -// the feature is supported and enabled, and false otherwise. -bool IsSwipeTrackingFromScrollEventsEnabled(); -#endif - } // namespace platform_util #endif // ATOM_COMMON_PLATFORM_UTIL_H_ diff --git a/atom/common/platform_util_mac.mm b/atom/common/platform_util_mac.mm index 2768230f0f95..d0146b11e085 100644 --- a/atom/common/platform_util_mac.mm +++ b/atom/common/platform_util_mac.mm @@ -11,7 +11,6 @@ #include "base/files/file_util.h" #include "base/logging.h" #include "base/mac/mac_logging.h" -#import "base/mac/sdk_forward_declarations.h" #include "base/mac/scoped_aedesc.h" #include "base/strings/sys_string_conversions.h" #include "net/base/mac/url_conversions.h" @@ -169,10 +168,4 @@ void Beep() { NSBeep(); } -bool IsSwipeTrackingFromScrollEventsEnabled() { - SEL selector = @selector(isSwipeTrackingFromScrollEventsEnabled); - return [NSEvent respondsToSelector:selector] - && [NSEvent performSelector:selector]; -} - } // namespace platform_util diff --git a/docs/api/system-preferences.md b/docs/api/system-preferences.md index 8a2af28a295d..0ac63b1b3c6a 100644 --- a/docs/api/system-preferences.md +++ b/docs/api/system-preferences.md @@ -13,6 +13,10 @@ console.log(systemPreferences.isDarkMode()) This method returns `true` if the system is in Dark Mode, and `false` otherwise. +### `systemPreferences.isSwipeTrackingFromScrollEventsEnabled()` _macOS_ + +This method returns `true` if the Swipe between pages setting is on, and `false` otherwise. + ### `systemPreferences.subscribeNotification(event, callback)` _macOS_ * `event` String