masked_targeter_delegate.cc 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  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. #include "ui/views/masked_targeter_delegate.h"
  5. #include "third_party/skia/include/core/SkPath.h"
  6. #include "third_party/skia/include/core/SkRegion.h"
  7. #include "ui/gfx/geometry/skia_conversions.h"
  8. #include "ui/views/view.h"
  9. namespace views {
  10. bool MaskedTargeterDelegate::DoesIntersectRect(const View* target,
  11. const gfx::Rect& rect) const {
  12. // Early return if |rect| does not even intersect the rectangular bounds
  13. // of |target|.
  14. if (!ViewTargeterDelegate::DoesIntersectRect(target, rect))
  15. return false;
  16. // Early return if |mask| is not a valid hit test mask.
  17. SkPath mask;
  18. if (!GetHitTestMask(&mask))
  19. return false;
  20. // Return whether or not |rect| intersects the custom hit test mask
  21. // of |target|.
  22. SkRegion clip_region;
  23. clip_region.setRect({0, 0, target->width(), target->height()});
  24. SkRegion mask_region;
  25. return mask_region.setPath(mask, clip_region) &&
  26. mask_region.intersects(RectToSkIRect(rect));
  27. }
  28. } // namespace views