| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "views/examples/widget_example.h" | 5 #include "views/examples/widget_example.h" |
| 6 | 6 |
| 7 #include "views/controls/button/native_button.h" | 7 #include "views/controls/button/native_button.h" |
| 8 #include "views/layout/box_layout.h" | 8 #include "views/layout/box_layout.h" |
| 9 #include "views/layout/layout_manager.h" | 9 #include "views/layout/layout_manager.h" |
| 10 #include "views/view.h" | 10 #include "views/view.h" |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 widget_container->set_background( | 101 widget_container->set_background( |
| 102 views::Background::CreateStandardPanelBackground()); | 102 views::Background::CreateStandardPanelBackground()); |
| 103 } | 103 } |
| 104 | 104 |
| 105 // Show the widget. | 105 // Show the widget. |
| 106 widget->Show(); | 106 widget->Show(); |
| 107 } | 107 } |
| 108 | 108 |
| 109 #if defined(OS_LINUX) | 109 #if defined(OS_LINUX) |
| 110 void WidgetExample::CreateChild(views::View* parent, bool transparent) { | 110 void WidgetExample::CreateChild(views::View* parent, bool transparent) { |
| 111 views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_CONTROL); | 111 views::Widget* widget = views::Widget::CreateWidget(); |
| 112 params.transparent = transparent; | |
| 113 views::Widget* widget = views::Widget::CreateWidget(params); | |
| 114 // Compute where to place the child widget. | 112 // Compute where to place the child widget. |
| 115 // We'll place it at the center of the root widget. | 113 // We'll place it at the center of the root widget. |
| 116 views::Widget* parent_widget = parent->GetWidget(); | 114 views::Widget* parent_widget = parent->GetWidget(); |
| 117 gfx::Rect bounds = parent_widget->GetClientAreaScreenBounds(); | 115 gfx::Rect bounds = parent_widget->GetClientAreaScreenBounds(); |
| 118 // Child widget is 200x200 square. | 116 // Child widget is 200x200 square. |
| 119 bounds.SetRect((bounds.width() - 200) / 2, (bounds.height() - 200) / 2, | 117 bounds.SetRect((bounds.width() - 200) / 2, (bounds.height() - 200) / 2, |
| 120 200, 200); | 118 200, 200); |
| 121 // Initialize the child widget with the computed bounds. | 119 // Initialize the child widget with the computed bounds. |
| 122 widget->InitWithWidget(parent_widget, bounds); | 120 views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_CONTROL); |
| 121 params.transparent = transparent; |
| 122 params.parent_widget = parent_widget; |
| 123 widget->Init(params); |
| 123 InitWidget(widget, transparent); | 124 InitWidget(widget, transparent); |
| 124 } | 125 } |
| 125 #endif | 126 #endif |
| 126 | 127 |
| 127 void WidgetExample::CreatePopup(views::View* parent, bool transparent) { | 128 void WidgetExample::CreatePopup(views::View* parent, bool transparent) { |
| 128 views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_POPUP); | 129 views::Widget* widget = views::Widget::CreateWidget(); |
| 129 params.transparent = transparent; | |
| 130 views::Widget* widget = views::Widget::CreateWidget(params); | |
| 131 | 130 |
| 132 // Compute where to place the popup widget. | 131 // Compute where to place the popup widget. |
| 133 // We'll place it right below the create button. | 132 // We'll place it right below the create button. |
| 134 gfx::Point point = parent->GetMirroredPosition(); | 133 gfx::Point point = parent->GetMirroredPosition(); |
| 135 // The position in point is relative to the parent. Make it absolute. | 134 // The position in point is relative to the parent. Make it absolute. |
| 136 views::View::ConvertPointToScreen(parent, &point); | 135 views::View::ConvertPointToScreen(parent, &point); |
| 137 // Add the height of create_button_. | 136 // Add the height of create_button_. |
| 138 point.Offset(0, parent->size().height()); | 137 point.Offset(0, parent->size().height()); |
| 139 gfx::Rect bounds(point.x(), point.y(), 200, 300); | 138 |
| 140 // Initialize the popup widget with the computed bounds. | 139 // Initialize the popup widget with the computed bounds. |
| 141 widget->InitWithWidget(parent->GetWidget(), bounds); | 140 views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_POPUP); |
| 141 params.transparent = transparent; |
| 142 params.parent_widget = parent->GetWidget(); |
| 143 params.bounds = gfx::Rect(point.x(), point.y(), 200, 300); |
| 144 widget->Init(params); |
| 142 InitWidget(widget, transparent); | 145 InitWidget(widget, transparent); |
| 143 } | 146 } |
| 144 | 147 |
| 145 void WidgetExample::ButtonPressed(views::Button* sender, | 148 void WidgetExample::ButtonPressed(views::Button* sender, |
| 146 const views::Event& event) { | 149 const views::Event& event) { |
| 147 switch (sender->tag()) { | 150 switch (sender->tag()) { |
| 148 case POPUP: | 151 case POPUP: |
| 149 CreatePopup(sender, false); | 152 CreatePopup(sender, false); |
| 150 break; | 153 break; |
| 151 case TRANSPARENT_POPUP: | 154 case TRANSPARENT_POPUP: |
| 152 CreatePopup(sender, true); | 155 CreatePopup(sender, true); |
| 153 break; | 156 break; |
| 154 #if defined(OS_LINUX) | 157 #if defined(OS_LINUX) |
| 155 case CHILD: | 158 case CHILD: |
| 156 CreateChild(sender, false); | 159 CreateChild(sender, false); |
| 157 break; | 160 break; |
| 158 case TRANSPARENT_CHILD: | 161 case TRANSPARENT_CHILD: |
| 159 CreateChild(sender, true); | 162 CreateChild(sender, true); |
| 160 break; | 163 break; |
| 161 #endif | 164 #endif |
| 162 case CLOSE_WIDGET: | 165 case CLOSE_WIDGET: |
| 163 sender->GetWidget()->Close(); | 166 sender->GetWidget()->Close(); |
| 164 break; | 167 break; |
| 165 } | 168 } |
| 166 } | 169 } |
| 167 | 170 |
| 168 } // namespace examples | 171 } // namespace examples |
| OLD | NEW |