1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:47:44 +00:00

LibGfx: Move StandardCursor enum to LibGfx

This enum existed both in LibGUI and WindowServer which was silly and
error-prone.
This commit is contained in:
Andreas Kling 2020-09-10 19:25:13 +02:00
parent c063a02979
commit 0f9be82826
23 changed files with 127 additions and 111 deletions

View file

@ -100,11 +100,11 @@ void ColorInput::mouseup_event(MouseEvent& event)
void ColorInput::mousemove_event(MouseEvent& event)
{
if (color_rect().contains(event.position())) {
window()->set_override_cursor(StandardCursor::Hand);
window()->set_override_cursor(Gfx::StandardCursor::Hand);
event.accept();
return;
} else {
window()->set_override_cursor(StandardCursor::IBeam);
window()->set_override_cursor(Gfx::StandardCursor::IBeam);
}
TextEditor::mousemove_event(event);

View file

@ -180,7 +180,7 @@ void HeaderView::mousemove_event(MouseEvent& event)
bool found_hovered_header = false;
for (int i = 0; i < section_count; ++i) {
if (section_resize_grabbable_rect(i).contains(event.position())) {
window()->set_override_cursor(StandardCursor::ResizeColumn);
window()->set_override_cursor(Gfx::StandardCursor::ResizeColumn);
set_hovered_section(-1);
return;
}
@ -192,7 +192,7 @@ void HeaderView::mousemove_event(MouseEvent& event)
if (!found_hovered_header)
set_hovered_section(-1);
}
window()->set_override_cursor(StandardCursor::None);
window()->set_override_cursor(Gfx::StandardCursor::None);
}
void HeaderView::mouseup_event(MouseEvent& event)
@ -200,7 +200,7 @@ void HeaderView::mouseup_event(MouseEvent& event)
if (event.button() == MouseButton::Left) {
if (m_in_section_resize) {
if (!section_resize_grabbable_rect(m_resizing_section).contains(event.position()))
window()->set_override_cursor(StandardCursor::None);
window()->set_override_cursor(Gfx::StandardCursor::None);
m_in_section_resize = false;
return;
}
@ -337,7 +337,7 @@ void HeaderView::leave_event(Core::Event& event)
{
Widget::leave_event(event);
set_hovered_section(-1);
window()->set_override_cursor(StandardCursor::None);
window()->set_override_cursor(Gfx::StandardCursor::None);
}
Gfx::TextAlignment HeaderView::section_alignment(int section) const

View file

@ -112,13 +112,13 @@ void ResizeCorner::mousedown_event(MouseEvent& event)
void ResizeCorner::enter_event(Core::Event& event)
{
window()->set_override_cursor(StandardCursor::ResizeDiagonalTLBR);
window()->set_override_cursor(Gfx::StandardCursor::ResizeDiagonalTLBR);
Widget::enter_event(event);
}
void ResizeCorner::leave_event(Core::Event& event)
{
window()->set_override_cursor(StandardCursor::None);
window()->set_override_cursor(Gfx::StandardCursor::None);
Widget::leave_event(event);
}

View file

@ -62,12 +62,12 @@ void Splitter::override_cursor(bool do_override)
{
if (do_override) {
if (!m_overriding_cursor) {
window()->set_override_cursor(m_orientation == Orientation::Horizontal ? StandardCursor::ResizeColumn : StandardCursor::ResizeRow);
window()->set_override_cursor(m_orientation == Orientation::Horizontal ? Gfx::StandardCursor::ResizeColumn : Gfx::StandardCursor::ResizeRow);
m_overriding_cursor = true;
}
} else {
if (m_overriding_cursor) {
window()->set_override_cursor(StandardCursor::None);
window()->set_override_cursor(Gfx::StandardCursor::None);
m_overriding_cursor = false;
}
}
@ -198,7 +198,7 @@ void Splitter::mouseup_event(MouseEvent& event)
m_first_resizee = nullptr;
m_second_resizee = nullptr;
if (!rect().contains(event.position()))
window()->set_override_cursor(StandardCursor::None);
window()->set_override_cursor(Gfx::StandardCursor::None);
}
}

View file

@ -1343,7 +1343,7 @@ void TextEditor::enter_event(Core::Event&)
{
ASSERT(window());
if (!is_displayonly())
window()->set_override_cursor(StandardCursor::IBeam);
window()->set_override_cursor(Gfx::StandardCursor::IBeam);
m_automatic_selection_scroll_timer->stop();
}
@ -1351,7 +1351,7 @@ void TextEditor::enter_event(Core::Event&)
void TextEditor::leave_event(Core::Event&)
{
ASSERT(window());
window()->set_override_cursor(StandardCursor::None);
window()->set_override_cursor(Gfx::StandardCursor::None);
if (m_in_drag_select)
m_automatic_selection_scroll_timer->start();

View file

@ -93,7 +93,7 @@ void Window::show()
auto* parent_window = find_parent_window();
m_override_cursor = StandardCursor::None;
m_override_cursor = Gfx::StandardCursor::None;
auto response = WindowServerConnection::the().send_sync<Messages::WindowServer::CreateWindow>(
m_rect_when_windowless,
!m_moved_by_client,
@ -138,7 +138,7 @@ void Window::server_did_destroy()
m_pending_paint_event_rects.clear();
m_back_bitmap = nullptr;
m_front_bitmap = nullptr;
m_override_cursor = StandardCursor::None;
m_override_cursor = Gfx::StandardCursor::None;
}
void Window::hide()
@ -226,7 +226,7 @@ void Window::set_window_type(WindowType window_type)
m_window_type = window_type;
}
void Window::set_override_cursor(StandardCursor cursor)
void Window::set_override_cursor(Gfx::StandardCursor cursor)
{
if (!is_visible())
return;

View file

@ -36,26 +36,10 @@
#include <LibGfx/Color.h>
#include <LibGfx/Forward.h>
#include <LibGfx/Rect.h>
#include <LibGfx/StandardCursor.h>
namespace GUI {
enum class StandardCursor {
None = 0,
Arrow,
IBeam,
ResizeHorizontal,
ResizeVertical,
ResizeDiagonalTLBR,
ResizeDiagonalBLTR,
ResizeColumn,
ResizeRow,
Hand,
Help,
Drag,
Move,
Wait,
};
class Window : public Core::Object {
C_OBJECT(Window)
public:
@ -184,7 +168,7 @@ public:
void set_no_resize_aspect_ratio() { set_resize_aspect_ratio({}); }
void set_resize_aspect_ratio(const Optional<Gfx::IntSize>& ratio);
void set_override_cursor(StandardCursor);
void set_override_cursor(Gfx::StandardCursor);
void set_override_cursor(const Gfx::Bitmap&);
void set_icon(const Gfx::Bitmap*);
@ -257,7 +241,7 @@ private:
Gfx::IntSize m_base_size;
Color m_background_color { Color::WarmGray };
WindowType m_window_type { WindowType::Normal };
StandardCursor m_override_cursor { StandardCursor::None };
Gfx::StandardCursor m_override_cursor { Gfx::StandardCursor::None };
bool m_is_active { false };
bool m_is_active_input { false };
bool m_has_alpha_channel { false };

View file

@ -0,0 +1,48 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
namespace Gfx {
enum class StandardCursor {
None = 0,
Arrow,
IBeam,
ResizeHorizontal,
ResizeVertical,
ResizeDiagonalTLBR,
ResizeDiagonalBLTR,
ResizeColumn,
ResizeRow,
Hand,
Help,
Drag,
Move,
Wait,
};
}

View file

@ -629,9 +629,9 @@ void TerminalWidget::mousemove_event(GUI::MouseEvent& event)
m_hovered_href = {};
}
if (!m_hovered_href.is_empty())
window()->set_override_cursor(GUI::StandardCursor::Hand);
window()->set_override_cursor(Gfx::StandardCursor::Hand);
else
window()->set_override_cursor(GUI::StandardCursor::None);
window()->set_override_cursor(Gfx::StandardCursor::None);
update();
}
@ -667,7 +667,7 @@ void TerminalWidget::mousemove_event(GUI::MouseEvent& event)
void TerminalWidget::leave_event(Core::Event&)
{
window()->set_override_cursor(GUI::StandardCursor::None);
window()->set_override_cursor(Gfx::StandardCursor::None);
bool should_update = !m_hovered_href.is_empty();
m_hovered_href = {};
m_hovered_href_id = {};

View file

@ -150,7 +150,7 @@ void InProcessWebView::page_did_change_selection()
update();
}
void InProcessWebView::page_did_request_cursor_change(GUI::StandardCursor cursor)
void InProcessWebView::page_did_request_cursor_change(Gfx::StandardCursor cursor)
{
if (window())
window()->set_override_cursor(cursor);
@ -358,7 +358,7 @@ void InProcessWebView::load_html(const StringView& html, const URL& url)
bool InProcessWebView::load(const URL& url)
{
if (window())
window()->set_override_cursor(GUI::StandardCursor::None);
window()->set_override_cursor(Gfx::StandardCursor::None);
return page().main_frame().loader().load(url, FrameLoader::Type::Navigation);
}
@ -378,7 +378,7 @@ LayoutDocument* InProcessWebView::layout_root()
void InProcessWebView::page_did_request_scroll_into_view(const Gfx::IntRect& rect)
{
scroll_into_view(rect, true, true);
window()->set_override_cursor(GUI::StandardCursor::None);
window()->set_override_cursor(Gfx::StandardCursor::None);
}
void InProcessWebView::load_empty_document()

View file

@ -91,7 +91,7 @@ private:
virtual void page_did_set_document_in_main_frame(DOM::Document*) override;
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_cursor_change(Gfx::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 URL&, const String& target, unsigned modifiers) override;
virtual void page_did_click_link(const URL&, const String& target, unsigned modifiers) override;

View file

@ -138,7 +138,7 @@ void OutOfProcessWebView::notify_server_did_request_scroll_into_view(Badge<WebCo
void OutOfProcessWebView::notify_server_did_hover_link(Badge<WebContentClient>, const URL& url)
{
if (window())
window()->set_override_cursor(GUI::StandardCursor::Hand);
window()->set_override_cursor(Gfx::StandardCursor::Hand);
if (on_link_hover)
on_link_hover(url);
}
@ -146,7 +146,7 @@ void OutOfProcessWebView::notify_server_did_hover_link(Badge<WebContentClient>,
void OutOfProcessWebView::notify_server_did_unhover_link(Badge<WebContentClient>)
{
if (window())
window()->set_override_cursor(GUI::StandardCursor::None);
window()->set_override_cursor(Gfx::StandardCursor::None);
if (on_link_hover)
on_link_hover({});
}

View file

@ -216,11 +216,11 @@ bool EventHandler::handle_mousemove(const Gfx::IntPoint& position, unsigned butt
}
if (is_hovering_link)
page_client.page_did_request_cursor_change(GUI::StandardCursor::Hand);
page_client.page_did_request_cursor_change(Gfx::StandardCursor::Hand);
else if (is_hovering_text)
page_client.page_did_request_cursor_change(GUI::StandardCursor::IBeam);
page_client.page_did_request_cursor_change(Gfx::StandardCursor::IBeam);
else
page_client.page_did_request_cursor_change(GUI::StandardCursor::None);
page_client.page_did_request_cursor_change(Gfx::StandardCursor::None);
if (hovered_node_changed) {
RefPtr<HTML::HTMLElement> hovered_html_element = document.hovered_node() ? document.hovered_node()->enclosing_html_element() : nullptr;

View file

@ -82,7 +82,7 @@ public:
virtual void page_did_change_title(const String&) { }
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_cursor_change(Gfx::StandardCursor) { }
virtual void page_did_request_context_menu(const Gfx::IntPoint&) { }
virtual void page_did_request_link_context_menu(const Gfx::IntPoint&, const URL&, [[maybe_unused]] const String& target, [[maybe_unused]] unsigned modifiers) { }
virtual void page_did_click_link(const URL&, [[maybe_unused]] const String& target, [[maybe_unused]] unsigned modifiers) { }