| 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, const Widget::InitParams& params) | 72 DefaultWidgetDelegate(Widget* widget, bool can_activate) |
| 73 : widget_(widget), | 73 : widget_(widget), |
| 74 can_activate_(!params.child && | 74 can_activate_(can_activate) { |
| 75 params.type != Widget::InitParams::TYPE_POPUP && | |
| 76 params.type != Widget::InitParams::TYPE_DRAG) { | |
| 77 } | 75 } |
| 78 virtual ~DefaultWidgetDelegate() {} | 76 virtual ~DefaultWidgetDelegate() {} |
| 79 | 77 |
| 80 // Overridden from WidgetDelegate: | 78 // Overridden from WidgetDelegate: |
| 81 virtual void DeleteDelegate() OVERRIDE { | 79 virtual void DeleteDelegate() OVERRIDE { |
| 82 delete this; | 80 delete this; |
| 83 } | 81 } |
| 84 virtual Widget* GetWidget() OVERRIDE { | 82 virtual Widget* GetWidget() OVERRIDE { |
| 85 return widget_; | 83 return widget_; |
| 86 } | 84 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 106 | 104 |
| 107 //////////////////////////////////////////////////////////////////////////////// | 105 //////////////////////////////////////////////////////////////////////////////// |
| 108 // Widget, InitParams: | 106 // Widget, InitParams: |
| 109 | 107 |
| 110 Widget::InitParams::InitParams() | 108 Widget::InitParams::InitParams() |
| 111 : type(TYPE_WINDOW), | 109 : type(TYPE_WINDOW), |
| 112 delegate(NULL), | 110 delegate(NULL), |
| 113 child(false), | 111 child(false), |
| 114 opacity(INFER_OPACITY), | 112 opacity(INFER_OPACITY), |
| 115 accept_events(true), | 113 accept_events(true), |
| 116 can_activate(true), | 114 activatable(ACTIVATABLE_DEFAULT), |
| 117 keep_on_top(false), | 115 keep_on_top(false), |
| 118 visible_on_all_workspaces(false), | 116 visible_on_all_workspaces(false), |
| 119 ownership(NATIVE_WIDGET_OWNS_WIDGET), | 117 ownership(NATIVE_WIDGET_OWNS_WIDGET), |
| 120 mirror_origin_in_rtl(false), | 118 mirror_origin_in_rtl(false), |
| 121 has_dropshadow(false), | 119 has_dropshadow(false), |
| 122 remove_standard_frame(false), | 120 remove_standard_frame(false), |
| 123 use_system_default_icon(false), | 121 use_system_default_icon(false), |
| 124 show_state(ui::SHOW_STATE_DEFAULT), | 122 show_state(ui::SHOW_STATE_DEFAULT), |
| 125 double_buffer(false), | 123 double_buffer(false), |
| 126 parent(NULL), | 124 parent(NULL), |
| 127 native_widget(NULL), | 125 native_widget(NULL), |
| 128 desktop_window_tree_host(NULL), | 126 desktop_window_tree_host(NULL), |
| 129 top_level(false), | 127 top_level(false), |
| 130 layer_type(aura::WINDOW_LAYER_TEXTURED), | 128 layer_type(aura::WINDOW_LAYER_TEXTURED), |
| 131 context(NULL), | 129 context(NULL), |
| 132 force_show_in_taskbar(false) { | 130 force_show_in_taskbar(false) { |
| 133 } | 131 } |
| 134 | 132 |
| 135 Widget::InitParams::InitParams(Type type) | 133 Widget::InitParams::InitParams(Type type) |
| 136 : type(type), | 134 : type(type), |
| 137 delegate(NULL), | 135 delegate(NULL), |
| 138 child(type == TYPE_CONTROL), | 136 child(type == TYPE_CONTROL), |
| 139 opacity(INFER_OPACITY), | 137 opacity(INFER_OPACITY), |
| 140 accept_events(true), | 138 accept_events(true), |
| 141 can_activate(type != TYPE_POPUP && type != TYPE_MENU && | 139 activatable(ACTIVATABLE_DEFAULT), |
| 142 type != TYPE_DRAG), | |
| 143 keep_on_top(type == TYPE_MENU || type == TYPE_DRAG), | 140 keep_on_top(type == TYPE_MENU || type == TYPE_DRAG), |
| 144 visible_on_all_workspaces(false), | 141 visible_on_all_workspaces(false), |
| 145 ownership(NATIVE_WIDGET_OWNS_WIDGET), | 142 ownership(NATIVE_WIDGET_OWNS_WIDGET), |
| 146 mirror_origin_in_rtl(false), | 143 mirror_origin_in_rtl(false), |
| 147 has_dropshadow(false), | 144 has_dropshadow(false), |
| 148 remove_standard_frame(false), | 145 remove_standard_frame(false), |
| 149 use_system_default_icon(false), | 146 use_system_default_icon(false), |
| 150 show_state(ui::SHOW_STATE_DEFAULT), | 147 show_state(ui::SHOW_STATE_DEFAULT), |
| 151 double_buffer(false), | 148 double_buffer(false), |
| 152 parent(NULL), | 149 parent(NULL), |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 void Widget::Init(const InitParams& in_params) { | 337 void Widget::Init(const InitParams& in_params) { |
| 341 TRACE_EVENT0("views", "Widget::Init"); | 338 TRACE_EVENT0("views", "Widget::Init"); |
| 342 InitParams params = in_params; | 339 InitParams params = in_params; |
| 343 | 340 |
| 344 is_top_level_ = params.top_level || | 341 is_top_level_ = params.top_level || |
| 345 (!params.child && | 342 (!params.child && |
| 346 params.type != InitParams::TYPE_CONTROL && | 343 params.type != InitParams::TYPE_CONTROL && |
| 347 params.type != InitParams::TYPE_TOOLTIP); | 344 params.type != InitParams::TYPE_TOOLTIP); |
| 348 params.top_level = is_top_level_; | 345 params.top_level = is_top_level_; |
| 349 | 346 |
| 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 |
| 350 if (params.opacity == views::Widget::InitParams::INFER_OPACITY && | 361 if (params.opacity == views::Widget::InitParams::INFER_OPACITY && |
| 351 params.type != views::Widget::InitParams::TYPE_WINDOW && | 362 params.type != views::Widget::InitParams::TYPE_WINDOW && |
| 352 params.type != views::Widget::InitParams::TYPE_PANEL) | 363 params.type != views::Widget::InitParams::TYPE_PANEL) |
| 353 params.opacity = views::Widget::InitParams::OPAQUE_WINDOW; | 364 params.opacity = views::Widget::InitParams::OPAQUE_WINDOW; |
| 354 | 365 |
| 355 if (ViewsDelegate::views_delegate) | 366 if (ViewsDelegate::views_delegate) |
| 356 ViewsDelegate::views_delegate->OnBeforeWidgetInit(¶ms, this); | 367 ViewsDelegate::views_delegate->OnBeforeWidgetInit(¶ms, this); |
| 357 | 368 |
| 358 if (params.opacity == views::Widget::InitParams::INFER_OPACITY) | 369 if (params.opacity == views::Widget::InitParams::INFER_OPACITY) |
| 359 params.opacity = views::Widget::InitParams::OPAQUE_WINDOW; | 370 params.opacity = views::Widget::InitParams::OPAQUE_WINDOW; |
| 360 | 371 |
| 361 widget_delegate_ = params.delegate ? | 372 widget_delegate_ = params.delegate ? |
| 362 params.delegate : new DefaultWidgetDelegate(this, params); | 373 params.delegate : new DefaultWidgetDelegate(this, can_activate_); |
| 363 ownership_ = params.ownership; | 374 ownership_ = params.ownership; |
| 364 native_widget_ = CreateNativeWidget(params.native_widget, this)-> | 375 native_widget_ = CreateNativeWidget(params.native_widget, this)-> |
| 365 AsNativeWidgetPrivate(); | 376 AsNativeWidgetPrivate(); |
| 366 root_view_.reset(CreateRootView()); | 377 root_view_.reset(CreateRootView()); |
| 367 default_theme_provider_.reset(new ui::DefaultThemeProvider); | 378 default_theme_provider_.reset(new ui::DefaultThemeProvider); |
| 368 if (params.type == InitParams::TYPE_MENU) { | 379 if (params.type == InitParams::TYPE_MENU) { |
| 369 is_mouse_button_pressed_ = | 380 is_mouse_button_pressed_ = |
| 370 internal::NativeWidgetPrivate::IsMouseButtonDown(); | 381 internal::NativeWidgetPrivate::IsMouseButtonDown(); |
| 371 } | 382 } |
| 372 native_widget_->InitNativeWidget(params); | 383 native_widget_->InitNativeWidget(params); |
| (...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1001 | 1012 |
| 1002 bool Widget::IsModal() const { | 1013 bool Widget::IsModal() const { |
| 1003 return widget_delegate_->GetModalType() != ui::MODAL_TYPE_NONE; | 1014 return widget_delegate_->GetModalType() != ui::MODAL_TYPE_NONE; |
| 1004 } | 1015 } |
| 1005 | 1016 |
| 1006 bool Widget::IsDialogBox() const { | 1017 bool Widget::IsDialogBox() const { |
| 1007 return !!widget_delegate_->AsDialogDelegate(); | 1018 return !!widget_delegate_->AsDialogDelegate(); |
| 1008 } | 1019 } |
| 1009 | 1020 |
| 1010 bool Widget::CanActivate() const { | 1021 bool Widget::CanActivate() const { |
| 1011 return widget_delegate_->CanActivate(); | 1022 return can_activate_ && widget_delegate_->CanActivate(); |
| 1012 } | 1023 } |
| 1013 | 1024 |
| 1014 bool Widget::IsInactiveRenderingDisabled() const { | 1025 bool Widget::IsInactiveRenderingDisabled() const { |
| 1015 return disable_inactive_rendering_; | 1026 return disable_inactive_rendering_; |
| 1016 } | 1027 } |
| 1017 | 1028 |
| 1018 void Widget::EnableInactiveRendering() { | 1029 void Widget::EnableInactiveRendering() { |
| 1019 SetInactiveRenderingDisabled(false); | 1030 SetInactiveRenderingDisabled(false); |
| 1020 } | 1031 } |
| 1021 | 1032 |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1503 | 1514 |
| 1504 //////////////////////////////////////////////////////////////////////////////// | 1515 //////////////////////////////////////////////////////////////////////////////// |
| 1505 // internal::NativeWidgetPrivate, NativeWidget implementation: | 1516 // internal::NativeWidgetPrivate, NativeWidget implementation: |
| 1506 | 1517 |
| 1507 internal::NativeWidgetPrivate* NativeWidgetPrivate::AsNativeWidgetPrivate() { | 1518 internal::NativeWidgetPrivate* NativeWidgetPrivate::AsNativeWidgetPrivate() { |
| 1508 return this; | 1519 return this; |
| 1509 } | 1520 } |
| 1510 | 1521 |
| 1511 } // namespace internal | 1522 } // namespace internal |
| 1512 } // namespace views | 1523 } // namespace views |
| OLD | NEW |