LayoutFrame.cpp 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. #include <LibGUI/Painter.h>
  27. #include <LibGUI/ScrollBar.h>
  28. #include <LibGUI/Widget.h>
  29. #include <LibGfx/Font.h>
  30. #include <LibGfx/StylePainter.h>
  31. #include <LibWeb/DOM/Document.h>
  32. #include <LibWeb/Frame/Frame.h>
  33. #include <LibWeb/Layout/LayoutDocument.h>
  34. #include <LibWeb/Layout/LayoutFrame.h>
  35. #include <LibWeb/PageView.h>
  36. namespace Web {
  37. LayoutFrame::LayoutFrame(const Element& element, NonnullRefPtr<StyleProperties> style)
  38. : LayoutReplaced(element, move(style))
  39. {
  40. }
  41. LayoutFrame::~LayoutFrame()
  42. {
  43. }
  44. void LayoutFrame::layout(LayoutMode layout_mode)
  45. {
  46. ASSERT(node().hosted_frame());
  47. set_has_intrinsic_width(true);
  48. set_has_intrinsic_height(true);
  49. // FIXME: Do proper error checking, etc.
  50. bool ok;
  51. set_intrinsic_width(node().attribute(HTML::AttributeNames::width).to_int(ok));
  52. set_intrinsic_height(node().attribute(HTML::AttributeNames::height).to_int(ok));
  53. LayoutReplaced::layout(layout_mode);
  54. }
  55. void LayoutFrame::render(RenderingContext& context)
  56. {
  57. LayoutReplaced::render(context);
  58. context.painter().save();
  59. auto old_viewport_rect = context.viewport_rect();
  60. context.painter().add_clip_rect(enclosing_int_rect(absolute_rect()));
  61. context.painter().translate(absolute_x(), absolute_y());
  62. context.set_viewport_rect({ {}, node().hosted_frame()->size() });
  63. node().hosted_frame()->document()->layout_node()->render(context);
  64. context.set_viewport_rect(old_viewport_rect);
  65. context.painter().restore();
  66. }
  67. void LayoutFrame::did_set_rect()
  68. {
  69. LayoutReplaced::did_set_rect();
  70. ASSERT(node().hosted_frame());
  71. node().hosted_frame()->set_size(size().to_int_size());
  72. }
  73. }