Skip to content

Commit 5cd8838

Browse files
[macOS 26] Fix NSTextField bezel not rendering on SDK 26
On macOS 26, the NSTextField bezel (rounded border) is drawn via a layer-backed rendering pipeline. Overriding drawRect:, setNeedsDisplay:, or setNeedsDisplayInRect: on the SWTTextField subclass prevents AppKit from rendering the native bezel. Similarly, calling setBordered(false) on an NSTextField destroys the bezel rendering even when no SWT.BORDER style is requested. Fix by conditionally skipping the display-invalidation method overrides (drawRect:, setNeedsDisplay:, setNeedsDisplayInRect:) on the SWTTextField class when running on macOS SDK 26, while preserving all mouse, keyboard, gesture, and responder event handling. Also skip setBordered(false) and setFocusRingType(NSFocusRingTypeNone) calls in Text.createHandle() on SDK 26 to avoid disrupting the native rendering.
1 parent ad26148 commit 5cd8838

2 files changed

Lines changed: 61 additions & 3 deletions

File tree

bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3160,7 +3160,55 @@ void initClasses () {
31603160
className = "SWTTextField";
31613161
cls = OS.objc_allocateClassPair(OS.class_NSTextField, className, 0);
31623162
OS.class_addIvar(cls, SWT_OBJECT, size, (byte)align, types);
3163-
addEventMethods(cls, proc2, proc3, drawRectProc, hitTestProc, setNeedsDisplayInRectProc);
3163+
int machOSDKVersion = OS.getMachOSDKVersion();
3164+
if (OS.VERSION_MAJOR(machOSDKVersion)==26) {
3165+
/*
3166+
* Bug in macOS 26: Overriding drawRect:, setNeedsDisplay: or
3167+
* setNeedsDisplayInRect: on NSTextField prevents the native bezel
3168+
* (rounded border) from being rendered. The new layer-backed rendering
3169+
* pipeline in macOS 26 bypasses drawRect: for the bezel. Only register
3170+
* the event/input methods from addEventMethods, skipping the display
3171+
* invalidation overrides.
3172+
*/
3173+
OS.class_addMethod(cls, OS.sel_mouseDown_, proc3, "@:@");
3174+
OS.class_addMethod(cls, OS.sel_mouseUp_, proc3, "@:@");
3175+
OS.class_addMethod(cls, OS.sel_scrollWheel_, proc3, "@:@");
3176+
OS.class_addMethod(cls, OS.sel_rightMouseDown_, proc3, "@:@");
3177+
OS.class_addMethod(cls, OS.sel_rightMouseUp_, proc3, "@:@");
3178+
OS.class_addMethod(cls, OS.sel_rightMouseDragged_, proc3, "@:@");
3179+
OS.class_addMethod(cls, OS.sel_otherMouseDown_, proc3, "@:@");
3180+
OS.class_addMethod(cls, OS.sel_otherMouseUp_, proc3, "@:@");
3181+
OS.class_addMethod(cls, OS.sel_otherMouseDragged_, proc3, "@:@");
3182+
OS.class_addMethod(cls, OS.sel_mouseDragged_, proc3, "@:@");
3183+
OS.class_addMethod(cls, OS.sel_mouseMoved_, proc3, "@:@");
3184+
OS.class_addMethod(cls, OS.sel_mouseEntered_, proc3, "@:@");
3185+
OS.class_addMethod(cls, OS.sel_mouseExited_, proc3, "@:@");
3186+
OS.class_addMethod(cls, OS.sel_menuForEvent_, proc3, "@:@");
3187+
OS.class_addMethod(cls, OS.sel_keyDown_, proc3, "@:@");
3188+
OS.class_addMethod(cls, OS.sel_keyUp_, proc3, "@:@");
3189+
OS.class_addMethod(cls, OS.sel_flagsChanged_, proc3, "@:@");
3190+
OS.class_addMethod(cls, OS.sel_cursorUpdate_, proc3, "@:@");
3191+
OS.class_addMethod(cls, OS.sel_shouldDelayWindowOrderingForEvent_, proc3, "@:@");
3192+
OS.class_addMethod(cls, OS.sel_acceptsFirstMouse_, proc3, "@:@");
3193+
OS.class_addMethod(cls, OS.sel_changeColor_, proc3, "@:@");
3194+
OS.class_addMethod(cls, OS.sel_cancelOperation_, proc3, "@:@");
3195+
OS.class_addMethod(cls, OS.sel_touchesBeganWithEvent_, proc3, "@:@");
3196+
OS.class_addMethod(cls, OS.sel_touchesMovedWithEvent_, proc3, "@:@");
3197+
OS.class_addMethod(cls, OS.sel_touchesEndedWithEvent_, proc3, "@:@");
3198+
OS.class_addMethod(cls, OS.sel_touchesCancelledWithEvent_, proc3, "@:@");
3199+
OS.class_addMethod(cls, OS.sel_swipeWithEvent_, proc3, "@:@");
3200+
OS.class_addMethod(cls, OS.sel_rotateWithEvent_, proc3, "@:@");
3201+
OS.class_addMethod(cls, OS.sel_magnifyWithEvent_, proc3, "@:@");
3202+
OS.class_addMethod(cls, OS.sel_resignFirstResponder, proc2, "@:");
3203+
OS.class_addMethod(cls, OS.sel_becomeFirstResponder, proc2, "@:");
3204+
OS.class_addMethod(cls, OS.sel_resetCursorRects, proc2, "@:");
3205+
OS.class_addMethod(cls, OS.sel_updateTrackingAreas, proc2, "@:");
3206+
OS.class_addMethod(cls, OS.sel_getImageView, proc2, "@:");
3207+
OS.class_addMethod(cls, OS.sel_mouseDownCanMoveWindow, proc2, "@:");
3208+
OS.class_addMethod(cls, OS.sel_hitTest_, hitTestProc, "@:{NSPoint}");
3209+
}else {
3210+
addEventMethods(cls, proc2, proc3, drawRectProc, hitTestProc, setNeedsDisplayInRectProc);
3211+
}
31643212
addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc);
31653213
addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
31663214
OS.class_addMethod(cls, OS.sel_acceptsFirstResponder, proc2, "@:");

bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Text.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -516,8 +516,18 @@ void createHandle () {
516516
widget.setSelectable (true);
517517
widget.setEditable((style & SWT.READ_ONLY) == 0);
518518
if ((style & SWT.BORDER) == 0) {
519-
widget.setFocusRingType (OS.NSFocusRingTypeNone);
520-
widget.setBordered (false);
519+
/*
520+
* Bug in macOS 26: Calling setBordered(false) on NSTextField destroys
521+
* the native rounded bezel rendering. On macOS 26, the bezel is drawn
522+
* via the layer-backed rendering pipeline and any modification to the
523+
* bordered/bezeled state prevents it from rendering correctly.
524+
* The workaround is to skip setBordered and setFocusRingType on SDK 26+.
525+
*/
526+
int machOSDKVersion = OS.getMachOSDKVersion();
527+
if (OS.VERSION_MAJOR(machOSDKVersion)!=26) {
528+
widget.setFocusRingType (OS.NSFocusRingTypeNone);
529+
widget.setBordered (false);
530+
}
521531
}
522532
/*
523533
* Bug in Cocoa: On OSX 10.10, setting the alignment on the search field

0 commit comments

Comments
 (0)