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

Side by Side Diff: ui/views/examples/widget_example.cc

Issue 11756005: Implement rough new dialog style. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments. Created 7 years, 11 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 | « ui/views/controls/button/label_button.cc ('k') | ui/views/window/dialog_delegate.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 "ui/views/examples/widget_example.h" 5 #include "ui/views/examples/widget_example.h"
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "ui/views/controls/button/text_button.h" 8 #include "ui/views/controls/button/text_button.h"
9 #include "ui/views/layout/box_layout.h" 9 #include "ui/views/layout/box_layout.h"
10 #include "ui/views/view.h" 10 #include "ui/views/view.h"
11 #include "ui/views/widget/widget.h" 11 #include "ui/views/widget/widget.h"
12 #include "ui/views/window/dialog_delegate.h" 12 #include "ui/views/window/dialog_delegate.h"
13 13
14 namespace views { 14 namespace views {
15 namespace examples { 15 namespace examples {
16 16
17 namespace {
18
19 class DialogExample : public DialogDelegateView {
20 public:
21 virtual string16 GetWindowTitle() const OVERRIDE;
22 };
23
24 string16 DialogExample::GetWindowTitle() const {
25 return ASCIIToUTF16("Dialog Widget Example");
26 }
27
28 } // namespace
29
17 WidgetExample::WidgetExample() : ExampleBase("Widget") { 30 WidgetExample::WidgetExample() : ExampleBase("Widget") {
18 } 31 }
19 32
20 WidgetExample::~WidgetExample() { 33 WidgetExample::~WidgetExample() {
21 } 34 }
22 35
23 void WidgetExample::CreateExampleView(View* container) { 36 void WidgetExample::CreateExampleView(View* container) {
24 container->SetLayoutManager(new BoxLayout(BoxLayout::kHorizontal, 0, 0, 2)); 37 container->SetLayoutManager(new BoxLayout(BoxLayout::kHorizontal, 0, 0, 2));
25 BuildButton(container, "Popup widget", POPUP); 38 BuildButton(container, "Popup widget", POPUP);
26 BuildButton(container, "Dialog widget", DIALOG); 39 BuildButton(container, "Dialog widget", DIALOG);
27 #if defined(OS_LINUX) 40 #if defined(OS_LINUX)
28 // Windows does not support TYPE_CONTROL top-level widgets. 41 // Windows does not support TYPE_CONTROL top-level widgets.
29 BuildButton(container, "Child widget", CHILD); 42 BuildButton(container, "Child widget", CHILD);
30 #endif 43 #endif
31 } 44 }
32 45
33 void WidgetExample::BuildButton(View* container, 46 void WidgetExample::BuildButton(View* container,
34 const std::string& label, 47 const std::string& label,
35 int tag) { 48 int tag) {
36 TextButton* button = new TextButton(this, ASCIIToUTF16(label)); 49 TextButton* button = new TextButton(this, ASCIIToUTF16(label));
50 button->set_focusable(true);
37 button->set_tag(tag); 51 button->set_tag(tag);
38 container->AddChildView(button); 52 container->AddChildView(button);
39 } 53 }
40 54
41 void WidgetExample::ShowWidget(View* sender, Widget::InitParams params) { 55 void WidgetExample::ShowWidget(View* sender, Widget::InitParams params) {
42 // Setup shared Widget heirarchy and bounds parameters. 56 // Setup shared Widget heirarchy and bounds parameters.
43 params.parent = sender->GetWidget()->GetNativeView(); 57 params.parent = sender->GetWidget()->GetNativeView();
44 params.bounds = gfx::Rect(sender->GetBoundsInScreen().CenterPoint(), 58 params.bounds = gfx::Rect(sender->GetBoundsInScreen().CenterPoint(),
45 gfx::Size(200, 100)); 59 gfx::Size(300, 200));
46 60
47 Widget* widget = new Widget(); 61 Widget* widget = new Widget();
48 widget->Init(params); 62 widget->Init(params);
49 63
50 // If the Widget has no contents by default, add a view with a 'Close' button. 64 // If the Widget has no contents by default, add a view with a 'Close' button.
51 if (!widget->GetContentsView()) { 65 if (!widget->GetContentsView()) {
52 View* contents = new View(); 66 View* contents = new View();
53 contents->SetLayoutManager(new BoxLayout(BoxLayout::kHorizontal, 0, 0, 0)); 67 contents->SetLayoutManager(new BoxLayout(BoxLayout::kHorizontal, 0, 0, 0));
54 contents->set_background(Background::CreateSolidBackground(SK_ColorGRAY)); 68 contents->set_background(Background::CreateSolidBackground(SK_ColorGRAY));
55 BuildButton(contents, "Close", CLOSE_WIDGET); 69 BuildButton(contents, "Close", CLOSE_WIDGET);
56 widget->SetContentsView(contents); 70 widget->SetContentsView(contents);
57 } 71 }
58 72
59 widget->Show(); 73 widget->Show();
60 } 74 }
61 75
62 void WidgetExample::ButtonPressed(Button* sender, const ui::Event& event) { 76 void WidgetExample::ButtonPressed(Button* sender, const ui::Event& event) {
63 switch (sender->tag()) { 77 switch (sender->tag()) {
64 case POPUP: 78 case POPUP:
65 ShowWidget(sender, Widget::InitParams(Widget::InitParams::TYPE_POPUP)); 79 ShowWidget(sender, Widget::InitParams(Widget::InitParams::TYPE_POPUP));
66 break; 80 break;
67 case DIALOG: { 81 case DIALOG: {
68 Widget::InitParams params(Widget::InitParams::TYPE_WINDOW); 82 Widget::InitParams params(Widget::InitParams::TYPE_WINDOW);
69 params.delegate = new DialogDelegateView(); 83 params.delegate = new DialogExample();
84 params.remove_standard_frame = true;
85 params.transparent = true;
70 ShowWidget(sender, params); 86 ShowWidget(sender, params);
71 break; 87 break;
72 } 88 }
73 case CHILD: 89 case CHILD:
74 ShowWidget(sender, Widget::InitParams(Widget::InitParams::TYPE_CONTROL)); 90 ShowWidget(sender, Widget::InitParams(Widget::InitParams::TYPE_CONTROL));
75 break; 91 break;
76 case CLOSE_WIDGET: 92 case CLOSE_WIDGET:
77 sender->GetWidget()->Close(); 93 sender->GetWidget()->Close();
78 break; 94 break;
79 } 95 }
80 } 96 }
81 97
82 } // namespace examples 98 } // namespace examples
83 } // namespace views 99 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/button/label_button.cc ('k') | ui/views/window/dialog_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698