-
Notifications
You must be signed in to change notification settings - Fork 227
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
Panels: Right click Reload, use Qt context menu #163
Conversation
e5fb8e1
to
250b309
Compare
Rebased with clang-format. |
354ee98
to
7ff451d
Compare
7ff451d
to
e16048a
Compare
e16048a
to
b837f62
Compare
b837f62
to
856ec9e
Compare
856ec9e
to
37acab1
Compare
37acab1
to
d82d093
Compare
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.
Discussed on call with @WizardCM . Leaving review notes here to help keep a paper trail.
d82d093
to
6e79a23
Compare
Items are copied from the CEF dropdown at runtime. If new menu item types are used, the reference is available here: https://magpcss.org/ceforum/apidocs3/projects/(default)/cef_menu_item_type_t.html
6e79a23
to
769a4ee
Compare
What happens if a URL overwrites the right-click menu? |
@jp9000 Solid question! I have verified on this page that the page's custom context menu takes priority in the correct situations. By the looks of it the CEF code never gets hit, so V8 (Chrome's JavaScript engine) probably handles that internally. |
Description
This PR introduces two core changes, split into their own two commits (Gif examples at the end).
It allows for the modification of the contents of the CEF context menu. This is a native capability, and I've used it to perform two minor changes: the first is to enable a Reload option, to refresh the page. The second is to hide the Print option, as it's not needed. I considered also hiding "View page source". Feedback here would be good. This change overall is quite small, and can be used down the line to add/remove any options, whether they're native ones (like the Reload one) or completely custom functions.
Next I added a function to replace the native CEF context menu with a Qt menu. This is also a native capability, and ensures that not only the context menu is consistent with others, but also matches the OBS theme.
The second change went through a few iterations, but in the end I settled on this.
Motivation and Context
The primary motivation is consistency. The context menu for browser docks doesn't currently follow the same design rules as all other context menus in OBS, making it feel out of place and "tacked on". It also behaves unexpectedly when the user presses the context menu key on the keyboard, where it opens two menus where one cannot be closed.
The second motivation is extensibility. By using native CEF functions to modify the dropdown, it opens the doors to further options in the future: like a "Dock Configuration" button, for example. In this case, it starts off simple by adding a much-requested Reload option.
Implementation details:
RunContextMenu
requires a "return true" if you're rendering your own context menu (which, we are). The callback can be run synchronously or asynchronously, and has no time limitparams
ormodel
outside of this callback." therefore I had to create a new object to store the basics of the contents of the dropdown. Themodel
gives us everything we need - thetext
,command id
,enabled
status, and menu itemtype
.model
, we create aQMenu
in the UI thread, and populate it with the items, creating separators as needed.exec()
was chosen as it's used in other places in OBS, and because it allowed for the smallest bit of code: it synchronously returns whether an action was clicked or not, allowing the ability to then run the necessary CEF callback. If you don't run the Cancel() callback if an item hasn't been chosen, then you can't open the dropdown a second time. The event just never triggers.How Has This Been Tested?
Add a custom browser dock, or enable service integration, and right click anywhere within the webpage. Depending on whether text is selected, and what element you right click on, CEF will give you different options in the context menu. Example: right click a random area where there's no text, and then right click a text input field (the latter will unlock Copy/Paste).
Before:
After:
Types of changes
Checklist: