From: uazo Date: Wed, 12 Apr 2023 08:22:00 +0000 Subject: Add setting to invert tap and long tap Reverses single tap to long tap in android for accessibility reasons. The feature can be activated from the accessibility settings. Need: bromite-build-utils.patch License: GPL-2.0-or-later - https://spdx.org/licenses/GPL-2.0-or-later.html --- chrome/android/java/res/values/ids.xml | 1 + .../ChromeAccessibilitySettingsDelegate.java | 18 ++++++++++ .../contextmenu/ChromeContextMenuItem.java | 5 ++- .../ChromeContextMenuPopulator.java | 5 +++ .../tab/TabContextMenuItemDelegate.java | 8 +++++ chrome/browser/about_flags.cc | 5 +++ .../contextmenu/ContextMenuItemDelegate.java | 2 ++ chrome/browser/flag_descriptions.cc | 4 +++ chrome/browser/flag_descriptions.h | 3 ++ .../flags/android/chrome_feature_list.cc | 1 + .../browser/flags/ChromeFeatureList.java | 5 +++ .../strings/android_chrome_strings.grd | 9 +++++ .../res/xml/accessibility_preferences.xml | 5 +++ .../accessibility/AccessibilitySettings.java | 11 ++++++ .../AccessibilitySettingsDelegate.java | 2 ++ third_party/blink/common/features.cc | 4 +++ third_party/blink/public/common/features.h | 2 ++ .../renderer/core/html/html_anchor_element.cc | 35 +++++++++++++++---- .../renderer/core/html/html_anchor_element.h | 9 +++-- .../renderer/core/html/html_image_element.cc | 17 +++++++++ .../renderer/core/html/html_image_element.h | 2 ++ .../core/page/context_menu_controller.cc | 32 ++++++++++++----- .../core/page/context_menu_controller.h | 5 +-- 23 files changed, 170 insertions(+), 20 deletions(-) diff --git a/chrome/android/java/res/values/ids.xml b/chrome/android/java/res/values/ids.xml --- a/chrome/android/java/res/values/ids.xml +++ b/chrome/android/java/res/values/ids.xml @@ -91,6 +91,7 @@ found in the LICENSE file. + diff --git a/chrome/android/java/src/org/chromium/chrome/browser/accessibility/settings/ChromeAccessibilitySettingsDelegate.java b/chrome/android/java/src/org/chromium/chrome/browser/accessibility/settings/ChromeAccessibilitySettingsDelegate.java --- a/chrome/android/java/src/org/chromium/chrome/browser/accessibility/settings/ChromeAccessibilitySettingsDelegate.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/accessibility/settings/ChromeAccessibilitySettingsDelegate.java @@ -163,6 +163,24 @@ public class ChromeAccessibilitySettingsDelegate implements AccessibilitySetting mSnackbarManager.showSnackbar(mSnackbar); } + private static class ShowAlwaysContextMenuOnLinksDelegate implements BooleanPreferenceDelegate { + @Override + public boolean isEnabled() { + return ChromeFeatureList.sShowAlwaysContextMenuOnLinks.isEnabled(); + } + + @Override + public void setEnabled(boolean value) { + CromiteNativeUtils.setFlagEnabled(ChromeFeatureList.SHOW_ALWAYS_CONTEXT_MENU_ON_LINKS, + "show-always-context-menu-on-links", value); + } + } + + @Override + public BooleanPreferenceDelegate getShowAlwaysContextMenuOnLinksDelegate() { + return new ShowAlwaysContextMenuOnLinksDelegate(); + } + @Override public void addExtraPreferences(PreferenceFragmentCompat fragment) { if (ImageDescriptionsController.getInstance().shouldShowImageDescriptionsMenuItem()) { diff --git a/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/ChromeContextMenuItem.java b/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/ChromeContextMenuItem.java --- a/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/ChromeContextMenuItem.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/ChromeContextMenuItem.java @@ -88,8 +88,9 @@ class ChromeContextMenuItem { int SHARE_HIGHLIGHT = 32; int REMOVE_HIGHLIGHT = 33; int LEARN_MORE = 34; + int FOLLOW_LINK = 35; // ALWAYS UPDATE! - int NUM_ENTRIES = 35; + int NUM_ENTRIES = 36; } /** @@ -131,6 +132,7 @@ class ChromeContextMenuItem { R.id.contextmenu_share_highlight, // Item.SHARE_HIGHLIGHT R.id.contextmenu_remove_highlight, // Item.REMOVE_HIGHLIGHT R.id.contextmenu_learn_more, // Item.LEARN_MORE + R.id.contextmenu_open_in_tab, // Item.OPEN_IN_NEW_CHROME_TAB }; /** @@ -172,6 +174,7 @@ class ChromeContextMenuItem { R.string.contextmenu_share_highlight, // Item.SHARE_HIGHLIGHT R.string.contextmenu_remove_highlight, // Item.REMOVE_HIGHLIGHT R.string.contextmenu_learn_more, // Item.LEARN_MORE + R.string.contextmenu_open_in_tab, // Item.OPEN_IN_NEW_CHROME_TAB: }; /** diff --git a/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/ChromeContextMenuPopulator.java b/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/ChromeContextMenuPopulator.java --- a/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/ChromeContextMenuPopulator.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/ChromeContextMenuPopulator.java @@ -239,6 +239,9 @@ public class ChromeContextMenuPopulator implements ContextMenuPopulator { if (mParams.isAnchor()) { ModelList linkGroup = new ModelList(); + if (ChromeFeatureList.sShowAlwaysContextMenuOnLinks.isEnabled()) { + linkGroup.add(createListItem(Item.FOLLOW_LINK)); + } if (FirstRunStatus.getFirstRunFlowComplete() && !isEmptyUrl(mParams.getUrl()) && UrlUtilities.isAcceptedScheme(mParams.getUrl())) { if (mMode == ContextMenuMode.NORMAL) { @@ -588,6 +591,8 @@ public class ChromeContextMenuPopulator implements ContextMenuPopulator { ShareHelper.shareDirectly( params, ShareHelper.getLastShareComponentName(), getProfile(), false); }); + } else if (itemId == R.id.contextmenu_open_in_tab) { + mItemDelegate.onOpenUrl(mParams.getUrl(), mParams.getReferrer()); } else if (itemId == R.id.contextmenu_open_in_chrome) { recordContextMenuSelection(ContextMenuUma.Action.OPEN_IN_CHROME); mItemDelegate.onOpenInChrome(mParams.getUrl(), mParams.getPageUrl()); diff --git a/chrome/android/java/src/org/chromium/chrome/browser/tab/TabContextMenuItemDelegate.java b/chrome/android/java/src/org/chromium/chrome/browser/tab/TabContextMenuItemDelegate.java --- a/chrome/android/java/src/org/chromium/chrome/browser/tab/TabContextMenuItemDelegate.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/tab/TabContextMenuItemDelegate.java @@ -247,6 +247,14 @@ public class TabContextMenuItemDelegate implements ContextMenuItemDelegate { mTab.loadUrl(loadUrlParams); } + @Override + public void onOpenUrl(GURL url, Referrer referrer) { + LoadUrlParams loadUrlParams = new LoadUrlParams(url.getSpec()); + loadUrlParams.setTransitionType(PageTransition.LINK); + loadUrlParams.setReferrer(referrer); + mTab.loadUrl(loadUrlParams); + } + @Override public void onOpenImageInNewTab(GURL url, Referrer referrer) { LoadUrlParams loadUrlParams = new LoadUrlParams(url.getSpec()); diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc --- a/chrome/browser/about_flags.cc +++ b/chrome/browser/about_flags.cc @@ -8404,6 +8404,11 @@ const FeatureEntry kFeatureEntries[] = { FEATURE_VALUE_TYPE(features::kElasticOverscroll)}, #endif + {"show-always-context-menu-on-links", + flag_descriptions::kShowAlwaysContextMenuOnLinksName, + flag_descriptions::kShowAlwaysContextMenuOnLinksDescription, kOsAndroid, + FEATURE_VALUE_TYPE(blink::features::kShowAlwaysContextMenuOnLinks)}, + {"device-posture", flag_descriptions::kDevicePostureName, flag_descriptions::kDevicePostureDescription, kOsAll, FEATURE_VALUE_TYPE(features::kDevicePosture)}, diff --git a/chrome/browser/contextmenu/java/src/org/chromium/chrome/browser/contextmenu/ContextMenuItemDelegate.java b/chrome/browser/contextmenu/java/src/org/chromium/chrome/browser/contextmenu/ContextMenuItemDelegate.java --- a/chrome/browser/contextmenu/java/src/org/chromium/chrome/browser/contextmenu/ContextMenuItemDelegate.java +++ b/chrome/browser/contextmenu/java/src/org/chromium/chrome/browser/contextmenu/ContextMenuItemDelegate.java @@ -111,6 +111,8 @@ public interface ContextMenuItemDelegate { */ void onOpenImageUrl(GURL url, Referrer referrer); + void onOpenUrl(GURL url, Referrer referrer); + /** * Called when the {@code url} is of an image and should be opened in a new tab. * @param url The image URL to open. diff --git a/chrome/browser/flag_descriptions.cc b/chrome/browser/flag_descriptions.cc --- a/chrome/browser/flag_descriptions.cc +++ b/chrome/browser/flag_descriptions.cc @@ -2056,6 +2056,10 @@ const char kMoveTopToolbarToBottomName[] = "Move top toolbar to bottom"; const char kMoveTopToolbarToBottomDescription[] = "Move the top toolbar to the bottom."; +const char kShowAlwaysContextMenuOnLinksName[] = "Always show contextmenu on links"; +const char kShowAlwaysContextMenuOnLinksDescription[] = + "Use accessibility settings to set it."; + const char kIncognitoDownloadsWarningName[] = "Enable Incognito downloads warning"; const char kIncognitoDownloadsWarningDescription[] = diff --git a/chrome/browser/flag_descriptions.h b/chrome/browser/flag_descriptions.h --- a/chrome/browser/flag_descriptions.h +++ b/chrome/browser/flag_descriptions.h @@ -1165,6 +1165,9 @@ extern const char kImprovedKeyboardShortcutsDescription[]; extern const char kMoveTopToolbarToBottomName[]; extern const char kMoveTopToolbarToBottomDescription[]; +extern const char kShowAlwaysContextMenuOnLinksName[]; +extern const char kShowAlwaysContextMenuOnLinksDescription[]; + extern const char kIncognitoReauthenticationForAndroidName[]; extern const char kIncognitoReauthenticationForAndroidDescription[]; diff --git a/chrome/browser/flags/android/chrome_feature_list.cc b/chrome/browser/flags/android/chrome_feature_list.cc --- a/chrome/browser/flags/android/chrome_feature_list.cc +++ b/chrome/browser/flags/android/chrome_feature_list.cc @@ -331,6 +331,7 @@ const base::Feature* const kFeaturesExposedToJava[] = { &kTabDragDropAndroid, &kTabAndLinkDragDropAndroid, &kTabEngagementReportingAndroid, + &blink::features::kShowAlwaysContextMenuOnLinks, &kTabStripRedesign, &kTabletToolbarReordering, &kTabStripStartupRefactoring, diff --git a/chrome/browser/flags/android/java/src/org/chromium/chrome/browser/flags/ChromeFeatureList.java b/chrome/browser/flags/android/java/src/org/chromium/chrome/browser/flags/ChromeFeatureList.java --- a/chrome/browser/flags/android/java/src/org/chromium/chrome/browser/flags/ChromeFeatureList.java +++ b/chrome/browser/flags/android/java/src/org/chromium/chrome/browser/flags/ChromeFeatureList.java @@ -330,6 +330,8 @@ public abstract class ChromeFeatureList { public static final String NEW_TAB_SEARCH_ENGINE_URL_ANDROID = "NewTabSearchEngineUrlAndroid"; public static final String MOVE_TOP_TOOLBAR_TO_BOTTOM = "MoveTopToolbarToBottom"; + public static final String SHOW_ALWAYS_CONTEXT_MENU_ON_LINKS = + "ShowAlwaysContextMenuOnLinks"; public static final String NOTIFICATION_PERMISSION_VARIANT = "NotificationPermissionVariant"; public static final String NOTIFICATION_PERMISSION_BOTTOM_SHEET = "NotificationPermissionBottomSheet"; @@ -600,6 +602,8 @@ public abstract class ChromeFeatureList { new CachedFlag(OMNIBOX_MATCH_TOOLBAR_AND_STATUS_BAR_COLOR, false); public static final CachedFlag sMoveTopToolbarToBottom = new CachedFlag(MOVE_TOP_TOOLBAR_TO_BOTTOM, false); + public static final CachedFlag sShowAlwaysContextMenuOnLinks = + new CachedFlag(SHOW_ALWAYS_CONTEXT_MENU_ON_LINKS, false); public static final CachedFlag sOmniboxModernizeVisualUpdate = new CachedFlag(OMNIBOX_MODERNIZE_VISUAL_UPDATE, true); public static final CachedFlag sOptimizationGuidePushNotifications = @@ -723,6 +727,7 @@ public abstract class ChromeFeatureList { sTabStripRedesign, sTabStripStartupRefactoring, sTabletToolbarReordering, + sShowAlwaysContextMenuOnLinks, sTabToGTSAnimation, sToolbarUseHardwareBitmapDraw, sUseChimeAndroidSdk, diff --git a/chrome/browser/ui/android/strings/android_chrome_strings.grd b/chrome/browser/ui/android/strings/android_chrome_strings.grd --- a/chrome/browser/ui/android/strings/android_chrome_strings.grd +++ b/chrome/browser/ui/android/strings/android_chrome_strings.grd @@ -1839,6 +1839,12 @@ Your Google account may have other forms of browsing history like searches and a Move toolbar to bottom + + Always open the context menu in the links + + + Allows the context menu to be opened with a tap and follow the link with long press + @@ -2891,6 +2897,9 @@ To change this setting, <resetlink>reset sync

Open in new Chrome tab + + Open in current tab + Open in Incognito tab diff --git a/components/browser_ui/accessibility/android/java/res/xml/accessibility_preferences.xml b/components/browser_ui/accessibility/android/java/res/xml/accessibility_preferences.xml --- a/components/browser_ui/accessibility/android/java/res/xml/accessibility_preferences.xml +++ b/components/browser_ui/accessibility/android/java/res/xml/accessibility_preferences.xml @@ -30,6 +30,11 @@ found in the LICENSE file. android:summary="@string/page_zoom_always_show_preference_summary" android:title="@string/page_zoom_always_show_preference_title" /> + + { Intent intent = new Intent(Settings.ACTION_CAPTIONING_SETTINGS); @@ -213,6 +221,9 @@ public class AccessibilitySettings extends PreferenceFragmentCompat } else if (PREF_MOVE_TOOLBAR_TO_BOTTOM.equals(preference.getKey())) { mMoveTopToolbarToBottomDelegate.setEnabled((Boolean) newValue); mDelegate.requestRestart(getActivity()); + } else if (PREF_ALWAYS_SHOW_CONTEXTMENU_ON_LINKS.equals(preference.getKey())) { + mShowAlwaysContextMenuOnLinksDelegate.setEnabled((Boolean) newValue); + mDelegate.requestRestart(getActivity()); } return true; diff --git a/components/browser_ui/accessibility/android/java/src/org/chromium/components/browser_ui/accessibility/AccessibilitySettingsDelegate.java b/components/browser_ui/accessibility/android/java/src/org/chromium/components/browser_ui/accessibility/AccessibilitySettingsDelegate.java --- a/components/browser_ui/accessibility/android/java/src/org/chromium/components/browser_ui/accessibility/AccessibilitySettingsDelegate.java +++ b/components/browser_ui/accessibility/android/java/src/org/chromium/components/browser_ui/accessibility/AccessibilitySettingsDelegate.java @@ -49,6 +49,8 @@ public interface AccessibilitySettingsDelegate { BooleanPreferenceDelegate getMoveTopToolbarToBottomDelegate(); + BooleanPreferenceDelegate getShowAlwaysContextMenuOnLinksDelegate(); + /** * @return The BrowserContextHandle that should be used to read and update settings. */ diff --git a/third_party/blink/common/features.cc b/third_party/blink/common/features.cc --- a/third_party/blink/common/features.cc +++ b/third_party/blink/common/features.cc @@ -241,6 +241,10 @@ BASE_FEATURE(kBackgroundResourceFetch, "BackgroundResourceFetch", base::FEATURE_DISABLED_BY_DEFAULT); +BASE_FEATURE(kShowAlwaysContextMenuOnLinks, + "ShowAlwaysContextMenuOnLinks", + base::FEATURE_DISABLED_BY_DEFAULT); + // Used to configure a per-origin allowlist of performance.mark events that are // permitted to be included in slow reports traces. See crbug.com/1181774. BASE_FEATURE(kBackgroundTracingPerformanceMark, diff --git a/third_party/blink/public/common/features.h b/third_party/blink/public/common/features.h --- a/third_party/blink/public/common/features.h +++ b/third_party/blink/public/common/features.h @@ -143,6 +143,8 @@ BLINK_COMMON_EXPORT BASE_DECLARE_FEATURE(kBackForwardCacheWithKeepaliveRequest); BLINK_COMMON_EXPORT BASE_DECLARE_FEATURE(kBackgroundResourceFetch); +BLINK_COMMON_EXPORT BASE_DECLARE_FEATURE(kShowAlwaysContextMenuOnLinks); + // Used to configure a per-origin allowlist of performance.mark events that are // permitted to be included in slow reports traces. See crbug.com/1181774. BLINK_COMMON_EXPORT BASE_DECLARE_FEATURE(kBackgroundTracingPerformanceMark); diff --git a/third_party/blink/renderer/core/html/html_anchor_element.cc b/third_party/blink/renderer/core/html/html_anchor_element.cc --- a/third_party/blink/renderer/core/html/html_anchor_element.cc +++ b/third_party/blink/renderer/core/html/html_anchor_element.cc @@ -59,6 +59,7 @@ #include "third_party/blink/renderer/core/loader/ping_loader.h" #include "third_party/blink/renderer/core/navigation_api/navigation_api.h" #include "third_party/blink/renderer/core/page/chrome_client.h" +#include "third_party/blink/renderer/core/page/context_menu_controller.h" #include "third_party/blink/renderer/core/page/page.h" #include "third_party/blink/renderer/core/speculation_rules/document_speculation_rules.h" #include "third_party/blink/renderer/platform/heap/garbage_collected.h" @@ -456,6 +457,17 @@ void HTMLAnchorElement::NavigateToHyperlink(ResourceRequest request, bool is_trusted, base::TimeTicks platform_time_stamp, KURL completed_url) { + UIEvent& event = *UIEvent::Create(); + NavigateToHyperlink2(std::move(request), navigation_policy, is_trusted, platform_time_stamp, + std::move(completed_url), event, true); +} + +void HTMLAnchorElement::NavigateToHyperlink2(ResourceRequest request, + NavigationPolicy navigation_policy, + bool is_trusted, + base::TimeTicks platform_time_stamp, + KURL completed_url, + Event& event, bool do_not_show_context_menu) { LocalDOMWindow* window = GetDocument().domWindow(); if (!window) { return; @@ -510,6 +522,15 @@ void HTMLAnchorElement::NavigateToHyperlink(ResourceRequest request, /*element=*/this, request.HasUserGesture())); } + if (!do_not_show_context_menu && + base::FeatureList::IsEnabled(features::kShowAlwaysContextMenuOnLinks)) { + if (Page* page = GetDocument().GetPage()) { + page->GetContextMenuController().HandleContextMenuEvent( + To(&event), /*do_not_show_context_menu*/true); + return; + } + } + Frame* target_frame = frame->Tree().FindOrCreateFrameForNavigation(frame_request, target).frame; @@ -553,7 +574,7 @@ void HTMLAnchorElement::SetHovered(bool hovered) { } } -void HTMLAnchorElement::HandleClick(Event& event) { +void HTMLAnchorElement::HandleClick(Event& event, bool do_not_show_context_menu) { event.SetDefaultHandled(); LocalDOMWindow* window = GetDocument().domWindow(); @@ -652,12 +673,12 @@ void HTMLAnchorElement::HandleClick(Event& event) { } NavigationPolicy navigation_policy = NavigationPolicyFromEvent(&event); - base::OnceClosure navigate_closure = WTF::BindOnce( - &HTMLAnchorElement::NavigateToHyperlink, WrapWeakPersistent(this), - std::move(request), navigation_policy, event.isTrusted(), - event.PlatformTimeStamp(), std::move(completed_url)); if (navigation_policy == kNavigationPolicyDownload) { + base::OnceClosure navigate_closure = WTF::BindOnce( + &HTMLAnchorElement::NavigateToHyperlink, WrapWeakPersistent(this), + std::move(request), navigation_policy, event.isTrusted(), + event.PlatformTimeStamp(), std::move(completed_url)); // If Alt is held down it will force a download, however, wait to see if // this is an alt-double-click which should instead select the text of the // link. @@ -669,7 +690,9 @@ void HTMLAnchorElement::HandleClick(Event& event) { frame->GetEventHandler().SetDownloadModifierTaskHandle( std::move(task_handle)); } else { - std::move(navigate_closure).Run(); + HTMLAnchorElement::NavigateToHyperlink2(std::move(request), navigation_policy, + event.isTrusted(), event.PlatformTimeStamp(), std::move(completed_url), + event, do_not_show_context_menu); } } diff --git a/third_party/blink/renderer/core/html/html_anchor_element.h b/third_party/blink/renderer/core/html/html_anchor_element.h --- a/third_party/blink/renderer/core/html/html_anchor_element.h +++ b/third_party/blink/renderer/core/html/html_anchor_element.h @@ -106,6 +106,7 @@ class CORE_EXPORT HTMLAnchorElement : public HTMLElement, public DOMURLUtils { void SetHovered(bool hovered) override; void Trace(Visitor*) const override; + void HandleClick(Event&, bool do_not_show_context_menu = false); protected: void ParseAttribute(const AttributeModificationParams&) override; @@ -127,12 +128,16 @@ class CORE_EXPORT HTMLAnchorElement : public HTMLElement, public DOMURLUtils { bool IsInteractiveContent() const final; InsertionNotificationRequest InsertedInto(ContainerNode&) override; void RemovedFrom(ContainerNode&) override; + void NavigateToHyperlink2(ResourceRequest, + NavigationPolicy, + bool is_trusted, + base::TimeTicks platform_time_stamp, + KURL, Event&, bool do_not_show_context_menu); void NavigateToHyperlink(ResourceRequest, NavigationPolicy, bool is_trusted, base::TimeTicks platform_time_stamp, - KURL); - void HandleClick(Event&); + KURL completed_url); unsigned link_relations_ : 31; mutable LinkHash cached_visited_link_hash_; diff --git a/third_party/blink/renderer/core/html/html_image_element.cc b/third_party/blink/renderer/core/html/html_image_element.cc --- a/third_party/blink/renderer/core/html/html_image_element.cc +++ b/third_party/blink/renderer/core/html/html_image_element.cc @@ -36,6 +36,7 @@ #include "third_party/blink/renderer/core/dom/events/event_dispatch_forbidden_scope.h" #include "third_party/blink/renderer/core/dom/node_traversal.h" #include "third_party/blink/renderer/core/dom/shadow_root.h" +#include "third_party/blink/renderer/core/events/mouse_event.h" #include "third_party/blink/renderer/core/frame/attribution_src_loader.h" #include "third_party/blink/renderer/core/frame/deprecation/deprecation.h" #include "third_party/blink/renderer/core/frame/local_dom_window.h" @@ -63,6 +64,7 @@ #include "third_party/blink/renderer/core/media_type_names.h" #include "third_party/blink/renderer/core/page/chrome_client.h" #include "third_party/blink/renderer/core/page/page.h" +#include "third_party/blink/renderer/core/page/context_menu_controller.h" #include "third_party/blink/renderer/core/paint/timing/paint_timing.h" #include "third_party/blink/renderer/core/probe/core_probes.h" #include "third_party/blink/renderer/core/style/content_data.h" @@ -753,6 +755,21 @@ void HTMLImageElement::DidFinishLifecycleUpdate( } } +void HTMLImageElement::DefaultEventHandler(Event& event) { + if (base::FeatureList::IsEnabled(features::kShowAlwaysContextMenuOnLinks)) { + auto* mouse_event = DynamicTo(&event); + if (mouse_event && mouse_event->type() == event_type_names::kClick) { + if (Page* page = GetDocument().GetPage()) { + page->GetContextMenuController().HandleContextMenuEvent( + mouse_event, /*do_not_show_context_menu*/true); + return; + } + } + } + + HTMLElement::DefaultEventHandler(event); +} + bool HTMLImageElement::draggable() const { // Image elements are draggable by default. return !EqualIgnoringASCIICase(FastGetAttribute(html_names::kDraggableAttr), diff --git a/third_party/blink/renderer/core/html/html_image_element.h b/third_party/blink/renderer/core/html/html_image_element.h --- a/third_party/blink/renderer/core/html/html_image_element.h +++ b/third_party/blink/renderer/core/html/html_image_element.h @@ -220,6 +220,8 @@ class CORE_EXPORT HTMLImageElement final void DidAddUserAgentShadowRoot(ShadowRoot&) override; void AdjustStyle(ComputedStyleBuilder&) override; + void DefaultEventHandler(Event&) override; + private: bool AreAuthorShadowsAllowed() const override { return false; } diff --git a/third_party/blink/renderer/core/page/context_menu_controller.cc b/third_party/blink/renderer/core/page/context_menu_controller.cc --- a/third_party/blink/renderer/core/page/context_menu_controller.cc +++ b/third_party/blink/renderer/core/page/context_menu_controller.cc @@ -236,14 +236,16 @@ void ContextMenuController::DocumentDetached(Document* document) { } } -void ContextMenuController::HandleContextMenuEvent(MouseEvent* mouse_event) { - DCHECK(mouse_event->type() == event_type_names::kContextmenu); +void ContextMenuController::HandleContextMenuEvent(MouseEvent* mouse_event, bool do_not_show_context_menu) { + if (!base::FeatureList::IsEnabled(features::kShowAlwaysContextMenuOnLinks)) { + DCHECK(mouse_event->type() == event_type_names::kContextmenu); + } LocalFrame* frame = mouse_event->target()->ToNode()->GetDocument().GetFrame(); PhysicalOffset location = PhysicalOffset::FromPointFRound(mouse_event->AbsoluteLocation()); if (ShowContextMenu(frame, location, mouse_event->GetMenuSourceType(), - mouse_event)) + mouse_event, do_not_show_context_menu)) mouse_event->SetDefaultHandled(); } @@ -461,7 +463,8 @@ bool ContextMenuController::ShouldShowContextMenuFromTouch( bool ContextMenuController::ShowContextMenu(LocalFrame* frame, const PhysicalOffset& point, WebMenuSourceType source_type, - const MouseEvent* mouse_event) { + const MouseEvent* mouse_event, + bool do_not_show_context_menu) { // Displaying the context menu in this function is a big hack as we don't // have context, i.e. whether this is being invoked via a script or in // response to user input (Mouse event WM_RBUTTONDOWN, @@ -484,6 +487,15 @@ bool ContextMenuController::ShowContextMenu(LocalFrame* frame, if (!result.InnerNodeOrImageMapImage()) return false; + if (!do_not_show_context_menu && + base::FeatureList::IsEnabled(features::kShowAlwaysContextMenuOnLinks)) { + if (auto* anchor_element = DynamicTo(result.URLElement())) { + Event event; + anchor_element->HandleClick(event, /*do_not_show_context_menu*/true); + return true; + } + } + // Clear any previously set cached results if we are resetting the hit test // result. image_selection_cached_result_ = nullptr; @@ -837,11 +849,13 @@ bool ContextMenuController::ShowContextMenu(LocalFrame* frame, data.form_renderer_id = GetFormRendererId(result); data.field_renderer_id = GetFieldRendererId(result); - const bool from_touch = source_type == kMenuSourceTouch || - source_type == kMenuSourceLongPress || - source_type == kMenuSourceLongTap; - if (from_touch && !ShouldShowContextMenuFromTouch(data)) - return false; + if (!base::FeatureList::IsEnabled(features::kShowAlwaysContextMenuOnLinks)) { + const bool from_touch = source_type == kMenuSourceTouch || + source_type == kMenuSourceLongPress || + source_type == kMenuSourceLongTap; + if (from_touch && !ShouldShowContextMenuFromTouch(data)) + return false; + } WebLocalFrameImpl* selected_web_frame = WebLocalFrameImpl::FromFrame(selected_frame); diff --git a/third_party/blink/renderer/core/page/context_menu_controller.h b/third_party/blink/renderer/core/page/context_menu_controller.h --- a/third_party/blink/renderer/core/page/context_menu_controller.h +++ b/third_party/blink/renderer/core/page/context_menu_controller.h @@ -57,7 +57,7 @@ class CORE_EXPORT ContextMenuController final void DocumentDetached(Document*); - void HandleContextMenuEvent(MouseEvent*); + void HandleContextMenuEvent(MouseEvent*, bool do_not_show_context_menu = false); void ShowContextMenuAtPoint(LocalFrame*, float x, float y, @@ -123,7 +123,8 @@ class CORE_EXPORT ContextMenuController final bool ShowContextMenu(LocalFrame*, const PhysicalOffset&, WebMenuSourceType, - const MouseEvent* mouse_event = nullptr); + const MouseEvent* mouse_event = nullptr, + bool do_not_show_context_menu = false); bool ShouldShowContextMenuFromTouch(const ContextMenuData&); -- 2.25.1