Skip to content

Truly independent web browser

LibWeb+LibWebView: Offer the image menu for images inside links

Andreas Kling82227b78903e
diff --git a/Libraries/LibWeb/Internals/Internals.cpp b/Libraries/LibWeb/Internals/Internals.cpp
index 8906cf2e3f3..2bd5170aaff 100644
--- a/Libraries/LibWeb/Internals/Internals.cpp
+++ b/Libraries/LibWeb/Internals/Internals.cpp
@@ -3728,6 +3728,8 @@ GC::Ptr<JS::Object> Internals::take_context_menu_request()
object->define_direct_property("target"_utf16_fly_string, target, JS::default_attributes);
object->define_direct_property("x"_utf16_fly_string, JS::Value(request->position.x().to_double()), JS::default_attributes);
object->define_direct_property("y"_utf16_fly_string, JS::Value(request->position.y().to_double()), JS::default_attributes);
+ if (request->link_url.has_value())
+ object->define_direct_property("linkURL"_utf16_fly_string, JS::PrimitiveString::create(vm(), utf16_string_from_url_ascii(request->link_url->serialize())), JS::default_attributes);
if (request->media.has_value()) {
object->define_direct_property("isPictureInPicture"_utf16_fly_string, JS::Value(request->media->is_picture_in_picture), JS::default_attributes);
object->define_direct_property("canEnterPictureInPicture"_utf16_fly_string, JS::Value(request->media->can_enter_picture_in_picture), JS::default_attributes);
diff --git a/Libraries/LibWeb/Page/EventHandler.cpp b/Libraries/LibWeb/Page/EventHandler.cpp
index 6366c25ec72..1026ab3f40e 100644
--- a/Libraries/LibWeb/Page/EventHandler.cpp
+++ b/Libraries/LibWeb/Page/EventHandler.cpp
@@ -4001,83 +4001,91 @@ void EventHandler::maybe_show_context_menu(GC::Ref<DOM::Node> node, MouseEventCo
return range->clone_range();
};
- if (auto const* link = node_under_pointer->enclosing_link_element()) {
+ // AD-HOC: Skip up the tree to the first ancestor that is not a UA shadow DOM node, and use its context menu.
+ // Media elements' controls' shadow DOM nodes should not have their own context menu, but rather
+ // activate their parent media element's menu.
+ auto context_menu_node = node_of_box_under_pointer;
+ while (auto shadow_root = context_menu_node->containing_shadow_root()) {
+ if (!shadow_root->is_user_agent_internal())
+ break;
+ VERIFY(shadow_root->host() != nullptr);
+ context_menu_node = *shadow_root->host();
+ }
+
+ auto const* link = node_under_pointer->enclosing_link_element();
+ Optional<URL::URL> link_url;
+ if (link)
+ link_url = document->encoding_parse_url(link->href());
+
+ // An image without a source has nothing for the image menu to act on.
+ auto* image_element = as_if<HTML::HTMLImageElement>(*context_menu_node);
+ Optional<URL::URL> image_url;
+ if (image_element && !image_element->current_src().is_empty())
+ image_url = image_element->document().encoding_parse_url(image_element->current_src());
+
+ if (image_url.has_value()) {
+ Optional<Gfx::Bitmap const*> bitmap;
+ if (auto frame = image_element->current_image_frame(); frame.has_value())
+ bitmap = &frame->bitmap();
+
+ // An image inside a link, or under an image map's link, offers both the image and the link.
+ Optional<HTML::PreparedNavigationDescriptor> link_navigation;
+ if (link_url.has_value())
+ link_navigation = HTML::prepare_navigation_from_document(*document, *link_url, link->hyperlink_element_utils_element().hyperlink_referrer_policy());
+
+ auto navigation = HTML::prepare_navigation_from_document(image_element->document(), image_url.release_value(), ReferrerPolicy::ReferrerPolicy::EmptyString);
+ m_navigable->page().record_context_menu_request({}, { .kind = Page::ContextMenuRequest::Kind::Image, .target = *image_element, .position = page_viewport_position, .link_url = move(link_url) });
+ m_navigable->page().client().page_did_request_image_context_menu(local_root_id, page_viewport_position, move(navigation), "", modifiers, bitmap, move(link_navigation));
+ } else if (link) {
// Right-clicking link text without an existing selection first selects the word under the pointer, as the
// ordinary page context menu does. A selected range is still only offered when the click lands within it.
(void)select_context_menu_text(read, document, coordinates);
- auto href = link->href();
- auto url = document->encoding_parse_url(href);
- if (url.has_value()) {
+ if (link_url.has_value()) {
auto const& element = link->hyperlink_element_utils_element();
- auto navigation = HTML::prepare_navigation_from_document(*document, url.release_value(), element.hyperlink_referrer_policy());
+ auto navigation = HTML::prepare_navigation_from_document(*document, link_url.release_value(), element.hyperlink_referrer_policy());
m_navigable->page().record_context_menu_request({}, { .kind = Page::ContextMenuRequest::Kind::Link, .target = const_cast<DOM::Element&>(element), .position = page_viewport_position });
m_navigable->page().client().page_did_request_link_context_menu(local_root_id, page_viewport_position, move(navigation), link->target().to_byte_string(), modifiers, selected_text_range_at_context_menu_position());
}
- } else {
- // AD-HOC: Skip up the tree to the first ancestor that is not a UA shadow DOM node, and use its context menu.
- // Media elements' controls' shadow DOM nodes should not have their own context menu, but rather
- // activate their parent media element's menu.
- auto context_menu_node = node_of_box_under_pointer;
- while (auto shadow_root = context_menu_node->containing_shadow_root()) {
- if (!shadow_root->is_user_agent_internal())
- break;
- VERIFY(shadow_root->host() != nullptr);
- context_menu_node = *shadow_root->host();
- }
-
- if (is<HTML::HTMLImageElement>(*context_menu_node)) {
- auto& image_element = as<HTML::HTMLImageElement>(*context_menu_node);
- auto image_url = image_element.document().encoding_parse_url(image_element.current_src());
- if (image_url.has_value()) {
- Optional<Gfx::Bitmap const*> bitmap;
- if (auto frame = image_element.current_image_frame(); frame.has_value())
- bitmap = &frame->bitmap();
-
- auto navigation = HTML::prepare_navigation_from_document(image_element.document(), image_url.release_value(), ReferrerPolicy::ReferrerPolicy::EmptyString);
- m_navigable->page().record_context_menu_request({}, { .kind = Page::ContextMenuRequest::Kind::Image, .target = image_element, .position = page_viewport_position });
- m_navigable->page().client().page_did_request_image_context_menu(local_root_id, page_viewport_position, move(navigation), "", modifiers, bitmap);
- }
- } else if (is<HTML::HTMLMediaElement>(*context_menu_node)) {
- auto& media_element = as<HTML::HTMLMediaElement>(*context_menu_node);
- auto* video_element = as_if<HTML::HTMLVideoElement>(*context_menu_node);
- auto is_video = video_element != nullptr;
-
- // A media element without a source, or one whose source does not resolve against the document's base
- // URL, has no URL to open or copy.
- Optional<URL::URL> media_url;
- if (auto const& current_src = media_element.current_src(); !current_src.is_empty())
- media_url = media_element.document().encoding_parse_url(current_src);
-
- Page::MediaContextMenu menu {
- .media_url = move(media_url),
- .is_video = is_video,
- .is_playing = media_element.potentially_playing(),
- .is_muted = media_element.muted(),
- .has_user_agent_controls = media_element.has_attribute(HTML::AttributeNames::controls),
- .is_looping = media_element.has_attribute(HTML::AttributeNames::loop),
- .is_fullscreen = is_video && media_element.is_fullscreen_element(),
- .is_picture_in_picture = media_element.is_picture_in_picture_element(),
- .can_enter_picture_in_picture = is_video && video_element->can_enter_picture_in_picture(),
- };
+ } else if (is<HTML::HTMLMediaElement>(*context_menu_node)) {
+ auto& media_element = as<HTML::HTMLMediaElement>(*context_menu_node);
+ auto* video_element = as_if<HTML::HTMLVideoElement>(*context_menu_node);
+ auto is_video = video_element != nullptr;
+
+ // A media element without a source, or one whose source does not resolve against the document's base
+ // URL, has no URL to open or copy.
+ Optional<URL::URL> media_url;
+ if (auto const& current_src = media_element.current_src(); !current_src.is_empty())
+ media_url = media_element.document().encoding_parse_url(current_src);
+
+ Page::MediaContextMenu menu {
+ .media_url = move(media_url),
+ .is_video = is_video,
+ .is_playing = media_element.potentially_playing(),
+ .is_muted = media_element.muted(),
+ .has_user_agent_controls = media_element.has_attribute(HTML::AttributeNames::controls),
+ .is_looping = media_element.has_attribute(HTML::AttributeNames::loop),
+ .is_fullscreen = is_video && media_element.is_fullscreen_element(),
+ .is_picture_in_picture = media_element.is_picture_in_picture_element(),
+ .can_enter_picture_in_picture = is_video && video_element->can_enter_picture_in_picture(),
+ };
- auto navigation = menu.media_url.map([&](auto const& url) {
- return HTML::prepare_navigation_from_document(media_element.document(), url, ReferrerPolicy::ReferrerPolicy::EmptyString);
- });
- m_navigable->page().record_context_menu_request({}, { .kind = Page::ContextMenuRequest::Kind::Media, .target = media_element, .position = page_viewport_position, .media = menu });
- m_navigable->page().did_request_media_context_menu(media_element.unique_id(), local_root_id, page_viewport_position, "", modifiers, menu, move(navigation));
- } else {
- auto misspelling = select_context_menu_misspelling(read, document, coordinates);
- if (!misspelling.has_value())
- select_context_menu_text(read, document, coordinates);
- Optional<Utf16String> misspelled_word;
- if (misspelling.has_value())
- misspelled_word = misspelling->word;
- m_navigable->page().record_context_menu_misspelling({}, move(misspelling));
-
- auto for_input_events_target = document->active_input_events_target() ? ContextMenuForInputEventsTarget::Yes : ContextMenuForInputEventsTarget::No;
- m_navigable->page().record_context_menu_request({}, { .kind = Page::ContextMenuRequest::Kind::Page, .target = context_menu_node, .position = page_viewport_position });
- m_navigable->page().client().page_did_request_context_menu(local_root_id, page_viewport_position, for_input_events_target, move(misspelled_word), selected_text_range_at_context_menu_position());
- }
+ auto navigation = menu.media_url.map([&](auto const& url) {
+ return HTML::prepare_navigation_from_document(media_element.document(), url, ReferrerPolicy::ReferrerPolicy::EmptyString);
+ });
+ m_navigable->page().record_context_menu_request({}, { .kind = Page::ContextMenuRequest::Kind::Media, .target = media_element, .position = page_viewport_position, .media = menu });
+ m_navigable->page().did_request_media_context_menu(media_element.unique_id(), local_root_id, page_viewport_position, "", modifiers, menu, move(navigation));
+ } else {
+ auto misspelling = select_context_menu_misspelling(read, document, coordinates);
+ if (!misspelling.has_value())
+ select_context_menu_text(read, document, coordinates);
+ Optional<Utf16String> misspelled_word;
+ if (misspelling.has_value())
+ misspelled_word = misspelling->word;
+ m_navigable->page().record_context_menu_misspelling({}, move(misspelling));
+
+ auto for_input_events_target = document->active_input_events_target() ? ContextMenuForInputEventsTarget::Yes : ContextMenuForInputEventsTarget::No;
+ m_navigable->page().record_context_menu_request({}, { .kind = Page::ContextMenuRequest::Kind::Page, .target = context_menu_node, .position = page_viewport_position });
+ m_navigable->page().client().page_did_request_context_menu(local_root_id, page_viewport_position, for_input_events_target, move(misspelled_word), selected_text_range_at_context_menu_position());
}
}
diff --git a/Libraries/LibWeb/Page/Page.h b/Libraries/LibWeb/Page/Page.h
index 0acf7a674a3..3ba8a1fb631 100644
--- a/Libraries/LibWeb/Page/Page.h
+++ b/Libraries/LibWeb/Page/Page.h
@@ -438,6 +438,7 @@ public:
GC::Ref<DOM::Node> target;
CSSPixelPoint position;
Optional<Web::MediaContextMenu> media {};
+ Optional<URL::URL> link_url {};
};
void record_context_menu_request(Badge<EventHandler>, ContextMenuRequest);
void clear_context_menu_request() { m_context_menu_request.clear(); }
@@ -839,7 +840,7 @@ public:
virtual void page_did_change_accessibility_focus(Web::UniqueNodeID) { }
virtual void page_did_request_context_menu([[maybe_unused]] HTML::CrossProcessId local_root_id, CSSPixelPoint, ContextMenuForInputEventsTarget, [[maybe_unused]] Optional<Utf16String> misspelled_word, [[maybe_unused]] GC::Ptr<DOM::Range> selected_text_range) { }
virtual void page_did_request_link_context_menu([[maybe_unused]] HTML::CrossProcessId local_root_id, CSSPixelPoint, HTML::PreparedNavigationDescriptor, [[maybe_unused]] ByteString const& target, [[maybe_unused]] unsigned modifiers, [[maybe_unused]] GC::Ptr<DOM::Range> selected_text_range) { }
- virtual void page_did_request_image_context_menu([[maybe_unused]] HTML::CrossProcessId local_root_id, CSSPixelPoint, HTML::PreparedNavigationDescriptor, [[maybe_unused]] ByteString const& target, [[maybe_unused]] unsigned modifiers, Optional<Gfx::Bitmap const*>) { }
+ virtual void page_did_request_image_context_menu([[maybe_unused]] HTML::CrossProcessId local_root_id, CSSPixelPoint, HTML::PreparedNavigationDescriptor, [[maybe_unused]] ByteString const& target, [[maybe_unused]] unsigned modifiers, Optional<Gfx::Bitmap const*>, [[maybe_unused]] Optional<HTML::PreparedNavigationDescriptor> link_navigation) { }
virtual void page_did_request_media_context_menu([[maybe_unused]] HTML::CrossProcessId local_root_id, CSSPixelPoint, [[maybe_unused]] ByteString const& target, [[maybe_unused]] unsigned modifiers, Page::MediaContextMenu const&, Optional<HTML::PreparedNavigationDescriptor>) { }
virtual void page_did_click_link(HTML::PreparedNavigationDescriptor, [[maybe_unused]] ByteString const& target, [[maybe_unused]] unsigned modifiers) { }
virtual void page_did_middle_click_link(HTML::PreparedNavigationDescriptor, [[maybe_unused]] ByteString const& target, [[maybe_unused]] unsigned modifiers) { }
diff --git a/Libraries/LibWebView/ViewImplementation.cpp b/Libraries/LibWebView/ViewImplementation.cpp
index 3ecf2b94a91..cc45a66749f 100644
--- a/Libraries/LibWebView/ViewImplementation.cpp
+++ b/Libraries/LibWebView/ViewImplementation.cpp
@@ -5516,12 +5516,8 @@ void ViewImplementation::did_request_page_context_menu(Badge<WebContentPage>, We
});
}
-void ViewImplementation::did_request_link_context_menu(Badge<WebContentPage>, Gfx::IntPoint content_position, Web::HTML::PreparedNavigationDescriptor navigation, Optional<u64> text_fragment_generation_id)
+void ViewImplementation::add_link_actions(Menu& menu, Web::HTML::PreparedNavigationDescriptor const& navigation)
{
- request_text_fragment_url(text_fragment_generation_id);
- prepare_inspect_element_action(content_position);
- ++m_context_menu_request_id;
-
auto url = navigation.url;
auto copy_url_text = [&] {
switch (url_type(url)) {
@@ -5535,16 +5531,25 @@ void ViewImplementation::did_request_link_context_menu(Badge<WebContentPage>, Gf
VERIFY_NOT_REACHED();
}();
- auto menu = Menu::create("Link Context Menu"sv);
- add_open_url_actions(*menu, url, navigation);
- menu->add_separator();
- menu->add_action(create_copy_url_action(copy_url_text, url));
- menu->add_action(Action::create("Download Linked File"sv, ActionID::DownloadLinkedFile, [this, url]() {
+ add_open_url_actions(menu, url, navigation);
+ menu.add_separator();
+ menu.add_action(create_copy_url_action(copy_url_text, url));
+ menu.add_action(Action::create("Download Linked File"sv, ActionID::DownloadLinkedFile, [this, url]() {
download_url(url, PromptForPath::No);
}));
- menu->add_action(Action::create("Save Link As…"sv, ActionID::DownloadLinkedFileAs, [this, url]() {
+ menu.add_action(Action::create("Save Link As…"sv, ActionID::DownloadLinkedFileAs, [this, url]() {
download_url(url, PromptForPath::Yes);
}));
+}
+
+void ViewImplementation::did_request_link_context_menu(Badge<WebContentPage>, Gfx::IntPoint content_position, Web::HTML::PreparedNavigationDescriptor navigation, Optional<u64> text_fragment_generation_id)
+{
+ request_text_fragment_url(text_fragment_generation_id);
+ prepare_inspect_element_action(content_position);
+ ++m_context_menu_request_id;
+
+ auto menu = Menu::create("Link Context Menu"sv);
+ add_link_actions(*menu, navigation);
menu->add_action(*m_copy_link_to_highlight_action);
menu->add_separator();
menu->add_action(*m_inspect_element_action);
@@ -5572,7 +5577,7 @@ void ViewImplementation::download_url(URL::URL const& url, PromptForPath prompt_
});
}
-void ViewImplementation::did_request_image_context_menu(Badge<WebContentPage>, Gfx::IntPoint content_position, Web::HTML::PreparedNavigationDescriptor navigation, Optional<Gfx::ShareableBitmap> bitmap)
+void ViewImplementation::did_request_image_context_menu(Badge<WebContentPage>, Gfx::IntPoint content_position, Web::HTML::PreparedNavigationDescriptor navigation, Optional<Gfx::ShareableBitmap> bitmap, Optional<Web::HTML::PreparedNavigationDescriptor> link_navigation)
{
prepare_inspect_element_action(content_position);
++m_context_menu_request_id;
@@ -5591,6 +5596,10 @@ void ViewImplementation::did_request_image_context_menu(Badge<WebContentPage>, G
copy_image_action->set_enabled(bitmap.has_value());
auto menu = Menu::create("Image Context Menu"sv);
+ if (link_navigation.has_value()) {
+ add_link_actions(*menu, *link_navigation);
+ menu->add_separator();
+ }
add_open_in_new_tab_action(*menu, "Open Image in New Tab"sv, url, navigation);
menu->add_action(Action::create("Open Image"sv, ActionID::OpenImage, [this, navigation]() {
load(navigation);
diff --git a/Libraries/LibWebView/ViewImplementation.h b/Libraries/LibWebView/ViewImplementation.h
index f47b8e88129..037d18b5339 100644
--- a/Libraries/LibWebView/ViewImplementation.h
+++ b/Libraries/LibWebView/ViewImplementation.h
@@ -699,7 +699,7 @@ public:
void reset_spell_checking();
void did_request_link_context_menu(Badge<WebContentPage>, Gfx::IntPoint content_position, Web::HTML::PreparedNavigationDescriptor, Optional<u64> text_fragment_generation_id);
void did_generate_text_fragment_url(u64 request_id, Optional<URL::URL>);
- void did_request_image_context_menu(Badge<WebContentPage>, Gfx::IntPoint content_position, Web::HTML::PreparedNavigationDescriptor, Optional<Gfx::ShareableBitmap> bitmap);
+ void did_request_image_context_menu(Badge<WebContentPage>, Gfx::IntPoint content_position, Web::HTML::PreparedNavigationDescriptor, Optional<Gfx::ShareableBitmap> bitmap, Optional<Web::HTML::PreparedNavigationDescriptor> link_navigation);
void did_request_media_context_menu(Badge<WebContentPage>, WebContentPage& requesting_page, Gfx::IntPoint content_position, Web::MediaContextMenu, Optional<Web::HTML::PreparedNavigationDescriptor>);
void did_request_color_picker(Badge<WebContentPage>, WebContentPage& requesting_page, Color current_color);
@@ -859,6 +859,7 @@ protected:
NonnullRefPtr<Menu> create_selected_text_link_context_menu(bool is_editable, String const& selected_text, URL::URL const&, Optional<DictionaryLookup> const&, Gfx::IntPoint content_position);
void add_open_in_new_tab_action(Menu&, StringView text, URL::URL const&, Optional<Web::HTML::PreparedNavigationDescriptor> const&);
void add_open_url_actions(Menu&, URL::URL const&, Optional<Web::HTML::PreparedNavigationDescriptor> const&);
+ void add_link_actions(Menu&, Web::HTML::PreparedNavigationDescriptor const&);
void add_text_edit_actions(Menu&, bool is_editable, bool has_selected_text);
void add_look_up_action(Menu&, Optional<DictionaryLookup> const&, Gfx::IntPoint content_position);
void update_report_website_issue_action();
diff --git a/Libraries/LibWebView/WebContentPage.cpp b/Libraries/LibWebView/WebContentPage.cpp
index 46d936fe1b4..8b44215499b 100644
--- a/Libraries/LibWebView/WebContentPage.cpp
+++ b/Libraries/LibWebView/WebContentPage.cpp
@@ -2996,13 +2996,17 @@ void WebContentPage::did_generate_text_fragment_url(u64 request_id, Optional<URL
view().did_generate_text_fragment_url(request_id, move(url));
}
-void WebContentPage::did_request_image_context_menu(Web::HTML::CrossProcessId local_root_id, Gfx::IntPoint content_position, Web::HTML::PreparedNavigationDescriptor navigation, ByteString, unsigned, Optional<Gfx::ShareableBitmap> bitmap)
+void WebContentPage::did_request_image_context_menu(Web::HTML::CrossProcessId local_root_id, Gfx::IntPoint content_position, Web::HTML::PreparedNavigationDescriptor navigation, ByteString, unsigned, Optional<Gfx::ShareableBitmap> bitmap, Optional<Web::HTML::PreparedNavigationDescriptor> link_navigation)
{
auto verified_navigation = navigation_from_page(client(), move(navigation));
if (!verified_navigation.has_value())
return;
+ // NB: A link the page may not navigate to takes only its own actions out of the menu, the image's stay.
+ Optional<Web::HTML::PreparedNavigationDescriptor> verified_link_navigation;
+ if (link_navigation.has_value())
+ verified_link_navigation = navigation_from_page(client(), link_navigation.release_value());
if (auto target = view_position(local_root_id, content_position); target.has_value())
- target->view.did_request_image_context_menu({}, target->position, verified_navigation.release_value(), move(bitmap));
+ target->view.did_request_image_context_menu({}, target->position, verified_navigation.release_value(), move(bitmap), move(verified_link_navigation));
}
void WebContentPage::did_request_media_context_menu(Web::HTML::CrossProcessId local_root_id, Gfx::IntPoint content_position, ByteString, unsigned, Web::MediaContextMenu menu, Optional<Web::HTML::PreparedNavigationDescriptor> navigation)
diff --git a/Libraries/LibWebView/WebContentPage.h b/Libraries/LibWebView/WebContentPage.h
index 5ab8102291a..70e003f0d64 100644
--- a/Libraries/LibWebView/WebContentPage.h
+++ b/Libraries/LibWebView/WebContentPage.h
@@ -365,7 +365,7 @@ private:
virtual void did_request_context_menu(Web::HTML::CrossProcessId local_root_id, Gfx::IntPoint content_position, Web::ContextMenuForInputEventsTarget for_input_events_target, Optional<Utf16String> misspelled_word, Optional<u64> text_fragment_generation_id) override;
virtual void did_request_link_context_menu(Web::HTML::CrossProcessId local_root_id, Gfx::IntPoint content_position, Web::HTML::PreparedNavigationDescriptor navigation, ByteString, unsigned, Optional<u64> text_fragment_generation_id) override;
virtual void did_generate_text_fragment_url(u64 request_id, Optional<URL::URL> url) override;
- virtual void did_request_image_context_menu(Web::HTML::CrossProcessId local_root_id, Gfx::IntPoint content_position, Web::HTML::PreparedNavigationDescriptor navigation, ByteString, unsigned, Optional<Gfx::ShareableBitmap> bitmap) override;
+ virtual void did_request_image_context_menu(Web::HTML::CrossProcessId local_root_id, Gfx::IntPoint content_position, Web::HTML::PreparedNavigationDescriptor navigation, ByteString, unsigned, Optional<Gfx::ShareableBitmap> bitmap, Optional<Web::HTML::PreparedNavigationDescriptor> link_navigation) override;
virtual void did_request_media_context_menu(Web::HTML::CrossProcessId local_root_id, Gfx::IntPoint content_position, ByteString, unsigned, Web::MediaContextMenu menu, Optional<Web::HTML::PreparedNavigationDescriptor> navigation) override;
virtual void did_get_highlighted_source(String html) override;
virtual void did_get_debugger_environments(u64 request_id, Optional<String> error, Vector<DebuggerEnvironment> environments) override;
diff --git a/Services/WebContent/PageClient.cpp b/Services/WebContent/PageClient.cpp
index 391c72571e3..6f82c2ef9d9 100644
--- a/Services/WebContent/PageClient.cpp
+++ b/Services/WebContent/PageClient.cpp
@@ -1304,13 +1304,13 @@ void PageClient::page_did_request_link_context_menu(Web::HTML::CrossProcessId lo
client().async_did_request_link_context_menu(m_id, local_root_id, page().css_to_device_point(content_position).to_type<int>(), move(navigation), target, modifiers, text_fragment_generation_id);
}
-void PageClient::page_did_request_image_context_menu(Web::HTML::CrossProcessId local_root_id, Web::CSSPixelPoint content_position, Web::HTML::PreparedNavigationDescriptor navigation, ByteString const& target, unsigned modifiers, Optional<Gfx::Bitmap const*> bitmap_pointer)
+void PageClient::page_did_request_image_context_menu(Web::HTML::CrossProcessId local_root_id, Web::CSSPixelPoint content_position, Web::HTML::PreparedNavigationDescriptor navigation, ByteString const& target, unsigned modifiers, Optional<Gfx::Bitmap const*> bitmap_pointer, Optional<Web::HTML::PreparedNavigationDescriptor> link_navigation)
{
Optional<Gfx::ShareableBitmap> bitmap;
if (bitmap_pointer.has_value() && bitmap_pointer.value())
bitmap = bitmap_pointer.value()->to_shareable_bitmap();
- client().async_did_request_image_context_menu(m_id, local_root_id, page().css_to_device_point(content_position).to_type<int>(), move(navigation), target, modifiers, bitmap);
+ client().async_did_request_image_context_menu(m_id, local_root_id, page().css_to_device_point(content_position).to_type<int>(), move(navigation), target, modifiers, bitmap, move(link_navigation));
}
void PageClient::page_did_request_media_context_menu(Web::HTML::CrossProcessId local_root_id, Web::CSSPixelPoint content_position, ByteString const& target, unsigned modifiers, Web::Page::MediaContextMenu const& menu, Optional<Web::HTML::PreparedNavigationDescriptor> navigation)
diff --git a/Services/WebContent/PageClient.h b/Services/WebContent/PageClient.h
index 6936ff8b790..30d42034deb 100644
--- a/Services/WebContent/PageClient.h
+++ b/Services/WebContent/PageClient.h
@@ -275,7 +275,7 @@ private:
virtual void page_did_request_context_menu(Web::HTML::CrossProcessId local_root_id, Web::CSSPixelPoint, Web::ContextMenuForInputEventsTarget, Optional<Utf16String> misspelled_word, GC::Ptr<Web::DOM::Range> selected_text_range) override;
virtual void page_did_request_spelling_menu_action_for_testing(Web::SpellingMenuActionForTesting, u32 guess_index) override;
virtual void page_did_request_link_context_menu(Web::HTML::CrossProcessId local_root_id, Web::CSSPixelPoint, Web::HTML::PreparedNavigationDescriptor, ByteString const& target, unsigned modifiers, GC::Ptr<Web::DOM::Range> selected_text_range) override;
- virtual void page_did_request_image_context_menu(Web::HTML::CrossProcessId local_root_id, Web::CSSPixelPoint, Web::HTML::PreparedNavigationDescriptor, ByteString const& target, unsigned modifiers, Optional<Gfx::Bitmap const*>) override;
+ virtual void page_did_request_image_context_menu(Web::HTML::CrossProcessId local_root_id, Web::CSSPixelPoint, Web::HTML::PreparedNavigationDescriptor, ByteString const& target, unsigned modifiers, Optional<Gfx::Bitmap const*>, Optional<Web::HTML::PreparedNavigationDescriptor> link_navigation) override;
virtual void page_did_request_media_context_menu(Web::HTML::CrossProcessId local_root_id, Web::CSSPixelPoint, ByteString const& target, unsigned modifiers, Web::Page::MediaContextMenu const&, Optional<Web::HTML::PreparedNavigationDescriptor>) override;
virtual void page_did_change_active_document_in_top_level_browsing_context(Web::DOM::Document&) override;
virtual void page_did_change_active_document_in_child_navigable(Web::DOM::Document&) override;
diff --git a/Services/WebContent/WebContentClient.ipc b/Services/WebContent/WebContentClient.ipc
index f762890ef65..502512d73e9 100644
--- a/Services/WebContent/WebContentClient.ipc
+++ b/Services/WebContent/WebContentClient.ipc
@@ -136,7 +136,7 @@ endpoint WebContentClient routed by Web::PageId page_id
did_request_context_menu(Web::PageId page_id, Web::HTML::CrossProcessId local_root_id, Gfx::IntPoint content_position, Web::ContextMenuForInputEventsTarget for_input_events_target, Optional<Utf16String> misspelled_word, Optional<u64> text_fragment_generation_id) =|
did_request_link_context_menu(Web::PageId page_id, Web::HTML::CrossProcessId local_root_id, Gfx::IntPoint content_position, Web::HTML::PreparedNavigationDescriptor navigation, ByteString target, unsigned modifiers, Optional<u64> text_fragment_generation_id) =|
did_generate_text_fragment_url(Web::PageId page_id, u64 request_id, Optional<URL::URL> url) =|
- did_request_image_context_menu(Web::PageId page_id, Web::HTML::CrossProcessId local_root_id, Gfx::IntPoint content_position, Web::HTML::PreparedNavigationDescriptor navigation, ByteString target, unsigned modifiers, Optional<Gfx::ShareableBitmap> bitmap) =|
+ did_request_image_context_menu(Web::PageId page_id, Web::HTML::CrossProcessId local_root_id, Gfx::IntPoint content_position, Web::HTML::PreparedNavigationDescriptor navigation, ByteString target, unsigned modifiers, Optional<Gfx::ShareableBitmap> bitmap, Optional<Web::HTML::PreparedNavigationDescriptor> link_navigation) =|
did_request_media_context_menu(Web::PageId page_id, Web::HTML::CrossProcessId local_root_id, Gfx::IntPoint content_position, ByteString target, unsigned modifiers, Web::MediaContextMenu menu, Optional<Web::HTML::PreparedNavigationDescriptor> navigation) =|
did_request_alert(Web::PageId page_id, Utf16String message) =|
did_request_before_unload(Web::PageId page_id, String source) =|
diff --git a/Tests/LibWeb/Text/expected/UIEvents/context-menu-linked-image.txt b/Tests/LibWeb/Text/expected/UIEvents/context-menu-linked-image.txt
index a2de5310dac..66c56d67bf2 100644
--- a/Tests/LibWeb/Text/expected/UIEvents/context-menu-linked-image.txt
+++ b/Tests/LibWeb/Text/expected/UIEvents/context-menu-linked-image.txt
@@ -1,3 +1,3 @@
-right-click #linked: link target=A#link
+right-click #linked: image target=IMG#linked link=https://example.com/around-image
right-click #linked-sourceless: link target=A#sourceless-link
-right-click #sourceless: image target=IMG#sourceless
+right-click #sourceless: page target=IMG#sourceless
diff --git a/Tests/LibWeb/Text/expected/UIEvents/image-map-context-menu-target.txt b/Tests/LibWeb/Text/expected/UIEvents/image-map-context-menu-target.txt
index a4538302559..4384afdee85 100644
--- a/Tests/LibWeb/Text/expected/UIEvents/image-map-context-menu-target.txt
+++ b/Tests/LibWeb/Text/expected/UIEvents/image-map-context-menu-target.txt
@@ -1,2 +1,2 @@
right-click #mapped: image target=IMG#mapped
-right-click #linkmapped: link target=AREA#linkarea
+right-click #linkmapped: image target=IMG#linkmapped link=https://example.com/area
diff --git a/Tests/LibWeb/Text/input/UIEvents/image-map-context-menu-target.html b/Tests/LibWeb/Text/input/UIEvents/image-map-context-menu-target.html
index d0fff80c628..96c55f07453 100644
--- a/Tests/LibWeb/Text/input/UIEvents/image-map-context-menu-target.html
+++ b/Tests/LibWeb/Text/input/UIEvents/image-map-context-menu-target.html
@@ -17,13 +17,14 @@
<script>
test(() => {
// An <area> is never rendered, so a right-click over an image map hit-tests to the area while the user agent
- // menu describes the image whose box was hit - unless the area is itself a link, which wins.
+ // menu describes the image whose box was hit. An area that is itself a link adds that link to the menu.
const describe = () => {
const request = internals.takeContextMenuRequest();
if (!request)
return 'no request';
const target = request.target;
- return `${request.kind} target=${target.id ? `${target.nodeName}#${target.id}` : target.nodeName}`;
+ const link = request.linkURL ? ` link=${request.linkURL}` : '';
+ return `${request.kind} target=${target.id ? `${target.nodeName}#${target.id}` : target.nodeName}${link}`;
};
const rightClickAt = element => {
const rect = element.getBoundingClientRect();