Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not use CONTEXT_MENU flag for tray menu (reland) #24194

Merged
merged 2 commits into from
Jun 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions patches/chromium/.patches
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,4 @@ fix_handling_non_client_pointer_events_from_pen_on_windows_10.patch
a11y_iterate_all_descendants_for_getselectioncount.patch
allow_ime_to_insert_zero-length_composition_string.patch
cherry-pick-eac3d9283d11.patch
remove_menu_window_task_item.patch
20 changes: 20 additions & 0 deletions patches/chromium/remove_menu_window_task_item.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Cheng Zhao <zcbenz@gmail.com>
Date: Thu, 4 Oct 2018 14:57:02 -0700
Subject: fix: remove menu window from taskbar

Refs https://chromium-review.googlesource.com/c/chromium/src/+/2245941

diff --git a/ui/views/widget/widget_hwnd_utils.cc b/ui/views/widget/widget_hwnd_utils.cc
index 40e66a212e3ea158b61f11d804a3c1644023b2d7..89f5b62f95dfec59bacf79f33895438039fac1c5 100644
--- a/ui/views/widget/widget_hwnd_utils.cc
+++ b/ui/views/widget/widget_hwnd_utils.cc
@@ -118,6 +118,8 @@ void CalculateWindowStylesFromInitParams(
else
*style |= WS_BORDER;
}
+ if (!params.force_show_in_taskbar)
+ *ex_style |= WS_EX_TOOLWINDOW;
break;
case Widget::InitParams::TYPE_TOOLTIP:
*style |= WS_POPUP;
35 changes: 5 additions & 30 deletions shell/browser/ui/win/notify_icon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/image/image.h"
#include "ui/views/controls/menu/menu_runner.h"
#include "ui/views/widget/widget.h"

namespace {

Expand All @@ -44,11 +43,7 @@ UINT ConvertIconType(electron::TrayIcon::IconType type) {
namespace electron {

NotifyIcon::NotifyIcon(NotifyIconHost* host, UINT id, HWND window, UINT message)
: host_(host),
icon_id_(id),
window_(window),
message_id_(message),
weak_factory_(this) {
: host_(host), icon_id_(id), window_(window), message_id_(message) {
NOTIFYICONDATA icon_data;
InitIconData(&icon_data);
icon_data.uFlags |= NIF_MESSAGE;
Expand Down Expand Up @@ -207,26 +202,10 @@ void NotifyIcon::PopUpContextMenu(const gfx::Point& pos,
if (pos.IsOrigin())
rect.set_origin(display::Screen::GetScreen()->GetCursorScreenPoint());

// Create a widget for the menu, otherwise we get no keyboard events, which
// is required for accessibility.
widget_.reset(new views::Widget());
views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP);
params.ownership =
views::Widget::InitParams::Ownership::WIDGET_OWNS_NATIVE_WIDGET;
params.bounds = gfx::Rect(0, 0, 0, 0);
params.force_software_compositing = true;
params.z_order = ui::ZOrderLevel::kFloatingUIElement;

widget_->Init(std::move(params));

widget_->Show();
widget_->Activate();
menu_runner_.reset(new views::MenuRunner(
menu_model != nullptr ? menu_model : menu_model_,
views::MenuRunner::CONTEXT_MENU | views::MenuRunner::HAS_MNEMONICS,
base::BindRepeating(&NotifyIcon::OnContextMenuClosed,
weak_factory_.GetWeakPtr())));
menu_runner_->RunMenuAt(widget_.get(), NULL, rect,
menu_runner_.reset(
new views::MenuRunner(menu_model != nullptr ? menu_model : menu_model_,
views::MenuRunner::HAS_MNEMONICS));
menu_runner_->RunMenuAt(nullptr, nullptr, rect,
views::MenuAnchorPosition::kTopLeft,
ui::MENU_SOURCE_MOUSE);
}
Expand Down Expand Up @@ -254,8 +233,4 @@ void NotifyIcon::InitIconData(NOTIFYICONDATA* icon_data) {
icon_data->uID = icon_id_;
}

void NotifyIcon::OnContextMenuClosed() {
widget_->Close();
}

} // namespace electron
11 changes: 1 addition & 10 deletions shell/browser/ui/win/notify_icon.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

#include "base/compiler_specific.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/win/scoped_gdi_object.h"
#include "shell/browser/ui/tray_icon.h"

Expand All @@ -24,8 +23,7 @@ class Point;

namespace views {
class MenuRunner;
class Widget;
} // namespace views
}

namespace electron {

Expand Down Expand Up @@ -68,7 +66,6 @@ class NotifyIcon : public TrayIcon {

private:
void InitIconData(NOTIFYICONDATA* icon_data);
void OnContextMenuClosed();

// The tray that owns us. Weak.
NotifyIconHost* host_;
Expand All @@ -91,12 +88,6 @@ class NotifyIcon : public TrayIcon {
// Context menu associated with this icon (if any).
std::unique_ptr<views::MenuRunner> menu_runner_;

// Temporary widget for the context menu, needed for keyboard event capture.
std::unique_ptr<views::Widget> widget_;

// WeakPtrFactory for CloseClosure safety.
base::WeakPtrFactory<NotifyIcon> weak_factory_;

DISALLOW_COPY_AND_ASSIGN(NotifyIcon);
};

Expand Down