Home | History | Annotate | Download | only in chromium
      1 /*
      2  * Copyright (C) 2008 Apple Inc. All Rights Reserved.
      3  * Copyright (C) 2008 Google Inc.
      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 "AXObjectCache.h"
     29 #include "AccessibilityObject.h"
     30 #include "AccessibilityScrollbar.h"
     31 #include "Chrome.h"
     32 #include "ChromeClient.h"
     33 #include "FrameView.h"
     34 #include "Scrollbar.h"
     35 
     36 namespace WebCore {
     37 
     38 void AXObjectCache::detachWrapper(AccessibilityObject* obj)
     39 {
     40     // In Chromium, AccessibilityObjects are wrapped lazily.
     41     if (AccessibilityObjectWrapper* wrapper = obj->wrapper())
     42         wrapper->detach();
     43 }
     44 
     45 void AXObjectCache::attachWrapper(AccessibilityObject*)
     46 {
     47     // In Chromium, AccessibilityObjects are wrapped lazily.
     48 }
     49 
     50 void AXObjectCache::postPlatformNotification(AccessibilityObject* obj, AXNotification notification)
     51 {
     52     if (obj && obj->isAccessibilityScrollbar() && notification == AXValueChanged) {
     53         // Send document value changed on scrollbar value changed notification.
     54         Scrollbar* scrollBar = static_cast<AccessibilityScrollbar*>(obj)->scrollbar();
     55         if (!scrollBar || !scrollBar->parent() || !scrollBar->parent()->isFrameView())
     56             return;
     57         Document* document = static_cast<FrameView*>(scrollBar->parent())->frame()->document();
     58         if (document != document->topDocument())
     59             return;
     60         obj = get(document->renderer());
     61     }
     62 
     63     if (!obj || !obj->document() || !obj->documentFrameView() || !obj->documentFrameView()->frame() || !obj->documentFrameView()->frame()->page())
     64         return;
     65 
     66     ChromeClient* client = obj->documentFrameView()->frame()->page()->chrome()->client();
     67     if (!client)
     68         return;
     69 
     70     switch (notification) {
     71     case AXActiveDescendantChanged:
     72         if (!obj->document()->focusedNode() || (obj->node() != obj->document()->focusedNode()))
     73             break;
     74 
     75         // Calling handleFocusedUIElementChanged will focus the new active
     76         // descendant and send the AXFocusedUIElementChanged notification.
     77         handleFocusedUIElementChanged(0, obj->document()->focusedNode()->renderer());
     78         break;
     79     case AXAutocorrectionOccured:
     80     case AXCheckedStateChanged:
     81     case AXChildrenChanged:
     82     case AXFocusedUIElementChanged:
     83     case AXLayoutComplete:
     84     case AXLiveRegionChanged:
     85     case AXLoadComplete:
     86     case AXMenuListValueChanged:
     87     case AXRowCollapsed:
     88     case AXRowCountChanged:
     89     case AXRowExpanded:
     90     case AXScrolledToAnchor:
     91     case AXSelectedChildrenChanged:
     92     case AXSelectedTextChanged:
     93     case AXValueChanged:
     94     case AXInvalidStatusChanged:
     95         break;
     96     }
     97 
     98     client->postAccessibilityNotification(obj, notification);
     99 }
    100 
    101 void AXObjectCache::nodeTextChangePlatformNotification(AccessibilityObject*, AXTextChange, unsigned, unsigned)
    102 {
    103 }
    104 
    105 void AXObjectCache::handleFocusedUIElementChanged(RenderObject*, RenderObject* newFocusedRenderer)
    106 {
    107     if (!newFocusedRenderer)
    108         return;
    109 
    110     Page* page = newFocusedRenderer->document()->page();
    111     if (!page)
    112         return;
    113 
    114     AccessibilityObject* focusedObject = focusedUIElementForPage(page);
    115     if (!focusedObject)
    116         return;
    117 
    118     postPlatformNotification(focusedObject, AXFocusedUIElementChanged);
    119 }
    120 
    121 void AXObjectCache::handleScrolledToAnchor(const Node* anchorNode)
    122 {
    123     // The anchor node may not be accessible. Post the notification for the
    124     // first accessible object.
    125     postPlatformNotification(AccessibilityObject::firstAccessibleObjectFromNode(anchorNode), AXScrolledToAnchor);
    126 }
    127 
    128 } // namespace WebCore
    129