Bug 16203: double-click drag should do selection in "word-by-word" mode. r+sr=roc

git-svn-id: svn://10.0.0.236/trunk@201921 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
uriber%gmail.com 2006-07-12 07:07:36 +00:00
parent a008236c73
commit 8949cb7ef1
3 changed files with 36 additions and 3 deletions

View File

@ -2048,7 +2048,7 @@ nsFrame::PeekBackwardAndForward(nsSelectionAmount aAmountBack,
//no release
// maintain selection
return GetFrameSelection()->MaintainSelection();
return GetFrameSelection()->MaintainSelection(aAmountBack);
}
// Figure out which view we should point capturing at, given that drag started

View File

@ -446,8 +446,10 @@ public:
* Dragging or extending selection will never allow for a subset
* (or the whole) of the maintained selection to become unselected.
* Primary use: double click selecting then dragging on second click
* @param aAmount the initial amount of text selected (word, line or paragraph).
* For "line", use eSelectBeginLine.
*/
nsresult MaintainSelection();
nsresult MaintainSelection(nsSelectionAmount aAmount = eSelectNoAmount);
nsFrameSelection();
@ -562,6 +564,7 @@ private:
// maintain selection
nsCOMPtr<nsIDOMRange> mMaintainRange;
nsSelectionAmount mMaintainedAmount;
//batching
PRInt32 mBatching;

View File

@ -2051,7 +2051,7 @@ nsFrameSelection::GetFrameFromLevel(nsIFrame *aFrameIn,
nsresult
nsFrameSelection::MaintainSelection()
nsFrameSelection::MaintainSelection(nsSelectionAmount aAmount)
{
PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
nsCOMPtr<nsIDOMRange> range;
@ -2061,6 +2061,8 @@ nsFrameSelection::MaintainSelection()
if (!range)
return NS_ERROR_FAILURE;
mMaintainedAmount = aAmount;
nsCOMPtr<nsIDOMNode> startNode;
nsCOMPtr<nsIDOMNode> endNode;
PRInt32 startOffset;
@ -2266,6 +2268,34 @@ nsFrameSelection::HandleDrag(nsIFrame *aFrame, nsPoint aPoint)
AdjustForMaintainedSelection(offsets.content, offsets.offset))
return;
// Adjust offsets according to maintained amount
if (mMaintainRange &&
mMaintainedAmount != eSelectNoAmount) {
nsCOMPtr<nsIDOMNode> rangenode;
PRInt32 rangeOffset;
mMaintainRange->GetStartContainer(getter_AddRefs(rangenode));
mMaintainRange->GetStartOffset(&rangeOffset);
nsCOMPtr<nsIDOMNode> domNode = do_QueryInterface(offsets.content);
PRInt32 relativePosition = nsRange::ComparePoints(rangenode, rangeOffset,
domNode, offsets.offset);
nsDirection direction = relativePosition > 0 ? eDirPrevious : eDirNext;
nsSelectionAmount amount = mMaintainedAmount;
if (amount == eSelectBeginLine && direction == eDirNext)
amount = eSelectEndLine;
nsPeekOffsetStruct pos;
pos.SetData(mShell, 0, amount, direction, offsets.offset, PR_FALSE,
PR_TRUE, PR_FALSE, mLimiter != nsnull, PR_TRUE, PR_FALSE);
nsIFrame* frame = mShell->GetPrimaryFrameFor(offsets.content);
if (NS_SUCCEEDED(result = frame->PeekOffset(mShell->GetPresContext(), &pos)) && pos.mResultContent) {
offsets.content = pos.mResultContent;
offsets.offset = pos.mContentOffset;
}
}
// XXX Code not up to date
#ifdef VISUALSELECTION
if (mShell->GetPresContext()->BidiEnabled()) {