Aragorn's rights as the Heir of Elendil and the Heir of Isildur were not exactly identical. Isildur was the only king to rule both Arnor and Gondor directly (although there is some evidence that Elendil may have been involved in Gondor -- such as his conferring the title of "prince" upon Imrahil's ancestors). When Isildur died his lordship over the Dunedain of the North and of the South did not exactly die with him, but it sort of passed into a state of limbo. There were High Kings after Isildur but these kings appear to have little if any actual authority over Gondor, and when the sons of Earendur divided Arnor between them, the High Kingship was effectively ended forever (Aragorn did not become High King, but simply King of the Reunited Realm).
When Arvedui claimed the throne of Gondor he presented his claim as the Heir of Isildur first. The Council of Gondor (led then by the Steward Pelendur) rejected his claim, and that rejection effectively LEGALLY barred Isildur's line from reasserting their royalty in Gondor. But Arvedui responded by asserting his right as the Heir of Elendil, and this time the Council of Gondor made no response, effectively leaving open the issue of whether a northern Heir of Elendil could claim the throne.
The crown was then given to Earnil, the victorious captain who had led Gondor's armies in war and saved the kingdom. He was a male line descendant of Anarion but there is some question of whether he was the most senior male line descendant in his time. Tolkien seems to imply there were other members of the House of Anarion who were not as pure of blood as Earnil and his son Earnur.
It has been argued (though not convincingly in my opinion) that the royalty of Gondor persisted with the House of Anarion until that House was no more. By the time of the War of the Ring, it seems clear that there were no more descendants of Anarion (of the male line, at least) in Gondor. Hence, the argument goes, the royalty of Gondor reverted to the House of Isildur. But the Isildurians had been rejected by the Council of Gondor, so by Gondorian law they could not be kings. And yet the kingship belonged rightfully only to the House of Elendil. This is why the Stewards never took the kingship upon themselves. Tolkien says that some people still remembered the northern line and hoped that a king would come from it some day, so the Stewards could not have been anything more than usurpers if they had tried to take the throne for themselves.
Now, my feeling on the issue is that no matter what Aragorn's rights were, Gondor would not have accepted someone who hadn't led her armies in war. Earnil II had established that precedent. i.e., the status of being a victorious captain was sufficient to elevate his claim above all others.
Aragorn's appearance was foretold, by Malbeth at least. The ancient Seer had foreseen that an Heir of Isildur would return to command the Oathbreakers who had been cursed by Isildur. And the portents Fat Middle listed are legitimate. A definite sign of the return of Gondor's royalty was in the air, so to speak. But the choice to accept the king was still Gondor's.
When Aragorn's identity was made known to Boromir in Rivendell, Aragorn asked him if Gondor wished for the House of Elendil to return. Aragorn was later on careful to present himself as Elendil's Heir to the Rohirrim, and though he had to march through Gondor as the Heir of Isildur (to command the Dead), he displayed the "tokens of Elendil's house" (according to Eomer) in the Battle of the Pelennor Fields.
It has been pointed out that both Faramir and Imrahil acknowledged Aragorn as their rightful king after the battle. Of course, Imrahil knew by this time that Denethor was dead and that Aragorn had led a Gondorian army in battle. Aragorn would have satisfied all the previous criteria for claimants to the throne, except coming from the House of Anarion (Aragorn's descent from Firiel, daughter of King Ondoher, didn't qualify him for the kingship). Faramir awoke from a nightmarish coma or sleep induced by the Black Breath and immediately hailed Aragorn as king, though he knew nothing of how the battle had gone or his father's death.
In response to the point about Faramir, I note that the narrative says "a light of knowledge and love was kindled in his eyes". Faramir had already heard of Aragorn from Frodo, and he had had plenty of time to ponder all the signs. Sauron's war was going to be the final assault against Gondor -- who could understand this better than Faramir, who had been monitoring the passage of Gondor's enemies through Ithilien? If the House of Elendil was going to make a return, now was the time. And he seems to have been given a gift of knowledge and understanding (by Iluvatar or the Valar, it doesn't really matter).
I think Faramir's declaration was intuitive, and if he had made it while his father was alive it would have placed him squarely in defiance of his father.
The political situation in Gondor would have become tense, and Aragorn acknowledged this before he entered Minas Tirith. That was why he had his banner furled and he declared himself to be simply a captain of the Rangers of the North. Later, when Imrahil learned that Faramir was become Steward (from Gandalf, in front of the Houses of Healing), he asked who should rule the City, and if they shouldn't send for Aragorn. Once again Aragorn declined to assert his right, and he suggested that Imrahil should rule the City. Aragorn's stated purpose was to avoid strife among Sauron's enemies.
By the time the Army of the West had set out and was marching through Ithilien Imrahil had heard Faramir's declaration and the situation in Minas Tirith was more secure and orderly. So he had the heralds proclaim the coming of the King Elessar, effectively ending all doubt about Aragorn's status. But by then many of Gondor's people had already "thrown in" with Aragorn by marching under his standard. He had arrived in Gondor as the unacknowledged king de jure (by right) and was now the de facto king, but he didn't yet rule Gondor (Faramir was still the Ruling Steward). Aragorn was proclaimed King of Gondor (given the throne) after the final battle with Sauron.
Had Denethor lived I think he would have been expected by many to step down. But there is the question of whether the Army of the West would or should have marched at all if Denethor had lived. Tolkien originally did not have Denethor kill himself during the battle, and the confrontation between the Ruling Steward and Aragorn after the Battle of the Pelennor Fields strikes me as being very unlike the way Tolkien finally chose to portray Aragorn. In "The Tale of Aragorn and Arwen" Elrond told Aragorn he would have to earn the Sceptre of Annuminas. I think by extension he had to earn the Crown of Gondor. Both were his by right, but they were being held in trust for an Heir of Elendil who would prove himself worthy.