• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2009 Google 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 are
6  * met:
7  *
8  *     * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  *     * Neither the name of Google Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #ifndef WebAccessibilityCacheImpl_h
32 #define WebAccessibilityCacheImpl_h
33 
34 #include "AccessibilityObjectWrapper.h"
35 #include "WebAccessibilityCache.h"
36 #include <wtf/HashMap.h>
37 #include <wtf/PassRefPtr.h>
38 
39 namespace WebKit {
40 
41 // FIXME: Should be eliminated to use AXObjectCache instead.
42 class WebAccessibilityCacheImpl : public WebKit::WebAccessibilityCache {
43 public:
44     virtual void initialize(WebView* view);
isInitialized()45     virtual bool isInitialized() const { return m_initialized; }
46 
47     virtual WebAccessibilityObject getObjectById(int);
48     virtual int addOrGetId(const WebKit::WebAccessibilityObject&);
49     virtual bool isCached(const WebAccessibilityObject&);
50 
51     virtual void remove(int);
52     virtual void clear();
53 
54 protected:
55     friend class WebKit::WebAccessibilityCache;
56 
57     WebAccessibilityCacheImpl();
58     ~WebAccessibilityCacheImpl();
59 
60 private:
61     // FIXME: This can be just part of Chromium's AccessibilityObjectWrapper.
62     class WeakHandle : public WebCore::AccessibilityObjectWrapper {
63     public:
64         static PassRefPtr<WeakHandle> create(WebCore::AccessibilityObject*);
65         virtual void detach();
66     private:
67         WeakHandle(WebCore::AccessibilityObject*);
68     };
69 
70     typedef HashMap<int, RefPtr<WeakHandle> > ObjectMap;
71     typedef HashMap<WebCore::AccessibilityObject*, int> IdMap;
72 
73     // Hashmap for caching of elements in use by the AT, mapping id (int) to
74     // WebAccessibilityObject.
75     ObjectMap m_objectMap;
76     // Hashmap for caching of elements in use by the AT, mapping a
77     // AccessibilityObject pointer to its id (int). Needed for reverse lookup,
78     // to ensure unnecessary duplicate entries are not created in the
79     // ObjectMap and for focus changes in WebKit.
80     IdMap m_idMap;
81 
82     // Unique identifier for retrieving an accessibility object from the page's
83     // hashmaps. Id is always 0 for the root of the accessibility object
84     // hierarchy (on a per-renderer process basis).
85     int m_nextNewId;
86 
87     bool m_initialized;
88 };
89 
90 }
91 
92 #endif
93