B won't gain cover.
To be "blocked", your line must pass through a border, not just touch it.
I should say the fact borders are mentioned by themselves may realy be missleading. Borders are mentioned specifically because there may be a solid border without a square to belong to. A thing thin enough to be placed between two otherwise clear squares.
This is absolutely counter-intuitive for me, when you mechanically can't effectively hide behind a 5 foot tree against a non-moving attacker.
What you need to understand is that the mechanics of combat are intended to function as abstractions for what actually happens in combat. Diegetically, the combatants aren't literally standing in place, waiting for all the other combatants to finish their "turn", every six seconds. That's just an abstraction we use to keep combat tactical and strategic.
Or, put another way: if you're a creature that is benefitting from half-cover, the only way you can then make an attack is if you physically move out of the way of that cover. It may not require you to use up movement speed (if, for example, you're peeking around the corner) but regardless, it's not like a potential assailant would specifically wait for you to make your attack and then retreat before trying to make their own attack; in fact, they'd probably specifically use the moment when you pop out of cover to make their attack.
Just to be clear, I'm not talking in terms of game mechanics; under most conditions, it's not possible for a creature to make an attack during someone else's turn, without using their Reaction or some other clearly specified game mechanic. I'm purely talking in terms of Narrative Diegesis, where "turns" don't exist and everything that characters do in combat is happening (relatively) simultaneously.
But of course that makes it more difficult, hence the mechanical advantage granted by cover of having extra AC, making it harder to successfully land a shot. In this context, the +2AC granted by half-cover is the abstraction meant to explain the difficulty of timing a shot to line up with when you pop out of cover.
This also holds for other kinds of cover: Half Cover abstracts for the fact that, due to being just half cover, maybe part of your body is sticking out beyond the cover outside of your control, whereas with 3/4ths cover, maybe this is no longer an issue. Narratively, how you justify these abstractions is ultimately down to the DM, or for flavor purposes, the players themselves.
So it might seem weird that a 5-ft tree is unable to completely block incoming attacks from hostile creatures, but once you follow how combat is abstracted around cover and the use of obstacles in turn-based combat, I think it's more understandable why these mechanics work the way they do.
Best Answer
Unless otherwise state by some specific ability (i.e. sharpshooter)
Cover applies equally to all forms of attack
I'm going to steal a fair amount from my answer about reach weapons and cover here, as I think it's mostly the same.
With that in mind we can evaluate whether or not an attack from some position incurs cover from another position.
p.250 and p.251 of the DMG have a chart/description.
So, we can attempt the same exercise with your image and we see that if either the woman or the wall were not there, no cover would be gained. Since both are present, the target receives a bonus for half cover.