[Android] Implement 3-way sensor fallback for Device Orientation.
[chromium-blink-merge.git] / ui / wm / core / masked_window_targeter.cc
blob74e8bc8a7c1fad5ad21a00b1d484e70aa415f215
1 // Copyright 2014 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.
5 #include "ui/wm/core/masked_window_targeter.h"
7 #include "ui/aura/window.h"
8 #include "ui/events/event.h"
9 #include "ui/gfx/path.h"
11 namespace wm {
13 MaskedWindowTargeter::MaskedWindowTargeter(aura::Window* masked_window)
14 : masked_window_(masked_window) {
17 MaskedWindowTargeter::~MaskedWindowTargeter() {}
19 bool MaskedWindowTargeter::EventLocationInsideBounds(
20 aura::Window* window,
21 const ui::LocatedEvent& event) const {
22 if (window == masked_window_) {
23 gfx::Path mask;
24 if (!GetHitTestMask(window, &mask))
25 return WindowTargeter::EventLocationInsideBounds(window, event);
27 gfx::Size size = window->bounds().size();
28 SkRegion clip_region;
29 clip_region.setRect(0, 0, size.width(), size.height());
31 gfx::Point point = event.location();
32 if (window->parent())
33 aura::Window::ConvertPointToTarget(window->parent(), window, &point);
35 SkRegion mask_region;
36 return mask_region.setPath(mask, clip_region) &&
37 mask_region.contains(point.x(), point.y());
40 return WindowTargeter::EventLocationInsideBounds(window, event);
43 } // namespace wm