2008-02-19 23:40:04 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 sw=2 et tw=80: */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Mozilla Japan.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2008
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Masayuki Nakano <masayuki@d-toybox.com>
|
2009-02-10 12:56:51 -08:00
|
|
|
* Ningjie Chen <chenn@email.uc.edu>
|
2008-02-19 23:40:04 -08:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
#include "nsContentEventHandler.h"
|
2008-02-19 23:40:04 -08:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsISelection.h"
|
|
|
|
#include "nsIDOMRange.h"
|
|
|
|
#include "nsRange.h"
|
|
|
|
#include "nsGUIEvent.h"
|
2008-07-16 03:52:01 -07:00
|
|
|
#include "nsCaret.h"
|
2009-03-17 19:04:01 -07:00
|
|
|
#include "nsCopySupport.h"
|
2008-02-19 23:40:04 -08:00
|
|
|
#include "nsFrameSelection.h"
|
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsIView.h"
|
|
|
|
#include "nsIContentIterator.h"
|
|
|
|
#include "nsTextFragment.h"
|
|
|
|
#include "nsTextFrame.h"
|
2009-02-10 12:56:51 -08:00
|
|
|
#include "nsISelectionController.h"
|
|
|
|
#include "nsISelectionPrivate.h"
|
|
|
|
#include "nsContentUtils.h"
|
2009-05-14 17:46:24 -07:00
|
|
|
#include "nsLayoutUtils.h"
|
2009-02-10 12:56:51 -08:00
|
|
|
#include "nsIMEStateManager.h"
|
2011-03-01 13:15:23 -08:00
|
|
|
#include "nsIObjectFrame.h"
|
2008-02-19 23:40:04 -08:00
|
|
|
|
|
|
|
nsresult NS_NewContentIterator(nsIContentIterator** aInstancePtrResult);
|
|
|
|
|
|
|
|
/******************************************************************/
|
2009-02-10 12:56:51 -08:00
|
|
|
/* nsContentEventHandler */
|
2008-02-19 23:40:04 -08:00
|
|
|
/******************************************************************/
|
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
nsContentEventHandler::nsContentEventHandler(
|
2008-02-19 23:40:04 -08:00
|
|
|
nsPresContext* aPresContext) :
|
|
|
|
mPresContext(aPresContext),
|
|
|
|
mPresShell(aPresContext->GetPresShell()), mSelection(nsnull),
|
|
|
|
mFirstSelectedRange(nsnull), mRootContent(nsnull)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2010-03-18 22:02:53 -07:00
|
|
|
nsContentEventHandler::InitCommon()
|
2008-02-19 23:40:04 -08:00
|
|
|
{
|
|
|
|
if (mSelection)
|
|
|
|
return NS_OK;
|
|
|
|
|
2010-03-18 22:02:53 -07:00
|
|
|
NS_ENSURE_TRUE(mPresShell, NS_ERROR_NOT_AVAILABLE);
|
2008-02-19 23:40:04 -08:00
|
|
|
|
2009-04-03 00:26:28 -07:00
|
|
|
// If text frame which has overflowing selection underline is dirty,
|
|
|
|
// we need to flush the pending reflow here.
|
2010-03-20 14:54:19 -07:00
|
|
|
mPresShell->FlushPendingNotifications(Flush_Layout);
|
2009-04-03 00:26:28 -07:00
|
|
|
|
2010-08-05 07:42:02 -07:00
|
|
|
// Flushing notifications can cause mPresShell to be destroyed (bug 577963).
|
|
|
|
NS_ENSURE_TRUE(!mPresShell->IsDestroying(), NS_ERROR_FAILURE);
|
|
|
|
|
2010-03-19 11:32:13 -07:00
|
|
|
nsCopySupport::GetSelectionForCopy(mPresShell->GetDocument(),
|
|
|
|
getter_AddRefs(mSelection));
|
2009-03-17 19:04:01 -07:00
|
|
|
|
2008-02-19 23:40:04 -08:00
|
|
|
nsCOMPtr<nsIDOMRange> firstRange;
|
2010-03-20 14:54:19 -07:00
|
|
|
nsresult rv = mSelection->GetRangeAt(0, getter_AddRefs(firstRange));
|
2008-02-19 23:40:04 -08:00
|
|
|
// This shell doesn't support selection.
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
mFirstSelectedRange = do_QueryInterface(firstRange);
|
|
|
|
NS_ENSURE_TRUE(mFirstSelectedRange, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsINode* startNode = mFirstSelectedRange->GetStartParent();
|
|
|
|
NS_ENSURE_TRUE(startNode, NS_ERROR_FAILURE);
|
2010-01-05 21:55:54 -08:00
|
|
|
nsINode* endNode = mFirstSelectedRange->GetEndParent();
|
|
|
|
NS_ENSURE_TRUE(endNode, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
// See bug 537041 comment 5, the range could have removed node.
|
|
|
|
NS_ENSURE_TRUE(startNode->GetCurrentDoc() == mPresShell->GetDocument(),
|
|
|
|
NS_ERROR_NOT_AVAILABLE);
|
|
|
|
NS_ASSERTION(startNode->GetCurrentDoc() == endNode->GetCurrentDoc(),
|
|
|
|
"mFirstSelectedRange crosses the document boundary");
|
|
|
|
|
2008-02-19 23:40:04 -08:00
|
|
|
mRootContent = startNode->GetSelectionRootContent(mPresShell);
|
|
|
|
NS_ENSURE_TRUE(mRootContent, NS_ERROR_FAILURE);
|
2010-03-18 22:02:53 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsContentEventHandler::Init(nsQueryContentEvent* aEvent)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aEvent, "aEvent must not be null");
|
|
|
|
|
|
|
|
nsresult rv = InitCommon();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
aEvent->mSucceeded = PR_FALSE;
|
2008-02-19 23:40:04 -08:00
|
|
|
|
|
|
|
aEvent->mReply.mContentsRoot = mRootContent.get();
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isCollapsed;
|
2010-03-18 22:02:53 -07:00
|
|
|
rv = mSelection->GetIsCollapsed(&isCollapsed);
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_NOT_AVAILABLE);
|
|
|
|
aEvent->mReply.mHasSelection = !isCollapsed;
|
|
|
|
|
2010-03-31 05:39:31 -07:00
|
|
|
nsRefPtr<nsCaret> caret = mPresShell->GetCaret();
|
|
|
|
NS_ASSERTION(caret, "GetCaret returned null");
|
2010-03-14 15:52:07 -07:00
|
|
|
|
2008-08-11 01:27:59 -07:00
|
|
|
nsRect r;
|
2010-03-14 15:52:07 -07:00
|
|
|
nsIFrame* frame = caret->GetGeometry(mSelection, &r);
|
|
|
|
NS_ENSURE_TRUE(frame, NS_ERROR_FAILURE);
|
|
|
|
|
2010-07-02 12:11:04 -07:00
|
|
|
aEvent->mReply.mFocusedWidget = frame->GetNearestWidget();
|
2008-08-11 01:27:59 -07:00
|
|
|
|
2008-02-19 23:40:04 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-03-18 22:02:53 -07:00
|
|
|
nsresult
|
|
|
|
nsContentEventHandler::Init(nsSelectionEvent* aEvent)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aEvent, "aEvent must not be null");
|
|
|
|
|
|
|
|
nsresult rv = InitCommon();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
aEvent->mSucceeded = PR_FALSE;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
// Editor places a bogus BR node under its root content if the editor doesn't
|
|
|
|
// have any text. This happens even for single line editors.
|
|
|
|
// When we get text content and when we change the selection,
|
|
|
|
// we don't want to include the bogus BRs at the end.
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool IsContentBR(nsIContent* aContent)
|
2009-02-10 12:56:51 -08:00
|
|
|
{
|
2009-08-24 13:02:07 -07:00
|
|
|
return aContent->IsHTML() &&
|
2009-02-10 12:56:51 -08:00
|
|
|
aContent->Tag() == nsGkAtoms::br &&
|
|
|
|
!aContent->AttrValueIs(kNameSpaceID_None,
|
|
|
|
nsGkAtoms::type,
|
|
|
|
nsGkAtoms::moz,
|
|
|
|
eIgnoreCase) &&
|
|
|
|
!aContent->AttrValueIs(kNameSpaceID_None,
|
|
|
|
nsGkAtoms::mozeditorbogusnode,
|
|
|
|
nsGkAtoms::_true,
|
|
|
|
eIgnoreCase);
|
|
|
|
}
|
|
|
|
|
2008-02-19 23:40:04 -08:00
|
|
|
static void ConvertToNativeNewlines(nsAFlatString& aString)
|
|
|
|
{
|
|
|
|
#if defined(XP_MACOSX)
|
|
|
|
aString.ReplaceSubstring(NS_LITERAL_STRING("\n"), NS_LITERAL_STRING("\r"));
|
|
|
|
#elif defined(XP_WIN)
|
|
|
|
aString.ReplaceSubstring(NS_LITERAL_STRING("\n"), NS_LITERAL_STRING("\r\n"));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static void AppendString(nsAString& aString, nsIContent* aContent)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aContent->IsNodeOfType(nsINode::eTEXT),
|
|
|
|
"aContent is not a text node!");
|
|
|
|
const nsTextFragment* text = aContent->GetText();
|
|
|
|
if (!text)
|
|
|
|
return;
|
|
|
|
text->AppendTo(aString);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void AppendSubString(nsAString& aString, nsIContent* aContent,
|
|
|
|
PRUint32 aXPOffset, PRUint32 aXPLength)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aContent->IsNodeOfType(nsINode::eTEXT),
|
|
|
|
"aContent is not a text node!");
|
|
|
|
const nsTextFragment* text = aContent->GetText();
|
|
|
|
if (!text)
|
|
|
|
return;
|
|
|
|
text->AppendTo(aString, PRInt32(aXPOffset), PRInt32(aXPLength));
|
|
|
|
}
|
|
|
|
|
2011-06-27 05:58:43 -07:00
|
|
|
#if defined(XP_WIN)
|
|
|
|
static PRUint32 CountNewlinesIn(nsIContent* aContent, PRUint32 aMaxOffset)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aContent->IsNodeOfType(nsINode::eTEXT),
|
|
|
|
"aContent is not a text node!");
|
|
|
|
const nsTextFragment* text = aContent->GetText();
|
|
|
|
if (!text)
|
|
|
|
return 0;
|
|
|
|
if (aMaxOffset == PR_UINT32_MAX) {
|
|
|
|
// search the entire string
|
|
|
|
aMaxOffset = text->GetLength();
|
|
|
|
}
|
|
|
|
PRUint32 newlines = 0;
|
|
|
|
for (PRUint32 i = 0; i < aMaxOffset; ++i) {
|
|
|
|
if (text->CharAt(i) == '\n') {
|
|
|
|
++newlines;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return newlines;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-06-27 05:59:01 -07:00
|
|
|
static PRUint32 GetNativeTextLength(nsIContent* aContent, PRUint32 aMaxLength = PR_UINT32_MAX)
|
2008-02-19 23:40:04 -08:00
|
|
|
{
|
2011-06-27 05:58:43 -07:00
|
|
|
if (aContent->IsNodeOfType(nsINode::eTEXT)) {
|
|
|
|
PRUint32 textLengthDifference =
|
|
|
|
#if defined(XP_MACOSX)
|
|
|
|
// On Mac, the length of a native newline ("\r") is equal to the length of
|
|
|
|
// the XP newline ("\n"), so the native length is the same as the XP length.
|
|
|
|
0;
|
|
|
|
#elif defined(XP_WIN)
|
|
|
|
// On Windows, the length of a native newline ("\r\n") is twice the length of
|
|
|
|
// the XP newline ("\n"), so XP length is equal to the length of the native
|
|
|
|
// offset plus the number of newlines encountered in the string.
|
2011-06-27 05:59:01 -07:00
|
|
|
CountNewlinesIn(aContent, aMaxLength);
|
2011-06-27 05:58:43 -07:00
|
|
|
#else
|
|
|
|
// On other platforms, the native and XP newlines are the same.
|
|
|
|
0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
const nsTextFragment* text = aContent->GetText();
|
|
|
|
if (!text)
|
|
|
|
return 0;
|
2011-06-27 05:59:01 -07:00
|
|
|
PRUint32 length = NS_MIN(text->GetLength(), aMaxLength);
|
|
|
|
return length + textLengthDifference;
|
2011-06-27 05:58:43 -07:00
|
|
|
} else if (IsContentBR(aContent)) {
|
|
|
|
#if defined(XP_WIN)
|
|
|
|
// Length of \r\n
|
|
|
|
return 2;
|
|
|
|
#else
|
|
|
|
return 1;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
return 0;
|
2008-02-19 23:40:04 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static PRUint32 ConvertToXPOffset(nsIContent* aContent, PRUint32 aNativeOffset)
|
|
|
|
{
|
2011-06-27 05:58:43 -07:00
|
|
|
#if defined(XP_MACOSX)
|
|
|
|
// On Mac, the length of a native newline ("\r") is equal to the length of
|
|
|
|
// the XP newline ("\n"), so the native offset is the same as the XP offset.
|
|
|
|
return aNativeOffset;
|
|
|
|
#elif defined(XP_WIN)
|
|
|
|
// On Windows, the length of a native newline ("\r\n") is twice the length of
|
|
|
|
// the XP newline ("\n"), so XP offset is equal to the length of the native
|
|
|
|
// offset minus the number of newlines encountered in the string.
|
|
|
|
return aNativeOffset - CountNewlinesIn(aContent, aNativeOffset);
|
|
|
|
#else
|
|
|
|
// On other platforms, the native and XP newlines are the same.
|
|
|
|
return aNativeOffset;
|
|
|
|
#endif
|
2008-02-19 23:40:04 -08:00
|
|
|
}
|
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
static nsresult GenerateFlatTextContent(nsIRange* aRange,
|
|
|
|
nsAFlatString& aString)
|
2008-02-19 23:40:04 -08:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContentIterator> iter;
|
|
|
|
nsresult rv = NS_NewContentIterator(getter_AddRefs(iter));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
NS_ASSERTION(iter, "NS_NewContentIterator succeeded, but the result is null");
|
|
|
|
nsCOMPtr<nsIDOMRange> domRange(do_QueryInterface(aRange));
|
|
|
|
NS_ASSERTION(domRange, "aRange doesn't have nsIDOMRange!");
|
|
|
|
iter->Init(domRange);
|
|
|
|
|
|
|
|
NS_ASSERTION(aString.IsEmpty(), "aString must be empty string");
|
|
|
|
|
|
|
|
nsINode* startNode = aRange->GetStartParent();
|
2009-11-26 00:41:32 -08:00
|
|
|
NS_ENSURE_TRUE(startNode, NS_ERROR_FAILURE);
|
2008-02-19 23:40:04 -08:00
|
|
|
nsINode* endNode = aRange->GetEndParent();
|
2009-11-26 00:41:32 -08:00
|
|
|
NS_ENSURE_TRUE(endNode, NS_ERROR_FAILURE);
|
2008-02-19 23:40:04 -08:00
|
|
|
|
|
|
|
if (startNode == endNode && startNode->IsNodeOfType(nsINode::eTEXT)) {
|
|
|
|
nsIContent* content = static_cast<nsIContent*>(startNode);
|
|
|
|
AppendSubString(aString, content, aRange->StartOffset(),
|
|
|
|
aRange->EndOffset() - aRange->StartOffset());
|
|
|
|
ConvertToNativeNewlines(aString);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString tmpStr;
|
|
|
|
for (; !iter->IsDone(); iter->Next()) {
|
2008-10-15 02:40:28 -07:00
|
|
|
nsINode* node = iter->GetCurrentNode();
|
|
|
|
if (!node || !node->IsNodeOfType(nsINode::eCONTENT))
|
2008-02-19 23:40:04 -08:00
|
|
|
continue;
|
2008-10-15 02:40:28 -07:00
|
|
|
nsIContent* content = static_cast<nsIContent*>(node);
|
2008-02-19 23:40:04 -08:00
|
|
|
|
|
|
|
if (content->IsNodeOfType(nsINode::eTEXT)) {
|
|
|
|
if (content == startNode)
|
|
|
|
AppendSubString(aString, content, aRange->StartOffset(),
|
|
|
|
content->TextLength() - aRange->StartOffset());
|
|
|
|
else if (content == endNode)
|
|
|
|
AppendSubString(aString, content, 0, aRange->EndOffset());
|
|
|
|
else
|
|
|
|
AppendString(aString, content);
|
2009-02-10 12:56:51 -08:00
|
|
|
} else if (IsContentBR(content))
|
2008-02-19 23:40:04 -08:00
|
|
|
aString.Append(PRUnichar('\n'));
|
|
|
|
}
|
|
|
|
ConvertToNativeNewlines(aString);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2009-02-10 12:56:51 -08:00
|
|
|
nsContentEventHandler::ExpandToClusterBoundary(nsIContent* aContent,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aForward,
|
2008-02-19 23:40:04 -08:00
|
|
|
PRUint32* aXPOffset)
|
|
|
|
{
|
|
|
|
// XXX This method assumes that the frame boundaries must be cluster
|
|
|
|
// boundaries. It's false, but no problem now, maybe.
|
|
|
|
if (!aContent->IsNodeOfType(nsINode::eTEXT) ||
|
|
|
|
*aXPOffset == 0 || *aXPOffset == aContent->TextLength())
|
|
|
|
return NS_OK;
|
2009-02-10 12:56:51 -08:00
|
|
|
|
|
|
|
NS_ASSERTION(*aXPOffset >= 0 && *aXPOffset <= aContent->TextLength(),
|
|
|
|
"offset is out of range.");
|
|
|
|
|
2011-05-18 20:10:49 -07:00
|
|
|
nsRefPtr<nsFrameSelection> fs = mPresShell->FrameSelection();
|
2008-02-19 23:40:04 -08:00
|
|
|
PRInt32 offsetInFrame;
|
|
|
|
nsFrameSelection::HINT hint =
|
|
|
|
aForward ? nsFrameSelection::HINTLEFT : nsFrameSelection::HINTRIGHT;
|
|
|
|
nsIFrame* frame = fs->GetFrameForNodeOffset(aContent, PRInt32(*aXPOffset),
|
|
|
|
hint, &offsetInFrame);
|
|
|
|
if (!frame) {
|
|
|
|
// This content doesn't have any frames, we only can check surrogate pair...
|
|
|
|
const nsTextFragment* text = aContent->GetText();
|
|
|
|
NS_ENSURE_TRUE(text, NS_ERROR_FAILURE);
|
|
|
|
if (NS_IS_LOW_SURROGATE(text->CharAt(*aXPOffset)) &&
|
|
|
|
NS_IS_HIGH_SURROGATE(text->CharAt(*aXPOffset - 1)))
|
|
|
|
*aXPOffset += aForward ? 1 : -1;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
PRInt32 startOffset, endOffset;
|
|
|
|
nsresult rv = frame->GetOffsets(startOffset, endOffset);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (*aXPOffset == PRUint32(startOffset) || *aXPOffset == PRUint32(endOffset))
|
|
|
|
return NS_OK;
|
|
|
|
if (frame->GetType() != nsGkAtoms::textFrame)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
nsTextFrame* textFrame = static_cast<nsTextFrame*>(frame);
|
2009-02-10 12:56:51 -08:00
|
|
|
PRInt32 newOffsetInFrame = *aXPOffset - startOffset;
|
2008-02-19 23:40:04 -08:00
|
|
|
newOffsetInFrame += aForward ? -1 : 1;
|
|
|
|
textFrame->PeekOffsetCharacter(aForward, &newOffsetInFrame);
|
|
|
|
*aXPOffset = startOffset + newOffsetInFrame;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2009-02-10 12:56:51 -08:00
|
|
|
nsContentEventHandler::SetRangeFromFlatTextOffset(
|
2008-02-19 23:40:04 -08:00
|
|
|
nsIRange* aRange,
|
|
|
|
PRUint32 aNativeOffset,
|
|
|
|
PRUint32 aNativeLength,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aExpandToClusterBoundaries)
|
2008-02-19 23:40:04 -08:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContentIterator> iter;
|
|
|
|
nsresult rv = NS_NewContentIterator(getter_AddRefs(iter));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
NS_ASSERTION(iter, "NS_NewContentIterator succeeded, but the result is null");
|
|
|
|
rv = iter->Init(mRootContent);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
nsCOMPtr<nsIDOMRange> domRange(do_QueryInterface(aRange));
|
|
|
|
NS_ASSERTION(domRange, "aRange doesn't have nsIDOMRange!");
|
|
|
|
|
|
|
|
PRUint32 nativeOffset = 0;
|
|
|
|
PRUint32 nativeEndOffset = aNativeOffset + aNativeLength;
|
2008-10-15 02:40:28 -07:00
|
|
|
nsCOMPtr<nsIContent> content;
|
2008-02-19 23:40:04 -08:00
|
|
|
for (; !iter->IsDone(); iter->Next()) {
|
2008-10-15 02:40:28 -07:00
|
|
|
nsINode* node = iter->GetCurrentNode();
|
|
|
|
if (!node || !node->IsNodeOfType(nsINode::eCONTENT))
|
2008-02-19 23:40:04 -08:00
|
|
|
continue;
|
2008-10-15 02:40:28 -07:00
|
|
|
nsIContent* content = static_cast<nsIContent*>(node);
|
2008-02-19 23:40:04 -08:00
|
|
|
|
|
|
|
PRUint32 nativeTextLength;
|
|
|
|
nativeTextLength = GetNativeTextLength(content);
|
|
|
|
if (nativeTextLength == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (nativeOffset <= aNativeOffset &&
|
|
|
|
aNativeOffset < nativeOffset + nativeTextLength) {
|
|
|
|
nsCOMPtr<nsIDOMNode> domNode(do_QueryInterface(content));
|
|
|
|
NS_ASSERTION(domNode, "aContent doesn't have nsIDOMNode!");
|
|
|
|
|
|
|
|
PRUint32 xpOffset =
|
|
|
|
content->IsNodeOfType(nsINode::eTEXT) ?
|
|
|
|
ConvertToXPOffset(content, aNativeOffset - nativeOffset) : 0;
|
|
|
|
|
|
|
|
if (aExpandToClusterBoundaries) {
|
|
|
|
rv = ExpandToClusterBoundary(content, PR_FALSE, &xpOffset);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = domRange->SetStart(domNode, PRInt32(xpOffset));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (aNativeLength == 0) {
|
|
|
|
// Ensure that the end offset and the start offset are same.
|
|
|
|
rv = domRange->SetEnd(domNode, PRInt32(xpOffset));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (nativeEndOffset <= nativeOffset + nativeTextLength) {
|
|
|
|
nsCOMPtr<nsIDOMNode> domNode(do_QueryInterface(content));
|
|
|
|
NS_ASSERTION(domNode, "aContent doesn't have nsIDOMNode!");
|
|
|
|
|
|
|
|
PRUint32 xpOffset;
|
|
|
|
if (content->IsNodeOfType(nsINode::eTEXT)) {
|
|
|
|
xpOffset = ConvertToXPOffset(content, nativeEndOffset - nativeOffset);
|
|
|
|
if (aExpandToClusterBoundaries) {
|
|
|
|
rv = ExpandToClusterBoundary(content, PR_TRUE, &xpOffset);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Use first position of next node, because the end node is ignored
|
|
|
|
// by ContentIterator when the offset is zero.
|
|
|
|
xpOffset = 0;
|
|
|
|
iter->Next();
|
|
|
|
if (iter->IsDone())
|
|
|
|
break;
|
|
|
|
domNode = do_QueryInterface(iter->GetCurrentNode());
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = domRange->SetEnd(domNode, PRInt32(xpOffset));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nativeOffset += nativeTextLength;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nativeOffset < aNativeOffset)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> domNode(do_QueryInterface(mRootContent));
|
|
|
|
NS_ASSERTION(domNode, "lastContent doesn't have nsIDOMNode!");
|
|
|
|
if (!content) {
|
|
|
|
rv = domRange->SetStart(domNode, 0);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
rv = domRange->SetEnd(domNode, PRInt32(mRootContent->GetChildCount()));
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "nsIDOMRange::SetEnd failed");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2009-02-10 12:56:51 -08:00
|
|
|
nsContentEventHandler::OnQuerySelectedText(nsQueryContentEvent* aEvent)
|
2008-02-19 23:40:04 -08:00
|
|
|
{
|
|
|
|
nsresult rv = Init(aEvent);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
NS_ASSERTION(aEvent->mReply.mString.IsEmpty(),
|
|
|
|
"The reply string must be empty");
|
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
rv = GetFlatTextOffsetOfRange(mRootContent,
|
|
|
|
mFirstSelectedRange, &aEvent->mReply.mOffset);
|
2008-02-19 23:40:04 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
nsCOMPtr<nsIDOMNode> anchorDomNode, focusDomNode;
|
|
|
|
rv = mSelection->GetAnchorNode(getter_AddRefs(anchorDomNode));
|
|
|
|
NS_ENSURE_TRUE(anchorDomNode, NS_ERROR_FAILURE);
|
|
|
|
rv = mSelection->GetFocusNode(getter_AddRefs(focusDomNode));
|
|
|
|
NS_ENSURE_TRUE(focusDomNode, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
PRInt32 anchorOffset, focusOffset;
|
|
|
|
rv = mSelection->GetAnchorOffset(&anchorOffset);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = mSelection->GetFocusOffset(&focusOffset);
|
2008-02-19 23:40:04 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
nsCOMPtr<nsINode> anchorNode(do_QueryInterface(anchorDomNode));
|
|
|
|
nsCOMPtr<nsINode> focusNode(do_QueryInterface(focusDomNode));
|
|
|
|
NS_ENSURE_TRUE(anchorNode && focusNode, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
PRInt16 compare = nsContentUtils::ComparePoints(anchorNode, anchorOffset,
|
|
|
|
focusNode, focusOffset);
|
|
|
|
aEvent->mReply.mReversed = compare > 0;
|
2008-02-19 23:40:04 -08:00
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
if (compare) {
|
|
|
|
nsCOMPtr<nsIRange> range = mFirstSelectedRange;
|
2008-02-19 23:40:04 -08:00
|
|
|
rv = GenerateFlatTextContent(range, aEvent->mReply.mString);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
aEvent->mSucceeded = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2009-02-10 12:56:51 -08:00
|
|
|
nsContentEventHandler::OnQueryTextContent(nsQueryContentEvent* aEvent)
|
2008-02-19 23:40:04 -08:00
|
|
|
{
|
|
|
|
nsresult rv = Init(aEvent);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
NS_ASSERTION(aEvent->mReply.mString.IsEmpty(),
|
|
|
|
"The reply string must be empty");
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRange> range = new nsRange();
|
|
|
|
NS_ENSURE_TRUE(range, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
rv = SetRangeFromFlatTextOffset(range, aEvent->mInput.mOffset,
|
|
|
|
aEvent->mInput.mLength, PR_FALSE);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = GenerateFlatTextContent(range, aEvent->mReply.mString);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
aEvent->mSucceeded = PR_TRUE;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
// Adjust to use a child node if possible
|
|
|
|
// to make the returned rect more accurate
|
|
|
|
static nsINode* AdjustTextRectNode(nsINode* aNode,
|
|
|
|
PRInt32& aOffset)
|
|
|
|
{
|
|
|
|
PRInt32 childCount = PRInt32(aNode->GetChildCount());
|
|
|
|
nsINode* node = aNode;
|
|
|
|
if (childCount) {
|
|
|
|
if (aOffset < childCount) {
|
|
|
|
node = aNode->GetChildAt(aOffset);
|
|
|
|
aOffset = 0;
|
|
|
|
} else if (aOffset == childCount) {
|
|
|
|
node = aNode->GetChildAt(childCount - 1);
|
|
|
|
aOffset = node->IsNodeOfType(nsINode::eTEXT) ?
|
|
|
|
static_cast<nsIContent*>(node)->TextLength() : 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Similar to nsFrameSelection::GetFrameForNodeOffset,
|
|
|
|
// but this is more flexible for OnQueryTextRect to use
|
2009-12-24 13:20:05 -08:00
|
|
|
static nsresult GetFrameForTextRect(nsINode* aNode,
|
2009-02-10 12:56:51 -08:00
|
|
|
PRInt32 aOffset,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aHint,
|
2009-02-10 12:56:51 -08:00
|
|
|
nsIFrame** aReturnFrame)
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(aNode && aNode->IsNodeOfType(nsINode::eCONTENT),
|
|
|
|
NS_ERROR_UNEXPECTED);
|
|
|
|
nsIContent* content = static_cast<nsIContent*>(aNode);
|
2009-12-24 13:20:05 -08:00
|
|
|
nsIFrame* frame = content->GetPrimaryFrame();
|
2009-02-10 12:56:51 -08:00
|
|
|
NS_ENSURE_TRUE(frame, NS_ERROR_FAILURE);
|
|
|
|
PRInt32 childOffset = 0;
|
|
|
|
return frame->GetChildFrameContainingOffset(aOffset, aHint, &childOffset,
|
|
|
|
aReturnFrame);
|
|
|
|
}
|
|
|
|
|
2008-02-19 23:40:04 -08:00
|
|
|
nsresult
|
2009-02-10 12:56:51 -08:00
|
|
|
nsContentEventHandler::OnQueryTextRect(nsQueryContentEvent* aEvent)
|
2008-02-19 23:40:04 -08:00
|
|
|
{
|
2009-02-10 12:56:51 -08:00
|
|
|
nsresult rv = Init(aEvent);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2009-04-06 10:17:37 -07:00
|
|
|
nsCOMPtr<nsIRange> range = new nsRange();
|
2009-02-10 12:56:51 -08:00
|
|
|
if (!range) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
rv = SetRangeFromFlatTextOffset(range, aEvent->mInput.mOffset,
|
|
|
|
aEvent->mInput.mLength, PR_TRUE);
|
2009-02-07 01:52:59 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
// used to iterate over all contents and their frames
|
|
|
|
nsCOMPtr<nsIContentIterator> iter;
|
|
|
|
rv = NS_NewContentIterator(getter_AddRefs(iter));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
iter->Init(range);
|
2009-02-10 03:15:36 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
// get the starting frame
|
|
|
|
PRInt32 offset = range->StartOffset();
|
|
|
|
nsINode* node = iter->GetCurrentNode();
|
|
|
|
if (!node) {
|
|
|
|
node = AdjustTextRectNode(range->GetStartParent(), offset);
|
|
|
|
}
|
|
|
|
nsIFrame* firstFrame = nsnull;
|
2009-12-24 13:20:05 -08:00
|
|
|
rv = GetFrameForTextRect(node, offset, PR_TRUE, &firstFrame);
|
2009-02-10 12:56:51 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// get the starting frame rect
|
|
|
|
nsRect rect(nsPoint(0, 0), firstFrame->GetRect().Size());
|
|
|
|
rv = ConvertToRootViewRelativeOffset(firstFrame, rect);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
nsRect frameRect = rect;
|
|
|
|
nsPoint ptOffset;
|
|
|
|
firstFrame->GetPointFromOffset(offset, &ptOffset);
|
|
|
|
// minus 1 to avoid creating an empty rect
|
|
|
|
rect.x += ptOffset.x - 1;
|
|
|
|
rect.width -= ptOffset.x - 1;
|
|
|
|
|
|
|
|
// get the ending frame
|
|
|
|
offset = range->EndOffset();
|
|
|
|
node = AdjustTextRectNode(range->GetEndParent(), offset);
|
|
|
|
nsIFrame* lastFrame = nsnull;
|
2009-12-24 13:20:05 -08:00
|
|
|
rv = GetFrameForTextRect(node, offset, range->Collapsed(), &lastFrame);
|
2009-02-10 12:56:51 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-02-19 23:40:04 -08:00
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
// iterate over all covered frames
|
|
|
|
for (nsIFrame* frame = firstFrame; frame != lastFrame;) {
|
|
|
|
frame = frame->GetNextContinuation();
|
|
|
|
if (!frame) {
|
|
|
|
do {
|
|
|
|
iter->Next();
|
|
|
|
node = iter->GetCurrentNode();
|
|
|
|
if (!node || !node->IsNodeOfType(nsINode::eCONTENT))
|
|
|
|
continue;
|
2009-12-24 13:20:05 -08:00
|
|
|
frame = static_cast<nsIContent*>(node)->GetPrimaryFrame();
|
2009-02-10 12:56:51 -08:00
|
|
|
} while (!frame && !iter->IsDone());
|
|
|
|
if (!frame) {
|
|
|
|
// this can happen when the end offset of the range is 0.
|
|
|
|
frame = lastFrame;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
frameRect.SetRect(nsPoint(0, 0), frame->GetRect().Size());
|
|
|
|
rv = ConvertToRootViewRelativeOffset(frame, frameRect);
|
2008-02-19 23:40:04 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-02-10 12:56:51 -08:00
|
|
|
if (frame != lastFrame) {
|
|
|
|
// not last frame, so just add rect to previous result
|
|
|
|
rect.UnionRect(rect, frameRect);
|
|
|
|
}
|
2008-02-19 23:40:04 -08:00
|
|
|
}
|
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
// get the ending frame rect
|
|
|
|
lastFrame->GetPointFromOffset(offset, &ptOffset);
|
|
|
|
// minus 1 to avoid creating an empty rect
|
|
|
|
frameRect.width -= lastFrame->GetRect().width - ptOffset.x - 1;
|
2008-02-19 23:40:04 -08:00
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
if (firstFrame == lastFrame) {
|
|
|
|
rect.IntersectRect(rect, frameRect);
|
|
|
|
} else {
|
|
|
|
rect.UnionRect(rect, frameRect);
|
|
|
|
}
|
|
|
|
aEvent->mReply.mRect =
|
2009-05-07 19:31:04 -07:00
|
|
|
rect.ToOutsidePixels(mPresContext->AppUnitsPerDevPixel());
|
2008-02-19 23:40:04 -08:00
|
|
|
aEvent->mSucceeded = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2009-02-10 12:56:51 -08:00
|
|
|
nsContentEventHandler::OnQueryEditorRect(nsQueryContentEvent* aEvent)
|
2008-02-19 23:40:04 -08:00
|
|
|
{
|
|
|
|
nsresult rv = Init(aEvent);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2009-12-24 13:20:05 -08:00
|
|
|
nsIFrame* frame = mRootContent->GetPrimaryFrame();
|
2009-02-10 12:56:51 -08:00
|
|
|
NS_ENSURE_TRUE(frame, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
// get rect for first frame
|
|
|
|
nsRect resultRect(nsPoint(0, 0), frame->GetRect().Size());
|
|
|
|
rv = ConvertToRootViewRelativeOffset(frame, resultRect);
|
2008-02-19 23:40:04 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
// account for any additional frames
|
|
|
|
while ((frame = frame->GetNextContinuation()) != nsnull) {
|
|
|
|
nsRect frameRect(nsPoint(0, 0), frame->GetRect().Size());
|
|
|
|
rv = ConvertToRootViewRelativeOffset(frame, frameRect);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
resultRect.UnionRect(resultRect, frameRect);
|
2008-02-19 23:40:04 -08:00
|
|
|
}
|
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
aEvent->mReply.mRect =
|
2009-05-07 19:31:04 -07:00
|
|
|
resultRect.ToOutsidePixels(mPresContext->AppUnitsPerDevPixel());
|
2009-02-10 12:56:51 -08:00
|
|
|
aEvent->mSucceeded = PR_TRUE;
|
|
|
|
return NS_OK;
|
2008-02-19 23:40:04 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2009-02-10 12:56:51 -08:00
|
|
|
nsContentEventHandler::OnQueryCaretRect(nsQueryContentEvent* aEvent)
|
2008-02-19 23:40:04 -08:00
|
|
|
{
|
|
|
|
nsresult rv = Init(aEvent);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2010-03-31 05:39:31 -07:00
|
|
|
nsRefPtr<nsCaret> caret = mPresShell->GetCaret();
|
|
|
|
NS_ASSERTION(caret, "GetCaret returned null");
|
2008-02-19 23:40:04 -08:00
|
|
|
|
|
|
|
// When the selection is collapsed and the queried offset is current caret
|
|
|
|
// position, we should return the "real" caret rect.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool selectionIsCollapsed;
|
2008-02-19 23:40:04 -08:00
|
|
|
rv = mSelection->GetIsCollapsed(&selectionIsCollapsed);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (selectionIsCollapsed) {
|
|
|
|
PRUint32 offset;
|
2009-02-10 12:56:51 -08:00
|
|
|
rv = GetFlatTextOffsetOfRange(mRootContent, mFirstSelectedRange, &offset);
|
2008-02-19 23:40:04 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (offset == aEvent->mInput.mOffset) {
|
2009-01-14 19:27:09 -08:00
|
|
|
nsRect rect;
|
2010-03-14 15:52:07 -07:00
|
|
|
nsIFrame* caretFrame = caret->GetGeometry(mSelection, &rect);
|
|
|
|
if (!caretFrame)
|
|
|
|
return NS_ERROR_FAILURE;
|
2010-03-18 22:02:53 -07:00
|
|
|
rv = ConvertToRootViewRelativeOffset(caretFrame, rect);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-02-10 12:56:51 -08:00
|
|
|
aEvent->mReply.mRect =
|
2010-03-14 15:52:07 -07:00
|
|
|
rect.ToOutsidePixels(caretFrame->PresContext()->AppUnitsPerDevPixel());
|
2008-02-19 23:40:04 -08:00
|
|
|
aEvent->mSucceeded = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, we should set the guessed caret rect.
|
|
|
|
nsCOMPtr<nsIRange> range = new nsRange();
|
|
|
|
NS_ENSURE_TRUE(range, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
rv = SetRangeFromFlatTextOffset(range, aEvent->mInput.mOffset, 0, PR_TRUE);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
PRInt32 offsetInFrame;
|
|
|
|
nsIFrame* frame;
|
|
|
|
rv = GetStartFrameAndOffset(range, &frame, &offsetInFrame);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsPoint posInFrame;
|
|
|
|
rv = frame->GetPointFromOffset(range->StartOffset(), &posInFrame);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsRect rect;
|
|
|
|
rect.x = posInFrame.x;
|
|
|
|
rect.y = posInFrame.y;
|
|
|
|
rect.width = caret->GetCaretRect().width;
|
|
|
|
rect.height = frame->GetSize().height;
|
|
|
|
|
|
|
|
rv = ConvertToRootViewRelativeOffset(frame, rect);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
aEvent->mReply.mRect =
|
2009-05-07 19:31:04 -07:00
|
|
|
rect.ToOutsidePixels(mPresContext->AppUnitsPerDevPixel());
|
2009-02-10 12:56:51 -08:00
|
|
|
aEvent->mSucceeded = PR_TRUE;
|
|
|
|
return NS_OK;
|
2008-02-19 23:40:04 -08:00
|
|
|
}
|
|
|
|
|
2009-03-17 19:04:01 -07:00
|
|
|
nsresult
|
|
|
|
nsContentEventHandler::OnQueryContentState(nsQueryContentEvent * aEvent)
|
|
|
|
{
|
|
|
|
nsresult rv = Init(aEvent);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
aEvent->mSucceeded = PR_TRUE;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsContentEventHandler::OnQuerySelectionAsTransferable(nsQueryContentEvent* aEvent)
|
|
|
|
{
|
|
|
|
nsresult rv = Init(aEvent);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
if (!aEvent->mReply.mHasSelection) {
|
|
|
|
aEvent->mSucceeded = PR_TRUE;
|
|
|
|
aEvent->mReply.mTransferable = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> doc = mPresShell->GetDocument();
|
|
|
|
NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
rv = nsCopySupport::GetTransferableForSelection(mSelection, doc, getter_AddRefs(aEvent->mReply.mTransferable));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
aEvent->mSucceeded = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-05-14 17:46:24 -07:00
|
|
|
nsresult
|
|
|
|
nsContentEventHandler::OnQueryCharacterAtPoint(nsQueryContentEvent* aEvent)
|
|
|
|
{
|
|
|
|
nsresult rv = Init(aEvent);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
nsIFrame* rootFrame = mPresShell->GetRootFrame();
|
2010-03-18 22:02:53 -07:00
|
|
|
NS_ENSURE_TRUE(rootFrame, NS_ERROR_FAILURE);
|
2010-07-02 12:11:04 -07:00
|
|
|
nsIWidget* rootWidget = rootFrame->GetNearestWidget();
|
2010-03-18 22:02:53 -07:00
|
|
|
NS_ENSURE_TRUE(rootWidget, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
// The root frame's widget might be different, e.g., the event was fired on
|
|
|
|
// a popup but the rootFrame is the document root.
|
|
|
|
if (rootWidget != aEvent->widget) {
|
|
|
|
NS_PRECONDITION(aEvent->widget, "The event must have the widget");
|
|
|
|
nsIView* view = nsIView::GetViewFor(aEvent->widget);
|
|
|
|
NS_ENSURE_TRUE(view, NS_ERROR_FAILURE);
|
|
|
|
rootFrame = nsLayoutUtils::GetFrameFor(view);
|
|
|
|
NS_ENSURE_TRUE(rootFrame, NS_ERROR_FAILURE);
|
2010-07-02 12:11:04 -07:00
|
|
|
rootWidget = rootFrame->GetNearestWidget();
|
2010-03-18 22:02:53 -07:00
|
|
|
NS_ENSURE_TRUE(rootWidget, NS_ERROR_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsQueryContentEvent eventOnRoot(PR_TRUE, NS_QUERY_CHARACTER_AT_POINT,
|
|
|
|
rootWidget);
|
|
|
|
eventOnRoot.refPoint = aEvent->refPoint;
|
|
|
|
if (rootWidget != aEvent->widget) {
|
|
|
|
eventOnRoot.refPoint += aEvent->widget->WidgetToScreenOffset();
|
|
|
|
eventOnRoot.refPoint -= rootWidget->WidgetToScreenOffset();
|
|
|
|
}
|
2009-05-14 17:46:24 -07:00
|
|
|
nsPoint ptInRoot =
|
2010-03-18 22:02:53 -07:00
|
|
|
nsLayoutUtils::GetEventCoordinatesRelativeTo(&eventOnRoot, rootFrame);
|
|
|
|
|
2009-05-14 17:46:24 -07:00
|
|
|
nsIFrame* targetFrame = nsLayoutUtils::GetFrameForPoint(rootFrame, ptInRoot);
|
2010-04-01 19:11:59 -07:00
|
|
|
if (!targetFrame || targetFrame->GetType() != nsGkAtoms::textFrame ||
|
|
|
|
!targetFrame->GetContent() ||
|
|
|
|
!nsContentUtils::ContentIsDescendantOf(targetFrame->GetContent(),
|
|
|
|
mRootContent)) {
|
2009-05-14 17:46:24 -07:00
|
|
|
// there is no character at the point.
|
|
|
|
aEvent->mReply.mOffset = nsQueryContentEvent::NOT_FOUND;
|
|
|
|
aEvent->mSucceeded = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-07-18 19:23:48 -07:00
|
|
|
nsPoint ptInTarget = ptInRoot + rootFrame->GetOffsetToCrossDoc(targetFrame);
|
|
|
|
PRInt32 rootAPD = rootFrame->PresContext()->AppUnitsPerDevPixel();
|
|
|
|
PRInt32 targetAPD = targetFrame->PresContext()->AppUnitsPerDevPixel();
|
|
|
|
ptInTarget = ptInTarget.ConvertAppUnits(rootAPD, targetAPD);
|
|
|
|
|
2009-05-14 17:46:24 -07:00
|
|
|
nsTextFrame* textframe = static_cast<nsTextFrame*>(targetFrame);
|
|
|
|
nsIFrame::ContentOffsets offsets =
|
|
|
|
textframe->GetCharacterOffsetAtFramePoint(ptInTarget);
|
|
|
|
NS_ENSURE_TRUE(offsets.content, NS_ERROR_FAILURE);
|
|
|
|
PRUint32 nativeOffset;
|
|
|
|
rv = GetFlatTextOffsetOfRange(mRootContent, offsets.content, offsets.offset,
|
|
|
|
&nativeOffset);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsQueryContentEvent textRect(PR_TRUE, NS_QUERY_TEXT_RECT, aEvent->widget);
|
|
|
|
textRect.InitForQueryTextRect(nativeOffset, 1);
|
|
|
|
rv = OnQueryTextRect(&textRect);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
NS_ENSURE_TRUE(textRect.mSucceeded, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
// currently, we don't need to get the actual text.
|
|
|
|
aEvent->mReply.mOffset = nativeOffset;
|
|
|
|
aEvent->mReply.mRect = textRect.mReply.mRect;
|
|
|
|
aEvent->mSucceeded = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-03-01 13:15:23 -08:00
|
|
|
nsresult
|
|
|
|
nsContentEventHandler::OnQueryDOMWidgetHittest(nsQueryContentEvent* aEvent)
|
|
|
|
{
|
|
|
|
nsresult rv = Init(aEvent);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
aEvent->mReply.mWidgetIsHit = PR_FALSE;
|
|
|
|
|
|
|
|
NS_ENSURE_TRUE(aEvent->widget, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsIDocument* doc = mPresShell->GetDocument();
|
|
|
|
NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);
|
|
|
|
nsIFrame* docFrame = mPresShell->GetRootFrame();
|
|
|
|
NS_ENSURE_TRUE(docFrame, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsIntPoint eventLoc =
|
|
|
|
aEvent->refPoint + aEvent->widget->WidgetToScreenOffset();
|
|
|
|
nsIntRect docFrameRect = docFrame->GetScreenRect(); // Returns CSS pixels
|
|
|
|
eventLoc.x = mPresContext->DevPixelsToIntCSSPixels(eventLoc.x);
|
|
|
|
eventLoc.y = mPresContext->DevPixelsToIntCSSPixels(eventLoc.y);
|
|
|
|
eventLoc.x -= docFrameRect.x;
|
|
|
|
eventLoc.y -= docFrameRect.y;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMElement> elementUnderMouse;
|
|
|
|
doc->ElementFromPointHelper(eventLoc.x, eventLoc.y, PR_FALSE, PR_FALSE,
|
|
|
|
getter_AddRefs(elementUnderMouse));
|
|
|
|
nsCOMPtr<nsIContent> contentUnderMouse = do_QueryInterface(elementUnderMouse);
|
|
|
|
if (contentUnderMouse) {
|
|
|
|
nsIWidget* targetWidget = nsnull;
|
|
|
|
nsIFrame* targetFrame = contentUnderMouse->GetPrimaryFrame();
|
|
|
|
nsIObjectFrame* pluginFrame = do_QueryFrame(targetFrame);
|
|
|
|
if (pluginFrame) {
|
|
|
|
targetWidget = pluginFrame->GetWidget();
|
|
|
|
} else if (targetFrame) {
|
|
|
|
targetWidget = targetFrame->GetNearestWidget();
|
|
|
|
}
|
|
|
|
if (aEvent->widget == targetWidget)
|
|
|
|
aEvent->mReply.mWidgetIsHit = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
aEvent->mSucceeded = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-02-19 23:40:04 -08:00
|
|
|
nsresult
|
2009-02-10 12:56:51 -08:00
|
|
|
nsContentEventHandler::GetFlatTextOffsetOfRange(nsIContent* aRootContent,
|
|
|
|
nsINode* aNode,
|
|
|
|
PRInt32 aNodeOffset,
|
|
|
|
PRUint32* aNativeOffset)
|
2008-02-19 23:40:04 -08:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aNativeOffset, "param is invalid");
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRange> prev = new nsRange();
|
|
|
|
NS_ENSURE_TRUE(prev, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
nsCOMPtr<nsIDOMRange> domPrev(do_QueryInterface(prev));
|
|
|
|
NS_ASSERTION(domPrev, "nsRange doesn't have nsIDOMRange??");
|
2009-02-10 12:56:51 -08:00
|
|
|
nsCOMPtr<nsIDOMNode> rootDOMNode(do_QueryInterface(aRootContent));
|
2008-02-19 23:40:04 -08:00
|
|
|
domPrev->SetStart(rootDOMNode, 0);
|
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
nsCOMPtr<nsIDOMNode> startDOMNode(do_QueryInterface(aNode));
|
2008-02-19 23:40:04 -08:00
|
|
|
NS_ASSERTION(startDOMNode, "startNode doesn't have nsIDOMNode");
|
2009-02-10 12:56:51 -08:00
|
|
|
domPrev->SetEnd(startDOMNode, aNodeOffset);
|
2008-02-19 23:40:04 -08:00
|
|
|
|
2011-06-27 05:59:01 -07:00
|
|
|
nsCOMPtr<nsIContentIterator> iter;
|
|
|
|
nsresult rv = NS_NewContentIterator(getter_AddRefs(iter));
|
2008-02-19 23:40:04 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-06-27 05:59:01 -07:00
|
|
|
NS_ASSERTION(iter, "NS_NewContentIterator succeeded, but the result is null");
|
|
|
|
iter->Init(domPrev);
|
|
|
|
|
|
|
|
nsCOMPtr<nsINode> startNode = do_QueryInterface(startDOMNode);
|
|
|
|
nsINode* endNode = aNode;
|
|
|
|
|
|
|
|
*aNativeOffset = 0;
|
|
|
|
for (; !iter->IsDone(); iter->Next()) {
|
|
|
|
nsINode* node = iter->GetCurrentNode();
|
|
|
|
if (!node || !node->IsNodeOfType(nsINode::eCONTENT))
|
|
|
|
continue;
|
|
|
|
nsIContent* content = static_cast<nsIContent*>(node);
|
|
|
|
|
|
|
|
if (node->IsNodeOfType(nsINode::eTEXT)) {
|
|
|
|
// Note: our range always starts from offset 0
|
|
|
|
if (node == endNode)
|
|
|
|
*aNativeOffset += GetNativeTextLength(content, aNodeOffset);
|
|
|
|
else
|
|
|
|
*aNativeOffset += GetNativeTextLength(content);
|
|
|
|
} else if (IsContentBR(content)) {
|
|
|
|
#if defined(XP_WIN)
|
|
|
|
// On Windows, the length of the newline is 2.
|
|
|
|
*aNativeOffset += 2;
|
|
|
|
#else
|
|
|
|
// On other platforms, the length of the newline is 1.
|
|
|
|
*aNativeOffset += 1;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
2008-02-19 23:40:04 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2009-02-10 12:56:51 -08:00
|
|
|
nsContentEventHandler::GetFlatTextOffsetOfRange(nsIContent* aRootContent,
|
|
|
|
nsIRange* aRange,
|
|
|
|
PRUint32* aNativeOffset)
|
|
|
|
{
|
|
|
|
nsINode* startNode = aRange->GetStartParent();
|
|
|
|
NS_ENSURE_TRUE(startNode, NS_ERROR_FAILURE);
|
|
|
|
PRInt32 startOffset = aRange->StartOffset();
|
|
|
|
return GetFlatTextOffsetOfRange(aRootContent, startNode, startOffset,
|
|
|
|
aNativeOffset);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsContentEventHandler::GetStartFrameAndOffset(nsIRange* aRange,
|
|
|
|
nsIFrame** aFrame,
|
|
|
|
PRInt32* aOffsetInFrame)
|
2008-02-19 23:40:04 -08:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aRange && aFrame && aOffsetInFrame, "params are invalid");
|
|
|
|
|
|
|
|
nsIContent* content = nsnull;
|
|
|
|
nsINode* node = aRange->GetStartParent();
|
|
|
|
if (node && node->IsNodeOfType(nsINode::eCONTENT))
|
|
|
|
content = static_cast<nsIContent*>(node);
|
|
|
|
NS_ASSERTION(content, "the start node doesn't have nsIContent!");
|
|
|
|
|
2011-05-18 20:10:49 -07:00
|
|
|
nsRefPtr<nsFrameSelection> fs = mPresShell->FrameSelection();
|
2008-02-19 23:40:04 -08:00
|
|
|
*aFrame = fs->GetFrameForNodeOffset(content, aRange->StartOffset(),
|
|
|
|
fs->GetHint(), aOffsetInFrame);
|
|
|
|
NS_ENSURE_TRUE((*aFrame), NS_ERROR_FAILURE);
|
|
|
|
NS_ASSERTION((*aFrame)->GetType() == nsGkAtoms::textFrame,
|
|
|
|
"The frame is not textframe");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2009-02-10 12:56:51 -08:00
|
|
|
nsContentEventHandler::ConvertToRootViewRelativeOffset(nsIFrame* aFrame,
|
|
|
|
nsRect& aRect)
|
2008-02-19 23:40:04 -08:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aFrame, "aFrame must not be null");
|
|
|
|
|
|
|
|
nsIView* view = nsnull;
|
|
|
|
nsPoint posInView;
|
|
|
|
aFrame->GetOffsetFromView(posInView, &view);
|
|
|
|
if (!view)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
aRect += posInView + view->GetOffsetTo(nsnull);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2009-02-10 12:56:51 -08:00
|
|
|
|
|
|
|
static void AdjustRangeForSelection(nsIContent* aRoot,
|
|
|
|
nsINode** aNode,
|
|
|
|
PRInt32* aOffset)
|
|
|
|
{
|
|
|
|
nsINode* node = *aNode;
|
|
|
|
PRInt32 offset = *aOffset;
|
|
|
|
if (aRoot != node && node->GetParent() &&
|
|
|
|
!node->IsNodeOfType(nsINode::eTEXT)) {
|
|
|
|
node = node->GetParent();
|
|
|
|
offset = node->IndexOf(*aNode) + (offset ? 1 : 0);
|
|
|
|
}
|
2009-08-24 13:02:07 -07:00
|
|
|
|
|
|
|
nsIContent* brContent = node->GetChildAt(offset - 1);
|
|
|
|
while (brContent && brContent->IsHTML()) {
|
2009-02-10 12:56:51 -08:00
|
|
|
if (brContent->Tag() != nsGkAtoms::br || IsContentBR(brContent))
|
|
|
|
break;
|
2009-08-24 13:02:07 -07:00
|
|
|
brContent = node->GetChildAt(--offset - 1);
|
2009-02-10 12:56:51 -08:00
|
|
|
}
|
|
|
|
*aNode = node;
|
2010-02-22 11:41:19 -08:00
|
|
|
*aOffset = NS_MAX(offset, 0);
|
2009-02-10 12:56:51 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsContentEventHandler::OnSelectionEvent(nsSelectionEvent* aEvent)
|
|
|
|
{
|
|
|
|
aEvent->mSucceeded = PR_FALSE;
|
|
|
|
|
|
|
|
// Get selection to manipulate
|
2010-03-18 22:02:53 -07:00
|
|
|
// XXX why do we need to get them from ISM? This method should work fine
|
|
|
|
// without ISM.
|
2009-02-10 12:56:51 -08:00
|
|
|
nsresult rv = nsIMEStateManager::
|
2010-03-18 22:02:53 -07:00
|
|
|
GetFocusSelectionAndRoot(getter_AddRefs(mSelection),
|
2009-02-10 12:56:51 -08:00
|
|
|
getter_AddRefs(mRootContent));
|
2010-03-18 22:02:53 -07:00
|
|
|
if (rv != NS_ERROR_NOT_AVAILABLE) {
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
} else {
|
|
|
|
rv = Init(aEvent);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2009-02-10 12:56:51 -08:00
|
|
|
|
|
|
|
// Get range from offset and length
|
|
|
|
nsRefPtr<nsRange> range = new nsRange();
|
|
|
|
NS_ENSURE_TRUE(range, NS_ERROR_OUT_OF_MEMORY);
|
2010-03-24 08:04:39 -07:00
|
|
|
rv = SetRangeFromFlatTextOffset(range, aEvent->mOffset, aEvent->mLength,
|
|
|
|
aEvent->mExpandToClusterBoundary);
|
2009-02-10 12:56:51 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsINode* startNode = range->GetStartParent();
|
|
|
|
nsINode* endNode = range->GetEndParent();
|
|
|
|
PRInt32 startOffset = range->StartOffset();
|
|
|
|
PRInt32 endOffset = range->EndOffset();
|
|
|
|
AdjustRangeForSelection(mRootContent, &startNode, &startOffset);
|
|
|
|
AdjustRangeForSelection(mRootContent, &endNode, &endOffset);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> startDomNode(do_QueryInterface(startNode));
|
|
|
|
nsCOMPtr<nsIDOMNode> endDomNode(do_QueryInterface(endNode));
|
|
|
|
NS_ENSURE_TRUE(startDomNode && endDomNode, NS_ERROR_UNEXPECTED);
|
|
|
|
|
2011-08-07 13:17:00 -07:00
|
|
|
nsCOMPtr<nsISelectionPrivate> selPrivate(do_QueryInterface(mSelection));
|
2009-02-10 12:56:51 -08:00
|
|
|
selPrivate->StartBatchChanges();
|
|
|
|
|
|
|
|
// Clear selection first before setting
|
2010-03-18 22:02:53 -07:00
|
|
|
rv = mSelection->RemoveAllRanges();
|
2009-02-10 12:56:51 -08:00
|
|
|
// Need to call EndBatchChanges at the end even if call failed
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
if (aEvent->mReversed) {
|
2010-03-18 22:02:53 -07:00
|
|
|
rv = mSelection->Collapse(endDomNode, endOffset);
|
2009-02-10 12:56:51 -08:00
|
|
|
} else {
|
2010-03-18 22:02:53 -07:00
|
|
|
rv = mSelection->Collapse(startDomNode, startOffset);
|
2009-02-10 12:56:51 -08:00
|
|
|
}
|
|
|
|
if (NS_SUCCEEDED(rv) &&
|
|
|
|
(startDomNode != endDomNode || startOffset != endOffset)) {
|
|
|
|
if (aEvent->mReversed) {
|
2010-03-18 22:02:53 -07:00
|
|
|
rv = mSelection->Extend(startDomNode, startOffset);
|
2009-02-10 12:56:51 -08:00
|
|
|
} else {
|
2010-03-18 22:02:53 -07:00
|
|
|
rv = mSelection->Extend(endDomNode, endOffset);
|
2009-02-10 12:56:51 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
selPrivate->EndBatchChanges();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2011-08-07 13:17:00 -07:00
|
|
|
selPrivate->ScrollIntoView(
|
2009-02-10 12:56:51 -08:00
|
|
|
nsISelectionController::SELECTION_FOCUS_REGION, PR_FALSE, -1, -1);
|
|
|
|
aEvent->mSucceeded = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|