Commit 8e95e428 authored by Aleks Totic's avatar Aleks Totic Committed by Commit Bot

[LayoutNG] Refactor dialog positioning into NG

Bug: 740993
Cq-Include-Trybots: luci.chromium.try:linux_layout_tests_layout_ng
Change-Id: I5a0dd12b81fd300b42bfae0c7a5432ffadd6fb39
Reviewed-on: https://chromium-review.googlesource.com/1110488Reviewed-by: default avatarKoji Ishii <kojii@chromium.org>
Commit-Queue: Aleks Totic <atotic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#569532}
parent f011f9bb
...@@ -55,6 +55,7 @@ ...@@ -55,6 +55,7 @@
#include "third_party/blink/renderer/core/layout/ng/inline/ng_line_height_metrics.h" #include "third_party/blink/renderer/core/layout/ng/inline/ng_line_height_metrics.h"
#include "third_party/blink/renderer/core/layout/ng/layout_ng_block_flow.h" #include "third_party/blink/renderer/core/layout/ng/layout_ng_block_flow.h"
#include "third_party/blink/renderer/core/layout/ng/legacy_layout_tree_walking.h" #include "third_party/blink/renderer/core/layout/ng/legacy_layout_tree_walking.h"
#include "third_party/blink/renderer/core/layout/ng/ng_absolute_utils.h"
#include "third_party/blink/renderer/core/layout/ng/ng_box_fragment.h" #include "third_party/blink/renderer/core/layout/ng/ng_box_fragment.h"
#include "third_party/blink/renderer/core/layout/ng/ng_fragmentation_utils.h" #include "third_party/blink/renderer/core/layout/ng/ng_fragmentation_utils.h"
#include "third_party/blink/renderer/core/layout/ng/ng_layout_result.h" #include "third_party/blink/renderer/core/layout/ng/ng_layout_result.h"
...@@ -4603,44 +4604,9 @@ LayoutBlockFlow::LayoutBlockFlowRareData& LayoutBlockFlow::EnsureRareData() { ...@@ -4603,44 +4604,9 @@ LayoutBlockFlow::LayoutBlockFlowRareData& LayoutBlockFlow::EnsureRareData() {
return *rare_data_; return *rare_data_;
} }
base::Optional<LayoutUnit> LayoutBlockFlow::ComputeDialogYPosition(
LayoutUnit height) const {
DCHECK(IsHTMLDialogElement(GetNode()));
HTMLDialogElement* dialog = ToHTMLDialogElement(GetNode());
if (dialog->GetCenteringMode() == HTMLDialogElement::kNotCentered)
return base::nullopt;
bool can_center_dialog = (Style()->GetPosition() == EPosition::kAbsolute ||
Style()->GetPosition() == EPosition::kFixed) &&
Style()->HasAutoTopAndBottom();
if (dialog->GetCenteringMode() == HTMLDialogElement::kCentered) {
if (can_center_dialog)
return dialog->CenteredPosition();
return base::nullopt;
}
DCHECK_EQ(dialog->GetCenteringMode(), HTMLDialogElement::kNeedsCentering);
if (!can_center_dialog) {
dialog->SetNotCentered();
return base::nullopt;
}
auto* scrollable_area = GetDocument().View()->LayoutViewport();
LayoutUnit top =
LayoutUnit((Style()->GetPosition() == EPosition::kFixed)
? 0
: scrollable_area->ScrollOffsetInt().Height());
int visible_height = GetDocument().View()->Height();
if (height < visible_height)
top += (visible_height - height) / 2;
dialog->SetCentered(top);
return top;
}
void LayoutBlockFlow::PositionDialog() { void LayoutBlockFlow::PositionDialog() {
base::Optional<LayoutUnit> y = ComputeDialogYPosition(Size().Height()); base::Optional<LayoutUnit> y =
ComputeAbsoluteDialogYPosition(*this, Size().Height());
if (y.has_value()) if (y.has_value())
SetY(y.value()); SetY(y.value());
} }
......
...@@ -808,8 +808,6 @@ class CORE_EXPORT LayoutBlockFlow : public LayoutBlock { ...@@ -808,8 +808,6 @@ class CORE_EXPORT LayoutBlockFlow : public LayoutBlock {
bool ShouldTruncateOverflowingText() const; bool ShouldTruncateOverflowingText() const;
base::Optional<LayoutUnit> ComputeDialogYPosition(LayoutUnit height) const;
int GetLayoutPassCountForTesting(); int GetLayoutPassCountForTesting();
protected: protected:
......
...@@ -4,9 +4,12 @@ ...@@ -4,9 +4,12 @@
#include "third_party/blink/renderer/core/layout/ng/ng_absolute_utils.h" #include "third_party/blink/renderer/core/layout/ng/ng_absolute_utils.h"
#include "third_party/blink/renderer/core/html/html_dialog_element.h"
#include "third_party/blink/renderer/core/layout/layout_object.h"
#include "third_party/blink/renderer/core/layout/ng/geometry/ng_static_position.h" #include "third_party/blink/renderer/core/layout/ng/geometry/ng_static_position.h"
#include "third_party/blink/renderer/core/layout/ng/ng_constraint_space.h" #include "third_party/blink/renderer/core/layout/ng/ng_constraint_space.h"
#include "third_party/blink/renderer/core/layout/ng/ng_length_utils.h" #include "third_party/blink/renderer/core/layout/ng/ng_length_utils.h"
#include "third_party/blink/renderer/core/paint/paint_layer_scrollable_area.h"
#include "third_party/blink/renderer/core/style/computed_style.h" #include "third_party/blink/renderer/core/style/computed_style.h"
#include "third_party/blink/renderer/platform/length_functions.h" #include "third_party/blink/renderer/platform/length_functions.h"
...@@ -495,6 +498,50 @@ bool AbsoluteNeedsChildInlineSize(const ComputedStyle& style) { ...@@ -495,6 +498,50 @@ bool AbsoluteNeedsChildInlineSize(const ComputedStyle& style) {
return AbsoluteVerticalNeedsEstimate(style); return AbsoluteVerticalNeedsEstimate(style);
} }
base::Optional<LayoutUnit> ComputeAbsoluteDialogYPosition(
const LayoutObject& dialog,
LayoutUnit height) {
if (!IsHTMLDialogElement(dialog.GetNode()))
return base::nullopt;
// This code implements <dialog> static position spec.
// //
// https://html.spec.whatwg.org/multipage/interactive-elements.html#the-dialog-element
HTMLDialogElement* dialog_node = ToHTMLDialogElement(dialog.GetNode());
if (dialog_node->GetCenteringMode() == HTMLDialogElement::kNotCentered)
return base::nullopt;
bool can_center_dialog =
(dialog.Style()->GetPosition() == EPosition::kAbsolute ||
dialog.Style()->GetPosition() == EPosition::kFixed) &&
dialog.Style()->HasAutoTopAndBottom();
if (dialog_node->GetCenteringMode() == HTMLDialogElement::kCentered) {
if (can_center_dialog)
return dialog_node->CenteredPosition();
return base::nullopt;
}
DCHECK_EQ(dialog_node->GetCenteringMode(),
HTMLDialogElement::kNeedsCentering);
if (!can_center_dialog) {
dialog_node->SetNotCentered();
return base::nullopt;
}
auto* scrollable_area = dialog.GetDocument().View()->LayoutViewport();
LayoutUnit top =
LayoutUnit((dialog.Style()->GetPosition() == EPosition::kFixed)
? 0
: scrollable_area->ScrollOffsetInt().Height());
int visible_height = dialog.GetDocument().View()->Height();
if (height < visible_height)
top += (visible_height - height) / 2;
dialog_node->SetCentered(top);
return top;
}
NGAbsolutePhysicalPosition ComputePartialAbsoluteWithChildInlineSize( NGAbsolutePhysicalPosition ComputePartialAbsoluteWithChildInlineSize(
const NGConstraintSpace& space, const NGConstraintSpace& space,
const ComputedStyle& style, const ComputedStyle& style,
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
namespace blink { namespace blink {
class ComputedStyle; class ComputedStyle;
class LayoutObject;
class NGConstraintSpace; class NGConstraintSpace;
struct NGStaticPosition; struct NGStaticPosition;
...@@ -24,6 +25,13 @@ struct CORE_EXPORT NGAbsolutePhysicalPosition { ...@@ -24,6 +25,13 @@ struct CORE_EXPORT NGAbsolutePhysicalPosition {
String ToString() const; String ToString() const;
}; };
// Implements <dialog> special case abspos static positining.
// Returns new dialog top position if layout_dialog requires
// <dialog> abspos centering.
CORE_EXPORT base::Optional<LayoutUnit> ComputeAbsoluteDialogYPosition(
const LayoutObject& layout_dialog,
LayoutUnit height);
// The following routines implement absolute size resolution algorithm. // The following routines implement absolute size resolution algorithm.
// https://www.w3.org/TR/css-position-3/#abs-non-replaced-width // https://www.w3.org/TR/css-position-3/#abs-non-replaced-width
// //
......
...@@ -4,8 +4,6 @@ ...@@ -4,8 +4,6 @@
#include "third_party/blink/renderer/core/layout/ng/ng_out_of_flow_layout_part.h" #include "third_party/blink/renderer/core/layout/ng/ng_out_of_flow_layout_part.h"
#include "third_party/blink/renderer/core/html/html_dialog_element.h"
#include "third_party/blink/renderer/core/layout/layout_block_flow.h"
#include "third_party/blink/renderer/core/layout/layout_object.h" #include "third_party/blink/renderer/core/layout/layout_object.h"
#include "third_party/blink/renderer/core/layout/ng/inline/ng_physical_line_box_fragment.h" #include "third_party/blink/renderer/core/layout/ng/inline/ng_physical_line_box_fragment.h"
#include "third_party/blink/renderer/core/layout/ng/ng_absolute_utils.h" #include "third_party/blink/renderer/core/layout/ng/ng_absolute_utils.h"
...@@ -379,18 +377,14 @@ scoped_refptr<NGLayoutResult> NGOutOfFlowLayoutPart::LayoutDescendant( ...@@ -379,18 +377,14 @@ scoped_refptr<NGLayoutResult> NGOutOfFlowLayoutPart::LayoutDescendant(
container_info.default_container_offset.inline_offset; container_info.default_container_offset.inline_offset;
offset->block_offset += container_info.default_container_offset.block_offset; offset->block_offset += container_info.default_container_offset.block_offset;
LayoutObject* layout_object = descendant.node.GetLayoutObject(); base::Optional<LayoutUnit> y = ComputeAbsoluteDialogYPosition(
if (IsHTMLDialogElement(layout_object->GetNode())) { *descendant.node.GetLayoutObject(),
base::Optional<LayoutUnit> y = layout_result->PhysicalFragment()->Size().height);
ToLayoutBlockFlow(layout_object) if (y.has_value()) {
->ComputeDialogYPosition( if (IsHorizontalWritingMode(container_writing_mode))
layout_result->PhysicalFragment()->Size().height); offset->block_offset = y.value();
if (y.has_value()) { else
if (IsHorizontalWritingMode(container_writing_mode)) offset->inline_offset = y.value();
offset->block_offset = y.value();
else
offset->inline_offset = y.value();
}
} }
return layout_result; return layout_result;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment