Frame.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 <LibGfx/Bitmap.h>
  32. #include <LibGfx/Rect.h>
  33. #include <LibGfx/Size.h>
  34. #include <LibWeb/Frame/EventHandler.h>
  35. #include <LibWeb/Loader/FrameLoader.h>
  36. #include <LibWeb/TreeNode.h>
  37. namespace Web {
  38. class Frame : public TreeNode<Frame> {
  39. public:
  40. static NonnullRefPtr<Frame> create_subframe(Element& host_element, Frame& main_frame) { return adopt(*new Frame(host_element, main_frame)); }
  41. static NonnullRefPtr<Frame> create(Page& page) { return adopt(*new Frame(page)); }
  42. ~Frame();
  43. bool is_main_frame() const { return this == &m_main_frame; }
  44. const Document* document() const { return m_document; }
  45. Document* document() { return m_document; }
  46. void set_document(Document*);
  47. Page& page() { return m_page; }
  48. const Page& page() const { return m_page; }
  49. const Gfx::IntSize& size() const { return m_size; }
  50. void set_size(const Gfx::IntSize&);
  51. void set_needs_display(const Gfx::IntRect&);
  52. void set_viewport_rect(const Gfx::IntRect&);
  53. Gfx::IntRect viewport_rect() const { return m_viewport_rect; }
  54. void did_scroll(Badge<PageView>);
  55. FrameLoader& loader() { return m_loader; }
  56. const FrameLoader& loader() const { return m_loader; }
  57. EventHandler& event_handler() { return m_event_handler; }
  58. const EventHandler& event_handler() const { return m_event_handler; }
  59. void scroll_to_anchor(const String&);
  60. Frame& main_frame() { return m_main_frame; }
  61. const Frame& main_frame() const { return m_main_frame; }
  62. Element* host_element() { return m_host_element; }
  63. const Element* host_element() const { return m_host_element; }
  64. Gfx::IntPoint to_main_frame_position(const Gfx::IntPoint&);
  65. Gfx::IntRect to_main_frame_rect(const Gfx::IntRect&);
  66. private:
  67. explicit Frame(Element& host_element, Frame& main_frame);
  68. explicit Frame(Page&);
  69. Page& m_page;
  70. Frame& m_main_frame;
  71. FrameLoader m_loader;
  72. EventHandler m_event_handler;
  73. WeakPtr<Element> m_host_element;
  74. RefPtr<Document> m_document;
  75. Gfx::IntSize m_size;
  76. Gfx::IntRect m_viewport_rect;
  77. };
  78. }