Repository: electron/electron
File: shell/browser/ui/win/electron_desktop_window_tree_host_win.cc (C++)

Code before:
    }
    return prevent_default;
  }

  return views::DesktopWindowTreeHostWin::HandleMouseEvent(event);
}

bool ElectronDesktopWindowTreeHostWin::HandleIMEMessage(UINT message,
                                                        WPARAM w_param,
                                                        LPARAM l_param,
                                                        LRESULT* result) {
  if ((message == WM_SYSCHAR) && (w_param == VK_SPACE)) {
    if (native_window_view_->widget() &&
        native_window_view_->widget()->non_client_view()) {
      const auto* frame =
          native_window_view_->widget()->non_client_view()->frame_view();
      auto location = frame->GetSystemMenuScreenPixelLocation();

      bool prevent_default = false;
      native_window_view_->NotifyWindowSystemContextMenu(
          location.x(), location.y(), &prevent_default);

      if (!prevent_default)
        views::DesktopWindowTreeHostWin::HandleIMEMessage(message, w_param,
                                                          l_param, result);
      return prevent_default;
    }
  }

  return views::DesktopWindowTreeHostWin::HandleIMEMessage(message, w_param,
                                                           l_param, result);
}

void ElectronDesktopWindowTreeHostWin::HandleVisibilityChanged(bool visible) {
  if (native_window_view_->widget())
    native_window_view_->widget()->OnNativeWidgetVisibilityChanged(visible);

  if (visible)
    UpdateAllowScreenshots();
}

void ElectronDesktopWindowTreeHostWin::SetAllowScreenshots(bool allow) {
  if (allow_screenshots_ == allow)
    return;

  allow_screenshots_ = allow;

  // If the window is not visible, do not set the window display affinity
  // because `SetWindowDisplayAffinity` will attempt to compose the window,
  if (!IsVisible())
    return;

Review comment (bug):
I am not 100% sure about this but it seems wrong to discard the value returned by the parent class' version of `HandleIMEMessage()` on line 169? Would we want something like this:

```suggestion
      if (prevent_default)
        return prevent_default;
        
     return views::DesktopWindowTreeHostWin::HandleIMEMessage(message, w_param,
                                                              l_param, result);
```

Code after:
    }
    return prevent_default;
  }

  return views::DesktopWindowTreeHostWin::HandleMouseEvent(event);
}

bool ElectronDesktopWindowTreeHostWin::HandleIMEMessage(UINT message,
                                                        WPARAM w_param,
                                                        LPARAM l_param,
                                                        LRESULT* result) {
  if ((message == WM_SYSCHAR) && (w_param == VK_SPACE)) {
    if (native_window_view_->widget() &&
        native_window_view_->widget()->non_client_view()) {
      const auto* frame =
          native_window_view_->widget()->non_client_view()->frame_view();
      auto location = frame->GetSystemMenuScreenPixelLocation();

      bool prevent_default = false;
      native_window_view_->NotifyWindowSystemContextMenu(
          location.x(), location.y(), &prevent_default);

      return prevent_default ||
             views::DesktopWindowTreeHostWin::HandleIMEMessage(message, w_param,
                                                               l_param, result);
    }
  }

  return views::DesktopWindowTreeHostWin::HandleIMEMessage(message, w_param,
                                                           l_param, result);
}

void ElectronDesktopWindowTreeHostWin::HandleVisibilityChanged(bool visible) {
  if (native_window_view_->widget())
    native_window_view_->widget()->OnNativeWidgetVisibilityChanged(visible);

  if (visible)
    UpdateAllowScreenshots();
}

void ElectronDesktopWindowTreeHostWin::SetAllowScreenshots(bool allow) {
  if (allow_screenshots_ == allow)
    return;

  allow_screenshots_ = allow;

  // If the window is not visible, do not set the window display affinity
  // because `SetWindowDisplayAffinity` will attempt to compose the window,
  if (!IsVisible())
    return;