Add a misc.clamp function that will clamp a value to a given
range (it can also call a callback if clamping occurs). Use it
to clamp the progress value that was previously clamped with
a set of customized logic that can now be replaced with a more
generalized logic that can be shared.
Change-Id: I8369dbb61f73a60932d9e15c8b4d06db249ea38e