2001-09-26 02:53:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04: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-22 03:57:55 +04:00
|
|
|
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "nsAutoPtr.h"
|
2001-05-22 03:57:55 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "nsDebug.h"
|
|
|
|
#include "nsError.h"
|
|
|
|
#include "nsFrameSelection.h"
|
2001-05-22 03:57:55 +04:00
|
|
|
#include "nsIContent.h"
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "nsIDOMNode.h"
|
|
|
|
#include "nsIEditor.h"
|
2001-05-22 03:57:55 +04:00
|
|
|
#include "nsIPresShell.h"
|
2014-04-10 20:09:40 +04:00
|
|
|
#include "mozilla/dom/Selection.h"
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "nsISupportsImpl.h"
|
|
|
|
#include "nsPlaintextEditor.h"
|
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsTextEditRules.h"
|
|
|
|
#include "nscore.h"
|
2001-05-22 03:57:55 +04:00
|
|
|
|
2013-02-16 00:09:28 +04:00
|
|
|
using namespace mozilla;
|
2014-04-10 20:09:40 +04:00
|
|
|
using namespace mozilla::dom;
|
2013-02-16 00:09:28 +04:00
|
|
|
|
2001-05-22 03:57:55 +04:00
|
|
|
// Test for distance between caret and text that will be deleted
|
|
|
|
nsresult
|
2014-11-02 15:04:13 +03:00
|
|
|
nsTextEditRules::CheckBidiLevelForDeletion(Selection* aSelection,
|
2015-05-28 18:58:42 +03:00
|
|
|
nsIDOMNode *aSelNode,
|
|
|
|
int32_t aSelOffset,
|
2001-05-22 03:57:55 +04:00
|
|
|
nsIEditor::EDirection aAction,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool *aCancel)
|
2001-05-22 03:57:55 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aCancel);
|
2011-10-17 18:59:28 +04:00
|
|
|
*aCancel = false;
|
2001-05-22 03:57:55 +04:00
|
|
|
|
2011-05-22 16:43:13 +04:00
|
|
|
nsCOMPtr<nsIPresShell> shell = mEditor->GetPresShell();
|
|
|
|
NS_ENSURE_TRUE(shell, NS_ERROR_NOT_INITIALIZED);
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2004-08-21 00:34:37 +04:00
|
|
|
nsPresContext *context = shell->GetPresContext();
|
2010-06-18 00:40:48 +04:00
|
|
|
NS_ENSURE_TRUE(context, NS_ERROR_NULL_POINTER);
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2004-04-13 04:28:44 +04:00
|
|
|
if (!context->BidiEnabled())
|
2001-05-22 03:57:55 +04:00
|
|
|
return NS_OK;
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2001-05-22 03:57:55 +04:00
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(aSelNode);
|
2010-06-18 00:40:48 +04:00
|
|
|
NS_ENSURE_TRUE(content, NS_ERROR_NULL_POINTER);
|
2006-04-26 05:57:22 +04:00
|
|
|
|
2014-11-20 13:45:22 +03:00
|
|
|
nsBidiLevel levelBefore;
|
|
|
|
nsBidiLevel levelAfter;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsFrameSelection> frameSelection =
|
2013-02-16 00:09:28 +04:00
|
|
|
static_cast<Selection*>(aSelection)->GetFrameSelection();
|
2010-06-18 00:40:48 +04:00
|
|
|
NS_ENSURE_TRUE(frameSelection, NS_ERROR_NULL_POINTER);
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2006-04-26 05:57:22 +04:00
|
|
|
nsPrevNextBidiLevels levels = frameSelection->
|
2011-10-17 18:59:28 +04:00
|
|
|
GetPrevNextBidiLevels(content, aSelOffset, true);
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2006-04-26 05:57:22 +04:00
|
|
|
levelBefore = levels.mLevelBefore;
|
|
|
|
levelAfter = levels.mLevelAfter;
|
2006-08-08 09:14:52 +04:00
|
|
|
|
2014-11-20 13:45:22 +03:00
|
|
|
nsBidiLevel currentCaretLevel = frameSelection->GetCaretBidiLevel();
|
2003-07-18 18:12:51 +04:00
|
|
|
|
2014-11-20 13:45:22 +03:00
|
|
|
nsBidiLevel levelOfDeletion;
|
2008-10-16 11:44:32 +04:00
|
|
|
levelOfDeletion =
|
|
|
|
(nsIEditor::eNext==aAction || nsIEditor::eNextWord==aAction) ?
|
|
|
|
levelAfter : levelBefore;
|
2001-05-22 03:57:55 +04:00
|
|
|
|
2006-08-08 09:14:52 +04:00
|
|
|
if (currentCaretLevel == levelOfDeletion)
|
2001-05-22 03:57:55 +04:00
|
|
|
; // perform the deletion
|
|
|
|
else
|
|
|
|
{
|
2006-03-07 09:03:37 +03:00
|
|
|
if (mDeleteBidiImmediately || levelBefore == levelAfter)
|
2001-05-22 03:57:55 +04:00
|
|
|
; // perform the deletion
|
|
|
|
else
|
2011-10-17 18:59:28 +04:00
|
|
|
*aCancel = true;
|
2001-05-22 03:57:55 +04:00
|
|
|
|
|
|
|
// Set the bidi level of the caret to that of the
|
|
|
|
// character that will be (or would have been) deleted
|
2006-08-08 09:14:52 +04:00
|
|
|
frameSelection->SetCaretBidiLevel(levelOfDeletion);
|
2001-05-22 03:57:55 +04:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-06-01 22:19:57 +03:00
|
|
|
void
|
|
|
|
nsTextEditRules::UndefineCaretBidiLevel(Selection* aSelection)
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* After inserting text the caret Bidi level must be set to the level of the
|
|
|
|
* inserted text.This is difficult, because we cannot know what the level is
|
|
|
|
* until after the Bidi algorithm is applied to the whole paragraph.
|
|
|
|
*
|
|
|
|
* So we set the caret Bidi level to UNDEFINED here, and the caret code will
|
|
|
|
* set it correctly later
|
|
|
|
*/
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsFrameSelection> frameSelection = aSelection->GetFrameSelection();
|
2015-06-01 22:19:57 +03:00
|
|
|
if (frameSelection) {
|
|
|
|
frameSelection->UndefineCaretBidiLevel();
|
|
|
|
}
|
|
|
|
}
|