Reduce the cost of the n^2 loop in collectTreeBoundaryCrossingRules

The loop inside collectTreeBoundaryCrossingRules is iterating all possible
scopes for every element which produces n^2 behavior based on the number
of ShadowRoots in your page.

Fixing the n^2 will require refactoring the way we do tree boundary crossing
rules so that instead of just storing a list of scopes we walk the ancestor
chain of the element and look for all ancestors that contain styles.

In the short term we can skip selector matching in the loop whenever we know
the rules couldn't possibly match.

This reduces the time in the root-styles.html and the reduction-2.html by
77% (from 180ms to 40ms). deep-styles.html still runs in 15ms though, and a
profile shows that the n^2 is just hammering containsIncludingShadowDOM and
resolveReprojection now. When we fix the n^2 it should hopefully fix that.

BUG=372083

Review URL: https://codereview.chromium.org/270953003

git-svn-id: svn://svn.chromium.org/blink/trunk@174436 bbb929c8-8fbe-4397-9dbb-9b2b20218538