summaryrefslogtreecommitdiffstats
path: root/components/mus/view_locator.cc
blob: 40cda4e84d7a98ded7e5a5d40e5688b46ecc13c8 (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
28
29
30
31
32
33
34
35
// Copyright 2015 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.

#include "components/mus/view_locator.h"

#include "components/mus/server_view.h"

namespace mus {

const ServerView* FindDeepestVisibleView(const ServerView* view,
                                         const gfx::Point& location) {
  for (const ServerView* child : view->GetChildren()) {
    if (!child->visible())
      continue;

    // TODO(sky): support transform.
    const gfx::Point child_location(location.x() - child->bounds().x(),
                                    location.y() - child->bounds().y());
    if (child_location.x() >= 0 && child_location.y() >= 0 &&
        child_location.x() < child->bounds().width() &&
        child_location.y() < child->bounds().height()) {
      return FindDeepestVisibleView(child, child_location);
    }
  }
  return view;
}

ServerView* FindDeepestVisibleView(ServerView* view,
                                   const gfx::Point& location) {
  return const_cast<ServerView*>(
      FindDeepestVisibleView(const_cast<const ServerView*>(view), location));
}

}  // namespace mus