Fix tooltip positioning near screen edges (#12870)

Change-Id: I3f5244565dd393e9fcb7386d352f835b5afd9faa