1/*
2 * Copyright (C) 2011 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 *    notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 *    notice, this list of conditions and the following disclaimer in the
11 *    documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#import "config.h"
27#import "WKAccessibilityWebPageObjectBase.h"
28
29#import "WebFrame.h"
30#import "WebPage.h"
31#import "WKArray.h"
32#import "WKNumber.h"
33#import "WKRetainPtr.h"
34#import "WKSharedAPICast.h"
35#import "WKString.h"
36#import "WKStringCF.h"
37#import <WebCore/AXObjectCache.h>
38#import <WebCore/Document.h>
39#import <WebCore/FrameView.h>
40#import <WebCore/MainFrame.h>
41#import <WebCore/Page.h>
42#import <WebCore/ScrollView.h>
43#import <WebCore/Scrollbar.h>
44#import <WebKitSystemInterface.h>
45#import <wtf/ObjcRuntimeExtras.h>
46
47using namespace WebCore;
48using namespace WebKit;
49
50@implementation WKAccessibilityWebPageObjectBase
51
52- (id)accessibilityRootObjectWrapper
53{
54    if (!WebCore::AXObjectCache::accessibilityEnabled())
55        WebCore::AXObjectCache::enableAccessibility();
56
57    NSObject* mainFramePluginAccessibilityObjectWrapper = m_page->accessibilityObjectForMainFramePlugin();
58    if (mainFramePluginAccessibilityObjectWrapper)
59        return mainFramePluginAccessibilityObjectWrapper;
60
61    WebCore::Page* page = m_page->corePage();
62    if (!page)
63        return nil;
64
65    WebCore::Frame& core = page->mainFrame();
66    if (!core.document())
67        return nil;
68
69    WebCore::AXObjectCache* cache = core.document()->axObjectCache();
70    if (!cache)
71        return nil;
72
73    if (AccessibilityObject* root = cache->rootObject())
74        return root->wrapper();
75
76    return nil;
77}
78
79- (void)setWebPage:(WebPage*)page
80{
81    m_page = page;
82}
83
84- (void)setRemoteParent:(id)parent
85{
86    if (parent != m_parent) {
87        [m_parent release];
88        m_parent = [parent retain];
89    }
90}
91
92- (id)accessibilityFocusedUIElement
93{
94    return [[self accessibilityRootObjectWrapper] accessibilityFocusedUIElement];
95}
96
97
98@end
99