First-principles identification of the charge-shifting mechanism and ferroelectricity in hybrid halide perovskites