
* chore: bump chromium in DEPS to 91.0.4435.3 * build: add 'use_rts' definition Refs:2694187
* chore: update patches * chore: media_internal_resources becomes resources Refs:2699022
* chore: update patches * refactor: extensions::ViewType moved to mojom Refs:2710351
* chore: might_have_observers has been removed Refs:2667839
* refactor: CertVerifier is not in the network namespace anymore Refs:2689805
* refactor: ExtensionUserScriptManager is now UserScriptManager Refs:2657617
* refactor: content::SiteInstance::GetSiteForURL was removed Refs:2680274
* refactor: MenuItemType was moved to mojom Refs:2071443
* refactor: extensions::ViewType was moved to mojom Refs:2710351
* refacotr: grit::ResourceMap replaced with webui::ResourcePath Refs:2685601
* refactor: blink::MenuItem::Type was moved to mojom Refs:2071443
* refactor: CreateDataPipe deprecated form was removed Refs:2698090
* refactor: DesktopMediaList::Type replaces content::DesktopMediaType_* Refs:2700637
* chore: wire up activation_time in OSR Refs:2638372
* chore: remove deleted file from chromium_src list * chore: fix lint * update patches * chore: bump chromium in DEPS to 91.0.4438.0 * chore: bump chromium in DEPS to 91.0.4439.0 * chore: bump chromium in DEPS to 91.0.4440.0 * chore: bump chromium in DEPS to 91.0.4441.0 * chore: bump chromium in DEPS to 91.0.4442.0 * chore: bump chromium in DEPS to 91.0.4443.0 * chore: bump chromium in DEPS to 91.0.4445.0 * chore: bump chromium in DEPS to 91.0.4446.0 * chore: update patches * fixup gn check * Merge branch 'master' into roller/chromium/master * update to xcode 12.4.0 Needed because of8008deb41c
* 2752406: [LSC] Replace base::string16 with std::u16string in //ui2752406
* 2752406: [LSC] Replace base::string16 with std::u16string in //ui2752406
* 2752932: Associate each AwProxyingURLLoaderFactory with a frame tree node id.2752932
* 2651385: Moving Profile::shared_cors_origin_access_list_ into //content layer.2651385
* 2734095: Introduce StoragePartitionId type to wrap current string representation.2734095
* chore: bump chromium in DEPS to 91.0.4448.0 * Update patches * 2743594: Remove WebSize from blink.2743594
* 2725403: Add URLLoaderClient::OnReceiveEarlyHints()2725403
* 2651385: Moving Profile::shared_cors_origin_access_list_ into //content layer.2651385
* 2721718: Move HostID to extensions::mojom::HostID2721718
* 2733070: Rename observer to URLLoaderNetworkServiceObserver2733070
* Use nogncheck for content/browser/site_instance_impl.h This is needed because //content/browser:browser is not a visible target * 2648046: Introduce alert notification helper .app2648046
* 2752406: [LSC] Replace base::string16 with std::u16string in //ui2752406
* only include mac notifications on mac * add additional skipping of atk toolchain check * 2757472: Reland "Reland "[LSC] Remove base::string16 alias""2757472
* 2757472: Reland "Reland "[LSC] Remove base::string16 alias""2757472
* 2720306: [api] Remove deprecated [Shared]ArrayBuffer API2720306
* Fixup 2721718: Move HostID to extensions::mojom::HostID * fixup 2651385: Moving Profile::shared_cors_origin_access_list_ into //content layer * Fixup 2752406: [LSC] Replace base::string16 with std::u16string in //ui * Fixup 2725403: Add URLLoaderClient::OnReceiveEarlyHints() * update node headers * chore: bump chromium in DEPS to 91.0.4449.0 * Revert "chore: bump chromium in DEPS to 91.0.4449.0" This reverts commitbccafa0289
. * 2693008: Fix loading non-system cursors on Windows on browser_tests2693008
* 2757472: Reland "Reland "[LSC] Remove base::string16 alias""2757472
* undo changes to WebContentsPreferences::GetPreloadPath to fix mac build * fix StrCat issue * incantations for WebContentsPreferences::GetPreloadPath wide strings * bump nan * fix GetAsString maybe? * windows build fixes * more windows build fix * SetAppUserModelID -> wstring * upgrade nan dep in tests * lint * wstrings are cross-platform * linter * only bind setAppUserModelId on windows * fix a messed up merge * well that was an odyssey * backport fcdf35e from v8 to fix nan crash * disable typedarrays-test.js * don't defer in NSWindow creation2707696
* use PartitionAllocator for ArrayBuffers in the main process * fix patches * chore: omit some unnecessary conversions * refactor: make LoginItemSettings::path a wstring * refactor: make ShowTaskDialog take a wstr * Revert "refactor: make LoginItemSettings::path a wstring" This reverts commit9127cff58b
. Co-authored-by: Samuel Attard <samuel.r.attard@gmail.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: John Kleinschmidt <jkleinsc@github.com> Co-authored-by: Jeremy Rose <nornagon@nornagon.net> Co-authored-by: Jeremy Rose <jeremya@chromium.org> Co-authored-by: Charles Kerr <charles@charleskerr.com>
243 lines
7.2 KiB
Text
243 lines
7.2 KiB
Text
// Copyright (c) 2018 GitHub, Inc.
|
|
// Use of this source code is governed by the MIT license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "shell/browser/ui/cocoa/electron_ns_window.h"
|
|
|
|
#include "base/strings/sys_string_conversions.h"
|
|
#include "shell/browser/native_window_mac.h"
|
|
#include "shell/browser/ui/cocoa/electron_preview_item.h"
|
|
#include "shell/browser/ui/cocoa/electron_touch_bar.h"
|
|
#include "shell/browser/ui/cocoa/root_view_mac.h"
|
|
#include "ui/base/cocoa/window_size_constants.h"
|
|
|
|
namespace electron {
|
|
|
|
bool ScopedDisableResize::disable_resize_ = false;
|
|
|
|
} // namespace electron
|
|
|
|
@interface NSWindow (PrivateAPI)
|
|
- (NSImage*)_cornerMask;
|
|
@end
|
|
|
|
@implementation ElectronNSWindow
|
|
|
|
@synthesize acceptsFirstMouse;
|
|
@synthesize enableLargerThanScreen;
|
|
@synthesize disableAutoHideCursor;
|
|
@synthesize disableKeyOrMainWindow;
|
|
@synthesize vibrantView;
|
|
@synthesize cornerMask;
|
|
|
|
- (id)initWithShell:(electron::NativeWindowMac*)shell
|
|
styleMask:(NSUInteger)styleMask {
|
|
if ((self = [super initWithContentRect:ui::kWindowSizeDeterminedLater
|
|
styleMask:styleMask
|
|
backing:NSBackingStoreBuffered
|
|
defer:NO])) {
|
|
shell_ = shell;
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (electron::NativeWindowMac*)shell {
|
|
return shell_;
|
|
}
|
|
|
|
- (id)accessibilityFocusedUIElement {
|
|
views::Widget* widget = shell_->widget();
|
|
id superFocus = [super accessibilityFocusedUIElement];
|
|
if (!widget || shell_->IsFocused())
|
|
return superFocus;
|
|
return nil;
|
|
}
|
|
- (NSRect)originalContentRectForFrameRect:(NSRect)frameRect {
|
|
return [super contentRectForFrameRect:frameRect];
|
|
}
|
|
|
|
- (NSTouchBar*)makeTouchBar API_AVAILABLE(macosx(10.12.2)) {
|
|
if (shell_->touch_bar())
|
|
return [shell_->touch_bar() makeTouchBar];
|
|
else
|
|
return nil;
|
|
}
|
|
|
|
// NSWindow overrides.
|
|
|
|
- (void)swipeWithEvent:(NSEvent*)event {
|
|
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");
|
|
}
|
|
}
|
|
|
|
- (void)rotateWithEvent:(NSEvent*)event {
|
|
shell_->NotifyWindowRotateGesture(event.rotation);
|
|
}
|
|
|
|
- (NSRect)contentRectForFrameRect:(NSRect)frameRect {
|
|
if (shell_->has_frame())
|
|
return [super contentRectForFrameRect:frameRect];
|
|
else
|
|
return frameRect;
|
|
}
|
|
|
|
- (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen*)screen {
|
|
// Resizing is disabled.
|
|
if (electron::ScopedDisableResize::IsResizeDisabled())
|
|
return [self frame];
|
|
|
|
NSRect result = [super constrainFrameRect:frameRect toScreen:screen];
|
|
// Enable the window to be larger than screen.
|
|
if ([self enableLargerThanScreen]) {
|
|
// If we have a frame, ensure that we only position the window
|
|
// somewhere where the user can move or resize it (and not
|
|
// behind the menu bar, for instance)
|
|
//
|
|
// If there's no frame, put the window wherever the developer
|
|
// wanted it to go
|
|
if (shell_->has_frame()) {
|
|
result.size = frameRect.size;
|
|
} else {
|
|
result = frameRect;
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
- (void)setFrame:(NSRect)windowFrame display:(BOOL)displayViews {
|
|
// constrainFrameRect is not called on hidden windows so disable adjusting
|
|
// the frame directly when resize is disabled
|
|
if (!electron::ScopedDisableResize::IsResizeDisabled())
|
|
[super setFrame:windowFrame display:displayViews];
|
|
}
|
|
|
|
- (id)accessibilityAttributeValue:(NSString*)attribute {
|
|
if ([attribute isEqual:NSAccessibilityEnabledAttribute])
|
|
return [NSNumber numberWithBool:YES];
|
|
if (![attribute isEqualToString:@"AXChildren"])
|
|
return [super accessibilityAttributeValue:attribute];
|
|
|
|
// We want to remove the window title (also known as
|
|
// NSAccessibilityReparentingCellProxy), which VoiceOver already sees.
|
|
// * when VoiceOver is disabled, this causes Cmd+C to be used for TTS but
|
|
// still leaves the buttons available in the accessibility tree.
|
|
// * when VoiceOver is enabled, the full accessibility tree is used.
|
|
// Without removing the title and with VO disabled, the TTS would always read
|
|
// the window title instead of using Cmd+C to get the selected text.
|
|
NSPredicate* predicate =
|
|
[NSPredicate predicateWithFormat:@"(self.className != %@)",
|
|
@"NSAccessibilityReparentingCellProxy"];
|
|
|
|
NSArray* children = [super accessibilityAttributeValue:attribute];
|
|
NSMutableArray* mutableChildren = [[children mutableCopy] autorelease];
|
|
[mutableChildren filterUsingPredicate:predicate];
|
|
|
|
return mutableChildren;
|
|
}
|
|
|
|
- (NSString*)accessibilityTitle {
|
|
return base::SysUTF8ToNSString(shell_->GetTitle());
|
|
}
|
|
|
|
- (BOOL)canBecomeMainWindow {
|
|
return !self.disableKeyOrMainWindow;
|
|
}
|
|
|
|
- (BOOL)canBecomeKeyWindow {
|
|
return !self.disableKeyOrMainWindow;
|
|
}
|
|
|
|
- (NSView*)frameView {
|
|
return [[self contentView] superview];
|
|
}
|
|
|
|
// By overriding this built-in method the corners of the vibrant view (if set)
|
|
// will be smooth.
|
|
- (NSImage*)_cornerMask {
|
|
if (self.vibrantView != nil) {
|
|
return [self cornerMask];
|
|
} else {
|
|
return [super _cornerMask];
|
|
}
|
|
}
|
|
|
|
// Quicklook methods
|
|
|
|
- (BOOL)acceptsPreviewPanelControl:(QLPreviewPanel*)panel {
|
|
return YES;
|
|
}
|
|
|
|
- (void)beginPreviewPanelControl:(QLPreviewPanel*)panel {
|
|
panel.delegate = [self delegate];
|
|
panel.dataSource = static_cast<id<QLPreviewPanelDataSource>>([self delegate]);
|
|
}
|
|
|
|
- (void)endPreviewPanelControl:(QLPreviewPanel*)panel {
|
|
panel.delegate = nil;
|
|
panel.dataSource = nil;
|
|
}
|
|
|
|
// Custom window button methods
|
|
|
|
- (BOOL)windowShouldClose:(id)sender {
|
|
return YES;
|
|
}
|
|
|
|
- (void)performClose:(id)sender {
|
|
if (shell_->title_bar_style() ==
|
|
electron::NativeWindowMac::TitleBarStyle::kCustomButtonsOnHover) {
|
|
[[self delegate] windowShouldClose:self];
|
|
} else if (shell_->IsSimpleFullScreen()) {
|
|
if ([[self delegate] respondsToSelector:@selector(windowShouldClose:)]) {
|
|
if (![[self delegate] windowShouldClose:self])
|
|
return;
|
|
} else if ([self respondsToSelector:@selector(windowShouldClose:)]) {
|
|
if (![self windowShouldClose:self])
|
|
return;
|
|
}
|
|
[self close];
|
|
} else if (shell_->is_modal() && shell_->parent() && shell_->IsVisible()) {
|
|
// We don't want to actually call [window close] here since
|
|
// we've already called endSheet on the modal sheet.
|
|
return;
|
|
} else {
|
|
[super performClose:sender];
|
|
}
|
|
}
|
|
|
|
- (void)toggleFullScreenMode:(id)sender {
|
|
bool is_simple_fs = shell_->IsSimpleFullScreen();
|
|
bool always_simple_fs = shell_->always_simple_fullscreen();
|
|
|
|
// If we're in simple fullscreen mode and trying to exit it
|
|
// we need to ensure we exit it properly to prevent a crash
|
|
// with NSWindowStyleMaskTitled mode.
|
|
if (is_simple_fs || always_simple_fs) {
|
|
shell_->SetSimpleFullScreen(!is_simple_fs);
|
|
} else {
|
|
bool maximizable = shell_->IsMaximizable();
|
|
[super toggleFullScreen:sender];
|
|
|
|
// Exiting fullscreen causes Cocoa to redraw the NSWindow, which resets
|
|
// the enabled state for NSWindowZoomButton. We need to persist it.
|
|
shell_->SetMaximizable(maximizable);
|
|
}
|
|
}
|
|
|
|
- (void)performMiniaturize:(id)sender {
|
|
if (shell_->title_bar_style() ==
|
|
electron::NativeWindowMac::TitleBarStyle::kCustomButtonsOnHover)
|
|
[self miniaturize:self];
|
|
else
|
|
[super performMiniaturize:sender];
|
|
}
|
|
|
|
@end
|