| 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/shell.h" | 5 #include "ui/aura_shell/shell.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "grit/ui_resources.h" | |
| 9 #include "ui/aura/desktop.h" | 8 #include "ui/aura/desktop.h" |
| 10 #include "ui/aura/toplevel_window_container.h" | 9 #include "ui/aura/toplevel_window_container.h" |
| 11 #include "ui/aura/window.h" | 10 #include "ui/aura/window.h" |
| 12 #include "ui/aura/window_types.h" | 11 #include "ui/aura/window_types.h" |
| 13 #include "ui/aura_shell/desktop_layout_manager.h" | 12 #include "ui/aura_shell/desktop_layout_manager.h" |
| 14 #include "ui/aura_shell/launcher/launcher_model.h" | 13 #include "ui/aura_shell/launcher/launcher.h" |
| 15 #include "ui/aura_shell/shell_delegate.h" | 14 #include "ui/aura_shell/shell_delegate.h" |
| 16 #include "ui/aura_shell/shell_factory.h" | 15 #include "ui/aura_shell/shell_factory.h" |
| 17 #include "ui/aura_shell/shell_window_ids.h" | 16 #include "ui/aura_shell/shell_window_ids.h" |
| 18 #include "ui/base/resource/resource_bundle.h" | |
| 19 #include "ui/gfx/compositor/layer.h" | 17 #include "ui/gfx/compositor/layer.h" |
| 20 #include "ui/gfx/image/image.h" | |
| 21 #include "views/controls/button/image_button.h" | |
| 22 #include "views/widget/widget.h" | 18 #include "views/widget/widget.h" |
| 23 | 19 |
| 24 namespace aura_shell { | 20 namespace aura_shell { |
| 25 | 21 |
| 26 namespace { | 22 namespace { |
| 23 |
| 27 // Creates each of the special window containers that holds windows of various | 24 // Creates each of the special window containers that holds windows of various |
| 28 // types in the shell UI. They are added to |containers| from back to front in | 25 // types in the shell UI. They are added to |containers| from back to front in |
| 29 // the z-index. | 26 // the z-index. |
| 30 void CreateSpecialContainers(aura::Window::Windows* containers) { | 27 void CreateSpecialContainers(aura::Window::Windows* containers) { |
| 31 aura::Window* background_container = new aura::Window(NULL); | 28 aura::Window* background_container = new aura::Window(NULL); |
| 32 background_container->set_id( | 29 background_container->set_id( |
| 33 internal::kShellWindowId_DesktopBackgroundContainer); | 30 internal::kShellWindowId_DesktopBackgroundContainer); |
| 34 containers->push_back(background_container); | 31 containers->push_back(background_container); |
| 35 | 32 |
| 36 aura::Window* default_container = new aura::ToplevelWindowContainer; | 33 aura::Window* default_container = new aura::ToplevelWindowContainer; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 | 113 |
| 117 } // namespace | 114 } // namespace |
| 118 | 115 |
| 119 // static | 116 // static |
| 120 Shell* Shell::instance_ = NULL; | 117 Shell* Shell::instance_ = NULL; |
| 121 | 118 |
| 122 //////////////////////////////////////////////////////////////////////////////// | 119 //////////////////////////////////////////////////////////////////////////////// |
| 123 // Shell, public: | 120 // Shell, public: |
| 124 | 121 |
| 125 Shell::Shell() | 122 Shell::Shell() |
| 126 : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), | 123 : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { |
| 127 new_browser_button_(NULL), | |
| 128 show_apps_button_(NULL) { | |
| 129 aura::Desktop::GetInstance()->SetDelegate(this); | 124 aura::Desktop::GetInstance()->SetDelegate(this); |
| 130 } | 125 } |
| 131 | 126 |
| 132 Shell::~Shell() { | 127 Shell::~Shell() { |
| 133 } | 128 } |
| 134 | 129 |
| 135 // static | 130 // static |
| 136 Shell* Shell::GetInstance() { | 131 Shell* Shell::GetInstance() { |
| 137 if (!instance_) { | 132 if (!instance_) { |
| 138 instance_ = new Shell; | 133 instance_ = new Shell; |
| 139 instance_->Init(); | 134 instance_->Init(); |
| 140 } | 135 } |
| 141 return instance_; | 136 return instance_; |
| 142 } | 137 } |
| 143 | 138 |
| 144 void Shell::Init() { | 139 void Shell::Init() { |
| 145 InitLauncherModel(); | |
| 146 | |
| 147 aura::Window::Windows containers; | 140 aura::Window::Windows containers; |
| 148 CreateSpecialContainers(&containers); | 141 CreateSpecialContainers(&containers); |
| 149 aura::Window::Windows::const_iterator i; | 142 aura::Window::Windows::const_iterator i; |
| 150 for (i = containers.begin(); i != containers.end(); ++i) { | 143 for (i = containers.begin(); i != containers.end(); ++i) { |
| 151 (*i)->Init(); | 144 (*i)->Init(); |
| 152 aura::Desktop::GetInstance()->window()->AddChild(*i); | 145 aura::Desktop::GetInstance()->window()->AddChild(*i); |
| 153 (*i)->Show(); | 146 (*i)->Show(); |
| 154 } | 147 } |
| 155 | 148 |
| 156 aura::Window* root_window = aura::Desktop::GetInstance()->window(); | 149 aura::Window* root_window = aura::Desktop::GetInstance()->window(); |
| 157 internal::DesktopLayoutManager* desktop_layout = | 150 internal::DesktopLayoutManager* desktop_layout = |
| 158 new internal::DesktopLayoutManager(root_window); | 151 new internal::DesktopLayoutManager(root_window); |
| 159 root_window->SetLayoutManager(desktop_layout); | 152 root_window->SetLayoutManager(desktop_layout); |
| 160 | 153 |
| 161 desktop_layout->set_background_widget(internal::CreateDesktopBackground()); | 154 desktop_layout->set_background_widget(internal::CreateDesktopBackground()); |
| 162 desktop_layout->set_launcher_widget( | 155 aura::ToplevelWindowContainer* toplevel_container = |
| 163 internal::CreateLauncher(launcher_model_.get())); | 156 GetContainer(internal::kShellWindowId_DefaultContainer)-> |
| 157 AsToplevelWindowContainer(); |
| 158 launcher_.reset(new Launcher(toplevel_container)); |
| 159 desktop_layout->set_launcher_widget(launcher_->widget()); |
| 164 desktop_layout->set_status_area_widget(internal::CreateStatusArea()); | 160 desktop_layout->set_status_area_widget(internal::CreateStatusArea()); |
| 165 } | 161 } |
| 166 | 162 |
| 167 void Shell::SetDelegate(ShellDelegate* delegate) { | 163 void Shell::SetDelegate(ShellDelegate* delegate) { |
| 168 delegate_.reset(delegate); | 164 delegate_.reset(delegate); |
| 169 } | 165 } |
| 170 | 166 |
| 171 aura::Window* Shell::GetContainer(int container_id) { | 167 aura::Window* Shell::GetContainer(int container_id) { |
| 172 return const_cast<aura::Window*>( | 168 return const_cast<aura::Window*>( |
| 173 const_cast<const aura_shell::Shell*>(this)->GetContainer(container_id)); | 169 const_cast<const aura_shell::Shell*>(this)->GetContainer(container_id)); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 for (size_t i = 0; i < to_restore_.size(); ++i) { | 211 for (size_t i = 0; i < to_restore_.size(); ++i) { |
| 216 to_restore_[i].first->layer()->SetAnimation( | 212 to_restore_[i].first->layer()->SetAnimation( |
| 217 aura::Window::CreateDefaultAnimation()); | 213 aura::Window::CreateDefaultAnimation()); |
| 218 to_restore_[i].first->SetBounds(to_restore_[i].second); | 214 to_restore_[i].first->SetBounds(to_restore_[i].second); |
| 219 to_restore_[i].first->layer()->SetTransform(identity_transform); | 215 to_restore_[i].first->layer()->SetTransform(identity_transform); |
| 220 to_restore_[i].first->layer()->SetOpacity(1.0f); | 216 to_restore_[i].first->layer()->SetOpacity(1.0f); |
| 221 } | 217 } |
| 222 to_restore_.clear(); | 218 to_restore_.clear(); |
| 223 } | 219 } |
| 224 | 220 |
| 225 void Shell::InitLauncherModel() { | |
| 226 launcher_model_.reset(new LauncherModel); | |
| 227 | |
| 228 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
| 229 new_browser_button_ = new views::ImageButton(this); | |
| 230 new_browser_button_->SetImage( | |
| 231 views::CustomButton::BS_NORMAL, | |
| 232 rb.GetImageNamed(IDR_AURA_LAUNCHER_ICON_CHROME).ToSkBitmap()); | |
| 233 launcher_model_->AddItem(new_browser_button_, 0, false); | |
| 234 | |
| 235 show_apps_button_ = new views::ImageButton(this); | |
| 236 show_apps_button_->SetImage( | |
| 237 views::CustomButton::BS_NORMAL, | |
| 238 rb.GetImageNamed(IDR_AURA_LAUNCHER_ICON_APPLIST).ToSkBitmap()); | |
| 239 launcher_model_->AddItem(show_apps_button_, 1, false); | |
| 240 } | |
| 241 | |
| 242 //////////////////////////////////////////////////////////////////////////////// | 221 //////////////////////////////////////////////////////////////////////////////// |
| 243 // Shell, aura::DesktopDelegate implementation: | 222 // Shell, aura::DesktopDelegate implementation: |
| 244 | 223 |
| 245 void Shell::AddChildToDefaultParent(aura::Window* window) { | 224 void Shell::AddChildToDefaultParent(aura::Window* window) { |
| 246 aura::Window* parent = NULL; | 225 aura::Window* parent = NULL; |
| 247 switch (window->type()) { | 226 switch (window->type()) { |
| 248 case aura::kWindowType_Toplevel: | 227 case aura::kWindowType_Toplevel: |
| 249 parent = GetContainer(internal::kShellWindowId_DefaultContainer); | 228 parent = GetContainer(internal::kShellWindowId_DefaultContainer); |
| 250 break; | 229 break; |
| 251 case aura::kWindowType_Menu: | 230 case aura::kWindowType_Menu: |
| 252 case aura::kWindowType_Tooltip: | 231 case aura::kWindowType_Tooltip: |
| 253 parent = GetContainer(internal::kShellWindowId_MenusAndTooltipsContainer); | 232 parent = GetContainer(internal::kShellWindowId_MenusAndTooltipsContainer); |
| 254 break; | 233 break; |
| 255 default: | 234 default: |
| 256 // This will crash for controls, since they can't be parented to anything. | 235 // This will crash for controls, since they can't be parented to anything. |
| 257 break; | 236 break; |
| 258 } | 237 } |
| 259 parent->AddChild(window); | 238 parent->AddChild(window); |
| 260 } | 239 } |
| 261 | 240 |
| 262 aura::Window* Shell::GetTopmostWindowToActivate(aura::Window* ignore) const { | 241 aura::Window* Shell::GetTopmostWindowToActivate(aura::Window* ignore) const { |
| 263 const aura::ToplevelWindowContainer* container = | 242 const aura::ToplevelWindowContainer* container = |
| 264 GetContainer(internal::kShellWindowId_DefaultContainer)-> | 243 GetContainer(internal::kShellWindowId_DefaultContainer)-> |
| 265 AsToplevelWindowContainer(); | 244 AsToplevelWindowContainer(); |
| 266 return container->GetTopmostWindowToActivate(ignore); | 245 return container->GetTopmostWindowToActivate(ignore); |
| 267 } | 246 } |
| 268 | 247 |
| 269 void Shell::ButtonPressed(views::Button* sender, | |
| 270 const views::Event& event) { | |
| 271 if (sender == new_browser_button_ && delegate_.get()) | |
| 272 delegate_->CreateNewWindow(); | |
| 273 else if (sender == show_apps_button_ && delegate_.get()) | |
| 274 delegate_->ShowApps(); | |
| 275 } | |
| 276 | |
| 277 } // namespace aura_shell | 248 } // namespace aura_shell |
| OLD | NEW |