1 /*
2 * Copyright (C) 2024 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "form_widget_info.h"
18
19 #include <string>
20 #include <vector>
21
22 #include "rect.h"
23
24 using std::vector;
25
26 namespace pdfClient {
27
28 const Rectangle_i kDefaultRect = IntRect(-1, -1, -1, -1);
29 const float kAutoSizeFontSize = 0;
30
FormWidgetInfo()31 FormWidgetInfo::FormWidgetInfo()
32 : widget_type_(-1),
33 widget_index_(-1),
34 widget_rect_(kDefaultRect),
35 read_only_(false),
36 editable_text_(false),
37 multiselect_(false),
38 multi_line_text_(false),
39 max_length_(-1),
40 font_size_(kAutoSizeFontSize) {}
41
~FormWidgetInfo()42 FormWidgetInfo::~FormWidgetInfo() {}
43
FoundWidget()44 bool FormWidgetInfo::FoundWidget() {
45 return widget_type_ >= 0;
46 }
47
OptionCount() const48 int FormWidgetInfo::OptionCount() const {
49 return options_.size();
50 }
51
HasOptions() const52 bool FormWidgetInfo::HasOptions() const {
53 return !options_.empty();
54 }
55
widget_type() const56 int FormWidgetInfo::widget_type() const {
57 return widget_type_;
58 }
59
set_widget_type(int widget_type)60 void FormWidgetInfo::set_widget_type(int widget_type) {
61 widget_type_ = widget_type;
62 }
63
widget_index() const64 int FormWidgetInfo::widget_index() const {
65 return widget_index_;
66 }
67
set_widget_index(int widget_index)68 void FormWidgetInfo::set_widget_index(int widget_index) {
69 widget_index_ = widget_index;
70 }
71
widget_rect() const72 Rectangle_i FormWidgetInfo::widget_rect() const {
73 return widget_rect_;
74 }
75
set_widget_rect(Rectangle_i widget_rect)76 void FormWidgetInfo::set_widget_rect(Rectangle_i widget_rect) {
77 widget_rect_ = widget_rect;
78 }
79
read_only() const80 bool FormWidgetInfo::read_only() const {
81 return read_only_;
82 }
83
set_read_only(bool read_only)84 void FormWidgetInfo::set_read_only(bool read_only) {
85 read_only_ = read_only;
86 }
87
text_value() const88 std::string FormWidgetInfo::text_value() const {
89 return text_value_;
90 }
91
set_text_value(std::string_view text_value)92 void FormWidgetInfo::set_text_value(std::string_view text_value) {
93 text_value_ = std::string(text_value);
94 }
95
accessibility_label() const96 std::string FormWidgetInfo::accessibility_label() const {
97 return accessibility_label_;
98 }
99
set_accessibility_label(std::string_view accessibility_label)100 void FormWidgetInfo::set_accessibility_label(std::string_view accessibility_label) {
101 accessibility_label_ = std::string(accessibility_label);
102 }
103
editable_text() const104 bool FormWidgetInfo::editable_text() const {
105 return editable_text_;
106 }
107
set_editable_text(bool editable_text)108 void FormWidgetInfo::set_editable_text(bool editable_text) {
109 editable_text_ = editable_text;
110 }
111
multiselect() const112 bool FormWidgetInfo::multiselect() const {
113 return multiselect_;
114 }
115
set_multiselect(bool multiselect)116 void FormWidgetInfo::set_multiselect(bool multiselect) {
117 multiselect_ = multiselect;
118 }
119
multi_line_text() const120 bool FormWidgetInfo::multi_line_text() const {
121 return multi_line_text_;
122 }
123
set_multi_line_text(bool multi_line_text)124 void FormWidgetInfo::set_multi_line_text(bool multi_line_text) {
125 multi_line_text_ = multi_line_text;
126 }
127
max_length() const128 int FormWidgetInfo::max_length() const {
129 return max_length_;
130 }
131
set_max_length(int max_length)132 void FormWidgetInfo::set_max_length(int max_length) {
133 max_length_ = max_length;
134 }
135
font_size() const136 float FormWidgetInfo::font_size() const {
137 return font_size_;
138 }
139
set_font_size(float font_size)140 void FormWidgetInfo::set_font_size(float font_size) {
141 font_size_ = font_size;
142 }
143
options() const144 const vector<Option>& FormWidgetInfo::options() const {
145 return options_;
146 }
147
set_options(const vector<Option> & options)148 void FormWidgetInfo::set_options(const vector<Option>& options) {
149 options_ = options;
150 }
151
152 } // namespace pdfClient