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

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

Issue 2665133003: [css-grid] Fix behavior of positioned items without specific dimensions (Closed)
Patch Set: Add comment requested in the review Created 3 years, 7 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
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com) 4 * (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com)
5 * (C) 2005, 2006 Samuel Weinig (sam.weinig@gmail.com) 5 * (C) 2005, 2006 Samuel Weinig (sam.weinig@gmail.com)
6 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. 6 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc.
7 * All rights reserved. 7 * All rights reserved.
8 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. 8 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved.
9 * 9 *
10 * This library is free software; you can redistribute it and/or 10 * This library is free software; you can redistribute it and/or
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 #include "platform/geometry/DoubleRect.h" 68 #include "platform/geometry/DoubleRect.h"
69 #include "platform/geometry/FloatQuad.h" 69 #include "platform/geometry/FloatQuad.h"
70 #include "platform/geometry/FloatRoundedRect.h" 70 #include "platform/geometry/FloatRoundedRect.h"
71 #include "platform/wtf/PtrUtil.h" 71 #include "platform/wtf/PtrUtil.h"
72 72
73 namespace blink { 73 namespace blink {
74 74
75 // Used by flexible boxes when flexing this element and by table cells. 75 // Used by flexible boxes when flexing this element and by table cells.
76 typedef WTF::HashMap<const LayoutBox*, LayoutUnit> OverrideSizeMap; 76 typedef WTF::HashMap<const LayoutBox*, LayoutUnit> OverrideSizeMap;
77 77
78 static OverrideSizeMap* g_extra_inline_offset_map = nullptr;
79 static OverrideSizeMap* g_extra_block_offset_map = nullptr;
80
81 // Size of border belt for autoscroll. When mouse pointer in border belt, 78 // Size of border belt for autoscroll. When mouse pointer in border belt,
82 // autoscroll is started. 79 // autoscroll is started.
83 static const int kAutoscrollBeltSize = 20; 80 static const int kAutoscrollBeltSize = 20;
84 static const unsigned kBackgroundObscurationTestMaxDepth = 4; 81 static const unsigned kBackgroundObscurationTestMaxDepth = 4;
85 82
86 struct SameSizeAsLayoutBox : public LayoutBoxModelObject { 83 struct SameSizeAsLayoutBox : public LayoutBoxModelObject {
87 LayoutRect frame_rect; 84 LayoutRect frame_rect;
88 LayoutSize previous_size; 85 LayoutSize previous_size;
89 LayoutUnit intrinsic_content_logical_height; 86 LayoutUnit intrinsic_content_logical_height;
90 LayoutRectOutsets margin_box_outsets; 87 LayoutRectOutsets margin_box_outsets;
(...skipping 26 matching lines...) Expand all
117 114
118 if (HasOverflowClip()) 115 if (HasOverflowClip())
119 return kOverflowClipPaintLayer; 116 return kOverflowClipPaintLayer;
120 117
121 return kNoPaintLayer; 118 return kNoPaintLayer;
122 } 119 }
123 120
124 void LayoutBox::WillBeDestroyed() { 121 void LayoutBox::WillBeDestroyed() {
125 ClearOverrideSize(); 122 ClearOverrideSize();
126 ClearContainingBlockOverrideSize(); 123 ClearContainingBlockOverrideSize();
127 ClearExtraInlineAndBlockOffests();
128 124
129 if (IsOutOfFlowPositioned()) 125 if (IsOutOfFlowPositioned())
130 LayoutBlock::RemovePositionedObject(this); 126 LayoutBlock::RemovePositionedObject(this);
131 RemoveFromPercentHeightContainer(); 127 RemoveFromPercentHeightContainer();
132 if (IsOrthogonalWritingModeRoot() && !DocumentBeingDestroyed()) 128 if (IsOrthogonalWritingModeRoot() && !DocumentBeingDestroyed())
133 UnmarkOrthogonalWritingModeRoot(); 129 UnmarkOrthogonalWritingModeRoot();
134 130
135 ShapeOutsideInfo::RemoveInfo(*this); 131 ShapeOutsideInfo::RemoveInfo(*this);
136 132
137 LayoutBoxModelObject::WillBeDestroyed(); 133 LayoutBoxModelObject::WillBeDestroyed();
(...skipping 1300 matching lines...) Expand 10 before | Expand all | Expand 10 after
1438 1434
1439 // TODO (lajava) Shouldn't we implement these functions based on physical 1435 // TODO (lajava) Shouldn't we implement these functions based on physical
1440 // direction ?. 1436 // direction ?.
1441 void LayoutBox::ClearOverrideContainingBlockContentLogicalHeight() { 1437 void LayoutBox::ClearOverrideContainingBlockContentLogicalHeight() {
1442 if (!rare_data_) 1438 if (!rare_data_)
1443 return; 1439 return;
1444 EnsureRareData().has_override_containing_block_content_logical_height_ = 1440 EnsureRareData().has_override_containing_block_content_logical_height_ =
1445 false; 1441 false;
1446 } 1442 }
1447 1443
1448 LayoutUnit LayoutBox::ExtraInlineOffset() const {
1449 return g_extra_inline_offset_map ? g_extra_inline_offset_map->at(this)
1450 : LayoutUnit();
1451 }
1452
1453 LayoutUnit LayoutBox::ExtraBlockOffset() const {
1454 return g_extra_block_offset_map ? g_extra_block_offset_map->at(this)
1455 : LayoutUnit();
1456 }
1457
1458 void LayoutBox::SetExtraInlineOffset(LayoutUnit inline_offest) {
1459 if (!g_extra_inline_offset_map)
1460 g_extra_inline_offset_map = new OverrideSizeMap;
1461 g_extra_inline_offset_map->Set(this, inline_offest);
1462 }
1463
1464 void LayoutBox::SetExtraBlockOffset(LayoutUnit block_offest) {
1465 if (!g_extra_block_offset_map)
1466 g_extra_block_offset_map = new OverrideSizeMap;
1467 g_extra_block_offset_map->Set(this, block_offest);
1468 }
1469
1470 void LayoutBox::ClearExtraInlineAndBlockOffests() {
1471 if (g_extra_inline_offset_map)
1472 g_extra_inline_offset_map->erase(this);
1473 if (g_extra_block_offset_map)
1474 g_extra_block_offset_map->erase(this);
1475 }
1476
1477 LayoutUnit LayoutBox::AdjustBorderBoxLogicalWidthForBoxSizing( 1444 LayoutUnit LayoutBox::AdjustBorderBoxLogicalWidthForBoxSizing(
1478 float width) const { 1445 float width) const {
1479 LayoutUnit borders_plus_padding = CollapsedBorderAndCSSPaddingLogicalWidth(); 1446 LayoutUnit borders_plus_padding = CollapsedBorderAndCSSPaddingLogicalWidth();
1480 LayoutUnit result(width); 1447 LayoutUnit result(width);
1481 if (Style()->BoxSizing() == EBoxSizing::kContentBox) 1448 if (Style()->BoxSizing() == EBoxSizing::kContentBox)
1482 return result + borders_plus_padding; 1449 return result + borders_plus_padding;
1483 return std::max(result, borders_plus_padding); 1450 return std::max(result, borders_plus_padding);
1484 } 1451 }
1485 1452
1486 LayoutUnit LayoutBox::AdjustBorderBoxLogicalHeightForBoxSizing( 1453 LayoutUnit LayoutBox::AdjustBorderBoxLogicalHeightForBoxSizing(
(...skipping 2402 matching lines...) Expand 10 before | Expand all | Expand 10 after
3889 3856
3890 void LayoutBox::ComputeInlineStaticDistance( 3857 void LayoutBox::ComputeInlineStaticDistance(
3891 Length& logical_left, 3858 Length& logical_left,
3892 Length& logical_right, 3859 Length& logical_right,
3893 const LayoutBox* child, 3860 const LayoutBox* child,
3894 const LayoutBoxModelObject* container_block, 3861 const LayoutBoxModelObject* container_block,
3895 LayoutUnit container_logical_width) { 3862 LayoutUnit container_logical_width) {
3896 if (!logical_left.IsAuto() || !logical_right.IsAuto()) 3863 if (!logical_left.IsAuto() || !logical_right.IsAuto())
3897 return; 3864 return;
3898 3865
3866 // This method is using EnclosingBox() which is wrong for absolutely
3867 // positioned gird items, as they rely on the grid area. So for grid items if
svillar 2017/05/08 11:18:10 Nit. gird->grid
Manuel Rego 2017/05/08 13:29:44 Fixed.
3868 // both "left" and "right" properties are "auto", we can consider that one of
3869 // them (depending on the direction) is simply "0".
3870 if (child->IsGridItem() && child->ContainingBlock() == child->Parent()) {
jfernandez 2017/05/08 12:56:07 Wouldn't be better to use the child's parent inste
Manuel Rego 2017/05/08 13:29:44 Done.
3871 if (child->Parent()->Style()->Direction() == TextDirection::kLtr)
3872 logical_left.SetValue(kFixed, 0);
3873 else
3874 logical_right.SetValue(kFixed, 0);
3875 return;
3876 }
3877
3899 // For multicol we also need to keep track of the block position, since that 3878 // For multicol we also need to keep track of the block position, since that
3900 // determines which column we're in and thus affects the inline position. 3879 // determines which column we're in and thus affects the inline position.
3901 LayoutUnit static_block_position = child->Layer()->StaticBlockPosition(); 3880 LayoutUnit static_block_position = child->Layer()->StaticBlockPosition();
3902 3881
3903 // FIXME: The static distance computation has not been patched for mixed 3882 // FIXME: The static distance computation has not been patched for mixed
3904 // writing modes yet. 3883 // writing modes yet.
3905 if (child->Parent()->Style()->Direction() == TextDirection::kLtr) { 3884 if (child->Parent()->Style()->Direction() == TextDirection::kLtr) {
3906 LayoutUnit static_position = child->Layer()->StaticInlinePosition() - 3885 LayoutUnit static_position = child->Layer()->StaticInlinePosition() -
3907 container_block->BorderLogicalLeft(); 3886 container_block->BorderLogicalLeft();
3908 for (LayoutObject* curr = child->Parent(); curr && curr != container_block; 3887 for (LayoutObject* curr = child->Parent(); curr && curr != container_block;
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
4071 margin_logical_right, min_values); 4050 margin_logical_right, min_values);
4072 4051
4073 if (computed_values.extent_ < min_values.extent_) { 4052 if (computed_values.extent_ < min_values.extent_) {
4074 computed_values.extent_ = min_values.extent_; 4053 computed_values.extent_ = min_values.extent_;
4075 computed_values.position_ = min_values.position_; 4054 computed_values.position_ = min_values.position_;
4076 computed_values.margins_.start_ = min_values.margins_.start_; 4055 computed_values.margins_.start_ = min_values.margins_.start_;
4077 computed_values.margins_.end_ = min_values.margins_.end_; 4056 computed_values.margins_.end_ = min_values.margins_.end_;
4078 } 4057 }
4079 } 4058 }
4080 4059
4081 if (!Style()->HasStaticInlinePosition(is_horizontal))
4082 computed_values.position_ += ExtraInlineOffset();
4083
4084 computed_values.extent_ += borders_plus_padding; 4060 computed_values.extent_ += borders_plus_padding;
4085 } 4061 }
4086 4062
4087 void LayoutBox::ComputeLogicalLeftPositionedOffset( 4063 void LayoutBox::ComputeLogicalLeftPositionedOffset(
4088 LayoutUnit& logical_left_pos, 4064 LayoutUnit& logical_left_pos,
4089 const LayoutBox* child, 4065 const LayoutBox* child,
4090 LayoutUnit logical_width_value, 4066 LayoutUnit logical_width_value,
4091 const LayoutBoxModelObject* container_block, 4067 const LayoutBoxModelObject* container_block,
4092 LayoutUnit container_logical_width) { 4068 LayoutUnit container_logical_width) {
4093 // Deal with differing writing modes here. Our offset needs to be in the 4069 // Deal with differing writing modes here. Our offset needs to be in the
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
4479 min_values); 4455 min_values);
4480 4456
4481 if (computed_values.extent_ < min_values.extent_) { 4457 if (computed_values.extent_ < min_values.extent_) {
4482 computed_values.extent_ = min_values.extent_; 4458 computed_values.extent_ = min_values.extent_;
4483 computed_values.position_ = min_values.position_; 4459 computed_values.position_ = min_values.position_;
4484 computed_values.margins_.before_ = min_values.margins_.before_; 4460 computed_values.margins_.before_ = min_values.margins_.before_;
4485 computed_values.margins_.after_ = min_values.margins_.after_; 4461 computed_values.margins_.after_ = min_values.margins_.after_;
4486 } 4462 }
4487 } 4463 }
4488 4464
4489 if (!Style()->HasStaticBlockPosition(IsHorizontalWritingMode()))
4490 computed_values.position_ += ExtraBlockOffset();
4491
4492 // Set final height value. 4465 // Set final height value.
4493 computed_values.extent_ += borders_plus_padding; 4466 computed_values.extent_ += borders_plus_padding;
4494 } 4467 }
4495 4468
4496 void LayoutBox::ComputeLogicalTopPositionedOffset( 4469 void LayoutBox::ComputeLogicalTopPositionedOffset(
4497 LayoutUnit& logical_top_pos, 4470 LayoutUnit& logical_top_pos,
4498 const LayoutBox* child, 4471 const LayoutBox* child,
4499 LayoutUnit logical_height_value, 4472 LayoutUnit logical_height_value,
4500 const LayoutBoxModelObject* container_block, 4473 const LayoutBoxModelObject* container_block,
4501 LayoutUnit container_logical_height) { 4474 LayoutUnit container_logical_height) {
(...skipping 1398 matching lines...) Expand 10 before | Expand all | Expand 10 after
5900 void LayoutBox::MutableForPainting:: 5873 void LayoutBox::MutableForPainting::
5901 SavePreviousContentBoxSizeAndLayoutOverflowRect() { 5874 SavePreviousContentBoxSizeAndLayoutOverflowRect() {
5902 auto& rare_data = GetLayoutBox().EnsureRareData(); 5875 auto& rare_data = GetLayoutBox().EnsureRareData();
5903 rare_data.has_previous_content_box_size_and_layout_overflow_rect_ = true; 5876 rare_data.has_previous_content_box_size_and_layout_overflow_rect_ = true;
5904 rare_data.previous_content_box_size_ = GetLayoutBox().ContentBoxRect().Size(); 5877 rare_data.previous_content_box_size_ = GetLayoutBox().ContentBoxRect().Size();
5905 rare_data.previous_layout_overflow_rect_ = 5878 rare_data.previous_layout_overflow_rect_ =
5906 GetLayoutBox().LayoutOverflowRect(); 5879 GetLayoutBox().LayoutOverflowRect();
5907 } 5880 }
5908 5881
5909 } // namespace blink 5882 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698