blob: 7c78ec0a172ed5bef73e439785c06cdaccdc5904 (
plain)
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
|
// Copyright (c) 2012 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/base_layout_manager.h"
#include "ash/wm/property_util.h"
#include "ash/wm/window_util.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/root_window.h"
#include "ui/aura/window.h"
#include "ui/base/ui_base_types.h"
#include "ui/gfx/screen.h"
namespace ash {
namespace internal {
/////////////////////////////////////////////////////////////////////////////
// BaseLayoutManager, public:
BaseLayoutManager::BaseLayoutManager() {
aura::RootWindow::GetInstance()->AddRootWindowObserver(this);
}
BaseLayoutManager::~BaseLayoutManager() {
for (WindowSet::const_iterator i = windows_.begin(); i != windows_.end(); ++i)
(*i)->RemoveObserver(this);
aura::RootWindow::GetInstance()->RemoveRootWindowObserver(this);
}
/////////////////////////////////////////////////////////////////////////////
// BaseLayoutManager, LayoutManager overrides:
void BaseLayoutManager::OnWindowResized() {
}
void BaseLayoutManager::OnWindowAddedToLayout(aura::Window* child) {
windows_.insert(child);
child->AddObserver(this);
if (child->GetProperty(aura::client::kShowStateKey)) {
UpdateBoundsFromShowState(child);
}
}
void BaseLayoutManager::OnWillRemoveWindowFromLayout(aura::Window* child) {
windows_.erase(child);
child->RemoveObserver(this);
}
void BaseLayoutManager::OnChildWindowVisibilityChanged(aura::Window* child,
bool visibile) {
}
void BaseLayoutManager::SetChildBounds(aura::Window* child,
const gfx::Rect& requested_bounds) {
gfx::Rect child_bounds(requested_bounds);
// Avoid a janky resize on startup by ensuring the initial bounds fill the
// screen.
if (window_util::IsWindowMaximized(child))
child_bounds = gfx::Screen::GetMonitorWorkAreaNearestWindow(child);
else if (window_util::IsWindowFullscreen(child))
child_bounds = gfx::Screen::GetMonitorAreaNearestWindow(child);
SetChildBoundsDirect(child, child_bounds);
}
/////////////////////////////////////////////////////////////////////////////
// BaseLayoutManager, RootWindowObserver overrides:
void BaseLayoutManager::OnRootWindowResized(const gfx::Size& new_size) {
// If a user plugs an external monitor into a laptop running Aura the
// monitor size will change. Maximized windows need to resize to match.
// We also do this when developers running Aura on a desktop manually resize
// the host window.
for (WindowSet::const_iterator it = windows_.begin();
it != windows_.end();
++it) {
aura::Window* window = *it;
// The work area may be smaller than the full screen.
gfx::Rect monitor_rect = window_util::IsWindowFullscreen(window) ?
gfx::Screen::GetMonitorAreaNearestWindow(window) :
gfx::Screen::GetMonitorWorkAreaNearestWindow(window);
// Put as much of the window as possible within the monitor area.
window->SetBounds(window->bounds().AdjustToFit(monitor_rect));
}
}
/////////////////////////////////////////////////////////////////////////////
// BaseLayoutManager, WindowObserver overrides:
void BaseLayoutManager::OnWindowPropertyChanged(aura::Window* window,
const char* name,
void* old) {
if (name == aura::client::kShowStateKey) {
UpdateBoundsFromShowState(window);
}
}
//////////////////////////////////////////////////////////////////////////////
// BaseLayoutManager, private:
void BaseLayoutManager::UpdateBoundsFromShowState(aura::Window* window) {
switch (window->GetIntProperty(aura::client::kShowStateKey)) {
case ui::SHOW_STATE_NORMAL: {
const gfx::Rect* restore = GetRestoreBounds(window);
window->SetProperty(aura::client::kRestoreBoundsKey, NULL);
if (restore)
window->SetBounds(*restore);
delete restore;
break;
}
case ui::SHOW_STATE_MAXIMIZED:
SetRestoreBoundsIfNotSet(window);
window->SetBounds(gfx::Screen::GetMonitorWorkAreaNearestWindow(window));
break;
case ui::SHOW_STATE_FULLSCREEN:
SetRestoreBoundsIfNotSet(window);
window->SetBounds(gfx::Screen::GetMonitorAreaNearestWindow(window));
break;
default:
break;
}
}
} // namespace internal
} // namespace ash
|