Skip to content

Commit

Permalink
Provide default implementation for js and file dialogs on Linux (#241)…
Browse files Browse the repository at this point in the history
…...

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.
  • Loading branch information
cztomczak committed Mar 20, 2017
1 parent c0a218b commit c5951b6
Show file tree
Hide file tree
Showing 15 changed files with 704 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/client_handler/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ UNAME_S = $(shell uname -s)
CCFLAGS = -fPIC $(CEF_CCFLAGS)

ifeq ($(UNAME_S), Linux)
SRC_MORE = x11.cpp
SRC_MORE = x11.cpp dialog_handler_gtk.cpp
else ifeq ($(UNAME_S), Darwin)
SRC_MORE = util_mac.mm
endif
Expand All @@ -22,7 +22,7 @@ SRC = client_handler.cpp cookie_visitor.cpp resource_handler.cpp \
task.cpp context_menu_handler.cpp display_handler.cpp \
download_handler.cpp focus_handler.cpp js_dialog_handler.cpp \
keyboard_handler.cpp lifespan_handler.cpp load_handler.cpp \
render_handler.cpp request_handler.cpp \
render_handler.cpp request_handler.cpp dialog_handler.cpp \
$(SRC_MORE)

OBJ = $(filter %.o, $(SRC:.cpp=.o) $(SRC:.mm=.o))
Expand Down
1 change: 1 addition & 0 deletions src/client_handler/client_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
// CefClient
// ----------------------------------------------------------------------------


bool ClientHandler::OnProcessMessageReceived(
CefRefPtr<CefBrowser> browser,
CefProcessId source_process,
Expand Down
8 changes: 8 additions & 0 deletions src/client_handler/client_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "common/cefpython_public_api.h"

#include "context_menu_handler.h"
#include "dialog_handler.h"
#include "display_handler.h"
#include "download_handler.h"
#include "focus_handler.h"
Expand All @@ -26,6 +27,7 @@

class ClientHandler : public CefClient,
public ContextMenuHandler,
public DialogHandler,
public DisplayHandler,
public DownloadHandler,
public FocusHandler,
Expand All @@ -44,6 +46,12 @@ class ClientHandler : public CefClient,
return this;
}

#if defined(OS_LINUX)
CefRefPtr<CefDialogHandler> GetDialogHandler() override {
return this;
}
#endif

CefRefPtr<CefDisplayHandler> GetDisplayHandler() override {
return this;
}
Expand Down
37 changes: 37 additions & 0 deletions src/client_handler/dialog_handler.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// 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

#include "dialog_handler.h"


DialogHandler::DialogHandler()
{
#if defined(OS_LINUX)
// Provide the GTK-based default dialog implementation on Linux.
dialog_handler_ = new ClientDialogHandlerGtk();
#endif
}


bool DialogHandler::OnFileDialog(CefRefPtr<CefBrowser> browser,
FileDialogMode mode,
const CefString& title,
const CefString& default_file_path,
const std::vector<CefString>& accept_filters,
int selected_accept_filter,
CefRefPtr<CefFileDialogCallback> callback)
{
#if defined(OS_LINUX)
return dialog_handler_->OnFileDialog(browser,
mode,
title,
default_file_path,
accept_filters,
selected_accept_filter,
callback);
#else
return false;
#endif

}
38 changes: 38 additions & 0 deletions src/client_handler/dialog_handler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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

#pragma once

#include "common/cefpython_public_api.h"
#include "include/cef_dialog_handler.h"

#if defined(OS_LINUX)
#include "dialog_handler_gtk.h"
#endif


class DialogHandler : public CefDialogHandler
{
public:
DialogHandler();
virtual ~DialogHandler(){}

bool OnFileDialog(CefRefPtr<CefBrowser> browser,
FileDialogMode mode,
const CefString& title,
const CefString& default_file_path,
const std::vector<CefString>& accept_filters,
int selected_accept_filter,
CefRefPtr<CefFileDialogCallback> callback)
override;

public:
#if defined(OS_LINUX)
// Default dialog handler impl for GTK.
CefRefPtr<ClientDialogHandlerGtk> dialog_handler_;
#endif

private:
IMPLEMENT_REFCOUNTING(DialogHandler);
};
Loading

0 comments on commit c5951b6

Please sign in to comment.