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
|
|
|
|
2016-07-09 05:34:41 +03:00
|
|
|
#include "mozilla/TextEditRules.h"
|
|
|
|
|
2016-07-09 05:54:50 +03:00
|
|
|
#include "mozilla/TextEditor.h"
|
|
|
|
#include "mozilla/dom/Selection.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"
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "nsISupportsImpl.h"
|
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nscore.h"
|
2001-05-22 03:57:55 +04:00
|
|
|
|
2016-07-09 05:34:41 +03:00
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
using namespace 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
|
2016-07-09 05:34:41 +03:00
|
|
|
TextEditRules::CheckBidiLevelForDeletion(Selection* aSelection,
|
|
|
|
nsIDOMNode* aSelNode,
|
|
|
|
int32_t aSelOffset,
|
|
|
|
nsIEditor::EDirection aAction,
|
|
|
|
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
|
|
|
|
2016-07-09 05:54:50 +03:00
|
|
|
nsCOMPtr<nsIPresShell> shell = mTextEditor->GetPresShell();
|
2011-05-22 16:43:13 +04:00
|
|
|
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
|
|
|
|
2016-10-24 05:27:45 +03:00
|
|
|
if (!context->BidiEnabled()) {
|
2001-05-22 03:57:55 +04:00
|
|
|
return NS_OK;
|
2016-10-24 05:27:45 +03:00
|
|
|
}
|
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 =
|
2016-06-17 16:32:49 +03:00
|
|
|
aSelection->AsSelection()->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
|
|
|
|
2016-10-24 05:27:45 +03:00
|
|
|
if (currentCaretLevel == levelOfDeletion) {
|
|
|
|
return NS_OK; // perform the deletion
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mDeleteBidiImmediately && levelBefore != levelAfter) {
|
|
|
|
*aCancel = true;
|
2001-05-22 03:57:55 +04:00
|
|
|
}
|
2016-10-24 05:27:45 +03:00
|
|
|
|
|
|
|
// Set the bidi level of the caret to that of the
|
|
|
|
// character that will be (or would have been) deleted
|
|
|
|
frameSelection->SetCaretBidiLevel(levelOfDeletion);
|
2001-05-22 03:57:55 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-06-01 22:19:57 +03:00
|
|
|
void
|
2016-07-09 05:34:41 +03:00
|
|
|
TextEditRules::UndefineCaretBidiLevel(Selection* aSelection)
|
2015-06-01 22:19:57 +03:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* 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();
|
|
|
|
}
|
|
|
|
}
|
2016-07-09 05:34:41 +03:00
|
|
|
|
|
|
|
} // namespace mozilla
|