2014-10-31 18:17:05 +00:00
|
|
|
// Copyright (c) 2014 GitHub, Inc.
|
2014-07-03 17:30:36 +00:00
|
|
|
// 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/native_window_views.h"
|
2014-07-03 17:30:36 +00:00
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2018-04-18 17:20:15 +00:00
|
|
|
#include <wrl/client.h>
|
2017-09-12 15:56:49 +00:00
|
|
|
#endif
|
2018-05-01 04:28:22 +00:00
|
|
|
|
2018-09-13 00:25:56 +00:00
|
|
|
#include <memory>
|
|
|
|
#include <utility>
|
2014-07-03 17:30:36 +00:00
|
|
|
#include <vector>
|
2015-02-11 01:14:26 +00:00
|
|
|
|
2021-08-11 21:04:56 +00:00
|
|
|
#include "base/cxx17_backports.h"
|
2019-07-10 14:40:11 +00:00
|
|
|
#include "base/stl_util.h"
|
2014-07-03 17:30:36 +00:00
|
|
|
#include "base/strings/utf_string_conversions.h"
|
2016-04-13 02:02:34 +00:00
|
|
|
#include "content/public/browser/browser_thread.h"
|
2019-08-15 06:51:15 +00:00
|
|
|
#include "content/public/browser/desktop_media_id.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/api/electron_api_web_contents.h"
|
|
|
|
#include "shell/browser/native_browser_view_views.h"
|
2020-10-27 21:28:43 +00:00
|
|
|
#include "shell/browser/ui/drag_util.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/ui/inspectable_web_contents.h"
|
|
|
|
#include "shell/browser/ui/inspectable_web_contents_view.h"
|
|
|
|
#include "shell/browser/ui/views/root_view.h"
|
|
|
|
#include "shell/browser/web_contents_preferences.h"
|
|
|
|
#include "shell/browser/web_view_manager.h"
|
|
|
|
#include "shell/browser/window_list.h"
|
|
|
|
#include "shell/common/electron_constants.h"
|
2019-10-25 13:03:28 +00:00
|
|
|
#include "shell/common/gin_converters/image_converter.h"
|
|
|
|
#include "shell/common/gin_helper/dictionary.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/common/options_switches.h"
|
2014-07-21 14:03:58 +00:00
|
|
|
#include "ui/aura/window_tree_host.h"
|
2014-07-07 14:39:39 +00:00
|
|
|
#include "ui/base/hit_test.h"
|
2015-02-07 01:00:26 +00:00
|
|
|
#include "ui/gfx/image/image.h"
|
2019-01-31 02:19:47 +00:00
|
|
|
#include "ui/gfx/native_widget_types.h"
|
2014-07-03 17:30:36 +00:00
|
|
|
#include "ui/views/background.h"
|
2014-07-07 15:02:46 +00:00
|
|
|
#include "ui/views/controls/webview/unhandled_keyboard_event_handler.h"
|
2014-07-03 17:30:36 +00:00
|
|
|
#include "ui/views/controls/webview/webview.h"
|
2014-12-16 01:28:51 +00:00
|
|
|
#include "ui/views/widget/native_widget_private.h"
|
2014-07-03 17:30:36 +00:00
|
|
|
#include "ui/views/widget/widget.h"
|
2016-08-26 22:30:02 +00:00
|
|
|
#include "ui/views/window/client_view.h"
|
2014-12-24 00:55:57 +00:00
|
|
|
#include "ui/wm/core/shadow_types.h"
|
2016-08-26 22:30:02 +00:00
|
|
|
#include "ui/wm/core/window_util.h"
|
2014-07-03 17:30:36 +00:00
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_LINUX)
|
2014-11-24 07:27:36 +00:00
|
|
|
#include "base/strings/string_util.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/browser.h"
|
2019-10-28 22:12:35 +00:00
|
|
|
#include "shell/browser/linux/unity_service.h"
|
2022-01-26 21:59:09 +00:00
|
|
|
#include "shell/browser/ui/electron_desktop_window_tree_host_linux.h"
|
|
|
|
#include "shell/browser/ui/views/client_frame_view_linux.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/ui/views/frameless_view.h"
|
|
|
|
#include "shell/browser/ui/views/native_frame_view.h"
|
2022-01-26 21:59:09 +00:00
|
|
|
#include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
|
2020-10-20 18:24:52 +00:00
|
|
|
#include "ui/views/window/native_frame_view.h"
|
|
|
|
|
2022-03-28 16:48:50 +00:00
|
|
|
#if defined(USE_OZONE)
|
2020-10-20 18:24:52 +00:00
|
|
|
#include "shell/browser/ui/views/global_menu_bar_x11.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/ui/x/event_disabler.h"
|
|
|
|
#include "shell/browser/ui/x/x_window_utils.h"
|
2014-08-26 04:15:22 +00:00
|
|
|
#include "ui/base/x/x11_util.h"
|
2020-07-15 03:07:42 +00:00
|
|
|
#include "ui/gfx/x/shape.h"
|
2020-05-26 20:06:26 +00:00
|
|
|
#include "ui/gfx/x/x11_atom_cache.h"
|
2020-11-14 00:16:56 +00:00
|
|
|
#include "ui/gfx/x/xproto.h"
|
2020-12-22 22:14:44 +00:00
|
|
|
#include "ui/gfx/x/xproto_util.h"
|
2022-03-28 16:48:50 +00:00
|
|
|
#include "ui/ozone/public/ozone_platform.h"
|
2020-10-20 18:24:52 +00:00
|
|
|
#endif
|
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#elif BUILDFLAG(IS_WIN)
|
2020-09-22 05:40:42 +00:00
|
|
|
#include "base/win/win_util.h"
|
2021-11-24 08:45:59 +00:00
|
|
|
#include "content/public/common/color_parser.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/ui/views/win_frame_view.h"
|
|
|
|
#include "shell/browser/ui/win/electron_desktop_native_widget_aura.h"
|
2015-10-23 03:17:14 +00:00
|
|
|
#include "skia/ext/skia_utils_win.h"
|
2014-08-05 10:17:14 +00:00
|
|
|
#include "ui/base/win/shell.h"
|
2016-07-21 17:20:43 +00:00
|
|
|
#include "ui/display/screen.h"
|
2016-08-26 22:30:02 +00:00
|
|
|
#include "ui/display/win/screen_win.h"
|
2021-08-11 18:07:36 +00:00
|
|
|
#include "ui/gfx/color_utils.h"
|
2014-07-07 07:35:16 +00:00
|
|
|
#endif
|
|
|
|
|
2014-07-03 17:30:36 +00:00
|
|
|
namespace electron {
|
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2019-01-31 02:19:47 +00:00
|
|
|
|
|
|
|
// Similar to the ones in display::win::ScreenWin, but with rounded values
|
|
|
|
// These help to avoid problems that arise from unresizable windows where the
|
|
|
|
// original ceil()-ed values can cause calculation errors, since converting
|
|
|
|
// both ways goes through a ceil() call. Related issue: #15816
|
|
|
|
gfx::Rect ScreenToDIPRect(HWND hwnd, const gfx::Rect& pixel_bounds) {
|
|
|
|
float scale_factor = display::win::ScreenWin::GetScaleFactorForHWND(hwnd);
|
|
|
|
gfx::Rect dip_rect = ScaleToRoundedRect(pixel_bounds, 1.0f / scale_factor);
|
|
|
|
dip_rect.set_origin(
|
|
|
|
display::win::ScreenWin::ScreenToDIPRect(hwnd, pixel_bounds).origin());
|
|
|
|
return dip_rect;
|
|
|
|
}
|
|
|
|
|
2021-05-19 01:34:40 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2021-05-19 01:34:40 +00:00
|
|
|
const LPCWSTR kUniqueTaskBarClassName = L"Shell_TrayWnd";
|
|
|
|
|
|
|
|
void FlipWindowStyle(HWND handle, bool on, DWORD flag) {
|
|
|
|
DWORD style = ::GetWindowLong(handle, GWL_STYLE);
|
|
|
|
if (on)
|
|
|
|
style |= flag;
|
|
|
|
else
|
|
|
|
style &= ~flag;
|
|
|
|
::SetWindowLong(handle, GWL_STYLE, style);
|
2021-09-23 07:33:41 +00:00
|
|
|
// Window's frame styles are cached so we need to call SetWindowPos
|
|
|
|
// with the SWP_FRAMECHANGED flag to update cache properly.
|
|
|
|
::SetWindowPos(handle, 0, 0, 0, 0, 0, // ignored
|
|
|
|
SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER |
|
|
|
|
SWP_NOACTIVATE | SWP_NOOWNERZORDER);
|
2021-05-19 01:34:40 +00:00
|
|
|
}
|
|
|
|
|
2019-01-31 02:19:47 +00:00
|
|
|
gfx::Rect DIPToScreenRect(HWND hwnd, const gfx::Rect& pixel_bounds) {
|
|
|
|
float scale_factor = display::win::ScreenWin::GetScaleFactorForHWND(hwnd);
|
|
|
|
gfx::Rect screen_rect = ScaleToRoundedRect(pixel_bounds, scale_factor);
|
|
|
|
screen_rect.set_origin(
|
|
|
|
display::win::ScreenWin::DIPToScreenRect(hwnd, pixel_bounds).origin());
|
|
|
|
return screen_rect;
|
|
|
|
}
|
|
|
|
|
2016-01-23 10:23:18 +00:00
|
|
|
#endif
|
|
|
|
|
2022-03-28 16:48:50 +00:00
|
|
|
#if defined(USE_OZONE)
|
|
|
|
|
|
|
|
bool CreateGlobalMenuBar() {
|
|
|
|
return ui::OzonePlatform::GetInstance()
|
|
|
|
->GetPlatformProperties()
|
|
|
|
.supports_global_application_menus;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(USE_OZONE_PLATFORM_X11)
|
|
|
|
|
|
|
|
bool IsX11() {
|
|
|
|
return ui::OzonePlatform::GetInstance()
|
|
|
|
->GetPlatformProperties()
|
|
|
|
.electron_can_call_x11;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2014-07-03 17:30:36 +00:00
|
|
|
class NativeWindowClientView : public views::ClientView {
|
|
|
|
public:
|
|
|
|
NativeWindowClientView(views::Widget* widget,
|
2018-05-01 04:28:22 +00:00
|
|
|
views::View* root_view,
|
|
|
|
NativeWindowViews* window)
|
|
|
|
: views::ClientView(widget, root_view), window_(window) {}
|
2018-05-16 19:12:45 +00:00
|
|
|
~NativeWindowClientView() override = default;
|
2014-07-03 17:30:36 +00:00
|
|
|
|
2021-11-03 11:41:45 +00:00
|
|
|
// disable copy
|
|
|
|
NativeWindowClientView(const NativeWindowClientView&) = delete;
|
|
|
|
NativeWindowClientView& operator=(const NativeWindowClientView&) = delete;
|
|
|
|
|
2020-08-12 18:33:58 +00:00
|
|
|
views::CloseRequestResult OnWindowCloseRequested() override {
|
2018-05-01 04:28:22 +00:00
|
|
|
window_->NotifyWindowCloseButtonClicked();
|
2020-08-12 18:33:58 +00:00
|
|
|
return views::CloseRequestResult::kCannotClose;
|
2014-07-03 17:30:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2018-05-01 04:28:22 +00:00
|
|
|
NativeWindowViews* window_;
|
2014-07-03 17:30:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2019-10-25 13:03:28 +00:00
|
|
|
NativeWindowViews::NativeWindowViews(const gin_helper::Dictionary& options,
|
2018-04-08 11:20:43 +00:00
|
|
|
NativeWindow* parent)
|
2018-04-10 06:23:16 +00:00
|
|
|
: NativeWindow(options, parent),
|
2021-06-08 02:00:05 +00:00
|
|
|
root_view_(std::make_unique<RootView>(this)),
|
|
|
|
keyboard_event_handler_(
|
|
|
|
std::make_unique<views::UnhandledKeyboardEventHandler>()) {
|
2015-11-13 05:58:31 +00:00
|
|
|
options.Get(options::kTitle, &title_);
|
2018-05-01 04:28:22 +00:00
|
|
|
|
|
|
|
bool menu_bar_autohide;
|
|
|
|
if (options.Get(options::kAutoHideMenuBar, &menu_bar_autohide))
|
|
|
|
root_view_->SetAutoHideMenuBar(menu_bar_autohide);
|
2014-07-03 17:30:36 +00:00
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2014-08-26 05:37:37 +00:00
|
|
|
// On Windows we rely on the CanResize() to indicate whether window can be
|
|
|
|
// resized, and it should be set before window is created.
|
2015-11-13 05:58:31 +00:00
|
|
|
options.Get(options::kResizable, &resizable_);
|
2016-01-18 22:46:35 +00:00
|
|
|
options.Get(options::kMinimizable, &minimizable_);
|
2016-01-22 21:24:33 +00:00
|
|
|
options.Get(options::kMaximizable, &maximizable_);
|
2016-07-09 12:49:15 +00:00
|
|
|
|
|
|
|
// Transparent window must not have thick frame.
|
|
|
|
options.Get("thickFrame", &thick_frame_);
|
|
|
|
if (transparent())
|
|
|
|
thick_frame_ = false;
|
2021-08-11 18:07:36 +00:00
|
|
|
|
|
|
|
overlay_button_color_ = color_utils::GetSysSkColor(COLOR_BTNFACE);
|
|
|
|
overlay_symbol_color_ = color_utils::GetSysSkColor(COLOR_BTNTEXT);
|
|
|
|
|
|
|
|
v8::Local<v8::Value> titlebar_overlay;
|
|
|
|
if (options.Get(options::ktitleBarOverlay, &titlebar_overlay) &&
|
|
|
|
titlebar_overlay->IsObject()) {
|
|
|
|
gin_helper::Dictionary titlebar_overlay_obj =
|
2022-01-24 22:09:21 +00:00
|
|
|
gin::Dictionary::CreateEmpty(options.isolate());
|
2021-08-11 18:07:36 +00:00
|
|
|
options.Get(options::ktitleBarOverlay, &titlebar_overlay_obj);
|
|
|
|
|
|
|
|
std::string overlay_color_string;
|
|
|
|
if (titlebar_overlay_obj.Get(options::kOverlayButtonColor,
|
|
|
|
&overlay_color_string)) {
|
2021-11-24 08:45:59 +00:00
|
|
|
bool success = content::ParseCssColorString(overlay_color_string,
|
|
|
|
&overlay_button_color_);
|
2021-08-11 18:07:36 +00:00
|
|
|
DCHECK(success);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string overlay_symbol_color_string;
|
|
|
|
if (titlebar_overlay_obj.Get(options::kOverlaySymbolColor,
|
|
|
|
&overlay_symbol_color_string)) {
|
2021-11-24 08:45:59 +00:00
|
|
|
bool success = content::ParseCssColorString(overlay_symbol_color_string,
|
|
|
|
&overlay_symbol_color_);
|
2021-08-11 18:07:36 +00:00
|
|
|
DCHECK(success);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (title_bar_style_ != TitleBarStyle::kNormal)
|
|
|
|
set_has_frame(false);
|
2014-08-26 05:37:37 +00:00
|
|
|
#endif
|
|
|
|
|
2015-08-05 04:46:32 +00:00
|
|
|
if (enable_larger_than_screen())
|
2014-08-17 04:23:00 +00:00
|
|
|
// We need to set a default maximum window size here otherwise Windows
|
|
|
|
// will not allow us to resize the window larger than scree.
|
2020-10-13 17:25:21 +00:00
|
|
|
// Setting directly to INT_MAX somehow doesn't work, so we just divide
|
2014-08-17 04:23:00 +00:00
|
|
|
// by 10, which should still be large enough.
|
2015-10-05 11:05:59 +00:00
|
|
|
SetContentSizeConstraints(extensions::SizeConstraints(
|
|
|
|
gfx::Size(), gfx::Size(INT_MAX / 10, INT_MAX / 10)));
|
2014-08-17 04:23:00 +00:00
|
|
|
|
2014-07-12 03:36:08 +00:00
|
|
|
int width = 800, height = 600;
|
2015-11-13 05:58:31 +00:00
|
|
|
options.Get(options::kWidth, &width);
|
|
|
|
options.Get(options::kHeight, &height);
|
2014-07-12 03:36:08 +00:00
|
|
|
gfx::Rect bounds(0, 0, width, height);
|
2015-05-20 08:37:13 +00:00
|
|
|
widget_size_ = bounds.size();
|
2014-07-12 03:36:08 +00:00
|
|
|
|
2018-04-25 06:59:16 +00:00
|
|
|
widget()->AddObserver(this);
|
2014-07-08 04:55:33 +00:00
|
|
|
|
2014-07-03 17:30:36 +00:00
|
|
|
views::Widget::InitParams params;
|
2014-07-04 09:24:49 +00:00
|
|
|
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
|
2014-07-12 03:36:08 +00:00
|
|
|
params.bounds = bounds;
|
2014-07-03 17:30:36 +00:00
|
|
|
params.delegate = this;
|
2017-04-05 09:02:06 +00:00
|
|
|
params.type = views::Widget::InitParams::TYPE_WINDOW;
|
2022-01-26 21:59:09 +00:00
|
|
|
params.remove_standard_frame = !has_frame() || has_client_frame();
|
2014-07-07 09:22:22 +00:00
|
|
|
|
2022-01-26 21:59:09 +00:00
|
|
|
// If a client frame, we need to draw our own shadows.
|
|
|
|
if (transparent() || has_client_frame())
|
2019-12-11 00:22:35 +00:00
|
|
|
params.opacity = views::Widget::InitParams::WindowOpacity::kTranslucent;
|
2014-12-24 00:55:57 +00:00
|
|
|
|
2016-01-23 10:55:12 +00:00
|
|
|
// The given window is most likely not rectangular since it uses
|
|
|
|
// transparency and has no standard frame, don't show a shadow for it.
|
|
|
|
if (transparent() && !has_frame())
|
2019-10-28 22:12:35 +00:00
|
|
|
params.shadow_type = views::Widget::InitParams::ShadowType::kNone;
|
2016-01-23 10:55:12 +00:00
|
|
|
|
2017-02-14 20:52:19 +00:00
|
|
|
bool focusable;
|
|
|
|
if (options.Get(options::kFocusable, &focusable) && !focusable)
|
2021-04-27 21:27:34 +00:00
|
|
|
params.activatable = views::Widget::InitParams::Activatable::kNo;
|
2016-06-13 08:24:45 +00:00
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2016-06-19 03:18:48 +00:00
|
|
|
if (parent)
|
|
|
|
params.parent = parent->GetNativeWindow();
|
|
|
|
|
2019-05-28 20:18:10 +00:00
|
|
|
params.native_widget = new ElectronDesktopNativeWidgetAura(this);
|
2022-02-10 02:58:52 +00:00
|
|
|
#elif BUILDFLAG(IS_LINUX)
|
2014-11-24 07:27:36 +00:00
|
|
|
std::string name = Browser::Get()->GetName();
|
2014-08-26 02:34:48 +00:00
|
|
|
// Set WM_WINDOW_ROLE.
|
2014-11-24 07:27:36 +00:00
|
|
|
params.wm_role_name = "browser-window";
|
2014-08-26 02:34:48 +00:00
|
|
|
// Set WM_CLASS.
|
2015-12-07 11:56:23 +00:00
|
|
|
params.wm_class_name = base::ToLowerASCII(name);
|
2014-11-24 07:27:36 +00:00
|
|
|
params.wm_class_class = name;
|
2022-01-26 21:59:09 +00:00
|
|
|
|
2022-03-28 16:48:50 +00:00
|
|
|
auto* native_widget = new views::DesktopNativeWidgetAura(widget());
|
|
|
|
params.native_widget = native_widget;
|
|
|
|
params.desktop_window_tree_host =
|
|
|
|
new ElectronDesktopWindowTreeHostLinux(this, native_widget);
|
2014-07-21 14:03:58 +00:00
|
|
|
#endif
|
2014-07-07 09:22:22 +00:00
|
|
|
|
2019-08-15 20:50:58 +00:00
|
|
|
widget()->Init(std::move(params));
|
2021-06-03 08:05:04 +00:00
|
|
|
SetCanResize(resizable_);
|
2014-07-03 17:30:36 +00:00
|
|
|
|
2015-09-28 23:20:09 +00:00
|
|
|
bool fullscreen = false;
|
2015-11-13 05:58:31 +00:00
|
|
|
options.Get(options::kFullscreen, &fullscreen);
|
2015-09-28 23:20:09 +00:00
|
|
|
|
2016-07-11 03:46:50 +00:00
|
|
|
std::string window_type;
|
|
|
|
options.Get(options::kType, &window_type);
|
|
|
|
|
2022-03-28 16:48:50 +00:00
|
|
|
#if BUILDFLAG(IS_LINUX)
|
2021-10-06 02:21:00 +00:00
|
|
|
// Set _GTK_THEME_VARIANT to dark if we have "dark-theme" option set.
|
|
|
|
bool use_dark_theme = false;
|
|
|
|
if (options.Get(options::kDarkTheme, &use_dark_theme) && use_dark_theme) {
|
|
|
|
SetGTKDarkThemeEnabled(use_dark_theme);
|
2020-08-20 20:53:06 +00:00
|
|
|
}
|
2014-08-26 04:15:22 +00:00
|
|
|
|
2020-10-20 18:24:52 +00:00
|
|
|
if (parent)
|
|
|
|
SetParentWindow(parent);
|
|
|
|
#endif
|
2015-02-11 04:12:22 +00:00
|
|
|
|
2022-03-28 16:48:50 +00:00
|
|
|
#if defined(USE_OZONE_PLATFORM_X11)
|
|
|
|
if (IsX11()) {
|
|
|
|
// TODO(ckerr): remove in Electron v20.0.0
|
|
|
|
// Before the window is mapped the SetWMSpecState can not work, so we have
|
|
|
|
// to manually set the _NET_WM_STATE.
|
|
|
|
std::vector<x11::Atom> state_atom_list;
|
|
|
|
bool skip_taskbar = false;
|
|
|
|
if (options.Get(options::kSkipTaskbar, &skip_taskbar) && skip_taskbar) {
|
|
|
|
state_atom_list.push_back(x11::GetAtom("_NET_WM_STATE_SKIP_TASKBAR"));
|
|
|
|
}
|
2015-06-29 13:53:33 +00:00
|
|
|
|
2022-03-28 16:48:50 +00:00
|
|
|
// Before the window is mapped, there is no SHOW_FULLSCREEN_STATE.
|
|
|
|
if (fullscreen) {
|
|
|
|
state_atom_list.push_back(x11::GetAtom("_NET_WM_STATE_FULLSCREEN"));
|
|
|
|
}
|
2016-06-20 06:44:50 +00:00
|
|
|
|
2022-03-28 16:48:50 +00:00
|
|
|
if (parent) {
|
|
|
|
// Force using dialog type for child window.
|
|
|
|
window_type = "dialog";
|
2015-06-29 13:53:33 +00:00
|
|
|
|
2022-03-28 16:48:50 +00:00
|
|
|
// Modal window needs the _NET_WM_STATE_MODAL hint.
|
|
|
|
if (is_modal())
|
|
|
|
state_atom_list.push_back(x11::GetAtom("_NET_WM_STATE_MODAL"));
|
|
|
|
}
|
2020-10-20 18:24:52 +00:00
|
|
|
|
2022-03-28 16:48:50 +00:00
|
|
|
if (!state_atom_list.empty())
|
|
|
|
SetArrayProperty(static_cast<x11::Window>(GetAcceleratedWidget()),
|
|
|
|
x11::GetAtom("_NET_WM_STATE"), x11::Atom::ATOM,
|
|
|
|
state_atom_list);
|
2020-10-20 18:24:52 +00:00
|
|
|
|
2022-03-28 16:48:50 +00:00
|
|
|
// Set the _NET_WM_WINDOW_TYPE.
|
|
|
|
if (!window_type.empty())
|
|
|
|
SetWindowType(static_cast<x11::Window>(GetAcceleratedWidget()),
|
|
|
|
window_type);
|
|
|
|
}
|
2014-08-21 04:24:55 +00:00
|
|
|
#endif
|
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2016-01-23 10:23:18 +00:00
|
|
|
if (!has_frame()) {
|
|
|
|
// Set Window style so that we get a minimize and maximize animation when
|
|
|
|
// frameless.
|
2019-01-31 02:19:47 +00:00
|
|
|
DWORD frame_style = WS_CAPTION | WS_OVERLAPPED;
|
2022-04-05 00:01:12 +00:00
|
|
|
if (resizable_)
|
2016-01-23 10:23:18 +00:00
|
|
|
frame_style |= WS_THICKFRAME;
|
|
|
|
if (minimizable_)
|
|
|
|
frame_style |= WS_MINIMIZEBOX;
|
|
|
|
if (maximizable_)
|
|
|
|
frame_style |= WS_MAXIMIZEBOX;
|
2022-04-05 00:01:12 +00:00
|
|
|
// We should not show a frame for transparent window.
|
|
|
|
if (!thick_frame_)
|
|
|
|
frame_style &= ~(WS_THICKFRAME | WS_CAPTION);
|
2016-01-23 10:23:18 +00:00
|
|
|
::SetWindowLong(GetAcceleratedWidget(), GWL_STYLE, frame_style);
|
|
|
|
}
|
2014-12-24 00:55:57 +00:00
|
|
|
|
2016-07-11 03:46:50 +00:00
|
|
|
LONG ex_style = ::GetWindowLong(GetAcceleratedWidget(), GWL_EXSTYLE);
|
|
|
|
if (window_type == "toolbar")
|
|
|
|
ex_style |= WS_EX_TOOLWINDOW;
|
|
|
|
::SetWindowLong(GetAcceleratedWidget(), GWL_EXSTYLE, ex_style);
|
2014-11-07 18:34:52 +00:00
|
|
|
#endif
|
2014-07-03 17:30:36 +00:00
|
|
|
|
2022-01-26 21:59:09 +00:00
|
|
|
if (has_frame() && !has_client_frame()) {
|
2017-08-21 08:21:59 +00:00
|
|
|
// TODO(zcbenz): This was used to force using native frame on Windows 2003,
|
|
|
|
// we should check whether setting it in InitParams can work.
|
2019-09-18 19:58:00 +00:00
|
|
|
widget()->set_frame_type(views::Widget::FrameType::kForceNative);
|
2018-04-25 06:59:16 +00:00
|
|
|
widget()->FrameTypeChanged();
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2017-08-21 08:21:59 +00:00
|
|
|
// thickFrame also works for normal window.
|
|
|
|
if (!thick_frame_)
|
|
|
|
FlipWindowStyle(GetAcceleratedWidget(), false, WS_THICKFRAME);
|
2017-08-21 08:42:45 +00:00
|
|
|
#endif
|
2014-11-12 05:45:21 +00:00
|
|
|
}
|
|
|
|
|
2018-05-08 07:02:57 +00:00
|
|
|
// Default content view.
|
|
|
|
SetContentView(new views::View());
|
|
|
|
|
2015-10-05 11:05:59 +00:00
|
|
|
gfx::Size size = bounds.size();
|
|
|
|
if (has_frame() &&
|
2015-11-13 05:58:31 +00:00
|
|
|
options.Get(options::kUseContentSize, &use_content_size_) &&
|
2015-10-05 11:05:59 +00:00
|
|
|
use_content_size_)
|
2016-08-04 17:58:59 +00:00
|
|
|
size = ContentBoundsToWindowBounds(gfx::Rect(size)).size();
|
2015-10-05 11:05:59 +00:00
|
|
|
|
2018-04-25 06:59:16 +00:00
|
|
|
widget()->CenterWindow(size);
|
2016-07-09 14:10:36 +00:00
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2016-07-09 14:10:36 +00:00
|
|
|
// Save initial window state.
|
|
|
|
if (fullscreen)
|
|
|
|
last_window_state_ = ui::SHOW_STATE_FULLSCREEN;
|
|
|
|
else
|
|
|
|
last_window_state_ = ui::SHOW_STATE_NORMAL;
|
|
|
|
#endif
|
2018-12-05 17:35:59 +00:00
|
|
|
|
2021-06-01 08:42:47 +00:00
|
|
|
// Listen to mouse events.
|
2018-12-05 17:35:59 +00:00
|
|
|
aura::Window* window = GetNativeWindow();
|
|
|
|
if (window)
|
|
|
|
window->AddPreTargetHandler(this);
|
2021-04-21 08:58:42 +00:00
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_LINUX)
|
2021-04-21 08:58:42 +00:00
|
|
|
// On linux after the widget is initialized we might have to force set the
|
|
|
|
// bounds if the bounds are smaller than the current display
|
|
|
|
SetBounds(gfx::Rect(GetPosition(), bounds.size()), false);
|
2018-12-05 17:35:59 +00:00
|
|
|
#endif
|
2021-06-22 19:17:16 +00:00
|
|
|
|
|
|
|
SetOwnedByWidget(false);
|
|
|
|
RegisterDeleteDelegateCallback(base::BindOnce(
|
|
|
|
[](NativeWindowViews* window) {
|
|
|
|
if (window->is_modal() && window->parent()) {
|
|
|
|
auto* parent = window->parent();
|
|
|
|
// Enable parent window after current window gets closed.
|
|
|
|
static_cast<NativeWindowViews*>(parent)->DecrementChildModals();
|
|
|
|
// Focus on parent window.
|
|
|
|
parent->Focus(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
window->NotifyWindowClosed();
|
|
|
|
},
|
|
|
|
this));
|
2014-07-03 17:30:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NativeWindowViews::~NativeWindowViews() {
|
2018-04-25 06:59:16 +00:00
|
|
|
widget()->RemoveObserver(this);
|
2017-08-15 23:03:33 +00:00
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2017-08-15 23:03:33 +00:00
|
|
|
// Disable mouse forwarding to relinquish resources, should any be held.
|
|
|
|
SetForwardMouseMessages(false);
|
|
|
|
#endif
|
2018-12-05 17:35:59 +00:00
|
|
|
|
|
|
|
aura::Window* window = GetNativeWindow();
|
|
|
|
if (window)
|
|
|
|
window->RemovePreTargetHandler(this);
|
2014-07-03 17:30:36 +00:00
|
|
|
}
|
|
|
|
|
2020-08-20 20:53:06 +00:00
|
|
|
void NativeWindowViews::SetGTKDarkThemeEnabled(bool use_dark_theme) {
|
2022-03-28 16:48:50 +00:00
|
|
|
#if defined(USE_OZONE_PLATFORM_X11)
|
|
|
|
if (IsX11()) {
|
|
|
|
const std::string color = use_dark_theme ? "dark" : "light";
|
|
|
|
x11::SetStringProperty(static_cast<x11::Window>(GetAcceleratedWidget()),
|
|
|
|
x11::GetAtom("_GTK_THEME_VARIANT"),
|
|
|
|
x11::GetAtom("UTF8_STRING"), color);
|
|
|
|
}
|
2020-08-20 20:53:06 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-05-08 03:51:27 +00:00
|
|
|
void NativeWindowViews::SetContentView(views::View* view) {
|
|
|
|
if (content_view()) {
|
|
|
|
root_view_->RemoveChildView(content_view());
|
2018-04-08 11:20:43 +00:00
|
|
|
}
|
2018-05-08 03:51:27 +00:00
|
|
|
set_content_view(view);
|
|
|
|
focused_view_ = view;
|
|
|
|
root_view_->AddChildView(content_view());
|
2018-05-01 04:28:22 +00:00
|
|
|
root_view_->Layout();
|
2018-04-08 11:20:43 +00:00
|
|
|
}
|
|
|
|
|
2014-07-03 17:30:36 +00:00
|
|
|
void NativeWindowViews::Close() {
|
2016-05-25 23:25:51 +00:00
|
|
|
if (!IsClosable()) {
|
|
|
|
WindowList::WindowCloseCancelled(this);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-25 06:59:16 +00:00
|
|
|
widget()->Close();
|
2014-07-03 17:30:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NativeWindowViews::CloseImmediately() {
|
2018-04-25 06:59:16 +00:00
|
|
|
widget()->CloseNow();
|
2014-07-03 17:30:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NativeWindowViews::Focus(bool focus) {
|
2016-07-05 01:34:52 +00:00
|
|
|
// For hidden window focus() should do nothing.
|
|
|
|
if (!IsVisible())
|
|
|
|
return;
|
|
|
|
|
2016-06-06 07:53:32 +00:00
|
|
|
if (focus) {
|
2018-04-25 06:59:16 +00:00
|
|
|
widget()->Activate();
|
2016-06-06 07:53:32 +00:00
|
|
|
} else {
|
2018-04-25 06:59:16 +00:00
|
|
|
widget()->Deactivate();
|
2016-06-06 07:53:32 +00:00
|
|
|
}
|
2014-07-03 17:30:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool NativeWindowViews::IsFocused() {
|
2018-04-25 06:59:16 +00:00
|
|
|
return widget()->IsActive();
|
2014-07-03 17:30:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NativeWindowViews::Show() {
|
2017-06-29 04:37:54 +00:00
|
|
|
if (is_modal() && NativeWindow::parent() &&
|
2018-04-25 06:59:16 +00:00
|
|
|
!widget()->native_widget_private()->IsVisible())
|
2018-10-18 21:23:40 +00:00
|
|
|
static_cast<NativeWindowViews*>(parent())->IncrementChildModals();
|
2016-06-20 06:44:50 +00:00
|
|
|
|
2018-10-27 03:49:13 +00:00
|
|
|
widget()->native_widget_private()->Show(GetRestoredState(), gfx::Rect());
|
2016-02-23 07:43:32 +00:00
|
|
|
|
2019-04-30 23:43:45 +00:00
|
|
|
// explicitly focus the window
|
|
|
|
widget()->Activate();
|
|
|
|
|
2016-03-08 17:36:41 +00:00
|
|
|
NotifyWindowShow();
|
|
|
|
|
2022-03-28 16:48:50 +00:00
|
|
|
#if defined(USE_OZONE)
|
2021-10-06 02:21:00 +00:00
|
|
|
if (global_menu_bar_)
|
2016-02-23 07:43:32 +00:00
|
|
|
global_menu_bar_->OnWindowMapped();
|
|
|
|
#endif
|
2014-10-17 14:51:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NativeWindowViews::ShowInactive() {
|
2018-04-25 06:59:16 +00:00
|
|
|
widget()->ShowInactive();
|
2016-02-23 07:43:32 +00:00
|
|
|
|
2016-03-08 17:36:41 +00:00
|
|
|
NotifyWindowShow();
|
|
|
|
|
2022-03-28 16:48:50 +00:00
|
|
|
#if defined(USE_OZONE)
|
2021-10-06 02:21:00 +00:00
|
|
|
if (global_menu_bar_)
|
2016-02-23 07:43:32 +00:00
|
|
|
global_menu_bar_->OnWindowMapped();
|
|
|
|
#endif
|
2014-07-03 17:30:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NativeWindowViews::Hide() {
|
2016-06-20 06:44:50 +00:00
|
|
|
if (is_modal() && NativeWindow::parent())
|
2018-10-18 21:23:40 +00:00
|
|
|
static_cast<NativeWindowViews*>(parent())->DecrementChildModals();
|
2016-06-20 06:44:50 +00:00
|
|
|
|
2018-04-25 06:59:16 +00:00
|
|
|
widget()->Hide();
|
2016-02-23 07:43:32 +00:00
|
|
|
|
2016-03-08 17:36:41 +00:00
|
|
|
NotifyWindowHide();
|
|
|
|
|
2022-03-28 16:48:50 +00:00
|
|
|
#if defined(USE_OZONE)
|
2021-10-06 02:21:00 +00:00
|
|
|
if (global_menu_bar_)
|
2016-02-23 07:43:32 +00:00
|
|
|
global_menu_bar_->OnWindowUnmapped();
|
|
|
|
#endif
|
2021-03-25 11:02:47 +00:00
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2021-03-25 11:02:47 +00:00
|
|
|
// When the window is removed from the taskbar via win.hide(),
|
|
|
|
// the thumbnail buttons need to be set up again.
|
|
|
|
// Ensure that when the window is hidden,
|
|
|
|
// the taskbar host is notified that it should re-add them.
|
|
|
|
taskbar_host_.SetThumbarButtonsAdded(false);
|
|
|
|
#endif
|
2014-07-03 17:30:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool NativeWindowViews::IsVisible() {
|
2018-04-25 06:59:16 +00:00
|
|
|
return widget()->IsVisible();
|
2014-07-03 17:30:36 +00:00
|
|
|
}
|
|
|
|
|
2016-06-17 08:38:44 +00:00
|
|
|
bool NativeWindowViews::IsEnabled() {
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2016-06-19 03:18:48 +00:00
|
|
|
return ::IsWindowEnabled(GetAcceleratedWidget());
|
2022-02-10 02:58:52 +00:00
|
|
|
#elif BUILDFLAG(IS_LINUX)
|
2022-03-28 16:48:50 +00:00
|
|
|
#if defined(USE_OZONE_PLATFORM_X11)
|
|
|
|
if (IsX11())
|
|
|
|
return !event_disabler_.get();
|
2020-10-20 18:24:52 +00:00
|
|
|
#endif
|
|
|
|
NOTIMPLEMENTED();
|
|
|
|
return true;
|
2016-06-19 06:47:27 +00:00
|
|
|
#endif
|
2016-06-17 08:38:44 +00:00
|
|
|
}
|
|
|
|
|
2018-10-18 21:23:40 +00:00
|
|
|
void NativeWindowViews::IncrementChildModals() {
|
|
|
|
num_modal_children_++;
|
|
|
|
SetEnabledInternal(ShouldBeEnabled());
|
|
|
|
}
|
|
|
|
|
|
|
|
void NativeWindowViews::DecrementChildModals() {
|
|
|
|
if (num_modal_children_ > 0) {
|
|
|
|
num_modal_children_--;
|
|
|
|
}
|
|
|
|
SetEnabledInternal(ShouldBeEnabled());
|
|
|
|
}
|
|
|
|
|
2018-04-08 11:20:43 +00:00
|
|
|
void NativeWindowViews::SetEnabled(bool enable) {
|
2018-10-18 21:23:40 +00:00
|
|
|
if (enable != is_enabled_) {
|
|
|
|
is_enabled_ = enable;
|
|
|
|
SetEnabledInternal(ShouldBeEnabled());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool NativeWindowViews::ShouldBeEnabled() {
|
|
|
|
return is_enabled_ && (num_modal_children_ == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NativeWindowViews::SetEnabledInternal(bool enable) {
|
|
|
|
if (enable && IsEnabled()) {
|
|
|
|
return;
|
|
|
|
} else if (!enable && !IsEnabled()) {
|
|
|
|
return;
|
2018-04-08 11:20:43 +00:00
|
|
|
}
|
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2018-04-08 11:20:43 +00:00
|
|
|
::EnableWindow(GetAcceleratedWidget(), enable);
|
2022-03-28 16:48:50 +00:00
|
|
|
#elif defined(USE_OZONE_PLATFORM_X11)
|
|
|
|
if (IsX11()) {
|
|
|
|
views::DesktopWindowTreeHostPlatform* tree_host =
|
|
|
|
views::DesktopWindowTreeHostLinux::GetHostForWidget(
|
|
|
|
GetAcceleratedWidget());
|
|
|
|
if (enable) {
|
|
|
|
tree_host->RemoveEventRewriter(event_disabler_.get());
|
|
|
|
event_disabler_.reset();
|
|
|
|
} else {
|
|
|
|
event_disabler_ = std::make_unique<EventDisabler>();
|
|
|
|
tree_host->AddEventRewriter(event_disabler_.get());
|
|
|
|
}
|
2018-04-08 11:20:43 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_LINUX)
|
2014-07-03 17:30:36 +00:00
|
|
|
void NativeWindowViews::Maximize() {
|
2022-03-09 22:30:42 +00:00
|
|
|
if (IsVisible()) {
|
2018-04-25 06:59:16 +00:00
|
|
|
widget()->Maximize();
|
2022-03-09 22:30:42 +00:00
|
|
|
} else {
|
2018-10-27 03:49:13 +00:00
|
|
|
widget()->native_widget_private()->Show(ui::SHOW_STATE_MAXIMIZED,
|
|
|
|
gfx::Rect());
|
2022-03-09 22:30:42 +00:00
|
|
|
NotifyWindowShow();
|
|
|
|
}
|
2014-07-03 17:30:36 +00:00
|
|
|
}
|
2019-05-21 00:50:03 +00:00
|
|
|
#endif
|
2014-07-03 17:30:36 +00:00
|
|
|
|
|
|
|
void NativeWindowViews::Unmaximize() {
|
2022-01-17 07:47:14 +00:00
|
|
|
if (IsMaximized()) {
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2022-01-17 07:47:14 +00:00
|
|
|
if (transparent()) {
|
|
|
|
SetBounds(restore_bounds_, false);
|
2022-01-31 21:10:57 +00:00
|
|
|
NotifyWindowUnmaximize();
|
2022-01-17 07:47:14 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-07-09 14:04:42 +00:00
|
|
|
#endif
|
|
|
|
|
2022-01-17 07:47:14 +00:00
|
|
|
widget()->Restore();
|
|
|
|
}
|
2014-07-03 17:30:36 +00:00
|
|
|
}
|
|
|
|
|
2014-07-07 15:49:28 +00:00
|
|
|
bool NativeWindowViews::IsMaximized() {
|
2021-04-05 23:53:59 +00:00
|
|
|
if (widget()->IsMaximized()) {
|
|
|
|
return true;
|
|
|
|
} else {
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2021-04-05 23:53:59 +00:00
|
|
|
if (transparent()) {
|
|
|
|
// Compare the size of the window with the size of the display
|
|
|
|
auto display = display::Screen::GetScreen()->GetDisplayNearestWindow(
|
|
|
|
GetNativeWindow());
|
|
|
|
// Maximized if the window is the same dimensions and placement as the
|
|
|
|
// display
|
|
|
|
return GetBounds() == display.work_area();
|
|
|
|
}
|
2020-12-01 06:27:58 +00:00
|
|
|
#endif
|
|
|
|
|
2021-04-05 23:53:59 +00:00
|
|
|
return false;
|
|
|
|
}
|
2014-07-07 15:49:28 +00:00
|
|
|
}
|
|
|
|
|
2014-07-03 17:30:36 +00:00
|
|
|
void NativeWindowViews::Minimize() {
|
2014-12-16 00:37:46 +00:00
|
|
|
if (IsVisible())
|
2018-04-25 06:59:16 +00:00
|
|
|
widget()->Minimize();
|
2014-12-16 00:37:46 +00:00
|
|
|
else
|
2018-10-27 03:49:13 +00:00
|
|
|
widget()->native_widget_private()->Show(ui::SHOW_STATE_MINIMIZED,
|
|
|
|
gfx::Rect());
|
2014-07-03 17:30:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NativeWindowViews::Restore() {
|
2018-04-25 06:59:16 +00:00
|
|
|
widget()->Restore();
|
2014-07-03 17:30:36 +00:00
|
|
|
}
|
|
|
|
|
2014-07-26 05:58:26 +00:00
|
|
|
bool NativeWindowViews::IsMinimized() {
|
2018-04-25 06:59:16 +00:00
|
|
|
return widget()->IsMinimized();
|
2014-07-26 05:58:26 +00:00
|
|
|
}
|
|
|
|
|
2014-11-25 06:34:14 +00:00
|
|
|
void NativeWindowViews::SetFullScreen(bool fullscreen) {
|
2016-03-05 12:38:06 +00:00
|
|
|
if (!IsFullScreenable())
|
|
|
|
return;
|
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2014-11-25 06:28:34 +00:00
|
|
|
// There is no native fullscreen state on Windows.
|
2017-06-14 00:47:15 +00:00
|
|
|
bool leaving_fullscreen = IsFullscreen() && !fullscreen;
|
2017-06-01 04:38:51 +00:00
|
|
|
|
2015-09-28 23:20:09 +00:00
|
|
|
if (fullscreen) {
|
2016-03-05 12:38:06 +00:00
|
|
|
last_window_state_ = ui::SHOW_STATE_FULLSCREEN;
|
|
|
|
NotifyWindowEnterFullScreen();
|
2015-09-28 23:20:09 +00:00
|
|
|
} else {
|
|
|
|
last_window_state_ = ui::SHOW_STATE_NORMAL;
|
2014-11-25 06:28:34 +00:00
|
|
|
NotifyWindowLeaveFullScreen();
|
2015-09-28 23:20:09 +00:00
|
|
|
}
|
2016-07-09 13:49:55 +00:00
|
|
|
|
2017-01-18 22:40:42 +00:00
|
|
|
// For window without WS_THICKFRAME style, we can not call SetFullscreen().
|
|
|
|
// This path will be used for transparent windows as well.
|
|
|
|
if (!thick_frame_) {
|
|
|
|
if (fullscreen) {
|
|
|
|
restore_bounds_ = GetBounds();
|
|
|
|
auto display =
|
|
|
|
display::Screen::GetScreen()->GetDisplayNearestPoint(GetPosition());
|
|
|
|
SetBounds(display.bounds(), false);
|
|
|
|
} else {
|
|
|
|
SetBounds(restore_bounds_, false);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-09-28 23:20:09 +00:00
|
|
|
// We set the new value after notifying, so we can handle the size event
|
|
|
|
// correctly.
|
2018-04-25 06:59:16 +00:00
|
|
|
widget()->SetFullscreen(fullscreen);
|
2017-06-01 04:38:51 +00:00
|
|
|
|
|
|
|
// If restoring from fullscreen and the window isn't visible, force visible,
|
|
|
|
// else a non-responsive window shell could be rendered.
|
|
|
|
// (this situation may arise when app starts with fullscreen: true)
|
2018-04-25 06:59:16 +00:00
|
|
|
// Note: the following must be after "widget()->SetFullscreen(fullscreen);"
|
2017-06-14 00:55:55 +00:00
|
|
|
if (leaving_fullscreen && !IsVisible())
|
2017-06-14 00:47:15 +00:00
|
|
|
FlipWindowStyle(GetAcceleratedWidget(), true, WS_VISIBLE);
|
2016-02-09 00:17:05 +00:00
|
|
|
#else
|
2016-03-05 12:38:06 +00:00
|
|
|
if (IsVisible())
|
2018-04-25 06:59:16 +00:00
|
|
|
widget()->SetFullscreen(fullscreen);
|
2016-08-24 21:30:29 +00:00
|
|
|
else if (fullscreen)
|
2018-10-27 03:49:13 +00:00
|
|
|
widget()->native_widget_private()->Show(ui::SHOW_STATE_FULLSCREEN,
|
|
|
|
gfx::Rect());
|
2016-07-11 04:10:19 +00:00
|
|
|
|
|
|
|
// Auto-hide menubar when in fullscreen.
|
|
|
|
if (fullscreen)
|
|
|
|
SetMenuBarVisibility(false);
|
|
|
|
else
|
2018-05-01 04:28:22 +00:00
|
|
|
SetMenuBarVisibility(!IsMenuBarAutoHide());
|
2014-11-25 06:28:34 +00:00
|
|
|
#endif
|
2014-07-03 17:30:36 +00:00
|
|
|
}
|
|
|
|
|
2015-04-21 13:35:36 +00:00
|
|
|
bool NativeWindowViews::IsFullscreen() const {
|
2018-04-25 06:59:16 +00:00
|
|
|
return widget()->IsFullscreen();
|
2014-07-03 17:30:36 +00:00
|
|
|
}
|
|
|
|
|
2016-07-09 13:49:55 +00:00
|
|
|
void NativeWindowViews::SetBounds(const gfx::Rect& bounds, bool animate) {
|
2022-03-22 06:07:09 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
|
|
|
if (is_moving_ || is_resizing_) {
|
|
|
|
pending_bounds_change_ = bounds;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX)
|
2017-11-12 23:35:39 +00:00
|
|
|
// On Linux and Windows the minimum and maximum size should be updated with
|
|
|
|
// window size when window is not resizable.
|
2015-05-01 14:40:46 +00:00
|
|
|
if (!resizable_) {
|
|
|
|
SetMaximumSize(bounds.size());
|
|
|
|
SetMinimumSize(bounds.size());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-04-25 06:59:16 +00:00
|
|
|
widget()->SetBounds(bounds);
|
2015-05-01 10:50:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gfx::Rect NativeWindowViews::GetBounds() {
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2015-05-01 14:40:46 +00:00
|
|
|
if (IsMinimized())
|
2018-04-25 06:59:16 +00:00
|
|
|
return widget()->GetRestoredBounds();
|
2015-05-01 14:40:46 +00:00
|
|
|
#endif
|
|
|
|
|
2018-04-25 06:59:16 +00:00
|
|
|
return widget()->GetWindowBoundsInScreen();
|
2015-05-01 10:50:53 +00:00
|
|
|
}
|
|
|
|
|
2016-07-29 01:19:17 +00:00
|
|
|
gfx::Rect NativeWindowViews::GetContentBounds() {
|
2018-05-08 03:51:27 +00:00
|
|
|
return content_view() ? content_view()->GetBoundsInScreen() : gfx::Rect();
|
2016-07-29 01:19:17 +00:00
|
|
|
}
|
|
|
|
|
2015-10-05 12:03:43 +00:00
|
|
|
gfx::Size NativeWindowViews::GetContentSize() {
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2015-10-05 13:06:57 +00:00
|
|
|
if (IsMinimized())
|
|
|
|
return NativeWindow::GetContentSize();
|
|
|
|
#endif
|
|
|
|
|
2018-05-08 03:51:27 +00:00
|
|
|
return content_view() ? content_view()->size() : gfx::Size();
|
2015-10-05 12:03:43 +00:00
|
|
|
}
|
|
|
|
|
2018-08-24 21:33:27 +00:00
|
|
|
gfx::Rect NativeWindowViews::GetNormalBounds() {
|
|
|
|
return widget()->GetRestoredBounds();
|
|
|
|
}
|
|
|
|
|
2015-10-06 08:06:39 +00:00
|
|
|
void NativeWindowViews::SetContentSizeConstraints(
|
|
|
|
const extensions::SizeConstraints& size_constraints) {
|
|
|
|
NativeWindow::SetContentSizeConstraints(size_constraints);
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2017-08-21 08:21:59 +00:00
|
|
|
// Changing size constraints would force adding the WS_THICKFRAME style, so
|
|
|
|
// do nothing if thickFrame is false.
|
2017-08-21 08:42:45 +00:00
|
|
|
if (!thick_frame_)
|
|
|
|
return;
|
|
|
|
#endif
|
2015-10-15 08:19:45 +00:00
|
|
|
// widget_delegate() is only available after Init() is called, we make use of
|
|
|
|
// this to determine whether native widget has initialized.
|
2018-04-25 06:59:16 +00:00
|
|
|
if (widget() && widget()->widget_delegate())
|
|
|
|
widget()->OnSizeConstraintsChanged();
|
2015-10-06 08:06:39 +00:00
|
|
|
if (resizable_)
|
|
|
|
old_size_constraints_ = size_constraints;
|
|
|
|
}
|
|
|
|
|
2014-07-03 17:30:36 +00:00
|
|
|
void NativeWindowViews::SetResizable(bool resizable) {
|
2014-08-26 05:37:37 +00:00
|
|
|
if (resizable != resizable_) {
|
|
|
|
// On Linux there is no "resizable" property of a window, we have to set
|
|
|
|
// both the minimum and maximum size to the window size to achieve it.
|
|
|
|
if (resizable) {
|
2015-10-06 08:06:39 +00:00
|
|
|
SetContentSizeConstraints(old_size_constraints_);
|
2018-09-26 01:41:40 +00:00
|
|
|
SetMaximizable(maximizable_);
|
2014-08-26 05:37:37 +00:00
|
|
|
} else {
|
2015-10-06 08:06:39 +00:00
|
|
|
old_size_constraints_ = GetContentSizeConstraints();
|
|
|
|
resizable_ = false;
|
|
|
|
gfx::Size content_size = GetContentSize();
|
|
|
|
SetContentSizeConstraints(
|
|
|
|
extensions::SizeConstraints(content_size, content_size));
|
2014-08-26 05:37:37 +00:00
|
|
|
}
|
|
|
|
}
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2017-11-12 23:35:39 +00:00
|
|
|
if (has_frame() && thick_frame_)
|
|
|
|
FlipWindowStyle(GetAcceleratedWidget(), resizable, WS_THICKFRAME);
|
|
|
|
#endif
|
2014-08-26 05:37:37 +00:00
|
|
|
resizable_ = resizable;
|
2021-06-03 08:05:04 +00:00
|
|
|
SetCanResize(resizable_);
|
2014-07-03 17:30:36 +00:00
|
|
|
}
|
|
|
|
|
2019-08-15 06:51:15 +00:00
|
|
|
bool NativeWindowViews::MoveAbove(const std::string& sourceId) {
|
|
|
|
const content::DesktopMediaID id = content::DesktopMediaID::Parse(sourceId);
|
|
|
|
if (id.type != content::DesktopMediaID::TYPE_WINDOW)
|
|
|
|
return false;
|
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2019-08-15 06:51:15 +00:00
|
|
|
const HWND otherWindow = reinterpret_cast<HWND>(id.id);
|
|
|
|
if (!::IsWindow(otherWindow))
|
|
|
|
return false;
|
|
|
|
|
2020-04-21 19:58:38 +00:00
|
|
|
::SetWindowPos(GetAcceleratedWidget(), GetWindow(otherWindow, GW_HWNDPREV), 0,
|
|
|
|
0, 0, 0,
|
2019-08-15 06:51:15 +00:00
|
|
|
SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
|
2022-03-28 16:48:50 +00:00
|
|
|
#elif defined(USE_OZONE_PLATFORM_X11)
|
|
|
|
if (IsX11()) {
|
|
|
|
if (!IsWindowValid(static_cast<x11::Window>(id.id)))
|
|
|
|
return false;
|
2019-08-15 06:51:15 +00:00
|
|
|
|
2022-03-28 16:48:50 +00:00
|
|
|
electron::MoveWindowAbove(static_cast<x11::Window>(GetAcceleratedWidget()),
|
|
|
|
static_cast<x11::Window>(id.id));
|
|
|
|
}
|
2019-08-15 06:51:15 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-04-03 13:04:32 +00:00
|
|
|
void NativeWindowViews::MoveTop() {
|
2021-06-08 02:00:05 +00:00
|
|
|
// TODO(julien.isorce): fix chromium in order to use existing
|
|
|
|
// widget()->StackAtTop().
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2018-04-03 13:04:32 +00:00
|
|
|
gfx::Point pos = GetPosition();
|
|
|
|
gfx::Size size = GetSize();
|
2018-04-18 01:55:30 +00:00
|
|
|
::SetWindowPos(GetAcceleratedWidget(), HWND_TOP, pos.x(), pos.y(),
|
|
|
|
size.width(), size.height(),
|
|
|
|
SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
|
2022-03-28 16:48:50 +00:00
|
|
|
#elif defined(USE_OZONE_PLATFORM_X11)
|
|
|
|
if (IsX11())
|
|
|
|
electron::MoveWindowToForeground(
|
|
|
|
static_cast<x11::Window>(GetAcceleratedWidget()));
|
2018-04-03 13:04:32 +00:00
|
|
|
#endif
|
2019-02-07 20:48:19 +00:00
|
|
|
}
|
2018-04-03 13:04:32 +00:00
|
|
|
|
2014-07-03 17:30:36 +00:00
|
|
|
bool NativeWindowViews::IsResizable() {
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2016-11-15 05:23:59 +00:00
|
|
|
if (has_frame())
|
2016-07-09 12:49:15 +00:00
|
|
|
return ::GetWindowLong(GetAcceleratedWidget(), GWL_STYLE) & WS_THICKFRAME;
|
2016-01-23 12:03:56 +00:00
|
|
|
#endif
|
2021-06-03 08:05:04 +00:00
|
|
|
return resizable_;
|
2014-07-03 17:30:36 +00:00
|
|
|
}
|
|
|
|
|
2019-11-01 16:22:07 +00:00
|
|
|
void NativeWindowViews::SetAspectRatio(double aspect_ratio,
|
|
|
|
const gfx::Size& extra_size) {
|
|
|
|
NativeWindow::SetAspectRatio(aspect_ratio, extra_size);
|
|
|
|
gfx::SizeF aspect(aspect_ratio, 1.0);
|
|
|
|
// Scale up because SetAspectRatio() truncates aspect value to int
|
|
|
|
aspect.Scale(100);
|
|
|
|
|
|
|
|
widget()->SetAspectRatio(aspect);
|
|
|
|
}
|
|
|
|
|
2016-01-18 22:46:35 +00:00
|
|
|
void NativeWindowViews::SetMovable(bool movable) {
|
|
|
|
movable_ = movable;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool NativeWindowViews::IsMovable() {
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2016-01-18 22:46:35 +00:00
|
|
|
return movable_;
|
2016-01-23 10:23:18 +00:00
|
|
|
#else
|
|
|
|
return true; // Not implemented on Linux.
|
2016-01-19 15:43:52 +00:00
|
|
|
#endif
|
2016-01-18 22:46:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NativeWindowViews::SetMinimizable(bool minimizable) {
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2016-01-23 10:23:18 +00:00
|
|
|
FlipWindowStyle(GetAcceleratedWidget(), minimizable, WS_MINIMIZEBOX);
|
2016-01-18 22:46:35 +00:00
|
|
|
#endif
|
|
|
|
minimizable_ = minimizable;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool NativeWindowViews::IsMinimizable() {
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2016-01-23 11:35:30 +00:00
|
|
|
return ::GetWindowLong(GetAcceleratedWidget(), GWL_STYLE) & WS_MINIMIZEBOX;
|
2016-01-23 10:23:18 +00:00
|
|
|
#else
|
2016-01-23 11:35:30 +00:00
|
|
|
return true; // Not implemented on Linux.
|
2016-01-18 22:46:35 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-01-22 21:24:33 +00:00
|
|
|
void NativeWindowViews::SetMaximizable(bool maximizable) {
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2016-01-23 10:23:18 +00:00
|
|
|
FlipWindowStyle(GetAcceleratedWidget(), maximizable, WS_MAXIMIZEBOX);
|
2016-01-22 21:24:33 +00:00
|
|
|
#endif
|
2016-01-23 10:23:18 +00:00
|
|
|
maximizable_ = maximizable;
|
2016-01-22 21:24:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool NativeWindowViews::IsMaximizable() {
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2016-01-23 11:35:30 +00:00
|
|
|
return ::GetWindowLong(GetAcceleratedWidget(), GWL_STYLE) & WS_MAXIMIZEBOX;
|
2016-01-23 10:23:18 +00:00
|
|
|
#else
|
2016-01-23 11:35:30 +00:00
|
|
|
return true; // Not implemented on Linux.
|
2016-01-22 21:24:33 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2019-03-27 12:10:23 +00:00
|
|
|
void NativeWindowViews::SetExcludedFromShownWindowsMenu(bool excluded) {}
|
|
|
|
|
|
|
|
bool NativeWindowViews::IsExcludedFromShownWindowsMenu() {
|
|
|
|
// return false on unsupported platforms
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-02-22 09:23:56 +00:00
|
|
|
void NativeWindowViews::SetFullScreenable(bool fullscreenable) {
|
|
|
|
fullscreenable_ = fullscreenable;
|
2016-01-22 21:24:33 +00:00
|
|
|
}
|
|
|
|
|
2016-01-23 07:47:37 +00:00
|
|
|
bool NativeWindowViews::IsFullScreenable() {
|
2016-02-22 09:23:56 +00:00
|
|
|
return fullscreenable_;
|
2016-01-22 21:24:33 +00:00
|
|
|
}
|
|
|
|
|
2016-01-18 22:46:35 +00:00
|
|
|
void NativeWindowViews::SetClosable(bool closable) {
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2016-01-18 22:46:35 +00:00
|
|
|
HMENU menu = GetSystemMenu(GetAcceleratedWidget(), false);
|
|
|
|
if (closable) {
|
|
|
|
EnableMenuItem(menu, SC_CLOSE, MF_BYCOMMAND | MF_ENABLED);
|
|
|
|
} else {
|
|
|
|
EnableMenuItem(menu, SC_CLOSE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool NativeWindowViews::IsClosable() {
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2016-01-18 22:46:35 +00:00
|
|
|
HMENU menu = GetSystemMenu(GetAcceleratedWidget(), false);
|
|
|
|
MENUITEMINFO info;
|
|
|
|
memset(&info, 0, sizeof(info));
|
|
|
|
info.cbSize = sizeof(info);
|
|
|
|
info.fMask = MIIM_STATE;
|
|
|
|
if (!GetMenuItemInfo(menu, SC_CLOSE, false, &info)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return !(info.fState & MFS_DISABLED);
|
2022-02-10 02:58:52 +00:00
|
|
|
#elif BUILDFLAG(IS_LINUX)
|
2016-01-18 22:46:35 +00:00
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2019-07-24 22:58:51 +00:00
|
|
|
void NativeWindowViews::SetAlwaysOnTop(ui::ZOrderLevel z_order,
|
2018-04-18 01:55:30 +00:00
|
|
|
const std::string& level,
|
2019-10-18 19:57:34 +00:00
|
|
|
int relativeLevel) {
|
2019-07-26 22:53:31 +00:00
|
|
|
bool level_changed = z_order != widget()->GetZOrderLevel();
|
2019-07-24 22:58:51 +00:00
|
|
|
widget()->SetZOrderLevel(z_order);
|
2019-07-10 14:40:11 +00:00
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2019-07-10 14:40:11 +00:00
|
|
|
// Reset the placement flag.
|
|
|
|
behind_task_bar_ = false;
|
2019-07-24 22:58:51 +00:00
|
|
|
if (z_order != ui::ZOrderLevel::kNormal) {
|
2019-07-10 14:40:11 +00:00
|
|
|
// On macOS the window is placed behind the Dock for the following levels.
|
|
|
|
// Re-use the same names on Windows to make it easier for the user.
|
|
|
|
static const std::vector<std::string> levels = {
|
|
|
|
"floating", "torn-off-menu", "modal-panel", "main-menu", "status"};
|
|
|
|
behind_task_bar_ = base::Contains(levels, level);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
MoveBehindTaskBarIfNeeded();
|
2019-07-26 22:53:31 +00:00
|
|
|
|
|
|
|
// This must be notified at the very end or IsAlwaysOnTop
|
|
|
|
// will not yet have been updated to reflect the new status
|
|
|
|
if (level_changed)
|
|
|
|
NativeWindow::NotifyWindowAlwaysOnTopChanged();
|
2014-07-03 17:30:36 +00:00
|
|
|
}
|
|
|
|
|
2019-07-24 22:58:51 +00:00
|
|
|
ui::ZOrderLevel NativeWindowViews::GetZOrderLevel() {
|
|
|
|
return widget()->GetZOrderLevel();
|
2014-07-03 17:30:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NativeWindowViews::Center() {
|
2018-04-25 06:59:16 +00:00
|
|
|
widget()->CenterWindow(GetSize());
|
2014-07-03 17:30:36 +00:00
|
|
|
}
|
|
|
|
|
2017-02-14 03:41:24 +00:00
|
|
|
void NativeWindowViews::Invalidate() {
|
2018-04-25 06:59:16 +00:00
|
|
|
widget()->SchedulePaintInRect(gfx::Rect(GetBounds().size()));
|
2017-02-14 03:41:24 +00:00
|
|
|
}
|
|
|
|
|
2014-07-03 17:30:36 +00:00
|
|
|
void NativeWindowViews::SetTitle(const std::string& title) {
|
|
|
|
title_ = title;
|
2018-04-25 06:59:16 +00:00
|
|
|
widget()->UpdateWindowTitle();
|
2014-07-03 17:30:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string NativeWindowViews::GetTitle() {
|
|
|
|
return title_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NativeWindowViews::FlashFrame(bool flash) {
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2014-12-16 01:27:58 +00:00
|
|
|
// The Chromium's implementation has a bug stopping flash.
|
|
|
|
if (!flash) {
|
|
|
|
FLASHWINFO fwi;
|
|
|
|
fwi.cbSize = sizeof(fwi);
|
|
|
|
fwi.hwnd = GetAcceleratedWidget();
|
|
|
|
fwi.dwFlags = FLASHW_STOP;
|
|
|
|
fwi.uCount = 0;
|
|
|
|
FlashWindowEx(&fwi);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
2018-04-25 06:59:16 +00:00
|
|
|
widget()->FlashFrame(flash);
|
2014-07-03 17:30:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NativeWindowViews::SetSkipTaskbar(bool skip) {
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2018-04-18 17:20:15 +00:00
|
|
|
Microsoft::WRL::ComPtr<ITaskbarList> taskbar;
|
2017-09-10 15:10:26 +00:00
|
|
|
if (FAILED(::CoCreateInstance(CLSID_TaskbarList, nullptr,
|
|
|
|
CLSCTX_INPROC_SERVER,
|
|
|
|
IID_PPV_ARGS(&taskbar))) ||
|
2014-07-21 14:03:58 +00:00
|
|
|
FAILED(taskbar->HrInit()))
|
|
|
|
return;
|
2016-08-12 15:55:42 +00:00
|
|
|
if (skip) {
|
2014-07-21 14:03:58 +00:00
|
|
|
taskbar->DeleteTab(GetAcceleratedWidget());
|
2016-08-12 15:55:42 +00:00
|
|
|
} else {
|
2014-07-21 14:03:58 +00:00
|
|
|
taskbar->AddTab(GetAcceleratedWidget());
|
2016-08-12 15:55:42 +00:00
|
|
|
taskbar_host_.RestoreThumbarButtons(GetAcceleratedWidget());
|
|
|
|
}
|
2022-03-28 16:48:50 +00:00
|
|
|
#elif defined(USE_OZONE_PLATFORM_X11)
|
|
|
|
if (IsX11())
|
|
|
|
SetWMSpecState(static_cast<x11::Window>(GetAcceleratedWidget()), skip,
|
|
|
|
x11::GetAtom("_NET_WM_STATE_SKIP_TASKBAR"));
|
2014-07-07 09:22:22 +00:00
|
|
|
#endif
|
2014-07-03 17:30:36 +00:00
|
|
|
}
|
|
|
|
|
2017-08-13 06:28:33 +00:00
|
|
|
void NativeWindowViews::SetSimpleFullScreen(bool simple_fullscreen) {
|
|
|
|
SetFullScreen(simple_fullscreen);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool NativeWindowViews::IsSimpleFullScreen() {
|
|
|
|
return IsFullscreen();
|
|
|
|
}
|
|
|
|
|
2014-07-03 17:30:36 +00:00
|
|
|
void NativeWindowViews::SetKiosk(bool kiosk) {
|
2014-11-25 06:34:14 +00:00
|
|
|
SetFullScreen(kiosk);
|
2014-07-03 17:30:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool NativeWindowViews::IsKiosk() {
|
|
|
|
return IsFullscreen();
|
|
|
|
}
|
|
|
|
|
2020-09-22 05:40:42 +00:00
|
|
|
bool NativeWindowViews::IsTabletMode() const {
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
|
|
|
return base::win::IsWindows10OrGreaterTabletMode(GetAcceleratedWidget());
|
2020-09-22 05:40:42 +00:00
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2019-12-13 16:08:30 +00:00
|
|
|
SkColor NativeWindowViews::GetBackgroundColor() {
|
2021-03-15 22:43:25 +00:00
|
|
|
auto* background = root_view_->background();
|
|
|
|
if (!background)
|
|
|
|
return SK_ColorTRANSPARENT;
|
|
|
|
return background->get_color();
|
2019-12-13 16:08:30 +00:00
|
|
|
}
|
|
|
|
|
2018-03-06 04:21:47 +00:00
|
|
|
void NativeWindowViews::SetBackgroundColor(SkColor background_color) {
|
2015-10-23 03:35:33 +00:00
|
|
|
// web views' background color.
|
2018-05-01 04:28:22 +00:00
|
|
|
root_view_->SetBackground(views::CreateSolidBackground(background_color));
|
2015-10-23 03:35:33 +00:00
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2015-10-23 03:35:33 +00:00
|
|
|
// Set the background color of native window.
|
|
|
|
HBRUSH brush = CreateSolidBrush(skia::SkColorToCOLORREF(background_color));
|
2018-04-18 01:55:30 +00:00
|
|
|
ULONG_PTR previous_brush =
|
|
|
|
SetClassLongPtr(GetAcceleratedWidget(), GCLP_HBRBACKGROUND,
|
|
|
|
reinterpret_cast<LONG_PTR>(brush));
|
2015-10-23 03:35:33 +00:00
|
|
|
if (previous_brush)
|
|
|
|
DeleteObject((HBRUSH)previous_brush);
|
2018-09-12 20:41:47 +00:00
|
|
|
InvalidateRect(GetAcceleratedWidget(), NULL, 1);
|
2015-10-23 03:35:33 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-01-23 10:55:12 +00:00
|
|
|
void NativeWindowViews::SetHasShadow(bool has_shadow) {
|
2018-04-18 17:39:54 +00:00
|
|
|
wm::SetShadowElevation(GetNativeWindow(),
|
|
|
|
has_shadow ? wm::kShadowElevationInactiveWindow
|
|
|
|
: wm::kShadowElevationNone);
|
2016-01-23 10:55:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool NativeWindowViews::HasShadow() {
|
2018-04-18 01:55:30 +00:00
|
|
|
return GetNativeWindow()->GetProperty(wm::kShadowElevationKey) !=
|
2018-04-18 17:39:54 +00:00
|
|
|
wm::kShadowElevationNone;
|
2016-01-23 10:55:12 +00:00
|
|
|
}
|
|
|
|
|
2017-09-29 02:26:02 +00:00
|
|
|
void NativeWindowViews::SetOpacity(const double opacity) {
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2021-08-11 21:04:56 +00:00
|
|
|
const double boundedOpacity = base::clamp(opacity, 0.0, 1.0);
|
2017-10-02 00:52:27 +00:00
|
|
|
HWND hwnd = GetAcceleratedWidget();
|
2017-09-29 02:26:02 +00:00
|
|
|
if (!layered_) {
|
2017-10-02 00:52:27 +00:00
|
|
|
LONG ex_style = ::GetWindowLong(hwnd, GWL_EXSTYLE);
|
2017-09-29 02:26:02 +00:00
|
|
|
ex_style |= WS_EX_LAYERED;
|
2017-10-02 00:52:27 +00:00
|
|
|
::SetWindowLong(hwnd, GWL_EXSTYLE, ex_style);
|
2017-09-29 02:26:02 +00:00
|
|
|
layered_ = true;
|
|
|
|
}
|
2019-08-07 07:17:32 +00:00
|
|
|
::SetLayeredWindowAttributes(hwnd, 0, boundedOpacity * 255, LWA_ALPHA);
|
|
|
|
opacity_ = boundedOpacity;
|
|
|
|
#else
|
|
|
|
opacity_ = 1.0; // setOpacity unsupported on Linux
|
2017-09-29 02:26:02 +00:00
|
|
|
#endif
|
2017-10-02 15:08:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double NativeWindowViews::GetOpacity() {
|
|
|
|
return opacity_;
|
2017-09-29 02:26:02 +00:00
|
|
|
}
|
|
|
|
|
2017-08-14 18:21:00 +00:00
|
|
|
void NativeWindowViews::SetIgnoreMouseEvents(bool ignore, bool forward) {
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2016-06-07 10:38:41 +00:00
|
|
|
LONG ex_style = ::GetWindowLong(GetAcceleratedWidget(), GWL_EXSTYLE);
|
|
|
|
if (ignore)
|
|
|
|
ex_style |= (WS_EX_TRANSPARENT | WS_EX_LAYERED);
|
|
|
|
else
|
|
|
|
ex_style &= ~(WS_EX_TRANSPARENT | WS_EX_LAYERED);
|
2017-09-29 02:26:02 +00:00
|
|
|
if (layered_)
|
|
|
|
ex_style |= WS_EX_LAYERED;
|
2016-06-07 10:38:41 +00:00
|
|
|
::SetWindowLong(GetAcceleratedWidget(), GWL_EXSTYLE, ex_style);
|
2017-08-14 18:21:00 +00:00
|
|
|
|
|
|
|
// Forwarding is always disabled when not ignoring mouse messages.
|
|
|
|
if (!ignore) {
|
|
|
|
SetForwardMouseMessages(false);
|
|
|
|
} else {
|
|
|
|
SetForwardMouseMessages(forward);
|
|
|
|
}
|
2022-03-28 16:48:50 +00:00
|
|
|
#elif defined(USE_OZONE_PLATFORM_X11)
|
|
|
|
if (IsX11()) {
|
|
|
|
auto* connection = x11::Connection::Get();
|
|
|
|
if (ignore) {
|
|
|
|
x11::Rectangle r{0, 0, 1, 1};
|
|
|
|
connection->shape().Rectangles({
|
|
|
|
.operation = x11::Shape::So::Set,
|
|
|
|
.destination_kind = x11::Shape::Sk::Input,
|
|
|
|
.ordering = x11::ClipOrdering::YXBanded,
|
|
|
|
.destination_window =
|
|
|
|
static_cast<x11::Window>(GetAcceleratedWidget()),
|
|
|
|
.rectangles = {r},
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
connection->shape().Mask({
|
|
|
|
.operation = x11::Shape::So::Set,
|
|
|
|
.destination_kind = x11::Shape::Sk::Input,
|
|
|
|
.destination_window =
|
|
|
|
static_cast<x11::Window>(GetAcceleratedWidget()),
|
|
|
|
.source_bitmap = x11::Pixmap::None,
|
|
|
|
});
|
|
|
|
}
|
2016-06-07 11:23:29 +00:00
|
|
|
}
|
2016-06-07 10:38:41 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-06-22 08:40:01 +00:00
|
|
|
void NativeWindowViews::SetContentProtection(bool enable) {
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2021-10-11 20:29:43 +00:00
|
|
|
HWND hwnd = GetAcceleratedWidget();
|
2021-11-15 09:51:27 +00:00
|
|
|
DWORD affinity = enable ? WDA_EXCLUDEFROMCAPTURE : WDA_NONE;
|
|
|
|
::SetWindowDisplayAffinity(hwnd, affinity);
|
2021-10-11 20:29:43 +00:00
|
|
|
if (!layered_) {
|
|
|
|
// Workaround to prevent black window on screen capture after hiding and
|
|
|
|
// showing the BrowserWindow.
|
|
|
|
LONG ex_style = ::GetWindowLong(hwnd, GWL_EXSTYLE);
|
|
|
|
ex_style |= WS_EX_LAYERED;
|
|
|
|
::SetWindowLong(hwnd, GWL_EXSTYLE, ex_style);
|
|
|
|
layered_ = true;
|
|
|
|
}
|
2016-06-22 08:40:01 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-06-13 08:10:28 +00:00
|
|
|
void NativeWindowViews::SetFocusable(bool focusable) {
|
2020-01-22 01:13:48 +00:00
|
|
|
widget()->widget_delegate()->SetCanActivate(focusable);
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2016-06-12 18:20:25 +00:00
|
|
|
LONG ex_style = ::GetWindowLong(GetAcceleratedWidget(), GWL_EXSTYLE);
|
2016-06-13 08:10:28 +00:00
|
|
|
if (focusable)
|
2016-06-12 18:20:25 +00:00
|
|
|
ex_style &= ~WS_EX_NOACTIVATE;
|
2016-06-13 08:24:45 +00:00
|
|
|
else
|
|
|
|
ex_style |= WS_EX_NOACTIVATE;
|
2016-06-12 18:20:25 +00:00
|
|
|
::SetWindowLong(GetAcceleratedWidget(), GWL_EXSTYLE, ex_style);
|
2016-06-13 08:24:45 +00:00
|
|
|
SetSkipTaskbar(!focusable);
|
|
|
|
Focus(false);
|
2016-06-12 18:20:25 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2021-04-21 10:32:19 +00:00
|
|
|
bool NativeWindowViews::IsFocusable() {
|
|
|
|
bool can_activate = widget()->widget_delegate()->CanActivate();
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2021-04-21 10:32:19 +00:00
|
|
|
LONG ex_style = ::GetWindowLong(GetAcceleratedWidget(), GWL_EXSTYLE);
|
|
|
|
bool no_activate = ex_style & WS_EX_NOACTIVATE;
|
|
|
|
return !no_activate && can_activate;
|
|
|
|
#else
|
|
|
|
return can_activate;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-07-06 23:04:18 +00:00
|
|
|
void NativeWindowViews::SetMenu(ElectronMenuModel* menu_model) {
|
2022-03-28 16:48:50 +00:00
|
|
|
#if defined(USE_OZONE)
|
2021-10-06 02:21:00 +00:00
|
|
|
// Remove global menu bar.
|
|
|
|
if (global_menu_bar_ && menu_model == nullptr) {
|
|
|
|
global_menu_bar_.reset();
|
|
|
|
root_view_->UnregisterAcceleratorsWithFocusManager();
|
|
|
|
return;
|
|
|
|
}
|
2020-10-20 18:24:52 +00:00
|
|
|
|
2021-10-06 02:21:00 +00:00
|
|
|
// Use global application menu bar when possible.
|
2022-03-28 16:48:50 +00:00
|
|
|
if (CreateGlobalMenuBar() && ShouldUseGlobalMenuBar()) {
|
2021-10-06 02:21:00 +00:00
|
|
|
if (!global_menu_bar_)
|
|
|
|
global_menu_bar_ = std::make_unique<GlobalMenuBarX11>(this);
|
|
|
|
if (global_menu_bar_->IsServerStarted()) {
|
|
|
|
root_view_->RegisterAcceleratorsWithFocusManager(menu_model);
|
|
|
|
global_menu_bar_->SetMenu(menu_model);
|
|
|
|
return;
|
2020-10-20 18:24:52 +00:00
|
|
|
}
|
2014-07-16 14:10:10 +00:00
|
|
|
}
|
2014-07-11 00:57:19 +00:00
|
|
|
#endif
|
2014-07-16 14:10:10 +00:00
|
|
|
|
2018-05-01 04:28:22 +00:00
|
|
|
// Should reset content size when setting menu.
|
|
|
|
gfx::Size content_size = GetContentSize();
|
|
|
|
bool should_reset_size = use_content_size_ && has_frame() &&
|
|
|
|
!IsMenuBarAutoHide() &&
|
|
|
|
((!!menu_model) != root_view_->HasMenu());
|
|
|
|
|
|
|
|
root_view_->SetMenu(menu_model);
|
|
|
|
|
|
|
|
if (should_reset_size) {
|
|
|
|
// Enlarge the size constraints for the menu.
|
|
|
|
int menu_bar_height = root_view_->GetMenuBarHeight();
|
|
|
|
extensions::SizeConstraints constraints = GetContentSizeConstraints();
|
|
|
|
if (constraints.HasMinimumSize()) {
|
|
|
|
gfx::Size min_size = constraints.GetMinimumSize();
|
|
|
|
min_size.set_height(min_size.height() + menu_bar_height);
|
|
|
|
constraints.set_minimum_size(min_size);
|
2014-08-07 05:47:58 +00:00
|
|
|
}
|
2018-05-01 04:28:22 +00:00
|
|
|
if (constraints.HasMaximumSize()) {
|
|
|
|
gfx::Size max_size = constraints.GetMaximumSize();
|
|
|
|
max_size.set_height(max_size.height() + menu_bar_height);
|
|
|
|
constraints.set_maximum_size(max_size);
|
|
|
|
}
|
|
|
|
SetContentSizeConstraints(constraints);
|
2014-07-17 06:23:28 +00:00
|
|
|
|
2018-05-01 04:28:22 +00:00
|
|
|
// Resize the window to make sure content size is not changed.
|
|
|
|
SetContentSize(content_size);
|
|
|
|
}
|
2014-07-04 08:54:10 +00:00
|
|
|
}
|
|
|
|
|
2018-12-22 01:49:26 +00:00
|
|
|
void NativeWindowViews::AddBrowserView(NativeBrowserView* view) {
|
2018-05-08 03:51:27 +00:00
|
|
|
if (!content_view())
|
2018-04-08 11:20:43 +00:00
|
|
|
return;
|
|
|
|
|
2018-12-22 01:49:26 +00:00
|
|
|
if (!view) {
|
|
|
|
return;
|
Implement initial, experimental BrowserView API
Right now, `<webview>` is the only way to embed additional content in a
`BrowserWindow`. Unfortunately `<webview>` suffers from a [number of
problems](https://github.com/electron/electron/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aopen%20label%3Awebview%20).
To make matters worse, many of these are upstream Chromium bugs instead
of Electron-specific bugs.
For us at [Figma](https://www.figma.com), the main issue is very slow
performance.
Despite the upstream improvements to `<webview>` through the OOPIF work, it is
probable that there will continue to be `<webview>`-specific bugs in the
future.
Therefore, this introduces a `<webview>` alternative to called `BrowserView`,
which...
- is a thin wrapper around `api::WebContents` (so bugs in `BrowserView` will
likely also be bugs in `BrowserWindow` web contents)
- is instantiated in the main process like `BrowserWindow` (and unlike
`<webview>`, which lives in the DOM of a `BrowserWindow` web contents)
- needs to be added to a `BrowserWindow` to display something on the screen
This implements the most basic API. The API is expected to evolve and change in
the near future and has consequently been marked as experimental. Please do not
use this API in production unless you are prepared to deal with breaking
changes.
In the future, we will want to change the API to support multiple
`BrowserView`s per window. We will also want to consider z-ordering
auto-resizing, and possibly even nested views.
2017-04-11 17:47:30 +00:00
|
|
|
}
|
|
|
|
|
2018-12-22 01:49:26 +00:00
|
|
|
add_browser_view(view);
|
2020-08-26 03:04:13 +00:00
|
|
|
if (view->GetInspectableWebContentsView())
|
|
|
|
content_view()->AddChildView(
|
|
|
|
view->GetInspectableWebContentsView()->GetView());
|
2018-12-22 01:49:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NativeWindowViews::RemoveBrowserView(NativeBrowserView* view) {
|
|
|
|
if (!content_view())
|
|
|
|
return;
|
|
|
|
|
2018-03-06 06:04:40 +00:00
|
|
|
if (!view) {
|
Implement initial, experimental BrowserView API
Right now, `<webview>` is the only way to embed additional content in a
`BrowserWindow`. Unfortunately `<webview>` suffers from a [number of
problems](https://github.com/electron/electron/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aopen%20label%3Awebview%20).
To make matters worse, many of these are upstream Chromium bugs instead
of Electron-specific bugs.
For us at [Figma](https://www.figma.com), the main issue is very slow
performance.
Despite the upstream improvements to `<webview>` through the OOPIF work, it is
probable that there will continue to be `<webview>`-specific bugs in the
future.
Therefore, this introduces a `<webview>` alternative to called `BrowserView`,
which...
- is a thin wrapper around `api::WebContents` (so bugs in `BrowserView` will
likely also be bugs in `BrowserWindow` web contents)
- is instantiated in the main process like `BrowserWindow` (and unlike
`<webview>`, which lives in the DOM of a `BrowserWindow` web contents)
- needs to be added to a `BrowserWindow` to display something on the screen
This implements the most basic API. The API is expected to evolve and change in
the near future and has consequently been marked as experimental. Please do not
use this API in production unless you are prepared to deal with breaking
changes.
In the future, we will want to change the API to support multiple
`BrowserView`s per window. We will also want to consider z-ordering
auto-resizing, and possibly even nested views.
2017-04-11 17:47:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-08-26 03:04:13 +00:00
|
|
|
if (view->GetInspectableWebContentsView())
|
|
|
|
content_view()->RemoveChildView(
|
|
|
|
view->GetInspectableWebContentsView()->GetView());
|
2018-12-22 01:49:26 +00:00
|
|
|
remove_browser_view(view);
|
Implement initial, experimental BrowserView API
Right now, `<webview>` is the only way to embed additional content in a
`BrowserWindow`. Unfortunately `<webview>` suffers from a [number of
problems](https://github.com/electron/electron/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aopen%20label%3Awebview%20).
To make matters worse, many of these are upstream Chromium bugs instead
of Electron-specific bugs.
For us at [Figma](https://www.figma.com), the main issue is very slow
performance.
Despite the upstream improvements to `<webview>` through the OOPIF work, it is
probable that there will continue to be `<webview>`-specific bugs in the
future.
Therefore, this introduces a `<webview>` alternative to called `BrowserView`,
which...
- is a thin wrapper around `api::WebContents` (so bugs in `BrowserView` will
likely also be bugs in `BrowserWindow` web contents)
- is instantiated in the main process like `BrowserWindow` (and unlike
`<webview>`, which lives in the DOM of a `BrowserWindow` web contents)
- needs to be added to a `BrowserWindow` to display something on the screen
This implements the most basic API. The API is expected to evolve and change in
the near future and has consequently been marked as experimental. Please do not
use this API in production unless you are prepared to deal with breaking
changes.
In the future, we will want to change the API to support multiple
`BrowserView`s per window. We will also want to consider z-ordering
auto-resizing, and possibly even nested views.
2017-04-11 17:47:30 +00:00
|
|
|
}
|
|
|
|
|
2021-02-10 07:23:35 +00:00
|
|
|
void NativeWindowViews::SetTopBrowserView(NativeBrowserView* view) {
|
|
|
|
if (!content_view())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!view) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
remove_browser_view(view);
|
|
|
|
add_browser_view(view);
|
|
|
|
|
|
|
|
if (view->GetInspectableWebContentsView())
|
|
|
|
content_view()->ReorderChildView(
|
|
|
|
view->GetInspectableWebContentsView()->GetView(), -1);
|
|
|
|
}
|
|
|
|
|
2016-06-17 06:28:43 +00:00
|
|
|
void NativeWindowViews::SetParentWindow(NativeWindow* parent) {
|
2016-06-20 05:49:24 +00:00
|
|
|
NativeWindow::SetParentWindow(parent);
|
|
|
|
|
2022-03-28 16:48:50 +00:00
|
|
|
#if defined(USE_OZONE_PLATFORM_X11)
|
|
|
|
if (IsX11())
|
|
|
|
x11::SetProperty(
|
|
|
|
static_cast<x11::Window>(GetAcceleratedWidget()),
|
|
|
|
x11::Atom::WM_TRANSIENT_FOR, x11::Atom::WINDOW,
|
|
|
|
parent ? static_cast<x11::Window>(parent->GetAcceleratedWidget())
|
|
|
|
: ui::GetX11RootWindow());
|
2022-02-10 02:58:52 +00:00
|
|
|
#elif BUILDFLAG(IS_WIN)
|
2018-12-13 00:05:16 +00:00
|
|
|
// To set parentship between windows into Windows is better to play with the
|
|
|
|
// owner instead of the parent, as Windows natively seems to do if a parent
|
|
|
|
// is specified at window creation time.
|
|
|
|
// For do this we must NOT use the ::SetParent function, instead we must use
|
|
|
|
// the ::GetWindowLongPtr or ::SetWindowLongPtr functions with "nIndex" set
|
|
|
|
// to "GWLP_HWNDPARENT" which actually means the window owner.
|
|
|
|
HWND hwndParent = parent ? parent->GetAcceleratedWidget() : NULL;
|
|
|
|
if (hwndParent ==
|
|
|
|
(HWND)::GetWindowLongPtr(GetAcceleratedWidget(), GWLP_HWNDPARENT))
|
|
|
|
return;
|
|
|
|
::SetWindowLongPtr(GetAcceleratedWidget(), GWLP_HWNDPARENT,
|
|
|
|
(LONG_PTR)hwndParent);
|
|
|
|
// Ensures the visibility
|
|
|
|
if (IsVisible()) {
|
|
|
|
WINDOWPLACEMENT wp;
|
|
|
|
wp.length = sizeof(WINDOWPLACEMENT);
|
|
|
|
::GetWindowPlacement(GetAcceleratedWidget(), &wp);
|
|
|
|
::ShowWindow(GetAcceleratedWidget(), SW_HIDE);
|
|
|
|
::ShowWindow(GetAcceleratedWidget(), wp.showCmd);
|
|
|
|
::BringWindowToTop(GetAcceleratedWidget());
|
2016-06-19 02:19:32 +00:00
|
|
|
}
|
|
|
|
#endif
|
2016-06-17 06:28:43 +00:00
|
|
|
}
|
|
|
|
|
2017-05-21 18:57:19 +00:00
|
|
|
gfx::NativeView NativeWindowViews::GetNativeView() const {
|
2018-04-25 06:59:16 +00:00
|
|
|
return widget()->GetNativeView();
|
2017-03-04 02:09:16 +00:00
|
|
|
}
|
|
|
|
|
2017-05-21 18:57:19 +00:00
|
|
|
gfx::NativeWindow NativeWindowViews::GetNativeWindow() const {
|
2018-04-25 06:59:16 +00:00
|
|
|
return widget()->GetNativeWindow();
|
2014-07-03 17:30:36 +00:00
|
|
|
}
|
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
void NativeWindowViews::SetProgressBar(double progress,
|
|
|
|
NativeWindow::ProgressState state) {
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2016-08-09 23:05:44 +00:00
|
|
|
taskbar_host_.SetProgressBar(GetAcceleratedWidget(), progress, state);
|
2022-02-10 02:58:52 +00:00
|
|
|
#elif BUILDFLAG(IS_LINUX)
|
2014-09-18 11:12:24 +00:00
|
|
|
if (unity::IsRunning()) {
|
|
|
|
unity::SetProgressFraction(progress);
|
|
|
|
}
|
2014-09-17 01:42:47 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-02-11 01:14:26 +00:00
|
|
|
void NativeWindowViews::SetOverlayIcon(const gfx::Image& overlay,
|
|
|
|
const std::string& description) {
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2021-01-21 05:45:06 +00:00
|
|
|
SkBitmap overlay_bitmap = overlay.AsBitmap();
|
|
|
|
taskbar_host_.SetOverlayIcon(GetAcceleratedWidget(), overlay_bitmap,
|
|
|
|
description);
|
2015-02-06 23:58:49 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-11-12 12:32:14 +00:00
|
|
|
void NativeWindowViews::SetAutoHideMenuBar(bool auto_hide) {
|
2018-05-01 04:28:22 +00:00
|
|
|
root_view_->SetAutoHideMenuBar(auto_hide);
|
2014-11-12 12:32:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool NativeWindowViews::IsMenuBarAutoHide() {
|
2018-05-01 04:28:22 +00:00
|
|
|
return root_view_->IsMenuBarAutoHide();
|
2014-11-12 12:32:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NativeWindowViews::SetMenuBarVisibility(bool visible) {
|
2018-05-01 04:28:22 +00:00
|
|
|
root_view_->SetMenuBarVisibility(visible);
|
2014-11-12 12:32:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool NativeWindowViews::IsMenuBarVisible() {
|
2018-05-01 04:28:22 +00:00
|
|
|
return root_view_->IsMenuBarVisible();
|
2014-11-12 12:32:14 +00:00
|
|
|
}
|
|
|
|
|
2021-02-02 12:24:04 +00:00
|
|
|
void NativeWindowViews::SetVisibleOnAllWorkspaces(
|
|
|
|
bool visible,
|
|
|
|
bool visibleOnFullScreen,
|
|
|
|
bool skipTransformProcessType) {
|
2018-04-25 06:59:16 +00:00
|
|
|
widget()->SetVisibleOnAllWorkspaces(visible);
|
2015-03-26 06:18:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool NativeWindowViews::IsVisibleOnAllWorkspaces() {
|
2022-03-28 16:48:50 +00:00
|
|
|
#if defined(USE_OZONE_PLATFORM_X11)
|
|
|
|
if (IsX11()) {
|
|
|
|
// Use the presence/absence of _NET_WM_STATE_STICKY in _NET_WM_STATE to
|
|
|
|
// determine whether the current window is visible on all workspaces.
|
|
|
|
x11::Atom sticky_atom = x11::GetAtom("_NET_WM_STATE_STICKY");
|
|
|
|
std::vector<x11::Atom> wm_states;
|
|
|
|
GetArrayProperty(static_cast<x11::Window>(GetAcceleratedWidget()),
|
|
|
|
x11::GetAtom("_NET_WM_STATE"), &wm_states);
|
|
|
|
return std::find(wm_states.begin(), wm_states.end(), sticky_atom) !=
|
|
|
|
wm_states.end();
|
|
|
|
}
|
2021-10-06 02:21:00 +00:00
|
|
|
#endif
|
2022-03-28 16:48:50 +00:00
|
|
|
return false;
|
2015-03-26 06:18:37 +00:00
|
|
|
}
|
|
|
|
|
2019-08-15 06:51:15 +00:00
|
|
|
content::DesktopMediaID NativeWindowViews::GetDesktopMediaID() const {
|
|
|
|
const gfx::AcceleratedWidget accelerated_widget = GetAcceleratedWidget();
|
|
|
|
content::DesktopMediaID::Id window_handle = content::DesktopMediaID::kNullId;
|
|
|
|
content::DesktopMediaID::Id aura_id = content::DesktopMediaID::kNullId;
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2019-08-15 06:51:15 +00:00
|
|
|
window_handle =
|
|
|
|
reinterpret_cast<content::DesktopMediaID::Id>(accelerated_widget);
|
2022-02-10 02:58:52 +00:00
|
|
|
#elif BUILDFLAG(IS_LINUX)
|
2020-06-22 17:35:10 +00:00
|
|
|
window_handle = static_cast<uint32_t>(accelerated_widget);
|
2019-08-15 06:51:15 +00:00
|
|
|
#endif
|
|
|
|
aura::WindowTreeHost* const host =
|
|
|
|
aura::WindowTreeHost::GetForAcceleratedWidget(accelerated_widget);
|
|
|
|
aura::Window* const aura_window = host ? host->window() : nullptr;
|
|
|
|
if (aura_window) {
|
|
|
|
aura_id = content::DesktopMediaID::RegisterNativeWindow(
|
|
|
|
content::DesktopMediaID::TYPE_WINDOW, aura_window)
|
|
|
|
.window_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
// No constructor to pass the aura_id. Make sure to not use the other
|
|
|
|
// constructor that has a third parameter, it is for yet another purpose.
|
|
|
|
content::DesktopMediaID result = content::DesktopMediaID(
|
|
|
|
content::DesktopMediaID::TYPE_WINDOW, window_handle);
|
|
|
|
|
|
|
|
// Confusing but this is how content::DesktopMediaID is designed. The id
|
|
|
|
// property is the window handle whereas the window_id property is an id
|
|
|
|
// given by a map containing all aura instances.
|
|
|
|
result.window_id = aura_id;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-05-21 18:57:19 +00:00
|
|
|
gfx::AcceleratedWidget NativeWindowViews::GetAcceleratedWidget() const {
|
2019-01-31 02:19:47 +00:00
|
|
|
if (GetNativeWindow() && GetNativeWindow()->GetHost())
|
|
|
|
return GetNativeWindow()->GetHost()->GetAcceleratedWidget();
|
|
|
|
else
|
|
|
|
return gfx::kNullAcceleratedWidget;
|
2014-07-21 14:03:58 +00:00
|
|
|
}
|
|
|
|
|
2018-12-11 17:45:55 +00:00
|
|
|
NativeWindowHandle NativeWindowViews::GetNativeWindowHandle() const {
|
|
|
|
return GetAcceleratedWidget();
|
2018-11-08 17:03:19 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 06:16:24 +00:00
|
|
|
gfx::Rect NativeWindowViews::ContentBoundsToWindowBounds(
|
|
|
|
const gfx::Rect& bounds) const {
|
|
|
|
if (!has_frame())
|
|
|
|
return bounds;
|
|
|
|
|
|
|
|
gfx::Rect window_bounds(bounds);
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2019-10-24 06:06:04 +00:00
|
|
|
if (widget()->non_client_view()) {
|
|
|
|
HWND hwnd = GetAcceleratedWidget();
|
|
|
|
gfx::Rect dpi_bounds = DIPToScreenRect(hwnd, bounds);
|
|
|
|
window_bounds = ScreenToDIPRect(
|
|
|
|
hwnd, widget()->non_client_view()->GetWindowBoundsForClientBounds(
|
|
|
|
dpi_bounds));
|
|
|
|
}
|
2018-02-22 06:16:24 +00:00
|
|
|
#endif
|
|
|
|
|
2018-05-01 04:28:22 +00:00
|
|
|
if (root_view_->HasMenu() && root_view_->IsMenuBarVisible()) {
|
|
|
|
int menu_bar_height = root_view_->GetMenuBarHeight();
|
|
|
|
window_bounds.set_y(window_bounds.y() - menu_bar_height);
|
|
|
|
window_bounds.set_height(window_bounds.height() + menu_bar_height);
|
2018-02-22 06:16:24 +00:00
|
|
|
}
|
|
|
|
return window_bounds;
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::Rect NativeWindowViews::WindowBoundsToContentBounds(
|
|
|
|
const gfx::Rect& bounds) const {
|
|
|
|
if (!has_frame())
|
|
|
|
return bounds;
|
|
|
|
|
|
|
|
gfx::Rect content_bounds(bounds);
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2018-02-22 06:16:24 +00:00
|
|
|
HWND hwnd = GetAcceleratedWidget();
|
2019-01-31 02:19:47 +00:00
|
|
|
content_bounds.set_size(DIPToScreenRect(hwnd, content_bounds).size());
|
2018-02-22 06:16:24 +00:00
|
|
|
RECT rect;
|
|
|
|
SetRectEmpty(&rect);
|
|
|
|
DWORD style = ::GetWindowLong(hwnd, GWL_STYLE);
|
|
|
|
DWORD ex_style = ::GetWindowLong(hwnd, GWL_EXSTYLE);
|
|
|
|
AdjustWindowRectEx(&rect, style, FALSE, ex_style);
|
|
|
|
content_bounds.set_width(content_bounds.width() - (rect.right - rect.left));
|
|
|
|
content_bounds.set_height(content_bounds.height() - (rect.bottom - rect.top));
|
2019-01-31 02:19:47 +00:00
|
|
|
content_bounds.set_size(ScreenToDIPRect(hwnd, content_bounds).size());
|
2018-02-22 06:16:24 +00:00
|
|
|
#endif
|
|
|
|
|
2018-05-01 04:28:22 +00:00
|
|
|
if (root_view_->HasMenu() && root_view_->IsMenuBarVisible()) {
|
|
|
|
int menu_bar_height = root_view_->GetMenuBarHeight();
|
|
|
|
content_bounds.set_y(content_bounds.y() + menu_bar_height);
|
|
|
|
content_bounds.set_height(content_bounds.height() - menu_bar_height);
|
2018-02-22 06:16:24 +00:00
|
|
|
}
|
|
|
|
return content_bounds;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NativeWindowViews::UpdateDraggableRegions(
|
2020-10-27 21:28:43 +00:00
|
|
|
const std::vector<mojom::DraggableRegionPtr>& regions) {
|
|
|
|
draggable_region_ = DraggableRegionsToSkRegion(regions);
|
2018-02-22 06:16:24 +00:00
|
|
|
}
|
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2016-05-31 08:47:45 +00:00
|
|
|
void NativeWindowViews::SetIcon(HICON window_icon, HICON app_icon) {
|
|
|
|
// We are responsible for storing the images.
|
|
|
|
window_icon_ = base::win::ScopedHICON(CopyIcon(window_icon));
|
|
|
|
app_icon_ = base::win::ScopedHICON(CopyIcon(app_icon));
|
|
|
|
|
2016-05-20 13:28:07 +00:00
|
|
|
HWND hwnd = GetAcceleratedWidget();
|
|
|
|
SendMessage(hwnd, WM_SETICON, ICON_SMALL,
|
2016-05-31 08:47:45 +00:00
|
|
|
reinterpret_cast<LPARAM>(window_icon_.get()));
|
2016-05-20 13:28:07 +00:00
|
|
|
SendMessage(hwnd, WM_SETICON, ICON_BIG,
|
2016-05-31 08:47:45 +00:00
|
|
|
reinterpret_cast<LPARAM>(app_icon_.get()));
|
2016-05-20 13:28:07 +00:00
|
|
|
}
|
2022-02-10 02:58:52 +00:00
|
|
|
#elif BUILDFLAG(IS_LINUX)
|
2016-05-20 13:22:15 +00:00
|
|
|
void NativeWindowViews::SetIcon(const gfx::ImageSkia& icon) {
|
2019-10-28 22:12:35 +00:00
|
|
|
auto* tree_host = views::DesktopWindowTreeHostLinux::GetHostForWidget(
|
|
|
|
GetAcceleratedWidget());
|
2020-03-18 00:31:31 +00:00
|
|
|
tree_host->SetWindowIcons(icon, {});
|
2016-05-20 13:22:15 +00:00
|
|
|
}
|
2016-05-20 13:28:07 +00:00
|
|
|
#endif
|
2016-05-20 13:22:15 +00:00
|
|
|
|
2018-04-25 06:59:16 +00:00
|
|
|
void NativeWindowViews::OnWidgetActivationChanged(views::Widget* changed_widget,
|
2018-04-18 01:55:30 +00:00
|
|
|
bool active) {
|
2018-04-25 06:59:16 +00:00
|
|
|
if (changed_widget != widget())
|
2014-07-08 04:55:33 +00:00
|
|
|
return;
|
|
|
|
|
2019-07-10 14:40:11 +00:00
|
|
|
if (active) {
|
|
|
|
MoveBehindTaskBarIfNeeded();
|
2018-09-07 18:21:58 +00:00
|
|
|
NativeWindow::NotifyWindowFocus();
|
2019-07-10 14:40:11 +00:00
|
|
|
} else {
|
2018-09-07 18:21:58 +00:00
|
|
|
NativeWindow::NotifyWindowBlur();
|
2019-07-10 14:40:11 +00:00
|
|
|
}
|
2014-08-07 06:02:03 +00:00
|
|
|
|
2014-08-07 06:48:02 +00:00
|
|
|
// Hide menu bar when window is blured.
|
2018-05-01 04:28:22 +00:00
|
|
|
if (!active && IsMenuBarAutoHide() && IsMenuBarVisible())
|
2014-08-07 06:02:03 +00:00
|
|
|
SetMenuBarVisibility(false);
|
2018-03-08 06:22:50 +00:00
|
|
|
|
2018-05-01 04:28:22 +00:00
|
|
|
root_view_->ResetAltState();
|
2014-07-08 04:55:33 +00:00
|
|
|
}
|
|
|
|
|
2018-04-25 06:59:16 +00:00
|
|
|
void NativeWindowViews::OnWidgetBoundsChanged(views::Widget* changed_widget,
|
2018-04-18 01:55:30 +00:00
|
|
|
const gfx::Rect& bounds) {
|
2018-04-25 06:59:16 +00:00
|
|
|
if (changed_widget != widget())
|
2015-05-09 15:55:10 +00:00
|
|
|
return;
|
|
|
|
|
2017-07-17 20:51:42 +00:00
|
|
|
// Note: We intentionally use `GetBounds()` instead of `bounds` to properly
|
|
|
|
// handle minimized windows on Windows.
|
|
|
|
const auto new_bounds = GetBounds();
|
|
|
|
if (widget_size_ != new_bounds.size()) {
|
2018-12-22 01:49:26 +00:00
|
|
|
int width_delta = new_bounds.width() - widget_size_.width();
|
|
|
|
int height_delta = new_bounds.height() - widget_size_.height();
|
|
|
|
for (NativeBrowserView* item : browser_views()) {
|
2020-10-26 18:56:31 +00:00
|
|
|
auto* native_view = static_cast<NativeBrowserViewViews*>(item);
|
2019-01-31 02:07:19 +00:00
|
|
|
native_view->SetAutoResizeProportions(widget_size_);
|
|
|
|
native_view->AutoResize(new_bounds, width_delta, height_delta);
|
2017-07-17 18:46:31 +00:00
|
|
|
}
|
|
|
|
|
2015-05-09 15:55:10 +00:00
|
|
|
NotifyWindowResize();
|
2017-07-17 20:51:42 +00:00
|
|
|
widget_size_ = new_bounds.size();
|
2015-05-09 15:55:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-14 19:30:08 +00:00
|
|
|
void NativeWindowViews::OnWidgetDestroying(views::Widget* widget) {
|
|
|
|
aura::Window* window = GetNativeWindow();
|
|
|
|
if (window)
|
|
|
|
window->RemovePreTargetHandler(this);
|
|
|
|
}
|
|
|
|
|
2021-01-19 02:37:21 +00:00
|
|
|
void NativeWindowViews::OnWidgetDestroyed(views::Widget* changed_widget) {
|
|
|
|
widget_destroyed_ = true;
|
|
|
|
}
|
|
|
|
|
2014-07-03 17:30:36 +00:00
|
|
|
views::View* NativeWindowViews::GetInitiallyFocusedView() {
|
2018-03-06 07:05:31 +00:00
|
|
|
return focused_view_;
|
2014-07-03 17:30:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool NativeWindowViews::CanMaximize() const {
|
2016-01-23 10:23:18 +00:00
|
|
|
return resizable_ && maximizable_;
|
2014-07-03 17:30:36 +00:00
|
|
|
}
|
|
|
|
|
2014-12-16 00:46:37 +00:00
|
|
|
bool NativeWindowViews::CanMinimize() const {
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2016-01-18 22:46:35 +00:00
|
|
|
return minimizable_;
|
2022-02-10 02:58:52 +00:00
|
|
|
#elif BUILDFLAG(IS_LINUX)
|
2014-12-16 00:46:37 +00:00
|
|
|
return true;
|
2016-01-18 22:46:35 +00:00
|
|
|
#endif
|
2014-12-16 00:46:37 +00:00
|
|
|
}
|
|
|
|
|
2021-03-16 16:18:45 +00:00
|
|
|
std::u16string NativeWindowViews::GetWindowTitle() const {
|
2014-07-03 17:30:36 +00:00
|
|
|
return base::UTF8ToUTF16(title_);
|
|
|
|
}
|
|
|
|
|
|
|
|
views::View* NativeWindowViews::GetContentsView() {
|
2018-05-01 04:28:22 +00:00
|
|
|
return root_view_.get();
|
2014-07-03 17:30:36 +00:00
|
|
|
}
|
|
|
|
|
2014-07-07 07:35:16 +00:00
|
|
|
bool NativeWindowViews::ShouldDescendIntoChildForEventHandling(
|
|
|
|
gfx::NativeView child,
|
|
|
|
const gfx::Point& location) {
|
2020-12-01 23:03:00 +00:00
|
|
|
// App window should claim mouse events that fall within any BrowserViews'
|
|
|
|
// draggable region.
|
|
|
|
for (auto* view : browser_views()) {
|
|
|
|
auto* native_view = static_cast<NativeBrowserViewViews*>(view);
|
|
|
|
auto* view_draggable_region = native_view->draggable_region();
|
|
|
|
if (view_draggable_region &&
|
|
|
|
view_draggable_region->contains(location.x(), location.y()))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-07-07 07:35:16 +00:00
|
|
|
// App window should claim mouse events that fall within the draggable region.
|
2015-08-05 04:32:22 +00:00
|
|
|
if (draggable_region() &&
|
|
|
|
draggable_region()->contains(location.x(), location.y()))
|
2014-07-07 14:39:39 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// And the events on border for dragging resizable frameless window.
|
2022-01-26 21:59:09 +00:00
|
|
|
if ((!has_frame() || has_client_frame()) && resizable_) {
|
2020-10-26 18:56:31 +00:00
|
|
|
auto* frame =
|
2018-04-25 06:59:16 +00:00
|
|
|
static_cast<FramelessView*>(widget()->non_client_view()->frame_view());
|
2014-07-07 14:39:39 +00:00
|
|
|
return frame->ResizingBorderHitTest(location) == HTNOWHERE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2014-07-07 07:35:16 +00:00
|
|
|
}
|
|
|
|
|
2014-07-03 17:30:36 +00:00
|
|
|
views::ClientView* NativeWindowViews::CreateClientView(views::Widget* widget) {
|
2018-05-01 04:28:22 +00:00
|
|
|
return new NativeWindowClientView(widget, root_view_.get(), this);
|
2014-07-03 17:30:36 +00:00
|
|
|
}
|
|
|
|
|
2020-07-14 01:13:34 +00:00
|
|
|
std::unique_ptr<views::NonClientFrameView>
|
|
|
|
NativeWindowViews::CreateNonClientFrameView(views::Widget* widget) {
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2020-07-14 01:13:34 +00:00
|
|
|
auto frame_view = std::make_unique<WinFrameView>();
|
2014-11-12 06:33:30 +00:00
|
|
|
frame_view->Init(this, widget);
|
|
|
|
return frame_view;
|
|
|
|
#else
|
2022-01-26 21:59:09 +00:00
|
|
|
if (has_frame() && !has_client_frame()) {
|
2020-07-14 01:13:34 +00:00
|
|
|
return std::make_unique<NativeFrameView>(this, widget);
|
2014-07-24 10:06:27 +00:00
|
|
|
} else {
|
2022-01-26 21:59:09 +00:00
|
|
|
auto frame_view = has_frame() && has_client_frame()
|
|
|
|
? std::make_unique<ClientFrameViewLinux>()
|
|
|
|
: std::make_unique<FramelessView>();
|
2014-07-24 10:06:27 +00:00
|
|
|
frame_view->Init(this, widget);
|
|
|
|
return frame_view;
|
|
|
|
}
|
|
|
|
#endif
|
2014-07-04 04:32:03 +00:00
|
|
|
}
|
|
|
|
|
2015-05-10 03:44:18 +00:00
|
|
|
void NativeWindowViews::OnWidgetMove() {
|
|
|
|
NotifyWindowMove();
|
|
|
|
}
|
|
|
|
|
2014-07-04 08:54:10 +00:00
|
|
|
void NativeWindowViews::HandleKeyboardEvent(
|
|
|
|
content::WebContents*,
|
|
|
|
const content::NativeWebKeyboardEvent& event) {
|
2021-01-19 02:37:21 +00:00
|
|
|
if (widget_destroyed_)
|
|
|
|
return;
|
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_LINUX)
|
2018-12-05 17:35:59 +00:00
|
|
|
if (event.windows_key_code == ui::VKEY_BROWSER_BACK)
|
|
|
|
NotifyWindowExecuteAppCommand(kBrowserBackward);
|
|
|
|
else if (event.windows_key_code == ui::VKEY_BROWSER_FORWARD)
|
|
|
|
NotifyWindowExecuteAppCommand(kBrowserForward);
|
|
|
|
#endif
|
|
|
|
|
2018-05-01 04:28:22 +00:00
|
|
|
keyboard_event_handler_->HandleKeyboardEvent(event,
|
|
|
|
root_view_->GetFocusManager());
|
|
|
|
root_view_->HandleKeyEvent(event);
|
2014-07-04 08:54:10 +00:00
|
|
|
}
|
|
|
|
|
2018-12-05 17:35:59 +00:00
|
|
|
void NativeWindowViews::OnMouseEvent(ui::MouseEvent* event) {
|
|
|
|
if (event->type() != ui::ET_MOUSE_PRESSED)
|
|
|
|
return;
|
|
|
|
|
2021-06-01 08:42:47 +00:00
|
|
|
// Alt+Click should not toggle menu bar.
|
|
|
|
root_view_->ResetAltState();
|
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_LINUX)
|
2018-12-05 17:35:59 +00:00
|
|
|
if (event->changed_button_flags() == ui::EF_BACK_MOUSE_BUTTON)
|
|
|
|
NotifyWindowExecuteAppCommand(kBrowserBackward);
|
|
|
|
else if (event->changed_button_flags() == ui::EF_FORWARD_MOUSE_BUTTON)
|
|
|
|
NotifyWindowExecuteAppCommand(kBrowserForward);
|
|
|
|
#endif
|
2021-06-01 08:42:47 +00:00
|
|
|
}
|
2018-12-05 17:35:59 +00:00
|
|
|
|
2015-03-26 08:39:03 +00:00
|
|
|
ui::WindowShowState NativeWindowViews::GetRestoredState() {
|
2021-09-07 08:18:43 +00:00
|
|
|
if (IsMaximized()) {
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2021-09-07 08:18:43 +00:00
|
|
|
// Only restore Maximized state when window is NOT transparent style
|
|
|
|
if (!transparent()) {
|
|
|
|
return ui::SHOW_STATE_MAXIMIZED;
|
|
|
|
}
|
|
|
|
#else
|
2015-03-26 08:39:03 +00:00
|
|
|
return ui::SHOW_STATE_MAXIMIZED;
|
2021-09-07 08:18:43 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-03-26 08:39:03 +00:00
|
|
|
if (IsFullscreen())
|
|
|
|
return ui::SHOW_STATE_FULLSCREEN;
|
|
|
|
|
|
|
|
return ui::SHOW_STATE_NORMAL;
|
|
|
|
}
|
|
|
|
|
2019-07-10 14:40:11 +00:00
|
|
|
void NativeWindowViews::MoveBehindTaskBarIfNeeded() {
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2019-07-10 14:40:11 +00:00
|
|
|
if (behind_task_bar_) {
|
|
|
|
const HWND task_bar_hwnd = ::FindWindow(kUniqueTaskBarClassName, nullptr);
|
|
|
|
::SetWindowPos(GetAcceleratedWidget(), task_bar_hwnd, 0, 0, 0, 0,
|
|
|
|
SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
// TODO(julien.isorce): Implement X11 case.
|
|
|
|
}
|
|
|
|
|
2014-07-03 17:30:36 +00:00
|
|
|
// static
|
2019-10-25 13:03:28 +00:00
|
|
|
NativeWindow* NativeWindow::Create(const gin_helper::Dictionary& options,
|
2018-04-08 11:20:43 +00:00
|
|
|
NativeWindow* parent) {
|
|
|
|
return new NativeWindowViews(options, parent);
|
2014-07-03 17:30:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace electron
|