Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ffe1b22

Browse filesBrowse files
NiuGuohuitordex
authored andcommitted
feat: Implements image click event.
feat: Optimized click event logic.
1 parent 171e03d commit ffe1b22
Copy full SHA for ffe1b22

File tree

Expand file treeCollapse file tree

9 files changed

+42
-9
lines changed
Filter options
Expand file treeCollapse file tree

9 files changed

+42
-9
lines changed

‎include/litehtml/document.h

Copy file name to clipboardExpand all lines: include/litehtml/document.h
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ namespace litehtml
6262
litehtml::size m_content_size;
6363
position::vector m_fixed_boxes;
6464
element::ptr m_over_element;
65+
element::ptr m_active_element;
6566
std::list<shared_ptr<render_item>> m_tabular_elements;
6667
media_query_list_list::vector m_media_lists;
6768
media_features m_media;
@@ -89,6 +90,7 @@ namespace litehtml
8990
bool on_mouse_over(int x, int y, int client_x, int client_y, position::vector& redraw_boxes);
9091
bool on_lbutton_down(int x, int y, int client_x, int client_y, position::vector& redraw_boxes);
9192
bool on_lbutton_up(int x, int y, int client_x, int client_y, position::vector& redraw_boxes);
93+
bool on_button_cancel(position::vector& redraw_boxes);
9294
bool on_mouse_leave(position::vector& redraw_boxes);
9395
element::ptr create_element(const char* tag_name, const string_map& attributes);
9496
element::ptr root();

‎include/litehtml/document_container.h

Copy file name to clipboardExpand all lines: include/litehtml/document_container.h
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +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) = 0;
5859
virtual void on_mouse_event(const litehtml::element::ptr& el, litehtml::mouse_event event) = 0;
5960
virtual void set_cursor(const char* cursor) = 0;
6061
virtual void transform_text(litehtml::string& text, litehtml::text_transform tt) = 0;

‎include/litehtml/el_image.h

Copy file name to clipboardExpand all lines: include/litehtml/el_image.h
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ namespace litehtml
1212
public:
1313
el_image(const document::ptr& doc);
1414

15+
void on_click() override;
1516
bool is_replaced() const override;
1617
void parse_attributes() override;
1718
void compute_styles(bool recursive = true) override;

‎include/litehtml/element.h

Copy file name to clipboardExpand all lines: include/litehtml/element.h
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ namespace litehtml
9494
virtual bool on_mouse_over();
9595
virtual bool on_mouse_leave();
9696
virtual bool on_lbutton_down();
97-
virtual bool on_lbutton_up();
97+
virtual bool on_lbutton_up(bool is_click = true);
9898
virtual void on_click();
9999
virtual bool set_pseudo_class(string_id cls, bool add);
100100
virtual bool set_class(const char* pclass, bool add);

‎include/litehtml/html_tag.h

Copy file name to clipboardExpand all lines: include/litehtml/html_tag.h
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ namespace litehtml
6161
bool on_mouse_over() override;
6262
bool on_mouse_leave() override;
6363
bool on_lbutton_down() override;
64-
bool on_lbutton_up() override;
64+
bool on_lbutton_up(bool is_click) override;
6565
void on_click() override;
6666
bool set_pseudo_class(string_id cls, bool add) override;
6767
bool set_class(const char* pclass, bool add) override;

‎src/document.cpp

Copy file name to clipboardExpand all lines: src/document.cpp
+22-2Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ document::document(document_container* container)
3636

3737
document::~document()
3838
{
39-
m_over_element = nullptr;
39+
m_over_element = m_active_element = nullptr;
4040
if(m_container)
4141
{
4242
for(auto& font : m_fonts)
@@ -700,6 +700,7 @@ bool document::on_lbutton_down( int x, int y, int client_x, int client_y, positi
700700
}
701701

702702
element::ptr over_el = m_root_render->get_element_by_point(x, y, client_x, client_y);
703+
m_active_element = over_el;
703704

704705
bool state_was_changed = false;
705706

@@ -753,14 +754,33 @@ bool document::on_lbutton_up( int /*x*/, int /*y*/, int /*client_x*/, int /*clie
753754
}
754755
if(m_over_element)
755756
{
756-
if(m_over_element->on_lbutton_up())
757+
if(m_over_element->on_lbutton_up(m_active_element == m_over_element))
757758
{
758759
return m_root->find_styles_changes(redraw_boxes);
759760
}
760761
}
761762
return false;
762763
}
763764

765+
bool document::on_button_cancel(position::vector& redraw_boxes) {
766+
if(!m_root || !m_root_render)
767+
{
768+
return false;
769+
}
770+
if(m_over_element)
771+
{
772+
if(m_over_element->on_mouse_leave())
773+
{
774+
m_container->on_mouse_event(m_over_element, mouse_event_leave);
775+
}
776+
if(m_over_element->on_lbutton_up(false))
777+
{
778+
return m_root->find_styles_changes(redraw_boxes);
779+
}
780+
}
781+
return false;
782+
}
783+
764784
void document::get_fixed_boxes( position::vector& fixed_boxes )
765785
{
766786
fixed_boxes = m_fixed_boxes;

‎src/el_image.cpp

Copy file name to clipboardExpand all lines: src/el_image.cpp
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,12 @@ std::shared_ptr<litehtml::render_item> litehtml::el_image::create_render_item(co
8383
ret->parent(parent_ri);
8484
return ret;
8585
}
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+
}

‎src/element.cpp

Copy file name to clipboardExpand all lines: src/element.cpp
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ string litehtml::element::get_counters_value(const string_vector& parameters)
317317
litehtml::trim(delims, "\"'");
318318

319319
string_vector values;
320-
320+
321321
element::ptr current = shared_from_this();
322322
while (current != nullptr)
323323
{
@@ -362,7 +362,7 @@ bool litehtml::element::find_counter(const string_id& counter_name_id, std::map<
362362
}
363363
current = current->parent();
364364
}
365-
365+
366366
return false;
367367
}
368368

@@ -451,7 +451,7 @@ bool element::is_text() const LITEHTML_RETURN_FUNC(false)
451451
bool element::on_mouse_over() LITEHTML_RETURN_FUNC(false)
452452
bool element::on_mouse_leave() LITEHTML_RETURN_FUNC(false)
453453
bool element::on_lbutton_down() LITEHTML_RETURN_FUNC(false)
454-
bool element::on_lbutton_up() LITEHTML_RETURN_FUNC(false)
454+
bool element::on_lbutton_up(const bool is_click) LITEHTML_RETURN_FUNC(false)
455455
bool element::set_pseudo_class( string_id /*cls*/, bool /*add*/ ) LITEHTML_RETURN_FUNC(false)
456456
bool element::set_class( const char* /*pclass*/, bool /*add*/ ) LITEHTML_RETURN_FUNC(false)
457457
bool element::is_replaced() const LITEHTML_RETURN_FUNC(false)

‎src/html_tag.cpp

Copy file name to clipboardExpand all lines: src/html_tag.cpp
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ bool litehtml::html_tag::on_lbutton_down()
816816
return ret;
817817
}
818818

819-
bool litehtml::html_tag::on_lbutton_up()
819+
bool litehtml::html_tag::on_lbutton_up(bool is_click)
820820
{
821821
bool ret = false;
822822

@@ -830,7 +830,7 @@ bool litehtml::html_tag::on_lbutton_up()
830830
el = el->parent();
831831
}
832832

833-
on_click();
833+
if (is_click) on_click();
834834

835835
return ret;
836836
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.