Refactoring the code to calculate the frame of popover.