electron/shell/browser/ui/cocoa/electron_ns_window.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

56 lines
1.7 KiB
C
Raw Normal View History

2018-04-19 16:53:12 +09:00
// Copyright (c) 2018 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef ELECTRON_SHELL_BROWSER_UI_COCOA_ELECTRON_NS_WINDOW_H_
#define ELECTRON_SHELL_BROWSER_UI_COCOA_ELECTRON_NS_WINDOW_H_
2018-04-19 16:53:12 +09:00
#include "base/memory/raw_ptr.h"
#include "components/remote_cocoa/app_shim/native_widget_mac_nswindow.h"
#include "shell/browser/ui/cocoa/event_dispatching_window.h"
#include "ui/views/widget/native_widget_mac.h"
2018-04-19 16:53:12 +09:00
namespace electron {
class NativeWindowMac;
// Prevents window from resizing during the scope.
class ScopedDisableResize {
public:
ScopedDisableResize() { disable_resize_++; }
~ScopedDisableResize() { disable_resize_--; }
2018-04-19 16:53:12 +09:00
// True if there are 1+ nested ScopedDisableResize objects in the scope
static bool IsResizeDisabled() { return disable_resize_ > 0; }
2018-04-19 16:53:12 +09:00
private:
static int disable_resize_;
2018-04-19 16:53:12 +09:00
};
} // namespace electron
refactor: remove InspectableWebContentsViewMac in favor of the Views version (#45238) * refactor: remove InspectableWebContentsViewMac in favor of the Views version * cherry-pick: refactor: remove InspectableWebContentsViewMac in favor of the Views version (#41326) commit e67ab9a93dadccecff30de50ab4555191c30b6c4 Confilcts not resolved, except removal of the files removed by the original commit. * resolved conflicts and build issues after cherry-pick * cherry-picked: fix: add method allowing to disable headless mode in native widget https://github.com/electron/electron/pull/42996 fixing https://github.com/electron/electron/issues/42995 * fix: displaying select popup in window created as fullscreen window `constrainFrameRect:toScreen:` is not being call for windows created with `fullscreen: true` therefore `headless` mode was not being removed and `RenderWidgetHostNSViewBridge::DisplayPopupMenu` ignored displaying popup. Issue could be fixed by placing additional removal of `headless` mode in the `toggleFullScreen:`, but `orderWindow:relativeTo:` is called both for a regular and a fullscreen window, therefore there will be a single place fixing both cases. Because `electron::NativeWindowMac` lifetime may be shorter than `ElectronNSWindow` on which macOS may execute `orderWindow:relativeTo:` we need to clear `shell_` when `NativeWindow` is being closed. Fixes #43010. * fix: Content visibility when using `vibrancy` We need to put `NSVisualEffectView` before `ViewsCompositorSuperview` otherwise when using `vibrancy` in `BrowserWindow` `NSVisualEffectView` will hide content displayed by the compositor. Fixes #43003 Fixes #42336 In fact main issues reported in these tickets were not present after cherry-picking original refactor switching to `views::WebView`, so text could be selected and click event was properly generated. However both issues testcases were using `vibrancy` and actual content was invisible, because it was covered by the `NSVisualEffectView`. * fix: EXCEPTION_ACCESS_VIOLATION crash on BrowserWindow.destroy() Restored postponed deletion of the `NativeWindow`. Restoration caused `DCHECK(new_parent_ui_layer->GetCompositor());` failure in `BrowserCompositorMac::SetParentUiLayer` after the spec test: `chrome extensions chrome.webRequest does not take precedence over Electron webRequest - http` with stack: ``` 7 Electron Framework 0x000000011fe07830 content::BrowserCompositorMac::SetParentUiLayer(ui::Layer*) + 628 8 Electron Framework 0x000000011fe0c154 content::RenderWidgetHostViewMac::SetParentUiLayer(ui::Layer*) + 220 9 Electron Framework 0x000000011fe226a8 content::WebContentsViewMac::CreateViewForWidget(content::RenderWidgetHost*) + 600 10 Electron Framework 0x000000011fd37e4c content::WebContentsImpl::CreateRenderWidgetHostViewForRenderManager(content::RenderViewHost*) + 164 11 Electron Framework 0x000000011fb32278 content::RenderFrameHostManager::CreateSpeculativeRenderFrame(content::SiteInstanceImpl*, bool, scoped_refptr<content::BrowsingContextState> const&) + 816 12 Electron Framework 0x000000011fb2ab8c content::RenderFrameHostManager::CreateSpeculativeRenderFrameHost(content::SiteInstanceImpl*, content::SiteInstanceImpl*, bool) + 1308 13 Electron Framework 0x000000011fb28598 content::RenderFrameHostManager::GetFrameHostForNavigation(content::NavigationRequest*, content::BrowsingContextGroupSwap*, std::__Cr::basic_string<char, std::__Cr::char_traits<char>, std::__Cr::allocator<char>>*) + 1796 14 Electron Framework 0x000000011fa78660 content::NavigationRequest::SelectFrameHostForOnRequestFailedInternal(bool, bool, std::__Cr::optional<std::__Cr::basic_string<char, std::__Cr::char_traits<char>, std::__Cr::allocator<char>>> const&) + 280 15 Electron Framework 0x000000011fa6a994 content::NavigationRequest::OnRequestFailedInternal(network::URLLoaderCompletionStatus const&, bool, std::__Cr::optional<std::__Cr::basic_string<char, std::__Cr::char_traits<char>, std::__Cr::allocator<char>>> const&, bo + 1008 16 Electron Framework 0x000000011fa7772c content::NavigationRequest::OnRequestFailed(network::URLLoaderCompletionStatus const&) + 72 17 Electron Framework 0x000000011f8554ac content::NavigationURLLoaderImpl::NotifyRequestFailed(network::URLLoaderCompletionStatus const&) + 248 ``` This was probably the reason of removing `NativeWindow` immediately in order to cleanup `views_host_` in `WebContentsViewMac` to prevent using layer without compositor in `WebContentsViewMac::CreateViewForWidget`. `[ElectronNSWindowDelegate windowWillClose:]` is deleting window host and the compositor used by the `NativeWindow` therefore detach `NativeWindow` contents from parent. This will clear `views_host_` and prevent failing mentioned `DCHECK`. Fixes #42975 * chore: Applied review suggestions Co-authored-by: Michał Pichliński <michal.pichlinski@here.io> * refactor: directly cleanup shell Co-authored-by: Samuel Maddock <smaddock@slack-corp.com> --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Michał Pichliński <michal.pichlinski@here.io> Co-authored-by: Samuel Maddock <smaddock@slack-corp.com>
2025-01-23 11:54:15 +01:00
class ElectronNativeWindowObserver;
2018-04-24 17:23:08 +09:00
@interface ElectronNSWindow : NativeWidgetMacNSWindow {
2018-04-19 16:53:12 +09:00
@private
raw_ptr<electron::NativeWindowMac> shell_;
2018-04-19 16:53:12 +09:00
}
@property BOOL acceptsFirstMouse;
@property BOOL enableLargerThanScreen;
@property BOOL disableAutoHideCursor;
@property BOOL disableKeyOrMainWindow;
@property(nonatomic, retain) NSVisualEffectView* vibrantView;
@property(nonatomic, retain) NSImage* cornerMask;
- (id)initWithShell:(electron::NativeWindowMac*)shell
styleMask:(NSUInteger)styleMask;
refactor: remove InspectableWebContentsViewMac in favor of the Views version (#45238) * refactor: remove InspectableWebContentsViewMac in favor of the Views version * cherry-pick: refactor: remove InspectableWebContentsViewMac in favor of the Views version (#41326) commit e67ab9a93dadccecff30de50ab4555191c30b6c4 Confilcts not resolved, except removal of the files removed by the original commit. * resolved conflicts and build issues after cherry-pick * cherry-picked: fix: add method allowing to disable headless mode in native widget https://github.com/electron/electron/pull/42996 fixing https://github.com/electron/electron/issues/42995 * fix: displaying select popup in window created as fullscreen window `constrainFrameRect:toScreen:` is not being call for windows created with `fullscreen: true` therefore `headless` mode was not being removed and `RenderWidgetHostNSViewBridge::DisplayPopupMenu` ignored displaying popup. Issue could be fixed by placing additional removal of `headless` mode in the `toggleFullScreen:`, but `orderWindow:relativeTo:` is called both for a regular and a fullscreen window, therefore there will be a single place fixing both cases. Because `electron::NativeWindowMac` lifetime may be shorter than `ElectronNSWindow` on which macOS may execute `orderWindow:relativeTo:` we need to clear `shell_` when `NativeWindow` is being closed. Fixes #43010. * fix: Content visibility when using `vibrancy` We need to put `NSVisualEffectView` before `ViewsCompositorSuperview` otherwise when using `vibrancy` in `BrowserWindow` `NSVisualEffectView` will hide content displayed by the compositor. Fixes #43003 Fixes #42336 In fact main issues reported in these tickets were not present after cherry-picking original refactor switching to `views::WebView`, so text could be selected and click event was properly generated. However both issues testcases were using `vibrancy` and actual content was invisible, because it was covered by the `NSVisualEffectView`. * fix: EXCEPTION_ACCESS_VIOLATION crash on BrowserWindow.destroy() Restored postponed deletion of the `NativeWindow`. Restoration caused `DCHECK(new_parent_ui_layer->GetCompositor());` failure in `BrowserCompositorMac::SetParentUiLayer` after the spec test: `chrome extensions chrome.webRequest does not take precedence over Electron webRequest - http` with stack: ``` 7 Electron Framework 0x000000011fe07830 content::BrowserCompositorMac::SetParentUiLayer(ui::Layer*) + 628 8 Electron Framework 0x000000011fe0c154 content::RenderWidgetHostViewMac::SetParentUiLayer(ui::Layer*) + 220 9 Electron Framework 0x000000011fe226a8 content::WebContentsViewMac::CreateViewForWidget(content::RenderWidgetHost*) + 600 10 Electron Framework 0x000000011fd37e4c content::WebContentsImpl::CreateRenderWidgetHostViewForRenderManager(content::RenderViewHost*) + 164 11 Electron Framework 0x000000011fb32278 content::RenderFrameHostManager::CreateSpeculativeRenderFrame(content::SiteInstanceImpl*, bool, scoped_refptr<content::BrowsingContextState> const&) + 816 12 Electron Framework 0x000000011fb2ab8c content::RenderFrameHostManager::CreateSpeculativeRenderFrameHost(content::SiteInstanceImpl*, content::SiteInstanceImpl*, bool) + 1308 13 Electron Framework 0x000000011fb28598 content::RenderFrameHostManager::GetFrameHostForNavigation(content::NavigationRequest*, content::BrowsingContextGroupSwap*, std::__Cr::basic_string<char, std::__Cr::char_traits<char>, std::__Cr::allocator<char>>*) + 1796 14 Electron Framework 0x000000011fa78660 content::NavigationRequest::SelectFrameHostForOnRequestFailedInternal(bool, bool, std::__Cr::optional<std::__Cr::basic_string<char, std::__Cr::char_traits<char>, std::__Cr::allocator<char>>> const&) + 280 15 Electron Framework 0x000000011fa6a994 content::NavigationRequest::OnRequestFailedInternal(network::URLLoaderCompletionStatus const&, bool, std::__Cr::optional<std::__Cr::basic_string<char, std::__Cr::char_traits<char>, std::__Cr::allocator<char>>> const&, bo + 1008 16 Electron Framework 0x000000011fa7772c content::NavigationRequest::OnRequestFailed(network::URLLoaderCompletionStatus const&) + 72 17 Electron Framework 0x000000011f8554ac content::NavigationURLLoaderImpl::NotifyRequestFailed(network::URLLoaderCompletionStatus const&) + 248 ``` This was probably the reason of removing `NativeWindow` immediately in order to cleanup `views_host_` in `WebContentsViewMac` to prevent using layer without compositor in `WebContentsViewMac::CreateViewForWidget`. `[ElectronNSWindowDelegate windowWillClose:]` is deleting window host and the compositor used by the `NativeWindow` therefore detach `NativeWindow` contents from parent. This will clear `views_host_` and prevent failing mentioned `DCHECK`. Fixes #42975 * chore: Applied review suggestions Co-authored-by: Michał Pichliński <michal.pichlinski@here.io> * refactor: directly cleanup shell Co-authored-by: Samuel Maddock <smaddock@slack-corp.com> --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Michał Pichliński <michal.pichlinski@here.io> Co-authored-by: Samuel Maddock <smaddock@slack-corp.com>
2025-01-23 11:54:15 +01:00
- (void)cleanup;
2018-05-02 20:43:45 +09:00
- (electron::NativeWindowMac*)shell;
- (id)accessibilityFocusedUIElement;
- (NSRect)originalContentRectForFrameRect:(NSRect)frameRect;
- (BOOL)toggleFullScreenMode:(id)sender;
- (NSImage*)_cornerMask;
fix: Update widget visibility in `NativeWindowMac::ShowInactive` (#45502) When using `views::WebView` on macOS `NativeWidgetMacNSWindowHost` contains a layer and compositor responsible for drawing web contents. To trigger drawing `NativeWidgetMacNSWindowHost::OnVisibilityChanged` needs to be called and `[NSWindow orderFrontRegardless]` does not trigger `[NSWindow orderWindow:relativeTo:]` which can change `NativeWidgetMacNSWindowHost` visiblity with stack: ``` views::NativeWidgetMacNSWindowHost::OnVisibilityChanged(bool) remote_cocoa::NativeWidgetNSWindowBridge::OnVisibilityChanged() -[ViewsNSWindowDelegate onWindowOrderChanged:] -[NativeWidgetMacNSWindow orderWindow:relativeTo:] ``` `views::Widget` has method for showing inactive window: `views::Widget::ShowInactive` which triggers `NativeWidgetMacNSWindowHost::OnVisibilityChanged` with stack: ``` views::NativeWidgetMacNSWindowHost::OnVisibilityChanged(bool) remote_cocoa::NativeWidgetNSWindowBridge::SetVisibilityState(remote_cocoa::mojom::WindowVisibilityState) views::NativeWidgetMacNSWindowHost::SetVisibilityState(remote_cocoa::mojom::WindowVisibilityState) views::NativeWidgetMac::Show(ui::mojom::WindowShowState, gfx::Rect const&) views::Widget::ShowInactive() + 168 ``` However this call seems to be insufficient to bring window to front, therefore `[NSWindow orderFrontRegardless]` still needs to be called. Calling `views::Widget::ShowInactive` ensures that all logic related to showing Chromium widget will be properly executed, but onfortunately it does not call `[NSWindow orderWindow:relativeTo:]` which is used to disabling headless mode by the `ElectronNSWindow`, therefore we need to trigger it manually through exposed `[ElectronNSWindow disableHeadlessMode]`. Fixes: #45415 Co-authored-by: Michał Pichliński <michal.pichlinski@here.io>
2025-02-06 18:40:59 -08:00
- (void)disableHeadlessMode;
2018-04-19 16:53:12 +09:00
@end
#endif // ELECTRON_SHELL_BROWSER_UI_COCOA_ELECTRON_NS_WINDOW_H_