Commit b72d5ac6 authored by Koji Ishii's avatar Koji Ishii Committed by Commit Bot

[NGFragmentItem] Add NGFragmentItem::Style()

This patch adds |NGFragmentItem::Style()|, by sharing the
code between |NGPhysicalFragment|.

Bug: 982194
Change-Id: I7153fb18df7aaa3e7d04995e1d99553fbf637d85
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1768604
Commit-Queue: Koji Ishii <kojii@chromium.org>
Reviewed-by: default avatarEmil A Eklund <eae@chromium.org>
Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#690384}
parent 51a2fe4e
...@@ -1844,6 +1844,26 @@ bool LayoutObject::IsSelectable() const { ...@@ -1844,6 +1844,26 @@ bool LayoutObject::IsSelectable() const {
StyleRef().UserModify() == EUserModify::kReadOnly); StyleRef().UserModify() == EUserModify::kReadOnly);
} }
const ComputedStyle& LayoutObject::SlowEffectiveStyle(
NGStyleVariant style_variant) const {
switch (style_variant) {
case NGStyleVariant::kStandard:
return StyleRef();
case NGStyleVariant::kFirstLine:
return FirstLineStyleRef();
case NGStyleVariant::kEllipsis:
// The ellipsis is styled according to the line style.
// https://www.w3.org/TR/css-overflow-3/#ellipsing-details
// Use first-line style if exists since most cases it is the first line.
DCHECK(IsInline());
if (LayoutObject* block = ContainingBlock())
return block->FirstLineStyleRef();
return FirstLineStyleRef();
}
NOTREACHED();
return StyleRef();
}
// Called when an object that was floating or positioned becomes a normal flow // Called when an object that was floating or positioned becomes a normal flow
// object again. We have to make sure the layout tree updates as needed to // object again. We have to make sure the layout tree updates as needed to
// accommodate the new normal flow object. // accommodate the new normal flow object.
......
...@@ -46,6 +46,7 @@ ...@@ -46,6 +46,7 @@
#include "third_party/blink/renderer/core/layout/layout_object_child_list.h" #include "third_party/blink/renderer/core/layout/layout_object_child_list.h"
#include "third_party/blink/renderer/core/layout/map_coordinates_flags.h" #include "third_party/blink/renderer/core/layout/map_coordinates_flags.h"
#include "third_party/blink/renderer/core/layout/ng/ng_outline_type.h" #include "third_party/blink/renderer/core/layout/ng/ng_outline_type.h"
#include "third_party/blink/renderer/core/layout/ng/ng_style_variant.h"
#include "third_party/blink/renderer/core/layout/subtree_layout_scope.h" #include "third_party/blink/renderer/core/layout/subtree_layout_scope.h"
#include "third_party/blink/renderer/core/loader/resource/image_resource_observer.h" #include "third_party/blink/renderer/core/loader/resource/image_resource_observer.h"
#include "third_party/blink/renderer/core/paint/compositing/compositing_state.h" #include "third_party/blink/renderer/core/paint/compositing/compositing_state.h"
...@@ -1770,6 +1771,12 @@ class CORE_EXPORT LayoutObject : public ImageResourceObserver, ...@@ -1770,6 +1771,12 @@ class CORE_EXPORT LayoutObject : public ImageResourceObserver,
inline const ComputedStyle* Style(bool first_line) const; inline const ComputedStyle* Style(bool first_line) const;
inline const ComputedStyle& StyleRef(bool first_line) const; inline const ComputedStyle& StyleRef(bool first_line) const;
const ComputedStyle& EffectiveStyle(NGStyleVariant style_variant) const {
return style_variant == NGStyleVariant::kStandard
? StyleRef()
: SlowEffectiveStyle(style_variant);
}
static inline Color ResolveColor(const ComputedStyle& style_to_use, static inline Color ResolveColor(const ComputedStyle& style_to_use,
const CSSProperty& color_property) { const CSSProperty& color_property) {
return style_to_use.VisitedDependentColor(color_property); return style_to_use.VisitedDependentColor(color_property);
...@@ -2554,6 +2561,8 @@ class CORE_EXPORT LayoutObject : public ImageResourceObserver, ...@@ -2554,6 +2561,8 @@ class CORE_EXPORT LayoutObject : public ImageResourceObserver,
}; };
virtual bool IsOfType(LayoutObjectType type) const { return false; } virtual bool IsOfType(LayoutObjectType type) const { return false; }
const ComputedStyle& SlowEffectiveStyle(NGStyleVariant style_variant) const;
// Updates only the local style ptr of the object. Does not update the state // Updates only the local style ptr of the object. Does not update the state
// of the object, and so only should be called when the style is known not to // of the object, and so only should be called when the style is known not to
// have changed (or from SetStyle). // have changed (or from SetStyle).
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "third_party/blink/renderer/core/core_export.h" #include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/layout/geometry/logical_offset.h" #include "third_party/blink/renderer/core/layout/geometry/logical_offset.h"
#include "third_party/blink/renderer/core/layout/layout_object.h"
#include "third_party/blink/renderer/core/layout/ng/inline/ng_line_box_fragment_builder.h" #include "third_party/blink/renderer/core/layout/ng/inline/ng_line_box_fragment_builder.h"
#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/platform/graphics/paint/display_item_client.h" #include "third_party/blink/renderer/platform/graphics/paint/display_item_client.h"
...@@ -72,8 +73,14 @@ class CORE_EXPORT NGFragmentItem : public DisplayItemClient { ...@@ -72,8 +73,14 @@ class CORE_EXPORT NGFragmentItem : public DisplayItemClient {
bool UsesFirstLineStyle() const { bool UsesFirstLineStyle() const {
return StyleVariant() == NGStyleVariant::kFirstLine; return StyleVariant() == NGStyleVariant::kFirstLine;
} }
// Returns the style for this fragment.
//
// For a line box, this returns the style of the containing block. This mostly
// represents the style for the line box, except 1) |style.Direction()| maybe
// incorrect, use |BaseDirection()| instead, and 2) margin/border/padding,
// background etc. do not apply to the line box.
const ComputedStyle& Style() const { const ComputedStyle& Style() const {
return layout_object_->StyleRef(UsesFirstLineStyle()); return layout_object_->EffectiveStyle(StyleVariant());
} }
const LayoutObject* GetLayoutObject() const { return layout_object_; } const LayoutObject* GetLayoutObject() const { return layout_object_; }
......
...@@ -269,28 +269,6 @@ void NGPhysicalFragment::Destroy() const { ...@@ -269,28 +269,6 @@ void NGPhysicalFragment::Destroy() const {
} }
} }
const ComputedStyle& NGPhysicalFragment::SlowEffectiveStyle() const {
switch (StyleVariant()) {
case NGStyleVariant::kStandard:
return layout_object_.StyleRef();
case NGStyleVariant::kFirstLine:
return layout_object_.FirstLineStyleRef();
case NGStyleVariant::kEllipsis:
DCHECK_EQ(Type(), kFragmentText);
DCHECK_EQ(StyleVariant(), NGStyleVariant::kEllipsis);
// The ellipsis is styled according to the line style.
// https://drafts.csswg.org/css-ui/#ellipsing-details
// Use first-line style if exists since most cases it is the first line.
// TODO(kojii): Should determine if it's really in the first line.
DCHECK(layout_object_.IsInline());
if (LayoutObject* block = layout_object_.ContainingBlock())
return block->FirstLineStyleRef();
return layout_object_.FirstLineStyleRef();
}
NOTREACHED();
return layout_object_.StyleRef();
}
Node* NGPhysicalFragment::GetNode() const { Node* NGPhysicalFragment::GetNode() const {
return !IsLineBox() ? layout_object_.GetNode() : nullptr; return !IsLineBox() ? layout_object_.GetNode() : nullptr;
} }
......
...@@ -171,9 +171,7 @@ class CORE_EXPORT NGPhysicalFragment ...@@ -171,9 +171,7 @@ class CORE_EXPORT NGPhysicalFragment
// incorrect, use |BaseDirection()| instead, and 2) margin/border/padding, // incorrect, use |BaseDirection()| instead, and 2) margin/border/padding,
// background etc. do not apply to the line box. // background etc. do not apply to the line box.
const ComputedStyle& Style() const { const ComputedStyle& Style() const {
return StyleVariant() == NGStyleVariant::kStandard return layout_object_.EffectiveStyle(StyleVariant());
? layout_object_.StyleRef()
: SlowEffectiveStyle();
} }
Node* GetNode() const; Node* GetNode() const;
......
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