-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Quip print from NSMenuItem shows up as an empty page #2744
Conversation
50b7213
to
2c7dbf8
Compare
return; | ||
} | ||
|
||
sendWithAsyncReply(Messages::WebPage::GenerateSyntheticCommandP(), WTFMove(callbackFunction)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to hard-code the command bindings of the web browser.
Is command-P the shortcut for printing worldwide in all the various translated versions of Safari?
I think it’s really sad that the websites hard code a keyboard equivalent, but it seems like this could entirely break printing for some Safari localizations.
We may need to do a more sophisticated fix that always looks like Command-P to the webpage, but then makes sure to actually do a print action once it gets back to the Mac menu system.
Here’s a testing idea: Customize the menu key shortcut for Print, changing it to something like Command-T, using the Keyboard Settings, Keyboard Shortcut, App Shortcuts, and see what happens.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is command-P the shortcut for printing worldwide in all the various translated versions of Safari?
Yes, it is (Command+P isn't localized in Safari)/
Here’s a testing idea: Customize the menu key shortcut for Print, changing it to something like Command-T, using the Keyboard Settings, Keyboard Shortcut, App Shortcuts, and see what happens.
Yup, I already tested this. Specifically, I tested:
- if it works in the DVORAK keyboard layout
- if it works for when the user changes the print command key binding (to
Command+Option+L
for example) - for a non-Latin system language and keyboard (specifically, Hebrew)
and all of these worked.
Note that I also have a corresponding Safari PR which is linked in the Radar. The Safari change will trigger the normal print flow if the command+P event was not handled
@@ -268,6 +268,8 @@ for this property. | |||
|
|||
- (void)_doAfterNextVisibleContentRectUpdate:(void (^)(void))updateBlock WK_API_AVAILABLE(macos(13.0), ios(16.0)); | |||
|
|||
- (void)_generateSyntheticCommandP:(void (^)(BOOL))completionBlock; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be marked as WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do the TBA
s mean like a future release? If that's the case, will that affect the Safari PR's mergability?
This approach looks very surprising to me, based on years old memories of working in this area. We don't have to synthesize any other keyboard shortcuts. It's up to the embedding application to override those that shouldn't be handled by WebKit (like Cmd+Q or Cmd+W), and the normal behavior is that everything is routed through WebKit. |
@aproskuryakov this is just a compat hack to make Print from the menu bar work for web apps that currently attempt to intercept all printing by handling |
https://bugs.webkit.org/show_bug.cgi?id=243218 rdar://90054391 Reviewed by NOBODY (OOPS!). When a user pressed Cmd+P, some websites (Quip, Google Docs, etc) intercept this event and do their own processing before sending a print event. However, when doing `File > Print`, the default print behavior is used. This causes discrepancies for how these websites are printed between the two different methods. This PR addresses this by synthesizing a Cmd+P event whenever `File > Print` is invoked or when `Print` is selected from the context menu, which allows for consistent behavior. * Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm: (-[WKWebView _generateSyntheticCommandP:]): * Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h: * Source/WebKit/UIProcess/WebPageProxy.cpp: (WebKit::WebPageProxy::generateSyntheticCommandP): * Source/WebKit/UIProcess/WebPageProxy.h: * Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm: (WebKit::WebPageProxy::generateSyntheticEditingCommand): Deleted. * Source/WebKit/WebProcess/WebPage/WebPage.cpp: (WebKit::WebPage::generateSyntheticCommandP): * Source/WebKit/WebProcess/WebPage/WebPage.h: * Source/WebKit/WebProcess/WebPage/WebPage.messages.in:
Right, what I'm saying is that ALL shortcuts go to the website, and if Cmd+P doesn't, then it's an exception that needs to be aligned with the norm. There shouldn't be a need to make it even more exceptional. |
Yes, all shortcuts (including Cmd+P) do indeed go through the website. It's just that when using the menu item (File > Print), the website is unaware of this, and unable to intercept it to do its own handling |
Ah, now I understand why you took this path. Yet, I'm very torn on faking keypresses when there are none, and it doesn't appear to be necessary anyway. Chrome doesn't do this, and yet quip pages print fine from it. What is the actual cause of quip pages being blank when printed in Safari? And if we do this after all, doing this with an SPI seems like a liability, as embedders that don't use the SPI don't get the fix, and embedders that use it even slightly incorrectly still fail when printing via Apple Events. |
I would like to know more about this. |
@aproskuryakov @darinadler Chrome has this same issue as well. Using Command+P on a Quip page in Chrome works as expected, but |
I see a completely blank page in print preview in Safari, and Chrome works. Yes, it's not the same content as with Cmd+P, but I wouldn't say that Chrome has an issue here, much less "the same issue". |
There are multiple other approaches for making printing work that I've seen in practice:
Intercepting Cmd+P does not catch printing via menu or automation (like Apple Events) in other browsers. Thinking about this as an innovation that other browsers might pick up in the future, we need to consider localizability issues not just on macOS, but on other platforms too, as well as resistance for standardizing such a hacky API. |
Even if we fix whatever caused the preview in Safari to be blank (such that our behavior would match Chrome’s) that’s still a user-facing bug, since the user would probably expect cmd+P to match File > Print. Do you have any alternative solutions in mind @aproskuryakov ? |
Personally, I expect the menu to bypass whatever bugs (or intentional "DRM" features) the site has, and print what I see. But that's likely me not being a normal user. But anyone would expect some kind of consciously aligned behavior between "Print", "Share" and "Export as PDF" Safari menus, although I'm not sure what exactly it should be. One solution that doesn't seem like a total hack is having the Print menu dispatch an equivalent of "window.print()" on the frontmost HTML document. That wouldn't fix Quip automatically, but this is something that can be adopted by websites AFAICT. I'm not sure what forums we have for aligning with other browsers on a behavior like this. |
30ffd1a