1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is mozilla.org code.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * Netscape Communications Corporation.
19 : * Portions created by the Initial Developer are Copyright (C) 1998
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : *
24 : * Alternatively, the contents of this file may be used under the terms of
25 : * either of the GNU General Public License Version 2 or later (the "GPL"),
26 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 : * in which case the provisions of the GPL or the LGPL are applicable instead
28 : * of those above. If you wish to allow use of your version of this file only
29 : * under the terms of either the GPL or the LGPL, and not to allow others to
30 : * use your version of this file under the terms of the MPL, indicate your
31 : * decision by deleting the provisions above and replace them with the notice
32 : * and other provisions required by the GPL or the LGPL. If you do not delete
33 : * the provisions above, a recipient may use your version of this file under
34 : * the terms of any one of the MPL, the GPL or the LGPL.
35 : *
36 : * ***** END LICENSE BLOCK ***** */
37 :
38 : #include "nsTextEditRules.h"
39 : #include "nsCOMPtr.h"
40 : #include "nsIDOMNode.h"
41 : #include "nsIContent.h"
42 : #include "nsIPresShell.h"
43 : #include "nsPresContext.h"
44 : #include "nsIFrame.h"
45 : #include "nsISelectionPrivate.h"
46 : #include "nsFrameSelection.h"
47 :
48 : // Test for distance between caret and text that will be deleted
49 : nsresult
50 0 : nsTextEditRules::CheckBidiLevelForDeletion(nsISelection *aSelection,
51 : nsIDOMNode *aSelNode,
52 : PRInt32 aSelOffset,
53 : nsIEditor::EDirection aAction,
54 : bool *aCancel)
55 : {
56 0 : NS_ENSURE_ARG_POINTER(aCancel);
57 0 : *aCancel = false;
58 :
59 0 : nsCOMPtr<nsIPresShell> shell = mEditor->GetPresShell();
60 0 : NS_ENSURE_TRUE(shell, NS_ERROR_NOT_INITIALIZED);
61 :
62 0 : nsPresContext *context = shell->GetPresContext();
63 0 : NS_ENSURE_TRUE(context, NS_ERROR_NULL_POINTER);
64 :
65 0 : if (!context->BidiEnabled())
66 0 : return NS_OK;
67 :
68 0 : nsCOMPtr<nsIContent> content = do_QueryInterface(aSelNode);
69 0 : NS_ENSURE_TRUE(content, NS_ERROR_NULL_POINTER);
70 :
71 : PRUint8 levelBefore;
72 : PRUint8 levelAfter;
73 :
74 0 : nsCOMPtr<nsISelectionPrivate> privateSelection(do_QueryInterface(aSelection));
75 0 : NS_ENSURE_TRUE(privateSelection, NS_ERROR_NULL_POINTER);
76 :
77 0 : nsRefPtr<nsFrameSelection> frameSelection;
78 0 : privateSelection->GetFrameSelection(getter_AddRefs(frameSelection));
79 0 : NS_ENSURE_TRUE(frameSelection, NS_ERROR_NULL_POINTER);
80 :
81 0 : nsPrevNextBidiLevels levels = frameSelection->
82 0 : GetPrevNextBidiLevels(content, aSelOffset, true);
83 :
84 0 : levelBefore = levels.mLevelBefore;
85 0 : levelAfter = levels.mLevelAfter;
86 :
87 0 : PRUint8 currentCaretLevel = frameSelection->GetCaretBidiLevel();
88 :
89 : PRUint8 levelOfDeletion;
90 : levelOfDeletion =
91 : (nsIEditor::eNext==aAction || nsIEditor::eNextWord==aAction) ?
92 0 : levelAfter : levelBefore;
93 :
94 0 : if (currentCaretLevel == levelOfDeletion)
95 : ; // perform the deletion
96 : else
97 : {
98 0 : if (mDeleteBidiImmediately || levelBefore == levelAfter)
99 : ; // perform the deletion
100 : else
101 0 : *aCancel = true;
102 :
103 : // Set the bidi level of the caret to that of the
104 : // character that will be (or would have been) deleted
105 0 : frameSelection->SetCaretBidiLevel(levelOfDeletion);
106 : }
107 0 : return NS_OK;
108 : }
109 :
|