Commit 0fbb8cde authored by sky's avatar sky Committed by Commit bot

Moves definitions of RootWindowController into root_window_controller.cc

As part of this I made sure the definitions and declarations matched
up. This resulted in reordering a couple of things. In addition the
only other non-move I did was moving what was CreateLayoutManagers()
into InitLayoutManagers() and CloseChildWindowsImpl() into
CloseChildWindows().

BUG=671246
TEST=none
R=jamescook@chromium.org

Review-Url: https://codereview.chromium.org/2628973002
Cr-Original-Commit-Position: refs/heads/master@{#443109}
Committed: https://chromium.googlesource.com/chromium/src/+/d20a89e7b56ad53a58f19edf4775528d066577d5
Review-Url: https://codereview.chromium.org/2628973002
Cr-Commit-Position: refs/heads/master@{#443166}
parent 904b7a6f
......@@ -595,7 +595,6 @@ component("ash") {
"common/wm_layout_manager.h",
"common/wm_lookup.cc",
"common/wm_lookup.h",
"common/wm_root_window_controller.cc",
"common/wm_shell.cc",
"common/wm_shell.h",
"common/wm_transient_window_observer.h",
......
// 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/root_window_controller.h"
#include "ash/aura/wm_window_aura.h"
#include "ash/common/session/session_state_delegate.h"
#include "ash/common/shelf/shelf_layout_manager.h"
#include "ash/common/shelf/shelf_widget.h"
#include "ash/common/shelf/wm_shelf.h"
#include "ash/common/shell_delegate.h"
#include "ash/common/system/status_area_widget.h"
#include "ash/common/wallpaper/wallpaper_delegate.h"
#include "ash/common/wallpaper/wallpaper_widget_controller.h"
#include "ash/common/wm/always_on_top_controller.h"
#include "ash/common/wm/container_finder.h"
#include "ash/common/wm/dock/docked_window_layout_manager.h"
#include "ash/common/wm/lock_layout_manager.h"
#include "ash/common/wm/panels/panel_layout_manager.h"
#include "ash/common/wm/root_window_layout_manager.h"
#include "ash/common/wm/system_modal_container_layout_manager.h"
#include "ash/common/wm/window_state.h"
#include "ash/common/wm/wm_snap_to_pixel_layout_manager.h"
#include "ash/common/wm/workspace/workspace_layout_manager.h"
#include "ash/common/wm/workspace_controller.h"
#include "ash/common/wm_shell.h"
#include "ash/common/wm_window.h"
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/root_window_controller.h"
#include "ash/shell.h"
#include "base/memory/ptr_util.h"
#include "ui/aura/env.h"
#include "ui/aura/mus/window_mus.h"
#include "ui/aura/mus/window_tree_client.h"
#include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/aura/window_tree_host.h"
#include "ui/base/models/menu_model.h"
#include "ui/events/event_targeter.h"
#include "ui/events/event_utils.h"
#include "ui/views/controls/menu/menu_model_adapter.h"
#include "ui/views/controls/menu/menu_runner.h"
#include "ui/wm/core/coordinate_conversion.h"
// TODO(sky): this file is temporary and here to make review easier. The
// contents of this file will be folded into root_window_controller.cc shortly.
namespace ash {
namespace {
// Scales |value| that is originally between 0 and |src_max| to be between
// 0 and |dst_max|.
float ToRelativeValue(int value, int src_max, int dst_max) {
return static_cast<float>(value) / static_cast<float>(src_max) * dst_max;
}
// Uses ToRelativeValue() to scale the origin of |bounds_in_out|. The
// width/height are not changed.
void MoveOriginRelativeToSize(const gfx::Size& src_size,
const gfx::Size& dst_size,
gfx::Rect* bounds_in_out) {
gfx::Point origin = bounds_in_out->origin();
bounds_in_out->set_origin(gfx::Point(
ToRelativeValue(origin.x(), src_size.width(), dst_size.width()),
ToRelativeValue(origin.y(), src_size.height(), dst_size.height())));
}
// Reparents |window| to |new_parent|.
// TODO(sky): This should take an aura::Window. http://crbug.com/671246.
void ReparentWindow(WmWindow* window, WmWindow* new_parent) {
const gfx::Size src_size = window->GetParent()->GetBounds().size();
const gfx::Size dst_size = new_parent->GetBounds().size();
// Update the restore bounds to make it relative to the display.
wm::WindowState* state = window->GetWindowState();
gfx::Rect restore_bounds;
bool has_restore_bounds = state->HasRestoreBounds();
bool update_bounds =
(state->IsNormalOrSnapped() || state->IsMinimized()) &&
new_parent->GetShellWindowId() != kShellWindowId_DockedContainer;
gfx::Rect local_bounds;
if (update_bounds) {
local_bounds = state->window()->GetBounds();
MoveOriginRelativeToSize(src_size, dst_size, &local_bounds);
}
if (has_restore_bounds) {
restore_bounds = state->GetRestoreBoundsInParent();
MoveOriginRelativeToSize(src_size, dst_size, &restore_bounds);
}
new_parent->AddChild(window);
// Docked windows have bounds handled by the layout manager in AddChild().
if (update_bounds)
window->SetBounds(local_bounds);
if (has_restore_bounds)
state->SetRestoreBoundsInParent(restore_bounds);
}
// Reparents the appropriate set of windows from |src| to |dst|.
// TODO(sky): This should take an aura::Window. http://crbug.com/671246.
void ReparentAllWindows(WmWindow* src, WmWindow* dst) {
// Set of windows to move.
const int kContainerIdsToMove[] = {
kShellWindowId_DefaultContainer,
kShellWindowId_DockedContainer,
kShellWindowId_PanelContainer,
kShellWindowId_AlwaysOnTopContainer,
kShellWindowId_SystemModalContainer,
kShellWindowId_LockSystemModalContainer,
kShellWindowId_UnparentedControlContainer,
kShellWindowId_OverlayContainer,
};
const int kExtraContainerIdsToMoveInUnifiedMode[] = {
kShellWindowId_LockScreenContainer,
kShellWindowId_LockScreenWallpaperContainer,
};
std::vector<int> container_ids(
kContainerIdsToMove,
kContainerIdsToMove + arraysize(kContainerIdsToMove));
// Check the display mode as this is also necessary when trasitioning between
// mirror and unified mode.
if (WmShell::Get()->IsInUnifiedModeIgnoreMirroring()) {
for (int id : kExtraContainerIdsToMoveInUnifiedMode)
container_ids.push_back(id);
}
for (int id : container_ids) {
WmWindow* src_container = src->GetChildByShellWindowId(id);
WmWindow* dst_container = dst->GetChildByShellWindowId(id);
while (!src_container->GetChildren().empty()) {
// Restart iteration from the source container windows each time as they
// may change as a result of moving other windows.
WmWindow::Windows src_container_children = src_container->GetChildren();
WmWindow::Windows::const_iterator iter = src_container_children.begin();
while (iter != src_container_children.end() &&
SystemModalContainerLayoutManager::IsModalBackground(*iter)) {
++iter;
}
// If the entire window list is modal background windows then stop.
if (iter == src_container_children.end())
break;
ReparentWindow(*iter, dst_container);
}
}
}
// Creates a new window for use as a container.
// TODO(sky): This should create an aura::Window. http://crbug.com/671246.
WmWindow* CreateContainer(int window_id, const char* name, WmWindow* parent) {
WmWindow* window = WmShell::Get()->NewWindow(ui::wm::WINDOW_TYPE_UNKNOWN,
ui::LAYER_NOT_DRAWN);
window->SetShellWindowId(window_id);
window->SetName(name);
parent->AddChild(window);
if (window_id != kShellWindowId_UnparentedControlContainer)
window->Show();
return window;
}
// TODO(sky): This should take an aura::Window. http://crbug.com/671246.
bool ShouldDestroyWindowInCloseChildWindows(WmWindow* window) {
if (!WmWindowAura::GetAuraWindow(window)->owned_by_parent())
return false;
if (!WmShell::Get()->IsRunningInMash())
return true;
aura::WindowMus* window_mus =
aura::WindowMus::Get(WmWindowAura::GetAuraWindow(window));
return Shell::window_tree_client()->WasCreatedByThisClient(window_mus) ||
Shell::window_tree_client()->IsRoot(window_mus);
}
} // namespace
void RootWindowController::SetWallpaperWidgetController(
WallpaperWidgetController* controller) {
wallpaper_widget_controller_.reset(controller);
}
void RootWindowController::SetAnimatingWallpaperWidgetController(
AnimatingWallpaperWidgetController* controller) {
if (animating_wallpaper_widget_controller_.get())
animating_wallpaper_widget_controller_->StopAnimating();
animating_wallpaper_widget_controller_.reset(controller);
}
wm::WorkspaceWindowState RootWindowController::GetWorkspaceWindowState() {
return workspace_controller_ ? workspace_controller()->GetWindowState()
: wm::WORKSPACE_WINDOW_STATE_DEFAULT;
}
SystemModalContainerLayoutManager*
RootWindowController::GetSystemModalLayoutManager(WmWindow* window) {
WmWindow* modal_container = nullptr;
if (window) {
WmWindow* window_container = wm::GetContainerForWindow(window);
if (window_container &&
window_container->GetShellWindowId() >=
kShellWindowId_LockScreenContainer) {
modal_container = GetWmContainer(kShellWindowId_LockSystemModalContainer);
} else {
modal_container = GetWmContainer(kShellWindowId_SystemModalContainer);
}
} else {
int modal_window_id =
WmShell::Get()->GetSessionStateDelegate()->IsUserSessionBlocked()
? kShellWindowId_LockSystemModalContainer
: kShellWindowId_SystemModalContainer;
modal_container = GetWmContainer(modal_window_id);
}
return modal_container ? static_cast<SystemModalContainerLayoutManager*>(
modal_container->GetLayoutManager())
: nullptr;
}
bool RootWindowController::HasShelf() {
return wm_shelf_->shelf_widget() != nullptr;
}
WmShelf* RootWindowController::GetShelf() {
return wm_shelf_.get();
}
void RootWindowController::CreateShelf() {
if (wm_shelf_->IsShelfInitialized())
return;
wm_shelf_->InitializeShelf();
if (panel_layout_manager_)
panel_layout_manager_->SetShelf(wm_shelf_.get());
if (docked_window_layout_manager_) {
docked_window_layout_manager_->SetShelf(wm_shelf_.get());
if (wm_shelf_->shelf_layout_manager())
docked_window_layout_manager_->AddObserver(
wm_shelf_->shelf_layout_manager());
}
// Notify shell observers that the shelf has been created.
// TODO(jamescook): Move this into WmShelf::InitializeShelf(). This will
// require changing AttachedPanelWidgetTargeter's access to WmShelf.
WmShell::Get()->NotifyShelfCreatedForRootWindow(
WmWindowAura::Get(GetRootWindow()));
wm_shelf_->shelf_widget()->PostCreateShelf();
}
void RootWindowController::ShowShelf() {
if (!wm_shelf_->IsShelfInitialized())
return;
// TODO(jamescook): Move this into WmShelf.
wm_shelf_->shelf_widget()->SetShelfVisibility(true);
wm_shelf_->shelf_widget()->status_area_widget()->Show();
}
const WmWindow* RootWindowController::GetWindow() const {
return WmWindowAura::Get(GetRootWindow());
}
const WmWindow* RootWindowController::GetWmContainer(int container_id) const {
const aura::Window* window = GetContainer(container_id);
return WmWindowAura::Get(window);
}
void RootWindowController::ConfigureWidgetInitParamsForContainer(
views::Widget* widget,
int shell_container_id,
views::Widget::InitParams* init_params) {
init_params->parent = GetContainer(shell_container_id);
}
WmWindow* RootWindowController::FindEventTarget(
const gfx::Point& location_in_screen) {
gfx::Point location_in_root(location_in_screen);
aura::Window* root_window = GetRootWindow();
::wm::ConvertPointFromScreen(root_window, &location_in_root);
ui::MouseEvent test_event(ui::ET_MOUSE_MOVED, location_in_root,
location_in_root, ui::EventTimeForNow(),
ui::EF_NONE, ui::EF_NONE);
ui::EventTarget* event_handler =
static_cast<ui::EventTarget*>(root_window)
->GetEventTargeter()
->FindTargetForEvent(root_window, &test_event);
return WmWindowAura::Get(static_cast<aura::Window*>(event_handler));
}
gfx::Point RootWindowController::GetLastMouseLocationInRoot() {
return window_tree_host_->dispatcher()->GetLastMouseLocationInRoot();
}
void RootWindowController::ShowContextMenu(const gfx::Point& location_in_screen,
ui::MenuSourceType source_type) {
ShellDelegate* delegate = WmShell::Get()->delegate();
DCHECK(delegate);
menu_model_.reset(delegate->CreateContextMenu(wm_shelf_.get(), nullptr));
if (!menu_model_)
return;
menu_model_adapter_ = base::MakeUnique<views::MenuModelAdapter>(
menu_model_.get(),
base::Bind(&RootWindowController::OnMenuClosed, base::Unretained(this)));
// The wallpaper controller may not be set yet if the user clicked on the
// status area before the initial animation completion. See crbug.com/222218
if (!wallpaper_widget_controller())
return;
menu_runner_ = base::MakeUnique<views::MenuRunner>(
menu_model_adapter_->CreateMenu(),
views::MenuRunner::CONTEXT_MENU | views::MenuRunner::ASYNC);
ignore_result(
menu_runner_->RunMenuAt(wallpaper_widget_controller()->widget(), nullptr,
gfx::Rect(location_in_screen, gfx::Size()),
views::MENU_ANCHOR_TOPLEFT, source_type));
}
void RootWindowController::UpdateAfterLoginStatusChange(LoginStatus status) {
StatusAreaWidget* status_area_widget =
wm_shelf_->shelf_widget()->status_area_widget();
if (status_area_widget)
status_area_widget->UpdateAfterLoginStatusChange(status);
}
void RootWindowController::MoveWindowsTo(aura::Window* dst) {
// Clear the workspace controller, so it doesn't incorrectly update the shelf.
workspace_controller_.reset();
ReparentAllWindows(GetWindow(), WmWindowAura::Get(dst));
}
void RootWindowController::CreateContainers() {
WmWindow* root = GetWindow();
// These containers are just used by PowerButtonController to animate groups
// of containers simultaneously without messing up the current transformations
// on those containers. These are direct children of the root window; all of
// the other containers are their children.
// The wallpaper container is not part of the lock animation, so it is not
// included in those animate groups. When the screen is locked, the wallpaper
// is moved to the lock screen wallpaper container (and moved back on unlock).
// Ensure that there's an opaque layer occluding the non-lock-screen layers.
WmWindow* wallpaper_container = CreateContainer(
kShellWindowId_WallpaperContainer, "WallpaperContainer", root);
wallpaper_container->SetChildWindowVisibilityChangesAnimated();
WmWindow* non_lock_screen_containers =
CreateContainer(kShellWindowId_NonLockScreenContainersContainer,
"NonLockScreenContainersContainer", root);
// Clip all windows inside this container, as half pixel of the window's
// texture may become visible when the screen is scaled. crbug.com/368591.
non_lock_screen_containers->SetMasksToBounds(true);
WmWindow* lock_wallpaper_containers =
CreateContainer(kShellWindowId_LockScreenWallpaperContainer,
"LockScreenWallpaperContainer", root);
lock_wallpaper_containers->SetChildWindowVisibilityChangesAnimated();
WmWindow* lock_screen_containers =
CreateContainer(kShellWindowId_LockScreenContainersContainer,
"LockScreenContainersContainer", root);
WmWindow* lock_screen_related_containers =
CreateContainer(kShellWindowId_LockScreenRelatedContainersContainer,
"LockScreenRelatedContainersContainer", root);
CreateContainer(kShellWindowId_UnparentedControlContainer,
"UnparentedControlContainer", non_lock_screen_containers);
WmWindow* default_container =
CreateContainer(kShellWindowId_DefaultContainer, "DefaultContainer",
non_lock_screen_containers);
default_container->SetChildWindowVisibilityChangesAnimated();
default_container->SetSnapsChildrenToPhysicalPixelBoundary();
default_container->SetBoundsInScreenBehaviorForChildren(
WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES);
default_container->SetChildrenUseExtendedHitRegion();
WmWindow* always_on_top_container =
CreateContainer(kShellWindowId_AlwaysOnTopContainer,
"AlwaysOnTopContainer", non_lock_screen_containers);
always_on_top_container->SetChildWindowVisibilityChangesAnimated();
always_on_top_container->SetSnapsChildrenToPhysicalPixelBoundary();
always_on_top_container->SetBoundsInScreenBehaviorForChildren(
WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES);
WmWindow* docked_container =
CreateContainer(kShellWindowId_DockedContainer, "DockedContainer",
non_lock_screen_containers);
docked_container->SetChildWindowVisibilityChangesAnimated();
docked_container->SetSnapsChildrenToPhysicalPixelBoundary();
docked_container->SetBoundsInScreenBehaviorForChildren(
WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES);
docked_container->SetChildrenUseExtendedHitRegion();
WmWindow* shelf_container =
CreateContainer(kShellWindowId_ShelfContainer, "ShelfContainer",
non_lock_screen_containers);
shelf_container->SetSnapsChildrenToPhysicalPixelBoundary();
shelf_container->SetBoundsInScreenBehaviorForChildren(
WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES);
shelf_container->SetLockedToRoot(true);
WmWindow* panel_container =
CreateContainer(kShellWindowId_PanelContainer, "PanelContainer",
non_lock_screen_containers);
panel_container->SetSnapsChildrenToPhysicalPixelBoundary();
panel_container->SetBoundsInScreenBehaviorForChildren(
WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES);
WmWindow* shelf_bubble_container =
CreateContainer(kShellWindowId_ShelfBubbleContainer,
"ShelfBubbleContainer", non_lock_screen_containers);
shelf_bubble_container->SetSnapsChildrenToPhysicalPixelBoundary();
shelf_bubble_container->SetBoundsInScreenBehaviorForChildren(
WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES);
shelf_bubble_container->SetLockedToRoot(true);
WmWindow* app_list_container =
CreateContainer(kShellWindowId_AppListContainer, "AppListContainer",
non_lock_screen_containers);
app_list_container->SetSnapsChildrenToPhysicalPixelBoundary();
app_list_container->SetBoundsInScreenBehaviorForChildren(
WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES);
WmWindow* modal_container =
CreateContainer(kShellWindowId_SystemModalContainer,
"SystemModalContainer", non_lock_screen_containers);
modal_container->SetSnapsChildrenToPhysicalPixelBoundary();
modal_container->SetChildWindowVisibilityChangesAnimated();
modal_container->SetBoundsInScreenBehaviorForChildren(
WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES);
modal_container->SetChildrenUseExtendedHitRegion();
// TODO(beng): Figure out if we can make this use
// SystemModalContainerEventFilter instead of stops_event_propagation.
WmWindow* lock_container =
CreateContainer(kShellWindowId_LockScreenContainer, "LockScreenContainer",
lock_screen_containers);
lock_container->SetSnapsChildrenToPhysicalPixelBoundary();
lock_container->SetBoundsInScreenBehaviorForChildren(
WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES);
// TODO(beng): stopsevents
WmWindow* lock_modal_container =
CreateContainer(kShellWindowId_LockSystemModalContainer,
"LockSystemModalContainer", lock_screen_containers);
lock_modal_container->SetSnapsChildrenToPhysicalPixelBoundary();
lock_modal_container->SetChildWindowVisibilityChangesAnimated();
lock_modal_container->SetBoundsInScreenBehaviorForChildren(
WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES);
lock_modal_container->SetChildrenUseExtendedHitRegion();
WmWindow* status_container =
CreateContainer(kShellWindowId_StatusContainer, "StatusContainer",
lock_screen_related_containers);
status_container->SetSnapsChildrenToPhysicalPixelBoundary();
status_container->SetBoundsInScreenBehaviorForChildren(
WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES);
status_container->SetLockedToRoot(true);
WmWindow* settings_bubble_container =
CreateContainer(kShellWindowId_SettingBubbleContainer,
"SettingBubbleContainer", lock_screen_related_containers);
settings_bubble_container->SetChildWindowVisibilityChangesAnimated();
settings_bubble_container->SetSnapsChildrenToPhysicalPixelBoundary();
settings_bubble_container->SetBoundsInScreenBehaviorForChildren(
WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES);
settings_bubble_container->SetLockedToRoot(true);
WmWindow* virtual_keyboard_parent_container = CreateContainer(
kShellWindowId_ImeWindowParentContainer, "VirtualKeyboardParentContainer",
lock_screen_related_containers);
virtual_keyboard_parent_container->SetSnapsChildrenToPhysicalPixelBoundary();
virtual_keyboard_parent_container->SetBoundsInScreenBehaviorForChildren(
WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES);
WmWindow* menu_container =
CreateContainer(kShellWindowId_MenuContainer, "MenuContainer",
lock_screen_related_containers);
menu_container->SetChildWindowVisibilityChangesAnimated();
menu_container->SetSnapsChildrenToPhysicalPixelBoundary();
menu_container->SetBoundsInScreenBehaviorForChildren(
WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES);
WmWindow* drag_drop_container = CreateContainer(
kShellWindowId_DragImageAndTooltipContainer,
"DragImageAndTooltipContainer", lock_screen_related_containers);
drag_drop_container->SetChildWindowVisibilityChangesAnimated();
drag_drop_container->SetSnapsChildrenToPhysicalPixelBoundary();
drag_drop_container->SetBoundsInScreenBehaviorForChildren(
WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES);
WmWindow* overlay_container =
CreateContainer(kShellWindowId_OverlayContainer, "OverlayContainer",
lock_screen_related_containers);
overlay_container->SetSnapsChildrenToPhysicalPixelBoundary();
overlay_container->SetBoundsInScreenBehaviorForChildren(
WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES);
WmWindow* mouse_cursor_container = CreateContainer(
kShellWindowId_MouseCursorContainer, "MouseCursorContainer", root);
mouse_cursor_container->SetBoundsInScreenBehaviorForChildren(
WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES);
CreateContainer(kShellWindowId_PowerButtonAnimationContainer,
"PowerButtonAnimationContainer", root);
}
void RootWindowController::CreateLayoutManagers() {
GetShelf()->CreateShelfWidget(GetWindow());
WmWindow* root = GetWindow();
root_window_layout_manager_ = new wm::RootWindowLayoutManager(root);
root->SetLayoutManager(base::WrapUnique(root_window_layout_manager_));
WmWindow* default_container = GetWmContainer(kShellWindowId_DefaultContainer);
// Installs WorkspaceLayoutManager on |default_container|.
workspace_controller_.reset(new WorkspaceController(default_container));
WmWindow* modal_container =
GetWmContainer(kShellWindowId_SystemModalContainer);
DCHECK(modal_container);
modal_container->SetLayoutManager(
base::MakeUnique<SystemModalContainerLayoutManager>(modal_container));
WmWindow* lock_modal_container =
GetWmContainer(kShellWindowId_LockSystemModalContainer);
DCHECK(lock_modal_container);
lock_modal_container->SetLayoutManager(
base::MakeUnique<SystemModalContainerLayoutManager>(
lock_modal_container));
WmWindow* lock_container = GetWmContainer(kShellWindowId_LockScreenContainer);
DCHECK(lock_container);
lock_container->SetLayoutManager(
base::MakeUnique<LockLayoutManager>(lock_container));
WmWindow* always_on_top_container =
GetWmContainer(kShellWindowId_AlwaysOnTopContainer);
DCHECK(always_on_top_container);
always_on_top_controller_ =
base::MakeUnique<AlwaysOnTopController>(always_on_top_container);
// Create Docked windows layout manager
WmWindow* docked_container = GetWmContainer(kShellWindowId_DockedContainer);
docked_window_layout_manager_ =
new DockedWindowLayoutManager(docked_container);
docked_container->SetLayoutManager(
base::WrapUnique(docked_window_layout_manager_));
// Create Panel layout manager
WmWindow* panel_container = GetWmContainer(kShellWindowId_PanelContainer);
panel_layout_manager_ = new PanelLayoutManager(panel_container);
panel_container->SetLayoutManager(base::WrapUnique(panel_layout_manager_));
wm::WmSnapToPixelLayoutManager::InstallOnContainers(root);
}
void RootWindowController::ResetRootForNewWindowsIfNecessary() {
WmShell* shell = WmShell::Get();
// Change the target root window before closing child windows. If any child
// being removed triggers a relayout of the shelf it will try to build a
// window list adding windows from the target root window's containers which
// may have already gone away.
WmWindow* root = GetWindow();
if (shell->GetRootWindowForNewWindows() == root) {
// The root window for new windows is being destroyed. Switch to the primary
// root window if possible.
WmWindow* primary_root = shell->GetPrimaryRootWindow();
shell->set_root_window_for_new_windows(primary_root == root ? nullptr
: primary_root);
}
}
// TODO(sky): fold into CloseChildWindows() when move back.
void RootWindowController::CloseChildWindowsImpl() {
// NOTE: this may be called multiple times.
// |panel_layout_manager_| needs to be shut down before windows are destroyed.
if (panel_layout_manager_) {
panel_layout_manager_->Shutdown();
panel_layout_manager_ = nullptr;
}
// |docked_window_layout_manager_| needs to be shut down before windows are
// destroyed.
if (docked_window_layout_manager_) {
docked_window_layout_manager_->Shutdown();
docked_window_layout_manager_ = nullptr;
}
WmShelf* shelf = GetShelf();
shelf->ShutdownShelfWidget();
workspace_controller_.reset();
// Explicitly destroy top level windows. We do this because such windows may
// query the RootWindow for state.
WmWindowTracker non_toplevel_windows;
WmWindow* root = GetWindow();
non_toplevel_windows.Add(root);
while (!non_toplevel_windows.windows().empty()) {
WmWindow* non_toplevel_window = non_toplevel_windows.Pop();
WmWindowTracker toplevel_windows;
for (WmWindow* child : non_toplevel_window->GetChildren()) {
if (!ShouldDestroyWindowInCloseChildWindows(child))
continue;
if (child->HasNonClientArea())
toplevel_windows.Add(child);
else
non_toplevel_windows.Add(child);
}
while (!toplevel_windows.windows().empty())
toplevel_windows.Pop()->Destroy();
}
// And then remove the containers.
while (!root->GetChildren().empty()) {
WmWindow* child = root->GetChildren()[0];
if (ShouldDestroyWindowInCloseChildWindows(child))
child->Destroy();
else
root->RemoveChild(child);
}
shelf->DestroyShelfWidget();
// CloseChildWindows() may be called twice during the shutdown of ash
// unittests. Avoid notifying WmShelf that the shelf has been destroyed twice.
if (shelf->IsShelfInitialized())
shelf->ShutdownShelf();
}
void RootWindowController::OnMenuClosed() {
menu_runner_.reset();
menu_model_adapter_.reset();
menu_model_.reset();
wm_shelf_->UpdateVisibilityState();
}
} // namespace ash
......@@ -144,6 +144,132 @@ bool IsWindowAboveContainer(aura::Window* window,
return true;
}
// Scales |value| that is originally between 0 and |src_max| to be between
// 0 and |dst_max|.
float ToRelativeValue(int value, int src_max, int dst_max) {
return static_cast<float>(value) / static_cast<float>(src_max) * dst_max;
}
// Uses ToRelativeValue() to scale the origin of |bounds_in_out|. The
// width/height are not changed.
void MoveOriginRelativeToSize(const gfx::Size& src_size,
const gfx::Size& dst_size,
gfx::Rect* bounds_in_out) {
gfx::Point origin = bounds_in_out->origin();
bounds_in_out->set_origin(gfx::Point(
ToRelativeValue(origin.x(), src_size.width(), dst_size.width()),
ToRelativeValue(origin.y(), src_size.height(), dst_size.height())));
}
// Reparents |window| to |new_parent|.
// TODO(sky): This should take an aura::Window. http://crbug.com/671246.
void ReparentWindow(WmWindow* window, WmWindow* new_parent) {
const gfx::Size src_size = window->GetParent()->GetBounds().size();
const gfx::Size dst_size = new_parent->GetBounds().size();
// Update the restore bounds to make it relative to the display.
wm::WindowState* state = window->GetWindowState();
gfx::Rect restore_bounds;
bool has_restore_bounds = state->HasRestoreBounds();
bool update_bounds =
(state->IsNormalOrSnapped() || state->IsMinimized()) &&
new_parent->GetShellWindowId() != kShellWindowId_DockedContainer;
gfx::Rect local_bounds;
if (update_bounds) {
local_bounds = state->window()->GetBounds();
MoveOriginRelativeToSize(src_size, dst_size, &local_bounds);
}
if (has_restore_bounds) {
restore_bounds = state->GetRestoreBoundsInParent();
MoveOriginRelativeToSize(src_size, dst_size, &restore_bounds);
}
new_parent->AddChild(window);
// Docked windows have bounds handled by the layout manager in AddChild().
if (update_bounds)
window->SetBounds(local_bounds);
if (has_restore_bounds)
state->SetRestoreBoundsInParent(restore_bounds);
}
// Reparents the appropriate set of windows from |src| to |dst|.
// TODO(sky): This should take an aura::Window. http://crbug.com/671246.
void ReparentAllWindows(WmWindow* src, WmWindow* dst) {
// Set of windows to move.
const int kContainerIdsToMove[] = {
kShellWindowId_DefaultContainer,
kShellWindowId_DockedContainer,
kShellWindowId_PanelContainer,
kShellWindowId_AlwaysOnTopContainer,
kShellWindowId_SystemModalContainer,
kShellWindowId_LockSystemModalContainer,
kShellWindowId_UnparentedControlContainer,
kShellWindowId_OverlayContainer,
};
const int kExtraContainerIdsToMoveInUnifiedMode[] = {
kShellWindowId_LockScreenContainer,
kShellWindowId_LockScreenWallpaperContainer,
};
std::vector<int> container_ids(
kContainerIdsToMove,
kContainerIdsToMove + arraysize(kContainerIdsToMove));
// Check the display mode as this is also necessary when trasitioning between
// mirror and unified mode.
if (WmShell::Get()->IsInUnifiedModeIgnoreMirroring()) {
for (int id : kExtraContainerIdsToMoveInUnifiedMode)
container_ids.push_back(id);
}
for (int id : container_ids) {
WmWindow* src_container = src->GetChildByShellWindowId(id);
WmWindow* dst_container = dst->GetChildByShellWindowId(id);
while (!src_container->GetChildren().empty()) {
// Restart iteration from the source container windows each time as they
// may change as a result of moving other windows.
WmWindow::Windows src_container_children = src_container->GetChildren();
WmWindow::Windows::const_iterator iter = src_container_children.begin();
while (iter != src_container_children.end() &&
SystemModalContainerLayoutManager::IsModalBackground(*iter)) {
++iter;
}
// If the entire window list is modal background windows then stop.
if (iter == src_container_children.end())
break;
ReparentWindow(*iter, dst_container);
}
}
}
// Creates a new window for use as a container.
// TODO(sky): This should create an aura::Window. http://crbug.com/671246.
WmWindow* CreateContainer(int window_id, const char* name, WmWindow* parent) {
WmWindow* window = WmShell::Get()->NewWindow(ui::wm::WINDOW_TYPE_UNKNOWN,
ui::LAYER_NOT_DRAWN);
window->SetShellWindowId(window_id);
window->SetName(name);
parent->AddChild(window);
if (window_id != kShellWindowId_UnparentedControlContainer)
window->Show();
return window;
}
// TODO(sky): This should take an aura::Window. http://crbug.com/671246.
bool ShouldDestroyWindowInCloseChildWindows(WmWindow* window) {
if (!WmWindowAura::GetAuraWindow(window)->owned_by_parent())
return false;
if (!WmShell::Get()->IsRunningInMash())
return true;
aura::WindowMus* window_mus =
aura::WindowMus::Get(WmWindowAura::GetAuraWindow(window));
return Shell::window_tree_client()->WasCreatedByThisClient(window_mus) ||
Shell::window_tree_client()->IsRoot(window_mus);
}
} // namespace
RootWindowController::~RootWindowController() {
......@@ -182,6 +308,13 @@ RootWindowController* RootWindowController::ForTargetRootWindow() {
return GetRootWindowController(Shell::GetTargetRootWindow());
}
void RootWindowController::ConfigureWidgetInitParamsForContainer(
views::Widget* widget,
int shell_container_id,
views::Widget::InitParams* init_params) {
init_params->parent = GetContainer(shell_container_id);
}
aura::WindowTreeHost* RootWindowController::GetHost() {
return window_tree_host_;
}
......@@ -198,24 +331,92 @@ const aura::Window* RootWindowController::GetRootWindow() const {
return GetHost()->window();
}
void RootWindowController::Shutdown() {
WmShell::Get()->RemoveShellObserver(this);
const WmWindow* RootWindowController::GetWindow() const {
return WmWindowAura::Get(GetRootWindow());
}
touch_exploration_manager_.reset();
wm::WorkspaceWindowState RootWindowController::GetWorkspaceWindowState() {
return workspace_controller_ ? workspace_controller()->GetWindowState()
: wm::WORKSPACE_WINDOW_STATE_DEFAULT;
}
ResetRootForNewWindowsIfNecessary();
bool RootWindowController::HasShelf() {
return wm_shelf_->shelf_widget() != nullptr;
}
CloseChildWindows();
aura::Window* root_window = GetRootWindow();
GetRootWindowSettings(root_window)->controller = NULL;
// Forget with the display ID so that display lookup
// ends up with invalid display.
GetRootWindowSettings(root_window)->display_id = display::kInvalidDisplayId;
if (ash_host_)
ash_host_->PrepareForShutdown();
WmShelf* RootWindowController::GetShelf() {
return wm_shelf_.get();
}
system_wallpaper_.reset();
aura::client::SetScreenPositionClient(root_window, NULL);
void RootWindowController::CreateShelf() {
if (wm_shelf_->IsShelfInitialized())
return;
wm_shelf_->InitializeShelf();
if (panel_layout_manager_)
panel_layout_manager_->SetShelf(wm_shelf_.get());
if (docked_window_layout_manager_) {
docked_window_layout_manager_->SetShelf(wm_shelf_.get());
if (wm_shelf_->shelf_layout_manager())
docked_window_layout_manager_->AddObserver(
wm_shelf_->shelf_layout_manager());
}
// Notify shell observers that the shelf has been created.
// TODO(jamescook): Move this into WmShelf::InitializeShelf(). This will
// require changing AttachedPanelWidgetTargeter's access to WmShelf.
WmShell::Get()->NotifyShelfCreatedForRootWindow(
WmWindowAura::Get(GetRootWindow()));
wm_shelf_->shelf_widget()->PostCreateShelf();
}
void RootWindowController::ShowShelf() {
if (!wm_shelf_->IsShelfInitialized())
return;
// TODO(jamescook): Move this into WmShelf.
wm_shelf_->shelf_widget()->SetShelfVisibility(true);
wm_shelf_->shelf_widget()->status_area_widget()->Show();
}
ShelfLayoutManager* RootWindowController::GetShelfLayoutManager() {
return wm_shelf_->shelf_layout_manager();
}
SystemModalContainerLayoutManager*
RootWindowController::GetSystemModalLayoutManager(WmWindow* window) {
WmWindow* modal_container = nullptr;
if (window) {
WmWindow* window_container = wm::GetContainerForWindow(window);
if (window_container &&
window_container->GetShellWindowId() >=
kShellWindowId_LockScreenContainer) {
modal_container = GetWmContainer(kShellWindowId_LockSystemModalContainer);
} else {
modal_container = GetWmContainer(kShellWindowId_SystemModalContainer);
}
} else {
int modal_window_id =
WmShell::Get()->GetSessionStateDelegate()->IsUserSessionBlocked()
? kShellWindowId_LockSystemModalContainer
: kShellWindowId_SystemModalContainer;
modal_container = GetWmContainer(modal_window_id);
}
return modal_container ? static_cast<SystemModalContainerLayoutManager*>(
modal_container->GetLayoutManager())
: nullptr;
}
StatusAreaWidget* RootWindowController::GetStatusAreaWidget() {
ShelfWidget* shelf_widget = wm_shelf_->shelf_widget();
return shelf_widget ? shelf_widget->status_area_widget() : nullptr;
}
SystemTray* RootWindowController::GetSystemTray() {
// We assume in throughout the code that this will not return NULL. If code
// triggers this for valid reasons, it should test status_area_widget first.
CHECK(wm_shelf_->shelf_widget()->status_area_widget());
return wm_shelf_->shelf_widget()->status_area_widget()->system_tray();
}
bool RootWindowController::CanWindowReceiveEvents(aura::Window* window) {
......@@ -263,6 +464,25 @@ bool RootWindowController::CanWindowReceiveEvents(aura::Window* window) {
return true;
}
WmWindow* RootWindowController::FindEventTarget(
const gfx::Point& location_in_screen) {
gfx::Point location_in_root(location_in_screen);
aura::Window* root_window = GetRootWindow();
::wm::ConvertPointFromScreen(root_window, &location_in_root);
ui::MouseEvent test_event(ui::ET_MOUSE_MOVED, location_in_root,
location_in_root, ui::EventTimeForNow(),
ui::EF_NONE, ui::EF_NONE);
ui::EventTarget* event_handler =
static_cast<ui::EventTarget*>(root_window)
->GetEventTargeter()
->FindTargetForEvent(root_window, &test_event);
return WmWindowAura::Get(static_cast<aura::Window*>(event_handler));
}
gfx::Point RootWindowController::GetLastMouseLocationInRoot() {
return window_tree_host_->dispatcher()->GetLastMouseLocationInRoot();
}
aura::Window* RootWindowController::GetContainer(int container_id) {
return GetRootWindow()->GetChildById(container_id);
}
......@@ -271,6 +491,23 @@ const aura::Window* RootWindowController::GetContainer(int container_id) const {
return window_tree_host_->window()->GetChildById(container_id);
}
const WmWindow* RootWindowController::GetWmContainer(int container_id) const {
const aura::Window* window = GetContainer(container_id);
return WmWindowAura::Get(window);
}
void RootWindowController::SetWallpaperWidgetController(
WallpaperWidgetController* controller) {
wallpaper_widget_controller_.reset(controller);
}
void RootWindowController::SetAnimatingWallpaperWidgetController(
AnimatingWallpaperWidgetController* controller) {
if (animating_wallpaper_widget_controller_.get())
animating_wallpaper_widget_controller_->StopAnimating();
animating_wallpaper_widget_controller_.reset(controller);
}
void RootWindowController::OnInitialWallpaperAnimationStarted() {
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kAshAnimateFromBootSplashScreen) &&
......@@ -299,7 +536,29 @@ void RootWindowController::OnWallpaperAnimationFinished(views::Widget* widget) {
}
}
void RootWindowController::Shutdown() {
WmShell::Get()->RemoveShellObserver(this);
touch_exploration_manager_.reset();
ResetRootForNewWindowsIfNecessary();
CloseChildWindows();
aura::Window* root_window = GetRootWindow();
GetRootWindowSettings(root_window)->controller = nullptr;
// Forget with the display ID so that display lookup
// ends up with invalid display.
GetRootWindowSettings(root_window)->display_id = display::kInvalidDisplayId;
if (ash_host_)
ash_host_->PrepareForShutdown();
system_wallpaper_.reset();
aura::client::SetScreenPositionClient(root_window, nullptr);
}
void RootWindowController::CloseChildWindows() {
// NOTE: this may be called multiple times.
// Remove observer as deactivating keyboard causes
// docked_window_layout_manager() to fire notifications.
if (docked_window_layout_manager() && wm_shelf_->shelf_layout_manager()) {
......@@ -311,30 +570,82 @@ void RootWindowController::CloseChildWindows() {
// down associated layout managers.
DeactivateKeyboard(keyboard::KeyboardController::GetInstance());
CloseChildWindowsImpl();
// |panel_layout_manager_| needs to be shut down before windows are destroyed.
if (panel_layout_manager_) {
panel_layout_manager_->Shutdown();
panel_layout_manager_ = nullptr;
}
// |docked_window_layout_manager_| needs to be shut down before windows are
// destroyed.
if (docked_window_layout_manager_) {
docked_window_layout_manager_->Shutdown();
docked_window_layout_manager_ = nullptr;
}
WmShelf* shelf = GetShelf();
shelf->ShutdownShelfWidget();
workspace_controller_.reset();
// Explicitly destroy top level windows. We do this because such windows may
// query the RootWindow for state.
WmWindowTracker non_toplevel_windows;
WmWindow* root = GetWindow();
non_toplevel_windows.Add(root);
while (!non_toplevel_windows.windows().empty()) {
WmWindow* non_toplevel_window = non_toplevel_windows.Pop();
WmWindowTracker toplevel_windows;
for (WmWindow* child : non_toplevel_window->GetChildren()) {
if (!ShouldDestroyWindowInCloseChildWindows(child))
continue;
if (child->HasNonClientArea())
toplevel_windows.Add(child);
else
non_toplevel_windows.Add(child);
}
while (!toplevel_windows.windows().empty())
toplevel_windows.Pop()->Destroy();
}
// And then remove the containers.
while (!root->GetChildren().empty()) {
WmWindow* child = root->GetChildren()[0];
if (ShouldDestroyWindowInCloseChildWindows(child))
child->Destroy();
else
root->RemoveChild(child);
}
shelf->DestroyShelfWidget();
// CloseChildWindows() may be called twice during the shutdown of ash
// unittests. Avoid notifying WmShelf that the shelf has been destroyed twice.
if (shelf->IsShelfInitialized())
shelf->ShutdownShelf();
aura::client::SetDragDropClient(GetRootWindow(), nullptr);
aura::client::SetTooltipClient(GetRootWindow(), nullptr);
}
ShelfLayoutManager* RootWindowController::GetShelfLayoutManager() {
return wm_shelf_->shelf_layout_manager();
void RootWindowController::MoveWindowsTo(aura::Window* dst) {
// Clear the workspace controller, so it doesn't incorrectly update the shelf.
workspace_controller_.reset();
ReparentAllWindows(GetWindow(), WmWindowAura::Get(dst));
}
StatusAreaWidget* RootWindowController::GetStatusAreaWidget() {
ShelfWidget* shelf_widget = wm_shelf_->shelf_widget();
return shelf_widget ? shelf_widget->status_area_widget() : nullptr;
void RootWindowController::UpdateShelfVisibility() {
wm_shelf_->UpdateVisibilityState();
}
SystemTray* RootWindowController::GetSystemTray() {
// We assume in throughout the code that this will not return NULL. If code
// triggers this for valid reasons, it should test status_area_widget first.
CHECK(wm_shelf_->shelf_widget()->status_area_widget());
return wm_shelf_->shelf_widget()->status_area_widget()->system_tray();
}
void RootWindowController::InitTouchHuds() {
if (WmShell::Get()->IsRunningInMash())
return;
void RootWindowController::UpdateShelfVisibility() {
wm_shelf_->UpdateVisibilityState();
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(switches::kAshTouchHud))
set_touch_hud_debug(new TouchHudDebug(GetRootWindow()));
if (Shell::GetInstance()->is_touch_hud_projection_enabled())
EnableTouchHudProjection();
}
aura::Window* RootWindowController::GetWindowForFullscreenMode() {
......@@ -400,6 +711,39 @@ void RootWindowController::SetTouchAccessibilityAnchorPoint(
touch_exploration_manager_->SetTouchAccessibilityAnchorPoint(anchor_point);
}
void RootWindowController::ShowContextMenu(const gfx::Point& location_in_screen,
ui::MenuSourceType source_type) {
ShellDelegate* delegate = WmShell::Get()->delegate();
DCHECK(delegate);
menu_model_.reset(delegate->CreateContextMenu(wm_shelf_.get(), nullptr));
if (!menu_model_)
return;
menu_model_adapter_ = base::MakeUnique<views::MenuModelAdapter>(
menu_model_.get(),
base::Bind(&RootWindowController::OnMenuClosed, base::Unretained(this)));
// The wallpaper controller may not be set yet if the user clicked on the
// status area before the initial animation completion. See crbug.com/222218
if (!wallpaper_widget_controller())
return;
menu_runner_ = base::MakeUnique<views::MenuRunner>(
menu_model_adapter_->CreateMenu(),
views::MenuRunner::CONTEXT_MENU | views::MenuRunner::ASYNC);
ignore_result(
menu_runner_->RunMenuAt(wallpaper_widget_controller()->widget(), nullptr,
gfx::Rect(location_in_screen, gfx::Size()),
views::MENU_ANCHOR_TOPLEFT, source_type));
}
void RootWindowController::UpdateAfterLoginStatusChange(LoginStatus status) {
StatusAreaWidget* status_area_widget =
wm_shelf_->shelf_widget()->status_area_widget();
if (status_area_widget)
status_area_widget->UpdateAfterLoginStatusChange(status);
}
////////////////////////////////////////////////////////////////////////////////
// RootWindowController, private:
......@@ -473,17 +817,62 @@ void RootWindowController::Init(RootWindowType root_window_type) {
void RootWindowController::InitLayoutManagers() {
// Create the shelf and status area widgets.
DCHECK(!wm_shelf_->shelf_widget());
aura::Window* shelf_container = GetContainer(kShellWindowId_ShelfContainer);
aura::Window* status_container = GetContainer(kShellWindowId_StatusContainer);
WmWindow* wm_shelf_container = WmWindowAura::Get(shelf_container);
WmWindow* wm_status_container = WmWindowAura::Get(status_container);
CreateLayoutManagers();
GetShelf()->CreateShelfWidget(GetWindow());
WmWindow* root = GetWindow();
root_window_layout_manager_ = new wm::RootWindowLayoutManager(root);
root->SetLayoutManager(base::WrapUnique(root_window_layout_manager_));
WmWindow* default_container = GetWmContainer(kShellWindowId_DefaultContainer);
// Installs WorkspaceLayoutManager on |default_container|.
workspace_controller_.reset(new WorkspaceController(default_container));
WmWindow* modal_container =
GetWmContainer(kShellWindowId_SystemModalContainer);
DCHECK(modal_container);
modal_container->SetLayoutManager(
base::MakeUnique<SystemModalContainerLayoutManager>(modal_container));
WmWindow* lock_modal_container =
GetWmContainer(kShellWindowId_LockSystemModalContainer);
DCHECK(lock_modal_container);
lock_modal_container->SetLayoutManager(
base::MakeUnique<SystemModalContainerLayoutManager>(
lock_modal_container));
WmWindow* lock_container = GetWmContainer(kShellWindowId_LockScreenContainer);
DCHECK(lock_container);
lock_container->SetLayoutManager(
base::MakeUnique<LockLayoutManager>(lock_container));
WmWindow* always_on_top_container =
GetWmContainer(kShellWindowId_AlwaysOnTopContainer);
DCHECK(always_on_top_container);
always_on_top_controller_ =
base::MakeUnique<AlwaysOnTopController>(always_on_top_container);
// Create Docked windows layout manager
WmWindow* docked_container = GetWmContainer(kShellWindowId_DockedContainer);
docked_window_layout_manager_ =
new DockedWindowLayoutManager(docked_container);
docked_container->SetLayoutManager(
base::WrapUnique(docked_window_layout_manager_));
// Create Panel layout manager
WmWindow* wm_panel_container = GetWmContainer(kShellWindowId_PanelContainer);
panel_layout_manager_ = new PanelLayoutManager(wm_panel_container);
wm_panel_container->SetLayoutManager(base::WrapUnique(panel_layout_manager_));
wm::WmSnapToPixelLayoutManager::InstallOnContainers(root);
// Make it easier to resize windows that partially overlap the shelf. Must
// occur after the ShelfLayoutManager is constructed by ShelfWidget.
aura::Window* shelf_container = GetContainer(kShellWindowId_ShelfContainer);
WmWindow* wm_shelf_container = WmWindowAura::Get(shelf_container);
shelf_container->SetEventTargeter(base::MakeUnique<ShelfWindowTargeter>(
wm_shelf_container, wm_shelf_.get()));
aura::Window* status_container = GetContainer(kShellWindowId_StatusContainer);
WmWindow* wm_status_container = WmWindowAura::Get(status_container);
status_container->SetEventTargeter(base::MakeUnique<ShelfWindowTargeter>(
wm_status_container, wm_shelf_.get()));
......@@ -504,15 +893,181 @@ void RootWindowController::InitLayoutManagers() {
touch_extend, panel_layout_manager())));
}
void RootWindowController::InitTouchHuds() {
if (WmShell::Get()->IsRunningInMash())
return;
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(switches::kAshTouchHud))
set_touch_hud_debug(new TouchHudDebug(GetRootWindow()));
if (Shell::GetInstance()->is_touch_hud_projection_enabled())
EnableTouchHudProjection();
void RootWindowController::CreateContainers() {
WmWindow* root = GetWindow();
// These containers are just used by PowerButtonController to animate groups
// of containers simultaneously without messing up the current transformations
// on those containers. These are direct children of the root window; all of
// the other containers are their children.
// The wallpaper container is not part of the lock animation, so it is not
// included in those animate groups. When the screen is locked, the wallpaper
// is moved to the lock screen wallpaper container (and moved back on unlock).
// Ensure that there's an opaque layer occluding the non-lock-screen layers.
WmWindow* wallpaper_container = CreateContainer(
kShellWindowId_WallpaperContainer, "WallpaperContainer", root);
wallpaper_container->SetChildWindowVisibilityChangesAnimated();
WmWindow* non_lock_screen_containers =
CreateContainer(kShellWindowId_NonLockScreenContainersContainer,
"NonLockScreenContainersContainer", root);
// Clip all windows inside this container, as half pixel of the window's
// texture may become visible when the screen is scaled. crbug.com/368591.
non_lock_screen_containers->SetMasksToBounds(true);
WmWindow* lock_wallpaper_containers =
CreateContainer(kShellWindowId_LockScreenWallpaperContainer,
"LockScreenWallpaperContainer", root);
lock_wallpaper_containers->SetChildWindowVisibilityChangesAnimated();
WmWindow* lock_screen_containers =
CreateContainer(kShellWindowId_LockScreenContainersContainer,
"LockScreenContainersContainer", root);
WmWindow* lock_screen_related_containers =
CreateContainer(kShellWindowId_LockScreenRelatedContainersContainer,
"LockScreenRelatedContainersContainer", root);
CreateContainer(kShellWindowId_UnparentedControlContainer,
"UnparentedControlContainer", non_lock_screen_containers);
WmWindow* default_container =
CreateContainer(kShellWindowId_DefaultContainer, "DefaultContainer",
non_lock_screen_containers);
default_container->SetChildWindowVisibilityChangesAnimated();
default_container->SetSnapsChildrenToPhysicalPixelBoundary();
default_container->SetBoundsInScreenBehaviorForChildren(
WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES);
default_container->SetChildrenUseExtendedHitRegion();
WmWindow* always_on_top_container =
CreateContainer(kShellWindowId_AlwaysOnTopContainer,
"AlwaysOnTopContainer", non_lock_screen_containers);
always_on_top_container->SetChildWindowVisibilityChangesAnimated();
always_on_top_container->SetSnapsChildrenToPhysicalPixelBoundary();
always_on_top_container->SetBoundsInScreenBehaviorForChildren(
WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES);
WmWindow* docked_container =
CreateContainer(kShellWindowId_DockedContainer, "DockedContainer",
non_lock_screen_containers);
docked_container->SetChildWindowVisibilityChangesAnimated();
docked_container->SetSnapsChildrenToPhysicalPixelBoundary();
docked_container->SetBoundsInScreenBehaviorForChildren(
WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES);
docked_container->SetChildrenUseExtendedHitRegion();
WmWindow* shelf_container =
CreateContainer(kShellWindowId_ShelfContainer, "ShelfContainer",
non_lock_screen_containers);
shelf_container->SetSnapsChildrenToPhysicalPixelBoundary();
shelf_container->SetBoundsInScreenBehaviorForChildren(
WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES);
shelf_container->SetLockedToRoot(true);
WmWindow* panel_container =
CreateContainer(kShellWindowId_PanelContainer, "PanelContainer",
non_lock_screen_containers);
panel_container->SetSnapsChildrenToPhysicalPixelBoundary();
panel_container->SetBoundsInScreenBehaviorForChildren(
WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES);
WmWindow* shelf_bubble_container =
CreateContainer(kShellWindowId_ShelfBubbleContainer,
"ShelfBubbleContainer", non_lock_screen_containers);
shelf_bubble_container->SetSnapsChildrenToPhysicalPixelBoundary();
shelf_bubble_container->SetBoundsInScreenBehaviorForChildren(
WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES);
shelf_bubble_container->SetLockedToRoot(true);
WmWindow* app_list_container =
CreateContainer(kShellWindowId_AppListContainer, "AppListContainer",
non_lock_screen_containers);
app_list_container->SetSnapsChildrenToPhysicalPixelBoundary();
app_list_container->SetBoundsInScreenBehaviorForChildren(
WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES);
WmWindow* modal_container =
CreateContainer(kShellWindowId_SystemModalContainer,
"SystemModalContainer", non_lock_screen_containers);
modal_container->SetSnapsChildrenToPhysicalPixelBoundary();
modal_container->SetChildWindowVisibilityChangesAnimated();
modal_container->SetBoundsInScreenBehaviorForChildren(
WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES);
modal_container->SetChildrenUseExtendedHitRegion();
// TODO(beng): Figure out if we can make this use
// SystemModalContainerEventFilter instead of stops_event_propagation.
WmWindow* lock_container =
CreateContainer(kShellWindowId_LockScreenContainer, "LockScreenContainer",
lock_screen_containers);
lock_container->SetSnapsChildrenToPhysicalPixelBoundary();
lock_container->SetBoundsInScreenBehaviorForChildren(
WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES);
// TODO(beng): stopsevents
WmWindow* lock_modal_container =
CreateContainer(kShellWindowId_LockSystemModalContainer,
"LockSystemModalContainer", lock_screen_containers);
lock_modal_container->SetSnapsChildrenToPhysicalPixelBoundary();
lock_modal_container->SetChildWindowVisibilityChangesAnimated();
lock_modal_container->SetBoundsInScreenBehaviorForChildren(
WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES);
lock_modal_container->SetChildrenUseExtendedHitRegion();
WmWindow* status_container =
CreateContainer(kShellWindowId_StatusContainer, "StatusContainer",
lock_screen_related_containers);
status_container->SetSnapsChildrenToPhysicalPixelBoundary();
status_container->SetBoundsInScreenBehaviorForChildren(
WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES);
status_container->SetLockedToRoot(true);
WmWindow* settings_bubble_container =
CreateContainer(kShellWindowId_SettingBubbleContainer,
"SettingBubbleContainer", lock_screen_related_containers);
settings_bubble_container->SetChildWindowVisibilityChangesAnimated();
settings_bubble_container->SetSnapsChildrenToPhysicalPixelBoundary();
settings_bubble_container->SetBoundsInScreenBehaviorForChildren(
WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES);
settings_bubble_container->SetLockedToRoot(true);
WmWindow* virtual_keyboard_parent_container = CreateContainer(
kShellWindowId_ImeWindowParentContainer, "VirtualKeyboardParentContainer",
lock_screen_related_containers);
virtual_keyboard_parent_container->SetSnapsChildrenToPhysicalPixelBoundary();
virtual_keyboard_parent_container->SetBoundsInScreenBehaviorForChildren(
WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES);
WmWindow* menu_container =
CreateContainer(kShellWindowId_MenuContainer, "MenuContainer",
lock_screen_related_containers);
menu_container->SetChildWindowVisibilityChangesAnimated();
menu_container->SetSnapsChildrenToPhysicalPixelBoundary();
menu_container->SetBoundsInScreenBehaviorForChildren(
WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES);
WmWindow* drag_drop_container = CreateContainer(
kShellWindowId_DragImageAndTooltipContainer,
"DragImageAndTooltipContainer", lock_screen_related_containers);
drag_drop_container->SetChildWindowVisibilityChangesAnimated();
drag_drop_container->SetSnapsChildrenToPhysicalPixelBoundary();
drag_drop_container->SetBoundsInScreenBehaviorForChildren(
WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES);
WmWindow* overlay_container =
CreateContainer(kShellWindowId_OverlayContainer, "OverlayContainer",
lock_screen_related_containers);
overlay_container->SetSnapsChildrenToPhysicalPixelBoundary();
overlay_container->SetBoundsInScreenBehaviorForChildren(
WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES);
WmWindow* mouse_cursor_container = CreateContainer(
kShellWindowId_MouseCursorContainer, "MouseCursorContainer", root);
mouse_cursor_container->SetBoundsInScreenBehaviorForChildren(
WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES);
CreateContainer(kShellWindowId_PowerButtonAnimationContainer,
"PowerButtonAnimationContainer", root);
}
void RootWindowController::CreateSystemWallpaper(
......@@ -552,6 +1107,29 @@ void RootWindowController::DisableTouchHudProjection() {
touch_hud_projection_->Remove();
}
void RootWindowController::ResetRootForNewWindowsIfNecessary() {
WmShell* shell = WmShell::Get();
// Change the target root window before closing child windows. If any child
// being removed triggers a relayout of the shelf it will try to build a
// window list adding windows from the target root window's containers which
// may have already gone away.
WmWindow* root = GetWindow();
if (shell->GetRootWindowForNewWindows() == root) {
// The root window for new windows is being destroyed. Switch to the primary
// root window if possible.
WmWindow* primary_root = shell->GetPrimaryRootWindow();
shell->set_root_window_for_new_windows(primary_root == root ? nullptr
: primary_root);
}
}
void RootWindowController::OnMenuClosed() {
menu_runner_.reset();
menu_model_adapter_.reset();
menu_model_.reset();
wm_shelf_->UpdateVisibilityState();
}
void RootWindowController::OnLoginStateChanged(LoginStatus status) {
wm_shelf_->UpdateVisibilityState();
}
......
......@@ -306,10 +306,6 @@ class ASH_EXPORT RootWindowController : public ShellObserver {
// Creates the containers (WmWindows) used by the shell.
void CreateContainers();
// Creates the LayoutManagers for the windows created by CreateContainers().
// TODO(sky): merge this with InitLayoutManagers().
void CreateLayoutManagers();
// Initializes |system_wallpaper_| and possibly also |boot_splash_screen_|.
// The initial color is determined by the |root_window_type| and whether or
// not this is the first boot.
......@@ -333,9 +329,6 @@ class ASH_EXPORT RootWindowController : public ShellObserver {
void OnLoginStateChanged(LoginStatus status) override;
void OnTouchHudProjectionToggled(bool enabled) override;
// TODO(sky): temporary, fold into CloseChildWindows().
void CloseChildWindowsImpl();
std::unique_ptr<AshWindowTreeHost> ash_host_;
std::unique_ptr<aura::WindowTreeHost> mus_window_tree_host_;
// This comes from |ash_host_| or |mus_window_tree_host_|.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment