Other Swedes might not agree and the distinction between these are not very clear, but I’ll give you my view which I think many would agree with. But as you’ll see the ”kex/kaka” distinction can be vague.
Then we have kex which is close to the second sense of kaka but kex are often not sweet and can be closer in meaning to cracker, such as this or this. However, I think it’s important that they contain wafers, because a popular type of chocolate bar is called kexchoklad and they look like this.
Wow, that was an exhaustive answer! :) But I have to say that now I am really confused, because the words are so near the Finnish equivalents, but the meanings are in some cases totally different. For example 'kakku' (kaka) is never biscuitlike (the last two examples in kaka paragraph), it would be called 'keksi' (kex). The green thing you call 'tårta' would be called '(prinsessa)kakku', whereas this would be called '(kääre)torttu' (tårta). Now I just wonder which one is which på finlandssvenska? (I have yet to recover from different meanings of 'semla', but that's another story...)
Again a small difference in rikssvenska and finlandssvenska. :D In finlandssvenska "en kaka" means a cake, not a cookie or biscuit. "Ett kex" on the other hand means a cookie or cracker, sweet or salty. And "tårta" would be a suitable word for almost anything "cakey". So for example "kääretorttu" could be called a "tårta" (but not a "kaka") or a piece of it would be "en tårtbit" in finlandssvenska. :)