fix: Alt+Click should not toggle menu bar (#29318)

This commit is contained in:
Cheng Zhao 2021-06-01 17:42:47 +09:00 committed by GitHub
parent 19dce8caa5
commit 0444d74830
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 10 deletions

View file

@ -331,12 +331,12 @@ NativeWindowViews::NativeWindowViews(const gin_helper::Dictionary& options,
last_window_state_ = ui::SHOW_STATE_NORMAL; last_window_state_ = ui::SHOW_STATE_NORMAL;
#endif #endif
#if defined(OS_LINUX) // Listen to mouse events.
// Listen to move events.
aura::Window* window = GetNativeWindow(); aura::Window* window = GetNativeWindow();
if (window) if (window)
window->AddPreTargetHandler(this); window->AddPreTargetHandler(this);
#if defined(OS_LINUX)
// On linux after the widget is initialized we might have to force set the // On linux after the widget is initialized we might have to force set the
// bounds if the bounds are smaller than the current display // bounds if the bounds are smaller than the current display
SetBounds(gfx::Rect(GetPosition(), bounds.size()), false); SetBounds(gfx::Rect(GetPosition(), bounds.size()), false);
@ -351,11 +351,9 @@ NativeWindowViews::~NativeWindowViews() {
SetForwardMouseMessages(false); SetForwardMouseMessages(false);
#endif #endif
#if defined(OS_LINUX)
aura::Window* window = GetNativeWindow(); aura::Window* window = GetNativeWindow();
if (window) if (window)
window->RemovePreTargetHandler(this); window->RemovePreTargetHandler(this);
#endif
} }
void NativeWindowViews::SetGTKDarkThemeEnabled(bool use_dark_theme) { void NativeWindowViews::SetGTKDarkThemeEnabled(bool use_dark_theme) {
@ -1460,11 +1458,9 @@ void NativeWindowViews::OnWidgetBoundsChanged(views::Widget* changed_widget,
} }
void NativeWindowViews::OnWidgetDestroying(views::Widget* widget) { void NativeWindowViews::OnWidgetDestroying(views::Widget* widget) {
#if defined(OS_LINUX)
aura::Window* window = GetNativeWindow(); aura::Window* window = GetNativeWindow();
if (window) if (window)
window->RemovePreTargetHandler(this); window->RemovePreTargetHandler(this);
#endif
} }
void NativeWindowViews::OnWidgetDestroyed(views::Widget* changed_widget) { void NativeWindowViews::OnWidgetDestroyed(views::Widget* changed_widget) {
@ -1582,17 +1578,20 @@ void NativeWindowViews::HandleKeyboardEvent(
root_view_->HandleKeyEvent(event); root_view_->HandleKeyEvent(event);
} }
#if defined(OS_LINUX)
void NativeWindowViews::OnMouseEvent(ui::MouseEvent* event) { void NativeWindowViews::OnMouseEvent(ui::MouseEvent* event) {
if (event->type() != ui::ET_MOUSE_PRESSED) if (event->type() != ui::ET_MOUSE_PRESSED)
return; return;
// Alt+Click should not toggle menu bar.
root_view_->ResetAltState();
#if defined(OS_LINUX)
if (event->changed_button_flags() == ui::EF_BACK_MOUSE_BUTTON) if (event->changed_button_flags() == ui::EF_BACK_MOUSE_BUTTON)
NotifyWindowExecuteAppCommand(kBrowserBackward); NotifyWindowExecuteAppCommand(kBrowserBackward);
else if (event->changed_button_flags() == ui::EF_FORWARD_MOUSE_BUTTON) else if (event->changed_button_flags() == ui::EF_FORWARD_MOUSE_BUTTON)
NotifyWindowExecuteAppCommand(kBrowserForward); NotifyWindowExecuteAppCommand(kBrowserForward);
}
#endif #endif
}
ui::WindowShowState NativeWindowViews::GetRestoredState() { ui::WindowShowState NativeWindowViews::GetRestoredState() {
if (IsMaximized()) if (IsMaximized())

View file

@ -224,10 +224,8 @@ class NativeWindowViews : public NativeWindow,
content::WebContents*, content::WebContents*,
const content::NativeWebKeyboardEvent& event) override; const content::NativeWebKeyboardEvent& event) override;
#if defined(OS_LINUX)
// ui::EventHandler: // ui::EventHandler:
void OnMouseEvent(ui::MouseEvent* event) override; void OnMouseEvent(ui::MouseEvent* event) override;
#endif
// Returns the restore state for the window. // Returns the restore state for the window.
ui::WindowShowState GetRestoredState(); ui::WindowShowState GetRestoredState();