It does a little of everything. Mostly it's building an estimation model for how much charge is left based on how much current is used, how much current goes in, temperature, etc. It's not a simple calculation based on internal resistance, voltage, current, etc. It's constantly monitoring what the battery is doing to determine how much estimated charge is left.
There are a lot of little things that go into calculating how much estimated charge there is, as well as estimating what the remaining capacity is. It can be off sometimes, which is why some people with older batteries see a sudden jump in charge level.