Bug 1661760 - Part 1: Unify all range from offset methods to one. r=morgan,nika

There are at least 8 different methods for getting a range from an offset:
1. left word
2. right word
3. line
4. left line
5. right line
6. sentence
7. paragraph
8. range with same style.

Having a single wrapper and IPDL method for all of those with an enum would remove
a lot of redundancies.

Differential Revision: https://phabricator.services.mozilla.com/D90936
This commit is contained in:
Eitan Isaacson 2020-09-24 16:04:41 +00:00
Родитель cbe71b6afa
Коммит 10d6dd02bc
12 изменённых файлов: 105 добавлений и 97 удалений

Просмотреть файл

@ -70,4 +70,26 @@ typedef uint32_t IHandlerControlHolder;
#endif // defined(XP_WIN) && defined(ACCESSIBILITY)
#if defined(MOZ_WIDGET_COCOA)
# if defined(ACCESSIBILITY)
# include "mozilla/a11y/RangeTypes.h"
namespace IPC {
template <>
struct ParamTraits<mozilla::a11y::EWhichRange>
: public ContiguousEnumSerializerInclusive<
mozilla::a11y::EWhichRange, mozilla::a11y::EWhichRange::eLeftWord,
mozilla::a11y::EWhichRange::eRightWord> {};
} // namespace IPC
# else
namespace mozilla {
namespace a11y {
typedef uint32_t EWhichRange;
} // namespace a11y
} // namespace mozilla
# endif // defined(ACCESSIBILITY)
#endif // defined(MOZ_WIDGET_COCOA)
#endif // mozilla_a11y_IPCTypes_h

Просмотреть файл

@ -16,9 +16,10 @@
namespace mozilla {
namespace a11y {
mozilla::ipc::IPCResult DocAccessiblePlatformExtChild::RecvLeftWordAt(
const uint64_t& aID, const int32_t& aOffset, uint64_t* aStartContainer,
int32_t* aStartOffset, uint64_t* aEndContainer, int32_t* aEndOffset) {
mozilla::ipc::IPCResult DocAccessiblePlatformExtChild::RecvRangeAt(
const uint64_t& aID, const int32_t& aOffset, const EWhichRange& aRangeType,
uint64_t* aStartContainer, int32_t* aStartOffset, uint64_t* aEndContainer,
int32_t* aEndOffset) {
*aStartContainer = 0;
*aStartOffset = 0;
*aEndContainer = 0;
@ -32,36 +33,8 @@ mozilla::ipc::IPCResult DocAccessiblePlatformExtChild::RecvLeftWordAt(
HyperTextAccessible* startContainer = nullptr;
HyperTextAccessible* endContainer = nullptr;
acc->LeftWordAt(aOffset, &startContainer, aStartOffset, &endContainer,
aEndOffset);
MOZ_ASSERT(!startContainer || startContainer->Document() == acc->Document());
MOZ_ASSERT(!endContainer || endContainer->Document() == acc->Document());
*aStartContainer = UNIQUE_ID(startContainer);
*aEndContainer = UNIQUE_ID(endContainer);
return IPC_OK();
}
mozilla::ipc::IPCResult DocAccessiblePlatformExtChild::RecvRightWordAt(
const uint64_t& aID, const int32_t& aOffset, uint64_t* aStartContainer,
int32_t* aStartOffset, uint64_t* aEndContainer, int32_t* aEndOffset) {
*aStartContainer = 0;
*aStartOffset = 0;
*aEndContainer = 0;
*aEndOffset = 0;
HyperTextAccessibleWrap* acc = IdToHyperTextAccessibleWrap(aID);
if (!acc) {
return IPC_OK();
}
HyperTextAccessible* startContainer = nullptr;
HyperTextAccessible* endContainer = nullptr;
acc->RightWordAt(aOffset, &startContainer, aStartOffset, &endContainer,
aEndOffset);
acc->RangeAt(aOffset, aRangeType, &startContainer, aStartOffset,
&endContainer, aEndOffset);
MOZ_ASSERT(!startContainer || startContainer->Document() == acc->Document());
MOZ_ASSERT(!endContainer || endContainer->Document() == acc->Document());

Просмотреть файл

@ -16,12 +16,9 @@ class DocAccessibleChild;
class DocAccessiblePlatformExtChild : public PDocAccessiblePlatformExtChild {
public:
mozilla::ipc::IPCResult RecvLeftWordAt(
const uint64_t& aID, const int32_t& aOffset, uint64_t* aStartContainer,
int32_t* aStartOffset, uint64_t* aEndContainer, int32_t* aEndOffset);
mozilla::ipc::IPCResult RecvRightWordAt(
const uint64_t& aID, const int32_t& aOffset, uint64_t* aStartContainer,
mozilla::ipc::IPCResult RecvRangeAt(
const uint64_t& aID, const int32_t& aOffset,
const EWhichRange& aRangeType, uint64_t* aStartContainer,
int32_t* aStartOffset, uint64_t* aEndContainer, int32_t* aEndOffset);
mozilla::ipc::IPCResult RecvNextClusterAt(const uint64_t& aID,

Просмотреть файл

@ -6,6 +6,7 @@
include protocol PDocAccessible;
using mozilla::a11y::EWhichRange from "mozilla/a11y/IPCTypes.h";
using nsIntRect from "nsRect.h";
namespace mozilla {
@ -17,11 +18,7 @@ nested(upto inside_sync) sync protocol PDocAccessiblePlatformExt {
child:
async __delete__();
nested(inside_sync) sync LeftWordAt(uint64_t aID, int32_t aOffset)
returns(uint64_t aStartContainer, int32_t aStartOffset,
uint64_t aEndContainer, int32_t aEndOffset);
nested(inside_sync) sync RightWordAt(uint64_t aID, int32_t aOffset)
nested(inside_sync) sync RangeAt(uint64_t aID, int32_t aOffset, EWhichRange aRangeType)
returns(uint64_t aStartContainer, int32_t aStartOffset,
uint64_t aEndContainer, int32_t aEndOffset);

Просмотреть файл

@ -39,11 +39,8 @@ class GeckoTextMarker final {
bool Previous();
// Return a word range left of the given offset.
GeckoTextMarkerRange LeftWordRange();
// Return a word range right of the given offset.
GeckoTextMarkerRange RightWordRange();
// Return a range with the given type relative to this marker.
GeckoTextMarkerRange Range(EWhichRange aRangeType);
AccessibleOrProxy Leaf();

Просмотреть файл

@ -219,49 +219,26 @@ uint32_t GeckoTextMarker::CharacterCount(const AccessibleOrProxy& aContainer) {
return 0;
}
GeckoTextMarkerRange GeckoTextMarker::LeftWordRange() {
GeckoTextMarkerRange GeckoTextMarker::Range(EWhichRange aRangeType) {
MOZ_ASSERT(!mContainer.IsNull());
if (mContainer.IsProxy()) {
int32_t startOffset = 0, endOffset = 0;
uint64_t startContainerID = 0, endContainerID = 0;
DocAccessibleParent* ipcDoc = mContainer.AsProxy()->Document();
Unused << ipcDoc->GetPlatformExtension()->SendLeftWordAt(
mContainer.AsProxy()->ID(), mOffset, &startContainerID, &startOffset,
&endContainerID, &endOffset);
return GeckoTextMarkerRange(
GeckoTextMarker(ipcDoc->GetAccessible(startContainerID), startOffset),
GeckoTextMarker(ipcDoc->GetAccessible(endContainerID), endOffset));
bool success = ipcDoc->GetPlatformExtension()->SendRangeAt(
mContainer.AsProxy()->ID(), mOffset, aRangeType, &startContainerID,
&startOffset, &endContainerID, &endOffset);
if (success) {
return GeckoTextMarkerRange(
GeckoTextMarker(ipcDoc->GetAccessible(startContainerID), startOffset),
GeckoTextMarker(ipcDoc->GetAccessible(endContainerID), endOffset));
}
} else if (auto htWrap = ContainerAsHyperTextWrap()) {
int32_t startOffset = 0, endOffset = 0;
HyperTextAccessible* startContainer = nullptr;
HyperTextAccessible* endContainer = nullptr;
htWrap->LeftWordAt(mOffset, &startContainer, &startOffset, &endContainer,
&endOffset);
return GeckoTextMarkerRange(GeckoTextMarker(startContainer, startOffset),
GeckoTextMarker(endContainer, endOffset));
}
return GeckoTextMarkerRange(GeckoTextMarker(), GeckoTextMarker());
}
GeckoTextMarkerRange GeckoTextMarker::RightWordRange() {
MOZ_ASSERT(!mContainer.IsNull());
if (mContainer.IsProxy()) {
int32_t startOffset = 0, endOffset = 0;
uint64_t startContainerID = 0, endContainerID = 0;
DocAccessibleParent* ipcDoc = mContainer.AsProxy()->Document();
Unused << ipcDoc->GetPlatformExtension()->SendRightWordAt(
mContainer.AsProxy()->ID(), mOffset, &startContainerID, &startOffset,
&endContainerID, &endOffset);
return GeckoTextMarkerRange(
GeckoTextMarker(ipcDoc->GetAccessible(startContainerID), startOffset),
GeckoTextMarker(ipcDoc->GetAccessible(endContainerID), endOffset));
} else if (auto htWrap = ContainerAsHyperTextWrap()) {
int32_t startOffset = 0, endOffset = 0;
HyperTextAccessible* startContainer = nullptr;
HyperTextAccessible* endContainer = nullptr;
htWrap->RightWordAt(mOffset, &startContainer, &startOffset, &endContainer,
&endOffset);
htWrap->RangeAt(mOffset, aRangeType, &startContainer, &startOffset,
&endContainer, &endOffset);
return GeckoTextMarkerRange(GeckoTextMarker(startContainer, startOffset),
GeckoTextMarker(endContainer, endOffset));
}

Просмотреть файл

@ -7,6 +7,7 @@
#define mozilla_a11y_HyperTextAccessibleWrap_h__
#include "HyperTextAccessible.h"
#include "RangeTypes.h"
namespace mozilla {
namespace a11y {
@ -32,13 +33,9 @@ class HyperTextAccessibleWrap : public HyperTextAccessible {
void OffsetAtIndex(int32_t aIndex, HyperTextAccessible** aContainer,
int32_t* aOffset);
void LeftWordAt(int32_t aOffset, HyperTextAccessible** aStartContainer,
int32_t* aStartOffset, HyperTextAccessible** aEndContainer,
int32_t* aEndOffset);
void RightWordAt(int32_t aOffset, HyperTextAccessible** aStartContainer,
int32_t* aStartOffset, HyperTextAccessible** aEndContainer,
int32_t* aEndOffset);
void RangeAt(int32_t aOffset, EWhichRange aRangeType,
HyperTextAccessible** aStartContainer, int32_t* aStartOffset,
HyperTextAccessible** aEndContainer, int32_t* aEndOffset);
void NextClusterAt(int32_t aOffset, HyperTextAccessible** aNextContainer,
int32_t* aNextOffset);
@ -58,11 +55,20 @@ class HyperTextAccessibleWrap : public HyperTextAccessible {
protected:
~HyperTextAccessibleWrap() {}
private:
TextPoint FindTextPoint(int32_t aOffset, nsDirection aDirection,
nsSelectionAmount aAmount,
EWordMovementType aWordMovementType);
HyperTextAccessibleWrap* EditableRoot();
void LeftWordAt(int32_t aOffset, HyperTextAccessible** aStartContainer,
int32_t* aStartOffset, HyperTextAccessible** aEndContainer,
int32_t* aEndOffset);
void RightWordAt(int32_t aOffset, HyperTextAccessible** aStartContainer,
int32_t* aStartOffset, HyperTextAccessible** aEndContainer,
int32_t* aEndOffset);
};
} // namespace a11y

Просмотреть файл

@ -247,6 +247,25 @@ void HyperTextAccessibleWrap::OffsetAtIndex(int32_t aIndex,
}
}
void HyperTextAccessibleWrap::RangeAt(int32_t aOffset, EWhichRange aRangeType,
HyperTextAccessible** aStartContainer,
int32_t* aStartOffset,
HyperTextAccessible** aEndContainer,
int32_t* aEndOffset) {
switch (aRangeType) {
case EWhichRange::eLeftWord:
LeftWordAt(aOffset, aStartContainer, aStartOffset, aEndContainer,
aEndOffset);
break;
case EWhichRange::eRightWord:
RightWordAt(aOffset, aStartContainer, aStartOffset, aEndContainer,
aEndOffset);
break;
default:
break;
}
}
void HyperTextAccessibleWrap::LeftWordAt(int32_t aOffset,
HyperTextAccessible** aStartContainer,
int32_t* aStartOffset,

Просмотреть файл

@ -166,7 +166,8 @@ static nsDataHashtable<nsUint64HashKey, MOXTextMarkerDelegate*> sDelegates;
return nil;
}
return geckoTextMarker.LeftWordRange().CreateAXTextMarkerRange();
return geckoTextMarker.Range(EWhichRange::eLeftWord)
.CreateAXTextMarkerRange();
}
- (id)moxRightWordTextMarkerRangeForTextMarker:(id)textMarker {
@ -175,7 +176,8 @@ static nsDataHashtable<nsUint64HashKey, MOXTextMarkerDelegate*> sDelegates;
return nil;
}
return geckoTextMarker.RightWordRange().CreateAXTextMarkerRange();
return geckoTextMarker.Range(EWhichRange::eRightWord)
.CreateAXTextMarkerRange();
}
- (id)moxNextTextMarkerForTextMarker:(id)textMarker {

Просмотреть файл

@ -0,0 +1,20 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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/. */
#ifndef mozilla_a11y_RangeTypes_h__
#define mozilla_a11y_RangeTypes_h__
namespace mozilla {
namespace a11y {
enum class EWhichRange {
eLeftWord,
eRightWord
};
} // namespace a11y
} // namespace mozilla
#endif

Просмотреть файл

@ -11,6 +11,7 @@ EXPORTS += [
EXPORTS.mozilla.a11y += [
'AccessibleWrap.h',
'HyperTextAccessibleWrap.h',
'RangeTypes.h',
]
UNIFIED_SOURCES += [

Просмотреть файл

@ -614,11 +614,8 @@ platform = win
description = Legacy a11y IPC
platform = win
[PDocAccessiblePlatformExt::LeftWordAt]
description = Retrieve left word range from offset. Platform API is synchronous, so this needs to be too.
platform = mac
[PDocAccessiblePlatformExt::RightWordAt]
description = Retrieve left word range from offset. Platform API is synchronous, so this needs to be too.
[PDocAccessiblePlatformExt::RangeAt]
description = Retrieve a text range given an offset and range type. Platform API is synchronous, so this needs to be too.
platform = mac
[PDocAccessiblePlatformExt::NextClusterAt]
description = Retrieve next character from offset. Platform API is synchronous, so this needs to be too.