Linux: Depend on liberation-fonts package for RPMs.
[chromium-blink-merge.git] / ui / views / accessibility / ax_aura_obj_cache.h
blob95c46f387104a498287303f6c2689f05a71d510d
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef UI_VIEWS_ACCESSIBILITY_AX_AURA_OBJ_CACHE_H_
6 #define UI_VIEWS_ACCESSIBILITY_AX_AURA_OBJ_CACHE_H_
8 #include <map>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "ui/views/views_export.h"
14 namespace base {
15 template <typename T> struct DefaultSingletonTraits;
18 namespace aura {
19 class Window;
20 } // namespace aura
22 namespace views {
23 class AXAuraObjWrapper;
24 class View;
25 class Widget;
27 // A cache responsible for assigning id's to a set of interesting Aura views.
28 class VIEWS_EXPORT AXAuraObjCache {
29 public:
30 // Get the single instance of this class.
31 static AXAuraObjCache* GetInstance();
33 // Get or create an entry in the cache based on an Aura view.
34 AXAuraObjWrapper* GetOrCreate(View* view);
35 AXAuraObjWrapper* GetOrCreate(Widget* widget);
36 AXAuraObjWrapper* GetOrCreate(aura::Window* window);
38 // Gets an id given an Aura view.
39 int32 GetID(View* view);
40 int32 GetID(Widget* widget);
41 int32 GetID(aura::Window* window);
43 // Gets the next unique id for this cache. Useful for non-Aura view backed
44 // views.
45 int32 GetNextID() { return current_id_++; }
47 // Removes an entry from this cache based on an Aura view.
48 void Remove(View* view);
49 void Remove(Widget* widget);
50 void Remove(aura::Window* window);
52 // Removes a view and all of its descendants from the cache.
53 void RemoveViewSubtree(View* view);
55 // Lookup a cached entry based on an id.
56 AXAuraObjWrapper* Get(int32 id);
58 // Remove a cached entry based on an id.
59 void Remove(int32 id);
61 // Get all top level windows this cache knows about.
62 void GetTopLevelWindows(std::vector<AXAuraObjWrapper*>* children);
64 // Indicates if this object's currently being destroyed.
65 bool is_destroying() { return is_destroying_; }
67 private:
68 friend struct base::DefaultSingletonTraits<AXAuraObjCache>;
70 AXAuraObjCache();
71 virtual ~AXAuraObjCache();
73 template <typename AuraViewWrapper, typename AuraView>
74 AXAuraObjWrapper* CreateInternal(
75 AuraView* aura_view, std::map<AuraView*, int32>& aura_view_to_id_map);
77 template<typename AuraView> int32 GetIDInternal(
78 AuraView* aura_view, std::map<AuraView*, int32>& aura_view_to_id_map);
80 template<typename AuraView> void RemoveInternal(
81 AuraView* aura_view, std::map<AuraView*, int32>& aura_view_to_id_map);
83 std::map<views::View*, int32> view_to_id_map_;
84 std::map<views::Widget*, int32> widget_to_id_map_;
85 std::map<aura::Window*, int32> window_to_id_map_;
87 std::map<int32, AXAuraObjWrapper*> cache_;
88 int32 current_id_;
90 // True immediately when entering this object's destructor.
91 bool is_destroying_;
93 DISALLOW_COPY_AND_ASSIGN(AXAuraObjCache);
96 } // namespace views
98 #endif // UI_VIEWS_ACCESSIBILITY_AX_AURA_OBJ_CACHE_H_