mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 04:12:43 +00:00 
			
		
		
		
	LibWeb: Add Page context menu request
Pages can request a context menu on right click. This is plumbed through the PageClient.
This commit is contained in:
		
							parent
							
								
									d28a824d4c
								
							
						
					
					
						commit
						cc675cbe24
					
				
					 4 changed files with 12 additions and 0 deletions
				
			
		|  | @ -150,6 +150,9 @@ bool EventHandler::handle_mousedown(const Gfx::IntPoint& position, unsigned butt | |||
|             dump_selection("MouseDown"); | ||||
|             m_in_mouse_selection = true; | ||||
|         } | ||||
|         else if (button == GUI::MouseButton::Right) { | ||||
|             page_client.page_did_request_context_menu(m_frame.to_main_frame_position(position)); | ||||
|         } | ||||
|     } | ||||
|     return true; | ||||
| } | ||||
|  |  | |||
|  | @ -74,6 +74,7 @@ public: | |||
|     virtual void page_did_start_loading(const URL&) { } | ||||
|     virtual void page_did_change_selection() { } | ||||
|     virtual void page_did_request_cursor_change(GUI::StandardCursor) { } | ||||
|     virtual void page_did_request_context_menu(const Gfx::IntPoint&) { } | ||||
|     virtual void page_did_request_link_context_menu(const Gfx::IntPoint&, [[maybe_unused]] const String& href, [[maybe_unused]] const String& target, [[maybe_unused]] unsigned modifiers) { } | ||||
|     virtual void page_did_click_link([[maybe_unused]] const String& href, [[maybe_unused]] const String& target, [[maybe_unused]] unsigned modifiers) { } | ||||
|     virtual void page_did_middle_click_link([[maybe_unused]] const String& href, [[maybe_unused]] const String& target, [[maybe_unused]] unsigned modifiers) { } | ||||
|  |  | |||
|  | @ -103,6 +103,12 @@ void PageView::page_did_request_cursor_change(GUI::StandardCursor cursor) | |||
|         window()->set_override_cursor(cursor); | ||||
| } | ||||
| 
 | ||||
| void PageView::page_did_request_context_menu(const Gfx::IntPoint& content_position) | ||||
| { | ||||
|     if (on_context_menu_request) | ||||
|         on_context_menu_request(screen_relative_rect().location().translated(to_widget_position(content_position))); | ||||
| } | ||||
| 
 | ||||
| void PageView::page_did_request_link_context_menu(const Gfx::IntPoint& content_position, const String& href, [[maybe_unused]] const String& target, [[maybe_unused]] unsigned modifiers) | ||||
| { | ||||
|     if (on_link_context_menu_request) | ||||
|  |  | |||
|  | @ -60,6 +60,7 @@ public: | |||
| 
 | ||||
|     void set_should_show_line_box_borders(bool value) { m_should_show_line_box_borders = value; } | ||||
| 
 | ||||
|     Function<void(const Gfx::IntPoint& screen_position)> on_context_menu_request; | ||||
|     Function<void(const String& href, const String& target, unsigned modifiers)> on_link_click; | ||||
|     Function<void(const String& href, const Gfx::IntPoint& screen_position)> on_link_context_menu_request; | ||||
|     Function<void(const String& href)> on_link_middle_click; | ||||
|  | @ -95,6 +96,7 @@ private: | |||
|     virtual void page_did_start_loading(const URL&) override; | ||||
|     virtual void page_did_change_selection() override; | ||||
|     virtual void page_did_request_cursor_change(GUI::StandardCursor) override; | ||||
|     virtual void page_did_request_context_menu(const Gfx::IntPoint&) override; | ||||
|     virtual void page_did_request_link_context_menu(const Gfx::IntPoint&, const String& href, const String& target, unsigned modifiers) override; | ||||
|     virtual void page_did_click_link(const String& href, const String& target, unsigned modifiers) override; | ||||
|     virtual void page_did_middle_click_link(const String& href, const String& target, unsigned modifiers) override; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andrew Kaster
						Andrew Kaster