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.
|
|
|
|
|
|
|
|
#include "atom/browser/common_web_contents_delegate.h"
|
|
|
|
|
2018-06-18 15:15:37 +00:00
|
|
|
#include "atom/browser/api/atom_api_web_contents_view.h"
|
2016-05-18 04:47:50 +00:00
|
|
|
#include "atom/browser/native_window_views.h"
|
2018-09-10 10:06:16 +00:00
|
|
|
#include "atom/browser/web_contents_preferences.h"
|
2016-05-18 04:47:50 +00:00
|
|
|
#include "base/strings/string_util.h"
|
|
|
|
#include "content/public/browser/native_web_keyboard_event.h"
|
|
|
|
#include "ui/events/keycodes/keyboard_codes.h"
|
|
|
|
|
|
|
|
#if defined(USE_X11)
|
|
|
|
#include "atom/browser/browser.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace atom {
|
|
|
|
|
|
|
|
void CommonWebContentsDelegate::HandleKeyboardEvent(
|
|
|
|
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-10 16:03:48 +00:00
|
|
|
return;
|
|
|
|
}
|
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))
|
|
|
|
return;
|
|
|
|
|
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);
|
2018-09-10 10:06:16 +00:00
|
|
|
}
|
2016-05-18 04:47:50 +00:00
|
|
|
}
|
|
|
|
|
2018-04-05 00:53:51 +00:00
|
|
|
void CommonWebContentsDelegate::ShowAutofillPopup(
|
|
|
|
content::RenderFrameHost* frame_host,
|
2018-06-18 15:15:37 +00:00
|
|
|
content::RenderFrameHost* embedder_frame_host,
|
|
|
|
bool offscreen,
|
2018-04-05 00:53:51 +00:00
|
|
|
const gfx::RectF& bounds,
|
|
|
|
const std::vector<base::string16>& values,
|
|
|
|
const std::vector<base::string16>& labels) {
|
|
|
|
if (!owner_window())
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto* window = static_cast<NativeWindowViews*>(owner_window());
|
2018-06-18 15:15:37 +00:00
|
|
|
autofill_popup_->CreateView(frame_host, embedder_frame_host, offscreen,
|
|
|
|
window->content_view(), bounds);
|
2018-04-05 00:53:51 +00:00
|
|
|
autofill_popup_->SetItems(values, labels);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommonWebContentsDelegate::HideAutofillPopup() {
|
|
|
|
if (autofill_popup_)
|
|
|
|
autofill_popup_->Hide();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(USE_X11)
|
|
|
|
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
|
|
|
|
|
|
|
|
} // namespace atom
|