1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DECLARATION_TEXTFIELD_TEXTFIELD_DECLARATION_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DECLARATION_TEXTFIELD_TEXTFIELD_DECLARATION_H 18 19 #include "bridge/common/dom/dom_type.h" 20 #include "core/common/ime/text_edit_controller.h" 21 #include "core/common/ime/text_input_action.h" 22 #include "core/common/ime/text_input_type.h" 23 #include "core/common/ime/text_selection.h" 24 #include "core/components/common/properties/input_option.h" 25 #include "core/components/declaration/common/declaration.h" 26 #include "core/components/declaration/input/input_declaration.h" 27 #include "core/components/text_field/text_field_controller.h" 28 #include "core/pipeline/base/component.h" 29 30 namespace OHOS::Ace { 31 32 struct TextFieldAttribute : Attribute { 33 bool isValueUpdated = false; 34 std::string value; 35 std::string placeholder; 36 std::string inputFilter; 37 TextSelection selection; 38 Dimension widthReserved; 39 // Obscure the text, for example, password. 40 bool obscure = false; 41 // Whether show counter, should work together with maxLength. 42 bool showCounter = false; 43 // Whether height of textfield can auto-extend. 44 bool extend = false; 45 bool autoFocus = false; 46 bool showEllipsis = false; 47 bool blockRightShade = false; 48 bool isVisible = true; 49 bool resetToStart = true; 50 bool hasSetResetToStart = false; 51 bool showCursor = true; 52 bool enabled = true; 53 bool needFade = false; 54 bool lengthLimited = false; 55 uint32_t maxLength = std::numeric_limits<uint32_t>::max(); 56 uint32_t textMaxLines = 1; 57 58 bool softKeyboardEnabled = true; 59 // Type of input method. 60 TextInputType keyboard = TextInputType::TEXT; 61 // Action when "enter" pressed. 62 TextInputAction action = TextInputAction::UNSPECIFIED; 63 std::string actionLabel; 64 65 // Attribute about header-icon of text-field. 66 std::string iconImage; 67 Dimension iconSize; 68 Dimension iconHotZoneSize; 69 // Icon to control password show or hide. 70 std::string showImage; 71 std::string hideImage; 72 bool showPasswordIcon = true; 73 74 // Menu options of text overlay 75 std::vector<InputOption> inputOptions; 76 }; 77 78 struct TextFieldStyle : Style { 79 Dimension height; 80 81 // style about cursor 82 Dimension cursorRadius; 83 Color cursorColor; 84 bool cursorColorIsSet = false; 85 86 TextAlign textAlign = TextAlign::START; 87 TextFieldOverflowX overflowX = TextFieldOverflowX::HIDDEN; 88 TextStyle textStyle; 89 TextStyle countTextStyle; 90 TextStyle overCountStyle; 91 TextStyle countTextStyleOuter; 92 TextStyle overCountStyleOuter; 93 TextStyle editingStyle; 94 TextStyle placeHoldStyle; 95 InputStyle inputStyle; 96 97 Color textColor; 98 Color focusTextColor; 99 Color placeholderColor; 100 Color focusPlaceholderColor; 101 Color bgColor; 102 Color focusBgColor; 103 Color selectedColor; 104 Color hoverColor; 105 Color pressColor; 106 107 // Style about error text 108 // Whether error text show inner or under. 109 bool errorIsInner = false; 110 TextStyle errorTextStyle; 111 // Spacing between error text and input text. 112 Dimension errorSpacing; 113 Dimension errorBorderWidth; 114 Color errorBorderColor; 115 Border originBorder; 116 HoverAnimationType hoverAnimationType; 117 118 RefPtr<Decoration> decoration; 119 }; 120 121 struct TextFieldEvent : Event { 122 // Trigger when text is changed. 123 EventMarker onTextChange; 124 // Trigger when selection is changed 125 EventMarker onSelectChange; 126 // Trigger when user press "enter" 127 EventMarker onFinishInput; 128 // Trigger when user click 129 EventMarker onTap; 130 // Trigger when user long press 131 EventMarker onLongPress; 132 // Trigger when user click option of menu 133 EventMarker onOptionsClick; 134 // Trigger when user click translate button of text overlay 135 EventMarker onTranslate; 136 // Trigger when user click share button of text overlay 137 EventMarker onShare; 138 // Trigger when user click search button of text overlay 139 EventMarker onSearch; 140 }; 141 142 struct TextFieldMethod : Method { DeleteTextFieldMethod143 void Delete(const RefPtr<TextFieldController>& textFieldController) const 144 { 145 if (textFieldController) { 146 textFieldController->Delete(); 147 } 148 } 149 }; 150 151 class TextFieldDeclaration : public Declaration { 152 DECLARE_ACE_TYPE(TextFieldDeclaration, Declaration); 153 154 public: 155 TextFieldDeclaration() = default; 156 ~TextFieldDeclaration() override = default; 157 158 void InitializeStyle() override; 159 160 bool SetSpecializedAttr(const std::pair<std::string, std::string>& attr) override; 161 bool SetSpecializedStyle(const std::pair<std::string, std::string>& style) override; 162 bool SetSpecializedEvent(int32_t pageId, const std::string& eventId, const std::string& event) override; 163 void CallSpecializedMethod(const std::string& method, const std::string& args) override; 164 void OnRequestFocus(bool shouldFocus) override; 165 GetInputFilter()166 const std::string& GetInputFilter() const 167 { 168 auto& attribute = static_cast<TextFieldAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 169 return attribute.inputFilter; 170 } 171 SetInputFilter(const std::string & inputFilter)172 void SetInputFilter(const std::string& inputFilter) 173 { 174 auto& attribute = MaybeResetAttribute<TextFieldAttribute>(AttributeTag::SPECIALIZED_ATTR); 175 attribute.inputFilter = inputFilter; 176 } 177 GetValue()178 const std::string& GetValue() const 179 { 180 auto& attribute = static_cast<TextFieldAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 181 return attribute.value; 182 } 183 SetValue(const std::string & value)184 void SetValue(const std::string& value) 185 { 186 auto& attribute = MaybeResetAttribute<TextFieldAttribute>(AttributeTag::SPECIALIZED_ATTR); 187 attribute.value = value; 188 attribute.isValueUpdated = true; 189 } 190 IsValueUpdated()191 bool IsValueUpdated() const 192 { 193 auto& attribute = static_cast<TextFieldAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 194 return attribute.isValueUpdated; 195 } 196 SetIsValueUpdated(bool isValueUpdated)197 void SetIsValueUpdated(bool isValueUpdated) 198 { 199 auto& attribute = MaybeResetAttribute<TextFieldAttribute>(AttributeTag::SPECIALIZED_ATTR); 200 attribute.isValueUpdated = isValueUpdated; 201 } 202 SetPlaceHoldStyle(const TextStyle & textstyle)203 void SetPlaceHoldStyle(const TextStyle& textstyle) 204 { 205 auto& style = MaybeResetStyle<TextFieldStyle>(StyleTag::SPECIALIZED_STYLE); 206 style.placeHoldStyle = textstyle; 207 } 208 SetEditingStyle(const TextStyle & textstyle)209 void SetEditingStyle(const TextStyle& textstyle) 210 { 211 auto& style = MaybeResetStyle<TextFieldStyle>(StyleTag::SPECIALIZED_STYLE); 212 style.editingStyle = textstyle; 213 } 214 GetInputStyle()215 InputStyle GetInputStyle() const 216 { 217 auto& style = static_cast<TextFieldStyle&>(GetStyle(StyleTag::SPECIALIZED_STYLE)); 218 return style.inputStyle; 219 } 220 SetInputStyle(InputStyle inputStyle)221 void SetInputStyle(InputStyle inputStyle) 222 { 223 auto& style = MaybeResetStyle<TextFieldStyle>(StyleTag::SPECIALIZED_STYLE); 224 style.inputStyle = inputStyle; 225 } 226 GetPlaceHoldStyle()227 const TextStyle& GetPlaceHoldStyle() const 228 { 229 auto& style = static_cast<TextFieldStyle&>(GetStyle(StyleTag::SPECIALIZED_STYLE)); 230 return style.placeHoldStyle; 231 } 232 GetEditingStyle()233 const TextStyle& GetEditingStyle() const 234 { 235 auto& style = static_cast<TextFieldStyle&>(GetStyle(StyleTag::SPECIALIZED_STYLE)); 236 return style.editingStyle; 237 } 238 GetPlaceholder()239 const std::string& GetPlaceholder() const 240 { 241 auto& attribute = static_cast<TextFieldAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 242 return attribute.placeholder; 243 } 244 SetPlaceholder(const std::string & placeholder)245 void SetPlaceholder(const std::string& placeholder) 246 { 247 auto& attribute = MaybeResetAttribute<TextFieldAttribute>(AttributeTag::SPECIALIZED_ATTR); 248 attribute.placeholder = placeholder; 249 } 250 GetSelection()251 const TextSelection& GetSelection() const 252 { 253 auto& attribute = static_cast<TextFieldAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 254 return attribute.selection; 255 } 256 SetSelectedStart(int32_t selectedStart)257 void SetSelectedStart(int32_t selectedStart) 258 { 259 auto& attribute = MaybeResetAttribute<TextFieldAttribute>(AttributeTag::SPECIALIZED_ATTR); 260 attribute.selection.baseOffset = selectedStart; 261 } 262 SetSelectedEnd(int32_t selectedEnd)263 void SetSelectedEnd(int32_t selectedEnd) 264 { 265 auto& attribute = MaybeResetAttribute<TextFieldAttribute>(AttributeTag::SPECIALIZED_ATTR); 266 attribute.selection.extentOffset = selectedEnd; 267 } 268 GetPlaceholderColor()269 const Color& GetPlaceholderColor() const 270 { 271 auto& style = static_cast<TextFieldStyle&>(GetStyle(StyleTag::SPECIALIZED_STYLE)); 272 return style.placeholderColor; 273 } 274 SetPlaceholderColor(const Color & placeholderColor)275 void SetPlaceholderColor(const Color& placeholderColor) 276 { 277 auto& style = MaybeResetStyle<TextFieldStyle>(StyleTag::SPECIALIZED_STYLE); 278 style.placeholderColor = placeholderColor; 279 } 280 SetTextMaxLines(uint32_t textMaxLines)281 void SetTextMaxLines(uint32_t textMaxLines) 282 { 283 auto& attribute = MaybeResetAttribute<TextFieldAttribute>(AttributeTag::SPECIALIZED_ATTR); 284 attribute.textMaxLines = textMaxLines; 285 } 286 GetTextMaxLines()287 uint32_t GetTextMaxLines() const 288 { 289 auto& attribute = static_cast<TextFieldAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 290 return attribute.textMaxLines; 291 } 292 GetTextAlign()293 TextAlign GetTextAlign() const 294 { 295 auto& style = static_cast<TextFieldStyle&>(GetStyle(StyleTag::SPECIALIZED_STYLE)); 296 return style.textAlign; 297 } 298 SetTextAlign(TextAlign textAlign)299 void SetTextAlign(TextAlign textAlign) 300 { 301 auto& style = MaybeResetStyle<TextFieldStyle>(StyleTag::SPECIALIZED_STYLE); 302 style.textAlign = textAlign; 303 } 304 GetTextStyle()305 TextStyle& GetTextStyle() const 306 { 307 auto& style = static_cast<TextFieldStyle&>(GetStyle(StyleTag::SPECIALIZED_STYLE)); 308 return style.textStyle; 309 } 310 SetTextStyle(const TextStyle & textStyle)311 void SetTextStyle(const TextStyle& textStyle) 312 { 313 auto& style = MaybeResetStyle<TextFieldStyle>(StyleTag::SPECIALIZED_STYLE); 314 style.textStyle = textStyle; 315 } 316 GetErrorTextStyle()317 const TextStyle& GetErrorTextStyle() const 318 { 319 auto& style = static_cast<TextFieldStyle&>(GetStyle(StyleTag::SPECIALIZED_STYLE)); 320 return style.errorTextStyle; 321 } 322 SetErrorTextStyle(const TextStyle & errorTextStyle)323 void SetErrorTextStyle(const TextStyle& errorTextStyle) 324 { 325 auto& style = MaybeResetStyle<TextFieldStyle>(StyleTag::SPECIALIZED_STYLE); 326 style.errorTextStyle = errorTextStyle; 327 } 328 GetErrorSpacing()329 const Dimension& GetErrorSpacing() const 330 { 331 auto& style = static_cast<TextFieldStyle&>(GetStyle(StyleTag::SPECIALIZED_STYLE)); 332 return style.errorSpacing; 333 } 334 SetErrorSpacing(const Dimension & errorSpacing)335 void SetErrorSpacing(const Dimension& errorSpacing) 336 { 337 auto& style = MaybeResetStyle<TextFieldStyle>(StyleTag::SPECIALIZED_STYLE); 338 style.errorSpacing = errorSpacing; 339 } 340 GetErrorIsInner()341 bool GetErrorIsInner() const 342 { 343 auto& style = static_cast<TextFieldStyle&>(GetStyle(StyleTag::SPECIALIZED_STYLE)); 344 return style.errorIsInner; 345 } 346 SetErrorIsInner(bool errorIsInner)347 void SetErrorIsInner(bool errorIsInner) 348 { 349 auto& style = MaybeResetStyle<TextFieldStyle>(StyleTag::SPECIALIZED_STYLE); 350 style.errorIsInner = errorIsInner; 351 } 352 GetErrorBorderWidth()353 const Dimension& GetErrorBorderWidth() const 354 { 355 auto& style = static_cast<TextFieldStyle&>(GetStyle(StyleTag::SPECIALIZED_STYLE)); 356 return style.errorBorderWidth; 357 } 358 SetErrorBorderWidth(const Dimension & errorBorderWidth)359 void SetErrorBorderWidth(const Dimension& errorBorderWidth) 360 { 361 auto& style = MaybeResetStyle<TextFieldStyle>(StyleTag::SPECIALIZED_STYLE); 362 style.errorBorderWidth = errorBorderWidth; 363 } 364 GetErrorBorderColor()365 const Color& GetErrorBorderColor() const 366 { 367 auto& style = static_cast<TextFieldStyle&>(GetStyle(StyleTag::SPECIALIZED_STYLE)); 368 return style.errorBorderColor; 369 } 370 SetErrorBorderColor(const Color & errorBorderColor)371 void SetErrorBorderColor(const Color& errorBorderColor) 372 { 373 auto& style = MaybeResetStyle<TextFieldStyle>(StyleTag::SPECIALIZED_STYLE); 374 style.errorBorderColor = errorBorderColor; 375 } 376 NeedFade()377 bool NeedFade() const 378 { 379 auto& attribute = static_cast<TextFieldAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 380 return attribute.needFade; 381 } 382 SetNeedFade(bool needFade)383 void SetNeedFade(bool needFade) 384 { 385 auto& attribute = MaybeResetAttribute<TextFieldAttribute>(AttributeTag::SPECIALIZED_ATTR); 386 attribute.needFade = needFade; 387 } 388 IsSoftKeyboardEnabled()389 bool IsSoftKeyboardEnabled() const 390 { 391 auto& attribute = static_cast<TextFieldAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 392 return attribute.softKeyboardEnabled; 393 } 394 SetSoftKeyboardEnabled(bool softKeyboardEnabled)395 void SetSoftKeyboardEnabled(bool softKeyboardEnabled) 396 { 397 auto& attribute = MaybeResetAttribute<TextFieldAttribute>(AttributeTag::SPECIALIZED_ATTR); 398 attribute.softKeyboardEnabled = softKeyboardEnabled; 399 } 400 GetDecoration()401 RefPtr<Decoration> GetDecoration() const 402 { 403 auto& style = static_cast<TextFieldStyle&>(GetStyle(StyleTag::SPECIALIZED_STYLE)); 404 if (!style.decoration) { 405 LOGE("GetStyle returns errStyle, contains null decoration"); 406 style.decoration = AceType::MakeRefPtr<Decoration>(); 407 } 408 return style.decoration; 409 } 410 SetDecoration(const RefPtr<Decoration> & decoration)411 void SetDecoration(const RefPtr<Decoration>& decoration) 412 { 413 auto& style = MaybeResetStyle<TextFieldStyle>(StyleTag::SPECIALIZED_STYLE); 414 style.decoration = decoration; 415 } 416 SetOriginBorder(const Border & originBorder)417 void SetOriginBorder(const Border& originBorder) 418 { 419 auto& style = MaybeResetStyle<TextFieldStyle>(StyleTag::SPECIALIZED_STYLE); 420 style.originBorder = originBorder; 421 } 422 GetOriginBorder()423 const Border& GetOriginBorder() const 424 { 425 auto& style = static_cast<TextFieldStyle&>(GetStyle(StyleTag::SPECIALIZED_STYLE)); 426 return style.originBorder; 427 } 428 ShowCursor()429 bool ShowCursor() const 430 { 431 auto& attribute = static_cast<TextFieldAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 432 return attribute.showCursor; 433 } 434 SetShowCursor(bool showCursor)435 void SetShowCursor(bool showCursor) 436 { 437 auto& attribute = MaybeResetAttribute<TextFieldAttribute>(AttributeTag::SPECIALIZED_ATTR); 438 attribute.showCursor = showCursor; 439 } 440 NeedObscure()441 bool NeedObscure() const 442 { 443 auto& attribute = static_cast<TextFieldAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 444 return attribute.obscure; 445 } 446 SetObscure(bool obscure)447 void SetObscure(bool obscure) 448 { 449 auto& attribute = MaybeResetAttribute<TextFieldAttribute>(AttributeTag::SPECIALIZED_ATTR); 450 attribute.obscure = obscure; 451 } 452 IsEnabled()453 bool IsEnabled() const 454 { 455 auto& attribute = static_cast<TextFieldAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 456 return attribute.enabled; 457 } 458 SetEnabled(bool enable)459 void SetEnabled(bool enable) 460 { 461 auto& attribute = MaybeResetAttribute<TextFieldAttribute>(AttributeTag::SPECIALIZED_ATTR); 462 attribute.enabled = enable; 463 } 464 GetTextInputType()465 TextInputType GetTextInputType() const 466 { 467 auto& attribute = static_cast<TextFieldAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 468 return attribute.keyboard; 469 } 470 SetTextInputType(TextInputType type)471 void SetTextInputType(TextInputType type) 472 { 473 auto& attribute = MaybeResetAttribute<TextFieldAttribute>(AttributeTag::SPECIALIZED_ATTR); 474 attribute.keyboard = type; 475 } 476 GetAction()477 TextInputAction GetAction() const 478 { 479 auto& attribute = static_cast<TextFieldAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 480 return attribute.action; 481 } 482 SetAction(TextInputAction action)483 void SetAction(TextInputAction action) 484 { 485 auto& attribute = MaybeResetAttribute<TextFieldAttribute>(AttributeTag::SPECIALIZED_ATTR); 486 attribute.action = action; 487 } 488 SetCursorColor(const Color & color)489 void SetCursorColor(const Color& color) 490 { 491 auto& style = MaybeResetStyle<TextFieldStyle>(StyleTag::SPECIALIZED_STYLE); 492 style.cursorColor = color; 493 style.cursorColorIsSet = true; 494 } 495 GetCursorColor()496 const Color& GetCursorColor() 497 { 498 auto& style = static_cast<TextFieldStyle&>(GetStyle(StyleTag::SPECIALIZED_STYLE)); 499 return style.cursorColor; 500 } 501 IsCursorColorSet()502 bool IsCursorColorSet() const 503 { 504 auto& style = static_cast<TextFieldStyle&>(GetStyle(StyleTag::SPECIALIZED_STYLE)); 505 return style.cursorColorIsSet; 506 } 507 SetCursorRadius(const Dimension & radius)508 void SetCursorRadius(const Dimension& radius) 509 { 510 auto& style = MaybeResetStyle<TextFieldStyle>(StyleTag::SPECIALIZED_STYLE); 511 style.cursorRadius = radius; 512 } 513 GetCursorRadius()514 const Dimension& GetCursorRadius() const 515 { 516 auto& style = static_cast<TextFieldStyle&>(GetStyle(StyleTag::SPECIALIZED_STYLE)); 517 return style.cursorRadius; 518 } 519 GetActionLabel()520 const std::string& GetActionLabel() const 521 { 522 auto& attribute = static_cast<TextFieldAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 523 return attribute.actionLabel; 524 } 525 SetActionLabel(const std::string & actionLabel)526 void SetActionLabel(const std::string& actionLabel) 527 { 528 auto& attribute = MaybeResetAttribute<TextFieldAttribute>(AttributeTag::SPECIALIZED_ATTR); 529 attribute.actionLabel = actionLabel; 530 } 531 GetMaxLength()532 uint32_t GetMaxLength() const 533 { 534 auto& attribute = static_cast<TextFieldAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 535 return attribute.maxLength; 536 } 537 SetMaxLength(uint32_t maxLength)538 void SetMaxLength(uint32_t maxLength) 539 { 540 auto& attribute = MaybeResetAttribute<TextFieldAttribute>(AttributeTag::SPECIALIZED_ATTR); 541 attribute.maxLength = maxLength; 542 attribute.lengthLimited = true; 543 } 544 IsTextLengthLimited()545 bool IsTextLengthLimited() const 546 { 547 auto& attribute = static_cast<TextFieldAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 548 return attribute.lengthLimited; 549 } 550 GetHeight()551 const Dimension& GetHeight() const 552 { 553 auto& style = static_cast<TextFieldStyle&>(GetStyle(StyleTag::SPECIALIZED_STYLE)); 554 return style.height; 555 } 556 SetHeight(const Dimension & height)557 void SetHeight(const Dimension& height) 558 { 559 auto& style = MaybeResetStyle<TextFieldStyle>(StyleTag::SPECIALIZED_STYLE); 560 style.height = height; 561 } 562 GetOverflowX()563 TextFieldOverflowX& GetOverflowX() const 564 { 565 auto& style = static_cast<TextFieldStyle&>(GetStyle(StyleTag::SPECIALIZED_STYLE)); 566 return style.overflowX; 567 } 568 SetOverflowX(const TextFieldOverflowX & overflowX)569 void SetOverflowX(const TextFieldOverflowX& overflowX) 570 { 571 auto& style = static_cast<TextFieldStyle&>(GetStyle(StyleTag::SPECIALIZED_STYLE)); 572 style.overflowX = overflowX; 573 } 574 GetAutoFocus()575 bool GetAutoFocus() const 576 { 577 auto& attribute = static_cast<TextFieldAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 578 return attribute.autoFocus; 579 } 580 SetAutoFocus(bool autoFocus)581 void SetAutoFocus(bool autoFocus) 582 { 583 auto& attribute = MaybeResetAttribute<TextFieldAttribute>(AttributeTag::SPECIALIZED_ATTR); 584 attribute.autoFocus = autoFocus; 585 } 586 IsExtend()587 bool IsExtend() const 588 { 589 auto& attribute = static_cast<TextFieldAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 590 return attribute.extend; 591 } 592 SetExtend(bool extend)593 void SetExtend(bool extend) 594 { 595 auto& attribute = MaybeResetAttribute<TextFieldAttribute>(AttributeTag::SPECIALIZED_ATTR); 596 attribute.extend = extend; 597 } 598 ShowEllipsis()599 bool ShowEllipsis() const 600 { 601 auto& attribute = static_cast<TextFieldAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 602 return attribute.showEllipsis; 603 } 604 SetShowEllipsis(bool showEllipsis)605 void SetShowEllipsis(bool showEllipsis) 606 { 607 auto& attribute = MaybeResetAttribute<TextFieldAttribute>(AttributeTag::SPECIALIZED_ATTR); 608 attribute.showEllipsis = showEllipsis; 609 } 610 ShowPasswordIcon()611 bool ShowPasswordIcon() const 612 { 613 auto& attribute = static_cast<TextFieldAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 614 return attribute.showPasswordIcon; 615 } 616 SetShowPasswordIcon(bool showPasswordIcon)617 void SetShowPasswordIcon(bool showPasswordIcon) 618 { 619 auto& attribute = MaybeResetAttribute<TextFieldAttribute>(AttributeTag::SPECIALIZED_ATTR); 620 attribute.showPasswordIcon = showPasswordIcon; 621 } 622 GetImageFill()623 const std::optional<Color>& GetImageFill() const 624 { 625 auto& imageStyle = static_cast<CommonImageStyle&>(GetStyle(StyleTag::COMMON_IMAGE_STYLE)); 626 return imageStyle.imageFill; 627 } 628 SetImageFill(const std::optional<Color> & color)629 void SetImageFill(const std::optional<Color>& color) 630 { 631 auto& imageStyle = MaybeResetStyle<CommonImageStyle>(StyleTag::COMMON_IMAGE_STYLE); 632 if (color != std::nullopt) { 633 imageStyle.imageFill = color.value(); 634 } 635 } 636 GetIconImage()637 const std::string& GetIconImage() const 638 { 639 auto& attribute = static_cast<TextFieldAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 640 return attribute.iconImage; 641 } 642 SetIconImage(const std::string & iconImage)643 void SetIconImage(const std::string& iconImage) 644 { 645 auto& attribute = MaybeResetAttribute<TextFieldAttribute>(AttributeTag::SPECIALIZED_ATTR); 646 attribute.iconImage = iconImage; 647 } 648 GetShowIconImage()649 const std::string& GetShowIconImage() const 650 { 651 auto& attribute = static_cast<TextFieldAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 652 return attribute.showImage; 653 } 654 SetShowIconImage(const std::string & showImage)655 void SetShowIconImage(const std::string& showImage) 656 { 657 auto& attribute = MaybeResetAttribute<TextFieldAttribute>(AttributeTag::SPECIALIZED_ATTR); 658 attribute.showImage = showImage; 659 } 660 GetHideIconImage()661 const std::string& GetHideIconImage() const 662 { 663 auto& attribute = static_cast<TextFieldAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 664 return attribute.hideImage; 665 } 666 SetHideIconImage(const std::string & hideImage)667 void SetHideIconImage(const std::string& hideImage) 668 { 669 auto& attribute = MaybeResetAttribute<TextFieldAttribute>(AttributeTag::SPECIALIZED_ATTR); 670 attribute.hideImage = hideImage; 671 } 672 GetIconSize()673 const Dimension& GetIconSize() const 674 { 675 auto& attribute = static_cast<TextFieldAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 676 return attribute.iconSize; 677 } 678 SetIconSize(const Dimension & iconSize)679 void SetIconSize(const Dimension& iconSize) 680 { 681 auto& attribute = MaybeResetAttribute<TextFieldAttribute>(AttributeTag::SPECIALIZED_ATTR); 682 attribute.iconSize = iconSize; 683 } 684 GetIconHotZoneSize()685 const Dimension& GetIconHotZoneSize() const 686 { 687 auto& attribute = static_cast<TextFieldAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 688 return attribute.iconHotZoneSize; 689 } 690 SetIconHotZoneSize(const Dimension & iconHotZoneSize)691 void SetIconHotZoneSize(const Dimension& iconHotZoneSize) 692 { 693 auto& attribute = MaybeResetAttribute<TextFieldAttribute>(AttributeTag::SPECIALIZED_ATTR); 694 attribute.iconHotZoneSize = iconHotZoneSize; 695 } 696 SetFocusBgColor(const Color & focusBgColor)697 void SetFocusBgColor(const Color& focusBgColor) 698 { 699 auto& style = MaybeResetStyle<TextFieldStyle>(StyleTag::SPECIALIZED_STYLE); 700 style.focusBgColor = focusBgColor; 701 } 702 GetFocusBgColor()703 const Color& GetFocusBgColor() 704 { 705 auto& style = static_cast<TextFieldStyle&>(GetStyle(StyleTag::SPECIALIZED_STYLE)); 706 return style.focusBgColor; 707 } 708 SetFocusPlaceholderColor(const Color & focusPlaceholderColor)709 void SetFocusPlaceholderColor(const Color& focusPlaceholderColor) 710 { 711 auto& style = MaybeResetStyle<TextFieldStyle>(StyleTag::SPECIALIZED_STYLE); 712 style.focusPlaceholderColor = focusPlaceholderColor; 713 } 714 GetFocusPlaceholderColor()715 const Color& GetFocusPlaceholderColor() 716 { 717 auto& style = static_cast<TextFieldStyle&>(GetStyle(StyleTag::SPECIALIZED_STYLE)); 718 return style.focusPlaceholderColor; 719 } 720 SetFocusTextColor(const Color & focusTextColor)721 void SetFocusTextColor(const Color& focusTextColor) 722 { 723 auto& style = MaybeResetStyle<TextFieldStyle>(StyleTag::SPECIALIZED_STYLE); 724 style.focusTextColor = focusTextColor; 725 } 726 GetFocusTextColor()727 const Color& GetFocusTextColor() 728 { 729 auto& style = static_cast<TextFieldStyle&>(GetStyle(StyleTag::SPECIALIZED_STYLE)); 730 return style.focusTextColor; 731 } 732 SetBgColor(const Color & bgColor)733 void SetBgColor(const Color& bgColor) 734 { 735 auto& style = MaybeResetStyle<TextFieldStyle>(StyleTag::SPECIALIZED_STYLE); 736 style.bgColor = bgColor; 737 } 738 GetBgColor()739 const Color& GetBgColor() 740 { 741 auto& style = static_cast<TextFieldStyle&>(GetStyle(StyleTag::SPECIALIZED_STYLE)); 742 return style.bgColor; 743 } 744 SetTextColor(const Color & textColor)745 void SetTextColor(const Color& textColor) 746 { 747 auto& style = MaybeResetStyle<TextFieldStyle>(StyleTag::SPECIALIZED_STYLE); 748 style.textColor = textColor; 749 } 750 GetTextColor()751 const Color& GetTextColor() 752 { 753 auto& style = static_cast<TextFieldStyle&>(GetStyle(StyleTag::SPECIALIZED_STYLE)); 754 return style.textColor; 755 } 756 SetWidthReserved(const Dimension & widthReserved)757 void SetWidthReserved(const Dimension& widthReserved) 758 { 759 auto& attribute = MaybeResetAttribute<TextFieldAttribute>(AttributeTag::SPECIALIZED_ATTR); 760 attribute.widthReserved = widthReserved; 761 } 762 GetWidthReserved()763 const Dimension& GetWidthReserved() const 764 { 765 auto& attribute = static_cast<TextFieldAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 766 return attribute.widthReserved; 767 } 768 GetSelectedColor()769 const Color& GetSelectedColor() const 770 { 771 auto& style = static_cast<TextFieldStyle&>(GetStyle(StyleTag::SPECIALIZED_STYLE)); 772 return style.selectedColor; 773 } 774 SetSelectedColor(const Color & selectedColor)775 void SetSelectedColor(const Color& selectedColor) 776 { 777 auto& style = MaybeResetStyle<TextFieldStyle>(StyleTag::SPECIALIZED_STYLE); 778 style.selectedColor = selectedColor; 779 } 780 GetHoverColor()781 const Color& GetHoverColor() const 782 { 783 auto& style = static_cast<TextFieldStyle&>(GetStyle(StyleTag::SPECIALIZED_STYLE)); 784 return style.hoverColor; 785 } 786 SetHoverColor(const Color & hoverColor)787 void SetHoverColor(const Color& hoverColor) 788 { 789 auto& style = MaybeResetStyle<TextFieldStyle>(StyleTag::SPECIALIZED_STYLE); 790 style.hoverColor = hoverColor; 791 } 792 GetPressColor()793 const Color& GetPressColor() const 794 { 795 auto& style = static_cast<TextFieldStyle&>(GetStyle(StyleTag::SPECIALIZED_STYLE)); 796 return style.pressColor; 797 } 798 SetPressColor(const Color & pressColor)799 void SetPressColor(const Color& pressColor) 800 { 801 auto& style = MaybeResetStyle<TextFieldStyle>(StyleTag::SPECIALIZED_STYLE); 802 style.pressColor = pressColor; 803 } 804 SetBlockRightShade(bool blockRightShade)805 void SetBlockRightShade(bool blockRightShade) 806 { 807 auto& attribute = MaybeResetAttribute<TextFieldAttribute>(AttributeTag::SPECIALIZED_ATTR); 808 attribute.blockRightShade = blockRightShade; 809 } 810 GetBlockRightShade()811 bool GetBlockRightShade() const 812 { 813 auto& attribute = static_cast<TextFieldAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 814 return attribute.blockRightShade; 815 } 816 SetIsVisible(bool isVisible)817 void SetIsVisible(bool isVisible) 818 { 819 auto& attribute = MaybeResetAttribute<TextFieldAttribute>(AttributeTag::SPECIALIZED_ATTR); 820 attribute.isVisible = isVisible; 821 } 822 IsVisible()823 bool IsVisible() const 824 { 825 auto& attribute = static_cast<TextFieldAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 826 return attribute.isVisible; 827 } 828 SetResetToStart(bool resetToStart)829 void SetResetToStart(bool resetToStart) 830 { 831 auto& attribute = MaybeResetAttribute<TextFieldAttribute>(AttributeTag::SPECIALIZED_ATTR); 832 attribute.resetToStart = resetToStart; 833 attribute.hasSetResetToStart = true; 834 } 835 GetResetToStart()836 bool GetResetToStart() const 837 { 838 auto& attribute = static_cast<TextFieldAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 839 return attribute.resetToStart; 840 } 841 HasSetResetToStart()842 bool HasSetResetToStart() const 843 { 844 auto& attribute = static_cast<TextFieldAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 845 return attribute.hasSetResetToStart; 846 } 847 SetShowCounter(bool showCounter)848 void SetShowCounter(bool showCounter) 849 { 850 auto& attribute = MaybeResetAttribute<TextFieldAttribute>(AttributeTag::SPECIALIZED_ATTR); 851 attribute.showCounter = showCounter; 852 } 853 ShowCounter()854 bool ShowCounter() const 855 { 856 auto& attribute = static_cast<TextFieldAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 857 return attribute.showCounter; 858 } 859 SetCountTextStyle(const TextStyle & countTextStyle)860 void SetCountTextStyle(const TextStyle& countTextStyle) 861 { 862 auto& style = MaybeResetStyle<TextFieldStyle>(StyleTag::SPECIALIZED_STYLE); 863 style.countTextStyle = countTextStyle; 864 } 865 GetCountTextStyle()866 const TextStyle& GetCountTextStyle() const 867 { 868 auto& style = static_cast<TextFieldStyle&>(GetStyle(StyleTag::SPECIALIZED_STYLE)); 869 return style.countTextStyle; 870 } 871 SetOverCountStyle(const TextStyle & overCountStyle)872 void SetOverCountStyle(const TextStyle& overCountStyle) 873 { 874 auto& style = MaybeResetStyle<TextFieldStyle>(StyleTag::SPECIALIZED_STYLE); 875 style.overCountStyle = overCountStyle; 876 } 877 GetOverCountStyle()878 const TextStyle& GetOverCountStyle() const 879 { 880 auto& style = static_cast<TextFieldStyle&>(GetStyle(StyleTag::SPECIALIZED_STYLE)); 881 return style.overCountStyle; 882 } 883 SetCountTextStyleOuter(const TextStyle & countTextStyleOuter)884 void SetCountTextStyleOuter(const TextStyle& countTextStyleOuter) 885 { 886 auto& style = MaybeResetStyle<TextFieldStyle>(StyleTag::SPECIALIZED_STYLE); 887 style.countTextStyleOuter = countTextStyleOuter; 888 } 889 GetCountTextStyleOuter()890 const TextStyle& GetCountTextStyleOuter() const 891 { 892 auto& style = static_cast<TextFieldStyle&>(GetStyle(StyleTag::SPECIALIZED_STYLE)); 893 return style.countTextStyleOuter; 894 } 895 SetOverCountStyleOuter(const TextStyle & overCountStyleOuter)896 void SetOverCountStyleOuter(const TextStyle& overCountStyleOuter) 897 { 898 auto& style = MaybeResetStyle<TextFieldStyle>(StyleTag::SPECIALIZED_STYLE); 899 style.overCountStyleOuter = overCountStyleOuter; 900 } 901 GetOverCountStyleOuter()902 const TextStyle& GetOverCountStyleOuter() const 903 { 904 auto& style = static_cast<TextFieldStyle&>(GetStyle(StyleTag::SPECIALIZED_STYLE)); 905 return style.overCountStyleOuter; 906 } 907 SetHoverAnimationType(HoverAnimationType animationType)908 void SetHoverAnimationType(HoverAnimationType animationType) 909 { 910 auto& style = static_cast<TextFieldStyle&>(GetStyle(StyleTag::SPECIALIZED_STYLE)); 911 style.hoverAnimationType = animationType; 912 } 913 GetHoverAnimationType()914 HoverAnimationType GetHoverAnimationType() const 915 { 916 auto& style = static_cast<TextFieldStyle&>(GetStyle(StyleTag::SPECIALIZED_STYLE)); 917 return style.hoverAnimationType; 918 } 919 SetInputOptions(const std::vector<InputOption> & inputOptions)920 void SetInputOptions(const std::vector<InputOption>& inputOptions) 921 { 922 auto& attribute = MaybeResetAttribute<TextFieldAttribute>(AttributeTag::SPECIALIZED_ATTR); 923 attribute.inputOptions = inputOptions; 924 } 925 GetInputOptions()926 const std::vector<InputOption>& GetInputOptions() const 927 { 928 auto& attribute = static_cast<TextFieldAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 929 return attribute.inputOptions; 930 } 931 GetOnTextChange()932 const EventMarker& GetOnTextChange() const 933 { 934 auto& event = static_cast<TextFieldEvent&>(GetEvent(EventTag::SPECIALIZED_EVENT)); 935 return event.onTextChange; 936 } 937 SetOnTextChange(const EventMarker & onTextChange)938 void SetOnTextChange(const EventMarker& onTextChange) 939 { 940 auto& event = MaybeResetEvent<TextFieldEvent>(EventTag::SPECIALIZED_EVENT); 941 event.onTextChange = onTextChange; 942 } 943 SetOnTextChangeFunction(std::function<void (const std::string &)> && onTextChangeCallback)944 void SetOnTextChangeFunction(std::function<void(const std::string&)>&& onTextChangeCallback) 945 { 946 auto& event = MaybeResetEvent<TextFieldEvent>(EventTag::SPECIALIZED_EVENT); 947 event.onTextChange.SetUiStrFunction(std::move(onTextChangeCallback)); 948 } 949 GetOnSelectChange()950 const EventMarker& GetOnSelectChange() const 951 { 952 auto& event = static_cast<TextFieldEvent&>(GetEvent(EventTag::SPECIALIZED_EVENT)); 953 return event.onSelectChange; 954 } 955 SetOnSelectChange(const EventMarker & onSelectChange)956 void SetOnSelectChange(const EventMarker& onSelectChange) 957 { 958 auto& event = MaybeResetEvent<TextFieldEvent>(EventTag::SPECIALIZED_EVENT); 959 event.onSelectChange = onSelectChange; 960 } 961 GetOnFinishInput()962 const EventMarker& GetOnFinishInput() const 963 { 964 auto& event = static_cast<TextFieldEvent&>(GetEvent(EventTag::SPECIALIZED_EVENT)); 965 return event.onFinishInput; 966 } 967 SetOnFinishInput(const EventMarker & onFinishInput)968 void SetOnFinishInput(const EventMarker& onFinishInput) 969 { 970 auto& event = MaybeResetEvent<TextFieldEvent>(EventTag::SPECIALIZED_EVENT); 971 event.onFinishInput = onFinishInput; 972 } 973 GetOnTap()974 const EventMarker& GetOnTap() const 975 { 976 auto& event = static_cast<TextFieldEvent&>(GetEvent(EventTag::SPECIALIZED_EVENT)); 977 return event.onTap; 978 } 979 SetOnTap(const EventMarker & onTap)980 void SetOnTap(const EventMarker& onTap) 981 { 982 auto& event = MaybeResetEvent<TextFieldEvent>(EventTag::SPECIALIZED_EVENT); 983 event.onTap = onTap; 984 } 985 GetOnLongPress()986 const EventMarker& GetOnLongPress() const 987 { 988 auto& event = static_cast<TextFieldEvent&>(GetEvent(EventTag::SPECIALIZED_EVENT)); 989 return event.onLongPress; 990 } 991 SetOnLongPress(const EventMarker & onLongPress)992 void SetOnLongPress(const EventMarker& onLongPress) 993 { 994 auto& event = MaybeResetEvent<TextFieldEvent>(EventTag::SPECIALIZED_EVENT); 995 event.onLongPress = onLongPress; 996 } 997 GetOnOptionsClick()998 const EventMarker& GetOnOptionsClick() const 999 { 1000 auto& event = static_cast<TextFieldEvent&>(GetEvent(EventTag::SPECIALIZED_EVENT)); 1001 return event.onOptionsClick; 1002 } 1003 SetOnOptionsClick(const EventMarker & onOptionsClick)1004 void SetOnOptionsClick(const EventMarker& onOptionsClick) 1005 { 1006 auto& event = MaybeResetEvent<TextFieldEvent>(EventTag::SPECIALIZED_EVENT); 1007 event.onOptionsClick = onOptionsClick; 1008 } 1009 GetOnTranslate()1010 const EventMarker& GetOnTranslate() const 1011 { 1012 auto& event = static_cast<TextFieldEvent&>(GetEvent(EventTag::SPECIALIZED_EVENT)); 1013 return event.onTranslate; 1014 } 1015 SetOnTranslate(const EventMarker & onTranslate)1016 void SetOnTranslate(const EventMarker& onTranslate) 1017 { 1018 auto& event = MaybeResetEvent<TextFieldEvent>(EventTag::SPECIALIZED_EVENT); 1019 event.onTranslate = onTranslate; 1020 } 1021 GetOnShare()1022 const EventMarker& GetOnShare() const 1023 { 1024 auto& event = static_cast<TextFieldEvent&>(GetEvent(EventTag::SPECIALIZED_EVENT)); 1025 return event.onShare; 1026 } 1027 SetOnShare(const EventMarker & onShare)1028 void SetOnShare(const EventMarker& onShare) 1029 { 1030 auto& event = MaybeResetEvent<TextFieldEvent>(EventTag::SPECIALIZED_EVENT); 1031 event.onShare = onShare; 1032 } 1033 GetOnSearch()1034 const EventMarker& GetOnSearch() const 1035 { 1036 auto& event = static_cast<TextFieldEvent&>(GetEvent(EventTag::SPECIALIZED_EVENT)); 1037 return event.onSearch; 1038 } 1039 SetOnSearch(const EventMarker & onSearch)1040 void SetOnSearch(const EventMarker& onSearch) 1041 { 1042 auto& event = MaybeResetEvent<TextFieldEvent>(EventTag::SPECIALIZED_EVENT); 1043 event.onSearch = onSearch; 1044 } 1045 GetTextEditController()1046 const RefPtr<TextEditController>& GetTextEditController() const 1047 { 1048 return textEditController_; 1049 } 1050 SetTextEditController(const RefPtr<TextEditController> & controller)1051 void SetTextEditController(const RefPtr<TextEditController>& controller) 1052 { 1053 textEditController_ = controller; 1054 } 1055 GetTextFieldController()1056 const RefPtr<TextFieldController>& GetTextFieldController() const 1057 { 1058 return textFieldController_; 1059 } 1060 SetTextFieldController(const RefPtr<TextFieldController> & controller)1061 void SetTextFieldController(const RefPtr<TextFieldController>& controller) 1062 { 1063 textFieldController_ = controller; 1064 } 1065 HasBoxRadius()1066 bool HasBoxRadius() const 1067 { 1068 return hasBoxRadius_; 1069 } 1070 1071 protected: 1072 void InitSpecialized() override; 1073 1074 private: 1075 bool hasBoxRadius_ = false; 1076 RefPtr<TextEditController> textEditController_; 1077 RefPtr<TextFieldController> textFieldController_; 1078 }; 1079 1080 } // namespace OHOS::Ace 1081 1082 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DECLARATION_TEXTFIELD_TEXTFIELD_DECLARATION_H 1083