Chromium Code Reviews| Index: ui/aura_shell/shell.cc |
| diff --git a/ui/aura_shell/shell.cc b/ui/aura_shell/shell.cc |
| index cc815c154f7fd1138b515123bf009252c06aedef..5ea26d645f21aa4081d5b1dbc73575f0784f41f6 100644 |
| --- a/ui/aura_shell/shell.cc |
| +++ b/ui/aura_shell/shell.cc |
| @@ -5,7 +5,6 @@ |
| #include "ui/aura_shell/shell.h" |
| #include "base/bind.h" |
| -#include "grit/ui_resources.h" |
| #include "ui/aura/desktop.h" |
| #include "ui/aura/toplevel_window_container.h" |
| #include "ui/aura/window.h" |
| @@ -15,15 +14,13 @@ |
| #include "ui/aura_shell/shell_delegate.h" |
| #include "ui/aura_shell/shell_factory.h" |
| #include "ui/aura_shell/shell_window_ids.h" |
| -#include "ui/base/resource/resource_bundle.h" |
| #include "ui/gfx/compositor/layer.h" |
| -#include "ui/gfx/image/image.h" |
| -#include "views/controls/button/image_button.h" |
| #include "views/widget/widget.h" |
| namespace aura_shell { |
| namespace { |
| + |
| // Creates each of the special window containers that holds windows of various |
| // types in the shell UI. They are added to |containers| from back to front in |
| // the z-index. |
| @@ -60,6 +57,13 @@ void CreateSpecialContainers(aura::Window::Windows* containers) { |
| containers->push_back(menu_container); |
| } |
| +// Returns true if |window| has ancestor with the id |id|. |
| +bool WindowHasAncestorWithId(const aura::Window* window, int id) { |
| + while (window && window->id() != id) |
| + window = window->parent(); |
| + return window != NULL; |
| +} |
| + |
| typedef std::pair<aura::Window*, gfx::Rect> WindowAndBoundsPair; |
| void CalculateWindowBoundsAndScaleForTiling( |
| @@ -123,9 +127,7 @@ Shell* Shell::instance_ = NULL; |
| // Shell, public: |
| Shell::Shell() |
| - : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), |
| - new_browser_button_(NULL), |
| - show_apps_button_(NULL) { |
| + : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { |
| aura::Desktop::GetInstance()->SetDelegate(this); |
| } |
| @@ -142,8 +144,6 @@ Shell* Shell::GetInstance() { |
| } |
| void Shell::Init() { |
| - InitLauncherModel(); |
| - |
| aura::Window::Windows containers; |
| CreateSpecialContainers(&containers); |
| aura::Window::Windows::const_iterator i; |
| @@ -159,8 +159,7 @@ void Shell::Init() { |
| root_window->SetLayoutManager(desktop_layout); |
| desktop_layout->set_background_widget(internal::CreateDesktopBackground()); |
| - desktop_layout->set_launcher_widget( |
| - internal::CreateLauncher(launcher_model_.get())); |
| + desktop_layout->set_launcher_widget(internal::CreateLauncher()); |
| desktop_layout->set_status_area_widget(internal::CreateStatusArea()); |
| } |
| @@ -222,23 +221,6 @@ void Shell::RestoreTiledWindows() { |
| to_restore_.clear(); |
| } |
| -void Shell::InitLauncherModel() { |
| - launcher_model_.reset(new LauncherModel); |
| - |
| - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| - new_browser_button_ = new views::ImageButton(this); |
| - new_browser_button_->SetImage( |
| - views::CustomButton::BS_NORMAL, |
| - rb.GetImageNamed(IDR_AURA_LAUNCHER_ICON_CHROME).ToSkBitmap()); |
| - launcher_model_->AddItem(new_browser_button_, 0, false); |
| - |
| - show_apps_button_ = new views::ImageButton(this); |
| - show_apps_button_->SetImage( |
| - views::CustomButton::BS_NORMAL, |
| - rb.GetImageNamed(IDR_AURA_LAUNCHER_ICON_APPLIST).ToSkBitmap()); |
| - launcher_model_->AddItem(show_apps_button_, 1, false); |
| -} |
| - |
| //////////////////////////////////////////////////////////////////////////////// |
| // Shell, aura::DesktopDelegate implementation: |
| @@ -266,12 +248,31 @@ aura::Window* Shell::GetTopmostWindowToActivate(aura::Window* ignore) const { |
| return container->GetTopmostWindowToActivate(ignore); |
| } |
| -void Shell::ButtonPressed(views::Button* sender, |
| - const views::Event& event) { |
| - if (sender == new_browser_button_ && delegate_.get()) |
| - delegate_->CreateNewWindow(); |
| - else if (sender == show_apps_button_ && delegate_.get()) |
| - delegate_->ShowApps(); |
| +void Shell::WindowAdded(aura::Window* window) { |
|
Ben Goodger (Google)
2011/10/13 03:03:39
Seems like you don't want to listen to all window
|
| + if (!delegate_.get()) |
| + return; |
| + aura::Window* top_level = window->GetToplevelWindow(); |
| + // Ignore non-top level windows. |
| + if (top_level != window || !WindowHasAncestorWithId(window, |
| + internal::kShellWindowId_DefaultContainer)) |
| + return; |
| + LauncherItem item; |
| + item.window = window; |
| + if (!delegate_->ConfigureLauncherItem(&item)) |
| + return; // The delegate doesn't want to show this item in the launcher. |
| + LauncherModel* model = LauncherModel::instance(); |
| + model->Add(model->items().size(), item); |
| +} |
| + |
| +void Shell::WillRemoveWindow(aura::Window* window) { |
| + LauncherModel* model = LauncherModel::instance(); |
| + const LauncherItems& items(model->items()); |
| + for (LauncherItems::const_iterator i = items.begin(); i != items.end(); ++i) { |
| + if (i->window == window) { |
| + model->RemoveItemAt(i - items.begin()); |
| + break; |
| + } |
| + } |
| } |
| } // namespace aura_shell |