From 454abe3d1d299f8d0c1b20fd5d1ef7f9658c00d0 Mon Sep 17 00:00:00 2001 From: demon Date: Thu, 20 Jul 2017 18:17:04 +0800 Subject: [PATCH 01/17] + Expose DragHandler.OnDragEnter + Expose DialogHandler.onFileDialog + Expose methods IsFile, IsFileName, IsFileNames in DragData. + Expose FileDialogCallback --- src/browser.pyx | 3 + src/callback.pyx | 23 +++++++ src/cefpython.pyx | 2 + src/client_handler/client_handler.h | 12 +++- src/client_handler/dialog_handler.cpp | 24 +++++-- src/client_handler/drag_handler.cpp | 14 +++++ src/client_handler/drag_handler.h | 23 +++++++ src/compile_time_constants.pxi | 2 +- src/drag_data.pyx | 26 ++++++-- src/extern/cef/cef_callback.pxd | 13 ++++ src/extern/cef/cef_drag_data.pxd | 8 ++- src/handlers/drag_handler.pyx | 90 +++++++++++++++++++++++++++ src/version/cef_version_win.h | 41 +++++++++--- 13 files changed, 255 insertions(+), 26 deletions(-) create mode 100644 src/client_handler/drag_handler.cpp create mode 100644 src/client_handler/drag_handler.h create mode 100644 src/handlers/drag_handler.pyx diff --git a/src/browser.pyx b/src/browser.pyx index 406a01c9..fd670043 100644 --- a/src/browser.pyx +++ b/src/browser.pyx @@ -237,6 +237,9 @@ cdef class PyBrowser: self.allowedClientCallbacks += ["OnTakeFocus", "OnSetFocus", "OnGotFocus"] + + self.allowedClientCallbacks += ["OnDragEnter","OnFileDialog"] + if name not in self.allowedClientCallbacks: raise Exception("Browser.SetClientCallback() failed: unknown " "callback: %s" % name) diff --git a/src/callback.pyx b/src/callback.pyx index 902b9b52..8dc44eda 100644 --- a/src/callback.pyx +++ b/src/callback.pyx @@ -18,3 +18,26 @@ cdef class PyCallback: cpdef py_void Cancel(self): self.cefCallback.get().Cancel() + + + +cdef PyFileDialogCallback CreatePyFileDialogCallback( + CefRefPtr[CefFileDialogCallback] cefCallback): + cdef PyFileDialogCallback pyCallback = PyFileDialogCallback() + pyCallback.cefCallback = cefCallback + return pyCallback + +cdef class PyFileDialogCallback: + cdef CefRefPtr[CefFileDialogCallback] cefCallback + + cpdef py_void Continue(self,int selected_accept_filter,list file_paths): + + cdef cpp_vector[CefString] filePaths + + for f in file_paths: + filePaths.push_back(PyToCefStringValue(f)) + + self.cefCallback.get().Continue(selected_accept_filter,filePaths) + + cpdef py_void Cancel(self): + self.cefCallback.get().Cancel() \ No newline at end of file diff --git a/src/cefpython.pyx b/src/cefpython.pyx index 7b5755eb..bc181e21 100644 --- a/src/cefpython.pyx +++ b/src/cefpython.pyx @@ -517,6 +517,7 @@ IF UNAME_SYSNAME == "Linux": include "handlers/browser_process_handler.pyx" include "handlers/display_handler.pyx" include "handlers/focus_handler.pyx" +include "handlers/drag_handler.pyx" include "handlers/javascript_dialog_handler.pyx" include "handlers/keyboard_handler.pyx" include "handlers/lifespan_handler.pyx" @@ -527,6 +528,7 @@ include "handlers/request_handler.pyx" include "handlers/v8context_handler.pyx" include "handlers/v8function_handler.pyx" + # ----------------------------------------------------------------------------- # Utility functions to provide settings to the C++ browser process code. diff --git a/src/client_handler/client_handler.h b/src/client_handler/client_handler.h index 3e9e3917..23166c1b 100644 --- a/src/client_handler/client_handler.h +++ b/src/client_handler/client_handler.h @@ -21,6 +21,7 @@ #include "load_handler.h" #include "render_handler.h" #include "request_handler.h" +#include "drag_handler.h" class ClientHandler : public CefClient, @@ -34,7 +35,8 @@ class ClientHandler : public CefClient, public LifespanHandler, public LoadHandler, public RenderHandler, - public RequestHandler + public RequestHandler, + public DragHandler { public: ClientHandler(){} @@ -44,11 +46,11 @@ class ClientHandler : public CefClient, return this; } -#if defined(OS_LINUX) +//#if defined(OS_LINUX) CefRefPtr GetDialogHandler() override { return this; } -#endif +//#endif CefRefPtr GetDisplayHandler() override { return this; @@ -86,6 +88,10 @@ class ClientHandler : public CefClient, return this; } + CefRefPtr GetDragHandler() override { + return this; + } + bool OnProcessMessageReceived(CefRefPtr browser, CefProcessId source_process, CefRefPtr message diff --git a/src/client_handler/dialog_handler.cpp b/src/client_handler/dialog_handler.cpp index ab90de9b..5a86c77c 100644 --- a/src/client_handler/dialog_handler.cpp +++ b/src/client_handler/dialog_handler.cpp @@ -4,7 +4,6 @@ #include "dialog_handler.h" - DialogHandler::DialogHandler() { #if defined(OS_LINUX) @@ -22,16 +21,29 @@ bool DialogHandler::OnFileDialog(CefRefPtr browser, int selected_accept_filter, CefRefPtr callback) { -#if defined(OS_LINUX) - return dialog_handler_->OnFileDialog(browser, + bool result; + result = DialogHandlerr_OnFileDialog(browser, mode, title, default_file_path, accept_filters, selected_accept_filter, callback); -#else - return false; -#endif + if(result){ + return result; + }else{ + + #if defined(OS_LINUX) + return dialog_handler_->OnFileDialog(browser, + mode, + title, + default_file_path, + accept_filters, + selected_accept_filter, + callback); + #else + return false; + #endif + } } diff --git a/src/client_handler/drag_handler.cpp b/src/client_handler/drag_handler.cpp new file mode 100644 index 00000000..e22c6735 --- /dev/null +++ b/src/client_handler/drag_handler.cpp @@ -0,0 +1,14 @@ +// Copyright (c) 2016 CEF Python, see the Authors file. +// All rights reserved. Licensed under BSD 3-clause license. +// Project website: https://github.com/cztomczak/cefpython + +#include "drag_handler.h" + + +bool DragHandler::OnDragEnter(CefRefPtr browser, + CefRefPtr dragData, + cef_drag_operations_mask_t mask) +{ + REQUIRE_UI_THREAD(); + return DragHandler_OnDragEnter(browser,dragData,mask); +} diff --git a/src/client_handler/drag_handler.h b/src/client_handler/drag_handler.h new file mode 100644 index 00000000..56115bdf --- /dev/null +++ b/src/client_handler/drag_handler.h @@ -0,0 +1,23 @@ +// Copyright (c) 2016 CEF Python, see the Authors file. +// All rights reserved. Licensed under BSD 3-clause license. +// Project website: https://github.com/cztomczak/cefpython + +#include "common/cefpython_public_api.h" +#include "include/cef_drag_handler.h" + + +class DragHandler : public CefDragHandler +{ +public: + DragHandler(){} + virtual ~DragHandler(){} + + bool OnDragEnter(CefRefPtr browser, + CefRefPtr dragData, + cef_drag_operations_mask_t mask) override; + + + +private: + IMPLEMENT_REFCOUNTING(DragHandler); +}; diff --git a/src/compile_time_constants.pxi b/src/compile_time_constants.pxi index 35f85002..10ec798a 100644 --- a/src/compile_time_constants.pxi +++ b/src/compile_time_constants.pxi @@ -1,3 +1,3 @@ # This file was generated by setup.py -DEF UNAME_SYSNAME = "Linux" +DEF UNAME_SYSNAME = "Windows" DEF PY_MAJOR_VERSION = 2 diff --git a/src/drag_data.pyx b/src/drag_data.pyx index ddb7d9f9..6c2b0734 100644 --- a/src/drag_data.pyx +++ b/src/drag_data.pyx @@ -18,6 +18,28 @@ cdef class DragData: self.cef_drag_data.get().SetFragmentHtml(PyToCefStringValue("none")) self.cef_drag_data.get().SetFragmentBaseURL(PyToCefStringValue("")) + + cpdef py_bool IsFile(self): + return self.cef_drag_data.get().IsFile() + + cpdef py_string GetFileName(self): + return CefToPyString(self.cef_drag_data.get().GetFileName()) + + cpdef list GetFileNames(self): + cdef cpp_vector[CefString] cefNames + self.cef_drag_data.get().GetFileNames(cefNames) + cdef list names = [] + cdef cpp_vector[CefString].iterator iterator = cefNames.begin() + cdef CefString cefString + while iterator != cefNames.end(): + cefString = deref(iterator) + names.append(CefToPyString(cefString)) + preinc(iterator) + + return names + # return [] + + cpdef py_bool IsLink(self): return self.cef_drag_data.get().IsLink() @@ -45,10 +67,6 @@ cdef class DragData: raise Exception("Image is not available") return PyImage_Init(cef_image) - cpdef tuple GetImageHotspot(self): - cdef CefPoint point = self.cef_drag_data.get().GetImageHotspot() - return (point.x, point.y) - cpdef py_bool HasImage(self): return self.cef_drag_data.get().HasImage() diff --git a/src/extern/cef/cef_callback.pxd b/src/extern/cef/cef_callback.pxd index 5189d07c..a2c53157 100644 --- a/src/extern/cef/cef_callback.pxd +++ b/src/extern/cef/cef_callback.pxd @@ -2,6 +2,10 @@ # All rights reserved. Licensed under BSD 3-clause license. # Project website: https://github.com/cztomczak/cefpython +from cef_string cimport CefString +# from libcpp cimport bool as cpp_bool +from libcpp.vector cimport vector as cpp_vector + cdef extern from "include/cef_callback.h": cdef cppclass CefCallback: @@ -10,3 +14,12 @@ cdef extern from "include/cef_callback.h": cdef cppclass CefCompletionCallback: void OnComplete() + + +cdef extern from "include/cef_dialog_handler.h": + + cdef cppclass CefFileDialogCallback: + void Continue(int selected_accept_filter, + const cpp_vector[CefString]& file_paths) + + void Cancel() \ No newline at end of file diff --git a/src/extern/cef/cef_drag_data.pxd b/src/extern/cef/cef_drag_data.pxd index 88fd3fa5..fcac0653 100644 --- a/src/extern/cef/cef_drag_data.pxd +++ b/src/extern/cef/cef_drag_data.pxd @@ -6,10 +6,15 @@ from libcpp cimport bool as cpp_bool from cef_string cimport CefString from cef_ptr cimport CefRefPtr from cef_image cimport CefImage -from cef_types cimport CefPoint + +from libcpp.vector cimport vector as cpp_vector cdef extern from "include/cef_drag_data.h": cdef cppclass CefDragData: + + cpp_bool IsFile() + CefString GetFileName() + cpp_bool GetFileNames(cpp_vector[CefString]& names) cpp_bool IsLink() cpp_bool IsFragment() CefString GetLinkURL() @@ -21,7 +26,6 @@ cdef extern from "include/cef_drag_data.h": void SetFragmentBaseURL(const CefString& base_url) cpp_bool HasImage() CefRefPtr[CefImage] GetImage() - CefPoint GetImageHotspot() cdef CefRefPtr[CefDragData] CefDragData_Create "CefDragData::Create"() diff --git a/src/handlers/drag_handler.pyx b/src/handlers/drag_handler.pyx new file mode 100644 index 00000000..070557ad --- /dev/null +++ b/src/handlers/drag_handler.pyx @@ -0,0 +1,90 @@ +# Copyright (c) 2012 CEF Python, see the Authors file. +# All rights reserved. Licensed under BSD 3-clause license. +# Project website: https://github.com/cztomczak/cefpython + +include "../cefpython.pyx" +include "../browser.pyx" +# +cimport cef_types + +cdef public cpp_bool DragHandler_OnDragEnter(CefRefPtr[CefBrowser] cef_browser, + CefRefPtr[CefDragData] cef_drag_data, + uint32 mask + ) except * with gil: + + cdef PyBrowser pyBrowser + cdef DragData drag_data + + cdef py_bool returnValue + try: + pyBrowser = GetPyBrowser(cef_browser, "OnDragEnter") + drag_data = DragData_Init(cef_drag_data) + + + callback = pyBrowser.GetClientCallback("OnDragEnter") + if callback: + returnValue = callback(browser=pyBrowser, + dragData=drag_data, + mask=mask) + + + return bool(returnValue) + + except: + (exc_type, exc_value, exc_trace) = sys.exc_info() + sys.excepthook(exc_type, exc_value, exc_trace) + + return False + + +cdef public cpp_bool DialogHandlerr_OnFileDialog(CefRefPtr[CefBrowser] cef_browser, + uint32 mode, + const CefString& cefTitle, + const CefString& cefDefaultFilePath, + const cpp_vector[CefString]& cefAcceptFilters, + int selected_accept_filter, + CefRefPtr[CefFileDialogCallback] cefFileDialogCallback + ) except * with gil: + + + cdef PyBrowser pyBrowser + cdef py_bool returnValue + cdef py_string title + cdef py_string default_file_path + cdef list accept_filters = [] + cdef cpp_vector[CefString].iterator it + + try: + pyBrowser = GetPyBrowser(cef_browser, "OnFileDialog") + + title = CefToPyString(cefTitle) + default_file_path = CefToPyString(cefDefaultFilePath) + + for i in range(cefAcceptFilters.size()): + accept_filters.append(CefToPyString(cefAcceptFilters[i])) + + + callback = pyBrowser.GetClientCallback("OnFileDialog") + if callback: + returnValue = callback(browser=pyBrowser, + mode=mode, + title=title, + default_file_path=default_file_path, + accept_filters=accept_filters, + selected_accept_filter=selected_accept_filter, + file_dialog_callback = CreatePyFileDialogCallback(cefFileDialogCallback) + ) + + + return bool(returnValue) + + except: + (exc_type, exc_value, exc_trace) = sys.exc_info() + sys.excepthook(exc_type, exc_value, exc_trace) + + return False + + + + + diff --git a/src/version/cef_version_win.h b/src/version/cef_version_win.h index 526e4630..328358b9 100644 --- a/src/version/cef_version_win.h +++ b/src/version/cef_version_win.h @@ -35,16 +35,28 @@ #ifndef CEF_INCLUDE_CEF_VERSION_H_ #define CEF_INCLUDE_CEF_VERSION_H_ -#define CEF_VERSION "3.3029.1604.g364cd86" +//#define CEF_VERSION "3.3029.1604.g364cd86" +//#define CEF_VERSION_MAJOR 3 +//#define CEF_COMMIT_NUMBER 1604 +//#define CEF_COMMIT_HASH "364cd863b14617f21e6bf8fd3ca3faea01e2ef38" +//#define COPYRIGHT_YEAR 2017 +// +//#define CHROME_VERSION_MAJOR 58 +//#define CHROME_VERSION_MINOR 0 +//#define CHROME_VERSION_BUILD 3029 +//#define CHROME_VERSION_PATCH 81 + +#define CEF_VERSION "3.2987.1601.gf035232" #define CEF_VERSION_MAJOR 3 -#define CEF_COMMIT_NUMBER 1604 -#define CEF_COMMIT_HASH "364cd863b14617f21e6bf8fd3ca3faea01e2ef38" +#define CEF_COMMIT_NUMBER 1601 +#define CEF_COMMIT_HASH "f035232c082f837d2b85bd7821a93a54fc742775" #define COPYRIGHT_YEAR 2017 -#define CHROME_VERSION_MAJOR 58 +#define CHROME_VERSION_MAJOR 57 #define CHROME_VERSION_MINOR 0 -#define CHROME_VERSION_BUILD 3029 -#define CHROME_VERSION_PATCH 81 +#define CHROME_VERSION_BUILD 2987 +#define CHROME_VERSION_PATCH 133 + #define DO_MAKE_STRING(p) #p #define MAKE_STRING(p) DO_MAKE_STRING(p) @@ -63,13 +75,22 @@ extern "C" { // universal hash value will change if any platform is affected whereas the // platform hash values will change only if that particular platform is // affected. -#define CEF_API_HASH_UNIVERSAL "f0e835273a00acd02a699af272fc8f6ff9c5645c" +//#define CEF_API_HASH_UNIVERSAL "f0e835273a00acd02a699af272fc8f6ff9c5645c" +//#if defined(OS_WIN) +//#define CEF_API_HASH_PLATFORM "3cf7ac2b9aa61adfb9e5decdf0d32fbf78813355" +//#elif defined(OS_MACOSX) +//#define CEF_API_HASH_PLATFORM "f1d2ed00ab93e03a215fd787e6da9127e2949fd8" +//#elif defined(OS_LINUX) +//#define CEF_API_HASH_PLATFORM "698e69c4297cc63b9893558a8591e7bd7aeeb0d4" +//#endif + +#define CEF_API_HASH_UNIVERSAL "b0a24e3e202f3d8b72f2fbc1ebc5864f96ec16ae" #if defined(OS_WIN) -#define CEF_API_HASH_PLATFORM "3cf7ac2b9aa61adfb9e5decdf0d32fbf78813355" +#define CEF_API_HASH_PLATFORM "1c6a27f840ac87c8c971350c907edbe2c5fa0387" #elif defined(OS_MACOSX) -#define CEF_API_HASH_PLATFORM "f1d2ed00ab93e03a215fd787e6da9127e2949fd8" +#define CEF_API_HASH_PLATFORM "1567db600ee83cc2a59bb8c17ca416d11a7c9b8a" #elif defined(OS_LINUX) -#define CEF_API_HASH_PLATFORM "698e69c4297cc63b9893558a8591e7bd7aeeb0d4" +#define CEF_API_HASH_PLATFORM "1f9f9e15bf7cf13de2557ddd411dfc9f694503b0" #endif // Returns CEF version information for the libcef library. The |entry| From c0ad480b300002f8d65b8d8c9594647510ecb2ef Mon Sep 17 00:00:00 2001 From: demon Date: Fri, 21 Jul 2017 11:28:58 +0800 Subject: [PATCH 02/17] * restructure dialog_handler to a correct file --- src/browser.pyx | 7 ++- src/callback.pyx | 23 --------- src/cefpython.pyx | 2 + src/extern/cef/cef_callback.pxd | 8 --- src/extern/cef/cef_dialog_handler.pxd | 16 ++++++ src/handlers/dialog_handler.pyx | 59 ++++++++++++++++++++++ src/handlers/drag_handler.pyx | 70 ++++++++------------------- 7 files changed, 104 insertions(+), 81 deletions(-) create mode 100644 src/extern/cef/cef_dialog_handler.pxd create mode 100644 src/handlers/dialog_handler.pyx diff --git a/src/browser.pyx b/src/browser.pyx index fd670043..9f78a38d 100644 --- a/src/browser.pyx +++ b/src/browser.pyx @@ -237,8 +237,13 @@ cdef class PyBrowser: self.allowedClientCallbacks += ["OnTakeFocus", "OnSetFocus", "OnGotFocus"] + # DragHandler + self.allowedClientCallbacks += ["OnDragEnter"] + + # DialogHanlder + self.allowedClientCallbacks += ["OnFileDialog"] + - self.allowedClientCallbacks += ["OnDragEnter","OnFileDialog"] if name not in self.allowedClientCallbacks: raise Exception("Browser.SetClientCallback() failed: unknown " diff --git a/src/callback.pyx b/src/callback.pyx index 8dc44eda..902b9b52 100644 --- a/src/callback.pyx +++ b/src/callback.pyx @@ -18,26 +18,3 @@ cdef class PyCallback: cpdef py_void Cancel(self): self.cefCallback.get().Cancel() - - - -cdef PyFileDialogCallback CreatePyFileDialogCallback( - CefRefPtr[CefFileDialogCallback] cefCallback): - cdef PyFileDialogCallback pyCallback = PyFileDialogCallback() - pyCallback.cefCallback = cefCallback - return pyCallback - -cdef class PyFileDialogCallback: - cdef CefRefPtr[CefFileDialogCallback] cefCallback - - cpdef py_void Continue(self,int selected_accept_filter,list file_paths): - - cdef cpp_vector[CefString] filePaths - - for f in file_paths: - filePaths.push_back(PyToCefStringValue(f)) - - self.cefCallback.get().Continue(selected_accept_filter,filePaths) - - cpdef py_void Cancel(self): - self.cefCallback.get().Cancel() \ No newline at end of file diff --git a/src/cefpython.pyx b/src/cefpython.pyx index bc181e21..46fefce3 100644 --- a/src/cefpython.pyx +++ b/src/cefpython.pyx @@ -431,6 +431,7 @@ from cef_command_line cimport * from cef_request_context cimport * from cef_request_context_handler cimport * from request_context_handler cimport * +from cef_dialog_handler cimport * from cef_jsdialog_handler cimport * from cef_path_util cimport * from cef_drag_data cimport * @@ -518,6 +519,7 @@ include "handlers/browser_process_handler.pyx" include "handlers/display_handler.pyx" include "handlers/focus_handler.pyx" include "handlers/drag_handler.pyx" +include "handlers/dialog_handler.pyx" include "handlers/javascript_dialog_handler.pyx" include "handlers/keyboard_handler.pyx" include "handlers/lifespan_handler.pyx" diff --git a/src/extern/cef/cef_callback.pxd b/src/extern/cef/cef_callback.pxd index a2c53157..17553643 100644 --- a/src/extern/cef/cef_callback.pxd +++ b/src/extern/cef/cef_callback.pxd @@ -15,11 +15,3 @@ cdef extern from "include/cef_callback.h": cdef cppclass CefCompletionCallback: void OnComplete() - -cdef extern from "include/cef_dialog_handler.h": - - cdef cppclass CefFileDialogCallback: - void Continue(int selected_accept_filter, - const cpp_vector[CefString]& file_paths) - - void Cancel() \ No newline at end of file diff --git a/src/extern/cef/cef_dialog_handler.pxd b/src/extern/cef/cef_dialog_handler.pxd new file mode 100644 index 00000000..649e6f28 --- /dev/null +++ b/src/extern/cef/cef_dialog_handler.pxd @@ -0,0 +1,16 @@ +# Copyright (c) 2013 CEF Python, see the Authors file. +# All rights reserved. Licensed under BSD 3-clause license. +# Project website: https://github.com/cztomczak/cefpython + +from cef_string cimport CefString +# from libcpp cimport bool as cpp_bool +from libcpp.vector cimport vector as cpp_vector + + +cdef extern from "include/cef_dialog_handler.h": + + cdef cppclass CefFileDialogCallback: + void Continue(int selected_accept_filter, + const cpp_vector[CefString]& file_paths) + + void Cancel() \ No newline at end of file diff --git a/src/handlers/dialog_handler.pyx b/src/handlers/dialog_handler.pyx new file mode 100644 index 00000000..e39a9d1a --- /dev/null +++ b/src/handlers/dialog_handler.pyx @@ -0,0 +1,59 @@ +# Copyright (c) 2012 CEF Python, see the Authors file. +# All rights reserved. Licensed under BSD 3-clause license. +# Project website: https://github.com/cztomczak/cefpython + +include "../cefpython.pyx" +include "../browser.pyx" + + +cdef public cpp_bool DialogHandlerr_OnFileDialog(CefRefPtr[CefBrowser] cef_browser, + uint32 mode, + const CefString& cefTitle, + const CefString& cefDefaultFilePath, + const cpp_vector[CefString]& cefAcceptFilters, + int selected_accept_filter, + CefRefPtr[CefFileDialogCallback] cefFileDialogCallback + ) except * with gil: + + + cdef PyBrowser pyBrowser + cdef py_bool returnValue + cdef py_string title + cdef py_string default_file_path + cdef list accept_filters = [] + cdef cpp_vector[CefString].iterator it + + try: + pyBrowser = GetPyBrowser(cef_browser, "OnFileDialog") + + title = CefToPyString(cefTitle) + default_file_path = CefToPyString(cefDefaultFilePath) + + for i in range(cefAcceptFilters.size()): + accept_filters.append(CefToPyString(cefAcceptFilters[i])) + + + callback = pyBrowser.GetClientCallback("OnFileDialog") + if callback: + returnValue = callback(browser=pyBrowser, + mode=mode, + title=title, + default_file_path=default_file_path, + accept_filters=accept_filters, + selected_accept_filter=selected_accept_filter, + file_dialog_callback = CreatePyFileDialogCallback(cefFileDialogCallback) + ) + + + return bool(returnValue) + + except: + (exc_type, exc_value, exc_trace) = sys.exc_info() + sys.excepthook(exc_type, exc_value, exc_trace) + + return False + + + + + diff --git a/src/handlers/drag_handler.pyx b/src/handlers/drag_handler.pyx index 070557ad..a326a738 100644 --- a/src/handlers/drag_handler.pyx +++ b/src/handlers/drag_handler.pyx @@ -4,8 +4,27 @@ include "../cefpython.pyx" include "../browser.pyx" -# -cimport cef_types + +cdef PyFileDialogCallback CreatePyFileDialogCallback( + CefRefPtr[CefFileDialogCallback] cefCallback): + cdef PyFileDialogCallback pyCallback = PyFileDialogCallback() + pyCallback.cefCallback = cefCallback + return pyCallback + +cdef class PyFileDialogCallback: + cdef CefRefPtr[CefFileDialogCallback] cefCallback + + cpdef py_void Continue(self,int selected_accept_filter,list file_paths): + + cdef cpp_vector[CefString] filePaths + + for f in file_paths: + filePaths.push_back(PyToCefStringValue(f)) + + self.cefCallback.get().Continue(selected_accept_filter,filePaths) + + cpdef py_void Cancel(self): + self.cefCallback.get().Cancel() cdef public cpp_bool DragHandler_OnDragEnter(CefRefPtr[CefBrowser] cef_browser, CefRefPtr[CefDragData] cef_drag_data, @@ -37,53 +56,6 @@ cdef public cpp_bool DragHandler_OnDragEnter(CefRefPtr[CefBrowser] cef_browser, return False -cdef public cpp_bool DialogHandlerr_OnFileDialog(CefRefPtr[CefBrowser] cef_browser, - uint32 mode, - const CefString& cefTitle, - const CefString& cefDefaultFilePath, - const cpp_vector[CefString]& cefAcceptFilters, - int selected_accept_filter, - CefRefPtr[CefFileDialogCallback] cefFileDialogCallback - ) except * with gil: - - - cdef PyBrowser pyBrowser - cdef py_bool returnValue - cdef py_string title - cdef py_string default_file_path - cdef list accept_filters = [] - cdef cpp_vector[CefString].iterator it - - try: - pyBrowser = GetPyBrowser(cef_browser, "OnFileDialog") - - title = CefToPyString(cefTitle) - default_file_path = CefToPyString(cefDefaultFilePath) - - for i in range(cefAcceptFilters.size()): - accept_filters.append(CefToPyString(cefAcceptFilters[i])) - - - callback = pyBrowser.GetClientCallback("OnFileDialog") - if callback: - returnValue = callback(browser=pyBrowser, - mode=mode, - title=title, - default_file_path=default_file_path, - accept_filters=accept_filters, - selected_accept_filter=selected_accept_filter, - file_dialog_callback = CreatePyFileDialogCallback(cefFileDialogCallback) - ) - - - return bool(returnValue) - - except: - (exc_type, exc_value, exc_trace) = sys.exc_info() - sys.excepthook(exc_type, exc_value, exc_trace) - - return False - From 1300969d191718d82ee37c0940ece8c8577dea40 Mon Sep 17 00:00:00 2001 From: demon Date: Fri, 21 Jul 2017 15:25:49 +0800 Subject: [PATCH 03/17] * Update docs for DragData --- api/API-index.md | 3 +++ api/DragData.md | 29 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/api/API-index.md b/api/API-index.md index e998df93..02cdb5e0 100644 --- a/api/API-index.md +++ b/api/API-index.md @@ -211,8 +211,11 @@ * [IsProcessDpiAware](DpiAware.md#isprocessdpiaware) * [SetProcessDpiAware](DpiAware.md#setprocessdpiaware) * [DragData (object)](DragData.md#dragdata-object) + * [IsFile](DragData.md#isfile) * [IsLink](DragData.md#islink) * [IsFragment](DragData.md#isfragment) + * [GetFileName](DragData.md#getfilename) + * [GetFileNames](DragData.md#getfilenames) * [GetLinkUrl](DragData.md#getlinkurl) * [GetLinkTitle](DragData.md#getlinktitle) * [GetFragmentText](DragData.md#getfragmenttext) diff --git a/api/DragData.md b/api/DragData.md index cc7dee86..910764d7 100644 --- a/api/DragData.md +++ b/api/DragData.md @@ -6,8 +6,11 @@ Table of contents: * [Methods](#methods) + * [IsFile](#isfile) * [IsLink](#islink) * [IsFragment](#isfragment) + * [GetFileName](#getfilename) + * [GetFileNames](#getfilenames) * [GetLinkUrl](#getlinkurl) * [GetLinkTitle](#getlinktitle) * [GetFragmentText](#getfragmenttext) @@ -19,6 +22,13 @@ Table of contents: ## Methods +### IsFile + +| | | +| --- | --- | +| __Return__ | bool | + +Returns true if the drag data is a file. ### IsLink @@ -38,6 +48,25 @@ Returns true if the drag data is a link. Returns true if the drag data is a text or html fragment. +### GetFileName + +| | | +| --- | --- | +| __Return__ | string | + + +Return the name of the file being dragged out of the browser window. + + +### GetFileNames + +| | | +| --- | --- | +| __Return__ | list | + + +Return the list of file names that are being dragged into the browser window. + ### GetLinkUrl | | | From f18e366e1d4a8f96ce29847c3aeaa68c3f4dda82 Mon Sep 17 00:00:00 2001 From: demon Date: Fri, 21 Jul 2017 15:26:29 +0800 Subject: [PATCH 04/17] Update README --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index a8721b78..27a89ab5 100644 --- a/README.md +++ b/README.md @@ -469,8 +469,11 @@ Additional information for v31.2 release: * [IsProcessDpiAware](api/DpiAware.md#isprocessdpiaware) * [SetProcessDpiAware](api/DpiAware.md#setprocessdpiaware) * [DragData (object)](api/DragData.md#dragdata-object) + * [IsFile](api/DragData.md#isfile) * [IsLink](api/DragData.md#islink) * [IsFragment](api/DragData.md#isfragment) + * [GetFileName](api/DragData.md#getfilename) + * [GetFileNames](api/DragData.md#getfilenames) * [GetLinkUrl](api/DragData.md#getlinkurl) * [GetLinkTitle](api/DragData.md#getlinktitle) * [GetFragmentText](api/DragData.md#getfragmenttext) From 1ee0a856c9fb6dc8126bc5b589f7aecc2b7acf42 Mon Sep 17 00:00:00 2001 From: demon Date: Fri, 21 Jul 2017 15:27:50 +0800 Subject: [PATCH 05/17] * Fixed coding style. --- src/browser.pyx | 2 -- src/client_handler/client_handler.h | 2 -- src/client_handler/dialog_handler.cpp | 26 ++++++++--------- src/client_handler/drag_handler.cpp | 8 +++--- src/client_handler/drag_handler.h | 2 +- src/drag_data.pyx | 6 ++-- src/extern/cef/cef_callback.pxd | 1 - src/extern/cef/cef_dialog_handler.pxd | 6 ++-- src/extern/cef/cef_drag_data.pxd | 2 ++ src/handlers/dialog_handler.pyx | 41 ++++++++++++++------------- src/handlers/drag_handler.pyx | 27 ++++++------------ 11 files changed, 54 insertions(+), 69 deletions(-) diff --git a/src/browser.pyx b/src/browser.pyx index 9f78a38d..f17994d1 100644 --- a/src/browser.pyx +++ b/src/browser.pyx @@ -243,8 +243,6 @@ cdef class PyBrowser: # DialogHanlder self.allowedClientCallbacks += ["OnFileDialog"] - - if name not in self.allowedClientCallbacks: raise Exception("Browser.SetClientCallback() failed: unknown " "callback: %s" % name) diff --git a/src/client_handler/client_handler.h b/src/client_handler/client_handler.h index 23166c1b..4d3658c2 100644 --- a/src/client_handler/client_handler.h +++ b/src/client_handler/client_handler.h @@ -46,11 +46,9 @@ class ClientHandler : public CefClient, return this; } -//#if defined(OS_LINUX) CefRefPtr GetDialogHandler() override { return this; } -//#endif CefRefPtr GetDisplayHandler() override { return this; diff --git a/src/client_handler/dialog_handler.cpp b/src/client_handler/dialog_handler.cpp index 5a86c77c..beea56e7 100644 --- a/src/client_handler/dialog_handler.cpp +++ b/src/client_handler/dialog_handler.cpp @@ -22,7 +22,7 @@ bool DialogHandler::OnFileDialog(CefRefPtr browser, CefRefPtr callback) { bool result; - result = DialogHandlerr_OnFileDialog(browser, + result = DialogHandler_OnFileDialog(browser, mode, title, default_file_path, @@ -32,18 +32,16 @@ bool DialogHandler::OnFileDialog(CefRefPtr browser, if(result){ return result; }else{ - - #if defined(OS_LINUX) - return dialog_handler_->OnFileDialog(browser, - mode, - title, - default_file_path, - accept_filters, - selected_accept_filter, - callback); - #else - return false; - #endif +#if defined(OS_LINUX) + return dialog_handler_->OnFileDialog(browser, + mode, + title, + default_file_path, + accept_filters, + selected_accept_filter, + callback); +#else + return false; +#endif } - } diff --git a/src/client_handler/drag_handler.cpp b/src/client_handler/drag_handler.cpp index e22c6735..4082164a 100644 --- a/src/client_handler/drag_handler.cpp +++ b/src/client_handler/drag_handler.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016 CEF Python, see the Authors file. +// Copyright (c) 2017 CEF Python, see the Authors file. // All rights reserved. Licensed under BSD 3-clause license. // Project website: https://github.com/cztomczak/cefpython @@ -6,9 +6,9 @@ bool DragHandler::OnDragEnter(CefRefPtr browser, - CefRefPtr dragData, - cef_drag_operations_mask_t mask) + CefRefPtr dragData, + cef_drag_operations_mask_t mask) { REQUIRE_UI_THREAD(); - return DragHandler_OnDragEnter(browser,dragData,mask); + return DragHandler_OnDragEnter(browser, dragData, mask); } diff --git a/src/client_handler/drag_handler.h b/src/client_handler/drag_handler.h index 56115bdf..cb107327 100644 --- a/src/client_handler/drag_handler.h +++ b/src/client_handler/drag_handler.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016 CEF Python, see the Authors file. +// Copyright (c) 2017 CEF Python, see the Authors file. // All rights reserved. Licensed under BSD 3-clause license. // Project website: https://github.com/cztomczak/cefpython diff --git a/src/drag_data.pyx b/src/drag_data.pyx index 6c2b0734..7ff9b424 100644 --- a/src/drag_data.pyx +++ b/src/drag_data.pyx @@ -37,8 +37,6 @@ cdef class DragData: preinc(iterator) return names - # return [] - cpdef py_bool IsLink(self): return self.cef_drag_data.get().IsLink() @@ -67,6 +65,10 @@ cdef class DragData: raise Exception("Image is not available") return PyImage_Init(cef_image) + cpdef tuple GetImageHotspot(self): + cdef CefPoint point = self.cef_drag_data.get().GetImageHotspot() + return (point.x, point.y) + cpdef py_bool HasImage(self): return self.cef_drag_data.get().HasImage() diff --git a/src/extern/cef/cef_callback.pxd b/src/extern/cef/cef_callback.pxd index 17553643..3f9ade20 100644 --- a/src/extern/cef/cef_callback.pxd +++ b/src/extern/cef/cef_callback.pxd @@ -3,7 +3,6 @@ # Project website: https://github.com/cztomczak/cefpython from cef_string cimport CefString -# from libcpp cimport bool as cpp_bool from libcpp.vector cimport vector as cpp_vector cdef extern from "include/cef_callback.h": diff --git a/src/extern/cef/cef_dialog_handler.pxd b/src/extern/cef/cef_dialog_handler.pxd index 649e6f28..b85f7abc 100644 --- a/src/extern/cef/cef_dialog_handler.pxd +++ b/src/extern/cef/cef_dialog_handler.pxd @@ -1,9 +1,8 @@ -# Copyright (c) 2013 CEF Python, see the Authors file. +# Copyright (c) 2017 CEF Python, see the Authors file. # All rights reserved. Licensed under BSD 3-clause license. # Project website: https://github.com/cztomczak/cefpython from cef_string cimport CefString -# from libcpp cimport bool as cpp_bool from libcpp.vector cimport vector as cpp_vector @@ -12,5 +11,4 @@ cdef extern from "include/cef_dialog_handler.h": cdef cppclass CefFileDialogCallback: void Continue(int selected_accept_filter, const cpp_vector[CefString]& file_paths) - - void Cancel() \ No newline at end of file + void Cancel() diff --git a/src/extern/cef/cef_drag_data.pxd b/src/extern/cef/cef_drag_data.pxd index fcac0653..3e01ad93 100644 --- a/src/extern/cef/cef_drag_data.pxd +++ b/src/extern/cef/cef_drag_data.pxd @@ -6,6 +6,7 @@ from libcpp cimport bool as cpp_bool from cef_string cimport CefString from cef_ptr cimport CefRefPtr from cef_image cimport CefImage +from cef_types cimport CefPoint from libcpp.vector cimport vector as cpp_vector @@ -26,6 +27,7 @@ cdef extern from "include/cef_drag_data.h": void SetFragmentBaseURL(const CefString& base_url) cpp_bool HasImage() CefRefPtr[CefImage] GetImage() + CefPoint GetImageHotspot() cdef CefRefPtr[CefDragData] CefDragData_Create "CefDragData::Create"() diff --git a/src/handlers/dialog_handler.pyx b/src/handlers/dialog_handler.pyx index e39a9d1a..f5e1f0a1 100644 --- a/src/handlers/dialog_handler.pyx +++ b/src/handlers/dialog_handler.pyx @@ -1,4 +1,4 @@ -# Copyright (c) 2012 CEF Python, see the Authors file. +# Copyright (c) 2017 CEF Python, see the Authors file. # All rights reserved. Licensed under BSD 3-clause license. # Project website: https://github.com/cztomczak/cefpython @@ -6,40 +6,41 @@ include "../cefpython.pyx" include "../browser.pyx" -cdef public cpp_bool DialogHandlerr_OnFileDialog(CefRefPtr[CefBrowser] cef_browser, - uint32 mode, - const CefString& cefTitle, - const CefString& cefDefaultFilePath, - const cpp_vector[CefString]& cefAcceptFilters, - int selected_accept_filter, - CefRefPtr[CefFileDialogCallback] cefFileDialogCallback - ) except * with gil: +cdef public cpp_bool DialogHandler_OnFileDialog( + CefRefPtr[CefBrowser] cef_browser, + uint32 mode, + const CefString& cefTitle, + const CefString& cefDefaultFilePath, + const cpp_vector[CefString]& cefAcceptFilters, + int selected_accept_filter, + CefRefPtr[CefFileDialogCallback] cefFileDialogCallback + ) except * with gil: cdef PyBrowser pyBrowser cdef py_bool returnValue - cdef py_string title - cdef py_string default_file_path - cdef list accept_filters = [] - cdef cpp_vector[CefString].iterator it + cdef py_string pyTitle + cdef py_string pyDefaultFilePath + cdef list pyAcceptFilters = [] try: pyBrowser = GetPyBrowser(cef_browser, "OnFileDialog") - title = CefToPyString(cefTitle) - default_file_path = CefToPyString(cefDefaultFilePath) + pyTitle = CefToPyString(cefTitle) + pyDefaultFilePath = CefToPyString(cefDefaultFilePath) for i in range(cefAcceptFilters.size()): - accept_filters.append(CefToPyString(cefAcceptFilters[i])) + pyAcceptFilters.append(CefToPyString(cefAcceptFilters[i])) callback = pyBrowser.GetClientCallback("OnFileDialog") if callback: - returnValue = callback(browser=pyBrowser, + returnValue = callback( + browser=pyBrowser, mode=mode, - title=title, - default_file_path=default_file_path, - accept_filters=accept_filters, + title=pyTitle, + default_file_path=pyDefaultFilePath, + accept_filters=pyAcceptFilters, selected_accept_filter=selected_accept_filter, file_dialog_callback = CreatePyFileDialogCallback(cefFileDialogCallback) ) diff --git a/src/handlers/drag_handler.pyx b/src/handlers/drag_handler.pyx index a326a738..cb95e460 100644 --- a/src/handlers/drag_handler.pyx +++ b/src/handlers/drag_handler.pyx @@ -1,4 +1,4 @@ -# Copyright (c) 2012 CEF Python, see the Authors file. +# Copyright (c) 2017 CEF Python, see the Authors file. # All rights reserved. Licensed under BSD 3-clause license. # Project website: https://github.com/cztomczak/cefpython @@ -13,23 +13,20 @@ cdef PyFileDialogCallback CreatePyFileDialogCallback( cdef class PyFileDialogCallback: cdef CefRefPtr[CefFileDialogCallback] cefCallback - cpdef py_void Continue(self,int selected_accept_filter,list file_paths): - cdef cpp_vector[CefString] filePaths - for f in file_paths: filePaths.push_back(PyToCefStringValue(f)) - self.cefCallback.get().Continue(selected_accept_filter,filePaths) cpdef py_void Cancel(self): self.cefCallback.get().Cancel() -cdef public cpp_bool DragHandler_OnDragEnter(CefRefPtr[CefBrowser] cef_browser, - CefRefPtr[CefDragData] cef_drag_data, - uint32 mask - ) except * with gil: +cdef public cpp_bool DragHandler_OnDragEnter( + CefRefPtr[CefBrowser] cef_browser, + CefRefPtr[CefDragData] cef_drag_data, + uint32 mask + ) except * with gil: cdef PyBrowser pyBrowser cdef DragData drag_data @@ -39,13 +36,11 @@ cdef public cpp_bool DragHandler_OnDragEnter(CefRefPtr[CefBrowser] cef_browser, pyBrowser = GetPyBrowser(cef_browser, "OnDragEnter") drag_data = DragData_Init(cef_drag_data) - callback = pyBrowser.GetClientCallback("OnDragEnter") if callback: returnValue = callback(browser=pyBrowser, - dragData=drag_data, - mask=mask) - + dragData=drag_data, + mask=mask) return bool(returnValue) @@ -54,9 +49,3 @@ cdef public cpp_bool DragHandler_OnDragEnter(CefRefPtr[CefBrowser] cef_browser, sys.excepthook(exc_type, exc_value, exc_trace) return False - - - - - - From aa346abddaa5492501b8672ec6f93a20d22a91fa Mon Sep 17 00:00:00 2001 From: demon Date: Fri, 21 Jul 2017 15:56:16 +0800 Subject: [PATCH 06/17] Fixed coding style. --- src/drag_data.pyx | 2 -- src/extern/cef/cef_callback.pxd | 4 ---- src/extern/cef/cef_dialog_handler.pxd | 1 - src/extern/cef/cef_drag_data.pxd | 1 - src/handlers/dialog_handler.pyx | 3 --- 5 files changed, 11 deletions(-) diff --git a/src/drag_data.pyx b/src/drag_data.pyx index 7ff9b424..51d4551d 100644 --- a/src/drag_data.pyx +++ b/src/drag_data.pyx @@ -18,7 +18,6 @@ cdef class DragData: self.cef_drag_data.get().SetFragmentHtml(PyToCefStringValue("none")) self.cef_drag_data.get().SetFragmentBaseURL(PyToCefStringValue("")) - cpdef py_bool IsFile(self): return self.cef_drag_data.get().IsFile() @@ -35,7 +34,6 @@ cdef class DragData: cefString = deref(iterator) names.append(CefToPyString(cefString)) preinc(iterator) - return names cpdef py_bool IsLink(self): diff --git a/src/extern/cef/cef_callback.pxd b/src/extern/cef/cef_callback.pxd index 3f9ade20..5189d07c 100644 --- a/src/extern/cef/cef_callback.pxd +++ b/src/extern/cef/cef_callback.pxd @@ -2,9 +2,6 @@ # All rights reserved. Licensed under BSD 3-clause license. # Project website: https://github.com/cztomczak/cefpython -from cef_string cimport CefString -from libcpp.vector cimport vector as cpp_vector - cdef extern from "include/cef_callback.h": cdef cppclass CefCallback: @@ -13,4 +10,3 @@ cdef extern from "include/cef_callback.h": cdef cppclass CefCompletionCallback: void OnComplete() - diff --git a/src/extern/cef/cef_dialog_handler.pxd b/src/extern/cef/cef_dialog_handler.pxd index b85f7abc..bc86d553 100644 --- a/src/extern/cef/cef_dialog_handler.pxd +++ b/src/extern/cef/cef_dialog_handler.pxd @@ -5,7 +5,6 @@ from cef_string cimport CefString from libcpp.vector cimport vector as cpp_vector - cdef extern from "include/cef_dialog_handler.h": cdef cppclass CefFileDialogCallback: diff --git a/src/extern/cef/cef_drag_data.pxd b/src/extern/cef/cef_drag_data.pxd index 3e01ad93..dd57b657 100644 --- a/src/extern/cef/cef_drag_data.pxd +++ b/src/extern/cef/cef_drag_data.pxd @@ -12,7 +12,6 @@ from libcpp.vector cimport vector as cpp_vector cdef extern from "include/cef_drag_data.h": cdef cppclass CefDragData: - cpp_bool IsFile() CefString GetFileName() cpp_bool GetFileNames(cpp_vector[CefString]& names) diff --git a/src/handlers/dialog_handler.pyx b/src/handlers/dialog_handler.pyx index f5e1f0a1..1d7b60b0 100644 --- a/src/handlers/dialog_handler.pyx +++ b/src/handlers/dialog_handler.pyx @@ -16,7 +16,6 @@ cdef public cpp_bool DialogHandler_OnFileDialog( CefRefPtr[CefFileDialogCallback] cefFileDialogCallback ) except * with gil: - cdef PyBrowser pyBrowser cdef py_bool returnValue cdef py_string pyTitle @@ -32,7 +31,6 @@ cdef public cpp_bool DialogHandler_OnFileDialog( for i in range(cefAcceptFilters.size()): pyAcceptFilters.append(CefToPyString(cefAcceptFilters[i])) - callback = pyBrowser.GetClientCallback("OnFileDialog") if callback: returnValue = callback( @@ -45,7 +43,6 @@ cdef public cpp_bool DialogHandler_OnFileDialog( file_dialog_callback = CreatePyFileDialogCallback(cefFileDialogCallback) ) - return bool(returnValue) except: From 99ed493d74419c8eaff8055f6d7732238147cd6b Mon Sep 17 00:00:00 2001 From: demon Date: Fri, 21 Jul 2017 16:06:23 +0800 Subject: [PATCH 07/17] Fixed coding style --- src/handlers/dialog_handler.pyx | 2 -- src/handlers/drag_handler.pyx | 4 ---- 2 files changed, 6 deletions(-) diff --git a/src/handlers/dialog_handler.pyx b/src/handlers/dialog_handler.pyx index 1d7b60b0..8bae72cc 100644 --- a/src/handlers/dialog_handler.pyx +++ b/src/handlers/dialog_handler.pyx @@ -44,11 +44,9 @@ cdef public cpp_bool DialogHandler_OnFileDialog( ) return bool(returnValue) - except: (exc_type, exc_value, exc_trace) = sys.exc_info() sys.excepthook(exc_type, exc_value, exc_trace) - return False diff --git a/src/handlers/drag_handler.pyx b/src/handlers/drag_handler.pyx index cb95e460..3c00d485 100644 --- a/src/handlers/drag_handler.pyx +++ b/src/handlers/drag_handler.pyx @@ -30,7 +30,6 @@ cdef public cpp_bool DragHandler_OnDragEnter( cdef PyBrowser pyBrowser cdef DragData drag_data - cdef py_bool returnValue try: pyBrowser = GetPyBrowser(cef_browser, "OnDragEnter") @@ -41,11 +40,8 @@ cdef public cpp_bool DragHandler_OnDragEnter( returnValue = callback(browser=pyBrowser, dragData=drag_data, mask=mask) - return bool(returnValue) - except: (exc_type, exc_value, exc_trace) = sys.exc_info() sys.excepthook(exc_type, exc_value, exc_trace) - return False From f03034bb82f1dcf06eebddf38ed69ddb84512926 Mon Sep 17 00:00:00 2001 From: demon Date: Fri, 21 Jul 2017 16:09:24 +0800 Subject: [PATCH 08/17] Fixed coding style. --- src/handlers/drag_handler.pyx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/handlers/drag_handler.pyx b/src/handlers/drag_handler.pyx index 3c00d485..04f868d8 100644 --- a/src/handlers/drag_handler.pyx +++ b/src/handlers/drag_handler.pyx @@ -33,12 +33,11 @@ cdef public cpp_bool DragHandler_OnDragEnter( cdef py_bool returnValue try: pyBrowser = GetPyBrowser(cef_browser, "OnDragEnter") - drag_data = DragData_Init(cef_drag_data) - + pyDragData = DragData_Init(cef_drag_data) callback = pyBrowser.GetClientCallback("OnDragEnter") if callback: returnValue = callback(browser=pyBrowser, - dragData=drag_data, + dragData=pyDragData, mask=mask) return bool(returnValue) except: From 9f75d73ad2cf10a3715824e8caf514da9c772743 Mon Sep 17 00:00:00 2001 From: demon Date: Mon, 24 Jul 2017 16:16:31 +0800 Subject: [PATCH 09/17] Fixed CEF_VERSION to 3.3029.1604.g364cd86 --- src/version/cef_version_win.h | 43 +++++++++-------------------------- 1 file changed, 11 insertions(+), 32 deletions(-) diff --git a/src/version/cef_version_win.h b/src/version/cef_version_win.h index 328358b9..da4e43e9 100644 --- a/src/version/cef_version_win.h +++ b/src/version/cef_version_win.h @@ -35,28 +35,16 @@ #ifndef CEF_INCLUDE_CEF_VERSION_H_ #define CEF_INCLUDE_CEF_VERSION_H_ -//#define CEF_VERSION "3.3029.1604.g364cd86" -//#define CEF_VERSION_MAJOR 3 -//#define CEF_COMMIT_NUMBER 1604 -//#define CEF_COMMIT_HASH "364cd863b14617f21e6bf8fd3ca3faea01e2ef38" -//#define COPYRIGHT_YEAR 2017 -// -//#define CHROME_VERSION_MAJOR 58 -//#define CHROME_VERSION_MINOR 0 -//#define CHROME_VERSION_BUILD 3029 -//#define CHROME_VERSION_PATCH 81 - -#define CEF_VERSION "3.2987.1601.gf035232" +#define CEF_VERSION "3.3029.1604.g364cd86" #define CEF_VERSION_MAJOR 3 -#define CEF_COMMIT_NUMBER 1601 -#define CEF_COMMIT_HASH "f035232c082f837d2b85bd7821a93a54fc742775" +#define CEF_COMMIT_NUMBER 1604 +#define CEF_COMMIT_HASH "364cd863b14617f21e6bf8fd3ca3faea01e2ef38" #define COPYRIGHT_YEAR 2017 -#define CHROME_VERSION_MAJOR 57 +#define CHROME_VERSION_MAJOR 58 #define CHROME_VERSION_MINOR 0 -#define CHROME_VERSION_BUILD 2987 -#define CHROME_VERSION_PATCH 133 - +#define CHROME_VERSION_BUILD 3029 +#define CHROME_VERSION_PATCH 81 #define DO_MAKE_STRING(p) #p #define MAKE_STRING(p) DO_MAKE_STRING(p) @@ -75,22 +63,13 @@ extern "C" { // universal hash value will change if any platform is affected whereas the // platform hash values will change only if that particular platform is // affected. -//#define CEF_API_HASH_UNIVERSAL "f0e835273a00acd02a699af272fc8f6ff9c5645c" -//#if defined(OS_WIN) -//#define CEF_API_HASH_PLATFORM "3cf7ac2b9aa61adfb9e5decdf0d32fbf78813355" -//#elif defined(OS_MACOSX) -//#define CEF_API_HASH_PLATFORM "f1d2ed00ab93e03a215fd787e6da9127e2949fd8" -//#elif defined(OS_LINUX) -//#define CEF_API_HASH_PLATFORM "698e69c4297cc63b9893558a8591e7bd7aeeb0d4" -//#endif - -#define CEF_API_HASH_UNIVERSAL "b0a24e3e202f3d8b72f2fbc1ebc5864f96ec16ae" +#define CEF_API_HASH_UNIVERSAL "f0e835273a00acd02a699af272fc8f6ff9c5645c" #if defined(OS_WIN) -#define CEF_API_HASH_PLATFORM "1c6a27f840ac87c8c971350c907edbe2c5fa0387" +#define CEF_API_HASH_PLATFORM "3cf7ac2b9aa61adfb9e5decdf0d32fbf78813355" #elif defined(OS_MACOSX) -#define CEF_API_HASH_PLATFORM "1567db600ee83cc2a59bb8c17ca416d11a7c9b8a" +#define CEF_API_HASH_PLATFORM "f1d2ed00ab93e03a215fd787e6da9127e2949fd8" #elif defined(OS_LINUX) -#define CEF_API_HASH_PLATFORM "1f9f9e15bf7cf13de2557ddd411dfc9f694503b0" +#define CEF_API_HASH_PLATFORM "698e69c4297cc63b9893558a8591e7bd7aeeb0d4" #endif // Returns CEF version information for the libcef library. The |entry| @@ -120,4 +99,4 @@ CEF_EXPORT const char* cef_api_hash(int entry); #endif // APSTUDIO_HIDDEN_SYMBOLS -#endif // CEF_INCLUDE_CEF_VERSION_H_ +#endif // CEF_INCLUDE_CEF_VERSION_H_ \ No newline at end of file From 2e8c0a879e33614bcfd171ea23897808a6036bc8 Mon Sep 17 00:00:00 2001 From: demon Date: Wed, 26 Jul 2017 13:25:18 +0800 Subject: [PATCH 10/17] Expose SetFragmentText, SetFragmentHtml, AddFile & ResetFileContents methods in DragData. --- src/drag_data.pyx | 21 +++++++++++++++++++++ src/extern/cef/cef_drag_data.pxd | 2 ++ 2 files changed, 23 insertions(+) diff --git a/src/drag_data.pyx b/src/drag_data.pyx index 51d4551d..3ed16720 100644 --- a/src/drag_data.pyx +++ b/src/drag_data.pyx @@ -54,6 +54,27 @@ cdef class DragData: cpdef py_string GetFragmentHtml(self): return CefToPyString(self.cef_drag_data.get().GetFragmentHtml()) + cpdef py_void SetFragmentText(self, text): + cdef CefString cefText + PyToCefString(text,cefText) + self.cef_drag_data.get().SetFragmentText(cefText) + + cpdef py_void SetFragmentHtml(self, html ): + cdef CefString cefHtml + PyToCefString(html,cefHtml) + self.cef_drag_data.get().SetFragmentHtml(cefHtml) + + cpdef py_void AddFile(self, path, display_name): + cdef CefString cefPath + cdef CefString cefDisplayName + PyToCefString(path,cefPath) + PyToCefString(display_name,cefDisplayName) + self.cef_drag_data.get().AddFile(cefPath,cefDisplayName) + + cpdef py_void ResetFileContents(self): + self.cef_drag_data.get().ResetFileContents() + + IF UNAME_SYSNAME == "Linux": cpdef PyImage GetImage(self): diff --git a/src/extern/cef/cef_drag_data.pxd b/src/extern/cef/cef_drag_data.pxd index dd57b657..9a13f051 100644 --- a/src/extern/cef/cef_drag_data.pxd +++ b/src/extern/cef/cef_drag_data.pxd @@ -27,6 +27,8 @@ cdef extern from "include/cef_drag_data.h": cpp_bool HasImage() CefRefPtr[CefImage] GetImage() CefPoint GetImageHotspot() + void ResetFileContents() + void AddFile(const CefString& path, const CefString& display_name) cdef CefRefPtr[CefDragData] CefDragData_Create "CefDragData::Create"() From 7e5891fdd5b0f9b18cbfaa7d5191c637276c2117 Mon Sep 17 00:00:00 2001 From: demon Date: Wed, 26 Jul 2017 13:52:12 +0800 Subject: [PATCH 11/17] Add testing for file dialog & drag event. --- unittests/filedialog_test.py | 121 +++++++++++++++++++++++++++ unittests/osr_test.py | 153 +++++++++++++++++++++++++++++++++++ 2 files changed, 274 insertions(+) create mode 100644 unittests/filedialog_test.py create mode 100644 unittests/osr_test.py diff --git a/unittests/filedialog_test.py b/unittests/filedialog_test.py new file mode 100644 index 00000000..08d53725 --- /dev/null +++ b/unittests/filedialog_test.py @@ -0,0 +1,121 @@ +# Copyright (c) 2017 CEF Python, see the Authors file. +# All rights reserved. Licensed under BSD 3-clause license. +# Project website: https://github.com/cztomczak/cefpython + +"""General testing of CEF Python.""" + +import unittest +# noinspection PyUnresolvedReferences +import _test_runner +from os.path import basename +from cefpython3 import cefpython as cef +import time +import base64 +import sys + +MESSAGE_LOOP_RANGE = 200 + +g_datauri_data = """ + + + + + + Title + + + + + + + + +""" + +g_datauri = "data:text/html;base64," + base64.b64encode(g_datauri_data.encode( + "utf-8", "replace")).decode("utf-8", "replace") + +g_subtests_ran = 0 + +def subtest_message(message): + global g_subtests_ran + g_subtests_ran += 1 + print(str(g_subtests_ran) + ". " + message) + sys.stdout.flush() + + +class DropTest_IsolatedTest(unittest.TestCase): + def test_filedialog(self): + print("") + print("CEF Python {ver}".format(ver=cef.__version__)) + print("Python {ver}".format(ver=sys.version[:6])) + + # Test initialization of CEF + settings = { + "debug": False, + "log_severity": cef.LOGSEVERITY_ERROR, + "log_file": "", + } + if "--debug" in sys.argv: + settings["debug"] = True + settings["log_severity"] = cef.LOGSEVERITY_INFO + cef.Initialize(settings) + + browser = cef.CreateBrowserSync(url=g_datauri) + browser.SetClientHandler(DisplayHandler(self)) + + + # Test handlers: DialogHandler etc. + browser.SetClientHandler(DialogHandler()) + + # Run message loop for some time. + for i in range(MESSAGE_LOOP_RANGE): + cef.MessageLoopWork() + time.sleep(0.01) + + #Simulating file dialog click event for testing OnFileDialog handler + browser.SendMouseClickEvent(67, 20, cef.MOUSEBUTTON_LEFT, False, 1) + browser.SendMouseClickEvent(67, 20, cef.MOUSEBUTTON_LEFT, True, 1) + + cef.Shutdown() + + +class DisplayHandler(object): + def __init__(self, test_case): + self.test_case = test_case + + # Asserts for True/False will be checked just before shutdown + self.test_for_True = True # Test whether asserts are working correctly + self.javascript_errors_False = False + self.OnConsoleMessage_True = False + + def OnConsoleMessage(self, message, **_): + if "error" in message.lower() or "uncaught" in message.lower(): + self.javascript_errors_False = True + raise Exception(message) + else: + # Check whether messages from javascript are coming + self.OnConsoleMessage_True = True + subtest_message(message) + + +class DialogHandler(object): + def OnFileDialog(self, browser, mode,title, default_file_path,accept_filters,selected_accept_filter,file_dialog_callback): + subtest_message("cef.OnFileDialog() ok") + file_dialog_callback.Continue(selected_accept_filter, [r"filedialog_test.py"]) + return False + + +if __name__ == "__main__": + unittests._test_runner.main(basename(__file__)) diff --git a/unittests/osr_test.py b/unittests/osr_test.py new file mode 100644 index 00000000..8d6b6bf9 --- /dev/null +++ b/unittests/osr_test.py @@ -0,0 +1,153 @@ +# Copyright (c) 2017 CEF Python, see the Authors file. +# All rights reserved. Licensed under BSD 3-clause license. +# Project website: https://github.com/cztomczak/cefpython +"""OSR testing of CEF Python.""" + +import unittest +import _test_runner +from cefpython3 import cefpython as cef +import platform +import sys,time,os +import base64 + +g_datauri_data = """ + + + + + Title + + + + + + +
+ + + +""" + +g_datauri = "data:text/html;base64," + base64.b64encode(g_datauri_data.encode( + "utf-8", "replace")).decode("utf-8", "replace") +VIEWPORT_SIZE = (1024, 768) + +g_subtests_ran = 0 + +def subtest_message(message): + global g_subtests_ran + g_subtests_ran += 1 + print(str(g_subtests_ran) + ". " + message) + sys.stdout.flush() + +class Handler(object): + def __init__(self): + self.OnPaint_called = False + + def OnConsoleMessage(self, message, **_): + if "error" in message.lower() or "uncaught" in message.lower(): + self.javascript_errors_False = True + raise Exception(message) + else: + # Check whether messages from javascript are coming + self.OnConsoleMessage_True = True + subtest_message(message) + + def OnDragEnter(self, browser, dragData, mask): + subtest_message('cef.OnDragEnter() OK') + return False + + def StartDragging(self,browser, drag_data, allowed_ops, x, y): + subtest_message('cef.StartDragging() OK') + return False + + def OnLoadEnd(self,browser,frame,http_code): + subtest_message('cef.OnLoadEnd() OK') + #testing mouse event + browser.SendMouseClickEvent(300, 20, cef.MOUSEBUTTON_LEFT, False, 1, cef.EVENTFLAG_LEFT_MOUSE_BUTTON) + browser.SendMouseMoveEvent(305, 25, False, cef.EVENTFLAG_LEFT_MOUSE_BUTTON) + browser.SendMouseClickEvent(305, 25, cef.MOUSEBUTTON_LEFT, True, 1, cef.EVENTFLAG_LEFT_MOUSE_BUTTON) + + # testing drag event + # It can trigging cef.OnDragEnter, but still not trigger dragenter event in JS. + dragData = cef.DragData() + dragData.SetFragmentText('Test') + dragData.ResetFileContents() + browser.DragTargetDragEnter(dragData, 301, 21, cef.DRAG_OPERATION_COPY ) + browser.DragTargetDragOver(302, 22, cef.DRAG_OPERATION_COPY ) + browser.DragTargetDrop(303, 23) + browser.DragSourceEndedAt(303, 23, cef.DRAG_OPERATION_COPY ) + browser.DragSourceSystemDragEnded() + + + + +class OSRTest_IsolatedTest(unittest.TestCase): + def test_dragdrop(self): + sys.excepthook = cef.ExceptHook + cef.Initialize(settings={"windowless_rendering_enabled": True}) + parent_window_handle = 0 + window_info = cef.WindowInfo() + window_info.SetAsOffscreen(parent_window_handle) + browser = cef.CreateBrowserSync(window_info=window_info, + url=g_datauri) + browser.SetClientHandler(Handler()) + browser.SendFocusEvent(True) + browser.WasResized() + for i in range(200): + cef.MessageLoopWork() + time.sleep(0.01) + cef.Shutdown() + + def test_dragdata(self): + dragData = cef.DragData() + testString = 'Testing DragData' + fileUri = r"C:\temp\ninja\README" + dragData.SetFragmentText(testString) + self.assertEqual(testString,dragData.GetFragmentText(),'SetFragmentText') + subtest_message('DragData.SetFragmentText() OK') + dragData.SetFragmentHtml(testString) + self.assertEqual(testString, dragData.GetFragmentHtml(), 'SetFragmentHtml') + subtest_message('DragData.SetFragmentHtml() OK') + dragData.AddFile(fileUri,'README') + subtest_message('DragData.AddFile() OK') + self.assertIn(fileUri, dragData.GetFileNames(), 'GetFileNames') + subtest_message('DragData.GetFileNames() OK') + +if __name__ == "__main__": + unittests._test_runner.main(basename(__file__)) \ No newline at end of file From 94c69b8b299df040a26b4bbdd68fe24958ba8ba0 Mon Sep 17 00:00:00 2001 From: demon Date: Wed, 26 Jul 2017 14:03:26 +0800 Subject: [PATCH 12/17] Update docs for DragData --- api/API-index.md | 3 +++ api/DragData.md | 31 ++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/api/API-index.md b/api/API-index.md index 02cdb5e0..553a10d5 100644 --- a/api/API-index.md +++ b/api/API-index.md @@ -223,6 +223,9 @@ * [GetImage](DragData.md#getimage) * [GetImageHotspot](DragData.md#getimagehotspot) * [HasImage](DragData.md#hasimage) + * [AddFile](DragData.md#addfile) + * [SetFragmentText](DragData.md#setfragmenttext) + * [SetFragmentHtml](DragData.md#setfragmenthtml) * [FocusHandler (interface)](FocusHandler.md#focushandler-interface) * [OnTakeFocus](FocusHandler.md#ontakefocus) * [OnSetFocus](FocusHandler.md#onsetfocus) diff --git a/api/DragData.md b/api/DragData.md index 910764d7..e847d407 100644 --- a/api/DragData.md +++ b/api/DragData.md @@ -18,7 +18,9 @@ Table of contents: * [GetImage](#getimage) * [GetImageHotspot](#getimagehotspot) * [HasImage](#hasimage) - + * [AddFile](#addfile) + * [SetFragmentText](#setfragmenttext) + * [SetFragmentHtml](#setfragmenthtml) ## Methods @@ -137,3 +139,30 @@ Linux-only currently (#251). Whether image representation of drag data is available. +### AddFile + +| | | +| --- | --- | +| path | string | +| display_name | string | +| __Return__ | void | + +Add a file that is being dragged into the webview. + +### SetFragmentText + +| | | +| --- | --- | +| text | string | +| __Return__ | void | + +Set the plain text fragment that is being dragged. + +### SetFragmentHtml + +| | | +| --- | --- | +| html | string | +| __Return__ | void | + +Set the text/html fragment that is being dragged. From b1a9afdd6ff1b84c5dd5cd669df3284b91d9a814 Mon Sep 17 00:00:00 2001 From: demon Date: Wed, 26 Jul 2017 14:07:03 +0800 Subject: [PATCH 13/17] Update the doc of DragData --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 27a89ab5..147ac1fb 100644 --- a/README.md +++ b/README.md @@ -481,6 +481,9 @@ Additional information for v31.2 release: * [GetImage](api/DragData.md#getimage) * [GetImageHotspot](api/DragData.md#getimagehotspot) * [HasImage](api/DragData.md#hasimage) + * [AddFile](api/DragData.md#addfile) + * [SetFragmentText](api/DragData.md#setfragmenttext) + * [SetFragmentHtml](api/DragData.md#setfragmenthtml) * [FocusHandler (interface)](api/FocusHandler.md#focushandler-interface) * [OnTakeFocus](api/FocusHandler.md#ontakefocus) * [OnSetFocus](api/FocusHandler.md#onsetfocus) From db79ee04d3a7000dbcbfb0ff345a8ae2f22cbb5f Mon Sep 17 00:00:00 2001 From: demon Date: Wed, 26 Jul 2017 18:41:20 +0800 Subject: [PATCH 14/17] Fixed code for pull request. --- README.md | 10 +++-- api/API-index.md | 10 +++-- api/DragData.md | 57 ++++++++++++++------------- api/DragHandler.md | 26 ++++++++++++ src/client_handler/dialog_handler.cpp | 19 +++++---- src/drag_data.pyx | 13 +++--- src/extern/cef/cef_drag_data.pxd | 11 +++--- src/handlers/dialog_handler.pyx | 9 +---- 8 files changed, 89 insertions(+), 66 deletions(-) create mode 100644 api/DragHandler.md diff --git a/README.md b/README.md index 147ac1fb..3f6ff51a 100644 --- a/README.md +++ b/README.md @@ -469,21 +469,23 @@ Additional information for v31.2 release: * [IsProcessDpiAware](api/DpiAware.md#isprocessdpiaware) * [SetProcessDpiAware](api/DpiAware.md#setprocessdpiaware) * [DragData (object)](api/DragData.md#dragdata-object) - * [IsFile](api/DragData.md#isfile) + * [AddFile](api/DragData.md#addfile) * [IsLink](api/DragData.md#islink) + * [IsFile](api/DragData.md#isfile) * [IsFragment](api/DragData.md#isfragment) - * [GetFileName](api/DragData.md#getfilename) - * [GetFileNames](api/DragData.md#getfilenames) * [GetLinkUrl](api/DragData.md#getlinkurl) * [GetLinkTitle](api/DragData.md#getlinktitle) + * [GetFileName](api/DragData.md#getfilename) + * [GetFileNames](api/DragData.md#getfilenames) * [GetFragmentText](api/DragData.md#getfragmenttext) * [GetFragmentHtml](api/DragData.md#getfragmenthtml) * [GetImage](api/DragData.md#getimage) * [GetImageHotspot](api/DragData.md#getimagehotspot) * [HasImage](api/DragData.md#hasimage) - * [AddFile](api/DragData.md#addfile) * [SetFragmentText](api/DragData.md#setfragmenttext) * [SetFragmentHtml](api/DragData.md#setfragmenthtml) +* [DragHandler (interface)](api/DragHandler.md#draghandler-interface) + * [OnDragEnter](api/DragHandler.md#ondragenter) * [FocusHandler (interface)](api/FocusHandler.md#focushandler-interface) * [OnTakeFocus](api/FocusHandler.md#ontakefocus) * [OnSetFocus](api/FocusHandler.md#onsetfocus) diff --git a/api/API-index.md b/api/API-index.md index 553a10d5..d3c2b377 100644 --- a/api/API-index.md +++ b/api/API-index.md @@ -211,21 +211,23 @@ * [IsProcessDpiAware](DpiAware.md#isprocessdpiaware) * [SetProcessDpiAware](DpiAware.md#setprocessdpiaware) * [DragData (object)](DragData.md#dragdata-object) - * [IsFile](DragData.md#isfile) + * [AddFile](DragData.md#addfile) * [IsLink](DragData.md#islink) + * [IsFile](DragData.md#isfile) * [IsFragment](DragData.md#isfragment) - * [GetFileName](DragData.md#getfilename) - * [GetFileNames](DragData.md#getfilenames) * [GetLinkUrl](DragData.md#getlinkurl) * [GetLinkTitle](DragData.md#getlinktitle) + * [GetFileName](DragData.md#getfilename) + * [GetFileNames](DragData.md#getfilenames) * [GetFragmentText](DragData.md#getfragmenttext) * [GetFragmentHtml](DragData.md#getfragmenthtml) * [GetImage](DragData.md#getimage) * [GetImageHotspot](DragData.md#getimagehotspot) * [HasImage](DragData.md#hasimage) - * [AddFile](DragData.md#addfile) * [SetFragmentText](DragData.md#setfragmenttext) * [SetFragmentHtml](DragData.md#setfragmenthtml) +* [DragHandler (interface)](DragHandler.md#draghandler-interface) + * [OnDragEnter](DragHandler.md#ondragenter) * [FocusHandler (interface)](FocusHandler.md#focushandler-interface) * [OnTakeFocus](FocusHandler.md#ontakefocus) * [OnSetFocus](FocusHandler.md#onsetfocus) diff --git a/api/DragData.md b/api/DragData.md index e847d407..65969d29 100644 --- a/api/DragData.md +++ b/api/DragData.md @@ -6,31 +6,34 @@ Table of contents: * [Methods](#methods) - * [IsFile](#isfile) + * [AddFile](#addfile) * [IsLink](#islink) + * [IsFile](#isfile) * [IsFragment](#isfragment) - * [GetFileName](#getfilename) - * [GetFileNames](#getfilenames) * [GetLinkUrl](#getlinkurl) * [GetLinkTitle](#getlinktitle) + * [GetFileName](#getfilename) + * [GetFileNames](#getfilenames) * [GetFragmentText](#getfragmenttext) * [GetFragmentHtml](#getfragmenthtml) * [GetImage](#getimage) * [GetImageHotspot](#getimagehotspot) * [HasImage](#hasimage) - * [AddFile](#addfile) * [SetFragmentText](#setfragmenttext) * [SetFragmentHtml](#setfragmenthtml) ## Methods -### IsFile +### AddFile | | | | --- | --- | -| __Return__ | bool | +| path | string | +| display_name | string | +| __Return__ | void | + +Add a file that is being dragged into the webview. -Returns true if the drag data is a file. ### IsLink @@ -41,6 +44,15 @@ Returns true if the drag data is a file. Returns true if the drag data is a link. +### IsFile + +| | | +| --- | --- | +| __Return__ | bool | + +Returns true if the drag data is a file. + + ### IsFragment | | | @@ -50,42 +62,43 @@ Returns true if the drag data is a link. Returns true if the drag data is a text or html fragment. -### GetFileName +### GetLinkUrl | | | | --- | --- | | __Return__ | string | -Return the name of the file being dragged out of the browser window. +Return the link URL that is being dragged. -### GetFileNames +### GetLinkTitle | | | | --- | --- | -| __Return__ | list | +| __Return__ | string | +Return the title associated with the link being dragged. -Return the list of file names that are being dragged into the browser window. -### GetLinkUrl +### GetFileName | | | | --- | --- | | __Return__ | string | -Return the link URL that is being dragged. +Return the name of the file being dragged out of the browser window. -### GetLinkTitle +### GetFileNames | | | | --- | --- | -| __Return__ | string | +| __Return__ | list | -Return the title associated with the link being dragged. + +Return the list of file names that are being dragged into the browser window. ### GetFragmentText @@ -139,16 +152,6 @@ Linux-only currently (#251). Whether image representation of drag data is available. -### AddFile - -| | | -| --- | --- | -| path | string | -| display_name | string | -| __Return__ | void | - -Add a file that is being dragged into the webview. - ### SetFragmentText | | | diff --git a/api/DragHandler.md b/api/DragHandler.md new file mode 100644 index 00000000..5be80a7c --- /dev/null +++ b/api/DragHandler.md @@ -0,0 +1,26 @@ +[API categories](API-categories.md) | [API index](API-index.md) + + +# DragHandler (interface) + +Implement this interface to handle events related to dragging. The methods of this class will be called on the UI thread. + + +Table of contents: +* [Callbacks](#callbacks) + * [OnDragEnter](#ondragenter) + +## Callbacks + + +### OnDragEnter + +| Parameter | Type | +| --- | --- | +| browser | [Browser](Browser.md) | +| dragData | [DragData](DragData.md) | +| mask | int | +| __Return__ | bool | + + Called when an external drag event enters the browser window. + diff --git a/src/client_handler/dialog_handler.cpp b/src/client_handler/dialog_handler.cpp index beea56e7..f271ef29 100644 --- a/src/client_handler/dialog_handler.cpp +++ b/src/client_handler/dialog_handler.cpp @@ -31,17 +31,16 @@ bool DialogHandler::OnFileDialog(CefRefPtr browser, callback); if(result){ return result; - }else{ + } #if defined(OS_LINUX) - return dialog_handler_->OnFileDialog(browser, - mode, - title, - default_file_path, - accept_filters, - selected_accept_filter, - callback); + return dialog_handler_->OnFileDialog(browser, + mode, + title, + default_file_path, + accept_filters, + selected_accept_filter, + callback); #else - return false; + return false; #endif - } } diff --git a/src/drag_data.pyx b/src/drag_data.pyx index 3ed16720..0d163505 100644 --- a/src/drag_data.pyx +++ b/src/drag_data.pyx @@ -56,25 +56,24 @@ cdef class DragData: cpdef py_void SetFragmentText(self, text): cdef CefString cefText - PyToCefString(text,cefText) + PyToCefString(text, cefText) self.cef_drag_data.get().SetFragmentText(cefText) - cpdef py_void SetFragmentHtml(self, html ): + cpdef py_void SetFragmentHtml(self, html): cdef CefString cefHtml - PyToCefString(html,cefHtml) + PyToCefString(html, cefHtml) self.cef_drag_data.get().SetFragmentHtml(cefHtml) cpdef py_void AddFile(self, path, display_name): cdef CefString cefPath cdef CefString cefDisplayName - PyToCefString(path,cefPath) - PyToCefString(display_name,cefDisplayName) - self.cef_drag_data.get().AddFile(cefPath,cefDisplayName) + PyToCefString(path, cefPath) + PyToCefString(display_name, cefDisplayName) + self.cef_drag_data.get().AddFile(cefPath, cefDisplayName) cpdef py_void ResetFileContents(self): self.cef_drag_data.get().ResetFileContents() - IF UNAME_SYSNAME == "Linux": cpdef PyImage GetImage(self): diff --git a/src/extern/cef/cef_drag_data.pxd b/src/extern/cef/cef_drag_data.pxd index 9a13f051..c254004f 100644 --- a/src/extern/cef/cef_drag_data.pxd +++ b/src/extern/cef/cef_drag_data.pxd @@ -12,23 +12,22 @@ from libcpp.vector cimport vector as cpp_vector cdef extern from "include/cef_drag_data.h": cdef cppclass CefDragData: - cpp_bool IsFile() - CefString GetFileName() - cpp_bool GetFileNames(cpp_vector[CefString]& names) + void AddFile(const CefString& path, const CefString& display_name) cpp_bool IsLink() + cpp_bool IsFile() cpp_bool IsFragment() CefString GetLinkURL() CefString GetLinkTitle() + CefString GetFileName() + cpp_bool GetFileNames(cpp_vector[CefString]& names) CefString GetFragmentText() CefString GetFragmentHtml() + void ResetFileContents() void SetFragmentText(const CefString& text) void SetFragmentHtml(const CefString& html) void SetFragmentBaseURL(const CefString& base_url) cpp_bool HasImage() CefRefPtr[CefImage] GetImage() CefPoint GetImageHotspot() - void ResetFileContents() - void AddFile(const CefString& path, const CefString& display_name) - cdef CefRefPtr[CefDragData] CefDragData_Create "CefDragData::Create"() diff --git a/src/handlers/dialog_handler.pyx b/src/handlers/dialog_handler.pyx index 8bae72cc..3c4700bc 100644 --- a/src/handlers/dialog_handler.pyx +++ b/src/handlers/dialog_handler.pyx @@ -40,16 +40,9 @@ cdef public cpp_bool DialogHandler_OnFileDialog( default_file_path=pyDefaultFilePath, accept_filters=pyAcceptFilters, selected_accept_filter=selected_accept_filter, - file_dialog_callback = CreatePyFileDialogCallback(cefFileDialogCallback) - ) - + file_dialog_callback = CreatePyFileDialogCallback(cefFileDialogCallback)) return bool(returnValue) except: (exc_type, exc_value, exc_trace) = sys.exc_info() sys.excepthook(exc_type, exc_value, exc_trace) return False - - - - - From 4f82ddb245ab602b40b49c9f69ac017166e66c75 Mon Sep 17 00:00:00 2001 From: demon Date: Thu, 27 Jul 2017 14:12:29 +0800 Subject: [PATCH 15/17] Add unittests for OnFileDialog & OnDragDrop. --- unittests/_common.py | 50 ++++++++++ unittests/filedialog_test.py | 121 ------------------------ unittests/main_test.py | 79 ++++++++-------- unittests/osr_test.py | 177 ++++++++++++++++++++--------------- 4 files changed, 188 insertions(+), 239 deletions(-) create mode 100644 unittests/_common.py delete mode 100644 unittests/filedialog_test.py diff --git a/unittests/_common.py b/unittests/_common.py new file mode 100644 index 00000000..dda6abc7 --- /dev/null +++ b/unittests/_common.py @@ -0,0 +1,50 @@ +# Copyright (c) 2017 CEF Python, see the Authors file. +# All rights reserved. Licensed under BSD 3-clause license. +# Project website: https://github.com/cztomczak/cefpython +"""Common function for unittests.""" +import base64 +import sys,time +from cefpython3 import cefpython as cef + +g_subtests_ran = 0 +def subtest_message(message): + global g_subtests_ran + g_subtests_ran += 1 + print(str(g_subtests_ran) + ". " + message) + sys.stdout.flush() + +def display_number_of_unittest(message): + print("\nRan " + str(g_subtests_ran) + " " + message) + +def html_to_data_uri(html): + html = html.encode("utf-8", "replace") + b64 = base64.b64encode(html).decode("utf-8", "replace") + ret = "data:text/html;base64,{data}".format(data=b64) + return ret + +def cef_waiting(loop_range): + for i in range(loop_range): + cef.MessageLoopWork() + time.sleep(0.01) + +def automatic_check_handlers(test_case,handlers=[]): + # Automatic check of asserts in handlers. + for obj in handlers: + test_for_True = False # Test whether asserts are working correctly + for key, value in obj.__dict__.items(): + if key == "test_for_True": + test_for_True = True + continue + if "_True" in key: + test_case.assertTrue(value, "Check assert: " + + obj.__class__.__name__ + "." + key) + subtest_message(obj.__class__.__name__ + "." + + key.replace("_True", "") + + " ok") + elif "_False" in key: + test_case.assertFalse(value, "Check assert: " + + obj.__class__.__name__ + "." + key) + subtest_message(obj.__class__.__name__ + "." + + key.replace("_False", "") + + " ok") + test_case.assertTrue(test_for_True) \ No newline at end of file diff --git a/unittests/filedialog_test.py b/unittests/filedialog_test.py deleted file mode 100644 index 08d53725..00000000 --- a/unittests/filedialog_test.py +++ /dev/null @@ -1,121 +0,0 @@ -# Copyright (c) 2017 CEF Python, see the Authors file. -# All rights reserved. Licensed under BSD 3-clause license. -# Project website: https://github.com/cztomczak/cefpython - -"""General testing of CEF Python.""" - -import unittest -# noinspection PyUnresolvedReferences -import _test_runner -from os.path import basename -from cefpython3 import cefpython as cef -import time -import base64 -import sys - -MESSAGE_LOOP_RANGE = 200 - -g_datauri_data = """ - - - - - - Title - - - - - - - - -""" - -g_datauri = "data:text/html;base64," + base64.b64encode(g_datauri_data.encode( - "utf-8", "replace")).decode("utf-8", "replace") - -g_subtests_ran = 0 - -def subtest_message(message): - global g_subtests_ran - g_subtests_ran += 1 - print(str(g_subtests_ran) + ". " + message) - sys.stdout.flush() - - -class DropTest_IsolatedTest(unittest.TestCase): - def test_filedialog(self): - print("") - print("CEF Python {ver}".format(ver=cef.__version__)) - print("Python {ver}".format(ver=sys.version[:6])) - - # Test initialization of CEF - settings = { - "debug": False, - "log_severity": cef.LOGSEVERITY_ERROR, - "log_file": "", - } - if "--debug" in sys.argv: - settings["debug"] = True - settings["log_severity"] = cef.LOGSEVERITY_INFO - cef.Initialize(settings) - - browser = cef.CreateBrowserSync(url=g_datauri) - browser.SetClientHandler(DisplayHandler(self)) - - - # Test handlers: DialogHandler etc. - browser.SetClientHandler(DialogHandler()) - - # Run message loop for some time. - for i in range(MESSAGE_LOOP_RANGE): - cef.MessageLoopWork() - time.sleep(0.01) - - #Simulating file dialog click event for testing OnFileDialog handler - browser.SendMouseClickEvent(67, 20, cef.MOUSEBUTTON_LEFT, False, 1) - browser.SendMouseClickEvent(67, 20, cef.MOUSEBUTTON_LEFT, True, 1) - - cef.Shutdown() - - -class DisplayHandler(object): - def __init__(self, test_case): - self.test_case = test_case - - # Asserts for True/False will be checked just before shutdown - self.test_for_True = True # Test whether asserts are working correctly - self.javascript_errors_False = False - self.OnConsoleMessage_True = False - - def OnConsoleMessage(self, message, **_): - if "error" in message.lower() or "uncaught" in message.lower(): - self.javascript_errors_False = True - raise Exception(message) - else: - # Check whether messages from javascript are coming - self.OnConsoleMessage_True = True - subtest_message(message) - - -class DialogHandler(object): - def OnFileDialog(self, browser, mode,title, default_file_path,accept_filters,selected_accept_filter,file_dialog_callback): - subtest_message("cef.OnFileDialog() ok") - file_dialog_callback.Continue(selected_accept_filter, [r"filedialog_test.py"]) - return False - - -if __name__ == "__main__": - unittests._test_runner.main(basename(__file__)) diff --git a/unittests/main_test.py b/unittests/main_test.py index d7a2fbf9..b03546ec 100644 --- a/unittests/main_test.py +++ b/unittests/main_test.py @@ -7,10 +7,10 @@ import unittest # noinspection PyUnresolvedReferences import _test_runner +from _common import subtest_message, display_number_of_unittest, html_to_data_uri, cef_waiting +from _common import automatic_check_handlers from os.path import basename from cefpython3 import cefpython as cef -import time -import base64 import sys # To show the window for an extended period of time increase this number. @@ -76,28 +76,23 @@ py_callback("String sent from Javascript"); print("py_callback() ok"); }); + + // Test receiving a file from OnFileDialog. + document.getElementById('selectFile').addEventListener('change', function(e){ + print('Received file "'+this.files[0].name + '" OK') + }, true); }; +

Main test

""" -g_datauri = "data:text/html;base64,"+base64.b64encode(g_datauri_data.encode( - "utf-8", "replace")).decode("utf-8", "replace") - -g_subtests_ran = 0 - - -def subtest_message(message): - global g_subtests_ran - g_subtests_ran += 1 - print(str(g_subtests_ran) + ". " + message) - sys.stdout.flush() - +g_datauri = html_to_data_uri(g_datauri_data) class MainTest_IsolatedTest(unittest.TestCase): @@ -132,8 +127,8 @@ def test_main(self): self.assertIsNotNone(browser, "Browser object") subtest_message("cef.CreateBrowserSync() ok") - # Test other handlers: LoadHandler, DisplayHandler etc. - client_handlers = [LoadHandler(self), DisplayHandler(self)] + # Test other handlers: LoadHandler, DisplayHandler, DialogHandler etc. + client_handlers = [LoadHandler(self), DisplayHandler(self), DialogHandler(self)] for handler in client_handlers: browser.SetClientHandler(handler) subtest_message("browser.SetClientHandler() ok") @@ -152,11 +147,16 @@ def test_main(self): # Run message loop for some time. # noinspection PyTypeChecker - for i in range(MESSAGE_LOOP_RANGE): - cef.MessageLoopWork() - time.sleep(0.01) + cef_waiting(MESSAGE_LOOP_RANGE) subtest_message("cef.MessageLoopWork() ok") + #Simulating file dialog click event for testing OnFileDialog handler + browser.SendMouseClickEvent(67, 20, cef.MOUSEBUTTON_LEFT, False, 1) + browser.SendMouseClickEvent(67, 20, cef.MOUSEBUTTON_LEFT, True, 1) + + # Run message loop for some time. + cef_waiting(MESSAGE_LOOP_RANGE) + # Test browser closing. Remember to clean reference. browser.CloseBrowser(True) del browser @@ -164,37 +164,17 @@ def test_main(self): # Give it some time to close before calling shutdown. # noinspection PyTypeChecker - for i in range(25): - cef.MessageLoopWork() - time.sleep(0.01) + cef_waiting(25) # Automatic check of asserts in handlers and in external - for obj in [] + client_handlers + [global_handler, external]: - test_for_True = False # Test whether asserts are working correctly - for key, value in obj.__dict__.items(): - if key == "test_for_True": - test_for_True = True - continue - if "_True" in key: - self.assertTrue(value, "Check assert: " + - obj.__class__.__name__ + "." + key) - subtest_message(obj.__class__.__name__ + "." + - key.replace("_True", "") + - " ok") - elif "_False" in key: - self.assertFalse(value, "Check assert: " + - obj.__class__.__name__ + "." + key) - subtest_message(obj.__class__.__name__ + "." + - key.replace("_False", "") + - " ok") - self.assertTrue(test_for_True) + automatic_check_handlers(self, [] + client_handlers + [global_handler, external]) # Test shutdown of CEF cef.Shutdown() subtest_message("cef.Shutdown() ok") # Display real number of tests there were run - print("\nRan " + str(g_subtests_ran) + " sub-tests in test_main") + display_number_of_unittest("sub-tests in test_main") sys.stdout.flush() @@ -282,6 +262,21 @@ def OnConsoleMessage(self, message, **_): subtest_message(message) +class DialogHandler(object): + def __init__(self, test_case): + self.test_case = test_case + + # Asserts for True/False will be checked just before shutdown + self.test_for_True = True # Test whether asserts are working correctly + self.OnFileDialog_True = False + + def OnFileDialog(self, browser, mode, title, default_file_path ,accept_filters ,selected_accept_filter ,file_dialog_callback): + self.test_case.assertFalse(self.OnFileDialog_True) + self.OnFileDialog_True = True + file_dialog_callback.Continue(selected_accept_filter, [__file__]) + return True + + class FrameSourceVisitor(object): """Visitor for Frame.GetSource().""" diff --git a/unittests/osr_test.py b/unittests/osr_test.py index 8d6b6bf9..3ecc2eeb 100644 --- a/unittests/osr_test.py +++ b/unittests/osr_test.py @@ -5,10 +5,11 @@ import unittest import _test_runner +from _common import subtest_message, display_number_of_unittest, html_to_data_uri, cef_waiting +from _common import automatic_check_handlers from cefpython3 import cefpython as cef import platform import sys,time,os -import base64 g_datauri_data = """ @@ -21,29 +22,27 @@ console.log(msg + " [JS]"); } window.onload = function(){ + // Test mouse event document.addEventListener("mousedown", function( e ) { - print('mousedown:'+e.pageX+","+e.pageY) + print('mousedown: '+e.pageX+", "+e.pageY) }, false); document.addEventListener("mouseup", function( e ) { - print('mouseup:'+e.pageX+","+e.pageY) + print('mouseup: '+e.pageX+", "+e.pageY) }, false); - document.addEventListener("mousemove", function( e ) { - print('mousemove:'+e.pageX+","+e.pageY) + print('mousemove: '+e.pageX+", "+e.pageY) }, false); + // Test drag & drop event. document.addEventListener("dragenter", function( e ) { - print('dragenter:'+e.pageX+","+e.pageY) + print('dragenter: '+e.pageX+", "+e.pageY) }, false); - document.addEventListener("dragover", function( e ) { - print('dragover:'+e.pageX+","+e.pageY) + print('dragover: '+e.pageX+", "+e.pageY) }, false); document.addEventListener("drop", function( e ) { - print('drop:'+e.pageX+","+e.pageY) + print('drop: '+e.pageX+", "+e.pageY) }, false); - - } print('window.onload init') @@ -63,91 +62,117 @@ """ -g_datauri = "data:text/html;base64," + base64.b64encode(g_datauri_data.encode( - "utf-8", "replace")).decode("utf-8", "replace") -VIEWPORT_SIZE = (1024, 768) +g_datauri = html_to_data_uri(g_datauri_data) -g_subtests_ran = 0 -def subtest_message(message): - global g_subtests_ran - g_subtests_ran += 1 - print(str(g_subtests_ran) + ". " + message) - sys.stdout.flush() +class OSRTest_IsolatedTest(unittest.TestCase): + def test_osr(self): + sys.excepthook = cef.ExceptHook + cef.Initialize(settings={"windowless_rendering_enabled": True}) + parent_window_handle = 0 + window_info = cef.WindowInfo() + window_info.SetAsOffscreen(parent_window_handle) + browser = cef.CreateBrowserSync(window_info=window_info, + url=g_datauri) + + client_handlers = [LoadHandler(self), + DisplayHandler(self), + RenderHandler(self), + DragHandler(self)] -class Handler(object): - def __init__(self): - self.OnPaint_called = False + for handler in client_handlers: + browser.SetClientHandler(handler) + + browser.SendFocusEvent(True) + browser.WasResized() + + # Test setting DragData. + self.subtest_dragdata() + cef_waiting(200) + + # Automatic check of asserts in handlers + automatic_check_handlers(self, [] + client_handlers) + + browser.CloseBrowser(True) + del browser + cef.Shutdown() + + def subtest_dragdata(self): + # Test setting DragData. + dragData = cef.DragData() + testString = "Testing DragData" + fileUri = __file__ + dragData.SetFragmentText(testString) + self.assertEqual(testString,dragData.GetFragmentText(),"SetFragmentText") + subtest_message("DragData.SetFragmentText() OK") + dragData.SetFragmentHtml(testString) + self.assertEqual(testString, dragData.GetFragmentHtml(), "SetFragmentHtml") + subtest_message("DragData.SetFragmentHtml() OK") + dragData.AddFile(fileUri,'testfile') + subtest_message("DragData.AddFile() OK") + self.assertIn(fileUri, dragData.GetFileNames(), "GetFileNames") + subtest_message("DragData.GetFileNames() OK") + +class DisplayHandler(object): + def __init__(self, test_case): + self.test_case = test_case + self.test_for_True = True def OnConsoleMessage(self, message, **_): if "error" in message.lower() or "uncaught" in message.lower(): - self.javascript_errors_False = True raise Exception(message) else: - # Check whether messages from javascript are coming - self.OnConsoleMessage_True = True subtest_message(message) - def OnDragEnter(self, browser, dragData, mask): - subtest_message('cef.OnDragEnter() OK') - return False - - def StartDragging(self,browser, drag_data, allowed_ops, x, y): - subtest_message('cef.StartDragging() OK') - return False +class LoadHandler(object): + def __init__(self, test_case): + self.test_case = test_case + self.test_for_True = True + self.OnLoadEnd_True = False def OnLoadEnd(self,browser,frame,http_code): - subtest_message('cef.OnLoadEnd() OK') - #testing mouse event - browser.SendMouseClickEvent(300, 20, cef.MOUSEBUTTON_LEFT, False, 1, cef.EVENTFLAG_LEFT_MOUSE_BUTTON) - browser.SendMouseMoveEvent(305, 25, False, cef.EVENTFLAG_LEFT_MOUSE_BUTTON) - browser.SendMouseClickEvent(305, 25, cef.MOUSEBUTTON_LEFT, True, 1, cef.EVENTFLAG_LEFT_MOUSE_BUTTON) + self.test_case.assertFalse(self.OnLoadEnd_True) + self.OnLoadEnd_True = True + + # testing trigger StartDragging handler. + # TODO: this test fails, following the steps of SendMouse*Event, + # it's not successfuly triggered. + # browser.SendMouseMoveEvent(305, 20, False, 0) + # browser.SendMouseClickEvent(300, 20, cef.MOUSEBUTTON_LEFT, False, 1, cef.EVENTFLAG_LEFT_MOUSE_BUTTON) + # browser.SendMouseMoveEvent(305, 25, False, cef.EVENTFLAG_LEFT_MOUSE_BUTTON) + # browser.SendMouseClickEvent(305, 25, cef.MOUSEBUTTON_LEFT, True, 1, cef.EVENTFLAG_LEFT_MOUSE_BUTTON) # testing drag event - # It can trigging cef.OnDragEnter, but still not trigger dragenter event in JS. + # TODO: It can trigging cef.OnDragEnter, + # but still not trigger dragenter event in JS. dragData = cef.DragData() - dragData.SetFragmentText('Test') - dragData.ResetFileContents() - browser.DragTargetDragEnter(dragData, 301, 21, cef.DRAG_OPERATION_COPY ) - browser.DragTargetDragOver(302, 22, cef.DRAG_OPERATION_COPY ) + browser.DragTargetDragEnter(dragData, 301, 21, cef.DRAG_OPERATION_COPY) + browser.DragTargetDragOver(302, 22, cef.DRAG_OPERATION_COPY) browser.DragTargetDrop(303, 23) - browser.DragSourceEndedAt(303, 23, cef.DRAG_OPERATION_COPY ) + browser.DragSourceEndedAt(303, 23, cef.DRAG_OPERATION_COPY) browser.DragSourceSystemDragEnded() +class RenderHandler(object): + def __init__(self, test_case): + self.test_case = test_case + self.test_for_True = True + # self.StartDragging_True = False + def StartDragging(self,browser, drag_data, allowed_ops, x, y): + # self.test_case.assertFalse(self.StartDragging_True) + # self.StartDragging_True = True + return False +class DragHandler(object): + def __init__(self, test_case): + self.test_case = test_case + self.test_for_True = True + self.OnDragEnter_True = False -class OSRTest_IsolatedTest(unittest.TestCase): - def test_dragdrop(self): - sys.excepthook = cef.ExceptHook - cef.Initialize(settings={"windowless_rendering_enabled": True}) - parent_window_handle = 0 - window_info = cef.WindowInfo() - window_info.SetAsOffscreen(parent_window_handle) - browser = cef.CreateBrowserSync(window_info=window_info, - url=g_datauri) - browser.SetClientHandler(Handler()) - browser.SendFocusEvent(True) - browser.WasResized() - for i in range(200): - cef.MessageLoopWork() - time.sleep(0.01) - cef.Shutdown() - - def test_dragdata(self): - dragData = cef.DragData() - testString = 'Testing DragData' - fileUri = r"C:\temp\ninja\README" - dragData.SetFragmentText(testString) - self.assertEqual(testString,dragData.GetFragmentText(),'SetFragmentText') - subtest_message('DragData.SetFragmentText() OK') - dragData.SetFragmentHtml(testString) - self.assertEqual(testString, dragData.GetFragmentHtml(), 'SetFragmentHtml') - subtest_message('DragData.SetFragmentHtml() OK') - dragData.AddFile(fileUri,'README') - subtest_message('DragData.AddFile() OK') - self.assertIn(fileUri, dragData.GetFileNames(), 'GetFileNames') - subtest_message('DragData.GetFileNames() OK') + def OnDragEnter(self, browser, dragData, mask): + self.test_case.assertFalse(self.OnDragEnter_True) + self.OnDragEnter_True = True + return False if __name__ == "__main__": - unittests._test_runner.main(basename(__file__)) \ No newline at end of file + unittests._test_runner.main(basename(__file__)) From 960de83fdd88282a77fd18f3842b7cafd6043898 Mon Sep 17 00:00:00 2001 From: demon Date: Thu, 27 Jul 2017 17:52:15 +0800 Subject: [PATCH 16/17] + --- README.md | 5 +++++ api/API-index.md | 5 +++++ api/DialogHandler.md | 31 +++++++++++++++++++++++++++++++ api/DragHandler.md | 4 ++-- api/FileDialogCallback.md | 38 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 api/DialogHandler.md create mode 100644 api/FileDialogCallback.md diff --git a/README.md b/README.md index 3f6ff51a..2713eeb3 100644 --- a/README.md +++ b/README.md @@ -456,6 +456,8 @@ Additional information for v31.2 release: * [FlushStore](api/CookieManager.md#flushstore) * [CookieVisitor (interface)](api/CookieVisitor.md#cookievisitor-interface) * [Visit](api/CookieVisitor.md#visit) +* [DialogHandler (interface)](api/DialogHandler.md#dialoghandler-interface) + * [OnFileDialog](api/DialogHandler.md#onfiledialog) * [DisplayHandler (interface)](api/DisplayHandler.md#displayhandler-interface) * [OnAddressChange](api/DisplayHandler.md#onaddresschange) * [OnTitleChange](api/DisplayHandler.md#ontitlechange) @@ -486,6 +488,9 @@ Additional information for v31.2 release: * [SetFragmentHtml](api/DragData.md#setfragmenthtml) * [DragHandler (interface)](api/DragHandler.md#draghandler-interface) * [OnDragEnter](api/DragHandler.md#ondragenter) +* [FileDialogCallback (object)](api/FileDialogCallback.md#filedialogcallback-object) + * [Cancel](api/FileDialogCallback.md#cancel) + * [Continue](api/FileDialogCallback.md#continue) * [FocusHandler (interface)](api/FocusHandler.md#focushandler-interface) * [OnTakeFocus](api/FocusHandler.md#ontakefocus) * [OnSetFocus](api/FocusHandler.md#onsetfocus) diff --git a/api/API-index.md b/api/API-index.md index d3c2b377..f5bf399b 100644 --- a/api/API-index.md +++ b/api/API-index.md @@ -198,6 +198,8 @@ * [FlushStore](CookieManager.md#flushstore) * [CookieVisitor (interface)](CookieVisitor.md#cookievisitor-interface) * [Visit](CookieVisitor.md#visit) +* [DialogHandler (interface)](DialogHandler.md#dialoghandler-interface) + * [OnFileDialog](DialogHandler.md#onfiledialog) * [DisplayHandler (interface)](DisplayHandler.md#displayhandler-interface) * [OnAddressChange](DisplayHandler.md#onaddresschange) * [OnTitleChange](DisplayHandler.md#ontitlechange) @@ -228,6 +230,9 @@ * [SetFragmentHtml](DragData.md#setfragmenthtml) * [DragHandler (interface)](DragHandler.md#draghandler-interface) * [OnDragEnter](DragHandler.md#ondragenter) +* [FileDialogCallback (object)](FileDialogCallback.md#filedialogcallback-object) + * [Cancel](FileDialogCallback.md#cancel) + * [Continue](FileDialogCallback.md#continue) * [FocusHandler (interface)](FocusHandler.md#focushandler-interface) * [OnTakeFocus](FocusHandler.md#ontakefocus) * [OnSetFocus](FocusHandler.md#onsetfocus) diff --git a/api/DialogHandler.md b/api/DialogHandler.md new file mode 100644 index 00000000..b1d47bf5 --- /dev/null +++ b/api/DialogHandler.md @@ -0,0 +1,31 @@ +[API categories](API-categories.md) | [API index](API-index.md) + + +# DialogHandler (interface) + +Description from upstream CEF: +> Implement this interface to handle dialog events. The methods of this class will be called on the browser process UI thread. + + +Table of contents: +* [Callbacks](#callbacks) + * [OnFileDialog](#onfiledialog) + +## Callbacks + + +### OnFileDialog + +| Parameter | Type | +| --- | --- | +| browser | [Browser](Browser.md) | +| mode | int | +| title | string | +| default_file_path | string | +| accept_filters | list | +| selected_accept_filter | int | +| file_dialog_callback | [FileDialogCallback](FileDialogCallback.md)| +| __Return__ | bool | + +Description from upstream CEF: +> Called to run a file chooser dialog. diff --git a/api/DragHandler.md b/api/DragHandler.md index 5be80a7c..97550f99 100644 --- a/api/DragHandler.md +++ b/api/DragHandler.md @@ -22,5 +22,5 @@ Table of contents: | mask | int | | __Return__ | bool | - Called when an external drag event enters the browser window. - +Description from upstream CEF: +> Called when an external drag event enters the browser window. diff --git a/api/FileDialogCallback.md b/api/FileDialogCallback.md new file mode 100644 index 00000000..5de77fe9 --- /dev/null +++ b/api/FileDialogCallback.md @@ -0,0 +1,38 @@ +[API categories](API-categories.md) | [API index](API-index.md) + + +# FileDialogCallback (object) + +Description from upstream CEF: +> Callback interface for asynchronous continuation of file dialog requests. + + +Table of contents: +* [Methods](#methods) + * [Cancel](#cancel) + * [Continue](#continue) + + +## Methods + + +### Cancel + +| Parameter | Type | +| --- | --- | +| __Return__ | void | + +Description from upstream CEF: +> Cancel the file selection. + + +### Continue + +| Parameter | Type | +| --- | --- | +| selected_accept_filter | int | +| file_paths | list | +| __Return__ | void | + +Description from upstream CEF: +> Continue the file selection. |selected_accept_filter| should be the 0-based index of the value selected from the accept filters array passed to CefDialogHandler::OnFileDialog. |file_paths| should be a single value or a list of values depending on the dialog mode. An empty |file_paths| value is treated the same as calling Cancel(). \ No newline at end of file From 3341550e485b55443ed1c57d6e7b99f345c1d160 Mon Sep 17 00:00:00 2001 From: demon Date: Fri, 28 Jul 2017 09:44:30 +0800 Subject: [PATCH 17/17] Update API docs. --- api/DialogHandler.md | 18 ++++++++++++++++-- api/FileDialogCallback.md | 6 +++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/api/DialogHandler.md b/api/DialogHandler.md index b1d47bf5..0c47d27c 100644 --- a/api/DialogHandler.md +++ b/api/DialogHandler.md @@ -4,7 +4,8 @@ # DialogHandler (interface) Description from upstream CEF: -> Implement this interface to handle dialog events. The methods of this class will be called on the browser process UI thread. +> Implement this interface to handle dialog events. +> The methods of this class will be called on the browser process UI thread. Table of contents: @@ -28,4 +29,17 @@ Table of contents: | __Return__ | bool | Description from upstream CEF: -> Called to run a file chooser dialog. +> Called to run a file chooser dialog. +> |mode| represents the type of dialog to display. +> |title| to the title to be used for the dialog and may be empty to show the default title ("Open" or "Save" depending +> on the mode). |default_file_path| is the path with optional directory and/or file name component that should +> be initially selected in the dialog. |accept_filters| are used to restrict the selectable file types and +> may anycombination of (a) valid lower-cased MIME types (e.g. "text/*" or "image/*"), (b) individual file +> extensions (e.g. ".txt" or ".png"), or (c) combined description and file extension delimited using "|" and ";" +> (e.g. "Image Types|.png;.gif;.jpg"). +> |selected_accept_filter| is the 0-based index of the filter that should be selected by default. To display a custom +> dialog return true and execute +> |callback| either inline or at a later time. To display the default dialog return false. + + + diff --git a/api/FileDialogCallback.md b/api/FileDialogCallback.md index 5de77fe9..e6fe78c7 100644 --- a/api/FileDialogCallback.md +++ b/api/FileDialogCallback.md @@ -35,4 +35,8 @@ Description from upstream CEF: | __Return__ | void | Description from upstream CEF: -> Continue the file selection. |selected_accept_filter| should be the 0-based index of the value selected from the accept filters array passed to CefDialogHandler::OnFileDialog. |file_paths| should be a single value or a list of values depending on the dialog mode. An empty |file_paths| value is treated the same as calling Cancel(). \ No newline at end of file +> Continue the file selection. +> |selected_accept_filter| should be the 0-based index of the value selected from the accept filters array passed to +> CefDialogHandler::OnFileDialog. |file_paths| should be a single value or a list of values +> depending on the dialog mode. An empty +> |file_paths| value is treated the same as calling Cancel(). \ No newline at end of file