1a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
2a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// found in the LICENSE file.
4a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
5116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "ui/views/masked_targeter_delegate.h"
6116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
7a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/gfx/path.h"
8a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/gfx/skia_util.h"
9a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/views/view.h"
10a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
11a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)namespace views {
12a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
13a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)bool MaskedTargeterDelegate::DoesIntersectRect(const View* target,
14a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                                               const gfx::Rect& rect) const {
15a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Early return if |rect| does not even intersect the rectangular bounds
16a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // of |target|.
17116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  if (!ViewTargeterDelegate::DoesIntersectRect(target, rect))
18    return false;
19
20  // Early return if |mask| is not a valid hit test mask.
21  gfx::Path mask;
22  if (!GetHitTestMask(&mask))
23    return false;
24
25  // Return whether or not |rect| intersects the custom hit test mask
26  // of |target|.
27  SkRegion clip_region;
28  clip_region.setRect(0, 0, target->width(), target->height());
29  SkRegion mask_region;
30  return mask_region.setPath(mask, clip_region) &&
31         mask_region.intersects(RectToSkIRect(rect));
32}
33
34}  // namespace views
35