| Index: chrome/browser/extensions/api/wm/wm_api.cc
|
| diff --git a/chrome/browser/extensions/api/wm/wm_api.cc b/chrome/browser/extensions/api/wm/wm_api.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..ebc774ba9e205e4606d9fcf17e83a760dc172c64
|
| --- /dev/null
|
| +++ b/chrome/browser/extensions/api/wm/wm_api.cc
|
| @@ -0,0 +1,312 @@
|
| +// Copyright (c) 2012 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 "chrome/browser/extensions/api/wm/wm_api.h"
|
| +
|
| +#include <vector>
|
| +
|
| +#include "ash/wm/window_util.h"
|
| +#include "base/memory/scoped_ptr.h"
|
| +#include "chrome/browser/extensions/api/wm/wm_utils.h"
|
| +#include "chrome/common/extensions/api/experimental_wm.h"
|
| +#include "content/public/browser/browser_thread.h"
|
| +#include "ui/aura/client/aura_constants.h"
|
| +#include "ui/aura/window.h"
|
| +#include "ui/base/ui_base_types.h"
|
| +#include "ui/compositor/layer.h"
|
| +#include "ui/compositor/scoped_layer_animation_settings.h"
|
| +#include "ui/gfx/display.h"
|
| +#include "ui/gfx/point3.h"
|
| +#include "ui/gfx/screen.h"
|
| +
|
| +namespace {
|
| +
|
| +const char kWindowOrderActivity[] = "activity";
|
| +
|
| +}
|
| +
|
| +namespace extensions {
|
| +namespace api {
|
| +
|
| +////////////////////////////////////////////////////////////////////////////////
|
| +// WindowFunction
|
| +
|
| +WindowFunction::WindowFunction() : window_id_(0) {
|
| +}
|
| +
|
| +WindowFunction::~WindowFunction() {}
|
| +
|
| +bool WindowFunction::Prepare() {
|
| + if (!args_.get() || args_->empty() ||
|
| + !args_->GetInteger(0, &window_id_))
|
| + return false;
|
| + EXTENSION_FUNCTION_VALIDATE(window_id_);
|
| + set_work_thread_id(content::BrowserThread::UI);
|
| + return true;
|
| +}
|
| +
|
| +void WindowFunction::Work() {
|
| + const aura::Window* window = wm::WindowIdTracker::GetInstance()->
|
| + ExtensionIdWindow(window_id_);
|
| + if (!window) {
|
| + SetResult(base::Value::CreateNullValue());
|
| + return;
|
| + }
|
| +
|
| + bool result = WorkOnWindow(const_cast<aura::Window*>(window));
|
| + SetResult(base::Value::CreateBooleanValue(result));
|
| +}
|
| +
|
| +bool WindowFunction::Respond() {
|
| + return true;
|
| +}
|
| +
|
| +////////////////////////////////////////////////////////////////////////////////
|
| +// WmCloseFunction
|
| +
|
| +WmCloseFunction::WmCloseFunction() {}
|
| +
|
| +WmCloseFunction::~WmCloseFunction() {}
|
| +
|
| +bool WmCloseFunction::WorkOnWindow(aura::Window* window) {
|
| + delete window;
|
| + return true;
|
| +}
|
| +
|
| +////////////////////////////////////////////////////////////////////////////////
|
| +// WmMinimizeFunction
|
| +
|
| +WmMinimizeFunction::WmMinimizeFunction() {}
|
| +
|
| +WmMinimizeFunction::~WmMinimizeFunction() {}
|
| +
|
| +bool WmMinimizeFunction::WorkOnWindow(aura::Window* window) {
|
| + ash::wm::MinimizeWindow(window);
|
| + return true;
|
| +}
|
| +
|
| +////////////////////////////////////////////////////////////////////////////////
|
| +// WmMaximizeFunction
|
| +
|
| +WmMaximizeFunction::WmMaximizeFunction() {}
|
| +
|
| +WmMaximizeFunction::~WmMaximizeFunction() {}
|
| +
|
| +bool WmMaximizeFunction::WorkOnWindow(aura::Window* window) {
|
| + ash::wm::MaximizeWindow(window);
|
| + return true;
|
| +}
|
| +
|
| +////////////////////////////////////////////////////////////////////////////////
|
| +// WmFullscreenFunction
|
| +
|
| +WmFullscreenFunction::WmFullscreenFunction() {}
|
| +
|
| +WmFullscreenFunction::~WmFullscreenFunction() {}
|
| +
|
| +bool WmFullscreenFunction::WorkOnWindow(aura::Window* window) {
|
| + window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
|
| + return true;
|
| +}
|
| +
|
| +////////////////////////////////////////////////////////////////////////////////
|
| +// WmRestoreFunction
|
| +
|
| +WmRestoreFunction::WmRestoreFunction() {}
|
| +
|
| +WmRestoreFunction::~WmRestoreFunction() {}
|
| +
|
| +bool WmRestoreFunction::WorkOnWindow(aura::Window* window) {
|
| + if (ash::wm::IsWindowFullscreen(window) || ash::wm::IsWindowMaximized(window))
|
| + ash::wm::RestoreWindow(window);
|
| + return true;
|
| +}
|
| +
|
| +////////////////////////////////////////////////////////////////////////////////
|
| +// WindowLayerFunction
|
| +
|
| +WindowLayerFunction::WindowLayerFunction(int num_arguments)
|
| + : duration_(0),
|
| + num_arguments_(num_arguments) {
|
| +}
|
| +
|
| +WindowLayerFunction::~WindowLayerFunction() {}
|
| +
|
| +bool WindowLayerFunction::Prepare() {
|
| + if (!WindowFunction::Prepare())
|
| + return false;
|
| + if (!args_->GetInteger(num_arguments_ + 1, &duration_))
|
| + duration_ = 0;
|
| + return true;
|
| +}
|
| +
|
| +bool WindowLayerFunction::WorkOnWindow(aura::Window* window) {
|
| + ui::Layer* layer = window->layer();
|
| + if (duration_ > 0) {
|
| + ui::ScopedLayerAnimationSettings settings(layer->GetAnimator());
|
| + settings.SetTransitionDuration(
|
| + base::TimeDelta::FromMilliseconds(duration_));
|
| + WorkOnLayer(layer);
|
| + } else {
|
| + WorkOnLayer(layer);
|
| + }
|
| + return true;
|
| +}
|
| +
|
| +////////////////////////////////////////////////////////////////////////////////
|
| +// WmOpacityFunction
|
| +
|
| +WmOpacityFunction::WmOpacityFunction()
|
| + : WindowLayerFunction(1),
|
| + opacity_(1.) {
|
| +}
|
| +
|
| +WmOpacityFunction::~WmOpacityFunction() {}
|
| +
|
| +bool WmOpacityFunction::Prepare() {
|
| + if (!WindowLayerFunction::Prepare())
|
| + return false;
|
| +
|
| + if (!args_->GetDouble(1, &opacity_))
|
| + return false;
|
| + EXTENSION_FUNCTION_VALIDATE(opacity_);
|
| + return true;
|
| +}
|
| +
|
| +void WmOpacityFunction::WorkOnLayer(ui::Layer* layer) {
|
| + layer->SetOpacity(static_cast<float>(opacity_));
|
| +}
|
| +
|
| +////////////////////////////////////////////////////////////////////////////////
|
| +// WmTransformFunction
|
| +
|
| +WmTransformFunction::WmTransformFunction()
|
| + : WindowLayerFunction(1) {
|
| +}
|
| +
|
| +WmTransformFunction::~WmTransformFunction() {}
|
| +
|
| +bool WmTransformFunction::Prepare() {
|
| + if (!WindowLayerFunction::Prepare())
|
| + return false;
|
| +
|
| + base::DictionaryValue* dict = NULL;
|
| + if (!args_->GetDictionary(1, &dict) || !dict)
|
| + return false;
|
| + dictionary_.reset(dict->DeepCopyWithoutEmptyChildren());
|
| + return true;
|
| +}
|
| +
|
| +void WmTransformFunction::WorkOnLayer(ui::Layer* layer) {
|
| + ui::Transform transform;
|
| +
|
| + double rotate = 0;
|
| + if (dictionary_->GetDouble("rotate", &rotate)) {
|
| + gfx::Point3f axis(1, 0, 0);
|
| + transform.ConcatRotateAbout(axis, rotate);
|
| + }
|
| +
|
| + double perspective = 0;
|
| + if (dictionary_->GetDouble("perspective", &perspective))
|
| + transform.SetPerspectiveDepth(perspective);
|
| +
|
| + double scale;
|
| + if (dictionary_->GetDouble("scale", &scale))
|
| + transform.ConcatScale(scale, scale);
|
| +
|
| + double translate_x = 0, translate_y = 0;
|
| + if (!dictionary_->GetDouble("translateX", &translate_x))
|
| + translate_x = 0;
|
| + if (!dictionary_->GetDouble("translateY", &translate_y))
|
| + translate_y = 0;
|
| + if (translate_x != 0 || translate_y != 0)
|
| + transform.ConcatTranslate(translate_x, translate_y);
|
| +
|
| + layer->SetTransform(transform);
|
| +}
|
| +
|
| +////////////////////////////////////////////////////////////////////////////////
|
| +// WmSetWindowBoundsFunction
|
| +
|
| +void WmSetWindowBoundsFunction::WorkOnLayer(ui::Layer* layer) {
|
| + int x, y, width, height;
|
| + gfx::Rect bounds = layer->GetTargetBounds();
|
| +
|
| + if (dictionary_->GetInteger("x", &x))
|
| + bounds.set_x(x);
|
| + if (dictionary_->GetInteger("y", &y))
|
| + bounds.set_y(y);
|
| + if (dictionary_->GetInteger("width", &width))
|
| + bounds.set_width(width);
|
| + if (dictionary_->GetInteger("height", &height))
|
| + bounds.set_height(height);
|
| +
|
| + // TODO(sad): Note that if the window is maximized/fullscreen, this has really
|
| + // nasty side-effects. Handle these cases gracefully.
|
| + layer->SetBounds(bounds);
|
| +}
|
| +
|
| +////////////////////////////////////////////////////////////////////////////////
|
| +// WmWindowsFunction
|
| +
|
| +bool WmWindowsFunction::RunImpl() {
|
| + std::string list_order;
|
| + std::vector<const aura::Window*> windows;
|
| + if (args_->GetString(0, &list_order) && list_order == kWindowOrderActivity) {
|
| + windows = wm::WindowIdTracker::GetInstance()->AllWindows(true);
|
| + } else {
|
| + windows = wm::WindowIdTracker::GetInstance()->AllWindows(false);
|
| + }
|
| +
|
| + ListValue* windowlist = new ListValue;
|
| + for (std::vector<const aura::Window*>::iterator iter = windows.begin();
|
| + iter != windows.end();
|
| + ++iter) {
|
| + experimental_wm::AshWindow extension_window;
|
| + wm::utils::AuraWindowToExtensionWindow(*iter, &extension_window);
|
| + windowlist->Append(
|
| + extension_window.ToValue()->DeepCopyWithoutEmptyChildren());
|
| + }
|
| + SetResult(windowlist);
|
| + return true;
|
| +}
|
| +
|
| +////////////////////////////////////////////////////////////////////////////////
|
| +// WmScreenBoundsFunction
|
| +
|
| +bool WmScreenBoundsFunction::RunImpl() {
|
| + base::DictionaryValue* dict = new base::DictionaryValue;
|
| + gfx::Rect bounds = gfx::Screen::GetPrimaryDisplay().bounds();
|
| + dict->SetInteger("x", bounds.x());
|
| + dict->SetInteger("y", bounds.y());
|
| + dict->SetInteger("width", bounds.width());
|
| + dict->SetInteger("height", bounds.height());
|
| + SetResult(dict);
|
| + return true;
|
| +}
|
| +
|
| +////////////////////////////////////////////////////////////////////////////////
|
| +// WmStackWindowAboveFunction
|
| +
|
| +bool WmStackWindowAboveFunction::RunImpl() {
|
| + int above_window_id, below_window_id;
|
| + if (!args_->GetInteger(0, &above_window_id) ||
|
| + !args_->GetInteger(1, &below_window_id))
|
| + return false;
|
| +
|
| + aura::Window* above_window = const_cast<aura::Window*>(
|
| + wm::WindowIdTracker::GetInstance()->ExtensionIdWindow(above_window_id));
|
| + aura::Window* below_window = const_cast<aura::Window*>(
|
| + wm::WindowIdTracker::GetInstance()->ExtensionIdWindow(below_window_id));
|
| +
|
| + if (!above_window || !below_window ||
|
| + above_window->parent() != below_window->parent())
|
| + return false;
|
| +
|
| + above_window->parent()->StackChildAbove(above_window, below_window);
|
| + return true;
|
| +}
|
| +
|
| +} // namespace api
|
| +} // namespace extensions
|
|
|