There is no "right" answer. The speaker can use "this", "that", or "it". The speaker decides which word to use based on how he thinks about the hat. If he thinks of the hat as being somehow "close" to himself, he would say "this hat". If he thinks of the hat as further away (such as on the other side of the room), he might say "that". "It" is more neutral and can always be used.