-
-
Notifications
You must be signed in to change notification settings - Fork 479
Expose OnDragEnter & OnFileDialog in ClientHandler (#188, #361) #375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
+ Expose DialogHandler.onFileDialog + Expose methods IsFile, IsFileName, IsFileNames in DragData. + Expose FileDialogCallback
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On what platforms have you tested these changes? (I guess Windows only)
Please provide an example with which I can test the new functionality. You can either add unit tests. Or you can attach a script in this PR through gist: https://gist.github.com/ .
I see you've modified cef_version_win.h and set to an older version of CEF (v57). Looks like you're using CEF Python v57 and in this case you should have made this PR to branch cefpython57 instead of master. Your change alters CEF version and also removes DragData.GetImageHotspot() function which you can't do.
src/client_handler/client_handler.h
Outdated
| } | ||
|
|
||
| #if defined(OS_LINUX) | ||
| //#if defined(OS_LINUX) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove the comment
src/client_handler/client_handler.h
Outdated
| return this; | ||
| } | ||
| #endif | ||
| //#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And this one too
| #if defined(OS_LINUX) | ||
| return dialog_handler_->OnFileDialog(browser, | ||
| bool result; | ||
| result = DialogHandlerr_OnFileDialog(browser, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix typo in the function name "DialogHandlerr_OnFileDialog" - there are two "r"
| if(result){ | ||
| return result; | ||
| }else{ | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the blank line
| return result; | ||
| }else{ | ||
|
|
||
| #if defined(OS_LINUX) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Preprocessor conditions like #if #else #endif should be without indent as in the original source file
src/handlers/drag_handler.pyx
Outdated
| returnValue = callback(browser=pyBrowser, | ||
| dragData=drag_data, | ||
| mask=mask) | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Too many blank lines
src/handlers/drag_handler.pyx
Outdated
| callback = pyBrowser.GetClientCallback("OnDragEnter") | ||
| if callback: | ||
| returnValue = callback(browser=pyBrowser, | ||
| dragData=drag_data, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix indent for func arguments
src/handlers/drag_handler.pyx
Outdated
| sys.excepthook(exc_type, exc_value, exc_trace) | ||
|
|
||
| return False | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Too many blank lines
src/version/cef_version_win.h
Outdated
|
|
||
| #define CEF_VERSION "3.2987.1601.gf035232" | ||
| #define CEF_VERSION_MAJOR 3 | ||
| #define CEF_COMMIT_NUMBER 1604 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can't modify this file in this PR, this was explained by me in the other comment
src/version/cef_version_win.h
Outdated
| //#define CHROME_VERSION_BUILD 3029 | ||
| //#define CHROME_VERSION_PATCH 81 | ||
|
|
||
| #define CEF_VERSION "3.2987.1601.gf035232" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like you're using CEF Python v57, but you made this PR to branch master which uses CEF Python v58.
|
Thanks for reviewing my code. I'll fixed the coding style. I only tested in Windows 7 platform. Sorry about changed CEF_VERSION in cef_version_win.h. |
|
When running the build.py / build_distrib.py tools unit tests and examples are run automatically. The build_distrib.py tool tests multiple python versions automatically, read top comments in sources. You can build master using these instructions that use Spotify binaries: But first you have to satisfy requirements: |
|
If having problems building master please ask on the Forum, as this is off-topic here. |
|
Useful resources in regards to installing multiple python versions with pyenv or editing cefpython's code using PyCharm are labeled Knowledge Base in the tracker. |
|
Thanks for your comments. |
| return result; | ||
| }else{ | ||
| #if defined(OS_LINUX) | ||
| return dialog_handler_->OnFileDialog(browser, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong indent, should be only 4 spaces.
api/DragData.md
Outdated
|
|
||
| Table of contents: | ||
| * [Methods](#methods) | ||
| * [IsFile](#isfile) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sections should be ordered alphabetically, then re-generate TOC.
| #include "drag_handler.h" | ||
|
|
||
|
|
||
| bool DragHandler::OnDragEnter(CefRefPtr<CefBrowser> browser, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that API doc for OnDragEnter is missing.
src/drag_data.pyx
Outdated
| PyToCefString(text,cefText) | ||
| self.cef_drag_data.get().SetFragmentText(cefText) | ||
|
|
||
| cpdef py_void SetFragmentHtml(self, html ): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An unnecessary space before closing parentheses.
src/drag_data.pyx
Outdated
|
|
||
| cpdef py_void SetFragmentText(self, text): | ||
| cdef CefString cefText | ||
| PyToCefString(text,cefText) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please separate arguments with a space after comma.
src/drag_data.pyx
Outdated
|
|
||
| cpdef py_void SetFragmentHtml(self, html ): | ||
| cdef CefString cefHtml | ||
| PyToCefString(html,cefHtml) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here too.
src/drag_data.pyx
Outdated
| cdef CefString cefPath | ||
| cdef CefString cefDisplayName | ||
| PyToCefString(path,cefPath) | ||
| PyToCefString(display_name,cefDisplayName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Space please.
src/drag_data.pyx
Outdated
| cdef CefString cefDisplayName | ||
| PyToCefString(path,cefPath) | ||
| PyToCefString(display_name,cefDisplayName) | ||
| self.cef_drag_data.get().AddFile(cefPath,cefDisplayName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here too.
src/extern/cef/cef_drag_data.pxd
Outdated
|
|
||
| cdef extern from "include/cef_drag_data.h": | ||
| cdef cppclass CefDragData: | ||
| cpp_bool IsFile() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the methods were ordered alphabetically before then please keep an alphabetic order when adding new ones.
| def __init__(self): | ||
| self.OnPaint_called = False | ||
|
|
||
| def OnConsoleMessage(self, message, **_): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This duplicates code from main_test.py. Can we create _common.py file in unittests/ and move the duplicate code there? The DisplayHandler from main_test.py should be moved there and be imported in main_test.py and osr_test.py.
| browser.DragSourceEndedAt(303, 23, cef.DRAG_OPERATION_COPY ) | ||
| browser.DragSourceSystemDragEnded() | ||
|
|
||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Too many blank lines.
unittests/osr_test.py
Outdated
| self.OnConsoleMessage_True = True | ||
| subtest_message(message) | ||
|
|
||
| def OnDragEnter(self, browser, dragData, mask): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should keep the naming convention for handlers as in main_test.py, so that there are DragHandler (with OnDragEnter and StartDragging) and LoadHandler (with OnLoadEnd) classes.
unittests/osr_test.py
Outdated
| """ | ||
|
|
||
| g_datauri = "data:text/html;base64," + base64.b64encode(g_datauri_data.encode( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please get rid of the duplicate code. Define "html_to_data_uri" function in _common.py. Code from tutorial.py:
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace these code with a call to html_to_data_uri in both main_test.py and osr_test.py.
unittests/osr_test.py
Outdated
|
|
||
| g_subtests_ran = 0 | ||
|
|
||
| def subtest_message(message): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please get rid of duplicate code in all tests by moving subtest_message to _common.py along with the g_subtests_ran variable.
unittests/osr_test.py
Outdated
|
|
||
|
|
||
| class OSRTest_IsolatedTest(unittest.TestCase): | ||
| def test_dragdrop(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See this comment in main_test.py:
def test_main(self):
"""Main entry point."""
# All this code must run inside one single test, otherwise strange
# things happen.
When working on main_test.py I noticed that you can't initialize CEF in one test run some other tests and then shutdown CEF in last test. I couldn't make it work with python's unittest module, strange things happened. The solution that worked was to run all tests inside on single test (test_main method) and introduce "subtest_message" function to report about results of various tests.
You can however run to separate tests by using IsolatedTest feature. See isolated_test.py - there are two classes defined IsolatedTest1 and IsolatedTest2 which run using separate python processes. This is the only way for CEF to work, because CEF can be initialized/shutdown only once during app lifetime.
I think the easiest thing is to define test_osr() and put both test_dragdrop() and test_dragdata() inside there. I don't mean to put all the code from test_dragdata() inside test_osr(), just make a call from there and the code should be in some separate function as it is now, but just don't make it a separate test.
The test_dragdata code seems to work now, however this seems to be invalid. Most of CEF API is intended to be called only after CEF was initialized. In your case CEF is initialized in test_dragdrop(), however this is a separate test and it shuts down CEF at the end, so after shut down you are not allowed to call any of CEF API anymore. You shouldn't instantiate cef.DragData() aftert CEF was shut down.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just info for the future - with IsolatedTest you can have multiple separate tests in one test file and each of these isolated tests can initalize CEF and shutdown CEF, because they are run using separate processes. But I don't think we need to put these two tests (dragdata and dragdrop) as isolated tests, it would just increase the time to run both tests (CEF initalization, shutdown, message loop - it all takes time). If there is a case for it, when two tests need to be run in separate processes as they might affect each other, then sure go for it and create two isolated tests or more in one test file.
unittests/osr_test.py
Outdated
|
|
||
| def test_dragdata(self): | ||
| dragData = cef.DragData() | ||
| testString = 'Testing DragData' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use double quotes everywhere to be consistent.
unittests/osr_test.py
Outdated
| testString = 'Testing DragData' | ||
| fileUri = r"C:\temp\ninja\README" | ||
| dragData.SetFragmentText(testString) | ||
| self.assertEqual(testString,dragData.GetFragmentText(),'SetFragmentText') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sepearate arguments with spaces.
unittests/osr_test.py
Outdated
| subtest_message('DragData.GetFileNames() OK') | ||
|
|
||
| if __name__ == "__main__": | ||
| unittests._test_runner.main(basename(__file__)) No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing blank line at eof.
unittests/osr_test.py
Outdated
| dragData = cef.DragData() | ||
| dragData.SetFragmentText('Test') | ||
| dragData.ResetFileContents() | ||
| browser.DragTargetDragEnter(dragData, 301, 21, cef.DRAG_OPERATION_COPY ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove unnecessary space before closing parantheses - on this line and other lines below it as well.
unittests/osr_test.py
Outdated
|
|
||
| def OnLoadEnd(self,browser,frame,http_code): | ||
| subtest_message('cef.OnLoadEnd() OK') | ||
| #testing mouse event |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Start a comment with a space and from upper case letter.
| 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Start a comment with a space and from upper case letter.
unittests/osr_test.py
Outdated
| 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add the code below before send the first mouse click event. As I explained on the Forum, you must first send move event to the location at which you will trigger a click event. Try this:
browser.SendMouseMoveEvent(305, 25, 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)
If this code doesn't work as expected then add comment about it that StartDragging is currently never called and is on TODO list. Add a comment with a link to the Forum post in which I referenced code from upstream CEF unit tests on how it should be done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be 300/20 coordinates:
browser.SendMouseMoveEvent(300, 20, False, 0)
|
Just FYI: I've just created Contributing code document. |
api/DragHandler.md
Outdated
| | mask | int | | ||
| | __Return__ | bool | | ||
|
|
||
| Called when an external drag event enters the browser window. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This description is not enough. Please copy complete description from CEF headers using template like: "Description from upstream CEF: ...." - similarly to how it is done in API docs for some of other callbacks.
| CefRefPtr<CefFileDialogCallback> callback) | ||
| { | ||
| bool result; | ||
| result = DialogHandler_OnFileDialog(browser, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are missing API docs for OnFileDialog.
|
Hi DemonXWeb, I see that you still haven't addressed many of my comments. Also I've noted some other issues that I commented about a few times, but still aren't addressed correctly. If you don't have time to work on this further or are overwhelmed by the requirements I can understand this. The features are good and I want them merged. I can make the necessary changes myself later, but the schedule for that is unknown for now. Cheers! |
|
Off-screen rendering test added in rev e72609c. |
abc5014 to
3ca4678
Compare
Expose DragHandler.OnDragEnter
Expose DialogHandler.onFileDialog