• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 #include "bridge/cj_frontend/cppview/search_controller.h"
16 
17 namespace OHOS::Ace::Framework {
18 
CaretPosition(int32_t caretPosition)19 void SearchController::CaretPosition(int32_t caretPosition)
20 {
21     auto controller = controller_.Upgrade();
22     if (controller) {
23         controller->CaretPosition(caretPosition);
24     } else {
25         LOGW("CaretPosition failed, controller is null.");
26     }
27 }
28 
StopEditing()29 void SearchController::StopEditing()
30 {
31     auto controller = controller_.Upgrade();
32     if (controller) {
33         controller->StopEditing();
34     } else {
35         LOGW("StopEditing failed, controller is null.");
36     }
37 }
38 
SetTextSelection(int32_t selectionStart,int32_t selectionEnd,const std::optional<SelectionOptions> & options)39 void SearchController::SetTextSelection(
40     int32_t selectionStart, int32_t selectionEnd, const std::optional<SelectionOptions>& options)
41 {
42     auto controller = controller_.Upgrade();
43     if (controller) {
44         controller->SetTextSelection(selectionStart, selectionEnd, options);
45     } else {
46         LOGW("SetTextSelection failed, controller is null.");
47     }
48 }
49 
GetTextContentLinesNum()50 int32_t SearchController::GetTextContentLinesNum()
51 {
52     int32_t linesNum = -1;
53     auto controller = controller_.Upgrade();
54     if (controller) {
55         linesNum = controller->GetTextContentLinesNum();
56     }
57     return linesNum;
58 }
59 
GetTextContentRect()60 CJRectResult SearchController::GetTextContentRect()
61 {
62     CJRectResult result;
63     auto controller = controller_.Upgrade();
64     if (controller) {
65         Rect rect = controller->GetTextContentRect();
66         result.x = rect.Left();
67         result.y = rect.Top();
68         result.width = rect.Width();
69         result.height = rect.Height();
70     }
71     return result;
72 }
73 
GetCaretOffset()74 CJCaretOffset SearchController::GetCaretOffset()
75 {
76     CJCaretOffset result;
77     auto controller = controller_.Upgrade();
78     if (controller) {
79         NG::OffsetF caretOffset = controller->GetCaretPosition();
80         result.index = controller->GetCaretIndex();
81         result.x = caretOffset.GetX();
82         result.y = caretOffset.GetY();
83     }
84     return result;
85 }
86 
87 } // namespace OHOS::Ace::Framework
88