Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / ui / views / focus / view_storage.h
blob5e36f3c5e9bcb678c78b895be293b7a9a3f2c1bd
1 // Copyright (c) 2012 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_FOCUS_VIEW_STORAGE_H_
6 #define UI_VIEWS_FOCUS_VIEW_STORAGE_H_
8 #include <map>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "ui/views/views_export.h"
14 template <typename T> struct DefaultSingletonTraits;
16 // This class is a simple storage place for storing/retrieving views. It is
17 // used for example in the FocusManager to store/restore focused views when the
18 // main window becomes active/inactive.
19 // It automatically removes a view from the storage if the view is removed from
20 // the tree hierarchy or when the view is destroyed, which ever comes first.
22 // To use it, you first need to create a view storage id that can then be used
23 // to store/retrieve views.
25 namespace views {
26 class View;
28 class VIEWS_EXPORT ViewStorage {
29 public:
30 // Returns the global ViewStorage instance.
31 // It is guaranted to be non NULL.
32 static ViewStorage* GetInstance();
34 // Returns a unique storage id that can be used to store/retrieve views.
35 int CreateStorageID();
37 // Associates |view| with the specified |storage_id|.
38 void StoreView(int storage_id, View* view);
40 // Returns the view associated with |storage_id| if any, NULL otherwise.
41 View* RetrieveView(int storage_id);
43 // Removes the view associated with |storage_id| if any.
44 void RemoveView(int storage_id);
46 // Notifies the ViewStorage that a view was removed from its parent somewhere.
47 void ViewRemoved(View* removed);
49 size_t view_count() const { return view_to_ids_.size(); }
51 private:
52 friend struct DefaultSingletonTraits<ViewStorage>;
54 ViewStorage();
55 ~ViewStorage();
57 // Removes the view associated with |storage_id|. If |remove_all_ids| is true,
58 // all other mapping pointing to the same view are removed as well.
59 void EraseView(int storage_id, bool remove_all_ids);
61 // Next id for the view storage.
62 int view_storage_next_id_;
64 // The association id to View used for the view storage.
65 std::map<int, View*> id_to_view_;
67 // Association View to id, used to speed up view notification removal.
68 std::map<View*, std::vector<int>*> view_to_ids_;
70 DISALLOW_COPY_AND_ASSIGN(ViewStorage);
73 } // namespace views
75 #endif // UI_VIEWS_FOCUS_VIEW_STORAGE_H_