| Index: chrome/browser/extensions/api/wm/wm_utils.cc
|
| diff --git a/chrome/browser/extensions/api/wm/wm_utils.cc b/chrome/browser/extensions/api/wm/wm_utils.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..1e2bb0b7c05e6eb928b5b13ae188c1b951a2d3c6
|
| --- /dev/null
|
| +++ b/chrome/browser/extensions/api/wm/wm_utils.cc
|
| @@ -0,0 +1,145 @@
|
| +// 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_utils.h"
|
| +
|
| +#include "ash/wm/window_util.h"
|
| +#include "base/utf_string_conversions.h"
|
| +#include "chrome/common/extensions/api/experimental_wm.h"
|
| +#include "ui/aura/client/aura_constants.h"
|
| +#include "ui/base/ui_base_types.h"
|
| +
|
| +namespace {
|
| +
|
| +const char kWindowStateFullscreen[] = "fullscreen";
|
| +const char kWindowStateMaximized[] = "maximized";
|
| +const char kWindowStateMinimized[] = "minimized";
|
| +const char kWindowStateNormal[] = "normal";
|
| +
|
| +const char kWindowTypeModal[] = "modal";
|
| +const char kWindowTypeNormal[] = "normal";
|
| +const char kWindowTypePanel[] = "panel";
|
| +
|
| +std::list<const aura::Window*>::iterator FindPosition(
|
| + std::list<const aura::Window*>& list,
|
| + const aura::Window* item) {
|
| + for (std::list<const aura::Window*>::iterator iter = list.begin();
|
| + iter != list.end();
|
| + ++iter) {
|
| + if (*iter == item)
|
| + return iter;
|
| + }
|
| + return list.end();
|
| +}
|
| +
|
| +}
|
| +
|
| +namespace extensions {
|
| +namespace api {
|
| +namespace wm {
|
| +
|
| +WindowIdTracker::WindowIdTracker()
|
| + : next_window_id_(0) {
|
| +}
|
| +
|
| +WindowIdTracker::~WindowIdTracker() {}
|
| +
|
| +// static
|
| +WindowIdTracker* WindowIdTracker::GetInstance() {
|
| + return Singleton<WindowIdTracker>::get();
|
| +}
|
| +
|
| +int WindowIdTracker::WindowExtensionId(const aura::Window* window) {
|
| + return lookup_[window];
|
| +}
|
| +
|
| +const aura::Window* WindowIdTracker::ExtensionIdWindow(int extension_id) {
|
| + return reverse_lookup_[extension_id];
|
| +}
|
| +
|
| +int WindowIdTracker::TrackWindow(const aura::Window* window) {
|
| + lookup_[window] = ++next_window_id_;
|
| + reverse_lookup_[next_window_id_] = window;
|
| + creation_order_.push_front(window);
|
| + return next_window_id_;
|
| +}
|
| +
|
| +void WindowIdTracker::UntrackWindow(const aura::Window* window) {
|
| + int window_extension_id = lookup_[window];
|
| + lookup_.erase(window);
|
| + reverse_lookup_.erase(window_extension_id);
|
| +
|
| + std::list<const aura::Window*>::iterator pos = FindPosition(activation_order_,
|
| + window);
|
| + if (pos != activation_order_.end())
|
| + activation_order_.erase(pos);
|
| +
|
| + pos = FindPosition(creation_order_, window);
|
| + if (pos != creation_order_.end())
|
| + creation_order_.erase(pos);
|
| +}
|
| +
|
| +void WindowIdTracker::ActivateWindow(const aura::Window* window) {
|
| + std::list<const aura::Window*>::iterator pos = FindPosition(activation_order_,
|
| + window);
|
| + if (pos != activation_order_.end())
|
| + activation_order_.erase(pos);
|
| + activation_order_.push_front(window);
|
| +}
|
| +
|
| +std::vector<const aura::Window*> WindowIdTracker::AllWindows(bool activation) {
|
| + std::vector<const aura::Window*> windows;
|
| + std::list<const aura::Window*>::iterator iter, begin, end;
|
| + begin = activation ? activation_order_.begin() : creation_order_.begin();
|
| + end = activation ? activation_order_.end() : creation_order_.end();
|
| + for (iter = begin; iter != end; ++iter)
|
| + windows.push_back(*iter);
|
| +
|
| + return windows;
|
| +}
|
| +
|
| +namespace utils {
|
| +
|
| +void AuraWindowToExtensionWindow(const aura::Window* window,
|
| + experimental_wm::AshWindow* extension_window) {
|
| + if (!window) {
|
| + extension_window->id = -1;
|
| + return;
|
| + }
|
| +
|
| + extension_window->id =
|
| + WindowIdTracker::GetInstance()->WindowExtensionId(window);
|
| + extension_window->title = UTF16ToUTF8(window->title());
|
| + extension_window->name = window->name();
|
| +
|
| + if (window->GetProperty(aura::client::kModalKey) == ui::MODAL_TYPE_WINDOW)
|
| + extension_window->type = kWindowTypeModal;
|
| + else if (window->type() == aura::client::WINDOW_TYPE_PANEL)
|
| + extension_window->type = kWindowTypePanel;
|
| + else
|
| + extension_window->type = kWindowTypeNormal;
|
| +
|
| + if (ash::wm::IsWindowMaximized(window))
|
| + extension_window->state = kWindowStateMaximized;
|
| + else if (ash::wm::IsWindowMinimized(window))
|
| + extension_window->state = kWindowStateMinimized;
|
| + else if (ash::wm::IsWindowFullscreen(window))
|
| + extension_window->state = kWindowStateFullscreen;
|
| + else
|
| + extension_window->state = kWindowStateNormal;
|
| +
|
| + gfx::Rect bounds = window->bounds();
|
| + extension_window->bounds.x = bounds.x();
|
| + extension_window->bounds.y = bounds.y();
|
| + extension_window->bounds.width = bounds.width();
|
| + extension_window->bounds.height = bounds.height();
|
| +
|
| + extension_window->active = ash::wm::IsActiveWindow(
|
| + const_cast<aura::Window*>(window));
|
| +}
|
| +
|
| +} // namespace utils
|
| +} // namespace wm
|
| +} // namespace api
|
| +} // namespace extensions
|
|
|