| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef COMPONENTS_MUS_PUBLIC_CPP_WINDOW_PROPERTY_H_ | 5 #ifndef COMPONENTS_MUS_PUBLIC_CPP_WINDOW_PROPERTY_H_ |
| 6 #define COMPONENTS_MUS_PUBLIC_CPP_WINDOW_PROPERTY_H_ | 6 #define COMPONENTS_MUS_PUBLIC_CPP_WINDOW_PROPERTY_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 // This header should be included by code that defines WindowProperties. It | 10 // This header should be included by code that defines WindowProperties. It |
| 11 // should not be included by code that only gets and sets WindowProperties. | 11 // should not be included by code that only gets and sets WindowProperties. |
| 12 // | 12 // |
| 13 // To define a new WindowProperty: | 13 // To define a new WindowProperty: |
| 14 // | 14 // |
| 15 // #include "components/mus/public/cpp/window_property.h" | 15 // #include "components/mus/public/cpp/window_property.h" |
| 16 // | 16 // |
| 17 // DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(FOO_EXPORT, MyType); | 17 // MUS_DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(FOO_EXPORT, MyType); |
| 18 // namespace foo { | 18 // namespace foo { |
| 19 // // Use this to define an exported property that is primitive, | 19 // // Use this to define an exported property that is primitive, |
| 20 // // or a pointer you don't want automatically deleted. | 20 // // or a pointer you don't want automatically deleted. |
| 21 // DEFINE_WINDOW_PROPERTY_KEY(MyType, kMyKey, MyDefault); | 21 // MUS_DEFINE_WINDOW_PROPERTY_KEY(MyType, kMyKey, MyDefault); |
| 22 // | 22 // |
| 23 // // Use this to define an exported property whose value is a heap | 23 // // Use this to define an exported property whose value is a heap |
| 24 // // allocated object, and has to be owned and freed by the window. | 24 // // allocated object, and has to be owned and freed by the window. |
| 25 // DEFINE_OWNED_WINDOW_PROPERTY_KEY(gfx::Rect, kRestoreBoundsKey, nullptr); | 25 // MUS_DEFINE_OWNED_WINDOW_PROPERTY_KEY(gfx::Rect, kRestoreBoundsKey, |
| 26 // nullptr); |
| 26 // | 27 // |
| 27 // // Use this to define a non exported property that is primitive, | 28 // // Use this to define a non exported property that is primitive, |
| 28 // // or a pointer you don't want to automatically deleted, and is used | 29 // // or a pointer you don't want to automatically deleted, and is used |
| 29 // // only in a specific file. This will define the property in an unnamed | 30 // // only in a specific file. This will define the property in an unnamed |
| 30 // // namespace which cannot be accessed from another file. | 31 // // namespace which cannot be accessed from another file. |
| 31 // DEFINE_LOCAL_WINDOW_PROPERTY_KEY(MyType, kMyKey, MyDefault); | 32 // MUS_DEFINE_LOCAL_WINDOW_PROPERTY_KEY(MyType, kMyKey, MyDefault); |
| 32 // | 33 // |
| 33 // } // foo namespace | 34 // } // foo namespace |
| 34 // | 35 // |
| 35 // To define a new type used for WindowProperty. | 36 // To define a new type used for WindowProperty. |
| 36 // | 37 // |
| 37 // // outside all namespaces: | 38 // // outside all namespaces: |
| 38 // DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(FOO_EXPORT, MyType) | 39 // MUS_DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(FOO_EXPORT, MyType) |
| 39 // | 40 // |
| 40 // If a property type is not exported, use DECLARE_WINDOW_PROPERTY_TYPE(MyType) | 41 // If a property type is not exported, use |
| 41 // which is a shorthand for DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(, MyType). | 42 // MUS_DECLARE_WINDOW_PROPERTY_TYPE(MyType) which is a shorthand for |
| 43 // MUS_DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(, MyType). |
| 42 | 44 |
| 43 namespace mus { | 45 namespace mus { |
| 44 | 46 |
| 45 template <typename T> | 47 template <typename T> |
| 46 void Window::SetSharedProperty(const std::string& name, const T& data) { | 48 void Window::SetSharedProperty(const std::string& name, const T& data) { |
| 47 const std::vector<uint8_t> bytes = | 49 const std::vector<uint8_t> bytes = |
| 48 mojo::TypeConverter<const std::vector<uint8_t>, T>::Convert(data); | 50 mojo::TypeConverter<const std::vector<uint8_t>, T>::Convert(data); |
| 49 SetSharedPropertyInternal(name, &bytes); | 51 SetSharedPropertyInternal(name, &bytes); |
| 50 } | 52 } |
| 51 | 53 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 } | 113 } |
| 112 | 114 |
| 113 template <typename T> | 115 template <typename T> |
| 114 void Window::ClearLocalProperty(const WindowProperty<T>* property) { | 116 void Window::ClearLocalProperty(const WindowProperty<T>* property) { |
| 115 SetLocalProperty(property, property->default_value); | 117 SetLocalProperty(property, property->default_value); |
| 116 } | 118 } |
| 117 | 119 |
| 118 } // namespace mus | 120 } // namespace mus |
| 119 | 121 |
| 120 // Macros to instantiate the property getter/setter template functions. | 122 // Macros to instantiate the property getter/setter template functions. |
| 121 #define DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(EXPORT, T) \ | 123 #define MUS_DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(EXPORT, T) \ |
| 122 template EXPORT void mus::Window::SetLocalProperty( \ | 124 template EXPORT void mus::Window::SetLocalProperty( \ |
| 123 const mus::WindowProperty<T>*, T); \ | 125 const mus::WindowProperty<T>*, T); \ |
| 124 template EXPORT T mus::Window::GetLocalProperty( \ | 126 template EXPORT T mus::Window::GetLocalProperty( \ |
| 125 const mus::WindowProperty<T>*) const; \ | 127 const mus::WindowProperty<T>*) const; \ |
| 126 template EXPORT void mus::Window::ClearLocalProperty( \ | 128 template EXPORT void mus::Window::ClearLocalProperty( \ |
| 127 const mus::WindowProperty<T>*); | 129 const mus::WindowProperty<T>*); |
| 128 #define DECLARE_WINDOW_PROPERTY_TYPE(T) \ | 130 #define MUS_DECLARE_WINDOW_PROPERTY_TYPE(T) \ |
| 129 DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(, T) | 131 MUS_DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(, T) |
| 130 | 132 |
| 131 #define DEFINE_WINDOW_PROPERTY_KEY(TYPE, NAME, DEFAULT) \ | 133 #define MUS_DEFINE_WINDOW_PROPERTY_KEY(TYPE, NAME, DEFAULT) \ |
| 132 static_assert(sizeof(TYPE) <= sizeof(int64_t), \ | 134 static_assert(sizeof(TYPE) <= sizeof(int64_t), \ |
| 133 "Property type must fit in 64 bits"); \ | 135 "Property type must fit in 64 bits"); \ |
| 134 namespace { \ | 136 namespace { \ |
| 135 const mus::WindowProperty<TYPE> NAME##_Value = {DEFAULT, #NAME, nullptr}; \ | 137 const mus::WindowProperty<TYPE> NAME##_Value = {DEFAULT, #NAME, nullptr}; \ |
| 136 } \ | 138 } \ |
| 137 const mus::WindowProperty<TYPE>* const NAME = &NAME##_Value; | 139 const mus::WindowProperty<TYPE>* const NAME = &NAME##_Value; |
| 138 | 140 |
| 139 #define DEFINE_LOCAL_WINDOW_PROPERTY_KEY(TYPE, NAME, DEFAULT) \ | 141 #define MUS_DEFINE_LOCAL_WINDOW_PROPERTY_KEY(TYPE, NAME, DEFAULT) \ |
| 140 static_assert(sizeof(TYPE) <= sizeof(int64_t), \ | 142 static_assert(sizeof(TYPE) <= sizeof(int64_t), \ |
| 141 "Property type must fit in 64 bits"); \ | 143 "Property type must fit in 64 bits"); \ |
| 142 namespace { \ | 144 namespace { \ |
| 143 const mus::WindowProperty<TYPE> NAME##_Value = {DEFAULT, #NAME, nullptr}; \ | 145 const mus::WindowProperty<TYPE> NAME##_Value = {DEFAULT, #NAME, nullptr}; \ |
| 144 const mus::WindowProperty<TYPE>* const NAME = &NAME##_Value; \ | 146 const mus::WindowProperty<TYPE>* const NAME = &NAME##_Value; \ |
| 145 } | 147 } |
| 146 | 148 |
| 147 #define DEFINE_OWNED_WINDOW_PROPERTY_KEY(TYPE, NAME, DEFAULT) \ | 149 #define MUS_DEFINE_OWNED_WINDOW_PROPERTY_KEY(TYPE, NAME, DEFAULT) \ |
| 148 namespace { \ | 150 namespace { \ |
| 149 void Deallocator##NAME(int64_t p) { \ | 151 void Deallocator##NAME(int64_t p) { \ |
| 150 enum { type_must_be_complete = sizeof(TYPE) }; \ | 152 enum { type_must_be_complete = sizeof(TYPE) }; \ |
| 151 delete mus::WindowPropertyCaster<TYPE*>::FromInt64(p); \ | 153 delete mus::WindowPropertyCaster<TYPE*>::FromInt64(p); \ |
| 152 } \ | 154 } \ |
| 153 const mus::WindowProperty<TYPE*> NAME##_Value = {DEFAULT, #NAME, \ | 155 const mus::WindowProperty<TYPE*> NAME##_Value = {DEFAULT, #NAME, \ |
| 154 &Deallocator##NAME}; \ | 156 &Deallocator##NAME}; \ |
| 155 } \ | 157 } \ |
| 156 const mus::WindowProperty<TYPE*>* const NAME = &NAME##_Value; | 158 const mus::WindowProperty<TYPE*>* const NAME = &NAME##_Value; |
| 157 | 159 |
| 158 #endif // COMPONENTS_MUS_PUBLIC_CPP_WINDOW_PROPERTY_H_ | 160 #endif // COMPONENTS_MUS_PUBLIC_CPP_WINDOW_PROPERTY_H_ |
| OLD | NEW |