1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
// Copyright (c) 2011 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 "ui/aura_shell/default_container_layout_manager.h"
#include "base/auto_reset.h"
#include "ui/aura/desktop.h"
#include "ui/aura/event.h"
#include "ui/aura/window.h"
#include "ui/aura/screen_aura.h"
#include "ui/aura/window_types.h"
#include "ui/aura_shell/workspace/workspace.h"
#include "ui/aura_shell/workspace/workspace_manager.h"
#include "ui/gfx/rect.h"
#include "views/widget/native_widget_aura.h"
namespace aura_shell {
namespace internal {
////////////////////////////////////////////////////////////////////////////////
// DefaultContainerLayoutManager, public:
DefaultContainerLayoutManager::DefaultContainerLayoutManager(
aura::Window* owner,
WorkspaceManager* workspace_manager)
: owner_(owner),
workspace_manager_(workspace_manager),
drag_window_(NULL),
ignore_calculate_bounds_(false) {
}
DefaultContainerLayoutManager::~DefaultContainerLayoutManager() {}
void DefaultContainerLayoutManager::PrepareForMoveOrResize(
aura::Window* drag,
aura::MouseEvent* event) {
drag_window_ = drag;
}
void DefaultContainerLayoutManager::CancelMoveOrResize(
aura::Window* drag,
aura::MouseEvent* event) {
drag_window_ = NULL;
}
void DefaultContainerLayoutManager::ProcessMove(
aura::Window* drag,
aura::MouseEvent* event) {
AutoReset<bool> reset(&ignore_calculate_bounds_, true);
// TODO(oshima): Just zooming out may (and will) move/swap window without
// a users's intent. We probably should scroll viewport, but that may not
// be enough. See crbug.com/101826 for more discussion.
workspace_manager_->SetOverview(true);
gfx::Point point_in_owner = event->location();
aura::Window::ConvertPointToWindow(
drag,
owner_,
&point_in_owner);
// TODO(oshima): We should support simply moving to another
// workspace when the destination workspace has enough room to accomodate.
aura::Window* rotate_target =
workspace_manager_->FindRotateWindowForLocation(point_in_owner);
if (rotate_target)
workspace_manager_->RotateWindows(drag, rotate_target);
}
void DefaultContainerLayoutManager::EndMove(
aura::Window* drag,
aura::MouseEvent* evnet) {
// TODO(oshima): finish moving window between workspaces.
AutoReset<bool> reset(&ignore_calculate_bounds_, true);
drag_window_ = NULL;
Workspace* workspace = workspace_manager_->FindBy(drag);
workspace->Layout(NULL, NULL);
workspace->Activate();
workspace_manager_->SetOverview(false);
}
void DefaultContainerLayoutManager::EndResize(
aura::Window* drag,
aura::MouseEvent* evnet) {
AutoReset<bool> reset(&ignore_calculate_bounds_, true);
drag_window_ = NULL;
Workspace* workspace = workspace_manager_->GetActiveWorkspace();
if (workspace)
workspace->Layout(NULL, NULL);
workspace_manager_->SetOverview(false);
}
////////////////////////////////////////////////////////////////////////////////
// DefaultContainerLayoutManager, aura::LayoutManager implementation:
void DefaultContainerLayoutManager::OnWindowResized() {
// Workspace is updated via DesktopObserver::OnDesktopResized.
}
void DefaultContainerLayoutManager::OnWindowAdded(aura::Window* child) {
if (child->type() != aura::WINDOW_TYPE_NORMAL || child->transient_parent())
return;
AutoReset<bool> reset(&ignore_calculate_bounds_, true);
Workspace* workspace = workspace_manager_->GetActiveWorkspace();
if (workspace) {
aura::Window* active = aura::Desktop::GetInstance()->active_window();
// Active window may not be in the default container layer.
if (!workspace->Contains(active))
active = NULL;
if (workspace->AddWindowAfter(child, active))
return;
}
// Create new workspace if new |child| doesn't fit to current workspace.
Workspace* new_workspace = workspace_manager_->CreateWorkspace();
new_workspace->AddWindowAfter(child, NULL);
new_workspace->Activate();
}
void DefaultContainerLayoutManager::OnWillRemoveWindow(aura::Window* child) {
AutoReset<bool> reset(&ignore_calculate_bounds_, true);
Workspace* workspace = workspace_manager_->FindBy(child);
if (!workspace)
return;
workspace->RemoveWindow(child);
if (workspace->is_empty())
delete workspace;
}
void DefaultContainerLayoutManager::OnChildWindowVisibilityChanged(
aura::Window* child,
bool visible) {
NOTIMPLEMENTED();
}
void DefaultContainerLayoutManager::CalculateBoundsForChild(
aura::Window* child,
gfx::Rect* requested_bounds) {
if (child->type() != aura::WINDOW_TYPE_NORMAL ||
ignore_calculate_bounds_ ||
child->transient_parent())
return;
// If a drag window is requesting bounds, make sure its attached to
// the workarea's top and fits within the total drag area.
if (drag_window_) {
gfx::Rect drag_area = workspace_manager_->GetDragAreaBounds();
requested_bounds->set_y(drag_area.y());
*requested_bounds = requested_bounds->AdjustToFit(drag_area);
return;
}
Workspace* workspace = workspace_manager_->FindBy(child);
gfx::Rect work_area = workspace->GetWorkAreaBounds();
requested_bounds->set_origin(
gfx::Point(child->GetTargetBounds().x(), work_area.y()));
*requested_bounds = requested_bounds->AdjustToFit(work_area);
}
} // namespace internal
} // namespace aura_shell
|