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/views/masked_view_targeter.h"
7 #include "ui/gfx/path.h"
8 #include "ui/gfx/skia_util.h"
9 #include "ui/views/view.h"
13 MaskedViewTargeter::MaskedViewTargeter(View
* masked_view
)
14 : masked_view_(masked_view
) {
17 MaskedViewTargeter::~MaskedViewTargeter() {
20 bool MaskedViewTargeter::EventLocationInsideBounds(
21 ui::EventTarget
* target
,
22 const ui::LocatedEvent
& event
) const {
23 View
* view
= static_cast<View
*>(target
);
24 if (view
== masked_view_
) {
26 if (!GetHitTestMask(view
, &mask
))
27 return ViewTargeter::EventLocationInsideBounds(view
, event
);
29 gfx::Size size
= view
->bounds().size();
31 clip_region
.setRect(0, 0, size
.width(), size
.height());
33 gfx::RectF bounds_f
= ViewTargeter::BoundsForEvent(event
);
35 View::ConvertRectToTarget(view
->parent(), view
, &bounds_f
);
36 gfx::Rect bounds
= gfx::ToEnclosingRect(bounds_f
);
39 return mask_region
.setPath(mask
, clip_region
) &&
40 mask_region
.intersects(RectToSkIRect(bounds
));
43 return ViewTargeter::EventLocationInsideBounds(view
, event
);