Move grid checking into the layout algorithm.
am: 26f637b555

Change-Id: Ie65d71bd7f6edb5e92f6dd331999424a592c8073