| 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 11 matching lines...) Expand all Loading... |
| 22 // Overridden from LayoutManager: | 22 // Overridden from LayoutManager: |
| 23 virtual void Layout(views::View* host) { | 23 virtual void Layout(views::View* host) { |
| 24 views::View* child = host->GetChildViewAt(0); | 24 views::View* child = host->GetChildViewAt(0); |
| 25 gfx::Size size = child->GetPreferredSize(); | 25 gfx::Size size = child->GetPreferredSize(); |
| 26 child->SetBounds((host->width() - size.width()) / 2, | 26 child->SetBounds((host->width() - size.width()) / 2, |
| 27 (host->height() - size.height()) / 2, | 27 (host->height() - size.height()) / 2, |
| 28 size.width(), size.height()); | 28 size.width(), size.height()); |
| 29 } | 29 } |
| 30 | 30 |
| 31 virtual gfx::Size GetPreferredSize(views::View* host) { | 31 virtual gfx::Size GetPreferredSize(views::View* host) { |
| 32 return host->GetPreferredSize(); | 32 return gfx::Size(); |
| 33 } | 33 } |
| 34 | 34 |
| 35 private: | 35 private: |
| 36 DISALLOW_COPY_AND_ASSIGN(CenterLayout); | 36 DISALLOW_COPY_AND_ASSIGN(CenterLayout); |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 } // namespace | 39 } // namespace |
| 40 | 40 |
| 41 namespace examples { | 41 namespace examples { |
| 42 | 42 |
| (...skipping 58 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* widget = views::Widget::CreateWidget(); | 111 views::Widget* widget = new views::Widget; |
| 112 // Compute where to place the child widget. | 112 // Compute where to place the child widget. |
| 113 // We'll place it at the center of the root widget. | 113 // We'll place it at the center of the root widget. |
| 114 views::Widget* parent_widget = parent->GetWidget(); | 114 views::Widget* parent_widget = parent->GetWidget(); |
| 115 gfx::Rect bounds = parent_widget->GetClientAreaScreenBounds(); | 115 gfx::Rect bounds = parent_widget->GetClientAreaScreenBounds(); |
| 116 // Child widget is 200x200 square. | 116 // Child widget is 200x200 square. |
| 117 bounds.SetRect((bounds.width() - 200) / 2, (bounds.height() - 200) / 2, | 117 bounds.SetRect((bounds.width() - 200) / 2, (bounds.height() - 200) / 2, |
| 118 200, 200); | 118 200, 200); |
| 119 // Initialize the child widget with the computed bounds. | 119 // Initialize the child widget with the computed bounds. |
| 120 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); | 120 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); |
| 121 params.transparent = transparent; | 121 params.transparent = transparent; |
| 122 params.parent_widget = parent_widget; | 122 params.parent_widget = parent_widget; |
| 123 widget->Init(params); | 123 widget->Init(params); |
| 124 InitWidget(widget, transparent); | 124 InitWidget(widget, transparent); |
| 125 } | 125 } |
| 126 #endif | 126 #endif |
| 127 | 127 |
| 128 void WidgetExample::CreatePopup(views::View* parent, bool transparent) { | 128 void WidgetExample::CreatePopup(views::View* parent, bool transparent) { |
| 129 views::Widget* widget = views::Widget::CreateWidget(); | 129 views::Widget* widget = new views::Widget; |
| 130 | 130 |
| 131 // Compute where to place the popup widget. | 131 // Compute where to place the popup widget. |
| 132 // We'll place it right below the create button. | 132 // We'll place it right below the create button. |
| 133 gfx::Point point = parent->GetMirroredPosition(); | 133 gfx::Point point = parent->GetMirroredPosition(); |
| 134 // 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. |
| 135 views::View::ConvertPointToScreen(parent, &point); | 135 views::View::ConvertPointToScreen(parent, &point); |
| 136 // Add the height of create_button_. | 136 // Add the height of create_button_. |
| 137 point.Offset(0, parent->size().height()); | 137 point.Offset(0, parent->size().height()); |
| 138 | 138 |
| 139 // Initialize the popup widget with the computed bounds. | 139 // Initialize the popup widget with the computed bounds. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 162 CreateChild(sender, true); | 162 CreateChild(sender, true); |
| 163 break; | 163 break; |
| 164 #endif | 164 #endif |
| 165 case CLOSE_WIDGET: | 165 case CLOSE_WIDGET: |
| 166 sender->GetWidget()->Close(); | 166 sender->GetWidget()->Close(); |
| 167 break; | 167 break; |
| 168 } | 168 } |
| 169 } | 169 } |
| 170 | 170 |
| 171 } // namespace examples | 171 } // namespace examples |
| OLD | NEW |