The RazorPanel::calculatePopupWindowPos function handles the situation when the window is out of the screen.