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

Unified Diff: ui/aura_shell/examples/window_type_launcher.cc

Issue 7972023: Implicit animations through Layer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More tweaks Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/aura_shell/examples/window_type_launcher.h ('k') | ui/gfx/compositor/compositor.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/aura_shell/examples/window_type_launcher.cc
diff --git a/ui/aura_shell/examples/window_type_launcher.cc b/ui/aura_shell/examples/window_type_launcher.cc
index e620088fdbde8a09830bf27cd47a2bae4b1a3759..8496f6a86795c2e8f2af6fa839b245376980e55e 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)),
« no previous file with comments | « ui/aura_shell/examples/window_type_launcher.h ('k') | ui/gfx/compositor/compositor.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698