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