fix: context-menu emitted twice (#44997)

* fix: context-menu emitted twice

Co-authored-by: Samuel Maddock <smaddock@slack-corp.com>

* refactor: simplify disabling draggable regions

Co-authored-by: Samuel Maddock <smaddock@slack-corp.com>

* cleanup

Co-authored-by: Samuel Maddock <smaddock@slack-corp.com>

---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Samuel Maddock <smaddock@slack-corp.com>
This commit is contained in:
trop[bot] 2024-12-11 13:24:32 -05:00 committed by GitHub
parent cfe549c739
commit 521835d70b
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) {
@ -2049,6 +2052,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);
@ -4592,6 +4599,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
@ -485,13 +489,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;
@ -888,8 +886,6 @@ class WebContents final : public ExclusiveAccessContext,
std::unique_ptr<SkRegion> draggable_region_;
bool force_non_draggable_ = false;
base::WeakPtrFactory<WebContents> weak_factory_{this};
};