Fixed and simplified handling of touch gestures.

Change-Id: I73712d2b741d12ba57036029bea9012c81951ccb