Home | History | Annotate | Download | only in gtk
      1 /*
      2  * Copyright (C) 2008 Apple Inc. All Rights Reserved.
      3  * Copyright (C) 2009 Jan Michael Alonzo
      4  *
      5  * Redistribution and use in source and binary forms, with or without
      6  * modification, are permitted provided that the following conditions
      7  * are met:
      8  * 1. Redistributions of source code must retain the above copyright
      9  *    notice, this list of conditions and the following disclaimer.
     10  * 2. Redistributions in binary form must reproduce the above copyright
     11  *    notice, this list of conditions and the following disclaimer in the
     12  *    documentation and/or other materials provided with the distribution.
     13  *
     14  * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
     15  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     17  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
     18  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     19  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     20  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     21  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
     22  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     24  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     25  */
     26 
     27 #include "config.h"
     28 #include "AccessibilityUIElement.h"
     29 
     30 #include <JavaScriptCore/JSStringRef.h>
     31 #include <wtf/Assertions.h>
     32 
     33 #include <atk/atk.h>
     34 #include <gtk/gtk.h>
     35 
     36 
     37 AccessibilityUIElement::AccessibilityUIElement(PlatformUIElement element)
     38     : m_element(element)
     39 {
     40 }
     41 
     42 AccessibilityUIElement::AccessibilityUIElement(const AccessibilityUIElement& other)
     43     : m_element(other.m_element)
     44 {
     45 }
     46 
     47 AccessibilityUIElement::~AccessibilityUIElement()
     48 {
     49 }
     50 
     51 void AccessibilityUIElement::getLinkedUIElements(Vector<AccessibilityUIElement>& elements)
     52 {
     53     // FIXME: implement
     54 }
     55 
     56 void AccessibilityUIElement::getDocumentLinks(Vector<AccessibilityUIElement>&)
     57 {
     58     // FIXME: implement
     59 }
     60 
     61 void AccessibilityUIElement::getChildren(Vector<AccessibilityUIElement>& children)
     62 {
     63     int count = childrenCount();
     64     for (int i = 0; i < count; i++) {
     65         AtkObject* child = atk_object_ref_accessible_child(ATK_OBJECT(m_element), i);
     66         children.append(AccessibilityUIElement(child));
     67     }
     68 }
     69 
     70 void AccessibilityUIElement::getChildrenWithRange(Vector<AccessibilityUIElement>& elementVector, unsigned start, unsigned end)
     71 {
     72     for (unsigned i = start; i < end; i++) {
     73         AtkObject* child = atk_object_ref_accessible_child(ATK_OBJECT(m_element), i);
     74         elementVector.append(AccessibilityUIElement(child));
     75     }
     76 }
     77 
     78 int AccessibilityUIElement::childrenCount()
     79 {
     80     if (!m_element)
     81         return 0;
     82 
     83     ASSERT(ATK_IS_OBJECT(m_element));
     84 
     85     return atk_object_get_n_accessible_children(ATK_OBJECT(m_element));
     86 }
     87 
     88 AccessibilityUIElement AccessibilityUIElement::elementAtPoint(int x, int y)
     89 {
     90     // FIXME: implement
     91     return 0;
     92 }
     93 
     94 AccessibilityUIElement AccessibilityUIElement::getChildAtIndex(unsigned index)
     95 {
     96     Vector<AccessibilityUIElement> children;
     97     getChildrenWithRange(children, index, index + 1);
     98 
     99     if (children.size() == 1)
    100         return children.at(0);
    101 
    102     return 0;
    103 }
    104 
    105 unsigned AccessibilityUIElement::indexOfChild(AccessibilityUIElement* element)
    106 {
    107     // FIXME: implement
    108     return 0;
    109 }
    110 
    111 JSStringRef AccessibilityUIElement::allAttributes()
    112 {
    113     // FIXME: implement
    114     return JSStringCreateWithCharacters(0, 0);
    115 }
    116 
    117 JSStringRef AccessibilityUIElement::attributesOfLinkedUIElements()
    118 {
    119     // FIXME: implement
    120     return JSStringCreateWithCharacters(0, 0);
    121 }
    122 
    123 JSStringRef AccessibilityUIElement::attributesOfDocumentLinks()
    124 {
    125     // FIXME: implement
    126     return JSStringCreateWithCharacters(0, 0);
    127 }
    128 
    129 AccessibilityUIElement AccessibilityUIElement::titleUIElement()
    130 {
    131     // FIXME: implement
    132     return 0;
    133 }
    134 
    135 AccessibilityUIElement AccessibilityUIElement::parentElement()
    136 {
    137     ASSERT(m_element);
    138     AtkObject* parent =  atk_object_get_parent(ATK_OBJECT(m_element));
    139 
    140     return parent ? AccessibilityUIElement(parent) : 0;
    141 }
    142 
    143 JSStringRef AccessibilityUIElement::attributesOfChildren()
    144 {
    145     // FIXME: implement
    146     return JSStringCreateWithCharacters(0, 0);
    147 }
    148 
    149 JSStringRef AccessibilityUIElement::parameterizedAttributeNames()
    150 {
    151     // FIXME: implement
    152     return JSStringCreateWithCharacters(0, 0);
    153 }
    154 
    155 JSStringRef AccessibilityUIElement::role()
    156 {
    157     AtkRole role = atk_object_get_role(ATK_OBJECT(m_element));
    158 
    159     if (!role)
    160         return JSStringCreateWithCharacters(0, 0);
    161 
    162     return JSStringCreateWithUTF8CString(atk_role_get_name(role));
    163 }
    164 
    165 JSStringRef AccessibilityUIElement::subrole()
    166 {
    167     return 0;
    168 }
    169 
    170 JSStringRef AccessibilityUIElement::roleDescription()
    171 {
    172     return 0;
    173 }
    174 
    175 JSStringRef AccessibilityUIElement::title()
    176 {
    177     const gchar* name = atk_object_get_name(ATK_OBJECT(m_element));
    178 
    179     if (!name)
    180         return JSStringCreateWithCharacters(0, 0);
    181 
    182     return JSStringCreateWithUTF8CString(name);
    183 }
    184 
    185 JSStringRef AccessibilityUIElement::description()
    186 {
    187     const gchar* description = atk_object_get_description(ATK_OBJECT(m_element));
    188 
    189     if (!description)
    190         return JSStringCreateWithCharacters(0, 0);
    191 
    192     return JSStringCreateWithUTF8CString(description);
    193 }
    194 
    195 JSStringRef AccessibilityUIElement::stringValue()
    196 {
    197     // FIXME: implement
    198     return JSStringCreateWithCharacters(0, 0);
    199 }
    200 
    201 JSStringRef AccessibilityUIElement::language()
    202 {
    203     // FIXME: implement
    204     return JSStringCreateWithCharacters(0, 0);
    205 }
    206 
    207 double AccessibilityUIElement::x()
    208 {
    209     int x, y;
    210 
    211     atk_component_get_position(ATK_COMPONENT(m_element), &x, &y, ATK_XY_SCREEN);
    212 
    213     return x;
    214 }
    215 
    216 double AccessibilityUIElement::y()
    217 {
    218     int x, y;
    219 
    220     atk_component_get_position(ATK_COMPONENT(m_element), &x, &y, ATK_XY_SCREEN);
    221 
    222     return y;
    223 }
    224 
    225 double AccessibilityUIElement::width()
    226 {
    227     int width, height;
    228 
    229     atk_component_get_size(ATK_COMPONENT(m_element), &width, &height);
    230 
    231     return width;
    232 }
    233 
    234 double AccessibilityUIElement::height()
    235 {
    236     int width, height;
    237 
    238     atk_component_get_size(ATK_COMPONENT(m_element), &width, &height);
    239 
    240     return height;
    241 }
    242 
    243 double AccessibilityUIElement::clickPointX()
    244 {
    245     return 0.f;
    246 }
    247 
    248 double AccessibilityUIElement::clickPointY()
    249 {
    250     return 0.f;
    251 }
    252 
    253 JSStringRef AccessibilityUIElement::orientation() const
    254 {
    255     return 0;
    256 }
    257 
    258 double AccessibilityUIElement::intValue() const
    259 {
    260     GValue value = { 0, { { 0 } } };
    261 
    262     if (!ATK_IS_VALUE(m_element))
    263         return 0.0f;
    264 
    265     atk_value_get_current_value(ATK_VALUE(m_element), &value);
    266 
    267     if (G_VALUE_HOLDS_DOUBLE(&value))
    268         return g_value_get_double(&value);
    269     else if (G_VALUE_HOLDS_INT(&value))
    270         return static_cast<double>(g_value_get_int(&value));
    271     else
    272         return 0.0f;
    273 }
    274 
    275 double AccessibilityUIElement::minValue()
    276 {
    277     GValue value = { 0, { { 0 } } };
    278 
    279     if (!ATK_IS_VALUE(m_element))
    280         return 0.0f;
    281 
    282     atk_value_get_minimum_value(ATK_VALUE(m_element), &value);
    283 
    284     if (G_VALUE_HOLDS_DOUBLE(&value))
    285         return g_value_get_double(&value);
    286     else if (G_VALUE_HOLDS_INT(&value))
    287         return static_cast<double>(g_value_get_int(&value));
    288     else
    289         return 0.0f;
    290 }
    291 
    292 double AccessibilityUIElement::maxValue()
    293 {
    294     GValue value = { 0, { { 0 } } };
    295 
    296     if (!ATK_IS_VALUE(m_element))
    297         return 0.0f;
    298 
    299     atk_value_get_maximum_value(ATK_VALUE(m_element), &value);
    300 
    301     if (G_VALUE_HOLDS_DOUBLE(&value))
    302         return g_value_get_double(&value);
    303     else if (G_VALUE_HOLDS_INT(&value))
    304         return static_cast<double>(g_value_get_int(&value));
    305     else
    306         return 0.0f;
    307 }
    308 
    309 JSStringRef AccessibilityUIElement::valueDescription()
    310 {
    311     // FIXME: implement
    312     return JSStringCreateWithCharacters(0, 0);
    313 }
    314 
    315 bool AccessibilityUIElement::isEnabled()
    316 {
    317     // FIXME: implement
    318     return false;
    319 }
    320 
    321 
    322 int AccessibilityUIElement::insertionPointLineNumber()
    323 {
    324     // FIXME: implement
    325     return 0;
    326 }
    327 
    328 bool AccessibilityUIElement::isActionSupported(JSStringRef action)
    329 {
    330     // FIXME: implement
    331     return false;
    332 }
    333 
    334 bool AccessibilityUIElement::isRequired() const
    335 {
    336     // FIXME: implement
    337     return false;
    338 }
    339 
    340 bool AccessibilityUIElement::isSelected() const
    341 {
    342     // FIXME: implement
    343     return false;
    344 }
    345 
    346 int AccessibilityUIElement::hierarchicalLevel() const
    347 {
    348     // FIXME: implement
    349     return 0;
    350 }
    351 
    352 bool AccessibilityUIElement::ariaIsGrabbed() const
    353 {
    354     return false;
    355 }
    356 
    357 JSStringRef AccessibilityUIElement::ariaDropEffects() const
    358 {
    359     return 0;
    360 }
    361 
    362 bool AccessibilityUIElement::isExpanded() const
    363 {
    364     // FIXME: implement
    365     return false;
    366 }
    367 
    368 bool AccessibilityUIElement::isChecked() const
    369 {
    370     return intValue();
    371 }
    372 
    373 JSStringRef AccessibilityUIElement::attributesOfColumnHeaders()
    374 {
    375     // FIXME: implement
    376     return JSStringCreateWithCharacters(0, 0);
    377 }
    378 
    379 JSStringRef AccessibilityUIElement::attributesOfRowHeaders()
    380 {
    381     // FIXME: implement
    382     return JSStringCreateWithCharacters(0, 0);
    383 }
    384 
    385 JSStringRef AccessibilityUIElement::attributesOfColumns()
    386 {
    387     // FIXME: implement
    388     return JSStringCreateWithCharacters(0, 0);
    389 }
    390 
    391 JSStringRef AccessibilityUIElement::attributesOfRows()
    392 {
    393     // FIXME: implement
    394     return JSStringCreateWithCharacters(0, 0);
    395 }
    396 
    397 JSStringRef AccessibilityUIElement::attributesOfVisibleCells()
    398 {
    399     // FIXME: implement
    400     return JSStringCreateWithCharacters(0, 0);
    401 }
    402 
    403 JSStringRef AccessibilityUIElement::attributesOfHeader()
    404 {
    405     // FIXME: implement
    406     return JSStringCreateWithCharacters(0, 0);
    407 }
    408 
    409 int AccessibilityUIElement::indexInTable()
    410 {
    411     // FIXME: implement
    412     return 0;
    413 }
    414 
    415 JSStringRef AccessibilityUIElement::rowIndexRange()
    416 {
    417     // FIXME: implement
    418     return JSStringCreateWithCharacters(0, 0);
    419 }
    420 
    421 JSStringRef AccessibilityUIElement::columnIndexRange()
    422 {
    423     // FIXME: implement
    424     return JSStringCreateWithCharacters(0, 0);
    425 }
    426 
    427 int AccessibilityUIElement::lineForIndex(int)
    428 {
    429     // FIXME: implement
    430     return 0;
    431 }
    432 
    433 JSStringRef AccessibilityUIElement::boundsForRange(unsigned location, unsigned length)
    434 {
    435     // FIXME: implement
    436     return JSStringCreateWithCharacters(0, 0);
    437 }
    438 
    439 JSStringRef AccessibilityUIElement::stringForRange(unsigned, unsigned)
    440 {
    441     // FIXME: implement
    442     return JSStringCreateWithCharacters(0, 0);
    443 }
    444 
    445 AccessibilityUIElement AccessibilityUIElement::cellForColumnAndRow(unsigned column, unsigned row)
    446 {
    447     // FIXME: implement
    448     return 0;
    449 }
    450 
    451 JSStringRef AccessibilityUIElement::selectedTextRange()
    452 {
    453     // FIXME: implement
    454     return JSStringCreateWithCharacters(0, 0);
    455 }
    456 
    457 void AccessibilityUIElement::setSelectedTextRange(unsigned location, unsigned length)
    458 {
    459     // FIXME: implement
    460 }
    461 
    462 JSStringRef AccessibilityUIElement::stringAttributeValue(JSStringRef attribute)
    463 {
    464     // FIXME: implement
    465     return JSStringCreateWithCharacters(0, 0);
    466 }
    467 
    468 bool AccessibilityUIElement::boolAttributeValue(JSStringRef attribute)
    469 {
    470     // FIXME: implement
    471     return false;
    472 }
    473 
    474 bool AccessibilityUIElement::isAttributeSettable(JSStringRef attribute)
    475 {
    476     // FIXME: implement
    477     return false;
    478 }
    479 
    480 bool AccessibilityUIElement::isAttributeSupported(JSStringRef attribute)
    481 {
    482     return false;
    483 }
    484 
    485 void AccessibilityUIElement::increment()
    486 {
    487     // FIXME: implement
    488 }
    489 
    490 void AccessibilityUIElement::decrement()
    491 {
    492     // FIXME: implement
    493 }
    494 
    495 void AccessibilityUIElement::showMenu()
    496 {
    497     // FIXME: implement
    498 }
    499 
    500 AccessibilityUIElement AccessibilityUIElement::disclosedRowAtIndex(unsigned index)
    501 {
    502     return 0;
    503 }
    504 
    505 AccessibilityUIElement AccessibilityUIElement::ariaOwnsElementAtIndex(unsigned index)
    506 {
    507     return 0;
    508 }
    509 
    510 AccessibilityUIElement AccessibilityUIElement::ariaFlowToElementAtIndex(unsigned index)
    511 {
    512     return 0;
    513 }
    514 
    515 AccessibilityUIElement AccessibilityUIElement::selectedRowAtIndex(unsigned index)
    516 {
    517     return 0;
    518 }
    519 
    520 AccessibilityUIElement AccessibilityUIElement::disclosedByRow()
    521 {
    522     return 0;
    523 }
    524 
    525 JSStringRef AccessibilityUIElement::accessibilityValue() const
    526 {
    527     // FIXME: implement
    528     return JSStringCreateWithCharacters(0, 0);
    529 }
    530 
    531 JSStringRef AccessibilityUIElement::documentEncoding()
    532 {
    533     AtkRole role = atk_object_get_role(ATK_OBJECT(m_element));
    534     if (role != ATK_ROLE_DOCUMENT_FRAME)
    535         return JSStringCreateWithCharacters(0, 0);
    536 
    537     return JSStringCreateWithUTF8CString(atk_document_get_attribute_value(ATK_DOCUMENT(m_element), "Encoding"));
    538 }
    539 
    540 JSStringRef AccessibilityUIElement::documentURI()
    541 {
    542     AtkRole role = atk_object_get_role(ATK_OBJECT(m_element));
    543     if (role != ATK_ROLE_DOCUMENT_FRAME)
    544         return JSStringCreateWithCharacters(0, 0);
    545 
    546     return JSStringCreateWithUTF8CString(atk_document_get_attribute_value(ATK_DOCUMENT(m_element), "URI"));
    547 }
    548 
    549 JSStringRef AccessibilityUIElement::url()
    550 {
    551     // FIXME: implement
    552     return JSStringCreateWithCharacters(0, 0);
    553 }
    554 
    555 bool AccessibilityUIElement::addNotificationListener(JSObjectRef functionCallback)
    556 {
    557     // FIXME: implement
    558     return false;
    559 }
    560 
    561 bool AccessibilityUIElement::isSelectable() const
    562 {
    563     // FIXME: implement
    564     return false;
    565 }
    566 
    567 bool AccessibilityUIElement::isMultiSelectable() const
    568 {
    569     // FIXME: implement
    570     return false;
    571 }
    572 
    573 bool AccessibilityUIElement::isVisible() const
    574 {
    575     // FIXME: implement
    576     return false;
    577 }
    578 
    579 bool AccessibilityUIElement::isOffScreen() const
    580 {
    581     // FIXME: implement
    582     return false;
    583 }
    584 
    585 bool AccessibilityUIElement::isCollapsed() const
    586 {
    587     // FIXME: implement
    588     return false;
    589 }
    590 
    591 bool AccessibilityUIElement::hasPopup() const
    592 {
    593     // FIXME: implement
    594     return false;
    595 }
    596 
    597 void AccessibilityUIElement::takeFocus()
    598 {
    599     // FIXME: implement
    600 }
    601 
    602 void AccessibilityUIElement::takeSelection()
    603 {
    604     // FIXME: implement
    605 }
    606 
    607 void AccessibilityUIElement::addSelection()
    608 {
    609     // FIXME: implement
    610 }
    611 
    612 void AccessibilityUIElement::removeSelection()
    613 {
    614     // FIXME: implement
    615 }
    616