OLD | NEW |
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 "mash/example/window_type_launcher/window_type_launcher.h" | 5 #include "mash/example/window_type_launcher/window_type_launcher.h" |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "mash/shell/public/interfaces/shell.mojom.h" | 9 #include "mash/shell/public/interfaces/shell.mojom.h" |
10 #include "mojo/converters/geometry/geometry_type_converters.h" | 10 #include "mojo/converters/geometry/geometry_type_converters.h" |
11 #include "mojo/shell/public/cpp/application_connection.h" | 11 #include "mojo/shell/public/cpp/application_connection.h" |
12 #include "mojo/shell/public/cpp/application_impl.h" | 12 #include "mojo/shell/public/cpp/shell.h" |
13 #include "ui/aura/window.h" | 13 #include "ui/aura/window.h" |
14 #include "ui/aura/window_event_dispatcher.h" | 14 #include "ui/aura/window_event_dispatcher.h" |
15 #include "ui/compositor/layer.h" | 15 #include "ui/compositor/layer.h" |
16 #include "ui/gfx/canvas.h" | 16 #include "ui/gfx/canvas.h" |
17 #include "ui/views/context_menu_controller.h" | 17 #include "ui/views/context_menu_controller.h" |
18 #include "ui/views/controls/button/button.h" | 18 #include "ui/views/controls/button/button.h" |
19 #include "ui/views/controls/button/label_button.h" | 19 #include "ui/views/controls/button/label_button.h" |
20 #include "ui/views/controls/menu/menu_delegate.h" | 20 #include "ui/views/controls/menu/menu_delegate.h" |
21 #include "ui/views/controls/menu/menu_item_view.h" | 21 #include "ui/views/controls/menu/menu_item_view.h" |
22 #include "ui/views/controls/menu/menu_runner.h" | 22 #include "ui/views/controls/menu/menu_runner.h" |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 layout->AddPaddingRow(0, 5); | 157 layout->AddPaddingRow(0, 5); |
158 } | 158 } |
159 | 159 |
160 // The contents view/delegate of a window that shows some buttons that create | 160 // The contents view/delegate of a window that shows some buttons that create |
161 // various window types. | 161 // various window types. |
162 class WindowTypeLauncherView : public views::WidgetDelegateView, | 162 class WindowTypeLauncherView : public views::WidgetDelegateView, |
163 public views::ButtonListener, | 163 public views::ButtonListener, |
164 public views::MenuDelegate, | 164 public views::MenuDelegate, |
165 public views::ContextMenuController { | 165 public views::ContextMenuController { |
166 public: | 166 public: |
167 explicit WindowTypeLauncherView(mojo::ApplicationImpl* app) | 167 explicit WindowTypeLauncherView(mojo::Shell* shell) |
168 : app_(app), | 168 : shell_(shell), |
169 create_button_(new views::LabelButton( | 169 create_button_(new views::LabelButton( |
170 this, base::ASCIIToUTF16("Create Window"))), | 170 this, base::ASCIIToUTF16("Create Window"))), |
171 panel_button_(new views::LabelButton( | 171 panel_button_(new views::LabelButton( |
172 this, base::ASCIIToUTF16("Create Panel"))), | 172 this, base::ASCIIToUTF16("Create Panel"))), |
173 create_nonresizable_button_(new views::LabelButton( | 173 create_nonresizable_button_(new views::LabelButton( |
174 this, base::ASCIIToUTF16("Create Non-Resizable Window"))), | 174 this, base::ASCIIToUTF16("Create Non-Resizable Window"))), |
175 bubble_button_(new views::LabelButton( | 175 bubble_button_(new views::LabelButton( |
176 this, base::ASCIIToUTF16("Create Pointy Bubble"))), | 176 this, base::ASCIIToUTF16("Create Pointy Bubble"))), |
177 lock_button_(new views::LabelButton( | 177 lock_button_(new views::LabelButton( |
178 this, base::ASCIIToUTF16("Lock Screen"))), | 178 this, base::ASCIIToUTF16("Lock Screen"))), |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 NOTIMPLEMENTED(); | 267 NOTIMPLEMENTED(); |
268 } | 268 } |
269 else if (sender == create_nonresizable_button_) { | 269 else if (sender == create_nonresizable_button_) { |
270 NOTIMPLEMENTED(); | 270 NOTIMPLEMENTED(); |
271 } | 271 } |
272 else if (sender == bubble_button_) { | 272 else if (sender == bubble_button_) { |
273 NOTIMPLEMENTED(); | 273 NOTIMPLEMENTED(); |
274 } | 274 } |
275 else if (sender == lock_button_) { | 275 else if (sender == lock_button_) { |
276 mash::shell::mojom::ShellPtr shell; | 276 mash::shell::mojom::ShellPtr shell; |
277 app_->ConnectToService("mojo:mash_shell", &shell); | 277 shell_->ConnectToService("mojo:mash_shell", &shell); |
278 shell->LockScreen(); | 278 shell->LockScreen(); |
279 } | 279 } |
280 else if (sender == widgets_button_) { | 280 else if (sender == widgets_button_) { |
281 NOTIMPLEMENTED(); | 281 NOTIMPLEMENTED(); |
282 } | 282 } |
283 else if (sender == system_modal_button_) { | 283 else if (sender == system_modal_button_) { |
284 ModalWindow::OpenModalWindow(GetWidget()->GetNativeView(), | 284 ModalWindow::OpenModalWindow(GetWidget()->GetNativeView(), |
285 ui::MODAL_TYPE_SYSTEM); | 285 ui::MODAL_TYPE_SYSTEM); |
286 } else if (sender == window_modal_button_) { | 286 } else if (sender == window_modal_button_) { |
287 ModalWindow::OpenModalWindow(GetWidget()->GetNativeView(), | 287 ModalWindow::OpenModalWindow(GetWidget()->GetNativeView(), |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 root, MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU)); | 324 root, MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU)); |
325 if (menu_runner_->RunMenuAt(GetWidget(), | 325 if (menu_runner_->RunMenuAt(GetWidget(), |
326 NULL, | 326 NULL, |
327 gfx::Rect(point, gfx::Size()), | 327 gfx::Rect(point, gfx::Size()), |
328 views::MENU_ANCHOR_TOPLEFT, | 328 views::MENU_ANCHOR_TOPLEFT, |
329 source_type) == MenuRunner::MENU_DELETED) { | 329 source_type) == MenuRunner::MENU_DELETED) { |
330 return; | 330 return; |
331 } | 331 } |
332 } | 332 } |
333 | 333 |
334 mojo::ApplicationImpl* app_; | 334 mojo::Shell* shell_; |
335 views::LabelButton* create_button_; | 335 views::LabelButton* create_button_; |
336 views::LabelButton* panel_button_; | 336 views::LabelButton* panel_button_; |
337 views::LabelButton* create_nonresizable_button_; | 337 views::LabelButton* create_nonresizable_button_; |
338 views::LabelButton* bubble_button_; | 338 views::LabelButton* bubble_button_; |
339 views::LabelButton* lock_button_; | 339 views::LabelButton* lock_button_; |
340 views::LabelButton* widgets_button_; | 340 views::LabelButton* widgets_button_; |
341 views::LabelButton* system_modal_button_; | 341 views::LabelButton* system_modal_button_; |
342 views::LabelButton* window_modal_button_; | 342 views::LabelButton* window_modal_button_; |
343 views::LabelButton* child_modal_button_; | 343 views::LabelButton* child_modal_button_; |
344 views::LabelButton* transient_button_; | 344 views::LabelButton* transient_button_; |
345 views::LabelButton* examples_button_; | 345 views::LabelButton* examples_button_; |
346 views::LabelButton* show_hide_window_button_; | 346 views::LabelButton* show_hide_window_button_; |
347 views::LabelButton* show_web_notification_; | 347 views::LabelButton* show_web_notification_; |
348 scoped_ptr<views::MenuRunner> menu_runner_; | 348 scoped_ptr<views::MenuRunner> menu_runner_; |
349 | 349 |
350 DISALLOW_COPY_AND_ASSIGN(WindowTypeLauncherView); | 350 DISALLOW_COPY_AND_ASSIGN(WindowTypeLauncherView); |
351 }; | 351 }; |
352 | 352 |
353 } // namespace | 353 } // namespace |
354 | 354 |
355 WindowTypeLauncher::WindowTypeLauncher() {} | 355 WindowTypeLauncher::WindowTypeLauncher() {} |
356 WindowTypeLauncher::~WindowTypeLauncher() {} | 356 WindowTypeLauncher::~WindowTypeLauncher() {} |
357 | 357 |
358 bool WindowTypeLauncher::AcceptConnection( | 358 bool WindowTypeLauncher::AcceptConnection( |
359 mojo::ApplicationConnection* connection) { | 359 mojo::ApplicationConnection* connection) { |
360 return false; | 360 return false; |
361 } | 361 } |
362 | 362 |
363 void WindowTypeLauncher::Initialize(mojo::ApplicationImpl* app) { | 363 void WindowTypeLauncher::Initialize(mojo::Shell* shell, const std::string& url, |
364 aura_init_.reset(new views::AuraInit(app, "views_mus_resources.pak")); | 364 uint32_t id) { |
| 365 aura_init_.reset(new views::AuraInit(shell, "views_mus_resources.pak")); |
365 | 366 |
366 views::WindowManagerConnection::Create(app); | 367 views::WindowManagerConnection::Create(shell); |
367 | 368 |
368 views::Widget* widget = new views::Widget; | 369 views::Widget* widget = new views::Widget; |
369 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); | 370 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); |
370 params.delegate = new WindowTypeLauncherView(app); | 371 params.delegate = new WindowTypeLauncherView(shell); |
371 widget->Init(params); | 372 widget->Init(params); |
372 widget->Show(); | 373 widget->Show(); |
373 } | 374 } |
OLD | NEW |