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 "ui/views/examples/widget_example.h" | 5 #include "ui/views/examples/widget_example.h" |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "ui/views/background.h" | 8 #include "ui/views/background.h" |
9 #include "ui/views/controls/button/label_button.h" | 9 #include "ui/views/controls/button/label_button.h" |
10 #include "ui/views/controls/label.h" | 10 #include "ui/views/controls/label.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 class DialogExample : public DialogDelegateView { | 23 class DialogExample : public DialogDelegateView { |
24 public: | 24 public: |
25 DialogExample(); | 25 DialogExample(); |
26 ~DialogExample() override; | 26 ~DialogExample() override; |
27 base::string16 GetWindowTitle() const override; | 27 base::string16 GetWindowTitle() const override; |
28 View* CreateExtraView() override; | 28 View* CreateExtraView() override; |
29 View* CreateTitlebarExtraView() override; | 29 View* CreateTitlebarExtraView() override; |
30 View* CreateFootnoteView() override; | 30 View* CreateFootnoteView() override; |
31 }; | 31 }; |
32 | 32 |
| 33 class ModalDialogExample : public DialogExample { |
| 34 public: |
| 35 ModalDialogExample() {} |
| 36 |
| 37 // WidgetDelegate: |
| 38 ui::ModalType GetModalType() const override { return ui::MODAL_TYPE_WINDOW; } |
| 39 |
| 40 private: |
| 41 DISALLOW_COPY_AND_ASSIGN(ModalDialogExample); |
| 42 }; |
| 43 |
33 DialogExample::DialogExample() { | 44 DialogExample::DialogExample() { |
34 set_background(Background::CreateSolidBackground(SK_ColorGRAY)); | 45 set_background(Background::CreateSolidBackground(SK_ColorGRAY)); |
35 SetLayoutManager(new BoxLayout(BoxLayout::kVertical, 10, 10, 10)); | 46 SetLayoutManager(new BoxLayout(BoxLayout::kVertical, 10, 10, 10)); |
36 AddChildView(new Label(ASCIIToUTF16("Dialog contents label!"))); | 47 AddChildView(new Label(ASCIIToUTF16("Dialog contents label!"))); |
37 } | 48 } |
38 | 49 |
39 DialogExample::~DialogExample() {} | 50 DialogExample::~DialogExample() {} |
40 | 51 |
41 base::string16 DialogExample::GetWindowTitle() const { | 52 base::string16 DialogExample::GetWindowTitle() const { |
42 return ASCIIToUTF16("Dialog Widget Example"); | 53 return ASCIIToUTF16("Dialog Widget Example"); |
(...skipping 20 matching lines...) Expand all Loading... |
63 WidgetExample::WidgetExample() : ExampleBase("Widget") { | 74 WidgetExample::WidgetExample() : ExampleBase("Widget") { |
64 } | 75 } |
65 | 76 |
66 WidgetExample::~WidgetExample() { | 77 WidgetExample::~WidgetExample() { |
67 } | 78 } |
68 | 79 |
69 void WidgetExample::CreateExampleView(View* container) { | 80 void WidgetExample::CreateExampleView(View* container) { |
70 container->SetLayoutManager(new BoxLayout(BoxLayout::kHorizontal, 0, 0, 10)); | 81 container->SetLayoutManager(new BoxLayout(BoxLayout::kHorizontal, 0, 0, 10)); |
71 BuildButton(container, "Popup widget", POPUP); | 82 BuildButton(container, "Popup widget", POPUP); |
72 BuildButton(container, "Dialog widget", DIALOG); | 83 BuildButton(container, "Dialog widget", DIALOG); |
| 84 BuildButton(container, "Modal Dialog", MODAL_DIALOG); |
73 #if defined(OS_LINUX) | 85 #if defined(OS_LINUX) |
74 // Windows does not support TYPE_CONTROL top-level widgets. | 86 // Windows does not support TYPE_CONTROL top-level widgets. |
75 BuildButton(container, "Child widget", CHILD); | 87 BuildButton(container, "Child widget", CHILD); |
76 #endif | 88 #endif |
77 } | 89 } |
78 | 90 |
79 void WidgetExample::BuildButton(View* container, | 91 void WidgetExample::BuildButton(View* container, |
80 const std::string& label, | 92 const std::string& label, |
81 int tag) { | 93 int tag) { |
82 LabelButton* button = new LabelButton(this, ASCIIToUTF16(label)); | 94 LabelButton* button = new LabelButton(this, ASCIIToUTF16(label)); |
(...skipping 26 matching lines...) Expand all Loading... |
109 void WidgetExample::ButtonPressed(Button* sender, const ui::Event& event) { | 121 void WidgetExample::ButtonPressed(Button* sender, const ui::Event& event) { |
110 switch (sender->tag()) { | 122 switch (sender->tag()) { |
111 case POPUP: | 123 case POPUP: |
112 ShowWidget(sender, Widget::InitParams(Widget::InitParams::TYPE_POPUP)); | 124 ShowWidget(sender, Widget::InitParams(Widget::InitParams::TYPE_POPUP)); |
113 break; | 125 break; |
114 case DIALOG: { | 126 case DIALOG: { |
115 DialogDelegate::CreateDialogWidget(new DialogExample(), NULL, | 127 DialogDelegate::CreateDialogWidget(new DialogExample(), NULL, |
116 sender->GetWidget()->GetNativeView())->Show(); | 128 sender->GetWidget()->GetNativeView())->Show(); |
117 break; | 129 break; |
118 } | 130 } |
| 131 case MODAL_DIALOG: { |
| 132 DialogDelegate::CreateDialogWidget(new ModalDialogExample(), NULL, |
| 133 sender->GetWidget()->GetNativeView())->Show(); |
| 134 break; |
| 135 } |
119 case CHILD: | 136 case CHILD: |
120 ShowWidget(sender, Widget::InitParams(Widget::InitParams::TYPE_CONTROL)); | 137 ShowWidget(sender, Widget::InitParams(Widget::InitParams::TYPE_CONTROL)); |
121 break; | 138 break; |
122 case CLOSE_WIDGET: | 139 case CLOSE_WIDGET: |
123 sender->GetWidget()->Close(); | 140 sender->GetWidget()->Close(); |
124 break; | 141 break; |
125 } | 142 } |
126 } | 143 } |
127 | 144 |
128 } // namespace examples | 145 } // namespace examples |
129 } // namespace views | 146 } // namespace views |
OLD | NEW |