| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/mus/property_util.h" | 5 #include "ash/mus/property_util.h" |
| 6 | 6 |
| 7 #include <stdint.h> | |
| 8 | |
| 9 #include "ash/mus/shadow.h" | |
| 10 #include "services/ui/public/cpp/property_type_converters.h" | 7 #include "services/ui/public/cpp/property_type_converters.h" |
| 11 #include "services/ui/public/cpp/window_property.h" | |
| 12 #include "services/ui/public/interfaces/window_manager.mojom.h" | 8 #include "services/ui/public/interfaces/window_manager.mojom.h" |
| 13 #include "ui/display/types/display_constants.h" | 9 #include "ui/display/types/display_constants.h" |
| 14 #include "ui/gfx/geometry/rect.h" | 10 #include "ui/gfx/geometry/rect.h" |
| 15 #include "ui/gfx/geometry/size.h" | 11 #include "ui/gfx/geometry/size.h" |
| 16 | 12 |
| 17 namespace { | |
| 18 | |
| 19 MUS_DEFINE_LOCAL_WINDOW_PROPERTY_KEY(ash::mus::Shadow*, | |
| 20 kLocalShadowProperty, | |
| 21 nullptr); | |
| 22 MUS_DEFINE_LOCAL_WINDOW_PROPERTY_KEY(bool, kWindowIsJankyProperty, false); | |
| 23 | |
| 24 } // namespace | |
| 25 | |
| 26 namespace ash { | 13 namespace ash { |
| 27 namespace mus { | 14 namespace mus { |
| 28 | 15 |
| 29 void SetWindowShowState(ui::Window* window, ui::mojom::ShowState show_state) { | 16 int64_t GetInitialDisplayId(const InitProperties& properties) { |
| 30 window->SetSharedProperty<int32_t>( | |
| 31 ui::mojom::WindowManager::kShowState_Property, | |
| 32 static_cast<uint32_t>(show_state)); | |
| 33 } | |
| 34 | |
| 35 ui::mojom::ShowState GetWindowShowState(const ui::Window* window) { | |
| 36 if (window->HasSharedProperty( | |
| 37 ui::mojom::WindowManager::kShowState_Property)) { | |
| 38 return static_cast<ui::mojom::ShowState>(window->GetSharedProperty<int32_t>( | |
| 39 ui::mojom::WindowManager::kShowState_Property)); | |
| 40 } | |
| 41 return ui::mojom::ShowState::DEFAULT; | |
| 42 } | |
| 43 | |
| 44 void SetWindowUserSetBounds(ui::Window* window, const gfx::Rect& bounds) { | |
| 45 if (bounds.IsEmpty()) { | |
| 46 window->ClearSharedProperty( | |
| 47 ui::mojom::WindowManager::kUserSetBounds_Property); | |
| 48 } else { | |
| 49 window->SetSharedProperty<gfx::Rect>( | |
| 50 ui::mojom::WindowManager::kUserSetBounds_Property, bounds); | |
| 51 } | |
| 52 } | |
| 53 | |
| 54 gfx::Rect GetWindowUserSetBounds(const ui::Window* window) { | |
| 55 if (window->HasSharedProperty( | |
| 56 ui::mojom::WindowManager::kUserSetBounds_Property)) { | |
| 57 return window->GetSharedProperty<gfx::Rect>( | |
| 58 ui::mojom::WindowManager::kUserSetBounds_Property); | |
| 59 } | |
| 60 return gfx::Rect(); | |
| 61 } | |
| 62 | |
| 63 void SetWindowPreferredSize(ui::Window* window, const gfx::Size& size) { | |
| 64 window->SetSharedProperty<gfx::Size>( | |
| 65 ui::mojom::WindowManager::kPreferredSize_Property, size); | |
| 66 } | |
| 67 | |
| 68 gfx::Size GetWindowPreferredSize(const ui::Window* window) { | |
| 69 if (window->HasSharedProperty( | |
| 70 ui::mojom::WindowManager::kPreferredSize_Property)) { | |
| 71 return window->GetSharedProperty<gfx::Size>( | |
| 72 ui::mojom::WindowManager::kPreferredSize_Property); | |
| 73 } | |
| 74 return gfx::Size(); | |
| 75 } | |
| 76 | |
| 77 bool GetRequestedContainer(const ui::Window* window, int* container_id) { | |
| 78 if (!window->HasSharedProperty( | |
| 79 ui::mojom::WindowManager::kInitialContainerId_Property)) | |
| 80 return false; | |
| 81 | |
| 82 *container_id = window->GetSharedProperty<int32_t>( | |
| 83 ui::mojom::WindowManager::kInitialContainerId_Property); | |
| 84 return true; | |
| 85 } | |
| 86 | |
| 87 void SetResizeBehavior(ui::Window::SharedProperties* properties, | |
| 88 int32_t resize_behavior) { | |
| 89 (*properties)[ui::mojom::WindowManager::kResizeBehavior_Property] = | |
| 90 mojo::ConvertTo<std::vector<uint8_t>>(resize_behavior); | |
| 91 } | |
| 92 | |
| 93 int32_t GetResizeBehavior(const ui::Window* window) { | |
| 94 if (window->HasSharedProperty( | |
| 95 ui::mojom::WindowManager::kResizeBehavior_Property)) { | |
| 96 return window->GetSharedProperty<int32_t>( | |
| 97 ui::mojom::WindowManager::kResizeBehavior_Property); | |
| 98 } | |
| 99 return ui::mojom::kResizeBehaviorNone; | |
| 100 } | |
| 101 | |
| 102 void SetRestoreBounds(ui::Window* window, const gfx::Rect& bounds) { | |
| 103 window->SetSharedProperty<gfx::Rect>( | |
| 104 ui::mojom::WindowManager::kRestoreBounds_Property, bounds); | |
| 105 } | |
| 106 | |
| 107 gfx::Rect GetRestoreBounds(const ui::Window* window) { | |
| 108 if (window->HasSharedProperty( | |
| 109 ui::mojom::WindowManager::kRestoreBounds_Property)) { | |
| 110 return window->GetSharedProperty<gfx::Rect>( | |
| 111 ui::mojom::WindowManager::kRestoreBounds_Property); | |
| 112 } | |
| 113 return gfx::Rect(); | |
| 114 } | |
| 115 | |
| 116 void SetShadow(ui::Window* window, Shadow* shadow) { | |
| 117 window->SetLocalProperty(kLocalShadowProperty, shadow); | |
| 118 } | |
| 119 | |
| 120 Shadow* GetShadow(const ui::Window* window) { | |
| 121 return window->GetLocalProperty(kLocalShadowProperty); | |
| 122 } | |
| 123 | |
| 124 ui::mojom::WindowType GetWindowType(const ui::Window* window) { | |
| 125 if (window->HasSharedProperty( | |
| 126 ui::mojom::WindowManager::kWindowType_Property)) { | |
| 127 return static_cast<ui::mojom::WindowType>( | |
| 128 window->GetSharedProperty<int32_t>( | |
| 129 ui::mojom::WindowManager::kWindowType_Property)); | |
| 130 } | |
| 131 return ui::mojom::WindowType::POPUP; | |
| 132 } | |
| 133 | |
| 134 ui::mojom::WindowType GetWindowType( | |
| 135 const ui::Window::SharedProperties& properties) { | |
| 136 const auto iter = | |
| 137 properties.find(ui::mojom::WindowManager::kWindowType_Property); | |
| 138 if (iter != properties.end()) { | |
| 139 return static_cast<ui::mojom::WindowType>( | |
| 140 mojo::ConvertTo<int32_t>(iter->second)); | |
| 141 } | |
| 142 return ui::mojom::WindowType::POPUP; | |
| 143 } | |
| 144 | |
| 145 ui::wm::WindowType GetWmWindowType(const ui::Window* window) { | |
| 146 switch (GetWindowType(window)) { | |
| 147 case ui::mojom::WindowType::WINDOW: | |
| 148 return ui::wm::WINDOW_TYPE_NORMAL; | |
| 149 | |
| 150 case ui::mojom::WindowType::PANEL: | |
| 151 return ui::wm::WINDOW_TYPE_PANEL; | |
| 152 | |
| 153 case ui::mojom::WindowType::CONTROL: | |
| 154 return ui::wm::WINDOW_TYPE_CONTROL; | |
| 155 | |
| 156 case ui::mojom::WindowType::WINDOW_FRAMELESS: | |
| 157 case ui::mojom::WindowType::POPUP: | |
| 158 case ui::mojom::WindowType::BUBBLE: | |
| 159 case ui::mojom::WindowType::DRAG: | |
| 160 return ui::wm::WINDOW_TYPE_POPUP; | |
| 161 | |
| 162 case ui::mojom::WindowType::MENU: | |
| 163 return ui::wm::WINDOW_TYPE_MENU; | |
| 164 | |
| 165 case ui::mojom::WindowType::TOOLTIP: | |
| 166 return ui::wm::WINDOW_TYPE_TOOLTIP; | |
| 167 | |
| 168 case ui::mojom::WindowType::UNKNOWN: | |
| 169 return ui::wm::WINDOW_TYPE_UNKNOWN; | |
| 170 } | |
| 171 | |
| 172 return ui::wm::WINDOW_TYPE_UNKNOWN; | |
| 173 } | |
| 174 | |
| 175 mojom::AshWindowType GetAshWindowType(const ui::Window* window) { | |
| 176 if (!window->HasSharedProperty(mojom::kAshWindowType_Property)) | |
| 177 return mojom::AshWindowType::COUNT; | |
| 178 | |
| 179 return static_cast<mojom::AshWindowType>( | |
| 180 window->GetSharedProperty<int32_t>(mojom::kAshWindowType_Property)); | |
| 181 } | |
| 182 | |
| 183 void SetWindowTitle(ui::Window* window, base::string16 title) { | |
| 184 window->SetSharedProperty<base::string16>( | |
| 185 ui::mojom::WindowManager::kWindowTitle_Property, title); | |
| 186 } | |
| 187 | |
| 188 base::string16 GetWindowTitle(const ui::Window* window) { | |
| 189 if (!window->HasSharedProperty( | |
| 190 ui::mojom::WindowManager::kWindowTitle_Property)) { | |
| 191 return base::string16(); | |
| 192 } | |
| 193 | |
| 194 return window->GetSharedProperty<base::string16>( | |
| 195 ui::mojom::WindowManager::kWindowTitle_Property); | |
| 196 } | |
| 197 | |
| 198 void SetAppID(ui::Window* window, const base::string16& app_id) { | |
| 199 window->SetSharedProperty<base::string16>( | |
| 200 ui::mojom::WindowManager::kAppID_Property, app_id); | |
| 201 } | |
| 202 | |
| 203 base::string16 GetAppID(const ui::Window* window) { | |
| 204 if (!window->HasSharedProperty(ui::mojom::WindowManager::kAppID_Property)) | |
| 205 return base::string16(); | |
| 206 | |
| 207 return window->GetSharedProperty<base::string16>( | |
| 208 ui::mojom::WindowManager::kAppID_Property); | |
| 209 } | |
| 210 | |
| 211 bool GetWindowIgnoredByShelf(ui::Window* window) { | |
| 212 return window->HasSharedProperty( | |
| 213 ui::mojom::WindowManager::kWindowIgnoredByShelf_Property) && | |
| 214 window->GetSharedProperty<bool>( | |
| 215 ui::mojom::WindowManager::kWindowIgnoredByShelf_Property); | |
| 216 } | |
| 217 | |
| 218 void SetWindowIsJanky(ui::Window* window, bool janky) { | |
| 219 window->SetLocalProperty(kWindowIsJankyProperty, janky); | |
| 220 } | |
| 221 | |
| 222 bool IsWindowJanky(ui::Window* window) { | |
| 223 return window->GetLocalProperty(kWindowIsJankyProperty); | |
| 224 } | |
| 225 | |
| 226 bool IsWindowJankyProperty(const void* key) { | |
| 227 return key == kWindowIsJankyProperty; | |
| 228 } | |
| 229 | |
| 230 void SetAlwaysOnTop(ui::Window* window, bool value) { | |
| 231 window->SetSharedProperty<bool>( | |
| 232 ui::mojom::WindowManager::kAlwaysOnTop_Property, value); | |
| 233 } | |
| 234 | |
| 235 bool IsAlwaysOnTop(ui::Window* window) { | |
| 236 return window->HasSharedProperty( | |
| 237 ui::mojom::WindowManager::kAlwaysOnTop_Property) && | |
| 238 window->GetSharedProperty<bool>( | |
| 239 ui::mojom::WindowManager::kAlwaysOnTop_Property); | |
| 240 } | |
| 241 | |
| 242 bool ShouldRemoveStandardFrame(ui::Window* window) { | |
| 243 return window->HasSharedProperty( | |
| 244 ui::mojom::WindowManager::kRemoveStandardFrame_Property) && | |
| 245 window->GetSharedProperty<bool>( | |
| 246 ui::mojom::WindowManager::kRemoveStandardFrame_Property); | |
| 247 } | |
| 248 | |
| 249 bool ShouldRenderParentTitleArea(ui::Window* window) { | |
| 250 return window->HasSharedProperty( | |
| 251 ui::mojom::WindowManager::kRendererParentTitleArea_Property) && | |
| 252 window->GetSharedProperty<bool>( | |
| 253 ui::mojom::WindowManager::kRendererParentTitleArea_Property); | |
| 254 } | |
| 255 | |
| 256 int64_t GetInitialDisplayId(const ui::Window::SharedProperties& properties) { | |
| 257 auto iter = | 17 auto iter = |
| 258 properties.find(ui::mojom::WindowManager::kInitialDisplayId_Property); | 18 properties.find(ui::mojom::WindowManager::kInitialDisplayId_Property); |
| 259 return iter == properties.end() ? display::kInvalidDisplayId | 19 return iter == properties.end() ? display::kInvalidDisplayId |
| 260 : mojo::ConvertTo<int64_t>(iter->second); | 20 : mojo::ConvertTo<int64_t>(iter->second); |
| 261 } | 21 } |
| 262 | 22 |
| 263 void SetExcludeFromMru(ui::Window* window, bool value) { | 23 bool GetInitialContainerId(const InitProperties& properties, |
| 264 window->SetSharedProperty<bool>( | 24 int* container_id) { |
| 265 ui::mojom::WindowManager::kExcludeFromMru_Property, value); | 25 auto iter = |
| 26 properties.find(ui::mojom::WindowManager::kInitialContainerId_Property); |
| 27 if (iter == properties.end()) |
| 28 return false; |
| 29 |
| 30 *container_id = mojo::ConvertTo<int32_t>(iter->second); |
| 31 return true; |
| 266 } | 32 } |
| 267 | 33 |
| 268 bool GetExcludeFromMru(const ui::Window* window) { | 34 bool GetInitialBounds(const InitProperties& properties, gfx::Rect* bounds) { |
| 269 return window->HasSharedProperty( | 35 auto iter = |
| 270 ui::mojom::WindowManager::kExcludeFromMru_Property) && | 36 properties.find(ui::mojom::WindowManager::kInitialBounds_Property); |
| 271 window->GetSharedProperty<bool>( | 37 if (iter == properties.end()) |
| 272 ui::mojom::WindowManager::kExcludeFromMru_Property); | 38 return false; |
| 39 |
| 40 *bounds = mojo::ConvertTo<gfx::Rect>(iter->second); |
| 41 return true; |
| 42 } |
| 43 |
| 44 bool GetWindowPreferredSize(const InitProperties& properties, gfx::Size* size) { |
| 45 auto iter = |
| 46 properties.find(ui::mojom::WindowManager::kPreferredSize_Property); |
| 47 if (iter == properties.end()) |
| 48 return false; |
| 49 |
| 50 *size = mojo::ConvertTo<gfx::Size>(iter->second); |
| 51 return true; |
| 52 } |
| 53 |
| 54 bool ShouldRemoveStandardFrame(const InitProperties& properties) { |
| 55 auto iter = |
| 56 properties.find(ui::mojom::WindowManager::kRemoveStandardFrame_Property); |
| 57 return iter != properties.end() && mojo::ConvertTo<bool>(iter->second); |
| 58 } |
| 59 |
| 60 bool ShouldEnableImmersive(const InitProperties& properties) { |
| 61 auto iter = |
| 62 properties.find(ui::mojom::WindowManager::kDisableImmersive_Property); |
| 63 return iter == properties.end() || !mojo::ConvertTo<bool>(iter->second); |
| 273 } | 64 } |
| 274 | 65 |
| 275 } // namespace mus | 66 } // namespace mus |
| 276 } // namespace ash | 67 } // namespace ash |
| OLD | NEW |