From 97fc259378b73b62d26da0acba66ddf77db71938 Mon Sep 17 00:00:00 2001 From: Seungkeun Lee Date: Mon, 20 Apr 2015 20:11:58 +0900 Subject: [PATCH] Support Disable Context-menu Change-Id: I76a26c8cb9a535473aaa0ef823ae27a82d2fd040 --- src/runtime/web_application.cc | 4 ++++ src/runtime/web_application.h | 1 + src/runtime/web_view.cc | 29 +++++++++++++++++++++++++++++ src/runtime/web_view.h | 1 + 4 files changed, 35 insertions(+) diff --git a/src/runtime/web_application.cc b/src/runtime/web_application.cc index 007e6bf..23f336f 100755 --- a/src/runtime/web_application.cc +++ b/src/runtime/web_application.cc @@ -356,6 +356,10 @@ void WebApplication::OnLowMemory() { ewk_context_notify_low_memory(ewk_context_); } +bool WebApplication::OnContextMenuDisabled(WebView* /*view*/) { + return !app_data_->setting_info()->context_menu_enabled(); +} + void WebApplication::OnLoadStart(WebView* view) { LoggerD("LoadStart"); } diff --git a/src/runtime/web_application.h b/src/runtime/web_application.h index 7e1bb09..2b8873a 100755 --- a/src/runtime/web_application.h +++ b/src/runtime/web_application.h @@ -50,6 +50,7 @@ class WebApplication : public WebView::EventListener { virtual void OnRendered(WebView* view); virtual void OnLanguageChanged(); virtual void OnLowMemory(); + virtual bool OnContextMenuDisabled(WebView* view); private: void ClearViewStack(); diff --git a/src/runtime/web_view.cc b/src/runtime/web_view.cc index 8413874..dd9588a 100755 --- a/src/runtime/web_view.cc +++ b/src/runtime/web_view.cc @@ -323,6 +323,35 @@ void WebView::Initialize() { console_message_callback, this); + + auto custom_context_menu = [](void* user_data, + Evas_Object*, + void* event_info) { + Ewk_Context_Menu* contextmenu = static_cast(event_info); + WebView* self = static_cast(user_data); + bool disabled = false; + if (self->listener_ && self->listener_->OnContextMenuDisabled(self)) { + disabled = true; + } + int cnt = ewk_context_menu_item_count(contextmenu); + for (unsigned idx = cnt-1; idx > 0; --idx) { + auto* item = ewk_context_menu_nth_item_get(contextmenu, idx); + Ewk_Context_Menu_Item_Tag tag = ewk_context_menu_item_tag_get(item); + switch (tag) { + case EWK_CONTEXT_MENU_ITEM_TAG_OPEN_IMAGE_IN_NEW_WINDOW: + case EWK_CONTEXT_MENU_ITEM_TAG_OPEN_LINK_IN_NEW_WINDOW: + case EWK_CONTEXT_MENU_ITEM_TAG_OPEN_FRAME_IN_NEW_WINDOW: + case EWK_CONTEXT_MENU_ITEM_TAG_SEARCH_WEB: + case EWK_CONTEXT_MENU_ITEM_TAG_DOWNLOAD_IMAGE_TO_DISK: + ewk_context_menu_item_remove(contextmenu, item); + break; + default: + if (disabled) + ewk_context_menu_item_remove(contextmenu, item); + } + } + }; + // rotation support ewk_view_orientation_send(ewk_view_, ToWebRotation(window_->rotation())); rotation_handler_id_ = window_->AddRotationHandler( diff --git a/src/runtime/web_view.h b/src/runtime/web_view.h index 08e57c9..bc503f5 100755 --- a/src/runtime/web_view.h +++ b/src/runtime/web_view.h @@ -40,6 +40,7 @@ class WebView { bool /*lock*/, int /*preferred_rotation*/) {} virtual void OnConsoleMessage(const std::string& /*msg*/, int /*level*/) {} + virtual bool OnContextMenuDisabled(WebView* /*view*/) { return false; } }; WebView(wrt::NativeWindow* window, Ewk_Context* context); -- 2.7.4