2001-09-25 22:53:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00: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/. */
|
2001-05-21 23:57:55 +00:00
|
|
|
|
2012-07-13 06:33:42 +00:00
|
|
|
#include "nsAutoPtr.h"
|
2001-05-21 23:57:55 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2012-07-13 06:33:42 +00:00
|
|
|
#include "nsDebug.h"
|
|
|
|
#include "nsError.h"
|
|
|
|
#include "nsFrameSelection.h"
|
2001-05-21 23:57:55 +00:00
|
|
|
#include "nsIContent.h"
|
2012-07-13 06:33:42 +00:00
|
|
|
#include "nsIDOMNode.h"
|
|
|
|
#include "nsIEditor.h"
|
2001-05-21 23:57:55 +00:00
|
|
|
#include "nsIPresShell.h"
|
2012-07-13 06:33:42 +00:00
|
|
|
#include "nsISelection.h"
|
2006-03-23 08:20:29 +00:00
|
|
|
#include "nsISelectionPrivate.h"
|
2012-07-13 06:33:42 +00:00
|
|
|
#include "nsISupportsImpl.h"
|
|
|
|
#include "nsPlaintextEditor.h"
|
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsTextEditRules.h"
|
|
|
|
#include "nscore.h"
|
|
|
|
#include "prtypes.h"
|
2001-05-21 23:57:55 +00:00
|
|
|
|
|
|
|
// Test for distance between caret and text that will be deleted
|
|
|
|
nsresult
|
2006-03-23 08:20:29 +00:00
|
|
|
nsTextEditRules::CheckBidiLevelForDeletion(nsISelection *aSelection,
|
|
|
|
nsIDOMNode *aSelNode,
|
2001-05-21 23:57:55 +00:00
|
|
|
PRInt32 aSelOffset,
|
|
|
|
nsIEditor::EDirection aAction,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool *aCancel)
|
2001-05-21 23:57:55 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aCancel);
|
2011-10-17 14:59:28 +00:00
|
|
|
*aCancel = false;
|
2001-05-21 23:57:55 +00:00
|
|
|
|
2011-05-22 12:43:13 +00:00
|
|
|
nsCOMPtr<nsIPresShell> shell = mEditor->GetPresShell();
|
|
|
|
NS_ENSURE_TRUE(shell, NS_ERROR_NOT_INITIALIZED);
|
2001-05-21 23:57:55 +00:00
|
|
|
|
2004-08-20 20:34:37 +00:00
|
|
|
nsPresContext *context = shell->GetPresContext();
|
2010-06-17 20:40:48 +00:00
|
|
|
NS_ENSURE_TRUE(context, NS_ERROR_NULL_POINTER);
|
2001-05-21 23:57:55 +00:00
|
|
|
|
2004-04-13 00:28:44 +00:00
|
|
|
if (!context->BidiEnabled())
|
2001-05-21 23:57:55 +00:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(aSelNode);
|
2010-06-17 20:40:48 +00:00
|
|
|
NS_ENSURE_TRUE(content, NS_ERROR_NULL_POINTER);
|
2006-04-26 01:57:22 +00:00
|
|
|
|
2006-03-23 08:20:29 +00:00
|
|
|
PRUint8 levelBefore;
|
|
|
|
PRUint8 levelAfter;
|
2003-07-18 14:12:51 +00:00
|
|
|
|
2006-03-23 08:20:29 +00:00
|
|
|
nsCOMPtr<nsISelectionPrivate> privateSelection(do_QueryInterface(aSelection));
|
2010-06-17 20:40:48 +00:00
|
|
|
NS_ENSURE_TRUE(privateSelection, NS_ERROR_NULL_POINTER);
|
2001-05-21 23:57:55 +00:00
|
|
|
|
2011-05-19 03:10:49 +00:00
|
|
|
nsRefPtr<nsFrameSelection> frameSelection;
|
2006-03-23 08:20:29 +00:00
|
|
|
privateSelection->GetFrameSelection(getter_AddRefs(frameSelection));
|
2010-06-17 20:40:48 +00:00
|
|
|
NS_ENSURE_TRUE(frameSelection, NS_ERROR_NULL_POINTER);
|
2006-03-23 08:20:29 +00:00
|
|
|
|
2006-04-26 01:57:22 +00:00
|
|
|
nsPrevNextBidiLevels levels = frameSelection->
|
2011-10-17 14:59:28 +00:00
|
|
|
GetPrevNextBidiLevels(content, aSelOffset, true);
|
2006-04-26 01:57:22 +00:00
|
|
|
|
|
|
|
levelBefore = levels.mLevelBefore;
|
|
|
|
levelAfter = levels.mLevelAfter;
|
2006-08-08 05:14:52 +00:00
|
|
|
|
|
|
|
PRUint8 currentCaretLevel = frameSelection->GetCaretBidiLevel();
|
2003-07-18 14:12:51 +00:00
|
|
|
|
|
|
|
PRUint8 levelOfDeletion;
|
2008-10-16 07:44:32 +00:00
|
|
|
levelOfDeletion =
|
|
|
|
(nsIEditor::eNext==aAction || nsIEditor::eNextWord==aAction) ?
|
|
|
|
levelAfter : levelBefore;
|
2001-05-21 23:57:55 +00:00
|
|
|
|
2006-08-08 05:14:52 +00:00
|
|
|
if (currentCaretLevel == levelOfDeletion)
|
2001-05-21 23:57:55 +00:00
|
|
|
; // perform the deletion
|
|
|
|
else
|
|
|
|
{
|
2006-03-07 06:03:37 +00:00
|
|
|
if (mDeleteBidiImmediately || levelBefore == levelAfter)
|
2001-05-21 23:57:55 +00:00
|
|
|
; // perform the deletion
|
|
|
|
else
|
2011-10-17 14:59:28 +00:00
|
|
|
*aCancel = true;
|
2001-05-21 23:57:55 +00:00
|
|
|
|
|
|
|
// Set the bidi level of the caret to that of the
|
|
|
|
// character that will be (or would have been) deleted
|
2006-08-08 05:14:52 +00:00
|
|
|
frameSelection->SetCaretBidiLevel(levelOfDeletion);
|
2001-05-21 23:57:55 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|