1 // Copyright 2020 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef UI_VIEWS_VIEW_UTILS_H_ 6 #define UI_VIEWS_VIEW_UTILS_H_ 7 8 #include <type_traits> 9 10 #include "ui/views/metadata/metadata_types.h" 11 #include "ui/views/view.h" 12 13 namespace views { 14 15 template <typename V> IsViewClass(View * view)16bool IsViewClass(View* view) { 17 static_assert(std::is_base_of<View, V>::value, "Only View classes supported"); 18 metadata::ClassMetaData* parent = V::MetaData(); 19 metadata::ClassMetaData* child = view->GetClassMetaData(); 20 while (child && child != parent) 21 child = child->parent_class_meta_data(); 22 return !!child; 23 } 24 25 } // namespace views 26 27 #endif // UI_VIEWS_VIEW_UTILS_H_ 28