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

Side by Side Diff: ash/shell/shell_main.cc

Issue 9788001: Remove stops_event_propagation from Window, since it's broken. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 9 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
« no previous file with comments | « ash/shell/shell_delegate_impl.cc ('k') | ash/shell/window_type_launcher.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <map> 5 #include <map>
6 6
7 #include "ash/launcher/launcher.h" 7 #include "ash/launcher/launcher.h"
8 #include "ash/launcher/launcher_delegate.h" 8 #include "ash/launcher/launcher_delegate.h"
9 #include "ash/launcher/launcher_model.h" 9 #include "ash/launcher/launcher_model.h"
10 #include "ash/launcher/launcher_types.h" 10 #include "ash/launcher/launcher_types.h"
11 #include "ash/shell.h" 11 #include "ash/shell.h"
12 #include "ash/shell_delegate.h" 12 #include "ash/shell_delegate.h"
13 #include "ash/shell_factory.h" 13 #include "ash/shell_factory.h"
14 #include "ash/shell_window_ids.h" 14 #include "ash/shell_window_ids.h"
15 #include "ash/shell/example_factory.h" 15 #include "ash/shell/launcher_delegate_impl.h"
16 #include "ash/shell/toplevel_window.h" 16 #include "ash/shell/shell_delegate_impl.h"
17 #include "ash/shell/shell_main_parts.h" 17 #include "ash/shell/shell_main_parts.h"
18 #include "ash/wm/partial_screenshot_view.h" 18 #include "ash/shell/window_watcher.h"
19 #include "ash/wm/window_util.h"
20 #include "base/at_exit.h" 19 #include "base/at_exit.h"
21 #include "base/command_line.h" 20 #include "base/command_line.h"
22 #include "base/memory/scoped_ptr.h" 21 #include "base/memory/scoped_ptr.h"
23 #include "base/message_loop.h" 22 #include "base/message_loop.h"
24 #include "grit/ui_resources.h"
25 #include "ui/aura/env.h" 23 #include "ui/aura/env.h"
26 #include "ui/aura/client/window_types.h" 24 #include "ui/aura/client/window_types.h"
27 #include "ui/aura/root_window.h" 25 #include "ui/aura/root_window.h"
28 #include "ui/aura/window_observer.h" 26 #include "ui/aura/window_observer.h"
29 #include "ui/base/resource/resource_bundle.h" 27 #include "ui/base/resource/resource_bundle.h"
30 #include "ui/base/ui_base_paths.h" 28 #include "ui/base/ui_base_paths.h"
31 #include "ui/gfx/canvas.h" 29 #include "ui/gfx/canvas.h"
32 #include "ui/gfx/compositor/test/compositor_test_support.h" 30 #include "ui/gfx/compositor/test/compositor_test_support.h"
33 #include "ui/views/test/test_views_delegate.h" 31 #include "ui/views/test/test_views_delegate.h"
34 #include "ui/views/widget/widget.h" 32 #include "ui/views/widget/widget.h"
(...skipping 13 matching lines...) Expand all
48 } 46 }
49 bool UseTransparentWindows() const OVERRIDE { 47 bool UseTransparentWindows() const OVERRIDE {
50 // Ash uses transparent window frames. 48 // Ash uses transparent window frames.
51 return true; 49 return true;
52 } 50 }
53 51
54 private: 52 private:
55 DISALLOW_COPY_AND_ASSIGN(ShellViewsDelegate); 53 DISALLOW_COPY_AND_ASSIGN(ShellViewsDelegate);
56 }; 54 };
57 55
58 // WindowWatcher is responsible for listening for newly created windows and
59 // creating items on the Launcher for them.
60 class WindowWatcher : public aura::WindowObserver {
61 public:
62 WindowWatcher()
63 : window_(ash::Shell::GetInstance()->launcher()->window_container()) {
64 window_->AddObserver(this);
65 }
66
67 virtual ~WindowWatcher() {
68 window_->RemoveObserver(this);
69 }
70
71 aura::Window* GetWindowByID(ash::LauncherID id) {
72 IDToWindow::const_iterator i = id_to_window_.find(id);
73 return i != id_to_window_.end() ? i->second : NULL;
74 }
75
76 ash::LauncherID GetIDByWindow(aura::Window* window) const {
77 for (IDToWindow::const_iterator i = id_to_window_.begin();
78 i != id_to_window_.end(); ++i) {
79 if (i->second == window)
80 return i->first;
81 }
82 return 0; // TODO: add a constant for this.
83 }
84
85 // aura::WindowObserver overrides:
86 virtual void OnWindowAdded(aura::Window* new_window) OVERRIDE {
87 if (new_window->type() != aura::client::WINDOW_TYPE_NORMAL)
88 return;
89
90 static int image_count = 0;
91 ash::LauncherModel* model = ash::Shell::GetInstance()->launcher()->model();
92 ash::LauncherItem item;
93 item.type = ash::TYPE_TABBED;
94 id_to_window_[model->next_id()] = new_window;
95 item.num_tabs = image_count + 1;
96 item.image.setConfig(SkBitmap::kARGB_8888_Config, 16, 16);
97 item.image.allocPixels();
98 item.image.eraseARGB(255,
99 image_count == 0 ? 255 : 0,
100 image_count == 1 ? 255 : 0,
101 image_count == 2 ? 255 : 0);
102 image_count = (image_count + 1) % 3;
103 model->Add(model->item_count(), item);
104 }
105
106 virtual void OnWillRemoveWindow(aura::Window* window) OVERRIDE {
107 for (IDToWindow::iterator i = id_to_window_.begin();
108 i != id_to_window_.end(); ++i) {
109 if (i->second == window) {
110 ash::LauncherModel* model =
111 ash::Shell::GetInstance()->launcher()->model();
112 int index = model->ItemIndexByID(i->first);
113 DCHECK_NE(-1, index);
114 model->RemoveItemAt(index);
115 id_to_window_.erase(i);
116 break;
117 }
118 }
119 }
120
121 private:
122 typedef std::map<ash::LauncherID, aura::Window*> IDToWindow;
123
124 // Window watching for newly created windows to be added to.
125 aura::Window* window_;
126
127 // Maps from window to the id we gave it.
128 IDToWindow id_to_window_;
129
130 DISALLOW_COPY_AND_ASSIGN(WindowWatcher);
131 };
132
133 class LauncherDelegateImpl : public ash::LauncherDelegate {
134 public:
135 explicit LauncherDelegateImpl(WindowWatcher* watcher)
136 : watcher_(watcher) {
137 }
138
139 void set_watcher(WindowWatcher* watcher) { watcher_ = watcher; }
140
141 // LauncherDelegate overrides:
142 virtual void CreateNewWindow() OVERRIDE {
143 ash::shell::ToplevelWindow::CreateParams create_params;
144 create_params.can_resize = true;
145 create_params.can_maximize = true;
146 ash::shell::ToplevelWindow::CreateToplevelWindow(create_params);
147 }
148
149 virtual void ItemClicked(const ash::LauncherItem& item) OVERRIDE {
150 aura::Window* window = watcher_->GetWindowByID(item.id);
151 window->Show();
152 ash::wm::ActivateWindow(window);
153 }
154
155 virtual int GetBrowserShortcutResourceId() OVERRIDE {
156 return IDR_AURA_LAUNCHER_BROWSER_SHORTCUT;
157 }
158
159 virtual string16 GetTitle(const ash::LauncherItem& item) OVERRIDE {
160 return watcher_->GetWindowByID(item.id)->title();
161 }
162
163 virtual ui::MenuModel* CreateContextMenu(
164 const ash::LauncherItem& item) OVERRIDE {
165 return NULL;
166 }
167
168 virtual ash::LauncherID GetIDByWindow(aura::Window* window) OVERRIDE {
169 return watcher_->GetIDByWindow(window);
170 }
171
172 private:
173 // Used to update Launcher. Owned by main.
174 WindowWatcher* watcher_;
175
176 DISALLOW_COPY_AND_ASSIGN(LauncherDelegateImpl);
177 };
178
179 class ShellDelegateImpl : public ash::ShellDelegate {
180 public:
181 ShellDelegateImpl() : watcher_(NULL), launcher_delegate_(NULL) {}
182
183 void SetWatcher(WindowWatcher* watcher) {
184 watcher_ = watcher;
185 if (launcher_delegate_)
186 launcher_delegate_->set_watcher(watcher);
187 }
188
189 virtual views::Widget* CreateStatusArea() OVERRIDE {
190 return NULL;
191 }
192
193 virtual bool CanCreateLauncher() OVERRIDE {
194 return true;
195 }
196
197 #if defined(OS_CHROMEOS)
198 virtual void LockScreen() OVERRIDE {
199 ash::shell::CreateLockScreen();
200 }
201 #endif
202
203 virtual void Exit() OVERRIDE {
204 MessageLoopForUI::current()->Quit();
205 }
206
207 virtual ash::AppListViewDelegate* CreateAppListViewDelegate() OVERRIDE {
208 return ash::shell::CreateAppListViewDelegate();
209 }
210
211 std::vector<aura::Window*> GetCycleWindowList(
212 CycleSource source) const OVERRIDE {
213 aura::Window* default_container = ash::Shell::GetInstance()->GetContainer(
214 ash::internal::kShellWindowId_DefaultContainer);
215 std::vector<aura::Window*> windows = default_container->children();
216 // Window cycling expects the topmost window at the front of the list.
217 std::reverse(windows.begin(), windows.end());
218 return windows;
219 }
220
221 virtual void StartPartialScreenshot(
222 ash::ScreenshotDelegate* screenshot_delegate) OVERRIDE {
223 ash::PartialScreenshotView::StartPartialScreenshot(screenshot_delegate);
224 }
225
226 virtual ash::LauncherDelegate* CreateLauncherDelegate(
227 ash::LauncherModel* model) OVERRIDE {
228 launcher_delegate_ = new LauncherDelegateImpl(watcher_);
229 return launcher_delegate_;
230 }
231
232 virtual ash::SystemTrayDelegate* CreateSystemTrayDelegate(
233 ash::SystemTray* tray) {
234 return NULL;
235 }
236
237 virtual ash::UserWallpaperDelegate* CreateUserWallpaperDelegate() {
238 return NULL;
239 }
240
241 private:
242 // Used to update Launcher. Owned by main.
243 WindowWatcher* watcher_;
244
245 LauncherDelegateImpl* launcher_delegate_;
246
247 DISALLOW_COPY_AND_ASSIGN(ShellDelegateImpl);
248 };
249
250 } // namespace 56 } // namespace
251 57
252 namespace ash { 58 namespace ash {
253 namespace shell { 59 namespace shell {
254 60
255 void InitWindowTypeLauncher(); 61 void InitWindowTypeLauncher();
256 62
257 } // namespace shell 63 } // namespace shell
258 } // namespace ash 64 } // namespace ash
259 65
260 int main(int argc, char** argv) { 66 int main(int argc, char** argv) {
261 CommandLine::Init(argc, argv); 67 CommandLine::Init(argc, argv);
262 68
263 // The exit manager is in charge of calling the dtors of singleton objects. 69 // The exit manager is in charge of calling the dtors of singleton objects.
264 base::AtExitManager exit_manager; 70 base::AtExitManager exit_manager;
265 71
266 ash::shell::PreMainMessageLoopStart(); 72 ash::shell::PreMainMessageLoopStart();
267 73
268 // Create the message-loop here before creating the root window. 74 // Create the message-loop here before creating the root window.
269 MessageLoop message_loop(MessageLoop::TYPE_UI); 75 MessageLoop message_loop(MessageLoop::TYPE_UI);
270 ui::CompositorTestSupport::Initialize(); 76 ui::CompositorTestSupport::Initialize();
271 77
272 // A ViewsDelegate is required. 78 // A ViewsDelegate is required.
273 if (!views::ViewsDelegate::views_delegate) 79 if (!views::ViewsDelegate::views_delegate)
274 views::ViewsDelegate::views_delegate = new ShellViewsDelegate; 80 views::ViewsDelegate::views_delegate = new ShellViewsDelegate;
275 81
276 ShellDelegateImpl* delegate = new ShellDelegateImpl; 82 ash::shell::ShellDelegateImpl* delegate = new ash::shell::ShellDelegateImpl;
277 ash::Shell::CreateInstance(delegate); 83 ash::Shell::CreateInstance(delegate);
278 84
279 scoped_ptr<WindowWatcher> window_watcher(new WindowWatcher); 85 scoped_ptr<ash::shell::WindowWatcher> window_watcher(
86 new ash::shell::WindowWatcher);
280 delegate->SetWatcher(window_watcher.get()); 87 delegate->SetWatcher(window_watcher.get());
281 88
282 ash::shell::InitWindowTypeLauncher(); 89 ash::shell::InitWindowTypeLauncher();
283 90
284 ash::Shell::GetRootWindow()->ShowRootWindow(); 91 ash::Shell::GetRootWindow()->ShowRootWindow();
285 MessageLoopForUI::current()->Run(); 92 MessageLoopForUI::current()->Run();
286 93
287 window_watcher.reset(); 94 window_watcher.reset();
288 95
289 ash::Shell::DeleteInstance(); 96 ash::Shell::DeleteInstance();
290 97
291 aura::Env::DeleteInstance(); 98 aura::Env::DeleteInstance();
292 99
293 ui::CompositorTestSupport::Terminate(); 100 ui::CompositorTestSupport::Terminate();
294 101
295 return 0; 102 return 0;
296 } 103 }
OLDNEW
« no previous file with comments | « ash/shell/shell_delegate_impl.cc ('k') | ash/shell/window_type_launcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698