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/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 } | 62 } |
63 return native_widget; | 63 return native_widget; |
64 } | 64 } |
65 | 65 |
66 } // namespace | 66 } // namespace |
67 | 67 |
68 // A default implementation of WidgetDelegate, used by Widget when no | 68 // A default implementation of WidgetDelegate, used by Widget when no |
69 // WidgetDelegate is supplied. | 69 // WidgetDelegate is supplied. |
70 class DefaultWidgetDelegate : public WidgetDelegate { | 70 class DefaultWidgetDelegate : public WidgetDelegate { |
71 public: | 71 public: |
72 DefaultWidgetDelegate(Widget* widget, bool can_activate) | 72 explicit DefaultWidgetDelegate(Widget* widget) : widget_(widget) { |
73 : widget_(widget), | |
74 can_activate_(can_activate) { | |
75 } | 73 } |
76 virtual ~DefaultWidgetDelegate() {} | 74 virtual ~DefaultWidgetDelegate() {} |
77 | 75 |
78 // Overridden from WidgetDelegate: | 76 // Overridden from WidgetDelegate: |
79 virtual void DeleteDelegate() OVERRIDE { | 77 virtual void DeleteDelegate() OVERRIDE { |
80 delete this; | 78 delete this; |
81 } | 79 } |
82 virtual Widget* GetWidget() OVERRIDE { | 80 virtual Widget* GetWidget() OVERRIDE { |
83 return widget_; | 81 return widget_; |
84 } | 82 } |
85 virtual const Widget* GetWidget() const OVERRIDE { | 83 virtual const Widget* GetWidget() const OVERRIDE { |
86 return widget_; | 84 return widget_; |
87 } | 85 } |
88 virtual bool CanActivate() const OVERRIDE { | |
89 return can_activate_; | |
90 } | |
91 virtual bool ShouldAdvanceFocusToTopLevelWidget() const OVERRIDE { | 86 virtual bool ShouldAdvanceFocusToTopLevelWidget() const OVERRIDE { |
92 // In most situations where a Widget is used without a delegate the Widget | 87 // In most situations where a Widget is used without a delegate the Widget |
93 // is used as a container, so that we want focus to advance to the top-level | 88 // is used as a container, so that we want focus to advance to the top-level |
94 // widget. A good example of this is the find bar. | 89 // widget. A good example of this is the find bar. |
95 return true; | 90 return true; |
96 } | 91 } |
97 | 92 |
98 private: | 93 private: |
99 Widget* widget_; | 94 Widget* widget_; |
100 bool can_activate_; | |
101 | 95 |
102 DISALLOW_COPY_AND_ASSIGN(DefaultWidgetDelegate); | 96 DISALLOW_COPY_AND_ASSIGN(DefaultWidgetDelegate); |
103 }; | 97 }; |
104 | 98 |
105 //////////////////////////////////////////////////////////////////////////////// | 99 //////////////////////////////////////////////////////////////////////////////// |
106 // Widget, InitParams: | 100 // Widget, InitParams: |
107 | 101 |
108 Widget::InitParams::InitParams() | 102 Widget::InitParams::InitParams() |
109 : type(TYPE_WINDOW), | 103 : type(TYPE_WINDOW), |
110 delegate(NULL), | 104 delegate(NULL), |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 void Widget::Init(const InitParams& in_params) { | 331 void Widget::Init(const InitParams& in_params) { |
338 TRACE_EVENT0("views", "Widget::Init"); | 332 TRACE_EVENT0("views", "Widget::Init"); |
339 InitParams params = in_params; | 333 InitParams params = in_params; |
340 | 334 |
341 is_top_level_ = params.top_level || | 335 is_top_level_ = params.top_level || |
342 (!params.child && | 336 (!params.child && |
343 params.type != InitParams::TYPE_CONTROL && | 337 params.type != InitParams::TYPE_CONTROL && |
344 params.type != InitParams::TYPE_TOOLTIP); | 338 params.type != InitParams::TYPE_TOOLTIP); |
345 params.top_level = is_top_level_; | 339 params.top_level = is_top_level_; |
346 | 340 |
347 if (params.activatable != InitParams::ACTIVATABLE_DEFAULT) { | |
348 can_activate_ = (params.activatable == InitParams::ACTIVATABLE_YES); | |
349 } else if (params.type != InitParams::TYPE_CONTROL && | |
350 params.type != InitParams::TYPE_POPUP && | |
351 params.type != InitParams::TYPE_MENU && | |
352 params.type != InitParams::TYPE_TOOLTIP && | |
353 params.type != InitParams::TYPE_DRAG) { | |
354 can_activate_ = true; | |
355 params.activatable = InitParams::ACTIVATABLE_YES; | |
356 } else { | |
357 can_activate_ = false; | |
358 params.activatable = InitParams::ACTIVATABLE_NO; | |
359 } | |
360 | |
361 if (params.opacity == views::Widget::InitParams::INFER_OPACITY && | 341 if (params.opacity == views::Widget::InitParams::INFER_OPACITY && |
362 params.type != views::Widget::InitParams::TYPE_WINDOW && | 342 params.type != views::Widget::InitParams::TYPE_WINDOW && |
363 params.type != views::Widget::InitParams::TYPE_PANEL) | 343 params.type != views::Widget::InitParams::TYPE_PANEL) |
364 params.opacity = views::Widget::InitParams::OPAQUE_WINDOW; | 344 params.opacity = views::Widget::InitParams::OPAQUE_WINDOW; |
365 | 345 |
366 if (ViewsDelegate::views_delegate) | 346 if (ViewsDelegate::views_delegate) |
367 ViewsDelegate::views_delegate->OnBeforeWidgetInit(¶ms, this); | 347 ViewsDelegate::views_delegate->OnBeforeWidgetInit(¶ms, this); |
368 | 348 |
369 if (params.opacity == views::Widget::InitParams::INFER_OPACITY) | 349 if (params.opacity == views::Widget::InitParams::INFER_OPACITY) |
370 params.opacity = views::Widget::InitParams::OPAQUE_WINDOW; | 350 params.opacity = views::Widget::InitParams::OPAQUE_WINDOW; |
371 | 351 |
| 352 bool can_activate = false; |
| 353 if (params.activatable != InitParams::ACTIVATABLE_DEFAULT) { |
| 354 can_activate = (params.activatable == InitParams::ACTIVATABLE_YES); |
| 355 } else if (params.type != InitParams::TYPE_CONTROL && |
| 356 params.type != InitParams::TYPE_POPUP && |
| 357 params.type != InitParams::TYPE_MENU && |
| 358 params.type != InitParams::TYPE_TOOLTIP && |
| 359 params.type != InitParams::TYPE_DRAG) { |
| 360 can_activate = true; |
| 361 params.activatable = InitParams::ACTIVATABLE_YES; |
| 362 } else { |
| 363 can_activate = false; |
| 364 params.activatable = InitParams::ACTIVATABLE_NO; |
| 365 } |
| 366 |
372 widget_delegate_ = params.delegate ? | 367 widget_delegate_ = params.delegate ? |
373 params.delegate : new DefaultWidgetDelegate(this, can_activate_); | 368 params.delegate : new DefaultWidgetDelegate(this); |
| 369 widget_delegate_->set_can_activate(can_activate); |
| 370 |
374 ownership_ = params.ownership; | 371 ownership_ = params.ownership; |
375 native_widget_ = CreateNativeWidget(params.native_widget, this)-> | 372 native_widget_ = CreateNativeWidget(params.native_widget, this)-> |
376 AsNativeWidgetPrivate(); | 373 AsNativeWidgetPrivate(); |
377 root_view_.reset(CreateRootView()); | 374 root_view_.reset(CreateRootView()); |
378 default_theme_provider_.reset(new ui::DefaultThemeProvider); | 375 default_theme_provider_.reset(new ui::DefaultThemeProvider); |
379 if (params.type == InitParams::TYPE_MENU) { | 376 if (params.type == InitParams::TYPE_MENU) { |
380 is_mouse_button_pressed_ = | 377 is_mouse_button_pressed_ = |
381 internal::NativeWidgetPrivate::IsMouseButtonDown(); | 378 internal::NativeWidgetPrivate::IsMouseButtonDown(); |
382 } | 379 } |
383 native_widget_->InitNativeWidget(params); | 380 native_widget_->InitNativeWidget(params); |
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1012 | 1009 |
1013 bool Widget::IsModal() const { | 1010 bool Widget::IsModal() const { |
1014 return widget_delegate_->GetModalType() != ui::MODAL_TYPE_NONE; | 1011 return widget_delegate_->GetModalType() != ui::MODAL_TYPE_NONE; |
1015 } | 1012 } |
1016 | 1013 |
1017 bool Widget::IsDialogBox() const { | 1014 bool Widget::IsDialogBox() const { |
1018 return !!widget_delegate_->AsDialogDelegate(); | 1015 return !!widget_delegate_->AsDialogDelegate(); |
1019 } | 1016 } |
1020 | 1017 |
1021 bool Widget::CanActivate() const { | 1018 bool Widget::CanActivate() const { |
1022 return can_activate_ && widget_delegate_->CanActivate(); | 1019 return widget_delegate_->CanActivate(); |
1023 } | 1020 } |
1024 | 1021 |
1025 bool Widget::IsInactiveRenderingDisabled() const { | 1022 bool Widget::IsInactiveRenderingDisabled() const { |
1026 return disable_inactive_rendering_; | 1023 return disable_inactive_rendering_; |
1027 } | 1024 } |
1028 | 1025 |
1029 void Widget::EnableInactiveRendering() { | 1026 void Widget::EnableInactiveRendering() { |
1030 SetInactiveRenderingDisabled(false); | 1027 SetInactiveRenderingDisabled(false); |
1031 } | 1028 } |
1032 | 1029 |
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1514 | 1511 |
1515 //////////////////////////////////////////////////////////////////////////////// | 1512 //////////////////////////////////////////////////////////////////////////////// |
1516 // internal::NativeWidgetPrivate, NativeWidget implementation: | 1513 // internal::NativeWidgetPrivate, NativeWidget implementation: |
1517 | 1514 |
1518 internal::NativeWidgetPrivate* NativeWidgetPrivate::AsNativeWidgetPrivate() { | 1515 internal::NativeWidgetPrivate* NativeWidgetPrivate::AsNativeWidgetPrivate() { |
1519 return this; | 1516 return this; |
1520 } | 1517 } |
1521 | 1518 |
1522 } // namespace internal | 1519 } // namespace internal |
1523 } // namespace views | 1520 } // namespace views |
OLD | NEW |