8000 fix: hover state bug when BrowserWindow is not resizable by sssooonnnggg · Pull Request #29721 · electron/electron · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: hover state bug when BrowserWindow is not resizable #29721

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

Merged
merged 1 commit into from
Jun 21, 2021

Conversation

sssooonnnggg
Copy link
Contributor
@sssooonnnggg sssooonnnggg commented Jun 16, 2021

Fix bug : when BrowserWindow is not resizable, the hover state of DOM element may not be cleared.

#611

Notes: fix hover state not clear bug when BrowserWindow is not resizable

@welcome
Copy link
welcome bot commented Jun 16, 2021

💖 Thanks for opening this pull request! 💖

We use semantic commit messages to streamline the release process. Before your pull request can be merged, you should update your pull request title to start with a semantic prefix.

Examples of commit messages with semantic prefixes:

  • fix: don't 8000 overwrite prevent_default if default wasn't prevented
  • feat: add app.isPackaged() method
  • docs: app.isDefaultProtocolClient is now available on Linux

Things that will help get your PR across the finish line:

  • Follow the JavaScript, C++, and Python coding style.
  • Run npm run lint locally to catch formatting errors earlier.
  • Document any user-facing changes you've made following the documentation styleguide.
  • Include tests when adding/changing behavior.
  • Include screenshots and animated GIFs whenever possible.

We get a lot of pull requests on this repo, so please be patient and we will get back to you as soon as we can.

@sssooonnnggg
Copy link
Contributor Author

我英文不太好,尝试解释一下 bug 产生的细节:

经研究发现:

shell/browser/ui/views/frameless_view.cc 里的处理有问题:

当 resizable 设置为 false 时,鼠标经过窗口边缘时(窗口边缘设置为5个像素[kResizeInsideBoundsSize]), 调用 FramelessView::ResizingBorderHitTest 时返回了 HTBORDER。

这会导致 Windows 误以为鼠标离开了窗口区域,从而向窗口发送了一个 WM_MOUSELEAVE 事件,实际上鼠标依然在窗口内。

chromium 在 legacy_render_widget_host_win.cc 里处理 WM_MOUSELEAVE 时,会通过 ::GetCursorPos()::WindowFromPoint() 来获取鼠标当前所在窗口 :

LRESULT LegacyRenderWidgetHostHWND::OnMouseLeave(UINT message,
                                                 WPARAM w_param,
                                                 LPARAM l_param) {
  mouse_tracking_enabled_ = false;
  LRESULT ret = 0;
  HWND capture_window = ::GetCapture();
  if ((capture_window != GetParent()) && GetWindowEventTarget(GetParent())) {
    // We should send a WM_MOUSELEAVE to the parent window only if the mouse
    // has moved outside the bounds of the parent.
    POINT cursor_pos;
    ::GetCursorPos(&cursor_pos);

    // WindowFromPoint returns the top-most HWND. As hwnd() may not
    // respond with HTTRANSPARENT to a WM_NCHITTEST message,
    // it may be returned.
    HWND window_from_point = ::WindowFromPoint(cursor_pos);
    if (window_from_point != GetParent() &&
        (capture_window || window_from_point != hwnd())) {
      bool msg_handled = false;
      ret = GetWindowEventTarget(GetParent())->HandleMouseMessage(
          message, w_param, l_param, &msg_handled);
      SetMsgHandled(msg_handled);
    }
  }
  return ret;
}

此时因为 WM_NCHITTEST 返回了 HTBORDER,因此虽然触发了 WM_MOUSELEAVE,但是鼠标仍然在窗口内部。

所以会导致 window_from_point != hwnd() 这个条件不会满足,进而 GetParent())->HandleMouseMessage(message, w_param, l_param, &msg_handled) 这个函数不会被执行,从而导致 DOM 的 hover 状态不会被清除。

所以当 BrowserWindow 的 resizable 属性设置为 false 时,NCHitTest 应该返回 HTCLIENT,这样才能让 Windows 在鼠标真正离开窗口时触发 WM_MOUSELEAVE,解决 hover 状态清除不掉的问题。

8000
@codebytere codebytere changed the title fix: fix hover state bug when BrowserWindow is not resizable (#611) fix: fix hover state bug when BrowserWindow is not resizable Jun 16, 2021
@sssooonnnggg
Copy link
Contributor Author

I am a new comer as an electron contributor, can anyone tell me why the linux build failed please ? I haven't comitted any code associated with linux

@zcbenz zcbenz added semver/patch backwards-compatible bug fixes target/12-x-y labels Jun 17, 2021
@electron-cation electron-cation bot removed the new-pr 🌱 PR opened recently label Jun 17, 2021
@zcbenz
Copy link
Contributor
zcbenz commented Jun 17, 2021

I am a new comer as an electron contributor, can anyone tell me why the linux build failed please ? I haven't comitted any code associated with linux

Our CI is not very stable recently and I think the failure is not related to this PR.

@sssooonnnggg
Copy link
Contributor Author

I am a new comer as an electron contributor, can anyone tell me why the linux build failed please ? I haven't comitted any code associated with linux

Our CI is not very stable recently and I think the failure is not related to this PR.

OK, thank you for the reply 😄

@sssooonnnggg sssooonnnggg reopened this Jun 17, 2021
@codebytere codebytere changed the title fix: fix hover state bug when BrowserWindow is not resizable fix: hover state bug when BrowserWindow is not resizable Jun 17, 2021
@zcbenz zcbenz merged commit e54667e into electron:main Jun 21, 2021
@welcome
Copy link
welcome bot commented Jun 21, 2021

Congrats on merging your first pull request! 🎉🎉🎉

@release-clerk
Copy link
release-clerk bot commented Jun 21, 2021

Release Notes Persisted

fix hover state not clear bug when BrowserWindow is not resizable

@trop
Copy link
Contributor
trop bot commented Jun 21, 2021

I have automatically backported this PR to "12-x-y", please check out #29799

@trop
Copy link
Contributor
trop bot commented Jun 21, 2021

I have automatically backported this PR to "13-x-y", please check out #29800

@trop
Copy link
Contributor
trop bot commented Jun 21, 2021

I have automatically backported this PR to "14-x-y", please check out #29801

gerhardberger pushed a commit to gerhardberger/electron that referenced this pull request Dec 26, 2021
…resizable (electron#611) (electron#29721)"

This reverts commit e54667e.

Around allows interactions within the non-client region so that the
floating window allows dragging. This also affects modals which
are not resizable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver/patch backwards-compatible bug fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0