The attached patch implements the above. The WindowAgg code is just my proposal from the other thread and wouldn't be part of the initial commit. Just the mechanical refactoring bits.
I've added this to Drafts and put on what I thought were relevant tags and status given that:
It only touches documentation.
I need feedback on what it does before moving forward.