| 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 "ash/shell/window_type_launcher.h" | 5 #include "ash/shell/window_type_launcher.h" |
| 6 | 6 |
| 7 #include "ash/root_window_controller.h" | 7 #include "ash/root_window_controller.h" |
| 8 #include "ash/screensaver/screensaver_view.h" | 8 #include "ash/screensaver/screensaver_view.h" |
| 9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 10 #include "ash/shell/example_factory.h" | 10 #include "ash/shell/example_factory.h" |
| 11 #include "ash/shell/panel_window.h" | 11 #include "ash/shell/panel_window.h" |
| 12 #include "ash/shell/toplevel_window.h" | 12 #include "ash/shell/toplevel_window.h" |
| 13 #include "ash/shell_delegate.h" | 13 #include "ash/shell_delegate.h" |
| 14 #include "ash/shell_window_ids.h" | 14 #include "ash/shell_window_ids.h" |
| 15 #include "ash/system/status_area_widget.h" | 15 #include "ash/system/status_area_widget.h" |
| 16 #include "ash/system/web_notification/web_notification_tray.h" | 16 #include "ash/system/web_notification/web_notification_tray.h" |
| 17 #include "base/bind.h" | 17 #include "base/bind.h" |
| 18 #include "base/time.h" | 18 #include "base/time.h" |
| 19 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
| 20 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 21 #include "ui/aura/root_window.h" | 21 #include "ui/aura/root_window.h" |
| 22 #include "ui/aura/window.h" | 22 #include "ui/aura/window.h" |
| 23 #include "ui/compositor/layer.h" | 23 #include "ui/compositor/layer.h" |
| 24 #include "ui/gfx/canvas.h" | 24 #include "ui/gfx/canvas.h" |
| 25 #include "ui/message_center/notification_types.h" | 25 #include "ui/message_center/notification_types.h" |
| 26 #include "ui/views/controls/button/text_button.h" | 26 #include "ui/views/controls/button/label_button.h" |
| 27 #include "ui/views/controls/menu/menu_item_view.h" | 27 #include "ui/views/controls/menu/menu_item_view.h" |
| 28 #include "ui/views/controls/menu/menu_runner.h" | 28 #include "ui/views/controls/menu/menu_runner.h" |
| 29 #include "ui/views/corewm/shadow_types.h" | 29 #include "ui/views/corewm/shadow_types.h" |
| 30 #include "ui/views/examples/examples_window_with_content.h" | 30 #include "ui/views/examples/examples_window_with_content.h" |
| 31 #include "ui/views/layout/grid_layout.h" | 31 #include "ui/views/layout/grid_layout.h" |
| 32 #include "ui/views/test/child_modal_window.h" | 32 #include "ui/views/test/child_modal_window.h" |
| 33 #include "ui/views/widget/widget.h" | 33 #include "ui/views/widget/widget.h" |
| 34 | 34 |
| 35 using views::MenuItemView; | 35 using views::MenuItemView; |
| 36 using views::MenuRunner; | 36 using views::MenuRunner; |
| 37 | 37 |
| 38 namespace ash { | 38 namespace ash { |
| 39 namespace shell { | 39 namespace shell { |
| 40 | 40 |
| 41 namespace { | 41 namespace { |
| 42 | 42 |
| 43 SkColor g_colors[] = { SK_ColorRED, | 43 SkColor g_colors[] = { SK_ColorRED, |
| 44 SK_ColorYELLOW, | 44 SK_ColorYELLOW, |
| 45 SK_ColorBLUE, | 45 SK_ColorBLUE, |
| 46 SK_ColorGREEN }; | 46 SK_ColorGREEN }; |
| 47 int g_color_index = 0; | 47 int g_color_index = 0; |
| 48 | 48 |
| 49 class ModalWindow : public views::WidgetDelegateView, | 49 class ModalWindow : public views::WidgetDelegateView, |
| 50 public views::ButtonListener { | 50 public views::ButtonListener { |
| 51 public: | 51 public: |
| 52 explicit ModalWindow(ui::ModalType modal_type) | 52 explicit ModalWindow(ui::ModalType modal_type) |
| 53 : modal_type_(modal_type), | 53 : modal_type_(modal_type), |
| 54 color_(g_colors[g_color_index]), | 54 color_(g_colors[g_color_index]), |
| 55 ALLOW_THIS_IN_INITIALIZER_LIST(open_button_( | 55 ALLOW_THIS_IN_INITIALIZER_LIST(open_button_( |
| 56 new views::NativeTextButton(this, ASCIIToUTF16("Moar!")))) { | 56 new views::LabelButton(this, ASCIIToUTF16("Moar!")))) { |
| 57 ++g_color_index %= arraysize(g_colors); | 57 ++g_color_index %= arraysize(g_colors); |
| 58 open_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); |
| 58 AddChildView(open_button_); | 59 AddChildView(open_button_); |
| 59 } | 60 } |
| 60 virtual ~ModalWindow() { | 61 virtual ~ModalWindow() { |
| 61 } | 62 } |
| 62 | 63 |
| 63 static void OpenModalWindow(aura::Window* parent, ui::ModalType modal_type) { | 64 static void OpenModalWindow(aura::Window* parent, ui::ModalType modal_type) { |
| 64 views::Widget* widget = | 65 views::Widget* widget = |
| 65 views::Widget::CreateWindowWithParent(new ModalWindow(modal_type), | 66 views::Widget::CreateWindowWithParent(new ModalWindow(modal_type), |
| 66 parent); | 67 parent); |
| 67 widget->GetNativeView()->SetName("ModalWindow"); | 68 widget->GetNativeView()->SetName("ModalWindow"); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 // Overridden from views::ButtonListener: | 101 // Overridden from views::ButtonListener: |
| 101 virtual void ButtonPressed(views::Button* sender, | 102 virtual void ButtonPressed(views::Button* sender, |
| 102 const ui::Event& event) OVERRIDE { | 103 const ui::Event& event) OVERRIDE { |
| 103 DCHECK(sender == open_button_); | 104 DCHECK(sender == open_button_); |
| 104 OpenModalWindow(GetWidget()->GetNativeView(), modal_type_); | 105 OpenModalWindow(GetWidget()->GetNativeView(), modal_type_); |
| 105 } | 106 } |
| 106 | 107 |
| 107 private: | 108 private: |
| 108 ui::ModalType modal_type_; | 109 ui::ModalType modal_type_; |
| 109 SkColor color_; | 110 SkColor color_; |
| 110 views::NativeTextButton* open_button_; | 111 views::LabelButton* open_button_; |
| 111 | 112 |
| 112 DISALLOW_COPY_AND_ASSIGN(ModalWindow); | 113 DISALLOW_COPY_AND_ASSIGN(ModalWindow); |
| 113 }; | 114 }; |
| 114 | 115 |
| 115 class NonModalTransient : public views::WidgetDelegateView { | 116 class NonModalTransient : public views::WidgetDelegateView { |
| 116 public: | 117 public: |
| 117 NonModalTransient() | 118 NonModalTransient() |
| 118 : color_(g_colors[g_color_index]) { | 119 : color_(g_colors[g_color_index]) { |
| 119 ++g_color_index %= arraysize(g_colors); | 120 ++g_color_index %= arraysize(g_colors); |
| 120 } | 121 } |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 Shell::GetPrimaryRootWindow(), | 192 Shell::GetPrimaryRootWindow(), |
| 192 gfx::Rect(120, 150, 300, 410)); | 193 gfx::Rect(120, 150, 300, 410)); |
| 193 widget->GetNativeView()->SetName("WindowTypeLauncher"); | 194 widget->GetNativeView()->SetName("WindowTypeLauncher"); |
| 194 views::corewm::SetShadowType(widget->GetNativeView(), | 195 views::corewm::SetShadowType(widget->GetNativeView(), |
| 195 views::corewm::SHADOW_TYPE_RECTANGULAR); | 196 views::corewm::SHADOW_TYPE_RECTANGULAR); |
| 196 widget->Show(); | 197 widget->Show(); |
| 197 } | 198 } |
| 198 | 199 |
| 199 WindowTypeLauncher::WindowTypeLauncher() | 200 WindowTypeLauncher::WindowTypeLauncher() |
| 200 : ALLOW_THIS_IN_INITIALIZER_LIST(create_button_( | 201 : ALLOW_THIS_IN_INITIALIZER_LIST(create_button_( |
| 201 new views::NativeTextButton(this, ASCIIToUTF16("Create Window")))), | 202 new views::LabelButton(this, ASCIIToUTF16("Create Window")))), |
| 202 ALLOW_THIS_IN_INITIALIZER_LIST(create_persistant_button_( | 203 ALLOW_THIS_IN_INITIALIZER_LIST(create_persistant_button_( |
| 203 new views::NativeTextButton( | 204 new views::LabelButton( |
| 204 this, ASCIIToUTF16("Create Persistant Window")))), | 205 this, ASCIIToUTF16("Create Persistant Window")))), |
| 205 ALLOW_THIS_IN_INITIALIZER_LIST(panel_button_( | 206 ALLOW_THIS_IN_INITIALIZER_LIST(panel_button_( |
| 206 new views::NativeTextButton(this, ASCIIToUTF16("Create Panel")))), | 207 new views::LabelButton(this, ASCIIToUTF16("Create Panel")))), |
| 207 ALLOW_THIS_IN_INITIALIZER_LIST(create_nonresizable_button_( | 208 ALLOW_THIS_IN_INITIALIZER_LIST(create_nonresizable_button_( |
| 208 new views::NativeTextButton( | 209 new views::LabelButton( |
| 209 this, ASCIIToUTF16("Create Non-Resizable Window")))), | 210 this, ASCIIToUTF16("Create Non-Resizable Window")))), |
| 210 ALLOW_THIS_IN_INITIALIZER_LIST(bubble_button_( | 211 ALLOW_THIS_IN_INITIALIZER_LIST(bubble_button_( |
| 211 new views::NativeTextButton( | 212 new views::LabelButton( |
| 212 this, ASCIIToUTF16("Create Pointy Bubble")))), | 213 this, ASCIIToUTF16("Create Pointy Bubble")))), |
| 213 ALLOW_THIS_IN_INITIALIZER_LIST(lock_button_( | 214 ALLOW_THIS_IN_INITIALIZER_LIST(lock_button_( |
| 214 new views::NativeTextButton(this, ASCIIToUTF16("Lock Screen")))), | 215 new views::LabelButton(this, ASCIIToUTF16("Lock Screen")))), |
| 215 ALLOW_THIS_IN_INITIALIZER_LIST(widgets_button_( | 216 ALLOW_THIS_IN_INITIALIZER_LIST(widgets_button_( |
| 216 new views::NativeTextButton( | 217 new views::LabelButton( |
| 217 this, ASCIIToUTF16("Show Example Widgets")))), | 218 this, ASCIIToUTF16("Show Example Widgets")))), |
| 218 ALLOW_THIS_IN_INITIALIZER_LIST(system_modal_button_( | 219 ALLOW_THIS_IN_INITIALIZER_LIST(system_modal_button_( |
| 219 new views::NativeTextButton( | 220 new views::LabelButton( |
| 220 this, ASCIIToUTF16("Open System Modal Window")))), | 221 this, ASCIIToUTF16("Open System Modal Window")))), |
| 221 ALLOW_THIS_IN_INITIALIZER_LIST(window_modal_button_( | 222 ALLOW_THIS_IN_INITIALIZER_LIST(window_modal_button_( |
| 222 new views::NativeTextButton( | 223 new views::LabelButton( |
| 223 this, ASCIIToUTF16("Open Window Modal Window")))), | 224 this, ASCIIToUTF16("Open Window Modal Window")))), |
| 224 ALLOW_THIS_IN_INITIALIZER_LIST(child_modal_button_( | 225 ALLOW_THIS_IN_INITIALIZER_LIST(child_modal_button_( |
| 225 new views::NativeTextButton( | 226 new views::LabelButton( |
| 226 this, ASCIIToUTF16("Open Child Modal Window")))), | 227 this, ASCIIToUTF16("Open Child Modal Window")))), |
| 227 ALLOW_THIS_IN_INITIALIZER_LIST(transient_button_( | 228 ALLOW_THIS_IN_INITIALIZER_LIST(transient_button_( |
| 228 new views::NativeTextButton( | 229 new views::LabelButton( |
| 229 this, ASCIIToUTF16("Open Non-Modal Transient Window")))), | 230 this, ASCIIToUTF16("Open Non-Modal Transient Window")))), |
| 230 ALLOW_THIS_IN_INITIALIZER_LIST(examples_button_( | 231 ALLOW_THIS_IN_INITIALIZER_LIST(examples_button_( |
| 231 new views::NativeTextButton( | 232 new views::LabelButton( |
| 232 this, ASCIIToUTF16("Open Views Examples Window")))), | 233 this, ASCIIToUTF16("Open Views Examples Window")))), |
| 233 ALLOW_THIS_IN_INITIALIZER_LIST(show_hide_window_button_( | 234 ALLOW_THIS_IN_INITIALIZER_LIST(show_hide_window_button_( |
| 234 new views::NativeTextButton( | 235 new views::LabelButton( |
| 235 this, ASCIIToUTF16("Show/Hide a Window")))), | 236 this, ASCIIToUTF16("Show/Hide a Window")))), |
| 236 ALLOW_THIS_IN_INITIALIZER_LIST(show_screensaver_( | 237 ALLOW_THIS_IN_INITIALIZER_LIST(show_screensaver_( |
| 237 new views::NativeTextButton( | 238 new views::LabelButton( |
| 238 this, ASCIIToUTF16("Show the Screensaver [for 5 seconds]")))), | 239 this, ASCIIToUTF16("Show the Screensaver [for 5 seconds]")))), |
| 239 ALLOW_THIS_IN_INITIALIZER_LIST(show_web_notification_( | 240 ALLOW_THIS_IN_INITIALIZER_LIST(show_web_notification_( |
| 240 new views::NativeTextButton( | 241 new views::LabelButton( |
| 241 this, ASCIIToUTF16("Show a web/app notification")))) { | 242 this, ASCIIToUTF16("Show a web/app notification")))) { |
| 243 create_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); |
| 244 create_persistant_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); |
| 245 panel_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); |
| 246 create_nonresizable_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); |
| 247 bubble_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); |
| 248 lock_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); |
| 249 widgets_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); |
| 250 system_modal_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); |
| 251 window_modal_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); |
| 252 child_modal_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); |
| 253 transient_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); |
| 254 examples_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); |
| 255 show_hide_window_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); |
| 256 show_screensaver_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); |
| 257 show_web_notification_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); |
| 258 |
| 242 views::GridLayout* layout = new views::GridLayout(this); | 259 views::GridLayout* layout = new views::GridLayout(this); |
| 243 layout->SetInsets(5, 5, 5, 5); | 260 layout->SetInsets(5, 5, 5, 5); |
| 244 SetLayoutManager(layout); | 261 SetLayoutManager(layout); |
| 245 views::ColumnSet* column_set = layout->AddColumnSet(0); | 262 views::ColumnSet* column_set = layout->AddColumnSet(0); |
| 246 column_set->AddColumn(views::GridLayout::LEADING, | 263 column_set->AddColumn(views::GridLayout::LEADING, |
| 247 views::GridLayout::CENTER, | 264 views::GridLayout::CENTER, |
| 248 0, | 265 0, |
| 249 views::GridLayout::USE_PREF, | 266 views::GridLayout::USE_PREF, |
| 250 0, | 267 0, |
| 251 0); | 268 0); |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 if (menu_runner_->RunMenuAt(GetWidget(), NULL, gfx::Rect(point, gfx::Size()), | 407 if (menu_runner_->RunMenuAt(GetWidget(), NULL, gfx::Rect(point, gfx::Size()), |
| 391 MenuItemView::TOPLEFT, | 408 MenuItemView::TOPLEFT, |
| 392 MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU) == | 409 MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU) == |
| 393 MenuRunner::MENU_DELETED) | 410 MenuRunner::MENU_DELETED) |
| 394 return; | 411 return; |
| 395 } | 412 } |
| 396 #endif // !defined(OS_MACOSX) | 413 #endif // !defined(OS_MACOSX) |
| 397 | 414 |
| 398 } // namespace shell | 415 } // namespace shell |
| 399 } // namespace ash | 416 } // namespace ash |
| OLD | NEW |