The ecological basis of coevolutionary history