tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

nsMaiInterfaceEditableText.cpp (2962B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #include "InterfaceInitFuncs.h"
      8 
      9 #include "LocalAccessible-inl.h"
     10 #include "HyperTextAccessible-inl.h"
     11 #include "nsMai.h"
     12 #include "RemoteAccessible.h"
     13 #include "nsString.h"
     14 #include "mozilla/Likely.h"
     15 
     16 using namespace mozilla::a11y;
     17 
     18 extern "C" {
     19 static void setTextContentsCB(AtkEditableText* aText, const gchar* aString) {
     20  if (Accessible* acc = GetInternalObj(ATK_OBJECT(aText))) {
     21    if (acc->IsTextRole()) {
     22      return;
     23    }
     24    if (HyperTextAccessibleBase* text = acc->AsHyperTextBase()) {
     25      NS_ConvertUTF8toUTF16 strContent(aString);
     26      text->ReplaceText(strContent);
     27    }
     28  }
     29 }
     30 
     31 static void insertTextCB(AtkEditableText* aText, const gchar* aString,
     32                         gint aLength, gint* aPosition) {
     33  if (Accessible* acc = GetInternalObj(ATK_OBJECT(aText))) {
     34    if (acc->IsTextRole()) {
     35      return;
     36    }
     37    if (HyperTextAccessibleBase* text = acc->AsHyperTextBase()) {
     38      NS_ConvertUTF8toUTF16 strContent(aString);
     39      text->InsertText(strContent, *aPosition);
     40    }
     41  }
     42 }
     43 
     44 static void copyTextCB(AtkEditableText* aText, gint aStartPos, gint aEndPos) {
     45  if (Accessible* acc = GetInternalObj(ATK_OBJECT(aText))) {
     46    if (acc->IsTextRole()) {
     47      return;
     48    }
     49    if (HyperTextAccessibleBase* text = acc->AsHyperTextBase()) {
     50      text->CopyText(aStartPos, aEndPos);
     51    }
     52  }
     53 }
     54 
     55 static void cutTextCB(AtkEditableText* aText, gint aStartPos, gint aEndPos) {
     56  if (Accessible* acc = GetInternalObj(ATK_OBJECT(aText))) {
     57    if (acc->IsTextRole()) {
     58      return;
     59    }
     60    if (HyperTextAccessibleBase* text = acc->AsHyperTextBase()) {
     61      text->CutText(aStartPos, aEndPos);
     62    }
     63  }
     64 }
     65 
     66 static void deleteTextCB(AtkEditableText* aText, gint aStartPos, gint aEndPos) {
     67  if (Accessible* acc = GetInternalObj(ATK_OBJECT(aText))) {
     68    if (acc->IsTextRole()) {
     69      return;
     70    }
     71    if (HyperTextAccessibleBase* text = acc->AsHyperTextBase()) {
     72      text->DeleteText(aStartPos, aEndPos);
     73    }
     74  }
     75 }
     76 
     77 MOZ_CAN_RUN_SCRIPT_BOUNDARY
     78 static void pasteTextCB(AtkEditableText* aText, gint aPosition) {
     79  if (Accessible* acc = GetInternalObj(ATK_OBJECT(aText))) {
     80    if (acc->IsTextRole()) {
     81      return;
     82    }
     83    if (HyperTextAccessibleBase* text = acc->AsHyperTextBase()) {
     84      text->PasteText(aPosition);
     85    }
     86  }
     87 }
     88 }
     89 
     90 void editableTextInterfaceInitCB(AtkEditableTextIface* aIface) {
     91  NS_ASSERTION(aIface, "Invalid aIface");
     92  if (MOZ_UNLIKELY(!aIface)) return;
     93 
     94  aIface->set_text_contents = setTextContentsCB;
     95  aIface->insert_text = insertTextCB;
     96  aIface->copy_text = copyTextCB;
     97  aIface->cut_text = cutTextCB;
     98  aIface->delete_text = deleteTextCB;
     99  aIface->paste_text = pasteTextCB;
    100 }