Merge pull request !694 from jinweiliu/dev
This commit is contained in:
openharmony_ci
2022-01-20 01:42:07 +00:00
committed by Gitee
9 changed files with 107 additions and 1 deletions
@@ -213,6 +213,7 @@ template("declarative_js_engine") {
"jsview/js_view_context.cpp",
"jsview/js_view_functions.cpp",
"jsview/js_view_stack_processor.cpp",
"jsview/menu/js_context_menu.cpp",
"jsview/scroll_bar/js_scroll_bar.cpp",
"sharedata/js_share_data.cpp",
"view_stack_processor.cpp",
@@ -137,6 +137,7 @@
#include "frameworks/bridge/declarative_frontend/jsview/js_xcomponent.h"
#include "frameworks/bridge/declarative_frontend/jsview/js_xcomponent_controller.h"
#endif
#include "frameworks/bridge/declarative_frontend/jsview/menu/js_context_menu.h"
#include "frameworks/bridge/declarative_frontend/jsview/scroll_bar/js_scroll_bar.h"
#include "frameworks/bridge/declarative_frontend/sharedata/js_share_data.h"
#include "frameworks/core/common/container.h"
@@ -806,6 +807,7 @@ static const std::unordered_map<std::string, std::function<void(BindingTarget)>>
{ "Radio", JSRadio::JSBind },
{ "ActionSheet", JSActionSheet::JSBind },
{ "AlertDialog", JSAlertDialog::JSBind },
{ "ContextMenu", JSContextMenu::JSBind },
{ "AbilityComponent", JSAbilityComponent::JSBind },
{ "TextArea", JSTextArea::JSBind },
{ "TextInput", JSTextInput::JSBind },
@@ -136,6 +136,7 @@
#include "frameworks/bridge/declarative_frontend/jsview/js_xcomponent.h"
#include "frameworks/bridge/declarative_frontend/jsview/js_xcomponent_controller.h"
#endif
#include "frameworks/bridge/declarative_frontend/jsview/menu/js_context_menu.h"
#include "frameworks/bridge/declarative_frontend/jsview/scroll_bar/js_scroll_bar.h"
#include "frameworks/bridge/declarative_frontend/sharedata/js_share_data.h"
#include "frameworks/bridge/js_frontend/engine/quickjs/qjs_utils.h"
@@ -944,7 +945,7 @@ void JsRegisterViews(BindingTarget globalObj)
JSActionSheet::JSBind(globalObj);
JSAlertDialog::JSBind(globalObj);
JSContextMenu::JSBind(globalObj);
JSAbilityComponent::JSBind(globalObj);
JSAbilityComponentController::JSBind(globalObj);
@@ -137,6 +137,7 @@
#include "frameworks/bridge/declarative_frontend/jsview/js_xcomponent.h"
#include "frameworks/bridge/declarative_frontend/jsview/js_xcomponent_controller.h"
#endif
#include "frameworks/bridge/declarative_frontend/jsview/menu/js_context_menu.h"
#include "frameworks/bridge/declarative_frontend/jsview/scroll_bar/js_scroll_bar.h"
#include "frameworks/bridge/declarative_frontend/sharedata/js_share_data.h"
@@ -621,6 +622,7 @@ static const std::unordered_map<std::string, std::function<void(BindingTarget)>>
{"Radio", JSRadio::JSBind},
{"ActionSheet", JSActionSheet::JSBind},
{"AlertDialog", JSAlertDialog::JSBind},
{"ContextMenu", JSContextMenu::JSBind },
{"AbilityComponent", JSAbilityComponent::JSBind},
{"TextArea", JSTextArea::JSBind},
{"TextInput", JSTextInput::JSBind},
@@ -0,0 +1,51 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "frameworks/bridge/declarative_frontend/jsview/menu/js_context_menu.h"
#include "core/common/container.h"
namespace OHOS::Ace::Framework {
void JSContextMenu::Close(const JSCallbackInfo& args)
{
// Close context menu.
auto container = Container::Current();
if (container) {
auto context = container->GetPipelineContext();
auto executor = Container::CurrentTaskExecutor();
if (executor) {
executor->PostTask(
[context]() {
if (context) {
context->CloseContextMenu();
}
},
TaskExecutor::TaskType::UI);
}
}
args.SetReturnValue(args.This());
}
void JSContextMenu::JSBind(BindingTarget globalObj)
{
JSClass<JSContextMenu>::Declare("ContextMenu");
JSClass<JSContextMenu>::StaticMethod("close", &JSContextMenu::Close);
JSClass<JSContextMenu>::Inherit<JSViewAbstract>();
JSClass<JSContextMenu>::Bind<>(globalObj);
}
} // namespace OHOS::Ace::Framework
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_MENU_CONTEXTMENU_H
#define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_MENU_CONTEXTMENU_H
#include "frameworks/bridge/declarative_frontend/jsview/js_interactable_view.h"
#include "frameworks/bridge/declarative_frontend/jsview/js_view_abstract.h"
namespace OHOS::Ace::Framework {
class JSContextMenu : public JSViewAbstract, public JSInteractableView {
public:
static void JSBind(BindingTarget globalObj);
static void Close(const JSCallbackInfo& args);
};
} // namespace OHOS::Ace::Framework
#endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_MENU_CONTEXTMENU_H
@@ -85,6 +85,7 @@ void MenuElement::OnTargetCallback(const ComposeId& id, const Offset& point)
auto popup = data_->GetPopup();
if (id.empty()) {
popup->ShowDialog(stack, point, point, true);
context->SetContextMenu(popup);
return;
}
@@ -61,6 +61,7 @@
#include "core/components/root/root_component.h"
#include "core/components/root/root_element.h"
#include "core/components/scroll/scrollable.h"
#include "core/components/select_popup/select_popup_component.h"
#include "core/components/semi_modal/semi_modal_component.h"
#include "core/components/semi_modal/semi_modal_element.h"
#include "core/components/semi_modal/semi_modal_theme.h"
@@ -967,6 +968,14 @@ RefPtr<DialogComponent> PipelineContext::ShowDialog(const DialogProperties& dial
return dialog;
}
void PipelineContext::CloseContextMenu()
{
auto menu = AceType::DynamicCast<SelectPopupComponent>(contextMenu_);
if (menu) {
menu->HideDialog(SELECT_INVALID_INDEX);
}
}
bool PipelineContext::CanPopPage()
{
auto stageElement = GetStageElement();
@@ -83,6 +83,7 @@ class AccessibilityManager;
class RenderContext;
struct PageTarget;
class DialogComponent;
class SelectPopupComponent;
struct WindowBlurInfo {
float progress_;
@@ -116,6 +117,7 @@ public:
RefPtr<Element> SetupRootElement();
RefPtr<DialogComponent> ShowDialog(const DialogProperties& dialogProperties, bool isRightToLeft);
void CloseContextMenu();
void GetBoundingRectData(int32_t nodeId, Rect& rect);
@@ -915,6 +917,11 @@ public:
void SetPreTargetRenderNode(const RefPtr<RenderNode>& preTargetRenderNode);
const RefPtr<RenderNode> GetPreTargetRenderNode() const;
void SetContextMenu(const RefPtr<Component>& contextMenu)
{
contextMenu_ = contextMenu;
}
double GetDensity() const
{
return density_;
@@ -1123,6 +1130,7 @@ private:
// strong deactivate element and it's id.
std::map<int32_t, RefPtr<Element>> deactivateElements_;
RefPtr<Component> contextMenu_;
// animation frame callback
AnimationCallback animationCallback_;