| 1 | /* |
| 2 | * Copyright (C) 2008 Nuanti Ltd. |
| 3 | * Copyright (C) 2009 Jan Alonzo |
| 4 | * Copyright (C) 2011, 2012 Igalia S.L. |
| 5 | * |
| 6 | * Portions from Mozilla a11y, copyright as follows: |
| 7 | * |
| 8 | * The Original Code is mozilla.org code. |
| 9 | * |
| 10 | * The Initial Developer of the Original Code is |
| 11 | * Sun Microsystems, Inc. |
| 12 | * Portions created by the Initial Developer are Copyright (C) 2002 |
| 13 | * the Initial Developer. All Rights Reserved. |
| 14 | * |
| 15 | * This library is free software; you can redistribute it and/or |
| 16 | * modify it under the terms of the GNU Library General Public |
| 17 | * License as published by the Free Software Foundation; either |
| 18 | * version 2 of the License, or (at your option) any later version. |
| 19 | * |
| 20 | * This library is distributed in the hope that it will be useful, |
| 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 23 | * Library General Public License for more details. |
| 24 | * |
| 25 | * You should have received a copy of the GNU Library General Public License |
| 26 | * along with this library; see the file COPYING.LIB. If not, write to |
| 27 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 28 | * Boston, MA 02110-1301, USA. |
| 29 | */ |
| 30 | |
| 31 | #include "config.h" |
| 32 | #include "WebKitAccessibleInterfaceEditableText.h" |
| 33 | |
| 34 | #if HAVE(ACCESSIBILITY) |
| 35 | |
| 36 | #include "AccessibilityObject.h" |
| 37 | #include "Document.h" |
| 38 | #include "Editor.h" |
| 39 | #include "Frame.h" |
| 40 | #include "NotImplemented.h" |
| 41 | #include "WebKitAccessible.h" |
| 42 | #include "WebKitAccessibleUtil.h" |
| 43 | |
| 44 | using namespace WebCore; |
| 45 | |
| 46 | static AccessibilityObject* core(AtkEditableText* text) |
| 47 | { |
| 48 | if (!WEBKIT_IS_ACCESSIBLE(text)) |
| 49 | return 0; |
| 50 | |
| 51 | return &webkitAccessibleGetAccessibilityObject(WEBKIT_ACCESSIBLE(text)); |
| 52 | } |
| 53 | |
| 54 | static gboolean webkitAccessibleEditableTextSetRunAttributes(AtkEditableText* text, AtkAttributeSet*, gint, gint) |
| 55 | { |
| 56 | g_return_val_if_fail(ATK_IS_EDITABLE_TEXT(text), FALSE); |
| 57 | returnValIfWebKitAccessibleIsInvalid(WEBKIT_ACCESSIBLE(text), FALSE); |
| 58 | |
| 59 | notImplemented(); |
| 60 | return FALSE; |
| 61 | } |
| 62 | |
| 63 | static void webkitAccessibleEditableTextSetTextContents(AtkEditableText* text, const gchar* string) |
| 64 | { |
| 65 | g_return_if_fail(ATK_IS_EDITABLE_TEXT(text)); |
| 66 | returnIfWebKitAccessibleIsInvalid(WEBKIT_ACCESSIBLE(text)); |
| 67 | |
| 68 | // FIXME: string nullcheck? |
| 69 | core(text)->setValue(String::fromUTF8(string)); |
| 70 | } |
| 71 | |
| 72 | static void webkitAccessibleEditableTextInsertText(AtkEditableText* text, const gchar* string, gint length, gint* position) |
| 73 | { |
| 74 | g_return_if_fail(ATK_IS_EDITABLE_TEXT(text)); |
| 75 | returnIfWebKitAccessibleIsInvalid(WEBKIT_ACCESSIBLE(text)); |
| 76 | |
| 77 | if (!string) |
| 78 | return; |
| 79 | |
| 80 | AccessibilityObject* coreObject = core(text); |
| 81 | // FIXME: Not implemented in WebCore |
| 82 | // coreObject->setSelectedTextRange(PlainTextRange(*position, 0)); |
| 83 | // coreObject->setSelectedText(String::fromUTF8(string)); |
| 84 | |
| 85 | Document* document = coreObject->document(); |
| 86 | if (!document || !document->frame()) |
| 87 | return; |
| 88 | |
| 89 | coreObject->setSelectedVisiblePositionRange(coreObject->visiblePositionRangeForRange(PlainTextRange(*position, 0))); |
| 90 | coreObject->setFocused(true); |
| 91 | // FIXME: We should set position to the actual inserted text length, which may be less than that requested. |
| 92 | if (document->frame()->editor().insertTextWithoutSendingTextEvent(String::fromUTF8(string).substring(0, length), false, 0)) |
| 93 | *position += length; |
| 94 | } |
| 95 | |
| 96 | static void webkitAccessibleEditableTextCopyText(AtkEditableText* text, gint, gint) |
| 97 | { |
| 98 | g_return_if_fail(ATK_IS_EDITABLE_TEXT(text)); |
| 99 | returnIfWebKitAccessibleIsInvalid(WEBKIT_ACCESSIBLE(text)); |
| 100 | |
| 101 | notImplemented(); |
| 102 | } |
| 103 | |
| 104 | static void webkitAccessibleEditableTextCutText(AtkEditableText* text, gint, gint) |
| 105 | { |
| 106 | g_return_if_fail(ATK_IS_EDITABLE_TEXT(text)); |
| 107 | returnIfWebKitAccessibleIsInvalid(WEBKIT_ACCESSIBLE(text)); |
| 108 | |
| 109 | notImplemented(); |
| 110 | } |
| 111 | |
| 112 | static void webkitAccessibleEditableTextDeleteText(AtkEditableText* text, gint startPos, gint endPos) |
| 113 | { |
| 114 | g_return_if_fail(ATK_IS_EDITABLE_TEXT(text)); |
| 115 | returnIfWebKitAccessibleIsInvalid(WEBKIT_ACCESSIBLE(text)); |
| 116 | |
| 117 | AccessibilityObject* coreObject = core(text); |
| 118 | // FIXME: Not implemented in WebCore |
| 119 | // coreObject->setSelectedTextRange(PlainTextRange(startPos, endPos - startPos)); |
| 120 | // coreObject->setSelectedText(String()); |
| 121 | |
| 122 | Document* document = coreObject->document(); |
| 123 | if (!document || !document->frame()) |
| 124 | return; |
| 125 | |
| 126 | coreObject->setSelectedVisiblePositionRange(coreObject->visiblePositionRangeForRange(PlainTextRange(startPos, endPos - startPos))); |
| 127 | coreObject->setFocused(true); |
| 128 | document->frame()->editor().performDelete(); |
| 129 | } |
| 130 | |
| 131 | static void webkitAccessibleEditableTextPasteText(AtkEditableText* text, gint) |
| 132 | { |
| 133 | g_return_if_fail(ATK_IS_EDITABLE_TEXT(text)); |
| 134 | returnIfWebKitAccessibleIsInvalid(WEBKIT_ACCESSIBLE(text)); |
| 135 | |
| 136 | notImplemented(); |
| 137 | } |
| 138 | |
| 139 | void webkitAccessibleEditableTextInterfaceInit(AtkEditableTextIface* iface) |
| 140 | { |
| 141 | iface->set_run_attributes = webkitAccessibleEditableTextSetRunAttributes; |
| 142 | iface->set_text_contents = webkitAccessibleEditableTextSetTextContents; |
| 143 | iface->insert_text = webkitAccessibleEditableTextInsertText; |
| 144 | iface->copy_text = webkitAccessibleEditableTextCopyText; |
| 145 | iface->cut_text = webkitAccessibleEditableTextCutText; |
| 146 | iface->delete_text = webkitAccessibleEditableTextDeleteText; |
| 147 | iface->paste_text = webkitAccessibleEditableTextPasteText; |
| 148 | } |
| 149 | |
| 150 | #endif |
| 151 | |