As the text states, ATP is generated by a proton gradient in the membrane. In the case of respiration, this gradient generates ATP in the inner membrane of the mitochondrion, while in photosynthesis, the process occurs in the thylakoid membrane.
In terms of structure, the most central part of the mitochondrion is called the mitochondrial matrix, where the Krebs cycle takes place, while inside the chloroplast are the thylakoids, which are surrounded by the stroma, where the Calvin cycle takes place.
Therefore, the answers would be in the following order:
1. thylakoid
2. mitochondrion
3. stroma
4. matrix