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/widget/native_widget_views.h" | 5 #include "views/widget/native_widget_views.h" |
6 | 6 |
7 #include "ui/gfx/compositor/compositor.h" | 7 #include "ui/gfx/compositor/compositor.h" |
| 8 #include "views/desktop/desktop_window_view.h" |
8 #include "views/view.h" | 9 #include "views/view.h" |
9 #include "views/views_delegate.h" | 10 #include "views/views_delegate.h" |
10 #include "views/widget/native_widget_view.h" | 11 #include "views/widget/native_widget_view.h" |
11 #include "views/widget/root_view.h" | 12 #include "views/widget/root_view.h" |
12 | 13 |
13 namespace views { | 14 namespace views { |
14 | 15 |
15 //////////////////////////////////////////////////////////////////////////////// | 16 //////////////////////////////////////////////////////////////////////////////// |
16 // NativeWidgetViews, public: | 17 // NativeWidgetViews, public: |
17 | 18 |
18 NativeWidgetViews::NativeWidgetViews(internal::NativeWidgetDelegate* delegate) | 19 NativeWidgetViews::NativeWidgetViews(internal::NativeWidgetDelegate* delegate) |
19 : delegate_(delegate), | 20 : delegate_(delegate), |
20 view_(NULL), | 21 view_(NULL), |
21 active_(false), | 22 active_(false), |
22 minimized_(false), | 23 minimized_(false), |
23 ALLOW_THIS_IN_INITIALIZER_LIST(close_widget_factory_(this)), | 24 ALLOW_THIS_IN_INITIALIZER_LIST(close_widget_factory_(this)), |
24 hosting_widget_(NULL) { | 25 hosting_widget_(NULL), |
| 26 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET), |
| 27 delete_native_view_(true) { |
25 } | 28 } |
26 | 29 |
27 NativeWidgetViews::~NativeWidgetViews() { | 30 NativeWidgetViews::~NativeWidgetViews() { |
| 31 delegate_->OnNativeWidgetDestroying(); |
| 32 if (delete_native_view_) { |
| 33 view_->parent()->RemoveChildView(view_); |
| 34 // We must prevent the NativeWidgetView from attempting to delete us. |
| 35 view_->set_delete_native_widget(false); |
| 36 delete view_; |
| 37 } |
| 38 delegate_->OnNativeWidgetDestroyed(); |
| 39 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) |
| 40 delete delegate_; |
28 } | 41 } |
29 | 42 |
30 View* NativeWidgetViews::GetView() { | 43 View* NativeWidgetViews::GetView() { |
31 return view_; | 44 return view_; |
32 } | 45 } |
33 | 46 |
34 const View* NativeWidgetViews::GetView() const { | 47 const View* NativeWidgetViews::GetView() const { |
35 return view_; | 48 return view_; |
36 } | 49 } |
37 | 50 |
38 void NativeWidgetViews::OnActivate(bool active) { | 51 void NativeWidgetViews::OnActivate(bool active) { |
39 active_ = active; | 52 active_ = active; |
40 view_->SchedulePaint(); | 53 view_->SchedulePaint(); |
41 } | 54 } |
42 | 55 |
43 //////////////////////////////////////////////////////////////////////////////// | 56 //////////////////////////////////////////////////////////////////////////////// |
44 // NativeWidgetViews, NativeWidget implementation: | 57 // NativeWidgetViews, NativeWidget implementation: |
45 | 58 |
46 void NativeWidgetViews::InitNativeWidget(const Widget::InitParams& params) { | 59 void NativeWidgetViews::InitNativeWidget(const Widget::InitParams& params) { |
| 60 ownership_ = params.ownership; |
47 View* desktop_view = ViewsDelegate::views_delegate->GetDefaultParentView(); | 61 View* desktop_view = ViewsDelegate::views_delegate->GetDefaultParentView(); |
48 hosting_widget_ = desktop_view->GetWidget(); | 62 hosting_widget_ = desktop_view->GetWidget(); |
49 view_ = new internal::NativeWidgetView(this); | 63 view_ = new internal::NativeWidgetView(this); |
50 view_->SetBoundsRect(params.bounds); | 64 view_->SetBoundsRect(params.bounds); |
51 view_->SetPaintToLayer(true); | 65 view_->SetPaintToLayer(true); |
| 66 // TODO(beng): This is insufficient. While this handles the case where |
| 67 // params.parent_widget is NULL, we need to somehow handle a case |
| 68 // where we are passed a specified, valid parent. We may have to |
| 69 // add View* Widget::GetContainerView(). |
52 desktop_view->AddChildView(view_); | 70 desktop_view->AddChildView(view_); |
53 | 71 |
54 // TODO(beng): handle parenting. | 72 // TODO(beng): handle parenting. |
55 // TODO(beng): SetInitParams(). | 73 // TODO(beng): SetInitParams(). |
56 } | 74 } |
57 | 75 |
58 NonClientFrameView* NativeWidgetViews::CreateNonClientFrameView() { | 76 NonClientFrameView* NativeWidgetViews::CreateNonClientFrameView() { |
59 return NULL; | 77 return NULL; |
60 } | 78 } |
61 | 79 |
(...skipping 17 matching lines...) Expand all Loading... |
79 } | 97 } |
80 | 98 |
81 gfx::NativeView NativeWidgetViews::GetNativeView() const { | 99 gfx::NativeView NativeWidgetViews::GetNativeView() const { |
82 return GetParentNativeWidget()->GetNativeView(); | 100 return GetParentNativeWidget()->GetNativeView(); |
83 } | 101 } |
84 | 102 |
85 gfx::NativeWindow NativeWidgetViews::GetNativeWindow() const { | 103 gfx::NativeWindow NativeWidgetViews::GetNativeWindow() const { |
86 return GetParentNativeWidget()->GetNativeWindow(); | 104 return GetParentNativeWidget()->GetNativeWindow(); |
87 } | 105 } |
88 | 106 |
| 107 Widget* NativeWidgetViews::GetTopLevelWidget() { |
| 108 if (view_->parent() == ViewsDelegate::views_delegate->GetDefaultParentView()) |
| 109 return GetWidget(); |
| 110 return view_->GetWidget()->GetTopLevelWidget(); |
| 111 } |
| 112 |
89 const ui::Compositor* NativeWidgetViews::GetCompositor() const { | 113 const ui::Compositor* NativeWidgetViews::GetCompositor() const { |
90 return hosting_widget_->GetCompositor(); | 114 return hosting_widget_->GetCompositor(); |
91 } | 115 } |
92 | 116 |
93 ui::Compositor* NativeWidgetViews::GetCompositor() { | 117 ui::Compositor* NativeWidgetViews::GetCompositor() { |
94 return hosting_widget_->GetCompositor(); | 118 return hosting_widget_->GetCompositor(); |
95 } | 119 } |
96 | 120 |
97 void NativeWidgetViews::MarkLayerDirty() { | 121 void NativeWidgetViews::MarkLayerDirty() { |
98 view_->MarkLayerDirty(); | 122 view_->MarkLayerDirty(); |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 | 251 |
228 void NativeWidgetViews::Close() { | 252 void NativeWidgetViews::Close() { |
229 Hide(); | 253 Hide(); |
230 if (close_widget_factory_.empty()) { | 254 if (close_widget_factory_.empty()) { |
231 MessageLoop::current()->PostTask(FROM_HERE, | 255 MessageLoop::current()->PostTask(FROM_HERE, |
232 close_widget_factory_.NewRunnableMethod(&NativeWidgetViews::CloseNow)); | 256 close_widget_factory_.NewRunnableMethod(&NativeWidgetViews::CloseNow)); |
233 } | 257 } |
234 } | 258 } |
235 | 259 |
236 void NativeWidgetViews::CloseNow() { | 260 void NativeWidgetViews::CloseNow() { |
237 view_->parent()->RemoveChildView(view_); | 261 // TODO(beng): what about the other case?? |
238 delete view_; | 262 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) |
| 263 delete view_; |
239 } | 264 } |
240 | 265 |
241 void NativeWidgetViews::EnableClose(bool enable) { | 266 void NativeWidgetViews::EnableClose(bool enable) { |
242 } | 267 } |
243 | 268 |
244 void NativeWidgetViews::Show() { | 269 void NativeWidgetViews::Show() { |
245 view_->SetVisible(true); | 270 view_->SetVisible(true); |
246 } | 271 } |
247 | 272 |
248 void NativeWidgetViews::Hide() { | 273 void NativeWidgetViews::Hide() { |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 } | 397 } |
373 | 398 |
374 const internal::NativeWidgetPrivate* | 399 const internal::NativeWidgetPrivate* |
375 NativeWidgetViews::GetParentNativeWidget() const { | 400 NativeWidgetViews::GetParentNativeWidget() const { |
376 return static_cast<const internal::NativeWidgetPrivate*>( | 401 return static_cast<const internal::NativeWidgetPrivate*>( |
377 view_->GetWidget()->native_widget()); | 402 view_->GetWidget()->native_widget()); |
378 } | 403 } |
379 | 404 |
380 } // namespace views | 405 } // namespace views |
381 | 406 |
OLD | NEW |