1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
10 #include "nsFrameSelection.h"
11 #include "nsIContent.h"
12 #include "nsIDOMNode.h"
13 #include "nsIEditor.h"
14 #include "nsIPresShell.h"
15 #include "nsISelection.h"
16 #include "nsISelectionPrivate.h"
17 #include "nsISupportsImpl.h"
18 #include "nsPlaintextEditor.h"
19 #include "nsPresContext.h"
20 #include "nsTextEditRules.h"
23 // Test for distance between caret and text that will be deleted
25 nsTextEditRules::CheckBidiLevelForDeletion(nsISelection
*aSelection
,
28 nsIEditor::EDirection aAction
,
31 NS_ENSURE_ARG_POINTER(aCancel
);
34 nsCOMPtr
<nsIPresShell
> shell
= mEditor
->GetPresShell();
35 NS_ENSURE_TRUE(shell
, NS_ERROR_NOT_INITIALIZED
);
37 nsPresContext
*context
= shell
->GetPresContext();
38 NS_ENSURE_TRUE(context
, NS_ERROR_NULL_POINTER
);
40 if (!context
->BidiEnabled())
43 nsCOMPtr
<nsIContent
> content
= do_QueryInterface(aSelNode
);
44 NS_ENSURE_TRUE(content
, NS_ERROR_NULL_POINTER
);
49 nsCOMPtr
<nsISelectionPrivate
> privateSelection(do_QueryInterface(aSelection
));
50 NS_ENSURE_TRUE(privateSelection
, NS_ERROR_NULL_POINTER
);
52 nsRefPtr
<nsFrameSelection
> frameSelection
;
53 privateSelection
->GetFrameSelection(getter_AddRefs(frameSelection
));
54 NS_ENSURE_TRUE(frameSelection
, NS_ERROR_NULL_POINTER
);
56 nsPrevNextBidiLevels levels
= frameSelection
->
57 GetPrevNextBidiLevels(content
, aSelOffset
, true);
59 levelBefore
= levels
.mLevelBefore
;
60 levelAfter
= levels
.mLevelAfter
;
62 uint8_t currentCaretLevel
= frameSelection
->GetCaretBidiLevel();
64 uint8_t levelOfDeletion
;
66 (nsIEditor::eNext
==aAction
|| nsIEditor::eNextWord
==aAction
) ?
67 levelAfter
: levelBefore
;
69 if (currentCaretLevel
== levelOfDeletion
)
70 ; // perform the deletion
73 if (mDeleteBidiImmediately
|| levelBefore
== levelAfter
)
74 ; // perform the deletion
78 // Set the bidi level of the caret to that of the
79 // character that will be (or would have been) deleted
80 frameSelection
->SetCaretBidiLevel(levelOfDeletion
);