Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ jobs:
checkout-macos:
needs: setup
if: ${{ needs.setup.outputs.src == 'true' && !inputs.skip-macos}}
runs-on: electron-arc-linux-amd64-32core
runs-on: ubuntu-latest
container:
image: ghcr.io/electron/build:${{ needs.setup.outputs.build-image-sha }}
options: --user root
Expand Down Expand Up @@ -120,7 +120,7 @@ jobs:
checkout-linux:
needs: setup
if: ${{ needs.setup.outputs.src == 'true' && !inputs.skip-linux}}
runs-on: electron-arc-linux-amd64-32core
runs-on: ubuntu-latest
container:
image: ghcr.io/electron/build:${{ needs.setup.outputs.build-image-sha }}
options: --user root
Expand Down Expand Up @@ -149,7 +149,7 @@ jobs:
checkout-windows:
needs: setup
if: ${{ needs.setup.outputs.src == 'true' && !inputs.skip-windows }}
runs-on: electron-arc-linux-amd64-32core
runs-on: ubuntu-latest
container:
image: ghcr.io/electron/build:${{ needs.setup.outputs.build-image-sha }}
options: --user root --device /dev/fuse --cap-add SYS_ADMIN
Expand Down Expand Up @@ -194,7 +194,7 @@ jobs:
with:
target-platform: linux
target-archs: x64 arm arm64
check-runs-on: electron-arc-linux-amd64-8core
check-runs-on: ubuntu-latest
check-container: '{"image":"ghcr.io/electron/build:${{ needs.checkout-linux.outputs.build-image-sha }}","options":"--user root","volumes":["/mnt/cross-instance-cache:/mnt/cross-instance-cache"]}'
gn-build-type: testing
secrets: inherit
Expand All @@ -205,7 +205,7 @@ jobs:
with:
target-platform: win
target-archs: x64 x86 arm64
check-runs-on: electron-arc-linux-amd64-8core
check-runs-on: ubuntu-latest
check-container: '{"image":"ghcr.io/electron/build:${{ needs.checkout-windows.outputs.build-image-sha }}","options":"--user root --device /dev/fuse --cap-add SYS_ADMIN","volumes":["/mnt/win-cache:/mnt/win-cache"]}'
gn-build-type: testing
secrets: inherit
Expand Down Expand Up @@ -255,8 +255,8 @@ jobs:
uses: ./.github/workflows/pipeline-electron-build-and-test-and-nan.yml
needs: checkout-linux
with:
build-runs-on: electron-arc-linux-amd64-32core
test-runs-on: electron-arc-linux-amd64-4core
build-runs-on: ubuntu-latest
test-runs-on: ubuntu-latest
build-container: '{"image":"ghcr.io/electron/build:${{ needs.checkout-linux.outputs.build-image-sha }}","options":"--user root","volumes":["/mnt/cross-instance-cache:/mnt/cross-instance-cache"]}'
test-container: '{"image":"ghcr.io/electron/build:${{ needs.checkout-linux.outputs.build-image-sha }}","options":"--user root --privileged --init"}'
target-platform: linux
Expand All @@ -275,8 +275,8 @@ jobs:
uses: ./.github/workflows/pipeline-electron-build-and-test.yml
needs: checkout-linux
with:
build-runs-on: electron-arc-linux-amd64-32core
test-runs-on: electron-arc-linux-amd64-4core
build-runs-on: ubuntu-latest
test-runs-on: ubuntu-latest
build-container: '{"image":"ghcr.io/electron/build:${{ needs.checkout-linux.outputs.build-image-sha }}","options":"--user root","volumes":["/mnt/cross-instance-cache:/mnt/cross-instance-cache"]}'
test-container: '{"image":"ghcr.io/electron/build:${{ needs.checkout-linux.outputs.build-image-sha }}","options":"--user root --privileged --init"}'
target-platform: linux
Expand All @@ -296,8 +296,8 @@ jobs:
uses: ./.github/workflows/pipeline-electron-build-and-test.yml
needs: checkout-linux
with:
build-runs-on: electron-arc-linux-amd64-32core
test-runs-on: electron-arc-linux-arm64-4core
build-runs-on: ubuntu-latest
test-runs-on: ubuntu-latest
build-container: '{"image":"ghcr.io/electron/build:${{ needs.checkout-linux.outputs.build-image-sha }}","options":"--user root","volumes":["/mnt/cross-instance-cache:/mnt/cross-instance-cache"]}'
test-container: '{"image":"ghcr.io/electron/test:arm32v7-${{ needs.checkout-linux.outputs.build-image-sha }}","options":"--user root --privileged --init","volumes":["/home/runner/externals:/mnt/runner-externals"]}'
target-platform: linux
Expand All @@ -316,8 +316,8 @@ jobs:
uses: ./.github/workflows/pipeline-electron-build-and-test.yml
needs: checkout-linux
with:
build-runs-on: electron-arc-linux-amd64-32core
test-runs-on: electron-arc-linux-arm64-4core
build-runs-on: ubuntu-latest
test-runs-on: ubuntu-latest
build-container: '{"image":"ghcr.io/electron/build:${{ needs.checkout-linux.outputs.build-image-sha }}","options":"--user root","volumes":["/mnt/cross-instance-cache:/mnt/cross-instance-cache"]}'
test-container: '{"image":"ghcr.io/electron/test:arm64v8-${{ needs.checkout-linux.outputs.build-image-sha }}","options":"--user root --privileged --init"}'
target-platform: linux
Expand All @@ -337,7 +337,7 @@ jobs:
needs: checkout-windows
if: ${{ needs.setup.outputs.src == 'true' && !inputs.skip-windows }}
with:
build-runs-on: electron-arc-windows-amd64-16core
build-runs-on: ubuntu-latest
test-runs-on: windows-latest
target-platform: win
target-arch: x64
Expand All @@ -356,7 +356,7 @@ jobs:
needs: checkout-windows
if: ${{ needs.setup.outputs.src == 'true' && !inputs.skip-windows }}
with:
build-runs-on: electron-arc-windows-amd64-16core
build-runs-on: ubuntu-latest
test-runs-on: windows-latest
target-platform: win
target-arch: x86
Expand All @@ -375,8 +375,8 @@ jobs:
needs: checkout-windows
if: ${{ needs.setup.outputs.src == 'true' && !inputs.skip-windows }}
with:
build-runs-on: electron-arc-windows-amd64-16core
test-runs-on: electron-hosted-windows-arm64-4core
build-runs-on: ubuntu-latest
test-runs-on: ubuntu-latest
target-platform: win
target-arch: arm64
is-release: false
Expand Down
4 changes: 4 additions & 0 deletions chromium_src/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ static_library("chrome") {
"//chrome/browser/permissions/system/media_authorization_wrapper_mac.h",
"//chrome/browser/platform_util_mac.mm",
"//chrome/browser/process_singleton_mac.mm",
"//chrome/browser/renderer_host/chrome_render_widget_host_view_mac_history_swiper.h",
"//chrome/browser/renderer_host/chrome_render_widget_host_view_mac_history_swiper.mm",
"//chrome/browser/renderer_host/chrome_render_widget_host_view_mac_delegate.h",
"//chrome/browser/renderer_host/chrome_render_widget_host_view_mac_delegate.mm",
"//chrome/browser/ui/views/eye_dropper/eye_dropper_view_mac.h",
"//chrome/browser/ui/views/eye_dropper/eye_dropper_view_mac.mm",
]
Expand Down
1 change: 1 addition & 0 deletions docs/api/structures/web-preferences.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
Default is `false`.
* `scrollBounce` boolean (optional) _macOS_ - Enables scroll bounce
(rubber banding) effect on macOS. Default is `false`.
* `enableTwoFingerSwipe` boolean (optional) _macOS_ - Enables two-finger swipe navigation on macOS. Default is `false`.
* `enableBlinkFeatures` string (optional) - A list of feature strings separated by `,`, like
`CSSVariables,KeyboardEventKey` to enable. The full list of supported feature
strings can be found in the [RuntimeEnabledFeatures.json5][runtime-enabled-features]
Expand Down
84 changes: 84 additions & 0 deletions patches/chromium/enable_history_swiper_with_web_preferences.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
diff --git a/content/browser/renderer_host/render_widget_host_view_mac.h b/content/browser/renderer_host/render_widget_host_view_mac.h
index 1111111111111111111111111111111111111111..2222222222222222222222222222222222222222 100644
--- a/content/browser/renderer_host/render_widget_host_view_mac.h
+++ b/content/browser/renderer_host/render_widget_host_view_mac.h
@@ -50,6 +50,11 @@ class ScopedPasswordInputEnabler;
class WebCursor;
} // namespace content

+#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
+class HistorySwiper;
+namespace electron { class WebContentsPreferences; }
+#endif
+
@class RenderWidgetHostViewCocoa;

namespace content {
@@ -400,6 +405,12 @@ class CONTENT_EXPORT RenderWidgetHostViewMac
void SetActive(bool active) override;
void SpeakSelection() override;
void SetWindowFrameInScreen(const gfx::Rect& rect) override;
+
+#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
+ // Check if two-finger swipe navigation should be enabled via WebPreferences
+ bool ShouldEnableHistorySwiper() const;
+ std::unique_ptr<HistorySwiper> history_swiper_;
+#endif

private:
friend class RenderWidgetHostViewMacTest;
diff --git a/content/browser/renderer_host/render_widget_host_view_mac.mm b/content/browser/renderer_host/render_widget_host_view_mac.mm
index 1111111111111111111111111111111111111111..2222222222222222222222222222222222222222 100644
--- a/content/browser/renderer_host/render_widget_host_view_mac.mm
+++ b/content/browser/renderer_host/render_widget_host_view_mac.mm
@@ -90,6 +90,11 @@
#include "ui/base/cocoa/secure_password_input.h"
#include "ui/base/cocoa/text_services_context_menu.h"

+#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
+#include "chrome/browser/renderer_host/chrome_render_widget_host_view_mac_history_swiper.h"
+#include "shell/browser/web_contents_preferences.h"
+#endif
+
using blink::DragOperationsMask;
using blink::WebInputEvent;
using blink::WebMouseEvent;
@@ -1234,6 +1239,21 @@ void RenderWidgetHostViewMac::SetActive(bool active) {
if (host_->is_hidden())
return;

+#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
+ // Initialize history swiper if enabled via WebPreferences
+ if (ShouldEnableHistorySwiper() && !history_swiper_) {
+ history_swiper_ = std::make_unique<HistorySwiper>(
+ this, cocoa_view_,
+ base::BindRepeating(&RenderWidgetHostViewMac::NavigateToHistoryOffset,
+ base::Unretained(this)));
+ } else if (!ShouldEnableHistorySwiper() && history_swiper_) {
+ // Disable history swiper if preference is turned off
+ history_swiper_.reset();
+ }
+#endif
+
if (HasFocus())
host_->Focus();
else
@@ -1242,6 +1262,19 @@ void RenderWidgetHostViewMac::SetActive(bool active) {
host_->SetActive(active);
}

+#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
+bool RenderWidgetHostViewMac::ShouldEnableHistorySwiper() const {
+ if (auto* web_contents = content::WebContents::FromRenderViewHost(
+ host_->render_view_host())) {
+ if (auto* preferences = electron::WebContentsPreferences::From(web_contents)) {
+ return preferences->ShouldEnableTwoFingerSwipe();
+ }
+ }
+ return false;
+}
+#endif
+
void RenderWidgetHostViewMac::SpeakSelection() {
RenderWidgetHostView::SpeakSelection();
}
3 changes: 3 additions & 0 deletions shell/browser/native_window_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ class NativeWindowMac : public NativeWindow,
default_frame_for_zoom_ = frame;
}

// Check if two-finger swipe navigation is enabled via WebPreferences
bool ShouldEnableTwoFingerSwipe() const;

protected:
// views::WidgetDelegate:
views::View* GetContentsView() override;
Expand Down
25 changes: 25 additions & 0 deletions shell/browser/native_window_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
#include "shell/browser/ui/cocoa/root_view_mac.h"
#include "shell/browser/ui/cocoa/window_buttons_proxy.h"
#include "shell/browser/ui/drag_util.h"
#include "shell/browser/web_contents_preferences.h"
#include "shell/browser/window_list.h"
#include "content/public/browser/web_contents.h"
#include "shell/common/gin_converters/gfx_converter.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/node_util.h"
Expand Down Expand Up @@ -326,6 +328,29 @@ static bool FromV8(v8::Isolate* isolate,

NativeWindowMac::~NativeWindowMac() = default;

bool NativeWindowMac::ShouldEnableTwoFingerSwipe() const {
// Find the WebContents associated with this window through the NativeWindowRelay
// We need to iterate through all WebContents to find the one that has this window as owner
auto* browser_context = Browser::Get()->browser_context();
if (!browser_context)
return false;

// Get all WebContents and check which one has this window as owner
auto web_contents_list = content::WebContents::GetAllWebContents();
for (auto* web_contents : web_contents_list) {
auto* relay = NativeWindowRelay::FromWebContents(web_contents);
if (relay && relay->GetNativeWindow() == this) {
// Found the WebContents for this window, now check preferences
auto* web_preferences = WebContentsPreferences::From(web_contents);
if (web_preferences) {
return web_preferences->ShouldEnableTwoFingerSwipe();
}
}
}

return false; // Default to disabled if no preferences found
}

void NativeWindowMac::SetContentView(views::View* view) {
views::View* root_view = GetContentsView();
if (content_view())
Expand Down
39 changes: 31 additions & 8 deletions shell/browser/ui/cocoa/electron_ns_window.mm
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,37 @@ - (void)swiz_nsview_swipeWithEvent:(NSEvent*)event {
electron::NativeWindowMac* shell =
(electron::NativeWindowMac*)[(id)self.window shell];
if (shell) {
if (event.deltaY == 1.0) {
shell->NotifyWindowSwipe("up");
} else if (event.deltaX == -1.0) {
shell->NotifyWindowSwipe("right");
} else if (event.deltaY == -1.0) {
shell->NotifyWindowSwipe("down");
} else if (event.deltaX == 1.0) {
shell->NotifyWindowSwipe("left");
// Check if this is a two-finger or three-finger swipe
// Two-finger swipes have phase information, three-finger swipes have deltaX/deltaY = ±1.0
bool is_two_finger_swipe = (event.phase != NSEventPhaseNone || event.momentumPhase != NSEventPhaseNone) &&
(fabs(event.deltaX) != 1.0 && fabs(event.deltaY) != 1.0);
bool is_three_finger_swipe = (event.deltaY == 1.0 || event.deltaX == -1.0 ||
event.deltaY == -1.0 || event.deltaX == 1.0);

if (is_two_finger_swipe) {
// Check if two-finger swipe is enabled via WebPreferences
if (shell->ShouldEnableTwoFingerSwipe()) {
if (event.deltaY > 0.5) {
shell->NotifyWindowSwipe("up");
} else if (event.deltaX < -0.5) {
shell->NotifyWindowSwipe("right");
} else if (event.deltaY < -0.5) {
shell->NotifyWindowSwipe("down");
} else if (event.deltaX > 0.5) {
shell->NotifyWindowSwipe("left");
}
}
}else if (is_three_finger_swipe) {
// Existing three-finger swipe logic
if (event.deltaY == 1.0) {
shell->NotifyWindowSwipe("up");
} else if (event.deltaX == -1.0) {
shell->NotifyWindowSwipe("right");
} else if (event.deltaY == -1.0) {
shell->NotifyWindowSwipe("down");
} else if (event.deltaX == 1.0) {
shell->NotifyWindowSwipe("left");
}
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions shell/browser/web_contents_preferences.cc
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ void WebContentsPreferences::Clear() {

#if BUILDFLAG(IS_MAC)
scroll_bounce_ = false;
enable_two_finger_swipe_ = false;
#endif
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
spellcheck_ = true;
Expand Down Expand Up @@ -254,6 +255,7 @@ void WebContentsPreferences::SetFromDictionary(

#if BUILDFLAG(IS_MAC)
web_preferences.Get(options::kScrollBounce, &scroll_bounce_);
web_preferences.Get(options::kEnableTwoFingerSwipe, &enable_two_finger_swipe_);
#endif

#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
Expand Down Expand Up @@ -487,4 +489,11 @@ void WebContentsPreferences::OverrideWebkitPrefs(

WEB_CONTENTS_USER_DATA_KEY_IMPL(WebContentsPreferences);

#if BUILDFLAG(IS_MAC)
bool WebContentsPreferences::ShouldEnableTwoFingerSwipe() const {
return enable_two_finger_swipe_;
}
#endif


} // namespace electron
4 changes: 4 additions & 0 deletions shell/browser/web_contents_preferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ class WebContentsPreferences
bool ShouldDisableHtmlFullscreenWindowResize() const {
return disable_html_fullscreen_window_resize_;
}
#if BUILDFLAG(IS_MAC)
bool ShouldEnableTwoFingerSwipe() const { return enable_two_finger_swipe_; }
#endif
bool AllowsNodeIntegrationInSubFrames() const {
return node_integration_in_sub_frames_;
}
Expand Down Expand Up @@ -138,6 +141,7 @@ class WebContentsPreferences

#if BUILDFLAG(IS_MAC)
bool scroll_bounce_;
bool enable_two_finger_swipe_;
#endif
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
bool spellcheck_;
Expand Down
3 changes: 3 additions & 0 deletions shell/common/options_switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ inline constexpr std::string_view kEnableDeprecatedPaste =
// Whether the -electron-corner-smoothing CSS rule is enabled.
inline constexpr std::string_view kEnableCornerSmoothingCSS =
"enableCornerSmoothingCSS";

// Whether to enable two-finger swipe navigation.
inline constexpr std::string_view kEnableTwoFingerSwipe = "enableTwoFingerSwipe";
} // namespace options

// Following are actually command line switches, should be moved to other files.
Expand Down
Loading