Commit 2ad20078 authored by Rune Lillesveen's avatar Rune Lillesveen Committed by Commit Bot

[Squad] Get rid of MutableStyleRef() in fullscreen code.

We set writing-mode based on parent layout objects, but now modify the
ComputedStyle before SetStyle to avoid non-const access to LayoutObject
ComputedStyle member.

This is part of the work to make the ComputedStyle member of
LayoutObject const.

Bug: 813068
Change-Id: Id1128c036e05532067a87a33f8b5f8b4b75ab8da
Reviewed-on: https://chromium-review.googlesource.com/1024838
Commit-Queue: Rune Lillesveen <futhark@chromium.org>
Reviewed-by: default avatarAleks Totic <atotic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#553492}
parent a4bd4e9a
...@@ -42,7 +42,7 @@ class LayoutFullScreenPlaceholder final : public LayoutBlockFlow { ...@@ -42,7 +42,7 @@ class LayoutFullScreenPlaceholder final : public LayoutBlockFlow {
SetDocumentForAnonymous(&owner->GetDocument()); SetDocumentForAnonymous(&owner->GetDocument());
} }
// Must call setStyleWithWritingModeOfParent() instead. // Must call SetStyleWithWritingModeOfParent() instead.
void SetStyle(scoped_refptr<ComputedStyle>) = delete; void SetStyle(scoped_refptr<ComputedStyle>) = delete;
bool CreatesNewFormattingContext() const override { return true; } bool CreatesNewFormattingContext() const override { return true; }
...@@ -97,7 +97,7 @@ void LayoutFullScreen::WillBeDestroyed() { ...@@ -97,7 +97,7 @@ void LayoutFullScreen::WillBeDestroyed() {
LayoutFlexibleBox::WillBeDestroyed(); LayoutFlexibleBox::WillBeDestroyed();
} }
void LayoutFullScreen::UpdateStyle(LayoutObject* parent) { scoped_refptr<ComputedStyle> LayoutFullScreen::CreateAnonymousStyle() {
scoped_refptr<ComputedStyle> fullscreen_style = ComputedStyle::Create(); scoped_refptr<ComputedStyle> fullscreen_style = ComputedStyle::Create();
// Create a stacking context: // Create a stacking context:
...@@ -123,19 +123,19 @@ void LayoutFullScreen::UpdateStyle(LayoutObject* parent) { ...@@ -123,19 +123,19 @@ void LayoutFullScreen::UpdateStyle(LayoutObject* parent) {
fullscreen_style->SetHeight(Length(viewport_size.Height(), blink::kFixed)); fullscreen_style->SetHeight(Length(viewport_size.Height(), blink::kFixed));
fullscreen_style->SetBackgroundColor(StyleColor(Color::kBlack)); fullscreen_style->SetBackgroundColor(StyleColor(Color::kBlack));
return fullscreen_style;
SetStyleWithWritingModeOf(fullscreen_style, parent);
} }
void LayoutFullScreen::UpdateStyle() { void LayoutFullScreen::UpdateStyle() {
UpdateStyle(Parent()); scoped_refptr<ComputedStyle> style = CreateAnonymousStyle();
SetStyleWithWritingModeOf(style, Parent());
} }
LayoutObject* LayoutFullScreen::WrapLayoutObject(LayoutObject* object, LayoutObject* LayoutFullScreen::WrapLayoutObject(LayoutObject* object,
LayoutObject* parent, LayoutObject* parent,
Document* document) { Document* document) {
// FIXME: We should not modify the structure of the layout tree during // TODO: We should not modify the structure of the layout tree during layout.
// layout. crbug.com/370459 // crbug.com/370459
DeprecatedDisableModifyLayoutTreeStructureAsserts disabler; DeprecatedDisableModifyLayoutTreeStructureAsserts disabler;
// A fullscreen <html> element should not be wrapped (see crbug.com/676432). // A fullscreen <html> element should not be wrapped (see crbug.com/676432).
...@@ -143,37 +143,41 @@ LayoutObject* LayoutFullScreen::WrapLayoutObject(LayoutObject* object, ...@@ -143,37 +143,41 @@ LayoutObject* LayoutFullScreen::WrapLayoutObject(LayoutObject* object,
LayoutFullScreen* fullscreen_layout_object = LayoutFullScreen* fullscreen_layout_object =
LayoutFullScreen::CreateAnonymous(document); LayoutFullScreen::CreateAnonymous(document);
fullscreen_layout_object->UpdateStyle(parent); scoped_refptr<ComputedStyle> fullscreen_style =
if (parent && !parent->IsChildAllowed(fullscreen_layout_object, fullscreen_layout_object->CreateAnonymousStyle();
fullscreen_layout_object->StyleRef())) {
if (parent &&
!parent->IsChildAllowed(fullscreen_layout_object, *fullscreen_style)) {
fullscreen_layout_object->Destroy(); fullscreen_layout_object->Destroy();
return nullptr; return nullptr;
} }
parent = object ? object->Parent() : nullptr;
fullscreen_layout_object->SetStyleWithWritingModeOf(fullscreen_style, parent);
// |object->Parent()| can be null if the object is not yet attached
// to |parent|.
if (parent) {
LayoutBlock* containing_block = object->ContainingBlock();
DCHECK(containing_block);
// Since we are moving the |object| to a new parent
// |fullscreen_layout_object|, the line box tree underneath our
// |containing_block| is not longer valid.
if (containing_block->IsLayoutBlockFlow())
ToLayoutBlockFlow(containing_block)->DeleteLineBoxTree();
parent->AddChild(fullscreen_layout_object, object);
object->Remove();
// Always just do a full layout to ensure that line boxes get deleted
// properly.
// Because objects moved from |parent| to |fullscreen_layout_object|, we
// want to make new line boxes instead of leaving the old ones around.
parent->SetNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(
LayoutInvalidationReason::kFullscreen);
containing_block->SetNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(
LayoutInvalidationReason::kFullscreen);
}
if (object) { if (object) {
// |object->parent()| can be null if the object is not yet attached
// to |parent|.
if (LayoutObject* parent = object->Parent()) {
LayoutBlock* containing_block = object->ContainingBlock();
DCHECK(containing_block);
// Since we are moving the |object| to a new parent
// |fullscreenLayoutObject|, the line box tree underneath our
// |containingBlock| is not longer valid.
if (containing_block->IsLayoutBlockFlow())
ToLayoutBlockFlow(containing_block)->DeleteLineBoxTree();
parent->AddChildWithWritingModeOfParent(fullscreen_layout_object, object);
object->Remove();
// Always just do a full layout to ensure that line boxes get deleted
// properly.
// Because objects moved from |parent| to |fullscreenLayoutObject|, we
// want to make new line boxes instead of leaving the old ones around.
parent->SetNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(
LayoutInvalidationReason::kFullscreen);
containing_block
->SetNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(
LayoutInvalidationReason::kFullscreen);
}
fullscreen_layout_object->AddChild(object); fullscreen_layout_object->AddChild(object);
fullscreen_layout_object fullscreen_layout_object
->SetNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation( ->SetNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(
...@@ -217,17 +221,17 @@ void LayoutFullScreen::CreatePlaceholder(scoped_refptr<ComputedStyle> style, ...@@ -217,17 +221,17 @@ void LayoutFullScreen::CreatePlaceholder(scoped_refptr<ComputedStyle> style,
if (style->Height().IsAuto()) if (style->Height().IsAuto())
style->SetHeight(Length(frame_rect.Height(), kFixed)); style->SetHeight(Length(frame_rect.Height(), kFixed));
if (!placeholder_) { if (placeholder_) {
placeholder_ = new LayoutFullScreenPlaceholder(this);
placeholder_->SetStyleWithWritingModeOfParent(std::move(style));
if (Parent()) {
Parent()->AddChildWithWritingModeOfParent(placeholder_, this);
Parent()->SetNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(
LayoutInvalidationReason::kFullscreen);
}
} else {
placeholder_->SetStyle(std::move(style));
placeholder_->SetStyleWithWritingModeOfParent(std::move(style)); placeholder_->SetStyleWithWritingModeOfParent(std::move(style));
return;
}
placeholder_ = new LayoutFullScreenPlaceholder(this);
placeholder_->SetStyleWithWritingModeOf(std::move(style), Parent());
if (Parent()) {
Parent()->AddChild(placeholder_, this);
Parent()->SetNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(
LayoutInvalidationReason::kFullscreen);
} }
} }
......
...@@ -54,7 +54,6 @@ class CORE_EXPORT LayoutFullScreen final : public LayoutFlexibleBox { ...@@ -54,7 +54,6 @@ class CORE_EXPORT LayoutFullScreen final : public LayoutFlexibleBox {
void UnwrapLayoutObject(); void UnwrapLayoutObject();
void UpdateStyle(); void UpdateStyle();
void UpdateStyle(LayoutObject* parent);
bool AnonymousHasStylePropagationOverride() override { return true; } bool AnonymousHasStylePropagationOverride() override { return true; }
// Must call setStyleWithWritingModeOfParent() instead. // Must call setStyleWithWritingModeOfParent() instead.
...@@ -63,6 +62,7 @@ class CORE_EXPORT LayoutFullScreen final : public LayoutFlexibleBox { ...@@ -63,6 +62,7 @@ class CORE_EXPORT LayoutFullScreen final : public LayoutFlexibleBox {
private: private:
LayoutFullScreen(); LayoutFullScreen();
void WillBeDestroyed() override; void WillBeDestroyed() override;
scoped_refptr<ComputedStyle> CreateAnonymousStyle();
protected: protected:
LayoutBlockFlow* placeholder_; LayoutBlockFlow* placeholder_;
......
...@@ -2305,18 +2305,6 @@ void LayoutObject::SetStyleWithWritingModeOfParent( ...@@ -2305,18 +2305,6 @@ void LayoutObject::SetStyleWithWritingModeOfParent(
SetStyleWithWritingModeOf(std::move(style), Parent()); SetStyleWithWritingModeOf(std::move(style), Parent());
} }
void LayoutObject::AddChildWithWritingModeOfParent(LayoutObject* new_child,
LayoutObject* before_child) {
const WritingMode old_writing_mode =
new_child->MutableStyleRef().GetWritingMode();
const WritingMode new_writing_mode = StyleRef().GetWritingMode();
if (old_writing_mode != new_writing_mode && new_child->IsBoxModelObject()) {
new_child->MutableStyleRef().SetWritingMode(new_writing_mode);
new_child->SetHorizontalWritingMode(IsHorizontalWritingMode());
}
AddChild(new_child, before_child);
}
void LayoutObject::UpdateFillImages(const FillLayer* old_layers, void LayoutObject::UpdateFillImages(const FillLayer* old_layers,
const FillLayer& new_layers) { const FillLayer& new_layers) {
// Optimize the common case // Optimize the common case
......
...@@ -1211,8 +1211,6 @@ class CORE_EXPORT LayoutObject : public ImageResourceObserver, ...@@ -1211,8 +1211,6 @@ class CORE_EXPORT LayoutObject : public ImageResourceObserver,
void SetStyleWithWritingModeOf(scoped_refptr<ComputedStyle>, void SetStyleWithWritingModeOf(scoped_refptr<ComputedStyle>,
LayoutObject* parent); LayoutObject* parent);
void SetStyleWithWritingModeOfParent(scoped_refptr<ComputedStyle>); void SetStyleWithWritingModeOfParent(scoped_refptr<ComputedStyle>);
void AddChildWithWritingModeOfParent(LayoutObject* new_child,
LayoutObject* before_child);
void FirstLineStyleDidChange(const ComputedStyle& old_style, void FirstLineStyleDidChange(const ComputedStyle& old_style,
const ComputedStyle& new_style); const ComputedStyle& new_style);
......
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