Mechanisms for armrests and headrests