Support Disable Context-menu
authorSeungkeun Lee <sngn.lee@samsung.com>
Mon, 20 Apr 2015 11:11:58 +0000 (20:11 +0900)
committerSeungkeun Lee <sngn.lee@samsung.com>
Tue, 21 Apr 2015 05:23:48 +0000 (14:23 +0900)
Change-Id: I76a26c8cb9a535473aaa0ef823ae27a82d2fd040

src/runtime/web_application.cc
src/runtime/web_application.h
src/runtime/web_view.cc
src/runtime/web_view.h

index 007e6bf..23f336f 100755 (executable)
@@ -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");
 }
index 7e1bb09..2b8873a 100755 (executable)
@@ -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();
index 8413874..dd9588a 100755 (executable)
@@ -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<Ewk_Context_Menu*>(event_info);
+    WebView* self = static_cast<WebView*>(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(
index 08e57c9..bc503f5 100755 (executable)
@@ -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);