Frame.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  19. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  22. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  23. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #pragma once
  27. #include <AK/Function.h>
  28. #include <AK/Noncopyable.h>
  29. #include <AK/RefPtr.h>
  30. #include <AK/WeakPtr.h>
  31. #include <LibCore/Timer.h>
  32. #include <LibGfx/Bitmap.h>
  33. #include <LibGfx/Rect.h>
  34. #include <LibGfx/Size.h>
  35. #include <LibWeb/DOM/Position.h>
  36. #include <LibWeb/Loader/FrameLoader.h>
  37. #include <LibWeb/Page/EventHandler.h>
  38. #include <LibWeb/TreeNode.h>
  39. namespace Web {
  40. class Frame : public TreeNode<Frame> {
  41. public:
  42. static NonnullRefPtr<Frame> create_subframe(DOM::Element& host_element, Frame& main_frame) { return adopt(*new Frame(host_element, main_frame)); }
  43. static NonnullRefPtr<Frame> create(Page& page) { return adopt(*new Frame(page)); }
  44. ~Frame();
  45. bool is_main_frame() const { return this == &m_main_frame; }
  46. bool is_focused_frame() const;
  47. const DOM::Document* document() const { return m_document; }
  48. DOM::Document* document() { return m_document; }
  49. void set_document(DOM::Document*);
  50. Page* page() { return m_page; }
  51. const Page* page() const { return m_page; }
  52. const Gfx::IntSize& size() const { return m_size; }
  53. void set_size(const Gfx::IntSize&);
  54. void set_needs_display(const Gfx::IntRect&);
  55. void set_viewport_scroll_offset(const Gfx::IntPoint&);
  56. Gfx::IntRect viewport_rect() const { return { m_viewport_scroll_offset, m_size }; }
  57. void did_scroll(Badge<InProcessWebView>);
  58. FrameLoader& loader() { return m_loader; }
  59. const FrameLoader& loader() const { return m_loader; }
  60. EventHandler& event_handler() { return m_event_handler; }
  61. const EventHandler& event_handler() const { return m_event_handler; }
  62. void scroll_to(const Gfx::IntPoint&);
  63. void scroll_to_anchor(const String&);
  64. Frame& main_frame() { return m_main_frame; }
  65. const Frame& main_frame() const { return m_main_frame; }
  66. DOM::Element* host_element() { return m_host_element; }
  67. const DOM::Element* host_element() const { return m_host_element; }
  68. Gfx::IntPoint to_main_frame_position(const Gfx::IntPoint&);
  69. Gfx::IntRect to_main_frame_rect(const Gfx::IntRect&);
  70. DOM::Position& cursor_position() { return m_cursor_position; }
  71. const DOM::Position& cursor_position() const { return m_cursor_position; }
  72. void set_cursor_position(const DOM::Position&);
  73. bool cursor_blink_state() const { return m_cursor_blink_state; }
  74. String selected_text() const;
  75. void did_edit(Badge<EditEventHandler>);
  76. private:
  77. explicit Frame(DOM::Element& host_element, Frame& main_frame);
  78. explicit Frame(Page&);
  79. void setup();
  80. WeakPtr<Page> m_page;
  81. Frame& m_main_frame;
  82. FrameLoader m_loader;
  83. EventHandler m_event_handler;
  84. WeakPtr<DOM::Element> m_host_element;
  85. RefPtr<DOM::Document> m_document;
  86. Gfx::IntSize m_size;
  87. Gfx::IntPoint m_viewport_scroll_offset;
  88. DOM::Position m_cursor_position;
  89. RefPtr<Core::Timer> m_cursor_blink_timer;
  90. bool m_cursor_blink_state { false };
  91. };
  92. }