Quantum Theory of Contact Electrification for Fluids and Solids