Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(428)

Side by Side Diff: ui/aura_shell/default_container_layout_manager.cc

Issue 8381015: Add workspace to desktop (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: " Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/default_container_layout_manager.h" 5 #include "ui/aura_shell/default_container_layout_manager.h"
6 6
7 #include "base/auto_reset.h"
7 #include "ui/aura/desktop.h" 8 #include "ui/aura/desktop.h"
8 #include "ui/aura/window.h" 9 #include "ui/aura/window.h"
9 #include "ui/aura/screen_aura.h" 10 #include "ui/aura/screen_aura.h"
10 #include "ui/aura/window_types.h" 11 #include "ui/aura/window_types.h"
12 #include "ui/aura_shell/workspace/workspace.h"
13 #include "ui/aura_shell/workspace/workspace_manager.h"
11 #include "ui/base/view_prop.h" 14 #include "ui/base/view_prop.h"
12 #include "ui/gfx/rect.h" 15 #include "ui/gfx/rect.h"
13 #include "views/widget/native_widget_aura.h" 16 #include "views/widget/native_widget_aura.h"
14 17
15 namespace aura_shell { 18 namespace aura_shell {
16 namespace internal { 19 namespace internal {
17 20
18 //////////////////////////////////////////////////////////////////////////////// 21 ////////////////////////////////////////////////////////////////////////////////
19 // DefaultContainerLayoutManager, public: 22 // DefaultContainerLayoutManager, public:
20 23
21 DefaultContainerLayoutManager::DefaultContainerLayoutManager( 24 DefaultContainerLayoutManager::DefaultContainerLayoutManager(
22 aura::Window* owner) 25 aura::Window* owner, WorkspaceManager* workspace_manager)
sky 2011/10/25 20:58:05 each param on its own line.
oshima 2011/10/25 23:37:23 Done. Seems like this is banned sometime this summ
23 : owner_(owner) { 26 : owner_(owner),
27 workspace_manager_(workspace_manager),
28 drag_window_(NULL),
29 layout_manager_has_control_(false) {
24 } 30 }
25 31
26 DefaultContainerLayoutManager::~DefaultContainerLayoutManager() {} 32 DefaultContainerLayoutManager::~DefaultContainerLayoutManager() {}
27 33
28 //////////////////////////////////////////////////////////////////////////////// 34 ////////////////////////////////////////////////////////////////////////////////
29 // DefaultContainerLayoutManager, aura::LayoutManager implementation: 35 // DefaultContainerLayoutManager, aura::LayoutManager implementation:
30 36
31 void DefaultContainerLayoutManager::OnWindowResized() { 37 void DefaultContainerLayoutManager::OnWindowResized() {
32 aura::Window::Windows::const_iterator i = owner_->children().begin(); 38 // Workspace is updated via DesktopObserver::OnDesktopResized.
33 // Use SetBounds because window may be maximized or fullscreen. 39 }
34 for (; i != owner_->children().end(); ++i) { 40
35 aura::Window* w = *i; 41 void DefaultContainerLayoutManager::OnWindowAdded(aura::Window* child) {
36 if (w->show_state() == ui::SHOW_STATE_MAXIMIZED) 42 intptr_t type = reinterpret_cast<intptr_t>(
37 w->Maximize(); 43 ui::ViewProp::GetValue(child, views::NativeWidgetAura::kWindowTypeKey));
38 else if (w->show_state() == ui::SHOW_STATE_FULLSCREEN) 44 if (type != views::Widget::InitParams::TYPE_WINDOW)
39 w->Fullscreen(); 45 return;
40 else 46
41 w->SetBounds(w->bounds()); 47 AutoReset<bool> reset(&layout_manager_has_control_, true);
48
49 Workspace* workspace = workspace_manager_->GetActiveWorkspace();
50 if (workspace) {
51 aura::Window* active = aura::Desktop::GetInstance()->active_window();
52 // Active window may not be in the default container layer.
53 if (!workspace->Contains(active))
54 active = NULL;
55 if (workspace->AddWindowAfter(child, active))
56 return;
42 } 57 }
58 // Create new workspace if new |child| doesn't fit to current workspace.
59 Workspace* new_workspace = workspace_manager_->CreateWorkspace();
60 new_workspace->AddWindowAfter(child, NULL);
61 new_workspace->Activate();
62 }
63
64 void DefaultContainerLayoutManager::OnWillRemoveWindow(aura::Window* child) {
65 AutoReset<bool> reset(&layout_manager_has_control_, true);
66 Workspace* workspace = workspace_manager_->FindBy(child);
67 if (!workspace)
68 return;
69 workspace->RemoveWindow(child);
70 if (workspace->is_empty())
71 delete workspace;
72 }
73
74 void DefaultContainerLayoutManager::OnChildWindowVisibilityChanged(
75 aura::Window* child, bool visible) {
43 NOTIMPLEMENTED(); 76 NOTIMPLEMENTED();
44 } 77 }
45 78
46 void DefaultContainerLayoutManager::OnWindowAdded(aura::Window* child) {
47 child->SetBounds(child->bounds());
48 NOTIMPLEMENTED();
49 }
50
51 void DefaultContainerLayoutManager::OnWillRemoveWindow(aura::Window* child) {
52 NOTIMPLEMENTED();
53 }
54
55 void DefaultContainerLayoutManager::OnChildWindowVisibilityChanged(
56 aura::Window* window, bool visibile) {
57 NOTIMPLEMENTED();
58 }
59
60 void DefaultContainerLayoutManager::CalculateBoundsForChild( 79 void DefaultContainerLayoutManager::CalculateBoundsForChild(
61 aura::Window* child, gfx::Rect* requested_bounds) { 80 aura::Window* child, gfx::Rect* requested_bounds) {
sky 2011/10/25 20:58:05 each param on its own line.
oshima 2011/10/25 23:37:23 Done.
62 intptr_t type = reinterpret_cast<intptr_t>( 81 intptr_t type = reinterpret_cast<intptr_t>(
63 ui::ViewProp::GetValue(child, views::NativeWidgetAura::kWindowTypeKey)); 82 ui::ViewProp::GetValue(child, views::NativeWidgetAura::kWindowTypeKey));
64 // DCLM controls windows with a frame. 83 if (type != views::Widget::InitParams::TYPE_WINDOW ||
65 if (type != views::Widget::InitParams::TYPE_WINDOW) 84 layout_manager_has_control_)
66 return; 85 return;
67 // TODO(oshima): Figure out bounds for default windows.
68 gfx::Rect viewport_bounds = owner_->bounds();
69 86
70 // A window can still be placed outside of the screen. 87 // If a drag window is requesting bounds, make sure its attached to
71 requested_bounds->SetRect( 88 // the workarea's top and fits within the total drag area.
72 requested_bounds->x(), 89 if (drag_window_) {
73 viewport_bounds.y(), 90 gfx::Rect drag_area = workspace_manager_->GetDragAreaBounds();
74 std::min(requested_bounds->width(), viewport_bounds.width()), 91 requested_bounds->set_y(drag_area.y());
75 std::min(requested_bounds->height(), viewport_bounds.height())); 92 *requested_bounds = requested_bounds->AdjustToFit(drag_area);
93 return;
94 }
95
96 Workspace* workspace = workspace_manager_->FindBy(child);
97 gfx::Rect work_area = workspace->GetWorkAreaBounds();
98 requested_bounds->set_origin(
99 gfx::Point(child->GetTargetBounds().x(), work_area.y()));
100 *requested_bounds = requested_bounds->AdjustToFit(work_area);
101 }
102
103 void DefaultContainerLayoutManager::PrepareForMoveOrResize(
104 aura::Window* drag, aura::MouseEvent* event) {
sky 2011/10/25 20:58:05 each param on its own line. This comment applies t
oshima 2011/10/25 23:37:23 Done.
105 drag_window_ = drag;
106 }
107
108 void DefaultContainerLayoutManager::CancelMoveOrResize(
109 aura::Window* drag, aura::MouseEvent* event) {
110 drag_window_ = NULL;
sky 2011/10/25 20:58:05 Does this need to revert to original position?
oshima 2011/10/25 23:37:23 We shouldn't have to do anything here because wind
111 }
112
113 void DefaultContainerLayoutManager::EndMove(
114 aura::Window* drag, aura::MouseEvent* evnet) {
115 // TODO(oshima): finish moving window between workspaces.
116 AutoReset<bool> reset(&layout_manager_has_control_, true);
117 drag_window_ = NULL;
118 Workspace* workspace = workspace_manager_->GetActiveWorkspace();
119 if (workspace)
120 workspace->Layout(NULL);
121 }
122
123 void DefaultContainerLayoutManager::EndResize(
124 aura::Window* drag, aura::MouseEvent* evnet) {
125 AutoReset<bool> reset(&layout_manager_has_control_, true);
126 drag_window_ = NULL;
127 Workspace* workspace = workspace_manager_->GetActiveWorkspace();
128 if (workspace)
129 workspace->Layout(NULL);
76 } 130 }
77 131
78 } // namespace internal 132 } // namespace internal
79 } // namespace aura_shell 133 } // namespace aura_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698