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 // Lookup a cached entry based on an id.
51 AXAuraObjWrapper
* Get(int32 id
);
53 // Remove a cached entry based on an id.
54 void Remove(int32 id
);
56 // Get all top level windows this cache knows about.
57 void GetTopLevelWindows(std::vector
<AXAuraObjWrapper
*>* children
);
59 // Indicates if this object's currently being destroyed.
60 bool is_destroying() { return is_destroying_
; }
63 friend struct DefaultSingletonTraits
<AXAuraObjCache
>;
66 virtual ~AXAuraObjCache();
68 template <typename AuraViewWrapper
, typename AuraView
>
69 AXAuraObjWrapper
* CreateInternal(
70 AuraView
* aura_view
, std::map
<AuraView
*, int32
>& aura_view_to_id_map
);
72 template<typename AuraView
> int32
GetIDInternal(
73 AuraView
* aura_view
, std::map
<AuraView
*, int32
>& aura_view_to_id_map
);
75 template<typename AuraView
> void RemoveInternal(
76 AuraView
* aura_view
, std::map
<AuraView
*, int32
>& aura_view_to_id_map
);
78 std::map
<views::View
*, int32
> view_to_id_map_
;
79 std::map
<views::Widget
*, int32
> widget_to_id_map_
;
80 std::map
<aura::Window
*, int32
> window_to_id_map_
;
82 std::map
<int32
, AXAuraObjWrapper
*> cache_
;
85 // True immediately when entering this object's destructor.
88 DISALLOW_COPY_AND_ASSIGN(AXAuraObjCache
);
93 #endif // UI_VIEWS_ACCESSIBILITY_AX_AURA_OBJ_CACHE_H_