summaryrefslogtreecommitdiff
path: root/chromium/ui/views/view_utils.h
blob: 071c093f4588115e9ea73c0de00670f11f7cb17a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef UI_VIEWS_VIEW_UTILS_H_
#define UI_VIEWS_VIEW_UTILS_H_

#include <type_traits>

#include "ui/views/metadata/metadata_types.h"
#include "ui/views/view.h"

namespace views {

template <typename V>
bool IsViewClass(View* view) {
  static_assert(std::is_base_of<View, V>::value, "Only View classes supported");
  metadata::ClassMetaData* parent = V::MetaData();
  metadata::ClassMetaData* child = view->GetClassMetaData();
  while (child && child != parent)
    child = child->parent_class_meta_data();
  return !!child;
}

}  // namespace views

#endif  // UI_VIEWS_VIEW_UTILS_H_