Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(745)

Side by Side Diff: ui/aura/window_id_registry.cc

Issue 100603002: Add aura::WindowIdRegistry. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/aura/window_id_registry.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
OLDNEW
« no previous file with comments | « ui/aura/window_id_registry.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698