diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-29 15:38:12 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-29 15:38:12 +0000 |
commit | 7fca53d420d201e1ec5a637ad236056c61e4e4b1 (patch) | |
tree | 8489ef482f21b5a0250582aa2dabff1c4335b270 /ui/aura_shell | |
parent | 79a5004a179fc12eb4e7ed6d1d12bd8b454fde6b (diff) | |
download | chromium_src-7fca53d420d201e1ec5a637ad236056c61e4e4b1.zip chromium_src-7fca53d420d201e1ec5a637ad236056c61e4e4b1.tar.gz chromium_src-7fca53d420d201e1ec5a637ad236056c61e4e4b1.tar.bz2 |
Adds the ability to set an Animation on Layer so that future changes to the layer result in animating the property. See code in desktop_window_view.cc and window.cc for usage.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/7972023
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@103282 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/aura_shell')
-rw-r--r-- | ui/aura_shell/desktop_layout_manager.cc | 2 | ||||
-rw-r--r-- | ui/aura_shell/examples/window_type_launcher.cc | 122 | ||||
-rw-r--r-- | ui/aura_shell/examples/window_type_launcher.h | 15 |
3 files changed, 135 insertions, 4 deletions
diff --git a/ui/aura_shell/desktop_layout_manager.cc b/ui/aura_shell/desktop_layout_manager.cc index 4585f58..6a8e639 100644 --- a/ui/aura_shell/desktop_layout_manager.cc +++ b/ui/aura_shell/desktop_layout_manager.cc @@ -30,7 +30,7 @@ DesktopLayoutManager::~DesktopLayoutManager() { void DesktopLayoutManager::OnWindowResized() { gfx::Rect fullscreen_bounds = gfx::Rect(owner_->bounds().width(), owner_->bounds().height()); - toplevel_window_container_->SetBounds(fullscreen_bounds, 0); + toplevel_window_container_->SetBounds(fullscreen_bounds); background_widget_->SetBounds(fullscreen_bounds); diff --git a/ui/aura_shell/examples/window_type_launcher.cc b/ui/aura_shell/examples/window_type_launcher.cc index b4a9681..0865692 100644 --- a/ui/aura_shell/examples/window_type_launcher.cc +++ b/ui/aura_shell/examples/window_type_launcher.cc @@ -5,11 +5,13 @@ #include "ui/aura_shell/examples/window_type_launcher.h" #include "base/utf_string_conversions.h" +#include "ui/aura/desktop.h" #include "ui/aura/window.h" #include "ui/aura_shell/examples/example_factory.h" #include "ui/aura_shell/examples/toplevel_window.h" #include "ui/aura_shell/toplevel_frame_view.h" #include "ui/gfx/canvas.h" +#include "ui/gfx/compositor/layer.h" #include "views/controls/button/text_button.h" #include "views/controls/menu/menu_item_view.h" #include "views/controls/menu/menu_runner.h" @@ -21,6 +23,64 @@ 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)->visibility() != aura::Window::VISIBILITY_HIDDEN) { + 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)->visibility() != aura::Window::VISIBILITY_HIDDEN) { + 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, @@ -36,7 +96,8 @@ WindowTypeLauncher::WindowTypeLauncher() create_nonresizable_button_(new views::NativeTextButton( this, L"Create Non-Resizable Window"))), ALLOW_THIS_IN_INITIALIZER_LIST(bubble_button_( - new views::NativeTextButton(this, L"Create Pointy Bubble"))) { + new views::NativeTextButton(this, L"Create Pointy Bubble"))), + ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { AddChildView(create_button_); AddChildView(create_nonresizable_button_); AddChildView(bubble_button_); @@ -46,6 +107,51 @@ WindowTypeLauncher::WindowTypeLauncher() WindowTypeLauncher::~WindowTypeLauncher() { } +void WindowTypeLauncher::TileWindows() { + to_restore_.clear(); + aura::Window* window_container = + aura::Desktop::GetInstance()->toplevel_window_container(); + 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() { + aura::Window* window_container = + aura::Desktop::GetInstance()->toplevel_window_container(); + 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()); } @@ -111,8 +217,16 @@ void WindowTypeLauncher::ButtonPressed(views::Button* sender, } void WindowTypeLauncher::ExecuteCommand(int id) { - DCHECK_EQ(id, COMMAND_NEW_WINDOW); - InitWindowTypeLauncher(); + switch (id) { + case COMMAND_NEW_WINDOW: + InitWindowTypeLauncher(); + break; + case COMMAND_TILE_WINDOWS: + TileWindows(); + break; + default: + break; + } } void WindowTypeLauncher::ShowContextMenuForView(views::View* source, @@ -120,6 +234,8 @@ 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); // MenuRunner takes ownership of root. menu_runner_.reset(new MenuRunner(root)); if (menu_runner_->RunMenuAt(GetWidget(), NULL, gfx::Rect(p, gfx::Size(0, 0)), diff --git a/ui/aura_shell/examples/window_type_launcher.h b/ui/aura_shell/examples/window_type_launcher.h index 9fb6eaf..ea39900 100644 --- a/ui/aura_shell/examples/window_type_launcher.h +++ b/ui/aura_shell/examples/window_type_launcher.h @@ -6,6 +6,10 @@ #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" @@ -30,10 +34,16 @@ class WindowTypeLauncher : public views::WidgetDelegateView, virtual ~WindowTypeLauncher(); private: + typedef std::pair<aura::Window*, gfx::Rect> WindowAndBoundsPair; + enum MenuCommands { COMMAND_NEW_WINDOW = 1, + COMMAND_TILE_WINDOWS = 2, }; + void TileWindows(); + void RestoreTiledWindows(); + // Overridden from views::View: virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; virtual void Layout() OVERRIDE; @@ -61,8 +71,13 @@ class WindowTypeLauncher : public views::WidgetDelegateView, views::NativeTextButton* create_button_; views::NativeTextButton* create_nonresizable_button_; views::NativeTextButton* bubble_button_; + views::NativeTextButton* tile_button_; scoped_ptr<views::MenuRunner> menu_runner_; + std::vector<WindowAndBoundsPair> to_restore_; + + ScopedRunnableMethodFactory<WindowTypeLauncher> method_factory_; + DISALLOW_COPY_AND_ASSIGN(WindowTypeLauncher); }; |