Frame.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. const DOM::Document* document() const { return m_document; }
  47. DOM::Document* document() { return m_document; }
  48. void set_document(DOM::Document*);
  49. Page& page() { return m_page; }
  50. const Page& page() const { return m_page; }
  51. const Gfx::IntSize& size() const { return m_size; }
  52. void set_size(const Gfx::IntSize&);
  53. void set_needs_display(const Gfx::IntRect&);
  54. void set_viewport_rect(const Gfx::IntRect&);
  55. Gfx::IntRect viewport_rect() const { return m_viewport_rect; }
  56. void did_scroll(Badge<PageView>);
  57. FrameLoader& loader() { return m_loader; }
  58. const FrameLoader& loader() const { return m_loader; }
  59. EventHandler& event_handler() { return m_event_handler; }
  60. const EventHandler& event_handler() const { return m_event_handler; }
  61. void scroll_to(const Gfx::IntPoint&);
  62. void scroll_to_anchor(const String&);
  63. Frame& main_frame() { return m_main_frame; }
  64. const Frame& main_frame() const { return m_main_frame; }
  65. DOM::Element* host_element() { return m_host_element; }
  66. const DOM::Element* host_element() const { return m_host_element; }
  67. Gfx::IntPoint to_main_frame_position(const Gfx::IntPoint&);
  68. Gfx::IntRect to_main_frame_rect(const Gfx::IntRect&);
  69. DOM::Position& cursor_position() { return m_cursor_position; }
  70. const DOM::Position& cursor_position() const { return m_cursor_position; }
  71. void set_cursor_position(const DOM::Position&);
  72. bool cursor_blink_state() const { return m_cursor_blink_state; }
  73. private:
  74. explicit Frame(DOM::Element& host_element, Frame& main_frame);
  75. explicit Frame(Page&);
  76. void setup();
  77. Page& m_page;
  78. Frame& m_main_frame;
  79. FrameLoader m_loader;
  80. EventHandler m_event_handler;
  81. WeakPtr<DOM::Element> m_host_element;
  82. RefPtr<DOM::Document> m_document;
  83. Gfx::IntSize m_size;
  84. Gfx::IntRect m_viewport_rect;
  85. DOM::Position m_cursor_position;
  86. RefPtr<Core::Timer> m_cursor_blink_timer;
  87. bool m_cursor_blink_state { false };
  88. };
  89. }