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.
|
|
|
|
|
2018-10-19 13:50:30 +00:00
|
|
|
#include "atom/browser/ui/views/atom_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() {
|
2017-12-20 22:02:49 +00:00
|
|
|
std::unique_ptr<base::Environment> env(base::Environment::Create());
|
|
|
|
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
|
|
|
|
|
2018-10-19 13:50:30 +00:00
|
|
|
namespace atom {
|
2014-07-03 08:44:58 +00:00
|
|
|
|
2018-04-18 01:56:12 +00:00
|
|
|
ViewsDelegate::ViewsDelegate() {}
|
2014-07-03 08:44:58 +00:00
|
|
|
|
2018-04-18 01:56:12 +00:00
|
|
|
ViewsDelegate::~ViewsDelegate() {}
|
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;
|
|
|
|
}
|
|
|
|
|
2018-04-18 01:56:12 +00:00
|
|
|
void ViewsDelegate::NotifyAccessibilityEvent(views::View* view,
|
2018-04-11 15:15:22 +00:00
|
|
|
ax::mojom::Event event_type) {}
|
2014-07-03 08:44:58 +00:00
|
|
|
|
2018-04-18 01:56:12 +00:00
|
|
|
void ViewsDelegate::NotifyMenuItemFocused(const base::string16& menu_name,
|
|
|
|
const base::string16& menu_item_name,
|
|
|
|
int item_index,
|
|
|
|
int item_count,
|
|
|
|
bool has_submenu) {}
|
2014-07-03 08:44:58 +00:00
|
|
|
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
HICON ViewsDelegate::GetDefaultWindowIcon() const {
|
2015-01-15 23:30:04 +00:00
|
|
|
// Use current exe's icon as default window icon.
|
2017-03-23 22:47:30 +00:00
|
|
|
return LoadIcon(GetModuleHandle(NULL),
|
2018-04-18 01:56:12 +00:00
|
|
|
MAKEINTRESOURCE(1 /* IDR_MAINFRAME */));
|
2014-07-03 08:44:58 +00:00
|
|
|
}
|
|
|
|
|
2015-03-18 04:55:02 +00:00
|
|
|
HICON ViewsDelegate::GetSmallWindowIcon() const {
|
|
|
|
return GetDefaultWindowIcon();
|
|
|
|
}
|
|
|
|
|
2014-07-03 08:44:58 +00:00
|
|
|
bool ViewsDelegate::IsWindowInMetro(gfx::NativeWindow window) const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
#elif defined(OS_LINUX) && !defined(OS_CHROMEOS)
|
|
|
|
gfx::ImageSkia* ViewsDelegate::GetDefaultWindowIcon() const {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
views::NonClientFrameView* ViewsDelegate::CreateDefaultNonClientFrameView(
|
|
|
|
views::Widget* widget) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-10-19 13:50:30 +00:00
|
|
|
} // namespace atom
|