1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
10 nscoord
Baseline::SynthesizeBOffsetFromMarginBox(const nsIFrame
* aFrame
,
12 BaselineSharingGroup aGroup
) {
13 MOZ_ASSERT(!aWM
.IsOrthogonalTo(aFrame
->GetWritingMode()));
14 auto margin
= aFrame
->GetLogicalUsedMargin(aWM
);
15 if (aGroup
== BaselineSharingGroup::First
) {
16 if (aWM
.IsAlphabeticalBaseline()) {
17 // First baseline for inverted-line content is the block-start margin
18 // edge, as the frame is in effect "flipped" for alignment purposes.
19 return MOZ_UNLIKELY(aWM
.IsLineInverted())
21 : aFrame
->BSize(aWM
) + margin
.BEnd(aWM
);
23 nscoord marginBoxCenter
= (aFrame
->BSize(aWM
) + margin
.BStartEnd(aWM
)) / 2;
24 return marginBoxCenter
- margin
.BStart(aWM
);
26 MOZ_ASSERT(aGroup
== BaselineSharingGroup::Last
);
27 if (aWM
.IsAlphabeticalBaseline()) {
28 // Last baseline for inverted-line content is the block-start margin edge,
29 // as the frame is in effect "flipped" for alignment purposes.
30 return MOZ_UNLIKELY(aWM
.IsLineInverted())
31 ? aFrame
->BSize(aWM
) + margin
.BStart(aWM
)
34 // Round up for central baseline offset, to be consistent with ::First.
35 nscoord marginBoxSize
= aFrame
->BSize(aWM
) + margin
.BStartEnd(aWM
);
36 nscoord marginBoxCenter
= (marginBoxSize
/ 2) + (marginBoxSize
% 2);
37 return marginBoxCenter
- margin
.BEnd(aWM
);
40 nscoord
Baseline::SynthesizeBOffsetFromBorderBox(const nsIFrame
* aFrame
,
42 BaselineSharingGroup aGroup
) {
43 nscoord borderBoxSize
=
44 MOZ_UNLIKELY(aWM
.IsOrthogonalTo(aFrame
->GetWritingMode()))
47 if (aGroup
== BaselineSharingGroup::First
) {
48 return MOZ_LIKELY(aWM
.IsAlphabeticalBaseline()) ? borderBoxSize
51 MOZ_ASSERT(aGroup
== BaselineSharingGroup::Last
);
52 // Round up for central baseline offset, to be consistent with ::First.
53 auto borderBoxCenter
= (borderBoxSize
/ 2) + (borderBoxSize
% 2);
54 return MOZ_LIKELY(aWM
.IsAlphabeticalBaseline()) ? 0 : borderBoxCenter
;
57 nscoord
Baseline::SynthesizeBOffsetFromContentBox(const nsIFrame
* aFrame
,
59 BaselineSharingGroup aGroup
) {
60 WritingMode wm
= aFrame
->GetWritingMode();
61 MOZ_ASSERT(!aWM
.IsOrthogonalTo(wm
));
62 const auto bp
= aFrame
->GetLogicalUsedBorderAndPadding(wm
)
63 .ApplySkipSides(aFrame
->GetLogicalSkipSides())
66 if (MOZ_UNLIKELY(aWM
.IsCentralBaseline())) {
67 nscoord contentBoxBSize
= aFrame
->BSize(aWM
) - bp
.BStartEnd(aWM
);
68 if (aGroup
== BaselineSharingGroup::First
) {
69 return contentBoxBSize
/ 2 + bp
.BStart(aWM
);
71 // Return the same center position as for ::First, but as offset from end:
72 nscoord halfContentBoxBSize
= (contentBoxBSize
/ 2) + (contentBoxBSize
% 2);
73 return halfContentBoxBSize
+ bp
.BEnd(aWM
);
75 if (aGroup
== BaselineSharingGroup::First
) {
76 // First baseline for inverted-line content is the block-start content
77 // edge, as the frame is in effect "flipped" for alignment purposes.
78 return MOZ_UNLIKELY(aWM
.IsLineInverted())
80 : aFrame
->BSize(aWM
) - bp
.BEnd(aWM
);
82 // Last baseline for inverted-line content is the block-start content edge,
83 // as the frame is in effect "flipped" for alignment purposes.
84 return MOZ_UNLIKELY(aWM
.IsLineInverted())
85 ? aFrame
->BSize(aWM
) - bp
.BStart(aWM
)
89 } // namespace mozilla