diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-23 16:34:51 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-23 16:34:51 +0000 |
commit | a3301dc481459341169381ed35cd20f5022823b2 (patch) | |
tree | 5b421cde79989939edc925bde317884783cef4ca /ui/aura_shell | |
parent | 5bb69ef0273481de128dfa9f3f4753db3e6e1f92 (diff) | |
download | chromium_src-a3301dc481459341169381ed35cd20f5022823b2.zip chromium_src-a3301dc481459341169381ed35cd20f5022823b2.tar.gz chromium_src-a3301dc481459341169381ed35cd20f5022823b2.tar.bz2 |
Move some more WM functionality down into ash.
http://crbug.com/108457
TEST=none
TBR=sky
Review URL: http://codereview.chromium.org/9035001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@115721 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/aura_shell')
42 files changed, 47 insertions, 5281 deletions
diff --git a/ui/aura_shell/aura_shell.gyp b/ui/aura_shell/aura_shell.gyp index 1e1d9a1..e820aa5 100644 --- a/ui/aura_shell/aura_shell.gyp +++ b/ui/aura_shell/aura_shell.gyp @@ -60,16 +60,8 @@ 'compact_layout_manager.h', 'compact_status_area_layout_manager.cc', 'compact_status_area_layout_manager.h', - 'default_container_event_filter.cc', - 'default_container_event_filter.h', - 'default_container_layout_manager.cc', - 'default_container_layout_manager.h', 'desktop_background_view.cc', 'desktop_background_view.h', - 'root_window_event_filter.cc', - 'root_window_event_filter.h', - 'root_window_layout_manager.cc', - 'root_window_layout_manager.h', 'drag_drop_controller.cc', 'drag_drop_controller.h', 'drag_image_view.cc', @@ -90,8 +82,6 @@ 'launcher/view_model.h', 'launcher/view_model_utils.cc', 'launcher/view_model_utils.h', - 'property_util.cc', - 'property_util.h', 'shelf_layout_manager.cc', 'shelf_layout_manager.h', 'shell.cc', @@ -109,29 +99,14 @@ 'status_area_view.h', 'tooltip_controller.cc', 'tooltip_controller.h', - 'toplevel_frame_view.cc', - 'toplevel_frame_view.h', - 'toplevel_layout_manager.cc', - 'toplevel_layout_manager.h', - 'toplevel_window_event_filter.cc', - 'toplevel_window_event_filter.h', - 'window_frame.cc', - 'window_frame.h', - 'window_properties.cc', - 'window_properties.h', - 'window_util.cc', - 'window_util.h', - 'workspace_controller.cc', - 'workspace_controller.h', - 'workspace/workspace.cc', - 'workspace/workspace.h', - 'workspace/workspace_manager.cc', - 'workspace/workspace_manager.h', - 'workspace/workspace_observer.h', '../../ash/wm/activation_controller.cc', '../../ash/wm/activation_controller.h', '../../ash/wm/always_on_top_controller.cc', '../../ash/wm/always_on_top_controller.h', + '../../ash/wm/default_container_event_filter.cc', + '../../ash/wm/default_container_event_filter.h', + '../../ash/wm/default_container_layout_manager.cc', + '../../ash/wm/default_container_layout_manager.h', '../../ash/wm/image_grid.cc', '../../ash/wm/image_grid.h', '../../ash/wm/modal_container_layout_manager.cc', @@ -139,6 +114,12 @@ '../../ash/wm/modality_event_filter.cc', '../../ash/wm/modality_event_filter.h', '../../ash/wm/modality_event_filter_delegate.h', + '../../ash/wm/property_util.cc', + '../../ash/wm/property_util.h', + '../../ash/wm/root_window_event_filter.cc', + '../../ash/wm/root_window_event_filter.h', + '../../ash/wm/root_window_layout_manager.cc', + '../../ash/wm/root_window_layout_manager.h', '../../ash/wm/shadow.cc', '../../ash/wm/shadow.h', '../../ash/wm/shadow_controller.cc', @@ -149,6 +130,25 @@ '../../ash/wm/show_state_controller.cc', '../../ash/wm/stacking_controller.cc', '../../ash/wm/stacking_controller.h', + '../../ash/wm/toplevel_frame_view.cc', + '../../ash/wm/toplevel_frame_view.h', + '../../ash/wm/toplevel_layout_manager.cc', + '../../ash/wm/toplevel_layout_manager.h', + '../../ash/wm/toplevel_window_event_filter.cc', + '../../ash/wm/toplevel_window_event_filter.h', + '../../ash/wm/window_frame.cc', + '../../ash/wm/window_frame.h', + '../../ash/wm/window_properties.cc', + '../../ash/wm/window_properties.h', + '../../ash/wm/window_util.cc', + '../../ash/wm/window_util.h', + '../../ash/wm/workspace_controller.cc', + '../../ash/wm/workspace_controller.h', + '../../ash/wm/workspace/workspace.cc', + '../../ash/wm/workspace/workspace.h', + '../../ash/wm/workspace/workspace_manager.cc', + '../../ash/wm/workspace/workspace_manager.h', + '../../ash/wm/workspace/workspace_observer.h', ], }, { @@ -174,8 +174,6 @@ 'aura_shell', ], 'sources': [ - 'default_container_layout_manager_unittest.cc', - 'root_window_event_filter_unittest.cc', 'drag_drop_controller_unittest.cc', 'launcher/launcher_model_unittest.cc', 'launcher/launcher_unittest.cc', @@ -194,14 +192,16 @@ 'test/test_shell_delegate.cc', 'test/test_shell_delegate.h', 'tooltip_controller_unittest.cc', - 'toplevel_layout_manager_unittest.cc', - 'toplevel_window_event_filter_unittest.cc', - 'workspace_controller_unittest.cc', - 'workspace/workspace_manager_unittest.cc', '../../ash/wm/activation_controller_unittest.cc', + '../../ash/wm/default_container_layout_manager_unittest.cc', '../../ash/wm/image_grid_unittest.cc', '../../ash/wm/modal_container_layout_manager_unittest.cc', + '../../ash/wm/root_window_event_filter_unittest.cc', '../../ash/wm/shadow_controller_unittest.cc', + '../../ash/wm/toplevel_layout_manager_unittest.cc', + '../../ash/wm/toplevel_window_event_filter_unittest.cc', + '../../ash/wm/workspace_controller_unittest.cc', + '../../ash/wm/workspace/workspace_manager_unittest.cc', '<(SHARED_INTERMEDIATE_DIR)/ui/gfx/gfx_resources.rc', '<(SHARED_INTERMEDIATE_DIR)/ui/ui_resources/ui_resources.rc', diff --git a/ui/aura_shell/compact_layout_manager.cc b/ui/aura_shell/compact_layout_manager.cc index 059a478..98959d8 100644 --- a/ui/aura_shell/compact_layout_manager.cc +++ b/ui/aura_shell/compact_layout_manager.cc @@ -4,9 +4,9 @@ #include "ui/aura_shell/compact_layout_manager.h" +#include "ash/wm/window_util.h" #include "ui/aura/client/aura_constants.h" #include "ui/aura/window.h" -#include "ui/aura_shell/window_util.h" #include "ui/base/ui_base_types.h" #include "ui/gfx/screen.h" #include "ui/views/widget/widget.h" diff --git a/ui/aura_shell/default_container_event_filter.cc b/ui/aura_shell/default_container_event_filter.cc deleted file mode 100644 index b38c0cb..0000000 --- a/ui/aura_shell/default_container_event_filter.cc +++ /dev/null @@ -1,131 +0,0 @@ -// Copyright (c) 2011 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 "ui/aura_shell/default_container_event_filter.h" - -#include "ui/aura/event.h" -#include "ui/aura/window.h" -#include "ui/aura_shell/default_container_layout_manager.h" -#include "ui/aura_shell/window_frame.h" -#include "ui/aura_shell/window_util.h" -#include "ui/base/hit_test.h" - -namespace { - -// Sends OnWindowHoveredChanged(|hovered|) to the WindowFrame for |window|, -// which may be NULL. -void WindowHoverChanged(aura::Window* window, bool hovered) { - if (!window) - return; - aura_shell::WindowFrame* window_frame = - static_cast<aura_shell::WindowFrame*>( - window->GetProperty(aura_shell::kWindowFrameKey)); - if (!window_frame) - return; - window_frame->OnWindowHoverChanged(hovered); -} - -} // namespace - -namespace aura_shell { -namespace internal { - -DefaultContainerEventFilter::DefaultContainerEventFilter(aura::Window* owner) - : ToplevelWindowEventFilter(owner), - drag_state_(DRAG_NONE), - hovered_window_(NULL) { -} - -DefaultContainerEventFilter::~DefaultContainerEventFilter() { -} - -bool DefaultContainerEventFilter::PreHandleMouseEvent(aura::Window* target, - aura::MouseEvent* event) { - DefaultContainerLayoutManager* layout_manager = - static_cast<DefaultContainerLayoutManager*>(owner()->layout_manager()); - DCHECK(layout_manager); - - // TODO(oshima|derat): Incorporate the logic below and introduce DragObserver - // (or something similar) to decouple DCLM. - - // Notify layout manager that drag event may move/resize the target wnidow. - if (event->type() == ui::ET_MOUSE_DRAGGED && drag_state_ == DRAG_NONE) - layout_manager->PrepareForMoveOrResize(target, event); - - bool handled = ToplevelWindowEventFilter::PreHandleMouseEvent(target, event); - - switch (event->type()) { - case ui::ET_MOUSE_DRAGGED: - // Cancel move/resize if the event wasn't handled, or - // drag_state_ didn't move to MOVE or RESIZE. - if (handled) { - switch (drag_state_) { - case DRAG_NONE: - if (!UpdateDragState()) - layout_manager->CancelMoveOrResize(target, event); - break; - case DRAG_MOVE: - layout_manager->ProcessMove(target, event); - break; - case DRAG_RESIZE: - break; - } - } else { - layout_manager->CancelMoveOrResize(target, event); - } - break; - case ui::ET_MOUSE_ENTERED: - UpdateHoveredWindow(GetActivatableWindow(target)); - break; - case ui::ET_MOUSE_EXITED: - UpdateHoveredWindow(NULL); - break; - case ui::ET_MOUSE_RELEASED: - if (drag_state_ == DRAG_MOVE) - layout_manager->EndMove(target, event); - else if (drag_state_ == DRAG_RESIZE) - layout_manager->EndResize(target, event); - - drag_state_ = DRAG_NONE; - break; - default: - break; - } - return handled; -} - -bool DefaultContainerEventFilter::UpdateDragState() { - DCHECK_EQ(DRAG_NONE, drag_state_); - switch (window_component()) { - case HTCAPTION: - drag_state_ = DRAG_MOVE; - break; - case HTTOP: - case HTTOPRIGHT: - case HTRIGHT: - case HTBOTTOMRIGHT: - case HTBOTTOM: - case HTBOTTOMLEFT: - case HTLEFT: - case HTTOPLEFT: - case HTGROWBOX: - drag_state_ = DRAG_RESIZE; - break; - default: - return false; - } - return true; -} - -void DefaultContainerEventFilter::UpdateHoveredWindow( - aura::Window* toplevel_window) { - if (toplevel_window == hovered_window_) - return; - WindowHoverChanged(hovered_window_, false); - hovered_window_ = toplevel_window; - WindowHoverChanged(hovered_window_, true); -} - -} // internal -} // aura_shell diff --git a/ui/aura_shell/default_container_event_filter.h b/ui/aura_shell/default_container_event_filter.h deleted file mode 100644 index a3c8d05..0000000 --- a/ui/aura_shell/default_container_event_filter.h +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (c) 2011 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. - -#ifndef UI_AURA_SHELL_DEFAULT_CONTAINER_EVENT_FILTER_H_ -#define UI_AURA_SHELL_DEFAULT_CONTAINER_EVENT_FILTER_H_ -#pragma once - -#include "ui/aura_shell/toplevel_window_event_filter.h" - -namespace aura { -class MouseEvent; -class Window; -} - -namespace aura_shell { -namespace internal { - -class DefaultContainerEventFilter : public ToplevelWindowEventFilter { - public: - explicit DefaultContainerEventFilter(aura::Window* owner); - virtual ~DefaultContainerEventFilter(); - - // Overridden from ToplevelWindowEventFilter: - virtual bool PreHandleMouseEvent(aura::Window* target, - aura::MouseEvent* event) OVERRIDE; - - private: - enum DragState { - DRAG_NONE, - DRAG_MOVE, - DRAG_RESIZE - }; - - // If the mouse is currently over a portion of the window that should - // trigger a drag or resize, drag_state_ is set appropriately and true - // is returned. If the mouse is not over a portion of the window that should - // trigger a more or resize, drag_state_ is not updated and false is returend. - bool UpdateDragState(); - - // Updates the top-level window under the mouse so that we can change - // the look of the caption area based on mouse-hover. - void UpdateHoveredWindow(aura::Window* toplevel); - - DragState drag_state_; - // Top-level window under the mouse cursor. - aura::Window* hovered_window_; - - DISALLOW_COPY_AND_ASSIGN(DefaultContainerEventFilter); -}; - -} // namespace internal -} // namespace aura_shell - -#endif // UI_AURA_SHELL_DEFAULT_CONTAINER_EVENT_FILTER_H_ diff --git a/ui/aura_shell/default_container_layout_manager.cc b/ui/aura_shell/default_container_layout_manager.cc deleted file mode 100644 index d2a911d..0000000 --- a/ui/aura_shell/default_container_layout_manager.cc +++ /dev/null @@ -1,190 +0,0 @@ -// Copyright (c) 2011 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 "ui/aura_shell/default_container_layout_manager.h" - -#include "ash/wm/show_state_controller.h" -#include "ui/aura/client/aura_constants.h" -#include "ui/aura/event.h" -#include "ui/aura/root_window.h" -#include "ui/aura/screen_aura.h" -#include "ui/aura/window.h" -#include "ui/aura/window_observer.h" -#include "ui/aura_shell/property_util.h" -#include "ui/aura_shell/window_util.h" -#include "ui/aura_shell/workspace/workspace.h" -#include "ui/aura_shell/workspace/workspace_manager.h" -#include "ui/base/ui_base_types.h" -#include "ui/gfx/rect.h" -#include "ui/views/widget/native_widget_aura.h" - -namespace aura_shell { -namespace internal { - -//////////////////////////////////////////////////////////////////////////////// -// DefaultContainerLayoutManager, public: - -DefaultContainerLayoutManager::DefaultContainerLayoutManager( - WorkspaceManager* workspace_manager) - : workspace_manager_(workspace_manager), - show_state_controller_(new ShowStateController(workspace_manager)) { -} - -DefaultContainerLayoutManager::~DefaultContainerLayoutManager() {} - -void DefaultContainerLayoutManager::PrepareForMoveOrResize( - aura::Window* drag, - aura::MouseEvent* event) { - workspace_manager_->set_ignored_window(drag); -} - -void DefaultContainerLayoutManager::CancelMoveOrResize( - aura::Window* drag, - aura::MouseEvent* event) { - workspace_manager_->set_ignored_window(NULL); -} - -void DefaultContainerLayoutManager::ProcessMove( - aura::Window* drag, - aura::MouseEvent* event) { - // TODO(oshima): Just zooming out may (and will) move/swap window without - // a users's intent. We probably should scroll viewport, but that may not - // be enough. See crbug.com/101826 for more discussion. - workspace_manager_->SetOverview(true); - - gfx::Point point_in_owner = event->location(); - aura::Window::ConvertPointToWindow( - drag, - workspace_manager_->contents_view(), - &point_in_owner); - // TODO(oshima): We should support simply moving to another - // workspace when the destination workspace has enough room to accomodate. - aura::Window* rotate_target = - workspace_manager_->FindRotateWindowForLocation(point_in_owner); - if (rotate_target) - workspace_manager_->RotateWindows(drag, rotate_target); -} - -void DefaultContainerLayoutManager::EndMove( - aura::Window* drag, - aura::MouseEvent* evnet) { - // TODO(oshima): finish moving window between workspaces. - workspace_manager_->set_ignored_window(NULL); - Workspace* workspace = workspace_manager_->FindBy(drag); - workspace->Layout(NULL); - workspace->Activate(); - workspace_manager_->SetOverview(false); -} - -void DefaultContainerLayoutManager::EndResize( - aura::Window* drag, - aura::MouseEvent* evnet) { - workspace_manager_->set_ignored_window(NULL); - Workspace* workspace = workspace_manager_->GetActiveWorkspace(); - if (workspace) - workspace->Layout(NULL); - workspace_manager_->SetOverview(false); -} - -//////////////////////////////////////////////////////////////////////////////// -// DefaultContainerLayoutManager, aura::LayoutManager implementation: - -void DefaultContainerLayoutManager::OnWindowResized() { - // Workspace is updated via RootWindowObserver::OnRootWindowResized. -} - -void DefaultContainerLayoutManager::OnWindowAddedToLayout(aura::Window* child) { - if (child->type() != aura::client::WINDOW_TYPE_NORMAL || - child->transient_parent()) { - return; - } - - if (!child->GetProperty(aura::client::kShowStateKey)) - child->SetIntProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); - - child->AddObserver(show_state_controller_.get()); - - Workspace* workspace = workspace_manager_->GetActiveWorkspace(); - if (workspace) { - aura::Window* active = aura_shell::GetActiveWindow(); - // 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::OnWillRemoveWindowFromLayout( - aura::Window* child) { - child->RemoveObserver(show_state_controller_.get()); - ClearRestoreBounds(child); - - Workspace* workspace = workspace_manager_->FindBy(child); - if (!workspace) - return; - workspace->RemoveWindow(child); - if (workspace->is_empty()) - delete workspace; -} - -void DefaultContainerLayoutManager::OnChildWindowVisibilityChanged( - aura::Window* child, - bool visible) { - NOTIMPLEMENTED(); -} - -void DefaultContainerLayoutManager::SetChildBounds( - aura::Window* child, - const gfx::Rect& requested_bounds) { - gfx::Rect adjusted_bounds = requested_bounds; - - // First, calculate the adjusted bounds. - if (child->type() != aura::client::WINDOW_TYPE_NORMAL || - workspace_manager_->layout_in_progress() || - child->transient_parent()) { - // Use the requested bounds as is. - } else if (child == workspace_manager_->ignored_window()) { - // If a drag window is requesting bounds, make sure its attached to - // the workarea's top and fits within the total drag area. - gfx::Rect drag_area = workspace_manager_->GetDragAreaBounds(); - adjusted_bounds.set_y(drag_area.y()); - adjusted_bounds = adjusted_bounds.AdjustToFit(drag_area); - } else { - Workspace* workspace = workspace_manager_->FindBy(child); - gfx::Rect work_area = workspace->GetWorkAreaBounds(); - adjusted_bounds.set_origin( - gfx::Point(child->GetTargetBounds().x(), work_area.y())); - adjusted_bounds = adjusted_bounds.AdjustToFit(work_area); - } - - ui::WindowShowState show_state = static_cast<ui::WindowShowState>( - child->GetIntProperty(aura::client::kShowStateKey)); - - // Second, check if the window is either maximized or in fullscreen mode. - if (show_state == ui::SHOW_STATE_MAXIMIZED || - show_state == ui::SHOW_STATE_FULLSCREEN) { - // If the request is not from workspace manager, - // remember the requested bounds. - if (!workspace_manager_->layout_in_progress()) - SetRestoreBounds(child, adjusted_bounds); - - Workspace* workspace = workspace_manager_->FindBy(child); - if (show_state == ui::SHOW_STATE_MAXIMIZED) - adjusted_bounds = workspace->GetWorkAreaBounds(); - else - adjusted_bounds = workspace->bounds(); - // Don't - if (child->GetTargetBounds() == adjusted_bounds) - return; - } - SetChildBoundsDirect(child, adjusted_bounds); -} - -} // namespace internal -} // namespace aura_shell diff --git a/ui/aura_shell/default_container_layout_manager.h b/ui/aura_shell/default_container_layout_manager.h deleted file mode 100644 index 7ac4b74..0000000 --- a/ui/aura_shell/default_container_layout_manager.h +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright (c) 2011 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. - -#ifndef UI_AURA_SHELL_DEFAULT_CONTAINER_LAYOUT_MANAGER_H_ -#define UI_AURA_SHELL_DEFAULT_CONTAINER_LAYOUT_MANAGER_H_ -#pragma once - -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "base/memory/scoped_ptr.h" -#include "ui/aura/layout_manager.h" -#include "ui/aura_shell/aura_shell_export.h" - -namespace aura { -class MouseEvent; -class Window; -} - -namespace gfx { -class Rect; -} - -namespace aura_shell { -namespace internal { - -class ShowStateController; -class WorkspaceManager; - -// LayoutManager for the default window container. -class AURA_SHELL_EXPORT DefaultContainerLayoutManager - : public aura::LayoutManager { - public: - explicit DefaultContainerLayoutManager(WorkspaceManager* workspace_manager); - virtual ~DefaultContainerLayoutManager(); - - // Returns the workspace manager for this container. - WorkspaceManager* workspace_manager() { - return workspace_manager_; - } - - // Invoked when a window receives drag event. - void PrepareForMoveOrResize(aura::Window* drag, aura::MouseEvent* event); - - // Invoked when a drag event didn't start any drag operation. - void CancelMoveOrResize(aura::Window* drag, aura::MouseEvent* event); - - // Invoked when a drag event moved the |window|. - void ProcessMove(aura::Window* window, aura::MouseEvent* event); - - // Invoked when a user finished moving window. - void EndMove(aura::Window* drag, aura::MouseEvent* evnet); - - // Invoked when a user finished resizing window. - void EndResize(aura::Window* drag, aura::MouseEvent* evnet); - - // Overridden from aura::LayoutManager: - virtual void OnWindowResized() OVERRIDE; - virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE; - virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE; - virtual void OnChildWindowVisibilityChanged(aura::Window* child, - bool visibile) OVERRIDE; - virtual void SetChildBounds(aura::Window* child, - const gfx::Rect& requested_bounds) OVERRIDE; - private: - // Owned by WorkspaceController. - WorkspaceManager* workspace_manager_; - - scoped_ptr<ShowStateController> show_state_controller_; - - DISALLOW_COPY_AND_ASSIGN(DefaultContainerLayoutManager); -}; - -} // namespace internal -} // namespace aura_shell - -#endif // UI_AURA_SHELL_DEFAULT_CONTAINER_LAYOUT_MANAGER_H_ diff --git a/ui/aura_shell/default_container_layout_manager_unittest.cc b/ui/aura_shell/default_container_layout_manager_unittest.cc deleted file mode 100644 index d9cb80c..0000000 --- a/ui/aura_shell/default_container_layout_manager_unittest.cc +++ /dev/null @@ -1,341 +0,0 @@ -// Copyright (c) 2011 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 "ui/aura_shell/default_container_layout_manager.h" - -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "base/memory/scoped_vector.h" -#include "ui/aura/client/aura_constants.h" -#include "ui/aura/root_window.h" -#include "ui/aura/screen_aura.h" -#include "ui/aura/test/aura_test_base.h" -#include "ui/aura/window.h" -#include "ui/aura_shell/workspace/workspace.h" -#include "ui/aura_shell/workspace/workspace_manager.h" -#include "ui/aura_shell/workspace_controller.h" -#include "ui/base/ui_base_types.h" -#include "ui/views/widget/native_widget_aura.h" - -namespace aura_shell { -namespace test { - -namespace { - -using views::Widget; -using aura_shell::internal::DefaultContainerLayoutManager; - -class DefaultContainerLayoutManagerTest : public aura::test::AuraTestBase { - public: - DefaultContainerLayoutManagerTest() : layout_manager_(NULL) {} - virtual ~DefaultContainerLayoutManagerTest() {} - - virtual void SetUp() OVERRIDE { - aura::test::AuraTestBase::SetUp(); - aura::RootWindow* root_window = aura::RootWindow::GetInstance(); - container_.reset( - CreateTestWindow(gfx::Rect(0, 0, 500, 400), root_window)); - workspace_controller_.reset( - new aura_shell::internal::WorkspaceController(container_.get())); - layout_manager_ = new DefaultContainerLayoutManager( - workspace_controller_->workspace_manager()); - container_->SetLayoutManager(layout_manager_); - - root_window->SetHostSize(gfx::Size(500, 400)); - } - - aura::Window* CreateTestWindowWithType(const gfx::Rect& bounds, - aura::Window* parent, - aura::client::WindowType type) { - aura::Window* window = new aura::Window(NULL); - window->SetType(type); - window->Init(ui::Layer::LAYER_HAS_NO_TEXTURE); - window->SetBounds(bounds); - window->Show(); - window->SetParent(parent); - return window; - } - - aura::Window* CreateTestWindow(const gfx::Rect& bounds, - aura::Window* parent) { - return CreateTestWindowWithType(bounds, - parent, - aura::client::WINDOW_TYPE_NORMAL); - } - - aura::Window* container() { return container_.get(); } - - DefaultContainerLayoutManager* default_container_layout_manager() { - return layout_manager_; - } - - protected: - aura_shell::internal::WorkspaceManager* workspace_manager() { - return workspace_controller_->workspace_manager(); - } - - private: - scoped_ptr<aura::Window> container_; - scoped_ptr<aura_shell::internal::WorkspaceController> workspace_controller_; - // LayoutManager is owned by |container|. - aura_shell::internal::DefaultContainerLayoutManager* layout_manager_; - - private: - DISALLOW_COPY_AND_ASSIGN(DefaultContainerLayoutManagerTest); -}; - -// Utility functions to set and get show state on |window|. -void Maximize(aura::Window* window) { - window->SetIntProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); -} - -void Fullscreen(aura::Window* window) { - window->SetIntProperty(aura::client::kShowStateKey, - ui::SHOW_STATE_FULLSCREEN); -} - -void Restore(aura::Window* window) { - window->SetIntProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); -} - -ui::WindowShowState GetShowState(aura::Window* window) { - return static_cast<ui::WindowShowState>( - window->GetIntProperty(aura::client::kShowStateKey)); -} - -} // namespace - -TEST_F(DefaultContainerLayoutManagerTest, SetBounds) { - // Layout Manager moves the window to (0,0) to fit to draggable area. - scoped_ptr<aura::Window> child( - CreateTestWindow(gfx::Rect(0, -1000, 100, 100), container())); - // Window is centered in workspace. - EXPECT_EQ("200,0 100x100", child->bounds().ToString()); - - // DCLM enforces the window height can't be taller than its owner's height. - child->SetBounds(gfx::Rect(0, 0, 100, 500)); - EXPECT_EQ("200,0 100x400", child->bounds().ToString()); - - // DCLM enforces the window width can't be wider than its owner's width. - child->SetBounds(gfx::Rect(0, 0, 900, 500)); - EXPECT_EQ("0,0 500x400", child->bounds().ToString()); - - // Y origin must always be the top of drag area. - child->SetBounds(gfx::Rect(0, 500, 900, 500)); - EXPECT_EQ("0,0 500x400", child->bounds().ToString()); - child->SetBounds(gfx::Rect(0, -500, 900, 500)); - EXPECT_EQ("0,0 500x400", child->bounds().ToString()); -} - -TEST_F(DefaultContainerLayoutManagerTest, DragWindow) { - scoped_ptr<aura::Window> child( - CreateTestWindow(gfx::Rect(0, -1000, 50, 50), container())); - gfx::Rect original_bounds = child->bounds(); - - default_container_layout_manager()->PrepareForMoveOrResize( - child.get(), NULL); - // X origin must fit within viewport. - child->SetBounds(gfx::Rect(-100, 500, 50, 50)); - EXPECT_EQ("0,0 50x50", child->GetTargetBounds().ToString()); - child->SetBounds(gfx::Rect(1000, 500, 50, 50)); - EXPECT_EQ("450,0 50x50", child->GetTargetBounds().ToString()); - default_container_layout_manager()->EndMove(child.get(), NULL); - EXPECT_EQ(original_bounds.ToString(), child->GetTargetBounds().ToString()); -} - -TEST_F(DefaultContainerLayoutManagerTest, Popup) { - scoped_ptr<aura::Window> popup( - CreateTestWindowWithType(gfx::Rect(0, -1000, 100, 100), - container(), - aura::client::WINDOW_TYPE_POPUP)); - // A popup window can be placed outside of draggable area. - EXPECT_EQ("0,-1000 100x100", popup->bounds().ToString()); - - // A popup window can be moved to outside of draggable area. - popup->SetBounds(gfx::Rect(-100, 0, 100, 100)); - EXPECT_EQ("-100,0 100x100", popup->bounds().ToString()); - - // A popup window can be resized to the size bigger than draggable area. - popup->SetBounds(gfx::Rect(0, 0, 1000, 1000)); - EXPECT_EQ("0,0 1000x1000", popup->bounds().ToString()); -} - -// Make sure a window with a transient parent isn't resized by the layout -// manager. -TEST_F(DefaultContainerLayoutManagerTest, IgnoreTransient) { - scoped_ptr<aura::Window> window(new aura::Window(NULL)); - window->SetType(aura::client::WINDOW_TYPE_NORMAL); - window->Init(ui::Layer::LAYER_HAS_NO_TEXTURE); - aura::RootWindow::GetInstance()->AddTransientChild(window.get()); - window->SetBounds(gfx::Rect(0, 0, 200, 200)); - window->Show(); - window->SetParent(container()); - - EXPECT_EQ("0,0 200x200", window->bounds().ToString()); -} - -TEST_F(DefaultContainerLayoutManagerTest, Fullscreen) { - scoped_ptr<aura::Window> w( - CreateTestWindow(gfx::Rect(0, 0, 100, 100), container())); - gfx::Rect fullscreen_bounds = - workspace_manager()->FindBy(w.get())->bounds(); - gfx::Rect original_bounds = w->GetTargetBounds(); - - // Restoreing the restored window. - Restore(w.get()); - EXPECT_EQ(ui::SHOW_STATE_NORMAL, GetShowState(w.get())); - EXPECT_EQ(original_bounds.ToString(), w->bounds().ToString()); - - // Fullscreen - Fullscreen(w.get()); - EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN, GetShowState(w.get())); - EXPECT_EQ(fullscreen_bounds.ToString(), w->bounds().ToString()); - w->SetIntProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); - EXPECT_EQ(ui::SHOW_STATE_NORMAL, GetShowState(w.get())); - EXPECT_EQ(original_bounds.ToString(), w->bounds().ToString()); - - Fullscreen(w.get()); - // Setting |ui::SHOW_STATE_FULLSCREEN| should have no additional effect. - Fullscreen(w.get()); - EXPECT_EQ(fullscreen_bounds, w->bounds()); - Restore(w.get()); - EXPECT_EQ(ui::SHOW_STATE_NORMAL, GetShowState(w.get())); - EXPECT_EQ(original_bounds.ToString(), w->bounds().ToString()); - - // Calling SetBounds() in fullscreen mode should only update the - // restore bounds not change the bounds of the window. - gfx::Rect new_bounds(50, 50, 50, 50); - Fullscreen(w.get()); - w->SetBounds(new_bounds); - EXPECT_EQ(fullscreen_bounds.ToString(), w->bounds().ToString()); - EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN, GetShowState(w.get())); - Restore(w.get()); - EXPECT_EQ(ui::SHOW_STATE_NORMAL, GetShowState(w.get())); - EXPECT_EQ(50, w->bounds().height()); -} - -TEST_F(DefaultContainerLayoutManagerTest, Maximized) { - scoped_ptr<aura::Window> w( - CreateTestWindow(gfx::Rect(0, 0, 100, 100), container())); - gfx::Rect original_bounds = w->GetTargetBounds(); - gfx::Rect fullscreen_bounds = - workspace_manager()->FindBy(w.get())->bounds(); - gfx::Rect work_area_bounds = - workspace_manager()->FindBy(w.get())->GetWorkAreaBounds(); - - // Maximized - Maximize(w.get()); - EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, GetShowState(w.get())); - EXPECT_EQ(work_area_bounds.ToString(), w->bounds().ToString()); - Restore(w.get()); - EXPECT_EQ(ui::SHOW_STATE_NORMAL, GetShowState(w.get())); - EXPECT_EQ(original_bounds.ToString(), w->bounds().ToString()); - - // Maximize twice - Maximize(w.get()); - Maximize(w.get()); - EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, GetShowState(w.get())); - EXPECT_EQ(work_area_bounds.ToString(), w->bounds().ToString()); - Restore(w.get()); - EXPECT_EQ(ui::SHOW_STATE_NORMAL, GetShowState(w.get())); - EXPECT_EQ(original_bounds.ToString(), w->bounds().ToString()); - - // Maximized -> Fullscreen -> Maximized -> Normal - Maximize(w.get()); - EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, GetShowState(w.get())); - EXPECT_EQ(work_area_bounds.ToString(), w->bounds().ToString()); - Fullscreen(w.get()); - EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN, GetShowState(w.get())); - EXPECT_EQ(fullscreen_bounds.ToString(), w->bounds().ToString()); - Maximize(w.get()); - EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, GetShowState(w.get())); - EXPECT_EQ(work_area_bounds.ToString(), w->bounds().ToString()); - Restore(w.get()); - EXPECT_EQ(ui::SHOW_STATE_NORMAL, GetShowState(w.get())); - EXPECT_EQ(original_bounds.ToString(), w->bounds().ToString()); - - // Calling SetBounds() in maximized mode mode should only update the - // restore bounds not change the bounds of the window. - gfx::Rect new_bounds(50, 50, 50, 50); - Maximize(w.get()); - w->SetBounds(new_bounds); - EXPECT_EQ(work_area_bounds.ToString(), w->bounds().ToString()); - Restore(w.get()); - EXPECT_EQ(ui::SHOW_STATE_NORMAL, GetShowState(w.get())); - EXPECT_EQ(50, w->bounds().height()); -} - -// Tests that fullscreen windows get resized after root window is resized. -TEST_F(DefaultContainerLayoutManagerTest, FullscreenAfterRootWindowResize) { - scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(300, 400), - container())); - gfx::Rect window_bounds = w1->GetTargetBounds(); - gfx::Rect fullscreen_bounds = - workspace_manager()->FindBy(w1.get())->bounds(); - - w1->Show(); - EXPECT_EQ(window_bounds.ToString(), w1->bounds().ToString()); - - Fullscreen(w1.get()); - EXPECT_EQ(fullscreen_bounds.ToString(), w1->bounds().ToString()); - - // Resize the root window. - aura::RootWindow* root_window = aura::RootWindow::GetInstance(); - gfx::Size new_root_window_size = root_window->GetHostSize(); - new_root_window_size.Enlarge(100, 200); - root_window->OnHostResized(new_root_window_size); - - gfx::Rect new_fullscreen_bounds = - workspace_manager()->FindBy(w1.get())->bounds(); - EXPECT_NE(fullscreen_bounds.size().ToString(), - new_fullscreen_bounds.size().ToString()); - - EXPECT_EQ(new_fullscreen_bounds.ToString(), - w1->GetTargetBounds().ToString()); - - Restore(w1.get()); - - // The following test does not pass due to crbug.com/102413. - // TODO(oshima): Re-enable this once the bug is fixed. - // EXPECT_EQ(window_bounds.size().ToString(), - // w1->GetTargetBounds().size().ToString()); -} - -// Tests that maximized windows get resized after root_window is resized. -TEST_F(DefaultContainerLayoutManagerTest, MaximizeAfterRootWindowResize) { - scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(300, 400), - container())); - gfx::Rect window_bounds = w1->GetTargetBounds(); - gfx::Rect work_area_bounds = - workspace_manager()->FindBy(w1.get())->GetWorkAreaBounds(); - - w1->Show(); - EXPECT_EQ(window_bounds.ToString(), w1->bounds().ToString()); - - Maximize(w1.get()); - EXPECT_EQ(work_area_bounds.ToString(), w1->bounds().ToString()); - - // Resize the root window. - aura::RootWindow* root_window = aura::RootWindow::GetInstance(); - gfx::Size new_root_window_size = root_window->GetHostSize(); - new_root_window_size.Enlarge(100, 200); - root_window->OnHostResized(new_root_window_size); - - gfx::Rect new_work_area_bounds = - workspace_manager()->FindBy(w1.get())->bounds(); - EXPECT_NE(work_area_bounds.size().ToString(), - new_work_area_bounds.size().ToString()); - - EXPECT_EQ(new_work_area_bounds.ToString(), - w1->GetTargetBounds().ToString()); - - Restore(w1.get()); - // The following test does not pass due to crbug.com/102413. - // TODO(oshima): Re-enable this once the bug is fixed. - // EXPECT_EQ(window_bounds.size().ToString(), - // w1->GetTargetBounds().size().ToString()); -} - -} // namespace test -} // namespace aura_shell diff --git a/ui/aura_shell/drag_drop_controller_unittest.cc b/ui/aura_shell/drag_drop_controller_unittest.cc index 7e55f97..b7022f2 100644 --- a/ui/aura_shell/drag_drop_controller_unittest.cc +++ b/ui/aura_shell/drag_drop_controller_unittest.cc @@ -4,11 +4,11 @@ #include "ui/aura_shell/drag_drop_controller.h" +#include "ash/wm/root_window_event_filter.h" #include "base/location.h" #include "base/utf_string_conversions.h" #include "ui/aura/event.h" #include "ui/aura/root_window.h" -#include "ui/aura_shell/root_window_event_filter.h" #include "ui/aura_shell/test/aura_shell_test_base.h" #include "ui/base/dragdrop/drag_drop_types.h" #include "ui/base/dragdrop/os_exchange_data.h" diff --git a/ui/aura_shell/property_util.cc b/ui/aura_shell/property_util.cc deleted file mode 100644 index 6026b99..0000000 --- a/ui/aura_shell/property_util.cc +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) 2011 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 "ui/aura_shell/property_util.h" - -#include "ui/aura/client/aura_constants.h" -#include "ui/aura/window.h" -#include "ui/base/ui_base_types.h" -#include "ui/gfx/rect.h" - -namespace aura_shell { - -void SetRestoreBounds(aura::Window* window, const gfx::Rect& bounds) { - delete GetRestoreBounds(window); - window->SetProperty(aura::client::kRestoreBoundsKey, new gfx::Rect(bounds)); -} - -void SetRestoreBoundsIfNotSet(aura::Window* window) { - if (!GetRestoreBounds(window)) - SetRestoreBounds(window, window->bounds()); -} - -const gfx::Rect* GetRestoreBounds(aura::Window* window) { - return reinterpret_cast<gfx::Rect*>( - window->GetProperty(aura::client::kRestoreBoundsKey)); -} - -void ClearRestoreBounds(aura::Window* window) { - delete GetRestoreBounds(window); - window->SetProperty(aura::client::kRestoreBoundsKey, NULL); -} - -} diff --git a/ui/aura_shell/property_util.h b/ui/aura_shell/property_util.h deleted file mode 100644 index bfd9345..0000000 --- a/ui/aura_shell/property_util.h +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (c) 2011 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. - -#ifndef UI_AURA_SHELL_PROPERTY_UTIL_H_ -#define UI_AURA_SHELL_PROPERTY_UTIL_H_ -#pragma once - -namespace aura { -class Window; -} - -namespace gfx { -class Rect; -} - -namespace aura_shell { - -// Sets the restore bounds property on |window|. Deletes existing bounds value -// if exists. -void SetRestoreBounds(aura::Window* window, const gfx::Rect& bounds); - -// Same as SetRestoreBounds(), but does nothing if the restore bounds have -// already been set. The bounds used are the bounds of the window. -void SetRestoreBoundsIfNotSet(aura::Window* window); - -// Returns the restore bounds property on |window|. NULL if the -// restore bounds property does not exist for |window|. |window| -// owns the bounds object. -const gfx::Rect* GetRestoreBounds(aura::Window* window); - -// Deletes and clears the restore bounds property on |window|. -void ClearRestoreBounds(aura::Window* window); - -} - -#endif // UI_AURA_SHELL_PROPERTY_UTIL_H_ diff --git a/ui/aura_shell/root_window_event_filter.cc b/ui/aura_shell/root_window_event_filter.cc deleted file mode 100644 index 6b4fa8e..0000000 --- a/ui/aura_shell/root_window_event_filter.cc +++ /dev/null @@ -1,168 +0,0 @@ -// Copyright (c) 2011 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 "ui/aura_shell/root_window_event_filter.h" - -#include "ash/wm/activation_controller.h" -#include "ui/aura/event.h" -#include "ui/aura/focus_manager.h" -#include "ui/aura/root_window.h" -#include "ui/aura/window_delegate.h" -#include "ui/aura_shell/shell.h" -#include "ui/aura_shell/window_util.h" -#include "ui/base/hit_test.h" - -namespace aura_shell { -namespace internal { - -// Returns the default cursor for a window component. -gfx::NativeCursor CursorForWindowComponent(int window_component) { - switch (window_component) { - case HTBOTTOM: - return aura::kCursorSouthResize; - case HTBOTTOMLEFT: - return aura::kCursorSouthWestResize; - case HTBOTTOMRIGHT: - return aura::kCursorSouthEastResize; - case HTLEFT: - return aura::kCursorWestResize; - case HTRIGHT: - return aura::kCursorEastResize; - case HTTOP: - return aura::kCursorNorthResize; - case HTTOPLEFT: - return aura::kCursorNorthWestResize; - case HTTOPRIGHT: - return aura::kCursorNorthEastResize; - default: - return aura::kCursorNull; - } -} - -//////////////////////////////////////////////////////////////////////////////// -// RootWindowEventFilter, public: - -RootWindowEventFilter::RootWindowEventFilter() - : EventFilter(aura::RootWindow::GetInstance()) { -} - -RootWindowEventFilter::~RootWindowEventFilter() { - // Additional filters are not owned by RootWindowEventFilter and they - // should all be removed when running here. |filters_| has - // check_empty == true and will DCHECK failure if it is not empty. -} - -void RootWindowEventFilter::AddFilter(aura::EventFilter* filter) { - filters_.AddObserver(filter); -} - -void RootWindowEventFilter::RemoveFilter(aura::EventFilter* filter) { - filters_.RemoveObserver(filter); -} - -//////////////////////////////////////////////////////////////////////////////// -// RootWindowEventFilter, EventFilter implementation: - -bool RootWindowEventFilter::PreHandleKeyEvent(aura::Window* target, - aura::KeyEvent* event) { - return FilterKeyEvent(target, event); -} - -bool RootWindowEventFilter::PreHandleMouseEvent(aura::Window* target, - aura::MouseEvent* event) { - // We must always update the cursor, otherwise the cursor can get stuck if an - // event filter registered with us consumes the event. - if (event->type() == ui::ET_MOUSE_MOVED) { - // Shows the cursor when mouse moved. - SetCursorVisible(target, event, true); - - UpdateCursor(target, event); - } - - if (FilterMouseEvent(target, event)) - return true; - - if (event->type() == ui::ET_MOUSE_PRESSED) - target->GetFocusManager()->SetFocusedWindow(target); - - return false; -} - -ui::TouchStatus RootWindowEventFilter::PreHandleTouchEvent( - aura::Window* target, - aura::TouchEvent* event) { - ui::TouchStatus status = FilterTouchEvent(target, event); - if (status != ui::TOUCH_STATUS_UNKNOWN) - return status; - - if (event->type() == ui::ET_TOUCH_PRESSED) { - // Hides the cursor when touch pressed. - SetCursorVisible(target, event, false); - - target->GetFocusManager()->SetFocusedWindow(target); - } - return ui::TOUCH_STATUS_UNKNOWN; -} - -//////////////////////////////////////////////////////////////////////////////// -// RootWindowEventFilter, private: - -void RootWindowEventFilter::UpdateCursor(aura::Window* target, - aura::MouseEvent* event) { - gfx::NativeCursor cursor = target->GetCursor(event->location()); - if (event->flags() & ui::EF_IS_NON_CLIENT) { - int window_component = - target->delegate()->GetNonClientComponent(event->location()); - cursor = CursorForWindowComponent(window_component); - } - aura::RootWindow::GetInstance()->SetCursor(cursor); -} - -void RootWindowEventFilter::SetCursorVisible(aura::Window* target, - aura::LocatedEvent* event, - bool show) { - aura::RootWindow::GetInstance()->ShowCursor(show); -} - -bool RootWindowEventFilter::FilterKeyEvent(aura::Window* target, - aura::KeyEvent* event) { - bool handled = false; - if (filters_.might_have_observers()) { - ObserverListBase<aura::EventFilter>::Iterator it(filters_); - aura::EventFilter* filter; - while (!handled && (filter = it.GetNext()) != NULL) - handled = filter->PreHandleKeyEvent(target, event); - } - return handled; -} - -bool RootWindowEventFilter::FilterMouseEvent(aura::Window* target, - aura::MouseEvent* event) { - bool handled = false; - if (filters_.might_have_observers()) { - ObserverListBase<aura::EventFilter>::Iterator it(filters_); - aura::EventFilter* filter; - while (!handled && (filter = it.GetNext()) != NULL) - handled = filter->PreHandleMouseEvent(target, event); - } - return handled; -} - -ui::TouchStatus RootWindowEventFilter::FilterTouchEvent( - aura::Window* target, - aura::TouchEvent* event) { - ui::TouchStatus status = ui::TOUCH_STATUS_UNKNOWN; - if (filters_.might_have_observers()) { - ObserverListBase<aura::EventFilter>::Iterator it(filters_); - aura::EventFilter* filter; - while (status == ui::TOUCH_STATUS_UNKNOWN && - (filter = it.GetNext()) != NULL) { - status = filter->PreHandleTouchEvent(target, event); - } - } - return status; -} - -} // namespace internal -} // namespace aura_shell diff --git a/ui/aura_shell/root_window_event_filter.h b/ui/aura_shell/root_window_event_filter.h deleted file mode 100644 index 9c0e61b..0000000 --- a/ui/aura_shell/root_window_event_filter.h +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright (c) 2011 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. - -#ifndef UI_AURA_SHELL_ROOT_WINDOW_EVENT_FILTER_H_ -#define UI_AURA_SHELL_ROOT_WINDOW_EVENT_FILTER_H_ -#pragma once - -#include "base/compiler_specific.h" -#include "base/observer_list.h" -#include "ui/aura/event.h" -#include "ui/aura/event_filter.h" -#include "ui/aura_shell/aura_shell_export.h" - -namespace aura_shell { -namespace internal { - -// RootWindowEventFilter gets all root window events first and can provide -// actions to those events. It implements root window features such as click to -// activate a window and cursor change when moving mouse. -// Additional event filters can be added to RootWIndowEventFilter. Events will -// pass through those additional filters in their addition order and could be -// consumed by any of those filters. If an event is consumed by a filter, the -// rest of the filter(s) and RootWindowEventFilter will not see the consumed -// event. -class AURA_SHELL_EXPORT RootWindowEventFilter : public aura::EventFilter { - public: - RootWindowEventFilter(); - virtual ~RootWindowEventFilter(); - - // Adds/removes additional event filters. - void AddFilter(aura::EventFilter* filter); - void RemoveFilter(aura::EventFilter* filter); - - // Overridden from EventFilter: - virtual bool PreHandleKeyEvent(aura::Window* target, - aura::KeyEvent* event) OVERRIDE; - virtual bool PreHandleMouseEvent(aura::Window* target, - aura::MouseEvent* event) OVERRIDE; - virtual ui::TouchStatus PreHandleTouchEvent(aura::Window* target, - aura::TouchEvent* event) OVERRIDE; - - private: - // Updates the cursor if the target provides a custom one, and provides - // default resize cursors for window edges. - void UpdateCursor(aura::Window* target, aura::MouseEvent* event); - - // Sets the cursor invisible when the target receives touch press event. - void SetCursorVisible(aura::Window* target, - aura::LocatedEvent* event, - bool show); - - // Dispatches event to additional filters. Returns false or - // ui::TOUCH_STATUS_UNKNOWN if event is consumed. - bool FilterKeyEvent(aura::Window* target, aura::KeyEvent* event); - bool FilterMouseEvent(aura::Window* target, aura::MouseEvent* event); - ui::TouchStatus FilterTouchEvent(aura::Window* target, - aura::TouchEvent* event); - - // Additional event filters that pre-handles events. - ObserverList<aura::EventFilter, true> filters_; - - DISALLOW_COPY_AND_ASSIGN(RootWindowEventFilter); -}; - -} // namespace internal -} // namespace aura_shell - -#endif // UI_AURA_SHELL_ROOT_WINDOW_EVENT_FILTER_H_ diff --git a/ui/aura_shell/root_window_event_filter_unittest.cc b/ui/aura_shell/root_window_event_filter_unittest.cc deleted file mode 100644 index 9b2a380..0000000 --- a/ui/aura_shell/root_window_event_filter_unittest.cc +++ /dev/null @@ -1,451 +0,0 @@ -// Copyright (c) 2011 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 "ui/aura_shell/root_window_event_filter.h" - -#include "ash/wm/activation_controller.h" -#include "ui/aura/client/activation_delegate.h" -#include "ui/aura/cursor.h" -#include "ui/aura/event.h" -#include "ui/aura/root_window.h" -#include "ui/aura/test/aura_test_base.h" -#include "ui/aura/test/event_generator.h" -#include "ui/aura/test/test_windows.h" -#include "ui/aura/test/test_event_filter.h" -#include "ui/aura/test/test_window_delegate.h" -#include "ui/aura_shell/shell_window_ids.h" -#include "ui/aura_shell/test/test_activation_delegate.h" -#include "ui/aura_shell/window_util.h" -#include "ui/base/hit_test.h" -#include "ui/gfx/screen.h" - -namespace aura_shell { -namespace test { - -class RootWindowEventFilterTest : public aura::test::AuraTestBase { - public: - RootWindowEventFilterTest() { - aura::RootWindow::GetInstance()->SetEventFilter( - new internal::RootWindowEventFilter); - - aura::RootWindow::GetInstance()->set_id( - internal::kShellWindowId_DefaultContainer); - activation_controller_.reset(new internal::ActivationController); - activation_controller_->set_default_container_for_test( - aura::RootWindow::GetInstance()); - } - virtual ~RootWindowEventFilterTest() { - aura::RootWindow::GetInstance()->SetEventFilter(NULL); - } - - private: - scoped_ptr<internal::ActivationController> activation_controller_; - - DISALLOW_COPY_AND_ASSIGN(RootWindowEventFilterTest); -}; - -class HitTestWindowDelegate : public aura::test::TestWindowDelegate { - public: - HitTestWindowDelegate() - : hittest_code_(HTNOWHERE) { - } - virtual ~HitTestWindowDelegate() {} - void set_hittest_code(int hittest_code) { hittest_code_ = hittest_code; } - - private: - // Overridden from TestWindowDelegate: - virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE { - return hittest_code_; - } - - int hittest_code_; - - DISALLOW_COPY_AND_ASSIGN(HitTestWindowDelegate); -}; - -TEST_F(RootWindowEventFilterTest, Focus) { - aura::RootWindow* root_window = aura::RootWindow::GetInstance(); - root_window->SetBounds(gfx::Rect(0, 0, 510, 510)); - - // Supplied ids are negative so as not to collide with shell ids. - // TODO(beng): maybe introduce a MAKE_SHELL_ID() macro that generates a safe - // id beyond shell id max? - scoped_ptr<aura::Window> w1(aura::test::CreateTestWindow( - SK_ColorWHITE, -1, gfx::Rect(10, 10, 500, 500), NULL)); - scoped_ptr<aura::Window> w11(aura::test::CreateTestWindow( - SK_ColorGREEN, -11, gfx::Rect(5, 5, 100, 100), w1.get())); - scoped_ptr<aura::Window> w111(aura::test::CreateTestWindow( - SK_ColorCYAN, -111, gfx::Rect(5, 5, 75, 75), w11.get())); - scoped_ptr<aura::Window> w1111(aura::test::CreateTestWindow( - SK_ColorRED, -1111, gfx::Rect(5, 5, 50, 50), w111.get())); - scoped_ptr<aura::Window> w12(aura::test::CreateTestWindow( - SK_ColorMAGENTA, -12, gfx::Rect(10, 420, 25, 25), w1.get())); - aura::test::ColorTestWindowDelegate* w121delegate = - new aura::test::ColorTestWindowDelegate(SK_ColorYELLOW); - scoped_ptr<aura::Window> w121(aura::test::CreateTestWindowWithDelegate( - w121delegate, -121, gfx::Rect(5, 5, 5, 5), w12.get())); - aura::test::ColorTestWindowDelegate* w122delegate = - new aura::test::ColorTestWindowDelegate(SK_ColorRED); - scoped_ptr<aura::Window> w122(aura::test::CreateTestWindowWithDelegate( - w122delegate, -122, gfx::Rect(10, 5, 5, 5), w12.get())); - scoped_ptr<aura::Window> w13(aura::test::CreateTestWindow( - SK_ColorGRAY, -13, gfx::Rect(5, 470, 50, 50), w1.get())); - - // Click on a sub-window (w121) to focus it. - gfx::Point click_point = w121->bounds().CenterPoint(); - aura::Window::ConvertPointToWindow(w121->parent(), root_window, &click_point); - aura::MouseEvent mouse(ui::ET_MOUSE_PRESSED, - click_point, - ui::EF_LEFT_MOUSE_BUTTON); - root_window->DispatchMouseEvent(&mouse); - aura::internal::FocusManager* focus_manager = w121->GetFocusManager(); - EXPECT_EQ(w121.get(), focus_manager->GetFocusedWindow()); - - // The key press should be sent to the focused sub-window. - aura::KeyEvent keyev(ui::ET_KEY_PRESSED, ui::VKEY_E, 0); - root_window->DispatchKeyEvent(&keyev); - EXPECT_EQ(ui::VKEY_E, w121delegate->last_key_code()); - - // Touch on a sub-window (w122) to focus it. - click_point = w122->bounds().CenterPoint(); - aura::Window::ConvertPointToWindow(w122->parent(), root_window, &click_point); - aura::TouchEvent touchev(ui::ET_TOUCH_PRESSED, click_point, 0); - root_window->DispatchTouchEvent(&touchev); - focus_manager = w122->GetFocusManager(); - EXPECT_EQ(w122.get(), focus_manager->GetFocusedWindow()); - - // The key press should be sent to the focused sub-window. - root_window->DispatchKeyEvent(&keyev); - EXPECT_EQ(ui::VKEY_E, w122delegate->last_key_code()); - - // Removing the focused window from parent should reset the focused window. - w12->RemoveChild(w122.get()); - EXPECT_EQ(NULL, w122->GetFocusManager()); - EXPECT_EQ(NULL, w12->GetFocusManager()->GetFocusedWindow()); - EXPECT_FALSE(root_window->DispatchKeyEvent(&keyev)); -} - -// Various assertion testing for activating windows. -TEST_F(RootWindowEventFilterTest, ActivateOnMouse) { - aura::RootWindow* root_window = aura::RootWindow::GetInstance(); - - TestActivationDelegate d1; - aura::test::TestWindowDelegate wd; - scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate( - &wd, 1, gfx::Rect(10, 10, 50, 50), NULL)); - d1.SetWindow(w1.get()); - TestActivationDelegate d2; - scoped_ptr<aura::Window> w2(aura::test::CreateTestWindowWithDelegate( - &wd, 2, gfx::Rect(70, 70, 50, 50), NULL)); - d2.SetWindow(w2.get()); - - aura::internal::FocusManager* focus_manager = w1->GetFocusManager(); - - d1.Clear(); - d2.Clear(); - - // Activate window1. - aura_shell::ActivateWindow(w1.get()); - EXPECT_TRUE(IsActiveWindow(w1.get())); - EXPECT_EQ(w1.get(), focus_manager->GetFocusedWindow()); - EXPECT_EQ(1, d1.activated_count()); - EXPECT_EQ(0, d1.lost_active_count()); - d1.Clear(); - - { - // Click on window2. - gfx::Point press_point = w2->bounds().CenterPoint(); - aura::Window::ConvertPointToWindow(w2->parent(), root_window, &press_point); - aura::test::EventGenerator generator(press_point); - generator.ClickLeftButton(); - - // Window2 should have become active. - EXPECT_TRUE(IsActiveWindow(w2.get())); - EXPECT_EQ(w2.get(), focus_manager->GetFocusedWindow()); - EXPECT_EQ(0, d1.activated_count()); - EXPECT_EQ(1, d1.lost_active_count()); - EXPECT_EQ(1, d2.activated_count()); - EXPECT_EQ(0, d2.lost_active_count()); - d1.Clear(); - d2.Clear(); - } - - { - // Click back on window1, but set it up so w1 doesn't activate on click. - gfx::Point press_point = w1->bounds().CenterPoint(); - aura::Window::ConvertPointToWindow(w1->parent(), root_window, &press_point); - aura::test::EventGenerator generator(press_point); - d1.set_activate(false); - generator.ClickLeftButton(); - - // Window2 should still be active and focused. - EXPECT_TRUE(IsActiveWindow(w2.get())); - EXPECT_EQ(w2.get(), focus_manager->GetFocusedWindow()); - EXPECT_EQ(0, d1.activated_count()); - EXPECT_EQ(0, d1.lost_active_count()); - EXPECT_EQ(0, d2.activated_count()); - EXPECT_EQ(0, d2.lost_active_count()); - d1.Clear(); - d2.Clear(); - } - - // Destroy window2, this should make window1 active. - d1.set_activate(true); - w2.reset(); - EXPECT_EQ(0, d2.activated_count()); - EXPECT_EQ(0, d2.lost_active_count()); - EXPECT_TRUE(IsActiveWindow(w1.get())); - EXPECT_EQ(w1.get(), focus_manager->GetFocusedWindow()); - EXPECT_EQ(1, d1.activated_count()); - EXPECT_EQ(0, d1.lost_active_count()); -} - -// Essentially the same as ActivateOnMouse, but for touch events. -TEST_F(RootWindowEventFilterTest, ActivateOnTouch) { - aura::RootWindow* root_window = aura::RootWindow::GetInstance(); - - TestActivationDelegate d1; - aura::test::TestWindowDelegate wd; - scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate( - &wd, -1, gfx::Rect(10, 10, 50, 50), NULL)); - d1.SetWindow(w1.get()); - TestActivationDelegate d2; - scoped_ptr<aura::Window> w2(aura::test::CreateTestWindowWithDelegate( - &wd, -2, gfx::Rect(70, 70, 50, 50), NULL)); - d2.SetWindow(w2.get()); - - aura::internal::FocusManager* focus_manager = w1->GetFocusManager(); - - d1.Clear(); - d2.Clear(); - - // Activate window1. - aura_shell::ActivateWindow(w1.get()); - EXPECT_TRUE(IsActiveWindow(w1.get())); - EXPECT_EQ(w1.get(), focus_manager->GetFocusedWindow()); - EXPECT_EQ(1, d1.activated_count()); - EXPECT_EQ(0, d1.lost_active_count()); - d1.Clear(); - - // Touch window2. - gfx::Point press_point = w2->bounds().CenterPoint(); - aura::Window::ConvertPointToWindow(w2->parent(), root_window, &press_point); - aura::TouchEvent touchev1(ui::ET_TOUCH_PRESSED, press_point, 0); - root_window->DispatchTouchEvent(&touchev1); - - // Window2 should have become active. - EXPECT_TRUE(IsActiveWindow(w2.get())); - EXPECT_EQ(w2.get(), focus_manager->GetFocusedWindow()); - EXPECT_EQ(0, d1.activated_count()); - EXPECT_EQ(1, d1.lost_active_count()); - EXPECT_EQ(1, d2.activated_count()); - EXPECT_EQ(0, d2.lost_active_count()); - d1.Clear(); - d2.Clear(); - - // Touch window1, but set it up so w1 doesn't activate on touch. - press_point = w1->bounds().CenterPoint(); - aura::Window::ConvertPointToWindow(w1->parent(), root_window, &press_point); - d1.set_activate(false); - aura::TouchEvent touchev2(ui::ET_TOUCH_PRESSED, press_point, 0); - root_window->DispatchTouchEvent(&touchev2); - - // Window2 should still be active and focused. - EXPECT_TRUE(IsActiveWindow(w2.get())); - EXPECT_EQ(w2.get(), focus_manager->GetFocusedWindow()); - EXPECT_EQ(0, d1.activated_count()); - EXPECT_EQ(0, d1.lost_active_count()); - EXPECT_EQ(0, d2.activated_count()); - EXPECT_EQ(0, d2.lost_active_count()); - d1.Clear(); - d2.Clear(); - - // Destroy window2, this should make window1 active. - d1.set_activate(true); - w2.reset(); - EXPECT_EQ(0, d2.activated_count()); - EXPECT_EQ(0, d2.lost_active_count()); - EXPECT_TRUE(IsActiveWindow(w1.get())); - EXPECT_EQ(w1.get(), focus_manager->GetFocusedWindow()); - EXPECT_EQ(1, d1.activated_count()); - EXPECT_EQ(0, d1.lost_active_count()); -} - -TEST_F(RootWindowEventFilterTest, MouseEventCursors) { - aura::RootWindow* root_window = aura::RootWindow::GetInstance(); - - // Create a window. - const int kWindowLeft = 123; - const int kWindowTop = 45; - HitTestWindowDelegate window_delegate; - scoped_ptr<aura::Window> window(aura::test::CreateTestWindowWithDelegate( - &window_delegate, - -1, - gfx::Rect(kWindowLeft, kWindowTop, 640, 480), - NULL)); - - // Create two mouse movement events we can switch between. - gfx::Point point1(kWindowLeft, kWindowTop); - aura::Window::ConvertPointToWindow(window->parent(), root_window, &point1); - aura::MouseEvent move1(ui::ET_MOUSE_MOVED, point1, 0x0); - - gfx::Point point2(kWindowLeft + 1, kWindowTop + 1); - aura::Window::ConvertPointToWindow(window->parent(), root_window, &point2); - aura::MouseEvent move2(ui::ET_MOUSE_MOVED, point2, 0x0); - - // Cursor starts as null. - EXPECT_EQ(aura::kCursorNull, root_window->last_cursor()); - - // Resize edges and corners show proper cursors. - window_delegate.set_hittest_code(HTBOTTOM); - root_window->DispatchMouseEvent(&move1); - EXPECT_EQ(aura::kCursorSouthResize, root_window->last_cursor()); - - window_delegate.set_hittest_code(HTBOTTOMLEFT); - root_window->DispatchMouseEvent(&move2); - EXPECT_EQ(aura::kCursorSouthWestResize, root_window->last_cursor()); - - window_delegate.set_hittest_code(HTBOTTOMRIGHT); - root_window->DispatchMouseEvent(&move1); - EXPECT_EQ(aura::kCursorSouthEastResize, root_window->last_cursor()); - - window_delegate.set_hittest_code(HTLEFT); - root_window->DispatchMouseEvent(&move2); - EXPECT_EQ(aura::kCursorWestResize, root_window->last_cursor()); - - window_delegate.set_hittest_code(HTRIGHT); - root_window->DispatchMouseEvent(&move1); - EXPECT_EQ(aura::kCursorEastResize, root_window->last_cursor()); - - window_delegate.set_hittest_code(HTTOP); - root_window->DispatchMouseEvent(&move2); - EXPECT_EQ(aura::kCursorNorthResize, root_window->last_cursor()); - - window_delegate.set_hittest_code(HTTOPLEFT); - root_window->DispatchMouseEvent(&move1); - EXPECT_EQ(aura::kCursorNorthWestResize, root_window->last_cursor()); - - window_delegate.set_hittest_code(HTTOPRIGHT); - root_window->DispatchMouseEvent(&move2); - EXPECT_EQ(aura::kCursorNorthEastResize, root_window->last_cursor()); - - // Client area uses null cursor. - window_delegate.set_hittest_code(HTCLIENT); - root_window->DispatchMouseEvent(&move1); - EXPECT_EQ(aura::kCursorNull, root_window->last_cursor()); -} - -TEST_F(RootWindowEventFilterTest, TransformActivate) { - aura::RootWindow* root_window = aura::RootWindow::GetInstance(); - gfx::Size size = root_window->GetHostSize(); - EXPECT_EQ(gfx::Rect(size), - gfx::Screen::GetMonitorAreaNearestPoint(gfx::Point())); - - // Rotate it clock-wise 90 degrees. - ui::Transform transform; - transform.SetRotate(90.0f); - transform.ConcatTranslate(size.width(), 0); - root_window->SetTransform(transform); - - TestActivationDelegate d1; - aura::test::TestWindowDelegate wd; - scoped_ptr<aura::Window> w1( - CreateTestWindowWithDelegate(&wd, 1, gfx::Rect(0, 10, 50, 50), NULL)); - d1.SetWindow(w1.get()); - w1->Show(); - - gfx::Point miss_point(5, 5); - transform.TransformPoint(miss_point); - aura::MouseEvent mouseev1(ui::ET_MOUSE_PRESSED, - miss_point, - ui::EF_LEFT_MOUSE_BUTTON); - root_window->DispatchMouseEvent(&mouseev1); - EXPECT_FALSE(w1->GetFocusManager()->GetFocusedWindow()); - aura::MouseEvent mouseup(ui::ET_MOUSE_RELEASED, - miss_point, - ui::EF_LEFT_MOUSE_BUTTON); - root_window->DispatchMouseEvent(&mouseup); - - gfx::Point hit_point(5, 15); - transform.TransformPoint(hit_point); - aura::MouseEvent mouseev2(ui::ET_MOUSE_PRESSED, - hit_point, - ui::EF_LEFT_MOUSE_BUTTON); - root_window->DispatchMouseEvent(&mouseev2); - EXPECT_TRUE(IsActiveWindow(w1.get())); - EXPECT_EQ(w1.get(), w1->GetFocusManager()->GetFocusedWindow()); -} - -TEST_F(RootWindowEventFilterTest, AdditionalFilters) { - aura::RootWindow* root_window = aura::RootWindow::GetInstance(); - - // Creates a window and make it active - scoped_ptr<aura::Window> w1(aura::test::CreateTestWindow( - SK_ColorWHITE, -1, gfx::Rect(0, 0, 100, 100), NULL)); - aura_shell::ActivateWindow(w1.get()); - - // Creates two addition filters - scoped_ptr<aura::test::TestEventFilter> f1( - new aura::test::TestEventFilter(NULL)); - scoped_ptr<aura::test::TestEventFilter> f2( - new aura::test::TestEventFilter(NULL)); - - // Adds them to root window event filter. - internal::RootWindowEventFilter* root_window_filter = - static_cast<internal::RootWindowEventFilter*>( - root_window->event_filter()); - root_window_filter->AddFilter(f1.get()); - root_window_filter->AddFilter(f2.get()); - - // Dispatches mouse and keyboard events. - aura::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_A, 0); - root_window->DispatchKeyEvent(&key_event); - aura::MouseEvent mouse_pressed(ui::ET_MOUSE_PRESSED, gfx::Point(0, 0), 0x0); - root_window->DispatchMouseEvent(&mouse_pressed); - - // Both filters should get the events. - EXPECT_EQ(1, f1->key_event_count()); - EXPECT_EQ(1, f1->mouse_event_count()); - EXPECT_EQ(1, f2->key_event_count()); - EXPECT_EQ(1, f2->mouse_event_count()); - - f1->ResetCounts(); - f2->ResetCounts(); - - // Makes f1 consume events. - f1->set_consumes_key_events(true); - f1->set_consumes_mouse_events(true); - - // Dispatches events. - root_window->DispatchKeyEvent(&key_event); - aura::MouseEvent mouse_released(ui::ET_MOUSE_RELEASED, gfx::Point(0, 0), 0x0); - root_window->DispatchMouseEvent(&mouse_released); - - // f1 should still get the events but f2 no longer gets them. - EXPECT_EQ(1, f1->key_event_count()); - EXPECT_EQ(1, f1->mouse_event_count()); - EXPECT_EQ(0, f2->key_event_count()); - EXPECT_EQ(0, f2->mouse_event_count()); - - f1->ResetCounts(); - f2->ResetCounts(); - - // Remove f1 from additonal filters list. - root_window_filter->RemoveFilter(f1.get()); - - // Dispatches events. - root_window->DispatchKeyEvent(&key_event); - root_window->DispatchMouseEvent(&mouse_pressed); - - // f1 should get no events since it's out and f2 should get them. - EXPECT_EQ(0, f1->key_event_count()); - EXPECT_EQ(0, f1->mouse_event_count()); - EXPECT_EQ(1, f2->key_event_count()); - EXPECT_EQ(1, f2->mouse_event_count()); - - root_window_filter->RemoveFilter(f2.get()); -} - -} // namespace test -} // namespace aura_shell diff --git a/ui/aura_shell/root_window_layout_manager.cc b/ui/aura_shell/root_window_layout_manager.cc deleted file mode 100644 index 556bc12..0000000 --- a/ui/aura_shell/root_window_layout_manager.cc +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (c) 2011 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 "ui/aura_shell/root_window_layout_manager.h" - -#include "ui/aura/window.h" -#include "ui/views/widget/widget.h" - -namespace aura_shell { -namespace internal { - -//////////////////////////////////////////////////////////////////////////////// -// RootWindowLayoutManager, public: - -RootWindowLayoutManager::RootWindowLayoutManager(aura::Window* owner) - : owner_(owner), - background_widget_(NULL) { -} - -RootWindowLayoutManager::~RootWindowLayoutManager() { -} - -//////////////////////////////////////////////////////////////////////////////// -// RootWindowLayoutManager, aura::LayoutManager implementation: - -void RootWindowLayoutManager::OnWindowResized() { - gfx::Rect fullscreen_bounds = - gfx::Rect(owner_->bounds().width(), owner_->bounds().height()); - - aura::Window::Windows::const_iterator i; - for (i = owner_->children().begin(); i != owner_->children().end(); ++i) - (*i)->SetBounds(fullscreen_bounds); - - if (background_widget_) - background_widget_->SetBounds(fullscreen_bounds); -} - -void RootWindowLayoutManager::OnWindowAddedToLayout(aura::Window* child) { -} - -void RootWindowLayoutManager::OnWillRemoveWindowFromLayout( - aura::Window* child) { -} - -void RootWindowLayoutManager::OnChildWindowVisibilityChanged( - aura::Window* child, - bool visible) { -} - -void RootWindowLayoutManager::SetChildBounds( - aura::Window* child, - const gfx::Rect& requested_bounds) { - SetChildBoundsDirect(child, requested_bounds); -} - -} // namespace internal -} // namespace aura_shell diff --git a/ui/aura_shell/root_window_layout_manager.h b/ui/aura_shell/root_window_layout_manager.h deleted file mode 100644 index 79c3d3f..0000000 --- a/ui/aura_shell/root_window_layout_manager.h +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (c) 2011 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. - -#ifndef UI_AURA_SHELL_ROOT_WINDOW_LAYOUT_MANAGER_H_ -#define UI_AURA_SHELL_ROOT_WINDOW_LAYOUT_MANAGER_H_ -#pragma once - -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "ui/aura/layout_manager.h" - -namespace aura { -class Window; -} -namespace gfx { -class Rect; -} -namespace views { -class Widget; -} - -namespace aura_shell { -namespace internal { - -// A layout manager for the root window. -// Resizes all of its immediate children to fill the bounds of the root window. -class RootWindowLayoutManager : public aura::LayoutManager { - public: - explicit RootWindowLayoutManager(aura::Window* owner); - virtual ~RootWindowLayoutManager(); - - void set_background_widget(views::Widget* background_widget) { - background_widget_ = background_widget; - } - - // Overridden from aura::LayoutManager: - virtual void OnWindowResized() OVERRIDE; - virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE; - virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE; - virtual void OnChildWindowVisibilityChanged(aura::Window* child, - bool visible) OVERRIDE; - virtual void SetChildBounds(aura::Window* child, - const gfx::Rect& requested_bounds) OVERRIDE; - - private: - aura::Window* owner_; - - // May be NULL if we're not painting a background. - views::Widget* background_widget_; - - DISALLOW_COPY_AND_ASSIGN(RootWindowLayoutManager); -}; - -} // namespace internal -} // namespace aura_shell - -#endif // UI_AURA_SHELL_ROOT_WINDOW_LAYOUT_MANAGER_H_ diff --git a/ui/aura_shell/shell.cc b/ui/aura_shell/shell.cc index 6fb354d..7c2a56c 100644 --- a/ui/aura_shell/shell.cc +++ b/ui/aura_shell/shell.cc @@ -6,10 +6,17 @@ #include <algorithm> +#include "ash/wm/default_container_event_filter.h" +#include "ash/wm/default_container_layout_manager.h" +#include "ash/wm/root_window_event_filter.h" +#include "ash/wm/root_window_layout_manager.h" #include "ash/wm/activation_controller.h" #include "ash/wm/modal_container_layout_manager.h" #include "ash/wm/shadow_controller.h" #include "ash/wm/stacking_controller.h" +#include "ash/wm/toplevel_layout_manager.h" +#include "ash/wm/toplevel_window_event_filter.h" +#include "ash/wm/workspace_controller.h" #include "base/bind.h" #include "base/command_line.h" #include "ui/aura/root_window.h" @@ -19,10 +26,6 @@ #include "ui/aura_shell/aura_shell_switches.h" #include "ui/aura_shell/compact_layout_manager.h" #include "ui/aura_shell/compact_status_area_layout_manager.h" -#include "ui/aura_shell/default_container_event_filter.h" -#include "ui/aura_shell/default_container_layout_manager.h" -#include "ui/aura_shell/root_window_event_filter.h" -#include "ui/aura_shell/root_window_layout_manager.h" #include "ui/aura_shell/drag_drop_controller.h" #include "ui/aura_shell/launcher/launcher.h" #include "ui/aura_shell/shelf_layout_manager.h" @@ -33,9 +36,6 @@ #include "ui/aura_shell/shell_window_ids.h" #include "ui/aura_shell/status_area_layout_manager.h" #include "ui/aura_shell/tooltip_controller.h" -#include "ui/aura_shell/toplevel_layout_manager.h" -#include "ui/aura_shell/toplevel_window_event_filter.h" -#include "ui/aura_shell/workspace_controller.h" #include "ui/gfx/compositor/layer.h" #include "ui/gfx/compositor/layer_animator.h" #include "ui/gfx/screen.h" diff --git a/ui/aura_shell/shell_accelerator_controller.cc b/ui/aura_shell/shell_accelerator_controller.cc index 2ec1739..34d458b 100644 --- a/ui/aura_shell/shell_accelerator_controller.cc +++ b/ui/aura_shell/shell_accelerator_controller.cc @@ -4,6 +4,7 @@ #include "ui/aura_shell/shell_accelerator_controller.h" +#include "ash/wm/window_util.h" #include "ui/aura/event.h" #include "ui/aura/root_window.h" #include "ui/aura_shell/launcher/launcher.h" @@ -11,7 +12,6 @@ #include "ui/aura_shell/screenshot_delegate.h" #include "ui/aura_shell/shell.h" #include "ui/aura_shell/shell_window_ids.h" -#include "ui/aura_shell/window_util.h" #include "ui/base/accelerators/accelerator.h" #include "ui/base/accelerators/accelerator_manager.h" #include "ui/gfx/compositor/debug_utils.h" diff --git a/ui/aura_shell/shell_accelerator_controller_unittest.cc b/ui/aura_shell/shell_accelerator_controller_unittest.cc index c2bb8a0..7539c95 100644 --- a/ui/aura_shell/shell_accelerator_controller_unittest.cc +++ b/ui/aura_shell/shell_accelerator_controller_unittest.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "ash/wm/window_util.h" #include "ui/aura/event.h" #include "ui/aura/root_window.h" #include "ui/aura/test/test_window_delegate.h" @@ -11,7 +12,6 @@ #include "ui/aura_shell/shell_accelerator_controller.h" #include "ui/aura_shell/shell_window_ids.h" #include "ui/aura_shell/test/aura_shell_test_base.h" -#include "ui/aura_shell/window_util.h" #if defined(USE_X11) #include <X11/Xlib.h> diff --git a/ui/aura_shell/test/test_activation_delegate.cc b/ui/aura_shell/test/test_activation_delegate.cc index e9a9bda..0400986 100644 --- a/ui/aura_shell/test/test_activation_delegate.cc +++ b/ui/aura_shell/test/test_activation_delegate.cc @@ -4,9 +4,9 @@ #include "ui/aura_shell/test/test_activation_delegate.h" +#include "ash/wm/window_util.h" #include "ui/aura/client/aura_constants.h" #include "ui/aura/window.h" -#include "ui/aura_shell/window_util.h" namespace aura_shell { namespace test { diff --git a/ui/aura_shell/toplevel_frame_view.cc b/ui/aura_shell/toplevel_frame_view.cc deleted file mode 100644 index 5265edc..0000000 --- a/ui/aura_shell/toplevel_frame_view.cc +++ /dev/null @@ -1,487 +0,0 @@ -// Copyright (c) 2011 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 "ui/aura_shell/toplevel_frame_view.h" - -#include "grit/ui_resources.h" -#include "ui/aura/cursor.h" -#include "ui/base/animation/throb_animation.h" -#include "ui/base/hit_test.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/gfx/canvas.h" -#include "ui/views/controls/button/custom_button.h" -#include "ui/views/widget/widget.h" -#include "ui/views/widget/widget_delegate.h" - -namespace aura_shell { -namespace internal { - -namespace { -// The thickness of the left, right and bottom edges of the frame. -const int kFrameBorderThickness = 8; -const int kFrameOpacity = 50; -// The color used to fill the frame. -const SkColor kFrameColor = SkColorSetARGB(kFrameOpacity, 0, 0, 0); -const int kFrameBorderHiddenOpacity = 0; -const int kFrameBorderVisibleOpacity = kFrameOpacity; -// How long the hover animation takes if uninterrupted. -const int kHoverFadeDurationMs = 250; -} // namespace - -// Buttons for window controls - close, zoom, etc. -class WindowControlButton : public views::CustomButton { - public: - WindowControlButton(views::ButtonListener* listener, - SkColor color, - const SkBitmap& icon) - : views::CustomButton(listener), - color_(color), - icon_(icon) { - } - virtual ~WindowControlButton() {} - - // Overridden from views::View: - virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { - canvas->FillRect(GetBackgroundColor(), GetLocalBounds()); - canvas->DrawBitmapInt(icon_, 0, 0); - } - virtual gfx::Size GetPreferredSize() OVERRIDE { - gfx::Size size(icon_.width(), icon_.height()); - size.Enlarge(3, 2); - return size; - } - - private: - SkColor GetBackgroundColor() { - return SkColorSetARGB(hover_animation_->CurrentValueBetween(0, 150), - SkColorGetR(color_), - SkColorGetG(color_), - SkColorGetB(color_)); - } - - SkColor color_; - SkBitmap icon_; - - DISALLOW_COPY_AND_ASSIGN(WindowControlButton); -}; - -// Base class for all animatable frame components such as sizing borders and -// the window's caption. Provides shared animation and event-handling logic. -class FrameComponent : public views::View, - public ui::AnimationDelegate { - public: - virtual ~FrameComponent() { - } - - // Control animations. - void Show() { - animation_->Show(); - } - void Hide() { - animation_->Hide(); - } - - // Current animation state. - bool IsShowing() const { - return animation_->IsShowing(); - } - bool IsHiding() const { - return animation_->IsClosing(); - } - - // Returns true if the view ignores events to itself or its children at the - // specified point in its parent's coordinates. By default, any events within - // the bounds of this view are ignored so that the parent (the NCFV) can - // handle them instead. Derived classes can override to disable this for some - // of their children. - virtual bool IgnoreEventsForPoint(const gfx::Point& point) { - gfx::Point translated_point(point); - ConvertPointToView(parent(), this, &translated_point); - return HitTest(translated_point); - } - - protected: - FrameComponent() - : ALLOW_THIS_IN_INITIALIZER_LIST( - animation_(new ui::SlideAnimation(this))) { - animation_->SetSlideDuration(kHoverFadeDurationMs); - } - - // Most of the frame components are rendered with a transparent bg. - void PaintTransparentBackground(gfx::Canvas* canvas) { - // Fill with current opacity value. - int opacity = animation_->CurrentValueBetween(kFrameBorderHiddenOpacity, - kFrameBorderVisibleOpacity); - canvas->FillRect(SkColorSetARGB(opacity, - SkColorGetR(kFrameColor), - SkColorGetG(kFrameColor), - SkColorGetB(kFrameColor)), - GetLocalBounds()); - } - - // Overridden from ui::AnimationDelegate: - virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE { - SchedulePaint(); - } - - private: - scoped_ptr<ui::SlideAnimation> animation_; - - DISALLOW_COPY_AND_ASSIGN(FrameComponent); -}; - -// A view that renders the title bar of the window, and also hosts the window -// controls. -class WindowCaption : public FrameComponent, - public views::ButtonListener { - public: - WindowCaption() { - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - close_button_ = - new WindowControlButton(this, SK_ColorRED, - *rb.GetBitmapNamed(IDR_AURA_WINDOW_CLOSE_ICON)); - zoom_button_ = - new WindowControlButton(this, SK_ColorGREEN, - *rb.GetBitmapNamed(IDR_AURA_WINDOW_ZOOM_ICON)); - AddChildView(close_button_); - AddChildView(zoom_button_); - } - virtual ~WindowCaption() {} - - // Returns the hit-test code for the specified point in parent coordinates. - int NonClientHitTest(const gfx::Point& point) { - gfx::Point translated_point(point); - View::ConvertPointToView(parent(), this, &translated_point); - // The window controls come second. - if (close_button_->GetMirroredBounds().Contains(translated_point)) - return HTCLOSE; - else if (zoom_button_->GetMirroredBounds().Contains(translated_point)) - return HTMAXBUTTON; - return HTNOWHERE; - } - - // Overridden from FrameComponent: - virtual bool IgnoreEventsForPoint(const gfx::Point& point) OVERRIDE { - gfx::Point translated_point(point); - ConvertPointToView(parent(), this, &translated_point); - if (PointIsInChildView(close_button_, translated_point)) - return false; - if (PointIsInChildView(zoom_button_, translated_point)) - return false; - return FrameComponent::IgnoreEventsForPoint(point); - } - - // Overridden from views::View: - virtual gfx::Size GetPreferredSize() OVERRIDE { - return gfx::Size(0, close_button_->GetPreferredSize().height()); - } - - private: - // Returns true if the specified |point| in this view's coordinates hit tests - // against |child|, a child view of this view. - bool PointIsInChildView(views::View* child, - const gfx::Point& point) const { - gfx::Point child_point(point); - ConvertPointToView(this, child, &child_point); - return child->HitTest(child_point); - } - - // Overridden from views::View: - virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { - PaintTransparentBackground(canvas); - } - virtual void Layout() OVERRIDE { - gfx::Size close_button_ps = close_button_->GetPreferredSize(); - close_button_->SetBoundsRect( - gfx::Rect(width() - close_button_ps.width(), - 0, close_button_ps.width(), close_button_ps.height())); - - gfx::Size zoom_button_ps = zoom_button_->GetPreferredSize(); - zoom_button_->SetBoundsRect( - gfx::Rect(close_button_->x() - zoom_button_ps.width(), 0, - zoom_button_ps.width(), zoom_button_ps.height())); - } - - // Overridden from views::ButtonListener: - virtual void ButtonPressed(views::Button* sender, - const views::Event& event) OVERRIDE { - if (sender == close_button_) { - GetWidget()->Close(); - } else if (sender == zoom_button_) { - if (GetWidget()->IsMaximized()) - GetWidget()->Restore(); - else - GetWidget()->Maximize(); - } - } - - views::Button* close_button_; - views::Button* zoom_button_; - - DISALLOW_COPY_AND_ASSIGN(WindowCaption); -}; - -// A class that renders the sizing border that appears when the user moves -// their mouse over a sizing edge. This view is not actually responsible for -// resizing the window, the EventFilter is. -class SizingBorder : public FrameComponent { - public: - SizingBorder() {} - virtual ~SizingBorder() {} - - void Configure(const gfx::Rect& hidden_bounds, - const gfx::Rect& visible_bounds) { - hidden_bounds_ = hidden_bounds; - visible_bounds_ = visible_bounds; - SetBoundsRect(hidden_bounds_); - } - - protected: - // Overridden from ui::AnimationDelegate: - virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE { - gfx::Rect current_bounds = animation->CurrentValueBetween(hidden_bounds_, - visible_bounds_); - SetBoundsRect(current_bounds); - FrameComponent::AnimationProgressed(animation); - } - - private: - // Overridden from views::View: - virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { - PaintTransparentBackground(canvas); - } - - // Each of these represents the hidden/visible states of the sizing border. - // When the view is shown or hidden it animates between them. - gfx::Rect hidden_bounds_; - gfx::Rect visible_bounds_; - - DISALLOW_COPY_AND_ASSIGN(SizingBorder); -}; - -//////////////////////////////////////////////////////////////////////////////// -// ToplevelFrameView, public: - -ToplevelFrameView::ToplevelFrameView() - : current_hittest_code_(HTNOWHERE), - caption_(new WindowCaption), - left_edge_(new SizingBorder), - right_edge_(new SizingBorder), - bottom_edge_(new SizingBorder) { - AddChildView(caption_); - AddChildView(left_edge_); - AddChildView(right_edge_); - AddChildView(bottom_edge_); -} - -ToplevelFrameView::~ToplevelFrameView() { -} - -//////////////////////////////////////////////////////////////////////////////// -// ToplevelFrameView, private: - -int ToplevelFrameView::NonClientBorderThickness() const { - return kFrameBorderThickness; -} - -int ToplevelFrameView::NonClientTopBorderHeight() const { - return caption_->GetPreferredSize().height(); -} - -int ToplevelFrameView::NonClientHitTestImpl(const gfx::Point& point) { - // Sanity check. - if (!GetLocalBounds().Contains(point)) - return HTNOWHERE; - - // The client view gets first crack at claiming the point. - int frame_component = GetWidget()->client_view()->NonClientHitTest(point); - if (frame_component != HTNOWHERE) - return frame_component; - - frame_component = caption_->NonClientHitTest(point); - if (frame_component != HTNOWHERE) - return frame_component; - - // Finally other portions of the frame/sizing border. - frame_component = - GetHTComponentForFrame(point, - NonClientBorderThickness(), - NonClientBorderThickness(), - NonClientBorderThickness(), - NonClientBorderThickness(), - GetWidget()->widget_delegate()->CanResize()); - - // Coerce HTCAPTION as a fallback. - return frame_component == HTNOWHERE ? HTCAPTION : frame_component; -} - -void ToplevelFrameView::ShowFrameComponent(FrameComponent* frame_component) { - if (frame_component && !frame_component->IsShowing()) - frame_component->Show(); - if (caption_ != frame_component && !caption_->IsHiding()) - caption_->Hide(); - if (left_edge_ != frame_component && !left_edge_->IsHiding()) - left_edge_->Hide(); - if (right_edge_ != frame_component && !right_edge_->IsHiding()) - right_edge_->Hide(); - if (bottom_edge_ != frame_component && !bottom_edge_->IsHiding()) - bottom_edge_->Hide(); -} - -gfx::Rect ToplevelFrameView::GetHiddenBoundsForSizingBorder( - int frame_component) const { - int border_size = NonClientBorderThickness(); - int caption_height = NonClientTopBorderHeight(); - switch (frame_component) { - case HTLEFT: - return gfx::Rect(border_size, caption_height, border_size, - height() - border_size - caption_height); - case HTBOTTOM: - return gfx::Rect(border_size, height() - 2 * border_size, - width() - 2 * border_size, border_size); - case HTRIGHT: - return gfx::Rect(width() - 2 * border_size, caption_height, border_size, - height() - border_size - caption_height); - default: - break; - } - return gfx::Rect(); -} - -gfx::Rect ToplevelFrameView::GetVisibleBoundsForSizingBorder( - int frame_component) const { - int border_size = NonClientBorderThickness(); - int caption_height = NonClientTopBorderHeight(); - switch (frame_component) { - case HTLEFT: - return gfx::Rect(0, caption_height, border_size, - height() - border_size - caption_height); - case HTBOTTOM: - return gfx::Rect(border_size, height() - border_size, - width() - 2 * border_size, border_size); - case HTRIGHT: - return gfx::Rect(width() - border_size, caption_height, border_size, - height() - border_size - caption_height); - default: - break; - } - return gfx::Rect(); -} - -//////////////////////////////////////////////////////////////////////////////// -// ToplevelFrameView, views::NonClientFrameView overrides: - -gfx::Rect ToplevelFrameView::GetBoundsForClientView() const { - return client_view_bounds_; -} - -gfx::Rect ToplevelFrameView::GetWindowBoundsForClientBounds( - const gfx::Rect& client_bounds) const { - gfx::Rect window_bounds = client_bounds; - window_bounds.Inset(-NonClientBorderThickness(), - -NonClientTopBorderHeight(), - -NonClientBorderThickness(), - -NonClientBorderThickness()); - return window_bounds; -} - -int ToplevelFrameView::NonClientHitTest(const gfx::Point& point) { - current_hittest_code_ = NonClientHitTestImpl(point); - return current_hittest_code_; -} - -void ToplevelFrameView::GetWindowMask(const gfx::Size& size, - gfx::Path* window_mask) { - // Nothing. -} - -void ToplevelFrameView::ResetWindowControls() { - NOTIMPLEMENTED(); -} - -void ToplevelFrameView::UpdateWindowIcon() { - NOTIMPLEMENTED(); -} - -//////////////////////////////////////////////////////////////////////////////// -// ToplevelFrameView, views::View overrides: - -void ToplevelFrameView::Layout() { - client_view_bounds_ = GetLocalBounds(); - client_view_bounds_.Inset(NonClientBorderThickness(), - NonClientTopBorderHeight(), - NonClientBorderThickness(), - NonClientBorderThickness()); - - caption_->SetBounds(NonClientBorderThickness(), 0, - width() - 2 * NonClientBorderThickness(), - NonClientTopBorderHeight()); - - left_edge_->Configure(GetHiddenBoundsForSizingBorder(HTLEFT), - GetVisibleBoundsForSizingBorder(HTLEFT)); - right_edge_->Configure(GetHiddenBoundsForSizingBorder(HTRIGHT), - GetVisibleBoundsForSizingBorder(HTRIGHT)); - bottom_edge_->Configure(GetHiddenBoundsForSizingBorder(HTBOTTOM), - GetVisibleBoundsForSizingBorder(HTBOTTOM)); -} - -void ToplevelFrameView::OnMouseMoved(const views::MouseEvent& event) { - switch (current_hittest_code_) { - case HTLEFT: - ShowFrameComponent(left_edge_); - break; - case HTRIGHT: - ShowFrameComponent(right_edge_); - break; - case HTBOTTOM: - ShowFrameComponent(bottom_edge_); - break; - case HTCAPTION: - ShowFrameComponent(caption_); - break; - default: - break; - } -} - -void ToplevelFrameView::OnMouseExited(const views::MouseEvent& event) { - ShowFrameComponent(NULL); -} - -views::View* ToplevelFrameView::GetEventHandlerForPoint( - const gfx::Point& point) { - if (left_edge_->IgnoreEventsForPoint(point) || - right_edge_->IgnoreEventsForPoint(point) || - bottom_edge_->IgnoreEventsForPoint(point) || - caption_->IgnoreEventsForPoint(point)) { - return this; - } - return View::GetEventHandlerForPoint(point); -} - -gfx::NativeCursor ToplevelFrameView::GetCursor(const views::MouseEvent& event) { - switch (current_hittest_code_) { - case HTBOTTOM: - return aura::kCursorSouthResize; - case HTBOTTOMLEFT: - return aura::kCursorSouthWestResize; - case HTBOTTOMRIGHT: - return aura::kCursorSouthEastResize; - case HTLEFT: - return aura::kCursorWestResize; - case HTRIGHT: - return aura::kCursorEastResize; - case HTTOP: - return aura::kCursorNorthResize; - case HTTOPLEFT: - return aura::kCursorNorthWestResize; - case HTTOPRIGHT: - return aura::kCursorNorthEastResize; - default: - return aura::kCursorNull; - } -} - -} // namespace internal -} // namespace aura_shell diff --git a/ui/aura_shell/toplevel_frame_view.h b/ui/aura_shell/toplevel_frame_view.h deleted file mode 100644 index 59f8fdc..0000000 --- a/ui/aura_shell/toplevel_frame_view.h +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright (c) 2011 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. - -#ifndef UI_AURA_SHELL_TOPLEVEL_FRAME_VIEW_H_ -#define UI_AURA_SHELL_TOPLEVEL_FRAME_VIEW_H_ -#pragma once - -#include "ui/aura_shell/aura_shell_export.h" -#include "ui/views/controls/button/button.h" -#include "ui/views/window/non_client_view.h" - -namespace aura_shell { -namespace internal { - -class FrameComponent; -class SizingBorder; -class WindowCaption; - -// A NonClientFrameView implementation for generic top-level windows in Aura. -// TODO(beng): Find a way to automatically this for all top-level windows in -// Aura. Right now windows have to override CreateNonClientFrameView -// on WidgetDelegate to specify this. -class AURA_SHELL_EXPORT ToplevelFrameView : public views::NonClientFrameView { - public: - ToplevelFrameView(); - virtual ~ToplevelFrameView(); - - private: - // Returns the height of the side/bottom non-client edges. - int NonClientBorderThickness() const; - - // Returns the height of the top non-client edge - the caption. - int NonClientTopBorderHeight() const; - - // Implementation of NonClientHitTest(). - int NonClientHitTestImpl(const gfx::Point& point); - - // Shows the specified |sizing_border|, hiding all others. - // If |sizing_border| is NULL, all other sizing borders are hidden. - void ShowFrameComponent(FrameComponent* sizing_border); - - // Returns true if the specified point (in FrameView coordinates) hit-tests - // against the specified child. - bool PointIsInChildView(views::View* child, const gfx::Point& point) const; - - // Returns the bounds of the specified sizing border for its visible and - // hidden states. - gfx::Rect GetHiddenBoundsForSizingBorder(int frame_component) const; - gfx::Rect GetVisibleBoundsForSizingBorder(int frame_component) const; - - // Overridden from views::NonClientFrameView: - virtual gfx::Rect GetBoundsForClientView() const OVERRIDE; - virtual gfx::Rect GetWindowBoundsForClientBounds( - const gfx::Rect& client_bounds) const OVERRIDE; - virtual int NonClientHitTest(const gfx::Point& point) OVERRIDE; - virtual void GetWindowMask(const gfx::Size& size, - gfx::Path* window_mask) OVERRIDE; - virtual void ResetWindowControls() OVERRIDE; - virtual void UpdateWindowIcon() OVERRIDE; - - // Overridden from views::View: - virtual void Layout() OVERRIDE; - virtual void OnMouseMoved(const views::MouseEvent& event) OVERRIDE; - virtual void OnMouseExited(const views::MouseEvent& event) OVERRIDE; - virtual views::View* GetEventHandlerForPoint( - const gfx::Point& point) OVERRIDE; - virtual gfx::NativeCursor GetCursor(const views::MouseEvent& event) OVERRIDE; - - gfx::Rect client_view_bounds_; - - int current_hittest_code_; - - WindowCaption* caption_; - SizingBorder* left_edge_; - SizingBorder* right_edge_; - SizingBorder* bottom_edge_; - - DISALLOW_COPY_AND_ASSIGN(ToplevelFrameView); -}; - -} // namespace internal -} // namespace aura_shell - -#endif // #ifndef UI_AURA_SHELL_TOPLEVEL_FRAME_VIEW_H_ diff --git a/ui/aura_shell/toplevel_layout_manager.cc b/ui/aura_shell/toplevel_layout_manager.cc deleted file mode 100644 index 872da95..0000000 --- a/ui/aura_shell/toplevel_layout_manager.cc +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright (c) 2011 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 "ui/aura_shell/toplevel_layout_manager.h" - -#include "ui/aura/client/aura_constants.h" -#include "ui/aura/window.h" -#include "ui/aura_shell/shelf_layout_manager.h" -#include "ui/aura_shell/window_util.h" -#include "ui/base/ui_base_types.h" -#include "ui/gfx/screen.h" - -namespace aura_shell { -namespace internal { - -ToplevelLayoutManager::ToplevelLayoutManager() : shelf_(NULL) { -} - -ToplevelLayoutManager::~ToplevelLayoutManager() { - for (Windows::const_iterator i = windows_.begin(); i != windows_.end(); ++i) - (*i)->RemoveObserver(this); -} - -void ToplevelLayoutManager::OnWindowResized() { -} - -void ToplevelLayoutManager::OnWindowAddedToLayout(aura::Window* child) { - windows_.insert(child); - child->AddObserver(this); - if (child->GetProperty(aura::client::kShowStateKey)) { - UpdateBoundsFromShowState(child); - UpdateShelfVisibility(); - } -} - -void ToplevelLayoutManager::OnWillRemoveWindowFromLayout( - aura::Window* child) { - windows_.erase(child); - child->RemoveObserver(this); - UpdateShelfVisibility(); -} - -void ToplevelLayoutManager::OnChildWindowVisibilityChanged(aura::Window* child, - bool visibile) { - UpdateShelfVisibility(); -} - -void ToplevelLayoutManager::SetChildBounds(aura::Window* child, - const gfx::Rect& requested_bounds) { - const static int kTitleHeight = 12; - gfx::Rect child_bounds(requested_bounds); - gfx::Rect work_area = gfx::Screen::GetMonitorWorkAreaNearestWindow(child); - if (child_bounds.y() < 0) - child_bounds.set_y(0); - else if (child_bounds.y() + kTitleHeight > work_area.bottom()) - child_bounds.set_y(work_area.bottom() - kTitleHeight); - SetChildBoundsDirect(child, child_bounds); -} - -void ToplevelLayoutManager::OnWindowPropertyChanged(aura::Window* window, - const char* name, - void* old) { - if (name == aura::client::kShowStateKey) { - UpdateBoundsFromShowState(window); - UpdateShelfVisibility(); - } -} - -void ToplevelLayoutManager::UpdateShelfVisibility() { - if (!shelf_) - return; - shelf_->SetVisible(!HasFullscreenWindow(windows_)); -} - -} // namespace internal -} // namespace aura_shell diff --git a/ui/aura_shell/toplevel_layout_manager.h b/ui/aura_shell/toplevel_layout_manager.h deleted file mode 100644 index f03328a..0000000 --- a/ui/aura_shell/toplevel_layout_manager.h +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright (c) 2011 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. - -#ifndef UI_AURA_SHELL_TOPLEVEL_LAYOUT_MANAGER_H_ -#define UI_AURA_SHELL_TOPLEVEL_LAYOUT_MANAGER_H_ -#pragma once - -#include <set> - -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "ui/aura/layout_manager.h" -#include "ui/aura/window_observer.h" -#include "ui/aura_shell/aura_shell_export.h" - -namespace aura_shell { -namespace internal { - -class ShelfLayoutManager; - -// ToplevelLayoutManager is the LayoutManager installed on a container that -// hosts what the shell considers to be top-level windows. It is used if the -// WorkspaceManager is not enabled. ToplevelLayoutManager listens for changes to -// kShowStateKey and resizes the window appropriately. -class AURA_SHELL_EXPORT ToplevelLayoutManager : public aura::LayoutManager, - public aura::WindowObserver { - public: - ToplevelLayoutManager(); - virtual ~ToplevelLayoutManager(); - - void set_shelf(ShelfLayoutManager* shelf) { shelf_ = shelf; } - - // LayoutManager overrides: - virtual void OnWindowResized() OVERRIDE; - virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE; - virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE; - virtual void OnChildWindowVisibilityChanged(aura::Window* child, - bool visibile) OVERRIDE; - virtual void SetChildBounds(aura::Window* child, - const gfx::Rect& requested_bounds) OVERRIDE; - - // WindowObserver overrides: - virtual void OnWindowPropertyChanged(aura::Window* window, - const char* name, - void* old) OVERRIDE; - - private: - typedef std::set<aura::Window*> Windows; - - // Updates the visibility of the shelf based on if there are any full screen - // windows. - void UpdateShelfVisibility(); - - // Set of windows we're listening to. - Windows windows_; - - // May be NULL if we're not using a shelf. - ShelfLayoutManager* shelf_; - - DISALLOW_COPY_AND_ASSIGN(ToplevelLayoutManager); -}; - -} // namespace aura_shell -} // namespace internal - -#endif // UI_AURA_SHELL_TOPLEVEL_LAYOUT_MANAGER_H_ diff --git a/ui/aura_shell/toplevel_layout_manager_unittest.cc b/ui/aura_shell/toplevel_layout_manager_unittest.cc deleted file mode 100644 index a28b898..0000000 --- a/ui/aura_shell/toplevel_layout_manager_unittest.cc +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright (c) 2011 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 "ui/aura_shell/toplevel_layout_manager.h" - -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "ui/aura/client/aura_constants.h" -#include "ui/aura/root_window.h" -#include "ui/aura/screen_aura.h" -#include "ui/aura/test/aura_test_base.h" -#include "ui/base/ui_base_types.h" -#include "ui/aura/window.h" - -namespace aura_shell { - -namespace { - -class ToplevelLayoutManagerTest : public aura::test::AuraTestBase { - public: - ToplevelLayoutManagerTest() : layout_manager_(NULL) {} - virtual ~ToplevelLayoutManagerTest() {} - - virtual void SetUp() OVERRIDE { - aura::test::AuraTestBase::SetUp(); - aura::RootWindow::GetInstance()->screen()->set_work_area_insets( - gfx::Insets(1, 2, 3, 4)); - aura::RootWindow::GetInstance()->SetHostSize(gfx::Size(500, 400)); - container_.reset(new aura::Window(NULL)); - container_->Init(ui::Layer::LAYER_HAS_NO_TEXTURE); - container_->SetBounds(gfx::Rect(0, 0, 500, 500)); - layout_manager_ = new internal::ToplevelLayoutManager(); - container_->SetLayoutManager(layout_manager_); - } - - aura::Window* CreateTestWindow(const gfx::Rect& bounds) { - aura::Window* window = new aura::Window(NULL); - window->Init(ui::Layer::LAYER_HAS_NO_TEXTURE); - window->SetBounds(bounds); - window->Show(); - window->SetParent(container_.get()); - return window; - } - - private: - // Owned by |container_|. - internal::ToplevelLayoutManager* layout_manager_; - - scoped_ptr<aura::Window> container_; - - DISALLOW_COPY_AND_ASSIGN(ToplevelLayoutManagerTest); -}; - -} // namespace - -// Tests normal->maximize->normal. -TEST_F(ToplevelLayoutManagerTest, Maximize) { - gfx::Rect bounds(100, 100, 200, 200); - scoped_ptr<aura::Window> window(CreateTestWindow(bounds)); - window->SetIntProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); - EXPECT_EQ(gfx::Screen::GetMonitorWorkAreaNearestWindow(window.get()), - window->bounds()); - window->SetIntProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); - EXPECT_EQ(bounds, window->bounds()); -} - -// Tests normal->fullscreen->normal. -TEST_F(ToplevelLayoutManagerTest, Fullscreen) { - gfx::Rect bounds(100, 100, 200, 200); - scoped_ptr<aura::Window> window(CreateTestWindow(bounds)); - window->SetIntProperty(aura::client::kShowStateKey, - ui::SHOW_STATE_FULLSCREEN); - EXPECT_EQ(gfx::Screen::GetMonitorAreaNearestWindow(window.get()), - window->bounds()); - window->SetIntProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); - EXPECT_EQ(bounds, window->bounds()); -} - -} // namespace aura_shell diff --git a/ui/aura_shell/toplevel_window_event_filter.cc b/ui/aura_shell/toplevel_window_event_filter.cc deleted file mode 100644 index e8c63e2..0000000 --- a/ui/aura_shell/toplevel_window_event_filter.cc +++ /dev/null @@ -1,353 +0,0 @@ -// Copyright (c) 2011 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 "ui/aura_shell/toplevel_window_event_filter.h" - -#include "ui/aura/client/aura_constants.h" -#include "ui/aura/cursor.h" -#include "ui/aura/event.h" -#include "ui/aura/root_window.h" -#include "ui/aura/window.h" -#include "ui/aura/window_delegate.h" -#include "ui/aura_shell/window_util.h" -#include "ui/base/hit_test.h" -#include "ui/base/ui_base_types.h" - -namespace aura_shell { - -namespace { - -// Identifies the types of bounds change operations performed by a drag to a -// particular window component. -const int kBoundsChange_None = 0; -const int kBoundsChange_Repositions = 1; -const int kBoundsChange_Resizes = 2; - -int GetBoundsChangeForWindowComponent(int window_component) { - int bounds_change = kBoundsChange_None; - switch (window_component) { - case HTTOPLEFT: - case HTTOP: - case HTTOPRIGHT: - case HTLEFT: - case HTBOTTOMLEFT: - bounds_change |= kBoundsChange_Repositions | kBoundsChange_Resizes; - break; - case HTCAPTION: - bounds_change |= kBoundsChange_Repositions; - break; - case HTRIGHT: - case HTBOTTOMRIGHT: - case HTBOTTOM: - case HTGROWBOX: - bounds_change |= kBoundsChange_Resizes; - break; - default: - break; - } - return bounds_change; -} - -// Possible directions for changing bounds. - -const int kBoundsChangeDirection_None = 0; -const int kBoundsChangeDirection_Horizontal = 1; -const int kBoundsChangeDirection_Vertical = 2; - -int GetPositionChangeDirectionForWindowComponent(int window_component) { - int pos_change_direction = kBoundsChangeDirection_None; - switch (window_component) { - case HTTOPLEFT: - case HTBOTTOMRIGHT: - case HTGROWBOX: - case HTCAPTION: - pos_change_direction |= - kBoundsChangeDirection_Horizontal | kBoundsChangeDirection_Vertical; - break; - case HTTOP: - case HTTOPRIGHT: - case HTBOTTOM: - pos_change_direction |= kBoundsChangeDirection_Vertical; - break; - case HTBOTTOMLEFT: - case HTRIGHT: - case HTLEFT: - pos_change_direction |= kBoundsChangeDirection_Horizontal; - break; - default: - break; - } - return pos_change_direction; -} - -int GetSizeChangeDirectionForWindowComponent(int window_component) { - int size_change_direction = kBoundsChangeDirection_None; - switch (window_component) { - case HTTOPLEFT: - case HTTOPRIGHT: - case HTBOTTOMLEFT: - case HTBOTTOMRIGHT: - case HTGROWBOX: - case HTCAPTION: - size_change_direction |= - kBoundsChangeDirection_Horizontal | kBoundsChangeDirection_Vertical; - break; - case HTTOP: - case HTBOTTOM: - size_change_direction |= kBoundsChangeDirection_Vertical; - break; - case HTRIGHT: - case HTLEFT: - size_change_direction |= kBoundsChangeDirection_Horizontal; - break; - default: - break; - } - return size_change_direction; -} - -// Returns true for resize components along the right edge, where a drag in -// positive x will make the window larger. -bool IsRightEdge(int window_component) { - return window_component == HTTOPRIGHT || - window_component == HTRIGHT || - window_component == HTBOTTOMRIGHT || - window_component == HTGROWBOX; -} - -// Returns true for resize components in along the bottom edge, where a drag -// in positive y will make the window larger. -bool IsBottomEdge(int window_component) { - return window_component == HTBOTTOMLEFT || - window_component == HTBOTTOM || - window_component == HTBOTTOMRIGHT || - window_component == HTGROWBOX; -} - -void ToggleMaximizedState(aura::Window* window) { - window->SetIntProperty(aura::client::kShowStateKey, - IsWindowMaximized(window) ? - ui::SHOW_STATE_NORMAL : ui::SHOW_STATE_MAXIMIZED); -} - -} // namespace - -ToplevelWindowEventFilter::ToplevelWindowEventFilter(aura::Window* owner) - : EventFilter(owner), - window_component_(HTNOWHERE) { -} - -ToplevelWindowEventFilter::~ToplevelWindowEventFilter() { -} - -bool ToplevelWindowEventFilter::PreHandleKeyEvent(aura::Window* target, - aura::KeyEvent* event) { - return false; -} - -bool ToplevelWindowEventFilter::PreHandleMouseEvent(aura::Window* target, - aura::MouseEvent* event) { - // Process EventFilters implementation first so that it processes - // activation/focus first. - switch (event->type()) { - case ui::ET_MOUSE_MOVED: - UpdateWindowComponentForEvent(target, event); - break; - case ui::ET_MOUSE_PRESSED: - // We also update the current window component here because for the - // mouse-drag-release-press case, where the mouse is released and - // pressed without mouse move event. - UpdateWindowComponentForEvent(target, event); - if (window_component_ == HTCAPTION && - event->flags() & ui::EF_IS_DOUBLE_CLICK) { - ToggleMaximizedState(target); - } - UpdateLocationFromEvent(target, event); - return GetBoundsChangeForWindowComponent(window_component_) != - kBoundsChange_None; - case ui::ET_MOUSE_DRAGGED: - return HandleDrag(target, event); - case ui::ET_MOUSE_RELEASED: - window_component_ = HTNOWHERE; - break; - default: - break; - } - return false; -} - -ui::TouchStatus ToplevelWindowEventFilter::PreHandleTouchEvent( - aura::Window* target, - aura::TouchEvent* event) { - // Process EventFilters implementation first so that it processes - // activation/focus first. - // TODO(sad): Allow resizing/maximizing etc. from touch? - UpdateWindowComponentForEvent(target, event); - int bounds_change = GetBoundsChangeForWindowComponent(window_component_); - if (bounds_change == kBoundsChange_None) - return ui::TOUCH_STATUS_UNKNOWN; - - // Handle touch move by simulate mouse drag with single touch. - switch (event->type()) { - case ui::ET_TOUCH_PRESSED: - UpdateLocationFromEvent(target, event); - pressed_touch_ids_.insert(event->touch_id()); - if (pressed_touch_ids_.size() == 1) - return ui::TOUCH_STATUS_START; - break; - case ui::ET_TOUCH_MOVED: - if (pressed_touch_ids_.size() == 1) { - if (HandleDrag(target, event)) - return ui::TOUCH_STATUS_CONTINUE; - } - break; - case ui::ET_TOUCH_RELEASED: - pressed_touch_ids_.erase(event->touch_id()); - if (pressed_touch_ids_.empty()) { - window_component_ = HTNOWHERE; - return ui::TOUCH_STATUS_END; - } - break; - default: - break; - } - return ui::TOUCH_STATUS_UNKNOWN; -} - -void ToplevelWindowEventFilter::MoveWindowToFront(aura::Window* target) { - aura::Window* parent = target->parent(); - aura::Window* child = target; - while (parent) { - parent->StackChildAtTop(child); - if (parent == owner()) - break; - parent = parent->parent(); - child = child->parent(); - } -} - -bool ToplevelWindowEventFilter::HandleDrag(aura::Window* target, - aura::LocatedEvent* event) { - // This function only be triggered to move window - // by mouse drag or touch move event. - DCHECK(event->type() == ui::ET_MOUSE_DRAGGED || - event->type() == ui::ET_TOUCH_MOVED); - - int bounds_change = GetBoundsChangeForWindowComponent(window_component_); - if (bounds_change == kBoundsChange_None) - return false; - - // Only a normal/default window can be moved/resized. - if (target->GetIntProperty(aura::client::kShowStateKey) != - ui::SHOW_STATE_NORMAL && - target->GetIntProperty(aura::client::kShowStateKey) != - ui::SHOW_STATE_DEFAULT) - return false; - - // Dragging a window moves the local coordinate frame, so do arithmetic - // in the parent coordinate frame. - gfx::Point event_location_in_parent(event->location()); - aura::Window::ConvertPointToWindow(target, target->parent(), - &event_location_in_parent); - int delta_x = event_location_in_parent.x() - mouse_down_offset_in_parent_.x(); - int delta_y = event_location_in_parent.y() - mouse_down_offset_in_parent_.y(); - - // The minimize size constraint may limit how much we change the window - // position. For example, dragging the left edge to the right should stop - // repositioning the window when the minimize size is reached. - gfx::Size size = GetSizeForDrag(bounds_change, target, &delta_x, &delta_y); - gfx::Point origin = GetOriginForDrag(bounds_change, delta_x, delta_y); - - target->SetBounds(gfx::Rect(origin, size)); - return true; -} - -void ToplevelWindowEventFilter::UpdateLocationFromEvent( - aura::Window* target, - aura::LocatedEvent* event) { - mouse_down_bounds_ = target->bounds(); - mouse_down_offset_in_parent_ = event->location(); - aura::Window::ConvertPointToWindow(target, target->parent(), - &mouse_down_offset_in_parent_); -} - -void ToplevelWindowEventFilter::UpdateWindowComponentForEvent( - aura::Window* target, - aura::LocatedEvent* event) { - window_component_ = - target->delegate()->GetNonClientComponent(event->location()); -} - -gfx::Point ToplevelWindowEventFilter::GetOriginForDrag( - int bounds_change, - int delta_x, - int delta_y) const { - gfx::Point origin = mouse_down_bounds_.origin(); - if (bounds_change & kBoundsChange_Repositions) { - int pos_change_direction = - GetPositionChangeDirectionForWindowComponent(window_component_); - if (pos_change_direction & kBoundsChangeDirection_Horizontal) - origin.Offset(delta_x, 0); - if (pos_change_direction & kBoundsChangeDirection_Vertical) - origin.Offset(0, delta_y); - } - return origin; -} - -gfx::Size ToplevelWindowEventFilter::GetSizeForDrag( - int bounds_change, - aura::Window* target, - int* delta_x, - int* delta_y) const { - gfx::Size size = mouse_down_bounds_.size(); - if (bounds_change & kBoundsChange_Resizes) { - gfx::Size min_size = target->delegate()->GetMinimumSize(); - int size_change_direction = - GetSizeChangeDirectionForWindowComponent(window_component_); - size.SetSize( - GetWidthForDrag(size_change_direction, min_size.width(), delta_x), - GetHeightForDrag(size_change_direction, min_size.height(), delta_y)); - } - return size; -} - -int ToplevelWindowEventFilter::GetWidthForDrag(int size_change_direction, - int min_width, - int* delta_x) const { - int width = mouse_down_bounds_.width(); - if (size_change_direction & kBoundsChangeDirection_Horizontal) { - // Along the right edge, positive delta_x increases the window size. - int x_multiplier = IsRightEdge(window_component_) ? 1 : -1; - width += x_multiplier * (*delta_x); - - // Ensure we don't shrink past the minimum width and clamp delta_x - // for the window origin computation. - if (width < min_width) { - width = min_width; - *delta_x = -x_multiplier * (mouse_down_bounds_.width() - min_width); - } - } - return width; -} - -int ToplevelWindowEventFilter::GetHeightForDrag(int size_change_direction, - int min_height, - int* delta_y) const { - int height = mouse_down_bounds_.height(); - if (size_change_direction & kBoundsChangeDirection_Vertical) { - // Along the bottom edge, positive delta_y increases the window size. - int y_multiplier = IsBottomEdge(window_component_) ? 1 : -1; - height += y_multiplier * (*delta_y); - - // Ensure we don't shrink past the minimum height and clamp delta_y - // for the window origin computation. - if (height < min_height) { - height = min_height; - *delta_y = -y_multiplier * (mouse_down_bounds_.height() - min_height); - } - } - return height; -} - -} // namespace aura diff --git a/ui/aura_shell/toplevel_window_event_filter.h b/ui/aura_shell/toplevel_window_event_filter.h deleted file mode 100644 index 50f290a..0000000 --- a/ui/aura_shell/toplevel_window_event_filter.h +++ /dev/null @@ -1,105 +0,0 @@ -// Copyright (c) 2011 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. - -#ifndef UI_AURA_SHELL_TOPLEVEL_WINDOW_EVENT_FILTER_H_ -#define UI_AURA_SHELL_TOPLEVEL_WINDOW_EVENT_FILTER_H_ -#pragma once - -#include <set> - -#include "base/compiler_specific.h" -#include "ui/aura/event_filter.h" -#include "ui/aura_shell/aura_shell_export.h" -#include "ui/gfx/point.h" -#include "ui/gfx/rect.h" - -namespace aura { -class LocatedEvent; -class MouseEvent; -class Window; -} - -namespace aura_shell { - -class AURA_SHELL_EXPORT ToplevelWindowEventFilter : public aura::EventFilter { - public: - explicit ToplevelWindowEventFilter(aura::Window* owner); - virtual ~ToplevelWindowEventFilter(); - - // Overridden from aura::EventFilter: - virtual bool PreHandleKeyEvent(aura::Window* target, - aura::KeyEvent* event) OVERRIDE; - virtual bool PreHandleMouseEvent(aura::Window* target, - aura::MouseEvent* event) OVERRIDE; - virtual ui::TouchStatus PreHandleTouchEvent(aura::Window* target, - aura::TouchEvent* event) OVERRIDE; - - protected: - // Returns the |window_component_|. See the variable definition below for - // more details. - int window_component() const { return window_component_; } - - private: - // Moves the target window and all of its parents to the front of their - // respective z-orders. - // NOTE: this does NOT activate the window. - void MoveWindowToFront(aura::Window* target); - - // Called during a drag to resize/position the window. - // The return value is returned by OnMouseEvent() above. - bool HandleDrag(aura::Window* target, aura::LocatedEvent* event); - - // Updates the event location to window. - void UpdateLocationFromEvent(aura::Window* target, - aura::LocatedEvent* event); - - // Updates the |window_component_| using the |event|'s location. - void UpdateWindowComponentForEvent(aura::Window* window, - aura::LocatedEvent* event); - - // Calculates the new origin of the window during a drag. - gfx::Point GetOriginForDrag(int bounds_change, - int delta_x, - int delta_y) const; - - // Calculates the new size of the |target| window during a drag. - // If the size is constrained, |delta_x| and |delta_y| may be clamped. - gfx::Size GetSizeForDrag(int bounds_change, - aura::Window* target, - int* delta_x, - int* delta_y) const; - - // Calculates new width of a window during a drag where the mouse - // position changed by |delta_x|. |delta_x| may be clamped if the window - // size is constrained by |min_width|. - int GetWidthForDrag(int size_change_direction, - int min_width, - int* delta_x) const; - - // Calculates new height of a window during a drag where the mouse - // position changed by |delta_y|. |delta_y| may be clamped if the window - // size is constrained by |min_height|. - int GetHeightForDrag(int size_change_direction, - int min_height, - int* delta_y) const; - - // The mouse position in the target window when the mouse was pressed, in - // the target window's parent's coordinates. - gfx::Point mouse_down_offset_in_parent_; - - // The bounds of the target window when the mouse was pressed. - gfx::Rect mouse_down_bounds_; - - // The window component (hit-test code) the mouse is currently over. - int window_component_; - - // Set of touch ids currently pressed. - std::set<int> pressed_touch_ids_; - - DISALLOW_COPY_AND_ASSIGN(ToplevelWindowEventFilter); -}; - -} // namespace aura - -#endif // UI_AURA_SHELL_TOPLEVEL_WINDOW_EVENT_FILTER_H_ diff --git a/ui/aura_shell/toplevel_window_event_filter_unittest.cc b/ui/aura_shell/toplevel_window_event_filter_unittest.cc deleted file mode 100644 index 72ca952..0000000 --- a/ui/aura_shell/toplevel_window_event_filter_unittest.cc +++ /dev/null @@ -1,324 +0,0 @@ -// Copyright (c) 2011 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 "base/basictypes.h" -#include "base/compiler_specific.h" -#include "testing/gtest/include/gtest/gtest.h" -#include "ui/aura/event.h" -#include "ui/aura/root_window.h" -#include "ui/aura/test/aura_test_base.h" -#include "ui/aura/test/event_generator.h" -#include "ui/aura/test/test_window_delegate.h" -#include "ui/aura_shell/toplevel_window_event_filter.h" -#include "ui/aura_shell/window_util.h" -#include "ui/base/hit_test.h" -#include "ui/gfx/screen.h" - -#if defined(OS_WIN) -// Windows headers define macros for these function names which screw with us. -#if defined(CreateWindow) -#undef CreateWindow -#endif -#endif - - -namespace aura_shell { -namespace test { - -namespace { - -// A simple window delegate that returns the specified hit-test code when -// requested and applies a minimum size constraint if there is one. -class TestWindowDelegate : public aura::test::TestWindowDelegate { - public: - explicit TestWindowDelegate(int hittest_code) - : hittest_code_(hittest_code) { - } - virtual ~TestWindowDelegate() {} - - void set_min_size(const gfx::Size& size) { - min_size_ = size; - } - - private: - // Overridden from aura::Test::TestWindowDelegate: - virtual gfx::Size GetMinimumSize() const OVERRIDE { - return min_size_; - } - virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE { - return hittest_code_; - } - virtual void OnWindowDestroyed() OVERRIDE { - delete this; - } - - int hittest_code_; - gfx::Size min_size_; - - DISALLOW_COPY_AND_ASSIGN(TestWindowDelegate); -}; - -class ToplevelWindowEventFilterTest : public aura::test::AuraTestBase { - public: - ToplevelWindowEventFilterTest() {} - virtual ~ToplevelWindowEventFilterTest() {} - - virtual void SetUp() OVERRIDE { - aura::test::AuraTestBase::SetUp(); - aura::RootWindow::GetInstance()->SetEventFilter( - new ToplevelWindowEventFilter(aura::RootWindow::GetInstance())); - } - - protected: - aura::Window* CreateWindow(int hittest_code) { - TestWindowDelegate* d1 = new TestWindowDelegate(hittest_code); - aura::Window* w1 = new aura::Window(d1); - w1->set_id(1); - w1->Init(ui::Layer::LAYER_HAS_TEXTURE); - w1->SetParent(NULL); - w1->SetBounds(gfx::Rect(0, 0, 100, 100)); - w1->Show(); - return w1; - } - - void DragFromCenterBy(aura::Window* window, int dx, int dy) { - aura::test::EventGenerator generator(window); - generator.DragMouseBy(dx, dy); - } - - void TouchDragFromCenterBy(aura::Window* window, int dx, int dy) { - aura::test::EventGenerator generator(window); - generator.PressMoveAndReleaseTouchBy(dx, dy); - } - - private: - DISALLOW_COPY_AND_ASSIGN(ToplevelWindowEventFilterTest); -}; - -} - -TEST_F(ToplevelWindowEventFilterTest, Caption) { - scoped_ptr<aura::Window> w1(CreateWindow(HTCAPTION)); - gfx::Size size = w1->bounds().size(); - DragFromCenterBy(w1.get(), 100, 100); - // Position should have been offset by 100,100. - EXPECT_EQ(gfx::Point(100, 100), w1->bounds().origin()); - // Size should not have. - EXPECT_EQ(size, w1->bounds().size()); - - TouchDragFromCenterBy(w1.get(), 100, 100); - // Position should have been offset by 100,100. - EXPECT_EQ(gfx::Point(200, 200), w1->bounds().origin()); - // Size should not have. - EXPECT_EQ(size, w1->bounds().size()); -} - -TEST_F(ToplevelWindowEventFilterTest, BottomRight) { - scoped_ptr<aura::Window> w1(CreateWindow(HTBOTTOMRIGHT)); - gfx::Point position = w1->bounds().origin(); - DragFromCenterBy(w1.get(), 100, 100); - // Position should not have changed. - EXPECT_EQ(position, w1->bounds().origin()); - // Size should have increased by 100,100. - EXPECT_EQ(gfx::Size(200, 200), w1->bounds().size()); -} - -TEST_F(ToplevelWindowEventFilterTest, GrowBox) { - scoped_ptr<aura::Window> w1(CreateWindow(HTGROWBOX)); - TestWindowDelegate* window_delegate = - static_cast<TestWindowDelegate*>(w1->delegate()); - window_delegate->set_min_size(gfx::Size(40, 40)); - - gfx::Point position = w1->bounds().origin(); - aura::test::EventGenerator generator; - generator.MoveMouseToCenterOf(w1.get()); - generator.DragMouseBy(100, 100); - // Position should not have changed. - EXPECT_EQ(position, w1->bounds().origin()); - // Size should have increased by 100,100. - EXPECT_EQ(gfx::Size(200, 200), w1->bounds().size()); - - // Shrink the wnidow by (-100, -100). - generator.DragMouseBy(-100, -100); - // Position should not have changed. - EXPECT_EQ(position, w1->bounds().origin()); - // Size should have decreased by 100,100. - EXPECT_EQ(gfx::Size(100, 100), w1->bounds().size()); - - // Enforce minimum size. - generator.DragMouseBy(-60, -60); - EXPECT_EQ(position, w1->bounds().origin()); - EXPECT_EQ(gfx::Size(40, 40), w1->bounds().size()); -} - -TEST_F(ToplevelWindowEventFilterTest, Right) { - scoped_ptr<aura::Window> w1(CreateWindow(HTRIGHT)); - gfx::Point position = w1->bounds().origin(); - DragFromCenterBy(w1.get(), 100, 100); - // Position should not have changed. - EXPECT_EQ(position, w1->bounds().origin()); - // Size should have increased by 100,0. - EXPECT_EQ(gfx::Size(200, 100), w1->bounds().size()); -} - -TEST_F(ToplevelWindowEventFilterTest, Bottom) { - scoped_ptr<aura::Window> w1(CreateWindow(HTBOTTOM)); - gfx::Point position = w1->bounds().origin(); - DragFromCenterBy(w1.get(), 100, 100); - // Position should not have changed. - EXPECT_EQ(position, w1->bounds().origin()); - // Size should have increased by 0,100. - EXPECT_EQ(gfx::Size(100, 200), w1->bounds().size()); -} - -TEST_F(ToplevelWindowEventFilterTest, TopRight) { - scoped_ptr<aura::Window> w1(CreateWindow(HTTOPRIGHT)); - DragFromCenterBy(w1.get(), -50, 50); - // Position should have been offset by 0,50. - EXPECT_EQ(gfx::Point(0, 50), w1->bounds().origin()); - // Size should have decreased by 50,50. - EXPECT_EQ(gfx::Size(50, 50), w1->bounds().size()); -} - -TEST_F(ToplevelWindowEventFilterTest, Top) { - scoped_ptr<aura::Window> w1(CreateWindow(HTTOP)); - DragFromCenterBy(w1.get(), 50, 50); - // Position should have been offset by 0,50. - EXPECT_EQ(gfx::Point(0, 50), w1->bounds().origin()); - // Size should have decreased by 0,50. - EXPECT_EQ(gfx::Size(100, 50), w1->bounds().size()); -} - -TEST_F(ToplevelWindowEventFilterTest, Left) { - scoped_ptr<aura::Window> w1(CreateWindow(HTLEFT)); - DragFromCenterBy(w1.get(), 50, 50); - // Position should have been offset by 50,0. - EXPECT_EQ(gfx::Point(50, 0), w1->bounds().origin()); - // Size should have decreased by 50,0. - EXPECT_EQ(gfx::Size(50, 100), w1->bounds().size()); -} - -TEST_F(ToplevelWindowEventFilterTest, BottomLeft) { - scoped_ptr<aura::Window> w1(CreateWindow(HTBOTTOMLEFT)); - DragFromCenterBy(w1.get(), 50, -50); - // Position should have been offset by 50,0. - EXPECT_EQ(gfx::Point(50, 0), w1->bounds().origin()); - // Size should have decreased by 50,50. - EXPECT_EQ(gfx::Size(50, 50), w1->bounds().size()); -} - -TEST_F(ToplevelWindowEventFilterTest, TopLeft) { - scoped_ptr<aura::Window> w1(CreateWindow(HTTOPLEFT)); - DragFromCenterBy(w1.get(), 50, 50); - // Position should have been offset by 50,50. - EXPECT_EQ(gfx::Point(50, 50), w1->bounds().origin()); - // Size should have decreased by 50,50. - EXPECT_EQ(gfx::Size(50, 50), w1->bounds().size()); -} - -TEST_F(ToplevelWindowEventFilterTest, Client) { - scoped_ptr<aura::Window> w1(CreateWindow(HTCLIENT)); - gfx::Rect bounds = w1->bounds(); - DragFromCenterBy(w1.get(), 100, 100); - // Neither position nor size should have changed. - EXPECT_EQ(bounds, w1->bounds()); -} - -TEST_F(ToplevelWindowEventFilterTest, LeftPastMinimum) { - scoped_ptr<aura::Window> w1(CreateWindow(HTLEFT)); - TestWindowDelegate* window_delegate = - static_cast<TestWindowDelegate*>(w1->delegate()); - window_delegate->set_min_size(gfx::Size(40, 40)); - - // Simulate a large left-to-right drag. Window width should be clamped to - // minimum and position change should be limited as well. - DragFromCenterBy(w1.get(), 333, 0); - EXPECT_EQ(gfx::Point(60, 0), w1->bounds().origin()); - EXPECT_EQ(gfx::Size(40, 100), w1->bounds().size()); -} - -TEST_F(ToplevelWindowEventFilterTest, RightPastMinimum) { - scoped_ptr<aura::Window> w1(CreateWindow(HTRIGHT)); - TestWindowDelegate* window_delegate = - static_cast<TestWindowDelegate*>(w1->delegate()); - window_delegate->set_min_size(gfx::Size(40, 40)); - gfx::Point position = w1->bounds().origin(); - - // Simulate a large right-to-left drag. Window width should be clamped to - // minimum and position should not change. - DragFromCenterBy(w1.get(), -333, 0); - EXPECT_EQ(position, w1->bounds().origin()); - EXPECT_EQ(gfx::Size(40, 100), w1->bounds().size()); -} - -TEST_F(ToplevelWindowEventFilterTest, TopLeftPastMinimum) { - scoped_ptr<aura::Window> w1(CreateWindow(HTTOPLEFT)); - TestWindowDelegate* window_delegate = - static_cast<TestWindowDelegate*>(w1->delegate()); - window_delegate->set_min_size(gfx::Size(40, 40)); - - // Simulate a large top-left to bottom-right drag. Window width should be - // clamped to minimum and position should be limited. - DragFromCenterBy(w1.get(), 333, 444); - EXPECT_EQ(gfx::Point(60, 60), w1->bounds().origin()); - EXPECT_EQ(gfx::Size(40, 40), w1->bounds().size()); -} - -TEST_F(ToplevelWindowEventFilterTest, TopRightPastMinimum) { - scoped_ptr<aura::Window> w1(CreateWindow(HTTOPRIGHT)); - TestWindowDelegate* window_delegate = - static_cast<TestWindowDelegate*>(w1->delegate()); - window_delegate->set_min_size(gfx::Size(40, 40)); - - // Simulate a large top-right to bottom-left drag. Window size should be - // clamped to minimum, x position should not change, and y position should - // be clamped. - DragFromCenterBy(w1.get(), -333, 444); - EXPECT_EQ(gfx::Point(0, 60), w1->bounds().origin()); - EXPECT_EQ(gfx::Size(40, 40), w1->bounds().size()); -} - -TEST_F(ToplevelWindowEventFilterTest, BottomLeftPastMinimum) { - scoped_ptr<aura::Window> w1(CreateWindow(HTBOTTOMLEFT)); - TestWindowDelegate* window_delegate = - static_cast<TestWindowDelegate*>(w1->delegate()); - window_delegate->set_min_size(gfx::Size(40, 40)); - - // Simulate a large bottom-left to top-right drag. Window size should be - // clamped to minimum, x position should be clamped, and y position should - // not change. - DragFromCenterBy(w1.get(), 333, -444); - EXPECT_EQ(gfx::Point(60, 0), w1->bounds().origin()); - EXPECT_EQ(gfx::Size(40, 40), w1->bounds().size()); -} - -TEST_F(ToplevelWindowEventFilterTest, BottomRightPastMinimum) { - scoped_ptr<aura::Window> w1(CreateWindow(HTBOTTOMRIGHT)); - TestWindowDelegate* window_delegate = - static_cast<TestWindowDelegate*>(w1->delegate()); - window_delegate->set_min_size(gfx::Size(40, 40)); - gfx::Point position = w1->bounds().origin(); - - // Simulate a large bottom-right to top-left drag. Window size should be - // clamped to minimum and position should not change. - DragFromCenterBy(w1.get(), -333, -444); - EXPECT_EQ(position, w1->bounds().origin()); - EXPECT_EQ(gfx::Size(40, 40), w1->bounds().size()); -} - -TEST_F(ToplevelWindowEventFilterTest, DoubleClickCaptionTogglesMaximize) { - scoped_ptr<aura::Window> w1(CreateWindow(HTCAPTION)); - EXPECT_FALSE(IsWindowMaximized(w1.get())); - - aura::test::EventGenerator generator(w1.get()); - generator.DoubleClickLeftButton(); - - EXPECT_TRUE(IsWindowMaximized(w1.get())); - generator.DoubleClickLeftButton(); - - EXPECT_FALSE(IsWindowMaximized(w1.get())); -} - -} // namespace test -} // namespace aura diff --git a/ui/aura_shell/window_frame.cc b/ui/aura_shell/window_frame.cc deleted file mode 100644 index d4ae694..0000000 --- a/ui/aura_shell/window_frame.cc +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) 2011 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 "ui/aura_shell/window_frame.h" - -namespace aura_shell { - -const char* const kWindowFrameKey = "WindowFrameKey"; - -} diff --git a/ui/aura_shell/window_frame.h b/ui/aura_shell/window_frame.h deleted file mode 100644 index 474f6a0..0000000 --- a/ui/aura_shell/window_frame.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) 2011 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. - -#ifndef UI_AURA_SHELL_WINDOW_FRAME_H_ -#define UI_AURA_SHELL_WINDOW_FRAME_H_ -#pragma once - -#include "ui/aura_shell/aura_shell_export.h" - -namespace aura_shell { - -// aura::Window property name for a pointer to the WindowFrame interface. -AURA_SHELL_EXPORT extern const char* const kWindowFrameKey; - -// Interface for clients implementing a window frame. Implementors should -// add a pointer to this interface to each aura::Window, using the key above. -class AURA_SHELL_EXPORT WindowFrame { - public: - virtual ~WindowFrame() {} - - // Called when the mouse enters or exits a top-level window. - virtual void OnWindowHoverChanged(bool hovered) = 0; -}; - -} // namespace aura_shell - -#endif // UI_AURA_SHELL_WINDOW_FRAME_H_ diff --git a/ui/aura_shell/window_properties.cc b/ui/aura_shell/window_properties.cc deleted file mode 100644 index 8ffe786..0000000 --- a/ui/aura_shell/window_properties.cc +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) 2011 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 "ui/aura_shell/window_properties.h" - -namespace aura_shell { -namespace internal { - -// Alphabetical sort. - -const char kShadowTypeKey[] = "ShadowType"; - -// Alphabetical sort. - -} // namespace internal -} // namespace aura_shell diff --git a/ui/aura_shell/window_properties.h b/ui/aura_shell/window_properties.h deleted file mode 100644 index b919333..0000000 --- a/ui/aura_shell/window_properties.h +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) 2011 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. - -#ifndef UI_AURA_SHELL_WINDOW_PROPERTIES_H_ -#define UI_AURA_SHELL_WINDOW_PROPERTIES_H_ -#pragma once - -namespace aura_shell { -namespace internal { - -// Shell-specific window property keys. - -// Alphabetical sort. - -// A property key for a value from ShadowType describing the drop shadow that -// should be displayed under the window. If unset, no shadow is displayed. -extern const char kShadowTypeKey[]; - -// Alphabetical sort. - -} // namespace internal -} // namespace aura_shell - -#endif // UI_AURA_SHELL_WINDOW_PROPERTIES_H_ diff --git a/ui/aura_shell/window_util.cc b/ui/aura_shell/window_util.cc deleted file mode 100644 index 6dd9cde..0000000 --- a/ui/aura_shell/window_util.cc +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright (c) 2011 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 "ui/aura_shell/window_util.h" - -#include "ash/wm/activation_controller.h" -#include "ui/aura/client/activation_client.h" -#include "ui/aura/client/aura_constants.h" -#include "ui/aura/root_window.h" -#include "ui/aura/window.h" -#include "ui/aura_shell/property_util.h" -#include "ui/base/ui_base_types.h" -#include "ui/gfx/screen.h" - -namespace aura_shell { - -bool IsWindowMaximized(aura::Window* window) { - return window->GetIntProperty(aura::client::kShowStateKey) == - ui::SHOW_STATE_MAXIMIZED; -} - -void ActivateWindow(aura::Window* window) { - aura::client::GetActivationClient()->ActivateWindow(window); -} - -void DeactivateWindow(aura::Window* window) { - aura::client::GetActivationClient()->DeactivateWindow(window); -} - -bool IsActiveWindow(aura::Window* window) { - return GetActiveWindow() == window; -} - -aura::Window* GetActiveWindow() { - return aura::client::GetActivationClient()->GetActiveWindow(); -} - -aura::Window* GetActivatableWindow(aura::Window* window) { - return internal::ActivationController::GetActivatableWindow(window); -} - -void 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; - } -} - -bool HasFullscreenWindow(const WindowSet& windows) { - for (WindowSet::const_iterator i = windows.begin(); i != windows.end(); ++i) { - if ((*i)->GetIntProperty(aura::client::kShowStateKey) - == ui::SHOW_STATE_FULLSCREEN) { - return true; - } - } - return false; -} - -} // namespace aura_shell diff --git a/ui/aura_shell/window_util.h b/ui/aura_shell/window_util.h deleted file mode 100644 index afe8465..0000000 --- a/ui/aura_shell/window_util.h +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (c) 2011 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. - -#ifndef UI_AURA_SHELL_WINDOW_UTIL_H_ -#define UI_AURA_SHELL_WINDOW_UTIL_H_ -#pragma once - -#include <set> - -#include "ui/aura_shell/aura_shell_export.h" - -namespace aura { -class Window; -} - -namespace aura_shell { - -// TODO(jamescook): Put all these functions in namespace window_util. - -// Returns true if |window| is in the maximized state. -AURA_SHELL_EXPORT bool IsWindowMaximized(aura::Window* window); - -// Convenience setters/getters for |aura::client::kRootWindowActiveWindow|. -AURA_SHELL_EXPORT void ActivateWindow(aura::Window* window); -AURA_SHELL_EXPORT void DeactivateWindow(aura::Window* window); -AURA_SHELL_EXPORT bool IsActiveWindow(aura::Window* window); -AURA_SHELL_EXPORT aura::Window* GetActiveWindow(); - -// Retrieves the activatable window for |window|. If |window| is activatable, -// this will just return it, otherwise it will climb the parent/transient parent -// chain looking for a window that is activatable, per the ActivationController. -// If you're looking for a function to get the activatable "top level" window, -// this is probably what you're looking for. -AURA_SHELL_EXPORT aura::Window* GetActivatableWindow(aura::Window* window); - -// Update window bounds based on a change in show state. -AURA_SHELL_EXPORT void UpdateBoundsFromShowState(aura::Window* window); - -// Returns true if the set of |windows| contains a full-screen window. -typedef std::set<aura::Window*> WindowSet; -AURA_SHELL_EXPORT bool HasFullscreenWindow(const WindowSet& windows); - -} // namespace aura_shell - -#endif // UI_AURA_SHELL_WINDOW_UTIL_H_ diff --git a/ui/aura_shell/workspace/workspace.cc b/ui/aura_shell/workspace/workspace.cc deleted file mode 100644 index a705936..0000000 --- a/ui/aura_shell/workspace/workspace.cc +++ /dev/null @@ -1,286 +0,0 @@ -// Copyright (c) 2011 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 "ui/aura_shell/workspace/workspace.h" - -#include <algorithm> - -#include "base/logging.h" -#include "ui/aura/client/aura_constants.h" -#include "ui/aura/root_window.h" -#include "ui/aura/window.h" -#include "ui/aura_shell/property_util.h" -#include "ui/aura_shell/window_util.h" -#include "ui/aura_shell/workspace/workspace_manager.h" -#include "ui/base/ui_base_types.h" -#include "ui/gfx/compositor/layer.h" -#include "ui/gfx/compositor/layer_animator.h" - -namespace { -// Horizontal margin between windows. -const int kWindowHorizontalMargin = 10; - -// Maximum number of windows a workspace can have. -size_t g_max_windows_per_workspace = 2; - -// Returns the bounds of the window that should be used to calculate -// the layout. It uses the restore bounds if exits, or -// the target bounds of the window. The target bounds is the -// final destination of |window| if the window's layer is animating, -// or the current bounds of the window of no animation is currently -// in progress. -gfx::Rect GetLayoutBounds(aura::Window* window) { - const gfx::Rect* restore_bounds = aura_shell::GetRestoreBounds(window); - return restore_bounds ? *restore_bounds : window->GetTargetBounds(); -} - -// Returns the width of the window that should be used to calculate -// the layout. See |GetLayoutBounds| for more details. -int GetLayoutWidth(aura::Window* window) { - return GetLayoutBounds(window).width(); -} - -} // namespace - -namespace aura_shell { -namespace internal { - -Workspace::Workspace(WorkspaceManager* manager) - : workspace_manager_(manager) { - workspace_manager_->AddWorkspace(this); -} - -Workspace::~Workspace() { - workspace_manager_->RemoveWorkspace(this); -} - -void Workspace::SetBounds(const gfx::Rect& bounds) { - bool bounds_changed = bounds_ != bounds; - bounds_ = bounds; - if (bounds_changed) - Layout(NULL); -} - -gfx::Rect Workspace::GetWorkAreaBounds() const { - return workspace_manager_->GetWorkAreaBounds(bounds_); -} - -bool Workspace::AddWindowAfter(aura::Window* window, aura::Window* after) { - if (!CanAdd(window)) - return false; - DCHECK(!Contains(window)); - - if (!after) { // insert at the end. - windows_.push_back(window); - } else { - DCHECK(Contains(after)); - aura::Window::Windows::iterator i = - std::find(windows_.begin(), windows_.end(), after); - windows_.insert(++i, window); - } - Layout(window); - - return true; -} - -void Workspace::RemoveWindow(aura::Window* window) { - DCHECK(Contains(window)); - windows_.erase(std::find(windows_.begin(), windows_.end(), window)); - Layout(NULL); -} - -bool Workspace::Contains(aura::Window* window) const { - return std::find(windows_.begin(), windows_.end(), window) != windows_.end(); -} - -aura::Window* Workspace::FindRotateWindowForLocation( - const gfx::Point& position) { - aura::Window* active = aura_shell::GetActiveWindow(); - if (GetTotalWindowsWidth() < bounds_.width()) { - // If all windows fit to the width of the workspace, it returns the - // window which contains |position|'s x coordinate. - for (aura::Window::Windows::const_iterator i = windows_.begin(); - i != windows_.end(); - ++i) { - if (active == *i) - continue; - gfx::Rect bounds = (*i)->GetTargetBounds(); - if (bounds.x() < position.x() && position.x() < bounds.right()) - return *i; - } - } else if (bounds_.x() < position.x() && position.x() < bounds_.right()) { - // If windows are overlapping, it divides the workspace into - // regions with the same width, and returns the Nth window that - // corresponds to the region that contains the |position|. - int width = bounds_.width() / windows_.size(); - size_t index = (position.x() - bounds_.x()) / width; - DCHECK(index < windows_.size()); - aura::Window* window = windows_[index]; - if (window != active) - return window; - } - return NULL; -} - -void Workspace::RotateWindows(aura::Window* source, aura::Window* target) { - DCHECK(Contains(source)); - DCHECK(Contains(target)); - aura::Window::Windows::iterator source_iter = - std::find(windows_.begin(), windows_.end(), source); - aura::Window::Windows::iterator target_iter = - std::find(windows_.begin(), windows_.end(), target); - DCHECK(source_iter != target_iter); - if (source_iter < target_iter) - std::rotate(source_iter, source_iter + 1, target_iter + 1); - else - std::rotate(target_iter, source_iter, source_iter + 1); - Layout(NULL); -} - -aura::Window* Workspace::ShiftWindows(aura::Window* insert, - aura::Window* until, - aura::Window* target, - ShiftDirection direction) { - DCHECK(until); - DCHECK(!Contains(insert)); - - bool shift_reached_until = GetIndexOf(until) >= 0; - if (shift_reached_until) { - // Calling RemoveWindow here causes the animation set in Layout below - // to be ignored. See crbug.com/102413. - windows_.erase(std::find(windows_.begin(), windows_.end(), until)); - } - aura::Window* pushed = NULL; - if (direction == SHIFT_TO_RIGHT) { - aura::Window::Windows::iterator iter = - std::find(windows_.begin(), windows_.end(), target); - // Insert at |target| position, or at the begining. - if (iter == windows_.end()) - iter = windows_.begin(); - windows_.insert(iter, insert); - if (!shift_reached_until) { - pushed = windows_.back(); - windows_.erase(--windows_.end()); - } - } else { - aura::Window::Windows::iterator iter = - std::find(windows_.begin(), windows_.end(), target); - // Insert after |target|, or at the end. - if (iter != windows_.end()) - ++iter; - windows_.insert(iter, insert); - if (!shift_reached_until) { - pushed = windows_.front(); - windows_.erase(windows_.begin()); - } - } - Layout(NULL); - return pushed; -} - -void Workspace::Activate() { - workspace_manager_->SetActiveWorkspace(this); -} - -void Workspace::Layout(aura::Window* no_animation) { - aura::Window* ignore = workspace_manager_->ignored_window(); - workspace_manager_->set_layout_in_progress(true); - gfx::Rect work_area = workspace_manager_->GetWorkAreaBounds(bounds_); - int total_width = GetTotalWindowsWidth(); - if (total_width < work_area.width()) { - int dx = (work_area.width() - total_width) / 2; - for (aura::Window::Windows::iterator i = windows_.begin(); - i != windows_.end(); - ++i) { - if (*i != ignore) { - MoveWindowTo(*i, - gfx::Point(work_area.x() + dx, work_area.y()), - no_animation != *i); - } - dx += GetLayoutWidth(*i) + kWindowHorizontalMargin; - } - } else { - DCHECK_LT(windows_.size(), 3U); - // TODO(oshima): This is messy. Figure out general algorithm to - // layout more than 2 windows. - if (windows_[0] != ignore) { - MoveWindowTo(windows_[0], - work_area.origin(), - no_animation != windows_[0]); - } - if (windows_.size() == 2 && windows_[1] != ignore) { - MoveWindowTo(windows_[1], - gfx::Point(work_area.right() - GetLayoutWidth(windows_[1]), - work_area.y()), - no_animation != windows_[1]); - } - } - workspace_manager_->set_layout_in_progress(false); -} - -bool Workspace::ContainsFullscreenWindow() const { - for (aura::Window::Windows::const_iterator i = windows_.begin(); - i != windows_.end(); - ++i) { - aura::Window* w = *i; - if (w->IsVisible() && - w->GetIntProperty(aura::client::kShowStateKey) == - ui::SHOW_STATE_FULLSCREEN) - return true; - } - return false; -} - -int Workspace::GetIndexOf(aura::Window* window) const { - aura::Window::Windows::const_iterator i = - std::find(windows_.begin(), windows_.end(), window); - return i == windows_.end() ? -1 : i - windows_.begin(); -} - -bool Workspace::CanAdd(aura::Window* window) const { - // TODO(oshima): This should be based on available space and the - // size of the |window|. - //NOTIMPLEMENTED(); - return windows_.size() < g_max_windows_per_workspace; -} - -void Workspace::MoveWindowTo( - aura::Window* window, - const gfx::Point& origin, - bool animate) { - gfx::Rect bounds = GetLayoutBounds(window); - gfx::Rect work_area = GetWorkAreaBounds(); - // Make sure the window isn't bigger than the workspace size. - bounds.SetRect(origin.x(), origin.y(), - std::min(work_area.width(), bounds.width()), - std::min(work_area.height(), bounds.height())); - if (animate) { - ui::LayerAnimator::ScopedSettings settings(window->layer()->GetAnimator()); - window->SetBounds(bounds); - } else { - window->SetBounds(bounds); - } -} - -int Workspace::GetTotalWindowsWidth() const { - int total_width = 0; - for (aura::Window::Windows::const_iterator i = windows_.begin(); - i != windows_.end(); - ++i) { - if (total_width) - total_width += kWindowHorizontalMargin; - total_width += GetLayoutWidth(*i); - } - return total_width; -} - -// static -size_t Workspace::SetMaxWindowsCount(size_t max) { - int old = g_max_windows_per_workspace; - g_max_windows_per_workspace = max; - return old; -} - -} // namespace internal -} // namespace aura_shell diff --git a/ui/aura_shell/workspace/workspace.h b/ui/aura_shell/workspace/workspace.h deleted file mode 100644 index aef800a..0000000 --- a/ui/aura_shell/workspace/workspace.h +++ /dev/null @@ -1,140 +0,0 @@ -// Copyright (c) 2011 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. - -#ifndef UI_AURA_SHELL_WORKSPACE_WORKSPACE_H_ -#define UI_AURA_SHELL_WORKSPACE_WORKSPACE_H_ - -#include <vector> - -#include "base/basictypes.h" -#include "base/gtest_prod_util.h" -#include "ui/aura_shell/aura_shell_export.h" -#include "ui/gfx/rect.h" - -namespace aura { -class Window; -} - -namespace aura_shell { -namespace internal { - -class WorkspaceManager; -class WorkspaceTest; - -// A workspace is a partial area of the entire desktop (viewport) that -// is visible to the user at a given time. The size of the workspace is -// generally the same as the size of the monitor, and the desktop can -// have multiple workspaces. -// A workspace contains a limited number of windows and the workspace -// manager may create a new workspace if there is not enough room for -// a new window. -class AURA_SHELL_EXPORT Workspace { - public: - explicit Workspace(WorkspaceManager* manager); - virtual ~Workspace(); - - // Specifies the direction to shift windows in |ShiftWindows()|. - enum ShiftDirection { - SHIFT_TO_RIGHT, - SHIFT_TO_LEFT - }; - - // Returns true if this workspace has no windows. - bool is_empty() const { return windows_.empty(); } - - // Sets/gets bounds of this workspace. - const gfx::Rect& bounds() { return bounds_; } - void SetBounds(const gfx::Rect& bounds); - - // Returns the work area bounds of this workspace in viewport - // coordinates. - gfx::Rect GetWorkAreaBounds() const; - - // Adds the |window| at the position after the window |after|. It - // inserts at the end if |after| is NULL. Return true if the - // |window| was successfully added to this workspace, or false if it - // failed. - bool AddWindowAfter(aura::Window* window, aura::Window* after); - - // Removes |window| from this workspace. - void RemoveWindow(aura::Window* window); - - // Return true if this workspace has |window|. - bool Contains(aura::Window* window) const; - - // Returns a window to rotate to based on |position|. - aura::Window* FindRotateWindowForLocation(const gfx::Point& position); - - // Rotates the windows by removing |source| and inserting it to the - // position that |target| was in. It re-layouts windows except for |source|. - void RotateWindows(aura::Window* source, aura::Window* target); - - // Shift the windows in the workspace by inserting |window| until it - // reaches |until|. If |direction| is |SHIFT_TO_RIGHT|, |insert| is - // inserted at the position of |target| or at the beginning if - // |target| is NULL. If |direction| is |SHIFT_TO_LEFT|, |insert| is - // inserted after the position of |target|, or at the end if - // |target| is NULL. It returns the window that is overflowed by - // shifting, or NULL if shifting stopped at |until|. - aura::Window* ShiftWindows(aura::Window* insert, - aura::Window* until, - aura::Window* target, - ShiftDirection direction); - - // Activates this workspace. - void Activate(); - - // Layout windows. The workspace doesn't set bounds on - // |WorkspaceManager::ignored_window| if it's set. It still uses the window's - // bounds to calculate bounds for other windows. Moving animation is - // applied to all windows except for the window specified by |no_animation| - // and |ignore|. - void Layout(aura::Window* no_animation); - - // Returns true if the workspace contains a fullscreen window. - bool ContainsFullscreenWindow() const; - - private: - FRIEND_TEST_ALL_PREFIXES(WorkspaceTest, WorkspaceBasic); - FRIEND_TEST_ALL_PREFIXES(WorkspaceTest, RotateWindows); - FRIEND_TEST_ALL_PREFIXES(WorkspaceTest, ShiftWindowsSingle); - FRIEND_TEST_ALL_PREFIXES(WorkspaceTest, ShiftWindowsMultiple); - FRIEND_TEST_ALL_PREFIXES(WorkspaceManagerTest, RotateWindows); - - // Returns the index in layout order of |window| in this workspace. - int GetIndexOf(aura::Window* window) const; - - // Returns true if the given |window| can be added to this workspace. - bool CanAdd(aura::Window* window) const; - - // Moves |window| to the given point. It performs animation when - // |animate| is true. - void MoveWindowTo(aura::Window* window, - const gfx::Point& origin, - bool animate); - - // Returns the sum of all window's width. - int GetTotalWindowsWidth() const; - - // Test only: Changes how may windows workspace can have. - // Returns the current value so that it can be reverted back to - // original value. - static size_t SetMaxWindowsCount(size_t max); - - WorkspaceManager* workspace_manager_; - - gfx::Rect bounds_; - - // Windows in the workspace in layout order. - std::vector<aura::Window*> windows_; - - DISALLOW_COPY_AND_ASSIGN(Workspace); -}; - -typedef std::vector<Workspace*> Workspaces; - -} // namespace internal -} // namespace aura_shell - -#endif // UI_AURA_SHELL_WORKSPACE_WORKSPACE_H_ diff --git a/ui/aura_shell/workspace/workspace_manager.cc b/ui/aura_shell/workspace/workspace_manager.cc deleted file mode 100644 index bcc1a1b..0000000 --- a/ui/aura_shell/workspace/workspace_manager.cc +++ /dev/null @@ -1,276 +0,0 @@ -// Copyright (c) 2011 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 "ui/aura_shell/workspace/workspace_manager.h" - -#include <algorithm> - -#include "base/auto_reset.h" -#include "base/logging.h" -#include "base/stl_util.h" -#include "ui/aura/root_window.h" -#include "ui/aura/screen_aura.h" -#include "ui/aura/window.h" -#include "ui/aura_shell/workspace/workspace.h" -#include "ui/aura_shell/workspace/workspace_observer.h" -#include "ui/gfx/compositor/layer.h" -#include "ui/gfx/compositor/layer_animator.h" -#include "ui/gfx/screen.h" -#include "ui/gfx/transform.h" - -namespace { - -// The horizontal margein between workspaces in pixels. -const int kWorkspaceHorizontalMargin = 50; - -// Minimum/maximum scale for overview mode. -const float kMaxOverviewScale = 0.9f; -const float kMinOverviewScale = 0.3f; - -} - -namespace aura_shell { -namespace internal { - -//////////////////////////////////////////////////////////////////////////////// -// WindowManager, public: - -WorkspaceManager::WorkspaceManager(aura::Window* contents_view) - : contents_view_(contents_view), - active_workspace_(NULL), - workspace_size_( - gfx::Screen::GetMonitorAreaNearestWindow(contents_view_).size()), - is_overview_(false), - layout_in_progress_(false), - ignored_window_(NULL) { - DCHECK(contents_view); -} - -WorkspaceManager::~WorkspaceManager() { - std::vector<Workspace*> copy_to_delete(workspaces_); - STLDeleteElements(©_to_delete); -} - -Workspace* WorkspaceManager::CreateWorkspace() { - Workspace* workspace = new Workspace(this); - LayoutWorkspaces(); - return workspace; -} - -Workspace* WorkspaceManager::GetActiveWorkspace() const { - return active_workspace_; -} - -Workspace* WorkspaceManager::FindBy(aura::Window* window) const { - int index = GetWorkspaceIndexContaining(window); - return index < 0 ? NULL : workspaces_[index]; -} - -aura::Window* WorkspaceManager::FindRotateWindowForLocation( - const gfx::Point& point) { - for (Workspaces::const_iterator i = workspaces_.begin(); - i != workspaces_.end(); - ++i) { - aura::Window* window = (*i)->FindRotateWindowForLocation(point); - if (window) - return window; - } - return NULL; -} - -void WorkspaceManager::LayoutWorkspaces() { - UpdateContentsView(); - - gfx::Rect bounds(workspace_size_); - int x = 0; - for (Workspaces::const_iterator i = workspaces_.begin(); - i != workspaces_.end(); - ++i) { - Workspace* workspace = *i; - bounds.set_x(x); - workspace->SetBounds(bounds); - x += bounds.width() + kWorkspaceHorizontalMargin; - } -} - -gfx::Rect WorkspaceManager::GetDragAreaBounds() { - return GetWorkAreaBounds(gfx::Rect(contents_view_->bounds().size())); -} - -void WorkspaceManager::SetOverview(bool overview) { - if (is_overview_ == overview) - return; - is_overview_ = overview; - - ui::Transform transform; - if (is_overview_) { - // TODO(oshima|sky): We limit the how small windows can be shrinked - // in overview mode, thus part of the contents_view may not be visible. - // We need to add capability to scroll/move contents_view in overview mode. - float scale = std::min( - kMaxOverviewScale, - workspace_size_.width() / - static_cast<float>(contents_view_->bounds().width())); - scale = std::max(kMinOverviewScale, scale); - - transform.SetScale(scale, scale); - - int overview_width = contents_view_->bounds().width() * scale; - int dx = 0; - if (overview_width < workspace_size_.width()) { - dx = (workspace_size_.width() - overview_width) / 2; - } else if (active_workspace_) { - // Center the active workspace. - int active_workspace_mid_x = (active_workspace_->bounds().x() + - active_workspace_->bounds().width() / 2) * scale; - dx = workspace_size_.width() / 2 - active_workspace_mid_x; - dx = std::min(0, std::max(dx, workspace_size_.width() - overview_width)); - } - - transform.SetTranslateX(dx); - transform.SetTranslateY(workspace_size_.height() * (1.0f - scale) / 2); - } else if (active_workspace_) { - transform.SetTranslateX(-active_workspace_->bounds().x()); - } - - ui::LayerAnimator::ScopedSettings settings( - contents_view_->layer()->GetAnimator()); - contents_view_->layer()->SetTransform(transform); -} - -void WorkspaceManager::RotateWindows(aura::Window* source, - aura::Window* target) { - DCHECK(source); - DCHECK(target); - int source_ws_index = GetWorkspaceIndexContaining(source); - int target_ws_index = GetWorkspaceIndexContaining(target); - DCHECK(source_ws_index >= 0); - DCHECK(target_ws_index >= 0); - if (source_ws_index == target_ws_index) { - workspaces_[source_ws_index]->RotateWindows(source, target); - } else { - aura::Window* insert = source; - aura::Window* target_to_insert = target; - if (source_ws_index < target_ws_index) { - for (int i = target_ws_index; i >= source_ws_index; --i) { - insert = workspaces_[i]->ShiftWindows( - insert, source, target_to_insert, Workspace::SHIFT_TO_LEFT); - // |target| can only be in the 1st workspace. - target_to_insert = NULL; - } - } else { - for (int i = target_ws_index; i <= source_ws_index; ++i) { - insert = workspaces_[i]->ShiftWindows( - insert, source, target_to_insert, Workspace::SHIFT_TO_RIGHT); - // |target| can only be in the 1st workspace. - target_to_insert = NULL; - } - } - } - FOR_EACH_OBSERVER(WorkspaceObserver, observers_, - WindowMoved(this, source, target)); - workspaces_[target_ws_index]->Activate(); -} - -void WorkspaceManager::SetWorkspaceSize(const gfx::Size& workspace_size) { - if (workspace_size == workspace_size_) - return; - workspace_size_ = workspace_size; - LayoutWorkspaces(); -} - -void WorkspaceManager::AddObserver(WorkspaceObserver* observer) { - observers_.AddObserver(observer); -} - -void WorkspaceManager::RemoveObserver(WorkspaceObserver* observer) { - observers_.RemoveObserver(observer); -} - -//////////////////////////////////////////////////////////////////////////////// -// WorkspaceManager, private: - -void WorkspaceManager::AddWorkspace(Workspace* workspace) { - Workspaces::iterator i = std::find(workspaces_.begin(), - workspaces_.end(), - workspace); - DCHECK(i == workspaces_.end()); - workspaces_.push_back(workspace); -} - -void WorkspaceManager::RemoveWorkspace(Workspace* workspace) { - Workspaces::iterator i = std::find(workspaces_.begin(), - workspaces_.end(), - workspace); - DCHECK(i != workspaces_.end()); - Workspace* old = NULL; - - if (workspace == active_workspace_) { - old = active_workspace_; - active_workspace_ = NULL; - } - workspaces_.erase(i); - LayoutWorkspaces(); - - if (old) { - FOR_EACH_OBSERVER(WorkspaceObserver, observers_, - ActiveWorkspaceChanged(this, old)); - } -} - -void WorkspaceManager::SetActiveWorkspace(Workspace* workspace) { - if (active_workspace_ == workspace) - return; - DCHECK(std::find(workspaces_.begin(), workspaces_.end(), - workspace) != workspaces_.end()); - Workspace* old = active_workspace_; - active_workspace_ = workspace; - - is_overview_ = false; - UpdateContentsView(); - - FOR_EACH_OBSERVER(WorkspaceObserver, observers_, - ActiveWorkspaceChanged(this, old)); -} - -gfx::Rect WorkspaceManager::GetWorkAreaBounds( - const gfx::Rect& workspace_bounds) { - gfx::Rect bounds = workspace_bounds; - bounds.Inset( - aura::RootWindow::GetInstance()->screen()->work_area_insets()); - return bounds; -} - -// Returns the index of the workspace that contains the |window|. -int WorkspaceManager::GetWorkspaceIndexContaining(aura::Window* window) const { - for (Workspaces::const_iterator i = workspaces_.begin(); - i != workspaces_.end(); - ++i) { - if ((*i)->Contains(window)) - return i - workspaces_.begin(); - } - return -1; -} - -void WorkspaceManager::UpdateContentsView() { - int num_workspaces = std::max(1, static_cast<int>(workspaces_.size())); - int total_width = workspace_size_.width() * num_workspaces + - kWorkspaceHorizontalMargin * (num_workspaces - 1); - gfx::Rect bounds(0, 0, total_width, workspace_size_.height()); - - if (contents_view_->GetTargetBounds() != bounds) - contents_view_->SetBounds(bounds); - - // Move to active workspace. - if (active_workspace_) { - ui::Transform transform; - transform.SetTranslateX(-active_workspace_->bounds().x()); - ui::LayerAnimator::ScopedSettings settings( - contents_view_->layer()->GetAnimator()); - contents_view_->SetTransform(transform); - } -} - -} // namespace internal -} // namespace aura_shell diff --git a/ui/aura_shell/workspace/workspace_manager.h b/ui/aura_shell/workspace/workspace_manager.h deleted file mode 100644 index 3887ce1..0000000 --- a/ui/aura_shell/workspace/workspace_manager.h +++ /dev/null @@ -1,135 +0,0 @@ -// Copyright (c) 2011 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. - -#ifndef UI_AURA_SHELL_WORKSPACE_WORKSPACE_MANAGER_H_ -#define UI_AURA_SHELL_WORKSPACE_WORKSPACE_MANAGER_H_ - -#include <vector> - -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "base/observer_list.h" -#include "ui/aura_shell/aura_shell_export.h" -#include "ui/gfx/insets.h" -#include "ui/gfx/size.h" - -namespace aura { -class Window; -} - -namespace gfx { -class Point; -class Rect; -} - -namespace aura_shell { -namespace internal { -class Workspace; -class WorkspaceObserver; - -// WorkspaceManager manages multiple workspaces in the desktop. -class AURA_SHELL_EXPORT WorkspaceManager { - public: - explicit WorkspaceManager(aura::Window* viewport); - virtual ~WorkspaceManager(); - - // Returns the Window this WorkspaceManager controls. - aura::Window* contents_view() { return contents_view_; } - - // Create new workspace. Workspace objects are managed by - // this WorkspaceManager. Deleting workspace will automatically - // remove the workspace from the workspace_manager. - Workspace* CreateWorkspace(); - - // Returns the active workspace. - Workspace* GetActiveWorkspace() const; - - // Returns the workspace that contanis the |window|. - Workspace* FindBy(aura::Window* window) const; - - // Returns the window for rotate operation based on the |location|. - aura::Window* FindRotateWindowForLocation(const gfx::Point& location); - - // Sets the bounds of all workspaces. - void LayoutWorkspaces(); - - // Returns the bounds in which a window can be moved/resized. - gfx::Rect GetDragAreaBounds(); - - // Turn on/off overview mode. - void SetOverview(bool overview); - bool is_overview() const { return is_overview_; } - - // Rotate windows by moving |source| window to the position of |target|. - void RotateWindows(aura::Window* source, aura::Window* target); - - // Sets the size of a single workspace (all workspaces have the same size). - void SetWorkspaceSize(const gfx::Size& workspace_size); - - // Adds/Removes workspace observer. - void AddObserver(WorkspaceObserver* observer); - void RemoveObserver(WorkspaceObserver* observer); - - // Returns true if this workspace manager is laying out windows. - // When true, LayoutManager must give windows their requested bounds. - bool layout_in_progress() const { return layout_in_progress_; } - - // Sets the |layout_in_progress_| flag. - void set_layout_in_progress(bool layout_in_progress) { - layout_in_progress_ = layout_in_progress; - } - - // Sets/Returns the ignored window that the workspace manager does not - // set bounds on. - void set_ignored_window(aura::Window* ignored_window) { - ignored_window_ = ignored_window; - } - aura::Window* ignored_window() { return ignored_window_; } - - private: - friend class Workspace; - - void AddWorkspace(Workspace* workspace); - void RemoveWorkspace(Workspace* workspace); - - // Sets the active workspace. - void SetActiveWorkspace(Workspace* workspace); - - // Returns the bounds of the work are given |workspace_bounds|. - gfx::Rect GetWorkAreaBounds(const gfx::Rect& workspace_bounds); - - // Returns the index of the workspace that contains the |window|. - int GetWorkspaceIndexContaining(aura::Window* window) const; - - // Update contents_view size and move the viewport to the active workspace. - void UpdateContentsView(); - - aura::Window* contents_view_; - - Workspace* active_workspace_; - - std::vector<Workspace*> workspaces_; - - // The size of a single workspace. This is generally the same as the size of - // monitor. - gfx::Size workspace_size_; - - // True if the workspace manager is in overview mode. - bool is_overview_; - - // True if this layout manager is laying out windows. - bool layout_in_progress_; - - // The window that WorkspaceManager does not set the bounds on. - aura::Window* ignored_window_; - - ObserverList<WorkspaceObserver> observers_; - - DISALLOW_COPY_AND_ASSIGN(WorkspaceManager); -}; - -} // namespace internal -} // namespace aura_shell - -#endif // UI_AURA_SHELL_WORKSPACE_WORKSPACE_MANAGER_H_ diff --git a/ui/aura_shell/workspace/workspace_manager_unittest.cc b/ui/aura_shell/workspace/workspace_manager_unittest.cc deleted file mode 100644 index 3c3e5e3..0000000 --- a/ui/aura_shell/workspace/workspace_manager_unittest.cc +++ /dev/null @@ -1,567 +0,0 @@ -// Copyright (c) 2011 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 "ui/aura_shell/workspace/workspace_manager.h" - -#include "ash/wm/activation_controller.h" -#include "ui/aura/client/aura_constants.h" -#include "ui/aura/root_window.h" -#include "ui/aura/screen_aura.h" -#include "ui/aura/test/aura_test_base.h" -#include "ui/aura/window.h" -#include "ui/aura_shell/shell_window_ids.h" -#include "ui/aura_shell/workspace/workspace.h" -#include "ui/aura_shell/workspace/workspace_observer.h" -#include "ui/base/ui_base_types.h" - -namespace { -using aura_shell::internal::Workspace; -using aura_shell::internal::WorkspaceManager; -using aura::Window; - -class TestWorkspaceObserver : public aura_shell::internal::WorkspaceObserver { - public: - explicit TestWorkspaceObserver(WorkspaceManager* manager) - : manager_(manager), - move_source_(NULL), - move_target_(NULL), - active_workspace_(NULL), - old_active_workspace_(NULL) { - manager_->AddObserver(this); - } - - virtual ~TestWorkspaceObserver() { - manager_->RemoveObserver(this); - } - - Window* move_source() { return move_source_; } - Window* move_target() { return move_target_; } - Workspace* active_workspace() { return active_workspace_; } - Workspace* old_active_workspace() { return old_active_workspace_; } - - // Resets the observer states. - void reset() { - active_workspace_ = NULL; - old_active_workspace_ = NULL; - move_source_ = NULL; - move_target_ = NULL; - } - - // Overridden from WorkspaceObserver: - virtual void WindowMoved(WorkspaceManager* manager, - Window* source, - Window* target) { - move_source_ = source; - move_target_ = target; - } - virtual void ActiveWorkspaceChanged(WorkspaceManager* manager, - Workspace* old) { - old_active_workspace_ = old; - active_workspace_ = manager->GetActiveWorkspace(); - } - - private: - WorkspaceManager* manager_; - Window* move_source_; - Window* move_target_; - Workspace* active_workspace_; - Workspace* old_active_workspace_; - - DISALLOW_COPY_AND_ASSIGN(TestWorkspaceObserver); -}; - -} // namespace - -namespace aura_shell { -namespace internal { - -class WorkspaceManagerTestBase : public aura::test::AuraTestBase { - public: - WorkspaceManagerTestBase() { - aura::RootWindow::GetInstance()->set_id( - internal::kShellWindowId_DefaultContainer); - activation_controller_.reset(new internal::ActivationController); - activation_controller_->set_default_container_for_test( - aura::RootWindow::GetInstance()); - } - virtual ~WorkspaceManagerTestBase() {} - - virtual void SetUp() OVERRIDE { - aura::test::AuraTestBase::SetUp(); - manager_.reset(new WorkspaceManager(viewport())); - } - - virtual void TearDown() OVERRIDE { - manager_.reset(); - aura::test::AuraTestBase::TearDown(); - } - - aura::Window* CreateTestWindow() { - aura::Window* window = new aura::Window(NULL); - window->Init(ui::Layer::LAYER_HAS_NO_TEXTURE); - return window; - } - - aura::Window* viewport() { - return aura::RootWindow::GetInstance(); - } - scoped_ptr<WorkspaceManager> manager_; - - private: - scoped_ptr<internal::ActivationController> activation_controller_; - - DISALLOW_COPY_AND_ASSIGN(WorkspaceManagerTestBase); -}; - -class WorkspaceManagerTest : public WorkspaceManagerTestBase { -}; - -TEST_F(WorkspaceManagerTest, WorkspaceManagerCreateAddFind) { - scoped_ptr<Window> w1(CreateTestWindow()); - scoped_ptr<Window> w2(CreateTestWindow()); - - Workspace* ws1 = manager_->CreateWorkspace(); - ws1->AddWindowAfter(w1.get(), NULL); - // w2 is not a part of any workspace yet. - EXPECT_EQ(NULL, manager_->FindBy(w2.get())); - - // w2 is in ws2 workspace. - Workspace* ws2 = manager_->CreateWorkspace(); - ws2->AddWindowAfter(w2.get(), NULL); - EXPECT_EQ(ws2, manager_->FindBy(w2.get())); - - // Make sure |FindBy(w1.get())| still returns - // correct workspace. - EXPECT_EQ(ws1, manager_->FindBy(w1.get())); - - // once workspace is gone, w2 shouldn't match - // any workspace. - delete ws2; - EXPECT_EQ(NULL, manager_->FindBy(w2.get())); - - // Reset now before windows are destroyed. - manager_.reset(); -} - -TEST_F(WorkspaceManagerTest, LayoutWorkspaces) { - manager_->SetWorkspaceSize(gfx::Size(100, 100)); - EXPECT_EQ("0,0 100x100", viewport()->bounds().ToString()); - - Workspace* ws1 = manager_->CreateWorkspace(); - manager_->LayoutWorkspaces(); - - // ws1 is laied out in left most position. - EXPECT_EQ(100, viewport()->bounds().width()); - EXPECT_EQ("0,0 100x100", ws1->bounds().ToString()); - - // ws2 is laied out next to ws1, with 50 margin. - Workspace* ws2 = manager_->CreateWorkspace(); - manager_->LayoutWorkspaces(); - - EXPECT_EQ(250, viewport()->bounds().width()); - EXPECT_EQ("0,0 100x100", ws1->bounds().ToString()); - EXPECT_EQ("150,0 100x100", ws2->bounds().ToString()); -} - -// Makes sure the bounds of window are resized if the workspace size shrinks. -TEST_F(WorkspaceManagerTest, ResizeDuringLayout) { - manager_->SetWorkspaceSize(gfx::Size(100, 100)); - EXPECT_EQ("0,0 100x100", viewport()->bounds().ToString()); - - Workspace* ws1 = manager_->CreateWorkspace(); - scoped_ptr<Window> w1(CreateTestWindow()); - w1->SetBounds(gfx::Rect(0, 0, 100, 100)); - viewport()->AddChild(w1.get()); - EXPECT_TRUE(ws1->AddWindowAfter(w1.get(), NULL)); - manager_->SetWorkspaceSize(gfx::Size(50, 50)); - - // ws1 is laied out in left most position. - EXPECT_EQ("0,0 50x50", ws1->bounds().ToString()); - EXPECT_EQ("0,0 50x50", w1->layer()->GetTargetBounds().ToString()); -} - -TEST_F(WorkspaceManagerTest, WorkspaceManagerDragArea) { - aura::RootWindow::GetInstance()->screen()->set_work_area_insets( - gfx::Insets(10, 10, 10, 10)); - viewport()->SetBounds(gfx::Rect(0, 0, 200, 200)); - EXPECT_EQ("10,10 180x180", manager_->GetDragAreaBounds().ToString()); -} - -TEST_F(WorkspaceManagerTest, WorkspaceManagerActivate) { - TestWorkspaceObserver observer(manager_.get()); - Workspace* ws1 = manager_->CreateWorkspace(); - Workspace* ws2 = manager_->CreateWorkspace(); - EXPECT_EQ(NULL, manager_->GetActiveWorkspace()); - - // Activate ws1. - ws1->Activate(); - EXPECT_EQ(ws1, manager_->GetActiveWorkspace()); - EXPECT_EQ(NULL, observer.old_active_workspace()); - EXPECT_EQ(ws1, observer.active_workspace()); - observer.reset(); - - // Activate ws2. - ws2->Activate(); - EXPECT_EQ(ws2, manager_->GetActiveWorkspace()); - EXPECT_EQ(ws1, observer.old_active_workspace()); - EXPECT_EQ(ws2, observer.active_workspace()); - observer.reset(); - - // Deleting active workspace sets active workspace to NULL. - delete ws2; - EXPECT_EQ(NULL, manager_->GetActiveWorkspace()); - EXPECT_EQ(ws2, observer.old_active_workspace()); - EXPECT_EQ(NULL, observer.active_workspace()); -} - -TEST_F(WorkspaceManagerTest, FindRotateWindow) { - manager_->SetWorkspaceSize(gfx::Size(500, 300)); - - Workspace* ws1 = manager_->CreateWorkspace(); - scoped_ptr<Window> w11(CreateTestWindow()); - w11->SetBounds(gfx::Rect(0, 0, 100, 100)); - ws1->AddWindowAfter(w11.get(), NULL); - - scoped_ptr<Window> w12(CreateTestWindow()); - w12->SetBounds(gfx::Rect(0, 0, 100, 100)); - ws1->AddWindowAfter(w12.get(), NULL); - manager_->LayoutWorkspaces(); - - // Workspaces are 0-<lmgn>-145-<w11>-245-<wmng>-255-<w12>-355-<rmgn>-500. - EXPECT_EQ(NULL, manager_->FindRotateWindowForLocation(gfx::Point(0, 0))); - EXPECT_EQ(NULL, manager_->FindRotateWindowForLocation(gfx::Point(100, 0))); - EXPECT_EQ(w11.get(), - manager_->FindRotateWindowForLocation(gfx::Point(150, 0))); - EXPECT_EQ(w12.get(), - manager_->FindRotateWindowForLocation(gfx::Point(300, 0))); - EXPECT_EQ(NULL, manager_->FindRotateWindowForLocation(gfx::Point(400, 0))); - - w11->SetBounds(gfx::Rect(0, 0, 400, 100)); - w12->SetBounds(gfx::Rect(0, 0, 200, 100)); - manager_->FindBy(w11.get())->Layout(NULL); - EXPECT_EQ(w11.get(), - manager_->FindRotateWindowForLocation(gfx::Point(10, 0))); - EXPECT_EQ(w11.get(), - manager_->FindRotateWindowForLocation(gfx::Point(240, 0))); - EXPECT_EQ(w12.get(), - manager_->FindRotateWindowForLocation(gfx::Point(260, 0))); - EXPECT_EQ(w12.get(), - manager_->FindRotateWindowForLocation(gfx::Point(490, 0))); - - Workspace* ws2 = manager_->CreateWorkspace(); - scoped_ptr<Window> w21(CreateTestWindow()); - w21->SetBounds(gfx::Rect(0, 0, 100, 100)); - ws2->AddWindowAfter(w21.get(), NULL); - manager_->LayoutWorkspaces(); - - // 2nd workspace starts from 500+50 and the window is centered 750-850. - EXPECT_EQ(NULL, manager_->FindRotateWindowForLocation(gfx::Point(600, 0))); - EXPECT_EQ(NULL, manager_->FindRotateWindowForLocation(gfx::Point(740, 0))); - EXPECT_EQ(w21.get(), - manager_->FindRotateWindowForLocation(gfx::Point(760, 0))); - EXPECT_EQ(w21.get(), - manager_->FindRotateWindowForLocation(gfx::Point(840, 0))); - EXPECT_EQ(NULL, manager_->FindRotateWindowForLocation(gfx::Point(860, 0))); - - // Reset now before windows are destroyed. - manager_.reset(); -} - -TEST_F(WorkspaceManagerTest, RotateWindows) { - scoped_ptr<TestWorkspaceObserver> observer( - new TestWorkspaceObserver(manager_.get())); - Workspace* ws1 = manager_->CreateWorkspace(); - Workspace* ws2 = manager_->CreateWorkspace(); - - scoped_ptr<Window> w11(CreateTestWindow()); - ws1->AddWindowAfter(w11.get(), NULL); - - scoped_ptr<Window> w21(CreateTestWindow()); - scoped_ptr<Window> w22(CreateTestWindow()); - ws2->AddWindowAfter(w21.get(), NULL); - ws2->AddWindowAfter(w22.get(), NULL); - - EXPECT_EQ(0, ws1->GetIndexOf(w11.get())); - EXPECT_EQ(0, ws2->GetIndexOf(w21.get())); - EXPECT_EQ(1, ws2->GetIndexOf(w22.get())); - - // Rotate right most to left most. - manager_->RotateWindows(w22.get(), w11.get()); - EXPECT_EQ(w22.get(), observer->move_source()); - EXPECT_EQ(w11.get(), observer->move_target()); - - EXPECT_EQ(0, ws1->GetIndexOf(w22.get())); - EXPECT_EQ(0, ws2->GetIndexOf(w11.get())); - EXPECT_EQ(1, ws2->GetIndexOf(w21.get())); - - // Rotate left most to right most. - manager_->RotateWindows(w22.get(), w21.get()); - EXPECT_EQ(0, ws1->GetIndexOf(w11.get())); - EXPECT_EQ(0, ws2->GetIndexOf(w21.get())); - EXPECT_EQ(1, ws2->GetIndexOf(w22.get())); - EXPECT_EQ(w22.get(), observer->move_source()); - EXPECT_EQ(w21.get(), observer->move_target()); - - // Rotate left most to 1st element in 2nd workspace. - manager_->RotateWindows(w11.get(), w21.get()); - EXPECT_EQ(0, ws1->GetIndexOf(w21.get())); - EXPECT_EQ(0, ws2->GetIndexOf(w11.get())); - EXPECT_EQ(1, ws2->GetIndexOf(w22.get())); - EXPECT_EQ(w11.get(), observer->move_source()); - EXPECT_EQ(w21.get(), observer->move_target()); - - // Rotate middle to right most. - manager_->RotateWindows(w11.get(), w22.get()); - EXPECT_EQ(0, ws1->GetIndexOf(w21.get())); - EXPECT_EQ(0, ws2->GetIndexOf(w22.get())); - EXPECT_EQ(1, ws2->GetIndexOf(w11.get())); - EXPECT_EQ(w11.get(), observer->move_source()); - EXPECT_EQ(w22.get(), observer->move_target()); - - // Rotate middle to left most. - manager_->RotateWindows(w22.get(), w21.get()); - EXPECT_EQ(0, ws1->GetIndexOf(w22.get())); - EXPECT_EQ(0, ws2->GetIndexOf(w21.get())); - EXPECT_EQ(1, ws2->GetIndexOf(w11.get())); - EXPECT_EQ(w22.get(), observer->move_source()); - EXPECT_EQ(w21.get(), observer->move_target()); - - // Reset now before windows are destroyed. - observer.reset(); - manager_.reset(); -} - -class WorkspaceTest : public WorkspaceManagerTestBase { -}; - -TEST_F(WorkspaceTest, WorkspaceBasic) { - Workspace* ws = manager_->CreateWorkspace(); - // Sanity check - EXPECT_TRUE(ws->is_empty()); - - scoped_ptr<Window> w1(CreateTestWindow()); - scoped_ptr<Window> w2(CreateTestWindow()); - scoped_ptr<Window> w3(CreateTestWindow()); - // ws is empty and can accomodate new window. - EXPECT_TRUE(ws->CanAdd(w1.get())); - - // Add w1. - EXPECT_TRUE(ws->AddWindowAfter(w1.get(), NULL)); - EXPECT_TRUE(ws->Contains(w1.get())); - EXPECT_FALSE(ws->is_empty()); - - // The workspac still has room for next window. - EXPECT_TRUE(ws->CanAdd(w2.get())); - EXPECT_TRUE(ws->AddWindowAfter(w2.get(), NULL)); - EXPECT_TRUE(ws->Contains(w2.get())); - - // The workspace no longer accepts new window. - EXPECT_FALSE(ws->CanAdd(w3.get())); - EXPECT_FALSE(ws->AddWindowAfter(w3.get(), NULL)); - EXPECT_FALSE(ws->Contains(w3.get())); - - // Check if the window has correct layout index. - EXPECT_EQ(0, ws->GetIndexOf(w1.get())); - EXPECT_EQ(1, ws->GetIndexOf(w2.get())); - EXPECT_EQ(-1, ws->GetIndexOf(w3.get())); - - // w1 is gone, so no index for w2. - ws->RemoveWindow(w1.get()); - EXPECT_EQ(-1, ws->GetIndexOf(w1.get())); - EXPECT_EQ(0, ws->GetIndexOf(w2.get())); - EXPECT_FALSE(ws->Contains(w1.get())); - - // Add w1 back. w1 now has index = 1. - EXPECT_TRUE(ws->AddWindowAfter(w1.get(), w2.get())); - EXPECT_EQ(0, ws->GetIndexOf(w2.get())); - EXPECT_EQ(1, ws->GetIndexOf(w1.get())); - - // Reset now before windows are destroyed. - manager_.reset(); -} - -TEST_F(WorkspaceTest, RotateWindows) { - size_t orig_max = Workspace::SetMaxWindowsCount(3); - Workspace* ws = manager_->CreateWorkspace(); - scoped_ptr<Window> w1(CreateTestWindow()); - scoped_ptr<Window> w2(CreateTestWindow()); - scoped_ptr<Window> w3(CreateTestWindow()); - ws->AddWindowAfter(w1.get(), NULL); - ws->AddWindowAfter(w2.get(), NULL); - ws->AddWindowAfter(w3.get(), NULL); - - EXPECT_EQ(0, ws->GetIndexOf(w1.get())); - EXPECT_EQ(1, ws->GetIndexOf(w2.get())); - EXPECT_EQ(2, ws->GetIndexOf(w3.get())); - - // Rotate to left. - ws->RotateWindows(w1.get(), w3.get()); - EXPECT_EQ(0, ws->GetIndexOf(w2.get())); - EXPECT_EQ(1, ws->GetIndexOf(w3.get())); - EXPECT_EQ(2, ws->GetIndexOf(w1.get())); - - // Rotate to right. - ws->RotateWindows(w1.get(), w2.get()); - EXPECT_EQ(0, ws->GetIndexOf(w1.get())); - EXPECT_EQ(1, ws->GetIndexOf(w2.get())); - EXPECT_EQ(2, ws->GetIndexOf(w3.get())); - - // Rotating to the middle from left. - ws->RotateWindows(w1.get(), w2.get()); - EXPECT_EQ(0, ws->GetIndexOf(w2.get())); - EXPECT_EQ(1, ws->GetIndexOf(w1.get())); - EXPECT_EQ(2, ws->GetIndexOf(w3.get())); - - // Rotating to the middle from right. - ws->RotateWindows(w3.get(), w1.get()); - EXPECT_EQ(0, ws->GetIndexOf(w2.get())); - EXPECT_EQ(1, ws->GetIndexOf(w3.get())); - EXPECT_EQ(2, ws->GetIndexOf(w1.get())); - - // Reset now before windows are destroyed. - manager_.reset(); - Workspace::SetMaxWindowsCount(orig_max); -} - -TEST_F(WorkspaceTest, ShiftWindowsSingle) { - Workspace* ws = manager_->CreateWorkspace(); - // Single window in a workspace case. - scoped_ptr<Window> w1(CreateTestWindow()); - ws->AddWindowAfter(w1.get(), NULL); - - scoped_ptr<Window> w2(CreateTestWindow()); - - // Sanity check. - EXPECT_EQ(0, ws->GetIndexOf(w1.get())); - EXPECT_EQ(-1, ws->GetIndexOf(w2.get())); - - // Insert |w2| at the beginning and shift. - aura::Window* overflow = - ws->ShiftWindows( - w2.get(), w2.get(), NULL, Workspace::SHIFT_TO_RIGHT); - EXPECT_EQ(w1.get(), overflow); - EXPECT_EQ(-1, ws->GetIndexOf(w1.get())); - EXPECT_EQ(0, ws->GetIndexOf(w2.get())); - - // Insert |w1| at the end and shift. - overflow = ws->ShiftWindows( - w1.get(), w1.get(), NULL, Workspace::SHIFT_TO_LEFT); - EXPECT_EQ(w2.get(), overflow); - EXPECT_EQ(-1, ws->GetIndexOf(w2.get())); - EXPECT_EQ(0, ws->GetIndexOf(w1.get())); - - // Insert |w2| at the begining and shift up to the w1. - overflow = ws->ShiftWindows( - w2.get(), w1.get(), NULL, Workspace::SHIFT_TO_RIGHT); - EXPECT_EQ(NULL, overflow); - EXPECT_EQ(-1, ws->GetIndexOf(w1.get())); - EXPECT_EQ(0, ws->GetIndexOf(w2.get())); - - // Insert |w1| at the end and shift up to the w2. - overflow = ws->ShiftWindows( - w1.get(), w2.get(), NULL, Workspace::SHIFT_TO_LEFT); - EXPECT_EQ(NULL, overflow); - EXPECT_EQ(-1, ws->GetIndexOf(w2.get())); - EXPECT_EQ(0, ws->GetIndexOf(w1.get())); - - // Reset now before windows are destroyed. - manager_.reset(); -} - -TEST_F(WorkspaceTest, ShiftWindowsMultiple) { - Workspace* ws = manager_->CreateWorkspace(); - // Single window in a workspace case. - scoped_ptr<Window> w1(CreateTestWindow()); - scoped_ptr<Window> w2(CreateTestWindow()); - ws->AddWindowAfter(w1.get(), NULL); - ws->AddWindowAfter(w2.get(), NULL); - - scoped_ptr<Window> w3(CreateTestWindow()); - - // Sanity check. - EXPECT_EQ(0, ws->GetIndexOf(w1.get())); - EXPECT_EQ(1, ws->GetIndexOf(w2.get())); - EXPECT_EQ(-1, ws->GetIndexOf(w3.get())); - - // Insert |w3| at the beginning and shift. - aura::Window* overflow = - ws->ShiftWindows(w3.get(), w3.get(), NULL, - Workspace::SHIFT_TO_RIGHT); - EXPECT_EQ(w2.get(), overflow); - EXPECT_EQ(-1, ws->GetIndexOf(w2.get())); - EXPECT_EQ(0, ws->GetIndexOf(w3.get())); - EXPECT_EQ(1, ws->GetIndexOf(w1.get())); - - // Insert |w3| at the end and shift. - overflow = ws->ShiftWindows(w2.get(), w2.get(), NULL, - Workspace::SHIFT_TO_LEFT); - EXPECT_EQ(w3.get(), overflow); - EXPECT_EQ(-1, ws->GetIndexOf(w3.get())); - EXPECT_EQ(0, ws->GetIndexOf(w1.get())); - EXPECT_EQ(1, ws->GetIndexOf(w2.get())); - - // Insert |w3| at the begining and shift up to the w1. - overflow = ws->ShiftWindows(w3.get(), w1.get(), NULL, - Workspace::SHIFT_TO_RIGHT); - EXPECT_EQ(NULL, overflow); - EXPECT_EQ(-1, ws->GetIndexOf(w1.get())); - EXPECT_EQ(0, ws->GetIndexOf(w3.get())); - EXPECT_EQ(1, ws->GetIndexOf(w2.get())); - - // Insert |w1| at the end and shift up to the w2. - overflow = ws->ShiftWindows(w1.get(), w2.get(), NULL, - Workspace::SHIFT_TO_LEFT); - EXPECT_EQ(NULL, overflow); - EXPECT_EQ(-1, ws->GetIndexOf(w2.get())); - EXPECT_EQ(0, ws->GetIndexOf(w3.get())); - EXPECT_EQ(1, ws->GetIndexOf(w1.get())); - - scoped_ptr<Window> unused(CreateTestWindow()); - - // Insert |w2| at the |w3| and shift to right. - overflow = ws->ShiftWindows(w2.get(), unused.get(), w3.get(), - Workspace::SHIFT_TO_RIGHT); - EXPECT_EQ(w1.get(), overflow); - EXPECT_EQ(-1, ws->GetIndexOf(w1.get())); - EXPECT_EQ(0, ws->GetIndexOf(w2.get())); - EXPECT_EQ(1, ws->GetIndexOf(w3.get())); - - // Insert |w1| at the |w2| and shift to left. - overflow = ws->ShiftWindows(w1.get(), unused.get(), w2.get(), - Workspace::SHIFT_TO_LEFT); - EXPECT_EQ(w2.get(), overflow); - EXPECT_EQ(-1, ws->GetIndexOf(w2.get())); - EXPECT_EQ(0, ws->GetIndexOf(w1.get())); - EXPECT_EQ(1, ws->GetIndexOf(w3.get())); - - // Reset now before windows are destroyed. - manager_.reset(); -} - -TEST_F(WorkspaceTest, ContainsFullscreenWindow) { - Workspace* ws = manager_->CreateWorkspace(); - scoped_ptr<Window> w1(CreateTestWindow()); - scoped_ptr<Window> w2(CreateTestWindow()); - ws->AddWindowAfter(w1.get(), NULL); - ws->AddWindowAfter(w2.get(), NULL); - w1->Show(); - w2->Show(); - - EXPECT_FALSE(ws->ContainsFullscreenWindow()); - - w1->SetIntProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); - EXPECT_TRUE(ws->ContainsFullscreenWindow()); - - w1->SetIntProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); - EXPECT_FALSE(ws->ContainsFullscreenWindow()); - - w2->SetIntProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); - EXPECT_TRUE(ws->ContainsFullscreenWindow()); - - w2->Hide(); - EXPECT_FALSE(ws->ContainsFullscreenWindow()); -} - -} // namespace internal -} // namespace aura_shell diff --git a/ui/aura_shell/workspace/workspace_observer.h b/ui/aura_shell/workspace/workspace_observer.h deleted file mode 100644 index e0387bb..0000000 --- a/ui/aura_shell/workspace/workspace_observer.h +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (c) 2011 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. - -#ifndef UI_AURA_SHELL_WORKSPACE_WORKSPACE_OBSERVER_H_ -#define UI_AURA_SHELL_WORKSPACE_WORKSPACE_OBSERVER_H_ -#pragma once - -#include "ui/aura_shell/aura_shell_export.h" - -namespace aura { -class Window; -} - -namespace aura_shell { -namespace internal { -class Workspace; -class WorkspaceManager; - -// A class to observe changes in workspace state. -class AURA_SHELL_EXPORT WorkspaceObserver { - public: - // Invoked when |start| window is moved and inserted - // at the |target| window's position by |WorkspaceManager::RotateWindow|. - virtual void WindowMoved(WorkspaceManager* manager, - aura::Window* source, - aura::Window* target) = 0; - - // Invoked when the active workspace changes. |old| is - // the old active workspace and can be NULL. - virtual void ActiveWorkspaceChanged(WorkspaceManager* manager, - Workspace* old) = 0; - protected: - virtual ~WorkspaceObserver() {} -}; - -} // namespace internal -} // namespace aura_shell - -#endif // UI_AURA_SHELL_WORKSPACE_WORKSPACE_OBSERVER_H_ diff --git a/ui/aura_shell/workspace_controller.cc b/ui/aura_shell/workspace_controller.cc deleted file mode 100644 index d7ef302..0000000 --- a/ui/aura_shell/workspace_controller.cc +++ /dev/null @@ -1,127 +0,0 @@ -// Copyright (c) 2011 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 "ui/aura_shell/workspace_controller.h" - -#include "ui/aura/client/activation_client.h" -#include "ui/aura/client/aura_constants.h" -#include "ui/aura/root_window.h" -#include "ui/aura/window.h" -#include "ui/aura_shell/default_container_layout_manager.h" -#include "ui/aura_shell/launcher/launcher.h" -#include "ui/aura_shell/launcher/launcher_model.h" -#include "ui/aura_shell/shell.h" -#include "ui/aura_shell/window_util.h" -#include "ui/aura_shell/workspace/workspace.h" -#include "ui/aura_shell/workspace/workspace_manager.h" - -namespace aura_shell { -namespace internal { - -WorkspaceController::WorkspaceController(aura::Window* viewport) - : workspace_manager_(new WorkspaceManager(viewport)), - launcher_model_(NULL), - ignore_move_event_(false) { - workspace_manager_->AddObserver(this); - aura::RootWindow::GetInstance()->AddRootWindowObserver(this); - aura::RootWindow::GetInstance()->AddObserver(this); -} - -WorkspaceController::~WorkspaceController() { - workspace_manager_->RemoveObserver(this); - if (launcher_model_) - launcher_model_->RemoveObserver(this); - aura::RootWindow::GetInstance()->RemoveObserver(this); - aura::RootWindow::GetInstance()->RemoveRootWindowObserver(this); -} - -void WorkspaceController::ToggleOverview() { - workspace_manager_->SetOverview(!workspace_manager_->is_overview()); -} - -void WorkspaceController::SetLauncherModel(LauncherModel* launcher_model) { - DCHECK(!launcher_model_); - launcher_model_ = launcher_model; - launcher_model_->AddObserver(this); -} - -//////////////////////////////////////////////////////////////////////////////// -// WorkspaceController, aura::RootWindowObserver overrides: - -void WorkspaceController::OnRootWindowResized(const gfx::Size& new_size) { - workspace_manager_->SetWorkspaceSize(new_size); -} - -//////////////////////////////////////////////////////////////////////////////// -// WorkspaceController, aura::WindowObserver overrides: - -void WorkspaceController::OnWindowPropertyChanged(aura::Window* window, - const char* key, - void* old) { - if (key == aura::client::kRootWindowActiveWindow) { - // FindBy handles NULL. - Workspace* workspace = workspace_manager_->FindBy(GetActiveWindow()); - if (workspace) - workspace->Activate(); - } -} - -//////////////////////////////////////////////////////////////////////////////// -// WorkspaceController, aura_shell::internal::WorkspaceObserver overrides: - -void WorkspaceController::WindowMoved(WorkspaceManager* manager, - aura::Window* source, - aura::Window* target) { - if (ignore_move_event_ || !launcher_model_) - return; - int start_index = launcher_model_->ItemIndexByWindow(source); - int target_index = launcher_model_->ItemIndexByWindow(target); - // The following condition may not be hold depending on future - // launcher design. Using DCHECK so that we can catch such change. - DCHECK(start_index >=0); - DCHECK(target_index >=0); - - ignore_move_event_ = true; - launcher_model_->Move(start_index, target_index); - ignore_move_event_ = false; -} - -void WorkspaceController::ActiveWorkspaceChanged(WorkspaceManager* manager, - Workspace* old) { - // TODO(oshima): Update Launcher and Status area state when the active - // workspace's fullscreen state changes. - //NOTIMPLEMENTED(); -} - -//////////////////////////////////////////////////////////////////////////////// -// WorkspaceController, aura_shell::LauncherModelObserver overrides: - -void WorkspaceController::LauncherItemAdded(int index) { -} - -void WorkspaceController::LauncherItemRemoved(int index) { -} - -void WorkspaceController::LauncherItemMoved(int start_index, int target_index) { - if (ignore_move_event_) - return; - DCHECK(launcher_model_); - // Adjust target/source indices as the item positions in |launcher_model_| - // has already been updated. - aura::Window* start = launcher_model_->items()[target_index].window; - size_t target_index_in_model = - start_index < target_index ? target_index - 1 : target_index + 1; - DCHECK_LE(target_index_in_model, launcher_model_->items().size()); - aura::Window* target = launcher_model_->items()[target_index_in_model].window; - - ignore_move_event_ = true; - workspace_manager_->RotateWindows(start, target); - ignore_move_event_ = false; -} - -void WorkspaceController::LauncherItemImagesChanged(int index) { -} - -} // namespace internal -} // namespace aura_shell diff --git a/ui/aura_shell/workspace_controller.h b/ui/aura_shell/workspace_controller.h deleted file mode 100644 index e1404da..0000000 --- a/ui/aura_shell/workspace_controller.h +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright (c) 2011 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. - -#ifndef UI_AURA_SHELL_WORKSPACE_CONTROLLER_H_ -#define UI_AURA_SHELL_WORKSPACE_CONTROLLER_H_ -#pragma once - -#include "base/basictypes.h" -#include "base/memory/scoped_ptr.h" -#include "ui/aura/root_window_observer.h" -#include "ui/aura/window_observer.h" -#include "ui/aura_shell/aura_shell_export.h" -#include "ui/aura_shell/launcher/launcher_model_observer.h" -#include "ui/aura_shell/workspace/workspace_observer.h" - -namespace aura { -class Window; -} - -namespace gfx { -class Size; -} - -namespace aura_shell { -class LauncherModel; - -namespace internal { - -class WorkspaceManager; - -// WorkspaceControlls owns a WorkspaceManager. WorkspaceControlls bridges -// events From RootWindowObserver translating them to WorkspaceManager, and -// a move event between Laucher and Workspace. -class AURA_SHELL_EXPORT WorkspaceController : - public aura::RootWindowObserver, - public aura::WindowObserver, - public aura_shell::internal::WorkspaceObserver, - public aura_shell::LauncherModelObserver { - public: - explicit WorkspaceController(aura::Window* workspace_viewport); - virtual ~WorkspaceController(); - - void ToggleOverview(); - - void SetLauncherModel(LauncherModel* launcher_model); - - // Returns the workspace manager that this controler owns. - WorkspaceManager* workspace_manager() { - return workspace_manager_.get(); - } - - // aura::RootWindowObserver overrides: - virtual void OnRootWindowResized(const gfx::Size& new_size) OVERRIDE; - - // aura::WindowObserver overrides: - virtual void OnWindowPropertyChanged(aura::Window* window, - const char* key, - void* old) OVERRIDE; - - // WorkspaceObserver overrides: - virtual void WindowMoved(WorkspaceManager* manager, - aura::Window* source, - aura::Window* target) OVERRIDE; - virtual void ActiveWorkspaceChanged(WorkspaceManager* manager, - Workspace* old) OVERRIDE; - - // Invoked after an item has been added to the model. - virtual void LauncherItemAdded(int index) OVERRIDE; - virtual void LauncherItemRemoved(int index) OVERRIDE; - virtual void LauncherItemMoved(int start_index, int target_index) OVERRIDE; - virtual void LauncherItemImagesChanged(int index) OVERRIDE; - virtual void LauncherItemImagesWillChange(int index) OVERRIDE {} - - private: - scoped_ptr<WorkspaceManager> workspace_manager_; - - // Owned by Launcher. - LauncherModel* launcher_model_; - - // True while the controller is moving window either on workspace or launcher. - // Used to prevent infinite recursive call between the workspace and launcher. - bool ignore_move_event_; - - DISALLOW_COPY_AND_ASSIGN(WorkspaceController); -}; - -} // namespace internal -} // namespace aura_shell - -#endif // UI_AURA_SHELL_WORKSPACE_CONTROLLER_H_ diff --git a/ui/aura_shell/workspace_controller_unittest.cc b/ui/aura_shell/workspace_controller_unittest.cc deleted file mode 100644 index 5a3ad04..0000000 --- a/ui/aura_shell/workspace_controller_unittest.cc +++ /dev/null @@ -1,119 +0,0 @@ -// Copyright (c) 2011 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 "ui/aura_shell/workspace_controller.h" - -#include "ash/wm/activation_controller.h" -#include "ui/aura/test/aura_test_base.h" -#include "ui/aura/root_window.h" -#include "ui/aura/window.h" -#include "ui/aura_shell/shell_window_ids.h" -#include "ui/aura_shell/window_util.h" -#include "ui/aura_shell/workspace/workspace.h" -#include "ui/aura_shell/workspace/workspace_manager.h" - -namespace aura_shell { -namespace internal { - -using aura::Window; - -class WorkspaceControllerTest : public aura::test::AuraTestBase { - public: - WorkspaceControllerTest() {} - virtual ~WorkspaceControllerTest() {} - - virtual void SetUp() OVERRIDE { - aura::test::AuraTestBase::SetUp(); - contents_view_ = aura::RootWindow::GetInstance(); - // Activatable windows need to be in a container the ActivationController - // recognizes. - contents_view_->set_id( - aura_shell::internal::kShellWindowId_DefaultContainer); - activation_controller_.reset(new ActivationController); - activation_controller_->set_default_container_for_test(contents_view_); - controller_.reset(new WorkspaceController(contents_view_)); - } - - virtual void TearDown() OVERRIDE { - activation_controller_.reset(); - controller_.reset(); - aura::test::AuraTestBase::TearDown(); - } - - aura::Window* CreateTestWindow() { - aura::Window* window = new aura::Window(NULL); - window->Init(ui::Layer::LAYER_HAS_NO_TEXTURE); - contents_view()->AddChild(window); - window->Show(); - return window; - } - - aura::Window* contents_view() { - return contents_view_; - } - - WorkspaceManager* workspace_manager() { - return controller_->workspace_manager(); - } - - scoped_ptr<WorkspaceController> controller_; - - private: - aura::Window* contents_view_; - - scoped_ptr<ActivationController> activation_controller_; - - DISALLOW_COPY_AND_ASSIGN(WorkspaceControllerTest); -}; - -TEST_F(WorkspaceControllerTest, Overview) { - workspace_manager()->SetWorkspaceSize(gfx::Size(500, 300)); - - // Creating two workspaces, ws1 which contains window w1, - // and ws2 which contains window w2. - Workspace* ws1 = workspace_manager()->CreateWorkspace(); - scoped_ptr<Window> w1(CreateTestWindow()); - EXPECT_TRUE(ws1->AddWindowAfter(w1.get(), NULL)); - - Workspace* ws2 = workspace_manager()->CreateWorkspace(); - scoped_ptr<Window> w2(CreateTestWindow()); - EXPECT_TRUE(ws2->AddWindowAfter(w2.get(), NULL)); - - // Activating a window switches the active workspace. - aura_shell::ActivateWindow(w2.get()); - EXPECT_EQ(ws2, workspace_manager()->GetActiveWorkspace()); - - // The size of contents_view() is now ws1(500) + ws2(500) + margin(50). - EXPECT_EQ("0,0 1050x300", contents_view()->bounds().ToString()); - EXPECT_FALSE(workspace_manager()->is_overview()); - workspace_manager()->SetOverview(true); - EXPECT_TRUE(workspace_manager()->is_overview()); - - // Switching overview mode doesn't change the active workspace. - EXPECT_EQ(ws2, workspace_manager()->GetActiveWorkspace()); - - // Activating window w1 switches the active window and - // the mode back to normal mode. - aura_shell::ActivateWindow(w1.get()); - EXPECT_EQ(ws1, workspace_manager()->GetActiveWorkspace()); - EXPECT_FALSE(workspace_manager()->is_overview()); - - // Deleting w1 without StackingClient resets the active workspace - ws1->RemoveWindow(w1.get()); - delete ws1; - w1.reset(); - EXPECT_EQ(ws2, workspace_manager()->GetActiveWorkspace()); - EXPECT_EQ("0,0 500x300", contents_view()->bounds().ToString()); - ws2->RemoveWindow(w2.get()); - delete ws2; - // The size of contents_view() for no workspace case must be - // same as one contents_view() case. - EXPECT_EQ("0,0 500x300", contents_view()->bounds().ToString()); - - // Reset now before windows are destroyed. - controller_.reset(); -} - -} // namespace internal -} // namespace aura_shell |