Skip to content

Commit 2376c45

Browse files
authored
fix: do not use CONTEXT_MENU flag for tray menu (reland) (electron#24097)
* fix: do not use CONTEXT_MENU flag for tray menu * fix: menu window should not appear in taskbar
1 parent b665eb6 commit 2376c45

File tree

4 files changed

+27
-40
lines changed

4 files changed

+27
-40
lines changed

patches/chromium/.patches

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,4 @@ fix_swap_global_proxies_before_initializing_the_windows_proxies.patch
101101
fix_default_to_ntlm_v2_in_network_service.patch
102102
feat_add_streaming-protocol_registry_to_multibuffer_data_source.patch
103103
fix_handling_non_client_pointer_events_from_pen_on_windows_10.patch
104+
remove_menu_window_task_item.patch
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: Cheng Zhao <zcbenz@gmail.com>
3+
Date: Thu, 4 Oct 2018 14:57:02 -0700
4+
Subject: fix: remove menu window from taskbar
5+
6+
Refs https://chromium-review.googlesource.com/c/chromium/src/+/2245941
7+
8+
diff --git a/ui/views/widget/widget_hwnd_utils.cc b/ui/views/widget/widget_hwnd_utils.cc
9+
index 40e66a212e3ea158b61f11d804a3c1644023b2d7..89f5b62f95dfec59bacf79f33895438039fac1c5 100644
10+
--- a/ui/views/widget/widget_hwnd_utils.cc
11+
+++ b/ui/views/widget/widget_hwnd_utils.cc
12+
@@ -118,6 +118,8 @@ void CalculateWindowStylesFromInitParams(
13+
else
14+
*style |= WS_BORDER;
15+
}
16+
+ if (!params.force_show_in_taskbar)
17+
+ *ex_style |= WS_EX_TOOLWINDOW;
18+
break;
19+
case Widget::InitParams::TYPE_TOOLTIP:
20+
*style |= WS_POPUP;

shell/browser/ui/win/notify_icon.cc

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include "ui/gfx/geometry/rect.h"
1919
#include "ui/gfx/image/image.h"
2020
#include "ui/views/controls/menu/menu_runner.h"
21-
#include "ui/views/widget/widget.h"
2221

2322
namespace {
2423

@@ -49,11 +48,7 @@ NotifyIcon::NotifyIcon(NotifyIconHost* host,
4948
HWND window,
5049
UINT message,
5150
GUID guid)
52-
: host_(host),
53-
icon_id_(id),
54-
window_(window),
55-
message_id_(message),
56-
weak_factory_(this) {
51+
: host_(host), icon_id_(id), window_(window), message_id_(message) {
5752
guid_ = guid;
5853
is_using_guid_ = guid != GUID_DEFAULT;
5954
NOTIFYICONDATA icon_data;
@@ -213,26 +208,10 @@ void NotifyIcon::PopUpContextMenu(const gfx::Point& pos,
213208
if (pos.IsOrigin())
214209
rect.set_origin(display::Screen::GetScreen()->GetCursorScreenPoint());
215210

216-
// Create a widget for the menu, otherwise we get no keyboard events, which
217-
// is required for accessibility.
218-
widget_.reset(new views::Widget());
219-
views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP);
220-
params.ownership =
221-
views::Widget::InitParams::Ownership::WIDGET_OWNS_NATIVE_WIDGET;
222-
params.bounds = gfx::Rect(0, 0, 0, 0);
223-
params.force_software_compositing = true;
224-
params.z_order = ui::ZOrderLevel::kFloatingUIElement;
225-
226-
widget_->Init(std::move(params));
227-
228-
widget_->Show();
229-
widget_->Activate();
230-
menu_runner_.reset(new views::MenuRunner(
231-
menu_model != nullptr ? menu_model : menu_model_,
232-
views::MenuRunner::CONTEXT_MENU | views::MenuRunner::HAS_MNEMONICS,
233-
base::BindRepeating(&NotifyIcon::OnContextMenuClosed,
234-
weak_factory_.GetWeakPtr())));
235-
menu_runner_->RunMenuAt(widget_.get(), NULL, rect,
211+
menu_runner_.reset(
212+
new views::MenuRunner(menu_model != nullptr ? menu_model : menu_model_,
213+
views::MenuRunner::HAS_MNEMONICS));
214+
menu_runner_->RunMenuAt(nullptr, nullptr, rect,
236215
views::MenuAnchorPosition::kTopLeft,
237216
ui::MENU_SOURCE_MOUSE);
238217
}
@@ -273,8 +252,4 @@ void NotifyIcon::InitIconData(NOTIFYICONDATA* icon_data) {
273252
}
274253
}
275254

276-
void NotifyIcon::OnContextMenuClosed() {
277-
widget_->Close();
278-
}
279-
280255
} // namespace electron

shell/browser/ui/win/notify_icon.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
#include "base/compiler_specific.h"
1616
#include "base/macros.h"
17-
#include "base/memory/weak_ptr.h"
1817
#include "base/win/scoped_gdi_object.h"
1918
#include "shell/browser/ui/tray_icon.h"
2019
#include "shell/browser/ui/win/notify_icon_host.h"
@@ -25,8 +24,7 @@ class Point;
2524

2625
namespace views {
2726
class MenuRunner;
28-
class Widget;
29-
} // namespace views
27+
}
3028

3129
namespace electron {
3230

@@ -75,7 +73,6 @@ class NotifyIcon : public TrayIcon {
7573

7674
private:
7775
void InitIconData(NOTIFYICONDATA* icon_data);
78-
void OnContextMenuClosed();
7976

8077
// The tray that owns us. Weak.
8178
NotifyIconHost* host_;
@@ -104,12 +101,6 @@ class NotifyIcon : public TrayIcon {
104101
// Context menu associated with this icon (if any).
105102
std::unique_ptr<views::MenuRunner> menu_runner_;
106103

107-
// Temporary widget for the context menu, needed for keyboard event capture.
108-
std::unique_ptr<views::Widget> widget_;
109-
110-
// WeakPtrFactory for CloseClosure safety.
111-
base::WeakPtrFactory<NotifyIcon> weak_factory_;
112-
113104
DISALLOW_COPY_AND_ASSIGN(NotifyIcon);
114105
};
115106

0 commit comments

Comments
 (0)