accessible/src/atk/nsMaiInterfaceEditableText.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/accessible/src/atk/nsMaiInterfaceEditableText.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,120 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim: set ts=2 et sw=2 tw=80: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#include "InterfaceInitFuncs.h"
    1.11 +
    1.12 +#include "Accessible-inl.h"
    1.13 +#include "HyperTextAccessible-inl.h"
    1.14 +#include "nsMai.h"
    1.15 +
    1.16 +#include "nsString.h"
    1.17 +#include "mozilla/Likely.h"
    1.18 +
    1.19 +using namespace mozilla::a11y;
    1.20 +
    1.21 +extern "C" {
    1.22 +static void
    1.23 +setTextContentsCB(AtkEditableText *aText, const gchar *aString)
    1.24 +{
    1.25 +  AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
    1.26 +  if (!accWrap)
    1.27 +    return;
    1.28 +
    1.29 +  HyperTextAccessible* text = accWrap->AsHyperText();
    1.30 +  if (!text || !text->IsTextRole())
    1.31 +    return;
    1.32 +
    1.33 +  NS_ConvertUTF8toUTF16 strContent(aString);
    1.34 +  text->ReplaceText(strContent);
    1.35 +}
    1.36 +
    1.37 +static void
    1.38 +insertTextCB(AtkEditableText *aText,
    1.39 +             const gchar *aString, gint aLength, gint *aPosition)
    1.40 +{
    1.41 +  AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
    1.42 +  if (!accWrap)
    1.43 +    return;
    1.44 +
    1.45 +  HyperTextAccessible* text = accWrap->AsHyperText();
    1.46 +  if (!text || !text->IsTextRole())
    1.47 +    return;
    1.48 +
    1.49 +  NS_ConvertUTF8toUTF16 strContent(aString, aLength);
    1.50 +  text->InsertText(strContent, *aPosition);
    1.51 +}
    1.52 +
    1.53 +static void
    1.54 +copyTextCB(AtkEditableText *aText, gint aStartPos, gint aEndPos)
    1.55 +{
    1.56 +  AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
    1.57 +  if (!accWrap)
    1.58 +    return;
    1.59 +
    1.60 +  HyperTextAccessible* text = accWrap->AsHyperText();
    1.61 +  if (!text || !text->IsTextRole())
    1.62 +    return;
    1.63 +
    1.64 +  text->CopyText(aStartPos, aEndPos);
    1.65 +}
    1.66 +
    1.67 +static void
    1.68 +cutTextCB(AtkEditableText *aText, gint aStartPos, gint aEndPos)
    1.69 +{
    1.70 +  AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
    1.71 +  if (!accWrap)
    1.72 +    return;
    1.73 +
    1.74 +  HyperTextAccessible* text = accWrap->AsHyperText();
    1.75 +  if (!text || !text->IsTextRole())
    1.76 +    return;
    1.77 +
    1.78 +  text->CutText(aStartPos, aEndPos);
    1.79 +}
    1.80 +
    1.81 +static void
    1.82 +deleteTextCB(AtkEditableText *aText, gint aStartPos, gint aEndPos)
    1.83 +{
    1.84 +  AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
    1.85 +  if (!accWrap)
    1.86 +    return;
    1.87 +
    1.88 +  HyperTextAccessible* text = accWrap->AsHyperText();
    1.89 +  if (!text || !text->IsTextRole())
    1.90 +    return;
    1.91 +
    1.92 +  text->DeleteText(aStartPos, aEndPos);
    1.93 +}
    1.94 +
    1.95 +static void
    1.96 +pasteTextCB(AtkEditableText *aText, gint aPosition)
    1.97 +{
    1.98 +  AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
    1.99 +  if (!accWrap)
   1.100 +    return;
   1.101 +
   1.102 +  HyperTextAccessible* text = accWrap->AsHyperText();
   1.103 +  if (!text || !text->IsTextRole())
   1.104 +    return;
   1.105 +
   1.106 +  text->PasteText(aPosition);
   1.107 +}
   1.108 +}
   1.109 +
   1.110 +void
   1.111 +editableTextInterfaceInitCB(AtkEditableTextIface* aIface)
   1.112 +{
   1.113 +  NS_ASSERTION(aIface, "Invalid aIface");
   1.114 +  if (MOZ_UNLIKELY(!aIface))
   1.115 +    return;
   1.116 +
   1.117 +  aIface->set_text_contents = setTextContentsCB;
   1.118 +  aIface->insert_text = insertTextCB;
   1.119 +  aIface->copy_text = copyTextCB;
   1.120 +  aIface->cut_text = cutTextCB;
   1.121 +  aIface->delete_text = deleteTextCB;
   1.122 +  aIface->paste_text = pasteTextCB;
   1.123 +}

mercurial