Bug 1653421 - Part 3: Don't normalize marker beyond editable root. r=morgan

When in an editable container, text markers are expected to not go past or before the editable root.

Differential Revision: https://phabricator.services.mozilla.com/D84055
This commit is contained in:
Eitan Isaacson 2020-07-21 23:02:57 +00:00
Родитель c52b49a014
Коммит 1d2bd5cd78
2 изменённых файлов: 34 добавлений и 10 удалений

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

@ -56,6 +56,8 @@ class GeckoTextMarker final {
private:
uint32_t CharacterCount(const AccessibleOrProxy& aContainer);
bool IsEditableRoot();
};
class GeckoTextMarkerRange final {

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

@ -100,6 +100,24 @@ bool GeckoTextMarker::operator<(const GeckoTextMarker& aPoint) const {
return false;
}
bool GeckoTextMarker::IsEditableRoot() {
uint64_t state =
mContainer.IsProxy() ? mContainer.AsProxy()->State() : mContainer.AsAccessible()->State();
if ((state & states::EDITABLE) == 0) {
return false;
}
AccessibleOrProxy parent = mContainer.Parent();
if (parent.IsNull()) {
// Not sure when this can happen, but it would technically be an editable root.
return true;
}
state = parent.IsProxy() ? parent.AsProxy()->State() : parent.AsAccessible()->State();
return (state & states::EDITABLE) == 0;
}
void GeckoTextMarker::NormalizeNext() {
if (AtEnd()) {
// If this is the end of the current container, mutate to its parent's
@ -109,6 +127,7 @@ void GeckoTextMarker::NormalizeNext() {
: mContainer.AsAccessible()->EndOffset();
if (endOffset != 0) {
if (!IsEditableRoot()) {
mContainer = mContainer.Parent();
mOffset = endOffset;
@ -116,6 +135,7 @@ void GeckoTextMarker::NormalizeNext() {
// or innermost link if at the beginning.
NormalizeNext();
}
}
} else {
AccessibleOrProxy link;
@ -146,6 +166,7 @@ void GeckoTextMarker::NormalizePrevious() {
: mContainer.AsAccessible()->StartOffset();
if (startOffset != 0) {
if (!IsEditableRoot()) {
mContainer = mContainer.Parent();
mOffset = startOffset;
@ -153,6 +174,7 @@ void GeckoTextMarker::NormalizePrevious() {
// or innermost link if at the end.
NormalizePrevious();
}
}
} else {
AccessibleOrProxy link;