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

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: temporarily exlucde tests failing on win 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,
23 : owner_(owner) { 26 WorkspaceManager* workspace_manager)
27 : owner_(owner),
28 workspace_manager_(workspace_manager),
29 drag_window_(NULL),
30 ignore_calculate_bounds_(false) {
24 } 31 }
25 32
26 DefaultContainerLayoutManager::~DefaultContainerLayoutManager() {} 33 DefaultContainerLayoutManager::~DefaultContainerLayoutManager() {}
27 34
35 void DefaultContainerLayoutManager::PrepareForMoveOrResize(
36 aura::Window* drag,
37 aura::MouseEvent* event) {
38 drag_window_ = drag;
39 }
40
41 void DefaultContainerLayoutManager::CancelMoveOrResize(
42 aura::Window* drag,
43 aura::MouseEvent* event) {
44 drag_window_ = NULL;
45 }
46
47 void DefaultContainerLayoutManager::EndMove(
48 aura::Window* drag,
49 aura::MouseEvent* evnet) {
50 // TODO(oshima): finish moving window between workspaces.
51 AutoReset<bool> reset(&ignore_calculate_bounds_, true);
52 drag_window_ = NULL;
53 Workspace* workspace = workspace_manager_->GetActiveWorkspace();
54 if (workspace)
55 workspace->Layout(NULL);
56 }
57
58 void DefaultContainerLayoutManager::EndResize(
59 aura::Window* drag,
60 aura::MouseEvent* evnet) {
61 AutoReset<bool> reset(&ignore_calculate_bounds_, true);
62 drag_window_ = NULL;
63 Workspace* workspace = workspace_manager_->GetActiveWorkspace();
64 if (workspace)
65 workspace->Layout(NULL);
66 }
67
28 //////////////////////////////////////////////////////////////////////////////// 68 ////////////////////////////////////////////////////////////////////////////////
29 // DefaultContainerLayoutManager, aura::LayoutManager implementation: 69 // DefaultContainerLayoutManager, aura::LayoutManager implementation:
30 70
31 void DefaultContainerLayoutManager::OnWindowResized() { 71 void DefaultContainerLayoutManager::OnWindowResized() {
32 aura::Window::Windows::const_iterator i = owner_->children().begin(); 72 // Workspace is updated via DesktopObserver::OnDesktopResized.
33 // Use SetBounds because window may be maximized or fullscreen.
34 for (; i != owner_->children().end(); ++i) {
35 aura::Window* w = *i;
36 if (w->show_state() == ui::SHOW_STATE_MAXIMIZED)
37 w->Maximize();
38 else if (w->show_state() == ui::SHOW_STATE_FULLSCREEN)
39 w->Fullscreen();
40 else
41 w->SetBounds(w->bounds());
42 }
43 NOTIMPLEMENTED();
44 } 73 }
45 74
46 void DefaultContainerLayoutManager::OnWindowAdded(aura::Window* child) { 75 void DefaultContainerLayoutManager::OnWindowAdded(aura::Window* child) {
47 child->SetBounds(child->bounds()); 76 intptr_t type = reinterpret_cast<intptr_t>(
48 NOTIMPLEMENTED(); 77 ui::ViewProp::GetValue(child, views::NativeWidgetAura::kWindowTypeKey));
78 if (type != views::Widget::InitParams::TYPE_WINDOW)
79 return;
80
81 AutoReset<bool> reset(&ignore_calculate_bounds_, true);
82
83 Workspace* workspace = workspace_manager_->GetActiveWorkspace();
84 if (workspace) {
85 aura::Window* active = aura::Desktop::GetInstance()->active_window();
86 // Active window may not be in the default container layer.
87 if (!workspace->Contains(active))
88 active = NULL;
89 if (workspace->AddWindowAfter(child, active))
90 return;
91 }
92 // Create new workspace if new |child| doesn't fit to current workspace.
93 Workspace* new_workspace = workspace_manager_->CreateWorkspace();
94 new_workspace->AddWindowAfter(child, NULL);
95 new_workspace->Activate();
49 } 96 }
50 97
51 void DefaultContainerLayoutManager::OnWillRemoveWindow(aura::Window* child) { 98 void DefaultContainerLayoutManager::OnWillRemoveWindow(aura::Window* child) {
52 NOTIMPLEMENTED(); 99 AutoReset<bool> reset(&ignore_calculate_bounds_, true);
100 Workspace* workspace = workspace_manager_->FindBy(child);
101 if (!workspace)
102 return;
103 workspace->RemoveWindow(child);
104 if (workspace->is_empty())
105 delete workspace;
53 } 106 }
54 107
55 void DefaultContainerLayoutManager::OnChildWindowVisibilityChanged( 108 void DefaultContainerLayoutManager::OnChildWindowVisibilityChanged(
56 aura::Window* window, bool visibile) { 109 aura::Window* child,
110 bool visible) {
57 NOTIMPLEMENTED(); 111 NOTIMPLEMENTED();
58 } 112 }
59 113
60 void DefaultContainerLayoutManager::CalculateBoundsForChild( 114 void DefaultContainerLayoutManager::CalculateBoundsForChild(
61 aura::Window* child, gfx::Rect* requested_bounds) { 115 aura::Window* child,
116 gfx::Rect* requested_bounds) {
62 intptr_t type = reinterpret_cast<intptr_t>( 117 intptr_t type = reinterpret_cast<intptr_t>(
63 ui::ViewProp::GetValue(child, views::NativeWidgetAura::kWindowTypeKey)); 118 ui::ViewProp::GetValue(child, views::NativeWidgetAura::kWindowTypeKey));
64 // DCLM controls windows with a frame. 119 if (type != views::Widget::InitParams::TYPE_WINDOW ||
65 if (type != views::Widget::InitParams::TYPE_WINDOW) 120 ignore_calculate_bounds_)
66 return; 121 return;
67 // TODO(oshima): Figure out bounds for default windows.
68 gfx::Rect viewport_bounds = owner_->bounds();
69 122
70 // A window can still be placed outside of the screen. 123 // If a drag window is requesting bounds, make sure its attached to
71 requested_bounds->SetRect( 124 // the workarea's top and fits within the total drag area.
72 requested_bounds->x(), 125 if (drag_window_) {
73 viewport_bounds.y(), 126 gfx::Rect drag_area = workspace_manager_->GetDragAreaBounds();
74 std::min(requested_bounds->width(), viewport_bounds.width()), 127 requested_bounds->set_y(drag_area.y());
75 std::min(requested_bounds->height(), viewport_bounds.height())); 128 *requested_bounds = requested_bounds->AdjustToFit(drag_area);
129 return;
130 }
131
132 Workspace* workspace = workspace_manager_->FindBy(child);
133 gfx::Rect work_area = workspace->GetWorkAreaBounds();
134 requested_bounds->set_origin(
135 gfx::Point(child->GetTargetBounds().x(), work_area.y()));
136 *requested_bounds = requested_bounds->AdjustToFit(work_area);
76 } 137 }
77 138
78 } // namespace internal 139 } // namespace internal
79 } // namespace aura_shell 140 } // namespace aura_shell
OLDNEW
« no previous file with comments | « ui/aura_shell/default_container_layout_manager.h ('k') | ui/aura_shell/default_container_layout_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698