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

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: Applied suggested changes 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 LayoutObject* parent = child->Parent();
3867 TextDirection parent_direction = parent->Style()->Direction();
3868
3869 // This method is using EnclosingBox() which is wrong for absolutely
3870 // positioned grid items, as they rely on the grid area. So for grid items if
3871 // both "left" and "right" properties are "auto", we can consider that one of
3872 // them (depending on the direction) is simply "0".
3873 if (parent->IsLayoutGrid() && parent == child->ContainingBlock()) {
3874 if (parent_direction == TextDirection::kLtr)
3875 logical_left.SetValue(kFixed, 0);
3876 else
3877 logical_right.SetValue(kFixed, 0);
3878 return;
3879 }
3880
3899 // For multicol we also need to keep track of the block position, since that 3881 // 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. 3882 // determines which column we're in and thus affects the inline position.
3901 LayoutUnit static_block_position = child->Layer()->StaticBlockPosition(); 3883 LayoutUnit static_block_position = child->Layer()->StaticBlockPosition();
3902 3884
3903 // FIXME: The static distance computation has not been patched for mixed 3885 // FIXME: The static distance computation has not been patched for mixed
3904 // writing modes yet. 3886 // writing modes yet.
3905 if (child->Parent()->Style()->Direction() == TextDirection::kLtr) { 3887 if (parent_direction == TextDirection::kLtr) {
3906 LayoutUnit static_position = child->Layer()->StaticInlinePosition() - 3888 LayoutUnit static_position = child->Layer()->StaticInlinePosition() -
3907 container_block->BorderLogicalLeft(); 3889 container_block->BorderLogicalLeft();
3908 for (LayoutObject* curr = child->Parent(); curr && curr != container_block; 3890 for (LayoutObject* curr = child->Parent(); curr && curr != container_block;
3909 curr = curr->Container()) { 3891 curr = curr->Container()) {
3910 if (curr->IsBox()) { 3892 if (curr->IsBox()) {
3911 static_position += ToLayoutBox(curr)->LogicalLeft(); 3893 static_position += ToLayoutBox(curr)->LogicalLeft();
3912 if (ToLayoutBox(curr)->IsInFlowPositioned()) 3894 if (ToLayoutBox(curr)->IsInFlowPositioned())
3913 static_position += 3895 static_position +=
3914 ToLayoutBox(curr)->OffsetForInFlowPosition().Width(); 3896 ToLayoutBox(curr)->OffsetForInFlowPosition().Width();
3915 if (curr->IsInsideFlowThread()) 3897 if (curr->IsInsideFlowThread())
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
4071 margin_logical_right, min_values); 4053 margin_logical_right, min_values);
4072 4054
4073 if (computed_values.extent_ < min_values.extent_) { 4055 if (computed_values.extent_ < min_values.extent_) {
4074 computed_values.extent_ = min_values.extent_; 4056 computed_values.extent_ = min_values.extent_;
4075 computed_values.position_ = min_values.position_; 4057 computed_values.position_ = min_values.position_;
4076 computed_values.margins_.start_ = min_values.margins_.start_; 4058 computed_values.margins_.start_ = min_values.margins_.start_;
4077 computed_values.margins_.end_ = min_values.margins_.end_; 4059 computed_values.margins_.end_ = min_values.margins_.end_;
4078 } 4060 }
4079 } 4061 }
4080 4062
4081 if (!Style()->HasStaticInlinePosition(is_horizontal))
4082 computed_values.position_ += ExtraInlineOffset();
4083
4084 computed_values.extent_ += borders_plus_padding; 4063 computed_values.extent_ += borders_plus_padding;
4085 } 4064 }
4086 4065
4087 void LayoutBox::ComputeLogicalLeftPositionedOffset( 4066 void LayoutBox::ComputeLogicalLeftPositionedOffset(
4088 LayoutUnit& logical_left_pos, 4067 LayoutUnit& logical_left_pos,
4089 const LayoutBox* child, 4068 const LayoutBox* child,
4090 LayoutUnit logical_width_value, 4069 LayoutUnit logical_width_value,
4091 const LayoutBoxModelObject* container_block, 4070 const LayoutBoxModelObject* container_block,
4092 LayoutUnit container_logical_width) { 4071 LayoutUnit container_logical_width) {
4093 // Deal with differing writing modes here. Our offset needs to be in the 4072 // 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); 4458 min_values);
4480 4459
4481 if (computed_values.extent_ < min_values.extent_) { 4460 if (computed_values.extent_ < min_values.extent_) {
4482 computed_values.extent_ = min_values.extent_; 4461 computed_values.extent_ = min_values.extent_;
4483 computed_values.position_ = min_values.position_; 4462 computed_values.position_ = min_values.position_;
4484 computed_values.margins_.before_ = min_values.margins_.before_; 4463 computed_values.margins_.before_ = min_values.margins_.before_;
4485 computed_values.margins_.after_ = min_values.margins_.after_; 4464 computed_values.margins_.after_ = min_values.margins_.after_;
4486 } 4465 }
4487 } 4466 }
4488 4467
4489 if (!Style()->HasStaticBlockPosition(IsHorizontalWritingMode()))
4490 computed_values.position_ += ExtraBlockOffset();
4491
4492 // Set final height value. 4468 // Set final height value.
4493 computed_values.extent_ += borders_plus_padding; 4469 computed_values.extent_ += borders_plus_padding;
4494 } 4470 }
4495 4471
4496 void LayoutBox::ComputeLogicalTopPositionedOffset( 4472 void LayoutBox::ComputeLogicalTopPositionedOffset(
4497 LayoutUnit& logical_top_pos, 4473 LayoutUnit& logical_top_pos,
4498 const LayoutBox* child, 4474 const LayoutBox* child,
4499 LayoutUnit logical_height_value, 4475 LayoutUnit logical_height_value,
4500 const LayoutBoxModelObject* container_block, 4476 const LayoutBoxModelObject* container_block,
4501 LayoutUnit container_logical_height) { 4477 LayoutUnit container_logical_height) {
(...skipping 1398 matching lines...) Expand 10 before | Expand all | Expand 10 after
5900 void LayoutBox::MutableForPainting:: 5876 void LayoutBox::MutableForPainting::
5901 SavePreviousContentBoxSizeAndLayoutOverflowRect() { 5877 SavePreviousContentBoxSizeAndLayoutOverflowRect() {
5902 auto& rare_data = GetLayoutBox().EnsureRareData(); 5878 auto& rare_data = GetLayoutBox().EnsureRareData();
5903 rare_data.has_previous_content_box_size_and_layout_overflow_rect_ = true; 5879 rare_data.has_previous_content_box_size_and_layout_overflow_rect_ = true;
5904 rare_data.previous_content_box_size_ = GetLayoutBox().ContentBoxRect().Size(); 5880 rare_data.previous_content_box_size_ = GetLayoutBox().ContentBoxRect().Size();
5905 rare_data.previous_layout_overflow_rect_ = 5881 rare_data.previous_layout_overflow_rect_ =
5906 GetLayoutBox().LayoutOverflowRect(); 5882 GetLayoutBox().LayoutOverflowRect();
5907 } 5883 }
5908 5884
5909 } // namespace blink 5885 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/LayoutBox.h ('k') | third_party/WebKit/Source/core/layout/LayoutGrid.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698