Serenity Operating System
at master 84 lines 2.2 kB view raw
1/* 2 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> 3 * Copyright (c) 2022, the SerenityOS developers. 4 * 5 * SPDX-License-Identifier: BSD-2-Clause 6 */ 7 8#pragma once 9 10#include <LibGUI/Action.h> 11#include <LibGUI/TextEditor.h> 12 13namespace GUI { 14 15class TextBox : public TextEditor { 16 C_OBJECT(TextBox) 17public: 18 virtual ~TextBox() override = default; 19 20 Function<void()> on_up_pressed; 21 Function<void()> on_down_pressed; 22 23 void set_history_enabled(bool enabled) { m_history_enabled = enabled; } 24 void add_current_text_to_history(); 25 26protected: 27 TextBox(); 28 29private: 30 virtual void keydown_event(GUI::KeyEvent&) override; 31 32 bool has_no_history() const { return !m_history_enabled || m_history.is_empty(); } 33 bool can_go_backwards_in_history() const { return m_history_index > 0; } 34 bool can_go_forwards_in_history() const { return m_history_index < static_cast<int>(m_history.size()) - 1; } 35 void add_input_to_history(DeprecatedString); 36 37 bool m_history_enabled { false }; 38 Vector<DeprecatedString> m_history; 39 int m_history_index { -1 }; 40 DeprecatedString m_saved_input; 41}; 42 43class PasswordBox : public TextBox { 44 C_OBJECT(PasswordBox) 45public: 46 bool is_showing_reveal_button() const { return m_show_reveal_button; } 47 void set_show_reveal_button(bool show) 48 { 49 m_show_reveal_button = show; 50 update(); 51 } 52 53private: 54 PasswordBox(); 55 56 virtual void paint_event(PaintEvent&) override; 57 virtual void mousedown_event(GUI::MouseEvent&) override; 58 59 Gfx::IntRect reveal_password_button_rect() const; 60 61 bool m_show_reveal_button { false }; 62}; 63 64class UrlBox : public TextBox { 65 C_OBJECT(UrlBox) 66public: 67 virtual ~UrlBox() override = default; 68 69 void set_focus_transition(bool focus_transition) { m_focus_transition = focus_transition; } 70 bool is_focus_transition() const { return m_focus_transition; } 71 72private: 73 UrlBox(); 74 75 void highlight_url(); 76 77 virtual void mousedown_event(GUI::MouseEvent&) override; 78 virtual void focusout_event(GUI::FocusEvent&) override; 79 virtual void focusin_event(GUI::FocusEvent&) override; 80 81 bool m_focus_transition { true }; 82}; 83 84}