| 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> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "ash/mus/shadow.h" | 9 #include "ash/mus/shadow.h" |
| 10 #include "services/ui/public/cpp/property_type_converters.h" | 10 #include "services/ui/public/cpp/property_type_converters.h" |
| 11 #include "services/ui/public/cpp/window_property.h" | 11 #include "services/ui/public/cpp/window_property.h" |
| 12 #include "ui/gfx/geometry/rect.h" | 12 #include "ui/gfx/geometry/rect.h" |
| 13 #include "ui/gfx/geometry/size.h" | 13 #include "ui/gfx/geometry/size.h" |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 MUS_DEFINE_LOCAL_WINDOW_PROPERTY_KEY(ash::mus::Shadow*, | 17 MUS_DEFINE_LOCAL_WINDOW_PROPERTY_KEY(ash::mus::Shadow*, |
| 18 kLocalShadowProperty, | 18 kLocalShadowProperty, |
| 19 nullptr); | 19 nullptr); |
| 20 MUS_DEFINE_LOCAL_WINDOW_PROPERTY_KEY(bool, kWindowIsJankyProperty, false); | 20 MUS_DEFINE_LOCAL_WINDOW_PROPERTY_KEY(bool, kWindowIsJankyProperty, false); |
| 21 | 21 |
| 22 } // namespace | 22 } // namespace |
| 23 | 23 |
| 24 namespace ash { | 24 namespace ash { |
| 25 namespace mus { | 25 namespace mus { |
| 26 | 26 |
| 27 void SetWindowShowState(::ui::Window* window, | 27 void SetWindowShowState(ui::Window* window, ui::mojom::ShowState show_state) { |
| 28 ::ui::mojom::ShowState show_state) { | |
| 29 window->SetSharedProperty<int32_t>( | 28 window->SetSharedProperty<int32_t>( |
| 30 ::ui::mojom::WindowManager::kShowState_Property, | 29 ui::mojom::WindowManager::kShowState_Property, |
| 31 static_cast<uint32_t>(show_state)); | 30 static_cast<uint32_t>(show_state)); |
| 32 } | 31 } |
| 33 | 32 |
| 34 ::ui::mojom::ShowState GetWindowShowState(const ::ui::Window* window) { | 33 ui::mojom::ShowState GetWindowShowState(const ui::Window* window) { |
| 35 if (window->HasSharedProperty( | 34 if (window->HasSharedProperty( |
| 36 ::ui::mojom::WindowManager::kShowState_Property)) { | 35 ui::mojom::WindowManager::kShowState_Property)) { |
| 37 return static_cast<::ui::mojom::ShowState>( | 36 return static_cast<ui::mojom::ShowState>(window->GetSharedProperty<int32_t>( |
| 38 window->GetSharedProperty<int32_t>( | 37 ui::mojom::WindowManager::kShowState_Property)); |
| 39 ::ui::mojom::WindowManager::kShowState_Property)); | |
| 40 } | 38 } |
| 41 return ::ui::mojom::ShowState::DEFAULT; | 39 return ui::mojom::ShowState::DEFAULT; |
| 42 } | 40 } |
| 43 | 41 |
| 44 void SetWindowUserSetBounds(::ui::Window* window, const gfx::Rect& bounds) { | 42 void SetWindowUserSetBounds(ui::Window* window, const gfx::Rect& bounds) { |
| 45 if (bounds.IsEmpty()) { | 43 if (bounds.IsEmpty()) { |
| 46 window->ClearSharedProperty( | 44 window->ClearSharedProperty( |
| 47 ::ui::mojom::WindowManager::kUserSetBounds_Property); | 45 ui::mojom::WindowManager::kUserSetBounds_Property); |
| 48 } else { | 46 } else { |
| 49 window->SetSharedProperty<gfx::Rect>( | 47 window->SetSharedProperty<gfx::Rect>( |
| 50 ::ui::mojom::WindowManager::kUserSetBounds_Property, bounds); | 48 ui::mojom::WindowManager::kUserSetBounds_Property, bounds); |
| 51 } | 49 } |
| 52 } | 50 } |
| 53 | 51 |
| 54 gfx::Rect GetWindowUserSetBounds(const ::ui::Window* window) { | 52 gfx::Rect GetWindowUserSetBounds(const ui::Window* window) { |
| 55 if (window->HasSharedProperty( | 53 if (window->HasSharedProperty( |
| 56 ::ui::mojom::WindowManager::kUserSetBounds_Property)) { | 54 ui::mojom::WindowManager::kUserSetBounds_Property)) { |
| 57 return window->GetSharedProperty<gfx::Rect>( | 55 return window->GetSharedProperty<gfx::Rect>( |
| 58 ::ui::mojom::WindowManager::kUserSetBounds_Property); | 56 ui::mojom::WindowManager::kUserSetBounds_Property); |
| 59 } | 57 } |
| 60 return gfx::Rect(); | 58 return gfx::Rect(); |
| 61 } | 59 } |
| 62 | 60 |
| 63 void SetWindowPreferredSize(::ui::Window* window, const gfx::Size& size) { | 61 void SetWindowPreferredSize(ui::Window* window, const gfx::Size& size) { |
| 64 window->SetSharedProperty<gfx::Size>( | 62 window->SetSharedProperty<gfx::Size>( |
| 65 ::ui::mojom::WindowManager::kPreferredSize_Property, size); | 63 ui::mojom::WindowManager::kPreferredSize_Property, size); |
| 66 } | 64 } |
| 67 | 65 |
| 68 gfx::Size GetWindowPreferredSize(const ::ui::Window* window) { | 66 gfx::Size GetWindowPreferredSize(const ui::Window* window) { |
| 69 if (window->HasSharedProperty( | 67 if (window->HasSharedProperty( |
| 70 ::ui::mojom::WindowManager::kPreferredSize_Property)) { | 68 ui::mojom::WindowManager::kPreferredSize_Property)) { |
| 71 return window->GetSharedProperty<gfx::Size>( | 69 return window->GetSharedProperty<gfx::Size>( |
| 72 ::ui::mojom::WindowManager::kPreferredSize_Property); | 70 ui::mojom::WindowManager::kPreferredSize_Property); |
| 73 } | 71 } |
| 74 return gfx::Size(); | 72 return gfx::Size(); |
| 75 } | 73 } |
| 76 | 74 |
| 77 bool GetRequestedContainer(const ::ui::Window* window, | 75 bool GetRequestedContainer(const ui::Window* window, |
| 78 mojom::Container* container) { | 76 mojom::Container* container) { |
| 79 if (!window->HasSharedProperty(mojom::kWindowContainer_Property)) | 77 if (!window->HasSharedProperty(mojom::kWindowContainer_Property)) |
| 80 return false; | 78 return false; |
| 81 | 79 |
| 82 *container = static_cast<mojom::Container>( | 80 *container = static_cast<mojom::Container>( |
| 83 window->GetSharedProperty<int32_t>(mojom::kWindowContainer_Property)); | 81 window->GetSharedProperty<int32_t>(mojom::kWindowContainer_Property)); |
| 84 return true; | 82 return true; |
| 85 } | 83 } |
| 86 | 84 |
| 87 int32_t GetResizeBehavior(const ::ui::Window* window) { | 85 int32_t GetResizeBehavior(const ui::Window* window) { |
| 88 if (window->HasSharedProperty( | 86 if (window->HasSharedProperty( |
| 89 ::ui::mojom::WindowManager::kResizeBehavior_Property)) { | 87 ui::mojom::WindowManager::kResizeBehavior_Property)) { |
| 90 return window->GetSharedProperty<int32_t>( | 88 return window->GetSharedProperty<int32_t>( |
| 91 ::ui::mojom::WindowManager::kResizeBehavior_Property); | 89 ui::mojom::WindowManager::kResizeBehavior_Property); |
| 92 } | 90 } |
| 93 return ::ui::mojom::kResizeBehaviorNone; | 91 return ui::mojom::kResizeBehaviorNone; |
| 94 } | 92 } |
| 95 | 93 |
| 96 void SetRestoreBounds(::ui::Window* window, const gfx::Rect& bounds) { | 94 void SetRestoreBounds(ui::Window* window, const gfx::Rect& bounds) { |
| 97 window->SetSharedProperty<gfx::Rect>( | 95 window->SetSharedProperty<gfx::Rect>( |
| 98 ::ui::mojom::WindowManager::kRestoreBounds_Property, bounds); | 96 ui::mojom::WindowManager::kRestoreBounds_Property, bounds); |
| 99 } | 97 } |
| 100 | 98 |
| 101 gfx::Rect GetRestoreBounds(const ::ui::Window* window) { | 99 gfx::Rect GetRestoreBounds(const ui::Window* window) { |
| 102 if (window->HasSharedProperty( | 100 if (window->HasSharedProperty( |
| 103 ::ui::mojom::WindowManager::kRestoreBounds_Property)) { | 101 ui::mojom::WindowManager::kRestoreBounds_Property)) { |
| 104 return window->GetSharedProperty<gfx::Rect>( | 102 return window->GetSharedProperty<gfx::Rect>( |
| 105 ::ui::mojom::WindowManager::kRestoreBounds_Property); | 103 ui::mojom::WindowManager::kRestoreBounds_Property); |
| 106 } | 104 } |
| 107 return gfx::Rect(); | 105 return gfx::Rect(); |
| 108 } | 106 } |
| 109 | 107 |
| 110 void SetShadow(::ui::Window* window, Shadow* shadow) { | 108 void SetShadow(ui::Window* window, Shadow* shadow) { |
| 111 window->SetLocalProperty(kLocalShadowProperty, shadow); | 109 window->SetLocalProperty(kLocalShadowProperty, shadow); |
| 112 } | 110 } |
| 113 | 111 |
| 114 Shadow* GetShadow(const ::ui::Window* window) { | 112 Shadow* GetShadow(const ui::Window* window) { |
| 115 return window->GetLocalProperty(kLocalShadowProperty); | 113 return window->GetLocalProperty(kLocalShadowProperty); |
| 116 } | 114 } |
| 117 | 115 |
| 118 ::ui::mojom::WindowType GetWindowType(const ::ui::Window* window) { | 116 ui::mojom::WindowType GetWindowType(const ui::Window* window) { |
| 119 if (window->HasSharedProperty( | 117 if (window->HasSharedProperty( |
| 120 ::ui::mojom::WindowManager::kWindowType_Property)) { | 118 ui::mojom::WindowManager::kWindowType_Property)) { |
| 121 return static_cast<::ui::mojom::WindowType>( | 119 return static_cast<ui::mojom::WindowType>( |
| 122 window->GetSharedProperty<int32_t>( | 120 window->GetSharedProperty<int32_t>( |
| 123 ::ui::mojom::WindowManager::kWindowType_Property)); | 121 ui::mojom::WindowManager::kWindowType_Property)); |
| 124 } | 122 } |
| 125 return ::ui::mojom::WindowType::POPUP; | 123 return ui::mojom::WindowType::POPUP; |
| 126 } | 124 } |
| 127 | 125 |
| 128 ::ui::mojom::WindowType GetWindowType( | 126 ui::mojom::WindowType GetWindowType( |
| 129 const ::ui::Window::SharedProperties& properties) { | 127 const ui::Window::SharedProperties& properties) { |
| 130 const auto iter = | 128 const auto iter = |
| 131 properties.find(::ui::mojom::WindowManager::kWindowType_Property); | 129 properties.find(ui::mojom::WindowManager::kWindowType_Property); |
| 132 if (iter != properties.end()) { | 130 if (iter != properties.end()) { |
| 133 return static_cast<::ui::mojom::WindowType>( | 131 return static_cast<ui::mojom::WindowType>( |
| 134 mojo::ConvertTo<int32_t>(iter->second)); | 132 mojo::ConvertTo<int32_t>(iter->second)); |
| 135 } | 133 } |
| 136 return ::ui::mojom::WindowType::POPUP; | 134 return ui::mojom::WindowType::POPUP; |
| 137 } | 135 } |
| 138 | 136 |
| 139 ui::wm::WindowType GetWmWindowType(const ::ui::Window* window) { | 137 ui::wm::WindowType GetWmWindowType(const ui::Window* window) { |
| 140 switch (GetWindowType(window)) { | 138 switch (GetWindowType(window)) { |
| 141 case ::ui::mojom::WindowType::WINDOW: | 139 case ui::mojom::WindowType::WINDOW: |
| 142 return ui::wm::WINDOW_TYPE_NORMAL; | 140 return ui::wm::WINDOW_TYPE_NORMAL; |
| 143 | 141 |
| 144 case ::ui::mojom::WindowType::PANEL: | 142 case ui::mojom::WindowType::PANEL: |
| 145 return ui::wm::WINDOW_TYPE_PANEL; | 143 return ui::wm::WINDOW_TYPE_PANEL; |
| 146 | 144 |
| 147 case ::ui::mojom::WindowType::CONTROL: | 145 case ui::mojom::WindowType::CONTROL: |
| 148 return ui::wm::WINDOW_TYPE_CONTROL; | 146 return ui::wm::WINDOW_TYPE_CONTROL; |
| 149 | 147 |
| 150 case ::ui::mojom::WindowType::WINDOW_FRAMELESS: | 148 case ui::mojom::WindowType::WINDOW_FRAMELESS: |
| 151 case ::ui::mojom::WindowType::POPUP: | 149 case ui::mojom::WindowType::POPUP: |
| 152 case ::ui::mojom::WindowType::BUBBLE: | 150 case ui::mojom::WindowType::BUBBLE: |
| 153 case ::ui::mojom::WindowType::DRAG: | 151 case ui::mojom::WindowType::DRAG: |
| 154 return ui::wm::WINDOW_TYPE_POPUP; | 152 return ui::wm::WINDOW_TYPE_POPUP; |
| 155 | 153 |
| 156 case ::ui::mojom::WindowType::MENU: | 154 case ui::mojom::WindowType::MENU: |
| 157 return ui::wm::WINDOW_TYPE_MENU; | 155 return ui::wm::WINDOW_TYPE_MENU; |
| 158 | 156 |
| 159 case ::ui::mojom::WindowType::TOOLTIP: | 157 case ui::mojom::WindowType::TOOLTIP: |
| 160 return ui::wm::WINDOW_TYPE_TOOLTIP; | 158 return ui::wm::WINDOW_TYPE_TOOLTIP; |
| 161 } | 159 } |
| 162 | 160 |
| 163 return ui::wm::WINDOW_TYPE_UNKNOWN; | 161 return ui::wm::WINDOW_TYPE_UNKNOWN; |
| 164 } | 162 } |
| 165 | 163 |
| 166 mojom::AshWindowType GetAshWindowType(const ::ui::Window* window) { | 164 mojom::AshWindowType GetAshWindowType(const ui::Window* window) { |
| 167 if (!window->HasSharedProperty(mojom::kAshWindowType_Property)) | 165 if (!window->HasSharedProperty(mojom::kAshWindowType_Property)) |
| 168 return mojom::AshWindowType::COUNT; | 166 return mojom::AshWindowType::COUNT; |
| 169 | 167 |
| 170 return static_cast<mojom::AshWindowType>( | 168 return static_cast<mojom::AshWindowType>( |
| 171 window->GetSharedProperty<int32_t>(mojom::kAshWindowType_Property)); | 169 window->GetSharedProperty<int32_t>(mojom::kAshWindowType_Property)); |
| 172 } | 170 } |
| 173 | 171 |
| 174 base::string16 GetWindowTitle(const ::ui::Window* window) { | 172 base::string16 GetWindowTitle(const ui::Window* window) { |
| 175 if (!window->HasSharedProperty( | 173 if (!window->HasSharedProperty( |
| 176 ::ui::mojom::WindowManager::kWindowTitle_Property)) { | 174 ui::mojom::WindowManager::kWindowTitle_Property)) { |
| 177 return base::string16(); | 175 return base::string16(); |
| 178 } | 176 } |
| 179 | 177 |
| 180 return window->GetSharedProperty<base::string16>( | 178 return window->GetSharedProperty<base::string16>( |
| 181 ::ui::mojom::WindowManager::kWindowTitle_Property); | 179 ui::mojom::WindowManager::kWindowTitle_Property); |
| 182 } | 180 } |
| 183 | 181 |
| 184 mojo::Array<uint8_t> GetWindowAppIcon(const ::ui::Window* window) { | 182 mojo::Array<uint8_t> GetWindowAppIcon(const ui::Window* window) { |
| 185 if (window->HasSharedProperty( | 183 if (window->HasSharedProperty( |
| 186 ::ui::mojom::WindowManager::kWindowAppIcon_Property)) { | 184 ui::mojom::WindowManager::kWindowAppIcon_Property)) { |
| 187 return mojo::Array<uint8_t>::From( | 185 return mojo::Array<uint8_t>::From( |
| 188 window->GetSharedProperty<std::vector<uint8_t>>( | 186 window->GetSharedProperty<std::vector<uint8_t>>( |
| 189 ::ui::mojom::WindowManager::kWindowAppIcon_Property)); | 187 ui::mojom::WindowManager::kWindowAppIcon_Property)); |
| 190 } | 188 } |
| 191 return mojo::Array<uint8_t>(); | 189 return mojo::Array<uint8_t>(); |
| 192 } | 190 } |
| 193 | 191 |
| 194 void SetAppID(::ui::Window* window, const base::string16& app_id) { | 192 void SetAppID(ui::Window* window, const base::string16& app_id) { |
| 195 window->SetSharedProperty<base::string16>( | 193 window->SetSharedProperty<base::string16>( |
| 196 ::ui::mojom::WindowManager::kAppID_Property, app_id); | 194 ui::mojom::WindowManager::kAppID_Property, app_id); |
| 197 } | 195 } |
| 198 | 196 |
| 199 base::string16 GetAppID(const ::ui::Window* window) { | 197 base::string16 GetAppID(const ui::Window* window) { |
| 200 if (!window->HasSharedProperty(::ui::mojom::WindowManager::kAppID_Property)) | 198 if (!window->HasSharedProperty(ui::mojom::WindowManager::kAppID_Property)) |
| 201 return base::string16(); | 199 return base::string16(); |
| 202 | 200 |
| 203 return window->GetSharedProperty<base::string16>( | 201 return window->GetSharedProperty<base::string16>( |
| 204 ::ui::mojom::WindowManager::kAppID_Property); | 202 ui::mojom::WindowManager::kAppID_Property); |
| 205 } | 203 } |
| 206 | 204 |
| 207 bool GetWindowIgnoredByShelf(::ui::Window* window) { | 205 bool GetWindowIgnoredByShelf(ui::Window* window) { |
| 208 return window->HasSharedProperty( | 206 return window->HasSharedProperty( |
| 209 ::ui::mojom::WindowManager::kWindowIgnoredByShelf_Property) && | 207 ui::mojom::WindowManager::kWindowIgnoredByShelf_Property) && |
| 210 window->GetSharedProperty<bool>( | 208 window->GetSharedProperty<bool>( |
| 211 ::ui::mojom::WindowManager::kWindowIgnoredByShelf_Property); | 209 ui::mojom::WindowManager::kWindowIgnoredByShelf_Property); |
| 212 } | 210 } |
| 213 | 211 |
| 214 void SetWindowIsJanky(::ui::Window* window, bool janky) { | 212 void SetWindowIsJanky(ui::Window* window, bool janky) { |
| 215 window->SetLocalProperty(kWindowIsJankyProperty, janky); | 213 window->SetLocalProperty(kWindowIsJankyProperty, janky); |
| 216 } | 214 } |
| 217 | 215 |
| 218 bool IsWindowJanky(::ui::Window* window) { | 216 bool IsWindowJanky(ui::Window* window) { |
| 219 return window->GetLocalProperty(kWindowIsJankyProperty); | 217 return window->GetLocalProperty(kWindowIsJankyProperty); |
| 220 } | 218 } |
| 221 | 219 |
| 222 bool IsWindowJankyProperty(const void* key) { | 220 bool IsWindowJankyProperty(const void* key) { |
| 223 return key == kWindowIsJankyProperty; | 221 return key == kWindowIsJankyProperty; |
| 224 } | 222 } |
| 225 | 223 |
| 226 void SetAlwaysOnTop(::ui::Window* window, bool value) { | 224 void SetAlwaysOnTop(ui::Window* window, bool value) { |
| 227 window->SetSharedProperty<bool>( | 225 window->SetSharedProperty<bool>( |
| 228 ::ui::mojom::WindowManager::kAlwaysOnTop_Property, value); | 226 ui::mojom::WindowManager::kAlwaysOnTop_Property, value); |
| 229 } | 227 } |
| 230 | 228 |
| 231 bool IsAlwaysOnTop(::ui::Window* window) { | 229 bool IsAlwaysOnTop(ui::Window* window) { |
| 232 return window->HasSharedProperty( | 230 return window->HasSharedProperty( |
| 233 ::ui::mojom::WindowManager::kAlwaysOnTop_Property) && | 231 ui::mojom::WindowManager::kAlwaysOnTop_Property) && |
| 234 window->GetSharedProperty<bool>( | 232 window->GetSharedProperty<bool>( |
| 235 ::ui::mojom::WindowManager::kAlwaysOnTop_Property); | 233 ui::mojom::WindowManager::kAlwaysOnTop_Property); |
| 236 } | 234 } |
| 237 | 235 |
| 238 bool ShouldRemoveStandardFrame(::ui::Window* window) { | 236 bool ShouldRemoveStandardFrame(ui::Window* window) { |
| 239 return window->HasSharedProperty( | 237 return window->HasSharedProperty( |
| 240 ::ui::mojom::WindowManager::kRemoveStandardFrame_Property) && | 238 ui::mojom::WindowManager::kRemoveStandardFrame_Property) && |
| 241 window->GetSharedProperty<bool>( | 239 window->GetSharedProperty<bool>( |
| 242 ::ui::mojom::WindowManager::kRemoveStandardFrame_Property); | 240 ui::mojom::WindowManager::kRemoveStandardFrame_Property); |
| 243 } | 241 } |
| 244 | 242 |
| 245 } // namespace mus | 243 } // namespace mus |
| 246 } // namespace ash | 244 } // namespace ash |
| OLD | NEW |