Add a trait for width calculation

+ Move out and separate the width calculation code for 6 cases like: block-replaced, block-non-replaced, float-replaced, etc.
  This implements #1683
+ Use the trait to have a common min-width and max-width calculation function (This completes #783 for blocks)
+ Add reftests for the above.