editor/libeditor/text/nsTextEditRulesBidi.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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/. */
     6 #include "nsAutoPtr.h"
     7 #include "nsCOMPtr.h"
     8 #include "nsDebug.h"
     9 #include "nsError.h"
    10 #include "nsFrameSelection.h"
    11 #include "nsIContent.h"
    12 #include "nsIDOMNode.h"
    13 #include "nsIEditor.h"
    14 #include "nsIPresShell.h"
    15 #include "mozilla/dom/Selection.h"
    16 #include "nsISelectionPrivate.h"
    17 #include "nsISupportsImpl.h"
    18 #include "nsPlaintextEditor.h"
    19 #include "nsPresContext.h"
    20 #include "nsTextEditRules.h"
    21 #include "nscore.h"
    23 using namespace mozilla;
    24 using namespace mozilla::dom;
    26 // Test for distance between caret and text that will be deleted
    27 nsresult
    28 nsTextEditRules::CheckBidiLevelForDeletion(nsISelection         *aSelection,
    29                                            nsIDOMNode           *aSelNode, 
    30                                            int32_t               aSelOffset, 
    31                                            nsIEditor::EDirection aAction,
    32                                            bool                 *aCancel)
    33 {
    34   NS_ENSURE_ARG_POINTER(aCancel);
    35   *aCancel = false;
    37   nsCOMPtr<nsIPresShell> shell = mEditor->GetPresShell();
    38   NS_ENSURE_TRUE(shell, NS_ERROR_NOT_INITIALIZED);
    40   nsPresContext *context = shell->GetPresContext();
    41   NS_ENSURE_TRUE(context, NS_ERROR_NULL_POINTER);
    43   if (!context->BidiEnabled())
    44     return NS_OK;
    46   nsCOMPtr<nsIContent> content = do_QueryInterface(aSelNode);
    47   NS_ENSURE_TRUE(content, NS_ERROR_NULL_POINTER);
    49   uint8_t levelBefore;
    50   uint8_t levelAfter;
    51   nsRefPtr<nsFrameSelection> frameSelection =
    52     static_cast<Selection*>(aSelection)->GetFrameSelection();
    53   NS_ENSURE_TRUE(frameSelection, NS_ERROR_NULL_POINTER);
    55   nsPrevNextBidiLevels levels = frameSelection->
    56     GetPrevNextBidiLevels(content, aSelOffset, true);
    58   levelBefore = levels.mLevelBefore;
    59   levelAfter = levels.mLevelAfter;
    61   uint8_t currentCaretLevel = frameSelection->GetCaretBidiLevel();
    63   uint8_t levelOfDeletion;
    64   levelOfDeletion =
    65     (nsIEditor::eNext==aAction || nsIEditor::eNextWord==aAction) ?
    66     levelAfter : levelBefore;
    68   if (currentCaretLevel == levelOfDeletion)
    69     ; // perform the deletion
    70   else
    71   {
    72     if (mDeleteBidiImmediately || levelBefore == levelAfter)
    73       ; // perform the deletion
    74     else
    75       *aCancel = true;
    77     // Set the bidi level of the caret to that of the
    78     // character that will be (or would have been) deleted
    79     frameSelection->SetCaretBidiLevel(levelOfDeletion);
    80   }
    81   return NS_OK;
    82 }

mercurial