OLD | NEW |
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 "ui/views/widget/widget.h" | 5 #include "ui/views/widget/widget.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "ui/base/events/event.h" | 10 #include "ui/base/events/event.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 if (view->layer()) { | 43 if (view->layer()) { |
44 layers->push_back(view->layer()); | 44 layers->push_back(view->layer()); |
45 } else { | 45 } else { |
46 for (int i = 0; i < view->child_count(); ++i) | 46 for (int i = 0; i < view->child_count(); ++i) |
47 BuildRootLayers(view->child_at(i), layers); | 47 BuildRootLayers(view->child_at(i), layers); |
48 } | 48 } |
49 } | 49 } |
50 | 50 |
51 // Create a native widget implementation. | 51 // Create a native widget implementation. |
52 // First, use the supplied one if non-NULL. | 52 // First, use the supplied one if non-NULL. |
53 // Second, ask the delegate. | |
54 // Finally, make a default one. | 53 // Finally, make a default one. |
55 NativeWidget* CreateNativeWidget(NativeWidget* native_widget, | 54 NativeWidget* CreateNativeWidget(NativeWidget* native_widget, |
56 internal::NativeWidgetDelegate* delegate, | 55 internal::NativeWidgetDelegate* delegate) { |
57 Widget::InitParams::Type type, | |
58 gfx::NativeView parent, | |
59 gfx::NativeView context) { | |
60 if (!native_widget) { | 56 if (!native_widget) { |
61 if (ViewsDelegate::views_delegate) { | 57 native_widget = |
62 native_widget = ViewsDelegate::views_delegate->CreateNativeWidget( | 58 internal::NativeWidgetPrivate::CreateNativeWidget(delegate); |
63 type, delegate, parent, context); | |
64 } | |
65 if (!native_widget) { | |
66 native_widget = | |
67 internal::NativeWidgetPrivate::CreateNativeWidget(delegate); | |
68 } | |
69 } | 59 } |
70 return native_widget; | 60 return native_widget; |
71 } | 61 } |
72 | 62 |
73 } // namespace | 63 } // namespace |
74 | 64 |
75 // This class is used to keep track of the event a Widget is processing, and | 65 // This class is used to keep track of the event a Widget is processing, and |
76 // restore any previously active event afterwards. | 66 // restore any previously active event afterwards. |
77 class ScopedEvent { | 67 class ScopedEvent { |
78 public: | 68 public: |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 delete native_widget_; | 214 delete native_widget_; |
225 } else { | 215 } else { |
226 DCHECK(native_widget_destroyed_) | 216 DCHECK(native_widget_destroyed_) |
227 << "Destroying a widget with a live native widget. " | 217 << "Destroying a widget with a live native widget. " |
228 << "Widget probably should use WIDGET_OWNS_NATIVE_WIDGET ownership."; | 218 << "Widget probably should use WIDGET_OWNS_NATIVE_WIDGET ownership."; |
229 } | 219 } |
230 } | 220 } |
231 | 221 |
232 // static | 222 // static |
233 Widget* Widget::CreateWindow(WidgetDelegate* delegate) { | 223 Widget* Widget::CreateWindow(WidgetDelegate* delegate) { |
234 return CreateWindowWithParentAndBounds(delegate, NULL, gfx::Rect()); | 224 Widget* widget = new Widget; |
| 225 Widget::InitParams params; |
| 226 params.delegate = delegate; |
| 227 params.top_level = true; |
| 228 widget->Init(params); |
| 229 return widget; |
235 } | 230 } |
236 | 231 |
237 // static | 232 // static |
238 Widget* Widget::CreateWindowWithParent(WidgetDelegate* delegate, | 233 Widget* Widget::CreateWindowWithParent(WidgetDelegate* delegate, |
239 gfx::NativeWindow parent) { | 234 gfx::NativeWindow parent) { |
240 return CreateWindowWithParentAndBounds(delegate, parent, gfx::Rect()); | 235 return CreateWindowWithParentAndBounds(delegate, parent, gfx::Rect()); |
241 } | 236 } |
242 | 237 |
243 // static | 238 // static |
244 Widget* Widget::CreateWindowWithBounds(WidgetDelegate* delegate, | 239 Widget* Widget::CreateWindowWithBounds(WidgetDelegate* delegate, |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 GetLocalizedContentsHeight(row_resource_id)); | 327 GetLocalizedContentsHeight(row_resource_id)); |
333 } | 328 } |
334 | 329 |
335 // static | 330 // static |
336 bool Widget::RequiresNonClientView(InitParams::Type type) { | 331 bool Widget::RequiresNonClientView(InitParams::Type type) { |
337 return type == InitParams::TYPE_WINDOW || | 332 return type == InitParams::TYPE_WINDOW || |
338 type == InitParams::TYPE_PANEL || | 333 type == InitParams::TYPE_PANEL || |
339 type == InitParams::TYPE_BUBBLE; | 334 type == InitParams::TYPE_BUBBLE; |
340 } | 335 } |
341 | 336 |
342 void Widget::Init(const InitParams& params) { | 337 void Widget::Init(const InitParams& in_params) { |
| 338 InitParams params = in_params; |
| 339 if (ViewsDelegate::views_delegate) |
| 340 ViewsDelegate::views_delegate->OnBeforeWidgetInit(¶ms, this); |
| 341 |
343 is_top_level_ = params.top_level || | 342 is_top_level_ = params.top_level || |
344 (!params.child && | 343 (!params.child && |
345 params.type != InitParams::TYPE_CONTROL && | 344 params.type != InitParams::TYPE_CONTROL && |
346 params.type != InitParams::TYPE_TOOLTIP); | 345 params.type != InitParams::TYPE_TOOLTIP); |
347 widget_delegate_ = params.delegate ? | 346 widget_delegate_ = params.delegate ? |
348 params.delegate : new DefaultWidgetDelegate(this, params); | 347 params.delegate : new DefaultWidgetDelegate(this, params); |
349 ownership_ = params.ownership; | 348 ownership_ = params.ownership; |
350 native_widget_ = CreateNativeWidget( | 349 native_widget_ = CreateNativeWidget(params.native_widget, this)-> |
351 params.native_widget, this, params.type, params.parent, params.context)-> | 350 AsNativeWidgetPrivate(); |
352 AsNativeWidgetPrivate(); | |
353 GetRootView(); | 351 GetRootView(); |
354 default_theme_provider_.reset(new DefaultThemeProvider); | 352 default_theme_provider_.reset(new DefaultThemeProvider); |
355 if (params.type == InitParams::TYPE_MENU) { | 353 if (params.type == InitParams::TYPE_MENU) { |
356 is_mouse_button_pressed_ = | 354 is_mouse_button_pressed_ = |
357 internal::NativeWidgetPrivate::IsMouseButtonDown(); | 355 internal::NativeWidgetPrivate::IsMouseButtonDown(); |
358 } | 356 } |
359 native_widget_->InitNativeWidget(params); | 357 native_widget_->InitNativeWidget(params); |
360 if (RequiresNonClientView(params.type)) { | 358 if (RequiresNonClientView(params.type)) { |
361 non_client_view_ = new NonClientView; | 359 non_client_view_ = new NonClientView; |
362 non_client_view_->SetFrameView(CreateNonClientFrameView()); | 360 non_client_view_->SetFrameView(CreateNonClientFrameView()); |
(...skipping 1023 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1386 | 1384 |
1387 //////////////////////////////////////////////////////////////////////////////// | 1385 //////////////////////////////////////////////////////////////////////////////// |
1388 // internal::NativeWidgetPrivate, NativeWidget implementation: | 1386 // internal::NativeWidgetPrivate, NativeWidget implementation: |
1389 | 1387 |
1390 internal::NativeWidgetPrivate* NativeWidgetPrivate::AsNativeWidgetPrivate() { | 1388 internal::NativeWidgetPrivate* NativeWidgetPrivate::AsNativeWidgetPrivate() { |
1391 return this; | 1389 return this; |
1392 } | 1390 } |
1393 | 1391 |
1394 } // namespace internal | 1392 } // namespace internal |
1395 } // namespace views | 1393 } // namespace views |
OLD | NEW |