Chromium Code Reviews| Index: ui/aura_shell/default_container_layout_manager.cc |
| diff --git a/ui/aura_shell/default_container_layout_manager.cc b/ui/aura_shell/default_container_layout_manager.cc |
| index 264c532e0aa12becfd0fb5b83bf2f6b7329b08c1..e42fb5590c5afd28b54fa758f4cd5341581335fb 100644 |
| --- a/ui/aura_shell/default_container_layout_manager.cc |
| +++ b/ui/aura_shell/default_container_layout_manager.cc |
| @@ -4,10 +4,13 @@ |
| #include "ui/aura_shell/default_container_layout_manager.h" |
| +#include "base/auto_reset.h" |
| #include "ui/aura/desktop.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/base/view_prop.h" |
| #include "ui/gfx/rect.h" |
| #include "views/widget/native_widget_aura.h" |
| @@ -19,8 +22,11 @@ namespace internal { |
| // DefaultContainerLayoutManager, public: |
| DefaultContainerLayoutManager::DefaultContainerLayoutManager( |
| - aura::Window* owner) |
| - : owner_(owner) { |
| + 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
|
| + : owner_(owner), |
| + workspace_manager_(workspace_manager), |
| + drag_window_(NULL), |
| + layout_manager_has_control_(false) { |
| } |
| DefaultContainerLayoutManager::~DefaultContainerLayoutManager() {} |
| @@ -29,31 +35,44 @@ DefaultContainerLayoutManager::~DefaultContainerLayoutManager() {} |
| // DefaultContainerLayoutManager, aura::LayoutManager implementation: |
| void DefaultContainerLayoutManager::OnWindowResized() { |
| - aura::Window::Windows::const_iterator i = owner_->children().begin(); |
| - // Use SetBounds because window may be maximized or fullscreen. |
| - for (; i != owner_->children().end(); ++i) { |
| - aura::Window* w = *i; |
| - if (w->show_state() == ui::SHOW_STATE_MAXIMIZED) |
| - w->Maximize(); |
| - else if (w->show_state() == ui::SHOW_STATE_FULLSCREEN) |
| - w->Fullscreen(); |
| - else |
| - w->SetBounds(w->bounds()); |
| - } |
| - NOTIMPLEMENTED(); |
| + // Workspace is updated via DesktopObserver::OnDesktopResized. |
| } |
| void DefaultContainerLayoutManager::OnWindowAdded(aura::Window* child) { |
| - child->SetBounds(child->bounds()); |
| - NOTIMPLEMENTED(); |
| + intptr_t type = reinterpret_cast<intptr_t>( |
| + ui::ViewProp::GetValue(child, views::NativeWidgetAura::kWindowTypeKey)); |
| + if (type != views::Widget::InitParams::TYPE_WINDOW) |
| + return; |
| + |
| + AutoReset<bool> reset(&layout_manager_has_control_, 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) { |
| - NOTIMPLEMENTED(); |
| + AutoReset<bool> reset(&layout_manager_has_control_, true); |
| + Workspace* workspace = workspace_manager_->FindBy(child); |
| + if (!workspace) |
| + return; |
| + workspace->RemoveWindow(child); |
| + if (workspace->is_empty()) |
| + delete workspace; |
| } |
| void DefaultContainerLayoutManager::OnChildWindowVisibilityChanged( |
| - aura::Window* window, bool visibile) { |
| + aura::Window* child, bool visible) { |
| NOTIMPLEMENTED(); |
| } |
| @@ -61,18 +80,53 @@ void DefaultContainerLayoutManager::CalculateBoundsForChild( |
| 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.
|
| intptr_t type = reinterpret_cast<intptr_t>( |
| ui::ViewProp::GetValue(child, views::NativeWidgetAura::kWindowTypeKey)); |
| - // DCLM controls windows with a frame. |
| - if (type != views::Widget::InitParams::TYPE_WINDOW) |
| + if (type != views::Widget::InitParams::TYPE_WINDOW || |
| + layout_manager_has_control_) |
| return; |
| - // TODO(oshima): Figure out bounds for default windows. |
| - gfx::Rect viewport_bounds = owner_->bounds(); |
| - |
| - // A window can still be placed outside of the screen. |
| - requested_bounds->SetRect( |
| - requested_bounds->x(), |
| - viewport_bounds.y(), |
| - std::min(requested_bounds->width(), viewport_bounds.width()), |
| - std::min(requested_bounds->height(), viewport_bounds.height())); |
| + |
| + // 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); |
| +} |
| + |
| +void DefaultContainerLayoutManager::PrepareForMoveOrResize( |
| + 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.
|
| + drag_window_ = drag; |
| +} |
| + |
| +void DefaultContainerLayoutManager::CancelMoveOrResize( |
| + aura::Window* drag, aura::MouseEvent* event) { |
| + 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
|
| +} |
| + |
| +void DefaultContainerLayoutManager::EndMove( |
| + aura::Window* drag, aura::MouseEvent* evnet) { |
| + // TODO(oshima): finish moving window between workspaces. |
| + AutoReset<bool> reset(&layout_manager_has_control_, true); |
| + drag_window_ = NULL; |
| + Workspace* workspace = workspace_manager_->GetActiveWorkspace(); |
| + if (workspace) |
| + workspace->Layout(NULL); |
| +} |
| + |
| +void DefaultContainerLayoutManager::EndResize( |
| + aura::Window* drag, aura::MouseEvent* evnet) { |
| + AutoReset<bool> reset(&layout_manager_has_control_, true); |
| + drag_window_ = NULL; |
| + Workspace* workspace = workspace_manager_->GetActiveWorkspace(); |
| + if (workspace) |
| + workspace->Layout(NULL); |
| } |
| } // namespace internal |