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_
11 #include "base/basictypes.h"
12 #include "ui/views/views_export.h"
14 template <typename T
> struct DefaultSingletonTraits
;
21 class AXAuraObjWrapper
;
25 // A cache responsible for assigning id's to a set of interesting Aura views.
26 class VIEWS_EXPORT AXAuraObjCache
{
28 // Get the single instance of this class.
29 static AXAuraObjCache
* GetInstance();
31 // Get or create an entry in the cache based on an Aura view.
32 AXAuraObjWrapper
* GetOrCreate(View
* view
);
33 AXAuraObjWrapper
* GetOrCreate(Widget
* widget
);
34 AXAuraObjWrapper
* GetOrCreate(aura::Window
* window
);
36 // Gets an id given an Aura view.
37 int32
GetID(View
* view
);
38 int32
GetID(Widget
* widget
);
39 int32
GetID(aura::Window
* window
);
41 // Gets the next unique id for this cache. Useful for non-Aura view backed
43 int32
GetNextID() { return current_id_
++; }
45 // Removes an entry from this cache based on an Aura view.
46 void Remove(View
* view
);
47 void Remove(Widget
* widget
);
48 void Remove(aura::Window
* window
);
50 // Removes a view and all of its descendants from the cache.
51 void RemoveViewSubtree(View
* view
);
53 // Lookup a cached entry based on an id.
54 AXAuraObjWrapper
* Get(int32 id
);
56 // Remove a cached entry based on an id.
57 void Remove(int32 id
);
59 // Get all top level windows this cache knows about.
60 void GetTopLevelWindows(std::vector
<AXAuraObjWrapper
*>* children
);
62 // Indicates if this object's currently being destroyed.
63 bool is_destroying() { return is_destroying_
; }
66 friend struct DefaultSingletonTraits
<AXAuraObjCache
>;
69 virtual ~AXAuraObjCache();
71 template <typename AuraViewWrapper
, typename AuraView
>
72 AXAuraObjWrapper
* CreateInternal(
73 AuraView
* aura_view
, std::map
<AuraView
*, int32
>& aura_view_to_id_map
);
75 template<typename AuraView
> int32
GetIDInternal(
76 AuraView
* aura_view
, std::map
<AuraView
*, int32
>& aura_view_to_id_map
);
78 template<typename AuraView
> void RemoveInternal(
79 AuraView
* aura_view
, std::map
<AuraView
*, int32
>& aura_view_to_id_map
);
81 std::map
<views::View
*, int32
> view_to_id_map_
;
82 std::map
<views::Widget
*, int32
> widget_to_id_map_
;
83 std::map
<aura::Window
*, int32
> window_to_id_map_
;
85 std::map
<int32
, AXAuraObjWrapper
*> cache_
;
88 // True immediately when entering this object's destructor.
91 DISALLOW_COPY_AND_ASSIGN(AXAuraObjCache
);
96 #endif // UI_VIEWS_ACCESSIBILITY_AX_AURA_OBJ_CACHE_H_