| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/extensions/api/wm/wm_utils.h" |
| 6 |
| 7 #include "ash/wm/window_util.h" |
| 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/common/extensions/api/experimental_wm.h" |
| 10 #include "ui/aura/client/aura_constants.h" |
| 11 #include "ui/base/ui_base_types.h" |
| 12 |
| 13 namespace { |
| 14 |
| 15 const char kWindowStateFullscreen[] = "fullscreen"; |
| 16 const char kWindowStateMaximized[] = "maximized"; |
| 17 const char kWindowStateMinimized[] = "minimized"; |
| 18 const char kWindowStateNormal[] = "normal"; |
| 19 |
| 20 const char kWindowTypeModal[] = "modal"; |
| 21 const char kWindowTypeNormal[] = "normal"; |
| 22 const char kWindowTypePanel[] = "panel"; |
| 23 |
| 24 std::list<const aura::Window*>::iterator FindPosition( |
| 25 std::list<const aura::Window*>& list, |
| 26 const aura::Window* item) { |
| 27 for (std::list<const aura::Window*>::iterator iter = list.begin(); |
| 28 iter != list.end(); |
| 29 ++iter) { |
| 30 if (*iter == item) |
| 31 return iter; |
| 32 } |
| 33 return list.end(); |
| 34 } |
| 35 |
| 36 } |
| 37 |
| 38 namespace extensions { |
| 39 namespace api { |
| 40 namespace wm { |
| 41 |
| 42 WindowIdTracker::WindowIdTracker() |
| 43 : next_window_id_(0) { |
| 44 } |
| 45 |
| 46 WindowIdTracker::~WindowIdTracker() {} |
| 47 |
| 48 // static |
| 49 WindowIdTracker* WindowIdTracker::GetInstance() { |
| 50 return Singleton<WindowIdTracker>::get(); |
| 51 } |
| 52 |
| 53 int WindowIdTracker::WindowExtensionId(const aura::Window* window) { |
| 54 return lookup_[window]; |
| 55 } |
| 56 |
| 57 const aura::Window* WindowIdTracker::ExtensionIdWindow(int extension_id) { |
| 58 return reverse_lookup_[extension_id]; |
| 59 } |
| 60 |
| 61 int WindowIdTracker::TrackWindow(const aura::Window* window) { |
| 62 lookup_[window] = ++next_window_id_; |
| 63 reverse_lookup_[next_window_id_] = window; |
| 64 creation_order_.push_front(window); |
| 65 return next_window_id_; |
| 66 } |
| 67 |
| 68 void WindowIdTracker::UntrackWindow(const aura::Window* window) { |
| 69 int window_extension_id = lookup_[window]; |
| 70 lookup_.erase(window); |
| 71 reverse_lookup_.erase(window_extension_id); |
| 72 |
| 73 std::list<const aura::Window*>::iterator pos = FindPosition(activation_order_, |
| 74 window); |
| 75 if (pos != activation_order_.end()) |
| 76 activation_order_.erase(pos); |
| 77 |
| 78 pos = FindPosition(creation_order_, window); |
| 79 if (pos != creation_order_.end()) |
| 80 creation_order_.erase(pos); |
| 81 } |
| 82 |
| 83 void WindowIdTracker::ActivateWindow(const aura::Window* window) { |
| 84 std::list<const aura::Window*>::iterator pos = FindPosition(activation_order_, |
| 85 window); |
| 86 if (pos != activation_order_.end()) |
| 87 activation_order_.erase(pos); |
| 88 activation_order_.push_front(window); |
| 89 } |
| 90 |
| 91 std::vector<const aura::Window*> WindowIdTracker::AllWindows(bool activation) { |
| 92 std::vector<const aura::Window*> windows; |
| 93 std::list<const aura::Window*>::iterator iter, begin, end; |
| 94 begin = activation ? activation_order_.begin() : creation_order_.begin(); |
| 95 end = activation ? activation_order_.end() : creation_order_.end(); |
| 96 for (iter = begin; iter != end; ++iter) |
| 97 windows.push_back(*iter); |
| 98 |
| 99 return windows; |
| 100 } |
| 101 |
| 102 namespace utils { |
| 103 |
| 104 void AuraWindowToExtensionWindow(const aura::Window* window, |
| 105 experimental_wm::AshWindow* extension_window) { |
| 106 if (!window) { |
| 107 extension_window->id = -1; |
| 108 return; |
| 109 } |
| 110 |
| 111 extension_window->id = |
| 112 WindowIdTracker::GetInstance()->WindowExtensionId(window); |
| 113 extension_window->title = UTF16ToUTF8(window->title()); |
| 114 extension_window->name = window->name(); |
| 115 |
| 116 if (window->GetProperty(aura::client::kModalKey) == ui::MODAL_TYPE_WINDOW) |
| 117 extension_window->type = kWindowTypeModal; |
| 118 else if (window->type() == aura::client::WINDOW_TYPE_PANEL) |
| 119 extension_window->type = kWindowTypePanel; |
| 120 else |
| 121 extension_window->type = kWindowTypeNormal; |
| 122 |
| 123 if (ash::wm::IsWindowMaximized(window)) |
| 124 extension_window->state = kWindowStateMaximized; |
| 125 else if (ash::wm::IsWindowMinimized(window)) |
| 126 extension_window->state = kWindowStateMinimized; |
| 127 else if (ash::wm::IsWindowFullscreen(window)) |
| 128 extension_window->state = kWindowStateFullscreen; |
| 129 else |
| 130 extension_window->state = kWindowStateNormal; |
| 131 |
| 132 gfx::Rect bounds = window->bounds(); |
| 133 extension_window->bounds.x = bounds.x(); |
| 134 extension_window->bounds.y = bounds.y(); |
| 135 extension_window->bounds.width = bounds.width(); |
| 136 extension_window->bounds.height = bounds.height(); |
| 137 |
| 138 extension_window->active = ash::wm::IsActiveWindow( |
| 139 const_cast<aura::Window*>(window)); |
| 140 } |
| 141 |
| 142 } // namespace utils |
| 143 } // namespace wm |
| 144 } // namespace api |
| 145 } // namespace extensions |
| OLD | NEW |