| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "ash/common/session/session_state_delegate.h" | 9 #include "ash/common/session/session_state_delegate.h" |
| 10 #include "ash/common/shelf/shelf_widget.h" | 10 #include "ash/common/shelf/shelf_widget.h" |
| 11 #include "ash/common/shell_window_ids.h" | 11 #include "ash/common/shell_window_ids.h" |
| 12 #include "ash/common/system/status_area_widget.h" | 12 #include "ash/common/system/status_area_widget.h" |
| 13 #include "ash/common/system/web_notification/web_notification_tray.h" | 13 #include "ash/common/system/web_notification/web_notification_tray.h" |
| 14 #include "ash/common/wm_shell.h" | 14 #include "ash/common/wm_shell.h" |
| 15 #include "ash/content/shell_content_state.h" | 15 #include "ash/content/shell_content_state.h" |
| 16 #include "ash/root_window_controller.h" | 16 #include "ash/root_window_controller.h" |
| 17 #include "ash/shell.h" | 17 #include "ash/shell.h" |
| 18 #include "ash/shell/example_factory.h" | 18 #include "ash/shell/example_factory.h" |
| 19 #include "ash/shell/panel_window.h" | 19 #include "ash/shell/panel_window.h" |
| 20 #include "ash/shell/toplevel_window.h" | 20 #include "ash/shell/toplevel_window.h" |
| 21 #include "ash/test/child_modal_window.h" | 21 #include "ash/test/child_modal_window.h" |
| 22 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
| 23 #include "ui/aura/window.h" | 23 #include "ui/aura/window.h" |
| 24 #include "ui/aura/window_event_dispatcher.h" | 24 #include "ui/aura/window_event_dispatcher.h" |
| 25 #include "ui/compositor/layer.h" | 25 #include "ui/compositor/layer.h" |
| 26 #include "ui/gfx/canvas.h" | 26 #include "ui/gfx/canvas.h" |
| 27 #include "ui/message_center/message_center.h" | 27 #include "ui/message_center/message_center.h" |
| 28 #include "ui/message_center/notification_types.h" | 28 #include "ui/message_center/notification_types.h" |
| 29 #include "ui/views/controls/button/label_button.h" | 29 #include "ui/views/controls/button/md_text_button.h" |
| 30 #include "ui/views/controls/menu/menu_item_view.h" | 30 #include "ui/views/controls/menu/menu_item_view.h" |
| 31 #include "ui/views/controls/menu/menu_runner.h" | 31 #include "ui/views/controls/menu/menu_runner.h" |
| 32 #include "ui/views/examples/examples_window_with_content.h" | 32 #include "ui/views/examples/examples_window_with_content.h" |
| 33 #include "ui/views/layout/grid_layout.h" | 33 #include "ui/views/layout/grid_layout.h" |
| 34 #include "ui/views/widget/widget.h" | 34 #include "ui/views/widget/widget.h" |
| 35 #include "ui/wm/core/shadow_types.h" | 35 #include "ui/wm/core/shadow_types.h" |
| 36 | 36 |
| 37 using views::MdTextButton; |
| 37 using views::MenuItemView; | 38 using views::MenuItemView; |
| 38 using views::MenuRunner; | 39 using views::MenuRunner; |
| 39 | 40 |
| 40 namespace ash { | 41 namespace ash { |
| 41 namespace shell { | 42 namespace shell { |
| 42 | 43 |
| 43 namespace { | 44 namespace { |
| 44 | 45 |
| 45 SkColor g_colors[] = {SK_ColorRED, SK_ColorYELLOW, SK_ColorBLUE, SK_ColorGREEN}; | 46 SkColor g_colors[] = {SK_ColorRED, SK_ColorYELLOW, SK_ColorBLUE, SK_ColorGREEN}; |
| 46 int g_color_index = 0; | 47 int g_color_index = 0; |
| 47 | 48 |
| 48 class ModalWindow : public views::WidgetDelegateView, | 49 class ModalWindow : public views::WidgetDelegateView, |
| 49 public views::ButtonListener { | 50 public views::ButtonListener { |
| 50 public: | 51 public: |
| 51 explicit ModalWindow(ui::ModalType modal_type) | 52 explicit ModalWindow(ui::ModalType modal_type) |
| 52 : modal_type_(modal_type), | 53 : modal_type_(modal_type), |
| 53 color_(g_colors[g_color_index]), | 54 color_(g_colors[g_color_index]), |
| 54 open_button_( | 55 open_button_( |
| 55 new views::LabelButton(this, base::ASCIIToUTF16("Moar!"))) { | 56 MdTextButton::CreateMdButton(this, base::ASCIIToUTF16("Moar!"))) { |
| 56 ++g_color_index %= arraysize(g_colors); | 57 ++g_color_index %= arraysize(g_colors); |
| 57 open_button_->SetStyle(views::Button::STYLE_BUTTON); | |
| 58 AddChildView(open_button_); | 58 AddChildView(open_button_); |
| 59 } | 59 } |
| 60 ~ModalWindow() override {} | 60 ~ModalWindow() override {} |
| 61 | 61 |
| 62 static void OpenModalWindow(aura::Window* parent, ui::ModalType modal_type) { | 62 static void OpenModalWindow(aura::Window* parent, ui::ModalType modal_type) { |
| 63 views::Widget* widget = views::Widget::CreateWindowWithParent( | 63 views::Widget* widget = views::Widget::CreateWindowWithParent( |
| 64 new ModalWindow(modal_type), parent); | 64 new ModalWindow(modal_type), parent); |
| 65 widget->GetNativeView()->SetName("ModalWindow"); | 65 widget->GetNativeView()->SetName("ModalWindow"); |
| 66 widget->Show(); | 66 widget->Show(); |
| 67 } | 67 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 88 | 88 |
| 89 // Overridden from views::ButtonListener: | 89 // Overridden from views::ButtonListener: |
| 90 void ButtonPressed(views::Button* sender, const ui::Event& event) override { | 90 void ButtonPressed(views::Button* sender, const ui::Event& event) override { |
| 91 DCHECK(sender == open_button_); | 91 DCHECK(sender == open_button_); |
| 92 OpenModalWindow(GetWidget()->GetNativeView(), modal_type_); | 92 OpenModalWindow(GetWidget()->GetNativeView(), modal_type_); |
| 93 } | 93 } |
| 94 | 94 |
| 95 private: | 95 private: |
| 96 ui::ModalType modal_type_; | 96 ui::ModalType modal_type_; |
| 97 SkColor color_; | 97 SkColor color_; |
| 98 views::LabelButton* open_button_; | 98 views::Button* open_button_; |
| 99 | 99 |
| 100 DISALLOW_COPY_AND_ASSIGN(ModalWindow); | 100 DISALLOW_COPY_AND_ASSIGN(ModalWindow); |
| 101 }; | 101 }; |
| 102 | 102 |
| 103 class NonModalTransient : public views::WidgetDelegateView { | 103 class NonModalTransient : public views::WidgetDelegateView { |
| 104 public: | 104 public: |
| 105 NonModalTransient() : color_(g_colors[g_color_index]) { | 105 NonModalTransient() : color_(g_colors[g_color_index]) { |
| 106 ++g_color_index %= arraysize(g_colors); | 106 ++g_color_index %= arraysize(g_colors); |
| 107 } | 107 } |
| 108 ~NonModalTransient() override {} | 108 ~NonModalTransient() override {} |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds( | 168 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds( |
| 169 new WindowTypeLauncher, Shell::GetPrimaryRootWindow(), | 169 new WindowTypeLauncher, Shell::GetPrimaryRootWindow(), |
| 170 gfx::Rect(120, 150, 300, 410)); | 170 gfx::Rect(120, 150, 300, 410)); |
| 171 widget->GetNativeView()->SetName("WindowTypeLauncher"); | 171 widget->GetNativeView()->SetName("WindowTypeLauncher"); |
| 172 ::wm::SetShadowType(widget->GetNativeView(), ::wm::SHADOW_TYPE_RECTANGULAR); | 172 ::wm::SetShadowType(widget->GetNativeView(), ::wm::SHADOW_TYPE_RECTANGULAR); |
| 173 widget->Show(); | 173 widget->Show(); |
| 174 } | 174 } |
| 175 | 175 |
| 176 WindowTypeLauncher::WindowTypeLauncher() | 176 WindowTypeLauncher::WindowTypeLauncher() |
| 177 : create_button_( | 177 : create_button_( |
| 178 new views::LabelButton(this, base::ASCIIToUTF16("Create Window"))), | 178 MdTextButton::CreateMdButton(this, |
| 179 base::ASCIIToUTF16("Create Window"))), |
| 179 panel_button_( | 180 panel_button_( |
| 180 new views::LabelButton(this, base::ASCIIToUTF16("Create Panel"))), | 181 MdTextButton::CreateMdButton(this, |
| 181 create_nonresizable_button_(new views::LabelButton( | 182 base::ASCIIToUTF16("Create Panel"))), |
| 183 create_nonresizable_button_(MdTextButton::CreateMdButton( |
| 182 this, | 184 this, |
| 183 base::ASCIIToUTF16("Create Non-Resizable Window"))), | 185 base::ASCIIToUTF16("Create Non-Resizable Window"))), |
| 184 bubble_button_( | 186 bubble_button_(MdTextButton::CreateMdButton( |
| 185 new views::LabelButton(this, | 187 this, |
| 186 base::ASCIIToUTF16("Create Pointy Bubble"))), | 188 base::ASCIIToUTF16("Create Pointy Bubble"))), |
| 187 lock_button_( | 189 lock_button_( |
| 188 new views::LabelButton(this, base::ASCIIToUTF16("Lock Screen"))), | 190 MdTextButton::CreateMdButton(this, |
| 189 widgets_button_( | 191 base::ASCIIToUTF16("Lock Screen"))), |
| 190 new views::LabelButton(this, | 192 widgets_button_(MdTextButton::CreateMdButton( |
| 191 base::ASCIIToUTF16("Show Example Widgets"))), | 193 this, |
| 192 system_modal_button_(new views::LabelButton( | 194 base::ASCIIToUTF16("Show Example Widgets"))), |
| 195 system_modal_button_(MdTextButton::CreateMdButton( |
| 193 this, | 196 this, |
| 194 base::ASCIIToUTF16("Open System Modal Window"))), | 197 base::ASCIIToUTF16("Open System Modal Window"))), |
| 195 window_modal_button_(new views::LabelButton( | 198 window_modal_button_(MdTextButton::CreateMdButton( |
| 196 this, | 199 this, |
| 197 base::ASCIIToUTF16("Open Window Modal Window"))), | 200 base::ASCIIToUTF16("Open Window Modal Window"))), |
| 198 child_modal_button_(new views::LabelButton( | 201 child_modal_button_(MdTextButton::CreateMdButton( |
| 199 this, | 202 this, |
| 200 base::ASCIIToUTF16("Open Child Modal Window"))), | 203 base::ASCIIToUTF16("Open Child Modal Window"))), |
| 201 transient_button_(new views::LabelButton( | 204 transient_button_(MdTextButton::CreateMdButton( |
| 202 this, | 205 this, |
| 203 base::ASCIIToUTF16("Open Non-Modal Transient Window"))), | 206 base::ASCIIToUTF16("Open Non-Modal Transient Window"))), |
| 204 examples_button_(new views::LabelButton( | 207 examples_button_(MdTextButton::CreateMdButton( |
| 205 this, | 208 this, |
| 206 base::ASCIIToUTF16("Open Views Examples Window"))), | 209 base::ASCIIToUTF16("Open Views Examples Window"))), |
| 207 show_hide_window_button_( | 210 show_hide_window_button_(MdTextButton::CreateMdButton( |
| 208 new views::LabelButton(this, | 211 this, |
| 209 base::ASCIIToUTF16("Show/Hide a Window"))), | 212 base::ASCIIToUTF16("Show/Hide a Window"))), |
| 210 show_web_notification_(new views::LabelButton( | 213 show_web_notification_(MdTextButton::CreateMdButton( |
| 211 this, | 214 this, |
| 212 base::ASCIIToUTF16("Show a web/app notification"))) { | 215 base::ASCIIToUTF16("Show a web/app notification"))) { |
| 213 create_button_->SetStyle(views::Button::STYLE_BUTTON); | |
| 214 panel_button_->SetStyle(views::Button::STYLE_BUTTON); | |
| 215 create_nonresizable_button_->SetStyle(views::Button::STYLE_BUTTON); | |
| 216 bubble_button_->SetStyle(views::Button::STYLE_BUTTON); | |
| 217 lock_button_->SetStyle(views::Button::STYLE_BUTTON); | |
| 218 widgets_button_->SetStyle(views::Button::STYLE_BUTTON); | |
| 219 system_modal_button_->SetStyle(views::Button::STYLE_BUTTON); | |
| 220 window_modal_button_->SetStyle(views::Button::STYLE_BUTTON); | |
| 221 child_modal_button_->SetStyle(views::Button::STYLE_BUTTON); | |
| 222 transient_button_->SetStyle(views::Button::STYLE_BUTTON); | |
| 223 examples_button_->SetStyle(views::Button::STYLE_BUTTON); | |
| 224 show_hide_window_button_->SetStyle(views::Button::STYLE_BUTTON); | |
| 225 show_web_notification_->SetStyle(views::Button::STYLE_BUTTON); | |
| 226 | |
| 227 views::GridLayout* layout = new views::GridLayout(this); | 216 views::GridLayout* layout = new views::GridLayout(this); |
| 228 layout->SetInsets(5, 5, 5, 5); | 217 layout->SetInsets(5, 5, 5, 5); |
| 229 SetLayoutManager(layout); | 218 SetLayoutManager(layout); |
| 230 views::ColumnSet* column_set = layout->AddColumnSet(0); | 219 views::ColumnSet* column_set = layout->AddColumnSet(0); |
| 231 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, | 220 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, |
| 232 0, views::GridLayout::USE_PREF, 0, 0); | 221 0, views::GridLayout::USE_PREF, 0, 0); |
| 233 AddViewToLayout(layout, create_button_); | 222 AddViewToLayout(layout, create_button_); |
| 234 AddViewToLayout(layout, panel_button_); | 223 AddViewToLayout(layout, panel_button_); |
| 235 AddViewToLayout(layout, create_nonresizable_button_); | 224 AddViewToLayout(layout, create_nonresizable_button_); |
| 236 AddViewToLayout(layout, bubble_button_); | 225 AddViewToLayout(layout, bubble_button_); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 views::MenuRunner::ASYNC)); | 348 views::MenuRunner::ASYNC)); |
| 360 if (menu_runner_->RunMenuAt(GetWidget(), NULL, gfx::Rect(point, gfx::Size()), | 349 if (menu_runner_->RunMenuAt(GetWidget(), NULL, gfx::Rect(point, gfx::Size()), |
| 361 views::MENU_ANCHOR_TOPLEFT, | 350 views::MENU_ANCHOR_TOPLEFT, |
| 362 source_type) == MenuRunner::MENU_DELETED) { | 351 source_type) == MenuRunner::MENU_DELETED) { |
| 363 return; | 352 return; |
| 364 } | 353 } |
| 365 } | 354 } |
| 366 | 355 |
| 367 } // namespace shell | 356 } // namespace shell |
| 368 } // namespace ash | 357 } // namespace ash |
| OLD | NEW |