2 * Copyright (C) 2009 Igalia S.L.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
21 #include "FrameSelection.h"
23 #include "AccessibilityObjectWrapperAtk.h"
24 #include "AXObjectCache.h"
32 static void emitTextSelectionChange(AccessibilityObject* object, VisibleSelection selection, int offset)
34 AtkObject* axObject = object->wrapper();
35 if (!axObject || !ATK_IS_TEXT(axObject))
38 g_signal_emit_by_name(axObject, "text-caret-moved", offset);
39 if (selection.isRange())
40 g_signal_emit_by_name(axObject, "text-selection-changed");
43 static void maybeEmitTextFocusChange(PassRefPtr<AccessibilityObject> prpObject)
45 // This static variable is needed to keep track of the old object
46 // as per previous calls to this function, in order to properly
47 // decide whether to emit some signals or not.
48 DEFINE_STATIC_LOCAL(RefPtr<AccessibilityObject>, oldObject, ());
50 RefPtr<AccessibilityObject> object = prpObject;
52 // Ensure the oldObject belongs to the same document that the
53 // current object so further comparisons make sense. Otherwise,
54 // just reset oldObject to 0 so it won't be taken into account in
55 // the immediately following call to this function.
56 if (object && oldObject && oldObject->document() != object->document())
59 AtkObject* axObject = object ? object->wrapper() : 0;
60 AtkObject* oldAxObject = oldObject ? oldObject->wrapper() : 0;
62 if (axObject != oldAxObject) {
63 if (oldAxObject && ATK_IS_TEXT(oldAxObject)) {
64 g_signal_emit_by_name(oldAxObject, "focus-event", false);
65 g_signal_emit_by_name(oldAxObject, "state-change", "focused", false);
67 if (axObject && ATK_IS_TEXT(axObject)) {
68 g_signal_emit_by_name(axObject, "focus-event", true);
69 g_signal_emit_by_name(axObject, "state-change", "focused", true);
73 // Update pointer to last focused object.
78 void FrameSelection::notifyAccessibilityForSelectionChange()
80 if (!AXObjectCache::accessibilityEnabled())
83 // Reset lastFocuseNode and return for no valid selections.
84 if (!m_selection.start().isNotNull() || !m_selection.end().isNotNull())
87 RenderObject* focusedNode = m_selection.end().deprecatedNode()->renderer();
88 AccessibilityObject* accessibilityObject = m_frame->document()->axObjectCache()->getOrCreate(focusedNode);
90 // Need to check this as getOrCreate could return 0,
91 if (!accessibilityObject)
95 // Always report the events w.r.t. the non-linked unignored parent. (i.e. ignoreLinks == true).
96 RefPtr<AccessibilityObject> object = objectAndOffsetUnignored(accessibilityObject, offset, true);
100 // Emit relatedsignals.
101 emitTextSelectionChange(object.get(), m_selection, offset);
102 maybeEmitTextFocusChange(object.release());
105 } // namespace WebCore