| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "ui/views/masked_view_targeter.h" | |
| 6 | |
| 7 #include "ui/gfx/path.h" | |
| 8 #include "ui/gfx/skia_util.h" | |
| 9 #include "ui/views/view.h" | |
| 10 | |
| 11 namespace views { | |
| 12 | |
| 13 MaskedViewTargeter::MaskedViewTargeter(View* masked_view) | |
| 14 : masked_view_(masked_view) { | |
| 15 } | |
| 16 | |
| 17 MaskedViewTargeter::~MaskedViewTargeter() { | |
| 18 } | |
| 19 | |
| 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_) { | |
| 25 gfx::Path mask; | |
| 26 if (!GetHitTestMask(view, &mask)) | |
| 27 return ViewTargeter::EventLocationInsideBounds(view, event); | |
| 28 | |
| 29 gfx::Size size = view->bounds().size(); | |
| 30 SkRegion clip_region; | |
| 31 clip_region.setRect(0, 0, size.width(), size.height()); | |
| 32 | |
| 33 gfx::RectF bounds_f = ViewTargeter::BoundsForEvent(event); | |
| 34 if (view->parent()) | |
| 35 View::ConvertRectToTarget(view->parent(), view, &bounds_f); | |
| 36 gfx::Rect bounds = gfx::ToEnclosingRect(bounds_f); | |
| 37 | |
| 38 SkRegion mask_region; | |
| 39 return mask_region.setPath(mask, clip_region) && | |
| 40 mask_region.intersects(RectToSkIRect(bounds)); | |
| 41 } | |
| 42 | |
| 43 return ViewTargeter::EventLocationInsideBounds(view, event); | |
| 44 } | |
| 45 | |
| 46 } // namespace views | |
| OLD | NEW |