• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "core/components/declaration/textarea/textarea_declaration.h"
17 
18 #include "base/utils/string_utils.h"
19 #include "core/components/declaration/common/declaration_constants.h"
20 #include "frameworks/bridge/common/dom/input/dom_textfield_util.h"
21 #include "frameworks/bridge/common/utils/utils.h"
22 #include "frameworks/core/components/text_field/textfield_theme.h"
23 
24 namespace OHOS::Ace {
25 namespace {
26 
27 constexpr uint32_t TEXTAREA_MAXLENGTH_VALUE_DEFAULT = std::numeric_limits<uint32_t>::max();
28 
29 } // namespace
30 
31 using namespace Framework;
32 
33 using TextareaMap = std::unordered_map<std::string, void (*)(const std::string&, TextareaDeclaration&)>;
34 
TextareaDeclaration()35 TextareaDeclaration::TextareaDeclaration()
36 {
37     textFieldDeclaration_ = AceType::MakeRefPtr<TextFieldDeclaration>();
38     textFieldDeclaration_->BindPipelineContext(pipelineContext_);
39     textFieldDeclaration_->Init();
40     textFieldDeclaration_->SetTextInputType(TextInputType::MULTILINE);
41     textFieldDeclaration_->SetTextEditController(AceType::MakeRefPtr<TextEditController>());
42     textFieldDeclaration_->SetTextFieldController(AceType::MakeRefPtr<TextFieldController>());
43 }
44 
InitializeStyle()45 void TextareaDeclaration::InitializeStyle()
46 {
47     auto theme = GetTheme<TextFieldTheme>();
48     if (!theme || !textFieldDeclaration_) {
49         return;
50     }
51 
52     textFieldDeclaration_->SetTextMaxLines(TEXTAREA_MAXLENGTH_VALUE_DEFAULT);
53     textFieldDeclaration_->SetCursorColor(theme->GetCursorColor());
54     textFieldDeclaration_->SetPlaceholderColor(theme->GetPlaceholderColor());
55     textFieldDeclaration_->SetFocusBgColor(theme->GetFocusBgColor());
56     textFieldDeclaration_->SetFocusPlaceholderColor(theme->GetFocusPlaceholderColor());
57     textFieldDeclaration_->SetFocusTextColor(theme->GetFocusTextColor());
58     textFieldDeclaration_->SetBgColor(theme->GetBgColor());
59     textFieldDeclaration_->SetTextColor(theme->GetTextColor());
60     textFieldDeclaration_->SetSelectedColor(theme->GetSelectedColor());
61     textFieldDeclaration_->SetHoverColor(theme->GetHoverColor());
62     textFieldDeclaration_->SetPressColor(theme->GetPressColor());
63     textFieldDeclaration_->GetTextStyle().SetTextColor(theme->GetTextColor());
64     textFieldDeclaration_->GetTextStyle().SetFontSize(theme->GetFontSize());
65     textFieldDeclaration_->GetTextStyle().SetFontWeight(theme->GetFontWeight());
66     textFieldDeclaration_->GetTextStyle().SetFontFamilies({
67         "sans-serif",
68     });
69     textFieldDeclaration_->SetCountTextStyle(theme->GetCountTextStyle());
70     textFieldDeclaration_->SetOverCountStyle(theme->GetOverCountStyle());
71     textFieldDeclaration_->SetCountTextStyleOuter(theme->GetCountTextStyleOuter());
72     textFieldDeclaration_->SetOverCountStyleOuter(theme->GetOverCountStyleOuter());
73 
74     textFieldDeclaration_->SetErrorBorderWidth(theme->GetErrorBorderWidth());
75     textFieldDeclaration_->SetErrorBorderColor(theme->GetErrorBorderColor());
76 
77     RefPtr<Decoration> backDecoration = AceType::MakeRefPtr<Decoration>();
78     backDecoration->SetPadding(theme->GetPadding());
79     backDecoration->SetBackgroundColor(theme->GetBgColor());
80     backDecoration->SetBorderRadius(theme->GetBorderRadius());
81     textFieldDeclaration_->SetDecoration(backDecoration);
82     textFieldDeclaration_->SetIconSize(theme->GetIconSize());
83     textFieldDeclaration_->SetIconHotZoneSize(theme->GetIconHotZoneSize());
84 }
85 
SetSpecializedAttr(const std::pair<std::string,std::string> & attr)86 bool TextareaDeclaration::SetSpecializedAttr(const std::pair<std::string, std::string>& attr)
87 {
88     return textFieldDeclaration_->SetSpecializedAttr(attr);
89 }
90 
SetSpecializedStyle(const std::pair<std::string,std::string> & style)91 bool TextareaDeclaration::SetSpecializedStyle(const std::pair<std::string, std::string>& style)
92 {
93     return textFieldDeclaration_->SetSpecializedStyle(style);
94 }
95 
SetSpecializedEvent(int32_t pageId,const std::string & eventId,const std::string & event)96 bool TextareaDeclaration::SetSpecializedEvent(int32_t pageId, const std::string& eventId, const std::string& event)
97 {
98     return textFieldDeclaration_->SetSpecializedEvent(pageId, eventId, event);
99 }
100 
CallSpecializedMethod(const std::string & method,const std::string & args)101 void TextareaDeclaration::CallSpecializedMethod(const std::string& method, const std::string& args)
102 {
103     textFieldDeclaration_->CallSpecializedMethod(method, args);
104 }
105 
OnRequestFocus(bool shouldFocus)106 void TextareaDeclaration::OnRequestFocus(bool shouldFocus)
107 {
108     textFieldDeclaration_->OnRequestFocus(shouldFocus);
109 }
110 
111 } // namespace OHOS::Ace