Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(456)

Side by Side Diff: third_party/WebKit/Source/core/layout/BaselineAlignment.cpp

Issue 1407633003: [css-grid] Implementation of Baseline Self-Alignment (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Improving the skipped tesst by solving some rounding issues Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "core/layout/BaselineAlignment.h"
6
7 namespace blink {
8
9 BaselineGroup::BaselineGroup(WritingMode blockFlow,
10 ItemPosition childPreference)
11 : m_maxAscent(0), m_maxDescent(0), m_items() {
12 m_blockFlow = blockFlow;
13 m_preference = childPreference;
14 }
15
16 void BaselineGroup::update(const LayoutBox& child,
17 LayoutUnit ascent,
18 LayoutUnit descent) {
19 if (m_items.insert(&child).isNewEntry) {
20 m_maxAscent = std::max(m_maxAscent, ascent);
21 m_maxDescent = std::max(m_maxDescent, descent);
22 }
23 }
24
25 bool BaselineGroup::isOppositeBlockFlow(WritingMode blockFlow) const {
26 switch (blockFlow) {
27 case WritingMode::kHorizontalTb:
28 return false;
29 case WritingMode::kVerticalLr:
30 return m_blockFlow == WritingMode::kVerticalRl;
31 case WritingMode::kVerticalRl:
32 return m_blockFlow == WritingMode::kVerticalLr;
33 default:
34 NOTREACHED();
35 return false;
36 }
37 }
38
39 bool BaselineGroup::isOrthogonalBlockFlow(WritingMode blockFlow) const {
40 switch (blockFlow) {
41 case WritingMode::kHorizontalTb:
42 return m_blockFlow != WritingMode::kHorizontalTb;
43 case WritingMode::kVerticalLr:
44 case WritingMode::kVerticalRl:
45 return m_blockFlow == WritingMode::kHorizontalTb;
46 default:
47 NOTREACHED();
48 return false;
49 }
50 }
51
52 bool BaselineGroup::isCompatible(WritingMode childBlockFlow,
53 ItemPosition childPreference) const {
54 DCHECK(isBaselinePosition(childPreference));
55 DCHECK_GT(size(), 0);
56 return ((m_blockFlow == childBlockFlow ||
57 isOrthogonalBlockFlow(childBlockFlow)) &&
58 m_preference == childPreference) ||
59 (isOppositeBlockFlow(childBlockFlow) &&
60 m_preference != childPreference);
61 }
62
63 BaselineContext::BaselineContext(const LayoutBox& child,
64 ItemPosition preference,
65 LayoutUnit ascent,
66 LayoutUnit descent) {
67 DCHECK(isBaselinePosition(preference));
68 updateSharedGroup(child, preference, ascent, descent);
69 }
70
71 const BaselineGroup& BaselineContext::getSharedGroup(
72 const LayoutBox& child,
73 ItemPosition preference) const {
74 DCHECK(isBaselinePosition(preference));
75 return const_cast<BaselineContext*>(this)->findCompatibleSharedGroup(
76 child, preference);
77 }
78
79 void BaselineContext::updateSharedGroup(const LayoutBox& child,
80 ItemPosition preference,
81 LayoutUnit ascent,
82 LayoutUnit descent) {
83 DCHECK(isBaselinePosition(preference));
84 BaselineGroup& group = findCompatibleSharedGroup(child, preference);
85 group.update(child, ascent, descent);
86 }
87
88 // TODO Properly implement baseline-group compatibility
89 // See https://github.com/w3c/csswg-drafts/issues/721
90 BaselineGroup& BaselineContext::findCompatibleSharedGroup(
91 const LayoutBox& child,
92 ItemPosition preference) {
93 WritingMode blockDirection = child.styleRef().getWritingMode();
94 for (auto& group : m_sharedGroups) {
95 if (group.isCompatible(blockDirection, preference))
96 return group;
97 }
98 m_sharedGroups.push_front(BaselineGroup(blockDirection, preference));
99 return m_sharedGroups[0];
100 }
101
102 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698