123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- // Copyright 2016 The Chromium Authors. All rights reserved.
- // Use of this source code is governed by a BSD-style license that can be
- // found in the LICENSE file.
- #include "ash/wm/fullscreen_window_finder.h"
- #include "ash/public/cpp/shell_window_ids.h"
- #include "ash/wm/desks/desks_util.h"
- #include "ash/wm/switchable_windows.h"
- #include "ash/wm/window_state.h"
- #include "ash/wm/window_util.h"
- #include "base/containers/adapters.h"
- #include "ui/aura/window.h"
- #include "ui/compositor/layer.h"
- #include "ui/wm/core/window_util.h"
- namespace ash {
- namespace {
- // Gets the parent switchable container of |context|.
- aura::Window* GetSwitchableContainerForContext(aura::Window* context) {
- while (context && !IsSwitchableContainer(context))
- context = context->parent();
- return context;
- }
- // Returns the active window if it is a child of a switchable container, or
- // nullptr otherwise.
- aura::Window* GetActiveWindowInSwitchableContainer() {
- aura::Window* active_window = window_util::GetActiveWindow();
- if (!active_window || !IsSwitchableContainer(active_window->parent()))
- return nullptr;
- return active_window;
- }
- // Given |container|, returns its topmost visible and positionable child.
- aura::Window* GetTopMostWindowInContainer(aura::Window* container) {
- DCHECK(container);
- DCHECK(IsSwitchableContainer(container));
- for (auto* child : base::Reversed(container->children())) {
- // `child` may be type `aura::client::WINDOW_TYPE_CONTROL` which has no
- // WindowState.
- if (WindowState::Get(child) &&
- WindowState::Get(child)->IsUserPositionable() &&
- child->layer()->GetTargetVisibility()) {
- return child;
- }
- }
- return nullptr;
- }
- // Given a |topmost_window|, returns it or one of its transient parents if the
- // returned window is fullscreen or pinned. Otherwise, return nullptr.
- aura::Window* FindFullscreenOrPinnedWindow(aura::Window* topmost_window) {
- while (topmost_window) {
- const WindowState* window_state = WindowState::Get(topmost_window);
- if (window_state->IsFullscreen() || window_state->IsPinned())
- return topmost_window;
- topmost_window = ::wm::GetTransientParent(topmost_window);
- if (topmost_window)
- topmost_window = topmost_window->GetToplevelWindow();
- }
- return nullptr;
- }
- } // namespace
- aura::Window* GetWindowForFullscreenModeForContext(aura::Window* context) {
- DCHECK(!context->IsRootWindow());
- // Get the active window on the same switchable container as that of
- // |context| if any.
- aura::Window* switchable_container_for_context =
- GetSwitchableContainerForContext(context);
- aura::Window* topmost_window = GetActiveWindowInSwitchableContainer();
- if (!topmost_window || (switchable_container_for_context !=
- GetSwitchableContainerForContext(topmost_window))) {
- if (!switchable_container_for_context)
- return nullptr;
- // If there's no active window, then get the topmost child on the switchable
- // container of context.
- topmost_window =
- GetTopMostWindowInContainer(switchable_container_for_context);
- }
- return FindFullscreenOrPinnedWindow(topmost_window);
- }
- aura::Window* GetWindowForFullscreenModeInRoot(aura::Window* root) {
- DCHECK(root->IsRootWindow());
- // Get the active window on the same |root| if any.
- aura::Window* topmost_window = GetActiveWindowInSwitchableContainer();
- if (!topmost_window || topmost_window->GetRootWindow() != root) {
- // If there's no active window, then get the top most child of the active
- // desk container.
- topmost_window = GetTopMostWindowInContainer(
- desks_util::GetActiveDeskContainerForRoot(root));
- }
- return FindFullscreenOrPinnedWindow(topmost_window);
- }
- } // namespace ash
|