mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 371680 - expose nsIAccessibleText::scrollSubstringTo, r=aaronlev, roc, sr=roc, a=roc
This commit is contained in:
parent
88f44b6ffb
commit
478d0ec01a
@ -45,7 +45,7 @@ typedef long nsAccessibleTextBoundary;
|
||||
|
||||
interface nsIAccessible;
|
||||
|
||||
[scriptable, uuid(17389a66-5cc5-4550-80e0-49e7b63990a4)]
|
||||
[scriptable, uuid(948419b2-53f6-4a74-bb69-1345faf3e8e8)]
|
||||
interface nsIAccessibleText : nsISupports
|
||||
{
|
||||
const nsAccessibleTextBoundary BOUNDARY_CHAR = 0;
|
||||
@ -167,6 +167,20 @@ interface nsIAccessibleText : nsISupports
|
||||
void addSelection (in long startOffset, in long endOffset);
|
||||
|
||||
void removeSelection (in long selectionNum);
|
||||
|
||||
|
||||
/**
|
||||
* Makes a specific part of string visible on screen.
|
||||
*
|
||||
* @param aStartIndex - 0-based character offset.
|
||||
* @param aEndIndex - 0-based character offset - the offset of the
|
||||
* character just past the last character of the
|
||||
* string.
|
||||
* @param aScrollType - defines how to scroll (see nsIAccessibleScrollType for
|
||||
* available constants).
|
||||
*/
|
||||
void scrollSubstringTo(in long aStartIndex, in long aEndIndex,
|
||||
in unsigned long aScrollType);
|
||||
};
|
||||
|
||||
/*
|
||||
|
@ -80,6 +80,12 @@ interface nsIAccessibleScrollType : nsISupports
|
||||
* window (or as close as possible).
|
||||
*/
|
||||
const unsigned long SCROLL_TYPE_RIGHT_EDGE = 0x05;
|
||||
|
||||
/**
|
||||
* Scroll an object the minimum amount necessary in order for the entire
|
||||
* frame to be visible (if possible).
|
||||
*/
|
||||
const unsigned long SCROLL_TYPE_ANYWHERE = 0x06;
|
||||
};
|
||||
|
||||
|
||||
@ -106,3 +112,4 @@ interface nsIAccessibleCoordinateType : nsISupports
|
||||
*/
|
||||
const unsigned long COORDTYPE_PARENT_RELATIVE = 0x02;
|
||||
};
|
||||
|
||||
|
@ -426,35 +426,8 @@ nsAccessNode::ScrollTo(PRUint32 aScrollType)
|
||||
nsCOMPtr<nsIContent> content = frame->GetContent();
|
||||
NS_ENSURE_TRUE(content, NS_ERROR_FAILURE);
|
||||
|
||||
PRInt32 vPercent, hPercent;
|
||||
switch (aScrollType)
|
||||
{
|
||||
case nsIAccessibleScrollType::SCROLL_TYPE_TOP_LEFT:
|
||||
vPercent = NS_PRESSHELL_SCROLL_TOP;
|
||||
hPercent = NS_PRESSHELL_SCROLL_LEFT;
|
||||
break;
|
||||
case nsIAccessibleScrollType::SCROLL_TYPE_BOTTOM_RIGHT:
|
||||
vPercent = NS_PRESSHELL_SCROLL_BOTTOM;
|
||||
hPercent = NS_PRESSHELL_SCROLL_RIGHT;
|
||||
break;
|
||||
case nsIAccessibleScrollType::SCROLL_TYPE_TOP_EDGE:
|
||||
vPercent = NS_PRESSHELL_SCROLL_TOP;
|
||||
hPercent = NS_PRESSHELL_SCROLL_ANYWHERE;
|
||||
break;
|
||||
case nsIAccessibleScrollType::SCROLL_TYPE_BOTTOM_EDGE:
|
||||
vPercent = NS_PRESSHELL_SCROLL_BOTTOM;
|
||||
hPercent = NS_PRESSHELL_SCROLL_ANYWHERE;
|
||||
break;
|
||||
case nsIAccessibleScrollType::SCROLL_TYPE_LEFT_EDGE:
|
||||
vPercent = NS_PRESSHELL_SCROLL_ANYWHERE;
|
||||
hPercent = NS_PRESSHELL_SCROLL_LEFT;
|
||||
break;
|
||||
case nsIAccessibleScrollType::SCROLL_TYPE_RIGHT_EDGE:
|
||||
vPercent = NS_PRESSHELL_SCROLL_ANYWHERE;
|
||||
hPercent = NS_PRESSHELL_SCROLL_RIGHT;
|
||||
break;
|
||||
}
|
||||
|
||||
PRInt16 vPercent, hPercent;
|
||||
nsAccUtils::ConvertScrollTypeToPercents(aScrollType, &vPercent, &hPercent);
|
||||
return shell->ScrollContentIntoView(content, vPercent, hPercent);
|
||||
}
|
||||
|
||||
|
@ -38,12 +38,21 @@
|
||||
|
||||
#include "nsAccessibilityUtils.h"
|
||||
|
||||
#include "nsIAccessibleTypes.h"
|
||||
#include "nsPIAccessible.h"
|
||||
#include "nsAccessibleEventData.h"
|
||||
|
||||
#include "nsIDOMRange.h"
|
||||
#include "nsIDOMXULSelectCntrlEl.h"
|
||||
#include "nsIDOMXULSelectCntrlItemEl.h"
|
||||
#include "nsIEventListenerManager.h"
|
||||
#include "nsISelection2.h"
|
||||
#include "nsISelectionController.h"
|
||||
|
||||
#include "nsContentCID.h"
|
||||
#include "nsComponentManagerUtils.h"
|
||||
|
||||
static NS_DEFINE_IID(kRangeCID, NS_RANGE_CID);
|
||||
|
||||
void
|
||||
nsAccUtils::GetAccAttr(nsIPersistentProperties *aAttributes, nsIAtom *aAttrName,
|
||||
@ -223,3 +232,82 @@ nsAccUtils::GetAncestorWithRole(nsIAccessible *aDescendant, PRUint32 aRole)
|
||||
}
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsAccUtils::ScrollSubstringTo(nsIFrame *aFrame,
|
||||
nsIDOMNode *aStartNode, PRInt32 aStartIndex,
|
||||
nsIDOMNode *aEndNode, PRInt32 aEndIndex,
|
||||
PRUint32 aScrollType)
|
||||
{
|
||||
if (!aFrame || !aStartNode || !aEndNode)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsPresContext *presContext = aFrame->PresContext();
|
||||
|
||||
nsCOMPtr<nsIDOMRange> scrollToRange = do_CreateInstance(kRangeCID);
|
||||
NS_ENSURE_TRUE(scrollToRange, NS_ERROR_FAILURE);
|
||||
|
||||
nsCOMPtr<nsISelectionController> selCon;
|
||||
aFrame->GetSelectionController(presContext, getter_AddRefs(selCon));
|
||||
NS_ENSURE_TRUE(selCon, NS_ERROR_FAILURE);
|
||||
|
||||
scrollToRange->SetStart(aStartNode, aStartIndex);
|
||||
scrollToRange->SetEnd(aEndNode, aEndIndex);
|
||||
|
||||
nsCOMPtr<nsISelection> selection1;
|
||||
selCon->GetSelection(nsISelectionController::SELECTION_ACCESSIBILITY,
|
||||
getter_AddRefs(selection1));
|
||||
|
||||
nsCOMPtr<nsISelection2> selection(do_QueryInterface(selection1));
|
||||
if (selection) {
|
||||
selection->RemoveAllRanges();
|
||||
selection->AddRange(scrollToRange);
|
||||
|
||||
PRInt16 vPercent, hPercent;
|
||||
ConvertScrollTypeToPercents(aScrollType, &vPercent, &hPercent);
|
||||
selection->ScrollIntoView(nsISelectionController::SELECTION_ANCHOR_REGION,
|
||||
PR_TRUE, vPercent, hPercent);
|
||||
|
||||
selection->CollapseToStart();
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsAccUtils::ConvertScrollTypeToPercents(PRUint32 aScrollType,
|
||||
PRInt16 *aVPercent,
|
||||
PRInt16 *aHPercent)
|
||||
{
|
||||
switch (aScrollType)
|
||||
{
|
||||
case nsIAccessibleScrollType::SCROLL_TYPE_TOP_LEFT:
|
||||
*aVPercent = NS_PRESSHELL_SCROLL_TOP;
|
||||
*aHPercent = NS_PRESSHELL_SCROLL_LEFT;
|
||||
break;
|
||||
case nsIAccessibleScrollType::SCROLL_TYPE_BOTTOM_RIGHT:
|
||||
*aVPercent = NS_PRESSHELL_SCROLL_BOTTOM;
|
||||
*aHPercent = NS_PRESSHELL_SCROLL_RIGHT;
|
||||
break;
|
||||
case nsIAccessibleScrollType::SCROLL_TYPE_TOP_EDGE:
|
||||
*aVPercent = NS_PRESSHELL_SCROLL_TOP;
|
||||
*aHPercent = NS_PRESSHELL_SCROLL_ANYWHERE;
|
||||
break;
|
||||
case nsIAccessibleScrollType::SCROLL_TYPE_BOTTOM_EDGE:
|
||||
*aVPercent = NS_PRESSHELL_SCROLL_BOTTOM;
|
||||
*aHPercent = NS_PRESSHELL_SCROLL_ANYWHERE;
|
||||
break;
|
||||
case nsIAccessibleScrollType::SCROLL_TYPE_LEFT_EDGE:
|
||||
*aVPercent = NS_PRESSHELL_SCROLL_ANYWHERE;
|
||||
*aHPercent = NS_PRESSHELL_SCROLL_LEFT;
|
||||
break;
|
||||
case nsIAccessibleScrollType::SCROLL_TYPE_RIGHT_EDGE:
|
||||
*aVPercent = NS_PRESSHELL_SCROLL_ANYWHERE;
|
||||
*aHPercent = NS_PRESSHELL_SCROLL_RIGHT;
|
||||
break;
|
||||
default:
|
||||
*aVPercent = NS_PRESSHELL_SCROLL_ANYWHERE;
|
||||
*aHPercent = NS_PRESSHELL_SCROLL_ANYWHERE;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,6 +45,7 @@
|
||||
#include "nsIDOMNode.h"
|
||||
#include "nsIPersistentProperties2.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsIFrame.h"
|
||||
|
||||
class nsAccUtils
|
||||
{
|
||||
@ -132,6 +133,31 @@ public:
|
||||
*/
|
||||
static already_AddRefed<nsIAccessible>
|
||||
GetAncestorWithRole(nsIAccessible *aDescendant, PRUint32 aRole);
|
||||
|
||||
/**
|
||||
* Helper method to scroll range into view, used for implementation of
|
||||
* nsIAccessibleText::scrollSubstringTo().
|
||||
*
|
||||
* @param aFrame the frame for accessible the range belongs to.
|
||||
* @param aStartNode start node of a range
|
||||
* @param aStartOffset an offset inside the start node
|
||||
* @param aEndNode end node of a range
|
||||
* @param aEndOffset an offset inside the end node
|
||||
* @param aScrollType the place a range should be scrolled to
|
||||
*/
|
||||
static nsresult ScrollSubstringTo(nsIFrame *aFrame,
|
||||
nsIDOMNode *aStartNode, PRInt32 aStartIndex,
|
||||
nsIDOMNode *aEndNode, PRInt32 aEndIndex,
|
||||
PRUint32 aScrollType);
|
||||
|
||||
/**
|
||||
* Converts scroll type constant defined in nsIAccessibleScrollType to
|
||||
* vertical and horizontal percents.
|
||||
*/
|
||||
static void ConvertScrollTypeToPercents(PRUint32 aScrollType,
|
||||
PRInt16 *aVPercent,
|
||||
PRInt16 *aHPercent);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -315,7 +315,9 @@ nsIntRect nsHyperTextAccessible::GetBoundsForString(nsIFrame *aFrame, PRUint32 a
|
||||
nsIFrame*
|
||||
nsHyperTextAccessible::GetPosAndText(PRInt32& aStartOffset, PRInt32& aEndOffset,
|
||||
nsAString *aText, nsIFrame **aEndFrame,
|
||||
nsIntRect *aBoundsRect)
|
||||
nsIntRect *aBoundsRect,
|
||||
nsIAccessible **aStartAcc,
|
||||
nsIAccessible **aEndAcc)
|
||||
{
|
||||
PRInt32 startOffset = aStartOffset;
|
||||
PRInt32 endOffset = aEndOffset;
|
||||
@ -339,6 +341,10 @@ nsHyperTextAccessible::GetPosAndText(PRInt32& aStartOffset, PRInt32& aEndOffset,
|
||||
if (aBoundsRect) {
|
||||
aBoundsRect->Empty();
|
||||
}
|
||||
if (aStartAcc)
|
||||
*aStartAcc = nsnull;
|
||||
if (aEndAcc)
|
||||
*aEndAcc = nsnull;
|
||||
|
||||
nsIntRect unionRect;
|
||||
nsCOMPtr<nsIAccessible> accessible;
|
||||
@ -385,6 +391,8 @@ nsHyperTextAccessible::GetPosAndText(PRInt32& aStartOffset, PRInt32& aEndOffset,
|
||||
&outStartLineUnused, &frame);
|
||||
if (aEndFrame) {
|
||||
*aEndFrame = frame; // We ended in the current frame
|
||||
if (aEndAcc)
|
||||
NS_ADDREF(*aEndAcc = accessible);
|
||||
}
|
||||
if (substringEndOffset > endOffset) {
|
||||
// Need to stop before the end of the available text
|
||||
@ -405,6 +413,8 @@ nsHyperTextAccessible::GetPosAndText(PRInt32& aStartOffset, PRInt32& aEndOffset,
|
||||
if (!startFrame) {
|
||||
startFrame = frame;
|
||||
aStartOffset = startOffset;
|
||||
if (aStartAcc)
|
||||
NS_ADDREF(*aStartAcc = accessible);
|
||||
}
|
||||
// We already started copying in this accessible's string,
|
||||
// for the next accessible we'll start at offset 0
|
||||
@ -438,6 +448,8 @@ nsHyperTextAccessible::GetPosAndText(PRInt32& aStartOffset, PRInt32& aEndOffset,
|
||||
if (!startFrame) {
|
||||
startFrame = frame;
|
||||
aStartOffset = 0;
|
||||
if (aStartAcc)
|
||||
NS_ADDREF(*aStartAcc = accessible);
|
||||
}
|
||||
}
|
||||
-- endOffset;
|
||||
@ -449,6 +461,8 @@ nsHyperTextAccessible::GetPosAndText(PRInt32& aStartOffset, PRInt32& aEndOffset,
|
||||
|
||||
if (aEndFrame && !*aEndFrame) {
|
||||
*aEndFrame = startFrame;
|
||||
if (aStartAcc && aEndAcc)
|
||||
NS_ADDREF(*aEndAcc = *aStartAcc);
|
||||
}
|
||||
|
||||
return startFrame;
|
||||
@ -1509,6 +1523,58 @@ NS_IMETHODIMP nsHyperTextAccessible::RemoveSelection(PRInt32 aSelectionNum)
|
||||
return domSel->RemoveRange(range);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHyperTextAccessible::ScrollSubstringTo(PRInt32 aStartIndex, PRInt32 aEndIndex,
|
||||
PRUint32 aScrollType)
|
||||
{
|
||||
PRInt32 startOffset = aStartIndex, endOffset = aEndIndex;
|
||||
nsIFrame *startFrame = nsnull, *endFrame = nsnull;
|
||||
nsCOMPtr<nsIAccessible> startAcc, endAcc;
|
||||
|
||||
startFrame = GetPosAndText(startOffset, endOffset,
|
||||
nsnull, &endFrame, nsnull,
|
||||
getter_AddRefs(startAcc), getter_AddRefs(endAcc));
|
||||
if (!startFrame || !endFrame)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIDOMNode> startNode;
|
||||
nsCOMPtr<nsIContent> startContent(startFrame->GetContent());
|
||||
|
||||
PRBool isStartAccText = IsText(startAcc);
|
||||
if (isStartAccText) {
|
||||
nsresult rv = RenderedToContentOffset(startFrame, startOffset,
|
||||
&startOffset);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
startNode = do_QueryInterface(startContent);
|
||||
} else {
|
||||
nsCOMPtr<nsIContent> startParent(startContent->GetParent());
|
||||
NS_ENSURE_STATE(startParent);
|
||||
startOffset = startParent->IndexOf(startContent);
|
||||
startNode = do_QueryInterface(startParent);
|
||||
}
|
||||
NS_ENSURE_STATE(startNode);
|
||||
|
||||
nsCOMPtr<nsIDOMNode> endNode;
|
||||
nsCOMPtr<nsIContent> endContent(endFrame->GetContent());
|
||||
|
||||
PRBool isEndAccText = IsText(endAcc);
|
||||
if (isEndAccText) {
|
||||
nsresult rv = RenderedToContentOffset(endFrame, endOffset,
|
||||
&endOffset);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
endNode = do_QueryInterface(endContent);
|
||||
} else {
|
||||
nsCOMPtr<nsIContent> endParent(endContent->GetParent());
|
||||
NS_ENSURE_STATE(endParent);
|
||||
endOffset = endParent->IndexOf(endContent);
|
||||
endNode = do_QueryInterface(endParent);
|
||||
}
|
||||
NS_ENSURE_STATE(endNode);
|
||||
|
||||
return nsAccUtils::ScrollSubstringTo(GetFrame(), startNode, startOffset,
|
||||
endNode, endOffset, aScrollType);
|
||||
}
|
||||
|
||||
nsresult nsHyperTextAccessible::ContentToRenderedOffset(nsIFrame *aFrame, PRInt32 aContentOffset,
|
||||
PRUint32 *aRenderedOffset)
|
||||
{
|
||||
|
@ -139,20 +139,38 @@ protected:
|
||||
*/
|
||||
PRInt32 GetRelativeOffset(nsIPresShell *aPresShell, nsIFrame *aFromFrame, PRInt32 aFromOffset,
|
||||
nsSelectionAmount aAmount, nsDirection aDirection, PRBool aNeedsStart);
|
||||
|
||||
/**
|
||||
* Given a start offset and end offset, get substring information. Different info is returned depending
|
||||
* on what optional paramters are provided.
|
||||
* @param aStartOffset, the start offset into the hyper text. This is also an out parameter used to return
|
||||
* the offset into the start frame's rendered text content (start frame is the @return)
|
||||
* @param aEndHyperOffset, the endoffset into the hyper text. This is also an out parameter used to return
|
||||
* the offset into the end frame's rendered text content
|
||||
* @param aText (optional), return the substring's text
|
||||
* @param aEndFrame (optional), return the end frame for this substring
|
||||
* @param aBoundsRect (optional), return the bounds rectangle for this substring
|
||||
* Provides information for substring that is defined by the given start
|
||||
* and end offsets for this hyper text.
|
||||
*
|
||||
* @param aStartOffset [inout] the start offset into the hyper text. This
|
||||
* is also an out parameter used to return the offset
|
||||
* into the start frame's rendered text content
|
||||
* (start frame is the @return)
|
||||
*
|
||||
* @param aEndOffset [inout] the end offset into the hyper text. This is
|
||||
* also an out parameter used to return
|
||||
* the offset into the end frame's rendered
|
||||
* text content.
|
||||
*
|
||||
* @param aText [out, optional] return the substring's text
|
||||
* @param aEndFrame [out, optional] return the end frame for this
|
||||
* substring
|
||||
* @param aBoundsRect [out, optional] return the bounds rectangle for this
|
||||
* substring
|
||||
* @param aStartAcc [out, optional] return the start accessible for this
|
||||
* substring
|
||||
* @param aEndAcc [out, optional] return the end accessible for this
|
||||
* substring
|
||||
* @return the start frame for this substring
|
||||
*/
|
||||
nsIFrame* GetPosAndText(PRInt32& aStartOffset, PRInt32& aEndOffset, nsAString *aText = nsnull,
|
||||
nsIFrame **aEndFrame = nsnull, nsIntRect *aBoundsRect = nsnull);
|
||||
nsIFrame* GetPosAndText(PRInt32& aStartOffset, PRInt32& aEndOffset,
|
||||
nsAString *aText = nsnull,
|
||||
nsIFrame **aEndFrame = nsnull,
|
||||
nsIntRect *aBoundsRect = nsnull,
|
||||
nsIAccessible **aStartAcc = nsnull,
|
||||
nsIAccessible **aEndAcc = nsnull);
|
||||
|
||||
nsIntRect GetBoundsForString(nsIFrame *aFrame, PRUint32 aStartRenderedOffset, PRUint32 aEndRenderedOffset);
|
||||
|
||||
|
@ -360,29 +360,8 @@ CAccessibleText::scrollSubstringTo(long aStartIndex, long aEndIndex,
|
||||
{
|
||||
GET_NSIACCESSIBLETEXT
|
||||
|
||||
nsCOMPtr<nsIAccessible> accessible;
|
||||
PRInt32 startOffset = 0, endOffset = 0;
|
||||
|
||||
// XXX: aEndIndex isn't used.
|
||||
textAcc->GetAttributeRange(aStartIndex, &startOffset, &endOffset,
|
||||
getter_AddRefs(accessible));
|
||||
if (!accessible)
|
||||
return E_FAIL;
|
||||
|
||||
nsCOMPtr<nsIWinAccessNode> winAccessNode(do_QueryInterface(accessible));
|
||||
if (!winAccessNode)
|
||||
return E_FAIL;
|
||||
|
||||
void **instancePtr = 0;
|
||||
winAccessNode->QueryNativeInterface(IID_IAccessible2, instancePtr);
|
||||
if (!instancePtr)
|
||||
return E_FAIL;
|
||||
|
||||
IAccessible2 *pAccessible2 = static_cast<IAccessible2*>(*instancePtr);
|
||||
HRESULT hr = pAccessible2->scrollTo(aScrollType);
|
||||
pAccessible2->Release();
|
||||
|
||||
return hr;
|
||||
nsresult rv = textAcc->ScrollSubstringTo(aStartIndex, aEndIndex, aScrollType);
|
||||
return NS_FAILED(rv) ? E_FAIL : S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP
|
||||
|
@ -39,21 +39,15 @@
|
||||
// NOTE: alphabetically ordered
|
||||
#include "nsTextAccessibleWrap.h"
|
||||
#include "ISimpleDOMText_i.c"
|
||||
#include "nsContentCID.h"
|
||||
#include "nsIAccessibleDocument.h"
|
||||
#include "nsIDOMRange.h"
|
||||
#include "nsIFontMetrics.h"
|
||||
#include "nsIFrame.h"
|
||||
#include "nsPresContext.h"
|
||||
#include "nsIPresShell.h"
|
||||
#include "nsIRenderingContext.h"
|
||||
#include "nsISelection.h"
|
||||
#include "nsISelectionController.h"
|
||||
#include "nsIWidget.h"
|
||||
#include "nsIComponentManager.h"
|
||||
|
||||
static NS_DEFINE_IID(kRangeCID, NS_RANGE_CID);
|
||||
|
||||
// --------------------------------------------------------
|
||||
// nsTextAccessibleWrap Accessible
|
||||
// --------------------------------------------------------
|
||||
@ -162,37 +156,10 @@ STDMETHODIMP nsTextAccessibleWrap::scrollToSubstring(
|
||||
/* [in] */ unsigned int aStartIndex,
|
||||
/* [in] */ unsigned int aEndIndex)
|
||||
{
|
||||
nsCOMPtr<nsIPresShell> presShell(GetPresShell());
|
||||
nsIFrame *frame = GetFrame();
|
||||
|
||||
if (!frame || !presShell) {
|
||||
return E_FAIL; // This accessible has been shut down
|
||||
}
|
||||
|
||||
nsPresContext *presContext = presShell->GetPresContext();
|
||||
nsCOMPtr<nsIDOMRange> scrollToRange = do_CreateInstance(kRangeCID);
|
||||
nsCOMPtr<nsISelectionController> selCon;
|
||||
frame->GetSelectionController(presContext, getter_AddRefs(selCon));
|
||||
if (!presContext || !scrollToRange || !selCon) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
scrollToRange->SetStart(mDOMNode, aStartIndex);
|
||||
scrollToRange->SetEnd(mDOMNode, aEndIndex);
|
||||
nsCOMPtr<nsISelection> domSel;
|
||||
selCon->GetSelection(nsISelectionController::SELECTION_ACCESSIBILITY,
|
||||
getter_AddRefs(domSel));
|
||||
if (domSel) {
|
||||
domSel->RemoveAllRanges();
|
||||
domSel->AddRange(scrollToRange);
|
||||
|
||||
selCon->ScrollSelectionIntoView(nsISelectionController::SELECTION_ACCESSIBILITY,
|
||||
nsISelectionController::SELECTION_ANCHOR_REGION, PR_TRUE);
|
||||
|
||||
domSel->CollapseToStart();
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
nsresult rv = nsAccUtils::ScrollSubstringTo(GetFrame(), mDOMNode, aStartIndex,
|
||||
mDOMNode, aEndIndex,
|
||||
nsIAccessibleScrollType::SCROLL_TYPE_ANYWHERE);
|
||||
return NS_FAILED(rv) ? E_FAIL : S_OK;
|
||||
}
|
||||
|
||||
nsIFrame* nsTextAccessibleWrap::GetPointFromOffset(nsIFrame *aContainingFrame,
|
||||
|
@ -47,7 +47,7 @@ interface nsIDOMRange;
|
||||
|
||||
[ptr] native RangeArray(nsCOMArray<nsIDOMRange>);
|
||||
|
||||
[scriptable, uuid(eab4ae76-efdc-4e09-828c-bd921e9a662f)]
|
||||
[scriptable, uuid(b515878d-3b06-433b-bc9e-5c53d2fa3eff)]
|
||||
interface nsISelection2 : nsISelection
|
||||
{
|
||||
void GetRangesForInterval(
|
||||
@ -62,4 +62,40 @@ interface nsISelection2 : nsISelection
|
||||
in nsIDOMNode endNode, in PRInt32 endOffset,
|
||||
in PRBool allowAdjacent,
|
||||
in RangeArray results);
|
||||
|
||||
/**
|
||||
* Scrolls a region of the selection, so that it is visible in
|
||||
* the scrolled view.
|
||||
*
|
||||
* @param aRegion - the region inside the selection to scroll into view
|
||||
* (see selection region constants defined in
|
||||
* nsISelectionController).
|
||||
* @param aIsSynchronous - when true, scrolls the selection into view
|
||||
* before returning. If false, posts a request which
|
||||
* is processed at some point after the method returns.
|
||||
* @param aVPercent - how to align the frame vertically. A value of 0
|
||||
* means the frame's upper edge is aligned with the top edge
|
||||
* of the visible area. A value of 100 means the frame's
|
||||
* bottom edge is aligned with the bottom edge of
|
||||
* the visible area. For values in between, the point
|
||||
* "aVPercent" down the frame is placed at the point
|
||||
* "aVPercent" down the visible area. A value of 50 centers
|
||||
* the frame vertically. A value of -1 means move
|
||||
* the frame the minimum amount necessary in order for
|
||||
* the entire frame to be visible vertically (if possible).
|
||||
* @param aHPercent - how to align the frame horizontally. A value of 0
|
||||
* means the frame's left edge is aligned with the left
|
||||
* edge of the visible area. A value of 100 means the
|
||||
* frame's right edge is aligned with the right edge of
|
||||
* the visible area. For values in between, the point
|
||||
* "aHPercent" across the frame is placed at the point
|
||||
* "aHPercent" across the visible area. A value of 50
|
||||
* centers the frame horizontally . A value of -1 means
|
||||
* move the frame the minimum amount necessary in order
|
||||
* for the entire frame to be visible horizontally
|
||||
* (if possible).
|
||||
*/
|
||||
void scrollIntoView(in short aRegion, in boolean aIsSynchronous,
|
||||
in short aVPercent, in short aHPercent);
|
||||
};
|
||||
|
||||
|
@ -215,7 +215,9 @@ public:
|
||||
// aDoFlush only matters if aIsSynchronous is true. If not, we'll just flush
|
||||
// when the scroll event fires so we make sure to scroll to the right place.
|
||||
nsresult ScrollIntoView(SelectionRegion aRegion, PRBool aIsSynchronous,
|
||||
PRBool aDoFlush);
|
||||
PRBool aDoFlush,
|
||||
PRInt16 aVPercent = NS_PRESSHELL_SCROLL_ANYWHERE,
|
||||
PRInt16 aHPercent = NS_PRESSHELL_SCROLL_ANYWHERE);
|
||||
nsresult AddItem(nsIDOMRange *aRange);
|
||||
nsresult RemoveItem(nsIDOMRange *aRange);
|
||||
nsresult Clear(nsPresContext* aPresContext);
|
||||
@ -7298,9 +7300,18 @@ nsTypedSelection::PostScrollSelectionIntoViewEvent(SelectionRegion aRegion)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTypedSelection::ScrollIntoView(SelectionRegion aRegion, PRBool aIsSynchronous,
|
||||
PRInt16 aVPercent, PRInt16 aHPercent)
|
||||
{
|
||||
return ScrollIntoView(aRegion, aIsSynchronous, PR_FALSE,
|
||||
aVPercent, aHPercent);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTypedSelection::ScrollIntoView(SelectionRegion aRegion,
|
||||
PRBool aIsSynchronous, PRBool aDoFlush)
|
||||
PRBool aIsSynchronous, PRBool aDoFlush,
|
||||
PRInt16 aVPercent, PRInt16 aHPercent)
|
||||
{
|
||||
nsresult result;
|
||||
if (!mFrameSelection)
|
||||
@ -7358,7 +7369,8 @@ nsTypedSelection::ScrollIntoView(SelectionRegion aRegion,
|
||||
if (!scrollableView)
|
||||
return NS_OK;
|
||||
|
||||
result = ScrollRectIntoView(scrollableView, rect, NS_PRESSHELL_SCROLL_ANYWHERE, NS_PRESSHELL_SCROLL_ANYWHERE, PR_TRUE);
|
||||
result = ScrollRectIntoView(scrollableView, rect, aVPercent, aHPercent,
|
||||
PR_TRUE);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user