2006-06-21 17:29:10 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2013-03-29 15:05:39 +04:00
|
|
|
/* vim: set ts=2 sw=2 et tw=78: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
2006-06-21 17:29:10 +04:00
|
|
|
|
2013-11-18 17:19:33 +04:00
|
|
|
#include "HyperTextAccessible-inl.h"
|
2010-04-27 10:52:03 +04:00
|
|
|
|
2012-04-13 18:17:03 +04:00
|
|
|
#include "Accessible-inl.h"
|
2006-06-21 17:29:10 +04:00
|
|
|
#include "nsAccessibilityService.h"
|
2013-10-26 18:58:53 +04:00
|
|
|
#include "nsIAccessibleTypes.h"
|
2012-05-27 13:01:40 +04:00
|
|
|
#include "DocAccessible.h"
|
2014-02-05 19:21:32 +04:00
|
|
|
#include "HTMLListAccessible.h"
|
2020-05-01 07:28:35 +03:00
|
|
|
#include "Relation.h"
|
2012-01-12 07:07:35 +04:00
|
|
|
#include "Role.h"
|
|
|
|
#include "States.h"
|
2012-03-10 11:29:51 +04:00
|
|
|
#include "TextAttrs.h"
|
2014-02-27 20:33:09 +04:00
|
|
|
#include "TextRange.h"
|
2013-09-11 20:56:01 +04:00
|
|
|
#include "TreeWalker.h"
|
2008-07-17 16:06:24 +04:00
|
|
|
|
2013-10-26 18:58:53 +04:00
|
|
|
#include "nsCaret.h"
|
2012-03-06 21:08:02 +04:00
|
|
|
#include "nsContentUtils.h"
|
2019-12-19 16:27:42 +03:00
|
|
|
#include "nsDebug.h"
|
2011-10-16 07:38:19 +04:00
|
|
|
#include "nsFocusManager.h"
|
2007-08-14 20:25:24 +04:00
|
|
|
#include "nsIEditingSession.h"
|
2014-05-25 02:20:39 +04:00
|
|
|
#include "nsContainerFrame.h"
|
2007-12-05 10:34:47 +03:00
|
|
|
#include "nsFrameSelection.h"
|
2007-12-11 17:15:21 +03:00
|
|
|
#include "nsILineIterator.h"
|
2007-08-14 20:25:24 +04:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
2018-09-15 19:58:31 +03:00
|
|
|
#include "nsPersistentProperties.h"
|
2007-12-11 17:15:21 +03:00
|
|
|
#include "nsIScrollableFrame.h"
|
2015-07-16 12:43:00 +03:00
|
|
|
#include "nsIMathMLFrame.h"
|
2018-05-17 19:01:38 +03:00
|
|
|
#include "nsRange.h"
|
2006-06-21 17:29:10 +04:00
|
|
|
#include "nsTextFragment.h"
|
2019-12-19 16:27:42 +03:00
|
|
|
#include "mozilla/Assertions.h"
|
2014-09-17 17:46:24 +04:00
|
|
|
#include "mozilla/BinarySearch.h"
|
2014-04-03 08:18:36 +04:00
|
|
|
#include "mozilla/EventStates.h"
|
2020-05-01 07:28:35 +03:00
|
|
|
#include "mozilla/HTMLEditor.h"
|
2013-09-30 19:56:44 +04:00
|
|
|
#include "mozilla/MathAlgorithms.h"
|
2019-04-03 15:40:26 +03:00
|
|
|
#include "mozilla/PresShell.h"
|
2017-08-07 11:42:50 +03:00
|
|
|
#include "mozilla/TextEditor.h"
|
2019-08-02 08:44:40 +03:00
|
|
|
#include "mozilla/dom/Element.h"
|
|
|
|
#include "mozilla/dom/HTMLBRElement.h"
|
2019-10-16 15:32:10 +03:00
|
|
|
#include "mozilla/dom/HTMLHeadingElement.h"
|
2019-08-02 08:44:40 +03:00
|
|
|
#include "mozilla/dom/Selection.h"
|
2007-08-04 05:12:24 +04:00
|
|
|
#include "gfxSkipChars.h"
|
2013-01-15 16:22:03 +04:00
|
|
|
#include <algorithm>
|
2006-06-21 17:29:10 +04:00
|
|
|
|
2012-04-07 04:09:31 +04:00
|
|
|
using namespace mozilla;
|
2011-07-27 16:43:01 +04:00
|
|
|
using namespace mozilla::a11y;
|
|
|
|
|
2010-06-11 12:23:18 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-05-31 12:04:41 +04:00
|
|
|
// HyperTextAccessible
|
2010-06-11 12:23:18 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-05-31 12:04:41 +04:00
|
|
|
HyperTextAccessible::HyperTextAccessible(nsIContent* aNode, DocAccessible* aDoc)
|
2014-10-22 04:49:28 +04:00
|
|
|
: AccessibleWrap(aNode, aDoc) {
|
2015-02-14 04:09:51 +03:00
|
|
|
mType = eHyperTextType;
|
2012-12-18 09:22:26 +04:00
|
|
|
mGenericTypes |= eHyperText;
|
2010-06-11 12:23:18 +04:00
|
|
|
}
|
2006-06-21 17:29:10 +04:00
|
|
|
|
2018-05-07 22:05:50 +03:00
|
|
|
role HyperTextAccessible::NativeRole() const {
|
2015-03-05 21:16:12 +03:00
|
|
|
a11y::role r = GetAccService()->MarkupRole(mContent);
|
|
|
|
if (r != roles::NOTHING) return r;
|
2010-11-15 21:30:44 +03:00
|
|
|
|
2015-05-13 18:40:15 +03:00
|
|
|
nsIFrame* frame = GetFrame();
|
2017-04-30 18:30:08 +03:00
|
|
|
if (frame && frame->IsInlineFrame()) return roles::TEXT;
|
2010-09-05 06:14:01 +04:00
|
|
|
|
2015-05-13 18:40:15 +03:00
|
|
|
return roles::TEXT_CONTAINER;
|
2006-06-21 17:29:10 +04:00
|
|
|
}
|
|
|
|
|
2018-05-15 21:04:50 +03:00
|
|
|
uint64_t HyperTextAccessible::NativeState() const {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint64_t states = AccessibleWrap::NativeState();
|
2006-06-21 17:29:10 +04:00
|
|
|
|
2020-05-14 19:46:08 +03:00
|
|
|
if (mContent->AsElement()->State().HasState(NS_EVENT_STATE_READWRITE)) {
|
2012-03-14 21:48:01 +04:00
|
|
|
states |= states::EDITABLE;
|
|
|
|
|
2015-03-03 14:08:59 +03:00
|
|
|
} else if (mContent->IsHTMLElement(nsGkAtoms::article)) {
|
2010-11-29 21:32:19 +03:00
|
|
|
// We want <article> to behave like a document in terms of readonly state.
|
2011-04-10 03:38:06 +04:00
|
|
|
states |= states::READONLY;
|
2006-06-21 17:29:10 +04:00
|
|
|
}
|
|
|
|
|
2011-04-10 03:38:06 +04:00
|
|
|
if (HasChildren()) states |= states::SELECTABLE_TEXT;
|
2007-04-02 19:56:24 +04:00
|
|
|
|
2011-04-10 03:38:06 +04:00
|
|
|
return states;
|
2006-06-21 17:29:10 +04:00
|
|
|
}
|
|
|
|
|
2013-11-25 22:28:27 +04:00
|
|
|
nsIntRect HyperTextAccessible::GetBoundsInFrame(nsIFrame* aFrame,
|
|
|
|
uint32_t aStartRenderedOffset,
|
|
|
|
uint32_t aEndRenderedOffset) {
|
2012-10-20 15:04:45 +04:00
|
|
|
nsPresContext* presContext = mDoc->PresContext();
|
2017-04-30 18:30:08 +03:00
|
|
|
if (!aFrame->IsTextFrame()) {
|
2012-10-20 15:04:45 +04:00
|
|
|
return aFrame->GetScreenRectInAppUnits().ToNearestPixels(
|
|
|
|
presContext->AppUnitsPerDevPixel());
|
2007-09-05 17:31:33 +04:00
|
|
|
}
|
2007-08-04 05:12:24 +04:00
|
|
|
|
2013-11-25 22:28:27 +04:00
|
|
|
// Substring must be entirely within the same text node.
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t startContentOffset, endContentOffset;
|
2007-08-10 23:24:10 +04:00
|
|
|
nsresult rv = RenderedToContentOffset(aFrame, aStartRenderedOffset,
|
|
|
|
&startContentOffset);
|
2012-10-20 15:04:45 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, nsIntRect());
|
2007-08-10 23:24:10 +04:00
|
|
|
rv = RenderedToContentOffset(aFrame, aEndRenderedOffset, &endContentOffset);
|
2012-10-20 15:04:45 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, nsIntRect());
|
2007-08-04 05:12:24 +04:00
|
|
|
|
2006-08-16 17:36:19 +04:00
|
|
|
nsIFrame* frame;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t startContentOffsetInFrame;
|
2007-08-04 05:12:24 +04:00
|
|
|
// Get the right frame continuation -- not really a child, but a sibling of
|
|
|
|
// the primary frame passed in
|
2011-10-17 18:59:28 +04:00
|
|
|
rv = aFrame->GetChildFrameContainingOffset(
|
2007-08-10 23:24:10 +04:00
|
|
|
startContentOffset, false, &startContentOffsetInFrame, &frame);
|
2012-10-20 15:04:45 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, nsIntRect());
|
2006-08-16 17:36:19 +04:00
|
|
|
|
2012-10-20 15:04:45 +04:00
|
|
|
nsRect screenRect;
|
2007-08-10 23:24:10 +04:00
|
|
|
while (frame && startContentOffset < endContentOffset) {
|
2014-04-26 06:42:19 +04:00
|
|
|
// Start with this frame's screen rect, which we will shrink based on
|
|
|
|
// the substring we care about within it. We will then add that frame to
|
|
|
|
// the total screenRect we are returning.
|
2012-10-20 15:04:45 +04:00
|
|
|
nsRect frameScreenRect = frame->GetScreenRectInAppUnits();
|
2006-08-16 17:36:19 +04:00
|
|
|
|
|
|
|
// Get the length of the substring in this frame that we want the bounds for
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t startFrameTextOffset, endFrameTextOffset;
|
2006-08-16 17:36:19 +04:00
|
|
|
frame->GetOffsets(startFrameTextOffset, endFrameTextOffset);
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t frameTotalTextLength = endFrameTextOffset - startFrameTextOffset;
|
|
|
|
int32_t seekLength = endContentOffset - startContentOffset;
|
2013-01-15 16:22:03 +04:00
|
|
|
int32_t frameSubStringLength =
|
|
|
|
std::min(frameTotalTextLength - startContentOffsetInFrame, seekLength);
|
2006-08-16 17:36:19 +04:00
|
|
|
|
|
|
|
// Add the point where the string starts to the frameScreenRect
|
|
|
|
nsPoint frameTextStartPoint;
|
2007-08-17 07:43:00 +04:00
|
|
|
rv = frame->GetPointFromOffset(startContentOffset, &frameTextStartPoint);
|
2009-01-15 06:27:09 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, nsIntRect());
|
2006-08-16 17:36:19 +04:00
|
|
|
|
|
|
|
// Use the point for the end offset to calculate the width
|
|
|
|
nsPoint frameTextEndPoint;
|
2007-08-17 07:43:00 +04:00
|
|
|
rv = frame->GetPointFromOffset(startContentOffset + frameSubStringLength,
|
|
|
|
&frameTextEndPoint);
|
2009-01-15 06:27:09 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, nsIntRect());
|
2013-09-27 18:15:19 +04:00
|
|
|
|
2018-01-12 20:07:29 +03:00
|
|
|
frameScreenRect.SetRectX(
|
|
|
|
frameScreenRect.X() +
|
|
|
|
std::min(frameTextStartPoint.x, frameTextEndPoint.x),
|
|
|
|
mozilla::Abs(frameTextStartPoint.x - frameTextEndPoint.x));
|
2006-08-16 17:36:19 +04:00
|
|
|
|
|
|
|
screenRect.UnionRect(frameScreenRect, screenRect);
|
|
|
|
|
|
|
|
// Get ready to loop back for next frame continuation
|
2007-08-10 23:24:10 +04:00
|
|
|
startContentOffset += frameSubStringLength;
|
|
|
|
startContentOffsetInFrame = 0;
|
2006-08-16 17:36:19 +04:00
|
|
|
frame = frame->GetNextContinuation();
|
|
|
|
}
|
|
|
|
|
2012-10-20 15:04:45 +04:00
|
|
|
return screenRect.ToNearestPixels(presContext->AppUnitsPerDevPixel());
|
2006-08-16 17:36:19 +04:00
|
|
|
}
|
|
|
|
|
2013-11-18 17:19:33 +04:00
|
|
|
void HyperTextAccessible::TextSubstring(int32_t aStartOffset,
|
|
|
|
int32_t aEndOffset, nsAString& aText) {
|
2011-02-01 19:08:36 +03:00
|
|
|
aText.Truncate();
|
|
|
|
|
2014-05-17 03:16:34 +04:00
|
|
|
index_t startOffset = ConvertMagicOffset(aStartOffset);
|
|
|
|
index_t endOffset = ConvertMagicOffset(aEndOffset);
|
|
|
|
if (!startOffset.IsValid() || !endOffset.IsValid() ||
|
|
|
|
startOffset > endOffset || endOffset > CharacterCount()) {
|
|
|
|
NS_ERROR("Wrong in offset");
|
|
|
|
return;
|
|
|
|
}
|
2012-05-23 22:06:07 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t startChildIdx = GetChildIndexAtOffset(startOffset);
|
2013-11-18 17:19:33 +04:00
|
|
|
if (startChildIdx == -1) return;
|
2011-02-01 19:08:36 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t endChildIdx = GetChildIndexAtOffset(endOffset);
|
2011-02-01 19:08:36 +03:00
|
|
|
if (endChildIdx == -1) return;
|
|
|
|
|
|
|
|
if (startChildIdx == endChildIdx) {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t childOffset = GetChildOffset(startChildIdx);
|
2013-11-18 17:19:33 +04:00
|
|
|
if (childOffset == -1) return;
|
2011-02-01 19:08:36 +03:00
|
|
|
|
2012-05-29 05:18:45 +04:00
|
|
|
Accessible* child = GetChildAt(startChildIdx);
|
2011-02-03 17:29:12 +03:00
|
|
|
child->AppendTextTo(aText, startOffset - childOffset,
|
|
|
|
endOffset - startOffset);
|
2013-11-18 17:19:33 +04:00
|
|
|
return;
|
2011-02-01 19:08:36 +03:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t startChildOffset = GetChildOffset(startChildIdx);
|
2013-11-18 17:19:33 +04:00
|
|
|
if (startChildOffset == -1) return;
|
2011-02-01 19:08:36 +03:00
|
|
|
|
2012-05-29 05:18:45 +04:00
|
|
|
Accessible* startChild = GetChildAt(startChildIdx);
|
2011-02-03 17:29:12 +03:00
|
|
|
startChild->AppendTextTo(aText, startOffset - startChildOffset);
|
2011-02-01 19:08:36 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t childIdx = startChildIdx + 1; childIdx < endChildIdx;
|
|
|
|
childIdx++) {
|
2012-05-29 05:18:45 +04:00
|
|
|
Accessible* child = GetChildAt(childIdx);
|
2011-02-01 19:08:36 +03:00
|
|
|
child->AppendTextTo(aText);
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t endChildOffset = GetChildOffset(endChildIdx);
|
2013-11-18 17:19:33 +04:00
|
|
|
if (endChildOffset == -1) return;
|
2011-02-01 19:08:36 +03:00
|
|
|
|
2012-05-29 05:18:45 +04:00
|
|
|
Accessible* endChild = GetChildAt(endChildIdx);
|
2011-02-03 17:29:12 +03:00
|
|
|
endChild->AppendTextTo(aText, 0, endOffset - endChildOffset);
|
2006-06-21 17:29:10 +04:00
|
|
|
}
|
|
|
|
|
2014-02-04 04:56:45 +04:00
|
|
|
uint32_t HyperTextAccessible::DOMPointToOffset(nsINode* aNode,
|
|
|
|
int32_t aNodeOffset,
|
|
|
|
bool aIsEndOffset) const {
|
2010-05-17 20:16:52 +04:00
|
|
|
if (!aNode) return 0;
|
2007-03-06 16:44:42 +03:00
|
|
|
|
2014-02-05 19:21:32 +04:00
|
|
|
uint32_t offset = 0;
|
2012-07-30 18:20:58 +04:00
|
|
|
nsINode* findNode = nullptr;
|
2006-07-12 17:14:53 +04:00
|
|
|
|
2007-08-29 01:57:53 +04:00
|
|
|
if (aNodeOffset == -1) {
|
|
|
|
findNode = aNode;
|
2010-06-11 12:23:18 +04:00
|
|
|
|
2018-04-13 01:41:00 +03:00
|
|
|
} else if (aNode->IsText()) {
|
2007-03-06 16:44:42 +03:00
|
|
|
// For text nodes, aNodeOffset comes in as a character offset
|
|
|
|
// Text offset will be added at the end, if we find the offset in this
|
2007-08-04 05:12:24 +04:00
|
|
|
// hypertext We want the "skipped" offset into the text (rendered text
|
|
|
|
// without the extra whitespace)
|
2014-02-04 04:56:45 +04:00
|
|
|
nsIFrame* frame = aNode->AsContent()->GetPrimaryFrame();
|
|
|
|
NS_ENSURE_TRUE(frame, 0);
|
|
|
|
|
2014-02-05 19:21:32 +04:00
|
|
|
nsresult rv = ContentToRenderedOffset(frame, aNodeOffset, &offset);
|
2014-02-04 04:56:45 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, 0);
|
2014-04-26 06:42:19 +04:00
|
|
|
|
2007-03-06 16:44:42 +03:00
|
|
|
findNode = aNode;
|
2010-06-11 12:23:18 +04:00
|
|
|
|
|
|
|
} else {
|
|
|
|
// findNode could be null if aNodeOffset == # of child nodes, which means
|
|
|
|
// one of two things:
|
2013-01-05 14:14:34 +04:00
|
|
|
// 1) there are no children, and the passed-in node is not mContent -- use
|
2010-06-11 12:23:18 +04:00
|
|
|
// parentContent for the node to find
|
2013-01-05 14:14:34 +04:00
|
|
|
// 2) there are no children and the passed-in node is mContent, which means
|
|
|
|
// we're an empty nsIAccessibleText
|
|
|
|
// 3) there are children and we're at the end of the children
|
2010-06-11 12:23:18 +04:00
|
|
|
|
2018-01-03 15:59:54 +03:00
|
|
|
findNode = aNode->GetChildAt_Deprecated(aNodeOffset);
|
2013-01-05 14:14:34 +04:00
|
|
|
if (!findNode) {
|
|
|
|
if (aNodeOffset == 0) {
|
|
|
|
if (aNode == GetNode()) {
|
|
|
|
// Case #1: this accessible has no children and thus has empty text,
|
|
|
|
// we can only be at hypertext offset 0.
|
2014-02-04 04:56:45 +04:00
|
|
|
return 0;
|
2013-01-05 14:14:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Case #2: there are no children, we're at this node.
|
|
|
|
findNode = aNode;
|
2014-04-26 06:42:19 +04:00
|
|
|
} else if (aNodeOffset == static_cast<int32_t>(aNode->GetChildCount())) {
|
2013-01-05 14:14:34 +04:00
|
|
|
// Case #3: we're after the last child, get next node to this one.
|
|
|
|
for (nsINode* tmpNode = aNode;
|
|
|
|
!findNode && tmpNode && tmpNode != mContent;
|
|
|
|
tmpNode = tmpNode->GetParent()) {
|
|
|
|
findNode = tmpNode->GetNextSibling();
|
|
|
|
}
|
2007-08-11 05:44:44 +04:00
|
|
|
}
|
2007-04-19 17:56:09 +04:00
|
|
|
}
|
2007-03-06 16:44:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get accessible for this findNode, or if that node isn't accessible, use the
|
|
|
|
// accessible for the next DOM node which has one (based on forward depth
|
|
|
|
// first search)
|
2014-02-04 04:56:45 +04:00
|
|
|
Accessible* descendant = nullptr;
|
2007-03-06 16:44:42 +03:00
|
|
|
if (findNode) {
|
2019-08-02 08:44:40 +03:00
|
|
|
dom::HTMLBRElement* brElement = dom::HTMLBRElement::FromNode(findNode);
|
|
|
|
if (brElement && brElement->IsPaddingForEmptyEditor()) {
|
|
|
|
// This <br> is the hacky "padding <br> element" used when there is no
|
|
|
|
// text in the editor.
|
2014-02-04 04:56:45 +04:00
|
|
|
return 0;
|
2008-01-22 04:32:11 +03:00
|
|
|
}
|
2014-02-15 19:21:40 +04:00
|
|
|
|
|
|
|
descendant = mDoc->GetAccessible(findNode);
|
|
|
|
if (!descendant && findNode->IsContent()) {
|
|
|
|
Accessible* container = mDoc->GetContainerAccessible(findNode);
|
|
|
|
if (container) {
|
|
|
|
TreeWalker walker(container, findNode->AsContent(),
|
|
|
|
TreeWalker::eWalkContextTree);
|
2016-02-19 01:57:17 +03:00
|
|
|
descendant = walker.Next();
|
2014-08-13 00:25:40 +04:00
|
|
|
if (!descendant) descendant = container;
|
2014-02-15 19:21:40 +04:00
|
|
|
}
|
|
|
|
}
|
2007-03-06 16:44:42 +03:00
|
|
|
}
|
2010-04-19 17:39:57 +04:00
|
|
|
|
2014-02-05 19:21:32 +04:00
|
|
|
return TransformOffset(descendant, offset, aIsEndOffset);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t HyperTextAccessible::TransformOffset(Accessible* aDescendant,
|
2014-04-26 06:42:19 +04:00
|
|
|
uint32_t aOffset,
|
|
|
|
bool aIsEndOffset) const {
|
2014-02-05 19:21:32 +04:00
|
|
|
// From the descendant, go up and get the immediate child of this hypertext.
|
2014-04-26 06:42:19 +04:00
|
|
|
uint32_t offset = aOffset;
|
2014-02-05 19:21:32 +04:00
|
|
|
Accessible* descendant = aDescendant;
|
2014-02-04 04:56:45 +04:00
|
|
|
while (descendant) {
|
|
|
|
Accessible* parent = descendant->Parent();
|
2014-02-05 19:21:32 +04:00
|
|
|
if (parent == this) return GetChildOffset(descendant) + offset;
|
2010-04-19 17:39:57 +04:00
|
|
|
|
2014-01-23 03:14:06 +04:00
|
|
|
// This offset no longer applies because the passed-in text object is not
|
|
|
|
// a child of the hypertext. This happens when there are nested hypertexts,
|
|
|
|
// e.g. <div>abc<h1>def</h1>ghi</div>. Thus we need to adjust the offset
|
|
|
|
// to make it relative the hypertext.
|
|
|
|
// If the end offset is not supposed to be inclusive and the original point
|
|
|
|
// is not at 0 offset then the returned offset should be after an embedded
|
|
|
|
// character the original point belongs to.
|
2019-09-25 05:10:08 +03:00
|
|
|
if (aIsEndOffset) {
|
|
|
|
// Similar to our special casing in FindOffset, we add handling for
|
|
|
|
// bulleted lists here because PeekOffset returns the inner text node
|
|
|
|
// for a list when it should return the list bullet.
|
|
|
|
// We manually set the offset so the error doesn't propagate up.
|
2019-09-30 19:23:30 +03:00
|
|
|
if (offset == 0 && parent && parent->IsHTMLListItem() &&
|
2019-09-25 05:10:08 +03:00
|
|
|
descendant->PrevSibling() && descendant->PrevSibling()->GetFrame() &&
|
|
|
|
descendant->PrevSibling()->GetFrame()->IsBulletFrame()) {
|
|
|
|
offset = 0;
|
|
|
|
} else {
|
|
|
|
offset = (offset > 0 || descendant->IndexInParent() > 0) ? 1 : 0;
|
|
|
|
}
|
|
|
|
} else {
|
2014-02-05 19:21:32 +04:00
|
|
|
offset = 0;
|
2019-09-25 05:10:08 +03:00
|
|
|
}
|
2010-04-19 17:39:57 +04:00
|
|
|
|
2014-02-04 04:56:45 +04:00
|
|
|
descendant = parent;
|
2007-03-06 16:44:42 +03:00
|
|
|
}
|
2007-08-29 01:57:53 +04:00
|
|
|
|
2014-02-05 19:21:32 +04:00
|
|
|
// If the given a11y point cannot be mapped into offset relative this
|
2014-02-04 04:56:45 +04:00
|
|
|
// hypertext offset then return length as fallback value.
|
2014-02-05 19:21:32 +04:00
|
|
|
return CharacterCount();
|
2006-06-21 17:29:10 +04:00
|
|
|
}
|
|
|
|
|
2015-03-03 22:25:52 +03:00
|
|
|
/**
|
|
|
|
* GetElementAsContentOf() returns a content representing an element which is
|
|
|
|
* or includes aNode.
|
|
|
|
*
|
|
|
|
* XXX This method is enough to retrieve ::before or ::after pseudo element.
|
|
|
|
* So, if you want to use this for other purpose, you might need to check
|
|
|
|
* ancestors too.
|
|
|
|
*/
|
|
|
|
static nsIContent* GetElementAsContentOf(nsINode* aNode) {
|
2019-11-29 23:39:36 +03:00
|
|
|
if (auto* element = dom::Element::FromNode(aNode)) {
|
2018-05-30 17:56:24 +03:00
|
|
|
return element;
|
2015-03-03 22:25:52 +03:00
|
|
|
}
|
2018-05-30 17:56:24 +03:00
|
|
|
return aNode->GetParentElement();
|
2015-03-03 22:25:52 +03:00
|
|
|
}
|
|
|
|
|
2013-12-13 20:26:35 +04:00
|
|
|
bool HyperTextAccessible::OffsetsToDOMRange(int32_t aStartOffset,
|
|
|
|
int32_t aEndOffset,
|
2020-03-25 18:39:37 +03:00
|
|
|
nsRange* aRange) const {
|
2013-12-13 20:26:35 +04:00
|
|
|
DOMPoint startPoint = OffsetToDOMPoint(aStartOffset);
|
|
|
|
if (!startPoint.node) return false;
|
|
|
|
|
2015-03-03 22:25:52 +03:00
|
|
|
// HyperTextAccessible manages pseudo elements generated by ::before or
|
|
|
|
// ::after. However, contents of them are not in the DOM tree normally.
|
|
|
|
// Therefore, they are not selectable and editable. So, when this creates
|
|
|
|
// a DOM range, it should not start from nor end in any pseudo contents.
|
|
|
|
|
|
|
|
nsIContent* container = GetElementAsContentOf(startPoint.node);
|
|
|
|
DOMPoint startPointForDOMRange =
|
|
|
|
ClosestNotGeneratedDOMPoint(startPoint, container);
|
|
|
|
aRange->SetStart(startPointForDOMRange.node, startPointForDOMRange.idx);
|
|
|
|
|
|
|
|
// If the caller wants collapsed range, let's collapse the range to its start.
|
2013-12-13 20:26:35 +04:00
|
|
|
if (aStartOffset == aEndOffset) {
|
2015-03-03 22:25:52 +03:00
|
|
|
aRange->Collapse(true);
|
2013-12-13 20:26:35 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
DOMPoint endPoint = OffsetToDOMPoint(aEndOffset);
|
|
|
|
if (!endPoint.node) return false;
|
|
|
|
|
2015-03-03 22:25:52 +03:00
|
|
|
if (startPoint.node != endPoint.node) {
|
|
|
|
container = GetElementAsContentOf(endPoint.node);
|
|
|
|
}
|
|
|
|
|
|
|
|
DOMPoint endPointForDOMRange =
|
|
|
|
ClosestNotGeneratedDOMPoint(endPoint, container);
|
|
|
|
aRange->SetEnd(endPointForDOMRange.node, endPointForDOMRange.idx);
|
2013-12-13 20:26:35 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-03-25 18:39:37 +03:00
|
|
|
DOMPoint HyperTextAccessible::OffsetToDOMPoint(int32_t aOffset) const {
|
2013-12-13 20:26:35 +04:00
|
|
|
// 0 offset is valid even if no children. In this case the associated editor
|
|
|
|
// is empty so return a DOM point for editor root element.
|
|
|
|
if (aOffset == 0) {
|
2017-08-07 11:42:50 +03:00
|
|
|
RefPtr<TextEditor> textEditor = GetEditor();
|
|
|
|
if (textEditor) {
|
2018-07-18 11:51:49 +03:00
|
|
|
if (textEditor->IsEmpty()) {
|
2017-08-07 11:42:50 +03:00
|
|
|
return DOMPoint(textEditor->GetRoot(), 0);
|
2008-08-28 18:48:41 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-13 20:26:35 +04:00
|
|
|
int32_t childIdx = GetChildIndexAtOffset(aOffset);
|
|
|
|
if (childIdx == -1) return DOMPoint();
|
2007-09-25 09:48:51 +04:00
|
|
|
|
2013-12-13 20:26:35 +04:00
|
|
|
Accessible* child = GetChildAt(childIdx);
|
|
|
|
int32_t innerOffset = aOffset - GetChildOffset(childIdx);
|
2007-09-25 09:48:51 +04:00
|
|
|
|
2016-03-05 20:26:18 +03:00
|
|
|
// A text leaf case.
|
2013-12-13 20:26:35 +04:00
|
|
|
if (child->IsTextLeaf()) {
|
2016-03-05 20:26:18 +03:00
|
|
|
// The point is inside the text node. This is always true for any text leaf
|
|
|
|
// except a last child one. See assertion below.
|
|
|
|
if (aOffset < GetChildOffset(childIdx + 1)) {
|
|
|
|
nsIContent* content = child->GetContent();
|
|
|
|
int32_t idx = 0;
|
|
|
|
if (NS_FAILED(RenderedToContentOffset(content->GetPrimaryFrame(),
|
|
|
|
innerOffset, &idx)))
|
|
|
|
return DOMPoint();
|
|
|
|
|
|
|
|
return DOMPoint(content, idx);
|
|
|
|
}
|
2007-09-25 09:48:51 +04:00
|
|
|
|
2016-03-05 20:26:18 +03:00
|
|
|
// Set the DOM point right after the text node.
|
|
|
|
MOZ_ASSERT(static_cast<uint32_t>(aOffset) == CharacterCount());
|
|
|
|
innerOffset = 1;
|
2013-12-13 20:26:35 +04:00
|
|
|
}
|
2007-09-25 09:48:51 +04:00
|
|
|
|
2013-12-13 20:26:35 +04:00
|
|
|
// Case of embedded object. The point is either before or after the element.
|
|
|
|
NS_ASSERTION(innerOffset == 0 || innerOffset == 1, "A wrong inner offset!");
|
|
|
|
nsINode* node = child->GetNode();
|
|
|
|
nsINode* parentNode = node->GetParentNode();
|
2018-01-23 16:30:18 +03:00
|
|
|
return parentNode ? DOMPoint(parentNode,
|
|
|
|
parentNode->ComputeIndexOf(node) + innerOffset)
|
2013-12-13 20:26:35 +04:00
|
|
|
: DOMPoint();
|
2007-09-25 09:48:51 +04:00
|
|
|
}
|
|
|
|
|
2015-03-03 22:25:52 +03:00
|
|
|
DOMPoint HyperTextAccessible::ClosestNotGeneratedDOMPoint(
|
2020-03-25 18:39:37 +03:00
|
|
|
const DOMPoint& aDOMPoint, nsIContent* aElementContent) const {
|
2015-03-03 22:25:52 +03:00
|
|
|
MOZ_ASSERT(aDOMPoint.node, "The node must not be null");
|
|
|
|
|
|
|
|
// ::before pseudo element
|
|
|
|
if (aElementContent &&
|
2016-08-19 06:17:00 +03:00
|
|
|
aElementContent->IsGeneratedContentContainerForBefore()) {
|
2015-03-03 22:25:52 +03:00
|
|
|
MOZ_ASSERT(aElementContent->GetParent(),
|
|
|
|
"::before must have parent element");
|
|
|
|
// The first child of its parent (i.e., immediately after the ::before) is
|
|
|
|
// good point for a DOM range.
|
|
|
|
return DOMPoint(aElementContent->GetParent(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ::after pseudo element
|
|
|
|
if (aElementContent &&
|
2016-08-19 06:17:00 +03:00
|
|
|
aElementContent->IsGeneratedContentContainerForAfter()) {
|
2015-03-03 22:25:52 +03:00
|
|
|
MOZ_ASSERT(aElementContent->GetParent(),
|
|
|
|
"::after must have parent element");
|
|
|
|
// The end of its parent (i.e., immediately before the ::after) is good
|
|
|
|
// point for a DOM range.
|
|
|
|
return DOMPoint(aElementContent->GetParent(),
|
|
|
|
aElementContent->GetParent()->GetChildCount());
|
|
|
|
}
|
|
|
|
|
|
|
|
return aDOMPoint;
|
|
|
|
}
|
|
|
|
|
2014-04-26 06:42:19 +04:00
|
|
|
uint32_t HyperTextAccessible::FindOffset(uint32_t aOffset,
|
|
|
|
nsDirection aDirection,
|
2013-12-06 22:47:00 +04:00
|
|
|
nsSelectionAmount aAmount,
|
|
|
|
EWordMovementType aWordMovementType) {
|
2014-05-27 20:07:00 +04:00
|
|
|
NS_ASSERTION(aDirection == eDirPrevious || aAmount != eSelectBeginLine,
|
|
|
|
"eSelectBeginLine should only be used with eDirPrevious");
|
|
|
|
|
2013-12-17 06:32:12 +04:00
|
|
|
// Find a leaf accessible frame to start with. PeekOffset wants this.
|
|
|
|
HyperTextAccessible* text = this;
|
|
|
|
Accessible* child = nullptr;
|
|
|
|
int32_t innerOffset = aOffset;
|
|
|
|
|
|
|
|
do {
|
|
|
|
int32_t childIdx = text->GetChildIndexAtOffset(innerOffset);
|
2014-08-13 00:25:40 +04:00
|
|
|
|
|
|
|
// We can have an empty text leaf as our only child. Since empty text
|
|
|
|
// leaves are not accessible we then have no children, but 0 is a valid
|
|
|
|
// innerOffset.
|
|
|
|
if (childIdx == -1) {
|
|
|
|
NS_ASSERTION(innerOffset == 0 && !text->ChildCount(), "No childIdx?");
|
|
|
|
return DOMPointToOffset(text->GetNode(), 0, aDirection == eDirNext);
|
|
|
|
}
|
2006-07-12 17:14:53 +04:00
|
|
|
|
2013-12-17 06:32:12 +04:00
|
|
|
child = text->GetChildAt(childIdx);
|
2014-02-05 19:21:32 +04:00
|
|
|
|
|
|
|
// HTML list items may need special processing because PeekOffset doesn't
|
|
|
|
// work with list bullets.
|
|
|
|
if (text->IsHTMLListItem()) {
|
|
|
|
HTMLLIAccessible* li = text->AsHTMLListItem();
|
|
|
|
if (child == li->Bullet()) {
|
2014-05-27 20:07:00 +04:00
|
|
|
// XXX: the logic is broken for multichar bullets in moving by
|
|
|
|
// char/cluster/word cases.
|
|
|
|
if (text != this) {
|
|
|
|
return aDirection == eDirPrevious ? TransformOffset(text, 0, false)
|
|
|
|
: TransformOffset(text, 1, true);
|
|
|
|
}
|
2014-02-05 19:21:32 +04:00
|
|
|
if (aDirection == eDirPrevious) return 0;
|
|
|
|
|
2014-05-27 20:07:00 +04:00
|
|
|
uint32_t nextOffset = GetChildOffset(1);
|
|
|
|
if (nextOffset == 0) return 0;
|
2014-02-05 19:21:32 +04:00
|
|
|
|
2014-05-27 20:07:00 +04:00
|
|
|
switch (aAmount) {
|
|
|
|
case eSelectLine:
|
|
|
|
case eSelectEndLine:
|
|
|
|
// Ask a text leaf next (if not empty) to the bullet for an offset
|
|
|
|
// since list item may be multiline.
|
|
|
|
return nextOffset < CharacterCount()
|
|
|
|
? FindOffset(nextOffset, aDirection, aAmount,
|
|
|
|
aWordMovementType)
|
|
|
|
: nextOffset;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return nextOffset;
|
2014-02-05 19:21:32 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-17 06:32:12 +04:00
|
|
|
innerOffset -= text->GetChildOffset(childIdx);
|
|
|
|
|
|
|
|
text = child->AsHyperText();
|
|
|
|
} while (text);
|
2007-08-04 05:12:24 +04:00
|
|
|
|
2013-12-17 06:32:12 +04:00
|
|
|
nsIFrame* childFrame = child->GetFrame();
|
2014-04-26 06:42:19 +04:00
|
|
|
if (!childFrame) {
|
|
|
|
NS_ERROR("No child frame");
|
|
|
|
return 0;
|
|
|
|
}
|
2008-11-01 06:58:07 +03:00
|
|
|
|
2013-12-17 06:32:12 +04:00
|
|
|
int32_t innerContentOffset = innerOffset;
|
|
|
|
if (child->IsTextLeaf()) {
|
2017-04-30 18:30:08 +03:00
|
|
|
NS_ASSERTION(childFrame->IsTextFrame(), "Wrong frame!");
|
2013-12-17 06:32:12 +04:00
|
|
|
RenderedToContentOffset(childFrame, innerOffset, &innerContentOffset);
|
2007-08-29 11:12:09 +04:00
|
|
|
}
|
2007-08-04 05:12:24 +04:00
|
|
|
|
2013-12-17 06:32:12 +04:00
|
|
|
nsIFrame* frameAtOffset = childFrame;
|
|
|
|
int32_t unusedOffsetInFrame = 0;
|
|
|
|
childFrame->GetChildFrameContainingOffset(
|
|
|
|
innerContentOffset, true, &unusedOffsetInFrame, &frameAtOffset);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-12-06 22:47:00 +04:00
|
|
|
const bool kIsJumpLinesOk = true; // okay to jump lines
|
|
|
|
const bool kIsScrollViewAStop = false; // do not stop at scroll views
|
|
|
|
const bool kIsKeyboardSelect = true; // is keyboard selection
|
|
|
|
const bool kIsVisualBidi = false; // use visual order for bidi text
|
2013-12-17 06:32:12 +04:00
|
|
|
nsPeekOffsetStruct pos(
|
|
|
|
aAmount, aDirection, innerContentOffset, nsPoint(0, 0), kIsJumpLinesOk,
|
2013-12-06 22:47:00 +04:00
|
|
|
kIsScrollViewAStop, kIsKeyboardSelect, kIsVisualBidi, false,
|
2019-02-23 00:12:48 +03:00
|
|
|
nsPeekOffsetStruct::ForceEditableRegion::No, aWordMovementType, false);
|
2013-12-17 06:32:12 +04:00
|
|
|
nsresult rv = frameAtOffset->PeekOffset(&pos);
|
2006-07-12 17:14:53 +04:00
|
|
|
|
2013-07-26 18:41:25 +04:00
|
|
|
// PeekOffset fails on last/first lines of the text in certain cases.
|
2019-09-06 02:41:36 +03:00
|
|
|
bool fallBackToSelectEndLine = false;
|
2013-07-26 18:41:25 +04:00
|
|
|
if (NS_FAILED(rv) && aAmount == eSelectLine) {
|
2019-09-06 02:41:36 +03:00
|
|
|
fallBackToSelectEndLine = aDirection == eDirNext;
|
|
|
|
pos.mAmount = fallBackToSelectEndLine ? eSelectEndLine : eSelectBeginLine;
|
2013-12-06 22:47:00 +04:00
|
|
|
frameAtOffset->PeekOffset(&pos);
|
2013-07-26 18:41:25 +04:00
|
|
|
}
|
2014-04-26 06:42:19 +04:00
|
|
|
if (!pos.mResultContent) {
|
|
|
|
NS_ERROR("No result content!");
|
|
|
|
return 0;
|
|
|
|
}
|
2007-03-06 16:44:42 +03:00
|
|
|
|
2014-02-04 04:56:45 +04:00
|
|
|
// Turn the resulting DOM point into an offset.
|
2014-04-26 06:42:19 +04:00
|
|
|
uint32_t hyperTextOffset = DOMPointToOffset(
|
|
|
|
pos.mResultContent, pos.mContentOffset, aDirection == eDirNext);
|
2007-03-06 16:44:42 +03:00
|
|
|
|
2019-09-06 02:41:36 +03:00
|
|
|
if (fallBackToSelectEndLine && IsLineEndCharAt(hyperTextOffset)) {
|
|
|
|
// We used eSelectEndLine, but the caller requested eSelectLine.
|
|
|
|
// If there's a '\n' at the end of the line, eSelectEndLine will stop
|
|
|
|
// on it rather than after it. This is not what we want, since the caller
|
|
|
|
// wants the next line, not the same line.
|
|
|
|
++hyperTextOffset;
|
|
|
|
}
|
|
|
|
|
2014-02-05 19:21:32 +04:00
|
|
|
if (aDirection == eDirPrevious) {
|
|
|
|
// If we reached the end during search, this means we didn't find the DOM
|
|
|
|
// point and we're actually at the start of the paragraph
|
|
|
|
if (hyperTextOffset == CharacterCount()) return 0;
|
|
|
|
|
|
|
|
// PeekOffset stops right before bullet so return 0 to workaround it.
|
2014-05-27 20:07:00 +04:00
|
|
|
if (IsHTMLListItem() && aAmount == eSelectBeginLine &&
|
|
|
|
hyperTextOffset > 0) {
|
|
|
|
Accessible* prevOffsetChild = GetChildAtOffset(hyperTextOffset - 1);
|
|
|
|
if (prevOffsetChild == AsHTMLListItem()->Bullet()) return 0;
|
|
|
|
}
|
2014-02-05 19:21:32 +04:00
|
|
|
}
|
2006-06-21 17:29:10 +04:00
|
|
|
|
2006-07-12 17:14:53 +04:00
|
|
|
return hyperTextOffset;
|
2006-06-21 17:29:10 +04:00
|
|
|
}
|
|
|
|
|
2014-04-26 06:42:19 +04:00
|
|
|
uint32_t HyperTextAccessible::FindLineBoundary(
|
2013-07-16 21:13:34 +04:00
|
|
|
uint32_t aOffset, EWhichLineBoundary aWhichLineBoundary) {
|
|
|
|
// Note: empty last line doesn't have own frame (a previous line contains '\n'
|
|
|
|
// character instead) thus when it makes a difference we need to process this
|
|
|
|
// case separately (otherwise operations are performed on previous line).
|
|
|
|
switch (aWhichLineBoundary) {
|
|
|
|
case ePrevLineBegin: {
|
|
|
|
// Fetch a previous line and move to its start (as arrow up and home keys
|
|
|
|
// were pressed).
|
|
|
|
if (IsEmptyLastLineOffset(aOffset))
|
|
|
|
return FindOffset(aOffset, eDirPrevious, eSelectBeginLine);
|
|
|
|
|
2014-04-26 06:42:19 +04:00
|
|
|
uint32_t tmpOffset = FindOffset(aOffset, eDirPrevious, eSelectLine);
|
2013-07-16 21:13:34 +04:00
|
|
|
return FindOffset(tmpOffset, eDirPrevious, eSelectBeginLine);
|
|
|
|
}
|
|
|
|
|
|
|
|
case ePrevLineEnd: {
|
|
|
|
if (IsEmptyLastLineOffset(aOffset)) return aOffset - 1;
|
|
|
|
|
|
|
|
// If offset is at first line then return 0 (first line start).
|
2014-04-26 06:42:19 +04:00
|
|
|
uint32_t tmpOffset = FindOffset(aOffset, eDirPrevious, eSelectBeginLine);
|
2013-07-16 21:13:34 +04:00
|
|
|
if (tmpOffset == 0) return 0;
|
|
|
|
|
|
|
|
// Otherwise move to end of previous line (as arrow up and end keys were
|
|
|
|
// pressed).
|
|
|
|
tmpOffset = FindOffset(aOffset, eDirPrevious, eSelectLine);
|
|
|
|
return FindOffset(tmpOffset, eDirNext, eSelectEndLine);
|
|
|
|
}
|
|
|
|
|
|
|
|
case eThisLineBegin:
|
|
|
|
if (IsEmptyLastLineOffset(aOffset)) return aOffset;
|
|
|
|
|
|
|
|
// Move to begin of the current line (as home key was pressed).
|
|
|
|
return FindOffset(aOffset, eDirPrevious, eSelectBeginLine);
|
|
|
|
|
|
|
|
case eThisLineEnd:
|
|
|
|
if (IsEmptyLastLineOffset(aOffset)) return aOffset;
|
|
|
|
|
|
|
|
// Move to end of the current line (as end key was pressed).
|
|
|
|
return FindOffset(aOffset, eDirNext, eSelectEndLine);
|
|
|
|
|
|
|
|
case eNextLineBegin: {
|
|
|
|
if (IsEmptyLastLineOffset(aOffset)) return aOffset;
|
|
|
|
|
|
|
|
// Move to begin of the next line if any (arrow down and home keys),
|
|
|
|
// otherwise end of the current line (arrow down only).
|
2014-04-26 06:42:19 +04:00
|
|
|
uint32_t tmpOffset = FindOffset(aOffset, eDirNext, eSelectLine);
|
2013-07-16 21:13:34 +04:00
|
|
|
if (tmpOffset == CharacterCount()) return tmpOffset;
|
|
|
|
|
|
|
|
return FindOffset(tmpOffset, eDirPrevious, eSelectBeginLine);
|
|
|
|
}
|
|
|
|
|
|
|
|
case eNextLineEnd: {
|
|
|
|
if (IsEmptyLastLineOffset(aOffset)) return aOffset;
|
|
|
|
|
|
|
|
// Move to next line end (as down arrow and end key were pressed).
|
2014-04-26 06:42:19 +04:00
|
|
|
uint32_t tmpOffset = FindOffset(aOffset, eDirNext, eSelectLine);
|
|
|
|
if (tmpOffset == CharacterCount()) return tmpOffset;
|
|
|
|
|
|
|
|
return FindOffset(tmpOffset, eDirNext, eSelectEndLine);
|
2013-07-16 21:13:34 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-26 06:42:19 +04:00
|
|
|
return 0;
|
2013-07-16 21:13:34 +04:00
|
|
|
}
|
|
|
|
|
2013-11-18 17:19:33 +04:00
|
|
|
void HyperTextAccessible::TextBeforeOffset(int32_t aOffset,
|
|
|
|
AccessibleTextBoundary aBoundaryType,
|
|
|
|
int32_t* aStartOffset,
|
|
|
|
int32_t* aEndOffset,
|
|
|
|
nsAString& aText) {
|
|
|
|
*aStartOffset = *aEndOffset = 0;
|
|
|
|
aText.Truncate();
|
|
|
|
|
2014-05-17 03:16:34 +04:00
|
|
|
index_t convertedOffset = ConvertMagicOffset(aOffset);
|
|
|
|
if (!convertedOffset.IsValid() || convertedOffset > CharacterCount()) {
|
|
|
|
NS_ERROR("Wrong in offset!");
|
2013-11-18 17:19:33 +04:00
|
|
|
return;
|
|
|
|
}
|
2013-03-31 17:39:29 +04:00
|
|
|
|
2014-04-26 06:42:19 +04:00
|
|
|
uint32_t adjustedOffset = convertedOffset;
|
2013-10-01 22:23:13 +04:00
|
|
|
if (aOffset == nsIAccessibleText::TEXT_OFFSET_CARET)
|
|
|
|
adjustedOffset = AdjustCaretOffset(adjustedOffset);
|
|
|
|
|
2013-03-31 17:39:29 +04:00
|
|
|
switch (aBoundaryType) {
|
2014-10-22 04:49:28 +04:00
|
|
|
case nsIAccessibleText::BOUNDARY_CHAR:
|
2013-12-19 23:28:51 +04:00
|
|
|
if (convertedOffset != 0)
|
|
|
|
CharAt(convertedOffset - 1, aText, aStartOffset, aEndOffset);
|
2013-11-18 17:19:33 +04:00
|
|
|
break;
|
2013-03-31 17:39:29 +04:00
|
|
|
|
2014-10-22 04:49:28 +04:00
|
|
|
case nsIAccessibleText::BOUNDARY_WORD_START: {
|
2013-05-17 08:06:13 +04:00
|
|
|
// If the offset is a word start (except text length offset) then move
|
|
|
|
// backward to find a start offset (end offset is the given offset).
|
|
|
|
// Otherwise move backward twice to find both start and end offsets.
|
2013-10-01 22:23:13 +04:00
|
|
|
if (adjustedOffset == CharacterCount()) {
|
|
|
|
*aEndOffset =
|
|
|
|
FindWordBoundary(adjustedOffset, eDirPrevious, eStartWord);
|
2013-05-17 08:06:13 +04:00
|
|
|
*aStartOffset = FindWordBoundary(*aEndOffset, eDirPrevious, eStartWord);
|
|
|
|
} else {
|
2013-10-01 22:23:13 +04:00
|
|
|
*aStartOffset =
|
|
|
|
FindWordBoundary(adjustedOffset, eDirPrevious, eStartWord);
|
2013-05-17 08:06:13 +04:00
|
|
|
*aEndOffset = FindWordBoundary(*aStartOffset, eDirNext, eStartWord);
|
2014-04-26 06:42:19 +04:00
|
|
|
if (*aEndOffset != static_cast<int32_t>(adjustedOffset)) {
|
2013-05-17 08:06:13 +04:00
|
|
|
*aEndOffset = *aStartOffset;
|
|
|
|
*aStartOffset =
|
|
|
|
FindWordBoundary(*aEndOffset, eDirPrevious, eStartWord);
|
|
|
|
}
|
2013-03-31 17:39:29 +04:00
|
|
|
}
|
2013-11-18 17:19:33 +04:00
|
|
|
TextSubstring(*aStartOffset, *aEndOffset, aText);
|
|
|
|
break;
|
2013-03-31 17:39:29 +04:00
|
|
|
}
|
2011-02-03 17:29:12 +03:00
|
|
|
|
2014-10-22 04:49:28 +04:00
|
|
|
case nsIAccessibleText::BOUNDARY_WORD_END: {
|
2013-03-31 17:39:29 +04:00
|
|
|
// Move word backward twice to find start and end offsets.
|
2013-11-01 07:26:27 +04:00
|
|
|
*aEndOffset = FindWordBoundary(convertedOffset, eDirPrevious, eEndWord);
|
2013-03-31 17:39:29 +04:00
|
|
|
*aStartOffset = FindWordBoundary(*aEndOffset, eDirPrevious, eEndWord);
|
2013-11-18 17:19:33 +04:00
|
|
|
TextSubstring(*aStartOffset, *aEndOffset, aText);
|
|
|
|
break;
|
2013-03-31 17:39:29 +04:00
|
|
|
}
|
|
|
|
|
2014-10-22 04:49:28 +04:00
|
|
|
case nsIAccessibleText::BOUNDARY_LINE_START:
|
2013-10-01 22:23:13 +04:00
|
|
|
*aStartOffset = FindLineBoundary(adjustedOffset, ePrevLineBegin);
|
|
|
|
*aEndOffset = FindLineBoundary(adjustedOffset, eThisLineBegin);
|
2013-11-18 17:19:33 +04:00
|
|
|
TextSubstring(*aStartOffset, *aEndOffset, aText);
|
|
|
|
break;
|
2013-07-11 17:16:18 +04:00
|
|
|
|
2014-10-22 04:49:28 +04:00
|
|
|
case nsIAccessibleText::BOUNDARY_LINE_END: {
|
2013-10-01 22:23:13 +04:00
|
|
|
*aEndOffset = FindLineBoundary(adjustedOffset, ePrevLineEnd);
|
2013-07-24 22:11:02 +04:00
|
|
|
int32_t tmpOffset = *aEndOffset;
|
|
|
|
// Adjust offset if line is wrapped.
|
|
|
|
if (*aEndOffset != 0 && !IsLineEndCharAt(*aEndOffset)) tmpOffset--;
|
|
|
|
|
|
|
|
*aStartOffset = FindLineBoundary(tmpOffset, ePrevLineEnd);
|
2013-11-18 17:19:33 +04:00
|
|
|
TextSubstring(*aStartOffset, *aEndOffset, aText);
|
|
|
|
break;
|
2013-07-24 22:11:02 +04:00
|
|
|
}
|
2013-03-31 17:39:29 +04:00
|
|
|
}
|
2006-06-21 17:29:10 +04:00
|
|
|
}
|
|
|
|
|
2013-11-18 17:19:33 +04:00
|
|
|
void HyperTextAccessible::TextAtOffset(int32_t aOffset,
|
|
|
|
AccessibleTextBoundary aBoundaryType,
|
|
|
|
int32_t* aStartOffset,
|
|
|
|
int32_t* aEndOffset, nsAString& aText) {
|
|
|
|
*aStartOffset = *aEndOffset = 0;
|
|
|
|
aText.Truncate();
|
2013-03-24 04:57:06 +04:00
|
|
|
|
2014-04-26 06:42:19 +04:00
|
|
|
uint32_t adjustedOffset = ConvertMagicOffset(aOffset);
|
|
|
|
if (adjustedOffset == std::numeric_limits<uint32_t>::max()) {
|
2013-11-18 17:19:33 +04:00
|
|
|
NS_ERROR("Wrong given offset!");
|
|
|
|
return;
|
|
|
|
}
|
2013-03-31 17:39:29 +04:00
|
|
|
|
2013-03-24 04:57:06 +04:00
|
|
|
switch (aBoundaryType) {
|
2014-10-22 04:49:28 +04:00
|
|
|
case nsIAccessibleText::BOUNDARY_CHAR:
|
2013-12-28 23:14:08 +04:00
|
|
|
// Return no char if caret is at the end of wrapped line (case of no line
|
|
|
|
// end character). Returning a next line char is confusing for AT.
|
|
|
|
if (aOffset == nsIAccessibleText::TEXT_OFFSET_CARET &&
|
|
|
|
IsCaretAtEndOfLine())
|
|
|
|
*aStartOffset = *aEndOffset = adjustedOffset;
|
|
|
|
else
|
|
|
|
CharAt(adjustedOffset, aText, aStartOffset, aEndOffset);
|
2013-11-18 17:19:33 +04:00
|
|
|
break;
|
2013-03-24 04:57:06 +04:00
|
|
|
|
2014-10-22 04:49:28 +04:00
|
|
|
case nsIAccessibleText::BOUNDARY_WORD_START:
|
2013-10-01 22:23:13 +04:00
|
|
|
if (aOffset == nsIAccessibleText::TEXT_OFFSET_CARET)
|
|
|
|
adjustedOffset = AdjustCaretOffset(adjustedOffset);
|
|
|
|
|
|
|
|
*aEndOffset = FindWordBoundary(adjustedOffset, eDirNext, eStartWord);
|
2013-03-31 17:39:29 +04:00
|
|
|
*aStartOffset = FindWordBoundary(*aEndOffset, eDirPrevious, eStartWord);
|
2013-11-18 17:19:33 +04:00
|
|
|
TextSubstring(*aStartOffset, *aEndOffset, aText);
|
|
|
|
break;
|
2013-03-31 17:39:29 +04:00
|
|
|
|
2014-10-22 04:49:28 +04:00
|
|
|
case nsIAccessibleText::BOUNDARY_WORD_END:
|
2013-05-07 13:18:37 +04:00
|
|
|
// Ignore the spec and follow what WebKitGtk does because Orca expects it,
|
|
|
|
// i.e. return a next word at word end offset of the current word
|
|
|
|
// (WebKitGtk behavior) instead the current word (AKT spec).
|
2013-10-01 22:23:13 +04:00
|
|
|
*aEndOffset = FindWordBoundary(adjustedOffset, eDirNext, eEndWord);
|
2013-05-07 13:18:37 +04:00
|
|
|
*aStartOffset = FindWordBoundary(*aEndOffset, eDirPrevious, eEndWord);
|
2013-11-18 17:19:33 +04:00
|
|
|
TextSubstring(*aStartOffset, *aEndOffset, aText);
|
|
|
|
break;
|
2013-03-24 04:57:06 +04:00
|
|
|
|
2014-10-22 04:49:28 +04:00
|
|
|
case nsIAccessibleText::BOUNDARY_LINE_START:
|
2013-07-09 21:32:07 +04:00
|
|
|
if (aOffset == nsIAccessibleText::TEXT_OFFSET_CARET)
|
2013-10-01 22:23:13 +04:00
|
|
|
adjustedOffset = AdjustCaretOffset(adjustedOffset);
|
2013-07-09 21:32:07 +04:00
|
|
|
|
2013-10-01 22:23:13 +04:00
|
|
|
*aStartOffset = FindLineBoundary(adjustedOffset, eThisLineBegin);
|
|
|
|
*aEndOffset = FindLineBoundary(adjustedOffset, eNextLineBegin);
|
2013-11-18 17:19:33 +04:00
|
|
|
TextSubstring(*aStartOffset, *aEndOffset, aText);
|
|
|
|
break;
|
2013-07-08 19:26:09 +04:00
|
|
|
|
2014-10-22 04:49:28 +04:00
|
|
|
case nsIAccessibleText::BOUNDARY_LINE_END:
|
2013-07-09 21:32:07 +04:00
|
|
|
if (aOffset == nsIAccessibleText::TEXT_OFFSET_CARET)
|
2013-10-01 22:23:13 +04:00
|
|
|
adjustedOffset = AdjustCaretOffset(adjustedOffset);
|
2013-07-09 21:32:07 +04:00
|
|
|
|
2013-07-15 17:01:03 +04:00
|
|
|
// In contrast to word end boundary we follow the spec here.
|
2013-10-01 22:23:13 +04:00
|
|
|
*aStartOffset = FindLineBoundary(adjustedOffset, ePrevLineEnd);
|
|
|
|
*aEndOffset = FindLineBoundary(adjustedOffset, eThisLineEnd);
|
2013-11-18 17:19:33 +04:00
|
|
|
TextSubstring(*aStartOffset, *aEndOffset, aText);
|
|
|
|
break;
|
2013-03-24 04:57:06 +04:00
|
|
|
}
|
2006-06-21 17:29:10 +04:00
|
|
|
}
|
|
|
|
|
2013-11-18 17:19:33 +04:00
|
|
|
void HyperTextAccessible::TextAfterOffset(int32_t aOffset,
|
|
|
|
AccessibleTextBoundary aBoundaryType,
|
|
|
|
int32_t* aStartOffset,
|
|
|
|
int32_t* aEndOffset,
|
|
|
|
nsAString& aText) {
|
|
|
|
*aStartOffset = *aEndOffset = 0;
|
|
|
|
aText.Truncate();
|
|
|
|
|
2014-05-17 03:16:34 +04:00
|
|
|
index_t convertedOffset = ConvertMagicOffset(aOffset);
|
|
|
|
if (!convertedOffset.IsValid() || convertedOffset > CharacterCount()) {
|
|
|
|
NS_ERROR("Wrong in offset!");
|
2013-11-18 17:19:33 +04:00
|
|
|
return;
|
|
|
|
}
|
2011-02-03 17:29:12 +03:00
|
|
|
|
2014-04-26 06:42:19 +04:00
|
|
|
uint32_t adjustedOffset = convertedOffset;
|
2013-10-01 22:23:13 +04:00
|
|
|
if (aOffset == nsIAccessibleText::TEXT_OFFSET_CARET)
|
|
|
|
adjustedOffset = AdjustCaretOffset(adjustedOffset);
|
|
|
|
|
2013-05-15 12:26:17 +04:00
|
|
|
switch (aBoundaryType) {
|
2014-10-22 04:49:28 +04:00
|
|
|
case nsIAccessibleText::BOUNDARY_CHAR:
|
2013-12-28 23:14:08 +04:00
|
|
|
// If caret is at the end of wrapped line (case of no line end character)
|
|
|
|
// then char after the offset is a first char at next line.
|
|
|
|
if (adjustedOffset >= CharacterCount())
|
|
|
|
*aStartOffset = *aEndOffset = CharacterCount();
|
|
|
|
else
|
|
|
|
CharAt(adjustedOffset + 1, aText, aStartOffset, aEndOffset);
|
2013-11-18 17:19:33 +04:00
|
|
|
break;
|
2013-05-15 12:26:17 +04:00
|
|
|
|
2014-10-22 04:49:28 +04:00
|
|
|
case nsIAccessibleText::BOUNDARY_WORD_START:
|
2013-05-15 12:26:17 +04:00
|
|
|
// Move word forward twice to find start and end offsets.
|
2013-10-01 22:23:13 +04:00
|
|
|
*aStartOffset = FindWordBoundary(adjustedOffset, eDirNext, eStartWord);
|
2013-05-15 12:26:17 +04:00
|
|
|
*aEndOffset = FindWordBoundary(*aStartOffset, eDirNext, eStartWord);
|
2013-11-18 17:19:33 +04:00
|
|
|
TextSubstring(*aStartOffset, *aEndOffset, aText);
|
|
|
|
break;
|
2013-05-15 12:26:17 +04:00
|
|
|
|
2014-10-22 04:49:28 +04:00
|
|
|
case nsIAccessibleText::BOUNDARY_WORD_END:
|
2013-05-15 12:26:17 +04:00
|
|
|
// If the offset is a word end (except 0 offset) then move forward to find
|
|
|
|
// end offset (start offset is the given offset). Otherwise move forward
|
|
|
|
// twice to find both start and end offsets.
|
2013-11-01 07:26:27 +04:00
|
|
|
if (convertedOffset == 0) {
|
|
|
|
*aStartOffset = FindWordBoundary(convertedOffset, eDirNext, eEndWord);
|
2013-05-15 12:26:17 +04:00
|
|
|
*aEndOffset = FindWordBoundary(*aStartOffset, eDirNext, eEndWord);
|
|
|
|
} else {
|
2013-11-01 07:26:27 +04:00
|
|
|
*aEndOffset = FindWordBoundary(convertedOffset, eDirNext, eEndWord);
|
2013-05-15 12:26:17 +04:00
|
|
|
*aStartOffset = FindWordBoundary(*aEndOffset, eDirPrevious, eEndWord);
|
2014-04-26 06:42:19 +04:00
|
|
|
if (*aStartOffset != static_cast<int32_t>(convertedOffset)) {
|
2013-05-15 12:26:17 +04:00
|
|
|
*aStartOffset = *aEndOffset;
|
|
|
|
*aEndOffset = FindWordBoundary(*aStartOffset, eDirNext, eEndWord);
|
|
|
|
}
|
|
|
|
}
|
2013-11-18 17:19:33 +04:00
|
|
|
TextSubstring(*aStartOffset, *aEndOffset, aText);
|
|
|
|
break;
|
2013-05-15 12:26:17 +04:00
|
|
|
|
2014-10-22 04:49:28 +04:00
|
|
|
case nsIAccessibleText::BOUNDARY_LINE_START:
|
2013-10-01 22:23:13 +04:00
|
|
|
*aStartOffset = FindLineBoundary(adjustedOffset, eNextLineBegin);
|
2013-07-16 21:13:34 +04:00
|
|
|
*aEndOffset = FindLineBoundary(*aStartOffset, eNextLineBegin);
|
2013-11-18 17:19:33 +04:00
|
|
|
TextSubstring(*aStartOffset, *aEndOffset, aText);
|
|
|
|
break;
|
2013-07-15 19:56:38 +04:00
|
|
|
|
2014-10-22 04:49:28 +04:00
|
|
|
case nsIAccessibleText::BOUNDARY_LINE_END:
|
2013-10-01 22:23:13 +04:00
|
|
|
*aStartOffset = FindLineBoundary(adjustedOffset, eThisLineEnd);
|
|
|
|
*aEndOffset = FindLineBoundary(adjustedOffset, eNextLineEnd);
|
2013-11-18 17:19:33 +04:00
|
|
|
TextSubstring(*aStartOffset, *aEndOffset, aText);
|
|
|
|
break;
|
2013-05-15 12:26:17 +04:00
|
|
|
}
|
2006-06-21 17:29:10 +04:00
|
|
|
}
|
|
|
|
|
2013-11-18 17:19:33 +04:00
|
|
|
already_AddRefed<nsIPersistentProperties> HyperTextAccessible::TextAttributes(
|
|
|
|
bool aIncludeDefAttrs, int32_t aOffset, int32_t* aStartOffset,
|
|
|
|
int32_t* aEndOffset) {
|
2010-05-25 12:40:26 +04:00
|
|
|
// 1. Get each attribute and its ranges one after another.
|
2008-07-17 16:06:24 +04:00
|
|
|
// 2. As we get each new attribute, we pass the current start and end offsets
|
|
|
|
// as in/out parameters. In other words, as attributes are collected,
|
|
|
|
// the attribute range itself can only stay the same or get smaller.
|
2006-06-21 17:29:10 +04:00
|
|
|
|
2013-11-18 17:19:33 +04:00
|
|
|
*aStartOffset = *aEndOffset = 0;
|
2014-05-17 03:16:34 +04:00
|
|
|
index_t offset = ConvertMagicOffset(aOffset);
|
|
|
|
if (!offset.IsValid() || offset > CharacterCount()) {
|
|
|
|
NS_ERROR("Wrong in offset!");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-09-15 19:58:31 +03:00
|
|
|
RefPtr<nsPersistentProperties> attributes = new nsPersistentProperties();
|
2010-05-21 15:27:00 +04:00
|
|
|
|
2013-01-13 00:24:13 +04:00
|
|
|
Accessible* accAtOffset = GetChildAtOffset(offset);
|
2010-08-15 15:28:49 +04:00
|
|
|
if (!accAtOffset) {
|
2010-05-25 12:40:26 +04:00
|
|
|
// Offset 0 is correct offset when accessible has empty text. Include
|
|
|
|
// default attributes if they were requested, otherwise return empty set.
|
2013-01-13 00:24:13 +04:00
|
|
|
if (offset == 0) {
|
2010-05-21 15:27:00 +04:00
|
|
|
if (aIncludeDefAttrs) {
|
2012-03-10 11:29:51 +04:00
|
|
|
TextAttrsMgr textAttrsMgr(this);
|
2013-11-18 17:19:33 +04:00
|
|
|
textAttrsMgr.GetAttributes(attributes);
|
2010-05-21 15:27:00 +04:00
|
|
|
}
|
2013-11-18 17:19:33 +04:00
|
|
|
return attributes.forget();
|
2010-05-21 15:27:00 +04:00
|
|
|
}
|
2013-11-18 17:19:33 +04:00
|
|
|
return nullptr;
|
2010-05-21 15:27:00 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t accAtOffsetIdx = accAtOffset->IndexInParent();
|
2014-04-26 06:42:19 +04:00
|
|
|
uint32_t startOffset = GetChildOffset(accAtOffsetIdx);
|
|
|
|
uint32_t endOffset = GetChildOffset(accAtOffsetIdx + 1);
|
2013-01-13 00:24:13 +04:00
|
|
|
int32_t offsetInAcc = offset - startOffset;
|
2006-07-12 17:14:53 +04:00
|
|
|
|
2012-03-10 11:29:51 +04:00
|
|
|
TextAttrsMgr textAttrsMgr(this, aIncludeDefAttrs, accAtOffset,
|
|
|
|
accAtOffsetIdx);
|
2013-11-18 17:19:33 +04:00
|
|
|
textAttrsMgr.GetAttributes(attributes, &startOffset, &endOffset);
|
2006-06-21 17:29:10 +04:00
|
|
|
|
2010-05-25 12:40:26 +04:00
|
|
|
// Compute spelling attributes on text accessible only.
|
2010-08-15 15:28:49 +04:00
|
|
|
nsIFrame* offsetFrame = accAtOffset->GetFrame();
|
2017-04-30 18:30:08 +03:00
|
|
|
if (offsetFrame && offsetFrame->IsTextFrame()) {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t nodeOffset = 0;
|
2013-11-18 17:19:33 +04:00
|
|
|
RenderedToContentOffset(offsetFrame, offsetInAcc, &nodeOffset);
|
2008-07-17 16:06:24 +04:00
|
|
|
|
2010-05-25 12:40:26 +04:00
|
|
|
// Set 'misspelled' text attribute.
|
2014-04-26 06:42:19 +04:00
|
|
|
GetSpellTextAttr(accAtOffset->GetNode(), nodeOffset, &startOffset,
|
|
|
|
&endOffset, attributes);
|
2010-05-25 12:40:26 +04:00
|
|
|
}
|
2008-07-17 16:06:24 +04:00
|
|
|
|
2010-05-25 12:40:26 +04:00
|
|
|
*aStartOffset = startOffset;
|
|
|
|
*aEndOffset = endOffset;
|
2013-11-18 17:19:33 +04:00
|
|
|
return attributes.forget();
|
2008-07-17 16:06:24 +04:00
|
|
|
}
|
|
|
|
|
2013-11-18 17:19:33 +04:00
|
|
|
already_AddRefed<nsIPersistentProperties>
|
|
|
|
HyperTextAccessible::DefaultTextAttributes() {
|
2018-09-15 19:58:31 +03:00
|
|
|
RefPtr<nsPersistentProperties> attributes = new nsPersistentProperties();
|
2008-07-17 16:06:24 +04:00
|
|
|
|
2012-03-10 11:29:51 +04:00
|
|
|
TextAttrsMgr textAttrsMgr(this);
|
2013-11-18 17:19:33 +04:00
|
|
|
textAttrsMgr.GetAttributes(attributes);
|
|
|
|
return attributes.forget();
|
2006-06-21 17:29:10 +04:00
|
|
|
}
|
|
|
|
|
2012-05-31 12:04:41 +04:00
|
|
|
int32_t HyperTextAccessible::GetLevelInternal() {
|
2019-10-16 15:32:10 +03:00
|
|
|
if (auto* heading = dom::HTMLHeadingElement::FromNode(mContent)) {
|
|
|
|
return heading->AccessibilityLevel();
|
|
|
|
}
|
2012-05-29 05:18:45 +04:00
|
|
|
return AccessibleWrap::GetLevelInternal();
|
2010-01-06 13:36:50 +03:00
|
|
|
}
|
|
|
|
|
2015-07-16 12:43:00 +03:00
|
|
|
void HyperTextAccessible::SetMathMLXMLRoles(
|
|
|
|
nsIPersistentProperties* aAttributes) {
|
|
|
|
// Add MathML xmlroles based on the position inside the parent.
|
|
|
|
Accessible* parent = Parent();
|
|
|
|
if (parent) {
|
|
|
|
switch (parent->Role()) {
|
|
|
|
case roles::MATHML_CELL:
|
|
|
|
case roles::MATHML_ENCLOSED:
|
|
|
|
case roles::MATHML_ERROR:
|
|
|
|
case roles::MATHML_MATH:
|
|
|
|
case roles::MATHML_ROW:
|
|
|
|
case roles::MATHML_SQUARE_ROOT:
|
|
|
|
case roles::MATHML_STYLE:
|
|
|
|
if (Role() == roles::MATHML_OPERATOR) {
|
|
|
|
// This is an operator inside an <mrow> (or an inferred <mrow>).
|
|
|
|
// See http://www.w3.org/TR/MathML3/chapter3.html#presm.inferredmrow
|
|
|
|
// XXX We should probably do something similar for MATHML_FENCED, but
|
|
|
|
// operators do not appear in the accessible tree. See bug 1175747.
|
|
|
|
nsIMathMLFrame* mathMLFrame = do_QueryFrame(GetFrame());
|
|
|
|
if (mathMLFrame) {
|
|
|
|
nsEmbellishData embellishData;
|
|
|
|
mathMLFrame->GetEmbellishData(embellishData);
|
|
|
|
if (NS_MATHML_EMBELLISH_IS_FENCE(embellishData.flags)) {
|
|
|
|
if (!PrevSibling()) {
|
|
|
|
nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::xmlroles,
|
|
|
|
nsGkAtoms::open_fence);
|
2018-04-13 01:41:00 +03:00
|
|
|
} else if (!NextSibling()) {
|
2015-07-16 12:43:00 +03:00
|
|
|
nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::xmlroles,
|
|
|
|
nsGkAtoms::close_fence);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2015-07-16 12:43:00 +03:00
|
|
|
}
|
|
|
|
if (NS_MATHML_EMBELLISH_IS_SEPARATOR(embellishData.flags)) {
|
|
|
|
nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::xmlroles,
|
|
|
|
nsGkAtoms::separator_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case roles::MATHML_FRACTION:
|
|
|
|
nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::xmlroles,
|
|
|
|
IndexInParent() == 0 ? nsGkAtoms::numerator
|
|
|
|
: nsGkAtoms::denominator);
|
|
|
|
break;
|
|
|
|
case roles::MATHML_ROOT:
|
|
|
|
nsAccUtils::SetAccAttr(
|
|
|
|
aAttributes, nsGkAtoms::xmlroles,
|
|
|
|
IndexInParent() == 0 ? nsGkAtoms::base : nsGkAtoms::root_index);
|
|
|
|
break;
|
|
|
|
case roles::MATHML_SUB:
|
|
|
|
nsAccUtils::SetAccAttr(
|
|
|
|
aAttributes, nsGkAtoms::xmlroles,
|
|
|
|
IndexInParent() == 0 ? nsGkAtoms::base : nsGkAtoms::subscript);
|
2018-11-30 13:46:48 +03:00
|
|
|
break;
|
2015-07-16 12:43:00 +03:00
|
|
|
case roles::MATHML_SUP:
|
|
|
|
nsAccUtils::SetAccAttr(
|
|
|
|
aAttributes, nsGkAtoms::xmlroles,
|
|
|
|
IndexInParent() == 0 ? nsGkAtoms::base : nsGkAtoms::superscript);
|
|
|
|
break;
|
|
|
|
case roles::MATHML_SUB_SUP: {
|
|
|
|
int32_t index = IndexInParent();
|
|
|
|
nsAccUtils::SetAccAttr(
|
|
|
|
aAttributes, nsGkAtoms::xmlroles,
|
|
|
|
index == 0
|
|
|
|
? nsGkAtoms::base
|
|
|
|
: (index == 1 ? nsGkAtoms::subscript : nsGkAtoms::superscript));
|
|
|
|
} break;
|
|
|
|
case roles::MATHML_UNDER:
|
|
|
|
nsAccUtils::SetAccAttr(
|
|
|
|
aAttributes, nsGkAtoms::xmlroles,
|
|
|
|
IndexInParent() == 0 ? nsGkAtoms::base : nsGkAtoms::underscript);
|
|
|
|
break;
|
|
|
|
case roles::MATHML_OVER:
|
|
|
|
nsAccUtils::SetAccAttr(
|
|
|
|
aAttributes, nsGkAtoms::xmlroles,
|
|
|
|
IndexInParent() == 0 ? nsGkAtoms::base : nsGkAtoms::overscript);
|
|
|
|
break;
|
|
|
|
case roles::MATHML_UNDER_OVER: {
|
|
|
|
int32_t index = IndexInParent();
|
|
|
|
nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::xmlroles,
|
|
|
|
index == 0
|
|
|
|
? nsGkAtoms::base
|
|
|
|
: (index == 1 ? nsGkAtoms::underscript
|
|
|
|
: nsGkAtoms::overscript));
|
|
|
|
} break;
|
|
|
|
case roles::MATHML_MULTISCRIPTS: {
|
|
|
|
// Get the <multiscripts> base.
|
|
|
|
nsIContent* child;
|
|
|
|
bool baseFound = false;
|
|
|
|
for (child = parent->GetContent()->GetFirstChild(); child;
|
|
|
|
child = child->GetNextSibling()) {
|
|
|
|
if (child->IsMathMLElement()) {
|
|
|
|
baseFound = true;
|
|
|
|
break;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2015-07-16 12:43:00 +03:00
|
|
|
}
|
|
|
|
if (baseFound) {
|
|
|
|
nsIContent* content = GetContent();
|
|
|
|
if (child == content) {
|
|
|
|
// We are the base.
|
|
|
|
nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::xmlroles,
|
|
|
|
nsGkAtoms::base);
|
|
|
|
} else {
|
|
|
|
// Browse the list of scripts to find us and determine our type.
|
|
|
|
bool postscript = true;
|
|
|
|
bool subscript = true;
|
|
|
|
for (child = child->GetNextSibling(); child;
|
|
|
|
child = child->GetNextSibling()) {
|
|
|
|
if (!child->IsMathMLElement()) continue;
|
|
|
|
if (child->IsMathMLElement(nsGkAtoms::mprescripts_)) {
|
|
|
|
postscript = false;
|
|
|
|
subscript = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (child == content) {
|
|
|
|
if (postscript) {
|
|
|
|
nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::xmlroles,
|
|
|
|
subscript ? nsGkAtoms::subscript
|
|
|
|
: nsGkAtoms::superscript);
|
|
|
|
} else {
|
|
|
|
nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::xmlroles,
|
|
|
|
subscript ? nsGkAtoms::presubscript
|
|
|
|
: nsGkAtoms::presuperscript);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
break;
|
2015-07-16 12:43:00 +03:00
|
|
|
}
|
|
|
|
subscript = !subscript;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-19 11:15:23 +04:00
|
|
|
already_AddRefed<nsIPersistentProperties>
|
|
|
|
HyperTextAccessible::NativeAttributes() {
|
|
|
|
nsCOMPtr<nsIPersistentProperties> attributes =
|
|
|
|
AccessibleWrap::NativeAttributes();
|
2006-09-01 01:07:41 +04:00
|
|
|
|
2012-10-19 11:15:23 +04:00
|
|
|
// 'formatting' attribute is deprecated, 'display' attribute should be
|
|
|
|
// instead.
|
2007-10-10 19:31:52 +04:00
|
|
|
nsIFrame* frame = GetFrame();
|
2017-04-30 18:30:08 +03:00
|
|
|
if (frame && frame->IsBlockFrame()) {
|
2012-10-19 11:15:23 +04:00
|
|
|
nsAutoString unused;
|
2020-07-01 11:29:29 +03:00
|
|
|
attributes->SetStringProperty("formatting"_ns, u"block"_ns, unused);
|
2007-10-10 19:31:52 +04:00
|
|
|
}
|
2006-09-01 01:07:41 +04:00
|
|
|
|
2011-09-28 05:46:11 +04:00
|
|
|
if (FocusMgr()->IsFocused(this)) {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t lineNumber = CaretLineNumber();
|
2007-12-11 17:15:21 +03:00
|
|
|
if (lineNumber >= 1) {
|
|
|
|
nsAutoString strLineNumber;
|
|
|
|
strLineNumber.AppendInt(lineNumber);
|
2012-10-19 11:15:23 +04:00
|
|
|
nsAccUtils::SetAccAttr(attributes, nsGkAtoms::lineNumber, strLineNumber);
|
2007-12-11 17:15:21 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-16 12:43:00 +03:00
|
|
|
if (HasOwnContent()) {
|
2015-03-08 04:20:17 +03:00
|
|
|
GetAccService()->MarkupAttributes(mContent, attributes);
|
2015-07-16 12:43:00 +03:00
|
|
|
if (mContent->IsMathMLElement()) SetMathMLXMLRoles(attributes);
|
|
|
|
}
|
2010-11-08 16:33:34 +03:00
|
|
|
|
2012-10-19 11:15:23 +04:00
|
|
|
return attributes.forget();
|
2006-09-01 01:07:41 +04:00
|
|
|
}
|
|
|
|
|
2015-03-01 01:25:06 +03:00
|
|
|
nsAtom* HyperTextAccessible::LandmarkRole() const {
|
2015-06-25 01:48:29 +03:00
|
|
|
if (!HasOwnContent()) return nullptr;
|
|
|
|
|
2015-03-01 01:25:06 +03:00
|
|
|
// For the html landmark elements we expose them like we do ARIA landmarks to
|
|
|
|
// make AT navigation schemes "just work".
|
2015-03-03 14:08:59 +03:00
|
|
|
if (mContent->IsHTMLElement(nsGkAtoms::nav)) {
|
2015-03-01 01:25:06 +03:00
|
|
|
return nsGkAtoms::navigation;
|
2015-03-03 14:08:59 +03:00
|
|
|
}
|
2015-03-01 01:25:06 +03:00
|
|
|
|
2015-03-03 14:08:59 +03:00
|
|
|
if (mContent->IsHTMLElement(nsGkAtoms::aside)) {
|
2015-03-01 01:25:06 +03:00
|
|
|
return nsGkAtoms::complementary;
|
2015-03-03 14:08:59 +03:00
|
|
|
}
|
2015-03-01 01:25:06 +03:00
|
|
|
|
2015-03-03 14:08:59 +03:00
|
|
|
if (mContent->IsHTMLElement(nsGkAtoms::main)) {
|
2015-03-01 01:25:06 +03:00
|
|
|
return nsGkAtoms::main;
|
2015-03-03 14:08:59 +03:00
|
|
|
}
|
2015-03-01 01:25:06 +03:00
|
|
|
|
2020-03-11 19:23:38 +03:00
|
|
|
return AccessibleWrap::LandmarkRole();
|
2015-03-01 01:25:06 +03:00
|
|
|
}
|
|
|
|
|
2013-11-18 17:19:33 +04:00
|
|
|
int32_t HyperTextAccessible::OffsetAtPoint(int32_t aX, int32_t aY,
|
|
|
|
uint32_t aCoordType) {
|
|
|
|
nsIFrame* hyperFrame = GetFrame();
|
|
|
|
if (!hyperFrame) return -1;
|
2006-06-21 17:29:10 +04:00
|
|
|
|
2012-12-18 00:11:02 +04:00
|
|
|
nsIntPoint coords =
|
|
|
|
nsAccUtils::ConvertToScreenCoords(aX, aY, aCoordType, this);
|
2006-06-21 17:29:10 +04:00
|
|
|
|
2012-10-20 13:03:48 +04:00
|
|
|
nsPresContext* presContext = mDoc->PresContext();
|
|
|
|
nsPoint coordsInAppUnits =
|
2015-04-21 18:04:57 +03:00
|
|
|
ToAppUnits(coords, presContext->AppUnitsPerDevPixel());
|
2012-10-20 13:03:48 +04:00
|
|
|
|
|
|
|
nsRect frameScreenRect = hyperFrame->GetScreenRectInAppUnits();
|
|
|
|
if (!frameScreenRect.Contains(coordsInAppUnits.x, coordsInAppUnits.y))
|
2013-11-18 17:19:33 +04:00
|
|
|
return -1; // Not found
|
2012-10-20 13:03:48 +04:00
|
|
|
|
2018-01-12 20:07:29 +03:00
|
|
|
nsPoint pointInHyperText(coordsInAppUnits.x - frameScreenRect.X(),
|
|
|
|
coordsInAppUnits.y - frameScreenRect.Y());
|
2006-09-19 21:29:10 +04:00
|
|
|
|
2006-06-21 17:29:10 +04:00
|
|
|
// Go through the frames to check if each one has the point.
|
|
|
|
// When one does, add up the character offsets until we have a match
|
|
|
|
|
|
|
|
// We have an point in an accessible child of this, now we need to add up the
|
|
|
|
// offsets before it to what we already have
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t offset = 0;
|
|
|
|
uint32_t childCount = ChildCount();
|
|
|
|
for (uint32_t childIdx = 0; childIdx < childCount; childIdx++) {
|
2012-05-29 05:18:45 +04:00
|
|
|
Accessible* childAcc = mChildren[childIdx];
|
2006-06-21 17:29:10 +04:00
|
|
|
|
2010-04-19 17:39:57 +04:00
|
|
|
nsIFrame* primaryFrame = childAcc->GetFrame();
|
2013-11-18 17:19:33 +04:00
|
|
|
NS_ENSURE_TRUE(primaryFrame, -1);
|
2007-08-21 08:24:21 +04:00
|
|
|
|
|
|
|
nsIFrame* frame = primaryFrame;
|
2006-09-19 21:29:10 +04:00
|
|
|
while (frame) {
|
|
|
|
nsIContent* content = frame->GetContent();
|
2013-11-18 17:19:33 +04:00
|
|
|
NS_ENSURE_TRUE(content, -1);
|
2012-10-20 13:03:48 +04:00
|
|
|
nsPoint pointInFrame = pointInHyperText - frame->GetOffsetTo(hyperFrame);
|
2006-09-19 21:29:10 +04:00
|
|
|
nsSize frameSize = frame->GetSize();
|
|
|
|
if (pointInFrame.x < frameSize.width &&
|
|
|
|
pointInFrame.y < frameSize.height) {
|
|
|
|
// Finished
|
2017-04-30 18:30:08 +03:00
|
|
|
if (frame->IsTextFrame()) {
|
2012-05-29 17:13:36 +04:00
|
|
|
nsIFrame::ContentOffsets contentOffsets =
|
|
|
|
frame->GetContentOffsetsFromPointExternal(
|
|
|
|
pointInFrame, nsIFrame::IGNORE_SELECTION_STYLE);
|
2006-09-19 21:29:10 +04:00
|
|
|
if (contentOffsets.IsNull() || contentOffsets.content != content) {
|
2013-11-18 17:19:33 +04:00
|
|
|
return -1; // Not found
|
2006-06-21 17:29:10 +04:00
|
|
|
}
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t addToOffset;
|
2007-08-21 08:24:21 +04:00
|
|
|
nsresult rv = ContentToRenderedOffset(
|
|
|
|
primaryFrame, contentOffsets.offset, &addToOffset);
|
2013-11-18 17:19:33 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, -1);
|
2007-08-04 05:12:24 +04:00
|
|
|
offset += addToOffset;
|
2006-06-21 17:29:10 +04:00
|
|
|
}
|
2013-11-18 17:19:33 +04:00
|
|
|
return offset;
|
2006-06-21 17:29:10 +04:00
|
|
|
}
|
2006-09-19 21:29:10 +04:00
|
|
|
frame = frame->GetNextContinuation();
|
2006-06-21 17:29:10 +04:00
|
|
|
}
|
2010-05-25 12:40:54 +04:00
|
|
|
|
|
|
|
offset += nsAccUtils::TextLength(childAcc);
|
2006-06-21 17:29:10 +04:00
|
|
|
}
|
2006-09-19 21:29:10 +04:00
|
|
|
|
2013-11-18 17:19:33 +04:00
|
|
|
return -1; // Not found
|
2006-06-21 17:29:10 +04:00
|
|
|
}
|
|
|
|
|
2013-11-25 22:28:27 +04:00
|
|
|
nsIntRect HyperTextAccessible::TextBounds(int32_t aStartOffset,
|
|
|
|
int32_t aEndOffset,
|
|
|
|
uint32_t aCoordType) {
|
2014-05-17 03:16:34 +04:00
|
|
|
index_t startOffset = ConvertMagicOffset(aStartOffset);
|
|
|
|
index_t endOffset = ConvertMagicOffset(aEndOffset);
|
|
|
|
if (!startOffset.IsValid() || !endOffset.IsValid() ||
|
|
|
|
startOffset > endOffset || endOffset > CharacterCount()) {
|
|
|
|
NS_ERROR("Wrong in offset");
|
|
|
|
return nsIntRect();
|
|
|
|
}
|
|
|
|
|
2018-05-23 18:02:33 +03:00
|
|
|
if (CharacterCount() == 0) {
|
|
|
|
nsPresContext* presContext = mDoc->PresContext();
|
|
|
|
// Empty content, use our own bound to at least get x,y coordinates
|
2020-06-08 08:11:23 +03:00
|
|
|
nsIFrame* frame = GetFrame();
|
|
|
|
if (!frame) {
|
|
|
|
return nsIntRect();
|
|
|
|
}
|
|
|
|
return frame->GetScreenRectInAppUnits().ToNearestPixels(
|
2018-05-23 18:02:33 +03:00
|
|
|
presContext->AppUnitsPerDevPixel());
|
|
|
|
}
|
2013-11-25 22:28:27 +04:00
|
|
|
|
|
|
|
int32_t childIdx = GetChildIndexAtOffset(startOffset);
|
|
|
|
if (childIdx == -1) return nsIntRect();
|
|
|
|
|
|
|
|
nsIntRect bounds;
|
|
|
|
int32_t prevOffset = GetChildOffset(childIdx);
|
|
|
|
int32_t offset1 = startOffset - prevOffset;
|
|
|
|
|
2014-04-26 06:42:19 +04:00
|
|
|
while (childIdx < static_cast<int32_t>(ChildCount())) {
|
2014-04-09 22:23:04 +04:00
|
|
|
nsIFrame* frame = GetChildAt(childIdx++)->GetFrame();
|
2013-12-05 01:15:22 +04:00
|
|
|
if (!frame) {
|
2018-06-18 08:43:11 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE("No frame for a child!");
|
2013-12-05 01:15:22 +04:00
|
|
|
continue;
|
|
|
|
}
|
2013-11-25 22:28:27 +04:00
|
|
|
|
|
|
|
int32_t nextOffset = GetChildOffset(childIdx);
|
2014-04-26 06:42:19 +04:00
|
|
|
if (nextOffset >= static_cast<int32_t>(endOffset)) {
|
2013-11-25 22:28:27 +04:00
|
|
|
bounds.UnionRect(
|
|
|
|
bounds, GetBoundsInFrame(frame, offset1, endOffset - prevOffset));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
bounds.UnionRect(bounds,
|
|
|
|
GetBoundsInFrame(frame, offset1, nextOffset - prevOffset));
|
|
|
|
|
|
|
|
prevOffset = nextOffset;
|
|
|
|
offset1 = 0;
|
|
|
|
}
|
|
|
|
|
2018-04-19 12:31:00 +03:00
|
|
|
// This document may have a resolution set, we will need to multiply
|
|
|
|
// the document-relative coordinates by that value and re-apply the doc's
|
|
|
|
// screen coordinates.
|
|
|
|
nsPresContext* presContext = mDoc->PresContext();
|
|
|
|
nsIFrame* rootFrame = presContext->PresShell()->GetRootFrame();
|
|
|
|
nsIntRect orgRectPixels =
|
|
|
|
rootFrame->GetScreenRectInAppUnits().ToNearestPixels(
|
|
|
|
presContext->AppUnitsPerDevPixel());
|
|
|
|
bounds.MoveBy(-orgRectPixels.X(), -orgRectPixels.Y());
|
|
|
|
bounds.ScaleRoundOut(presContext->PresShell()->GetResolution());
|
|
|
|
bounds.MoveBy(orgRectPixels.X(), orgRectPixels.Y());
|
|
|
|
|
2018-01-12 20:07:29 +03:00
|
|
|
auto boundsX = bounds.X();
|
|
|
|
auto boundsY = bounds.Y();
|
|
|
|
nsAccUtils::ConvertScreenCoordsTo(&boundsX, &boundsY, aCoordType, this);
|
|
|
|
bounds.MoveTo(boundsX, boundsY);
|
2013-11-25 22:28:27 +04:00
|
|
|
return bounds;
|
|
|
|
}
|
|
|
|
|
2012-05-31 12:04:41 +04:00
|
|
|
already_AddRefed<TextEditor> HyperTextAccessible::GetEditor() const {
|
2010-06-11 12:23:18 +04:00
|
|
|
if (!mContent->HasFlag(NODE_IS_EDITABLE)) {
|
2007-09-06 08:18:22 +04:00
|
|
|
// If we're inside an editable container, then return that container's
|
|
|
|
// editor
|
2012-05-29 05:18:45 +04:00
|
|
|
Accessible* ancestor = Parent();
|
2012-03-08 07:28:38 +04:00
|
|
|
while (ancestor) {
|
2012-05-31 12:04:41 +04:00
|
|
|
HyperTextAccessible* hyperText = ancestor->AsHyperText();
|
2012-03-08 07:28:38 +04:00
|
|
|
if (hyperText) {
|
2007-09-06 08:18:22 +04:00
|
|
|
// Recursion will stop at container doc because it has its own impl
|
2012-03-08 07:28:38 +04:00
|
|
|
// of GetEditor()
|
|
|
|
return hyperText->GetEditor();
|
2007-09-06 08:18:22 +04:00
|
|
|
}
|
2012-03-08 07:28:38 +04:00
|
|
|
|
|
|
|
ancestor = ancestor->Parent();
|
2007-09-06 08:18:22 +04:00
|
|
|
}
|
2012-03-08 07:28:38 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2007-08-14 20:25:24 +04:00
|
|
|
}
|
|
|
|
|
2013-02-13 02:02:51 +04:00
|
|
|
nsCOMPtr<nsIDocShell> docShell = nsCoreUtils::GetDocShellFor(mContent);
|
2016-03-14 21:00:13 +03:00
|
|
|
nsCOMPtr<nsIEditingSession> editingSession;
|
|
|
|
docShell->GetEditingSession(getter_AddRefs(editingSession));
|
2012-07-30 18:20:58 +04:00
|
|
|
if (!editingSession) return nullptr; // No editing session interface
|
2007-08-14 20:25:24 +04:00
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
dom::Document* docNode = mDoc->DocumentNode();
|
2017-08-07 11:42:50 +03:00
|
|
|
RefPtr<HTMLEditor> htmlEditor =
|
|
|
|
editingSession->GetHTMLEditorForWindow(docNode->GetWindow());
|
|
|
|
return htmlEditor.forget();
|
2007-07-05 21:12:28 +04:00
|
|
|
}
|
|
|
|
|
2006-06-21 17:29:10 +04:00
|
|
|
/**
|
|
|
|
* =================== Caret & Selection ======================
|
|
|
|
*/
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
nsresult HyperTextAccessible::SetSelectionRange(int32_t aStartPos,
|
|
|
|
int32_t aEndPos) {
|
2012-11-03 16:08:09 +04:00
|
|
|
// Before setting the selection range, we need to ensure that the editor
|
|
|
|
// is initialized. (See bug 804927.)
|
|
|
|
// Otherwise, it's possible that lazy editor initialization will override
|
|
|
|
// the selection we set here and leave the caret at the end of the text.
|
|
|
|
// By calling GetEditor here, we ensure that editor initialization is
|
|
|
|
// completed before we set the selection.
|
2017-08-07 11:42:50 +03:00
|
|
|
RefPtr<TextEditor> textEditor = GetEditor();
|
2012-11-03 16:08:09 +04:00
|
|
|
|
2012-06-04 09:41:06 +04:00
|
|
|
bool isFocusable = InteractiveState() & states::FOCUSABLE;
|
2012-02-08 08:31:18 +04:00
|
|
|
|
|
|
|
// If accessible is focusable then focus it before setting the selection to
|
|
|
|
// neglect control's selection changes on focus if any (for example, inputs
|
|
|
|
// that do select all on focus).
|
|
|
|
// some input controls
|
|
|
|
if (isFocusable) TakeFocus();
|
2010-02-21 03:50:50 +03:00
|
|
|
|
2020-03-06 15:03:23 +03:00
|
|
|
RefPtr<dom::Selection> domSel = DOMSelection();
|
2011-10-12 11:39:58 +04:00
|
|
|
NS_ENSURE_STATE(domSel);
|
|
|
|
|
2014-02-08 17:25:11 +04:00
|
|
|
// Set up the selection.
|
2020-02-12 15:27:32 +03:00
|
|
|
for (int32_t idx = domSel->RangeCount() - 1; idx > 0; idx--) {
|
|
|
|
RefPtr<nsRange> range{domSel->GetRangeAt(idx)};
|
|
|
|
domSel->RemoveRangeAndUnselectFramesAndNotifyListeners(*range,
|
|
|
|
IgnoreErrors());
|
|
|
|
}
|
2014-02-08 17:25:11 +04:00
|
|
|
SetSelectionBoundsAt(0, aStartPos, aEndPos);
|
2006-11-02 17:17:36 +03:00
|
|
|
|
2017-10-11 11:43:53 +03:00
|
|
|
// Make sure it is visible
|
|
|
|
domSel->ScrollIntoView(nsISelectionController::SELECTION_FOCUS_REGION,
|
2019-04-30 03:07:49 +03:00
|
|
|
ScrollAxis(), ScrollAxis(),
|
2017-10-11 11:43:53 +03:00
|
|
|
dom::Selection::SCROLL_FOR_CARET_MOVE |
|
|
|
|
dom::Selection::SCROLL_OVERFLOW_HIDDEN);
|
|
|
|
|
2012-02-08 08:31:18 +04:00
|
|
|
// When selection is done, move the focus to the selection if accessible is
|
|
|
|
// not focusable. That happens when selection is set within hypertext
|
|
|
|
// accessible.
|
|
|
|
if (isFocusable) return NS_OK;
|
|
|
|
|
2011-10-16 07:38:19 +04:00
|
|
|
nsFocusManager* DOMFocusManager = nsFocusManager::GetFocusManager();
|
|
|
|
if (DOMFocusManager) {
|
2012-02-08 02:38:54 +04:00
|
|
|
NS_ENSURE_TRUE(mDoc, NS_ERROR_FAILURE);
|
2019-01-02 16:05:23 +03:00
|
|
|
dom::Document* docNode = mDoc->DocumentNode();
|
2012-02-08 02:38:54 +04:00
|
|
|
NS_ENSURE_TRUE(docNode, NS_ERROR_FAILURE);
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> window = docNode->GetWindow();
|
2018-04-26 17:37:47 +03:00
|
|
|
RefPtr<dom::Element> result;
|
2012-07-30 18:20:58 +04:00
|
|
|
DOMFocusManager->MoveFocus(
|
|
|
|
window, nullptr, nsIFocusManager::MOVEFOCUS_CARET,
|
2011-10-16 07:38:19 +04:00
|
|
|
nsIFocusManager::FLAG_BYMOVEFOCUS, getter_AddRefs(result));
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
2006-06-21 17:29:10 +04:00
|
|
|
}
|
|
|
|
|
2013-11-18 17:19:33 +04:00
|
|
|
int32_t HyperTextAccessible::CaretOffset() const {
|
2012-02-13 07:37:52 +04:00
|
|
|
// Not focused focusable accessible except document accessible doesn't have
|
|
|
|
// a caret.
|
|
|
|
if (!IsDoc() && !FocusMgr()->IsFocused(this) &&
|
2012-06-04 09:41:06 +04:00
|
|
|
(InteractiveState() & states::FOCUSABLE)) {
|
2013-11-18 17:19:33 +04:00
|
|
|
return -1;
|
2012-02-13 07:37:52 +04:00
|
|
|
}
|
|
|
|
|
2014-05-01 19:45:40 +04:00
|
|
|
// Check cached value.
|
|
|
|
int32_t caretOffset = -1;
|
|
|
|
HyperTextAccessible* text = SelectionMgr()->AccessibleWithCaret(&caretOffset);
|
|
|
|
|
|
|
|
// Use cached value if it corresponds to this accessible.
|
|
|
|
if (caretOffset != -1) {
|
|
|
|
if (text == this) return caretOffset;
|
|
|
|
|
|
|
|
nsINode* textNode = text->GetNode();
|
|
|
|
// Ignore offset if cached accessible isn't a text leaf.
|
|
|
|
if (nsCoreUtils::IsAncestorOf(GetNode(), textNode))
|
2018-04-13 01:41:00 +03:00
|
|
|
return TransformOffset(text, textNode->IsText() ? caretOffset : 0, false);
|
2014-05-01 19:45:40 +04:00
|
|
|
}
|
|
|
|
|
2008-12-16 13:14:20 +03:00
|
|
|
// No caret if the focused node is not inside this DOM node and this DOM node
|
|
|
|
// is not inside of focused node.
|
2011-09-28 05:46:11 +04:00
|
|
|
FocusManager::FocusDisposition focusDisp =
|
|
|
|
FocusMgr()->IsInOrContainsFocus(this);
|
|
|
|
if (focusDisp == FocusManager::eNone) return -1;
|
2006-06-21 17:29:10 +04:00
|
|
|
|
2008-12-16 13:14:20 +03:00
|
|
|
// Turn the focus node and offset of the selection into caret hypretext
|
|
|
|
// offset.
|
2014-04-10 20:09:40 +04:00
|
|
|
dom::Selection* domSel = DOMSelection();
|
2013-11-18 17:19:33 +04:00
|
|
|
NS_ENSURE_TRUE(domSel, -1);
|
2006-06-21 17:29:10 +04:00
|
|
|
|
2012-04-07 04:09:31 +04:00
|
|
|
nsINode* focusNode = domSel->GetFocusNode();
|
2013-12-17 18:12:33 +04:00
|
|
|
uint32_t focusOffset = domSel->FocusOffset();
|
2008-12-16 13:14:20 +03:00
|
|
|
|
|
|
|
// No caret if this DOM node is inside of focused node but the selection's
|
|
|
|
// focus point is not inside of this DOM node.
|
2011-09-28 05:46:11 +04:00
|
|
|
if (focusDisp == FocusManager::eContainedByFocus) {
|
2013-11-18 17:19:33 +04:00
|
|
|
nsINode* resultNode =
|
2008-12-16 13:14:20 +03:00
|
|
|
nsCoreUtils::GetDOMNodeFromDOMPoint(focusNode, focusOffset);
|
2010-01-27 14:43:25 +03:00
|
|
|
|
2011-09-28 05:46:11 +04:00
|
|
|
nsINode* thisNode = GetNode();
|
2010-01-27 14:43:25 +03:00
|
|
|
if (resultNode != thisNode &&
|
|
|
|
!nsCoreUtils::IsAncestorOf(thisNode, resultNode))
|
2013-11-18 17:19:33 +04:00
|
|
|
return -1;
|
2008-12-16 13:14:20 +03:00
|
|
|
}
|
2006-07-12 17:14:53 +04:00
|
|
|
|
2014-02-04 04:56:45 +04:00
|
|
|
return DOMPointToOffset(focusNode, focusOffset);
|
2006-06-21 17:29:10 +04:00
|
|
|
}
|
|
|
|
|
2012-05-31 12:04:41 +04:00
|
|
|
int32_t HyperTextAccessible::CaretLineNumber() {
|
2007-12-11 17:15:21 +03:00
|
|
|
// Provide the line number for the caret, relative to the
|
|
|
|
// currently focused node. Use a 1-based index
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsFrameSelection> frameSelection = FrameSelection();
|
2011-10-12 11:39:58 +04:00
|
|
|
if (!frameSelection) return -1;
|
|
|
|
|
2016-06-09 12:35:22 +03:00
|
|
|
dom::Selection* domSel = frameSelection->GetSelection(SelectionType::eNormal);
|
2011-10-12 11:39:58 +04:00
|
|
|
if (!domSel) return -1;
|
2007-12-11 17:15:21 +03:00
|
|
|
|
2012-04-07 04:09:31 +04:00
|
|
|
nsINode* caretNode = domSel->GetFocusNode();
|
|
|
|
if (!caretNode || !caretNode->IsContent()) return -1;
|
|
|
|
|
|
|
|
nsIContent* caretContent = caretNode->AsContent();
|
|
|
|
if (!nsCoreUtils::IsAncestorOf(GetNode(), caretContent)) return -1;
|
2007-12-11 17:15:21 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t returnOffsetUnused;
|
2013-12-17 18:12:33 +04:00
|
|
|
uint32_t caretOffset = domSel->FocusOffset();
|
2014-08-06 09:19:27 +04:00
|
|
|
CaretAssociationHint hint = frameSelection->GetHint();
|
2007-12-11 17:15:21 +03:00
|
|
|
nsIFrame* caretFrame = frameSelection->GetFrameForNodeOffset(
|
|
|
|
caretContent, caretOffset, hint, &returnOffsetUnused);
|
|
|
|
NS_ENSURE_TRUE(caretFrame, -1);
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t lineNumber = 1;
|
2008-10-30 22:17:59 +03:00
|
|
|
nsAutoLineIterator lineIterForCaret;
|
2012-07-30 18:20:58 +04:00
|
|
|
nsIContent* hyperTextContent = IsContent() ? mContent.get() : nullptr;
|
2007-12-11 17:15:21 +03:00
|
|
|
while (caretFrame) {
|
|
|
|
if (hyperTextContent == caretFrame->GetContent()) {
|
|
|
|
return lineNumber; // Must be in a single line hyper text, there is no
|
|
|
|
// line iterator
|
|
|
|
}
|
2014-05-25 02:20:39 +04:00
|
|
|
nsContainerFrame* parentFrame = caretFrame->GetParent();
|
2007-12-11 17:15:21 +03:00
|
|
|
if (!parentFrame) break;
|
|
|
|
|
|
|
|
// Add lines for the sibling frames before the caret
|
2016-01-29 17:42:14 +03:00
|
|
|
nsIFrame* sibling = parentFrame->PrincipalChildList().FirstChild();
|
2007-12-11 17:15:21 +03:00
|
|
|
while (sibling && sibling != caretFrame) {
|
2008-10-30 22:17:59 +03:00
|
|
|
nsAutoLineIterator lineIterForSibling = sibling->GetLineIterator();
|
2007-12-11 17:15:21 +03:00
|
|
|
if (lineIterForSibling) {
|
|
|
|
// For the frames before that grab all the lines
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t addLines = lineIterForSibling->GetNumLines();
|
2007-12-11 17:15:21 +03:00
|
|
|
lineNumber += addLines;
|
|
|
|
}
|
|
|
|
sibling = sibling->GetNextSibling();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the line number relative to the container with lines
|
|
|
|
if (!lineIterForCaret) { // Add the caret line just once
|
2008-10-30 22:17:59 +03:00
|
|
|
lineIterForCaret = parentFrame->GetLineIterator();
|
2007-12-11 17:15:21 +03:00
|
|
|
if (lineIterForCaret) {
|
|
|
|
// Ancestor of caret
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t addLines = lineIterForCaret->FindLineContaining(caretFrame);
|
2007-12-11 17:15:21 +03:00
|
|
|
lineNumber += addLines;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
caretFrame = parentFrame;
|
|
|
|
}
|
|
|
|
|
2018-06-18 08:43:11 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE(
|
|
|
|
"DOM ancestry had this hypertext but frame ancestry didn't");
|
2007-12-11 17:15:21 +03:00
|
|
|
return lineNumber;
|
|
|
|
}
|
|
|
|
|
2013-10-26 18:58:53 +04:00
|
|
|
LayoutDeviceIntRect HyperTextAccessible::GetCaretRect(nsIWidget** aWidget) {
|
|
|
|
*aWidget = nullptr;
|
|
|
|
|
2019-04-13 15:13:15 +03:00
|
|
|
RefPtr<nsCaret> caret = mDoc->PresShellPtr()->GetCaret();
|
2015-11-12 16:34:27 +03:00
|
|
|
NS_ENSURE_TRUE(caret, LayoutDeviceIntRect());
|
2013-10-26 18:58:53 +04:00
|
|
|
|
2014-08-06 09:19:29 +04:00
|
|
|
bool isVisible = caret->IsVisible();
|
2015-11-12 16:34:27 +03:00
|
|
|
if (!isVisible) return LayoutDeviceIntRect();
|
2013-10-26 18:58:53 +04:00
|
|
|
|
|
|
|
nsRect rect;
|
2014-08-06 09:19:26 +04:00
|
|
|
nsIFrame* frame = caret->GetGeometry(&rect);
|
2015-11-12 16:34:27 +03:00
|
|
|
if (!frame || rect.IsEmpty()) return LayoutDeviceIntRect();
|
2013-10-26 18:58:53 +04:00
|
|
|
|
|
|
|
nsPoint offset;
|
|
|
|
// Offset from widget origin to the frame origin, which includes chrome
|
|
|
|
// on the widget.
|
|
|
|
*aWidget = frame->GetNearestWidget(offset);
|
2015-11-12 16:34:27 +03:00
|
|
|
NS_ENSURE_TRUE(*aWidget, LayoutDeviceIntRect());
|
2013-10-26 18:58:53 +04:00
|
|
|
rect.MoveBy(offset);
|
|
|
|
|
2015-11-12 16:34:27 +03:00
|
|
|
LayoutDeviceIntRect caretRect = LayoutDeviceIntRect::FromUnknownRect(
|
|
|
|
rect.ToOutsidePixels(frame->PresContext()->AppUnitsPerDevPixel()));
|
2012-10-20 04:56:58 +04:00
|
|
|
// clang-format off
|
2013-10-26 18:58:53 +04:00
|
|
|
// ((content screen origin) - (content offset in the widget)) = widget origin on the screen
|
2008-07-17 16:06:24 +04:00
|
|
|
// clang-format on
|
2015-11-12 16:34:27 +03:00
|
|
|
caretRect.MoveBy((*aWidget)->WidgetToScreenOffset() -
|
|
|
|
(*aWidget)->GetClientOffset());
|
2013-10-26 18:58:53 +04:00
|
|
|
|
|
|
|
// Correct for character size, so that caret always matches the size of
|
|
|
|
// the character. This is important for font size transitions, and is
|
|
|
|
// necessary because the Gecko caret uses the previous character's size as
|
|
|
|
// the user moves forward in the text by character.
|
2013-11-18 17:19:33 +04:00
|
|
|
nsIntRect charRect = CharBounds(
|
|
|
|
CaretOffset(), nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE);
|
|
|
|
if (!charRect.IsEmpty()) {
|
2018-01-12 20:07:29 +03:00
|
|
|
caretRect.SetTopEdge(charRect.Y());
|
2013-10-26 18:58:53 +04:00
|
|
|
}
|
|
|
|
return caretRect;
|
|
|
|
}
|
|
|
|
|
2016-06-11 05:06:37 +03:00
|
|
|
void HyperTextAccessible::GetSelectionDOMRanges(SelectionType aSelectionType,
|
2012-05-31 12:04:41 +04:00
|
|
|
nsTArray<nsRange*>* aRanges) {
|
2013-04-22 12:10:09 +04:00
|
|
|
// Ignore selection if it is not visible.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsFrameSelection> frameSelection = FrameSelection();
|
2013-04-22 12:10:09 +04:00
|
|
|
if (!frameSelection || frameSelection->GetDisplaySelection() <=
|
|
|
|
nsISelectionController::SELECTION_HIDDEN)
|
2011-10-12 11:39:58 +04:00
|
|
|
return;
|
2008-07-17 16:06:24 +04:00
|
|
|
|
2016-06-11 05:06:37 +03:00
|
|
|
dom::Selection* domSel = frameSelection->GetSelection(aSelectionType);
|
2011-10-12 11:39:58 +04:00
|
|
|
if (!domSel) return;
|
2007-09-19 02:28:26 +04:00
|
|
|
|
2017-08-07 11:42:50 +03:00
|
|
|
nsINode* startNode = GetNode();
|
2008-07-17 16:06:24 +04:00
|
|
|
|
2017-08-07 11:42:50 +03:00
|
|
|
RefPtr<TextEditor> textEditor = GetEditor();
|
|
|
|
if (textEditor) {
|
|
|
|
startNode = textEditor->GetRoot();
|
2011-10-12 11:39:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!startNode) return;
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t childCount = startNode->GetChildCount();
|
2012-01-10 18:19:54 +04:00
|
|
|
nsresult rv = domSel->GetRangesForIntervalArray(startNode, 0, startNode,
|
|
|
|
childCount, true, aRanges);
|
2012-09-14 14:00:31 +04:00
|
|
|
NS_ENSURE_SUCCESS_VOID(rv);
|
2011-10-12 11:39:58 +04:00
|
|
|
|
|
|
|
// Remove collapsed ranges
|
2020-06-08 12:01:48 +03:00
|
|
|
aRanges->RemoveElementsBy(
|
|
|
|
[](const auto& range) { return range->Collapsed(); });
|
2006-06-21 17:29:10 +04:00
|
|
|
}
|
|
|
|
|
2013-11-18 17:19:33 +04:00
|
|
|
int32_t HyperTextAccessible::SelectionCount() {
|
2012-01-10 18:19:54 +04:00
|
|
|
nsTArray<nsRange*> ranges;
|
2016-06-09 12:35:22 +03:00
|
|
|
GetSelectionDOMRanges(SelectionType::eNormal, &ranges);
|
2013-11-18 17:19:33 +04:00
|
|
|
return ranges.Length();
|
2006-06-21 17:29:10 +04:00
|
|
|
}
|
|
|
|
|
2013-11-18 17:19:33 +04:00
|
|
|
bool HyperTextAccessible::SelectionBoundsAt(int32_t aSelectionNum,
|
|
|
|
int32_t* aStartOffset,
|
|
|
|
int32_t* aEndOffset) {
|
2006-07-12 17:14:53 +04:00
|
|
|
*aStartOffset = *aEndOffset = 0;
|
|
|
|
|
2012-01-10 18:19:54 +04:00
|
|
|
nsTArray<nsRange*> ranges;
|
2016-06-09 12:35:22 +03:00
|
|
|
GetSelectionDOMRanges(SelectionType::eNormal, &ranges);
|
2006-06-21 17:29:10 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t rangeCount = ranges.Length();
|
2014-04-26 06:42:19 +04:00
|
|
|
if (aSelectionNum < 0 || aSelectionNum >= static_cast<int32_t>(rangeCount))
|
2013-11-18 17:19:33 +04:00
|
|
|
return false;
|
2006-06-21 17:29:10 +04:00
|
|
|
|
2012-01-10 18:19:54 +04:00
|
|
|
nsRange* range = ranges[aSelectionNum];
|
2006-07-12 17:14:53 +04:00
|
|
|
|
2012-03-06 21:08:02 +04:00
|
|
|
// Get start and end points.
|
2017-07-11 14:53:04 +03:00
|
|
|
nsINode* startNode = range->GetStartContainer();
|
2017-07-11 15:11:37 +03:00
|
|
|
nsINode* endNode = range->GetEndContainer();
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t startOffset = range->StartOffset(), endOffset = range->EndOffset();
|
2012-03-06 21:08:02 +04:00
|
|
|
|
|
|
|
// Make sure start is before end, by swapping DOM points. This occurs when
|
|
|
|
// the user selects backwards in the text.
|
2019-12-19 16:27:42 +03:00
|
|
|
const Maybe<int32_t> order =
|
|
|
|
nsContentUtils::ComparePoints(endNode, endOffset, startNode, startOffset);
|
|
|
|
|
|
|
|
if (!order) {
|
|
|
|
MOZ_ASSERT_UNREACHABLE();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*order < 0) {
|
2012-03-06 21:08:02 +04:00
|
|
|
nsINode* tempNode = startNode;
|
|
|
|
startNode = endNode;
|
|
|
|
endNode = tempNode;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t tempOffset = startOffset;
|
2007-09-19 02:28:26 +04:00
|
|
|
startOffset = endOffset;
|
|
|
|
endOffset = tempOffset;
|
|
|
|
}
|
|
|
|
|
2019-07-12 16:10:28 +03:00
|
|
|
if (!startNode->IsInclusiveDescendantOf(mContent))
|
2014-08-14 02:03:50 +04:00
|
|
|
*aStartOffset = 0;
|
|
|
|
else
|
|
|
|
*aStartOffset = DOMPointToOffset(startNode, startOffset);
|
|
|
|
|
2019-07-12 16:10:28 +03:00
|
|
|
if (!endNode->IsInclusiveDescendantOf(mContent))
|
2014-08-14 02:03:50 +04:00
|
|
|
*aEndOffset = CharacterCount();
|
|
|
|
else
|
|
|
|
*aEndOffset = DOMPointToOffset(endNode, endOffset, true);
|
2013-11-18 17:19:33 +04:00
|
|
|
return true;
|
2006-06-21 17:29:10 +04:00
|
|
|
}
|
|
|
|
|
2013-11-18 17:19:33 +04:00
|
|
|
bool HyperTextAccessible::SetSelectionBoundsAt(int32_t aSelectionNum,
|
|
|
|
int32_t aStartOffset,
|
|
|
|
int32_t aEndOffset) {
|
2014-05-17 03:16:34 +04:00
|
|
|
index_t startOffset = ConvertMagicOffset(aStartOffset);
|
|
|
|
index_t endOffset = ConvertMagicOffset(aEndOffset);
|
|
|
|
if (!startOffset.IsValid() || !endOffset.IsValid() ||
|
2018-07-05 15:19:00 +03:00
|
|
|
std::max(startOffset, endOffset) > CharacterCount()) {
|
2014-05-17 03:16:34 +04:00
|
|
|
NS_ERROR("Wrong in offset");
|
|
|
|
return false;
|
|
|
|
}
|
2013-01-13 00:24:13 +04:00
|
|
|
|
2020-03-06 15:03:23 +03:00
|
|
|
RefPtr<dom::Selection> domSel = DOMSelection();
|
2013-11-18 17:19:33 +04:00
|
|
|
if (!domSel) return false;
|
2012-04-07 04:09:31 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsRange> range;
|
2015-02-25 19:08:00 +03:00
|
|
|
uint32_t rangeCount = domSel->RangeCount();
|
2020-01-30 16:23:35 +03:00
|
|
|
if (aSelectionNum == static_cast<int32_t>(rangeCount)) {
|
|
|
|
range = nsRange::Create(mContent);
|
|
|
|
} else {
|
2012-04-07 04:09:31 +04:00
|
|
|
range = domSel->GetRangeAt(aSelectionNum);
|
2020-01-30 16:23:35 +03:00
|
|
|
}
|
2006-06-21 17:29:10 +04:00
|
|
|
|
2013-11-18 17:19:33 +04:00
|
|
|
if (!range) return false;
|
|
|
|
|
2018-07-05 15:19:00 +03:00
|
|
|
if (!OffsetsToDOMRange(std::min(startOffset, endOffset),
|
|
|
|
std::max(startOffset, endOffset), range))
|
2013-12-13 20:26:35 +04:00
|
|
|
return false;
|
2006-07-12 17:14:53 +04:00
|
|
|
|
2018-07-05 15:19:00 +03:00
|
|
|
// If this is not a new range, notify selection listeners that the existing
|
|
|
|
// selection range has changed. Otherwise, just add the new range.
|
|
|
|
if (aSelectionNum != static_cast<int32_t>(rangeCount)) {
|
2019-07-02 17:17:05 +03:00
|
|
|
domSel->RemoveRangeAndUnselectFramesAndNotifyListeners(*range,
|
|
|
|
IgnoreErrors());
|
2018-03-27 07:35:22 +03:00
|
|
|
}
|
2011-10-12 11:39:58 +04:00
|
|
|
|
2018-03-27 07:35:22 +03:00
|
|
|
IgnoredErrorResult err;
|
2019-07-02 16:16:12 +03:00
|
|
|
domSel->AddRangeAndSelectFramesAndNotifyListeners(*range, err);
|
2018-07-05 15:19:00 +03:00
|
|
|
|
|
|
|
if (!err.Failed()) {
|
|
|
|
// Changing the direction of the selection assures that the caret
|
|
|
|
// will be at the logical end of the selection.
|
|
|
|
domSel->SetDirection(startOffset < endOffset ? eDirNext : eDirPrevious);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2006-06-21 17:29:10 +04:00
|
|
|
}
|
|
|
|
|
2013-11-18 17:19:33 +04:00
|
|
|
bool HyperTextAccessible::RemoveFromSelection(int32_t aSelectionNum) {
|
2020-03-06 15:03:23 +03:00
|
|
|
RefPtr<dom::Selection> domSel = DOMSelection();
|
2013-11-18 17:19:33 +04:00
|
|
|
if (!domSel) return false;
|
2006-06-21 17:29:10 +04:00
|
|
|
|
2015-02-25 19:08:00 +03:00
|
|
|
if (aSelectionNum < 0 ||
|
|
|
|
aSelectionNum >= static_cast<int32_t>(domSel->RangeCount()))
|
2013-11-18 17:19:33 +04:00
|
|
|
return false;
|
2006-06-21 17:29:10 +04:00
|
|
|
|
2020-02-12 15:27:32 +03:00
|
|
|
const RefPtr<nsRange> range{domSel->GetRangeAt(aSelectionNum)};
|
|
|
|
domSel->RemoveRangeAndUnselectFramesAndNotifyListeners(*range,
|
|
|
|
IgnoreErrors());
|
2013-11-18 17:19:33 +04:00
|
|
|
return true;
|
2006-06-21 17:29:10 +04:00
|
|
|
}
|
|
|
|
|
2013-11-18 17:19:33 +04:00
|
|
|
void HyperTextAccessible::ScrollSubstringTo(int32_t aStartOffset,
|
|
|
|
int32_t aEndOffset,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aScrollType) {
|
2020-01-30 16:23:35 +03:00
|
|
|
RefPtr<nsRange> range = nsRange::Create(mContent);
|
2013-12-13 20:26:35 +04:00
|
|
|
if (OffsetsToDOMRange(aStartOffset, aEndOffset, range))
|
2013-11-18 17:19:33 +04:00
|
|
|
nsCoreUtils::ScrollSubstringTo(GetFrame(), range, aScrollType);
|
2007-09-25 09:48:51 +04:00
|
|
|
}
|
|
|
|
|
2013-11-18 17:19:33 +04:00
|
|
|
void HyperTextAccessible::ScrollSubstringToPoint(int32_t aStartOffset,
|
|
|
|
int32_t aEndOffset,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aCoordinateType,
|
|
|
|
int32_t aX, int32_t aY) {
|
2007-09-25 09:48:51 +04:00
|
|
|
nsIFrame* frame = GetFrame();
|
|
|
|
if (!frame) return;
|
2007-08-24 08:54:45 +04:00
|
|
|
|
2012-12-18 00:11:02 +04:00
|
|
|
nsIntPoint coords =
|
|
|
|
nsAccUtils::ConvertToScreenCoords(aX, aY, aCoordinateType, this);
|
2007-08-24 08:54:45 +04:00
|
|
|
|
2020-01-30 16:23:35 +03:00
|
|
|
RefPtr<nsRange> range = nsRange::Create(mContent);
|
2013-12-13 20:26:35 +04:00
|
|
|
if (!OffsetsToDOMRange(aStartOffset, aEndOffset, range)) return;
|
2007-08-24 08:54:45 +04:00
|
|
|
|
2012-10-21 05:38:15 +04:00
|
|
|
nsPresContext* presContext = frame->PresContext();
|
|
|
|
nsPoint coordsInAppUnits =
|
2015-04-21 18:04:57 +03:00
|
|
|
ToAppUnits(coords, presContext->AppUnitsPerDevPixel());
|
2007-09-25 09:48:51 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool initialScrolled = false;
|
2007-09-25 09:48:51 +04:00
|
|
|
nsIFrame* parentFrame = frame;
|
2008-02-08 12:35:42 +03:00
|
|
|
while ((parentFrame = parentFrame->GetParent())) {
|
2009-01-12 22:20:59 +03:00
|
|
|
nsIScrollableFrame* scrollableFrame = do_QueryFrame(parentFrame);
|
2007-09-25 09:48:51 +04:00
|
|
|
if (scrollableFrame) {
|
|
|
|
if (!initialScrolled) {
|
|
|
|
// Scroll substring to the given point. Turn the point into percents
|
2008-10-16 05:52:58 +04:00
|
|
|
// relative scrollable area to use nsCoreUtils::ScrollSubstringTo.
|
2012-10-21 05:38:15 +04:00
|
|
|
nsRect frameRect = parentFrame->GetScreenRectInAppUnits();
|
2018-01-12 20:07:29 +03:00
|
|
|
nscoord offsetPointX = coordsInAppUnits.x - frameRect.X();
|
|
|
|
nscoord offsetPointY = coordsInAppUnits.y - frameRect.Y();
|
2007-09-25 09:48:51 +04:00
|
|
|
|
|
|
|
nsSize size(parentFrame->GetSize());
|
2009-11-10 17:07:19 +03:00
|
|
|
|
|
|
|
// avoid divide by zero
|
|
|
|
size.width = size.width ? size.width : 1;
|
|
|
|
size.height = size.height ? size.height : 1;
|
|
|
|
|
2012-10-21 05:38:15 +04:00
|
|
|
int16_t hPercent = offsetPointX * 100 / size.width;
|
|
|
|
int16_t vPercent = offsetPointY * 100 / size.height;
|
2007-09-25 09:48:51 +04:00
|
|
|
|
2014-08-08 03:48:38 +04:00
|
|
|
nsresult rv = nsCoreUtils::ScrollSubstringTo(
|
2020-01-17 05:10:31 +03:00
|
|
|
frame, range, ScrollAxis(vPercent, WhenToScroll::Always),
|
|
|
|
ScrollAxis(hPercent, WhenToScroll::Always));
|
2013-11-18 17:19:33 +04:00
|
|
|
if (NS_FAILED(rv)) return;
|
2007-09-25 09:48:51 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
initialScrolled = true;
|
2007-09-25 09:48:51 +04:00
|
|
|
} else {
|
|
|
|
// Substring was scrolled to the given point already inside its closest
|
|
|
|
// scrollable area. If there are nested scrollable areas then make
|
|
|
|
// sure we scroll lower areas to the given point inside currently
|
|
|
|
// traversed scrollable area.
|
2008-10-16 05:52:58 +04:00
|
|
|
nsCoreUtils::ScrollFrameToPoint(parentFrame, frame, coords);
|
2007-09-25 09:48:51 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
frame = parentFrame;
|
2007-08-24 08:54:45 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-27 20:33:09 +04:00
|
|
|
void HyperTextAccessible::EnclosingRange(a11y::TextRange& aRange) const {
|
2014-04-16 16:50:28 +04:00
|
|
|
if (IsTextField()) {
|
|
|
|
aRange.Set(mDoc, const_cast<HyperTextAccessible*>(this), 0,
|
2014-05-23 04:10:19 +04:00
|
|
|
const_cast<HyperTextAccessible*>(this), CharacterCount());
|
2014-04-16 16:50:28 +04:00
|
|
|
} else {
|
2014-05-23 04:10:19 +04:00
|
|
|
aRange.Set(mDoc, mDoc, 0, mDoc, mDoc->CharacterCount());
|
2014-04-16 16:50:28 +04:00
|
|
|
}
|
2014-02-27 20:33:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void HyperTextAccessible::SelectionRanges(
|
|
|
|
nsTArray<a11y::TextRange>* aRanges) const {
|
2014-04-10 20:09:40 +04:00
|
|
|
dom::Selection* sel = DOMSelection();
|
2020-06-23 21:52:42 +03:00
|
|
|
if (!sel) {
|
|
|
|
return;
|
2014-04-16 16:50:28 +04:00
|
|
|
}
|
2020-06-23 21:52:42 +03:00
|
|
|
|
|
|
|
TextRange::TextRangesFromSelection(sel, aRanges);
|
2014-02-27 20:33:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void HyperTextAccessible::VisibleRanges(
|
|
|
|
nsTArray<a11y::TextRange>* aRanges) const {}
|
|
|
|
|
|
|
|
void HyperTextAccessible::RangeByChild(Accessible* aChild,
|
|
|
|
a11y::TextRange& aRange) const {
|
2014-05-23 04:10:19 +04:00
|
|
|
HyperTextAccessible* ht = aChild->AsHyperText();
|
|
|
|
if (ht) {
|
|
|
|
aRange.Set(mDoc, ht, 0, ht, ht->CharacterCount());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Accessible* child = aChild;
|
|
|
|
Accessible* parent = nullptr;
|
|
|
|
while ((parent = child->Parent()) && !(ht = parent->AsHyperText()))
|
|
|
|
child = parent;
|
|
|
|
|
|
|
|
// If no text then return collapsed text range, otherwise return a range
|
|
|
|
// containing the text enclosed by the given child.
|
|
|
|
if (ht) {
|
|
|
|
int32_t childIdx = child->IndexInParent();
|
|
|
|
int32_t startOffset = ht->GetChildOffset(childIdx);
|
|
|
|
int32_t endOffset =
|
|
|
|
child->IsTextLeaf() ? ht->GetChildOffset(childIdx + 1) : startOffset;
|
|
|
|
aRange.Set(mDoc, ht, startOffset, ht, endOffset);
|
|
|
|
}
|
2014-02-27 20:33:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void HyperTextAccessible::RangeAtPoint(int32_t aX, int32_t aY,
|
|
|
|
a11y::TextRange& aRange) const {
|
2014-04-16 16:50:28 +04:00
|
|
|
Accessible* child = mDoc->ChildAtPoint(aX, aY, eDeepestChild);
|
2014-05-23 04:10:19 +04:00
|
|
|
if (!child) return;
|
|
|
|
|
|
|
|
Accessible* parent = nullptr;
|
|
|
|
while ((parent = child->Parent()) && !parent->IsHyperText()) child = parent;
|
|
|
|
|
|
|
|
// Return collapsed text range for the point.
|
|
|
|
if (parent) {
|
|
|
|
HyperTextAccessible* ht = parent->AsHyperText();
|
|
|
|
int32_t offset = ht->GetChildOffset(child);
|
|
|
|
aRange.Set(mDoc, ht, offset, ht, offset);
|
|
|
|
}
|
2014-02-27 20:33:09 +04:00
|
|
|
}
|
|
|
|
|
2010-06-21 17:08:27 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-05-29 05:18:45 +04:00
|
|
|
// Accessible public
|
2010-06-21 17:08:27 +04:00
|
|
|
|
2012-10-14 08:18:39 +04:00
|
|
|
// Accessible protected
|
2018-05-15 19:13:02 +03:00
|
|
|
ENameValueFlag HyperTextAccessible::NativeName(nsString& aName) const {
|
2013-06-12 13:13:34 +04:00
|
|
|
// Check @alt attribute for invalid img elements.
|
|
|
|
bool hasImgAlt = false;
|
2015-03-03 14:08:59 +03:00
|
|
|
if (mContent->IsHTMLElement(nsGkAtoms::img)) {
|
2017-12-07 21:13:50 +03:00
|
|
|
hasImgAlt = mContent->AsElement()->GetAttr(kNameSpaceID_None,
|
|
|
|
nsGkAtoms::alt, aName);
|
2013-06-12 13:13:34 +04:00
|
|
|
if (!aName.IsEmpty()) return eNameOK;
|
|
|
|
}
|
|
|
|
|
2012-10-17 10:38:16 +04:00
|
|
|
ENameValueFlag nameFlag = AccessibleWrap::NativeName(aName);
|
|
|
|
if (!aName.IsEmpty()) return nameFlag;
|
2011-11-24 15:31:25 +04:00
|
|
|
|
|
|
|
// Get name from title attribute for HTML abbr and acronym elements making it
|
|
|
|
// a valid name from markup. Otherwise their name isn't picked up by recursive
|
|
|
|
// name computation algorithm. See NS_OK_NAME_FROM_TOOLTIP.
|
2017-12-07 21:13:50 +03:00
|
|
|
if (IsAbbreviation() && mContent->AsElement()->GetAttr(
|
|
|
|
kNameSpaceID_None, nsGkAtoms::title, aName))
|
2012-10-14 08:18:39 +04:00
|
|
|
aName.CompressWhitespace();
|
|
|
|
|
2013-06-12 13:13:34 +04:00
|
|
|
return hasImgAlt ? eNoNameOnPurpose : eNameOK;
|
2011-11-24 15:31:25 +04:00
|
|
|
}
|
|
|
|
|
2016-04-01 03:46:58 +03:00
|
|
|
void HyperTextAccessible::Shutdown() {
|
2010-07-02 05:50:03 +04:00
|
|
|
mOffsets.Clear();
|
2016-04-01 03:46:58 +03:00
|
|
|
AccessibleWrap::Shutdown();
|
2010-06-21 17:08:27 +04:00
|
|
|
}
|
|
|
|
|
2012-05-31 12:04:41 +04:00
|
|
|
bool HyperTextAccessible::RemoveChild(Accessible* aAccessible) {
|
2020-06-08 11:50:15 +03:00
|
|
|
const int32_t childIndex = aAccessible->IndexInParent();
|
|
|
|
if (childIndex < static_cast<int64_t>(mOffsets.Length())) {
|
|
|
|
mOffsets.RemoveLastElements(mOffsets.Length() -
|
|
|
|
aAccessible->IndexInParent());
|
|
|
|
}
|
2011-02-02 20:02:48 +03:00
|
|
|
|
2016-06-10 00:33:48 +03:00
|
|
|
return AccessibleWrap::RemoveChild(aAccessible);
|
2011-02-02 20:02:48 +03:00
|
|
|
}
|
|
|
|
|
2016-04-01 10:39:00 +03:00
|
|
|
bool HyperTextAccessible::InsertChildAt(uint32_t aIndex, Accessible* aChild) {
|
2020-06-08 11:50:15 +03:00
|
|
|
if (aIndex < mOffsets.Length()) {
|
|
|
|
mOffsets.RemoveLastElements(mOffsets.Length() - aIndex);
|
2016-04-01 10:39:00 +03:00
|
|
|
}
|
2020-06-08 11:50:15 +03:00
|
|
|
|
2016-06-10 00:33:48 +03:00
|
|
|
return AccessibleWrap::InsertChildAt(aIndex, aChild);
|
2016-04-01 10:39:00 +03:00
|
|
|
}
|
|
|
|
|
2018-05-15 16:47:10 +03:00
|
|
|
Relation HyperTextAccessible::RelationByType(RelationType aType) const {
|
2015-06-24 16:40:00 +03:00
|
|
|
Relation rel = Accessible::RelationByType(aType);
|
|
|
|
|
|
|
|
switch (aType) {
|
|
|
|
case RelationType::NODE_CHILD_OF:
|
2015-07-02 15:50:00 +03:00
|
|
|
if (HasOwnContent() && mContent->IsMathMLElement()) {
|
2015-06-24 16:40:00 +03:00
|
|
|
Accessible* parent = Parent();
|
|
|
|
if (parent) {
|
|
|
|
nsIContent* parentContent = parent->GetContent();
|
2015-07-02 15:50:00 +03:00
|
|
|
if (parentContent &&
|
|
|
|
parentContent->IsMathMLElement(nsGkAtoms::mroot_)) {
|
2015-06-24 16:40:00 +03:00
|
|
|
// Add a relation pointing to the parent <mroot>.
|
|
|
|
rel.AppendTarget(parent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case RelationType::NODE_PARENT_OF:
|
2015-07-02 15:50:00 +03:00
|
|
|
if (HasOwnContent() && mContent->IsMathMLElement(nsGkAtoms::mroot_)) {
|
2015-06-24 16:40:00 +03:00
|
|
|
Accessible* base = GetChildAt(0);
|
|
|
|
Accessible* index = GetChildAt(1);
|
|
|
|
if (base && index) {
|
|
|
|
// Append the <mroot> children in the order index, base.
|
|
|
|
rel.AppendTarget(index);
|
|
|
|
rel.AppendTarget(base);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rel;
|
|
|
|
}
|
|
|
|
|
2010-06-21 17:08:27 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-05-31 12:04:41 +04:00
|
|
|
// HyperTextAccessible public static
|
2010-06-21 17:08:27 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
nsresult HyperTextAccessible::ContentToRenderedOffset(
|
|
|
|
nsIFrame* aFrame, int32_t aContentOffset, uint32_t* aRenderedOffset) const {
|
2007-11-27 21:12:15 +03:00
|
|
|
if (!aFrame) {
|
|
|
|
// Current frame not rendered -- this can happen if text is set on
|
|
|
|
// something with display: none
|
|
|
|
*aRenderedOffset = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-04-05 12:15:26 +04:00
|
|
|
|
|
|
|
if (IsTextField()) {
|
|
|
|
*aRenderedOffset = aContentOffset;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-04-30 18:30:08 +03:00
|
|
|
NS_ASSERTION(aFrame->IsTextFrame(), "Need text frame for offset conversion");
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ASSERTION(aFrame->GetPrevContinuation() == nullptr,
|
2007-09-05 17:31:33 +04:00
|
|
|
"Call on primary frame only");
|
|
|
|
|
2015-10-30 09:23:10 +03:00
|
|
|
nsIFrame::RenderedText text =
|
2015-11-30 16:21:25 +03:00
|
|
|
aFrame->GetRenderedText(aContentOffset, aContentOffset + 1,
|
2019-04-26 02:03:04 +03:00
|
|
|
nsIFrame::TextOffsetType::OffsetsInContentText,
|
|
|
|
nsIFrame::TrailingWhitespace::DontTrim);
|
2015-10-30 09:23:10 +03:00
|
|
|
*aRenderedOffset = text.mOffsetWithinNodeRenderedText;
|
2007-08-04 05:12:24 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
nsresult HyperTextAccessible::RenderedToContentOffset(
|
|
|
|
nsIFrame* aFrame, uint32_t aRenderedOffset, int32_t* aContentOffset) const {
|
2013-04-05 12:15:26 +04:00
|
|
|
if (IsTextField()) {
|
|
|
|
*aContentOffset = aRenderedOffset;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-11-27 21:12:15 +03:00
|
|
|
*aContentOffset = 0;
|
|
|
|
NS_ENSURE_TRUE(aFrame, NS_ERROR_FAILURE);
|
|
|
|
|
2017-04-30 18:30:08 +03:00
|
|
|
NS_ASSERTION(aFrame->IsTextFrame(), "Need text frame for offset conversion");
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ASSERTION(aFrame->GetPrevContinuation() == nullptr,
|
2007-09-05 17:31:33 +04:00
|
|
|
"Call on primary frame only");
|
|
|
|
|
2015-10-30 09:23:10 +03:00
|
|
|
nsIFrame::RenderedText text =
|
2015-11-30 16:21:25 +03:00
|
|
|
aFrame->GetRenderedText(aRenderedOffset, aRenderedOffset + 1,
|
2019-04-26 03:27:13 +03:00
|
|
|
nsIFrame::TextOffsetType::OffsetsInRenderedText,
|
2019-04-26 02:03:04 +03:00
|
|
|
nsIFrame::TrailingWhitespace::DontTrim);
|
2015-10-30 09:23:10 +03:00
|
|
|
*aContentOffset = text.mOffsetWithinNodeText;
|
2007-08-04 05:12:24 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-07-02 05:50:03 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-05-31 12:04:41 +04:00
|
|
|
// HyperTextAccessible public
|
2010-07-02 05:50:03 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t HyperTextAccessible::GetChildOffset(uint32_t aChildIndex,
|
2014-01-25 18:07:37 +04:00
|
|
|
bool aInvalidateAfter) const {
|
2011-01-20 11:02:10 +03:00
|
|
|
if (aChildIndex == 0) {
|
|
|
|
if (aInvalidateAfter) mOffsets.Clear();
|
|
|
|
|
2010-08-15 15:28:49 +04:00
|
|
|
return aChildIndex;
|
2011-01-20 11:02:10 +03:00
|
|
|
}
|
2010-07-02 05:50:03 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t count = mOffsets.Length() - aChildIndex;
|
2010-07-02 05:50:03 +04:00
|
|
|
if (count > 0) {
|
2010-08-15 15:28:49 +04:00
|
|
|
if (aInvalidateAfter) mOffsets.RemoveElementsAt(aChildIndex, count);
|
2010-07-02 05:50:03 +04:00
|
|
|
|
2010-08-15 15:28:49 +04:00
|
|
|
return mOffsets[aChildIndex - 1];
|
2010-07-02 05:50:03 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t lastOffset =
|
2010-07-02 05:50:03 +04:00
|
|
|
mOffsets.IsEmpty() ? 0 : mOffsets[mOffsets.Length() - 1];
|
|
|
|
|
2010-08-15 15:28:49 +04:00
|
|
|
while (mOffsets.Length() < aChildIndex) {
|
2012-05-29 05:18:45 +04:00
|
|
|
Accessible* child = mChildren[mOffsets.Length()];
|
2010-07-02 05:50:03 +04:00
|
|
|
lastOffset += nsAccUtils::TextLength(child);
|
|
|
|
mOffsets.AppendElement(lastOffset);
|
|
|
|
}
|
|
|
|
|
2010-08-15 15:28:49 +04:00
|
|
|
return mOffsets[aChildIndex - 1];
|
2010-07-02 05:50:03 +04:00
|
|
|
}
|
2010-05-25 12:40:26 +04:00
|
|
|
|
2014-01-25 18:07:37 +04:00
|
|
|
int32_t HyperTextAccessible::GetChildIndexAtOffset(uint32_t aOffset) const {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t lastOffset = 0;
|
2014-09-17 17:46:24 +04:00
|
|
|
const uint32_t offsetCount = mOffsets.Length();
|
|
|
|
|
2010-08-15 15:28:49 +04:00
|
|
|
if (offsetCount > 0) {
|
|
|
|
lastOffset = mOffsets[offsetCount - 1];
|
|
|
|
if (aOffset < lastOffset) {
|
2014-09-17 17:46:24 +04:00
|
|
|
size_t index;
|
|
|
|
if (BinarySearch(mOffsets, 0, offsetCount, aOffset, &index)) {
|
|
|
|
return (index < (offsetCount - 1)) ? index + 1 : index;
|
2010-08-15 15:28:49 +04:00
|
|
|
}
|
2010-06-21 17:08:27 +04:00
|
|
|
|
2014-09-17 17:46:24 +04:00
|
|
|
return (index == offsetCount) ? -1 : index;
|
2010-05-25 12:40:26 +04:00
|
|
|
}
|
2010-08-15 15:28:49 +04:00
|
|
|
}
|
2010-05-25 12:40:26 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t childCount = ChildCount();
|
2010-08-15 15:28:49 +04:00
|
|
|
while (mOffsets.Length() < childCount) {
|
2012-05-29 05:18:45 +04:00
|
|
|
Accessible* child = GetChildAt(mOffsets.Length());
|
2010-08-15 15:28:49 +04:00
|
|
|
lastOffset += nsAccUtils::TextLength(child);
|
|
|
|
mOffsets.AppendElement(lastOffset);
|
|
|
|
if (aOffset < lastOffset) return mOffsets.Length() - 1;
|
2010-05-25 12:40:26 +04:00
|
|
|
}
|
|
|
|
|
2010-08-15 15:28:49 +04:00
|
|
|
if (aOffset == lastOffset) return mOffsets.Length() - 1;
|
|
|
|
|
|
|
|
return -1;
|
2010-05-25 12:40:26 +04:00
|
|
|
}
|
|
|
|
|
2010-08-15 15:28:49 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-05-31 12:04:41 +04:00
|
|
|
// HyperTextAccessible protected
|
2010-08-15 15:28:49 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
nsresult HyperTextAccessible::GetDOMPointByFrameOffset(nsIFrame* aFrame,
|
|
|
|
int32_t aOffset,
|
2012-05-31 12:04:41 +04:00
|
|
|
Accessible* aAccessible,
|
2012-04-06 22:08:24 +04:00
|
|
|
DOMPoint* aPoint) {
|
2007-09-25 09:48:51 +04:00
|
|
|
NS_ENSURE_ARG(aAccessible);
|
|
|
|
|
|
|
|
if (!aFrame) {
|
|
|
|
// If the given frame is null then set offset after the DOM node of the
|
|
|
|
// given accessible.
|
2014-04-26 06:42:19 +04:00
|
|
|
NS_ASSERTION(!aAccessible->IsDoc(),
|
2012-04-15 06:24:37 +04:00
|
|
|
"Shouldn't be called on document accessible!");
|
|
|
|
|
|
|
|
nsIContent* content = aAccessible->GetContent();
|
|
|
|
NS_ASSERTION(content, "Shouldn't operate on defunct accessible!");
|
2007-09-25 09:48:51 +04:00
|
|
|
|
2012-04-15 06:24:37 +04:00
|
|
|
nsIContent* parent = content->GetParent();
|
2007-09-25 09:48:51 +04:00
|
|
|
|
2018-01-23 16:30:18 +03:00
|
|
|
aPoint->idx = parent->ComputeIndexOf(content) + 1;
|
2012-04-06 22:08:24 +04:00
|
|
|
aPoint->node = parent;
|
2007-09-25 09:48:51 +04:00
|
|
|
|
2017-04-30 18:30:08 +03:00
|
|
|
} else if (aFrame->IsTextFrame()) {
|
2012-04-06 22:08:24 +04:00
|
|
|
nsIContent* content = aFrame->GetContent();
|
2007-09-25 09:48:51 +04:00
|
|
|
NS_ENSURE_STATE(content);
|
|
|
|
|
2009-12-25 00:20:05 +03:00
|
|
|
nsIFrame* primaryFrame = content->GetPrimaryFrame();
|
2012-04-06 22:08:24 +04:00
|
|
|
nsresult rv =
|
|
|
|
RenderedToContentOffset(primaryFrame, aOffset, &(aPoint->idx));
|
2007-09-25 09:48:51 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-04-06 22:08:24 +04:00
|
|
|
aPoint->node = content;
|
2007-09-25 09:48:51 +04:00
|
|
|
|
|
|
|
} else {
|
2012-04-06 22:08:24 +04:00
|
|
|
nsIContent* content = aFrame->GetContent();
|
2007-09-25 09:48:51 +04:00
|
|
|
NS_ENSURE_STATE(content);
|
|
|
|
|
2012-04-06 22:08:24 +04:00
|
|
|
nsIContent* parent = content->GetParent();
|
2007-09-25 09:48:51 +04:00
|
|
|
NS_ENSURE_STATE(parent);
|
|
|
|
|
2018-01-23 16:30:18 +03:00
|
|
|
aPoint->idx = parent->ComputeIndexOf(content);
|
2012-04-06 22:08:24 +04:00
|
|
|
aPoint->node = parent;
|
2007-09-25 09:48:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-08-04 05:12:24 +04:00
|
|
|
|
2012-05-31 12:04:41 +04:00
|
|
|
// HyperTextAccessible
|
2014-04-26 06:42:19 +04:00
|
|
|
void HyperTextAccessible::GetSpellTextAttr(
|
|
|
|
nsINode* aNode, int32_t aNodeOffset, uint32_t* aStartOffset,
|
|
|
|
uint32_t* aEndOffset, nsIPersistentProperties* aAttributes) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsFrameSelection> fs = FrameSelection();
|
2012-10-20 04:56:58 +04:00
|
|
|
if (!fs) return;
|
2008-07-17 16:06:24 +04:00
|
|
|
|
2016-06-09 12:37:36 +03:00
|
|
|
dom::Selection* domSel = fs->GetSelection(SelectionType::eSpellCheck);
|
2012-10-20 04:56:58 +04:00
|
|
|
if (!domSel) return;
|
2008-07-17 16:06:24 +04:00
|
|
|
|
2015-02-25 19:08:00 +03:00
|
|
|
int32_t rangeCount = domSel->RangeCount();
|
2012-10-20 04:56:58 +04:00
|
|
|
if (rangeCount <= 0) return;
|
2008-07-17 16:06:24 +04:00
|
|
|
|
2014-05-17 03:16:34 +04:00
|
|
|
uint32_t startOffset = 0, endOffset = 0;
|
2012-10-20 04:56:58 +04:00
|
|
|
for (int32_t idx = 0; idx < rangeCount; idx++) {
|
2020-05-03 02:43:02 +03:00
|
|
|
const nsRange* range = domSel->GetRangeAt(idx);
|
2012-10-20 04:56:58 +04:00
|
|
|
if (range->Collapsed()) continue;
|
2008-07-17 16:06:24 +04:00
|
|
|
|
2012-10-20 04:56:58 +04:00
|
|
|
// See if the point comes after the range in which case we must continue in
|
|
|
|
// case there is another range after this one.
|
2017-07-11 15:11:37 +03:00
|
|
|
nsINode* endNode = range->GetEndContainer();
|
2014-04-26 06:42:19 +04:00
|
|
|
int32_t endNodeOffset = range->EndOffset();
|
2019-12-19 16:27:42 +03:00
|
|
|
Maybe<int32_t> order = nsContentUtils::ComparePoints(
|
|
|
|
aNode, aNodeOffset, endNode, endNodeOffset);
|
|
|
|
if (NS_WARN_IF(!order)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*order >= 0) {
|
2012-10-20 04:56:58 +04:00
|
|
|
continue;
|
2019-12-19 16:27:42 +03:00
|
|
|
}
|
2008-07-17 16:06:24 +04:00
|
|
|
|
2012-10-20 04:56:58 +04:00
|
|
|
// At this point our point is either in this range or before it but after
|
|
|
|
// the previous range. So we check to see if the range starts before the
|
|
|
|
// point in which case the point is in the missspelled range, otherwise it
|
|
|
|
// must be before the range and after the previous one if any.
|
2017-07-11 14:53:04 +03:00
|
|
|
nsINode* startNode = range->GetStartContainer();
|
2014-04-26 06:42:19 +04:00
|
|
|
int32_t startNodeOffset = range->StartOffset();
|
2019-12-19 16:27:42 +03:00
|
|
|
order = nsContentUtils::ComparePoints(startNode, startNodeOffset, aNode,
|
|
|
|
aNodeOffset);
|
|
|
|
if (!order) {
|
|
|
|
// As (`aNode`, `aNodeOffset`) is comparable to the end of the range, it
|
|
|
|
// should also be comparable to the range's start. Returning here
|
|
|
|
// prevents crashes in release builds.
|
|
|
|
MOZ_ASSERT_UNREACHABLE();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*order <= 0) {
|
2014-04-26 06:42:19 +04:00
|
|
|
startOffset = DOMPointToOffset(startNode, startNodeOffset);
|
2008-07-17 16:06:24 +04:00
|
|
|
|
2014-04-26 06:42:19 +04:00
|
|
|
endOffset = DOMPointToOffset(endNode, endNodeOffset);
|
2008-07-17 16:06:24 +04:00
|
|
|
|
2014-04-26 06:42:19 +04:00
|
|
|
if (startOffset > *aStartOffset) *aStartOffset = startOffset;
|
2012-10-20 04:56:58 +04:00
|
|
|
|
2014-04-26 06:42:19 +04:00
|
|
|
if (endOffset < *aEndOffset) *aEndOffset = endOffset;
|
2008-07-17 16:06:24 +04:00
|
|
|
|
2008-07-24 19:20:39 +04:00
|
|
|
if (aAttributes) {
|
2020-07-01 11:29:29 +03:00
|
|
|
nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::invalid, u"spelling"_ns);
|
2008-07-24 19:20:39 +04:00
|
|
|
}
|
2008-07-17 16:06:24 +04:00
|
|
|
|
2014-04-26 06:42:19 +04:00
|
|
|
return;
|
2008-07-17 16:06:24 +04:00
|
|
|
}
|
2012-10-20 04:56:58 +04:00
|
|
|
|
|
|
|
// This range came after the point.
|
2014-04-26 06:42:19 +04:00
|
|
|
endOffset = DOMPointToOffset(startNode, startNodeOffset);
|
2012-10-20 04:56:58 +04:00
|
|
|
|
|
|
|
if (idx > 0) {
|
2020-05-03 02:43:02 +03:00
|
|
|
const nsRange* prevRange = domSel->GetRangeAt(idx - 1);
|
2017-07-11 15:11:37 +03:00
|
|
|
startOffset = DOMPointToOffset(prevRange->GetEndContainer(),
|
2014-04-26 06:42:19 +04:00
|
|
|
prevRange->EndOffset());
|
2012-10-20 04:56:58 +04:00
|
|
|
}
|
|
|
|
|
2018-08-24 06:08:28 +03:00
|
|
|
// The previous range might not be within this accessible. In that case,
|
|
|
|
// DOMPointToOffset returns length as a fallback. We don't want to use
|
|
|
|
// that offset if so, hence the startOffset < *aEndOffset check.
|
|
|
|
if (startOffset > *aStartOffset && startOffset < *aEndOffset)
|
2014-04-26 06:42:19 +04:00
|
|
|
*aStartOffset = startOffset;
|
2012-10-20 04:56:58 +04:00
|
|
|
|
2014-04-26 06:42:19 +04:00
|
|
|
if (endOffset < *aEndOffset) *aEndOffset = endOffset;
|
2012-10-20 04:56:58 +04:00
|
|
|
|
2014-04-26 06:42:19 +04:00
|
|
|
return;
|
2008-07-17 16:06:24 +04:00
|
|
|
}
|
|
|
|
|
2012-10-20 04:56:58 +04:00
|
|
|
// We never found a range that ended after the point, therefore we know that
|
|
|
|
// the point is not in a range, that we do not need to compute an end offset,
|
|
|
|
// and that we should use the end offset of the last range to compute the
|
|
|
|
// start offset of the text attribute range.
|
2020-05-03 02:43:02 +03:00
|
|
|
const nsRange* prevRange = domSel->GetRangeAt(rangeCount - 1);
|
2017-07-11 15:11:37 +03:00
|
|
|
startOffset =
|
|
|
|
DOMPointToOffset(prevRange->GetEndContainer(), prevRange->EndOffset());
|
2012-10-20 04:56:58 +04:00
|
|
|
|
2018-08-24 06:08:28 +03:00
|
|
|
// The previous range might not be within this accessible. In that case,
|
|
|
|
// DOMPointToOffset returns length as a fallback. We don't want to use
|
|
|
|
// that offset if so, hence the startOffset < *aEndOffset check.
|
|
|
|
if (startOffset > *aStartOffset && startOffset < *aEndOffset)
|
2014-04-26 06:42:19 +04:00
|
|
|
*aStartOffset = startOffset;
|
2008-07-17 16:06:24 +04:00
|
|
|
}
|
2012-04-14 05:19:41 +04:00
|
|
|
|
2012-05-31 12:04:41 +04:00
|
|
|
bool HyperTextAccessible::IsTextRole() {
|
2016-07-12 22:34:13 +03:00
|
|
|
const nsRoleMapEntry* roleMapEntry = ARIARoleMap();
|
|
|
|
if (roleMapEntry && (roleMapEntry->role == roles::GRAPHIC ||
|
|
|
|
roleMapEntry->role == roles::IMAGE_MAP ||
|
|
|
|
roleMapEntry->role == roles::SLIDER ||
|
|
|
|
roleMapEntry->role == roles::PROGRESSBAR ||
|
|
|
|
roleMapEntry->role == roles::SEPARATOR))
|
2012-04-14 05:19:41 +04:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|