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/text_overlay/text_overlay_component.h"
17
18 #include "base/i18n/localization.h"
19 #include "core/components/box/box_component.h"
20 #include "core/components/clip/clip_component.h"
21 #include "core/components/common/properties/shadow_config.h"
22 #include "core/components/focus_collaboration/focus_collaboration_component.h"
23 #include "core/components/padding/padding_component.h"
24 #include "core/components/text/text_component.h"
25 #include "core/components/text_overlay/render_text_overlay.h"
26 #include "core/components/text_overlay/text_overlay_element.h"
27 #include "core/components/theme/theme_manager.h"
28
29 namespace OHOS::Ace {
30 namespace {
31
32 constexpr char BUTTON_COPY_ALL[] = "textoverlay.select_all";
33 constexpr char BUTTON_CUT[] = "textoverlay.cut";
34 constexpr char BUTTON_COPY[] = "textoverlay.copy";
35 constexpr char BUTTON_PASTE[] = "textoverlay.paste";
36 constexpr char BUTTON_TRANSLATE[] = "textoverlay.translate";
37 constexpr char BUTTON_SHARE[] = "textoverlay.share";
38 constexpr char BUTTON_SEARCH[] = "textoverlay.search";
39 constexpr char OVERLAY_TRANSLATE[] = "translate";
40 constexpr char OVERLAY_SHARE[] = "share";
41 constexpr char OVERLAY_SEARCH[] = "search";
42
43 constexpr Dimension OVERLAY_MARGIN_BOTTOM = 8.0_vp;
44 constexpr Dimension TOOL_BAR_HEIGHT = 40.0_vp;
45
46 } // namespace
47
TextOverlayComponent(const RefPtr<ThemeManager> & themeManager,const RefPtr<AccessibilityManager> & accessibilityManager)48 TextOverlayComponent::TextOverlayComponent(
49 const RefPtr<ThemeManager>& themeManager, const RefPtr<AccessibilityManager>& accessibilityManager)
50 {
51 themeManager_ = themeManager;
52 accessibilityManager_ = accessibilityManager;
53 InitThemeStyle(themeManager);
54 }
55
CreateElement()56 RefPtr<Element> TextOverlayComponent::CreateElement()
57 {
58 return AceType::MakeRefPtr<TextOverlayElement>();
59 }
60
CreateRenderNode()61 RefPtr<RenderNode> TextOverlayComponent::CreateRenderNode()
62 {
63 return RenderTextOverlay::Create();
64 }
65
InitThemeStyle(const RefPtr<ThemeManager> & themeManager)66 void TextOverlayComponent::InitThemeStyle(const RefPtr<ThemeManager>& themeManager)
67 {
68 theme_ = themeManager->GetTheme<TextOverlayTheme>();
69 if (!theme_) {
70 return;
71 }
72 handleColor_ = theme_->GetHandleColor();
73 handleColorInner_ = theme_->GetHandleColorInner();
74 handleDiameter_ = theme_->GetHandleDiameter();
75 handleDiameterInner_ = theme_->GetHandleDiameterInner();
76 menuSpacingWithText_ = theme_->GetMenuSpacingWithText();
77 }
78
BuildChild(bool isSingleHandle,bool hasToolBar,bool hasMenu,bool hasIcon,bool hasAnimation)79 RefPtr<Component> TextOverlayComponent::BuildChild(
80 bool isSingleHandle, bool hasToolBar, bool hasMenu, bool hasIcon, bool hasAnimation)
81 {
82 // if type of input is password, don't show tool menu.
83 if (isPassword_) {
84 return nullptr;
85 }
86 if (!hasToolBar && !hasMenu && !hasIcon) {
87 return nullptr;
88 }
89 std::list<RefPtr<Component>> columnChildren;
90 auto column = AceType::MakeRefPtr<ColumnComponent>(FlexAlign::SPACE_AROUND, FlexAlign::FLEX_END, columnChildren);
91 if (GetTextDirection() == TextDirection::RTL) {
92 column->SetCrossAxisAlign(FlexAlign::FLEX_START);
93 }
94 column->SetMainAxisSize(MainAxisSize::MIN);
95
96 if (!isUsingMouse_) {
97 column->AppendChild(BuildToolBar(isSingleHandle, hasToolBar, hasMenu, hasIcon, hasAnimation));
98 } else {
99 column->AppendChild(BuildMenu());
100 }
101 // Add toolbar.
102 if (hasMenu && !isUsingMouse_) {
103 // Add menu.
104 column->AppendChild(BuildMenu());
105 } else {
106 menu_.Reset();
107 }
108
109 // Add focus collaboration to show focus animation.
110 auto focusCollaboration = AceType::MakeRefPtr<FocusCollaborationComponent>();
111 focusCollaboration->InsertChild(0, column);
112 return focusCollaboration;
113 }
114
BuildToolBar(bool isSingleHandle,bool hasToolBar,bool hasMenu,bool hasIcon,bool hasAnimation)115 RefPtr<Component> TextOverlayComponent::BuildToolBar(
116 bool isSingleHandle, bool hasToolBar, bool hasMenu, bool hasIcon, bool hasAnimation)
117 {
118 if (!hasToolBar && !hasMenu && !hasIcon) {
119 return nullptr;
120 }
121
122 std::list<RefPtr<Component>> operations;
123 auto row = AceType::MakeRefPtr<RowComponent>(FlexAlign::SPACE_AROUND, FlexAlign::FLEX_START, operations);
124 row->SetMainAxisSize(MainAxisSize::MIN);
125 row->SetStretchToParent(true);
126 if (hasToolBar) {
127 if (!isSingleHandle) {
128 if (onCut_) {
129 row->AppendChild(
130 BuildButton(Localization::GetInstance()->GetEntryLetters(BUTTON_CUT), cutButtonMarker_));
131 }
132 if (onCopy_) {
133 row->AppendChild(
134 BuildButton(Localization::GetInstance()->GetEntryLetters(BUTTON_COPY), copyButtonMarker_));
135 }
136 }
137 if (onPaste_) {
138 row->AppendChild(
139 BuildButton(Localization::GetInstance()->GetEntryLetters(BUTTON_PASTE), pasteButtonMarker_));
140 }
141 if (onCopyAll_) {
142 row->AppendChild(
143 BuildButton(Localization::GetInstance()->GetEntryLetters(BUTTON_COPY_ALL), copyAllButtonMarker_));
144 }
145 if (!translateButtonMarker_.IsEmpty()) {
146 const auto& translateButtonMarker = BackEndEventManager<void()>::GetInstance().GetAvailableMarker();
147 BackEndEventManager<void()>::GetInstance().BindBackendEvent(
148 translateButtonMarker, [weak = WeakClaim(this)]() {
149 auto overlay = weak.Upgrade();
150 if (overlay) {
151 overlay->OnToolBarButtonClick(overlay->translateButtonMarker_, OVERLAY_TRANSLATE);
152 }
153 });
154 row->AppendChild(
155 BuildButton(Localization::GetInstance()->GetEntryLetters(BUTTON_TRANSLATE), translateButtonMarker));
156 }
157 }
158 if (hasIcon && (!options_.empty() || !shareButtonMarker_.IsEmpty() || !searchButtonMarker_.IsEmpty())) {
159 hasMoreButton_ = true;
160 row->AppendChild(BuildMoreIconButton(hasMenu));
161 } else {
162 hasMoreButton_ = false;
163 }
164 auto firstButton = DynamicCast<ButtonComponent>(row->GetChildren().front());
165 if (firstButton) {
166 firstButton->SetAutoFocusState(true);
167 }
168 auto box = AceType::MakeRefPtr<BoxComponent>();
169 if (theme_) {
170 auto backDecoration = AceType::MakeRefPtr<Decoration>();
171 backDecoration->SetBackgroundColor(theme_->GetMenuBackgroundColor());
172 backDecoration->SetBorder(theme_->GetMenuBorder());
173 backDecoration->SetBorderRadius(Radius(theme_->GetMenuButtonHeight()));
174 box->SetBackDecoration(backDecoration);
175 box->SetPadding(theme_->GetMenuPadding());
176 }
177
178 if (hasAnimation) {
179 if (innerComposeId_.empty()) {
180 innerComposeId_ = TweenComponent::AllocTweenComponentId();
181 }
182 auto innerTween = AceType::MakeRefPtr<TweenComponent>(innerComposeId_, innerComposeId_, row);
183 innerTween->SetIsFirstFrameShow(true);
184 box->SetChild(innerTween);
185 } else {
186 box->SetChild(row);
187 }
188 box->SetTextDirection(GetTextDirection());
189 return BuildAnimation(box, hasAnimation);
190 }
191
BuildButton(const std::string & data,const EventMarker & onClick)192 RefPtr<ButtonComponent> TextOverlayComponent::BuildButton(const std::string& data, const EventMarker& onClick)
193 {
194 if (!theme_) {
195 return nullptr;
196 }
197 auto text = AceType::MakeRefPtr<TextComponent>(data);
198 text->SetTextStyle(theme_->GetMenuButtonTextStyle());
199 text->SetFocusColor(theme_->GetMenuButtonTextStyle().GetTextColor());
200
201 auto padding = AceType::MakeRefPtr<PaddingComponent>();
202 padding->SetPadding(theme_->GetMenuButtonPadding());
203 padding->SetChild(text);
204
205 std::list<RefPtr<Component>> children;
206 children.emplace_back(padding);
207 auto button = AceType::MakeRefPtr<ButtonComponent>(children);
208 button->SetIsInnerBorder(true);
209 button->SetClickedEventId(onClick);
210 button->SetHeight(theme_->GetMenuButtonHeight());
211 button->SetRectRadius(theme_->GetMenuButtonHeight() / 2.0);
212 button->SetBackgroundColor(theme_->GetMenuBackgroundColor());
213 button->SetHoverColor(theme_->GetButtonHoverColor());
214 button->SetClickedColor(theme_->GetButtonClickedColor());
215 button->SetFocusColor(theme_->GetMenuBackgroundColor());
216 button->SetFocusable(false);
217 return button;
218 }
219
BuildMoreIconButton(bool hasMenu)220 RefPtr<ButtonComponent> TextOverlayComponent::BuildMoreIconButton(bool hasMenu)
221 {
222 if (!theme_) {
223 return nullptr;
224 }
225
226 std::list<RefPtr<Component>> children;
227 auto context = context_.Upgrade();
228 if (context && context->GetIsDeclarative()) {
229 children.emplace_back(AceType::MakeRefPtr<ImageComponent>(InternalResource::ResourceId::IC_MORE));
230 }
231 auto button = AceType::MakeRefPtr<ButtonComponent>(children);
232 button->SetIsInnerBorder(true);
233 button->SetClickedEventId(moreButtonMarker_);
234 button->SetHeight(theme_->GetMenuButtonHeight());
235 button->SetWidth(theme_->GetMenuButtonHeight());
236 button->SetRectRadius(theme_->GetMenuButtonHeight() / 2.0);
237 button->SetBackgroundColor(Color::TRANSPARENT);
238 button->SetHoverColor(theme_->GetButtonHoverColor());
239 button->SetClickedColor(theme_->GetButtonClickedColor());
240 button->SetFocusColor(theme_->GetMenuBackgroundColor());
241 return button;
242 }
243
BuildAnimation(const RefPtr<Component> & child,bool hasAnimation)244 RefPtr<Component> TextOverlayComponent::BuildAnimation(const RefPtr<Component>& child, bool hasAnimation)
245 {
246 auto box = AceType::MakeRefPtr<BoxComponent>();
247 if (hasAnimation) {
248 auto clip = AceType::MakeRefPtr<ClipComponent>(child);
249 clip->SetTopLeftRadius(Radius(theme_->GetMenuButtonHeight()));
250 clip->SetTopRightRadius(Radius(theme_->GetMenuButtonHeight()));
251 clip->SetBottomLeftRadius(Radius(theme_->GetMenuButtonHeight()));
252 clip->SetBottomRightRadius(Radius(theme_->GetMenuButtonHeight()));
253 clip->SetHeight(TOOL_BAR_HEIGHT);
254 clip->SetClipWithShadow(true);
255
256 if (outerComposeId_.empty()) {
257 outerComposeId_ = TweenComponent::AllocTweenComponentId();
258 }
259 auto outerTween = AceType::MakeRefPtr<TweenComponent>(outerComposeId_, outerComposeId_, clip);
260 outerTween->SetIsFirstFrameShow(true);
261 box->SetChild(outerTween);
262 } else {
263 box->SetChild(child);
264 }
265
266 auto backDecoration = AceType::MakeRefPtr<Decoration>();
267 backDecoration->AddShadow(ShadowConfig::DefaultShadowM);
268 backDecoration->SetBackgroundColor(theme_->GetMenuBackgroundColor());
269 backDecoration->SetBorder(theme_->GetMenuBorder());
270 backDecoration->SetBorderRadius(Radius(theme_->GetMenuButtonHeight()));
271 box->SetBackDecoration(backDecoration);
272 return box;
273 }
274
BuildMenuForDeclative(bool isSingleHandle)275 void TextOverlayComponent::BuildMenuForDeclative(bool isSingleHandle)
276 {
277 if (onCut_ && !isSingleHandle) {
278 auto optionComponent = BuildMenuOption(
279 "", InternalResource::ResourceId::NO_ID, Localization::GetInstance()->GetEntryLetters(BUTTON_CUT), false);
280 optionComponent->SetClickEvent(cutButtonMarker_);
281 menu_->AppendSelectOption(optionComponent);
282 }
283 if (onCopy_ && !isSingleHandle) {
284 auto optionComponent = BuildMenuOption(
285 "", InternalResource::ResourceId::NO_ID, Localization::GetInstance()->GetEntryLetters(BUTTON_COPY), false);
286 optionComponent->SetClickEvent(copyButtonMarker_);
287 menu_->AppendSelectOption(optionComponent);
288 }
289
290 if (onPaste_) {
291 auto optionComponent = BuildMenuOption(
292 "", InternalResource::ResourceId::NO_ID, Localization::GetInstance()->GetEntryLetters(BUTTON_PASTE), false);
293 optionComponent->SetClickEvent(pasteButtonMarker_);
294 menu_->AppendSelectOption(optionComponent);
295 }
296 if (onCopyAll_) {
297 auto optionComponent = BuildMenuOption("", InternalResource::ResourceId::NO_ID,
298 Localization::GetInstance()->GetEntryLetters(BUTTON_COPY_ALL), false);
299 optionComponent->SetClickEvent(copyAllButtonMarker_);
300 menu_->AppendSelectOption(optionComponent);
301 }
302 }
303
BuildMenu(bool isSingleHandle)304 RefPtr<Component> TextOverlayComponent::BuildMenu(bool isSingleHandle)
305 {
306 if (!menu_) {
307 menu_ = AceType::MakeRefPtr<SelectPopupComponent>();
308 menu_->ClearAllOptions();
309 auto context = context_.Upgrade();
310 if (context && context->GetIsDeclarative() && isUsingMouse_) {
311 BuildMenuForDeclative(isSingleHandle);
312 } else {
313 if (!shareButtonMarker_.IsEmpty()) {
314 auto optionComponent = BuildMenuOption("", InternalResource::ResourceId::SHARE_SVG,
315 Localization::GetInstance()->GetEntryLetters(BUTTON_SHARE), true);
316 const auto& shareButtonMarker = BackEndEventManager<void()>::GetInstance().GetAvailableMarker();
317 optionComponent->SetClickEvent(shareButtonMarker);
318 BackEndEventManager<void()>::GetInstance().BindBackendEvent(
319 shareButtonMarker, [weak = WeakClaim(this)]() {
320 auto overlay = weak.Upgrade();
321 if (overlay) {
322 overlay->OnToolBarButtonClick(overlay->shareButtonMarker_, OVERLAY_SHARE);
323 }
324 });
325 menu_->AppendSelectOption(optionComponent);
326 }
327 if (!searchButtonMarker_.IsEmpty()) {
328 auto optionComponent = BuildMenuOption("", InternalResource::ResourceId::SEARCH_SVG,
329 Localization::GetInstance()->GetEntryLetters(BUTTON_SEARCH), true);
330 const auto& searchButtonMarker = BackEndEventManager<void()>::GetInstance().GetAvailableMarker();
331 optionComponent->SetClickEvent(searchButtonMarker);
332 BackEndEventManager<void()>::GetInstance().BindBackendEvent(
333 searchButtonMarker, [weak = WeakClaim(this)]() {
334 auto overlay = weak.Upgrade();
335 if (overlay) {
336 overlay->OnToolBarButtonClick(overlay->searchButtonMarker_, OVERLAY_SEARCH);
337 }
338 });
339 menu_->AppendSelectOption(optionComponent);
340 }
341 }
342 AddOptionForMenu();
343 menu_->SetIsFullScreen(false);
344 menu_->InitTheme(themeManager_);
345 menu_->Initialize(accessibilityManager_.Upgrade());
346 }
347
348 auto box = AceType::MakeRefPtr<BoxComponent>();
349 box->SetChild(menu_);
350 box->SetMargin(Edge(0.0_vp, OVERLAY_MARGIN_BOTTOM, 0.0_vp, 0.0_vp));
351 return box;
352 }
353
AddOptionForMenu()354 void TextOverlayComponent::AddOptionForMenu()
355 {
356 int32_t index = 0;
357 for (const auto& option : options_) {
358 auto optionComponent = BuildMenuOption(option.image, InternalResource::ResourceId::NO_ID, option.text, false);
359 EventMarker clickEvent = BackEndEventManager<void()>::GetInstance().GetAvailableMarker();
360 optionComponent->SetClickEvent(clickEvent);
361 BackEndEventManager<void()>::GetInstance().BindBackendEvent(clickEvent, [weak = WeakClaim(this), index]() {
362 auto overlay = weak.Upgrade();
363 overlay->OnOptionClick(index);
364 });
365 menu_->AppendSelectOption(optionComponent);
366 ++index;
367 }
368 }
369
BuildMenuOption(const std::string & imageSrc,InternalResource::ResourceId resourceId,const std::string & text,bool useResource)370 RefPtr<OptionComponent> TextOverlayComponent::BuildMenuOption(
371 const std::string& imageSrc, InternalResource::ResourceId resourceId, const std::string& text, bool useResource)
372 {
373 auto optionComponent = AceType::MakeRefPtr<OptionComponent>();
374 RefPtr<ImageComponent> image;
375 if (useResource) {
376 image = AceType::MakeRefPtr<ImageComponent>(resourceId);
377 if (theme_) {
378 // fill color only effect svg image color
379 image->SetImageFill(theme_->GetMenuIconColor());
380 }
381 } else {
382 image = AceType::MakeRefPtr<ImageComponent>(imageSrc);
383 if (image) {
384 // fill color only effect svg image color
385 image->SetImageFill(imageFill_);
386 }
387 }
388 if (!isUsingMouse_) {
389 optionComponent->SetIcon(image);
390 } else {
391 optionComponent->SetNeedDrawDividerLine(false);
392 }
393 auto textComponent = AceType::MakeRefPtr<TextComponent>(text);
394 optionComponent->SetText(textComponent);
395 optionComponent->SetValue(text);
396 optionComponent->InitTheme(themeManager_);
397 optionComponent->Initialize(accessibilityManager_.Upgrade());
398 return optionComponent;
399 }
400
OnOptionClick(int32_t index)401 void TextOverlayComponent::OnOptionClick(int32_t index)
402 {
403 const auto& event = AceAsyncEvent<void(const std::string&)>::Create(optionsClickMarker_, context_);
404 if (event) {
405 auto jsonResult = JsonUtil::Create(true);
406 jsonResult->Put("index", index);
407 jsonResult->Put("value", GetSelectedText().c_str());
408 event(std::string(R"("optionselect",)").append(jsonResult->ToString()));
409 }
410 if (popOverlay_) {
411 popOverlay_();
412 }
413 }
414
OnToolBarButtonClick(const EventMarker & marker,const std::string & eventName)415 void TextOverlayComponent::OnToolBarButtonClick(const EventMarker& marker, const std::string& eventName)
416 {
417 const auto& event = AceAsyncEvent<void(const std::string&)>::Create(marker, context_);
418 if (event) {
419 auto jsonResult = JsonUtil::Create(true);
420 jsonResult->Put("value", GetSelectedText().c_str());
421 if (eventName == OVERLAY_TRANSLATE) {
422 event(std::string(R"("translate",)").append(jsonResult->ToString()));
423 } else if (eventName == OVERLAY_SHARE) {
424 event(std::string(R"("share",)").append(jsonResult->ToString()));
425 } else if (eventName == OVERLAY_SEARCH) {
426 event(std::string(R"("search",)").append(jsonResult->ToString()));
427 }
428 }
429 if (popOverlay_) {
430 popOverlay_();
431 }
432 }
433
GetSelectedText() const434 std::string TextOverlayComponent::GetSelectedText() const
435 {
436 const auto& textField = weakTextField_.Upgrade();
437 if (textField) {
438 return textField->GetEditingValue().GetSelectedText();
439 }
440 return "";
441 }
442
HasMoreButton() const443 bool TextOverlayComponent::HasMoreButton() const
444 {
445 return hasMoreButton_;
446 }
447
SetIsPassword(bool isPassword)448 void TextOverlayComponent::SetIsPassword(bool isPassword)
449 {
450 isPassword_ = isPassword;
451 }
452
GetIsPassword() const453 bool TextOverlayComponent::GetIsPassword() const
454 {
455 return isPassword_;
456 }
457
SetIsSingleHandle(bool isSingleHandle)458 void TextOverlayComponent::SetIsSingleHandle(bool isSingleHandle)
459 {
460 isSingleHandle_ = isSingleHandle;
461 }
462
GetIsSingleHandle() const463 bool TextOverlayComponent::GetIsSingleHandle() const
464 {
465 return isSingleHandle_;
466 }
467
SetLineHeight(double lineHeight)468 void TextOverlayComponent::SetLineHeight(double lineHeight)
469 {
470 lineHeight_ = lineHeight;
471 }
472
GetLineHeight() const473 double TextOverlayComponent::GetLineHeight() const
474 {
475 return lineHeight_;
476 }
477
SetStartHandleHeight(double startHandleHeight)478 void TextOverlayComponent::SetStartHandleHeight(double startHandleHeight)
479 {
480 startHandleHeight_ = startHandleHeight;
481 }
482
GetStartHandleHeight() const483 const std::optional<double>& TextOverlayComponent::GetStartHandleHeight() const
484 {
485 return startHandleHeight_;
486 }
487
SetEndHandleHeight(double endHandleHeight)488 void TextOverlayComponent::SetEndHandleHeight(double endHandleHeight)
489 {
490 endHandleHeight_ = endHandleHeight;
491 }
492
GetEndHandleHeight() const493 const std::optional<double>& TextOverlayComponent::GetEndHandleHeight() const
494 {
495 return endHandleHeight_;
496 }
497
SetClipRect(const Rect & clipRect)498 void TextOverlayComponent::SetClipRect(const Rect& clipRect)
499 {
500 clipRect_ = clipRect;
501 }
502
GetClipRect() const503 const Rect& TextOverlayComponent::GetClipRect() const
504 {
505 return clipRect_;
506 }
507
SetHandleColor(const Color & handleColor)508 void TextOverlayComponent::SetHandleColor(const Color& handleColor)
509 {
510 handleColor_ = handleColor;
511 }
512
GetHandleColor() const513 const Color& TextOverlayComponent::GetHandleColor() const
514 {
515 return handleColor_;
516 }
517
SetHandleColorInner(const Color & handleColorInner)518 void TextOverlayComponent::SetHandleColorInner(const Color& handleColorInner)
519 {
520 handleColorInner_ = handleColorInner;
521 }
522
GetHandleColorInner() const523 const Color& TextOverlayComponent::GetHandleColorInner() const
524 {
525 return handleColorInner_;
526 }
527
SetHandleDiameter(const Dimension & handleDiameter)528 void TextOverlayComponent::SetHandleDiameter(const Dimension& handleDiameter)
529 {
530 handleDiameter_ = handleDiameter;
531 }
532
GetHandleDiameter() const533 const Dimension& TextOverlayComponent::GetHandleDiameter() const
534 {
535 return handleDiameter_;
536 }
537
SetHandleDiameterInner(const Dimension & handleDiameterInner)538 void TextOverlayComponent::SetHandleDiameterInner(const Dimension& handleDiameterInner)
539 {
540 handleDiameterInner_ = handleDiameterInner;
541 }
542
GetHandleDiameterInner() const543 const Dimension& TextOverlayComponent::GetHandleDiameterInner() const
544 {
545 return handleDiameterInner_;
546 }
547
SetMenuSpacingWithText(const Dimension & menuSpacingWithText)548 void TextOverlayComponent::SetMenuSpacingWithText(const Dimension& menuSpacingWithText)
549 {
550 menuSpacingWithText_ = menuSpacingWithText;
551 }
552
GetMenuSpacingWithText() const553 const Dimension& TextOverlayComponent::GetMenuSpacingWithText() const
554 {
555 return menuSpacingWithText_;
556 }
557
SetOnFocusChange(const std::function<void (bool,bool)> & onFocusChange)558 void TextOverlayComponent::SetOnFocusChange(const std::function<void(bool, bool)>& onFocusChange)
559 {
560 onFocusChange_ = onFocusChange;
561 }
562
GetOnFocusChange() const563 const std::function<void(bool, bool)>& TextOverlayComponent::GetOnFocusChange() const
564 {
565 return onFocusChange_;
566 }
567
SetOnCut(const CommonCallback & onCut)568 void TextOverlayComponent::SetOnCut(const CommonCallback& onCut)
569 {
570 onCut_ = onCut;
571 }
572
GetOnCut() const573 const CommonCallback& TextOverlayComponent::GetOnCut() const
574 {
575 return onCut_;
576 }
577
SetOnCopy(const CommonCallback & onCopy)578 void TextOverlayComponent::SetOnCopy(const CommonCallback& onCopy)
579 {
580 onCopy_ = onCopy;
581 }
582
GetOnCopy() const583 const CommonCallback& TextOverlayComponent::GetOnCopy() const
584 {
585 return onCopy_;
586 }
587
SetOnPaste(const CommonCallback & onPaste)588 void TextOverlayComponent::SetOnPaste(const CommonCallback& onPaste)
589 {
590 onPaste_ = onPaste;
591 }
592
GetOnPaste() const593 const CommonCallback& TextOverlayComponent::GetOnPaste() const
594 {
595 return onPaste_;
596 }
597
SetOnCopyAll(const CopyAllCallback & onCopyAll)598 void TextOverlayComponent::SetOnCopyAll(const CopyAllCallback& onCopyAll)
599 {
600 onCopyAll_ = onCopyAll;
601 }
602
GetOnCopyAll() const603 const CopyAllCallback& TextOverlayComponent::GetOnCopyAll() const
604 {
605 return onCopyAll_;
606 }
607
SetCutButtonMarker(const EventMarker & cutButtonMarker)608 void TextOverlayComponent::SetCutButtonMarker(const EventMarker& cutButtonMarker)
609 {
610 cutButtonMarker_ = cutButtonMarker;
611 }
612
GetCutButtonMarker() const613 const EventMarker& TextOverlayComponent::GetCutButtonMarker() const
614 {
615 return cutButtonMarker_;
616 }
617
SetCopyButtonMarker(const EventMarker & copyButtonMarker)618 void TextOverlayComponent::SetCopyButtonMarker(const EventMarker& copyButtonMarker)
619 {
620 copyButtonMarker_ = copyButtonMarker;
621 }
622
GetCopyButtonMarker() const623 const EventMarker& TextOverlayComponent::GetCopyButtonMarker() const
624 {
625 return copyButtonMarker_;
626 }
627
SetPasteButtonMarker(const EventMarker & pasteButtonMarker)628 void TextOverlayComponent::SetPasteButtonMarker(const EventMarker& pasteButtonMarker)
629 {
630 pasteButtonMarker_ = pasteButtonMarker;
631 }
632
GetPasteButtonMarker() const633 const EventMarker& TextOverlayComponent::GetPasteButtonMarker() const
634 {
635 return pasteButtonMarker_;
636 }
637
SetCopyAllButtonMarker(const EventMarker & copyAllButtonMarker)638 void TextOverlayComponent::SetCopyAllButtonMarker(const EventMarker& copyAllButtonMarker)
639 {
640 copyAllButtonMarker_ = copyAllButtonMarker;
641 }
642
GetCopyAllButtonMarker() const643 const EventMarker& TextOverlayComponent::GetCopyAllButtonMarker() const
644 {
645 return copyAllButtonMarker_;
646 }
647
SetMoreButtonMarker(const EventMarker & moreButtonMarker)648 void TextOverlayComponent::SetMoreButtonMarker(const EventMarker& moreButtonMarker)
649 {
650 moreButtonMarker_ = moreButtonMarker;
651 }
652
GetMoreButtonMarker() const653 const EventMarker& TextOverlayComponent::GetMoreButtonMarker() const
654 {
655 return moreButtonMarker_;
656 }
657
SetStartHandleOffset(const Offset & offset)658 void TextOverlayComponent::SetStartHandleOffset(const Offset& offset)
659 {
660 startHandleOffset_ = offset;
661 }
662
GetStartHandleOffset() const663 const Offset& TextOverlayComponent::GetStartHandleOffset() const
664 {
665 return startHandleOffset_;
666 }
667
SetEndHandleOffset(const Offset & offset)668 void TextOverlayComponent::SetEndHandleOffset(const Offset& offset)
669 {
670 endHandleOffset_ = offset;
671 }
672
GetEndHandleOffset() const673 const Offset& TextOverlayComponent::GetEndHandleOffset() const
674 {
675 return endHandleOffset_;
676 }
677
SetMouseOffset(const Offset & mouseOffset)678 void TextOverlayComponent::SetMouseOffset(const Offset& mouseOffset)
679 {
680 mouseOffset_ = mouseOffset;
681 }
682
GetMouseOffset() const683 const Offset& TextOverlayComponent::GetMouseOffset() const
684 {
685 return mouseOffset_;
686 }
687
SetOnStartHandleMove(const StartHandleMoveCallback & onStartHandleMove)688 void TextOverlayComponent::SetOnStartHandleMove(const StartHandleMoveCallback& onStartHandleMove)
689 {
690 onStartHandleMove_ = onStartHandleMove;
691 }
692
GetOnStartHandleMove() const693 const StartHandleMoveCallback& TextOverlayComponent::GetOnStartHandleMove() const
694 {
695 return onStartHandleMove_;
696 }
697
SetOnEndHandleMove(const EndHandleMoveCallback & onEndHandleMove)698 void TextOverlayComponent::SetOnEndHandleMove(const EndHandleMoveCallback& onEndHandleMove)
699 {
700 onEndHandleMove_ = onEndHandleMove;
701 }
702
GetOnEndHandleMove() const703 const EndHandleMoveCallback& TextOverlayComponent::GetOnEndHandleMove() const
704 {
705 return onEndHandleMove_;
706 }
707
SetWeakTextField(const WeakPtr<RenderTextField> & weakTextField)708 void TextOverlayComponent::SetWeakTextField(const WeakPtr<RenderTextField>& weakTextField)
709 {
710 weakTextField_ = weakTextField;
711 }
712
GetWeakTextField() const713 const WeakPtr<RenderTextField>& TextOverlayComponent::GetWeakTextField() const
714 {
715 return weakTextField_;
716 }
717
SetWeakText(const WeakPtr<RenderText> & weakText)718 void TextOverlayComponent::SetWeakText(const WeakPtr<RenderText>& weakText)
719 {
720 weakText_ = weakText;
721 }
722
GetWeakText() const723 const WeakPtr<RenderText>& TextOverlayComponent::GetWeakText() const
724 {
725 return weakText_;
726 }
727
SetWeakImage(const WeakPtr<RenderImage> & weakImage)728 void TextOverlayComponent::SetWeakImage(const WeakPtr<RenderImage>& weakImage)
729 {
730 weakImage_ = weakImage;
731 }
732
GetWeakImage() const733 const WeakPtr<RenderImage>& TextOverlayComponent::GetWeakImage() const
734 {
735 return weakImage_;
736 }
737
738 #ifdef WEB_SUPPORTED
SetWeakWeb(const WeakPtr<RenderWeb> & weakWeb)739 void TextOverlayComponent::SetWeakWeb(const WeakPtr<RenderWeb>& weakWeb)
740 {
741 weakWeb_ = weakWeb;
742 }
743
GetWeakWeb() const744 const WeakPtr<RenderWeb>& TextOverlayComponent::GetWeakWeb() const
745 {
746 return weakWeb_;
747 }
748 #endif
749
SetRealTextDirection(TextDirection realTextDirection)750 void TextOverlayComponent::SetRealTextDirection(TextDirection realTextDirection)
751 {
752 realTextDirection_ = realTextDirection;
753 }
754
GetRealTextDirection() const755 TextDirection TextOverlayComponent::GetRealTextDirection() const
756 {
757 return realTextDirection_;
758 }
759
SetOptions(const std::vector<InputOption> & options)760 void TextOverlayComponent::SetOptions(const std::vector<InputOption>& options)
761 {
762 options_ = options;
763 }
764
GetOptions() const765 const std::vector<InputOption>& TextOverlayComponent::GetOptions() const
766 {
767 return options_;
768 }
769
SetImageFill(const std::optional<Color> & imageFill)770 void TextOverlayComponent::SetImageFill(const std::optional<Color>& imageFill)
771 {
772 imageFill_ = imageFill;
773 }
774
SetOptionsClickMarker(const EventMarker & onOptionsClick)775 void TextOverlayComponent::SetOptionsClickMarker(const EventMarker& onOptionsClick)
776 {
777 optionsClickMarker_ = onOptionsClick;
778 }
779
SetTranslateButtonMarker(const EventMarker & onTranslate)780 void TextOverlayComponent::SetTranslateButtonMarker(const EventMarker& onTranslate)
781 {
782 translateButtonMarker_ = onTranslate;
783 }
784
SetShareButtonMarker(const EventMarker & onShare)785 void TextOverlayComponent::SetShareButtonMarker(const EventMarker& onShare)
786 {
787 shareButtonMarker_ = onShare;
788 }
789
SetSearchButtonMarker(const EventMarker & onSearch)790 void TextOverlayComponent::SetSearchButtonMarker(const EventMarker& onSearch)
791 {
792 searchButtonMarker_ = onSearch;
793 }
794
SetPopOverlay(const CommonCallback & popOverlay)795 void TextOverlayComponent::SetPopOverlay(const CommonCallback& popOverlay)
796 {
797 popOverlay_ = popOverlay;
798 }
799
SetContext(const WeakPtr<PipelineContext> & context)800 void TextOverlayComponent::SetContext(const WeakPtr<PipelineContext>& context)
801 {
802 context_ = context;
803 }
804
GetMenu() const805 const RefPtr<SelectPopupComponent>& TextOverlayComponent::GetMenu() const
806 {
807 return menu_;
808 }
809
810 } // namespace OHOS::Ace
811