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

Unified Diff: chrome/browser/extensions/api/wm/wm_utils.cc

Issue 10824364: [NOT FOR REVIEW] ash: Add some implementation for the window management extension API. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 4 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 | « chrome/browser/extensions/api/wm/wm_utils.h ('k') | chrome/browser/ui/ash/window_manager_extension.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..0f7adb7cff386127d2ac9bc696c8292f76acb827
--- /dev/null
+++ b/chrome/browser/extensions/api/wm/wm_utils.cc
@@ -0,0 +1,100 @@
+// 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";
+
+}
+
+namespace extensions {
+namespace api {
+namespace wm {
+
+WindowIdTracker::WindowIdTracker()
+ : next_window_id_(1) {
+}
+
+WindowIdTracker::~WindowIdTracker() {}
+
+// static
+WindowIdTracker* WindowIdTracker::GetInstance() {
+ return Singleton<WindowIdTracker>::get();
+}
+
+int WindowIdTracker::GetWindowExtensionId(gfx::NativeWindow window) {
+ if (!lookup_.count(window)) {
+ lookup_[window] = next_window_id_;
+ reverse_lookup_[next_window_id_] = window;
+ ++next_window_id_;
+ }
+ return lookup_[window];
+}
+
+void WindowIdTracker::UntrackWindow(gfx::NativeWindow window) {
+ int window_extension_id = lookup_[window];
+ lookup_.erase(window);
+ reverse_lookup_.erase(window_extension_id);
+}
+
+namespace utils {
+
+#if defined(USE_ASH)
+void NativeWindowToExtensionWindow(
+ gfx::NativeWindow window,
+ experimental_wm::WmWindow* extension_window) {
+ if (!window) {
+ extension_window->id = -1;
+ return;
+ }
+
+ extension_window->id =
+ WindowIdTracker::GetInstance()->GetWindowExtensionId(window);
+ extension_window->title = UTF16ToUTF8(window->title());
+
+ 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(window);
+}
+#endif // defined(USE_ASH)
+
+} // namespace utils
+} // namespace wm
+} // namespace api
+} // namespace extensions
« no previous file with comments | « chrome/browser/extensions/api/wm/wm_utils.h ('k') | chrome/browser/ui/ash/window_manager_extension.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698