Commit def30295 authored by Wei Li's avatar Wei Li Committed by Commit Bot

Views: Support property getter func to return const ref

Make the return type of property metadata's getter function to be more
flexible so that both returning a value and returning a constant
reference of that value are allowed.

Also, convert ImageViewBase's accessible_name to a property as an
example of such usage.

BUG=938501,957272

Change-Id: I8d6adeb9392b06be948b9fcf727b408661791f1a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1615380Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarAllen Bauer <kylixrd@chromium.org>
Commit-Queue: Wei Li <weili@chromium.org>
Cr-Commit-Position: refs/heads/master@{#660883}
parent 911726ec
......@@ -61,7 +61,11 @@ ImageViewBase::Alignment ImageViewBase::GetVerticalAlignment() const {
}
void ImageViewBase::SetAccessibleName(const base::string16& accessible_name) {
if (accessible_name_ == accessible_name)
return;
accessible_name_ = accessible_name;
OnPropertyChanged(&accessible_name_, kPropertyEffectsNone);
}
const base::string16& ImageViewBase::GetAccessibleName() const {
......@@ -153,6 +157,7 @@ BEGIN_METADATA(ImageViewBase)
METADATA_PARENT_CLASS(View)
ADD_PROPERTY_METADATA(ImageViewBase, Alignment, HorizontalAlignment)
ADD_PROPERTY_METADATA(ImageViewBase, Alignment, VerticalAlignment)
ADD_PROPERTY_METADATA(ImageViewBase, base::string16, AccessibleName)
END_METADATA()
} // namespace views
......@@ -5,6 +5,8 @@
#ifndef UI_VIEWS_METADATA_METADATA_MACROS_INTERNAL_H_
#define UI_VIEWS_METADATA_METADATA_MACROS_INTERNAL_H_
#include <utility>
#include "base/compiler_specific.h"
#include "ui/views/metadata/metadata_types.h"
......@@ -33,15 +35,18 @@
DISALLOW_COPY_AND_ASSIGN(METADATA_CLASS_NAME_INTERNAL(class_name)); \
}
#define METADATA_PROPERTY_TYPE_INTERNAL(class_name, property_type, \
property_name) \
views::metadata::ClassPropertyMetaData<class_name, property_type, \
&class_name::Set##property_name, \
&class_name::Get##property_name>
#define METADATA_PROPERTY_TYPE_INTERNAL(class_name, property_type, \
property_name) \
views::metadata::ClassPropertyMetaData< \
class_name, property_type, &class_name::Set##property_name, \
decltype(std::declval<class_name>().Get##property_name()), \
&class_name::Get##property_name>
#define METADATA_READONLY_PROPERTY_TYPE_INTERNAL(class_name, property_type, \
property_name) \
views::metadata::ClassPropertyReadOnlyMetaData< \
class_name, property_type, &class_name::Get##property_name>
class_name, property_type, \
decltype(std::declval<class_name>().Get##property_name()), \
&class_name::Get##property_name>
#endif // UI_VIEWS_METADATA_METADATA_MACROS_INTERNAL_H_
......@@ -19,7 +19,12 @@ namespace metadata {
// Represents meta data for a specific read-only property member of class
// |TClass|, with underlying type |TValue|, as the type of the actual member.
template <typename TClass, typename TValue, TValue (TClass::*Get)() const>
// Using a separate |TRet| type for the getter function's return type to allow
// it to return a type with qualifier and by reference.
template <typename TClass,
typename TValue,
typename TRet,
TRet (TClass::*Get)() const>
class ClassPropertyReadOnlyMetaData : public MemberMetaDataBase {
public:
ClassPropertyReadOnlyMetaData() {}
......@@ -45,9 +50,10 @@ class ClassPropertyReadOnlyMetaData : public MemberMetaDataBase {
template <typename TClass,
typename TValue,
void (TClass::*Set)(ArgType<TValue>),
TValue (TClass::*Get)() const>
typename TRet,
TRet (TClass::*Get)() const>
class ClassPropertyMetaData
: public ClassPropertyReadOnlyMetaData<TClass, TValue, Get> {
: public ClassPropertyReadOnlyMetaData<TClass, TValue, TRet, Get> {
public:
ClassPropertyMetaData() {}
~ClassPropertyMetaData() override = default;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment