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

Unified Diff: ui/aura/window_property.h

Issue 801953002: Use template specialization to generate WindowProperty code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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 side-by-side diff with in-line comments
Download patch
Index: ui/aura/window_property.h
diff --git a/ui/aura/window_property.h b/ui/aura/window_property.h
index 0b1574e4f368dcc753d773ba036fad886c87dcaa..642620f323054b001fbcc9097cb28f80a757a89a 100644
--- a/ui/aura/window_property.h
+++ b/ui/aura/window_property.h
@@ -9,8 +9,7 @@
#include "ui/aura/aura_export.h"
#include "ui/aura/window.h"
-// This header should be included by code that defines WindowProperties. It
-// should not be included by code that only gets and sets WindowProperties.
+// This header should be included by code that defines WindowProperties.
//
// To define a new WindowProperty:
//
@@ -78,41 +77,52 @@ struct WindowProperty {
Window::PropertyDeallocator deallocator;
};
-template<typename T>
-void Window::SetProperty(const WindowProperty<T>* property, T value) {
- int64 old = SetPropertyInternal(
- property,
- property->name,
- value == property->default_value ? NULL : property->deallocator,
- WindowPropertyCaster<T>::ToInt64(value),
- WindowPropertyCaster<T>::ToInt64(property->default_value));
- if (property->deallocator &&
- old != WindowPropertyCaster<T>::ToInt64(property->default_value)) {
- (*property->deallocator)(old);
- }
-}
+namespace subtle {
-template<typename T>
-T Window::GetProperty(const WindowProperty<T>* property) const {
- return WindowPropertyCaster<T>::FromInt64(GetPropertyInternal(
- property, WindowPropertyCaster<T>::ToInt64(property->default_value)));
-}
+class AURA_EXPORT PropertyHelper {
+ public:
+ template<typename T>
+ static void Set(Window* window, const WindowProperty<T>* property, T value) {
+ int64 old = window->SetPropertyInternal(
+ property,
+ property->name,
+ value == property->default_value ? NULL : property->deallocator,
+ WindowPropertyCaster<T>::ToInt64(value),
+ WindowPropertyCaster<T>::ToInt64(property->default_value));
+ if (property->deallocator &&
+ old != WindowPropertyCaster<T>::ToInt64(property->default_value)) {
+ (*property->deallocator)(old);
+ }
+ }
+ template<typename T>
+ static T Get(const Window* window, const WindowProperty<T>* property) {
+ return WindowPropertyCaster<T>::FromInt64(window->GetPropertyInternal(
+ property, WindowPropertyCaster<T>::ToInt64(property->default_value)));
+ }
+ template<typename T>
+ static void Clear(Window* window, const WindowProperty<T>* property) {
+ window->SetProperty(property, property->default_value); \
+ }
+};
-template<typename T>
-void Window::ClearProperty(const WindowProperty<T>* property) {
- SetProperty(property, property->default_value);
-}
+} // namespace subtle
} // namespace aura
// Macros to instantiate the property getter/setter template functions.
#define DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(EXPORT, T) \
- template EXPORT void aura::Window::SetProperty( \
- const aura::WindowProperty<T >*, T); \
- template EXPORT T aura::Window::GetProperty( \
- const aura::WindowProperty<T >*) const; \
- template EXPORT void aura::Window::ClearProperty( \
- const aura::WindowProperty<T >*);
+ template<> EXPORT void aura::Window::SetProperty( \
+ const aura::WindowProperty<T >* property, T value) { \
+ subtle::PropertyHelper::Set<T>(this, property, value); \
+ } \
+ template<> EXPORT T aura::Window::GetProperty( \
+ const aura::WindowProperty<T >* property) const { \
+ return subtle::PropertyHelper::Get<T>(this, property); \
+ } \
+ template<> EXPORT void aura::Window::ClearProperty( \
+ const aura::WindowProperty<T >* property) { \
+ subtle::PropertyHelper::Clear<T>(this, property); \
+ }
#define DECLARE_WINDOW_PROPERTY_TYPE(T) \
DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(, T)
« no previous file with comments | « ui/aura/window.h ('k') | ui/aura/window_unittest.cc » ('j') | ui/aura/window_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698