mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 09:38:11 +00:00

The "paintable" state in Layout::Box was actually not safe to access until after layout had been performed. As a first step towards making this harder to mess up accidentally, this patch moves painting information from Layout::Box to a new class: Painting::Box. Every layout can have a corresponding paint box, and it holds the final used metrics determined by layout. The paint box is created and populated by FormattingState::commit(). I've also added DOM::Node::paint_box() as a convenient way to access the paint box (if available) of a given DOM node. Going forward, I believe this will allow us to better separate data that belongs to layout vs painting, and also open up opportunities for naturally invalidating caches in the paint box (since it's reconstituted by every layout.)
47 lines
1.7 KiB
C++
47 lines
1.7 KiB
C++
/*
|
|
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <LibWeb/Layout/Box.h>
|
|
#include <LibWeb/Layout/LineBox.h>
|
|
|
|
namespace Web::Layout {
|
|
|
|
// https://www.w3.org/TR/css-display/#block-container
|
|
class BlockContainer : public Box {
|
|
public:
|
|
BlockContainer(DOM::Document&, DOM::Node*, NonnullRefPtr<CSS::StyleProperties>);
|
|
BlockContainer(DOM::Document&, DOM::Node*, CSS::ComputedValues);
|
|
virtual ~BlockContainer() override;
|
|
|
|
virtual void paint(PaintContext&, PaintPhase) override;
|
|
|
|
virtual HitTestResult hit_test(const Gfx::IntPoint&, HitTestType) const override;
|
|
|
|
BlockContainer* previous_sibling() { return verify_cast<BlockContainer>(Node::previous_sibling()); }
|
|
const BlockContainer* previous_sibling() const { return verify_cast<BlockContainer>(Node::previous_sibling()); }
|
|
BlockContainer* next_sibling() { return verify_cast<BlockContainer>(Node::next_sibling()); }
|
|
const BlockContainer* next_sibling() const { return verify_cast<BlockContainer>(Node::next_sibling()); }
|
|
|
|
bool is_scrollable() const;
|
|
const Gfx::FloatPoint& scroll_offset() const { return m_scroll_offset; }
|
|
void set_scroll_offset(const Gfx::FloatPoint&);
|
|
|
|
private:
|
|
virtual bool is_block_container() const final { return true; }
|
|
virtual bool wants_mouse_events() const override { return false; }
|
|
virtual bool handle_mousewheel(Badge<EventHandler>, const Gfx::IntPoint&, unsigned buttons, unsigned modifiers, int wheel_delta_x, int wheel_delta_y) override;
|
|
|
|
bool should_clip_overflow() const;
|
|
|
|
Gfx::FloatPoint m_scroll_offset;
|
|
};
|
|
|
|
template<>
|
|
inline bool Node::fast_is<BlockContainer>() const { return is_block_container(); }
|
|
|
|
}
|