2020-05-24 19:24:36 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/NonnullRefPtrVector.h>
|
|
|
|
#include <LibWeb/DOM/Element.h>
|
|
|
|
#include <LibWeb/Forward.h>
|
|
|
|
|
2020-07-28 18:20:36 +02:00
|
|
|
namespace Web::HTML {
|
2020-05-24 19:24:36 +02:00
|
|
|
|
|
|
|
class StackOfOpenElements {
|
|
|
|
public:
|
|
|
|
StackOfOpenElements() { }
|
|
|
|
~StackOfOpenElements();
|
|
|
|
|
2020-07-26 19:37:56 +02:00
|
|
|
DOM::Element& first() { return m_elements.first(); }
|
|
|
|
DOM::Element& last() { return m_elements.last(); }
|
2020-05-28 00:27:46 +02:00
|
|
|
|
2020-05-24 19:24:36 +02:00
|
|
|
bool is_empty() const { return m_elements.is_empty(); }
|
2020-07-26 19:37:56 +02:00
|
|
|
void push(NonnullRefPtr<DOM::Element> element) { m_elements.append(move(element)); }
|
|
|
|
NonnullRefPtr<DOM::Element> pop() { return m_elements.take_last(); }
|
2020-05-24 19:24:36 +02:00
|
|
|
|
2020-07-26 19:37:56 +02:00
|
|
|
const DOM::Element& current_node() const { return m_elements.last(); }
|
|
|
|
DOM::Element& current_node() { return m_elements.last(); }
|
2020-05-24 19:24:36 +02:00
|
|
|
|
|
|
|
bool has_in_scope(const FlyString& tag_name) const;
|
2020-05-24 22:21:25 +02:00
|
|
|
bool has_in_button_scope(const FlyString& tag_name) const;
|
2020-05-25 20:30:34 +02:00
|
|
|
bool has_in_table_scope(const FlyString& tag_name) const;
|
2020-05-29 22:06:05 +02:00
|
|
|
bool has_in_list_item_scope(const FlyString& tag_name) const;
|
2020-05-30 19:58:52 +02:00
|
|
|
bool has_in_select_scope(const FlyString& tag_name) const;
|
2020-05-24 19:24:36 +02:00
|
|
|
|
2020-07-26 19:37:56 +02:00
|
|
|
bool has_in_scope(const DOM::Element&) const;
|
2020-05-27 23:22:42 +02:00
|
|
|
|
2020-07-26 19:37:56 +02:00
|
|
|
bool contains(const DOM::Element&) const;
|
2020-05-30 11:13:57 +02:00
|
|
|
bool contains(const FlyString& tag_name) const;
|
2020-05-24 22:39:59 +02:00
|
|
|
|
2020-07-26 19:37:56 +02:00
|
|
|
const NonnullRefPtrVector<DOM::Element>& elements() const { return m_elements; }
|
|
|
|
NonnullRefPtrVector<DOM::Element>& elements() { return m_elements; }
|
2020-05-24 22:39:59 +02:00
|
|
|
|
2020-05-28 18:09:31 +02:00
|
|
|
void pop_until_an_element_with_tag_name_has_been_popped(const FlyString&);
|
|
|
|
|
2020-07-26 19:37:56 +02:00
|
|
|
DOM::Element* topmost_special_node_below(const DOM::Element&);
|
2020-05-29 22:06:05 +02:00
|
|
|
|
2020-08-19 22:30:33 +01:00
|
|
|
struct LastElementResult {
|
|
|
|
DOM::Element* element;
|
|
|
|
ssize_t index;
|
|
|
|
};
|
|
|
|
LastElementResult last_element_with_tag_name(const FlyString&);
|
2020-07-26 19:37:56 +02:00
|
|
|
DOM::Element* element_before(const DOM::Element&);
|
2020-06-21 17:00:55 +02:00
|
|
|
|
2020-05-24 19:24:36 +02:00
|
|
|
private:
|
2020-05-24 22:21:25 +02:00
|
|
|
bool has_in_scope_impl(const FlyString& tag_name, const Vector<FlyString>&) const;
|
2020-07-26 19:37:56 +02:00
|
|
|
bool has_in_scope_impl(const DOM::Element& target_node, const Vector<FlyString>&) const;
|
2020-05-24 22:21:25 +02:00
|
|
|
|
2020-07-26 19:37:56 +02:00
|
|
|
NonnullRefPtrVector<DOM::Element> m_elements;
|
2020-05-24 19:24:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|