Index: mojo/services/public/cpp/view_manager/view.h |
diff --git a/mojo/services/public/cpp/view_manager/view.h b/mojo/services/public/cpp/view_manager/view.h |
index 72f044ce0b1d6e12e266c9e986e57ef0fc6c1a75..85011ba3c4adc3527a37b0597e5b12e3e4497adf 100644 |
--- a/mojo/services/public/cpp/view_manager/view.h |
+++ b/mojo/services/public/cpp/view_manager/view.h |
@@ -23,6 +23,10 @@ class View; |
class ViewManager; |
class ViewObserver; |
+// Defined in view_property.h (which we do not include) |
+template <typename T> |
+struct ViewProperty; |
+ |
// Views are owned by the ViewManager. |
// TODO(beng): Right now, you'll have to implement a ViewObserver to track |
// destruction and NULL any pointers you have. |
@@ -49,11 +53,41 @@ class View { |
bool visible() const { return visible_; } |
void SetVisible(bool value); |
- const std::map<std::string, std::vector<uint8_t>>& properties() const { |
+ // Returns the set of string to bag of byte properties. These properties are |
+ // shared with the view manager. |
+ const std::map<std::string, std::vector<uint8_t>>& shared_properties() const { |
return properties_; |
} |
// Sets a property. If |data| is null, this property is deleted. |
- void SetProperty(const std::string& name, const std::vector<uint8_t>* data); |
+ void SetSharedProperty(const std::string& name, |
+ const std::vector<uint8_t>* data); |
+ |
+ // Sets the |value| of the given window |property|. Setting to the default |
+ // value (e.g., NULL) removes the property. The caller is responsible for the |
+ // lifetime of any object set as a property on the View. |
+ // |
+ // These properties are not visible to the view manager. |
+ template <typename T> |
+ void SetLocalProperty(const ViewProperty<T>* property, T value); |
+ |
+ // Returns the value of the given window |property|. Returns the |
+ // property-specific default value if the property was not previously set. |
+ // |
+ // These properties are only visible in the current process and are not |
+ // shared with other mojo services. |
+ template <typename T> |
+ T GetLocalProperty(const ViewProperty<T>* property) const; |
+ |
+ // Sets the |property| to its default value. Useful for avoiding a cast when |
+ // setting to NULL. |
+ // |
+ // These properties are only visible in the current process and are not |
+ // shared with other mojo services. |
+ template <typename T> |
+ void ClearLocalProperty(const ViewProperty<T>* property); |
+ |
+ // Type of a function to delete a property that this view owns. |
+ typedef void (*PropertyDeallocator)(int64 value); |
// A View is drawn if the View and all its ancestors are visible and the |
// View is attached to the root. |
@@ -101,6 +135,14 @@ class View { |
explicit View(ViewManager* manager); |
+ // Called by the public {Set,Get,Clear}Property functions. |
+ int64 SetLocalPropertyInternal(const void* key, |
+ const char* name, |
+ PropertyDeallocator deallocator, |
+ int64 value, |
+ int64 default_value); |
+ int64 GetLocalPropertyInternal(const void* key, int64 default_value) const; |
+ |
void LocalDestroy(); |
void LocalAddChild(View* child); |
void LocalRemoveChild(View* child); |
@@ -126,6 +168,17 @@ class View { |
// state. This field is only used if the view has no parent (eg it's a root). |
bool drawn_; |
+ // Value struct to keep the name and deallocator for this property. |
+ // Key cannot be used for this purpose because it can be char* or |
+ // WindowProperty<>. |
+ struct Value { |
+ const char* name; |
+ int64 value; |
+ PropertyDeallocator deallocator; |
+ }; |
+ |
+ std::map<const void*, Value> prop_map_; |
+ |
DISALLOW_COPY_AND_ASSIGN(View); |
}; |