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