Chromium Code Reviews| 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/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 49 #include "ui/views/widget/window_reorderer.h" | 49 #include "ui/views/widget/window_reorderer.h" |
| 50 #include "ui/wm/core/compound_event_filter.h" | 50 #include "ui/wm/core/compound_event_filter.h" |
| 51 #include "ui/wm/core/cursor_manager.h" | 51 #include "ui/wm/core/cursor_manager.h" |
| 52 #include "ui/wm/core/focus_controller.h" | 52 #include "ui/wm/core/focus_controller.h" |
| 53 #include "ui/wm/core/native_cursor_manager.h" | 53 #include "ui/wm/core/native_cursor_manager.h" |
| 54 #include "ui/wm/core/shadow_controller.h" | 54 #include "ui/wm/core/shadow_controller.h" |
| 55 #include "ui/wm/core/shadow_types.h" | 55 #include "ui/wm/core/shadow_types.h" |
| 56 #include "ui/wm/core/visibility_controller.h" | 56 #include "ui/wm/core/visibility_controller.h" |
| 57 #include "ui/wm/core/window_animations.h" | 57 #include "ui/wm/core/window_animations.h" |
| 58 #include "ui/wm/core/window_modality_controller.h" | 58 #include "ui/wm/core/window_modality_controller.h" |
| 59 #include "ui/wm/core/window_util.h" | |
| 59 #include "ui/wm/public/activation_client.h" | 60 #include "ui/wm/public/activation_client.h" |
| 60 | 61 |
| 61 #if defined(OS_WIN) | 62 #if defined(OS_WIN) |
| 62 #include "ui/base/win/shell.h" | 63 #include "ui/base/win/shell.h" |
| 63 #endif | 64 #endif |
| 64 | 65 |
| 65 DECLARE_EXPORTED_UI_CLASS_PROPERTY_TYPE(VIEWS_EXPORT, | 66 DECLARE_EXPORTED_UI_CLASS_PROPERTY_TYPE(VIEWS_EXPORT, |
| 66 views::DesktopNativeWidgetAura*); | 67 views::DesktopNativeWidgetAura*); |
| 67 | 68 |
| 68 namespace views { | 69 namespace views { |
| 69 | 70 |
| 70 DEFINE_UI_CLASS_PROPERTY_KEY(DesktopNativeWidgetAura*, | 71 DEFINE_UI_CLASS_PROPERTY_KEY(DesktopNativeWidgetAura*, |
| 71 kDesktopNativeWidgetAuraKey, NULL); | 72 kDesktopNativeWidgetAuraKey, NULL); |
| 72 | 73 |
| 73 namespace { | 74 namespace { |
| 74 | 75 |
| 76 // Returns true if |widget| has modal transient child, otherwise false. | |
| 77 bool HasModalTransientChild(const Widget* widget) { | |
| 78 DCHECK(widget); | |
| 79 for (auto* window : ::wm::GetTransientChildren(widget->GetNativeView())) { | |
| 80 ui::ModalType type = Widget::GetWidgetForNativeView(window) | |
|
sky
2017/06/02 17:34:10
Are you sure you don't want GetModalTransient(widg
Qiang(Joe) Xu
2017/06/02 21:37:08
I should use this. Thanks!
| |
| 81 ->widget_delegate() | |
| 82 ->GetModalType(); | |
| 83 if (type == ui::MODAL_TYPE_SYSTEM || type == ui::MODAL_TYPE_WINDOW) | |
| 84 return true; | |
| 85 } | |
| 86 return false; | |
| 87 } | |
| 88 | |
| 75 // This class provides functionality to create a top level widget to host a | 89 // This class provides functionality to create a top level widget to host a |
| 76 // child window. | 90 // child window. |
| 77 class DesktopNativeWidgetTopLevelHandler : public aura::WindowObserver { | 91 class DesktopNativeWidgetTopLevelHandler : public aura::WindowObserver { |
| 78 public: | 92 public: |
| 79 // This function creates a widget with the bounds passed in which eventually | 93 // This function creates a widget with the bounds passed in which eventually |
| 80 // becomes the parent of the child window passed in. | 94 // becomes the parent of the child window passed in. |
| 81 static aura::Window* CreateParentWindow(aura::Window* child_window, | 95 static aura::Window* CreateParentWindow(aura::Window* child_window, |
| 82 const gfx::Rect& bounds, | 96 const gfx::Rect& bounds, |
| 83 bool full_screen, | 97 bool full_screen, |
| 84 bool root_is_always_on_top) { | 98 bool root_is_always_on_top) { |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 357 // This function can be called before the focus manager has had a | 371 // This function can be called before the focus manager has had a |
| 358 // chance to set the focused view. In which case we should get the | 372 // chance to set the focused view. In which case we should get the |
| 359 // last focused view. | 373 // last focused view. |
| 360 views::FocusManager* focus_manager = GetWidget()->GetFocusManager(); | 374 views::FocusManager* focus_manager = GetWidget()->GetFocusManager(); |
| 361 View* view_for_activation = focus_manager->GetFocusedView() | 375 View* view_for_activation = focus_manager->GetFocusedView() |
| 362 ? focus_manager->GetFocusedView() | 376 ? focus_manager->GetFocusedView() |
| 363 : focus_manager->GetStoredFocusView(); | 377 : focus_manager->GetStoredFocusView(); |
| 364 if (!view_for_activation) { | 378 if (!view_for_activation) { |
| 365 view_for_activation = GetWidget()->GetRootView(); | 379 view_for_activation = GetWidget()->GetRootView(); |
| 366 } else if (view_for_activation == focus_manager->GetStoredFocusView()) { | 380 } else if (view_for_activation == focus_manager->GetStoredFocusView()) { |
| 367 focus_manager->RestoreFocusedView(); | 381 // The desktop native widget may have modal transient child, whose focus |
|
sky
2017/06/02 17:34:10
This just documents the code, the interesting part
Qiang(Joe) Xu
2017/06/02 21:37:08
Done.
| |
| 368 // Set to false if desktop native widget has activated activation | 382 // is not managed by |focus_manager|. We shall restore focus to modal |
| 369 // change, so that aura window activation change focus restore operation | 383 // window only in this case (crbug.com/727641). |
| 370 // can be ignored. | 384 if (!HasModalTransientChild(GetWidget())) { |
| 371 restore_focus_on_activate_ = false; | 385 focus_manager->RestoreFocusedView(); |
| 386 // Set to false if desktop native widget has activated activation | |
| 387 // change, so that aura window activation change focus restore | |
| 388 // operation can be ignored. | |
| 389 restore_focus_on_activate_ = false; | |
| 390 } | |
| 372 } | 391 } |
| 373 activation_client->ActivateWindow( | 392 activation_client->ActivateWindow( |
| 374 view_for_activation->GetWidget()->GetNativeView()); | 393 view_for_activation->GetWidget()->GetNativeView()); |
| 375 // Refreshes the focus info to IMF in case that IMF cached the old info | 394 // Refreshes the focus info to IMF in case that IMF cached the old info |
| 376 // about focused text input client when it was "inactive". | 395 // about focused text input client when it was "inactive". |
| 377 GetInputMethod()->OnFocus(); | 396 GetInputMethod()->OnFocus(); |
| 378 } | 397 } |
| 379 } else { | 398 } else { |
| 380 // If we're not active we need to deactivate the corresponding | 399 // If we're not active we need to deactivate the corresponding |
| 381 // aura::Window. This way if a child widget is active it gets correctly | 400 // aura::Window. This way if a child widget is active it gets correctly |
| (...skipping 823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1205 if (cursor_reference_count_ == 0) { | 1224 if (cursor_reference_count_ == 0) { |
| 1206 // We are the last DesktopNativeWidgetAura instance, and we are responsible | 1225 // We are the last DesktopNativeWidgetAura instance, and we are responsible |
| 1207 // for cleaning up |cursor_manager_|. | 1226 // for cleaning up |cursor_manager_|. |
| 1208 delete cursor_manager_; | 1227 delete cursor_manager_; |
| 1209 native_cursor_manager_ = NULL; | 1228 native_cursor_manager_ = NULL; |
| 1210 cursor_manager_ = NULL; | 1229 cursor_manager_ = NULL; |
| 1211 } | 1230 } |
| 1212 } | 1231 } |
| 1213 | 1232 |
| 1214 } // namespace views | 1233 } // namespace views |
| OLD | NEW |