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