| 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 "sky/engine/config.h" | |
| 6 #include "sky/engine/core/html/canvas/HitRegion.h" | |
| 7 | |
| 8 #include "sky/engine/core/rendering/RenderBoxModelObject.h" | |
| 9 | |
| 10 namespace blink { | |
| 11 | |
| 12 HitRegion::HitRegion(const HitRegionOptions& options) | |
| 13 : m_id(options.id) | |
| 14 , m_control(options.control) | |
| 15 , m_path(options.path) | |
| 16 , m_fillRule(options.fillRule) | |
| 17 { | |
| 18 } | |
| 19 | |
| 20 void HitRegion::updateAccessibility(Element* canvas) | |
| 21 { | |
| 22 } | |
| 23 | |
| 24 bool HitRegion::contains(const LayoutPoint& point) const | |
| 25 { | |
| 26 return m_path.contains(point, m_fillRule); | |
| 27 } | |
| 28 | |
| 29 void HitRegion::removePixels(const Path& clearArea) | |
| 30 { | |
| 31 m_path.subtractPath(clearArea); | |
| 32 } | |
| 33 | |
| 34 void HitRegionManager::addHitRegion(PassRefPtr<HitRegion> passHitRegion) | |
| 35 { | |
| 36 RefPtr<HitRegion> hitRegion = passHitRegion; | |
| 37 | |
| 38 m_hitRegionList.add(hitRegion); | |
| 39 | |
| 40 if (!hitRegion->id().isEmpty()) | |
| 41 m_hitRegionIdMap.set(hitRegion->id(), hitRegion); | |
| 42 | |
| 43 if (hitRegion->control()) | |
| 44 m_hitRegionControlMap.set(hitRegion->control(), hitRegion); | |
| 45 } | |
| 46 | |
| 47 void HitRegionManager::removeHitRegion(HitRegion* hitRegion) | |
| 48 { | |
| 49 if (!hitRegion) | |
| 50 return; | |
| 51 | |
| 52 if (!hitRegion->id().isEmpty()) | |
| 53 m_hitRegionIdMap.remove(hitRegion->id()); | |
| 54 | |
| 55 if (hitRegion->control()) | |
| 56 m_hitRegionControlMap.remove(hitRegion->control()); | |
| 57 | |
| 58 m_hitRegionList.remove(hitRegion); | |
| 59 } | |
| 60 | |
| 61 void HitRegionManager::removeHitRegionById(const String& id) | |
| 62 { | |
| 63 if (!id.isEmpty()) | |
| 64 removeHitRegion(getHitRegionById(id)); | |
| 65 } | |
| 66 | |
| 67 void HitRegionManager::removeHitRegionByControl(Element* control) | |
| 68 { | |
| 69 removeHitRegion(getHitRegionByControl(control)); | |
| 70 } | |
| 71 | |
| 72 void HitRegionManager::removeHitRegionsInRect(const FloatRect& rect, const Affin
eTransform& ctm) | |
| 73 { | |
| 74 Path clearArea; | |
| 75 clearArea.addRect(rect); | |
| 76 clearArea.transform(ctm); | |
| 77 | |
| 78 HitRegionIterator itEnd = m_hitRegionList.rend(); | |
| 79 HitRegionList toBeRemoved; | |
| 80 | |
| 81 for (HitRegionIterator it = m_hitRegionList.rbegin(); it != itEnd; ++it) { | |
| 82 RefPtr<HitRegion> hitRegion = *it; | |
| 83 hitRegion->removePixels(clearArea); | |
| 84 if (hitRegion->path().isEmpty()) | |
| 85 toBeRemoved.add(hitRegion); | |
| 86 } | |
| 87 | |
| 88 itEnd = toBeRemoved.rend(); | |
| 89 for (HitRegionIterator it = toBeRemoved.rbegin(); it != itEnd; ++it) | |
| 90 removeHitRegion(it->get()); | |
| 91 } | |
| 92 | |
| 93 void HitRegionManager::removeAllHitRegions() | |
| 94 { | |
| 95 m_hitRegionList.clear(); | |
| 96 m_hitRegionIdMap.clear(); | |
| 97 m_hitRegionControlMap.clear(); | |
| 98 } | |
| 99 | |
| 100 HitRegion* HitRegionManager::getHitRegionById(const String& id) const | |
| 101 { | |
| 102 return m_hitRegionIdMap.get(id); | |
| 103 } | |
| 104 | |
| 105 HitRegion* HitRegionManager::getHitRegionByControl(Element* control) const | |
| 106 { | |
| 107 if (control) | |
| 108 return m_hitRegionControlMap.get(control); | |
| 109 | |
| 110 return 0; | |
| 111 } | |
| 112 | |
| 113 HitRegion* HitRegionManager::getHitRegionAtPoint(const LayoutPoint& point) const | |
| 114 { | |
| 115 HitRegionIterator itEnd = m_hitRegionList.rend(); | |
| 116 | |
| 117 for (HitRegionIterator it = m_hitRegionList.rbegin(); it != itEnd; ++it) { | |
| 118 RefPtr<HitRegion> hitRegion = *it; | |
| 119 if (hitRegion->contains(point)) | |
| 120 return hitRegion.get(); | |
| 121 } | |
| 122 | |
| 123 return 0; | |
| 124 } | |
| 125 | |
| 126 unsigned HitRegionManager::getHitRegionsCount() const | |
| 127 { | |
| 128 return m_hitRegionList.size(); | |
| 129 } | |
| 130 | |
| 131 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(HitRegionManager) | |
| 132 | |
| 133 } // namespace blink | |
| OLD | NEW |