touch_action_region.cc 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright 2017 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 "cc/layers/touch_action_region.h"
  5. #include "ui/gfx/geometry/rect.h"
  6. namespace cc {
  7. TouchActionRegion::TouchActionRegion() {}
  8. TouchActionRegion::TouchActionRegion(
  9. const TouchActionRegion& touch_action_region) = default;
  10. TouchActionRegion::TouchActionRegion(TouchActionRegion&& touch_action_region) =
  11. default;
  12. TouchActionRegion::~TouchActionRegion() = default;
  13. Region TouchActionRegion::GetAllRegions() const {
  14. Region all_regions;
  15. for (const auto& pair : map_)
  16. all_regions.Union(pair.second);
  17. return all_regions;
  18. }
  19. void TouchActionRegion::Union(TouchAction touch_action, const gfx::Rect& rect) {
  20. map_[touch_action].Union(rect);
  21. }
  22. const Region& TouchActionRegion::GetRegionForTouchAction(
  23. TouchAction touch_action) const {
  24. static const Region* empty_region = new Region;
  25. auto it = map_.find(touch_action);
  26. if (it == map_.end())
  27. return *empty_region;
  28. return it->second;
  29. }
  30. TouchAction TouchActionRegion::GetAllowedTouchAction(
  31. const gfx::Point& point) const {
  32. TouchAction allowed_touch_action = TouchAction::kAuto;
  33. for (const auto& pair : map_) {
  34. if (!pair.second.Contains(point))
  35. continue;
  36. allowed_touch_action &= pair.first;
  37. }
  38. return allowed_touch_action;
  39. }
  40. TouchActionRegion& TouchActionRegion::operator=(
  41. const TouchActionRegion& other) {
  42. map_ = other.map_;
  43. return *this;
  44. }
  45. TouchActionRegion& TouchActionRegion::operator=(TouchActionRegion&& other) =
  46. default;
  47. bool TouchActionRegion::operator==(const TouchActionRegion& other) const {
  48. return map_ == other.map_;
  49. }
  50. } // namespace cc