From df397dab305d881a8e80dd59296f62e22df8adce Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 6 May 2016 14:57:43 +0900 Subject: [PATCH] Add scrollBounce option and disable it by default --- atom/browser/web_contents_preferences.cc | 8 ++++++++ atom/common/options_switches.cc | 4 ++++ atom/common/options_switches.h | 2 ++ atom/renderer/atom_renderer_client.cc | 19 +++++++++++++++++++ docs/api/browser-window.md | 2 ++ 5 files changed, 35 insertions(+) diff --git a/atom/browser/web_contents_preferences.cc b/atom/browser/web_contents_preferences.cc index 05286a2..41db39b 100644 --- a/atom/browser/web_contents_preferences.cc +++ b/atom/browser/web_contents_preferences.cc @@ -141,6 +141,14 @@ void WebContentsPreferences::AppendExtraCommandLineSwitches( command_line->AppendSwitchASCII(switches::kOpenerID, base::IntToString(opener_id)); +#if defined(OS_MACOSX) + // Enable scroll bounce. + bool scroll_bounce; + if (web_preferences.GetBoolean(options::kScrollBounce, &scroll_bounce) && + scroll_bounce) + command_line->AppendSwitch(switches::kScrollBounce); +#endif + // Enable blink features. std::string blink_features; if (web_preferences.GetString(options::kBlinkFeatures, &blink_features)) diff --git a/atom/common/options_switches.cc b/atom/common/options_switches.cc index 562171d..166942d 100644 --- a/atom/common/options_switches.cc +++ b/atom/common/options_switches.cc @@ -103,6 +103,9 @@ const char kExperimentalCanvasFeatures[] = "experimentalCanvasFeatures"; // Opener window's ID. const char kOpenerID[] = "openerId"; +// Enable the rubber banding effect. +const char kScrollBounce[] = "scrollBounce"; + // Enable blink features. const char kBlinkFeatures[] = "blinkFeatures"; @@ -146,6 +149,7 @@ const char kPreloadURL[] = "preload-url"; const char kNodeIntegration[] = "node-integration"; const char kGuestInstanceID[] = "guest-instance-id"; const char kOpenerID[] = "opener-id"; +const char kScrollBounce[] = "scroll-bounce"; // Widevine options // Path to Widevine CDM binaries. diff --git a/atom/common/options_switches.h b/atom/common/options_switches.h index 5746a7b..653f35a 100644 --- a/atom/common/options_switches.h +++ b/atom/common/options_switches.h @@ -56,6 +56,7 @@ extern const char kGuestInstanceID[]; extern const char kExperimentalFeatures[]; extern const char kExperimentalCanvasFeatures[]; extern const char kOpenerID[]; +extern const char kScrollBounce[]; extern const char kBlinkFeatures[]; } // namespace options @@ -82,6 +83,7 @@ extern const char kPreloadURL[]; extern const char kNodeIntegration[]; extern const char kGuestInstanceID[]; extern const char kOpenerID[]; +extern const char kScrollBounce[]; extern const char kWidevineCdmPath[]; extern const char kWidevineCdmVersion[]; diff --git a/atom/renderer/atom_renderer_client.cc b/atom/renderer/atom_renderer_client.cc index 4bb3cd2..d090d8a 100644 --- a/atom/renderer/atom_renderer_client.cc +++ b/atom/renderer/atom_renderer_client.cc @@ -36,6 +36,11 @@ #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" #include "third_party/WebKit/public/web/WebView.h" +#if defined(OS_MACOSX) +#include "base/mac/mac_util.h" +#include "base/strings/sys_string_conversions.h" +#endif + #if defined(OS_WIN) #include #endif @@ -97,6 +102,7 @@ void AtomRendererClient::RenderThreadStarted() { content::RenderThread::Get()->AddObserver(this); #if defined(OS_WIN) + // Set ApplicationUserModelID in renderer process. base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); base::string16 app_id = command_line->GetSwitchValueNative(switches::kAppUserModelId); @@ -104,6 +110,19 @@ void AtomRendererClient::RenderThreadStarted() { SetCurrentProcessExplicitAppUserModelID(app_id.c_str()); } #endif + +#if defined(OS_MACOSX) + // Disable rubber banding by default. + base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); + if (!command_line->HasSwitch(switches::kScrollBounce)) { + base::ScopedCFTypeRef key( + base::SysUTF8ToCFStringRef("NSScrollViewRubberbanding")); + base::ScopedCFTypeRef value( + base::SysUTF8ToCFStringRef("false")); + CFPreferencesSetAppValue(key, value, kCFPreferencesCurrentApplication); + CFPreferencesAppSynchronize(kCFPreferencesCurrentApplication); + } +#endif } void AtomRendererClient::RenderFrameCreated( diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index 895547c..d4ed6c0 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -170,6 +170,8 @@ The `webPreferences` option is an object that can have following properties: canvas features. Default is `false`. * `directWrite` Boolean - Enables DirectWrite font rendering system on Windows. Default is `true`. +* `scrollBounce` Boolean - Enables scroll bounce (rubber banding) effect on + OS X. Default is `false`. * `blinkFeatures` String - A list of feature strings separated by `,`, like `CSSVariables,KeyboardEventKey`. The full list of supported feature strings can be found in the [setFeatureEnabledFromString][blink-feature-string] -- 2.7.4