rounded_window_targeter.cc 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. // Copyright 2021 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 "ash/utility/rounded_window_targeter.h"
  5. #include "base/check.h"
  6. #include "ui/gfx/geometry/point.h"
  7. namespace ash {
  8. RoundedWindowTargeter::RoundedWindowTargeter(int radius)
  9. : RoundedWindowTargeter(radius * 2, radius * 2, radius) {
  10. DCHECK_GT(radius, 0);
  11. DCHECK_EQ(rrectf_.GetType(), gfx::RRectF::Type::kSingle);
  12. }
  13. RoundedWindowTargeter::RoundedWindowTargeter(int width, int height, int radius)
  14. : rrectf_(0, 0, width, height, radius) {}
  15. RoundedWindowTargeter::~RoundedWindowTargeter() = default;
  16. bool RoundedWindowTargeter::EventLocationInsideBounds(
  17. aura::Window* target,
  18. const ui::LocatedEvent& event) const {
  19. gfx::Point point = ConvertEventLocationToWindowCoordinates(target, event);
  20. // Assumes a rectangle with height and width one is a point. This may match
  21. // 1px off at the bottom-right corner.
  22. // TODO(crbug/1220713): Expose SkRRect::ContainsPoint() instead.
  23. gfx::RectF rectf_point(point.x(), point.y(), 1, 1);
  24. return rrectf_.Contains(rectf_point);
  25. }
  26. } // namespace ash