OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/aura_shell/toplevel_layout_manager.h" | 5 #include "ui/aura_shell/toplevel_layout_manager.h" |
6 | 6 |
7 #include "ui/aura/client/aura_constants.h" | 7 #include "ui/aura/client/aura_constants.h" |
8 #include "ui/aura/window.h" | 8 #include "ui/aura/window.h" |
9 #include "ui/aura_shell/property_util.h" | |
10 #include "ui/aura_shell/shelf_layout_manager.h" | 9 #include "ui/aura_shell/shelf_layout_manager.h" |
11 #include "ui/aura_shell/workspace/workspace.h" | 10 #include "ui/aura_shell/window_util.h" |
12 #include "ui/aura_shell/workspace/workspace_manager.h" | |
13 #include "ui/base/ui_base_types.h" | 11 #include "ui/base/ui_base_types.h" |
14 #include "ui/gfx/screen.h" | |
15 | 12 |
16 namespace aura_shell { | 13 namespace aura_shell { |
17 namespace internal { | 14 namespace internal { |
18 | 15 |
19 ToplevelLayoutManager::ToplevelLayoutManager() : shelf_(NULL) { | 16 ToplevelLayoutManager::ToplevelLayoutManager() : shelf_(NULL) { |
20 } | 17 } |
21 | 18 |
22 ToplevelLayoutManager::~ToplevelLayoutManager() { | 19 ToplevelLayoutManager::~ToplevelLayoutManager() { |
23 for (Windows::const_iterator i = windows_.begin(); i != windows_.end(); ++i) | 20 for (Windows::const_iterator i = windows_.begin(); i != windows_.end(); ++i) |
24 (*i)->RemoveObserver(this); | 21 (*i)->RemoveObserver(this); |
25 } | 22 } |
26 | 23 |
27 void ToplevelLayoutManager::OnWindowResized() { | 24 void ToplevelLayoutManager::OnWindowResized() { |
28 } | 25 } |
29 | 26 |
30 void ToplevelLayoutManager::OnWindowAddedToLayout(aura::Window* child) { | 27 void ToplevelLayoutManager::OnWindowAddedToLayout(aura::Window* child) { |
31 windows_.insert(child); | 28 windows_.insert(child); |
32 child->AddObserver(this); | 29 child->AddObserver(this); |
33 if (child->GetProperty(aura::kShowStateKey)) | 30 if (child->GetProperty(aura::kShowStateKey)) { |
34 WindowStateChanged(child); | 31 UpdateBoundsFromShowState(child); |
| 32 UpdateShelfVisibility(); |
| 33 } |
35 } | 34 } |
36 | 35 |
37 void ToplevelLayoutManager::OnWillRemoveWindowFromLayout( | 36 void ToplevelLayoutManager::OnWillRemoveWindowFromLayout( |
38 aura::Window* child) { | 37 aura::Window* child) { |
39 windows_.erase(child); | 38 windows_.erase(child); |
40 child->RemoveObserver(this); | 39 child->RemoveObserver(this); |
41 UpdateShelfVisibility(); | 40 UpdateShelfVisibility(); |
42 } | 41 } |
43 | 42 |
44 void ToplevelLayoutManager::OnChildWindowVisibilityChanged(aura::Window* child, | 43 void ToplevelLayoutManager::OnChildWindowVisibilityChanged(aura::Window* child, |
45 bool visibile) { | 44 bool visibile) { |
46 UpdateShelfVisibility(); | 45 UpdateShelfVisibility(); |
47 } | 46 } |
48 | 47 |
49 void ToplevelLayoutManager::SetChildBounds(aura::Window* child, | 48 void ToplevelLayoutManager::SetChildBounds(aura::Window* child, |
50 const gfx::Rect& requested_bounds) { | 49 const gfx::Rect& requested_bounds) { |
51 SetChildBoundsDirect(child, requested_bounds); | 50 SetChildBoundsDirect(child, requested_bounds); |
52 } | 51 } |
53 | 52 |
54 void ToplevelLayoutManager::OnWindowPropertyChanged(aura::Window* window, | 53 void ToplevelLayoutManager::OnWindowPropertyChanged(aura::Window* window, |
55 const char* name, | 54 const char* name, |
56 void* old) { | 55 void* old) { |
57 if (name == aura::kShowStateKey) | 56 if (name == aura::kShowStateKey) { |
58 WindowStateChanged(window); | 57 UpdateBoundsFromShowState(window); |
59 } | 58 UpdateShelfVisibility(); |
60 | |
61 void ToplevelLayoutManager::WindowStateChanged(aura::Window* window) { | |
62 switch (window->GetIntProperty(aura::kShowStateKey)) { | |
63 case ui::SHOW_STATE_NORMAL: { | |
64 const gfx::Rect* restore = GetRestoreBounds(window); | |
65 window->SetProperty(aura::kRestoreBoundsKey, NULL); | |
66 if (restore) | |
67 window->SetBounds(*restore); | |
68 delete restore; | |
69 break; | |
70 } | |
71 | |
72 case ui::SHOW_STATE_MAXIMIZED: | |
73 SetRestoreBoundsIfNotSet(window); | |
74 window->SetBounds(gfx::Screen::GetMonitorWorkAreaNearestWindow(window)); | |
75 break; | |
76 | |
77 case ui::SHOW_STATE_FULLSCREEN: | |
78 SetRestoreBoundsIfNotSet(window); | |
79 window->SetBounds(gfx::Screen::GetMonitorAreaNearestWindow(window)); | |
80 break; | |
81 | |
82 default: | |
83 break; | |
84 } | 59 } |
85 | |
86 UpdateShelfVisibility(); | |
87 } | 60 } |
88 | 61 |
89 void ToplevelLayoutManager::UpdateShelfVisibility() { | 62 void ToplevelLayoutManager::UpdateShelfVisibility() { |
90 if (!shelf_) | 63 if (!shelf_) |
91 return; | 64 return; |
92 | 65 |
93 bool has_fullscreen_window = false; | 66 bool has_fullscreen_window = false; |
94 for (Windows::const_iterator i = windows_.begin(); i != windows_.end(); ++i) { | 67 for (Windows::const_iterator i = windows_.begin(); i != windows_.end(); ++i) { |
95 if ((*i)->GetIntProperty(aura::kShowStateKey) == | 68 if ((*i)->GetIntProperty(aura::kShowStateKey) == |
96 ui::SHOW_STATE_FULLSCREEN) { | 69 ui::SHOW_STATE_FULLSCREEN) { |
97 has_fullscreen_window = true; | 70 has_fullscreen_window = true; |
98 break; | 71 break; |
99 } | 72 } |
100 } | 73 } |
101 shelf_->SetVisible(!has_fullscreen_window); | 74 shelf_->SetVisible(!has_fullscreen_window); |
102 } | 75 } |
103 | 76 |
104 } // namespace internal | 77 } // namespace internal |
105 } // namespace aura_shell | 78 } // namespace aura_shell |
OLD | NEW |