2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2013-03-29 04:05:39 -07:00
|
|
|
/* vim: set ts=2 sw=2 et tw=78: */
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-11-18 05:19:33 -08:00
|
|
|
#include "HyperTextAccessible-inl.h"
|
2010-04-26 23:52:03 -07:00
|
|
|
|
2012-04-13 07:17:03 -07:00
|
|
|
#include "Accessible-inl.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsAccessibilityService.h"
|
2013-10-26 07:58:53 -07:00
|
|
|
#include "nsIAccessibleTypes.h"
|
2012-05-27 02:01:40 -07:00
|
|
|
#include "DocAccessible.h"
|
2014-02-05 07:21:32 -08:00
|
|
|
#include "HTMLListAccessible.h"
|
2012-01-11 19:07:35 -08:00
|
|
|
#include "Role.h"
|
|
|
|
#include "States.h"
|
2012-03-09 23:29:51 -08:00
|
|
|
#include "TextAttrs.h"
|
2014-02-27 08:33:09 -08:00
|
|
|
#include "TextRange.h"
|
2013-09-11 09:56:01 -07:00
|
|
|
#include "TreeWalker.h"
|
2008-07-17 05:06:24 -07:00
|
|
|
|
2013-10-26 07:58:53 -07:00
|
|
|
#include "nsCaret.h"
|
2012-03-06 09:08:02 -08:00
|
|
|
#include "nsContentUtils.h"
|
2011-10-15 20:38:19 -07:00
|
|
|
#include "nsFocusManager.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDOMRange.h"
|
2007-08-14 09:25:24 -07:00
|
|
|
#include "nsIEditingSession.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIFrame.h"
|
2007-12-04 23:34:47 -08:00
|
|
|
#include "nsFrameSelection.h"
|
2007-12-11 06:15:21 -08:00
|
|
|
#include "nsILineIterator.h"
|
2007-08-14 09:25:24 -07:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
2013-09-10 15:18:59 -07:00
|
|
|
#include "nsIPersistentProperties2.h"
|
2007-12-11 06:15:21 -08:00
|
|
|
#include "nsIScrollableFrame.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIServiceManager.h"
|
2013-12-20 08:53:58 -08:00
|
|
|
#include "nsITextControlElement.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsTextFragment.h"
|
2014-01-21 08:24:23 -08:00
|
|
|
#include "mozilla/dom/Element.h"
|
2014-04-02 21:18:36 -07:00
|
|
|
#include "mozilla/EventStates.h"
|
2014-04-10 09:09:40 -07:00
|
|
|
#include "mozilla/dom/Selection.h"
|
2013-09-30 08:56:44 -07:00
|
|
|
#include "mozilla/MathAlgorithms.h"
|
2007-08-03 18:12:24 -07:00
|
|
|
#include "gfxSkipChars.h"
|
2013-01-15 04:22:03 -08:00
|
|
|
#include <algorithm>
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-04-06 17:09:31 -07:00
|
|
|
using namespace mozilla;
|
2011-07-27 05:43:01 -07:00
|
|
|
using namespace mozilla::a11y;
|
|
|
|
|
2010-06-11 01:23:18 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-05-31 01:04:41 -07:00
|
|
|
// HyperTextAccessible
|
2010-06-11 01:23:18 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-05-31 01:04:41 -07:00
|
|
|
HyperTextAccessible::
|
|
|
|
HyperTextAccessible(nsIContent* aNode, DocAccessible* aDoc) :
|
2013-11-18 05:19:33 -08:00
|
|
|
AccessibleWrap(aNode, aDoc), xpcAccessibleHyperText()
|
2010-06-11 01:23:18 -07:00
|
|
|
{
|
2012-12-17 21:22:26 -08:00
|
|
|
mGenericTypes |= eHyperText;
|
2010-06-11 01:23:18 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-05-31 01:04:41 -07:00
|
|
|
nsresult
|
|
|
|
HyperTextAccessible::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-11-18 05:19:33 -08:00
|
|
|
xpcAccessibleHyperText::QueryInterface(aIID, aInstancePtr);
|
|
|
|
return *aInstancePtr ? NS_OK : Accessible::QueryInterface(aIID, aInstancePtr);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2013-11-18 05:19:33 -08:00
|
|
|
NS_IMPL_ADDREF_INHERITED(HyperTextAccessible, AccessibleWrap)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(HyperTextAccessible, AccessibleWrap)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-01-11 19:07:35 -08:00
|
|
|
role
|
2012-05-31 01:04:41 -07:00
|
|
|
HyperTextAccessible::NativeRole()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-11 01:23:18 -07:00
|
|
|
nsIAtom *tag = mContent->Tag();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-04-24 11:35:23 -07:00
|
|
|
if (tag == nsGkAtoms::dd)
|
|
|
|
return roles::DEFINITION;
|
|
|
|
|
2011-06-03 14:35:17 -07:00
|
|
|
if (tag == nsGkAtoms::form)
|
2012-01-11 19:07:35 -08:00
|
|
|
return roles::FORM;
|
2010-09-04 19:14:01 -07:00
|
|
|
|
2012-01-11 19:07:35 -08:00
|
|
|
if (tag == nsGkAtoms::blockquote || tag == nsGkAtoms::div ||
|
2012-03-28 01:20:50 -07:00
|
|
|
tag == nsGkAtoms::section || tag == nsGkAtoms::nav)
|
2012-01-11 19:07:35 -08:00
|
|
|
return roles::SECTION;
|
2010-09-04 19:14:01 -07:00
|
|
|
|
2012-01-11 19:07:35 -08:00
|
|
|
if (tag == nsGkAtoms::h1 || tag == nsGkAtoms::h2 ||
|
|
|
|
tag == nsGkAtoms::h3 || tag == nsGkAtoms::h4 ||
|
|
|
|
tag == nsGkAtoms::h5 || tag == nsGkAtoms::h6)
|
|
|
|
return roles::HEADING;
|
2010-09-04 19:14:01 -07:00
|
|
|
|
2011-06-03 14:35:17 -07:00
|
|
|
if (tag == nsGkAtoms::article)
|
2012-01-11 19:07:35 -08:00
|
|
|
return roles::DOCUMENT;
|
2010-11-29 10:32:19 -08:00
|
|
|
|
2010-11-08 05:33:34 -08:00
|
|
|
// Deal with html landmark elements
|
2011-06-03 14:35:17 -07:00
|
|
|
if (tag == nsGkAtoms::header)
|
2012-01-11 19:07:35 -08:00
|
|
|
return roles::HEADER;
|
2010-11-08 05:33:34 -08:00
|
|
|
|
2011-06-03 14:35:17 -07:00
|
|
|
if (tag == nsGkAtoms::footer)
|
2012-01-11 19:07:35 -08:00
|
|
|
return roles::FOOTER;
|
2010-11-08 05:33:34 -08:00
|
|
|
|
2011-06-03 14:35:17 -07:00
|
|
|
if (tag == nsGkAtoms::aside)
|
2012-01-11 19:07:35 -08:00
|
|
|
return roles::NOTE;
|
2010-11-15 10:30:44 -08:00
|
|
|
|
2010-11-08 05:33:34 -08:00
|
|
|
// Treat block frames as paragraphs
|
2010-09-04 19:14:01 -07:00
|
|
|
nsIFrame *frame = GetFrame();
|
2011-11-30 04:36:20 -08:00
|
|
|
if (frame && frame->GetType() == nsGkAtoms::blockFrame)
|
2012-01-11 19:07:35 -08:00
|
|
|
return roles::PARAGRAPH;
|
2010-09-04 19:14:01 -07:00
|
|
|
|
2012-01-11 19:07:35 -08:00
|
|
|
return roles::TEXT_CONTAINER; // In ATK this works
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t
|
2012-05-31 01:04:41 -07:00
|
|
|
HyperTextAccessible::NativeState()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t states = AccessibleWrap::NativeState();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-01-21 08:24:23 -08:00
|
|
|
if (mContent->AsElement()->State().HasState(NS_EVENT_STATE_MOZ_READWRITE)) {
|
2012-03-14 10:48:01 -07:00
|
|
|
states |= states::EDITABLE;
|
|
|
|
|
2011-06-03 14:35:17 -07:00
|
|
|
} else if (mContent->Tag() == nsGkAtoms::article) {
|
2010-11-29 10:32:19 -08:00
|
|
|
// We want <article> to behave like a document in terms of readonly state.
|
2011-04-09 16:38:06 -07:00
|
|
|
states |= states::READONLY;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-05-25 03:53:45 -07:00
|
|
|
if (HasChildren())
|
2011-04-09 16:38:06 -07:00
|
|
|
states |= states::SELECTABLE_TEXT;
|
2007-04-02 08:56:24 -07:00
|
|
|
|
2011-04-09 16:38:06 -07:00
|
|
|
return states;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-05-31 01:04:41 -07:00
|
|
|
nsIntRect
|
2013-11-25 10:28:27 -08:00
|
|
|
HyperTextAccessible::GetBoundsInFrame(nsIFrame* aFrame,
|
|
|
|
uint32_t aStartRenderedOffset,
|
|
|
|
uint32_t aEndRenderedOffset)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-10-20 04:04:45 -07:00
|
|
|
nsPresContext* presContext = mDoc->PresContext();
|
2011-06-03 14:35:17 -07:00
|
|
|
if (aFrame->GetType() != nsGkAtoms::textFrame) {
|
2012-10-20 04:04:45 -07:00
|
|
|
return aFrame->GetScreenRectInAppUnits().
|
|
|
|
ToNearestPixels(presContext->AppUnitsPerDevPixel());
|
2007-09-05 06:31:33 -07:00
|
|
|
}
|
2007-08-03 18:12:24 -07:00
|
|
|
|
2013-11-25 10:28:27 -08:00
|
|
|
// Substring must be entirely within the same text node.
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t startContentOffset, endContentOffset;
|
2007-08-10 12:24:10 -07:00
|
|
|
nsresult rv = RenderedToContentOffset(aFrame, aStartRenderedOffset, &startContentOffset);
|
2012-10-20 04:04:45 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, nsIntRect());
|
2007-08-10 12:24:10 -07:00
|
|
|
rv = RenderedToContentOffset(aFrame, aEndRenderedOffset, &endContentOffset);
|
2012-10-20 04:04:45 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, nsIntRect());
|
2007-08-03 18:12:24 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame *frame;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t startContentOffsetInFrame;
|
2007-08-03 18:12:24 -07:00
|
|
|
// Get the right frame continuation -- not really a child, but a sibling of
|
|
|
|
// the primary frame passed in
|
2011-10-17 07:59:28 -07:00
|
|
|
rv = aFrame->GetChildFrameContainingOffset(startContentOffset, false,
|
2007-08-10 12:24:10 -07:00
|
|
|
&startContentOffsetInFrame, &frame);
|
2012-10-20 04:04:45 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, nsIntRect());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-10-20 04:04:45 -07:00
|
|
|
nsRect screenRect;
|
2007-08-10 12:24:10 -07:00
|
|
|
while (frame && startContentOffset < endContentOffset) {
|
2007-03-22 10:30:00 -07: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 04:04:45 -07:00
|
|
|
nsRect frameScreenRect = frame->GetScreenRectInAppUnits();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Get the length of the substring in this frame that we want the bounds for
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t startFrameTextOffset, endFrameTextOffset;
|
2007-03-22 10:30:00 -07:00
|
|
|
frame->GetOffsets(startFrameTextOffset, endFrameTextOffset);
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t frameTotalTextLength = endFrameTextOffset - startFrameTextOffset;
|
|
|
|
int32_t seekLength = endContentOffset - startContentOffset;
|
2013-01-15 04:22:03 -08:00
|
|
|
int32_t frameSubStringLength = std::min(frameTotalTextLength - startContentOffsetInFrame, seekLength);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Add the point where the string starts to the frameScreenRect
|
|
|
|
nsPoint frameTextStartPoint;
|
2007-08-16 20:43:00 -07:00
|
|
|
rv = frame->GetPointFromOffset(startContentOffset, &frameTextStartPoint);
|
2009-01-14 19:27:09 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, nsIntRect());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Use the point for the end offset to calculate the width
|
|
|
|
nsPoint frameTextEndPoint;
|
2007-08-16 20:43:00 -07:00
|
|
|
rv = frame->GetPointFromOffset(startContentOffset + frameSubStringLength, &frameTextEndPoint);
|
2009-01-14 19:27:09 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, nsIntRect());
|
2013-09-27 07:15:19 -07:00
|
|
|
|
|
|
|
frameScreenRect.x += std::min(frameTextStartPoint.x, frameTextEndPoint.x);
|
2013-09-30 08:56:44 -07:00
|
|
|
frameScreenRect.width = mozilla::Abs(frameTextStartPoint.x - frameTextEndPoint.x);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
screenRect.UnionRect(frameScreenRect, screenRect);
|
|
|
|
|
|
|
|
// Get ready to loop back for next frame continuation
|
2007-08-10 12:24:10 -07:00
|
|
|
startContentOffset += frameSubStringLength;
|
|
|
|
startContentOffsetInFrame = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
frame = frame->GetNextContinuation();
|
|
|
|
}
|
|
|
|
|
2012-10-20 04:04:45 -07:00
|
|
|
return screenRect.ToNearestPixels(presContext->AppUnitsPerDevPixel());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-11-18 05:19:33 -08:00
|
|
|
void
|
|
|
|
HyperTextAccessible::TextSubstring(int32_t aStartOffset, int32_t aEndOffset,
|
|
|
|
nsAString& aText)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-02-01 08:08:36 -08:00
|
|
|
aText.Truncate();
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t startOffset = ConvertMagicOffset(aStartOffset);
|
|
|
|
int32_t endOffset = ConvertMagicOffset(aEndOffset);
|
2012-05-23 11:06:07 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t startChildIdx = GetChildIndexAtOffset(startOffset);
|
2013-11-18 05:19:33 -08:00
|
|
|
if (startChildIdx == -1)
|
|
|
|
return;
|
2011-02-01 08:08:36 -08:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t endChildIdx = GetChildIndexAtOffset(endOffset);
|
2011-02-01 08:08:36 -08:00
|
|
|
if (endChildIdx == -1)
|
2013-11-18 05:19:33 -08:00
|
|
|
return;
|
2011-02-01 08:08:36 -08:00
|
|
|
|
|
|
|
if (startChildIdx == endChildIdx) {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t childOffset = GetChildOffset(startChildIdx);
|
2013-11-18 05:19:33 -08:00
|
|
|
if (childOffset == -1)
|
|
|
|
return;
|
2011-02-01 08:08:36 -08:00
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* child = GetChildAt(startChildIdx);
|
2011-02-03 06:29:12 -08:00
|
|
|
child->AppendTextTo(aText, startOffset - childOffset,
|
|
|
|
endOffset - startOffset);
|
2013-11-18 05:19:33 -08:00
|
|
|
return;
|
2011-02-01 08:08:36 -08:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t startChildOffset = GetChildOffset(startChildIdx);
|
2013-11-18 05:19:33 -08:00
|
|
|
if (startChildOffset == -1)
|
|
|
|
return;
|
2011-02-01 08:08:36 -08:00
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* startChild = GetChildAt(startChildIdx);
|
2011-02-03 06:29:12 -08:00
|
|
|
startChild->AppendTextTo(aText, startOffset - startChildOffset);
|
2011-02-01 08:08:36 -08:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t childIdx = startChildIdx + 1; childIdx < endChildIdx; childIdx++) {
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* child = GetChildAt(childIdx);
|
2011-02-01 08:08:36 -08:00
|
|
|
child->AppendTextTo(aText);
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t endChildOffset = GetChildOffset(endChildIdx);
|
2013-11-18 05:19:33 -08:00
|
|
|
if (endChildOffset == -1)
|
|
|
|
return;
|
2011-02-01 08:08:36 -08:00
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* endChild = GetChildAt(endChildIdx);
|
2011-02-03 06:29:12 -08:00
|
|
|
endChild->AppendTextTo(aText, 0, endOffset - endChildOffset);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-02-03 16:56:45 -08:00
|
|
|
int32_t
|
|
|
|
HyperTextAccessible::DOMPointToOffset(nsINode* aNode, int32_t aNodeOffset,
|
|
|
|
bool aIsEndOffset) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-05-17 09:16:52 -07:00
|
|
|
if (!aNode)
|
2014-02-03 16:56:45 -08:00
|
|
|
return 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-02-05 07:21:32 -08:00
|
|
|
uint32_t offset = 0;
|
2012-07-30 07:20:58 -07:00
|
|
|
nsINode* findNode = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-08-28 14:57:53 -07:00
|
|
|
if (aNodeOffset == -1) {
|
|
|
|
findNode = aNode;
|
2010-06-11 01:23:18 -07:00
|
|
|
|
|
|
|
} else if (aNode->IsNodeOfType(nsINode::eTEXT)) {
|
2007-03-22 10:30:00 -07: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 hypertext
|
2007-08-03 18:12:24 -07:00
|
|
|
// We want the "skipped" offset into the text (rendered text without the extra whitespace)
|
2014-02-03 16:56:45 -08:00
|
|
|
nsIFrame* frame = aNode->AsContent()->GetPrimaryFrame();
|
|
|
|
NS_ENSURE_TRUE(frame, 0);
|
|
|
|
|
2014-02-05 07:21:32 -08:00
|
|
|
nsresult rv = ContentToRenderedOffset(frame, aNodeOffset, &offset);
|
2014-02-03 16:56:45 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, 0);
|
2007-03-22 10:30:00 -07:00
|
|
|
// Get the child node and
|
|
|
|
findNode = aNode;
|
2010-06-11 01:23:18 -07:00
|
|
|
|
|
|
|
} else {
|
|
|
|
// findNode could be null if aNodeOffset == # of child nodes, which means
|
|
|
|
// one of two things:
|
2013-01-05 02:14:34 -08:00
|
|
|
// 1) there are no children, and the passed-in node is not mContent -- use
|
2010-06-11 01:23:18 -07:00
|
|
|
// parentContent for the node to find
|
2013-01-05 02:14:34 -08: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 01:23:18 -07:00
|
|
|
|
|
|
|
findNode = aNode->GetChildAt(aNodeOffset);
|
2013-01-05 02:14:34 -08: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-03 16:56:45 -08:00
|
|
|
return 0;
|
2013-01-05 02:14:34 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Case #2: there are no children, we're at this node.
|
|
|
|
findNode = aNode;
|
|
|
|
} else if (aNodeOffset == aNode->GetChildCount()) {
|
|
|
|
// 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-10 18:44:44 -07:00
|
|
|
}
|
2007-04-19 06:56:09 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07: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-03 16:56:45 -08:00
|
|
|
Accessible* descendant = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (findNode) {
|
2010-06-11 01:23:18 -07:00
|
|
|
nsCOMPtr<nsIContent> findContent(do_QueryInterface(findNode));
|
|
|
|
if (findContent && findContent->IsHTML() &&
|
2011-06-03 14:35:17 -07:00
|
|
|
findContent->NodeInfo()->Equals(nsGkAtoms::br) &&
|
2010-02-08 13:02:18 -08:00
|
|
|
findContent->AttrValueIs(kNameSpaceID_None,
|
2011-06-03 14:35:17 -07:00
|
|
|
nsGkAtoms::mozeditorbogusnode,
|
|
|
|
nsGkAtoms::_true,
|
2010-02-08 13:02:18 -08:00
|
|
|
eIgnoreCase)) {
|
|
|
|
// This <br> is the hacky "bogus node" used when there is no text in a control
|
2014-02-03 16:56:45 -08:00
|
|
|
return 0;
|
2008-01-21 17:32:11 -08:00
|
|
|
}
|
2014-02-15 07:21:40 -08:00
|
|
|
|
|
|
|
descendant = mDoc->GetAccessible(findNode);
|
|
|
|
if (!descendant && findNode->IsContent()) {
|
|
|
|
Accessible* container = mDoc->GetContainerAccessible(findNode);
|
|
|
|
if (container) {
|
|
|
|
TreeWalker walker(container, findNode->AsContent(),
|
|
|
|
TreeWalker::eWalkContextTree);
|
|
|
|
descendant = walker.NextChild();
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-04-19 06:39:57 -07:00
|
|
|
|
2014-02-05 07:21:32 -08:00
|
|
|
return TransformOffset(descendant, offset, aIsEndOffset);
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
|
|
|
HyperTextAccessible::TransformOffset(Accessible* aDescendant,
|
|
|
|
int32_t aOffset, bool aIsEndOffset) const
|
|
|
|
{
|
|
|
|
// From the descendant, go up and get the immediate child of this hypertext.
|
|
|
|
int32_t offset = aOffset;
|
|
|
|
Accessible* descendant = aDescendant;
|
2014-02-03 16:56:45 -08:00
|
|
|
while (descendant) {
|
|
|
|
Accessible* parent = descendant->Parent();
|
2014-02-05 07:21:32 -08:00
|
|
|
if (parent == this)
|
|
|
|
return GetChildOffset(descendant) + offset;
|
2010-04-19 06:39:57 -07:00
|
|
|
|
2014-01-22 15:14:06 -08: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.
|
|
|
|
if (aIsEndOffset)
|
2014-02-05 07:21:32 -08:00
|
|
|
offset = (offset > 0 || descendant->IndexInParent() > 0) ? 1 : 0;
|
2014-01-22 15:14:06 -08:00
|
|
|
else
|
2014-02-05 07:21:32 -08:00
|
|
|
offset = 0;
|
2010-04-19 06:39:57 -07:00
|
|
|
|
2014-02-03 16:56:45 -08:00
|
|
|
descendant = parent;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-08-28 14:57:53 -07:00
|
|
|
|
2014-02-05 07:21:32 -08:00
|
|
|
// If the given a11y point cannot be mapped into offset relative this hypertext
|
2014-02-03 16:56:45 -08:00
|
|
|
// offset then return length as fallback value.
|
2014-02-05 07:21:32 -08:00
|
|
|
return CharacterCount();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-12-13 08:26:35 -08:00
|
|
|
bool
|
|
|
|
HyperTextAccessible::OffsetsToDOMRange(int32_t aStartOffset, int32_t aEndOffset,
|
|
|
|
nsRange* aRange)
|
2007-09-24 22:48:51 -07:00
|
|
|
{
|
2013-12-13 08:26:35 -08:00
|
|
|
DOMPoint startPoint = OffsetToDOMPoint(aStartOffset);
|
|
|
|
if (!startPoint.node)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
aRange->SetStart(startPoint.node, startPoint.idx);
|
|
|
|
if (aStartOffset == aEndOffset) {
|
|
|
|
aRange->SetEnd(startPoint.node, startPoint.idx);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
DOMPoint endPoint = OffsetToDOMPoint(aEndOffset);
|
|
|
|
if (!endPoint.node)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
aRange->SetEnd(endPoint.node, endPoint.idx);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
DOMPoint
|
|
|
|
HyperTextAccessible::OffsetToDOMPoint(int32_t aOffset)
|
|
|
|
{
|
|
|
|
// 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) {
|
2012-03-07 19:28:38 -08:00
|
|
|
nsCOMPtr<nsIEditor> editor = GetEditor();
|
2008-08-28 07:48:41 -07:00
|
|
|
if (editor) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isEmpty = false;
|
2008-08-28 07:48:41 -07:00
|
|
|
editor->GetDocumentIsEmpty(&isEmpty);
|
|
|
|
if (isEmpty) {
|
|
|
|
nsCOMPtr<nsIDOMElement> editorRootElm;
|
|
|
|
editor->GetRootElement(getter_AddRefs(editorRootElm));
|
|
|
|
|
2012-04-06 11:08:24 -07:00
|
|
|
nsCOMPtr<nsINode> editorRoot(do_QueryInterface(editorRootElm));
|
2013-12-13 08:26:35 -08:00
|
|
|
return DOMPoint(editorRoot, 0);
|
2008-08-28 07:48:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-13 08:26:35 -08:00
|
|
|
int32_t childIdx = GetChildIndexAtOffset(aOffset);
|
|
|
|
if (childIdx == -1)
|
|
|
|
return DOMPoint();
|
2007-09-24 22:48:51 -07:00
|
|
|
|
2013-12-13 08:26:35 -08:00
|
|
|
Accessible* child = GetChildAt(childIdx);
|
|
|
|
int32_t innerOffset = aOffset - GetChildOffset(childIdx);
|
2007-09-24 22:48:51 -07:00
|
|
|
|
2013-12-13 08:26:35 -08:00
|
|
|
// A text leaf case. The point is inside the text node.
|
|
|
|
if (child->IsTextLeaf()) {
|
|
|
|
nsIContent* content = child->GetContent();
|
|
|
|
int32_t idx = 0;
|
|
|
|
if (NS_FAILED(RenderedToContentOffset(content->GetPrimaryFrame(),
|
|
|
|
innerOffset, &idx)))
|
|
|
|
return DOMPoint();
|
2007-09-24 22:48:51 -07:00
|
|
|
|
2013-12-13 08:26:35 -08:00
|
|
|
return DOMPoint(content, idx);
|
|
|
|
}
|
2007-09-24 22:48:51 -07:00
|
|
|
|
2013-12-13 08:26:35 -08: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();
|
|
|
|
return parentNode ?
|
|
|
|
DOMPoint(parentNode, parentNode->IndexOf(node) + innerOffset) :
|
|
|
|
DOMPoint();
|
2007-09-24 22:48:51 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t
|
2013-12-06 10:47:00 -08:00
|
|
|
HyperTextAccessible::FindOffset(int32_t aOffset, nsDirection aDirection,
|
|
|
|
nsSelectionAmount aAmount,
|
|
|
|
EWordMovementType aWordMovementType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-12-16 18:32:12 -08: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);
|
|
|
|
NS_ASSERTION(childIdx != -1, "Bad in offset!");
|
|
|
|
if (childIdx == -1)
|
2013-12-06 10:47:00 -08:00
|
|
|
return -1;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-12-16 18:32:12 -08:00
|
|
|
child = text->GetChildAt(childIdx);
|
2014-02-05 07:21:32 -08: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()) {
|
|
|
|
// It works only when the bullet is one single char.
|
|
|
|
if (aDirection == eDirPrevious)
|
|
|
|
return text != this ? TransformOffset(text, 0, false) : 0;
|
|
|
|
|
|
|
|
if (aAmount == eSelectEndLine || aAmount == eSelectLine) {
|
|
|
|
if (text != this)
|
|
|
|
return TransformOffset(text, 1, true);
|
|
|
|
|
|
|
|
// Ask a text leaf next (if not empty) to the bullet for an offset
|
|
|
|
// since list item may be multiline.
|
|
|
|
return aOffset + 1 < CharacterCount() ?
|
|
|
|
FindOffset(aOffset + 1, aDirection, aAmount, aWordMovementType) : 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Case of word and char boundaries.
|
|
|
|
return text != this ? TransformOffset(text, 1, true) : 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-16 18:32:12 -08:00
|
|
|
innerOffset -= text->GetChildOffset(childIdx);
|
|
|
|
|
|
|
|
text = child->AsHyperText();
|
|
|
|
} while (text);
|
2007-08-03 18:12:24 -07:00
|
|
|
|
2013-12-16 18:32:12 -08:00
|
|
|
nsIFrame* childFrame = child->GetFrame();
|
|
|
|
NS_ENSURE_TRUE(childFrame, -1);
|
2008-10-31 20:58:07 -07:00
|
|
|
|
2013-12-16 18:32:12 -08:00
|
|
|
int32_t innerContentOffset = innerOffset;
|
|
|
|
if (child->IsTextLeaf()) {
|
|
|
|
NS_ASSERTION(childFrame->GetType() == nsGkAtoms::textFrame, "Wrong frame!");
|
|
|
|
RenderedToContentOffset(childFrame, innerOffset, &innerContentOffset);
|
2007-08-29 00:12:09 -07:00
|
|
|
}
|
2007-08-03 18:12:24 -07:00
|
|
|
|
2013-12-16 18:32:12 -08:00
|
|
|
nsIFrame* frameAtOffset = childFrame;
|
|
|
|
int32_t unusedOffsetInFrame = 0;
|
|
|
|
childFrame->GetChildFrameContainingOffset(innerContentOffset, true,
|
|
|
|
&unusedOffsetInFrame,
|
|
|
|
&frameAtOffset);
|
|
|
|
|
2013-12-06 10:47:00 -08: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-16 18:32:12 -08:00
|
|
|
nsPeekOffsetStruct pos(aAmount, aDirection, innerContentOffset,
|
2013-12-06 10:47:00 -08:00
|
|
|
0, kIsJumpLinesOk, kIsScrollViewAStop,
|
|
|
|
kIsKeyboardSelect, kIsVisualBidi,
|
2013-03-23 17:57:06 -07:00
|
|
|
aWordMovementType);
|
2013-12-16 18:32:12 -08:00
|
|
|
nsresult rv = frameAtOffset->PeekOffset(&pos);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-07-26 07:41:25 -07:00
|
|
|
// PeekOffset fails on last/first lines of the text in certain cases.
|
|
|
|
if (NS_FAILED(rv) && aAmount == eSelectLine) {
|
|
|
|
pos.mAmount = (aDirection == eDirNext) ? eSelectEndLine : eSelectBeginLine;
|
2013-12-06 10:47:00 -08:00
|
|
|
frameAtOffset->PeekOffset(&pos);
|
2013-07-26 07:41:25 -07:00
|
|
|
}
|
2010-06-11 01:23:18 -07:00
|
|
|
if (!pos.mResultContent)
|
|
|
|
return -1;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-02-03 16:56:45 -08:00
|
|
|
// Turn the resulting DOM point into an offset.
|
|
|
|
int32_t hyperTextOffset = DOMPointToOffset(pos.mResultContent,
|
|
|
|
pos.mContentOffset,
|
|
|
|
aDirection == eDirNext);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-02-05 07:21:32 -08: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.
|
|
|
|
if (IsHTMLListItem() && aAmount == eSelectBeginLine && hyperTextOffset == 1)
|
|
|
|
return 0;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return hyperTextOffset;
|
|
|
|
}
|
|
|
|
|
2013-07-16 10:13:34 -07:00
|
|
|
int32_t
|
|
|
|
HyperTextAccessible::FindLineBoundary(int32_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);
|
|
|
|
|
|
|
|
int32_t tmpOffset = FindOffset(aOffset, eDirPrevious, eSelectLine);
|
|
|
|
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).
|
|
|
|
int32_t tmpOffset = FindOffset(aOffset, eDirPrevious, eSelectBeginLine);
|
|
|
|
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).
|
|
|
|
int32_t tmpOffset = FindOffset(aOffset, eDirNext, eSelectLine);
|
|
|
|
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).
|
|
|
|
int32_t tmpOffset = FindOffset(aOffset, eDirNext, eSelectLine);
|
|
|
|
if (tmpOffset != CharacterCount())
|
|
|
|
return FindOffset(tmpOffset, eDirNext, eSelectEndLine);
|
|
|
|
return tmpOffset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-11-18 05:19:33 -08:00
|
|
|
void
|
|
|
|
HyperTextAccessible::TextBeforeOffset(int32_t aOffset,
|
|
|
|
AccessibleTextBoundary aBoundaryType,
|
|
|
|
int32_t* aStartOffset, int32_t* aEndOffset,
|
|
|
|
nsAString& aText)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-11-18 05:19:33 -08:00
|
|
|
*aStartOffset = *aEndOffset = 0;
|
|
|
|
aText.Truncate();
|
|
|
|
|
2013-10-31 20:26:27 -07:00
|
|
|
int32_t convertedOffset = ConvertMagicOffset(aOffset);
|
2013-11-18 05:19:33 -08:00
|
|
|
if (convertedOffset < 0) {
|
|
|
|
NS_ERROR("Wrong given offset!");
|
|
|
|
return;
|
|
|
|
}
|
2013-03-31 06:39:29 -07:00
|
|
|
|
2013-10-31 20:26:27 -07:00
|
|
|
int32_t adjustedOffset = convertedOffset;
|
2013-10-01 11:23:13 -07:00
|
|
|
if (aOffset == nsIAccessibleText::TEXT_OFFSET_CARET)
|
|
|
|
adjustedOffset = AdjustCaretOffset(adjustedOffset);
|
|
|
|
|
2013-03-31 06:39:29 -07:00
|
|
|
switch (aBoundaryType) {
|
|
|
|
case BOUNDARY_CHAR:
|
2013-12-19 11:28:51 -08:00
|
|
|
if (convertedOffset != 0)
|
|
|
|
CharAt(convertedOffset - 1, aText, aStartOffset, aEndOffset);
|
2013-11-18 05:19:33 -08:00
|
|
|
break;
|
2013-03-31 06:39:29 -07:00
|
|
|
|
|
|
|
case BOUNDARY_WORD_START: {
|
2013-05-16 21:06:13 -07: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 11:23:13 -07:00
|
|
|
if (adjustedOffset == CharacterCount()) {
|
|
|
|
*aEndOffset = FindWordBoundary(adjustedOffset, eDirPrevious, eStartWord);
|
2013-05-16 21:06:13 -07:00
|
|
|
*aStartOffset = FindWordBoundary(*aEndOffset, eDirPrevious, eStartWord);
|
|
|
|
} else {
|
2013-10-01 11:23:13 -07:00
|
|
|
*aStartOffset = FindWordBoundary(adjustedOffset, eDirPrevious, eStartWord);
|
2013-05-16 21:06:13 -07:00
|
|
|
*aEndOffset = FindWordBoundary(*aStartOffset, eDirNext, eStartWord);
|
2013-10-01 11:23:13 -07:00
|
|
|
if (*aEndOffset != adjustedOffset) {
|
2013-05-16 21:06:13 -07:00
|
|
|
*aEndOffset = *aStartOffset;
|
|
|
|
*aStartOffset = FindWordBoundary(*aEndOffset, eDirPrevious, eStartWord);
|
|
|
|
}
|
2013-03-31 06:39:29 -07:00
|
|
|
}
|
2013-11-18 05:19:33 -08:00
|
|
|
TextSubstring(*aStartOffset, *aEndOffset, aText);
|
|
|
|
break;
|
2013-03-31 06:39:29 -07:00
|
|
|
}
|
2011-02-03 06:29:12 -08:00
|
|
|
|
2013-03-31 06:39:29 -07:00
|
|
|
case BOUNDARY_WORD_END: {
|
|
|
|
// Move word backward twice to find start and end offsets.
|
2013-10-31 20:26:27 -07:00
|
|
|
*aEndOffset = FindWordBoundary(convertedOffset, eDirPrevious, eEndWord);
|
2013-03-31 06:39:29 -07:00
|
|
|
*aStartOffset = FindWordBoundary(*aEndOffset, eDirPrevious, eEndWord);
|
2013-11-18 05:19:33 -08:00
|
|
|
TextSubstring(*aStartOffset, *aEndOffset, aText);
|
|
|
|
break;
|
2013-03-31 06:39:29 -07:00
|
|
|
}
|
|
|
|
|
2013-07-16 10:13:34 -07:00
|
|
|
case BOUNDARY_LINE_START:
|
2013-10-01 11:23:13 -07:00
|
|
|
*aStartOffset = FindLineBoundary(adjustedOffset, ePrevLineBegin);
|
|
|
|
*aEndOffset = FindLineBoundary(adjustedOffset, eThisLineBegin);
|
2013-11-18 05:19:33 -08:00
|
|
|
TextSubstring(*aStartOffset, *aEndOffset, aText);
|
|
|
|
break;
|
2013-07-11 06:16:18 -07:00
|
|
|
|
2013-07-24 11:11:02 -07:00
|
|
|
case BOUNDARY_LINE_END: {
|
2013-10-01 11:23:13 -07:00
|
|
|
*aEndOffset = FindLineBoundary(adjustedOffset, ePrevLineEnd);
|
2013-07-24 11:11:02 -07:00
|
|
|
int32_t tmpOffset = *aEndOffset;
|
|
|
|
// Adjust offset if line is wrapped.
|
|
|
|
if (*aEndOffset != 0 && !IsLineEndCharAt(*aEndOffset))
|
|
|
|
tmpOffset--;
|
|
|
|
|
|
|
|
*aStartOffset = FindLineBoundary(tmpOffset, ePrevLineEnd);
|
2013-11-18 05:19:33 -08:00
|
|
|
TextSubstring(*aStartOffset, *aEndOffset, aText);
|
|
|
|
break;
|
2013-07-24 11:11:02 -07:00
|
|
|
}
|
2013-03-31 06:39:29 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-11-18 05:19:33 -08:00
|
|
|
void
|
|
|
|
HyperTextAccessible::TextAtOffset(int32_t aOffset,
|
|
|
|
AccessibleTextBoundary aBoundaryType,
|
|
|
|
int32_t* aStartOffset, int32_t* aEndOffset,
|
|
|
|
nsAString& aText)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-11-18 05:19:33 -08:00
|
|
|
*aStartOffset = *aEndOffset = 0;
|
|
|
|
aText.Truncate();
|
2013-03-23 17:57:06 -07:00
|
|
|
|
2013-10-01 11:23:13 -07:00
|
|
|
int32_t adjustedOffset = ConvertMagicOffset(aOffset);
|
2013-11-18 05:19:33 -08:00
|
|
|
if (adjustedOffset < 0) {
|
|
|
|
NS_ERROR("Wrong given offset!");
|
|
|
|
return;
|
|
|
|
}
|
2013-03-31 06:39:29 -07:00
|
|
|
|
2013-03-23 17:57:06 -07:00
|
|
|
switch (aBoundaryType) {
|
|
|
|
case BOUNDARY_CHAR:
|
2013-12-28 11:14:08 -08: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 05:19:33 -08:00
|
|
|
break;
|
2013-03-23 17:57:06 -07:00
|
|
|
|
2013-05-03 07:10:05 -07:00
|
|
|
case BOUNDARY_WORD_START:
|
2013-10-01 11:23:13 -07:00
|
|
|
if (aOffset == nsIAccessibleText::TEXT_OFFSET_CARET)
|
|
|
|
adjustedOffset = AdjustCaretOffset(adjustedOffset);
|
|
|
|
|
|
|
|
*aEndOffset = FindWordBoundary(adjustedOffset, eDirNext, eStartWord);
|
2013-03-31 06:39:29 -07:00
|
|
|
*aStartOffset = FindWordBoundary(*aEndOffset, eDirPrevious, eStartWord);
|
2013-11-18 05:19:33 -08:00
|
|
|
TextSubstring(*aStartOffset, *aEndOffset, aText);
|
|
|
|
break;
|
2013-03-31 06:39:29 -07:00
|
|
|
|
2013-05-03 07:10:05 -07:00
|
|
|
case BOUNDARY_WORD_END:
|
2013-05-07 02:18:37 -07: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 11:23:13 -07:00
|
|
|
*aEndOffset = FindWordBoundary(adjustedOffset, eDirNext, eEndWord);
|
2013-05-07 02:18:37 -07:00
|
|
|
*aStartOffset = FindWordBoundary(*aEndOffset, eDirPrevious, eEndWord);
|
2013-11-18 05:19:33 -08:00
|
|
|
TextSubstring(*aStartOffset, *aEndOffset, aText);
|
|
|
|
break;
|
2013-03-23 17:57:06 -07:00
|
|
|
|
2013-07-16 10:13:34 -07:00
|
|
|
case BOUNDARY_LINE_START:
|
2013-07-09 10:32:07 -07:00
|
|
|
if (aOffset == nsIAccessibleText::TEXT_OFFSET_CARET)
|
2013-10-01 11:23:13 -07:00
|
|
|
adjustedOffset = AdjustCaretOffset(adjustedOffset);
|
2013-07-09 10:32:07 -07:00
|
|
|
|
2013-10-01 11:23:13 -07:00
|
|
|
*aStartOffset = FindLineBoundary(adjustedOffset, eThisLineBegin);
|
|
|
|
*aEndOffset = FindLineBoundary(adjustedOffset, eNextLineBegin);
|
2013-11-18 05:19:33 -08:00
|
|
|
TextSubstring(*aStartOffset, *aEndOffset, aText);
|
|
|
|
break;
|
2013-07-08 08:26:09 -07:00
|
|
|
|
2013-07-16 10:13:34 -07:00
|
|
|
case BOUNDARY_LINE_END:
|
2013-07-09 10:32:07 -07:00
|
|
|
if (aOffset == nsIAccessibleText::TEXT_OFFSET_CARET)
|
2013-10-01 11:23:13 -07:00
|
|
|
adjustedOffset = AdjustCaretOffset(adjustedOffset);
|
2013-07-09 10:32:07 -07:00
|
|
|
|
2013-07-15 06:01:03 -07:00
|
|
|
// In contrast to word end boundary we follow the spec here.
|
2013-10-01 11:23:13 -07:00
|
|
|
*aStartOffset = FindLineBoundary(adjustedOffset, ePrevLineEnd);
|
|
|
|
*aEndOffset = FindLineBoundary(adjustedOffset, eThisLineEnd);
|
2013-11-18 05:19:33 -08:00
|
|
|
TextSubstring(*aStartOffset, *aEndOffset, aText);
|
|
|
|
break;
|
2013-03-23 17:57:06 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-11-18 05:19:33 -08:00
|
|
|
void
|
|
|
|
HyperTextAccessible::TextAfterOffset(int32_t aOffset,
|
|
|
|
AccessibleTextBoundary aBoundaryType,
|
|
|
|
int32_t* aStartOffset, int32_t* aEndOffset,
|
|
|
|
nsAString& aText)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-11-18 05:19:33 -08:00
|
|
|
*aStartOffset = *aEndOffset = 0;
|
|
|
|
aText.Truncate();
|
|
|
|
|
2013-10-31 20:26:27 -07:00
|
|
|
int32_t convertedOffset = ConvertMagicOffset(aOffset);
|
2013-11-18 05:19:33 -08:00
|
|
|
if (convertedOffset < 0) {
|
|
|
|
NS_ERROR("Wrong given offset!");
|
|
|
|
return;
|
|
|
|
}
|
2011-02-03 06:29:12 -08:00
|
|
|
|
2013-10-31 20:26:27 -07:00
|
|
|
int32_t adjustedOffset = convertedOffset;
|
2013-10-01 11:23:13 -07:00
|
|
|
if (aOffset == nsIAccessibleText::TEXT_OFFSET_CARET)
|
|
|
|
adjustedOffset = AdjustCaretOffset(adjustedOffset);
|
|
|
|
|
2013-05-15 01:26:17 -07:00
|
|
|
switch (aBoundaryType) {
|
|
|
|
case BOUNDARY_CHAR:
|
2013-12-28 11:14:08 -08: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 05:19:33 -08:00
|
|
|
break;
|
2013-05-15 01:26:17 -07:00
|
|
|
|
|
|
|
case BOUNDARY_WORD_START:
|
|
|
|
// Move word forward twice to find start and end offsets.
|
2013-10-01 11:23:13 -07:00
|
|
|
*aStartOffset = FindWordBoundary(adjustedOffset, eDirNext, eStartWord);
|
2013-05-15 01:26:17 -07:00
|
|
|
*aEndOffset = FindWordBoundary(*aStartOffset, eDirNext, eStartWord);
|
2013-11-18 05:19:33 -08:00
|
|
|
TextSubstring(*aStartOffset, *aEndOffset, aText);
|
|
|
|
break;
|
2013-05-15 01:26:17 -07:00
|
|
|
|
|
|
|
case BOUNDARY_WORD_END:
|
|
|
|
// 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-10-31 20:26:27 -07:00
|
|
|
if (convertedOffset == 0) {
|
|
|
|
*aStartOffset = FindWordBoundary(convertedOffset, eDirNext, eEndWord);
|
2013-05-15 01:26:17 -07:00
|
|
|
*aEndOffset = FindWordBoundary(*aStartOffset, eDirNext, eEndWord);
|
|
|
|
} else {
|
2013-10-31 20:26:27 -07:00
|
|
|
*aEndOffset = FindWordBoundary(convertedOffset, eDirNext, eEndWord);
|
2013-05-15 01:26:17 -07:00
|
|
|
*aStartOffset = FindWordBoundary(*aEndOffset, eDirPrevious, eEndWord);
|
2013-10-31 20:26:27 -07:00
|
|
|
if (*aStartOffset != convertedOffset) {
|
2013-05-15 01:26:17 -07:00
|
|
|
*aStartOffset = *aEndOffset;
|
|
|
|
*aEndOffset = FindWordBoundary(*aStartOffset, eDirNext, eEndWord);
|
|
|
|
}
|
|
|
|
}
|
2013-11-18 05:19:33 -08:00
|
|
|
TextSubstring(*aStartOffset, *aEndOffset, aText);
|
|
|
|
break;
|
2013-05-15 01:26:17 -07:00
|
|
|
|
|
|
|
case BOUNDARY_LINE_START:
|
2013-10-01 11:23:13 -07:00
|
|
|
*aStartOffset = FindLineBoundary(adjustedOffset, eNextLineBegin);
|
2013-07-16 10:13:34 -07:00
|
|
|
*aEndOffset = FindLineBoundary(*aStartOffset, eNextLineBegin);
|
2013-11-18 05:19:33 -08:00
|
|
|
TextSubstring(*aStartOffset, *aEndOffset, aText);
|
|
|
|
break;
|
2013-07-15 08:56:38 -07:00
|
|
|
|
2013-05-15 01:26:17 -07:00
|
|
|
case BOUNDARY_LINE_END:
|
2013-10-01 11:23:13 -07:00
|
|
|
*aStartOffset = FindLineBoundary(adjustedOffset, eThisLineEnd);
|
|
|
|
*aEndOffset = FindLineBoundary(adjustedOffset, eNextLineEnd);
|
2013-11-18 05:19:33 -08:00
|
|
|
TextSubstring(*aStartOffset, *aEndOffset, aText);
|
|
|
|
break;
|
2013-05-15 01:26:17 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-11-18 05:19:33 -08:00
|
|
|
already_AddRefed<nsIPersistentProperties>
|
|
|
|
HyperTextAccessible::TextAttributes(bool aIncludeDefAttrs, int32_t aOffset,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t* aStartOffset,
|
2013-11-18 05:19:33 -08:00
|
|
|
int32_t* aEndOffset)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-05-25 01:40:26 -07:00
|
|
|
// 1. Get each attribute and its ranges one after another.
|
2008-07-17 05:06:24 -07: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.
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-11-18 05:19:33 -08:00
|
|
|
*aStartOffset = *aEndOffset = 0;
|
|
|
|
nsCOMPtr<nsIPersistentProperties> attributes =
|
|
|
|
do_CreateInstance(NS_PERSISTENTPROPERTIES_CONTRACTID);
|
2010-05-21 04:27:00 -07:00
|
|
|
|
2013-01-12 12:24:13 -08:00
|
|
|
int32_t offset = ConvertMagicOffset(aOffset);
|
|
|
|
Accessible* accAtOffset = GetChildAtOffset(offset);
|
2010-08-15 04:28:49 -07:00
|
|
|
if (!accAtOffset) {
|
2010-05-25 01:40:26 -07:00
|
|
|
// Offset 0 is correct offset when accessible has empty text. Include
|
|
|
|
// default attributes if they were requested, otherwise return empty set.
|
2013-01-12 12:24:13 -08:00
|
|
|
if (offset == 0) {
|
2010-05-21 04:27:00 -07:00
|
|
|
if (aIncludeDefAttrs) {
|
2012-03-09 23:29:51 -08:00
|
|
|
TextAttrsMgr textAttrsMgr(this);
|
2013-11-18 05:19:33 -08:00
|
|
|
textAttrsMgr.GetAttributes(attributes);
|
2010-05-21 04:27:00 -07:00
|
|
|
}
|
2013-11-18 05:19:33 -08:00
|
|
|
return attributes.forget();
|
2010-05-21 04:27:00 -07:00
|
|
|
}
|
2013-11-18 05:19:33 -08:00
|
|
|
return nullptr;
|
2010-05-21 04:27:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t accAtOffsetIdx = accAtOffset->IndexInParent();
|
|
|
|
int32_t startOffset = GetChildOffset(accAtOffsetIdx);
|
|
|
|
int32_t endOffset = GetChildOffset(accAtOffsetIdx + 1);
|
2013-01-12 12:24:13 -08:00
|
|
|
int32_t offsetInAcc = offset - startOffset;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-09 23:29:51 -08:00
|
|
|
TextAttrsMgr textAttrsMgr(this, aIncludeDefAttrs, accAtOffset,
|
|
|
|
accAtOffsetIdx);
|
2013-11-18 05:19:33 -08:00
|
|
|
textAttrsMgr.GetAttributes(attributes, &startOffset, &endOffset);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-05-25 01:40:26 -07:00
|
|
|
// Compute spelling attributes on text accessible only.
|
2010-08-15 04:28:49 -07:00
|
|
|
nsIFrame *offsetFrame = accAtOffset->GetFrame();
|
2011-06-03 14:35:17 -07:00
|
|
|
if (offsetFrame && offsetFrame->GetType() == nsGkAtoms::textFrame) {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t nodeOffset = 0;
|
2013-11-18 05:19:33 -08:00
|
|
|
RenderedToContentOffset(offsetFrame, offsetInAcc, &nodeOffset);
|
2008-07-17 05:06:24 -07:00
|
|
|
|
2010-05-25 01:40:26 -07:00
|
|
|
// Set 'misspelled' text attribute.
|
2013-11-18 05:19:33 -08:00
|
|
|
GetSpellTextAttribute(accAtOffset->GetNode(), nodeOffset,
|
|
|
|
&startOffset, &endOffset, attributes);
|
2010-05-25 01:40:26 -07:00
|
|
|
}
|
2008-07-17 05:06:24 -07:00
|
|
|
|
2010-05-25 01:40:26 -07:00
|
|
|
*aStartOffset = startOffset;
|
|
|
|
*aEndOffset = endOffset;
|
2013-11-18 05:19:33 -08:00
|
|
|
return attributes.forget();
|
2008-07-17 05:06:24 -07:00
|
|
|
}
|
|
|
|
|
2013-11-18 05:19:33 -08:00
|
|
|
already_AddRefed<nsIPersistentProperties>
|
|
|
|
HyperTextAccessible::DefaultTextAttributes()
|
2008-07-17 05:06:24 -07:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIPersistentProperties> attributes =
|
|
|
|
do_CreateInstance(NS_PERSISTENTPROPERTIES_CONTRACTID);
|
|
|
|
|
2012-03-09 23:29:51 -08:00
|
|
|
TextAttrsMgr textAttrsMgr(this);
|
2013-11-18 05:19:33 -08:00
|
|
|
textAttrsMgr.GetAttributes(attributes);
|
|
|
|
return attributes.forget();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t
|
2012-05-31 01:04:41 -07:00
|
|
|
HyperTextAccessible::GetLevelInternal()
|
2010-01-06 02:36:50 -08:00
|
|
|
{
|
2010-06-11 01:23:18 -07:00
|
|
|
nsIAtom *tag = mContent->Tag();
|
2011-06-03 14:35:17 -07:00
|
|
|
if (tag == nsGkAtoms::h1)
|
2010-01-06 02:36:50 -08:00
|
|
|
return 1;
|
2011-06-03 14:35:17 -07:00
|
|
|
if (tag == nsGkAtoms::h2)
|
2010-01-06 02:36:50 -08:00
|
|
|
return 2;
|
2011-06-03 14:35:17 -07:00
|
|
|
if (tag == nsGkAtoms::h3)
|
2010-01-06 02:36:50 -08:00
|
|
|
return 3;
|
2011-06-03 14:35:17 -07:00
|
|
|
if (tag == nsGkAtoms::h4)
|
2010-01-06 02:36:50 -08:00
|
|
|
return 4;
|
2011-06-03 14:35:17 -07:00
|
|
|
if (tag == nsGkAtoms::h5)
|
2010-01-06 02:36:50 -08:00
|
|
|
return 5;
|
2011-06-03 14:35:17 -07:00
|
|
|
if (tag == nsGkAtoms::h6)
|
2010-01-06 02:36:50 -08:00
|
|
|
return 6;
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
return AccessibleWrap::GetLevelInternal();
|
2010-01-06 02:36:50 -08:00
|
|
|
}
|
|
|
|
|
2012-10-19 00:15:23 -07:00
|
|
|
already_AddRefed<nsIPersistentProperties>
|
|
|
|
HyperTextAccessible::NativeAttributes()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-10-19 00:15:23 -07:00
|
|
|
nsCOMPtr<nsIPersistentProperties> attributes =
|
|
|
|
AccessibleWrap::NativeAttributes();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-10-19 00:15:23 -07:00
|
|
|
// 'formatting' attribute is deprecated, 'display' attribute should be
|
|
|
|
// instead.
|
2007-10-10 08:31:52 -07:00
|
|
|
nsIFrame *frame = GetFrame();
|
2011-06-03 14:35:17 -07:00
|
|
|
if (frame && frame->GetType() == nsGkAtoms::blockFrame) {
|
2012-10-19 00:15:23 -07:00
|
|
|
nsAutoString unused;
|
|
|
|
attributes->SetStringProperty(NS_LITERAL_CSTRING("formatting"),
|
|
|
|
NS_LITERAL_STRING("block"), unused);
|
2007-10-10 08:31:52 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-27 18:46:11 -07:00
|
|
|
if (FocusMgr()->IsFocused(this)) {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t lineNumber = CaretLineNumber();
|
2007-12-11 06:15:21 -08:00
|
|
|
if (lineNumber >= 1) {
|
|
|
|
nsAutoString strLineNumber;
|
|
|
|
strLineNumber.AppendInt(lineNumber);
|
2012-10-19 00:15:23 -07:00
|
|
|
nsAccUtils::SetAccAttr(attributes, nsGkAtoms::lineNumber, strLineNumber);
|
2007-12-11 06:15:21 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-30 19:25:17 -07:00
|
|
|
if (!HasOwnContent())
|
|
|
|
return attributes.forget();
|
|
|
|
|
2010-11-08 05:33:34 -08:00
|
|
|
// For the html landmark elements we expose them like we do aria landmarks to
|
2013-03-29 04:05:39 -07:00
|
|
|
// make AT navigation schemes "just work".
|
|
|
|
nsIAtom* tag = mContent->Tag();
|
|
|
|
if (tag == nsGkAtoms::nav) {
|
2012-10-19 00:15:23 -07:00
|
|
|
nsAccUtils::SetAccAttr(attributes, nsGkAtoms::xmlroles,
|
2010-11-08 05:33:34 -08:00
|
|
|
NS_LITERAL_STRING("navigation"));
|
2013-03-29 04:05:39 -07:00
|
|
|
} else if (tag == nsGkAtoms::section) {
|
2012-10-19 00:15:23 -07:00
|
|
|
nsAccUtils::SetAccAttr(attributes, nsGkAtoms::xmlroles,
|
2012-03-28 01:20:50 -07:00
|
|
|
NS_LITERAL_STRING("region"));
|
2013-03-29 04:05:39 -07:00
|
|
|
} else if (tag == nsGkAtoms::header || tag == nsGkAtoms::footer) {
|
|
|
|
// Only map header and footer if they are not descendants
|
|
|
|
// of an article or section tag.
|
|
|
|
nsIContent* parent = mContent->GetParent();
|
|
|
|
while (parent) {
|
|
|
|
if (parent->Tag() == nsGkAtoms::article ||
|
|
|
|
parent->Tag() == nsGkAtoms::section)
|
|
|
|
break;
|
|
|
|
parent = parent->GetParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
// No article or section elements found.
|
|
|
|
if (!parent) {
|
|
|
|
if (tag == nsGkAtoms::header) {
|
|
|
|
nsAccUtils::SetAccAttr(attributes, nsGkAtoms::xmlroles,
|
|
|
|
NS_LITERAL_STRING("banner"));
|
|
|
|
} else if (tag == nsGkAtoms::footer) {
|
|
|
|
nsAccUtils::SetAccAttr(attributes, nsGkAtoms::xmlroles,
|
|
|
|
NS_LITERAL_STRING("contentinfo"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (tag == nsGkAtoms::aside) {
|
2012-10-19 00:15:23 -07:00
|
|
|
nsAccUtils::SetAccAttr(attributes, nsGkAtoms::xmlroles,
|
2011-07-05 07:28:53 -07:00
|
|
|
NS_LITERAL_STRING("complementary"));
|
2013-03-29 04:05:39 -07:00
|
|
|
} else if (tag == nsGkAtoms::article) {
|
2012-10-19 00:15:23 -07:00
|
|
|
nsAccUtils::SetAccAttr(attributes, nsGkAtoms::xmlroles,
|
2012-06-11 08:16:48 -07:00
|
|
|
NS_LITERAL_STRING("article"));
|
2013-03-29 04:05:39 -07:00
|
|
|
} else if (tag == nsGkAtoms::main) {
|
2013-01-29 04:31:45 -08:00
|
|
|
nsAccUtils::SetAccAttr(attributes, nsGkAtoms::xmlroles,
|
|
|
|
NS_LITERAL_STRING("main"));
|
2013-03-29 04:05:39 -07:00
|
|
|
}
|
2010-11-08 05:33:34 -08:00
|
|
|
|
2012-10-19 00:15:23 -07:00
|
|
|
return attributes.forget();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-11-18 05:19:33 -08:00
|
|
|
int32_t
|
|
|
|
HyperTextAccessible::OffsetAtPoint(int32_t aX, int32_t aY, uint32_t aCoordType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-11-18 05:19:33 -08:00
|
|
|
nsIFrame* hyperFrame = GetFrame();
|
|
|
|
if (!hyperFrame)
|
|
|
|
return -1;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-12-17 12:11:02 -08:00
|
|
|
nsIntPoint coords = nsAccUtils::ConvertToScreenCoords(aX, aY, aCoordType,
|
|
|
|
this);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-10-20 02:03:48 -07:00
|
|
|
nsPresContext* presContext = mDoc->PresContext();
|
|
|
|
nsPoint coordsInAppUnits =
|
|
|
|
coords.ToAppUnits(presContext->AppUnitsPerDevPixel());
|
|
|
|
|
|
|
|
nsRect frameScreenRect = hyperFrame->GetScreenRectInAppUnits();
|
|
|
|
if (!frameScreenRect.Contains(coordsInAppUnits.x, coordsInAppUnits.y))
|
2013-11-18 05:19:33 -08:00
|
|
|
return -1; // Not found
|
2012-10-20 02:03:48 -07:00
|
|
|
|
|
|
|
nsPoint pointInHyperText(coordsInAppUnits.x - frameScreenRect.x,
|
|
|
|
coordsInAppUnits.y - frameScreenRect.y);
|
2007-03-22 10:30:00 -07: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 08:56:38 -07:00
|
|
|
int32_t offset = 0;
|
|
|
|
uint32_t childCount = ChildCount();
|
|
|
|
for (uint32_t childIdx = 0; childIdx < childCount; childIdx++) {
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* childAcc = mChildren[childIdx];
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-04-19 06:39:57 -07:00
|
|
|
nsIFrame *primaryFrame = childAcc->GetFrame();
|
2013-11-18 05:19:33 -08:00
|
|
|
NS_ENSURE_TRUE(primaryFrame, -1);
|
2007-08-20 21:24:21 -07:00
|
|
|
|
|
|
|
nsIFrame *frame = primaryFrame;
|
2007-03-22 10:30:00 -07:00
|
|
|
while (frame) {
|
|
|
|
nsIContent *content = frame->GetContent();
|
2013-11-18 05:19:33 -08:00
|
|
|
NS_ENSURE_TRUE(content, -1);
|
2012-10-20 02:03:48 -07:00
|
|
|
nsPoint pointInFrame = pointInHyperText - frame->GetOffsetTo(hyperFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsSize frameSize = frame->GetSize();
|
|
|
|
if (pointInFrame.x < frameSize.width && pointInFrame.y < frameSize.height) {
|
|
|
|
// Finished
|
2011-06-03 14:35:17 -07:00
|
|
|
if (frame->GetType() == nsGkAtoms::textFrame) {
|
2012-05-29 06:13:36 -07:00
|
|
|
nsIFrame::ContentOffsets contentOffsets =
|
|
|
|
frame->GetContentOffsetsFromPointExternal(pointInFrame, nsIFrame::IGNORE_SELECTION_STYLE);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (contentOffsets.IsNull() || contentOffsets.content != content) {
|
2013-11-18 05:19:33 -08:00
|
|
|
return -1; // Not found
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t addToOffset;
|
2007-08-20 21:24:21 -07:00
|
|
|
nsresult rv = ContentToRenderedOffset(primaryFrame,
|
|
|
|
contentOffsets.offset,
|
|
|
|
&addToOffset);
|
2013-11-18 05:19:33 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, -1);
|
2007-08-03 18:12:24 -07:00
|
|
|
offset += addToOffset;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2013-11-18 05:19:33 -08:00
|
|
|
return offset;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
frame = frame->GetNextContinuation();
|
|
|
|
}
|
2010-05-25 01:40:54 -07:00
|
|
|
|
|
|
|
offset += nsAccUtils::TextLength(childAcc);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-11-18 05:19:33 -08:00
|
|
|
return -1; // Not found
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-11-25 10:28:27 -08:00
|
|
|
nsIntRect
|
|
|
|
HyperTextAccessible::TextBounds(int32_t aStartOffset, int32_t aEndOffset,
|
|
|
|
uint32_t aCoordType)
|
|
|
|
{
|
|
|
|
int32_t startOffset = ConvertMagicOffset(aStartOffset);
|
|
|
|
int32_t endOffset = ConvertMagicOffset(aEndOffset);
|
|
|
|
NS_ASSERTION(startOffset < endOffset, "Wrong bad in!");
|
|
|
|
|
|
|
|
int32_t childIdx = GetChildIndexAtOffset(startOffset);
|
|
|
|
if (childIdx == -1)
|
|
|
|
return nsIntRect();
|
|
|
|
|
|
|
|
nsIntRect bounds;
|
|
|
|
int32_t prevOffset = GetChildOffset(childIdx);
|
|
|
|
int32_t offset1 = startOffset - prevOffset;
|
|
|
|
|
|
|
|
while (childIdx < ChildCount()) {
|
2014-04-09 11:23:04 -07:00
|
|
|
nsIFrame* frame = GetChildAt(childIdx++)->GetFrame();
|
2013-12-04 13:15:22 -08:00
|
|
|
if (!frame) {
|
|
|
|
NS_NOTREACHED("No frame for a child!");
|
|
|
|
continue;
|
|
|
|
}
|
2013-11-25 10:28:27 -08:00
|
|
|
|
|
|
|
int32_t nextOffset = GetChildOffset(childIdx);
|
|
|
|
if (nextOffset >= endOffset) {
|
|
|
|
bounds.UnionRect(bounds, GetBoundsInFrame(frame, offset1,
|
|
|
|
endOffset - prevOffset));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
bounds.UnionRect(bounds, GetBoundsInFrame(frame, offset1,
|
|
|
|
nextOffset - prevOffset));
|
|
|
|
|
|
|
|
prevOffset = nextOffset;
|
|
|
|
offset1 = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAccUtils::ConvertScreenCoordsTo(&bounds.x, &bounds.y, aCoordType, this);
|
|
|
|
return bounds;
|
|
|
|
}
|
|
|
|
|
2012-03-07 19:28:38 -08:00
|
|
|
already_AddRefed<nsIEditor>
|
2012-05-31 01:04:41 -07:00
|
|
|
HyperTextAccessible::GetEditor() const
|
2007-07-05 10:12:28 -07:00
|
|
|
{
|
2010-06-11 01:23:18 -07:00
|
|
|
if (!mContent->HasFlag(NODE_IS_EDITABLE)) {
|
2007-09-05 21:18:22 -07:00
|
|
|
// If we're inside an editable container, then return that container's editor
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* ancestor = Parent();
|
2012-03-07 19:28:38 -08:00
|
|
|
while (ancestor) {
|
2012-05-31 01:04:41 -07:00
|
|
|
HyperTextAccessible* hyperText = ancestor->AsHyperText();
|
2012-03-07 19:28:38 -08:00
|
|
|
if (hyperText) {
|
2007-09-05 21:18:22 -07:00
|
|
|
// Recursion will stop at container doc because it has its own impl
|
2012-03-07 19:28:38 -08:00
|
|
|
// of GetEditor()
|
|
|
|
return hyperText->GetEditor();
|
2007-09-05 21:18:22 -07:00
|
|
|
}
|
2012-03-07 19:28:38 -08:00
|
|
|
|
|
|
|
ancestor = ancestor->Parent();
|
2007-09-05 21:18:22 -07:00
|
|
|
}
|
2012-03-07 19:28:38 -08:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-08-14 09:25:24 -07:00
|
|
|
}
|
|
|
|
|
2013-02-12 14:02:51 -08:00
|
|
|
nsCOMPtr<nsIDocShell> docShell = nsCoreUtils::GetDocShellFor(mContent);
|
|
|
|
nsCOMPtr<nsIEditingSession> editingSession(do_GetInterface(docShell));
|
2007-08-14 09:25:24 -07:00
|
|
|
if (!editingSession)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr; // No editing session interface
|
2007-08-14 09:25:24 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIEditor> editor;
|
2012-10-11 19:25:34 -07:00
|
|
|
nsIDocument* docNode = mDoc->DocumentNode();
|
2012-03-07 19:28:38 -08:00
|
|
|
editingSession->GetEditorForWindow(docNode->GetWindow(),
|
|
|
|
getter_AddRefs(editor));
|
|
|
|
return editor.forget();
|
2007-07-05 10:12:28 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* =================== Caret & Selection ======================
|
|
|
|
*/
|
|
|
|
|
2010-02-20 16:50:50 -08:00
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
HyperTextAccessible::SetSelectionRange(int32_t aStartPos, int32_t aEndPos)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-11-03 05:08:09 -07: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.
|
|
|
|
nsCOMPtr<nsIEditor> editor = GetEditor();
|
|
|
|
|
2012-06-03 22:41:06 -07:00
|
|
|
bool isFocusable = InteractiveState() & states::FOCUSABLE;
|
2012-02-07 20:31:18 -08: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-20 16:50:50 -08:00
|
|
|
|
2014-04-10 09:09:40 -07:00
|
|
|
dom::Selection* domSel = DOMSelection();
|
2011-10-12 00:39:58 -07:00
|
|
|
NS_ENSURE_STATE(domSel);
|
|
|
|
|
2014-02-08 05:25:11 -08:00
|
|
|
// Set up the selection.
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t idx = domSel->GetRangeCount() - 1; idx > 0; idx--)
|
2012-04-06 17:09:31 -07:00
|
|
|
domSel->RemoveRange(domSel->GetRangeAt(idx));
|
2014-02-08 05:25:11 -08:00
|
|
|
SetSelectionBoundsAt(0, aStartPos, aEndPos);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-02-07 20:31:18 -08: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-15 20:38:19 -07:00
|
|
|
nsFocusManager* DOMFocusManager = nsFocusManager::GetFocusManager();
|
|
|
|
if (DOMFocusManager) {
|
2012-02-07 14:38:54 -08:00
|
|
|
NS_ENSURE_TRUE(mDoc, NS_ERROR_FAILURE);
|
2012-10-11 19:25:34 -07:00
|
|
|
nsIDocument* docNode = mDoc->DocumentNode();
|
2012-02-07 14:38:54 -08:00
|
|
|
NS_ENSURE_TRUE(docNode, NS_ERROR_FAILURE);
|
|
|
|
nsCOMPtr<nsPIDOMWindow> window = docNode->GetWindow();
|
2011-10-15 20:38:19 -07:00
|
|
|
nsCOMPtr<nsIDOMElement> result;
|
2012-07-30 07:20:58 -07:00
|
|
|
DOMFocusManager->MoveFocus(window, nullptr, nsIFocusManager::MOVEFOCUS_CARET,
|
2011-10-15 20:38:19 -07:00
|
|
|
nsIFocusManager::FLAG_BYMOVEFOCUS, getter_AddRefs(result));
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-11-18 05:19:33 -08:00
|
|
|
int32_t
|
|
|
|
HyperTextAccessible::CaretOffset() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-02-12 19:37:52 -08:00
|
|
|
// Not focused focusable accessible except document accessible doesn't have
|
|
|
|
// a caret.
|
|
|
|
if (!IsDoc() && !FocusMgr()->IsFocused(this) &&
|
2012-06-03 22:41:06 -07:00
|
|
|
(InteractiveState() & states::FOCUSABLE)) {
|
2013-11-18 05:19:33 -08:00
|
|
|
return -1;
|
2012-02-12 19:37:52 -08:00
|
|
|
}
|
|
|
|
|
2008-12-16 02:14:20 -08: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-27 18:46:11 -07:00
|
|
|
FocusManager::FocusDisposition focusDisp =
|
|
|
|
FocusMgr()->IsInOrContainsFocus(this);
|
|
|
|
if (focusDisp == FocusManager::eNone)
|
2013-11-18 05:19:33 -08:00
|
|
|
return -1;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-12-16 02:14:20 -08:00
|
|
|
// Turn the focus node and offset of the selection into caret hypretext
|
|
|
|
// offset.
|
2014-04-10 09:09:40 -07:00
|
|
|
dom::Selection* domSel = DOMSelection();
|
2013-11-18 05:19:33 -08:00
|
|
|
NS_ENSURE_TRUE(domSel, -1);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-04-06 17:09:31 -07:00
|
|
|
nsINode* focusNode = domSel->GetFocusNode();
|
2013-12-17 06:12:33 -08:00
|
|
|
uint32_t focusOffset = domSel->FocusOffset();
|
2008-12-16 02:14:20 -08: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-27 18:46:11 -07:00
|
|
|
if (focusDisp == FocusManager::eContainedByFocus) {
|
2013-11-18 05:19:33 -08:00
|
|
|
nsINode* resultNode =
|
2008-12-16 02:14:20 -08:00
|
|
|
nsCoreUtils::GetDOMNodeFromDOMPoint(focusNode, focusOffset);
|
2010-01-27 03:43:25 -08:00
|
|
|
|
2011-09-27 18:46:11 -07:00
|
|
|
nsINode* thisNode = GetNode();
|
2010-01-27 03:43:25 -08:00
|
|
|
if (resultNode != thisNode &&
|
|
|
|
!nsCoreUtils::IsAncestorOf(thisNode, resultNode))
|
2013-11-18 05:19:33 -08:00
|
|
|
return -1;
|
2008-12-16 02:14:20 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-02-03 16:56:45 -08:00
|
|
|
return DOMPointToOffset(focusNode, focusOffset);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t
|
2012-05-31 01:04:41 -07:00
|
|
|
HyperTextAccessible::CaretLineNumber()
|
2007-12-11 06:15:21 -08:00
|
|
|
{
|
|
|
|
// Provide the line number for the caret, relative to the
|
|
|
|
// currently focused node. Use a 1-based index
|
2011-10-12 00:39:58 -07:00
|
|
|
nsRefPtr<nsFrameSelection> frameSelection = FrameSelection();
|
|
|
|
if (!frameSelection)
|
|
|
|
return -1;
|
|
|
|
|
2014-04-10 09:09:40 -07:00
|
|
|
dom::Selection* domSel =
|
2011-10-12 00:39:58 -07:00
|
|
|
frameSelection->GetSelection(nsISelectionController::SELECTION_NORMAL);
|
|
|
|
if (!domSel)
|
|
|
|
return - 1;
|
2007-12-11 06:15:21 -08:00
|
|
|
|
2012-04-06 17:09:31 -07:00
|
|
|
nsINode* caretNode = domSel->GetFocusNode();
|
|
|
|
if (!caretNode || !caretNode->IsContent())
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
nsIContent* caretContent = caretNode->AsContent();
|
|
|
|
if (!nsCoreUtils::IsAncestorOf(GetNode(), caretContent))
|
2007-12-11 06:15:21 -08:00
|
|
|
return -1;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t returnOffsetUnused;
|
2013-12-17 06:12:33 -08:00
|
|
|
uint32_t caretOffset = domSel->FocusOffset();
|
2007-12-11 06:15:21 -08:00
|
|
|
nsFrameSelection::HINT hint = frameSelection->GetHint();
|
|
|
|
nsIFrame *caretFrame = frameSelection->GetFrameForNodeOffset(caretContent, caretOffset,
|
|
|
|
hint, &returnOffsetUnused);
|
|
|
|
NS_ENSURE_TRUE(caretFrame, -1);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t lineNumber = 1;
|
2008-10-30 12:17:59 -07:00
|
|
|
nsAutoLineIterator lineIterForCaret;
|
2012-07-30 07:20:58 -07:00
|
|
|
nsIContent *hyperTextContent = IsContent() ? mContent.get() : nullptr;
|
2007-12-11 06:15:21 -08:00
|
|
|
while (caretFrame) {
|
|
|
|
if (hyperTextContent == caretFrame->GetContent()) {
|
|
|
|
return lineNumber; // Must be in a single line hyper text, there is no line iterator
|
|
|
|
}
|
|
|
|
nsIFrame *parentFrame = caretFrame->GetParent();
|
|
|
|
if (!parentFrame)
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Add lines for the sibling frames before the caret
|
2011-08-24 13:54:30 -07:00
|
|
|
nsIFrame *sibling = parentFrame->GetFirstPrincipalChild();
|
2007-12-11 06:15:21 -08:00
|
|
|
while (sibling && sibling != caretFrame) {
|
2008-10-30 12:17:59 -07:00
|
|
|
nsAutoLineIterator lineIterForSibling = sibling->GetLineIterator();
|
2007-12-11 06:15:21 -08:00
|
|
|
if (lineIterForSibling) {
|
|
|
|
// For the frames before that grab all the lines
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t addLines = lineIterForSibling->GetNumLines();
|
2007-12-11 06:15:21 -08: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 12:17:59 -07:00
|
|
|
lineIterForCaret = parentFrame->GetLineIterator();
|
2007-12-11 06:15:21 -08:00
|
|
|
if (lineIterForCaret) {
|
|
|
|
// Ancestor of caret
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t addLines = lineIterForCaret->FindLineContaining(caretFrame);
|
2007-12-11 06:15:21 -08:00
|
|
|
lineNumber += addLines;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
caretFrame = parentFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_NOTREACHED("DOM ancestry had this hypertext but frame ancestry didn't");
|
|
|
|
return lineNumber;
|
|
|
|
}
|
|
|
|
|
2013-10-26 07:58:53 -07:00
|
|
|
nsIntRect
|
|
|
|
HyperTextAccessible::GetCaretRect(nsIWidget** aWidget)
|
|
|
|
{
|
|
|
|
*aWidget = nullptr;
|
|
|
|
|
|
|
|
nsRefPtr<nsCaret> caret = mDoc->PresShell()->GetCaret();
|
|
|
|
NS_ENSURE_TRUE(caret, nsIntRect());
|
|
|
|
|
|
|
|
nsISelection* caretSelection = caret->GetCaretDOMSelection();
|
|
|
|
NS_ENSURE_TRUE(caretSelection, nsIntRect());
|
|
|
|
|
|
|
|
bool isVisible = false;
|
|
|
|
caret->GetCaretVisible(&isVisible);
|
|
|
|
if (!isVisible)
|
|
|
|
return nsIntRect();
|
|
|
|
|
|
|
|
nsRect rect;
|
|
|
|
nsIFrame* frame = caret->GetGeometry(caretSelection, &rect);
|
|
|
|
if (!frame || rect.IsEmpty())
|
|
|
|
return nsIntRect();
|
|
|
|
|
|
|
|
nsPoint offset;
|
|
|
|
// Offset from widget origin to the frame origin, which includes chrome
|
|
|
|
// on the widget.
|
|
|
|
*aWidget = frame->GetNearestWidget(offset);
|
|
|
|
NS_ENSURE_TRUE(*aWidget, nsIntRect());
|
|
|
|
rect.MoveBy(offset);
|
|
|
|
|
|
|
|
nsIntRect caretRect;
|
|
|
|
caretRect = rect.ToOutsidePixels(frame->PresContext()->AppUnitsPerDevPixel());
|
|
|
|
// ((content screen origin) - (content offset in the widget)) = widget origin on the screen
|
|
|
|
caretRect.MoveBy((*aWidget)->WidgetToScreenOffset() - (*aWidget)->GetClientOffset());
|
|
|
|
|
|
|
|
// 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 05:19:33 -08:00
|
|
|
nsIntRect charRect = CharBounds(CaretOffset(),
|
|
|
|
nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE);
|
|
|
|
if (!charRect.IsEmpty()) {
|
|
|
|
caretRect.height -= charRect.y - caretRect.y;
|
|
|
|
caretRect.y = charRect.y;
|
2013-10-26 07:58:53 -07:00
|
|
|
}
|
|
|
|
return caretRect;
|
|
|
|
}
|
|
|
|
|
2011-10-12 00:39:58 -07:00
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
HyperTextAccessible::GetSelectionDOMRanges(int16_t aType,
|
2012-05-31 01:04:41 -07:00
|
|
|
nsTArray<nsRange*>* aRanges)
|
2011-10-12 00:39:58 -07:00
|
|
|
{
|
2013-04-22 01:10:09 -07:00
|
|
|
// Ignore selection if it is not visible.
|
2011-10-12 00:39:58 -07:00
|
|
|
nsRefPtr<nsFrameSelection> frameSelection = FrameSelection();
|
2013-04-22 01:10:09 -07:00
|
|
|
if (!frameSelection ||
|
|
|
|
frameSelection->GetDisplaySelection() <= nsISelectionController::SELECTION_HIDDEN)
|
2011-10-12 00:39:58 -07:00
|
|
|
return;
|
2008-07-17 05:06:24 -07:00
|
|
|
|
2014-04-10 09:09:40 -07:00
|
|
|
dom::Selection* domSel = frameSelection->GetSelection(aType);
|
2011-10-12 00:39:58 -07:00
|
|
|
if (!domSel)
|
|
|
|
return;
|
2007-09-18 15:28:26 -07:00
|
|
|
|
2011-10-12 00:39:58 -07:00
|
|
|
nsCOMPtr<nsINode> startNode = GetNode();
|
2008-07-17 05:06:24 -07:00
|
|
|
|
2012-03-07 19:28:38 -08:00
|
|
|
nsCOMPtr<nsIEditor> editor = GetEditor();
|
2011-10-12 00:39:58 -07:00
|
|
|
if (editor) {
|
|
|
|
nsCOMPtr<nsIDOMElement> editorRoot;
|
|
|
|
editor->GetRootElement(getter_AddRefs(editorRoot));
|
|
|
|
startNode = do_QueryInterface(editorRoot);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!startNode)
|
|
|
|
return;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t childCount = startNode->GetChildCount();
|
2012-04-06 17:09:31 -07:00
|
|
|
nsresult rv = domSel->
|
2012-01-10 06:19:54 -08:00
|
|
|
GetRangesForIntervalArray(startNode, 0, startNode, childCount, true, aRanges);
|
2012-09-14 03:00:31 -07:00
|
|
|
NS_ENSURE_SUCCESS_VOID(rv);
|
2011-10-12 00:39:58 -07:00
|
|
|
|
|
|
|
// Remove collapsed ranges
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t numRanges = aRanges->Length();
|
|
|
|
for (uint32_t idx = 0; idx < numRanges; idx ++) {
|
2012-03-06 09:08:02 -08:00
|
|
|
if ((*aRanges)[idx]->Collapsed()) {
|
|
|
|
aRanges->RemoveElementAt(idx);
|
2011-10-12 00:39:58 -07:00
|
|
|
--numRanges;
|
2012-03-06 09:08:02 -08:00
|
|
|
--idx;
|
2007-09-18 15:28:26 -07:00
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-11-18 05:19:33 -08:00
|
|
|
int32_t
|
|
|
|
HyperTextAccessible::SelectionCount()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-01-10 06:19:54 -08:00
|
|
|
nsTArray<nsRange*> ranges;
|
2011-10-12 00:39:58 -07:00
|
|
|
GetSelectionDOMRanges(nsISelectionController::SELECTION_NORMAL, &ranges);
|
2013-11-18 05:19:33 -08:00
|
|
|
return ranges.Length();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-11-18 05:19:33 -08:00
|
|
|
bool
|
|
|
|
HyperTextAccessible::SelectionBoundsAt(int32_t aSelectionNum,
|
|
|
|
int32_t* aStartOffset,
|
|
|
|
int32_t* aEndOffset)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
*aStartOffset = *aEndOffset = 0;
|
|
|
|
|
2012-01-10 06:19:54 -08:00
|
|
|
nsTArray<nsRange*> ranges;
|
2011-10-12 00:39:58 -07:00
|
|
|
GetSelectionDOMRanges(nsISelectionController::SELECTION_NORMAL, &ranges);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t rangeCount = ranges.Length();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aSelectionNum < 0 || aSelectionNum >= rangeCount)
|
2013-11-18 05:19:33 -08:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-01-10 06:19:54 -08:00
|
|
|
nsRange* range = ranges[aSelectionNum];
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-06 09:08:02 -08:00
|
|
|
// Get start and end points.
|
|
|
|
nsINode* startNode = range->GetStartParent();
|
|
|
|
nsINode* endNode = range->GetEndParent();
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t startOffset = range->StartOffset(), endOffset = range->EndOffset();
|
2012-03-06 09:08:02 -08:00
|
|
|
|
|
|
|
// Make sure start is before end, by swapping DOM points. This occurs when
|
|
|
|
// the user selects backwards in the text.
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t rangeCompare = nsContentUtils::ComparePoints(endNode, endOffset,
|
2012-03-06 09:08:02 -08:00
|
|
|
startNode, startOffset);
|
|
|
|
if (rangeCompare < 0) {
|
|
|
|
nsINode* tempNode = startNode;
|
|
|
|
startNode = endNode;
|
|
|
|
endNode = tempNode;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t tempOffset = startOffset;
|
2007-09-18 15:28:26 -07:00
|
|
|
startOffset = endOffset;
|
|
|
|
endOffset = tempOffset;
|
|
|
|
}
|
|
|
|
|
2014-02-03 16:56:45 -08:00
|
|
|
*aStartOffset = DOMPointToOffset(startNode, startOffset);
|
|
|
|
*aEndOffset = DOMPointToOffset(endNode, endOffset, true);
|
2013-11-18 05:19:33 -08:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-11-18 05:19:33 -08:00
|
|
|
bool
|
|
|
|
HyperTextAccessible::SetSelectionBoundsAt(int32_t aSelectionNum,
|
|
|
|
int32_t aStartOffset,
|
|
|
|
int32_t aEndOffset)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-01-12 12:24:13 -08:00
|
|
|
int32_t startOffset = ConvertMagicOffset(aStartOffset);
|
|
|
|
int32_t endOffset = ConvertMagicOffset(aEndOffset);
|
|
|
|
|
2014-04-10 09:09:40 -07:00
|
|
|
dom::Selection* domSel = DOMSelection();
|
2013-11-18 05:19:33 -08:00
|
|
|
if (!domSel)
|
|
|
|
return false;
|
2012-04-06 17:09:31 -07:00
|
|
|
|
|
|
|
nsRefPtr<nsRange> range;
|
2013-11-18 05:19:33 -08:00
|
|
|
uint32_t rangeCount = domSel->GetRangeCount();
|
2012-04-06 17:09:31 -07:00
|
|
|
if (aSelectionNum == rangeCount)
|
2013-02-07 04:09:41 -08:00
|
|
|
range = new nsRange(mContent);
|
2012-04-06 17:09:31 -07:00
|
|
|
else
|
|
|
|
range = domSel->GetRangeAt(aSelectionNum);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-11-18 05:19:33 -08:00
|
|
|
if (!range)
|
|
|
|
return false;
|
|
|
|
|
2013-12-13 08:26:35 -08:00
|
|
|
if (!OffsetsToDOMRange(startOffset, endOffset, range))
|
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-12 00:39:58 -07:00
|
|
|
// If new range was created then add it, otherwise notify selection listeners
|
|
|
|
// that existing selection range was changed.
|
|
|
|
if (aSelectionNum == rangeCount)
|
2013-11-18 05:19:33 -08:00
|
|
|
return NS_SUCCEEDED(domSel->AddRange(range));
|
2011-10-12 00:39:58 -07:00
|
|
|
|
|
|
|
domSel->RemoveRange(range);
|
2013-11-18 05:19:33 -08:00
|
|
|
return NS_SUCCEEDED(domSel->AddRange(range));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-11-18 05:19:33 -08:00
|
|
|
bool
|
|
|
|
HyperTextAccessible::RemoveFromSelection(int32_t aSelectionNum)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-04-10 09:09:40 -07:00
|
|
|
dom::Selection* domSel = DOMSelection();
|
2013-11-18 05:19:33 -08:00
|
|
|
if (!domSel)
|
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-04-06 17:09:31 -07:00
|
|
|
if (aSelectionNum < 0 || aSelectionNum >= domSel->GetRangeCount())
|
2013-11-18 05:19:33 -08:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-11-18 05:19:33 -08:00
|
|
|
domSel->RemoveRange(domSel->GetRangeAt(aSelectionNum));
|
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-11-18 05:19:33 -08:00
|
|
|
void
|
|
|
|
HyperTextAccessible::ScrollSubstringTo(int32_t aStartOffset, int32_t aEndOffset,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aScrollType)
|
2007-08-23 21:54:45 -07:00
|
|
|
{
|
2013-02-07 04:09:41 -08:00
|
|
|
nsRefPtr<nsRange> range = new nsRange(mContent);
|
2013-12-13 08:26:35 -08:00
|
|
|
if (OffsetsToDOMRange(aStartOffset, aEndOffset, range))
|
2013-11-18 05:19:33 -08:00
|
|
|
nsCoreUtils::ScrollSubstringTo(GetFrame(), range, aScrollType);
|
2007-09-24 22:48:51 -07:00
|
|
|
}
|
|
|
|
|
2013-11-18 05:19:33 -08:00
|
|
|
void
|
|
|
|
HyperTextAccessible::ScrollSubstringToPoint(int32_t aStartOffset,
|
|
|
|
int32_t aEndOffset,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aCoordinateType,
|
|
|
|
int32_t aX, int32_t aY)
|
2007-09-24 22:48:51 -07:00
|
|
|
{
|
|
|
|
nsIFrame *frame = GetFrame();
|
|
|
|
if (!frame)
|
2013-11-18 05:19:33 -08:00
|
|
|
return;
|
2007-08-23 21:54:45 -07:00
|
|
|
|
2012-12-17 12:11:02 -08:00
|
|
|
nsIntPoint coords = nsAccUtils::ConvertToScreenCoords(aX, aY, aCoordinateType,
|
|
|
|
this);
|
2007-08-23 21:54:45 -07:00
|
|
|
|
2013-02-07 04:09:41 -08:00
|
|
|
nsRefPtr<nsRange> range = new nsRange(mContent);
|
2013-12-13 08:26:35 -08:00
|
|
|
if (!OffsetsToDOMRange(aStartOffset, aEndOffset, range))
|
2013-11-18 05:19:33 -08:00
|
|
|
return;
|
2007-08-23 21:54:45 -07:00
|
|
|
|
2012-10-20 18:38:15 -07:00
|
|
|
nsPresContext* presContext = frame->PresContext();
|
|
|
|
nsPoint coordsInAppUnits =
|
|
|
|
coords.ToAppUnits(presContext->AppUnitsPerDevPixel());
|
2007-09-24 22:48:51 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool initialScrolled = false;
|
2007-09-24 22:48:51 -07:00
|
|
|
nsIFrame *parentFrame = frame;
|
2008-02-08 01:35:42 -08:00
|
|
|
while ((parentFrame = parentFrame->GetParent())) {
|
2009-01-12 11:20:59 -08:00
|
|
|
nsIScrollableFrame *scrollableFrame = do_QueryFrame(parentFrame);
|
2007-09-24 22:48:51 -07:00
|
|
|
if (scrollableFrame) {
|
|
|
|
if (!initialScrolled) {
|
|
|
|
// Scroll substring to the given point. Turn the point into percents
|
2008-10-15 18:52:58 -07:00
|
|
|
// relative scrollable area to use nsCoreUtils::ScrollSubstringTo.
|
2012-10-20 18:38:15 -07:00
|
|
|
nsRect frameRect = parentFrame->GetScreenRectInAppUnits();
|
|
|
|
nscoord offsetPointX = coordsInAppUnits.x - frameRect.x;
|
|
|
|
nscoord offsetPointY = coordsInAppUnits.y - frameRect.y;
|
2007-09-24 22:48:51 -07:00
|
|
|
|
|
|
|
nsSize size(parentFrame->GetSize());
|
2009-11-10 06:07:19 -08:00
|
|
|
|
|
|
|
// avoid divide by zero
|
|
|
|
size.width = size.width ? size.width : 1;
|
|
|
|
size.height = size.height ? size.height : 1;
|
|
|
|
|
2012-10-20 18:38:15 -07:00
|
|
|
int16_t hPercent = offsetPointX * 100 / size.width;
|
|
|
|
int16_t vPercent = offsetPointY * 100 / size.height;
|
2007-09-24 22:48:51 -07:00
|
|
|
|
2013-12-13 08:26:35 -08:00
|
|
|
nsresult rv = nsCoreUtils::ScrollSubstringTo(frame, range, vPercent, hPercent);
|
2013-11-18 05:19:33 -08:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return;
|
2007-09-24 22:48:51 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
initialScrolled = true;
|
2007-09-24 22:48:51 -07: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-15 18:52:58 -07:00
|
|
|
nsCoreUtils::ScrollFrameToPoint(parentFrame, frame, coords);
|
2007-09-24 22:48:51 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
frame = parentFrame;
|
2007-08-23 21:54:45 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-27 08:33:09 -08:00
|
|
|
void
|
|
|
|
HyperTextAccessible::EnclosingRange(a11y::TextRange& aRange) const
|
|
|
|
{
|
2014-04-16 05:50:28 -07:00
|
|
|
if (IsTextField()) {
|
|
|
|
aRange.Set(mDoc, const_cast<HyperTextAccessible*>(this), 0,
|
|
|
|
const_cast<HyperTextAccessible*>(this), ChildCount());
|
|
|
|
} else {
|
|
|
|
aRange.Set(mDoc, mDoc, 0, mDoc, mDoc->ChildCount());
|
|
|
|
}
|
2014-02-27 08:33:09 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HyperTextAccessible::SelectionRanges(nsTArray<a11y::TextRange>* aRanges) const
|
|
|
|
{
|
2014-04-16 05:50:28 -07:00
|
|
|
NS_ASSERTION(aRanges->Length() != 0, "TextRange array supposed to be empty");
|
|
|
|
|
2014-04-10 09:09:40 -07:00
|
|
|
dom::Selection* sel = DOMSelection();
|
2014-04-16 05:50:28 -07:00
|
|
|
if (!sel)
|
|
|
|
return;
|
|
|
|
|
|
|
|
aRanges->SetCapacity(sel->RangeCount());
|
|
|
|
|
|
|
|
for (uint32_t idx = 0; idx < sel->RangeCount(); idx++) {
|
|
|
|
nsRange* DOMRange = sel->GetRangeAt(idx);
|
|
|
|
HyperTextAccessible* startParent =
|
|
|
|
nsAccUtils::GetTextContainer(DOMRange->GetStartParent());
|
|
|
|
HyperTextAccessible* endParent =
|
|
|
|
nsAccUtils::GetTextContainer(DOMRange->GetEndParent());
|
|
|
|
if (!startParent || !endParent)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
int32_t startOffset =
|
|
|
|
startParent->DOMPointToOffset(DOMRange->GetStartParent(),
|
|
|
|
DOMRange->StartOffset(), false);
|
|
|
|
int32_t endOffset =
|
|
|
|
endParent->DOMPointToOffset(DOMRange->GetEndParent(),
|
|
|
|
DOMRange->EndOffset(), true);
|
|
|
|
|
|
|
|
TextRange tr(IsTextField() ? const_cast<HyperTextAccessible*>(this) : mDoc,
|
|
|
|
startParent, startOffset, endParent, endOffset);
|
|
|
|
*(aRanges->AppendElement()) = Move(tr);
|
|
|
|
}
|
2014-02-27 08:33:09 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HyperTextAccessible::VisibleRanges(nsTArray<a11y::TextRange>* aRanges) const
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HyperTextAccessible::RangeByChild(Accessible* aChild,
|
|
|
|
a11y::TextRange& aRange) const
|
|
|
|
{
|
2014-04-16 05:50:28 -07:00
|
|
|
aRange.Set(mDoc, aChild, 0, aChild, aChild->ChildCount());
|
2014-02-27 08:33:09 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HyperTextAccessible::RangeAtPoint(int32_t aX, int32_t aY,
|
|
|
|
a11y::TextRange& aRange) const
|
|
|
|
{
|
2014-04-16 05:50:28 -07:00
|
|
|
Accessible* child = mDoc->ChildAtPoint(aX, aY, eDeepestChild);
|
|
|
|
if (child)
|
|
|
|
aRange.Set(mDoc, child, 0, child, child->ChildCount());
|
2014-02-27 08:33:09 -08:00
|
|
|
}
|
|
|
|
|
2010-06-21 06:08:27 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-05-28 18:18:45 -07:00
|
|
|
// Accessible public
|
2010-06-21 06:08:27 -07:00
|
|
|
|
2012-10-13 21:18:39 -07:00
|
|
|
// Accessible protected
|
|
|
|
ENameValueFlag
|
|
|
|
HyperTextAccessible::NativeName(nsString& aName)
|
2011-11-24 03:31:25 -08:00
|
|
|
{
|
2013-06-12 02:13:34 -07:00
|
|
|
// Check @alt attribute for invalid img elements.
|
|
|
|
bool hasImgAlt = false;
|
|
|
|
if (mContent->IsHTML(nsGkAtoms::img)) {
|
|
|
|
hasImgAlt = mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::alt, aName);
|
|
|
|
if (!aName.IsEmpty())
|
|
|
|
return eNameOK;
|
|
|
|
}
|
|
|
|
|
2012-10-16 23:38:16 -07:00
|
|
|
ENameValueFlag nameFlag = AccessibleWrap::NativeName(aName);
|
|
|
|
if (!aName.IsEmpty())
|
|
|
|
return nameFlag;
|
2011-11-24 03:31:25 -08: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.
|
2012-10-16 23:38:16 -07:00
|
|
|
if (IsAbbreviation() &&
|
2012-10-13 21:18:39 -07:00
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::title, aName))
|
|
|
|
aName.CompressWhitespace();
|
|
|
|
|
2013-06-12 02:13:34 -07:00
|
|
|
return hasImgAlt ? eNoNameOnPurpose : eNameOK;
|
2011-11-24 03:31:25 -08:00
|
|
|
}
|
|
|
|
|
2010-06-21 06:08:27 -07:00
|
|
|
void
|
2012-05-31 01:04:41 -07:00
|
|
|
HyperTextAccessible::InvalidateChildren()
|
2010-06-21 06:08:27 -07:00
|
|
|
{
|
2010-07-01 18:50:03 -07:00
|
|
|
mOffsets.Clear();
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap::InvalidateChildren();
|
2010-06-21 06:08:27 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2012-05-31 01:04:41 -07:00
|
|
|
HyperTextAccessible::RemoveChild(Accessible* aAccessible)
|
2011-02-02 09:02:48 -08:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t childIndex = aAccessible->IndexInParent();
|
|
|
|
int32_t count = mOffsets.Length() - childIndex;
|
2011-02-02 09:02:48 -08:00
|
|
|
if (count > 0)
|
|
|
|
mOffsets.RemoveElementsAt(childIndex, count);
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
return Accessible::RemoveChild(aAccessible);
|
2011-02-02 09:02:48 -08:00
|
|
|
}
|
|
|
|
|
2013-09-11 09:56:01 -07:00
|
|
|
void
|
|
|
|
HyperTextAccessible::CacheChildren()
|
|
|
|
{
|
|
|
|
// Trailing HTML br element don't play any difference. We don't need to expose
|
|
|
|
// it to AT (see bug https://bugzilla.mozilla.org/show_bug.cgi?id=899433#c16
|
|
|
|
// for details).
|
|
|
|
|
|
|
|
TreeWalker walker(this, mContent);
|
|
|
|
Accessible* child = nullptr;
|
|
|
|
Accessible* lastChild = nullptr;
|
|
|
|
while ((child = walker.NextChild())) {
|
|
|
|
if (lastChild)
|
|
|
|
AppendChild(lastChild);
|
|
|
|
|
|
|
|
lastChild = child;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lastChild) {
|
|
|
|
if (lastChild->IsHTMLBr())
|
|
|
|
Document()->UnbindFromDocument(lastChild);
|
|
|
|
else
|
|
|
|
AppendChild(lastChild);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-21 06:08:27 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-05-31 01:04:41 -07:00
|
|
|
// HyperTextAccessible public static
|
2010-06-21 06:08:27 -07:00
|
|
|
|
2012-05-31 01:04:41 -07:00
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
HyperTextAccessible::ContentToRenderedOffset(nsIFrame* aFrame, int32_t aContentOffset,
|
2013-11-18 05:19:33 -08:00
|
|
|
uint32_t* aRenderedOffset) const
|
2007-08-03 18:12:24 -07:00
|
|
|
{
|
2007-11-27 10:12:15 -08: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 01:15:26 -07:00
|
|
|
|
|
|
|
if (IsTextField()) {
|
|
|
|
*aRenderedOffset = aContentOffset;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-06-03 14:35:17 -07:00
|
|
|
NS_ASSERTION(aFrame->GetType() == nsGkAtoms::textFrame,
|
2007-09-05 06:31:33 -07:00
|
|
|
"Need text frame for offset conversion");
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ASSERTION(aFrame->GetPrevContinuation() == nullptr,
|
2007-09-05 06:31:33 -07:00
|
|
|
"Call on primary frame only");
|
|
|
|
|
2007-08-03 18:12:24 -07:00
|
|
|
gfxSkipChars skipChars;
|
|
|
|
gfxSkipCharsIterator iter;
|
2009-01-11 10:46:17 -08:00
|
|
|
// Only get info up to original offset, we know that will be larger than skipped offset
|
2012-07-30 07:20:58 -07:00
|
|
|
nsresult rv = aFrame->GetRenderedText(nullptr, &skipChars, &iter, 0, aContentOffset);
|
2007-08-03 18:12:24 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t ourRenderedStart = iter.GetSkippedOffset();
|
|
|
|
int32_t ourContentStart = iter.GetOriginalOffset();
|
2007-08-03 18:12:24 -07:00
|
|
|
|
|
|
|
*aRenderedOffset = iter.ConvertOriginalToSkipped(aContentOffset + ourContentStart) -
|
|
|
|
ourRenderedStart;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-05-31 01:04:41 -07:00
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
HyperTextAccessible::RenderedToContentOffset(nsIFrame* aFrame, uint32_t aRenderedOffset,
|
2013-11-18 05:19:33 -08:00
|
|
|
int32_t* aContentOffset) const
|
2007-08-03 18:12:24 -07:00
|
|
|
{
|
2013-04-05 01:15:26 -07:00
|
|
|
if (IsTextField()) {
|
|
|
|
*aContentOffset = aRenderedOffset;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-11-27 10:12:15 -08:00
|
|
|
*aContentOffset = 0;
|
|
|
|
NS_ENSURE_TRUE(aFrame, NS_ERROR_FAILURE);
|
|
|
|
|
2011-06-03 14:35:17 -07:00
|
|
|
NS_ASSERTION(aFrame->GetType() == nsGkAtoms::textFrame,
|
2007-09-05 06:31:33 -07:00
|
|
|
"Need text frame for offset conversion");
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ASSERTION(aFrame->GetPrevContinuation() == nullptr,
|
2007-09-05 06:31:33 -07:00
|
|
|
"Call on primary frame only");
|
|
|
|
|
2007-08-03 18:12:24 -07:00
|
|
|
gfxSkipChars skipChars;
|
|
|
|
gfxSkipCharsIterator iter;
|
|
|
|
// We only need info up to skipped offset -- that is what we're converting to original offset
|
2012-07-30 07:20:58 -07:00
|
|
|
nsresult rv = aFrame->GetRenderedText(nullptr, &skipChars, &iter, 0, aRenderedOffset);
|
2007-08-03 18:12:24 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t ourRenderedStart = iter.GetSkippedOffset();
|
|
|
|
int32_t ourContentStart = iter.GetOriginalOffset();
|
2007-08-03 18:12:24 -07:00
|
|
|
|
|
|
|
*aContentOffset = iter.ConvertSkippedToOriginal(aRenderedOffset + ourRenderedStart) - ourContentStart;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-07-01 18:50:03 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-05-31 01:04:41 -07:00
|
|
|
// HyperTextAccessible public
|
2010-07-01 18:50:03 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t
|
|
|
|
HyperTextAccessible::GetChildOffset(uint32_t aChildIndex,
|
2014-01-25 06:07:37 -08:00
|
|
|
bool aInvalidateAfter) const
|
2010-07-01 18:50:03 -07:00
|
|
|
{
|
2011-01-20 00:02:10 -08:00
|
|
|
if (aChildIndex == 0) {
|
|
|
|
if (aInvalidateAfter)
|
|
|
|
mOffsets.Clear();
|
|
|
|
|
2010-08-15 04:28:49 -07:00
|
|
|
return aChildIndex;
|
2011-01-20 00:02:10 -08:00
|
|
|
}
|
2010-07-01 18:50:03 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t count = mOffsets.Length() - aChildIndex;
|
2010-07-01 18:50:03 -07:00
|
|
|
if (count > 0) {
|
|
|
|
if (aInvalidateAfter)
|
2010-08-15 04:28:49 -07:00
|
|
|
mOffsets.RemoveElementsAt(aChildIndex, count);
|
2010-07-01 18:50:03 -07:00
|
|
|
|
2010-08-15 04:28:49 -07:00
|
|
|
return mOffsets[aChildIndex - 1];
|
2010-07-01 18:50:03 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t lastOffset = mOffsets.IsEmpty() ?
|
2010-07-01 18:50:03 -07:00
|
|
|
0 : mOffsets[mOffsets.Length() - 1];
|
|
|
|
|
2010-08-15 04:28:49 -07:00
|
|
|
while (mOffsets.Length() < aChildIndex) {
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* child = mChildren[mOffsets.Length()];
|
2010-07-01 18:50:03 -07:00
|
|
|
lastOffset += nsAccUtils::TextLength(child);
|
|
|
|
mOffsets.AppendElement(lastOffset);
|
|
|
|
}
|
|
|
|
|
2010-08-15 04:28:49 -07:00
|
|
|
return mOffsets[aChildIndex - 1];
|
2010-07-01 18:50:03 -07:00
|
|
|
}
|
2010-05-25 01:40:26 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t
|
2014-01-25 06:07:37 -08:00
|
|
|
HyperTextAccessible::GetChildIndexAtOffset(uint32_t aOffset) const
|
2010-06-21 06:08:27 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t lastOffset = 0;
|
|
|
|
uint32_t offsetCount = mOffsets.Length();
|
2010-08-15 04:28:49 -07:00
|
|
|
if (offsetCount > 0) {
|
|
|
|
lastOffset = mOffsets[offsetCount - 1];
|
|
|
|
if (aOffset < lastOffset) {
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t low = 0, high = offsetCount;
|
2010-08-15 04:28:49 -07:00
|
|
|
while (high > low) {
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mid = (high + low) >> 1;
|
2010-08-15 04:28:49 -07:00
|
|
|
if (mOffsets[mid] == aOffset)
|
|
|
|
return mid < offsetCount - 1 ? mid + 1 : mid;
|
|
|
|
|
|
|
|
if (mOffsets[mid] < aOffset)
|
|
|
|
low = mid + 1;
|
|
|
|
else
|
|
|
|
high = mid;
|
|
|
|
}
|
|
|
|
if (high == offsetCount)
|
|
|
|
return -1;
|
2010-06-21 06:08:27 -07:00
|
|
|
|
2010-08-18 19:14:14 -07:00
|
|
|
return low;
|
2010-05-25 01:40:26 -07:00
|
|
|
}
|
2010-08-15 04:28:49 -07:00
|
|
|
}
|
2010-05-25 01:40:26 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t childCount = ChildCount();
|
2010-08-15 04:28:49 -07:00
|
|
|
while (mOffsets.Length() < childCount) {
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* child = GetChildAt(mOffsets.Length());
|
2010-08-15 04:28:49 -07:00
|
|
|
lastOffset += nsAccUtils::TextLength(child);
|
|
|
|
mOffsets.AppendElement(lastOffset);
|
|
|
|
if (aOffset < lastOffset)
|
|
|
|
return mOffsets.Length() - 1;
|
2010-05-25 01:40:26 -07:00
|
|
|
}
|
|
|
|
|
2010-08-15 04:28:49 -07:00
|
|
|
if (aOffset == lastOffset)
|
|
|
|
return mOffsets.Length() - 1;
|
|
|
|
|
|
|
|
return -1;
|
2010-05-25 01:40:26 -07:00
|
|
|
}
|
|
|
|
|
2010-08-15 04:28:49 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-05-31 01:04:41 -07:00
|
|
|
// HyperTextAccessible protected
|
2010-08-15 04:28:49 -07:00
|
|
|
|
2007-09-24 22:48:51 -07:00
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
HyperTextAccessible::GetDOMPointByFrameOffset(nsIFrame* aFrame, int32_t aOffset,
|
2012-05-31 01:04:41 -07:00
|
|
|
Accessible* aAccessible,
|
2012-04-06 11:08:24 -07:00
|
|
|
DOMPoint* aPoint)
|
2007-09-24 22:48:51 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(aAccessible);
|
|
|
|
|
|
|
|
if (!aFrame) {
|
|
|
|
// If the given frame is null then set offset after the DOM node of the
|
|
|
|
// given accessible.
|
2012-04-14 19:24:37 -07:00
|
|
|
NS_ASSERTION(!aAccessible->IsDoc(),
|
|
|
|
"Shouldn't be called on document accessible!");
|
|
|
|
|
|
|
|
nsIContent* content = aAccessible->GetContent();
|
|
|
|
NS_ASSERTION(content, "Shouldn't operate on defunct accessible!");
|
2007-09-24 22:48:51 -07:00
|
|
|
|
2012-04-14 19:24:37 -07:00
|
|
|
nsIContent* parent = content->GetParent();
|
2007-09-24 22:48:51 -07:00
|
|
|
|
2012-04-06 11:08:24 -07:00
|
|
|
aPoint->idx = parent->IndexOf(content) + 1;
|
|
|
|
aPoint->node = parent;
|
2007-09-24 22:48:51 -07:00
|
|
|
|
2011-06-03 14:35:17 -07:00
|
|
|
} else if (aFrame->GetType() == nsGkAtoms::textFrame) {
|
2012-04-06 11:08:24 -07:00
|
|
|
nsIContent* content = aFrame->GetContent();
|
2007-09-24 22:48:51 -07:00
|
|
|
NS_ENSURE_STATE(content);
|
|
|
|
|
2009-12-24 13:20:05 -08:00
|
|
|
nsIFrame *primaryFrame = content->GetPrimaryFrame();
|
2012-04-06 11:08:24 -07:00
|
|
|
nsresult rv = RenderedToContentOffset(primaryFrame, aOffset, &(aPoint->idx));
|
2007-09-24 22:48:51 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-04-06 11:08:24 -07:00
|
|
|
aPoint->node = content;
|
2007-09-24 22:48:51 -07:00
|
|
|
|
|
|
|
} else {
|
2012-04-06 11:08:24 -07:00
|
|
|
nsIContent* content = aFrame->GetContent();
|
2007-09-24 22:48:51 -07:00
|
|
|
NS_ENSURE_STATE(content);
|
|
|
|
|
2012-04-06 11:08:24 -07:00
|
|
|
nsIContent* parent = content->GetParent();
|
2007-09-24 22:48:51 -07:00
|
|
|
NS_ENSURE_STATE(parent);
|
|
|
|
|
2012-04-06 11:08:24 -07:00
|
|
|
aPoint->idx = parent->IndexOf(content);
|
|
|
|
aPoint->node = parent;
|
2007-09-24 22:48:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-08-03 18:12:24 -07:00
|
|
|
|
2012-05-31 01:04:41 -07:00
|
|
|
// HyperTextAccessible
|
2008-07-17 05:06:24 -07:00
|
|
|
nsresult
|
2012-05-31 01:04:41 -07:00
|
|
|
HyperTextAccessible::GetSpellTextAttribute(nsINode* aNode,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aNodeOffset,
|
|
|
|
int32_t* aHTStartOffset,
|
|
|
|
int32_t* aHTEndOffset,
|
2012-05-31 01:04:41 -07:00
|
|
|
nsIPersistentProperties* aAttributes)
|
2008-07-17 05:06:24 -07:00
|
|
|
{
|
2012-10-19 17:56:58 -07:00
|
|
|
nsRefPtr<nsFrameSelection> fs = FrameSelection();
|
|
|
|
if (!fs)
|
2008-07-17 05:06:24 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
2014-04-10 09:09:40 -07:00
|
|
|
dom::Selection* domSel = fs->GetSelection(nsISelectionController::SELECTION_SPELLCHECK);
|
2012-10-19 17:56:58 -07:00
|
|
|
if (!domSel)
|
|
|
|
return NS_OK;
|
2008-07-17 05:06:24 -07:00
|
|
|
|
2012-10-19 17:56:58 -07:00
|
|
|
int32_t rangeCount = domSel->GetRangeCount();
|
|
|
|
if (rangeCount <= 0)
|
|
|
|
return NS_OK;
|
2008-07-17 05:06:24 -07:00
|
|
|
|
2012-10-19 17:56:58 -07:00
|
|
|
int32_t startHTOffset = 0, endHTOffset = 0;
|
|
|
|
for (int32_t idx = 0; idx < rangeCount; idx++) {
|
|
|
|
nsRange* range = domSel->GetRangeAt(idx);
|
|
|
|
if (range->Collapsed())
|
|
|
|
continue;
|
2008-07-17 05:06:24 -07:00
|
|
|
|
2012-10-19 17:56:58 -07:00
|
|
|
// See if the point comes after the range in which case we must continue in
|
|
|
|
// case there is another range after this one.
|
|
|
|
nsINode* endNode = range->GetEndParent();
|
|
|
|
int32_t endOffset = range->EndOffset();
|
|
|
|
if (nsContentUtils::ComparePoints(aNode, aNodeOffset, endNode, endOffset) >= 0)
|
|
|
|
continue;
|
2008-07-17 05:06:24 -07:00
|
|
|
|
2012-10-19 17:56:58 -07: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.
|
|
|
|
nsINode* startNode = range->GetStartParent();
|
|
|
|
int32_t startOffset = range->StartOffset();
|
|
|
|
if (nsContentUtils::ComparePoints(startNode, startOffset, aNode,
|
|
|
|
aNodeOffset) <= 0) {
|
2014-02-14 08:40:08 -08:00
|
|
|
startHTOffset = DOMPointToOffset(startNode, startOffset);
|
2008-07-17 05:06:24 -07:00
|
|
|
|
2014-02-14 08:40:08 -08:00
|
|
|
endHTOffset = DOMPointToOffset(endNode, endOffset);
|
2008-07-17 05:06:24 -07:00
|
|
|
|
|
|
|
if (startHTOffset > *aHTStartOffset)
|
|
|
|
*aHTStartOffset = startHTOffset;
|
2012-10-19 17:56:58 -07:00
|
|
|
|
2008-07-17 05:06:24 -07:00
|
|
|
if (endHTOffset < *aHTEndOffset)
|
|
|
|
*aHTEndOffset = endHTOffset;
|
|
|
|
|
2008-07-24 08:20:39 -07:00
|
|
|
if (aAttributes) {
|
2011-06-03 14:35:17 -07:00
|
|
|
nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::invalid,
|
2008-10-16 02:12:05 -07:00
|
|
|
NS_LITERAL_STRING("spelling"));
|
2008-07-24 08:20:39 -07:00
|
|
|
}
|
2008-07-17 05:06:24 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-10-19 17:56:58 -07:00
|
|
|
|
|
|
|
// This range came after the point.
|
2014-02-14 08:40:08 -08:00
|
|
|
endHTOffset = DOMPointToOffset(startNode, startOffset);
|
2012-10-19 17:56:58 -07:00
|
|
|
|
|
|
|
if (idx > 0) {
|
2014-02-14 08:40:08 -08:00
|
|
|
nsRange* prevRange = domSel->GetRangeAt(idx - 1);
|
|
|
|
startHTOffset = DOMPointToOffset(prevRange->GetEndParent(),
|
|
|
|
prevRange->EndOffset());
|
2012-10-19 17:56:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (startHTOffset > *aHTStartOffset)
|
|
|
|
*aHTStartOffset = startHTOffset;
|
|
|
|
|
|
|
|
if (endHTOffset < *aHTEndOffset)
|
|
|
|
*aHTEndOffset = endHTOffset;
|
|
|
|
|
|
|
|
return NS_OK;
|
2008-07-17 05:06:24 -07:00
|
|
|
}
|
|
|
|
|
2012-10-19 17:56:58 -07: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.
|
2014-02-14 08:40:08 -08:00
|
|
|
nsRange* prevRange = domSel->GetRangeAt(rangeCount - 1);
|
|
|
|
startHTOffset = DOMPointToOffset(prevRange->GetEndParent(),
|
|
|
|
prevRange->EndOffset());
|
2012-10-19 17:56:58 -07:00
|
|
|
|
|
|
|
if (startHTOffset > *aHTStartOffset)
|
|
|
|
*aHTStartOffset = startHTOffset;
|
|
|
|
|
2008-07-17 05:06:24 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-04-13 18:19:41 -07:00
|
|
|
|
|
|
|
bool
|
2012-05-31 01:04:41 -07:00
|
|
|
HyperTextAccessible::IsTextRole()
|
2012-04-13 18:19:41 -07:00
|
|
|
{
|
|
|
|
if (mRoleMapEntry &&
|
|
|
|
(mRoleMapEntry->role == roles::GRAPHIC ||
|
|
|
|
mRoleMapEntry->role == roles::IMAGE_MAP ||
|
|
|
|
mRoleMapEntry->role == roles::SLIDER ||
|
|
|
|
mRoleMapEntry->role == roles::PROGRESSBAR ||
|
|
|
|
mRoleMapEntry->role == roles::SEPARATOR))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|