Bug 1473376: Ensure hit test regions never grow excessively complex. r=kats draft
authorBas Schouten <bschouten@mozilla.com>
Wed, 04 Jul 2018 18:52:10 +0000
changeset 814210 72aa2252e1eb8aead0b14bb7ff91e171f80e2913
parent 814209 0550477d1cdff62dab4bb1bab11283b32890ea78
push id115131
push userbschouten@mozilla.com
push dateWed, 04 Jul 2018 19:07:01 +0000
reviewerskats
bugs1473376
milestone63.0a1
Bug 1473376: Ensure hit test regions never grow excessively complex. r=kats MozReview-Commit-ID: JpkdVSPbeAI
layout/base/nsLayoutUtils.cpp
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -9466,16 +9466,26 @@ nsLayoutUtils::TransformToAncestorAndCom
       if (aClip->GetRoundedRectCount() > 0) {
         isPrecise = false;
       }
     }
     transformedRegion.OrWith(transformed);
   }
   nsRegion* dest = isPrecise ? aPreciseTargetDest : aImpreciseTargetDest;
   dest->OrWith(transformedRegion.ToRegion());
+  // If the region becomes too complex this has a large performance impact.
+  // We limit its complexity here.
+  if (dest->GetNumRects() > 12) {
+    dest->SimplifyOutward(6);
+    if (isPrecise) {
+      aPreciseTargetDest->OrWith(*aImpreciseTargetDest);
+      *aImpreciseTargetDest = std::move(*aPreciseTargetDest);
+      *aPreciseTargetDest = nsRegion();
+    }
+  }
 }
 
 /* static */ bool
 nsLayoutUtils::ShouldUseNoScriptSheet(nsIDocument* aDocument)
 {
   // also handle the case where print is done from print preview
   // see bug #342439 for more details
   if (aDocument->IsStaticDocument()) {