Skip to content

Commit 165bed4

Browse files
NiuGuohuitordex
authored andcommitted
feat: Implements element click event API in document_container.
1 parent 5300da5 commit 165bed4

File tree

5 files changed

+9
-15
lines changed

5 files changed

+9
-15
lines changed

include/litehtml/document_container.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ namespace litehtml
5555
virtual void set_base_url(const char* base_url) = 0;
5656
virtual void link(const std::shared_ptr<litehtml::document>& doc, const litehtml::element::ptr& el) = 0;
5757
virtual void on_anchor_click(const char* url, const litehtml::element::ptr& el) = 0;
58-
virtual void on_image_click(const char* /*src*/, const litehtml::element::ptr& /*el*/) {};
58+
virtual bool on_element_click(const litehtml::element::ptr& /*el*/) { return false; };
5959
virtual void on_mouse_event(const litehtml::element::ptr& el, litehtml::mouse_event event) = 0;
6060
virtual void set_cursor(const char* cursor) = 0;
6161
virtual void transform_text(litehtml::string& text, litehtml::text_transform tt) = 0;

include/litehtml/el_image.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ namespace litehtml
1212
public:
1313
el_image(const document::ptr& doc);
1414

15-
void on_click() override;
1615
bool is_replaced() const override;
1716
void parse_attributes() override;
1817
void compute_styles(bool recursive = true) override;

src/document.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,7 @@ bool document::on_button_cancel(position::vector& redraw_boxes) {
767767
{
768768
return false;
769769
}
770+
m_active_element = nullptr;
770771
if(m_over_element)
771772
{
772773
if(m_over_element->on_mouse_leave())

src/el_image.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,4 @@ std::shared_ptr<litehtml::render_item> litehtml::el_image::create_render_item(co
8282
auto ret = std::make_shared<render_item_image>(shared_from_this());
8383
ret->parent(parent_ri);
8484
return ret;
85-
}
86-
87-
void litehtml::el_image::on_click() {
88-
const char* src = get_attr("src");
89-
90-
if(src)
91-
{
92-
get_document()->container()->on_image_click(src, shared_from_this());
93-
}
94-
}
85+
}

src/html_tag.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -839,10 +839,13 @@ void litehtml::html_tag::on_click()
839839
{
840840
if (!is_root())
841841
{
842-
element::ptr el_parent = parent();
843-
if (el_parent)
842+
if(!get_document()->container()->on_element_click(shared_from_this()))
844843
{
845-
el_parent->on_click();
844+
element::ptr el_parent = parent();
845+
if (el_parent)
846+
{
847+
el_parent->on_click();
848+
}
846849
}
847850
}
848851
}

0 commit comments

Comments
 (0)