| 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/native_widget_aura.h" | 5 #include "ui/views/widget/native_widget_aura.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "third_party/skia/include/core/SkRegion.h" | 9 #include "third_party/skia/include/core/SkRegion.h" |
| 10 #include "ui/aura/client/activation_client.h" | 10 #include "ui/aura/client/activation_client.h" |
| 11 #include "ui/aura/client/aura_constants.h" | 11 #include "ui/aura/client/aura_constants.h" |
| 12 #include "ui/aura/client/dispatcher_client.h" | |
| 13 #include "ui/aura/client/drag_drop_client.h" | 12 #include "ui/aura/client/drag_drop_client.h" |
| 14 #include "ui/aura/client/window_move_client.h" | 13 #include "ui/aura/client/window_move_client.h" |
| 15 #include "ui/aura/client/window_types.h" | 14 #include "ui/aura/client/window_types.h" |
| 16 #include "ui/aura/desktop/desktop_activation_client.h" | |
| 17 #include "ui/aura/desktop/desktop_dispatcher_client.h" | |
| 18 #include "ui/aura/desktop/desktop_root_window_event_filter.h" | |
| 19 #include "ui/aura/env.h" | 15 #include "ui/aura/env.h" |
| 20 #include "ui/aura/event.h" | 16 #include "ui/aura/event.h" |
| 21 #include "ui/aura/root_window.h" | 17 #include "ui/aura/root_window.h" |
| 22 #include "ui/aura/window.h" | 18 #include "ui/aura/window.h" |
| 23 #include "ui/aura/window_observer.h" | 19 #include "ui/aura/window_observer.h" |
| 24 #include "ui/base/dragdrop/os_exchange_data.h" | 20 #include "ui/base/dragdrop/os_exchange_data.h" |
| 25 #include "ui/base/ui_base_types.h" | 21 #include "ui/base/ui_base_types.h" |
| 26 #include "ui/gfx/canvas.h" | 22 #include "ui/gfx/canvas.h" |
| 27 #include "ui/gfx/compositor/layer.h" | 23 #include "ui/gfx/compositor/layer.h" |
| 28 #include "ui/gfx/font.h" | 24 #include "ui/gfx/font.h" |
| 29 #include "ui/gfx/screen.h" | 25 #include "ui/gfx/screen.h" |
| 30 #include "ui/views/drag_utils.h" | 26 #include "ui/views/drag_utils.h" |
| 31 #include "ui/views/ime/input_method_bridge.h" | 27 #include "ui/views/ime/input_method_bridge.h" |
| 28 #include "ui/views/views_delegate.h" |
| 32 #include "ui/views/widget/drop_helper.h" | 29 #include "ui/views/widget/drop_helper.h" |
| 33 #include "ui/views/widget/native_widget_delegate.h" | 30 #include "ui/views/widget/native_widget_delegate.h" |
| 31 #include "ui/views/widget/native_widget_helper_aura.h" |
| 34 #include "ui/views/widget/root_view.h" | 32 #include "ui/views/widget/root_view.h" |
| 35 #include "ui/views/widget/tooltip_manager_aura.h" | 33 #include "ui/views/widget/tooltip_manager_aura.h" |
| 36 #include "ui/views/widget/widget_delegate.h" | 34 #include "ui/views/widget/widget_delegate.h" |
| 37 | 35 |
| 38 #if defined(OS_WIN) | 36 #if defined(OS_WIN) |
| 39 #include "base/win/scoped_gdi_object.h" | 37 #include "base/win/scoped_gdi_object.h" |
| 40 #include "base/win/win_util.h" | 38 #include "base/win/win_util.h" |
| 41 #include "ui/base/l10n/l10n_util_win.h" | 39 #include "ui/base/l10n/l10n_util_win.h" |
| 42 #endif | 40 #endif |
| 43 | 41 |
| 44 #if defined(ENABLE_DIP) | 42 #if defined(ENABLE_DIP) |
| 45 #include "ui/aura/monitor.h" | 43 #include "ui/aura/monitor.h" |
| 46 #include "ui/aura/monitor_manager.h" | 44 #include "ui/aura/monitor_manager.h" |
| 47 #endif | 45 #endif |
| 48 | 46 |
| 49 namespace views { | 47 namespace views { |
| 50 | 48 |
| 51 bool NativeWidgetAura::g_aura_desktop_hax = false; | |
| 52 | |
| 53 namespace { | 49 namespace { |
| 54 | 50 |
| 55 aura::client::WindowType GetAuraWindowTypeForWidgetType( | 51 aura::client::WindowType GetAuraWindowTypeForWidgetType( |
| 56 Widget::InitParams::Type type) { | 52 Widget::InitParams::Type type) { |
| 57 switch (type) { | 53 switch (type) { |
| 58 case Widget::InitParams::TYPE_WINDOW: | 54 case Widget::InitParams::TYPE_WINDOW: |
| 59 return aura::client::WINDOW_TYPE_NORMAL; | 55 return aura::client::WINDOW_TYPE_NORMAL; |
| 60 case Widget::InitParams::TYPE_PANEL: | 56 case Widget::InitParams::TYPE_PANEL: |
| 61 return aura::client::WINDOW_TYPE_PANEL; | 57 return aura::client::WINDOW_TYPE_PANEL; |
| 62 case Widget::InitParams::TYPE_CONTROL: | 58 case Widget::InitParams::TYPE_CONTROL: |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 NativeWidgetAura* host_; | 128 NativeWidgetAura* host_; |
| 133 | 129 |
| 134 DISALLOW_COPY_AND_ASSIGN(ActiveWindowObserver); | 130 DISALLOW_COPY_AND_ASSIGN(ActiveWindowObserver); |
| 135 }; | 131 }; |
| 136 | 132 |
| 137 //////////////////////////////////////////////////////////////////////////////// | 133 //////////////////////////////////////////////////////////////////////////////// |
| 138 // NativeWidgetAura, public: | 134 // NativeWidgetAura, public: |
| 139 | 135 |
| 140 NativeWidgetAura::NativeWidgetAura(internal::NativeWidgetDelegate* delegate) | 136 NativeWidgetAura::NativeWidgetAura(internal::NativeWidgetDelegate* delegate) |
| 141 : delegate_(delegate), | 137 : delegate_(delegate), |
| 142 root_window_(NULL), | 138 ALLOW_THIS_IN_INITIALIZER_LIST(desktop_helper_( |
| 139 ViewsDelegate::views_delegate ? |
| 140 ViewsDelegate::views_delegate->CreateNativeWidgetHelper(this) : |
| 141 NULL)), |
| 143 ALLOW_THIS_IN_INITIALIZER_LIST(window_(new aura::Window(this))), | 142 ALLOW_THIS_IN_INITIALIZER_LIST(window_(new aura::Window(this))), |
| 144 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET), | 143 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET), |
| 145 ALLOW_THIS_IN_INITIALIZER_LIST(close_widget_factory_(this)), | 144 ALLOW_THIS_IN_INITIALIZER_LIST(close_widget_factory_(this)), |
| 146 can_activate_(true), | 145 can_activate_(true), |
| 147 cursor_(gfx::kNullCursor), | 146 cursor_(gfx::kNullCursor), |
| 148 saved_window_state_(ui::SHOW_STATE_DEFAULT) { | 147 saved_window_state_(ui::SHOW_STATE_DEFAULT) { |
| 149 } | 148 } |
| 150 | 149 |
| 151 NativeWidgetAura::~NativeWidgetAura() { | 150 NativeWidgetAura::~NativeWidgetAura() { |
| 152 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) | 151 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 166 #else | 165 #else |
| 167 return gfx::Font(); | 166 return gfx::Font(); |
| 168 #endif | 167 #endif |
| 169 } | 168 } |
| 170 | 169 |
| 171 //////////////////////////////////////////////////////////////////////////////// | 170 //////////////////////////////////////////////////////////////////////////////// |
| 172 // NativeWidgetAura, internal::NativeWidgetPrivate implementation: | 171 // NativeWidgetAura, internal::NativeWidgetPrivate implementation: |
| 173 | 172 |
| 174 void NativeWidgetAura::InitNativeWidget(const Widget::InitParams& params) { | 173 void NativeWidgetAura::InitNativeWidget(const Widget::InitParams& params) { |
| 175 ownership_ = params.ownership; | 174 ownership_ = params.ownership; |
| 176 // TODO(erg): What kind of windows do we want to have their own root windows? | |
| 177 if (g_aura_desktop_hax) { | |
| 178 gfx::Rect bounds = params.bounds; | |
| 179 if (bounds.IsEmpty()) { | |
| 180 // We must pass some non-zero value when we initialize a RootWindow. This | |
| 181 // will probably be SetBounds()ed soon. | |
| 182 bounds.set_size(gfx::Size(100, 100)); | |
| 183 } | |
| 184 root_window_.reset(new aura::RootWindow(bounds)); | |
| 185 root_window_->SetEventFilter( | |
| 186 new aura::DesktopRootWindowEventFilter(root_window_.get())); | |
| 187 root_window_->AddRootWindowObserver(this); | |
| 188 | 175 |
| 189 aura::client::SetActivationClient( | 176 if (desktop_helper_.get()) |
| 190 root_window_.get(), | 177 desktop_helper_->PreInitialize(params); |
| 191 new aura::DesktopActivationClient(root_window_.get())); | |
| 192 aura::client::SetDispatcherClient(root_window_.get(), | |
| 193 new aura::DesktopDispatcherClient); | |
| 194 } | |
| 195 | 178 |
| 196 window_->set_user_data(this); | 179 window_->set_user_data(this); |
| 197 window_->SetType(GetAuraWindowTypeForWidgetType(params.type)); | 180 window_->SetType(GetAuraWindowTypeForWidgetType(params.type)); |
| 198 window_->SetProperty(aura::client::kShowStateKey, params.show_state); | 181 window_->SetProperty(aura::client::kShowStateKey, params.show_state); |
| 199 if (params.type == Widget::InitParams::TYPE_BUBBLE) | 182 if (params.type == Widget::InitParams::TYPE_BUBBLE) |
| 200 aura::client::SetHideOnDeactivate(window_, true); | 183 aura::client::SetHideOnDeactivate(window_, true); |
| 201 window_->SetTransparent(params.transparent); | 184 window_->SetTransparent(params.transparent); |
| 202 window_->Init(params.layer_type); | 185 window_->Init(params.layer_type); |
| 203 if (params.type == Widget::InitParams::TYPE_CONTROL) | 186 if (params.type == Widget::InitParams::TYPE_CONTROL) |
| 204 window_->Show(); | 187 window_->Show(); |
| 205 | 188 |
| 206 delegate_->OnNativeWidgetCreated(); | 189 delegate_->OnNativeWidgetCreated(); |
| 207 if (root_window_.get()) { | 190 if (desktop_helper_.get() && desktop_helper_->GetRootWindow()) { |
| 208 window_->SetParent(root_window_.get()); | 191 window_->SetParent(desktop_helper_->GetRootWindow()); |
| 209 } else if (params.child) { | 192 } else if (params.child) { |
| 210 window_->SetParent(params.GetParent()); | 193 window_->SetParent(params.GetParent()); |
| 211 } else { | 194 } else { |
| 212 // Set up the transient child before the window is added. This way the | 195 // Set up the transient child before the window is added. This way the |
| 213 // LayoutManager knows the window has a transient parent. | 196 // LayoutManager knows the window has a transient parent. |
| 214 gfx::NativeView parent = params.GetParent(); | 197 gfx::NativeView parent = params.GetParent(); |
| 215 if (parent && parent->type() != aura::client::WINDOW_TYPE_UNKNOWN) { | 198 if (parent && parent->type() != aura::client::WINDOW_TYPE_UNKNOWN) { |
| 216 parent->AddTransientChild(window_); | 199 parent->AddTransientChild(window_); |
| 217 | 200 |
| 218 // TODO(erg): The StackingClient interface implies that there is only a | 201 // TODO(erg): The StackingClient interface implies that there is only a |
| 219 // single root window. Solving this would require setting a stacking | 202 // single root window. Solving this would require setting a stacking |
| 220 // client per root window instead. For now, we hax our way around this by | 203 // client per root window instead. For now, we hax our way around this by |
| 221 // forcing the parent to be the root window instead of passing NULL as | 204 // forcing the parent to be the root window instead of passing NULL as |
| 222 // the parent which will dispatch to the stacking client. | 205 // the parent which will dispatch to the stacking client. |
| 223 if (g_aura_desktop_hax) | 206 if (desktop_helper_.get()) |
| 224 parent = parent->GetRootWindow(); | 207 parent = parent->GetRootWindow(); |
| 225 else | 208 else |
| 226 parent = NULL; | 209 parent = NULL; |
| 227 } | 210 } |
| 228 // SetAlwaysOnTop before SetParent so that always-on-top container is used. | 211 // SetAlwaysOnTop before SetParent so that always-on-top container is used. |
| 229 SetAlwaysOnTop(params.keep_on_top); | 212 SetAlwaysOnTop(params.keep_on_top); |
| 230 window_->SetParent(parent); | 213 window_->SetParent(parent); |
| 231 } | 214 } |
| 232 | 215 |
| 233 // Wait to set the bounds until we have a parent. That way we can know our | 216 // Wait to set the bounds until we have a parent. That way we can know our |
| (...skipping 12 matching lines...) Expand all Loading... |
| 246 #endif // !defined(OS_MACOSX) | 229 #endif // !defined(OS_MACOSX) |
| 247 | 230 |
| 248 drop_helper_.reset(new DropHelper(GetWidget()->GetRootView())); | 231 drop_helper_.reset(new DropHelper(GetWidget()->GetRootView())); |
| 249 if (params.type != Widget::InitParams::TYPE_TOOLTIP && | 232 if (params.type != Widget::InitParams::TYPE_TOOLTIP && |
| 250 params.type != Widget::InitParams::TYPE_POPUP) { | 233 params.type != Widget::InitParams::TYPE_POPUP) { |
| 251 aura::client::SetDragDropDelegate(window_, this); | 234 aura::client::SetDragDropDelegate(window_, this); |
| 252 } | 235 } |
| 253 | 236 |
| 254 aura::client::SetActivationDelegate(window_, this); | 237 aura::client::SetActivationDelegate(window_, this); |
| 255 | 238 |
| 256 if (root_window_.get()) | 239 // TODO(erg): Move this somewhere else? |
| 257 root_window_->ShowRootWindow(); | 240 if (desktop_helper_.get()) |
| 241 desktop_helper_->ShowRootWindow(); |
| 258 } | 242 } |
| 259 | 243 |
| 260 NonClientFrameView* NativeWidgetAura::CreateNonClientFrameView() { | 244 NonClientFrameView* NativeWidgetAura::CreateNonClientFrameView() { |
| 261 return NULL; | 245 return NULL; |
| 262 } | 246 } |
| 263 | 247 |
| 264 void NativeWidgetAura::UpdateFrameAfterFrameChange() { | 248 void NativeWidgetAura::UpdateFrameAfterFrameChange() { |
| 265 } | 249 } |
| 266 | 250 |
| 267 bool NativeWidgetAura::ShouldUseNativeFrame() const { | 251 bool NativeWidgetAura::ShouldUseNativeFrame() const { |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 return ConvertRectFromMonitor( | 448 return ConvertRectFromMonitor( |
| 465 restore_bounds ? *restore_bounds : window_->bounds()); | 449 restore_bounds ? *restore_bounds : window_->bounds()); |
| 466 #else | 450 #else |
| 467 return restore_bounds ? *restore_bounds : window_->bounds(); | 451 return restore_bounds ? *restore_bounds : window_->bounds(); |
| 468 #endif | 452 #endif |
| 469 } | 453 } |
| 470 | 454 |
| 471 void NativeWidgetAura::SetBounds(const gfx::Rect& in_bounds) { | 455 void NativeWidgetAura::SetBounds(const gfx::Rect& in_bounds) { |
| 472 gfx::Rect bounds = in_bounds; | 456 gfx::Rect bounds = in_bounds; |
| 473 | 457 |
| 474 if (root_window_.get() && !bounds.IsEmpty()) { | 458 if (desktop_helper_.get()) |
| 475 root_window_->SetHostBounds(bounds); | 459 bounds = desktop_helper_->ModifyAndSetBounds(bounds); |
| 476 bounds.set_x(0); | |
| 477 bounds.set_y(0); | |
| 478 } | |
| 479 #if defined(ENABLE_DIP) | 460 #if defined(ENABLE_DIP) |
| 480 bounds = ConvertRectToMonitor(bounds); | 461 bounds = ConvertRectToMonitor(bounds); |
| 481 #endif | 462 #endif |
| 482 window_->SetBounds(bounds); | 463 window_->SetBounds(bounds); |
| 483 } | 464 } |
| 484 | 465 |
| 485 void NativeWidgetAura::SetSize(const gfx::Size& size) { | 466 void NativeWidgetAura::SetSize(const gfx::Size& size) { |
| 486 #if defined(ENABLE_DIP) | 467 #if defined(ENABLE_DIP) |
| 487 gfx::Size monitor_size = ConvertSizeToMonitor(size); | 468 gfx::Size monitor_size = ConvertSizeToMonitor(size); |
| 488 window_->SetBounds(gfx::Rect(window_->bounds().origin(), monitor_size)); | 469 window_->SetBounds(gfx::Rect(window_->bounds().origin(), monitor_size)); |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 866 delegate_->OnNativeWidgetDestroyed(); | 847 delegate_->OnNativeWidgetDestroyed(); |
| 867 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) | 848 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) |
| 868 delete this; | 849 delete this; |
| 869 } | 850 } |
| 870 | 851 |
| 871 void NativeWidgetAura::OnWindowVisibilityChanged(bool visible) { | 852 void NativeWidgetAura::OnWindowVisibilityChanged(bool visible) { |
| 872 delegate_->OnNativeWidgetVisibilityChanged(visible); | 853 delegate_->OnNativeWidgetVisibilityChanged(visible); |
| 873 } | 854 } |
| 874 | 855 |
| 875 //////////////////////////////////////////////////////////////////////////////// | 856 //////////////////////////////////////////////////////////////////////////////// |
| 876 // NativeWidgetAura, aura::RootWindowObserver implementation: | |
| 877 | |
| 878 void NativeWidgetAura::OnRootWindowResized(const aura::RootWindow* root, | |
| 879 const gfx::Size& old_size) { | |
| 880 // This case can only happen if we have our own aura::RootWindow*. When that | |
| 881 // happens, our main window should be at the origin and sized to the | |
| 882 // RootWindow. | |
| 883 DCHECK_EQ(root, root_window_.get()); | |
| 884 SetBounds(gfx::Rect(root->GetHostSize())); | |
| 885 } | |
| 886 | |
| 887 void NativeWidgetAura::OnRootWindowHostClosed(const aura::RootWindow* root) { | |
| 888 DCHECK_EQ(root, root_window_.get()); | |
| 889 GetWidget()->Close(); | |
| 890 } | |
| 891 | |
| 892 //////////////////////////////////////////////////////////////////////////////// | |
| 893 // NativeWidgetAura, aura::ActivationDelegate implementation: | 857 // NativeWidgetAura, aura::ActivationDelegate implementation: |
| 894 | 858 |
| 895 bool NativeWidgetAura::ShouldActivate(const aura::Event* event) { | 859 bool NativeWidgetAura::ShouldActivate(const aura::Event* event) { |
| 896 return can_activate_ && delegate_->CanActivate(); | 860 return can_activate_ && delegate_->CanActivate(); |
| 897 } | 861 } |
| 898 | 862 |
| 899 void NativeWidgetAura::OnActivated() { | 863 void NativeWidgetAura::OnActivated() { |
| 900 if (GetWidget()->HasFocusManager()) | 864 if (GetWidget()->HasFocusManager()) |
| 901 GetWidget()->GetFocusManager()->RestoreFocusedView(); | 865 GetWidget()->GetFocusManager()->RestoreFocusedView(); |
| 902 delegate_->OnNativeWidgetActivationChanged(true); | 866 delegate_->OnNativeWidgetActivationChanged(true); |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1085 } | 1049 } |
| 1086 } | 1050 } |
| 1087 | 1051 |
| 1088 // static | 1052 // static |
| 1089 bool NativeWidgetPrivate::IsMouseButtonDown() { | 1053 bool NativeWidgetPrivate::IsMouseButtonDown() { |
| 1090 return aura::Env::GetInstance()->is_mouse_button_down(); | 1054 return aura::Env::GetInstance()->is_mouse_button_down(); |
| 1091 } | 1055 } |
| 1092 | 1056 |
| 1093 } // namespace internal | 1057 } // namespace internal |
| 1094 } // namespace views | 1058 } // namespace views |
| OLD | NEW |