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

Side by Side Diff: ui/aura_shell/shell.cc

Issue 8247012: Positions the launcher in the bottom left corner. Adds ShellDelegate (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix TestDesktopDelegate Created 9 years, 2 months 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
OLDNEW
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_model.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 16 matching lines...) Expand all
53 50
54 aura::Window* status_container = new aura::Window(NULL); 51 aura::Window* status_container = new aura::Window(NULL);
55 status_container->set_id(internal::kShellWindowId_StatusContainer); 52 status_container->set_id(internal::kShellWindowId_StatusContainer);
56 containers->push_back(status_container); 53 containers->push_back(status_container);
57 54
58 aura::Window* menu_container = new aura::Window(NULL); 55 aura::Window* menu_container = new aura::Window(NULL);
59 menu_container->set_id(internal::kShellWindowId_MenusAndTooltipsContainer); 56 menu_container->set_id(internal::kShellWindowId_MenusAndTooltipsContainer);
60 containers->push_back(menu_container); 57 containers->push_back(menu_container);
61 } 58 }
62 59
60 // Returns true if |window| has ancestor with the id |id|.
61 bool WindowHasAncestorWithId(const aura::Window* window, int id) {
62 while (window && window->id() != id)
63 window = window->parent();
64 return window != NULL;
65 }
66
63 typedef std::pair<aura::Window*, gfx::Rect> WindowAndBoundsPair; 67 typedef std::pair<aura::Window*, gfx::Rect> WindowAndBoundsPair;
64 68
65 void CalculateWindowBoundsAndScaleForTiling( 69 void CalculateWindowBoundsAndScaleForTiling(
66 const gfx::Size& containing_size, 70 const gfx::Size& containing_size,
67 const aura::Window::Windows& windows, 71 const aura::Window::Windows& windows,
68 float* x_scale, 72 float* x_scale,
69 float* y_scale, 73 float* y_scale,
70 std::vector<WindowAndBoundsPair>* bounds) { 74 std::vector<WindowAndBoundsPair>* bounds) {
71 *x_scale = 1.0f; 75 *x_scale = 1.0f;
72 *y_scale = 1.0f; 76 *y_scale = 1.0f;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 120
117 } // namespace 121 } // namespace
118 122
119 // static 123 // static
120 Shell* Shell::instance_ = NULL; 124 Shell* Shell::instance_ = NULL;
121 125
122 //////////////////////////////////////////////////////////////////////////////// 126 ////////////////////////////////////////////////////////////////////////////////
123 // Shell, public: 127 // Shell, public:
124 128
125 Shell::Shell() 129 Shell::Shell()
126 : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), 130 : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {
127 new_browser_button_(NULL),
128 show_apps_button_(NULL) {
129 aura::Desktop::GetInstance()->SetDelegate(this); 131 aura::Desktop::GetInstance()->SetDelegate(this);
130 } 132 }
131 133
132 Shell::~Shell() { 134 Shell::~Shell() {
133 } 135 }
134 136
135 // static 137 // static
136 Shell* Shell::GetInstance() { 138 Shell* Shell::GetInstance() {
137 if (!instance_) { 139 if (!instance_) {
138 instance_ = new Shell; 140 instance_ = new Shell;
139 instance_->Init(); 141 instance_->Init();
140 } 142 }
141 return instance_; 143 return instance_;
142 } 144 }
143 145
144 void Shell::Init() { 146 void Shell::Init() {
145 InitLauncherModel();
146
147 aura::Window::Windows containers; 147 aura::Window::Windows containers;
148 CreateSpecialContainers(&containers); 148 CreateSpecialContainers(&containers);
149 aura::Window::Windows::const_iterator i; 149 aura::Window::Windows::const_iterator i;
150 for (i = containers.begin(); i != containers.end(); ++i) { 150 for (i = containers.begin(); i != containers.end(); ++i) {
151 (*i)->Init(); 151 (*i)->Init();
152 aura::Desktop::GetInstance()->window()->AddChild(*i); 152 aura::Desktop::GetInstance()->window()->AddChild(*i);
153 (*i)->Show(); 153 (*i)->Show();
154 } 154 }
155 155
156 aura::Window* root_window = aura::Desktop::GetInstance()->window(); 156 aura::Window* root_window = aura::Desktop::GetInstance()->window();
157 internal::DesktopLayoutManager* desktop_layout = 157 internal::DesktopLayoutManager* desktop_layout =
158 new internal::DesktopLayoutManager(root_window); 158 new internal::DesktopLayoutManager(root_window);
159 root_window->SetLayoutManager(desktop_layout); 159 root_window->SetLayoutManager(desktop_layout);
160 160
161 desktop_layout->set_background_widget(internal::CreateDesktopBackground()); 161 desktop_layout->set_background_widget(internal::CreateDesktopBackground());
162 desktop_layout->set_launcher_widget( 162 desktop_layout->set_launcher_widget(internal::CreateLauncher());
163 internal::CreateLauncher(launcher_model_.get()));
164 desktop_layout->set_status_area_widget(internal::CreateStatusArea()); 163 desktop_layout->set_status_area_widget(internal::CreateStatusArea());
165 } 164 }
166 165
167 void Shell::SetDelegate(ShellDelegate* delegate) { 166 void Shell::SetDelegate(ShellDelegate* delegate) {
168 delegate_.reset(delegate); 167 delegate_.reset(delegate);
169 } 168 }
170 169
171 aura::Window* Shell::GetContainer(int container_id) { 170 aura::Window* Shell::GetContainer(int container_id) {
172 return const_cast<aura::Window*>( 171 return const_cast<aura::Window*>(
173 const_cast<const aura_shell::Shell*>(this)->GetContainer(container_id)); 172 const_cast<const aura_shell::Shell*>(this)->GetContainer(container_id));
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 for (size_t i = 0; i < to_restore_.size(); ++i) { 214 for (size_t i = 0; i < to_restore_.size(); ++i) {
216 to_restore_[i].first->layer()->SetAnimation( 215 to_restore_[i].first->layer()->SetAnimation(
217 aura::Window::CreateDefaultAnimation()); 216 aura::Window::CreateDefaultAnimation());
218 to_restore_[i].first->SetBounds(to_restore_[i].second); 217 to_restore_[i].first->SetBounds(to_restore_[i].second);
219 to_restore_[i].first->layer()->SetTransform(identity_transform); 218 to_restore_[i].first->layer()->SetTransform(identity_transform);
220 to_restore_[i].first->layer()->SetOpacity(1.0f); 219 to_restore_[i].first->layer()->SetOpacity(1.0f);
221 } 220 }
222 to_restore_.clear(); 221 to_restore_.clear();
223 } 222 }
224 223
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 //////////////////////////////////////////////////////////////////////////////// 224 ////////////////////////////////////////////////////////////////////////////////
243 // Shell, aura::DesktopDelegate implementation: 225 // Shell, aura::DesktopDelegate implementation:
244 226
245 void Shell::AddChildToDefaultParent(aura::Window* window) { 227 void Shell::AddChildToDefaultParent(aura::Window* window) {
246 aura::Window* parent = NULL; 228 aura::Window* parent = NULL;
247 switch (window->type()) { 229 switch (window->type()) {
248 case aura::kWindowType_Toplevel: 230 case aura::kWindowType_Toplevel:
249 parent = GetContainer(internal::kShellWindowId_DefaultContainer); 231 parent = GetContainer(internal::kShellWindowId_DefaultContainer);
250 break; 232 break;
251 case aura::kWindowType_Menu: 233 case aura::kWindowType_Menu:
252 case aura::kWindowType_Tooltip: 234 case aura::kWindowType_Tooltip:
253 parent = GetContainer(internal::kShellWindowId_MenusAndTooltipsContainer); 235 parent = GetContainer(internal::kShellWindowId_MenusAndTooltipsContainer);
254 break; 236 break;
255 default: 237 default:
256 // This will crash for controls, since they can't be parented to anything. 238 // This will crash for controls, since they can't be parented to anything.
257 break; 239 break;
258 } 240 }
259 parent->AddChild(window); 241 parent->AddChild(window);
260 } 242 }
261 243
262 aura::Window* Shell::GetTopmostWindowToActivate(aura::Window* ignore) const { 244 aura::Window* Shell::GetTopmostWindowToActivate(aura::Window* ignore) const {
263 const aura::ToplevelWindowContainer* container = 245 const aura::ToplevelWindowContainer* container =
264 GetContainer(internal::kShellWindowId_DefaultContainer)-> 246 GetContainer(internal::kShellWindowId_DefaultContainer)->
265 AsToplevelWindowContainer(); 247 AsToplevelWindowContainer();
266 return container->GetTopmostWindowToActivate(ignore); 248 return container->GetTopmostWindowToActivate(ignore);
267 } 249 }
268 250
269 void Shell::ButtonPressed(views::Button* sender, 251 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
270 const views::Event& event) { 252 if (!delegate_.get())
271 if (sender == new_browser_button_ && delegate_.get()) 253 return;
272 delegate_->CreateNewWindow(); 254 aura::Window* top_level = window->GetToplevelWindow();
273 else if (sender == show_apps_button_ && delegate_.get()) 255 // Ignore non-top level windows.
274 delegate_->ShowApps(); 256 if (top_level != window || !WindowHasAncestorWithId(window,
257 internal::kShellWindowId_DefaultContainer))
258 return;
259 LauncherItem item;
260 item.window = window;
261 if (!delegate_->ConfigureLauncherItem(&item))
262 return; // The delegate doesn't want to show this item in the launcher.
263 LauncherModel* model = LauncherModel::instance();
264 model->Add(model->items().size(), item);
265 }
266
267 void Shell::WillRemoveWindow(aura::Window* window) {
268 LauncherModel* model = LauncherModel::instance();
269 const LauncherItems& items(model->items());
270 for (LauncherItems::const_iterator i = items.begin(); i != items.end(); ++i) {
271 if (i->window == window) {
272 model->RemoveItemAt(i - items.begin());
273 break;
274 }
275 }
275 } 276 }
276 277
277 } // namespace aura_shell 278 } // namespace aura_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698