Robert Baratheon was descended from Princess Rhaelle Targaryen, a daughter of King Aegon V (That makes her Aerys II's aunt).
That is of course if you reject the rumors that founder of house Baratheon, Orys Baratheon was actually a bastard brother of Aegon I Targaryen, making Baratheons an unacknowledged cadet dynasty of House Targaryen. It has been confirmed in Fire & Blood that Orys Baratheon was indeed a dragonseed and Bastard son of Lord Aenar Targaryen, making him half brother of Aegon, Visenya and Rhaenys.)
She married Lord Ormund Baratheon and the couple had a son Steffon Baratheon. Steffon is the father of Robert, Renly and Stannis Baratheon. So that makes Robert and Rhaegar cousins of sorts (Rhaegar is reported to have referred to Robert as "Our cousin Robert").
That's how Baratheons presented an alternate leadership for those who resented the chaotic rule of Aerys II Targaryen, as they were the only ones who had a claim by blood on Iron Throne outside the Targaryen dynasty.
Given the tragedy of Summerhall which result in deaths of many members of House Targaryen, the family tree was reduced to one lonely Branch of then Prince (and later King) Jaehaerys Targaryen. Jaehaerys had only two children:
- Prince Aerys (Later King Aerys II, the mad King. Also as Jayraj pointed out, in the show, he's son of King Aegon V, not his grandson through king Jaehaerys)
- Princess Rhaella
The two were already married before the time of Tragedy of Summerhall, Princess Rhaella was in fact actually in labour when the palace burnt down (The Royal family had gathered there on pretext of celebrating birth of her child). She gave birth to her first-born son Rhaegar out there while rest of the Targaryens burnt inside including King Aegon V and his eldest son Prince Duncan.
So now you understand that despite being a very old dynasty, why were there no other Targaryen claimants than Viserys and Daenerys when the Show started.
How did he become King?
He actually did not harbor any intention of rebelling until King Aerys issued orders for his and Eddard Stark's death. Lord Arryn, their foster-parent, refused to carry out those orders and called his banners instead. Since among the Rebels, only House Baratheon had a claim on the throne1, Robert became the leader.
They did not choose the existing Targaryen claimants because:
- Prince Rhaegar was unlikely to forgive and forget the Rebels in case of their success given that Aerys was his father. The Prince was splendid but they had to consider notorious Targaryen madness as well. Even Aerys II wasn't always mad, his early reign started with splendor (Although mostly because of Tywin Lannister's brilliance).
- Prince Viserys was a child who was known to have erratic behavior.
- Prince Aegon, Rhaegar's son, was a toddler. There was no way to tell which way he would have swung.
- Princess Rhaenys, Rhaegar's daughter, was well a daughter. Since the Targaryen civil war between son and daughter of King Viserys I, it was a de-facto practice of Westeros that women shouldn't be allowed to take the Iron throne.
- Queen Consort Rhaella, was a timid woman who had the same flaw as her granddaughter; her gender.
- Princess Daenerys was not even born at that time. She was in her Mum's womb.
So the war began and eventually the Rebels prevailed. Tywin Lannister basically decided the big question that whether they should have another Targaryen King by Killing Prince Aegon and Princess Rhaenys. Rhaegar had already died. Rhaella fled with Viserys and then died herself while giving birth to Daenerys.
So it was Robert who took the throne and ordered Stannis to capture last Targaryens (Which he failed to do).
That is a subjective thing. There are people in Westeros who still call Baratheons usurpers. Then there are people who have moved on and consider them the real authority. And then there are people who want to be the royal authority themselves.
Who is the legal heir?
Again, legitimacy is subjective. This is what GRRM has to say about succession laws:
"The short answer is that the laws of inheritance in the Seven
Kingdoms are modelled on those in real medieval history... which is to
say, they were vague, uncodified, subject to varying interpretations,
and often contradictory."
But considering that there was no Kingdom of Westeros or Iron throne before Aegon the Conqueror forged it in fire and blood, let's consider the Targaryens to be the only real heirs.
Given that assumption, Daenerys would be on top of the list as sole Targaryen.
Jon Snow doesn't know about his Targaryen heritage. He is a bastard (Secretly Legitimate according to Show canon) as far as people are concerned as of now and therefore barred from inheriting titles as per laws of the land. D&D however care naught for the laws and made him King in the North anyways.
Since Jon is King for some reason, if he realizes his ancestry, he can formally remove the taint of bastardy from himself and take the Targaryen name (Book canon - As per the Show he is already Trueborn), shall he wish to do so. If he does that (Doesn't need to as per the show), he becomes the sole surviving male Targaryen and therefore becomes the heir, bypassing Daenerys. But Daenerys has dragons so she can burn his position in line of succession anytime.
Or alternatively they could marry and Jon could become King Consort (Because Dragons make Daenerys the Queen, not Queen consort) and take title of "Protector of the Realm" like Prince Daemon did when he married self-proclaimed Queen Rhaenyra Targaryen.
1. The Baratheons had a bloodline claim. Given the low number of Targaryens, they were in line of primogeniture succession regardless to their distant descent from King Aegon V. The Agnatic Primogeniture line in Days of Aerys II would have been Rhaegar -> Aegon -> Viserys -> Robert -> Stannis -> Renly
I have answered a number of relevant questions previously. If you are interested you can take a look at:
- Can Cersei Lannister take the throne legally?
- The bastard status of Jon
- Gendry and Lordship of House baratheon
- Legitimization and Jon
- Tangible proof of Jon's parentage
- Targaryens and creation of the Iron Throne