fix: context-menu emitted twice (#44978)

* fix: context-menu emitted twice

* refactor: simplify disabling draggable regions

* cleanup
This commit is contained in:
Sam Maddock 2024-12-11 11:42:48 -05:00 committed by GitHub
parent cf5a4640f5
commit 2c698d3f75
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 51 additions and 65 deletions

View file

@ -371,6 +371,9 @@ namespace electron::api {
namespace {
// Global toggle for disabling draggable regions checks.
bool g_disable_draggable_regions = false;
constexpr std::string_view CursorTypeToString(
ui::mojom::CursorType cursor_type) {
switch (cursor_type) {
@ -2070,6 +2073,10 @@ void WebContents::DraggableRegionsChanged(
draggable_region_ = DraggableRegionsToSkRegion(regions);
}
SkRegion* WebContents::draggable_region() {
return g_disable_draggable_regions ? nullptr : draggable_region_.get();
}
void WebContents::DidStartNavigation(
content::NavigationHandle* navigation_handle) {
EmitNavigationEvent("did-start-navigation", navigation_handle);
@ -4614,6 +4621,11 @@ std::list<WebContents*> WebContents::GetWebContentsList() {
return list;
}
// static
void WebContents::SetDisableDraggableRegions(bool disable) {
g_disable_draggable_regions = disable;
}
// static
gin::WrapperInfo WebContents::kWrapperInfo = {gin::kEmbedderNativeGin};

View file

@ -151,6 +151,10 @@ class WebContents final : public ExclusiveAccessContext,
static WebContents* FromID(int32_t id);
static std::list<WebContents*> GetWebContentsList();
// Whether to disable draggable regions globally. This can be used to allow
// events to skip client region hit tests.
static void SetDisableDraggableRegions(bool disable);
// Get the V8 wrapper of the |web_contents|, or create one if not existed.
//
// The lifetime of |web_contents| is NOT managed by this class, and the type
@ -486,13 +490,7 @@ class WebContents final : public ExclusiveAccessContext,
void PDFReadyToPrint();
SkRegion* draggable_region() {
return force_non_draggable_ ? nullptr : draggable_region_.get();
}
void SetForceNonDraggable(bool force_non_draggable) {
force_non_draggable_ = force_non_draggable;
}
SkRegion* draggable_region();
// disable copy
WebContents(const WebContents&) = delete;
@ -892,8 +890,6 @@ class WebContents final : public ExclusiveAccessContext,
std::unique_ptr<SkRegion> draggable_region_;
bool force_non_draggable_ = false;
base::WeakPtrFactory<WebContents> weak_factory_{this};
};