1 // Copyright 2018 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "third_party/blink/renderer/core/paint/fieldset_paint_info.h"
6
7 #include "third_party/blink/renderer/core/style/computed_style.h"
8
9 namespace blink {
10
FieldsetPaintInfo(const ComputedStyle & fieldset_style,const PhysicalSize & fieldset_size,const LayoutRectOutsets & fieldset_borders,const PhysicalRect & legend_border_box)11 FieldsetPaintInfo::FieldsetPaintInfo(const ComputedStyle& fieldset_style,
12 const PhysicalSize& fieldset_size,
13 const LayoutRectOutsets& fieldset_borders,
14 const PhysicalRect& legend_border_box) {
15 if (fieldset_style.IsHorizontalWritingMode()) {
16 // horizontal-tb
17 LayoutUnit legend_size = legend_border_box.size.height;
18 LayoutUnit border_size = fieldset_borders.Top();
19 LayoutUnit legend_excess_size = legend_size - border_size;
20 if (legend_excess_size > LayoutUnit())
21 border_outsets.SetTop(legend_excess_size / 2);
22 legend_cutout_rect = PhysicalRect(legend_border_box.X(), LayoutUnit(),
23 legend_border_box.Width(),
24 std::max(legend_size, border_size));
25 } else {
26 LayoutUnit legend_size = legend_border_box.Width();
27 LayoutUnit border_size;
28 if (fieldset_style.IsFlippedBlocksWritingMode()) {
29 // vertical-rl
30 border_size = fieldset_borders.Right();
31 LayoutUnit legend_excess_size = legend_size - border_size;
32 if (legend_excess_size > LayoutUnit())
33 border_outsets.SetRight(legend_excess_size / 2);
34 } else {
35 // vertical-lr
36 border_size = fieldset_borders.Left();
37 LayoutUnit legend_excess_size = legend_size - border_size;
38 if (legend_excess_size > LayoutUnit())
39 border_outsets.SetLeft(legend_excess_size / 2);
40 }
41 LayoutUnit legend_total_block_size = std::max(legend_size, border_size);
42 legend_cutout_rect =
43 PhysicalRect(LayoutUnit(), legend_border_box.offset.top,
44 legend_total_block_size, legend_border_box.size.height);
45 if (fieldset_style.IsFlippedBlocksWritingMode()) {
46 // Offset cutout to right fieldset edge for vertical-rl
47 LayoutUnit clip_x = fieldset_size.width - legend_total_block_size;
48 legend_cutout_rect.offset.left += clip_x;
49 }
50 }
51 }
52
53 } // namespace blink
54