summaryrefslogtreecommitdiffstats
path: root/widget/cocoa/nsChildView.mm
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:35:49 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:35:49 +0000
commitd8bbc7858622b6d9c278469aab701ca0b609cddf (patch)
treeeff41dc61d9f714852212739e6b3738b82a2af87 /widget/cocoa/nsChildView.mm
parentReleasing progress-linux version 125.0.3-1~progress7.99u1. (diff)
downloadfirefox-d8bbc7858622b6d9c278469aab701ca0b609cddf.tar.xz
firefox-d8bbc7858622b6d9c278469aab701ca0b609cddf.zip
Merging upstream version 126.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'widget/cocoa/nsChildView.mm')
-rw-r--r--widget/cocoa/nsChildView.mm162
1 files changed, 42 insertions, 120 deletions
diff --git a/widget/cocoa/nsChildView.mm b/widget/cocoa/nsChildView.mm
index 79919ba69a..d3241a983f 100644
--- a/widget/cocoa/nsChildView.mm
+++ b/widget/cocoa/nsChildView.mm
@@ -473,17 +473,20 @@ void* nsChildView::GetNativeData(uint32_t aDataType) {
#pragma mark -
void nsChildView::SuppressAnimation(bool aSuppress) {
- GetAppWindowWidget()->SuppressAnimation(aSuppress);
+ if (nsCocoaWindow* widget = GetAppWindowWidget()) {
+ widget->SuppressAnimation(aSuppress);
+ }
}
bool nsChildView::IsVisible() const {
NS_OBJC_BEGIN_TRY_BLOCK_RETURN;
if (!mVisible) {
- return mVisible;
+ return false;
}
- if (!GetAppWindowWidget()->IsVisible()) {
+ nsCocoaWindow* widget = GetAppWindowWidget();
+ if (NS_WARN_IF(!widget) || !widget->IsVisible()) {
return false;
}
@@ -739,11 +742,11 @@ void nsChildView::Resize(double aWidth, double aHeight, bool aRepaint) {
mBounds.height = height;
ManipulateViewWithoutNeedingDisplay(mView, ^{
- [mView setFrame:DevPixelsToCocoaPoints(mBounds)];
+ mView.frame = DevPixelsToCocoaPoints(mBounds);
});
if (mVisible && aRepaint) {
- [[mView pixelHostingView] setNeedsDisplay:YES];
+ mView.pixelHostingView.needsDisplay = YES;
}
ReportSizeEvent();
@@ -779,11 +782,11 @@ void nsChildView::Resize(double aX, double aY, double aWidth, double aHeight,
}
ManipulateViewWithoutNeedingDisplay(mView, ^{
- [mView setFrame:DevPixelsToCocoaPoints(mBounds)];
+ mView.frame = DevPixelsToCocoaPoints(mBounds);
});
if (mVisible && aRepaint) {
- [[mView pixelHostingView] setNeedsDisplay:YES];
+ mView.pixelHostingView.needsDisplay = YES;
}
if (isMoving) {
@@ -1070,10 +1073,8 @@ nsresult nsChildView::SynthesizeNativeTouchpadDoubleTap(
bool nsChildView::SendEventToNativeMenuSystem(NSEvent* aEvent) {
bool handled = false;
- nsCocoaWindow* widget = GetAppWindowWidget();
- if (widget) {
- nsMenuBarX* mb = widget->GetMenuBar();
- if (mb) {
+ if (nsCocoaWindow* widget = GetAppWindowWidget()) {
+ if (nsMenuBarX* mb = widget->GetMenuBar()) {
// Check if main menu wants to handle the event.
handled = mb->PerformKeyEquivalent(aEvent);
}
@@ -1157,10 +1158,8 @@ nsresult nsChildView::ActivateNativeMenuItemAt(const nsAString& indexString) {
nsresult nsChildView::ForceUpdateNativeMenuAt(const nsAString& indexString) {
NS_OBJC_BEGIN_TRY_BLOCK_RETURN;
- nsCocoaWindow* widget = GetAppWindowWidget();
- if (widget) {
- nsMenuBarX* mb = widget->GetMenuBar();
- if (mb) {
+ if (nsCocoaWindow* widget = GetAppWindowWidget()) {
+ if (nsMenuBarX* mb = widget->GetMenuBar()) {
if (indexString.IsEmpty())
mb->ForceNativeMenuReload();
else
@@ -1689,33 +1688,6 @@ RefPtr<layers::NativeLayerRoot> nsChildView::GetNativeLayerRoot() {
return mNativeLayerRoot;
}
-static int32_t FindTitlebarBottom(
- const nsTArray<nsIWidget::ThemeGeometry>& aThemeGeometries,
- int32_t aWindowWidth) {
- int32_t titlebarBottom = 0;
- for (auto& g : aThemeGeometries) {
- if (g.mType == eThemeGeometryTypeTitlebar && g.mRect.X() <= 0 &&
- g.mRect.XMost() >= aWindowWidth && g.mRect.Y() <= 0) {
- titlebarBottom = std::max(titlebarBottom, g.mRect.YMost());
- }
- }
- return titlebarBottom;
-}
-
-static int32_t FindUnifiedToolbarBottom(
- const nsTArray<nsIWidget::ThemeGeometry>& aThemeGeometries,
- int32_t aWindowWidth, int32_t aTitlebarBottom) {
- int32_t unifiedToolbarBottom = aTitlebarBottom;
- for (uint32_t i = 0; i < aThemeGeometries.Length(); ++i) {
- const nsIWidget::ThemeGeometry& g = aThemeGeometries[i];
- if ((g.mType == eThemeGeometryTypeToolbar) && g.mRect.X() <= 0 &&
- g.mRect.XMost() >= aWindowWidth && g.mRect.Y() <= aTitlebarBottom) {
- unifiedToolbarBottom = std::max(unifiedToolbarBottom, g.mRect.YMost());
- }
- }
- return unifiedToolbarBottom;
-}
-
static LayoutDeviceIntRect FindFirstRectOfType(
const nsTArray<nsIWidget::ThemeGeometry>& aThemeGeometries,
nsITheme::ThemeGeometryType aThemeGeometryType) {
@@ -1730,32 +1702,17 @@ 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;
-
- // 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();
+ if (![mView.window isKindOfClass:[ToolbarWindow class]]) {
+ return;
+ }
ToolbarWindow* win = (ToolbarWindow*)[mView window];
- int32_t titlebarHeight = [win drawsContentsIntoWindowFrame]
- ? 0
- : CocoaPointsToDevPixels([win titlebarHeight]);
- 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 =
@@ -1768,10 +1725,8 @@ void nsChildView::UpdateThemeGeometries(
static Maybe<VibrancyType> ThemeGeometryTypeToVibrancyType(
nsITheme::ThemeGeometryType aThemeGeometryType) {
switch (aThemeGeometryType) {
- case eThemeGeometryTypeTooltip:
- return Some(VibrancyType::TOOLTIP);
- case eThemeGeometryTypeMenu:
- return Some(VibrancyType::MENU);
+ case eThemeGeometryTypeTitlebar:
+ return Some(VibrancyType::TITLEBAR);
default:
return Nothing();
}
@@ -1781,7 +1736,7 @@ static LayoutDeviceIntRegion GatherVibrantRegion(
const nsTArray<nsIWidget::ThemeGeometry>& aThemeGeometries,
VibrancyType aVibrancyType) {
LayoutDeviceIntRegion region;
- for (auto& geometry : aThemeGeometries) {
+ for (const auto& geometry : aThemeGeometries) {
if (ThemeGeometryTypeToVibrancyType(geometry.mType) ==
Some(aVibrancyType)) {
region.OrWith(geometry.mRect);
@@ -1790,40 +1745,13 @@ static LayoutDeviceIntRegion GatherVibrantRegion(
return region;
}
-template <typename Region>
-static void MakeRegionsNonOverlappingImpl(Region& aOutUnion) {}
-
-template <typename Region, typename... Regions>
-static void MakeRegionsNonOverlappingImpl(Region& aOutUnion, Region& aFirst,
- Regions&... aRest) {
- MakeRegionsNonOverlappingImpl(aOutUnion, aRest...);
- aFirst.SubOut(aOutUnion);
- aOutUnion.OrWith(aFirst);
-}
-
-// Subtracts parts from regions in such a way that they don't have any overlap.
-// Each region in the argument list will have the union of all the regions
-// *following* it subtracted from itself. In other words, the arguments are
-// sorted low priority to high priority.
-template <typename Region, typename... Regions>
-static void MakeRegionsNonOverlapping(Region& aFirst, Regions&... aRest) {
- Region unionOfAll;
- MakeRegionsNonOverlappingImpl(unionOfAll, aFirst, aRest...);
-}
-
void nsChildView::UpdateVibrancy(
const nsTArray<ThemeGeometry>& aThemeGeometries) {
- LayoutDeviceIntRegion menuRegion =
- GatherVibrantRegion(aThemeGeometries, VibrancyType::MENU);
- LayoutDeviceIntRegion tooltipRegion =
- GatherVibrantRegion(aThemeGeometries, VibrancyType::TOOLTIP);
-
- MakeRegionsNonOverlapping(menuRegion, tooltipRegion);
+ LayoutDeviceIntRegion titlebarRegion =
+ GatherVibrantRegion(aThemeGeometries, VibrancyType::TITLEBAR);
auto& vm = EnsureVibrancyManager();
- bool changed = false;
- changed |= vm.UpdateVibrantRegion(VibrancyType::MENU, menuRegion);
- changed |= vm.UpdateVibrantRegion(VibrancyType::TOOLTIP, tooltipRegion);
+ bool changed = vm.UpdateVibrantRegion(VibrancyType::TITLEBAR, titlebarRegion);
if (changed) {
SuspendAsyncCATransactions();
@@ -1834,7 +1762,7 @@ mozilla::VibrancyManager& nsChildView::EnsureVibrancyManager() {
MOZ_ASSERT(mView, "Only call this once we have a view!");
if (!mVibrancyManager) {
mVibrancyManager =
- MakeUnique<VibrancyManager>(*this, [mView vibrancyViewsContainer]);
+ MakeUnique<VibrancyManager>(*this, mView.vibrancyViewsContainer);
}
return *mVibrancyManager;
}
@@ -1897,7 +1825,7 @@ void nsChildView::UpdateWindowDraggingRegion(
// Suppress calls to setNeedsDisplay during NSView geometry changes.
ManipulateViewWithoutNeedingDisplay(mView, ^() {
changed = mNonDraggableRegion.UpdateRegion(
- nonDraggable, *this, [mView nonDraggableViewsContainer], ^() {
+ nonDraggable, *this, mView.nonDraggableViewsContainer, ^() {
return [[NonDraggableView alloc] initWithFrame:NSZeroRect];
});
});
@@ -2198,22 +2126,22 @@ NSEvent* gLastDragMouseDownEvent = nil; // [strong]
mCancelSwipeAnimation = nil;
#endif
+ auto bounds = self.bounds;
mNonDraggableViewsContainer =
- [[ViewRegionContainerView alloc] initWithFrame:[self bounds]];
+ [[ViewRegionContainerView alloc] initWithFrame:bounds];
mVibrancyViewsContainer =
- [[ViewRegionContainerView alloc] initWithFrame:[self bounds]];
+ [[ViewRegionContainerView alloc] initWithFrame:bounds];
- [mNonDraggableViewsContainer
- setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
- [mVibrancyViewsContainer
- setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
+ mNonDraggableViewsContainer.autoresizingMask =
+ mVibrancyViewsContainer.autoresizingMask =
+ NSViewWidthSizable | NSViewHeightSizable;
[self addSubview:mNonDraggableViewsContainer];
[self addSubview:mVibrancyViewsContainer];
- mPixelHostingView = [[PixelHostingView alloc] initWithFrame:[self bounds]];
- [mPixelHostingView
- setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
+ mPixelHostingView = [[PixelHostingView alloc] initWithFrame:bounds];
+ mPixelHostingView.autoresizingMask =
+ NSViewWidthSizable | NSViewHeightSizable;
[self addSubview:mPixelHostingView];
@@ -2222,7 +2150,7 @@ NSEvent* gLastDragMouseDownEvent = nil; // [strong]
mRootCALayer.bounds = NSZeroRect;
mRootCALayer.anchorPoint = NSZeroPoint;
mRootCALayer.contentsGravity = kCAGravityTopLeft;
- [[mPixelHostingView layer] addSublayer:mRootCALayer];
+ [mPixelHostingView.layer addSublayer:mRootCALayer];
mLastPressureStage = 0;
}
@@ -2398,7 +2326,7 @@ NSEvent* gLastDragMouseDownEvent = nil; // [strong]
// This call will cause updateRootCALayer to be called during the upcoming
// main thread CoreAnimation transaction. It will also trigger a transaction
// if no transaction is currently pending.
- [[mPixelHostingView layer] setNeedsDisplay];
+ [mPixelHostingView.layer setNeedsDisplay];
}
}
@@ -5129,18 +5057,12 @@ BOOL ChildViewMouseTracker::WindowAcceptsEvent(NSWindow* aWindow,
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;
}