Skip to content
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

Merged
merged 2 commits into from
Mar 23, 2021

Conversation

WizardCM
Copy link
Member

@WizardCM WizardCM commented May 18, 2019

Description

This PR introduces two core changes, split into their own two commits (Gif examples at the end).

  1. 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.

  2. 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 limit
  • CEF Docs state: "Do not keep references to params or model outside of this callback." therefore I had to create a new object to store the basics of the contents of the dropdown. The model gives us everything we need - the text, command id, enabled status, and menu item type.
  • Qt doesn't allow you to create widgets outside of the UI thread, so once the menu items are acquired from the model, we create a QMenu in the UI thread, and populate it with the items, creating separators as needed.
  • The use of 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:
2019-05-18_21-29-19

After:
2019-05-18_21-34-36

Types of changes

  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Code cleanup (non-breaking change which makes code smaller or more readable)

Checklist:

  • My code has been run through clang-format.
  • I have read the contributing document.
  • My code is not on the master branch.
  • The code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.

@WizardCM WizardCM force-pushed the custom-context-menu branch from e5fb8e1 to 250b309 Compare June 25, 2019 23:13
@WizardCM
Copy link
Member Author

Rebased with clang-format.

@WizardCM WizardCM force-pushed the custom-context-menu branch 2 times, most recently from 354ee98 to 7ff451d Compare July 26, 2019 10:31
@WizardCM WizardCM force-pushed the custom-context-menu branch from 7ff451d to e16048a Compare August 21, 2019 09:46
@WizardCM WizardCM force-pushed the custom-context-menu branch from e16048a to b837f62 Compare August 29, 2019 11:00
@WizardCM WizardCM force-pushed the custom-context-menu branch from b837f62 to 856ec9e Compare October 15, 2019 10:52
@WizardCM WizardCM added Bug Fix Non-breaking change which fixes an issue Code Cleanup Non-breaking change which makes code smaller or more readable Enhancement New feature or improvement labels Dec 27, 2019
@WizardCM WizardCM force-pushed the custom-context-menu branch from 856ec9e to 37acab1 Compare August 20, 2020 00:29
@WizardCM WizardCM force-pushed the custom-context-menu branch from 37acab1 to d82d093 Compare November 27, 2020 09:42
Copy link
Member

@RytoEX RytoEX left a 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.

panel/browser-panel-client.cpp Outdated Show resolved Hide resolved
panel/browser-panel-client.cpp Outdated Show resolved Hide resolved
panel/browser-panel-client.cpp Show resolved Hide resolved
@WizardCM WizardCM force-pushed the custom-context-menu branch from d82d093 to 6e79a23 Compare December 19, 2020 00:08
@WizardCM WizardCM force-pushed the custom-context-menu branch from 6e79a23 to 769a4ee Compare January 13, 2021 09:52
@WizardCM WizardCM added this to the 27.0 milestone Feb 28, 2021
@jp9000
Copy link
Member

jp9000 commented Mar 22, 2021

What happens if a URL overwrites the right-click menu?

@WizardCM
Copy link
Member Author

@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.

@jp9000 jp9000 merged commit 62c5bf2 into obsproject:master Mar 23, 2021
@WizardCM WizardCM deleted the custom-context-menu branch September 12, 2021 03:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Fix Non-breaking change which fixes an issue Code Cleanup Non-breaking change which makes code smaller or more readable Enhancement New feature or improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants