| 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/desktop_aura/desktop_native_widget_aura.h" | 5 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 wm::CursorManager* DesktopNativeWidgetAura::cursor_manager_ = NULL; | 237 wm::CursorManager* DesktopNativeWidgetAura::cursor_manager_ = NULL; |
| 238 | 238 |
| 239 DesktopNativeWidgetAura::DesktopNativeWidgetAura( | 239 DesktopNativeWidgetAura::DesktopNativeWidgetAura( |
| 240 internal::NativeWidgetDelegate* delegate) | 240 internal::NativeWidgetDelegate* delegate) |
| 241 : desktop_window_tree_host_(NULL), | 241 : desktop_window_tree_host_(NULL), |
| 242 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET), | 242 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET), |
| 243 content_window_container_(NULL), | 243 content_window_container_(NULL), |
| 244 content_window_(new aura::Window(this)), | 244 content_window_(new aura::Window(this)), |
| 245 native_widget_delegate_(delegate), | 245 native_widget_delegate_(delegate), |
| 246 last_drop_operation_(ui::DragDropTypes::DRAG_NONE), | 246 last_drop_operation_(ui::DragDropTypes::DRAG_NONE), |
| 247 restore_focus_on_activate_(false), |
| 247 cursor_(gfx::kNullCursor), | 248 cursor_(gfx::kNullCursor), |
| 248 widget_type_(Widget::InitParams::TYPE_WINDOW), | 249 widget_type_(Widget::InitParams::TYPE_WINDOW), |
| 249 close_widget_factory_(this) { | 250 close_widget_factory_(this) { |
| 250 aura::client::SetFocusChangeObserver(content_window_, this); | 251 aura::client::SetFocusChangeObserver(content_window_, this); |
| 251 aura::client::SetActivationChangeObserver(content_window_, this); | 252 aura::client::SetActivationChangeObserver(content_window_, this); |
| 252 } | 253 } |
| 253 | 254 |
| 254 DesktopNativeWidgetAura::~DesktopNativeWidgetAura() { | 255 DesktopNativeWidgetAura::~DesktopNativeWidgetAura() { |
| 255 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) | 256 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) |
| 256 delete native_widget_delegate_; | 257 delete native_widget_delegate_; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 return; | 354 return; |
| 354 if (active) { | 355 if (active) { |
| 355 if (GetWidget()->HasFocusManager()) { | 356 if (GetWidget()->HasFocusManager()) { |
| 356 // This function can be called before the focus manager has had a | 357 // This function can be called before the focus manager has had a |
| 357 // chance to set the focused view. In which case we should get the | 358 // chance to set the focused view. In which case we should get the |
| 358 // last focused view. | 359 // last focused view. |
| 359 views::FocusManager* focus_manager = GetWidget()->GetFocusManager(); | 360 views::FocusManager* focus_manager = GetWidget()->GetFocusManager(); |
| 360 View* view_for_activation = focus_manager->GetFocusedView() | 361 View* view_for_activation = focus_manager->GetFocusedView() |
| 361 ? focus_manager->GetFocusedView() | 362 ? focus_manager->GetFocusedView() |
| 362 : focus_manager->GetStoredFocusView(); | 363 : focus_manager->GetStoredFocusView(); |
| 363 if (!view_for_activation) | 364 if (!view_for_activation) { |
| 364 view_for_activation = GetWidget()->GetRootView(); | 365 view_for_activation = GetWidget()->GetRootView(); |
| 365 else if (view_for_activation == focus_manager->GetStoredFocusView()) | 366 } else if (view_for_activation == focus_manager->GetStoredFocusView()) { |
| 366 focus_manager->RestoreFocusedView(); | 367 focus_manager->RestoreFocusedView(); |
| 368 // Set to false if desktop native widget has activated activation |
| 369 // change, so that aura window activation change focus restore operation |
| 370 // can be ignored. |
| 371 restore_focus_on_activate_ = false; |
| 372 } |
| 367 activation_client->ActivateWindow( | 373 activation_client->ActivateWindow( |
| 368 view_for_activation->GetWidget()->GetNativeView()); | 374 view_for_activation->GetWidget()->GetNativeView()); |
| 369 // Refreshes the focus info to IMF in case that IMF cached the old info | 375 // Refreshes the focus info to IMF in case that IMF cached the old info |
| 370 // about focused text input client when it was "inactive". | 376 // about focused text input client when it was "inactive". |
| 371 GetInputMethod()->OnFocus(); | 377 GetInputMethod()->OnFocus(); |
| 372 } | 378 } |
| 373 } else { | 379 } else { |
| 374 // If we're not active we need to deactivate the corresponding | 380 // If we're not active we need to deactivate the corresponding |
| 375 // aura::Window. This way if a child widget is active it gets correctly | 381 // aura::Window. This way if a child widget is active it gets correctly |
| 376 // deactivated (child widgets don't get native desktop activation changes, | 382 // deactivated (child widgets don't get native desktop activation changes, |
| (...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1084 | 1090 |
| 1085 //////////////////////////////////////////////////////////////////////////////// | 1091 //////////////////////////////////////////////////////////////////////////////// |
| 1086 // DesktopNativeWidgetAura, aura::client::ActivationChangeObserver | 1092 // DesktopNativeWidgetAura, aura::client::ActivationChangeObserver |
| 1087 // implementation: | 1093 // implementation: |
| 1088 | 1094 |
| 1089 void DesktopNativeWidgetAura::OnWindowActivated( | 1095 void DesktopNativeWidgetAura::OnWindowActivated( |
| 1090 aura::client::ActivationChangeObserver::ActivationReason reason, | 1096 aura::client::ActivationChangeObserver::ActivationReason reason, |
| 1091 aura::Window* gained_active, | 1097 aura::Window* gained_active, |
| 1092 aura::Window* lost_active) { | 1098 aura::Window* lost_active) { |
| 1093 DCHECK(content_window_ == gained_active || content_window_ == lost_active); | 1099 DCHECK(content_window_ == gained_active || content_window_ == lost_active); |
| 1094 if (lost_active == content_window_ && GetWidget()->HasFocusManager()) { | 1100 if (gained_active == content_window_ && restore_focus_on_activate_) { |
| 1101 restore_focus_on_activate_ = false; |
| 1102 // For OS_LINUX, desktop native widget may not be activated when child |
| 1103 // widgets gets aura activation changes. Only when desktop native widget is |
| 1104 // active, we can rely on aura activation to restore focused view. |
| 1105 if (GetWidget()->IsActive()) |
| 1106 GetWidget()->GetFocusManager()->RestoreFocusedView(); |
| 1107 } else if (lost_active == content_window_ && GetWidget()->HasFocusManager()) { |
| 1108 DCHECK(!restore_focus_on_activate_); |
| 1109 restore_focus_on_activate_ = true; |
| 1095 // Pass in false so that ClearNativeFocus() isn't invoked. | 1110 // Pass in false so that ClearNativeFocus() isn't invoked. |
| 1096 GetWidget()->GetFocusManager()->StoreFocusedView(false); | 1111 GetWidget()->GetFocusManager()->StoreFocusedView(false); |
| 1097 } | 1112 } |
| 1098 } | 1113 } |
| 1099 | 1114 |
| 1100 //////////////////////////////////////////////////////////////////////////////// | 1115 //////////////////////////////////////////////////////////////////////////////// |
| 1101 // DesktopNativeWidgetAura, aura::client::FocusChangeObserver implementation: | 1116 // DesktopNativeWidgetAura, aura::client::FocusChangeObserver implementation: |
| 1102 | 1117 |
| 1103 void DesktopNativeWidgetAura::OnWindowFocused(aura::Window* gained_focus, | 1118 void DesktopNativeWidgetAura::OnWindowFocused(aura::Window* gained_focus, |
| 1104 aura::Window* lost_focus) { | 1119 aura::Window* lost_focus) { |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1191 if (cursor_reference_count_ == 0) { | 1206 if (cursor_reference_count_ == 0) { |
| 1192 // We are the last DesktopNativeWidgetAura instance, and we are responsible | 1207 // We are the last DesktopNativeWidgetAura instance, and we are responsible |
| 1193 // for cleaning up |cursor_manager_|. | 1208 // for cleaning up |cursor_manager_|. |
| 1194 delete cursor_manager_; | 1209 delete cursor_manager_; |
| 1195 native_cursor_manager_ = NULL; | 1210 native_cursor_manager_ = NULL; |
| 1196 cursor_manager_ = NULL; | 1211 cursor_manager_ = NULL; |
| 1197 } | 1212 } |
| 1198 } | 1213 } |
| 1199 | 1214 |
| 1200 } // namespace views | 1215 } // namespace views |
| OLD | NEW |