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

Side by Side Diff: components/mus/public/cpp/window_property.h

Issue 1462123002: views/mus: Set-up transient windows correctly. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 years, 1 month 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 unified diff | Download patch
OLDNEW
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
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 COMPILE_ASSERT(sizeof(TYPE) <= sizeof(int64_t), property_type_too_large); \ 134 COMPILE_ASSERT(sizeof(TYPE) <= sizeof(int64_t), property_type_too_large); \
133 namespace { \ 135 namespace { \
134 const mus::WindowProperty<TYPE> NAME##_Value = {DEFAULT, #NAME, nullptr}; \ 136 const mus::WindowProperty<TYPE> NAME##_Value = {DEFAULT, #NAME, nullptr}; \
135 } \ 137 } \
136 const mus::WindowProperty<TYPE>* const NAME = &NAME##_Value; 138 const mus::WindowProperty<TYPE>* const NAME = &NAME##_Value;
137 139
138 #define DEFINE_LOCAL_WINDOW_PROPERTY_KEY(TYPE, NAME, DEFAULT) \ 140 #define MUS_DEFINE_LOCAL_WINDOW_PROPERTY_KEY(TYPE, NAME, DEFAULT) \
139 COMPILE_ASSERT(sizeof(TYPE) <= sizeof(int64_t), property_type_too_large); \ 141 COMPILE_ASSERT(sizeof(TYPE) <= sizeof(int64_t), property_type_too_large); \
140 namespace { \ 142 namespace { \
141 const mus::WindowProperty<TYPE> NAME##_Value = {DEFAULT, #NAME, nullptr}; \ 143 const mus::WindowProperty<TYPE> NAME##_Value = {DEFAULT, #NAME, nullptr}; \
142 const mus::WindowProperty<TYPE>* const NAME = &NAME##_Value; \ 144 const mus::WindowProperty<TYPE>* const NAME = &NAME##_Value; \
143 } 145 }
144 146
145 #define DEFINE_OWNED_WINDOW_PROPERTY_KEY(TYPE, NAME, DEFAULT) \ 147 #define MUS_DEFINE_OWNED_WINDOW_PROPERTY_KEY(TYPE, NAME, DEFAULT) \
146 namespace { \ 148 namespace { \
147 void Deallocator##NAME(int64_t p) { \ 149 void Deallocator##NAME(int64_t p) { \
148 enum { type_must_be_complete = sizeof(TYPE) }; \ 150 enum { type_must_be_complete = sizeof(TYPE) }; \
149 delete mus::WindowPropertyCaster<TYPE*>::FromInt64(p); \ 151 delete mus::WindowPropertyCaster<TYPE*>::FromInt64(p); \
150 } \ 152 } \
151 const mus::WindowProperty<TYPE*> NAME##_Value = {DEFAULT, #NAME, \ 153 const mus::WindowProperty<TYPE*> NAME##_Value = {DEFAULT, #NAME, \
152 &Deallocator##NAME}; \ 154 &Deallocator##NAME}; \
153 } \ 155 } \
154 const mus::WindowProperty<TYPE*>* const NAME = &NAME##_Value; 156 const mus::WindowProperty<TYPE*>* const NAME = &NAME##_Value;
155 157
156 #endif // COMPONENTS_MUS_PUBLIC_CPP_WINDOW_PROPERTY_H_ 158 #endif // COMPONENTS_MUS_PUBLIC_CPP_WINDOW_PROPERTY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698