| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef VIEWS_FOCUS_VIEW_STORAGE_H_ | 5 #ifndef VIEWS_FOCUS_VIEW_STORAGE_H_ |
| 6 #define VIEWS_FOCUS_VIEW_STORAGE_H_ | 6 #define VIEWS_FOCUS_VIEW_STORAGE_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/memory/singleton.h" | 9 #include "ui/views/focus/view_storage.h" |
| 10 #include "views/view.h" | 10 // TODO(tfarina): remove this file once all includes have been updated. |
| 11 | |
| 12 // This class is a simple storage place for storing/retrieving views. It is | |
| 13 // used for example in the FocusManager to store/restore focused views when the | |
| 14 // main window becomes active/inactive. | |
| 15 // It automatically removes a view from the storage if the view is removed from | |
| 16 // the tree hierarchy. | |
| 17 // | |
| 18 // To use it, you first need to create a view storage id that can then be used | |
| 19 // to store/retrieve views. | |
| 20 | |
| 21 namespace views { | |
| 22 | |
| 23 class VIEWS_EXPORT ViewStorage { | |
| 24 public: | |
| 25 // Returns the global ViewStorage instance. | |
| 26 // It is guaranted to be non NULL. | |
| 27 static ViewStorage* GetInstance(); | |
| 28 | |
| 29 // Returns a unique storage id that can be used to store/retrieve views. | |
| 30 int CreateStorageID(); | |
| 31 | |
| 32 // Associates |view| with the specified |storage_id|. | |
| 33 void StoreView(int storage_id, View* view); | |
| 34 | |
| 35 // Returns the view associated with |storage_id| if any, NULL otherwise. | |
| 36 View* RetrieveView(int storage_id); | |
| 37 | |
| 38 // Removes the view associated with |storage_id| if any. | |
| 39 void RemoveView(int storage_id); | |
| 40 | |
| 41 // Notifies the ViewStorage that a view was removed from its parent somewhere. | |
| 42 void ViewRemoved(View* removed); | |
| 43 | |
| 44 size_t view_count() const { return view_to_ids_.size(); } | |
| 45 | |
| 46 private: | |
| 47 friend struct DefaultSingletonTraits<ViewStorage>; | |
| 48 | |
| 49 ViewStorage(); | |
| 50 ~ViewStorage(); | |
| 51 | |
| 52 // Removes the view associated with |storage_id|. If |remove_all_ids| is true, | |
| 53 // all other mapping pointing to the same view are removed as well. | |
| 54 void EraseView(int storage_id, bool remove_all_ids); | |
| 55 | |
| 56 // Next id for the view storage. | |
| 57 int view_storage_next_id_; | |
| 58 | |
| 59 // The association id to View used for the view storage. | |
| 60 std::map<int, View*> id_to_view_; | |
| 61 | |
| 62 // Association View to id, used to speed up view notification removal. | |
| 63 std::map<View*, std::vector<int>*> view_to_ids_; | |
| 64 | |
| 65 DISALLOW_COPY_AND_ASSIGN(ViewStorage); | |
| 66 }; | |
| 67 | |
| 68 } // namespace views | |
| 69 | 11 |
| 70 #endif // VIEWS_FOCUS_VIEW_STORAGE_H_ | 12 #endif // VIEWS_FOCUS_VIEW_STORAGE_H_ |
| OLD | NEW |