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

Side by Side Diff: ui/views/test/child_modal_window.cc

Issue 11316287: Move WindowModalityController to CoreWm. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years 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/test/child_modal_window.h ('k') | ui/views/views.gyp » ('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 "ash/test/child_modal_window.h" 5 #include "ui/views/test/child_modal_window.h"
6 6
7 #include "ash/wm/window_modality_controller.h"
8 #include "base/utf_string_conversions.h" // ASCIIToUTF16 7 #include "base/utf_string_conversions.h" // ASCIIToUTF16
9 #include "ui/aura/window.h" 8 #include "ui/aura/window.h"
10 #include "ui/gfx/canvas.h" 9 #include "ui/gfx/canvas.h"
11 #include "ui/views/background.h" 10 #include "ui/views/background.h"
12 #include "ui/views/controls/button/text_button.h" 11 #include "ui/views/controls/button/text_button.h"
13 #include "ui/views/controls/native/native_view_host.h" 12 #include "ui/views/controls/native/native_view_host.h"
14 #include "ui/views/controls/textfield/textfield.h" 13 #include "ui/views/controls/textfield/textfield.h"
14 #include "ui/views/corewm/window_modality_controller.h"
15 #include "ui/views/widget/widget.h" 15 #include "ui/views/widget/widget.h"
16 #include "ui/views/widget/widget_delegate.h" 16 #include "ui/views/widget/widget_delegate.h"
17 17
18 namespace ash { 18 namespace views {
19 namespace test { 19 namespace test {
20 20
21 namespace { 21 namespace {
22 22
23 // Parent window size and position. 23 // Parent window size and position.
24 const int kWindowLeft = 170; 24 const int kWindowLeft = 170;
25 const int kWindowTop = 200; 25 const int kWindowTop = 200;
26 const int kWindowWidth = 400; 26 const int kWindowWidth = 400;
27 const int kWindowHeight = 400; 27 const int kWindowHeight = 400;
28 28
(...skipping 10 matching lines...) Expand all
39 const int kChildTextfieldTop = 50; 39 const int kChildTextfieldTop = 50;
40 const int kChildTextfieldWidth = 290; 40 const int kChildTextfieldWidth = 290;
41 const int kChildTextfieldHeight = 35; 41 const int kChildTextfieldHeight = 35;
42 42
43 const SkColor kModalParentColor = SK_ColorWHITE; 43 const SkColor kModalParentColor = SK_ColorWHITE;
44 const SkColor kChildColor = SK_ColorWHITE; 44 const SkColor kChildColor = SK_ColorWHITE;
45 45
46 } // namespace 46 } // namespace
47 47
48 void CreateChildModalParent() { 48 void CreateChildModalParent() {
49 views::Widget::CreateWindowWithBounds( 49 Widget::CreateWindowWithBounds(
50 new ChildModalParent, 50 new ChildModalParent,
51 gfx::Rect(kWindowLeft, kWindowTop, kWindowWidth, kWindowHeight))->Show(); 51 gfx::Rect(kWindowLeft, kWindowTop, kWindowWidth, kWindowHeight))->Show();
52 } 52 }
53 53
54 54
55 class ChildModalWindow : public views::WidgetDelegateView { 55 class ChildModalWindow : public WidgetDelegateView {
56 public: 56 public:
57 ChildModalWindow(); 57 ChildModalWindow();
58 virtual ~ChildModalWindow(); 58 virtual ~ChildModalWindow();
59 59
60 private: 60 private:
61 // Overridden from views::View: 61 // Overridden from View:
62 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; 62 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
63 virtual gfx::Size GetPreferredSize() OVERRIDE; 63 virtual gfx::Size GetPreferredSize() OVERRIDE;
64 64
65 // Overridden from views::WidgetDelegate: 65 // Overridden from WidgetDelegate:
66 virtual views::View* GetContentsView() OVERRIDE; 66 virtual View* GetContentsView() OVERRIDE;
67 virtual string16 GetWindowTitle() const OVERRIDE; 67 virtual string16 GetWindowTitle() const OVERRIDE;
68 virtual bool CanResize() const OVERRIDE; 68 virtual bool CanResize() const OVERRIDE;
69 virtual ui::ModalType GetModalType() const OVERRIDE; 69 virtual ui::ModalType GetModalType() const OVERRIDE;
70 70
71 DISALLOW_COPY_AND_ASSIGN(ChildModalWindow); 71 DISALLOW_COPY_AND_ASSIGN(ChildModalWindow);
72 }; 72 };
73 73
74 ChildModalWindow::ChildModalWindow() { 74 ChildModalWindow::ChildModalWindow() {
75 views::Textfield* textfield = new views::Textfield; 75 Textfield* textfield = new Textfield;
76 AddChildView(textfield); 76 AddChildView(textfield);
77 textfield->SetBounds( 77 textfield->SetBounds(
78 kChildTextfieldLeft, kChildTextfieldTop, 78 kChildTextfieldLeft, kChildTextfieldTop,
79 kChildTextfieldWidth, kChildTextfieldHeight); 79 kChildTextfieldWidth, kChildTextfieldHeight);
80 } 80 }
81 81
82 ChildModalWindow::~ChildModalWindow() { 82 ChildModalWindow::~ChildModalWindow() {
83 } 83 }
84 84
85 void ChildModalWindow::OnPaint(gfx::Canvas* canvas) { 85 void ChildModalWindow::OnPaint(gfx::Canvas* canvas) {
86 canvas->FillRect(GetLocalBounds(), kChildColor); 86 canvas->FillRect(GetLocalBounds(), kChildColor);
87 } 87 }
88 88
89 gfx::Size ChildModalWindow::GetPreferredSize() { 89 gfx::Size ChildModalWindow::GetPreferredSize() {
90 return gfx::Size(kChildWindowWidth, kChildWindowHeight); 90 return gfx::Size(kChildWindowWidth, kChildWindowHeight);
91 } 91 }
92 92
93 views::View* ChildModalWindow::GetContentsView() { 93 View* ChildModalWindow::GetContentsView() {
94 return this; 94 return this;
95 } 95 }
96 96
97 string16 ChildModalWindow::GetWindowTitle() const { 97 string16 ChildModalWindow::GetWindowTitle() const {
98 return ASCIIToUTF16("Examples: Child Modal Window"); 98 return ASCIIToUTF16("Examples: Child Modal Window");
99 } 99 }
100 100
101 bool ChildModalWindow::CanResize() const { 101 bool ChildModalWindow::CanResize() const {
102 return false; 102 return false;
103 } 103 }
104 104
105 ui::ModalType ChildModalWindow::GetModalType() const { 105 ui::ModalType ChildModalWindow::GetModalType() const {
106 return ui::MODAL_TYPE_CHILD; 106 return ui::MODAL_TYPE_CHILD;
107 } 107 }
108 108
109 ChildModalParent::ChildModalParent() 109 ChildModalParent::ChildModalParent()
110 : ALLOW_THIS_IN_INITIALIZER_LIST(button_(new views::NativeTextButton( 110 : ALLOW_THIS_IN_INITIALIZER_LIST(button_(new NativeTextButton(
111 this, ASCIIToUTF16("Show/Hide Child Modal Window")))), 111 this, ASCIIToUTF16("Show/Hide Child Modal Window")))),
112 textfield_(new views::Textfield), 112 textfield_(new Textfield),
113 host_(new views::NativeViewHost), 113 host_(new NativeViewHost),
114 modal_parent_(NULL), 114 modal_parent_(NULL),
115 child_(NULL) { 115 child_(NULL) {
116 views::Widget* widget = new views::Widget; 116 Widget* widget = new Widget;
117 widget->Init( 117 widget->Init(Widget::InitParams(Widget::InitParams::TYPE_CONTROL));
118 views::Widget::InitParams(views::Widget::InitParams::TYPE_CONTROL));
119 widget->GetRootView()->set_background( 118 widget->GetRootView()->set_background(
120 views::Background::CreateSolidBackground(kModalParentColor)); 119 Background::CreateSolidBackground(kModalParentColor));
121 modal_parent_ = widget->GetNativeView(); 120 modal_parent_ = widget->GetNativeView();
122 widget->GetNativeView()->SetName("ModalParent"); 121 widget->GetNativeView()->SetName("ModalParent");
123 AddChildView(button_); 122 AddChildView(button_);
124 AddChildView(textfield_); 123 AddChildView(textfield_);
125 AddChildView(host_); 124 AddChildView(host_);
126 } 125 }
127 126
128 ChildModalParent::~ChildModalParent() { 127 ChildModalParent::~ChildModalParent() {
129 } 128 }
130 129
131 void ChildModalParent::ShowChild() { 130 void ChildModalParent::ShowChild() {
132 if (!child_) 131 if (!child_)
133 child_ = CreateChild(); 132 child_ = CreateChild();
134 child_->Show(); 133 child_->Show();
135 } 134 }
136 135
137 gfx::NativeWindow ChildModalParent::GetModalParent() const { 136 gfx::NativeWindow ChildModalParent::GetModalParent() const {
138 return modal_parent_; 137 return modal_parent_;
139 } 138 }
140 139
141 gfx::NativeWindow ChildModalParent::GetChild() const { 140 gfx::NativeWindow ChildModalParent::GetChild() const {
142 if (child_) 141 if (child_)
143 return child_->GetNativeView(); 142 return child_->GetNativeView();
144 return NULL; 143 return NULL;
145 } 144 }
146 145
147 views::Widget* ChildModalParent::CreateChild() { 146 Widget* ChildModalParent::CreateChild() {
148 views::Widget* child = views::Widget::CreateWindowWithParent( 147 Widget* child = Widget::CreateWindowWithParent(
149 new ChildModalWindow, GetWidget()->GetNativeView()); 148 new ChildModalWindow, GetWidget()->GetNativeView());
150 ash::SetModalParent(child->GetNativeView(), GetModalParent()); 149 corewm::SetModalParent(child->GetNativeView(), GetModalParent());
151 child->AddObserver(this); 150 child->AddObserver(this);
152 child->GetNativeView()->SetName("ChildModalWindow"); 151 child->GetNativeView()->SetName("ChildModalWindow");
153 return child; 152 return child;
154 } 153 }
155 154
156 views::View* ChildModalParent::GetContentsView() { 155 View* ChildModalParent::GetContentsView() {
157 return this; 156 return this;
158 } 157 }
159 158
160 string16 ChildModalParent::GetWindowTitle() const { 159 string16 ChildModalParent::GetWindowTitle() const {
161 return ASCIIToUTF16("Examples: Child Modal Parent"); 160 return ASCIIToUTF16("Examples: Child Modal Parent");
162 } 161 }
163 162
164 bool ChildModalParent::CanResize() const { 163 bool ChildModalParent::CanResize() const {
165 return false; 164 return false;
166 } 165 }
167 166
168 void ChildModalParent::DeleteDelegate() { 167 void ChildModalParent::DeleteDelegate() {
169 if (child_) { 168 if (child_) {
170 child_->RemoveObserver(this); 169 child_->RemoveObserver(this);
171 child_->Close(); 170 child_->Close();
172 child_ = NULL; 171 child_ = NULL;
173 } 172 }
174 } 173 }
175 174
176 void ChildModalParent::Layout() { 175 void ChildModalParent::Layout() {
177 int running_y = y(); 176 int running_y = y();
178 button_->SetBounds(x(), running_y, width(), kButtonHeight); 177 button_->SetBounds(x(), running_y, width(), kButtonHeight);
179 running_y += kButtonHeight; 178 running_y += kButtonHeight;
180 textfield_->SetBounds(x(), running_y, width(), kTextfieldHeight); 179 textfield_->SetBounds(x(), running_y, width(), kTextfieldHeight);
181 running_y += kTextfieldHeight; 180 running_y += kTextfieldHeight;
182 host_->SetBounds(x(), running_y, width(), height() - running_y); 181 host_->SetBounds(x(), running_y, width(), height() - running_y);
183 } 182 }
184 183
185 void ChildModalParent::ViewHierarchyChanged(bool is_add, 184 void ChildModalParent::ViewHierarchyChanged(bool is_add,
186 views::View* parent, 185 View* parent,
187 views::View* child) { 186 View* child) {
188 if (is_add && child == this) { 187 if (is_add && child == this) {
189 host_->Attach(modal_parent_); 188 host_->Attach(modal_parent_);
190 GetWidget()->GetNativeView()->SetName("Parent"); 189 GetWidget()->GetNativeView()->SetName("Parent");
191 } 190 }
192 } 191 }
193 192
194 void ChildModalParent::ButtonPressed(views::Button* sender, 193 void ChildModalParent::ButtonPressed(Button* sender,
195 const ui::Event& event) { 194 const ui::Event& event) {
196 if (sender == button_) { 195 if (sender == button_) {
197 if (!child_) 196 if (!child_)
198 child_ = CreateChild(); 197 child_ = CreateChild();
199 if (child_->IsVisible()) 198 if (child_->IsVisible())
200 child_->Hide(); 199 child_->Hide();
201 else 200 else
202 child_->Show(); 201 child_->Show();
203 } 202 }
204 } 203 }
205 204
206 void ChildModalParent::OnWidgetClosing(views::Widget* widget) { 205 void ChildModalParent::OnWidgetClosing(Widget* widget) {
207 if (child_) { 206 if (child_) {
208 DCHECK_EQ(child_, widget); 207 DCHECK_EQ(child_, widget);
209 child_ = NULL; 208 child_ = NULL;
210 } 209 }
211 } 210 }
212 211
213 } // namespace test 212 } // namespace test
214 } // namespace ash 213 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/test/child_modal_window.h ('k') | ui/views/views.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698