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 #include "ui/aura_shell/launcher/launcher.h" | 5 #include "ui/aura_shell/launcher/launcher.h" |
6 | 6 |
7 #include "ui/aura/toplevel_window_container.h" | 7 #include "ui/aura/toplevel_window_container.h" |
8 #include "ui/aura_shell/launcher/launcher_model.h" | 8 #include "ui/aura_shell/launcher/launcher_model.h" |
9 #include "ui/aura_shell/launcher/launcher_view.h" | 9 #include "ui/aura_shell/launcher/launcher_view.h" |
10 #include "ui/aura_shell/shell.h" | 10 #include "ui/aura_shell/shell.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 widget_->SetBounds(gfx::Rect(0, 0, pref.width(), pref.height())); | 36 widget_->SetBounds(gfx::Rect(0, 0, pref.width(), pref.height())); |
37 widget_->SetContentsView(launcher_view); | 37 widget_->SetContentsView(launcher_view); |
38 widget_->Show(); | 38 widget_->Show(); |
39 widget_->GetNativeView()->set_name("LauncherView"); | 39 widget_->GetNativeView()->set_name("LauncherView"); |
40 } | 40 } |
41 | 41 |
42 Launcher::~Launcher() { | 42 Launcher::~Launcher() { |
43 window_container_->RemoveObserver(this); | 43 window_container_->RemoveObserver(this); |
44 } | 44 } |
45 | 45 |
46 void Launcher::OnWindowAdded(aura::Window* new_window) { | 46 void Launcher::MaybeAdd(aura::Window* window) { |
| 47 if (known_windows_[window] == true) |
| 48 return; // We already tried to add this window. |
| 49 |
| 50 known_windows_[window] = true; |
47 ShellDelegate* delegate = Shell::GetInstance()->delegate(); | 51 ShellDelegate* delegate = Shell::GetInstance()->delegate(); |
48 if (!delegate) | 52 if (!delegate) |
49 return; | 53 return; |
50 LauncherItem item; | 54 LauncherItem item; |
51 item.window = new_window; | 55 item.window = window; |
52 if (!delegate->ConfigureLauncherItem(&item)) | 56 if (!delegate->ConfigureLauncherItem(&item)) |
53 return; // The delegate doesn't want to show this item in the launcher. | 57 return; // The delegate doesn't want to show this item in the launcher. |
54 model_->Add(model_->items().size(), item); | 58 model_->Add(model_->items().size(), item); |
55 } | 59 } |
56 | 60 |
| 61 void Launcher::OnWindowAdded(aura::Window* new_window) { |
| 62 DCHECK(known_windows_.find(new_window) == known_windows_.end()); |
| 63 known_windows_[new_window] = false; |
| 64 new_window->AddObserver(this); |
| 65 // Windows are created initially invisible. Wait until the window is made |
| 66 // visible before asking, as othewise the delegate likely doesn't know about |
| 67 // window (it's still creating it). |
| 68 if (new_window->IsVisible()) |
| 69 MaybeAdd(new_window); |
| 70 } |
| 71 |
57 void Launcher::OnWillRemoveWindow(aura::Window* window) { | 72 void Launcher::OnWillRemoveWindow(aura::Window* window) { |
58 const LauncherItems& items(model_->items()); | 73 window->RemoveObserver(this); |
59 for (LauncherItems::const_iterator i = items.begin(); i != items.end(); ++i) { | 74 known_windows_.erase(window); |
60 if (i->window == window) { | 75 LauncherItems::const_iterator i = model_->ItemByWindow(window); |
61 model_->RemoveItemAt(i - items.begin()); | 76 if (i != model_->items().end()) |
62 break; | 77 model_->RemoveItemAt(i - model_->items().begin()); |
63 } | 78 } |
64 } | 79 |
| 80 void Launcher::OnWindowVisibilityChanged(aura::Window* window, |
| 81 bool visibile) { |
| 82 if (visibile && !known_windows_[window]) |
| 83 MaybeAdd(window); |
65 } | 84 } |
66 | 85 |
67 } // namespace aura_shell | 86 } // namespace aura_shell |
OLD | NEW |