OLD | NEW |
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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 const int kChildTextfieldWidth = 290; | 42 const int kChildTextfieldWidth = 290; |
43 const int kChildTextfieldHeight = 35; | 43 const int kChildTextfieldHeight = 35; |
44 | 44 |
45 const SkColor kModalParentColor = SK_ColorWHITE; | 45 const SkColor kModalParentColor = SK_ColorWHITE; |
46 const SkColor kChildColor = SK_ColorWHITE; | 46 const SkColor kChildColor = SK_ColorWHITE; |
47 | 47 |
48 } // namespace | 48 } // namespace |
49 | 49 |
50 void CreateChildModalParent(gfx::NativeView context) { | 50 void CreateChildModalParent(gfx::NativeView context) { |
51 Widget::CreateWindowWithContextAndBounds( | 51 Widget::CreateWindowWithContextAndBounds( |
52 new ChildModalParent(context), | 52 new ChildModalParent(context), context, |
53 context, | 53 gfx::Rect(kWindowLeft, kWindowTop, kWindowWidth, kWindowHeight)) |
54 gfx::Rect(kWindowLeft, kWindowTop, kWindowWidth, kWindowHeight))->Show(); | 54 ->Show(); |
55 } | 55 } |
56 | 56 |
57 | |
58 class ChildModalWindow : public views::WidgetDelegateView { | 57 class ChildModalWindow : public views::WidgetDelegateView { |
59 public: | 58 public: |
60 ChildModalWindow(); | 59 ChildModalWindow(); |
61 ~ChildModalWindow() override; | 60 ~ChildModalWindow() override; |
62 | 61 |
63 private: | 62 private: |
64 // Overridden from View: | 63 // Overridden from View: |
65 void OnPaint(gfx::Canvas* canvas) override; | 64 void OnPaint(gfx::Canvas* canvas) override; |
66 gfx::Size GetPreferredSize() const override; | 65 gfx::Size GetPreferredSize() const override; |
67 | 66 |
68 // Overridden from WidgetDelegate: | 67 // Overridden from WidgetDelegate: |
69 View* GetContentsView() override; | 68 View* GetContentsView() override; |
70 base::string16 GetWindowTitle() const override; | 69 base::string16 GetWindowTitle() const override; |
71 bool CanResize() const override; | 70 bool CanResize() const override; |
72 ui::ModalType GetModalType() const override; | 71 ui::ModalType GetModalType() const override; |
73 | 72 |
74 DISALLOW_COPY_AND_ASSIGN(ChildModalWindow); | 73 DISALLOW_COPY_AND_ASSIGN(ChildModalWindow); |
75 }; | 74 }; |
76 | 75 |
77 ChildModalWindow::ChildModalWindow() { | 76 ChildModalWindow::ChildModalWindow() { |
78 views::Textfield* textfield = new views::Textfield; | 77 views::Textfield* textfield = new views::Textfield; |
79 AddChildView(textfield); | 78 AddChildView(textfield); |
80 textfield->SetBounds( | 79 textfield->SetBounds(kChildTextfieldLeft, kChildTextfieldTop, |
81 kChildTextfieldLeft, kChildTextfieldTop, | 80 kChildTextfieldWidth, kChildTextfieldHeight); |
82 kChildTextfieldWidth, kChildTextfieldHeight); | |
83 } | 81 } |
84 | 82 |
85 ChildModalWindow::~ChildModalWindow() { | 83 ChildModalWindow::~ChildModalWindow() {} |
86 } | |
87 | 84 |
88 void ChildModalWindow::OnPaint(gfx::Canvas* canvas) { | 85 void ChildModalWindow::OnPaint(gfx::Canvas* canvas) { |
89 canvas->FillRect(GetLocalBounds(), kChildColor); | 86 canvas->FillRect(GetLocalBounds(), kChildColor); |
90 } | 87 } |
91 | 88 |
92 gfx::Size ChildModalWindow::GetPreferredSize() const { | 89 gfx::Size ChildModalWindow::GetPreferredSize() const { |
93 return gfx::Size(kChildWindowWidth, kChildWindowHeight); | 90 return gfx::Size(kChildWindowWidth, kChildWindowHeight); |
94 } | 91 } |
95 | 92 |
96 views::View* ChildModalWindow::GetContentsView() { | 93 views::View* ChildModalWindow::GetContentsView() { |
97 return this; | 94 return this; |
98 } | 95 } |
99 | 96 |
100 base::string16 ChildModalWindow::GetWindowTitle() const { | 97 base::string16 ChildModalWindow::GetWindowTitle() const { |
101 return base::ASCIIToUTF16("Examples: Child Modal Window"); | 98 return base::ASCIIToUTF16("Examples: Child Modal Window"); |
102 } | 99 } |
103 | 100 |
104 bool ChildModalWindow::CanResize() const { | 101 bool ChildModalWindow::CanResize() const { |
105 return false; | 102 return false; |
106 } | 103 } |
107 | 104 |
108 ui::ModalType ChildModalWindow::GetModalType() const { | 105 ui::ModalType ChildModalWindow::GetModalType() const { |
109 return ui::MODAL_TYPE_CHILD; | 106 return ui::MODAL_TYPE_CHILD; |
110 } | 107 } |
111 | 108 |
112 ChildModalParent::ChildModalParent(gfx::NativeView context) | 109 ChildModalParent::ChildModalParent(gfx::NativeView context) |
113 : button_(new views::LabelButton(this, | 110 : button_(new views::LabelButton( |
114 base::ASCIIToUTF16( | 111 this, |
115 "Show/Hide Child Modal Window"))), | 112 base::ASCIIToUTF16("Show/Hide Child Modal Window"))), |
116 textfield_(new views::Textfield), | 113 textfield_(new views::Textfield), |
117 host_(new views::NativeViewHost), | 114 host_(new views::NativeViewHost), |
118 modal_parent_(NULL), | 115 modal_parent_(NULL), |
119 child_(NULL) { | 116 child_(NULL) { |
120 Widget* widget = new Widget; | 117 Widget* widget = new Widget; |
121 Widget::InitParams params(Widget::InitParams::TYPE_CONTROL); | 118 Widget::InitParams params(Widget::InitParams::TYPE_CONTROL); |
122 params.context = context; | 119 params.context = context; |
123 widget->Init(params); | 120 widget->Init(params); |
124 widget->GetRootView()->set_background( | 121 widget->GetRootView()->set_background( |
125 views::Background::CreateSolidBackground(kModalParentColor)); | 122 views::Background::CreateSolidBackground(kModalParentColor)); |
126 modal_parent_ = widget->GetNativeView(); | 123 modal_parent_ = widget->GetNativeView(); |
127 widget->GetNativeView()->SetName("ModalParent"); | 124 widget->GetNativeView()->SetName("ModalParent"); |
128 AddChildView(button_); | 125 AddChildView(button_); |
129 AddChildView(textfield_); | 126 AddChildView(textfield_); |
130 AddChildView(host_); | 127 AddChildView(host_); |
131 } | 128 } |
132 | 129 |
133 ChildModalParent::~ChildModalParent() { | 130 ChildModalParent::~ChildModalParent() {} |
134 } | |
135 | 131 |
136 void ChildModalParent::ShowChild() { | 132 void ChildModalParent::ShowChild() { |
137 if (!child_) | 133 if (!child_) |
138 child_ = CreateChild(); | 134 child_ = CreateChild(); |
139 child_->Show(); | 135 child_->Show(); |
140 } | 136 } |
141 | 137 |
142 gfx::NativeWindow ChildModalParent::GetModalParent() const { | 138 gfx::NativeWindow ChildModalParent::GetModalParent() const { |
143 return modal_parent_; | 139 return modal_parent_; |
144 } | 140 } |
145 | 141 |
146 gfx::NativeWindow ChildModalParent::GetChild() const { | 142 gfx::NativeWindow ChildModalParent::GetChild() const { |
147 if (child_) | 143 if (child_) |
148 return child_->GetNativeView(); | 144 return child_->GetNativeView(); |
149 return NULL; | 145 return NULL; |
150 } | 146 } |
151 | 147 |
152 Widget* ChildModalParent::CreateChild() { | 148 Widget* ChildModalParent::CreateChild() { |
153 Widget* child = Widget::CreateWindowWithParent( | 149 Widget* child = Widget::CreateWindowWithParent(new ChildModalWindow, |
154 new ChildModalWindow, GetWidget()->GetNativeView()); | 150 GetWidget()->GetNativeView()); |
155 wm::SetModalParent(child->GetNativeView(), GetModalParent()); | 151 wm::SetModalParent(child->GetNativeView(), GetModalParent()); |
156 child->AddObserver(this); | 152 child->AddObserver(this); |
157 child->GetNativeView()->SetName("ChildModalWindow"); | 153 child->GetNativeView()->SetName("ChildModalWindow"); |
158 return child; | 154 return child; |
159 } | 155 } |
160 | 156 |
161 views::View* ChildModalParent::GetContentsView() { | 157 views::View* ChildModalParent::GetContentsView() { |
162 return this; | 158 return this; |
163 } | 159 } |
164 | 160 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 | 207 |
212 void ChildModalParent::OnWidgetDestroying(Widget* widget) { | 208 void ChildModalParent::OnWidgetDestroying(Widget* widget) { |
213 if (child_) { | 209 if (child_) { |
214 DCHECK_EQ(child_, widget); | 210 DCHECK_EQ(child_, widget); |
215 child_ = NULL; | 211 child_ = NULL; |
216 } | 212 } |
217 } | 213 } |
218 | 214 |
219 } // namespace test | 215 } // namespace test |
220 } // namespace ash | 216 } // namespace ash |
OLD | NEW |