File: ax_text_attributes.cc

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (120 lines) | stat: -rw-r--r-- 4,527 bytes parent folder | download | duplicates (4)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ui/accessibility/ax_text_attributes.h"

#include "ui/accessibility/ax_node_data.h"

namespace ui {

namespace {

void UpdateProperty(ax::mojom::IntAttribute attribute,
                    const AXNodeData& node_data,
                    int* value) {
  int maybe_value = node_data.GetIntAttribute(attribute);
  if (maybe_value || node_data.HasIntAttribute(attribute)) {
    *value = maybe_value;
  }
}

void UpdateProperty(ax::mojom::FloatAttribute attribute,
                    const AXNodeData& node_data,
                    float* value) {
  float maybe_value = node_data.GetFloatAttribute(attribute);
  if (maybe_value || node_data.HasFloatAttribute(attribute)) {
    *value = maybe_value;
  }
}

}  // namespace

AXTextAttributes::AXTextAttributes() = default;

AXTextAttributes::~AXTextAttributes() = default;

AXTextAttributes::AXTextAttributes(const AXNodeData& node_data) {
  UpdateProperty(ax::mojom::IntAttribute::kBackgroundColor, node_data,
                 &background_color);
  UpdateProperty(ax::mojom::IntAttribute::kColor, node_data, &color);
  UpdateProperty(ax::mojom::IntAttribute::kInvalidState, node_data,
                 &invalid_state);
  UpdateProperty(ax::mojom::IntAttribute::kTextOverlineStyle, node_data,
                 &overline_style);
  UpdateProperty(ax::mojom::IntAttribute::kTextDirection, node_data,
                 &text_direction);
  UpdateProperty(ax::mojom::IntAttribute::kTextPosition, node_data,
                 &text_position);
  UpdateProperty(ax::mojom::IntAttribute::kTextStrikethroughStyle, node_data,
                 &strikethrough_style);
  UpdateProperty(ax::mojom::IntAttribute::kTextStyle, node_data, &text_style);
  UpdateProperty(ax::mojom::IntAttribute::kTextUnderlineStyle, node_data,
                 &underline_style);
  UpdateProperty(ax::mojom::FloatAttribute::kFontSize, node_data, &font_size);
  UpdateProperty(ax::mojom::FloatAttribute::kFontWeight, node_data,
                 &font_weight);
  font_family =
      node_data.GetStringAttribute(ax::mojom::StringAttribute::kFontFamily);
  marker_types =
      node_data.GetIntListAttribute(ax::mojom::IntListAttribute::kMarkerTypes);
  highlight_types = node_data.GetIntListAttribute(
      ax::mojom::IntListAttribute::kHighlightTypes);
}

AXTextAttributes::AXTextAttributes(AXTextAttributes&& other)
    : background_color(other.background_color),
      color(other.color),
      invalid_state(other.invalid_state),
      overline_style(other.overline_style),
      strikethrough_style(other.strikethrough_style),
      text_direction(other.text_direction),
      text_position(other.text_position),
      text_style(other.text_style),
      underline_style(other.underline_style),
      font_size(other.font_size),
      font_weight(other.font_weight),
      font_family(std::move(other.font_family)),
      marker_types(std::move(other.marker_types)),
      highlight_types(std::move(other.highlight_types)) {}

AXTextAttributes& AXTextAttributes::operator=(AXTextAttributes&& other) {
  if (this == &other)
    return *this;

  background_color = other.background_color;
  color = other.color;
  invalid_state = other.invalid_state;
  overline_style = other.overline_style;
  strikethrough_style = other.strikethrough_style;
  text_direction = other.text_direction;
  text_position = other.text_position;
  text_style = other.text_style;
  underline_style = other.underline_style;
  font_size = other.font_size;
  font_weight = other.font_weight;
  font_family = other.font_family;
  marker_types = other.marker_types;
  highlight_types = other.highlight_types;

  return *this;
}

bool AXTextAttributes::IsUnset() const {
  return background_color == kUnsetValue && color == kUnsetValue &&
         invalid_state == kUnsetValue && overline_style == kUnsetValue &&
         strikethrough_style == kUnsetValue && text_position == kUnsetValue &&
         font_size == kUnsetValue && font_weight == kUnsetValue &&
         text_style == kUnsetValue && underline_style == kUnsetValue &&
         font_family.length() == 0 && marker_types.size() == 0 &&
         highlight_types.size() == 0;
}

bool AXTextAttributes::HasTextStyle(
    ax::mojom::TextStyle text_style_enum) const {
  return text_style != kUnsetValue &&
         (static_cast<uint32_t>(text_style) &
          (1U << static_cast<uint32_t>(text_style_enum))) != 0;
}

}  // namespace ui