Skip to content

Commit

Permalink
Bug 1884631 - Remove macOS native sheet support. r=mac-reviewers,alec…
Browse files Browse the repository at this point in the history
…a,kaie,bradwerth

Firefox never uses this. TB could use the same approach Firefox uses,
but for now on macOS the sheets become regular modal dialogs, which is
the same as on Windows and Linux.

See bug 1755330 and bug 1737489 for more context.

Differential Revision: https://phabricator.services.mozilla.com/D204209
  • Loading branch information
emilio committed Mar 18, 2024
1 parent 78c4019 commit 6bfd255
Show file tree
Hide file tree
Showing 12 changed files with 202 additions and 584 deletions.
3 changes: 1 addition & 2 deletions layout/base/PresShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11708,8 +11708,7 @@ static bool IsTopLevelWidget(nsIWidget* aWidget) {

auto windowType = aWidget->GetWindowType();
return windowType == WindowType::TopLevel ||
windowType == WindowType::Dialog || windowType == WindowType::Popup ||
windowType == WindowType::Sheet;
windowType == WindowType::Dialog || windowType == WindowType::Popup;
}

PresShell::WindowSizeConstraints PresShell::GetWindowSizeConstraints() {
Expand Down
1 change: 0 additions & 1 deletion widget/InitData.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ enum class WindowType : uint8_t {
TopLevel, // default top level window
Dialog, // top level window but usually handled differently
// by the OS
Sheet, // MacOSX sheet (special dialog class)
Popup, // used for combo boxes, etc
Child, // child windows (contained inside a window on the
// desktop (has no border))
Expand Down
6 changes: 0 additions & 6 deletions widget/cocoa/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ with Files("**"):
with Files("*TextInput*"):
BUG_COMPONENT = ("Core", "DOM: UI Events & Focus Handling")

XPIDL_SOURCES += [
"nsPIWidgetCocoa.idl",
]

XPIDL_MODULE = "widget_cocoa"

EXPORTS += [
"DesktopBackgroundImage.h",
"MediaHardwareKeysEventSourceMac.h",
Expand Down
28 changes: 9 additions & 19 deletions widget/cocoa/nsChildView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1730,19 +1730,21 @@ static LayoutDeviceIntRect FindFirstRectOfType(

void nsChildView::UpdateThemeGeometries(
const nsTArray<ThemeGeometry>& aThemeGeometries) {
if (![mView window]) return;
if (!mView.window) {
return;
}

UpdateVibrancy(aThemeGeometries);

if (![[mView window] isKindOfClass:[ToolbarWindow class]]) return;
if (![mView.window isKindOfClass:[ToolbarWindow class]]) {
return;
}

// Update unified toolbar height and sheet attachment position.
int32_t windowWidth = mBounds.width;
int32_t titlebarBottom = FindTitlebarBottom(aThemeGeometries, windowWidth);
int32_t unifiedToolbarBottom =
FindUnifiedToolbarBottom(aThemeGeometries, windowWidth, titlebarBottom);
int32_t toolboxBottom =
FindFirstRectOfType(aThemeGeometries, eThemeGeometryTypeToolbox).YMost();

ToolbarWindow* win = (ToolbarWindow*)[mView window];
int32_t titlebarHeight = [win drawsContentsIntoWindowFrame]
Expand All @@ -1751,12 +1753,6 @@ static LayoutDeviceIntRect FindFirstRectOfType(
int32_t devUnifiedHeight = titlebarHeight + unifiedToolbarBottom;
[win setUnifiedToolbarHeight:DevPixelsToCocoaPoints(devUnifiedHeight)];

int32_t sheetPositionDevPx = std::max(toolboxBottom, unifiedToolbarBottom);
NSPoint sheetPositionView = {0, DevPixelsToCocoaPoints(sheetPositionDevPx)};
NSPoint sheetPositionWindow = [mView convertPoint:sheetPositionView
toView:nil];
[win setSheetAttachmentPosition:sheetPositionWindow.y];

// Update titlebar control offsets.
LayoutDeviceIntRect windowButtonRect =
FindFirstRectOfType(aThemeGeometries, eThemeGeometryTypeWindowButtons);
Expand Down Expand Up @@ -5129,18 +5125,12 @@ - (BOOL)wantsBestResolutionOpenGLSurface {

case WindowType::TopLevel:
case WindowType::Dialog:
if ([aWindow attachedSheet]) return NO;
if (aWindow.attachedSheet) {
return NO;
}

topLevelWindow = aWindow;
break;
case WindowType::Sheet: {
nsIWidget* parentWidget = windowWidget->GetSheetWindowParent();
if (!parentWidget) return YES;

topLevelWindow = (NSWindow*)parentWidget->GetNativeData(NS_NATIVE_WINDOW);
break;
}

default:
return YES;
}
Expand Down
192 changes: 89 additions & 103 deletions widget/cocoa/nsCocoaWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

#include "mozilla/RefPtr.h"
#include "nsBaseWidget.h"
#include "nsPIWidgetCocoa.h"
#include "nsCocoaUtils.h"
#include "nsTouchBar.h"
#include <dlfcn.h>
Expand Down Expand Up @@ -189,7 +188,6 @@ typedef struct _nsCocoaWindowList {
FullscreenTitlebarTracker* mFullscreenTitlebarTracker;

CGFloat mUnifiedToolbarHeight;
CGFloat mSheetAttachmentPosition;
CGFloat mMenuBarHeight;
/* Store the height of the titlebar when this window is initialized. The
titlebarHeight getter returns 0 when in fullscreen, which is not useful in
Expand All @@ -203,68 +201,61 @@ typedef struct _nsCocoaWindowList {
- (NSRect)titlebarRect;
- (void)setTitlebarNeedsDisplay;
- (void)setDrawsContentsIntoWindowFrame:(BOOL)aState;
- (void)setSheetAttachmentPosition:(CGFloat)aY;
- (CGFloat)sheetAttachmentPosition;
- (void)placeWindowButtons:(NSRect)aRect;
- (NSRect)windowButtonsRect;
- (void)windowMainStateChanged;
@end

class nsCocoaWindow final : public nsBaseWidget, public nsPIWidgetCocoa {
class nsCocoaWindow final : public nsBaseWidget {
private:
typedef nsBaseWidget Inherited;

public:
nsCocoaWindow();

NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSPIWIDGETCOCOA; // semicolon for clang-format bug 1629756

[[nodiscard]] virtual nsresult Create(nsIWidget* aParent,
nsNativeWidget aNativeParent,
const DesktopIntRect& aRect,
InitData* = nullptr) override;

[[nodiscard]] virtual nsresult Create(nsIWidget* aParent,
nsNativeWidget aNativeParent,
const LayoutDeviceIntRect& aRect,
InitData* = nullptr) override;

virtual void Destroy() override;

virtual void Show(bool aState) override;
virtual bool NeedsRecreateToReshow() override;

virtual nsIWidget* GetSheetWindowParent(void) override;
virtual void Enable(bool aState) override;
virtual bool IsEnabled() const override;
virtual void SetModal(bool aState) override;
virtual void SetFakeModal(bool aState) override;
virtual bool IsRunningAppModal() override;
virtual bool IsVisible() const override;
virtual void SetFocus(Raise, mozilla::dom::CallerType aCallerType) override;
virtual LayoutDeviceIntPoint WidgetToScreenOffset() override;
virtual LayoutDeviceIntPoint GetClientOffset() override;
virtual LayoutDeviceIntMargin ClientToWindowMargin() override;

virtual void* GetNativeData(uint32_t aDataType) override;

virtual void ConstrainPosition(DesktopIntPoint&) override;
virtual void SetSizeConstraints(const SizeConstraints& aConstraints) override;
virtual void Move(double aX, double aY) override;
virtual nsSizeMode SizeMode() override { return mSizeMode; }
virtual void SetSizeMode(nsSizeMode aMode) override;
virtual void GetWorkspaceID(nsAString& workspaceID) override;
virtual void MoveToWorkspace(const nsAString& workspaceID) override;
virtual void SuppressAnimation(bool aSuppress) override;
virtual void HideWindowChrome(bool aShouldHide) override;

virtual bool PrepareForFullscreenTransition(nsISupports** aData) override;
virtual void PerformFullscreenTransition(FullscreenTransitionStage aStage,
uint16_t aDuration,
nsISupports* aData,
nsIRunnable* aCallback) override;
virtual void CleanupFullscreenTransition() override;
[[nodiscard]] nsresult Create(nsIWidget* aParent,
nsNativeWidget aNativeParent,
const DesktopIntRect& aRect,
InitData* = nullptr) override;

[[nodiscard]] nsresult Create(nsIWidget* aParent,
nsNativeWidget aNativeParent,
const LayoutDeviceIntRect& aRect,
InitData* = nullptr) override;

void Destroy() override;

void Show(bool aState) override;
bool NeedsRecreateToReshow() override;

void Enable(bool aState) override;
bool IsEnabled() const override;
void SetModal(bool aState) override;
void SetFakeModal(bool aState) override;
bool IsRunningAppModal() override;
bool IsVisible() const override;
void SetFocus(Raise, mozilla::dom::CallerType aCallerType) override;
LayoutDeviceIntPoint WidgetToScreenOffset() override;
LayoutDeviceIntPoint GetClientOffset() override;
LayoutDeviceIntMargin ClientToWindowMargin() override;

void* GetNativeData(uint32_t aDataType) override;

void ConstrainPosition(DesktopIntPoint&) override;
void SetSizeConstraints(const SizeConstraints& aConstraints) override;
void Move(double aX, double aY) override;
nsSizeMode SizeMode() override { return mSizeMode; }
void SetSizeMode(nsSizeMode aMode) override;
void GetWorkspaceID(nsAString& workspaceID) override;
void MoveToWorkspace(const nsAString& workspaceID) override;
void SuppressAnimation(bool aSuppress) override;
void HideWindowChrome(bool aShouldHide) override;

bool PrepareForFullscreenTransition(nsISupports** aData) override;
void PerformFullscreenTransition(FullscreenTransitionStage aStage,
uint16_t aDuration, nsISupports* aData,
nsIRunnable* aCallback) override;
void CleanupFullscreenTransition() override;
nsresult MakeFullScreen(bool aFullScreen) final;
nsresult MakeFullScreenWithNativeTransition(bool aFullScreen) final;
NSAnimation* FullscreenTransitionAnimation() const {
Expand All @@ -277,79 +268,77 @@ class nsCocoaWindow final : public nsBaseWidget, public nsPIWidgetCocoa {
mFullscreenTransitionAnimation = nil;
}

virtual void Resize(double aWidth, double aHeight, bool aRepaint) override;
virtual void Resize(double aX, double aY, double aWidth, double aHeight,
bool aRepaint) override;
void Resize(double aWidth, double aHeight, bool aRepaint) override;
void Resize(double aX, double aY, double aWidth, double aHeight,
bool aRepaint) override;
NSRect GetClientCocoaRect();
virtual LayoutDeviceIntRect GetClientBounds() override;
virtual LayoutDeviceIntRect GetScreenBounds() override;
LayoutDeviceIntRect GetClientBounds() override;
LayoutDeviceIntRect GetScreenBounds() override;
void ReportMoveEvent();
void ReportSizeEvent();
virtual void SetCursor(const Cursor&) override;
void SetCursor(const Cursor&) override;

CGFloat BackingScaleFactor();
void BackingScaleFactorChanged();
virtual double GetDefaultScaleInternal() override;
virtual int32_t RoundsWidgetCoordinatesTo() override;
double GetDefaultScaleInternal() override;
int32_t RoundsWidgetCoordinatesTo() override;

mozilla::DesktopToLayoutDeviceScale GetDesktopToDeviceScale() final {
return mozilla::DesktopToLayoutDeviceScale(BackingScaleFactor());
}

virtual nsresult SetTitle(const nsAString& aTitle) override;

virtual void Invalidate(const LayoutDeviceIntRect& aRect) override;
virtual WindowRenderer* GetWindowRenderer() override;
virtual nsresult DispatchEvent(mozilla::WidgetGUIEvent* aEvent,
nsEventStatus& aStatus) override;
virtual void CaptureRollupEvents(bool aDoCapture) override;
[[nodiscard]] virtual nsresult GetAttention(int32_t aCycleCount) override;
virtual bool HasPendingInputEvent() override;
virtual TransparencyMode GetTransparencyMode() override;
virtual void SetTransparencyMode(TransparencyMode aMode) override;
virtual void SetWindowShadowStyle(mozilla::WindowShadow aStyle) override;
virtual void SetWindowOpacity(float aOpacity) override;
virtual void SetWindowTransform(
const mozilla::gfx::Matrix& aTransform) override;
virtual void SetInputRegion(const InputRegion&) override;
virtual void SetColorScheme(
const mozilla::Maybe<mozilla::ColorScheme>&) override;
virtual void SetShowsToolbarButton(bool aShow) override;
virtual void SetSupportsNativeFullscreen(bool aShow) override;
virtual void SetWindowAnimationType(WindowAnimationType aType) override;
virtual void SetDrawsTitle(bool aDrawTitle) override;
virtual nsresult SetNonClientMargins(const LayoutDeviceIntMargin&) override;
nsresult SetTitle(const nsAString& aTitle) override;

void Invalidate(const LayoutDeviceIntRect& aRect) override;
WindowRenderer* GetWindowRenderer() override;
nsresult DispatchEvent(mozilla::WidgetGUIEvent* aEvent,
nsEventStatus& aStatus) override;
void CaptureRollupEvents(bool aDoCapture) override;
[[nodiscard]] nsresult GetAttention(int32_t aCycleCount) override;
bool HasPendingInputEvent() override;
TransparencyMode GetTransparencyMode() override;
void SetTransparencyMode(TransparencyMode aMode) override;
void SetWindowShadowStyle(mozilla::WindowShadow aStyle) override;
void SetWindowOpacity(float aOpacity) override;
void SetWindowTransform(const mozilla::gfx::Matrix& aTransform) override;
void SetInputRegion(const InputRegion&) override;
void SetColorScheme(const mozilla::Maybe<mozilla::ColorScheme>&) override;
void SetShowsToolbarButton(bool aShow) override;
void SetSupportsNativeFullscreen(bool aShow) override;
void SetWindowAnimationType(WindowAnimationType aType) override;
void SetDrawsTitle(bool aDrawTitle) override;
nsresult SetNonClientMargins(const LayoutDeviceIntMargin&) override;
void SetDrawsInTitlebar(bool aState);
virtual void UpdateThemeGeometries(
void UpdateThemeGeometries(
const nsTArray<ThemeGeometry>& aThemeGeometries) override;
virtual nsresult SynthesizeNativeMouseEvent(
LayoutDeviceIntPoint aPoint, NativeMouseMessage aNativeMessage,
mozilla::MouseButton aButton, nsIWidget::Modifiers aModifierFlags,
nsIObserver* aObserver) override;
virtual nsresult SynthesizeNativeMouseScrollEvent(
nsresult SynthesizeNativeMouseEvent(LayoutDeviceIntPoint aPoint,
NativeMouseMessage aNativeMessage,
mozilla::MouseButton aButton,
nsIWidget::Modifiers aModifierFlags,
nsIObserver* aObserver) override;
nsresult SynthesizeNativeMouseScrollEvent(
LayoutDeviceIntPoint aPoint, uint32_t aNativeMessage, double aDeltaX,
double aDeltaY, double aDeltaZ, uint32_t aModifierFlags,
uint32_t aAdditionalFlags, nsIObserver* aObserver) override;
virtual void LockAspectRatio(bool aShouldLock) override;
void LockAspectRatio(bool aShouldLock) override;

void DispatchSizeModeEvent();
void DispatchOcclusionEvent();

// be notified that a some form of drag event needs to go into Gecko
virtual bool DragEvent(unsigned int aMessage,
mozilla::gfx::Point aMouseGlobal,
UInt16 aKeyModifiers);
bool DragEvent(unsigned int aMessage, mozilla::gfx::Point aMouseGlobal,
UInt16 aKeyModifiers);

bool HasModalDescendents() { return mNumModalDescendents > 0; }
NSWindow* GetCocoaWindow() { return mWindow; }

void SetMenuBar(RefPtr<nsMenuBarX>&& aMenuBar);
nsMenuBarX* GetMenuBar();

virtual void SetInputContext(const InputContext& aContext,
const InputContextAction& aAction) override;
virtual InputContext GetInputContext() override { return mInputContext; }
MOZ_CAN_RUN_SCRIPT virtual bool GetEditCommands(
void SetInputContext(const InputContext& aContext,
const InputContextAction& aAction) override;
InputContext GetInputContext() override { return mInputContext; }
MOZ_CAN_RUN_SCRIPT bool GetEditCommands(
mozilla::NativeKeyBindingsType aType,
const mozilla::WidgetKeyboardEvent& aEvent,
nsTArray<mozilla::CommandInt>& aCommands) override;
Expand Down Expand Up @@ -400,14 +389,15 @@ class nsCocoaWindow final : public nsBaseWidget, public nsPIWidgetCocoa {
void DestroyNativeWindow();
void UpdateBounds();
int32_t GetWorkspaceID();
void SendSetZLevelEvent();

void DoResize(double aX, double aY, double aWidth, double aHeight,
bool aRepaint, bool aConstrainToCurrentScreen);

void UpdateFullscreenState(bool aFullScreen, bool aNativeMode);
nsresult DoMakeFullScreen(bool aFullScreen, bool aUseSystemTransition);

virtual already_AddRefed<nsIWidget> AllocateChildPopupWidget() override {
already_AddRefed<nsIWidget> AllocateChildPopupWidget() override {
return nsIWidget::CreateTopLevelWindow();
}

Expand All @@ -417,8 +407,6 @@ class nsCocoaWindow final : public nsBaseWidget, public nsPIWidgetCocoa {
WindowDelegate*
mDelegate; // our delegate for processing window msgs [STRONG]
RefPtr<nsMenuBarX> mMenuBar;
NSWindow* mSheetWindowParent; // if this is a sheet, this is the NSWindow
// it's attached to
nsChildView*
mPopupContentView; // if this is a popup, this is its content widget
// if this is a toplevel window, and there is any ongoing fullscreen
Expand All @@ -432,8 +420,6 @@ class nsCocoaWindow final : public nsBaseWidget, public nsPIWidgetCocoa {
WindowAnimationType mAnimationType;

bool mWindowMadeHere; // true if we created the window, false for embedding
bool mSheetNeedsShow; // if this is a sheet, are we waiting to be shown?
// this is used for sibling sheet contention only
nsSizeMode mSizeMode;
bool mInFullScreenMode;
// Whether we are currently using native fullscreen. It could be false because
Expand Down
Loading

0 comments on commit 6bfd255

Please sign in to comment.