⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 accessibilityobjectwrapperatk.cpp

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (C) 2008 Nuanti Ltd. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB.  If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */#include "config.h"#include "AccessibilityObjectWrapperAtk.h"#if HAVE(ACCESSIBILITY)#include "AXObjectCache.h"#include "AccessibilityListBox.h"#include "AccessibilityRenderObject.h"#include "AtomicString.h"#include "CString.h"#include "Document.h"#include "Editor.h"#include "Frame.h"#include "FrameView.h"#include "IntRect.h"#include "NotImplemented.h"#include <atk/atk.h>using namespace WebCore;// Used to provide const char* returns.static const char* returnString(const String& str){    static CString returnedString;    returnedString = str.utf8();    return returnedString.data();}static AccessibilityObject* core(WebKitAccessible* accessible){    if (!accessible)        return 0;    return accessible->m_object;}static AccessibilityObject* core(AtkObject* object){    if (!WEBKIT_IS_ACCESSIBLE(object))        return 0;    return core(WEBKIT_ACCESSIBLE(object));}static AccessibilityObject* core(AtkAction* action){    return core(ATK_OBJECT(action));}static AccessibilityObject* core(AtkStreamableContent* streamable){    return core(ATK_OBJECT(streamable));}static AccessibilityObject* core(AtkText* text){    return core(ATK_OBJECT(text));}static AccessibilityObject* core(AtkEditableText* text){    return core(ATK_OBJECT(text));}extern "C" {static gpointer parent_class = NULL;static void webkit_accessible_init(AtkObject* object, gpointer data){    g_return_if_fail(WEBKIT_IS_ACCESSIBLE(object));    g_return_if_fail(data);    if (ATK_OBJECT_CLASS(parent_class)->initialize)        ATK_OBJECT_CLASS(parent_class)->initialize(object, data);    WEBKIT_ACCESSIBLE(object)->m_object = reinterpret_cast<AccessibilityObject*>(data);}static void webkit_accessible_finalize(GObject* object){    // This is a good time to clear the return buffer.    returnString(String());    if (G_OBJECT_CLASS(parent_class)->finalize)        G_OBJECT_CLASS(parent_class)->finalize(object);}static const gchar* webkit_accessible_get_name(AtkObject* object){    // TODO: Deal with later changes.    if (!object->name)        atk_object_set_name(object, core(object)->stringValue().utf8().data());    return object->name;}static const gchar* webkit_accessible_get_description(AtkObject* object){    // TODO: the Mozilla MSAA implementation prepends "Description: "    // Should we do this too?    // TODO: Deal with later changes.    if (!object->description)        atk_object_set_description(object, core(object)->accessibilityDescription().utf8().data());    return object->description;}static AtkObject* webkit_accessible_get_parent(AtkObject* object){    AccessibilityObject* coreParent = core(object)->parentObject();    if (!coreParent)        return NULL;    return coreParent->wrapper();}static gint webkit_accessible_get_n_children(AtkObject* object){    return core(object)->children().size();}static AtkObject* webkit_accessible_ref_child(AtkObject* object, gint index){    AccessibilityObject* coreObject = core(object);    g_return_val_if_fail(index >= 0, NULL);    g_return_val_if_fail(static_cast<size_t>(index) < coreObject->children().size(), NULL);    AccessibilityObject* coreChild = coreObject->children().at(index).get();    if (!coreChild)        return NULL;    AtkObject* child = coreChild->wrapper();    // TODO: Should we call atk_object_set_parent() here?    //atk_object_set_parent(child, object);    g_object_ref(child);    return child;}static gint webkit_accessible_get_index_in_parent(AtkObject* object){    // FIXME: This needs to be implemented.    notImplemented();    return 0;}static AtkRole atkRole(AccessibilityRole role){    switch (role) {    case WebCore::ButtonRole:        return ATK_ROLE_PUSH_BUTTON;    case WebCore::RadioButtonRole:        return ATK_ROLE_RADIO_BUTTON;    case WebCore::CheckBoxRole:        return ATK_ROLE_CHECK_BOX;    case WebCore::SliderRole:        return ATK_ROLE_SLIDER;    case WebCore::TabGroupRole:        return ATK_ROLE_PAGE_TAB_LIST;    case WebCore::TextFieldRole:    case WebCore::TextAreaRole:    case WebCore::ListMarkerRole:        return ATK_ROLE_ENTRY;    case WebCore::StaticTextRole:        return ATK_ROLE_TEXT; //?    case WebCore::OutlineRole:        return ATK_ROLE_TREE;    case WebCore::ColumnRole:        return ATK_ROLE_UNKNOWN; //?    case WebCore::RowRole:        return ATK_ROLE_LIST_ITEM;    case WebCore::GroupRole:        return ATK_ROLE_UNKNOWN; //?    case WebCore::ListRole:        return ATK_ROLE_LIST;    case WebCore::TableRole:        return ATK_ROLE_TABLE;    case WebCore::LinkRole:    case WebCore::WebCoreLinkRole:        return ATK_ROLE_LINK;    case WebCore::ImageMapRole:    case WebCore::ImageRole:        return ATK_ROLE_IMAGE;    default:        return ATK_ROLE_UNKNOWN;    }}static AtkRole webkit_accessible_get_role(AtkObject* object){    return atkRole(core(object)->roleValue());}static void webkit_accessible_class_init(AtkObjectClass* klass){    GObjectClass* gobject_class = G_OBJECT_CLASS(klass);    parent_class = g_type_class_peek_parent(klass);    klass->initialize = webkit_accessible_init;    gobject_class->finalize = webkit_accessible_finalize;    klass->get_name = webkit_accessible_get_name;    klass->get_description = webkit_accessible_get_description;    klass->get_parent = webkit_accessible_get_parent;    klass->get_n_children = webkit_accessible_get_n_children;    klass->ref_child = webkit_accessible_ref_child;    //klass->get_index_in_parent = webkit_accessible_get_index_in_parent;    klass->get_role = webkit_accessible_get_role;    //klass->get_attributes = webkit_accessible_get_attributes;    //klass->ref_state_set = webkit_accessible_ref_state_set;    //klass->ref_relation_set = webkit_accessible_ref_relation_set;}static gboolean webkit_accessible_action_do_action(AtkAction* action, gint i){    g_return_val_if_fail(i == 0, FALSE);    return core(action)->performDefaultAction();}static gint webkit_accessible_action_get_n_actions(AtkAction* action){    return 1;}static const gchar* webkit_accessible_action_get_description(AtkAction* action, gint i){    g_return_val_if_fail(i == 0, NULL);    // TODO: Need a way to provide/localize action descriptions.    notImplemented();    return "";}static const gchar* webkit_accessible_action_get_keybinding(AtkAction* action, gint i){    g_return_val_if_fail(i == 0, NULL);    // FIXME: Construct a proper keybinding string.    return returnString(core(action)->accessKey().string());}static const gchar* webkit_accessible_action_get_name(AtkAction* action, gint i){    g_return_val_if_fail(i == 0, NULL);    return returnString(core(action)->actionVerb());}static void atk_action_interface_init(AtkActionIface* iface){    g_return_if_fail(iface);    iface->do_action = webkit_accessible_action_do_action;    iface->get_n_actions = webkit_accessible_action_get_n_actions;    iface->get_description = webkit_accessible_action_get_description;    iface->get_keybinding = webkit_accessible_action_get_keybinding;    iface->get_name = webkit_accessible_action_get_name;}// Textstatic gchar* webkit_accessible_text_get_text(AtkText* text, gint start_offset, gint end_offset){    String ret = core(text)->doAXStringForRange(PlainTextRange(start_offset, end_offset - start_offset));    // TODO: Intentionally copied?    return g_strdup(ret.utf8().data());}static gchar* webkit_accessible_text_get_text_after_offset(AtkText* text, gint offset, AtkTextBoundary boundary_type, gint* start_offset, gint* end_offset){    notImplemented();    return NULL;}static gchar* webkit_accessible_text_get_text_at_offset(AtkText* text, gint offset, AtkTextBoundary boundary_type, gint* start_offset, gint* end_offset){    notImplemented();    return NULL;}static gunichar webkit_accessible_text_get_character_at_offset(AtkText* text, gint offset){    notImplemented();    return 0;}static gchar* webkit_accessible_text_get_text_before_offset(AtkText* text, gint offset, AtkTextBoundary boundary_type, gint* start_offset, gint* end_offset){    notImplemented();    return NULL;}static gint webkit_accessible_text_get_caret_offset(AtkText* text){    // TODO: Verify this, especially for RTL text.    return core(text)->selectionStart();}static AtkAttributeSet* webkit_accessible_text_get_run_attributes(AtkText* text, gint offset, gint* start_offset, gint* end_offset){    notImplemented();    return NULL;}static AtkAttributeSet* webkit_accessible_text_get_default_attributes(AtkText* text){    notImplemented();    return NULL;}static void webkit_accessible_text_get_character_extents(AtkText* text, gint offset, gint* x, gint* y, gint* width, gint* height, AtkCoordType coords){    IntRect extents = core(text)->doAXBoundsForRange(PlainTextRange(offset, 1));    // FIXME: Use the AtkCoordType    // Requires WebCore::ScrollView::contentsToScreen() to be implemented#if 0    switch(coords) {    case ATK_XY_SCREEN:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -