2016-05-18 04:47:50 +00:00
|
|
|
// Copyright (c) 2016 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/common_web_contents_delegate.h"
|
2016-05-18 04:47:50 +00:00
|
|
|
|
|
|
|
#include "base/strings/string_util.h"
|
|
|
|
#include "content/public/browser/native_web_keyboard_event.h"
|
2020-02-04 20:19:40 +00:00
|
|
|
#include "shell/browser/api/electron_api_web_contents_view.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/native_window_views.h"
|
|
|
|
#include "shell/browser/web_contents_preferences.h"
|
2016-05-18 04:47:50 +00:00
|
|
|
#include "ui/events/keycodes/keyboard_codes.h"
|
|
|
|
|
2020-09-21 00:11:59 +00:00
|
|
|
#if defined(OS_LINUX)
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/browser.h"
|
2016-05-18 04:47:50 +00:00
|
|
|
#endif
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
namespace electron {
|
2016-05-18 04:47:50 +00:00
|
|
|
|
2019-01-09 20:01:49 +00:00
|
|
|
bool CommonWebContentsDelegate::HandleKeyboardEvent(
|
2016-05-18 04:47:50 +00:00
|
|
|
content::WebContents* source,
|
|
|
|
const content::NativeWebKeyboardEvent& event) {
|
|
|
|
// Escape exits tabbed fullscreen mode.
|
2019-01-10 16:03:48 +00:00
|
|
|
if (event.windows_key_code == ui::VKEY_ESCAPE && is_html_fullscreen()) {
|
2016-05-18 04:47:50 +00:00
|
|
|
ExitFullscreenModeForTab(source);
|
2019-01-09 20:01:49 +00:00
|
|
|
return true;
|
2019-01-10 16:03:48 +00:00
|
|
|
}
|
2016-05-18 04:47:50 +00:00
|
|
|
|
2018-09-27 15:41:09 +00:00
|
|
|
// Check if the webContents has preferences and to ignore shortcuts
|
|
|
|
auto* web_preferences = WebContentsPreferences::From(source);
|
|
|
|
if (web_preferences &&
|
|
|
|
web_preferences->IsEnabled("ignoreMenuShortcuts", false))
|
2019-01-09 20:01:49 +00:00
|
|
|
return false;
|
2018-09-27 15:41:09 +00:00
|
|
|
|
2016-05-18 04:47:50 +00:00
|
|
|
// Let the NativeWindow handle other parts.
|
2018-09-27 15:41:09 +00:00
|
|
|
if (owner_window()) {
|
|
|
|
owner_window()->HandleKeyboardEvent(source, event);
|
2019-01-09 20:01:49 +00:00
|
|
|
return true;
|
2018-09-10 10:06:16 +00:00
|
|
|
}
|
2019-01-09 20:01:49 +00:00
|
|
|
|
|
|
|
return false;
|
2016-05-18 04:47:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gfx::ImageSkia CommonWebContentsDelegate::GetDevToolsWindowIcon() {
|
|
|
|
if (!owner_window())
|
|
|
|
return gfx::ImageSkia();
|
2018-04-18 01:55:30 +00:00
|
|
|
return static_cast<views::WidgetDelegate*>(
|
|
|
|
static_cast<NativeWindowViews*>(owner_window()))
|
|
|
|
->GetWindowAppIcon();
|
2016-05-18 04:47:50 +00:00
|
|
|
}
|
|
|
|
|
2020-09-21 00:11:59 +00:00
|
|
|
#if defined(OS_LINUX)
|
2016-05-18 04:47:50 +00:00
|
|
|
void CommonWebContentsDelegate::GetDevToolsWindowWMClass(
|
2018-04-18 01:55:30 +00:00
|
|
|
std::string* name,
|
|
|
|
std::string* class_name) {
|
2016-05-18 04:47:50 +00:00
|
|
|
*class_name = Browser::Get()->GetName();
|
|
|
|
*name = base::ToLowerASCII(*class_name);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
} // namespace electron
|