Or does gravity depend on the density of the object as well?
The problem with this question is that it's rather ambiguous as to what you mean by "gravity". An object doesn't have a single number that is its "gravity". If a ship is near a star, the gravitational force that the ship feels depends on the mass of the star, the mass of the ship, and the distance between them. If we consider the acceleration, rather than the force, then we can divide out by the mass of the ship. So rather than saying "gravity", I will talk about the gravitational acceleration. We can take the mass of the star as being fixed, but that still leaves the variable of the distance between them.
So the question is whether this distance is measured from the center of the object, or from the surface of the object. If the distance is measured from the center, then gravitational acceleration does not depend on the density of the object. If the Sun were to contract and become more dense, the orbit of the Earth would not be affected.
However, the less dense the object is (for a fixed mass), the further the surface will be from the center. So decreasing the density of an object decreases its surface gravitational acceleration. If the Earth were to expand in volume, but not increase in mass, then the gravitational acceleration at its new surface would be lower.
Also, it's more the escape velocity, rather than the gravitational acceleration, that determines whether something is a black hole. However, the escape velocity follows the same pattern as gravitational acceleration: the escape velocity relative to the center of an object does not depend on the density, but the surface escape velocity does. As a star collapses, its surface escape velocity increases, and once the surface escape velocity reaches the speed of light, it is a black hole.