diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-07 23:22:56 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-07 23:22:56 +0000 |
commit | cac10fc621aec369c6491a9db28c3bccce9220ea (patch) | |
tree | 3db0199a067745ce5b645471eb496d81503566ea /ui | |
parent | c93e4b3821d88d3bed0ff806817e11da6fa39994 (diff) | |
download | chromium_src-cac10fc621aec369c6491a9db28c3bccce9220ea.zip chromium_src-cac10fc621aec369c6491a9db28c3bccce9220ea.tar.gz chromium_src-cac10fc621aec369c6491a9db28c3bccce9220ea.tar.bz2 |
Move window scale animation down into the shell (it'll do as an overview for now).
Make Shell accessible via a GetInstance() method.
Make clicking on the desktop show the scale animation.
Who you finna try?!
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/8198014
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@104600 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r-- | ui/aura_shell/aura_shell_main.cc | 3 | ||||
-rw-r--r-- | ui/aura_shell/desktop_background_view.cc | 11 | ||||
-rw-r--r-- | ui/aura_shell/desktop_background_view.h | 2 | ||||
-rw-r--r-- | ui/aura_shell/examples/window_type_launcher.cc | 110 | ||||
-rw-r--r-- | ui/aura_shell/examples/window_type_launcher.h | 14 | ||||
-rw-r--r-- | ui/aura_shell/shell.cc | 120 | ||||
-rw-r--r-- | ui/aura_shell/shell.h | 22 |
7 files changed, 155 insertions, 127 deletions
diff --git a/ui/aura_shell/aura_shell_main.cc b/ui/aura_shell/aura_shell_main.cc index e0bc660..b556ffa 100644 --- a/ui/aura_shell/aura_shell_main.cc +++ b/ui/aura_shell/aura_shell_main.cc @@ -26,8 +26,7 @@ int main(int argc, char** argv) { // Create the message-loop here before creating the desktop. MessageLoop message_loop(MessageLoop::TYPE_UI); - aura_shell::Shell shell; - shell.Init(); + aura_shell::Shell::GetInstance(); aura_shell::examples::InitWindowTypeLauncher(); diff --git a/ui/aura_shell/desktop_background_view.cc b/ui/aura_shell/desktop_background_view.cc index f4acf63..86690e3 100644 --- a/ui/aura_shell/desktop_background_view.cc +++ b/ui/aura_shell/desktop_background_view.cc @@ -8,6 +8,7 @@ #include "grit/ui_resources.h" #include "ui/aura/desktop.h" #include "ui/aura_shell/aura_shell_export.h" +#include "ui/aura_shell/shell.h" #include "ui/aura_shell/shell_window_ids.h" #include "ui/base/resource/resource_bundle.h" #include "ui/gfx/canvas.h" @@ -34,10 +35,18 @@ void DesktopBackgroundView::OnPaint(gfx::Canvas* canvas) { canvas->TileImageInt(wallpaper_, 0, 0, width(), height()); } +bool DesktopBackgroundView::OnMousePressed(const views::MouseEvent& event) { + return true; +} + +void DesktopBackgroundView::OnMouseReleased(const views::MouseEvent& event) { + Shell::GetInstance()->TileWindows(); +} + views::Widget* CreateDesktopBackground() { views::Widget* desktop_widget = new views::Widget; views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); - params.parent = aura::Desktop::GetInstance()->window()->GetChildById( + params.parent = Shell::GetInstance()->GetContainer( aura_shell::internal::kShellWindowId_DesktopBackgroundContainer); DesktopBackgroundView* view = new DesktopBackgroundView; params.delegate = view; diff --git a/ui/aura_shell/desktop_background_view.h b/ui/aura_shell/desktop_background_view.h index 59380a6..09020ae 100644 --- a/ui/aura_shell/desktop_background_view.h +++ b/ui/aura_shell/desktop_background_view.h @@ -21,6 +21,8 @@ class DesktopBackgroundView : public views::WidgetDelegateView { private: // Overridden from views::View: virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; + virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE; + virtual void OnMouseReleased(const views::MouseEvent& event) OVERRIDE; SkBitmap wallpaper_; diff --git a/ui/aura_shell/examples/window_type_launcher.cc b/ui/aura_shell/examples/window_type_launcher.cc index d5455a2..9ee649e 100644 --- a/ui/aura_shell/examples/window_type_launcher.cc +++ b/ui/aura_shell/examples/window_type_launcher.cc @@ -24,64 +24,6 @@ using views::MenuRunner; namespace aura_shell { namespace examples { -namespace { - -typedef std::pair<aura::Window*, gfx::Rect> WindowAndBoundsPair; - -void CalculateWindowBoundsAndScaleForTiling( - const gfx::Size& containing_size, - const aura::Window::Windows& windows, - float* x_scale, - float* y_scale, - std::vector<WindowAndBoundsPair>* bounds) { - *x_scale = 1.0f; - *y_scale = 1.0f; - int total_width = 0; - int max_height = 0; - int shown_window_count = 0; - for (aura::Window::Windows::const_iterator i = windows.begin(); - i != windows.end(); ++i) { - if ((*i)->IsVisible()) { - total_width += (*i)->bounds().width(); - max_height = std::max((*i)->bounds().height(), max_height); - shown_window_count++; - } - } - - if (shown_window_count == 0) - return; - - const int kPadding = 10; - total_width += (shown_window_count - 1) * kPadding; - if (total_width > containing_size.width()) { - *x_scale = static_cast<float>(containing_size.width()) / - static_cast<float>(total_width); - } - if (max_height > containing_size.height()) { - *y_scale = static_cast<float>(containing_size.height()) / - static_cast<float>(max_height); - } - *x_scale = *y_scale = std::min(*x_scale, *y_scale); - - int x = std::max(0, static_cast<int>( - (containing_size.width() * - total_width * *x_scale) / 2)); - for (aura::Window::Windows::const_iterator i = windows.begin(); - i != windows.end(); - ++i) { - if ((*i)->IsVisible()) { - const gfx::Rect& current_bounds((*i)->bounds()); - int y = (containing_size.height() - - current_bounds.height() * *y_scale) / 2; - bounds->push_back(std::make_pair(*i, - gfx::Rect(x, y, current_bounds.width(), current_bounds.height()))); - x += static_cast<int>( - static_cast<float>(current_bounds.width() + kPadding) * *x_scale); - } - } -} - -} // namespace - void InitWindowTypeLauncher() { views::Widget* widget = views::Widget::CreateWindowWithBounds(new WindowTypeLauncher, @@ -99,8 +41,7 @@ WindowTypeLauncher::WindowTypeLauncher() ALLOW_THIS_IN_INITIALIZER_LIST(bubble_button_( new views::NativeTextButton(this, L"Create Pointy Bubble"))), ALLOW_THIS_IN_INITIALIZER_LIST(lock_button_( - new views::NativeTextButton(this, L"Lock Screen"))), - ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { + new views::NativeTextButton(this, L"Lock Screen"))) { AddChildView(create_button_); AddChildView(create_nonresizable_button_); AddChildView(bubble_button_); @@ -111,50 +52,6 @@ WindowTypeLauncher::WindowTypeLauncher() WindowTypeLauncher::~WindowTypeLauncher() { } -void WindowTypeLauncher::TileWindows() { - to_restore_.clear(); - aura::Window* window_container = - aura::Desktop::GetInstance()->window()->GetChildById( - internal::kShellWindowId_DefaultContainer); - const aura::Window::Windows& windows = window_container->children(); - if (windows.empty()) - return; - float x_scale = 1.0f; - float y_scale = 1.0f; - std::vector<WindowAndBoundsPair> bounds; - CalculateWindowBoundsAndScaleForTiling(window_container->bounds().size(), - windows, &x_scale, &y_scale, &bounds); - if (bounds.empty()) - return; - ui::Transform transform; - transform.SetScale(x_scale, y_scale); - for (size_t i = 0; i < bounds.size(); ++i) { - to_restore_.push_back( - std::make_pair(bounds[i].first, bounds[i].first->bounds())); - bounds[i].first->layer()->SetAnimation( - aura::Window::CreateDefaultAnimation()); - bounds[i].first->SetBounds(bounds[i].second); - bounds[i].first->layer()->SetTransform(transform); - bounds[i].first->layer()->SetOpacity(0.5f); - } - - MessageLoop::current()->PostDelayedTask( - FROM_HERE, method_factory_.NewRunnableMethod( - &WindowTypeLauncher::RestoreTiledWindows), 2000); -} - -void WindowTypeLauncher::RestoreTiledWindows() { - ui::Transform identity_transform; - for (size_t i = 0; i < to_restore_.size(); ++i) { - to_restore_[i].first->layer()->SetAnimation( - aura::Window::CreateDefaultAnimation()); - to_restore_[i].first->SetBounds(to_restore_[i].second); - to_restore_[i].first->layer()->SetTransform(identity_transform); - to_restore_[i].first->layer()->SetOpacity(1.0f); - } - to_restore_.clear(); -} - void WindowTypeLauncher::OnPaint(gfx::Canvas* canvas) { canvas->FillRectInt(SK_ColorWHITE, 0, 0, width(), height()); } @@ -231,9 +128,6 @@ void WindowTypeLauncher::ExecuteCommand(int id) { case COMMAND_NEW_WINDOW: InitWindowTypeLauncher(); break; - case COMMAND_TILE_WINDOWS: - TileWindows(); - break; case COMMAND_TOGGLE_FULLSCREEN: GetWidget()->SetFullscreen(!GetWidget()->IsFullscreen()); break; @@ -247,8 +141,6 @@ void WindowTypeLauncher::ShowContextMenuForView(views::View* source, bool is_mouse_gesture) { MenuItemView* root = new MenuItemView(this); root->AppendMenuItem(COMMAND_NEW_WINDOW, L"New Window", MenuItemView::NORMAL); - root->AppendMenuItem(COMMAND_TILE_WINDOWS, L"Tile Windows", - MenuItemView::NORMAL); root->AppendMenuItem(COMMAND_TOGGLE_FULLSCREEN, L"Toggle FullScreen", MenuItemView::NORMAL); // MenuRunner takes ownership of root. diff --git a/ui/aura_shell/examples/window_type_launcher.h b/ui/aura_shell/examples/window_type_launcher.h index 6b06ca7..ff46ffc 100644 --- a/ui/aura_shell/examples/window_type_launcher.h +++ b/ui/aura_shell/examples/window_type_launcher.h @@ -6,10 +6,6 @@ #define UI_AURA_SHELL_EXAMPLES_WINDOW_TYPE_LAUNCHER_H_ #pragma once -#include <utility> -#include <vector> - -#include "base/task.h" #include "views/context_menu_controller.h" #include "views/controls/button/button.h" #include "views/controls/menu/menu_delegate.h" @@ -38,13 +34,9 @@ class WindowTypeLauncher : public views::WidgetDelegateView, enum MenuCommands { COMMAND_NEW_WINDOW = 1, - COMMAND_TILE_WINDOWS = 2, COMMAND_TOGGLE_FULLSCREEN = 3, }; - void TileWindows(); - void RestoreTiledWindows(); - // Overridden from views::View: virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; virtual void Layout() OVERRIDE; @@ -61,7 +53,7 @@ class WindowTypeLauncher : public views::WidgetDelegateView, virtual void ButtonPressed(views::Button* sender, const views::Event& event) OVERRIDE; - // Overriden from views::MenuDelegate: + // Overridden from views::MenuDelegate: virtual void ExecuteCommand(int id) OVERRIDE; // Override from views::ContextMenuController: @@ -75,10 +67,6 @@ class WindowTypeLauncher : public views::WidgetDelegateView, views::NativeTextButton* lock_button_; scoped_ptr<views::MenuRunner> menu_runner_; - std::vector<WindowAndBoundsPair> to_restore_; - - ScopedRunnableMethodFactory<WindowTypeLauncher> method_factory_; - DISALLOW_COPY_AND_ASSIGN(WindowTypeLauncher); }; diff --git a/ui/aura_shell/shell.cc b/ui/aura_shell/shell.cc index a0958db..bc4505e 100644 --- a/ui/aura_shell/shell.cc +++ b/ui/aura_shell/shell.cc @@ -11,6 +11,7 @@ #include "ui/aura_shell/desktop_layout_manager.h" #include "ui/aura_shell/shell_factory.h" #include "ui/aura_shell/shell_window_ids.h" +#include "ui/gfx/compositor/layer.h" #include "views/widget/widget.h" namespace aura_shell { @@ -51,15 +52,85 @@ void CreateSpecialContainers(aura::Window::Windows* containers) { menu_container->set_id(internal::kShellWindowId_MenusAndTooltipsContainer); containers->push_back(menu_container); } + +typedef std::pair<aura::Window*, gfx::Rect> WindowAndBoundsPair; + +void CalculateWindowBoundsAndScaleForTiling( + const gfx::Size& containing_size, + const aura::Window::Windows& windows, + float* x_scale, + float* y_scale, + std::vector<WindowAndBoundsPair>* bounds) { + *x_scale = 1.0f; + *y_scale = 1.0f; + int total_width = 0; + int max_height = 0; + int shown_window_count = 0; + for (aura::Window::Windows::const_iterator i = windows.begin(); + i != windows.end(); ++i) { + if ((*i)->IsVisible()) { + total_width += (*i)->bounds().width(); + max_height = std::max((*i)->bounds().height(), max_height); + shown_window_count++; + } + } + + if (shown_window_count == 0) + return; + + const int kPadding = 10; + total_width += (shown_window_count - 1) * kPadding; + if (total_width > containing_size.width()) { + *x_scale = static_cast<float>(containing_size.width()) / + static_cast<float>(total_width); + } + if (max_height > containing_size.height()) { + *y_scale = static_cast<float>(containing_size.height()) / + static_cast<float>(max_height); + } + *x_scale = *y_scale = std::min(*x_scale, *y_scale); + + int x = std::max(0, static_cast<int>( + (containing_size.width() * - total_width * *x_scale) / 2)); + for (aura::Window::Windows::const_iterator i = windows.begin(); + i != windows.end(); + ++i) { + if ((*i)->IsVisible()) { + const gfx::Rect& current_bounds((*i)->bounds()); + int y = (containing_size.height() - + current_bounds.height() * *y_scale) / 2; + bounds->push_back(std::make_pair(*i, + gfx::Rect(x, y, current_bounds.width(), current_bounds.height()))); + x += static_cast<int>( + static_cast<float>(current_bounds.width() + kPadding) * *x_scale); + } + } +} + } // namespace -Shell::Shell() { +// static +Shell* Shell::instance_ = NULL; + +//////////////////////////////////////////////////////////////////////////////// +// Shell, public: + +Shell::Shell() : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { aura::Desktop::GetInstance()->SetDelegate(this); } Shell::~Shell() { } +// static +Shell* Shell::GetInstance() { + if (!instance_) { + instance_ = new Shell; + instance_->Init(); + } + return instance_; +} + void Shell::Init() { aura::Window::Windows containers; CreateSpecialContainers(&containers); @@ -89,6 +160,53 @@ const aura::Window* Shell::GetContainer(int container_id) const { return aura::Desktop::GetInstance()->window()->GetChildById(container_id); } +void Shell::TileWindows() { + to_restore_.clear(); + aura::Window* window_container = + aura::Desktop::GetInstance()->window()->GetChildById( + internal::kShellWindowId_DefaultContainer); + const aura::Window::Windows& windows = window_container->children(); + if (windows.empty()) + return; + float x_scale = 1.0f; + float y_scale = 1.0f; + std::vector<WindowAndBoundsPair> bounds; + CalculateWindowBoundsAndScaleForTiling(window_container->bounds().size(), + windows, &x_scale, &y_scale, &bounds); + if (bounds.empty()) + return; + ui::Transform transform; + transform.SetScale(x_scale, y_scale); + for (size_t i = 0; i < bounds.size(); ++i) { + to_restore_.push_back( + std::make_pair(bounds[i].first, bounds[i].first->bounds())); + bounds[i].first->layer()->SetAnimation( + aura::Window::CreateDefaultAnimation()); + bounds[i].first->SetBounds(bounds[i].second); + bounds[i].first->layer()->SetTransform(transform); + bounds[i].first->layer()->SetOpacity(0.5f); + } + + MessageLoop::current()->PostDelayedTask( + FROM_HERE, method_factory_.NewRunnableMethod( + &Shell::RestoreTiledWindows), 2000); +} + +void Shell::RestoreTiledWindows() { + ui::Transform identity_transform; + for (size_t i = 0; i < to_restore_.size(); ++i) { + to_restore_[i].first->layer()->SetAnimation( + aura::Window::CreateDefaultAnimation()); + to_restore_[i].first->SetBounds(to_restore_[i].second); + to_restore_[i].first->layer()->SetTransform(identity_transform); + to_restore_[i].first->layer()->SetOpacity(1.0f); + } + to_restore_.clear(); +} + +//////////////////////////////////////////////////////////////////////////////// +// Shell, aura::DesktopDelegate implementation: + void Shell::AddChildToDefaultParent(aura::Window* window) { aura::Window* parent = NULL; switch (window->type()) { diff --git a/ui/aura_shell/shell.h b/ui/aura_shell/shell.h index 1b67eaa..2d1107c 100644 --- a/ui/aura_shell/shell.h +++ b/ui/aura_shell/shell.h @@ -6,6 +6,10 @@ #define UI_AURA_SHELL_SHELL_H_ #pragma once +#include <utility> +#include <vector> + +#include "base/task.h" #include "base/basictypes.h" #include "base/compiler_specific.h" #include "ui/aura/desktop_delegate.h" @@ -13,6 +17,9 @@ namespace aura { class Window; } +namespace gfx{ +class Rect; +} namespace aura_shell { @@ -25,17 +32,30 @@ class Shell : public aura::DesktopDelegate { Shell(); virtual ~Shell(); + static Shell* GetInstance(); + void Init(); - private: aura::Window* GetContainer(int container_id); const aura::Window* GetContainer(int container_id) const; + void TileWindows(); + void RestoreTiledWindows(); + + private: + typedef std::pair<aura::Window*, gfx::Rect> WindowAndBoundsPair; + // Overridden from aura::DesktopDelegate: virtual void AddChildToDefaultParent(aura::Window* window) OVERRIDE; virtual aura::Window* GetTopmostWindowToActivate( aura::Window* ignore) const OVERRIDE; + static Shell* instance_; + + std::vector<WindowAndBoundsPair> to_restore_; + + ScopedRunnableMethodFactory<Shell> method_factory_; + DISALLOW_COPY_AND_ASSIGN(Shell); }; |