In a recent letter (Denkov et al., Phys. Rev. Lett., vol. 100 (2008) p. 138301) we calculated theoretically the macroscopic viscous stress of steadily sheared foam/emulsion from the energy dissipated inside the transient planar films, formed between neighboring bubbles/drops in the shear flow. The model predicts that the viscous stress in these systems should be a proportional to Ca^1/2, where Ca is the capillary number and n = 1/2 is the power-law index. In the current paper we explain in detail our model and develop it further in several aspects: First, we extend the model to account for the effects of viscous friction in the curved meniscus regions, surrounding the planar films, on the dynamics of film formation and on the total viscous stress. Second, we consider the effects of surface forces (electrostatic, van der Waals, etc.) acting between the surfaces of the neighboring bubbles/drops and show that these forces could be important in emulsions, due to the relatively small thickness of emulsion films (often comparable to the range of action of the surface forces). Third, additional consideration is made for bubbles/drops exhibiting high surface viscosity, for which we demonstrate an additional contribution to the macroscopic viscous stress, created by the surface dissipation of energy. The new upgraded model predicts that the energy dissipation at the bubble/drop surface leads to power-law index n < 1/2, whereas the contribution of the surface forces leads to n > 1/2, which explains the rich variety of foam/emulsion behaviors observed upon steady shear. Various comparisons are made between model predictions and experimental results for both foams and emulsions, and a very good agreement is found.