2014-07-03 08:44:58 +00:00
|
|
|
// Copyright (c) 2014 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE-CHROMIUM file.
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
#include "shell/browser/ui/views/electron_views_delegate.h"
|
2014-07-03 08:44:58 +00:00
|
|
|
|
2018-09-13 00:25:56 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2014-07-03 08:44:58 +00:00
|
|
|
#include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
|
2015-10-04 14:15:01 +00:00
|
|
|
#include "ui/views/widget/native_widget_aura.h"
|
2014-07-03 08:44:58 +00:00
|
|
|
|
2014-07-12 03:45:24 +00:00
|
|
|
#if defined(OS_LINUX)
|
2017-12-20 22:02:49 +00:00
|
|
|
#include "base/environment.h"
|
|
|
|
#include "base/nix/xdg_util.h"
|
2014-07-12 03:45:24 +00:00
|
|
|
#include "ui/views/linux_ui/linux_ui.h"
|
|
|
|
#endif
|
|
|
|
|
2017-12-20 22:02:49 +00:00
|
|
|
namespace {
|
|
|
|
|
2018-01-10 07:49:21 +00:00
|
|
|
#if defined(OS_LINUX)
|
2018-05-10 20:59:48 +00:00
|
|
|
bool IsDesktopEnvironmentUnity() {
|
2021-06-04 00:23:06 +00:00
|
|
|
auto env = base::Environment::Create();
|
2017-12-20 22:02:49 +00:00
|
|
|
base::nix::DesktopEnvironment desktop_env =
|
|
|
|
base::nix::GetDesktopEnvironment(env.get());
|
|
|
|
return desktop_env == base::nix::DESKTOP_ENVIRONMENT_UNITY;
|
|
|
|
}
|
2018-05-10 20:59:48 +00:00
|
|
|
#endif
|
2017-12-20 22:02:49 +00:00
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
namespace electron {
|
2014-07-03 08:44:58 +00:00
|
|
|
|
2019-09-16 22:12:00 +00:00
|
|
|
ViewsDelegate::ViewsDelegate() = default;
|
2014-07-03 08:44:58 +00:00
|
|
|
|
2019-09-16 22:12:00 +00:00
|
|
|
ViewsDelegate::~ViewsDelegate() = default;
|
2014-07-03 08:44:58 +00:00
|
|
|
|
|
|
|
void ViewsDelegate::SaveWindowPlacement(const views::Widget* window,
|
|
|
|
const std::string& window_name,
|
|
|
|
const gfx::Rect& bounds,
|
2018-04-18 01:56:12 +00:00
|
|
|
ui::WindowShowState show_state) {}
|
2014-07-03 08:44:58 +00:00
|
|
|
|
|
|
|
bool ViewsDelegate::GetSavedWindowPlacement(
|
|
|
|
const views::Widget* widget,
|
|
|
|
const std::string& window_name,
|
|
|
|
gfx::Rect* bounds,
|
|
|
|
ui::WindowShowState* show_state) const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-03-16 16:18:45 +00:00
|
|
|
void ViewsDelegate::NotifyMenuItemFocused(const std::u16string& menu_name,
|
|
|
|
const std::u16string& menu_item_name,
|
2018-04-18 01:56:12 +00:00
|
|
|
int item_index,
|
|
|
|
int item_count,
|
|
|
|
bool has_submenu) {}
|
2014-07-03 08:44:58 +00:00
|
|
|
|
2019-11-19 14:07:10 +00:00
|
|
|
#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
|
2014-07-03 08:44:58 +00:00
|
|
|
gfx::ImageSkia* ViewsDelegate::GetDefaultWindowIcon() const {
|
2019-09-16 22:12:00 +00:00
|
|
|
return nullptr;
|
2014-07-03 08:44:58 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-07-14 01:13:34 +00:00
|
|
|
std::unique_ptr<views::NonClientFrameView>
|
|
|
|
ViewsDelegate::CreateDefaultNonClientFrameView(views::Widget* widget) {
|
2019-09-16 22:12:00 +00:00
|
|
|
return nullptr;
|
2014-07-03 08:44:58 +00:00
|
|
|
}
|
|
|
|
|
2018-04-18 01:56:12 +00:00
|
|
|
void ViewsDelegate::AddRef() {}
|
2014-07-03 08:44:58 +00:00
|
|
|
|
2018-04-18 01:56:12 +00:00
|
|
|
void ViewsDelegate::ReleaseRef() {}
|
2014-07-03 08:44:58 +00:00
|
|
|
|
|
|
|
void ViewsDelegate::OnBeforeWidgetInit(
|
|
|
|
views::Widget::InitParams* params,
|
|
|
|
views::internal::NativeWidgetDelegate* delegate) {
|
|
|
|
// If we already have a native_widget, we don't have to try to come
|
|
|
|
// up with one.
|
|
|
|
if (params->native_widget)
|
|
|
|
return;
|
|
|
|
|
2018-04-18 01:56:12 +00:00
|
|
|
if (params->parent && params->type != views::Widget::InitParams::TYPE_MENU &&
|
2015-10-04 14:15:01 +00:00
|
|
|
params->type != views::Widget::InitParams::TYPE_TOOLTIP) {
|
|
|
|
params->native_widget = new views::NativeWidgetAura(delegate);
|
|
|
|
} else {
|
2014-07-03 08:44:58 +00:00
|
|
|
params->native_widget = new views::DesktopNativeWidgetAura(delegate);
|
2015-10-04 14:15:01 +00:00
|
|
|
}
|
2014-07-03 08:44:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ViewsDelegate::WindowManagerProvidesTitleBar(bool maximized) {
|
2014-07-12 03:45:24 +00:00
|
|
|
#if defined(OS_LINUX)
|
|
|
|
// On Ubuntu Unity, the system always provides a title bar for maximized
|
|
|
|
// windows.
|
2017-12-20 22:02:49 +00:00
|
|
|
if (!maximized)
|
|
|
|
return false;
|
|
|
|
static bool is_desktop_environment_unity = IsDesktopEnvironmentUnity();
|
|
|
|
return is_desktop_environment_unity;
|
2014-07-12 03:45:24 +00:00
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
2014-07-03 08:44:58 +00:00
|
|
|
}
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
} // namespace electron
|