Refactor CocoView

Refactor CocoView in issue #784.