| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/aura_shell/launcher/launcher.h" |
| 6 |
| 7 #include "ui/aura/toplevel_window_container.h" |
| 8 #include "ui/aura_shell/launcher/launcher_model.h" |
| 9 #include "ui/aura_shell/launcher/launcher_view.h" |
| 10 #include "ui/aura_shell/shell.h" |
| 11 #include "ui/aura_shell/shell_delegate.h" |
| 12 #include "ui/aura_shell/shell_window_ids.h" |
| 13 #include "ui/gfx/compositor/layer.h" |
| 14 #include "views/widget/widget.h" |
| 15 |
| 16 namespace aura_shell { |
| 17 |
| 18 Launcher::Launcher(aura::ToplevelWindowContainer* window_container) |
| 19 : window_container_(window_container), |
| 20 widget_(NULL) { |
| 21 window_container->AddObserver(this); |
| 22 |
| 23 model_.reset(new LauncherModel); |
| 24 |
| 25 widget_ = new views::Widget; |
| 26 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); |
| 27 params.parent = Shell::GetInstance()->GetContainer( |
| 28 aura_shell::internal::kShellWindowId_LauncherContainer); |
| 29 internal::LauncherView* launcher_view = |
| 30 new internal::LauncherView(model_.get()); |
| 31 launcher_view->Init(); |
| 32 params.delegate = launcher_view; |
| 33 widget_->Init(params); |
| 34 widget_->GetNativeWindow()->layer()->SetOpacity(0.8f); |
| 35 gfx::Size pref = static_cast<views::View*>(launcher_view)->GetPreferredSize(); |
| 36 widget_->SetBounds(gfx::Rect(0, 0, pref.width(), pref.height())); |
| 37 widget_->SetContentsView(launcher_view); |
| 38 widget_->Show(); |
| 39 widget_->GetNativeView()->set_name("LauncherView"); |
| 40 } |
| 41 |
| 42 Launcher::~Launcher() { |
| 43 window_container_->RemoveObserver(this); |
| 44 } |
| 45 |
| 46 void Launcher::OnWindowAdded(aura::Window* new_window) { |
| 47 ShellDelegate* delegate = Shell::GetInstance()->delegate(); |
| 48 if (!delegate) |
| 49 return; |
| 50 LauncherItem item; |
| 51 item.window = new_window; |
| 52 if (!delegate->ConfigureLauncherItem(&item)) |
| 53 return; // The delegate doesn't want to show this item in the launcher. |
| 54 model_->Add(model_->items().size(), item); |
| 55 } |
| 56 |
| 57 void Launcher::OnWillRemoveWindow(aura::Window* window) { |
| 58 const LauncherItems& items(model_->items()); |
| 59 for (LauncherItems::const_iterator i = items.begin(); i != items.end(); ++i) { |
| 60 if (i->window == window) { |
| 61 model_->RemoveItemAt(i - items.begin()); |
| 62 break; |
| 63 } |
| 64 } |
| 65 } |
| 66 |
| 67 } // namespace aura_shell |
| OLD | NEW |