blob: ae1b5fb8774d053ca4c65485a5b7ccadf63e0e9a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/core/layout/layout_list_marker_image.h"
#include "third_party/blink/renderer/core/layout/intrinsic_sizing_info.h"
#include "third_party/blink/renderer/core/layout/ng/list/layout_ng_list_item.h"
#include "third_party/blink/renderer/core/svg/graphics/svg_image.h"
namespace blink {
LayoutListMarkerImage::LayoutListMarkerImage(Element* element)
: LayoutImage(element) {}
LayoutListMarkerImage* LayoutListMarkerImage::CreateAnonymous(
Document* document) {
LayoutListMarkerImage* object = new LayoutListMarkerImage(nullptr);
object->SetDocumentForAnonymous(document);
return object;
}
bool LayoutListMarkerImage::IsOfType(LayoutObjectType type) const {
return type == kLayoutObjectListMarkerImage || LayoutImage::IsOfType(type);
}
LayoutSize LayoutListMarkerImage::DefaultSize() const {
const SimpleFontData* font_data = Style()->GetFont().PrimaryFont();
DCHECK(font_data);
if (!font_data)
return LayoutSize(kDefaultWidth, kDefaultHeight);
LayoutUnit bullet_width =
font_data->GetFontMetrics().Ascent() / LayoutUnit(2);
return LayoutSize(bullet_width, bullet_width);
}
// Because ImageResource() is always LayoutImageResourceStyleImage. So we could
// use StyleImage::ImageSize to determine the concrete object size with
// default object size(ascent/2 x ascent/2).
void LayoutListMarkerImage::ComputeIntrinsicSizingInfoByDefaultSize(
IntrinsicSizingInfo& intrinsic_sizing_info) const {
FloatSize concrete_size = ImageResource()->ImageSizeWithDefaultSize(
Style()->EffectiveZoom(), DefaultSize());
concrete_size.Scale(ImageDevicePixelRatio());
LayoutSize image_size(RoundedLayoutSize(concrete_size));
intrinsic_sizing_info.size.SetWidth(image_size.Width());
intrinsic_sizing_info.size.SetHeight(image_size.Height());
intrinsic_sizing_info.has_width = true;
intrinsic_sizing_info.has_height = true;
}
void LayoutListMarkerImage::ComputeIntrinsicSizingInfo(
IntrinsicSizingInfo& intrinsic_sizing_info) const {
LayoutImage::ComputeIntrinsicSizingInfo(intrinsic_sizing_info);
// If this is an image without intrinsic width and height, compute the
// concrete object size by using the specified default object size.
if (intrinsic_sizing_info.size.IsEmpty() && ImageResource())
ComputeIntrinsicSizingInfoByDefaultSize(intrinsic_sizing_info);
}
} // namespace blink
|