From b0068bfe229f3ee8f829ff7270d1972a68a5bdfe Mon Sep 17 00:00:00 2001 From: Markus Stange Date: Wed, 27 Oct 2021 20:38:07 +0000 Subject: [PATCH] Bug 1737869 - Fix build with the macOS 12 SDK, by using AXTextMarker(Range)Ref instead of id and by ifdefing the declarations that are now public in the new SDK. r=eeejay I think this patch is functionally neutral. I'm not completely sure about the best way to do these casts - the __bridge may not be necessary since we don't use ARC yet. But it's probably fine to add it anyway. Also, returning autoreleased CFTypeRef objects seems a bit weird, but it's what we've already been doing and it's probably fine. And some of these nils should maybe be nullptrs, but the compiler doesn't seem to care. Differential Revision: https://phabricator.services.mozilla.com/D129559 --- accessible/mac/GeckoTextMarker.h | 12 ++- accessible/mac/GeckoTextMarker.mm | 41 +++------- accessible/mac/MOXAccessibleProtocol.h | 73 ++++++++++-------- accessible/mac/MOXTextMarkerDelegate.h | 63 +++++++++------- accessible/mac/MOXTextMarkerDelegate.mm | 99 +++++++++++++++---------- accessible/mac/mozTextAccessible.mm | 3 +- widget/cocoa/SDKDeclarations.h | 19 +++++ widget/cocoa/moz.build | 1 + 8 files changed, 181 insertions(+), 130 deletions(-) diff --git a/accessible/mac/GeckoTextMarker.h b/accessible/mac/GeckoTextMarker.h index eea8a88f855a..6c16b7f6d640 100644 --- a/accessible/mac/GeckoTextMarker.h +++ b/accessible/mac/GeckoTextMarker.h @@ -9,8 +9,12 @@ #ifndef _GeckoTextMarker_H_ #define _GeckoTextMarker_H_ -typedef CFTypeRef AXTextMarkerRef; -typedef CFTypeRef AXTextMarkerRangeRef; +#include +#include + +#include "HyperTextAccessibleWrap.h" +#include "PlatformExtTypes.h" +#include "SDKDeclarations.h" namespace mozilla { namespace a11y { @@ -32,7 +36,7 @@ class GeckoTextMarker final { static GeckoTextMarker MarkerFromIndex(Accessible* aRoot, int32_t aIndex); - id CreateAXTextMarker(); + AXTextMarkerRef CreateAXTextMarker(); bool Next(); @@ -77,7 +81,7 @@ class GeckoTextMarkerRange final { explicit GeckoTextMarkerRange(Accessible* aAccessible); - id CreateAXTextMarkerRange(); + AXTextMarkerRangeRef CreateAXTextMarkerRange(); bool IsValid() const { return !!mStart.mContainer && !!mEnd.mContainer; }; diff --git a/accessible/mac/GeckoTextMarker.mm b/accessible/mac/GeckoTextMarker.mm index c841f3520385..a93855daa2e2 100644 --- a/accessible/mac/GeckoTextMarker.mm +++ b/accessible/mac/GeckoTextMarker.mm @@ -5,38 +5,17 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#import "GeckoTextMarker.h" + +#include "DocAccessible.h" #include "DocAccessibleParent.h" #include "AccAttributes.h" #include "nsCocoaUtils.h" +#include "MOXAccessibleBase.h" +#include "mozAccessible.h" #include "mozilla/a11y/DocAccessiblePlatformExtParent.h" -#import "GeckoTextMarker.h" - -extern "C" { - -CFTypeID AXTextMarkerGetTypeID(); - -AXTextMarkerRef AXTextMarkerCreate(CFAllocatorRef allocator, const UInt8* bytes, - CFIndex length); - -const UInt8* AXTextMarkerGetBytePtr(AXTextMarkerRef text_marker); - -size_t AXTextMarkerGetLength(AXTextMarkerRef text_marker); - -CFTypeID AXTextMarkerRangeGetTypeID(); - -AXTextMarkerRangeRef AXTextMarkerRangeCreate(CFAllocatorRef allocator, - AXTextMarkerRef start_marker, - AXTextMarkerRef end_marker); - -AXTextMarkerRef AXTextMarkerRangeCopyStartMarker( - AXTextMarkerRangeRef text_marker_range); - -AXTextMarkerRef AXTextMarkerRangeCopyEndMarker( - AXTextMarkerRangeRef text_marker_range); -} - namespace mozilla { namespace a11y { @@ -123,7 +102,7 @@ GeckoTextMarker GeckoTextMarker::MarkerFromIndex(Accessible* aRoot, return GeckoTextMarker(); } -id GeckoTextMarker::CreateAXTextMarker() { +AXTextMarkerRef GeckoTextMarker::CreateAXTextMarker() { if (!IsValid()) { return nil; } @@ -146,7 +125,7 @@ id GeckoTextMarker::CreateAXTextMarker() { kCFAllocatorDefault, reinterpret_cast(&opaqueMarker), sizeof(OpaqueGeckoTextMarker)); - return [static_cast(cf_text_marker) autorelease]; + return (__bridge AXTextMarkerRef)[(__bridge id)(cf_text_marker)autorelease]; } bool GeckoTextMarker::operator<(const GeckoTextMarker& aPoint) const { @@ -380,7 +359,7 @@ GeckoTextMarkerRange::GeckoTextMarkerRange(Accessible* aAccessible) { } } -id GeckoTextMarkerRange::CreateAXTextMarkerRange() { +AXTextMarkerRangeRef GeckoTextMarkerRange::CreateAXTextMarkerRange() { if (!IsValid()) { return nil; } @@ -388,7 +367,9 @@ id GeckoTextMarkerRange::CreateAXTextMarkerRange() { AXTextMarkerRangeRef cf_text_marker_range = AXTextMarkerRangeCreate(kCFAllocatorDefault, mStart.CreateAXTextMarker(), mEnd.CreateAXTextMarker()); - return [static_cast(cf_text_marker_range) autorelease]; + + return (__bridge AXTextMarkerRangeRef)[(__bridge id)( + cf_text_marker_range)autorelease]; } NSString* GeckoTextMarkerRange::Text() const { diff --git a/accessible/mac/MOXAccessibleProtocol.h b/accessible/mac/MOXAccessibleProtocol.h index 78cfe00a2ec6..f99dc15c46d2 100644 --- a/accessible/mac/MOXAccessibleProtocol.h +++ b/accessible/mac/MOXAccessibleProtocol.h @@ -5,7 +5,10 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include "SDKDeclarations.h" + @protocol MOXTextMarkerSupport; +@protocol mozAccessible; // This protocol's primary use is for abstracting the NSAccessibility informal // protocol into a formal internal API. Conforming classes get to choose a @@ -418,89 +421,101 @@ #pragma mark - TextAttributeGetters // AXStartTextMarker -- (id _Nullable)moxStartTextMarker; +- (AXTextMarkerRef _Nullable)moxStartTextMarker; // AXEndTextMarker -- (id _Nullable)moxEndTextMarker; +- (AXTextMarkerRef _Nullable)moxEndTextMarker; // AXSelectedTextMarkerRange -- (id _Nullable)moxSelectedTextMarkerRange; +- (AXTextMarkerRangeRef _Nullable)moxSelectedTextMarkerRange; #pragma mark - ParameterizedTextAttributeGetters // AXLengthForTextMarkerRange -- (NSNumber* _Nullable)moxLengthForTextMarkerRange:(id _Nonnull)textMarkerRange; +- (NSNumber* _Nullable)moxLengthForTextMarkerRange: + (AXTextMarkerRangeRef _Nonnull)textMarkerRange; // AXStringForTextMarkerRange -- (NSString* _Nullable)moxStringForTextMarkerRange:(id _Nonnull)textMarkerRange; +- (NSString* _Nullable)moxStringForTextMarkerRange: + (AXTextMarkerRangeRef _Nonnull)textMarkerRange; // AXTextMarkerRangeForUnorderedTextMarkers -- (id _Nullable)moxTextMarkerRangeForUnorderedTextMarkers: +- (AXTextMarkerRangeRef _Nullable)moxTextMarkerRangeForUnorderedTextMarkers: (NSArray* _Nonnull)textMarkers; // AXLeftWordTextMarkerRangeForTextMarker -- (id _Nullable)moxLeftWordTextMarkerRangeForTextMarker:(id _Nonnull)textMarker; +- (AXTextMarkerRangeRef _Nullable)moxLeftWordTextMarkerRangeForTextMarker: + (AXTextMarkerRef _Nonnull)textMarker; // AXRightWordTextMarkerRangeForTextMarker -- (id _Nullable)moxRightWordTextMarkerRangeForTextMarker: - (id _Nonnull)textMarker; +- (AXTextMarkerRangeRef _Nullable)moxRightWordTextMarkerRangeForTextMarker: + (AXTextMarkerRef _Nonnull)textMarker; // AXStartTextMarkerForTextMarkerRange -- (id _Nullable)moxStartTextMarkerForTextMarkerRange: - (id _Nonnull)textMarkerRange; +- (AXTextMarkerRef _Nullable)moxStartTextMarkerForTextMarkerRange: + (AXTextMarkerRangeRef _Nonnull)textMarkerRange; // AXEndTextMarkerForTextMarkerRange -- (id _Nullable)moxEndTextMarkerForTextMarkerRange:(id _Nonnull)textMarkerRange; +- (AXTextMarkerRef _Nullable)moxEndTextMarkerForTextMarkerRange: + (AXTextMarkerRangeRef _Nonnull)textMarkerRange; // AXNextTextMarkerForTextMarker -- (id _Nullable)moxNextTextMarkerForTextMarker:(id _Nonnull)textMarker; +- (AXTextMarkerRef _Nullable)moxNextTextMarkerForTextMarker: + (AXTextMarkerRef _Nonnull)textMarker; // AXPreviousTextMarkerForTextMarker -- (id _Nullable)moxPreviousTextMarkerForTextMarker:(id _Nonnull)textMarker; +- (AXTextMarkerRef _Nullable)moxPreviousTextMarkerForTextMarker: + (AXTextMarkerRef _Nonnull)textMarker; // AXAttributedStringForTextMarkerRange - (NSAttributedString* _Nullable)moxAttributedStringForTextMarkerRange: - (id _Nonnull)textMarkerRange; + (AXTextMarkerRangeRef _Nonnull)textMarkerRange; // AXBoundsForTextMarkerRange -- (NSValue* _Nullable)moxBoundsForTextMarkerRange:(id _Nonnull)textMarkerRange; +- (NSValue* _Nullable)moxBoundsForTextMarkerRange: + (AXTextMarkerRangeRef _Nonnull)textMarkerRange; // AXIndexForTextMarker -- (NSNumber* _Nullable)moxIndexForTextMarker:(id _Nonnull)textMarker; +- (NSNumber* _Nullable)moxIndexForTextMarker: + (AXTextMarkerRef _Nonnull)textMarker; // AXTextMarkerForIndex -- (id _Nullable)moxTextMarkerForIndex:(NSNumber* _Nonnull)index; +- (AXTextMarkerRef _Nullable)moxTextMarkerForIndex:(NSNumber* _Nonnull)index; // AXUIElementForTextMarker -- (id _Nullable)moxUIElementForTextMarker:(id _Nonnull)textMarker; +- (id _Nullable)moxUIElementForTextMarker:(AXTextMarkerRef _Nonnull)textMarker; // AXTextMarkerRangeForUIElement -- (id _Nullable)moxTextMarkerRangeForUIElement:(id _Nonnull)element; +- (AXTextMarkerRangeRef _Nullable)moxTextMarkerRangeForUIElement: + (id _Nonnull)element; // AXLineTextMarkerRangeForTextMarker -- (id _Nullable)moxLineTextMarkerRangeForTextMarker:(id _Nonnull)textMarker; +- (AXTextMarkerRangeRef _Nullable)moxLineTextMarkerRangeForTextMarker: + (AXTextMarkerRef _Nonnull)textMarker; // AXLeftLineTextMarkerRangeForTextMarker -- (id _Nullable)moxLeftLineTextMarkerRangeForTextMarker:(id _Nonnull)textMarker; +- (AXTextMarkerRangeRef _Nullable)moxLeftLineTextMarkerRangeForTextMarker: + (AXTextMarkerRef _Nonnull)textMarker; // AXRightLineTextMarkerRangeForTextMarker -- (id _Nullable)moxRightLineTextMarkerRangeForTextMarker: - (id _Nonnull)textMarker; +- (AXTextMarkerRangeRef _Nullable)moxRightLineTextMarkerRangeForTextMarker: + (AXTextMarkerRef _Nonnull)textMarker; // AXParagraphTextMarkerRangeForTextMarker -- (id _Nullable)moxParagraphTextMarkerRangeForTextMarker: - (id _Nonnull)textMarker; +- (AXTextMarkerRangeRef _Nullable)moxParagraphTextMarkerRangeForTextMarker: + (AXTextMarkerRef _Nonnull)textMarker; // AXStyleTextMarkerRangeForTextMarker -- (id _Nullable)moxStyleTextMarkerRangeForTextMarker:(id _Nonnull)textMarker; +- (AXTextMarkerRangeRef _Nullable)moxStyleTextMarkerRangeForTextMarker: + (AXTextMarkerRef _Nonnull)textMarker; // AXMozDebugDescriptionForTextMarker - (NSString* _Nullable)moxMozDebugDescriptionForTextMarker: - (id _Nonnull)textMarker; + (AXTextMarkerRef _Nonnull)textMarker; // AXMozDebugDescriptionForTextMarkerRange - (NSString* _Nullable)moxMozDebugDescriptionForTextMarkerRange: - (id _Nonnull)textMarkerRange; + (AXTextMarkerRangeRef _Nonnull)textMarkerRange; #pragma mark - TextAttributeSetters diff --git a/accessible/mac/MOXTextMarkerDelegate.h b/accessible/mac/MOXTextMarkerDelegate.h index d41f3db490df..24d9c5d7338a 100644 --- a/accessible/mac/MOXTextMarkerDelegate.h +++ b/accessible/mac/MOXTextMarkerDelegate.h @@ -12,9 +12,9 @@ @interface MOXTextMarkerDelegate : NSObject { mozilla::a11y::Accessible* mGeckoDocAccessible; - id mSelection; - id mCaret; - id mPrevCaret; + AXTextMarkerRangeRef mSelection; + AXTextMarkerRef mCaret; + AXTextMarkerRef mPrevCaret; } + (id)getOrCreateForDoc:(mozilla::a11y::Accessible*)aDoc; @@ -39,74 +39,85 @@ - (mozilla::a11y::GeckoTextMarkerRange)selection; // override -- (id)moxStartTextMarker; +- (AXTextMarkerRef)moxStartTextMarker; // override -- (id)moxEndTextMarker; +- (AXTextMarkerRef)moxEndTextMarker; // override -- (id)moxSelectedTextMarkerRange; +- (AXTextMarkerRangeRef)moxSelectedTextMarkerRange; // override -- (NSNumber*)moxLengthForTextMarkerRange:(id)textMarkerRange; +- (NSNumber*)moxLengthForTextMarkerRange:(AXTextMarkerRangeRef)textMarkerRange; // override -- (NSString*)moxStringForTextMarkerRange:(id)textMarkerRange; +- (NSString*)moxStringForTextMarkerRange:(AXTextMarkerRangeRef)textMarkerRange; // override -- (id)moxTextMarkerRangeForUnorderedTextMarkers:(NSArray*)textMarkers; +- (AXTextMarkerRangeRef)moxTextMarkerRangeForUnorderedTextMarkers: + (NSArray*)textMarkers; // override -- (id)moxStartTextMarkerForTextMarkerRange:(id)textMarkerRange; +- (AXTextMarkerRef)moxStartTextMarkerForTextMarkerRange: + (AXTextMarkerRangeRef)textMarkerRange; // override -- (id)moxEndTextMarkerForTextMarkerRange:(id)textMarkerRange; +- (AXTextMarkerRef)moxEndTextMarkerForTextMarkerRange: + (AXTextMarkerRangeRef)textMarkerRange; // override -- (id)moxLeftWordTextMarkerRangeForTextMarker:(id)textMarker; +- (AXTextMarkerRangeRef)moxLeftWordTextMarkerRangeForTextMarker: + (AXTextMarkerRef)textMarker; // override -- (id)moxRightWordTextMarkerRangeForTextMarker:(id)textMarker; +- (AXTextMarkerRangeRef)moxRightWordTextMarkerRangeForTextMarker: + (AXTextMarkerRef)textMarker; // override -- (id)moxLineTextMarkerRangeForTextMarker:(id)textMarker; +- (AXTextMarkerRangeRef)moxLineTextMarkerRangeForTextMarker: + (AXTextMarkerRef)textMarker; // override -- (id)moxLeftLineTextMarkerRangeForTextMarker:(id)textMarker; +- (AXTextMarkerRangeRef)moxLeftLineTextMarkerRangeForTextMarker: + (AXTextMarkerRef)textMarker; // override -- (id)moxRightLineTextMarkerRangeForTextMarker:(id)textMarker; +- (AXTextMarkerRangeRef)moxRightLineTextMarkerRangeForTextMarker: + (AXTextMarkerRef)textMarker; // override -- (id)moxParagraphTextMarkerRangeForTextMarker:(id)textMarker; +- (AXTextMarkerRangeRef)moxParagraphTextMarkerRangeForTextMarker: + (AXTextMarkerRef)textMarker; // override -- (id)moxStyleTextMarkerRangeForTextMarker:(id)textMarker; +- (AXTextMarkerRangeRef)moxStyleTextMarkerRangeForTextMarker: + (AXTextMarkerRef)textMarker; // override -- (id)moxNextTextMarkerForTextMarker:(id)textMarker; +- (AXTextMarkerRef)moxNextTextMarkerForTextMarker:(AXTextMarkerRef)textMarker; // override -- (id)moxPreviousTextMarkerForTextMarker:(id)textMarker; +- (AXTextMarkerRef)moxPreviousTextMarkerForTextMarker: + (AXTextMarkerRef)textMarker; // override - (NSAttributedString*)moxAttributedStringForTextMarkerRange: - (id)textMarkerRange; + (AXTextMarkerRangeRef)textMarkerRange; // override -- (NSValue*)moxBoundsForTextMarkerRange:(id)textMarkerRange; +- (NSValue*)moxBoundsForTextMarkerRange:(AXTextMarkerRangeRef)textMarkerRange; // override -- (id)moxUIElementForTextMarker:(id)textMarker; +- (id)moxUIElementForTextMarker:(AXTextMarkerRef)textMarker; // override -- (id)moxTextMarkerRangeForUIElement:(id)element; +- (AXTextMarkerRangeRef)moxTextMarkerRangeForUIElement:(id)element; // override -- (NSString*)moxMozDebugDescriptionForTextMarker:(id)textMarker; +- (NSString*)moxMozDebugDescriptionForTextMarker:(AXTextMarkerRef)textMarker; // override -- (void)moxSetSelectedTextMarkerRange:(id)textMarkerRange; +- (void)moxSetSelectedTextMarkerRange:(AXTextMarkerRangeRef)textMarkerRange; @end diff --git a/accessible/mac/MOXTextMarkerDelegate.mm b/accessible/mac/MOXTextMarkerDelegate.mm index 6b1244fdb074..844bedd07e2c 100644 --- a/accessible/mac/MOXTextMarkerDelegate.mm +++ b/accessible/mac/MOXTextMarkerDelegate.mm @@ -6,11 +6,13 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #import - -#include "mozilla/Preferences.h" +#include "DocAccessible.h" #import "MOXTextMarkerDelegate.h" +#include "mozAccessible.h" +#include "mozilla/Preferences.h" + using namespace mozilla::a11y; #define PREF_ACCESSIBILITY_MAC_DEBUG "accessibility.mac.debug" @@ -69,7 +71,8 @@ static nsTHashMap, // way to keep a weak reference - when we need to use the // range we can convert it back to a GeckoTextMarkerRange // and check that it's valid. - mSelection = [selection.CreateAXTextMarkerRange() retain]; + mSelection = selection.CreateAXTextMarkerRange(); + CFRetain(mSelection); } - (void)setCaretOffset:(mozilla::a11y::Accessible*)container @@ -77,7 +80,8 @@ static nsTHashMap, GeckoTextMarker caretMarker(container, offset); mPrevCaret = mCaret; - mCaret = [caretMarker.CreateAXTextMarker() retain]; + mCaret = caretMarker.CreateAXTextMarker(); + CFRetain(mCaret); } // This returns an info object to pass with AX SelectedTextChanged events. @@ -94,8 +98,9 @@ static nsTHashMap, // This is the base info object, includes the selected marker range and // the change type depending on the collapsed state of the selection. NSMutableDictionary* info = [[@{ - @"AXSelectedTextMarkerRange" : selectedGeckoRange.IsValid() ? mSelection - : [NSNull null], + @"AXSelectedTextMarkerRange" : selectedGeckoRange.IsValid() + ? (__bridge id)mSelection + : [NSNull null], @"AXTextStateChangeType" : @(stateChangeType), } mutableCopy] autorelease]; @@ -162,9 +167,9 @@ static nsTHashMap, } - (void)invalidateSelection { - [mSelection release]; - [mCaret release]; - [mPrevCaret release]; + CFRelease(mSelection); + CFRelease(mCaret); + CFRelease(mPrevCaret); mSelection = nil; } @@ -172,12 +177,12 @@ static nsTHashMap, return mozilla::a11y::GeckoTextMarkerRange(mGeckoDocAccessible, mSelection); } -- (id)moxStartTextMarker { +- (AXTextMarkerRef)moxStartTextMarker { GeckoTextMarker geckoTextPoint(mGeckoDocAccessible, 0); return geckoTextPoint.CreateAXTextMarker(); } -- (id)moxEndTextMarker { +- (AXTextMarkerRef)moxEndTextMarker { uint32_t characterCount = mGeckoDocAccessible->IsRemote() ? mGeckoDocAccessible->AsRemote()->CharacterCount() @@ -189,14 +194,14 @@ static nsTHashMap, return geckoTextPoint.CreateAXTextMarker(); } -- (id)moxSelectedTextMarkerRange { +- (AXTextMarkerRangeRef)moxSelectedTextMarkerRange { return mSelection && GeckoTextMarkerRange(mGeckoDocAccessible, mSelection).IsValid() ? mSelection : nil; } -- (NSString*)moxStringForTextMarkerRange:(id)textMarkerRange { +- (NSString*)moxStringForTextMarkerRange:(AXTextMarkerRangeRef)textMarkerRange { mozilla::a11y::GeckoTextMarkerRange range(mGeckoDocAccessible, textMarkerRange); if (!range.IsValid()) { @@ -206,18 +211,21 @@ static nsTHashMap, return range.Text(); } -- (NSNumber*)moxLengthForTextMarkerRange:(id)textMarkerRange { +- (NSNumber*)moxLengthForTextMarkerRange:(AXTextMarkerRangeRef)textMarkerRange { return @([[self moxStringForTextMarkerRange:textMarkerRange] length]); } -- (id)moxTextMarkerRangeForUnorderedTextMarkers:(NSArray*)textMarkers { +- (AXTextMarkerRangeRef)moxTextMarkerRangeForUnorderedTextMarkers: + (NSArray*)textMarkers { if ([textMarkers count] != 2) { // Don't allow anything but a two member array. return nil; } - GeckoTextMarker p1(mGeckoDocAccessible, textMarkers[0]); - GeckoTextMarker p2(mGeckoDocAccessible, textMarkers[1]); + GeckoTextMarker p1(mGeckoDocAccessible, + (__bridge AXTextMarkerRef)textMarkers[0]); + GeckoTextMarker p2(mGeckoDocAccessible, + (__bridge AXTextMarkerRef)textMarkers[1]); if (!p1.IsValid() || !p2.IsValid()) { // If either marker is invalid, return nil. @@ -230,21 +238,24 @@ static nsTHashMap, return range.CreateAXTextMarkerRange(); } -- (id)moxStartTextMarkerForTextMarkerRange:(id)textMarkerRange { +- (AXTextMarkerRef)moxStartTextMarkerForTextMarkerRange: + (AXTextMarkerRangeRef)textMarkerRange { mozilla::a11y::GeckoTextMarkerRange range(mGeckoDocAccessible, textMarkerRange); return range.IsValid() ? range.mStart.CreateAXTextMarker() : nil; } -- (id)moxEndTextMarkerForTextMarkerRange:(id)textMarkerRange { +- (AXTextMarkerRef)moxEndTextMarkerForTextMarkerRange: + (AXTextMarkerRangeRef)textMarkerRange { mozilla::a11y::GeckoTextMarkerRange range(mGeckoDocAccessible, textMarkerRange); return range.IsValid() ? range.mEnd.CreateAXTextMarker() : nil; } -- (id)moxLeftWordTextMarkerRangeForTextMarker:(id)textMarker { +- (AXTextMarkerRangeRef)moxLeftWordTextMarkerRangeForTextMarker: + (AXTextMarkerRef)textMarker { GeckoTextMarker geckoTextMarker(mGeckoDocAccessible, textMarker); if (!geckoTextMarker.IsValid()) { return nil; @@ -254,7 +265,8 @@ static nsTHashMap, .CreateAXTextMarkerRange(); } -- (id)moxRightWordTextMarkerRangeForTextMarker:(id)textMarker { +- (AXTextMarkerRangeRef)moxRightWordTextMarkerRangeForTextMarker: + (AXTextMarkerRef)textMarker { GeckoTextMarker geckoTextMarker(mGeckoDocAccessible, textMarker); if (!geckoTextMarker.IsValid()) { return nil; @@ -264,7 +276,8 @@ static nsTHashMap, .CreateAXTextMarkerRange(); } -- (id)moxLineTextMarkerRangeForTextMarker:(id)textMarker { +- (AXTextMarkerRangeRef)moxLineTextMarkerRangeForTextMarker: + (AXTextMarkerRef)textMarker { GeckoTextMarker geckoTextMarker(mGeckoDocAccessible, textMarker); if (!geckoTextMarker.IsValid()) { return nil; @@ -273,7 +286,8 @@ static nsTHashMap, return geckoTextMarker.Range(EWhichRange::eLine).CreateAXTextMarkerRange(); } -- (id)moxLeftLineTextMarkerRangeForTextMarker:(id)textMarker { +- (AXTextMarkerRangeRef)moxLeftLineTextMarkerRangeForTextMarker: + (AXTextMarkerRef)textMarker { GeckoTextMarker geckoTextMarker(mGeckoDocAccessible, textMarker); if (!geckoTextMarker.IsValid()) { return nil; @@ -283,7 +297,8 @@ static nsTHashMap, .CreateAXTextMarkerRange(); } -- (id)moxRightLineTextMarkerRangeForTextMarker:(id)textMarker { +- (AXTextMarkerRangeRef)moxRightLineTextMarkerRangeForTextMarker: + (AXTextMarkerRef)textMarker { GeckoTextMarker geckoTextMarker(mGeckoDocAccessible, textMarker); if (!geckoTextMarker.IsValid()) { return nil; @@ -293,7 +308,8 @@ static nsTHashMap, .CreateAXTextMarkerRange(); } -- (id)moxParagraphTextMarkerRangeForTextMarker:(id)textMarker { +- (AXTextMarkerRangeRef)moxParagraphTextMarkerRangeForTextMarker: + (AXTextMarkerRef)textMarker { GeckoTextMarker geckoTextMarker(mGeckoDocAccessible, textMarker); if (!geckoTextMarker.IsValid()) { return nil; @@ -304,7 +320,8 @@ static nsTHashMap, } // override -- (id)moxStyleTextMarkerRangeForTextMarker:(id)textMarker { +- (AXTextMarkerRangeRef)moxStyleTextMarkerRangeForTextMarker: + (AXTextMarkerRef)textMarker { GeckoTextMarker geckoTextMarker(mGeckoDocAccessible, textMarker); if (!geckoTextMarker.IsValid()) { return nil; @@ -313,7 +330,7 @@ static nsTHashMap, return geckoTextMarker.Range(EWhichRange::eStyle).CreateAXTextMarkerRange(); } -- (id)moxNextTextMarkerForTextMarker:(id)textMarker { +- (AXTextMarkerRef)moxNextTextMarkerForTextMarker:(AXTextMarkerRef)textMarker { GeckoTextMarker geckoTextMarker(mGeckoDocAccessible, textMarker); if (!geckoTextMarker.IsValid()) { return nil; @@ -326,7 +343,8 @@ static nsTHashMap, return geckoTextMarker.CreateAXTextMarker(); } -- (id)moxPreviousTextMarkerForTextMarker:(id)textMarker { +- (AXTextMarkerRef)moxPreviousTextMarkerForTextMarker: + (AXTextMarkerRef)textMarker { GeckoTextMarker geckoTextMarker(mGeckoDocAccessible, textMarker); if (!geckoTextMarker.IsValid()) { return nil; @@ -340,7 +358,7 @@ static nsTHashMap, } - (NSAttributedString*)moxAttributedStringForTextMarkerRange: - (id)textMarkerRange { + (AXTextMarkerRangeRef)textMarkerRange { mozilla::a11y::GeckoTextMarkerRange range(mGeckoDocAccessible, textMarkerRange); if (!range.IsValid()) { @@ -350,7 +368,7 @@ static nsTHashMap, return range.AttributedText(); } -- (NSValue*)moxBoundsForTextMarkerRange:(id)textMarkerRange { +- (NSValue*)moxBoundsForTextMarkerRange:(AXTextMarkerRangeRef)textMarkerRange { mozilla::a11y::GeckoTextMarkerRange range(mGeckoDocAccessible, textMarkerRange); if (!range.IsValid()) { @@ -360,7 +378,7 @@ static nsTHashMap, return range.Bounds(); } -- (NSNumber*)moxIndexForTextMarker:(id)textMarker { +- (NSNumber*)moxIndexForTextMarker:(AXTextMarkerRef)textMarker { GeckoTextMarker geckoTextMarker(mGeckoDocAccessible, textMarker); if (!geckoTextMarker.IsValid()) { return nil; @@ -372,7 +390,7 @@ static nsTHashMap, return @(range.Length()); } -- (id)moxTextMarkerForIndex:(NSNumber*)index { +- (AXTextMarkerRef)moxTextMarkerForIndex:(NSNumber*)index { GeckoTextMarker geckoTextMarker = GeckoTextMarker::MarkerFromIndex( mGeckoDocAccessible, [index integerValue]); if (!geckoTextMarker.IsValid()) { @@ -382,7 +400,7 @@ static nsTHashMap, return geckoTextMarker.CreateAXTextMarker(); } -- (id)moxUIElementForTextMarker:(id)textMarker { +- (id)moxUIElementForTextMarker:(AXTextMarkerRef)textMarker { GeckoTextMarker geckoTextMarker(mGeckoDocAccessible, textMarker); if (!geckoTextMarker.IsValid()) { return nil; @@ -396,17 +414,17 @@ static nsTHashMap, return GetNativeFromGeckoAccessible(leaf); } -- (id)moxTextMarkerRangeForUIElement:(id)element { +- (AXTextMarkerRangeRef)moxTextMarkerRangeForUIElement:(id)element { if (![element isKindOfClass:[mozAccessible class]]) { return nil; } - GeckoTextMarkerRange range([element geckoAccessible]); + GeckoTextMarkerRange range((Accessible*)[element geckoAccessible]); return range.CreateAXTextMarkerRange(); } -- (NSString*)moxMozDebugDescriptionForTextMarker:(id)textMarker { - if (!Preferences::GetBool(PREF_ACCESSIBILITY_MAC_DEBUG)) { +- (NSString*)moxMozDebugDescriptionForTextMarker:(AXTextMarkerRef)textMarker { + if (!mozilla::Preferences::GetBool(PREF_ACCESSIBILITY_MAC_DEBUG)) { return nil; } @@ -420,8 +438,9 @@ static nsTHashMap, geckoTextMarker.mOffset]; } -- (NSString*)moxMozDebugDescriptionForTextMarkerRange:(id)textMarkerRange { - if (!Preferences::GetBool(PREF_ACCESSIBILITY_MAC_DEBUG)) { +- (NSString*)moxMozDebugDescriptionForTextMarkerRange: + (AXTextMarkerRangeRef)textMarkerRange { + if (!mozilla::Preferences::GetBool(PREF_ACCESSIBILITY_MAC_DEBUG)) { return nil; } @@ -437,7 +456,7 @@ static nsTHashMap, range.mEnd.mContainer, range.mEnd.mOffset]; } -- (void)moxSetSelectedTextMarkerRange:(id)textMarkerRange { +- (void)moxSetSelectedTextMarkerRange:(AXTextMarkerRangeRef)textMarkerRange { mozilla::a11y::GeckoTextMarkerRange range(mGeckoDocAccessible, textMarkerRange); if (range.IsValid()) { diff --git a/accessible/mac/mozTextAccessible.mm b/accessible/mac/mozTextAccessible.mm index fe39e9078c5b..d6c6aff40dc8 100644 --- a/accessible/mac/mozTextAccessible.mm +++ b/accessible/mac/mozTextAccessible.mm @@ -306,7 +306,8 @@ inline NSString* ToNSString(id aValue) { @"AXTextStateChangeType" : @(AXTextStateChangeTypeEdit), @"AXTextChangeValues" : @[ @{ @"AXTextChangeValue" : (change ? change : @""), - @"AXTextChangeValueStartMarker" : startMarker.CreateAXTextMarker(), + @"AXTextChangeValueStartMarker" : + (__bridge id)startMarker.CreateAXTextMarker(), @"AXTextEditType" : isInserted ? @(AXTextEditTypeTyping) : @(AXTextEditTypeDelete) } ] diff --git a/widget/cocoa/SDKDeclarations.h b/widget/cocoa/SDKDeclarations.h index 475a81e62ff7..242c15eced43 100644 --- a/widget/cocoa/SDKDeclarations.h +++ b/widget/cocoa/SDKDeclarations.h @@ -101,4 +101,23 @@ typedef NS_ENUM(NSInteger, NSTitlebarSeparatorStyle) { #endif +#if !defined(MAC_OS_VERSION_12_0) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_VERSION_12_0 + +typedef CFTypeRef AXTextMarkerRef; +typedef CFTypeRef AXTextMarkerRangeRef; + +extern "C" { +CFTypeID AXTextMarkerGetTypeID(); +AXTextMarkerRef AXTextMarkerCreate(CFAllocatorRef allocator, const UInt8* bytes, CFIndex length); +const UInt8* AXTextMarkerGetBytePtr(AXTextMarkerRef text_marker); +CFIndex AXTextMarkerGetLength(AXTextMarkerRef text_marker); +CFTypeID AXTextMarkerRangeGetTypeID(); +AXTextMarkerRangeRef AXTextMarkerRangeCreate(CFAllocatorRef allocator, AXTextMarkerRef start_marker, + AXTextMarkerRef end_marker); +AXTextMarkerRef AXTextMarkerRangeCopyStartMarker(AXTextMarkerRangeRef text_marker_range); +AXTextMarkerRef AXTextMarkerRangeCopyEndMarker(AXTextMarkerRangeRef text_marker_range); +} + +#endif + #endif // SDKDefines_h diff --git a/widget/cocoa/moz.build b/widget/cocoa/moz.build index 93517c514771..f4cf072b530f 100644 --- a/widget/cocoa/moz.build +++ b/widget/cocoa/moz.build @@ -27,6 +27,7 @@ EXPORTS += [ "nsChangeObserver.h", "nsCocoaFeatures.h", "nsCocoaUtils.h", + "SDKDeclarations.h", ] EXPORTS.mozilla.widget += [