| 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 30 matching lines...) Expand all Loading... |
| 41 // views that are direct children of the Widgets layer. | 41 // views that are direct children of the Widgets layer. |
| 42 void BuildRootLayers(View* view, std::vector<ui::Layer*>* layers) { | 42 void BuildRootLayers(View* view, std::vector<ui::Layer*>* layers) { |
| 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. |
| 52 // First, use the supplied one if non-NULL. |
| 53 // Second, ask the delegate. |
| 54 // Finally, make a default one. |
| 55 NativeWidget* CreateNativeWidget(NativeWidget* native_widget, |
| 56 internal::NativeWidgetDelegate* delegate, |
| 57 gfx::NativeView parent) { |
| 58 if (!native_widget) { |
| 59 if (ViewsDelegate::views_delegate) { |
| 60 native_widget = |
| 61 ViewsDelegate::views_delegate->CreateNativeWidget(delegate, parent); |
| 62 } |
| 63 if (!native_widget) { |
| 64 native_widget = |
| 65 internal::NativeWidgetPrivate::CreateNativeWidget(delegate); |
| 66 } |
| 67 } |
| 68 return native_widget; |
| 69 } |
| 70 |
| 51 } // namespace | 71 } // namespace |
| 52 | 72 |
| 53 // This class is used to keep track of the event a Widget is processing, and | 73 // This class is used to keep track of the event a Widget is processing, and |
| 54 // restore any previously active event afterwards. | 74 // restore any previously active event afterwards. |
| 55 class ScopedEvent { | 75 class ScopedEvent { |
| 56 public: | 76 public: |
| 57 ScopedEvent(Widget* widget, const ui::Event& event) | 77 ScopedEvent(Widget* widget, const ui::Event& event) |
| 58 : widget_(widget), | 78 : widget_(widget), |
| 59 event_(&event) { | 79 event_(&event) { |
| 60 widget->event_stack_.push(this); | 80 widget->event_stack_.push(this); |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 } | 322 } |
| 303 | 323 |
| 304 void Widget::Init(const InitParams& params) { | 324 void Widget::Init(const InitParams& params) { |
| 305 is_top_level_ = params.top_level || | 325 is_top_level_ = params.top_level || |
| 306 (!params.child && | 326 (!params.child && |
| 307 params.type != InitParams::TYPE_CONTROL && | 327 params.type != InitParams::TYPE_CONTROL && |
| 308 params.type != InitParams::TYPE_TOOLTIP); | 328 params.type != InitParams::TYPE_TOOLTIP); |
| 309 widget_delegate_ = params.delegate ? | 329 widget_delegate_ = params.delegate ? |
| 310 params.delegate : new DefaultWidgetDelegate(this, params); | 330 params.delegate : new DefaultWidgetDelegate(this, params); |
| 311 ownership_ = params.ownership; | 331 ownership_ = params.ownership; |
| 312 native_widget_ = params.native_widget ? | 332 native_widget_ = |
| 313 params.native_widget->AsNativeWidgetPrivate() : | 333 CreateNativeWidget(params.native_widget, this, params.GetParent())-> |
| 314 internal::NativeWidgetPrivate::CreateNativeWidget(this); | 334 AsNativeWidgetPrivate(); |
| 315 GetRootView(); | 335 GetRootView(); |
| 316 default_theme_provider_.reset(new DefaultThemeProvider); | 336 default_theme_provider_.reset(new DefaultThemeProvider); |
| 317 if (params.type == InitParams::TYPE_MENU) { | 337 if (params.type == InitParams::TYPE_MENU) { |
| 318 is_mouse_button_pressed_ = | 338 is_mouse_button_pressed_ = |
| 319 internal::NativeWidgetPrivate::IsMouseButtonDown(); | 339 internal::NativeWidgetPrivate::IsMouseButtonDown(); |
| 320 } | 340 } |
| 321 native_widget_->InitNativeWidget(params); | 341 native_widget_->InitNativeWidget(params); |
| 322 if (RequiresNonClientView(params.type)) { | 342 if (RequiresNonClientView(params.type)) { |
| 323 non_client_view_ = new NonClientView; | 343 non_client_view_ = new NonClientView; |
| 324 non_client_view_->SetFrameView(CreateNonClientFrameView()); | 344 non_client_view_->SetFrameView(CreateNonClientFrameView()); |
| (...skipping 1002 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1327 | 1347 |
| 1328 //////////////////////////////////////////////////////////////////////////////// | 1348 //////////////////////////////////////////////////////////////////////////////// |
| 1329 // internal::NativeWidgetPrivate, NativeWidget implementation: | 1349 // internal::NativeWidgetPrivate, NativeWidget implementation: |
| 1330 | 1350 |
| 1331 internal::NativeWidgetPrivate* NativeWidgetPrivate::AsNativeWidgetPrivate() { | 1351 internal::NativeWidgetPrivate* NativeWidgetPrivate::AsNativeWidgetPrivate() { |
| 1332 return this; | 1352 return this; |
| 1333 } | 1353 } |
| 1334 | 1354 |
| 1335 } // namespace internal | 1355 } // namespace internal |
| 1336 } // namespace views | 1356 } // namespace views |
| OLD | NEW |