| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 UI_VIEWS_FOCUS_VIEW_STORAGE_H_ | 5 #ifndef UI_VIEWS_FOCUS_VIEW_STORAGE_H_ |
| 6 #define UI_VIEWS_FOCUS_VIEW_STORAGE_H_ | 6 #define UI_VIEWS_FOCUS_VIEW_STORAGE_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "ui/views/views_export.h" | 12 #include "ui/views/views_export.h" |
| 13 | 13 |
| 14 namespace base { |
| 14 template <typename T> struct DefaultSingletonTraits; | 15 template <typename T> struct DefaultSingletonTraits; |
| 16 } |
| 15 | 17 |
| 16 // This class is a simple storage place for storing/retrieving views. It is | 18 // 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 | 19 // used for example in the FocusManager to store/restore focused views when the |
| 18 // main window becomes active/inactive. | 20 // main window becomes active/inactive. |
| 19 // It automatically removes a view from the storage if the view is removed from | 21 // 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 // the tree hierarchy or when the view is destroyed, which ever comes first. |
| 21 // | 23 // |
| 22 // To use it, you first need to create a view storage id that can then be used | 24 // To use it, you first need to create a view storage id that can then be used |
| 23 // to store/retrieve views. | 25 // to store/retrieve views. |
| 24 | 26 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 42 | 44 |
| 43 // Removes the view associated with |storage_id| if any. | 45 // Removes the view associated with |storage_id| if any. |
| 44 void RemoveView(int storage_id); | 46 void RemoveView(int storage_id); |
| 45 | 47 |
| 46 // Notifies the ViewStorage that a view was removed from its parent somewhere. | 48 // Notifies the ViewStorage that a view was removed from its parent somewhere. |
| 47 void ViewRemoved(View* removed); | 49 void ViewRemoved(View* removed); |
| 48 | 50 |
| 49 size_t view_count() const { return view_to_ids_.size(); } | 51 size_t view_count() const { return view_to_ids_.size(); } |
| 50 | 52 |
| 51 private: | 53 private: |
| 52 friend struct DefaultSingletonTraits<ViewStorage>; | 54 friend struct base::DefaultSingletonTraits<ViewStorage>; |
| 53 | 55 |
| 54 ViewStorage(); | 56 ViewStorage(); |
| 55 ~ViewStorage(); | 57 ~ViewStorage(); |
| 56 | 58 |
| 57 // Removes the view associated with |storage_id|. If |remove_all_ids| is true, | 59 // 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. | 60 // all other mapping pointing to the same view are removed as well. |
| 59 void EraseView(int storage_id, bool remove_all_ids); | 61 void EraseView(int storage_id, bool remove_all_ids); |
| 60 | 62 |
| 61 // Next id for the view storage. | 63 // Next id for the view storage. |
| 62 int view_storage_next_id_; | 64 int view_storage_next_id_; |
| 63 | 65 |
| 64 // The association id to View used for the view storage. | 66 // The association id to View used for the view storage. |
| 65 std::map<int, View*> id_to_view_; | 67 std::map<int, View*> id_to_view_; |
| 66 | 68 |
| 67 // Association View to id, used to speed up view notification removal. | 69 // Association View to id, used to speed up view notification removal. |
| 68 std::map<View*, std::vector<int>*> view_to_ids_; | 70 std::map<View*, std::vector<int>*> view_to_ids_; |
| 69 | 71 |
| 70 DISALLOW_COPY_AND_ASSIGN(ViewStorage); | 72 DISALLOW_COPY_AND_ASSIGN(ViewStorage); |
| 71 }; | 73 }; |
| 72 | 74 |
| 73 } // namespace views | 75 } // namespace views |
| 74 | 76 |
| 75 #endif // UI_VIEWS_FOCUS_VIEW_STORAGE_H_ | 77 #endif // UI_VIEWS_FOCUS_VIEW_STORAGE_H_ |
| OLD | NEW |