Emit cancel events when clicking on close button, or when pressing esc key.