• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 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 "frameworks/bridge/declarative_frontend/jsview/js_calendar.h"
17 
18 #include <cstdint>
19 #include <optional>
20 
21 #include "base/geometry/dimension.h"
22 #include "base/log/ace_scoring_log.h"
23 #include "base/memory/ace_type.h"
24 #include "base/utils/utils.h"
25 #include "bridge/declarative_frontend/engine/js_ref_ptr.h"
26 #include "core/common/ace_application_info.h"
27 #include "core/common/container.h"
28 #include "core/components/common/properties/color.h"
29 #include "core/components_ng/base/ui_node.h"
30 #include "core/components_ng/base/view_stack_processor.h"
31 #include "core/components_ng/pattern/calendar/calendar_model_ng.h"
32 #include "core/pipeline/pipeline_context.h"
33 #include "frameworks/bridge/declarative_frontend/jsview/js_calendar_controller.h"
34 #include "frameworks/bridge/declarative_frontend/jsview/js_view_common_def.h"
35 #include "frameworks/bridge/declarative_frontend/jsview/models/calendar_model_impl.h"
36 
37 namespace OHOS::Ace {
38 std::unique_ptr<CalendarModel> CalendarModel::instance_ = nullptr;
39 std::once_flag CalendarModel::onceFlag_;
40 
GetInstance()41 CalendarModel* CalendarModel::GetInstance()
42 {
43     std::call_once(onceFlag_, []() {
44 #ifdef NG_BUILD
45         instance_.reset(new NG::CalendarModelNG());
46 #else
47         if (Container::IsCurrentUseNewPipeline()) {
48             instance_.reset(new NG::CalendarModelNG());
49         } else {
50             instance_.reset(new Framework::CalendarModelImpl());
51         }
52 #endif
53     });
54 
55     return instance_.get();
56 }
57 } // namespace OHOS::Ace
58 
59 namespace OHOS::Ace::Framework {
60 namespace {
61 constexpr int32_t CALENDAR_INVALID = -1;
62 } // namespace
63 
JSBind(BindingTarget globalObj)64 void JSCalendar::JSBind(BindingTarget globalObj)
65 {
66     JSClass<JSCalendar>::Declare("Calendar");
67     MethodOptions opt = MethodOptions::NONE;
68     JSClass<JSCalendar>::StaticMethod("create", &JSCalendar::Create, opt);
69     JSClass<JSCalendar>::StaticMethod("showLunar", &JSCalendar::SetShowLunar, opt);
70     JSClass<JSCalendar>::StaticMethod("showHoliday", &JSCalendar::SetShowHoliday, opt);
71     JSClass<JSCalendar>::StaticMethod("needSlide", &JSCalendar::SetNeedSlide, opt);
72     JSClass<JSCalendar>::StaticMethod("startOfWeek", &JSCalendar::SetStartOfWeek, opt);
73     JSClass<JSCalendar>::StaticMethod("offDays", &JSCalendar::SetOffDays, opt);
74     JSClass<JSCalendar>::StaticMethod("onSelectChange", &JSCalendar::JsOnSelectedChange, opt);
75     JSClass<JSCalendar>::StaticMethod("onRequestData", &JSCalendar::JsOnRequestData, opt);
76     JSClass<JSCalendar>::StaticMethod("direction", &JSCalendar::SetDirection, opt);
77     JSClass<JSCalendar>::StaticMethod("currentDayStyle", &JSCalendar::SetCurrentDayStyle, opt);
78     JSClass<JSCalendar>::StaticMethod("nonCurrentDayStyle", &JSCalendar::SetNonCurrentDayStyle, opt);
79     JSClass<JSCalendar>::StaticMethod("todayStyle", &JSCalendar::SetTodayStyle, opt);
80     JSClass<JSCalendar>::StaticMethod("weekStyle", &JSCalendar::SetWeekStyle, opt);
81     JSClass<JSCalendar>::StaticMethod("workStateStyle", &JSCalendar::SetWorkStateStyle, opt);
82     JSClass<JSCalendar>::InheritAndBind<JSViewAbstract>(globalObj);
83 }
84 
Create(const JSCallbackInfo & info)85 void JSCalendar::Create(const JSCallbackInfo& info)
86 {
87     if (!info[0]->IsObject()) {
88         return;
89     }
90     auto obj = JSRef<JSObject>::Cast(info[0]);
91     auto dataJsVal = obj->GetProperty("date");
92     auto currentDataJsVal = obj->GetProperty("currentData");
93     auto preDataJsVal = obj->GetProperty("preData");
94     auto nextDataJsVal = obj->GetProperty("nextData");
95     if (!(dataJsVal->IsObject() && currentDataJsVal->IsObject() && preDataJsVal->IsObject() &&
96         nextDataJsVal->IsObject())) {
97         return;
98     }
99     auto date = JSRef<JSObject>::Cast(dataJsVal);
100     auto currentData = JSRef<JSObject>::Cast(currentDataJsVal);
101     auto preData = JSRef<JSObject>::Cast(preDataJsVal);
102     auto nextData = JSRef<JSObject>::Cast(nextDataJsVal);
103     auto controllerObj = obj->GetProperty("controller");
104     auto yearValue = date->GetProperty("year");
105     auto monthValue = date->GetProperty("month");
106     auto dayValue = date->GetProperty("day");
107     if (!yearValue->IsNumber() || !monthValue->IsNumber() || !dayValue->IsNumber()) {
108         return;
109     }
110     CalendarDay day;
111     day.month.year = yearValue->ToNumber<int32_t>();
112     day.month.month = monthValue->ToNumber<int32_t>();
113     day.day = dayValue->ToNumber<int32_t>();
114     CalendarModelData calendarData;
115     calendarData.date = day;
116     ObtainedMonth currentMonthData = GetCurrentData(currentData);
117     ObtainedMonth preMonthData = GetPreData(preData);
118     ObtainedMonth nextMonthData = GetNextData(nextData);
119     calendarData.currentData = currentMonthData;
120     calendarData.preData = preMonthData;
121     calendarData.nextData = nextMonthData;
122     if (controllerObj->IsObject()) {
123         auto jsCalendarController = JSRef<JSObject>::Cast(controllerObj)->Unwrap<JSCalendarController>();
124         if (jsCalendarController) {
125             jsCalendarController->SetInstanceId(Container::CurrentId());
126             calendarData.controller = jsCalendarController->GetController();
127         }
128     }
129     CalendarModel::GetInstance()->Create(calendarData);
130 }
131 
SetCalendarData(const JSRef<JSObject> & obj,MonthState monthState,const RefPtr<CalendarComponentV2> & component)132 void JSCalendar::SetCalendarData(
133     const JSRef<JSObject>& obj, MonthState monthState, const RefPtr<CalendarComponentV2>& component)
134 {
135     CHECK_NULL_VOID(component);
136 
137 #if defined(PREVIEW)
138     if (obj->IsUndefined()) {
139         return;
140     }
141 #endif
142 
143     component->SetCalendarData(GetCalendarData(obj, monthState));
144 }
145 
GetCalendarData(const JSRef<JSObject> & obj,MonthState monthState)146 ObtainedMonth JSCalendar::GetCalendarData(const JSRef<JSObject>& obj, MonthState monthState)
147 {
148 #if defined(PREVIEW)
149     if (obj->IsUndefined()) {
150         return ObtainedMonth();
151     }
152 #endif
153 
154     auto yearValue = obj->GetProperty("year");
155     auto monthValue = obj->GetProperty("month");
156     auto arrayValue = obj->GetProperty("data");
157     if (!yearValue->IsNumber() || !monthValue->IsNumber() || !arrayValue->IsArray()) {
158         return ObtainedMonth();
159     }
160     ObtainedMonth obtainedMonth;
161     obtainedMonth.year = yearValue->ToNumber<int32_t>();
162     obtainedMonth.month = monthValue->ToNumber<int32_t>();
163     std::vector<CalendarDay> days;
164     JSRef<JSArray> dataArray = JSRef<JSArray>::Cast(arrayValue);
165     size_t length = dataArray->Length();
166     for (size_t i = 0; i < length; ++i) {
167         CalendarDay day;
168         JSRef<JSVal> item = dataArray->GetValueAt(i);
169         if (!item->IsObject()) {
170             days.emplace_back(std::move(day));
171             continue;
172         }
173         JSRef<JSObject> itemObj = JSRef<JSObject>::Cast(item);
174         day.index = itemObj->GetPropertyValue<int32_t>("index", 0);
175         day.lunarMonth = itemObj->GetPropertyValue<std::string>("lunarMonth", "");
176         day.lunarDay = itemObj->GetPropertyValue<std::string>("lunarDay", "");
177         day.dayMark = itemObj->GetPropertyValue<std::string>("dayMark", "");
178         day.dayMarkValue = itemObj->GetPropertyValue<std::string>("dayMarkValue", "");
179         day.month.year = itemObj->GetPropertyValue<int32_t>("year", 0);
180         day.month.month = itemObj->GetPropertyValue<int32_t>("month", 0);
181         day.day = itemObj->GetPropertyValue<int32_t>("day", 0);
182         if (day.day == 1 && obtainedMonth.firstDayIndex == CALENDAR_INVALID) {
183             obtainedMonth.firstDayIndex = day.index;
184         }
185         day.isFirstOfLunar = itemObj->GetPropertyValue<bool>("isFirstOfLunar", false);
186         day.hasSchedule = itemObj->GetPropertyValue<bool>("hasSchedule", false);
187         day.markLunarDay = itemObj->GetPropertyValue<bool>("markLunarDay", false);
188         days.emplace_back(std::move(day));
189     }
190     obtainedMonth.days = days;
191     return obtainedMonth;
192 }
193 
SetCardCalendar(bool cardCalendar)194 void JSCalendar::SetCardCalendar(bool cardCalendar)
195 {
196     auto component = GetComponent();
197     CHECK_NULL_VOID(component);
198 
199     component->SetCardCalendar(cardCalendar);
200 }
201 
SetDate(const JSRef<JSObject> & obj,const RefPtr<CalendarComponentV2> & component)202 void JSCalendar::SetDate(const JSRef<JSObject>& obj, const RefPtr<CalendarComponentV2>& component)
203 {
204     if (component) {
205         auto yearValue = obj->GetProperty("year");
206         auto monthValue = obj->GetProperty("month");
207         auto dayValue = obj->GetProperty("day");
208         if (!yearValue->IsNumber() || !monthValue->IsNumber() || !dayValue->IsNumber()) {
209             return;
210         }
211         CalendarDay day;
212         day.month.year = yearValue->ToNumber<int32_t>();
213         day.month.month = monthValue->ToNumber<int32_t>();
214         day.day = dayValue->ToNumber<int32_t>();
215         component->SetCalendarDate(day);
216     }
217 }
218 
SetHolidays(const std::string & holidays)219 void JSCalendar::SetHolidays(const std::string& holidays)
220 {
221     auto component = GetComponent();
222     CHECK_NULL_VOID(component);
223 
224     component->SetHolidays(holidays);
225 }
226 
SetOffDays(int32_t offDays)227 void JSCalendar::SetOffDays(int32_t offDays)
228 {
229     uint32_t bit = 0b1;
230     std::string result;
231     const static int32_t dayOfWeek = 7;
232     for (auto i = 0; i < dayOfWeek; ++i) {
233         if (bit & static_cast<uint32_t>(offDays)) {
234             result += std::to_string(i);
235             result += ",";
236         }
237         bit <<= 1;
238     }
239 
240     CalendarModel::GetInstance()->SetOffDays(result);
241 }
242 
SetShowHoliday(const JSCallbackInfo & info)243 void JSCalendar::SetShowHoliday(const JSCallbackInfo& info)
244 {
245     bool showHoliday = true;
246     if (info[0]->IsBoolean()) {
247         showHoliday = info[0]->ToBoolean();
248     }
249     CalendarModel::GetInstance()->SetShowHoliday(showHoliday);
250 }
251 
SetShowLunar(const JSCallbackInfo & info)252 void JSCalendar::SetShowLunar(const JSCallbackInfo& info)
253 {
254     bool showLunar = false;
255     if (info[0]->IsBoolean()) {
256         showLunar = info[0]->ToBoolean();
257     }
258     CalendarModel::GetInstance()->SetShowLunar(showLunar);
259 }
260 
SetStartOfWeek(const JSCallbackInfo & info)261 void JSCalendar::SetStartOfWeek(const JSCallbackInfo& info)
262 {
263     if (info[0]->IsNumber()) {
264         auto startOfWeek = info[0]->ToNumber<int32_t>();
265         CalendarModel::GetInstance()->SetStartOfWeek(startOfWeek);
266     }
267 }
268 
SetNeedSlide(const JSCallbackInfo & info)269 void JSCalendar::SetNeedSlide(const JSCallbackInfo& info)
270 {
271     bool needSlide = false;
272     if (info[0]->IsBoolean()) {
273         needSlide = info[0]->ToBoolean();
274     }
275     CalendarModel::GetInstance()->SetNeedSlide(needSlide);
276 }
277 
SetWorkDays(const std::string & workDays)278 void JSCalendar::SetWorkDays(const std::string& workDays)
279 {
280     auto component = GetComponent();
281     CHECK_NULL_VOID(component);
282 
283     component->SetWorkDays(workDays);
284 }
285 
GetComponent()286 RefPtr<CalendarComponentV2> JSCalendar::GetComponent()
287 {
288     auto stack = ViewStackProcessor::GetInstance();
289     if (!stack) {
290         return nullptr;
291     }
292     auto component = AceType::DynamicCast<CalendarComponentV2>(stack->GetMainComponent());
293     if (AceApplicationInfo::GetInstance().IsRightToLeft()) {
294         component->SetTextDirection(TextDirection::RTL);
295     }
296     return component;
297 }
298 
JsOnSelectedChange(const JSCallbackInfo & info)299 void JSCalendar::JsOnSelectedChange(const JSCallbackInfo& info)
300 {
301     if (!info[0]->IsFunction()) {
302         return;
303     }
304     if (info[0]->IsFunction()) {
305         auto frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
306         auto selectedChangeFuc = AceType::MakeRefPtr<JsFunction>(JSRef<JSObject>(), JSRef<JSFunc>::Cast(info[0]));
307         auto selectedChange = [execCtx = info.GetExecutionContext(), func = std::move(selectedChangeFuc),
308                                   node = frameNode](const std::string& info) {
309             JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
310             std::vector<std::string> keys = { "year", "month", "day" };
311             ACE_SCORING_EVENT("Calendar.onSelectedChange");
312             PipelineContext::SetCallBackNode(node);
313             func->Execute(keys, info);
314         };
315         CalendarModel::GetInstance()->SetSelectedChangeEvent(std::move(selectedChange));
316     }
317 }
318 
JsOnRequestData(const JSCallbackInfo & info)319 void JSCalendar::JsOnRequestData(const JSCallbackInfo& info)
320 {
321     if (!info[0]->IsFunction()) {
322         return;
323     }
324     WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
325     auto requestDataFuc = AceType::MakeRefPtr<JsFunction>(JSRef<JSObject>(), JSRef<JSFunc>::Cast(info[0]));
326     auto requestData = [execCtx = info.GetExecutionContext(), func = std::move(requestDataFuc), node = frameNode](
327                            const std::string& info) {
328         JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
329         ACE_SCORING_EVENT("Calendar.onRequestData");
330         std::vector<std::string> keys = { "year", "month", "currentMonth", "currentYear", "monthState" };
331         PipelineContext::SetCallBackNode(node);
332         func->Execute(keys, info);
333     };
334     CalendarModel::GetInstance()->SetOnRequestDataEvent(std::move(requestData));
335 }
336 
SetCurrentData(const JSRef<JSObject> & obj,const RefPtr<CalendarComponentV2> & component)337 void JSCalendar::SetCurrentData(const JSRef<JSObject>& obj, const RefPtr<CalendarComponentV2>& component)
338 {
339     SetCalendarData(obj, MonthState::CUR_MONTH, component);
340 }
341 
GetCurrentData(const JSRef<JSObject> & obj)342 ObtainedMonth JSCalendar::GetCurrentData(const JSRef<JSObject>& obj)
343 {
344     return GetCalendarData(obj, MonthState::CUR_MONTH);
345 }
346 
SetPreData(const JSRef<JSObject> & obj,const RefPtr<CalendarComponentV2> & component)347 void JSCalendar::SetPreData(const JSRef<JSObject>& obj, const RefPtr<CalendarComponentV2>& component)
348 {
349     SetCalendarData(obj, MonthState::PRE_MONTH, component);
350 }
351 
GetPreData(const JSRef<JSObject> & obj)352 ObtainedMonth JSCalendar::GetPreData(const JSRef<JSObject>& obj)
353 {
354     return GetCalendarData(obj, MonthState::PRE_MONTH);
355 }
356 
SetNextData(const JSRef<JSObject> & obj,const RefPtr<CalendarComponentV2> & component)357 void JSCalendar::SetNextData(const JSRef<JSObject>& obj, const RefPtr<CalendarComponentV2>& component)
358 {
359     SetCalendarData(obj, MonthState::NEXT_MONTH, component);
360 }
361 
GetNextData(const JSRef<JSObject> & obj)362 ObtainedMonth JSCalendar::GetNextData(const JSRef<JSObject>& obj)
363 {
364     return GetCalendarData(obj, MonthState::NEXT_MONTH);
365 }
366 
SetDirection(const JSCallbackInfo & info)367 void JSCalendar::SetDirection(const JSCallbackInfo& info)
368 {
369     if (info[0]->IsNumber()) {
370         auto dir = info[0]->ToNumber<int32_t>();
371         CalendarModel::GetInstance()->SetDirection(dir);
372     }
373 }
374 
SetCurrentDayStyle(const JSCallbackInfo & info)375 void JSCalendar::SetCurrentDayStyle(const JSCallbackInfo& info)
376 {
377     if (!info[0]->IsObject()) {
378         return;
379     }
380     auto obj = JSRef<JSObject>::Cast(info[0]);
381     CurrentDayStyleData currentDayStyleData;
382     Color dayColor;
383     if (ConvertFromJSValue(obj->GetProperty("dayColor"), dayColor)) {
384         currentDayStyleData.dayColor = dayColor;
385     }
386     Color lunarColor;
387     if (ConvertFromJSValue(obj->GetProperty("lunarColor"), lunarColor)) {
388         currentDayStyleData.lunarColor = lunarColor;
389     }
390     Color markLunarColor;
391     if (ConvertFromJSValue(obj->GetProperty("markLunarColor"), markLunarColor)) {
392         currentDayStyleData.markLunarColor = markLunarColor;
393     }
394     CalcDimension dayFontSize;
395     if (ParseJsDimensionFp(obj->GetProperty("dayFontSize"), dayFontSize)) {
396         currentDayStyleData.dayFontSize = dayFontSize;
397     }
398     CalcDimension lunarDayFontSize;
399     if (ParseJsDimensionFp(obj->GetProperty("lunarDayFontSize"), lunarDayFontSize)) {
400         currentDayStyleData.lunarDayFontSize = lunarDayFontSize;
401     }
402     CalcDimension dayHeight;
403     if (ParseJsDimensionFp(obj->GetProperty("dayHeight"), dayHeight)) {
404         currentDayStyleData.dayHeight = dayHeight;
405     }
406     CalcDimension dayWidth;
407     if (ParseJsDimensionFp(obj->GetProperty("dayWidth"), dayWidth)) {
408         currentDayStyleData.dayWidth = dayWidth;
409     }
410     CalcDimension gregorianCalendarHeight;
411     if (ParseJsDimensionFp(obj->GetProperty("gregorianCalendarHeight"), gregorianCalendarHeight)) {
412         currentDayStyleData.gregorianCalendarHeight = gregorianCalendarHeight;
413     }
414     CalcDimension lunarHeight;
415     if (ParseJsDimensionFp(obj->GetProperty("lunarHeight"), lunarHeight)) {
416         currentDayStyleData.lunarHeight = lunarHeight;
417     }
418     CalcDimension dayYAxisOffset;
419     if (ParseJsDimensionFp(obj->GetProperty("dayYAxisOffset"), dayYAxisOffset)) {
420         currentDayStyleData.dayYAxisOffset = dayYAxisOffset;
421     }
422     CalcDimension lunarDayYAxisOffset;
423     if (ParseJsDimensionFp(obj->GetProperty("lunarDayYAxisOffset"), lunarDayYAxisOffset)) {
424         currentDayStyleData.lunarDayYAxisOffset = lunarDayYAxisOffset;
425     }
426     CalcDimension underscoreXAxisOffset;
427     if (ParseJsDimensionFp(obj->GetProperty("underscoreXAxisOffset"), underscoreXAxisOffset)) {
428         currentDayStyleData.underscoreXAxisOffset = underscoreXAxisOffset;
429     }
430     CalcDimension underscoreYAxisOffset;
431     if (ParseJsDimensionFp(obj->GetProperty("underscoreYAxisOffset"), underscoreYAxisOffset)) {
432         currentDayStyleData.underscoreYAxisOffset = underscoreYAxisOffset;
433     }
434     CalcDimension scheduleMarkerXAxisOffset;
435     if (ParseJsDimensionFp(obj->GetProperty("scheduleMarkerXAxisOffset"), scheduleMarkerXAxisOffset)) {
436         currentDayStyleData.scheduleMarkerXAxisOffset = scheduleMarkerXAxisOffset;
437     }
438     CalcDimension scheduleMarkerYAxisOffset;
439     if (ParseJsDimensionFp(obj->GetProperty("scheduleMarkerYAxisOffset"), scheduleMarkerYAxisOffset)) {
440         currentDayStyleData.scheduleMarkerYAxisOffset = scheduleMarkerYAxisOffset;
441     }
442     CalcDimension colSpace;
443     if (ParseJsDimensionFp(obj->GetProperty("colSpace"), colSpace)) {
444         currentDayStyleData.colSpace = colSpace;
445     }
446     CalcDimension dailyFiveRowSpace;
447     if (ParseJsDimensionFp(obj->GetProperty("dailyFiveRowSpace"), dailyFiveRowSpace)) {
448         currentDayStyleData.dailyFiveRowSpace = dailyFiveRowSpace;
449     }
450     CalcDimension dailySixRowSpace;
451     if (ParseJsDimensionFp(obj->GetProperty("dailySixRowSpace"), dailySixRowSpace)) {
452         currentDayStyleData.dailySixRowSpace = dailySixRowSpace;
453     }
454     CalcDimension underscoreWidth;
455     if (ParseJsDimensionFp(obj->GetProperty("underscoreWidth"), underscoreWidth)) {
456         currentDayStyleData.underscoreWidth = underscoreWidth;
457     }
458     CalcDimension underscoreLength;
459     if (ParseJsDimensionFp(obj->GetProperty("underscoreLength"), underscoreLength)) {
460         currentDayStyleData.underscoreLength = underscoreLength;
461     }
462     CalcDimension scheduleMarkerRadius;
463     if (ParseJsDimensionFp(obj->GetProperty("scheduleMarkerRadius"), scheduleMarkerRadius)) {
464         currentDayStyleData.scheduleMarkerRadius = scheduleMarkerRadius;
465     }
466     CalcDimension boundaryRowOffset;
467     if (ParseJsDimensionFp(obj->GetProperty("boundaryRowOffset"), boundaryRowOffset)) {
468         currentDayStyleData.boundaryRowOffset = boundaryRowOffset;
469     }
470     CalcDimension boundaryColOffset;
471     if (ParseJsDimensionFp(obj->GetProperty("boundaryColOffset"), boundaryColOffset)) {
472         currentDayStyleData.boundaryColOffset = boundaryColOffset;
473     }
474 
475     CurrentDayStyleData CurrentDayStyleDataImpl;
476     ConvertFromJSValue(obj->GetProperty("dayColor"), CurrentDayStyleDataImpl.dayColor);
477     ConvertFromJSValue(obj->GetProperty("lunarColor"), CurrentDayStyleDataImpl.lunarColor);
478     ConvertFromJSValue(obj->GetProperty("markLunarColor"), CurrentDayStyleDataImpl.markLunarColor);
479     CalcDimension dayFontSize_impl;
480     if (ParseJsDimensionFp(obj->GetProperty("dayFontSize"), dayFontSize_impl)) {
481         CurrentDayStyleDataImpl.dayFontSize = dayFontSize_impl;
482     }
483     CalcDimension lunarDayFontSize_impl;
484     if (ParseJsDimensionFp(obj->GetProperty("lunarDayFontSize"), lunarDayFontSize_impl)) {
485         CurrentDayStyleDataImpl.lunarDayFontSize = lunarDayFontSize_impl;
486     }
487     ConvertFromJSValue(obj->GetProperty("dayHeight"), CurrentDayStyleDataImpl.dayHeight);
488     ConvertFromJSValue(obj->GetProperty("dayWidth"), CurrentDayStyleDataImpl.dayWidth);
489     ConvertFromJSValue(obj->GetProperty("gregorianCalendarHeight"), CurrentDayStyleDataImpl.gregorianCalendarHeight);
490     ConvertFromJSValue(obj->GetProperty("lunarHeight"), CurrentDayStyleDataImpl.lunarHeight);
491     ConvertFromJSValue(obj->GetProperty("dayYAxisOffset"), CurrentDayStyleDataImpl.dayYAxisOffset);
492     ConvertFromJSValue(obj->GetProperty("lunarDayYAxisOffset"), CurrentDayStyleDataImpl.lunarDayYAxisOffset);
493     ConvertFromJSValue(obj->GetProperty("underscoreXAxisOffset"), CurrentDayStyleDataImpl.underscoreXAxisOffset);
494     ConvertFromJSValue(obj->GetProperty("underscoreYAxisOffset"), CurrentDayStyleDataImpl.underscoreYAxisOffset);
495     ConvertFromJSValue(obj->GetProperty("scheduleMarkerXAxisOffset"),
496         CurrentDayStyleDataImpl.scheduleMarkerXAxisOffset);
497     ConvertFromJSValue(obj->GetProperty("scheduleMarkerYAxisOffset"),
498         CurrentDayStyleDataImpl.scheduleMarkerYAxisOffset);
499     ConvertFromJSValue(obj->GetProperty("colSpace"), CurrentDayStyleDataImpl.colSpace);
500     ConvertFromJSValue(obj->GetProperty("dailyFiveRowSpace"), CurrentDayStyleDataImpl.dailyFiveRowSpace);
501     ConvertFromJSValue(obj->GetProperty("dailySixRowSpace"), CurrentDayStyleDataImpl.dailySixRowSpace);
502     ConvertFromJSValue(obj->GetProperty("underscoreWidth"), CurrentDayStyleDataImpl.underscoreWidth);
503     ConvertFromJSValue(obj->GetProperty("underscoreLength"), CurrentDayStyleDataImpl.underscoreLength);
504     ConvertFromJSValue(obj->GetProperty("scheduleMarkerRadius"), CurrentDayStyleDataImpl.scheduleMarkerRadius);
505     ConvertFromJSValue(obj->GetProperty("boundaryRowOffset"), CurrentDayStyleDataImpl.boundaryRowOffset);
506     ConvertFromJSValue(obj->GetProperty("boundaryColOffset"), CurrentDayStyleDataImpl.boundaryColOffset);
507     ConvertFromJSValue(obj->GetProperty("touchCircleStrokeWidth"), CurrentDayStyleDataImpl.touchCircleStrokeWidth);
508 
509     CalendarModel::GetInstance()->SetCurrentDayStyle(currentDayStyleData, CurrentDayStyleDataImpl);
510 }
511 
SetNonCurrentDayStyle(const JSCallbackInfo & info)512 void JSCalendar::SetNonCurrentDayStyle(const JSCallbackInfo& info)
513 {
514     if (info.Length() < 1 || !info[0]->IsObject()) {
515         return;
516     }
517     auto obj = JSRef<JSObject>::Cast(info[0]);
518     NonCurrentDayStyleData nonCurrentDayStyleData;
519     Color nonCurrentMonthDayColor;
520     if (ConvertFromJSValue(obj->GetProperty("nonCurrentMonthDayColor"), nonCurrentMonthDayColor)) {
521         nonCurrentDayStyleData.nonCurrentMonthDayColor = nonCurrentMonthDayColor;
522     }
523     Color nonCurrentMonthLunarColor;
524     if (ConvertFromJSValue(obj->GetProperty("nonCurrentMonthLunarColor"), nonCurrentMonthLunarColor)) {
525         nonCurrentDayStyleData.nonCurrentMonthLunarColor = nonCurrentMonthLunarColor;
526     }
527     Color nonCurrentMonthWorkDayMarkColor;
528     if (ConvertFromJSValue(obj->GetProperty("nonCurrentMonthWorkDayMarkColor"), nonCurrentMonthWorkDayMarkColor)) {
529         nonCurrentDayStyleData.nonCurrentMonthWorkDayMarkColor = nonCurrentMonthWorkDayMarkColor;
530     }
531     Color nonCurrentMonthOffDayMarkColor;
532     if (ConvertFromJSValue(obj->GetProperty("nonCurrentMonthOffDayMarkColor"), nonCurrentMonthOffDayMarkColor)) {
533         nonCurrentDayStyleData.nonCurrentMonthOffDayMarkColor = nonCurrentMonthOffDayMarkColor;
534     }
535     CalendarModel::GetInstance()->SetNonCurrentDayStyle(nonCurrentDayStyleData);
536 }
537 
SetTodayStyle(const JSCallbackInfo & info)538 void JSCalendar::SetTodayStyle(const JSCallbackInfo& info)
539 {
540     if (info.Length() < 1 || !info[0]->IsObject()) {
541         return;
542     }
543     auto obj = JSRef<JSObject>::Cast(info[0]);
544     TodayStyleData todayStyle;
545     Color focusedDayColor;
546     if (ConvertFromJSValue(obj->GetProperty("focusedDayColor"), focusedDayColor)) {
547         todayStyle.focusedDayColor = focusedDayColor;
548     }
549     Color focusedLunarColor;
550     if (ConvertFromJSValue(obj->GetProperty("focusedLunarColor"), focusedLunarColor)) {
551         todayStyle.focusedLunarColor = focusedLunarColor;
552     }
553     Color focusedAreaBackgroundColor;
554     if (ConvertFromJSValue(obj->GetProperty("focusedAreaBackgroundColor"), focusedAreaBackgroundColor)) {
555         todayStyle.focusedAreaBackgroundColor = focusedAreaBackgroundColor;
556     }
557     CalcDimension focusedAreaRadius;
558     if (ConvertFromJSValue(obj->GetProperty("focusedAreaRadius"), focusedAreaRadius)) {
559         todayStyle.focusedAreaRadius = focusedAreaRadius;
560     }
561     CalendarModel::GetInstance()->SetTodayStyle(todayStyle);
562 }
563 
SetWeekStyle(const JSCallbackInfo & info)564 void JSCalendar::SetWeekStyle(const JSCallbackInfo& info)
565 {
566     if (info.Length() < 1 || !info[0]->IsObject()) {
567         return;
568     }
569     auto obj = JSRef<JSObject>::Cast(info[0]);
570     WeekStyleData weekStyle;
571     Color weekColor;
572     if (ConvertFromJSValue(obj->GetProperty("weekColor"), weekColor)) {
573         weekStyle.weekColor = weekColor;
574     }
575     Color weekendDayColor;
576     if (ConvertFromJSValue(obj->GetProperty("weekendDayColor"), weekendDayColor)) {
577         weekStyle.weekendDayColor = weekendDayColor;
578     }
579     Color weekendLunarColor;
580     if (ConvertFromJSValue(obj->GetProperty("weekendLunarColor"), weekendLunarColor)) {
581         weekStyle.weekendLunarColor = weekendLunarColor;
582     }
583     CalcDimension weekFontSize;
584     if (ParseJsDimensionFp(obj->GetProperty("weekFontSize"), weekFontSize)) {
585         weekStyle.weekFontSize = weekFontSize;
586     }
587     CalcDimension weekHeight;
588     if (ConvertFromJSValue(obj->GetProperty("weekHeight"), weekHeight)) {
589         weekStyle.weekHeight = weekHeight;
590     }
591     CalcDimension weekWidth;
592     if (ConvertFromJSValue(obj->GetProperty("weekWidth"), weekWidth)) {
593         weekStyle.weekWidth = weekWidth;
594     }
595     CalcDimension weekAndDayRowSpace;
596     if (ConvertFromJSValue(obj->GetProperty("weekAndDayRowSpace"), weekAndDayRowSpace)) {
597         weekStyle.weekAndDayRowSpace = weekAndDayRowSpace;
598     }
599     CalendarModel::GetInstance()->SetWeekStyle(weekStyle);
600 }
601 
SetWorkStateStyle(const JSCallbackInfo & info)602 void JSCalendar::SetWorkStateStyle(const JSCallbackInfo& info)
603 {
604     if (info.Length() < 1 || !info[0]->IsObject()) {
605         return;
606     }
607     auto obj = JSRef<JSObject>::Cast(info[0]);
608     WorkStateStyleData workStateStyle;
609     Color workDayMarkColor;
610     if (ConvertFromJSValue(obj->GetProperty("workDayMarkColor"), workDayMarkColor)) {
611         workStateStyle.workDayMarkColor = workDayMarkColor;
612     }
613     Color offDayMarkColor;
614     if (ConvertFromJSValue(obj->GetProperty("offDayMarkColor"), offDayMarkColor)) {
615         workStateStyle.offDayMarkColor = offDayMarkColor;
616     }
617     CalcDimension workDayMarkSize;
618     if (ConvertFromJSValue(obj->GetProperty("workDayMarkSize"), workDayMarkSize)) {
619         workStateStyle.workDayMarkSize = workDayMarkSize;
620     }
621     CalcDimension offDayMarkSize;
622     if (ConvertFromJSValue(obj->GetProperty("offDayMarkSize"), offDayMarkSize)) {
623         workStateStyle.offDayMarkSize = offDayMarkSize;
624     }
625     CalcDimension workStateWidth;
626     if (ConvertFromJSValue(obj->GetProperty("workStateWidth"), workStateWidth)) {
627         workStateStyle.workStateWidth = workStateWidth;
628     }
629     CalcDimension workStateHorizontalMovingDistance;
630     if (ConvertFromJSValue(
631         obj->GetProperty("workStateHorizontalMovingDistance"), workStateHorizontalMovingDistance)) {
632         workStateStyle.workStateHorizontalMovingDistance = workStateHorizontalMovingDistance;
633     }
634     CalcDimension workStateVerticalMovingDistance;
635     if (ConvertFromJSValue(obj->GetProperty("workStateVerticalMovingDistance"), workStateVerticalMovingDistance)) {
636         workStateStyle.workStateVerticalMovingDistance = workStateVerticalMovingDistance;
637     }
638     CalendarModel::GetInstance()->SetWorkStateStyle(workStateStyle);
639 }
640 } // namespace OHOS::Ace::Framework
641