OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 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. |
| 4 |
| 5 #include "ui/aura/window_id_registry.h" |
| 6 |
| 7 #include "ui/aura/window.h" |
| 8 |
| 9 namespace aura { |
| 10 |
| 11 // static |
| 12 WindowIdRegistry* WindowIdRegistry::GetInstance() { |
| 13 return Singleton<WindowIdRegistry>::get(); |
| 14 } |
| 15 |
| 16 int WindowIdRegistry::GetIdForWindow(Window* window) { |
| 17 // First check if an Id is already assigned to the |window|. |
| 18 std::map<Window*, int>::iterator it = window_to_id_map_.find(window); |
| 19 if (it != window_to_id_map_.end()) { |
| 20 return it->second; |
| 21 } |
| 22 |
| 23 // If the windows doesn't have an Id yet assign it. |
| 24 int id = next_id_++; |
| 25 window_to_id_map_[window] = id; |
| 26 id_to_window_map_[id] = window; |
| 27 window->AddObserver(this); |
| 28 return id; |
| 29 } |
| 30 |
| 31 Window* WindowIdRegistry::GetWindowById(int id) { |
| 32 std::map<int, Window*>::iterator it = id_to_window_map_.find(id); |
| 33 return (it != id_to_window_map_.end()) ? it->second : NULL; |
| 34 } |
| 35 |
| 36 WindowIdRegistry::WindowIdRegistry() |
| 37 : next_id_(0) { |
| 38 } |
| 39 |
| 40 WindowIdRegistry::~WindowIdRegistry() {} |
| 41 |
| 42 void WindowIdRegistry::OnWindowDestroying(Window* window) { |
| 43 std::map<Window*, int>::iterator it = window_to_id_map_.find(window); |
| 44 DCHECK(it != window_to_id_map_.end()); |
| 45 id_to_window_map_.erase(it->second); |
| 46 window_to_id_map_.erase(it); |
| 47 } |
| 48 |
| 49 } // namespace aura |
OLD | NEW |