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

Side by Side Diff: ash/test/child_modal_window.cc

Issue 2390953004: WidgetDelegateView is its own contents view. (Closed)
Patch Set: another minor fix Created 4 years, 2 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "ash/test/child_modal_window.h"
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "ui/aura/window.h" 8 #include "ui/aura/window.h"
9 #include "ui/gfx/canvas.h" 9 #include "ui/gfx/canvas.h"
10 #include "ui/views/background.h" 10 #include "ui/views/background.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 public: 58 public:
59 ChildModalWindow(); 59 ChildModalWindow();
60 ~ChildModalWindow() override; 60 ~ChildModalWindow() override;
61 61
62 private: 62 private:
63 // Overridden from View: 63 // Overridden from View:
64 void OnPaint(gfx::Canvas* canvas) override; 64 void OnPaint(gfx::Canvas* canvas) override;
65 gfx::Size GetPreferredSize() const override; 65 gfx::Size GetPreferredSize() const override;
66 66
67 // Overridden from WidgetDelegate: 67 // Overridden from WidgetDelegate:
68 View* GetContentsView() override;
69 base::string16 GetWindowTitle() const override; 68 base::string16 GetWindowTitle() const override;
70 bool CanResize() const override; 69 bool CanResize() const override;
71 ui::ModalType GetModalType() const override; 70 ui::ModalType GetModalType() const override;
72 71
73 DISALLOW_COPY_AND_ASSIGN(ChildModalWindow); 72 DISALLOW_COPY_AND_ASSIGN(ChildModalWindow);
74 }; 73 };
75 74
76 ChildModalWindow::ChildModalWindow() { 75 ChildModalWindow::ChildModalWindow() {
77 views::Textfield* textfield = new views::Textfield; 76 views::Textfield* textfield = new views::Textfield;
78 AddChildView(textfield); 77 AddChildView(textfield);
79 textfield->SetBounds(kChildTextfieldLeft, kChildTextfieldTop, 78 textfield->SetBounds(kChildTextfieldLeft, kChildTextfieldTop,
80 kChildTextfieldWidth, kChildTextfieldHeight); 79 kChildTextfieldWidth, kChildTextfieldHeight);
81 } 80 }
82 81
83 ChildModalWindow::~ChildModalWindow() {} 82 ChildModalWindow::~ChildModalWindow() {}
84 83
85 void ChildModalWindow::OnPaint(gfx::Canvas* canvas) { 84 void ChildModalWindow::OnPaint(gfx::Canvas* canvas) {
86 canvas->FillRect(GetLocalBounds(), kChildColor); 85 canvas->FillRect(GetLocalBounds(), kChildColor);
87 } 86 }
88 87
89 gfx::Size ChildModalWindow::GetPreferredSize() const { 88 gfx::Size ChildModalWindow::GetPreferredSize() const {
90 return gfx::Size(kChildWindowWidth, kChildWindowHeight); 89 return gfx::Size(kChildWindowWidth, kChildWindowHeight);
91 } 90 }
92 91
93 views::View* ChildModalWindow::GetContentsView() {
94 return this;
95 }
96
97 base::string16 ChildModalWindow::GetWindowTitle() const { 92 base::string16 ChildModalWindow::GetWindowTitle() const {
98 return base::ASCIIToUTF16("Examples: Child Modal Window"); 93 return base::ASCIIToUTF16("Examples: Child Modal Window");
99 } 94 }
100 95
101 bool ChildModalWindow::CanResize() const { 96 bool ChildModalWindow::CanResize() const {
102 return false; 97 return false;
103 } 98 }
104 99
105 ui::ModalType ChildModalWindow::GetModalType() const { 100 ui::ModalType ChildModalWindow::GetModalType() const {
106 return ui::MODAL_TYPE_CHILD; 101 return ui::MODAL_TYPE_CHILD;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 142
148 Widget* ChildModalParent::CreateChild() { 143 Widget* ChildModalParent::CreateChild() {
149 Widget* child = Widget::CreateWindowWithParent(new ChildModalWindow, 144 Widget* child = Widget::CreateWindowWithParent(new ChildModalWindow,
150 GetWidget()->GetNativeView()); 145 GetWidget()->GetNativeView());
151 wm::SetModalParent(child->GetNativeView(), GetModalParent()); 146 wm::SetModalParent(child->GetNativeView(), GetModalParent());
152 child->AddObserver(this); 147 child->AddObserver(this);
153 child->GetNativeView()->SetName("ChildModalWindow"); 148 child->GetNativeView()->SetName("ChildModalWindow");
154 return child; 149 return child;
155 } 150 }
156 151
157 views::View* ChildModalParent::GetContentsView() {
158 return this;
159 }
160
161 base::string16 ChildModalParent::GetWindowTitle() const { 152 base::string16 ChildModalParent::GetWindowTitle() const {
162 return base::ASCIIToUTF16("Examples: Child Modal Parent"); 153 return base::ASCIIToUTF16("Examples: Child Modal Parent");
163 } 154 }
164 155
165 bool ChildModalParent::CanResize() const { 156 bool ChildModalParent::CanResize() const {
166 return false; 157 return false;
167 } 158 }
168 159
169 void ChildModalParent::DeleteDelegate() { 160 void ChildModalParent::DeleteDelegate() {
170 if (child_) { 161 if (child_) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 198
208 void ChildModalParent::OnWidgetDestroying(Widget* widget) { 199 void ChildModalParent::OnWidgetDestroying(Widget* widget) {
209 if (child_) { 200 if (child_) {
210 DCHECK_EQ(child_, widget); 201 DCHECK_EQ(child_, widget);
211 child_ = NULL; 202 child_ = NULL;
212 } 203 }
213 } 204 }
214 205
215 } // namespace test 206 } // namespace test
216 } // namespace ash 207 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698