The full title of the UK is "Her Majesty's United Kingdom of Great Britain and Northern Ireland". The countries/nations included in it are England, Wales, Scotland and Northern Ireland.
While not a part of the United Kingdom, the states in the Channel Islands (such as Guernsey, Jersey and Alderney) and the Isle of Man are Crown Dependencies and are closely associated with the UK. The citizens of these places are full British citizens, but not EU citizens, as these places are outside the European Union.
Booklet AN (Pages 4 & 5) does specify that you need to have been resident in "England, Wales, Scotland, Northern Ireland, the Isle of Man or the Channel Islands" at the beginning of the 5 year or 3 year qualifying period for citizenship. It then continues with the appearance of using "the United Kingdom" as short form for these places.
Gibralter is an Overseas Territory of the United Kingdom. Till recently (2002), they had a separate citizenship-British Overseas Territories citizenship(BOTC)-and a BOTC citizen had to go through the same hoops as a non-EEA citizen to settle in the UK. In 2002, all BOTC citizens were made full British citizens in addition to their BOTC citizenships.
However, if you met the conditions for citizenship in Gibraltar, the Gibraltar government (not the UK Home Office) would be responsible for your citizenship and would grant you a BOTC with Gibraltarian belonger status. You would then have to register to become a British citizen.
Gibraltar is not a part of the UK for immigration purposes. For instance, non-EEA citizens with a UK work permit or PBS visa need a separate visa to visit Gibraltar.
Therefore I believe that you can not use your stay in Gibraltar for the purposes of naturalisation.
As an aside, the British practice is unlike that of France, where Reunion, French Polynesia, New Caledonia and St Pierre and Miquelon are fully a part of the French Republic, on par with the Metropole. Likewise, Ceuta, Melilla and the Canary Islands are fully part of Spain.
Conversely, I believe that Dutch & Danish practice is similar to that of the UK in treating their overseas countries (the Caribbean Netherlands in case of the former & Greenland and the Faroe Islands in case of the latter) as separate immigration jurisdictions.