fix_remove_caption-removing_style_call.patch 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Raymond Zhao <[email protected]>
  3. Date: Wed, 17 Aug 2022 13:49:40 -0700
  4. Subject: fix: Adjust caption-removing style call
  5. There is a SetWindowLong call that removes WS_CAPTION for frameless
  6. windows, but Electron uses WS_CAPTION even for frameless windows,
  7. unless they are transparent.
  8. Changing this call only affects frameless windows, and it fixes
  9. a visual glitch where they showed a Windows 7 style frame
  10. during startup.
  11. The if statement was originally introduced by
  12. https://codereview.chromium.org/9372053/, and it was there to fix
  13. a visual glitch with the close button showing up during startup
  14. or resizing, but Electron does not seem to run into that issue
  15. for opaque frameless windows even with that block commented out.
  16. diff --git a/ui/views/win/hwnd_message_handler.cc b/ui/views/win/hwnd_message_handler.cc
  17. index 759f00dd4e674d1dfca690b82e6e1820900ebf0c..9888ac709c51cd30228e3bca6915f7d89071cb83 100644
  18. --- a/ui/views/win/hwnd_message_handler.cc
  19. +++ b/ui/views/win/hwnd_message_handler.cc
  20. @@ -1786,7 +1786,23 @@ LRESULT HWNDMessageHandler::OnCreate(CREATESTRUCT* create_struct) {
  21. SendMessage(hwnd(), WM_CHANGEUISTATE, MAKELPARAM(UIS_CLEAR, UISF_HIDEFOCUS),
  22. 0);
  23. - if (!delegate_->HasFrame()) {
  24. + LONG is_popup =
  25. + GetWindowLong(hwnd(), GWL_STYLE) & static_cast<LONG>(WS_POPUP);
  26. +
  27. + // For transparent windows, Electron removes the WS_CAPTION style,
  28. + // so we continue to remove it here. If we didn't, an opaque rectangle
  29. + // would show up.
  30. + // For non-transparent windows, Electron keeps the WS_CAPTION style,
  31. + // so we don't remove it in that case. If we did, a Windows 7 frame
  32. + // would show up.
  33. + // We also need this block for frameless popup windows. When the user opens
  34. + // a dropdown in an Electron app, the internal popup menu from
  35. + // third_party/blink/renderer/core/html/forms/internal_popup_menu.h
  36. + // is rendered. That menu is actually an HTML page inside of a frameless popup window.
  37. + // A new popup window is created every time the user opens the dropdown,
  38. + // and this code path is run. The code block below runs SendFrameChanged,
  39. + // which gives the dropdown options the proper layout.
  40. + if (!delegate_->HasFrame() && (is_translucent_ || is_popup)) {
  41. SetWindowLong(hwnd(), GWL_STYLE,
  42. GetWindowLong(hwnd(), GWL_STYLE) & ~WS_CAPTION);
  43. SendFrameChanged();