Prevent text selection divs from overflowing page boundries

This fixes [bug 837462](https://bugzilla.mozilla.org/show_bug.cgi?id=837462).