99.9% of the work was done by KHTML. All apple did was submit a few patches many of them poorly document and have since been reverted. Apple does not know how to work well with the open source communities and caused a big issue which is why it forked.
That's disingenuous, Apple needed to fork KHTML to abstract it, removing any QT and KDE specific code to make it completely platform-agnostic. They also have made substantial code contributions, to the point Konqueror considered adopting Webkit, and has since been been integrated into QT and is now an alternate rendering engine in Konqueror. While Apple's relationship with the opensource community was strained at first, with the forked code being made available in one big lump back to KHTML, which made it difficult to merge, they have since worked out their differences. Numerous opensource projects, as well as commercial ones, have adopted Webkit over KHTML because it is already abstracted and universally adopted and supported by websites. As for opensource in general, remember that Darwin, the OSX core, is opensource and synchronised with FreeBSD. They have developed several opensource projects, mostly under-the-hood Unix tools or protocols, some adapted from previous opensource projects, some new. Clang is a major project which affects numerous Unix variants, it is adopted by FreeBSDs as their new compiler.
As to the original question, while largely answered; Apple didn't want to be reliant on Microsoft or any other company for something as increasingly crucial as a web browser, especially not seeing how Microsoft had been neglecting it, and had plans to axe it altogether; it made for a bad user experience for people considering adopting Macs. Microsoft also used it (as well as Office) as leverage against Apple in the lead-up. It was a sore point for Steve Jobs.
Morever, just as IE's underlying engine supply systemwide services, Webkit
is crucial to providing the same OS-integrated services on Macs which no 3rd party browser can, used in things like Preview and Mail and now iTunes and the Mac App store. It also enables 3rd party software developers like Adium to use it.
As for the Windows port, I believe it had as much to do with providing an implementation for largely Windows-based web developers to test against, versus them simply ignoring it, since at the time lots of websites had various rendering issues. It also brought Webkit to Windows. Now of course Adobe has adopted Webkit in Dreamweaver and Air on both platforms.