X Tutup
Skip to content

Commit c5951b6

Browse files
committed
Provide default implementation for js and file dialogs on Linux (cztomczak#241)...
In wxpython.py and gtk2.py examples the js alert dialog when run from a popup gives focus to the main window. The popup window is created internally by CEF and this probably needs to be changed so that popups are created by wx in OnBeforePopup and this will resolve issue with alert focus. In qt4.py and tkinter.py and hello_world.py examples focus works fine in the popup window. Add --hello-world flag to build.py and run_examples.py tools.
1 parent c0a218b commit c5951b6

15 files changed

+704
-16
lines changed

src/client_handler/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ UNAME_S = $(shell uname -s)
1212
CCFLAGS = -fPIC $(CEF_CCFLAGS)
1313

1414
ifeq ($(UNAME_S), Linux)
15-
SRC_MORE = x11.cpp
15+
SRC_MORE = x11.cpp dialog_handler_gtk.cpp
1616
else ifeq ($(UNAME_S), Darwin)
1717
SRC_MORE = util_mac.mm
1818
endif
@@ -22,7 +22,7 @@ SRC = client_handler.cpp cookie_visitor.cpp resource_handler.cpp \
2222
task.cpp context_menu_handler.cpp display_handler.cpp \
2323
download_handler.cpp focus_handler.cpp js_dialog_handler.cpp \
2424
keyboard_handler.cpp lifespan_handler.cpp load_handler.cpp \
25-
render_handler.cpp request_handler.cpp \
25+
render_handler.cpp request_handler.cpp dialog_handler.cpp \
2626
$(SRC_MORE)
2727

2828
OBJ = $(filter %.o, $(SRC:.cpp=.o) $(SRC:.mm=.o))

src/client_handler/client_handler.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
// CefClient
2525
// ----------------------------------------------------------------------------
2626

27+
2728
bool ClientHandler::OnProcessMessageReceived(
2829
CefRefPtr<CefBrowser> browser,
2930
CefProcessId source_process,

src/client_handler/client_handler.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "common/cefpython_public_api.h"
1414

1515
#include "context_menu_handler.h"
16+
#include "dialog_handler.h"
1617
#include "display_handler.h"
1718
#include "download_handler.h"
1819
#include "focus_handler.h"
@@ -26,6 +27,7 @@
2627

2728
class ClientHandler : public CefClient,
2829
public ContextMenuHandler,
30+
public DialogHandler,
2931
public DisplayHandler,
3032
public DownloadHandler,
3133
public FocusHandler,
@@ -44,6 +46,12 @@ class ClientHandler : public CefClient,
4446
return this;
4547
}
4648

49+
#if defined(OS_LINUX)
50+
CefRefPtr<CefDialogHandler> GetDialogHandler() override {
51+
return this;
52+
}
53+
#endif
54+
4755
CefRefPtr<CefDisplayHandler> GetDisplayHandler() override {
4856
return this;
4957
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright (c) 2017 CEF Python, see the Authors file.
2+
// All rights reserved. Licensed under BSD 3-clause license.
3+
// Project website: https://github.com/cztomczak/cefpython
4+
5+
#include "dialog_handler.h"
6+
7+
8+
DialogHandler::DialogHandler()
9+
{
10+
#if defined(OS_LINUX)
11+
// Provide the GTK-based default dialog implementation on Linux.
12+
dialog_handler_ = new ClientDialogHandlerGtk();
13+
#endif
14+
}
15+
16+
17+
bool DialogHandler::OnFileDialog(CefRefPtr<CefBrowser> browser,
18+
FileDialogMode mode,
19+
const CefString& title,
20+
const CefString& default_file_path,
21+
const std::vector<CefString>& accept_filters,
22+
int selected_accept_filter,
23+
CefRefPtr<CefFileDialogCallback> callback)
24+
{
25+
#if defined(OS_LINUX)
26+
return dialog_handler_->OnFileDialog(browser,
27+
mode,
28+
title,
29+
default_file_path,
30+
accept_filters,
31+
selected_accept_filter,
32+
callback);
33+
#else
34+
return false;
35+
#endif
36+
37+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (c) 2017 CEF Python, see the Authors file.
2+
// All rights reserved. Licensed under BSD 3-clause license.
3+
// Project website: https://github.com/cztomczak/cefpython
4+
5+
#pragma once
6+
7+
#include "common/cefpython_public_api.h"
8+
#include "include/cef_dialog_handler.h"
9+
10+
#if defined(OS_LINUX)
11+
#include "dialog_handler_gtk.h"
12+
#endif
13+
14+
15+
class DialogHandler : public CefDialogHandler
16+
{
17+
public:
18+
DialogHandler();
19+
virtual ~DialogHandler(){}
20+
21+
bool OnFileDialog(CefRefPtr<CefBrowser> browser,
22+
FileDialogMode mode,
23+
const CefString& title,
24+
const CefString& default_file_path,
25+
const std::vector<CefString>& accept_filters,
26+
int selected_accept_filter,
27+
CefRefPtr<CefFileDialogCallback> callback)
28+
override;
29+
30+
public:
31+
#if defined(OS_LINUX)
32+
// Default dialog handler impl for GTK.
33+
CefRefPtr<ClientDialogHandlerGtk> dialog_handler_;
34+
#endif
35+
36+
private:
37+
IMPLEMENT_REFCOUNTING(DialogHandler);
38+
};

0 commit comments

Comments
 (0)
X Tutup