Skip to content
This repository has been archived by the owner on Sep 2, 2021. It is now read-only.

Commit

Permalink
Merge pull request #665 from adobe/master
Browse files Browse the repository at this point in the history
Merge master to release for 1.14 release
  • Loading branch information
narayani28 authored Apr 26, 2019
2 parents b858d45 + 651b74b commit e31c5f5
Show file tree
Hide file tree
Showing 15 changed files with 305 additions and 33 deletions.
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ module.exports = function (grunt) {
"version" : cef_version
},
"node": {
"version" : "6.11.0"
"version" : "6.14.0"
},
"icu": {
"url" : "http://s3.amazonaws.com/files.brackets.io/icu",
Expand Down
3 changes: 3 additions & 0 deletions appshell.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,9 @@
'$(SDKROOT)/System/Library/Frameworks/ScriptingBridge.framework',
'$(SDKROOT)/System/Library/Frameworks/Security.framework',
'$(CONFIGURATION)/<(framework_name).framework/<(framework_name)',
'deps/icu/lib/libicuuc.a',
'deps/icu/lib/libicui18n.a',
'deps/icu/lib/libicudata.a',
],
},
'sources': [
Expand Down
210 changes: 191 additions & 19 deletions appshell/browser/root_window_gtk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,202 @@
#include "appshell/browser/window_test.h"
#include "appshell/common/client_switches.h"

// Brackets specific change.
// Brackets specific changes.
#include "appshell/native_menu_model.h"
#include "appshell/command_callbacks.h"
#include "appshell/appshell_helpers.h"

#define DEFAULT_WINDOW_WIDTH 800
#define DEFAULT_WINDOW_HEIGHT 600
// End of Brackets specific changes.

namespace client {

namespace {

const char kMenuIdKey[] = "menu_id";

bool IsWindowMaximized(GtkWindow* window) {
GdkWindow* gdk_window = gtk_widget_get_window(GTK_WIDGET(window));
gint state = gdk_window_get_state(gdk_window);
return (state & GDK_WINDOW_STATE_MAXIMIZED) ? true : false;
// Brackets specific changes.
gboolean IsWindowMaximized(GtkWindow* window) {

if (window) {
GdkWindow* gdk_window = gtk_widget_get_window(GTK_WIDGET(window));
if (gdk_window) {
gint state = gdk_window_get_state(gdk_window);
return (state & GDK_WINDOW_STATE_MAXIMIZED) ? TRUE : FALSE;
}
} else {
return FALSE;
}

}

void MinimizeWindow(GtkWindow* window) {
// Unmaximize the window before minimizing so restore behaves correctly.
if (IsWindowMaximized(window))
gtk_window_unmaximize(window);

gtk_window_iconify(window);
if (window) {
// Unmaximize the window before minimizing so restore behaves correctly.
if (IsWindowMaximized(window))
gtk_window_unmaximize(window);

gtk_window_iconify(window);
}
}

void MaximizeWindow(GtkWindow* window) {
gtk_window_maximize(window);
if (window) {
gtk_window_maximize(window);
}
}

void SaveWindowState(GtkWindow* window) {

if (!window)
return;

gint left = 1;
gint top = 1;
gint width = DEFAULT_WINDOW_WIDTH;
gint height = DEFAULT_WINDOW_HEIGHT;

// Try to center the window.
GdkScreen* screen = gdk_screen_get_default();
if (screen) {
left = (gdk_screen_get_width(screen) - DEFAULT_WINDOW_WIDTH) / 2 ;
top = (gdk_screen_get_height(screen) - DEFAULT_WINDOW_HEIGHT) / 2 ;
}

GKeyFile* key_file = g_key_file_new();
GError* err = NULL;
gchar* filePath = NULL;

if (key_file) {
filePath = g_strdup_printf("%s/%s", appshell::AppGetSupportDirectory().ToString().c_str(), "window.ini");
gboolean maximized = IsWindowMaximized(window);

// If window is not maximized, save current size and position

if (!maximized) {
gtk_window_get_position(window, &left, &top);
gtk_window_get_size(window, &width, &height);
} else if (g_key_file_load_from_file(key_file, filePath, G_KEY_FILE_NONE, &err)) {

// If maximized, load size and position from file
// to preserve last saved values
left = g_key_file_get_integer(key_file, "position", "left", &err);
if (!err)
top = g_key_file_get_integer(key_file, "position", "top", &err);

if (!err)
width = g_key_file_get_integer(key_file, "size", "width", &err);

if (!err)
height = g_key_file_get_integer(key_file, "size", "height", &err);

// If any value can not be read, restore defaults
if (err) {
left = 1;
top = 1;
width = DEFAULT_WINDOW_WIDTH;
height = DEFAULT_WINDOW_HEIGHT;
g_error_free(err);
}
}

// The values would always be written to file.
g_key_file_set_integer(key_file, "position", "left", left);
g_key_file_set_integer(key_file, "position", "top", top);
g_key_file_set_integer(key_file, "size", "width", width - 1); // DelayedResize() 1 pixel compensation
g_key_file_set_integer(key_file, "size", "height", height - 1); // DelayedResize() 1 pixel compensation
g_key_file_set_boolean(key_file, "state", "maximized", maximized);

err = NULL;
g_key_file_save_to_file(key_file, filePath, &err);

if (err) {
fprintf(stderr, "Err -> SaveWindowState(): could not write to `window.ini`. Error Description: %s\n", err->message);
}
} else {
fprintf(stderr, "Err -> SaveWindowState(): could not write to `window.ini`\n");
}
}

void LoadWindowState(GtkWindow* window) {

if (!window) {
return;
}

// Default values for the window state.
gint left = 1;
gint top = 1;
gint width = DEFAULT_WINDOW_WIDTH;
gint height = DEFAULT_WINDOW_HEIGHT;

// Try to center the window.
GdkScreen* screen = gdk_screen_get_default();
if (screen) {
left = (gdk_screen_get_width(screen) - DEFAULT_WINDOW_WIDTH) / 2 ;
top = (gdk_screen_get_height(screen) - DEFAULT_WINDOW_HEIGHT) / 2 ;
}

gboolean maximized = false;

GKeyFile* key_file = g_key_file_new();
bool any_error = false;
GError* err = NULL;
gchar* filePath = g_strdup_printf("%s/%s", appshell::AppGetSupportDirectory().ToString().c_str(), "window.ini");

if (key_file && g_key_file_load_from_file(key_file, filePath, G_KEY_FILE_NONE, &err)) {

left = g_key_file_get_integer(key_file, "position", "left", &err);
if (!err)
top = g_key_file_get_integer(key_file, "position", "top", &err);

if (!err)
width = g_key_file_get_integer(key_file, "size", "width", &err);

if (!err)
height = g_key_file_get_integer(key_file, "size", "height", &err);

if (!err)
maximized = g_key_file_get_boolean(key_file, "state", "maximized", &err);

// If any value can not be readed, set defaults again
if (err) {
left = 1;
top = 1;
width = DEFAULT_WINDOW_WIDTH;
height = DEFAULT_WINDOW_HEIGHT;
maximized = TRUE;
}
} else {
any_error = true;
}

gtk_window_move(GTK_WINDOW(window), left, top);
gtk_window_set_default_size(GTK_WINDOW(window), width, height);

if (maximized)
MaximizeWindow(window);

if (err || any_error) {

// The failure could be because the file may not have been present,
// or the file read itself failed.
// In either of the cases default to maximizing the window.
MaximizeWindow(window);

if (err) {
if (err->code != G_KEY_FILE_ERROR_KEY_NOT_FOUND){
fprintf(stderr, "LoadWindowState(): Could not read %s. Error Description:%s.\n", filePath, err->message);
}
g_error_free(err);
} else {
fprintf(stderr, "LoadWindowState(): Could not read %s.\n", filePath);
}
}
}
// End of Brackets specific changes.

} // namespace

Expand Down Expand Up @@ -197,6 +366,7 @@ void RootWindowGtk::Close(bool force) {
REQUIRE_MAIN_THREAD();

if (window_) {
SaveWindowState(GTK_WINDOW(window_));
force_close_ = force;
gtk_widget_destroy(window_);
}
Expand Down Expand Up @@ -242,18 +412,20 @@ void RootWindowGtk::CreateRootWindow(const CefBrowserSettings& settings) {
// in the upper-left corner. Maybe there's a better default place to put it?
int x = start_rect_.x;
int y = start_rect_.y;
int width, height;
int width = start_rect_.width;
int height = start_rect_.height;

window_ = gtk_window_new(GTK_WINDOW_TOPLEVEL);

// Brackets specific change.
if (start_rect_.IsEmpty()) {
// TODO(port): Also, maybe there's a better way to choose the default size.
width = 800;
height = 600;
LoadWindowState(GTK_WINDOW(window_));
} else {
width = start_rect_.width;
height = start_rect_.height;
gtk_window_move(GTK_WINDOW(window_), x, y);
gtk_window_set_default_size(GTK_WINDOW(window_), width, height);
}
// End of Brackets specific change.

window_ = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size(GTK_WINDOW(window_), width, height);
g_signal_connect(G_OBJECT(window_), "focus-in-event",
G_CALLBACK(&RootWindowGtk::WindowFocusIn), this);
g_signal_connect(G_OBJECT(window_), "window-state-event",
Expand Down Expand Up @@ -341,7 +513,7 @@ void RootWindowGtk::CreateRootWindow(const CefBrowserSettings& settings) {
// Most window managers ignore requests for initial window positions (instead
// using a user-defined placement algorithm) and honor requests after the
// window has already been shown.
gtk_window_move(GTK_WINDOW(window_), x, y);
//gtk_window_move(GTK_WINDOW(window_), x, y);

// Windowed browsers are parented to the X11 Window underlying the GtkWindow*
// and must be sized manually. The OSR GTK widget, on the other hand, can be
Expand Down
30 changes: 30 additions & 0 deletions appshell/cefclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@

CefRefPtr<ClientHandler> g_handler;

#ifdef OS_WIN
bool g_force_enable_acc = false;
#endif

CefRefPtr<CefBrowser> AppGetBrowser() {
if (!g_handler.get())
return NULL;
Expand All @@ -32,6 +36,20 @@ CefWindowHandle AppGetMainHwnd() {
return g_handler->GetMainHwnd();
}

// CefCommandLine::HasSwitch is unable to report the presense of switches,
// in the command line properly. This is a generic function that could be
// used to check for any particular switch, passed as a command line argument.
bool HasSwitch(CefRefPtr<CefCommandLine> command_line , CefString& switch_name)
{
if (command_line) {
ExtensionString cmdLine = command_line->GetCommandLineString();
size_t idx = cmdLine.find(switch_name);
return idx > 0 && idx < cmdLine.length();
} else {
return false;
}
}

// Returns the application settings based on command line arguments.
void AppGetSettings(CefSettings& settings, CefRefPtr<CefCommandLine> command_line) {
DCHECK(command_line.get());
Expand Down Expand Up @@ -91,4 +109,16 @@ void AppGetSettings(CefSettings& settings, CefRefPtr<CefCommandLine> command_lin
// Set product version, which gets added to the User Agent string
CefString(&settings.product_version) = versionStr;
}

#ifdef OS_WIN
// We disable renderer accessibility by default as it is known to cause performance
// issues. But if any one wants to enable it back, then we need to honor the flag.

CefString force_acc_switch_name("--force-renderer-accessibility");
CefString enable_acc_switch_name("--enable-renderer-accessibility");

if (HasSwitch(command_line, force_acc_switch_name) || HasSwitch(command_line, enable_acc_switch_name))
g_force_enable_acc = true;
#endif

}
25 changes: 25 additions & 0 deletions appshell/client_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
#include "appshell/appshell_extension_handler.h"
#include "appshell/appshell_helpers.h"

#ifdef OS_WIN
extern bool g_force_enable_acc;
#endif

ClientApp::ClientApp() {
CreateRenderDelegates(render_delegates_);
}
Expand All @@ -42,6 +46,27 @@ void ClientApp::OnContextCreated(CefRefPtr<CefBrowser> browser,
(*it)->OnContextCreated(this, browser, frame, context);
}

void ClientApp::OnBeforeCommandLineProcessing(
const CefString& process_type,
CefRefPtr<CefCommandLine> command_line)
{
#ifdef OS_WIN
// Check if the user wants to enable renderer accessibility
// and if not, then disable renderer accessibility.
if (!g_force_enable_acc)
command_line->AppendSwitch("disable-renderer-accessibility");
#endif
}

void ClientApp::OnBeforeChildProcessLaunch(
CefRefPtr<CefCommandLine> command_line)
{
#ifdef OS_WIN
if (!g_force_enable_acc)
command_line->AppendSwitch("disable-renderer-accessibility");
#endif
}

void ClientApp::OnContextReleased(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefV8Context> context) {
Expand Down
9 changes: 9 additions & 0 deletions appshell/client_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ class ClientApp : public CefApp,
}
virtual CefRefPtr<CefRenderProcessHandler> GetRenderProcessHandler()
OVERRIDE { return this; }

virtual CefRefPtr<CefBrowserProcessHandler> GetBrowserProcessHandler()
OVERRIDE { return this; }
virtual void OnBeforeCommandLineProcessing(
const CefString& process_type,
CefRefPtr<CefCommandLine> command_line);

virtual void OnBeforeChildProcessLaunch(
CefRefPtr<CefCommandLine> command_line);

// CefRenderProcessHandler methods.
virtual void OnWebKitInitialized() OVERRIDE;
Expand Down
4 changes: 2 additions & 2 deletions appshell/mac/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.13.0</string>
<string>1.14.0</string>
<key>CFBundleShortVersionString</key>
<string>1.13.0</string>
<string>1.14.0</string>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>
Expand Down
Loading

0 comments on commit e31c5f5

Please sign in to comment.