The coloring is certainly attractive, and now is done mainly as decoration, but casehardening was originally used to harden the outer layer of ferrous metal by driving more carbon into it under high heat while leaving a softer inner core, desirable for "toughness" in tools, guns, etc. made back before tool steels and such were developed. The item is packed in a container with charcoal and bone (in the case of firearms), the whole thing is heated to something like 1300 degrees, then quickly quenched, usually in oil. True color-casehardening is a pretty involved process. Here's a couple of links if you care to know more. Turnbull is considered an artist for his color case-hardening and gun restoration skills:
A closer look at the function and fashion of various heat treatments, carburizing and color case hardening methods.
uplandguncompany.com
Turnbull Restoration has played a pivotal role in preserving and perfecting this traditional metal finish and others over the last 40 years.
www.turnbullrestoration.com
As
@heimannm pointed out, gun bluing or browning is a completely different process, whose purpose is to provide a protective layer on the steel. A good bluing job is certainly attractive, but the appearance was not the primary purpose originally.
Probably more than you wanted to know (sorry), but well-made tools like guns and chainsaws have always fascinated me, and some of my interest lies in all the many side details.