Skip to content

Commit

Permalink
Bug 1654601 - Ensure given text marker is valid in public API. r=MarcoZ
Browse files Browse the repository at this point in the history
  • Loading branch information
eeejay committed Jul 22, 2020
1 parent 5779810 commit 41858f5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions accessible/mac/GeckoTextMarker.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class GeckoTextMarker final {
// Return a word range for the given offset.
GeckoTextMarkerRange WordRange();

bool IsValid() const { return !mContainer.IsNull(); };

bool operator<(const GeckoTextMarker& aPoint) const;

AccessibleOrProxy mContainer;
Expand Down
3 changes: 3 additions & 0 deletions accessible/mac/GeckoTextMarker.mm
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ AXTextMarkerRangeRef AXTextMarkerRangeCreate(CFAllocatorRef allocator, AXTextMar
}

void GeckoTextMarker::NormalizeNext() {
MOZ_ASSERT(!mContainer.IsNull());
if (AtEnd()) {
// If this is the end of the current container, mutate to its parent's
// end offset.
Expand Down Expand Up @@ -159,6 +160,7 @@ AXTextMarkerRangeRef AXTextMarkerRangeCreate(CFAllocatorRef allocator, AXTextMar
}

void GeckoTextMarker::NormalizePrevious() {
MOZ_ASSERT(!mContainer.IsNull());
if (mOffset == 0) {
// If we are at the beginning of a container, mutate to its parent's start offset.
bool unused;
Expand Down Expand Up @@ -210,6 +212,7 @@ AXTextMarkerRangeRef AXTextMarkerRangeCreate(CFAllocatorRef allocator, AXTextMar
}

GeckoTextMarkerRange GeckoTextMarker::WordRange() {
MOZ_ASSERT(!mContainer.IsNull());
int32_t wordstart_start = 0, wordstart_end = 0, wordend_start = 0, wordend_end = 0;
nsAutoString unused;
if (mContainer.IsProxy()) {
Expand Down
14 changes: 14 additions & 0 deletions accessible/mac/MOXTextMarkerDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ - (id)moxEndTextMarkerForTextMarkerRange:(id)textMarkerRange {

- (id)moxLeftWordTextMarkerRangeForTextMarker:(id)textMarker {
GeckoTextMarker geckoTextMarker(mGeckoDocAccessible, textMarker);
if (!geckoTextMarker.IsValid()) {
return nil;
}

geckoTextMarker.NormalizePrevious();

if (geckoTextMarker.mOffset == 0) {
Expand All @@ -160,6 +164,10 @@ - (id)moxLeftWordTextMarkerRangeForTextMarker:(id)textMarker {

- (id)moxRightWordTextMarkerRangeForTextMarker:(id)textMarker {
GeckoTextMarker geckoTextMarker(mGeckoDocAccessible, textMarker);
if (!geckoTextMarker.IsValid()) {
return nil;
}

geckoTextMarker.NormalizeNext();

GeckoTextMarkerRange range = geckoTextMarker.AtEnd()
Expand All @@ -171,6 +179,9 @@ - (id)moxRightWordTextMarkerRangeForTextMarker:(id)textMarker {

- (id)moxNextTextMarkerForTextMarker:(id)textMarker {
GeckoTextMarker geckoTextMarker(mGeckoDocAccessible, textMarker);
if (!geckoTextMarker.IsValid()) {
return nil;
}

geckoTextMarker.NormalizeNext();
if (geckoTextMarker.AtEnd()) {
Expand All @@ -184,6 +195,9 @@ - (id)moxNextTextMarkerForTextMarker:(id)textMarker {

- (id)moxPreviousTextMarkerForTextMarker:(id)textMarker {
GeckoTextMarker geckoTextMarker(mGeckoDocAccessible, textMarker);
if (!geckoTextMarker.IsValid()) {
return nil;
}

geckoTextMarker.NormalizePrevious();
if (geckoTextMarker.mOffset == 0) {
Expand Down

0 comments on commit 41858f5

Please sign in to comment.