-
Notifications
You must be signed in to change notification settings - Fork 535
Expand file tree
/
Copy pathelement.h
More file actions
1793 lines (1399 loc) · 61.5 KB
/
Copy pathelement.h
File metadata and controls
1793 lines (1399 loc) · 61.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2019 The Lynx Authors. All rights reserved.
// Licensed under the Apache License Version 2.0 that can be found in the
// LICENSE file in the root directory of this source tree.
#ifndef CORE_RENDERER_DOM_ELEMENT_H_
#define CORE_RENDERER_DOM_ELEMENT_H_
#include <array>
#include <cstdint>
#include <list>
#include <map>
#include <memory>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
#include "base/include/auto_create_optional.h"
#include "base/include/closure.h"
#include "base/include/flex_optional.h"
#include "base/include/fml/memory/ref_ptr.h"
#include "base/include/no_destructor.h"
#include "base/include/value/ref_type.h"
#include "base/include/value/table.h"
#include "base/include/vector.h"
#include "core/animation/css_keyframe_manager.h"
#include "core/animation/css_transition_manager.h"
#include "core/base/lynx_export.h"
#include "core/event/event_target.h"
#include "core/inspector/style_sheet.h"
#include "core/public/common_constants.h"
#include "core/renderer/css/computed_css_style.h"
#include "core/renderer/css/css_content_data.h"
#include "core/renderer/css/css_style_sheet_manager.h"
#include "core/renderer/css/css_variable_handler.h"
#include "core/renderer/css/dynamic_css_styles_manager.h"
#include "core/renderer/css/layout_property.h"
#include "core/renderer/css/ng/invalidation/invalidation_set.h"
#include "core/renderer/dom/attribute_holder.h"
#include "core/renderer/dom/base_element_container.h"
#include "core/renderer/dom/element_property.h"
#include "core/renderer/dom/imperative_animation_state.h"
#include "core/renderer/dom/selector/selector_item.h"
#include "core/renderer/dom/style_resolver.h"
#include "core/renderer/events/events.h"
#include "core/renderer/events/gesture.h"
#include "core/renderer/simple_styling/simple_style_node.h"
#include "core/renderer/simple_styling/style_object.h"
#include "core/renderer/starlight/types/layout_result.h"
#include "core/renderer/ui_wrapper/layout/layout_node.h"
#include "core/renderer/ui_wrapper/painting/catalyzer.h"
#include "core/renderer/ui_wrapper/painting/painting_context.h"
#include "core/renderer/utils/base/element_template_info.h"
#include "core/renderer/utils/base/tasm_constants.h"
namespace lynx {
namespace runtime {
class MessageEvent;
} // namespace runtime
namespace tasm {
class AttributeHolder;
class ElementManager;
class ElementContainer;
class HierarchyObserver;
class ListNode;
class Fragment;
class CSSFragmentDecorator;
class CSSParseToken;
struct LayoutBundle;
class PseudoElement;
class ListItemSchedulerAdapter;
class PlatformLayoutFunctionWrapper;
using ElementChildrenArray =
base::InlineVector<Element*, kChildrenInlineVectorSize>;
enum ElementArchTypeEnum : uint8_t {
FiberArch = 0,
RadonArch,
};
class InspectorAttribute {
public:
LYNX_EXPORT_FOR_DEVTOOL InspectorAttribute();
LYNX_EXPORT_FOR_DEVTOOL ~InspectorAttribute();
public:
int node_type_;
std::string local_name_;
std::string node_name_;
std::string node_value_;
std::string selector_id_;
std::vector<std::string> class_order_;
lynx::devtool::InspectorElementType type_;
// plug element's corresponding slot name
std::string slot_name_;
// element's parent component name, only plug element need set this attribute
std::string parent_component_name_;
std::vector<std::string> attr_order_;
std::unordered_map<std::string, std::string> attr_map_;
std::vector<std::string> data_order_;
std::unordered_map<std::string, std::string> data_map_;
std::vector<std::string> event_order_;
std::unordered_map<std::string, std::string> event_map_;
Element* style_root_; // not owned
lynx::devtool::InspectorStyleSheet inline_style_sheet_;
std::vector<lynx::devtool::InspectorCSSRule> css_rules_;
int start_line_;
std::unordered_multimap<std::string, lynx::devtool::InspectorStyleSheet>
style_sheet_map_;
// DevTool selector edits need the exact source token. Keep the cache on the
// style root so cached tokens cannot outlive the inspected DOM lifetime.
std::unordered_map<std::string, fml::RefPtr<CSSParseToken>>
style_sheet_source_token_map_;
std::unordered_map<std::string, std::vector<lynx::devtool::InspectorKeyframe>>
animation_map_;
// for component remove view, erase component
// id from node_manager in element destructor
bool needs_erase_id_ = false;
bool enable_css_selector_ = false;
bool wrapper_component_ = false;
std::unique_ptr<Element> doc_;
std::unique_ptr<Element> style_value_;
};
class Element : public lepus::RefCounted,
public fml::EnableWeakFromThis<Element>,
public event::EventTarget,
public SelectorItem,
public style::SimpleStyleNode {
public:
Element(const base::String& tag, ElementManager* element_manager,
uint32_t node_index);
Element& operator=(const Element&) = delete;
// Element state, used to indicate whether the current Element is on the root
// Dom tree.
enum class State : uint8_t {
// attached to root DOM tree
kAttached,
// removed from root DOM tree
kDetached,
};
enum class Action : uint8_t {
kCreateAct = 0,
kDestroyAct,
kInsertChildAct,
kRemoveChildAct,
kMoveAct,
kUpdatePropsAct,
kRemoveIntergenerationAct,
};
struct ActionParam {
ActionParam(Action type, Element* parent, const fml::RefPtr<Element>& child,
int from, Element* ref_node, bool is_fixed = false,
bool has_z_index = false)
: type_(type),
parent_(parent),
child_(child),
index_(from),
ref_node_(ref_node),
is_fixed_(is_fixed),
has_z_index_(has_z_index) {}
Action type_;
Element* parent_;
fml::RefPtr<Element> child_;
int index_;
Element* ref_node_;
bool is_fixed_;
bool has_z_index_;
};
// Direction mapping support for RTL/LTR layout
struct DirectionMapping {
DirectionMapping()
: is_logic_(false),
ltr_property_(kPropertyStart),
rtl_property_(kPropertyStart) {}
DirectionMapping(bool is_logic, CSSPropertyID ltr_property,
CSSPropertyID rtl_property)
: is_logic_(is_logic),
ltr_property_(ltr_property),
rtl_property_(rtl_property) {}
bool is_logic_{false};
CSSPropertyID ltr_property_{CSSPropertyID::kPropertyStart};
CSSPropertyID rtl_property_{CSSPropertyID::kPropertyStart};
};
static const uint32_t kDirtyCreated;
static const uint32_t kDirtyTree;
static const uint32_t kDirtyStyle;
static const uint32_t kDirtyAttr;
static const uint32_t kDirtyForceUpdate;
static const uint32_t kDirtyEvent;
static const uint32_t kDirtyReAttachContainer;
static const uint32_t kDirtyPropagateInherited;
static const uint32_t kDirtyDataset;
static const uint32_t kDirtyGesture;
static const uint32_t kDirtyFontSize;
static const uint32_t kDirtyRefreshCSSVariables;
static const uint32_t kDirtyStyleObjects;
static constexpr uint32_t kDirtyCloned = 0x01 << 14;
static constexpr uint32_t kDirtyDynamicStyleObjects = 0x01 << 15;
static constexpr uint32_t kDirtyInvoke = 0x01 << 16;
enum class AsyncResolveStatus : uint8_t {
kCreated = 0,
kPrepareRequested,
kPrepareTriggered,
kPreparing,
kSyncResolving,
kResolving,
kResolved,
kUpdated,
};
constexpr static const char* kFiberParallelPrepareMode = "ParallelPrepare";
static const uint32_t kFlagGreedyParallel = 0x01 << 0;
static const uint32_t kFlagLevelOrderParallel = 0x01 << 1;
lepus::RefType GetRefType() const override {
return lepus::RefType::kElement;
};
void SetAttributeHolder(const fml::RefPtr<AttributeHolder>& data_model) {
data_model_ = data_model;
data_model_->SetElement(this);
data_model_->set_tag(tag_);
}
AttributeHolder* data_model() const { return data_model_.get(); };
bool is_fixed() { return is_fixed_; }
// TODO(ZHOUZHITAO): Move parallel_flush_ flag from element to
// ParallelResolver
bool is_parallel_flush() { return parallel_flush_ > 0; }
bool is_greedy_parallel_flush() {
return (parallel_flush_ & kFlagGreedyParallel) > 0;
}
void MarkParallelFlushFlag(uint32_t flag) { parallel_flush_ |= flag; }
void ResetParallelFlushFlag() { parallel_flush_ = 0; }
int32_t impl_id() const { return id_; }
uint32_t GlobalInsertionOrder() const { return global_insertion_order_; }
void UpdateGlobalInsertionOrder();
void ResetGlobalInsertionOrder() {
global_insertion_order_ = kInitialGlobalInsertionOrder;
}
void SetNodeIndex(uint32_t node_index) { node_index_ = node_index; }
uint32_t NodeIndex() const { return node_index_; }
std::vector<float> ScrollBy(float width, float height);
std::vector<float> GetRectToLynxView();
std::vector<float> GetRectToScreen();
void Invoke(const std::string& method, const pub::Value& params,
const std::function<void(int32_t code, const pub::Value& data)>&
callback);
void AppendPendingInvokeTask(base::closure task);
void EnqueueInvoke(
const std::string& method, const pub::Value& params,
const std::function<void(int32_t code, const pub::Value& data)>&
callback);
void FlushPendingInvokeTasks();
SLNode* GetLayoutObject() const { return sl_node_.get(); }
SLNode* slnode() const { return sl_node_.get(); }
ElementManager* element_manager() const { return element_manager_; }
Element* parent() const { return parent_; }
Element* next_sibling() const { return Sibling(1); }
Element* previous_sibling() const { return Sibling(-1); }
virtual Element* Sibling(int offset) const;
// only for fiber arch, indicate current real render tree hierarchy
Element* render_parent() { return render_parent_; }
Element* first_render_child() { return first_render_child_; }
virtual Element* first_child() const;
virtual Element* last_child() const;
Element* next_render_sibling() { return next_render_sibling_; }
const auto& children() const { return scoped_children_; }
const auto& logical_children() const { return logical_children_; }
// Helpers for finding non-virtual / non-wrapper nodes in the render tree
// starting from the current element.
Element* FindFirstNonVirtualRenderAncestor();
Element* FindFirstNonVirtualRenderSibling();
Element* FindFirstNonWrapperRenderAncestor();
Element* FindFirstNonWrapperChildOrSibling();
DirectionMapping CheckDirectionMapping(CSSPropertyID css_id);
// CSS inheritance and direction-related helpers
bool IsInheritable(CSSPropertyID id) const;
bool IsDirectionChangedEnabled() const;
std::pair<bool, CSSPropertyID> ConvertRtlCSSPropertyID(CSSPropertyID id);
virtual ~Element();
// For style op
LYNX_EXPORT_FOR_DEVTOOL virtual void ConsumeStyle(
const StyleMap& styles, const StyleMap* inherit_styles = nullptr) = 0;
void CacheStyleFromAttributes(CSSPropertyID id, CSSValue&& value);
void CacheStyleFromAttributes(CSSPropertyID id, const lepus::Value& value);
void RemoveStyleFromAttributes(CSSPropertyID id) {
if (styles_from_attributes_.has_value()) {
styles_from_attributes_->erase(id);
if (styles_from_attributes_->empty()) {
styles_from_attributes_.reset();
}
}
RemoveCommittedStyleFromAttributes(id);
}
const StyleMap* PeekCachedStylesFromAttributes() const {
if (!styles_from_attributes_.has_value() ||
styles_from_attributes_->empty()) {
return nullptr;
}
return &*styles_from_attributes_;
}
virtual const StyleMap* PeekCommittedStylesFromAttributes() const {
return nullptr;
}
void ClearCachedStylesFromAttributes() { styles_from_attributes_.reset(); }
void DidConsumeStyle();
virtual void ProcessFullRawInlineStyle(CSSVariableMap* changed_css_vars) {}
virtual void ConsumeStyleInternal(
const StyleMap& styles, const StyleMap* inherit_styles,
std::function<bool(CSSPropertyID, const tasm::CSSValue&)> should_skip) {
ConsumeStyle(styles, inherit_styles);
}
virtual void SetStyleInternal(CSSPropertyID id, const tasm::CSSValue& value);
LYNX_EXPORT_FOR_DEVTOOL virtual void ResetStyle(
const base::Vector<CSSPropertyID>& style_names);
/**
* Before SetAttribute(), reserve array size.
*/
virtual void ReserveForAttribute(size_t count) {
updated_attr_map_.reserve(count);
}
/**
* Element API for appending single attribute to element
* @param key the attribute String type name
* @param value the attribute value
*/
LYNX_EXPORT_FOR_DEVTOOL virtual void SetAttribute(
const base::String& key, const lepus::Value& value,
bool need_update_data_model = true);
virtual void ResetAttribute(const base::String& key);
void WillConsumeAttribute(const base::String& key, const lepus::Value& value);
/**
* Element API for setting class name to Element
* @param clazz the name of class selector
*/
void SetClass(const base::String& clazz);
/**
* Element API for setting class names to Element
* @param classes the vector contains the name of class selector
*/
LYNX_EXPORT_FOR_DEVTOOL void SetClasses(ClassList&& classes);
/**
* Element API for removing all classes of
*/
LYNX_EXPORT_FOR_DEVTOOL void RemoveAllClass();
virtual void SetBuiltinAttribute(ElementBuiltInAttributeEnum key,
const lepus::Value& value);
/**
* Element API for setting id for element
* @param idSelector the id of the element
*/
LYNX_EXPORT_FOR_DEVTOOL void SetIdSelector(const base::String& idSelector);
// For dataset op
void SetDataSet(const tasm::DataMap& data);
void AddDataset(const base::String& key, const lepus::Value& value);
void RemoveDataset(const base::String& key);
void SetDataset(const lepus::Value& data_set);
// For event handler
virtual void SetEventHandler(const base::String& name, EventHandler* handler);
virtual void ResetEventHandlers();
/**
* Element API for adding js event
* @param name the binding event's name
* @param type the binding event's type
* @param callback the binding event's corresponding js function name
*/
void SetJSEventHandler(const base::String& name, const base::String& type,
const base::String& callback);
/**
* Element API for adding lepus event
* @param name the binding event's name
* @param type the binding event's type
* @param script the binding event's corresponding lepus script
* @param callback the binding event's corresponding lepus function
*/
void SetLepusEventHandler(const base::String& name, const base::String& type,
const lepus::Value& script,
const lepus::Value& callback);
/**
* Element API for adding worklet event
* @param name the binding worklet event's name
* @param type the binding worklet event's type
* @param worklet_info the binding worklet info, passed to the front-end
* @param ctx the context of Lepus / LepusNg
* framework
*/
void SetWorkletEventHandler(const base::String& name,
const base::String& type,
const lepus::Value& worklet_info,
runtime::MTSRuntime* ctx);
void SetWorkletEventHandler(const base::String& name,
const base::String& type,
const lepus::Value& worklet_info,
const std::string& context_name);
event::DispatchEventResult DispatchMessageEvent(
fml::RefPtr<runtime::MessageEvent> event);
/**
* Element API for removing specific event
* @param name the removed event's name
* @param type the removed event's type
*/
void RemoveEvent(const base::String& name, const base::String& type);
/**
* Element API for removing all events
*/
void RemoveAllEvents();
/**
* Element API for adding config.
* @param key the config key,
* @param value the config value.
*/
void AddConfig(const base::String& key, const lepus::Value& value);
/**
* Element API for setting config.
* @param config the config will be setted,
*/
void SetConfig(const lepus::Value& config);
/**
* A key function to get element's config.
* The returned value is constant. You should not get Table() from
* the value and change configs. Use AddConfig() instead which will
* guarantee this element creates a writable config table.
*/
const lepus::Value config() const;
// For gesture handler
void SetGestureDetectorState(int32_t gesture_id, int32_t state);
void SetGestureDetector(const uint32_t key, GestureDetectorImpl* detector);
void ConsumeGesture(int32_t gesture_id, const lepus::Value& params);
// For prop op
void SetProp(const char* key, const lepus::Value& value);
// For keyframe op
// The first parameter names can be string type or array type of lepus value
void SetKeyframesByNames(const lepus::Value& names,
const CSSKeyframesTokenMap&, bool force_flush);
// The first parameter names can be string type or array type of lepus value
lepus::Value ResolveCSSKeyframesByNames(
const lepus::Value& names, const tasm::CSSKeyframesTokenMap& frames,
const tasm::CssMeasureContext& context,
const tasm::CSSParserConfigs& configs, bool force_flush);
// For font face
void SetFontFaces(const CSSFontFaceRuleMap&);
// For pseudo
void ResetPseudoType(int pseudo_type) { pseudo_type_ = pseudo_type; }
// For Animation API
void Animate(const lepus::Value& args,
std::shared_ptr<PipelineOptions>& pipeline_option);
// For Animation API
void AnimateV2(const lepus::Value& args,
std::shared_ptr<PipelineOptions>& pipeline_option);
// For JS API setNativeProps
virtual void SetNativeProps(
const lepus::Value& args,
std::shared_ptr<PipelineOptions>& pipeline_options) = 0;
// Get List Node
virtual ListNode* GetListNode() = 0;
/**
* A key function to get parent component's element
*/
LYNX_EXPORT_FOR_DEVTOOL virtual Element* GetParentComponentElement() const;
Catalyzer* GetCaCatalyzer() { return catalyzer_; }
virtual const EventMap& event_map() const;
virtual const EventMap& lepus_event_map();
virtual const EventMap& global_bind_event_map();
// GestureMap key - gesture id / value - GestureDetector
virtual const GestureMap& gesture_map();
virtual bool InComponent() const;
virtual int ParentComponentId() const { return 0; }
virtual std::string ParentComponentIdString() const;
virtual const std::string& ParentComponentEntryName() const;
const base::String& entry_name() const { return element_entry_name_; }
void set_entry_name(const base::String& entry_name) {
element_entry_name_ = entry_name;
}
inline bool IsLayoutOnly() { return is_layout_only_; }
// Check if this element is a fixed element using the new fixed positioning
// system
bool IsNewFixed() const;
// Get whether the new fixed positioning system is enabled
bool GetEnableFixedNew() const;
// Check if this element is a fixed element using the unified fixed behavior
bool IsFixedUnified() const;
// Get whether the unified fixed behavior is enabled, to be removed when
// enable_unify_fixed_behavior is default enabled
bool IsFixedUnifiedEnabled() const;
// Check if either new fixed or unified fixed behavior is enabled, to be
// removed when enable_unify_fixed_behavior is default enabled
bool IsFixedNewOrUnifiedEnabled() const;
// Check if this element uses either new fixed positioning or
// unified fixed
bool IsFixedNewOrUnified() const;
// Check if this element uses unified fixed behavior but not new fixed
// positioning
bool IsFixedUnifiedOnly() const;
inline bool is_virtual() { return is_virtual_; }
LYNX_EXPORT_FOR_DEVTOOL virtual bool GetPageElementEnabled() { return false; }
LYNX_EXPORT_FOR_DEVTOOL virtual bool GetRemoveCSSScopeEnabled() {
return false;
}
bool IsRadonArch() const { return arch_type_ == RadonArch; }
bool IsFiberArch() const { return arch_type_ == FiberArch; }
// Element type checking methods
virtual bool is_none() const { return false; }
virtual bool is_block() const { return false; }
virtual bool is_if() const { return false; }
virtual bool is_for() const { return false; }
bool is_inline_element() const { return is_inline_element_; }
// Virtual parent node access methods (for AirModeFiber)
void set_virtual_parent(Element* virtual_parent) {
virtual_parent_ = virtual_parent;
}
Element* virtual_parent() { return virtual_parent_; }
Element* root_virtual_parent();
// Parent component unique ID access methods
int64_t GetParentComponentUniqueIdForFiber() {
return parent_component_unique_id_;
}
void SetParentComponentUniqueIdForFiber(int64_t id) {
if (id != parent_component_unique_id_) {
parent_component_element_ = nullptr;
}
parent_component_unique_id_ = id;
}
void SetParentComponentUniqueIdRecursively(int64_t id) {
if (is_page()) {
SetParentComponentUniqueIdForFiber(impl_id());
} else {
SetParentComponentUniqueIdForFiber(id);
}
for (const auto& child : scoped_children_) {
child->SetParentComponentUniqueIdRecursively(
is_page() || is_component() ? impl_id() : id);
}
}
/**
* A function to resolve parent component element CSSFragment
*/
void ResolveParentComponentElement() const;
void ResolveParentComponentElementImpl() const;
void ClearExtremeParsedStyles() {
if (has_extreme_parsed_styles_) {
extreme_parsed_styles_.reset();
has_extreme_parsed_styles_ = false;
}
}
// Exported for accessing private field from Element Manager to handle legacy
// logic
inline Element* GetRenderRootElement() { return render_root_element_; }
bool IsInSameCSSScope(Element* element) {
return css_id_ == element->css_id_;
}
// This interface is currently only used by the inspector. The inspector
// determines whether an element is created by the itself by checking whether
// element has a data model. Since the data model of a fiber element is not
// empty by default, this interface is provided to the inspector to reset the
// data model and mark the element as created by the inspector.
void ResetDataModel() { data_model_ = nullptr; }
void MarkCanBeLayoutOnly(bool flag) { can_be_layout_only_ = flag; }
// Async resolve status query methods
void UpdateResolveStatus(AsyncResolveStatus value) {
resolve_status_ = value;
}
bool IsAsyncResolveInvoked() {
return resolve_status_ != AsyncResolveStatus::kCreated &&
resolve_status_ != AsyncResolveStatus::kUpdated;
}
bool IsAsyncResolveResolving() {
return resolve_status_ == AsyncResolveStatus::kResolving ||
resolve_status_ == AsyncResolveStatus::kResolved ||
resolve_status_ == AsyncResolveStatus::kPreparing ||
resolve_status_ == AsyncResolveStatus::kSyncResolving;
}
bool flush_required() { return flush_required_; }
inline bool ShouldProcessParallelTasks() {
return is_parallel_flush() ||
resolve_status_ == AsyncResolveStatus::kSyncResolving;
}
inline bool ShouldResolveStyle() {
return !IsAsyncResolveResolving() &&
((dirty_ & ~(kDirtyTree | kDirtyReAttachContainer)) != 0);
}
inline void EnqueueReduceTask(base::MoveOnlyClosure<void> operation) {
parallel_reduce_tasks_->emplace_back(std::move(operation));
}
inline bool IsAsyncFlushRoot() const { return is_async_flush_root_; }
inline void MarkAsyncFlushRoot(bool value) { is_async_flush_root_ = value; }
// Data model accessor methods
const ClassList& classes() { return data_model_->classes(); }
ClassList ReleaseClasses() { return data_model_->ReleaseClasses(); }
const base::String& GetIdSelector() { return data_model_->idSelector(); }
const DataMap& dataset() { return data_model_->dataset(); }
// Check has_value() before usage to avoid unintentional construction.
const auto& builtin_attr_map() const { return builtin_attr_map_; }
// Check has_value() before usage to avoid unintentional construction.
const auto& updated_attr_map() const { return updated_attr_map_; }
void set_style_sheet_manager(
const std::shared_ptr<CSSStyleSheetManager>& manager) {
css_style_sheet_manager_ = manager;
}
const std::shared_ptr<CSSStyleSheetManager>& style_sheet_manager() {
return css_style_sheet_manager_;
}
void ResetStyleSheet();
void set_attached_to_layout_parent(bool has) {
attached_to_layout_parent_ = has;
}
bool attached_to_layout_parent() const { return attached_to_layout_parent_; }
void UpdateAttrMap(const base::String& key, const lepus::Value& value) {
updated_attr_map_[key] = value;
}
void MarkAttrDirtyForPseudoElement() { dirty_ |= kDirtyAttr; }
void UpdateLayout(float left, float top, float width, float height,
const std::array<float, 4>& paddings,
const std::array<float, 4>& margins,
const std::array<float, 4>& borders,
const std::array<float, 4>* sticky_positions,
float max_height, bool display_none = false);
// Used to update child element's left and top value from list element. The
// another overloaded function is used to update layout info from starlight,
// but if the element is list's child, the left and top's value are always 0.
void UpdateLayout(float left, float top);
virtual Element* GetChildAt(size_t index);
virtual size_t GetChildCount();
virtual ElementChildrenArray GetChildren();
virtual size_t GetUIIndexForChild(Element* child) { return 0; }
virtual int32_t IndexOf(const Element* child) const;
virtual void InsertNode(const fml::RefPtr<Element>& child) = 0;
virtual void InsertNode(const fml::RefPtr<Element>& child, int32_t index) = 0;
virtual void RemoveNode(const fml::RefPtr<Element>& child,
bool destroy = true) = 0;
inline bool CanHasLayoutOnlyChildren() {
return can_has_layout_only_children_;
};
void OnNodeReady();
void onNodeReload();
/*
* return the font size from platform_css_style_.
*/
LYNX_EXPORT_FOR_DEVTOOL virtual double GetFontSize();
/*
* return the font size of parent.
*/
double GetParentFontSize();
/*
* return the root font size from platform_css_style_.
*/
double GetRecordedRootFontSize();
/*
* return the value of the root element's GetFontSize() function.
*/
double GetCurrentRootFontSize();
virtual void OnPseudoStatusChanged(PseudoState prev_status,
PseudoState current_status) {}
ContentData* content_data() const { return content_data_.get(); }
virtual void UpdateDynamicElementStyle(uint32_t style, bool force_update) = 0;
bool HasPlaceHolder() { return has_placeholder_; }
bool HasTextSelection() { return has_text_selection_; }
PaintingContext* painting_context();
// Declared platform node tag
const base::String& GetTag() const { return tag_; }
bool IsOverlay() const { return is_overlay_; }
// The actual platform node tag, which is typically the same as the declared
// platform node tag, except in one case:
// - In a list, the actual platform node tag can be specified using the
// custom-list-name attribute.
virtual const base::String& GetPlatformNodeTag() const { return tag_; }
void UpdateElement();
int ZIndex() {
return GetEnableZIndex() ? computed_css_style()->GetZIndex() : 0;
}
bool HasElementContainer() { return element_container_ != nullptr; }
bool IsStackingContextNode();
bool IsCSSInheritanceEnabled() const;
bool IsCSSInlineVariablesEnabled() const;
BaseElementContainer* element_container() const {
return element_container_.get();
}
ElementContainer* element_container_impl();
Fragment* fragment_impl();
void CreateElementContainer(bool platform_is_flatten);
virtual void EnqueueLayoutTask(base::MoveOnlyClosure<void> operation);
virtual void HandleDelayTask(base::MoveOnlyClosure<void> operation) {
operation();
}
void set_parent(Element* parent) { parent_ = parent; }
bool EnableTriggerGlobalEvent() const { return trigger_global_event_; }
void PreparePropBundleIfNeed();
fml::RefPtr<PropBundle> GetPropBundleForRecording();
bool GetEnableZIndex();
virtual void MarkLayoutDirty();
virtual void MarkLayoutDirtyLite(){};
// Dirty flag primitives
int32_t dirty() const { return dirty_; }
void MarkDirty(const uint32_t flag) {
dirty_ |= flag;
RequireFlush();
}
virtual void MarkDirtyLite(const uint32_t flag) {
dirty_ |= flag;
MarkRequireFlush();
}
void ResetAllDirtyBits() { dirty_ = 0; }
bool StyleDirty() const { return dirty_ & kDirtyStyle; }
bool AttrDirty() const { return dirty_ & kDirtyAttr; }
void MarkPropsDirty() { MarkDirty(kDirtyForceUpdate); }
void MarkRefreshCSSStyles() { MarkDirty(kDirtyRefreshCSSVariables); }
// In RadonDiff Mode, worklets require the following two APIs. In RL3.0 or
// TTML NoDiff, the implementation of worklets no longer relies on these
// capabilities. After the 2.0 worklet services are phased out, the following
// two APIs will also be removed.
virtual StyleMap GetStylesForWorklet() = 0;
virtual const AttrMap& GetAttributesForWorklet();
inline const auto& GlobalBindTarget() { return global_bind_target_set_; }
virtual bool CanBeLayoutOnly() const = 0;
LYNX_EXPORT_FOR_DEVTOOL bool HasUIPrimitive() const;
virtual void CheckHasInlineContainer(Element* parent);
//{need_request_layout,has_pending_bundle}
std::tuple<bool, bool> FlushAnimatedStyle();
void FlushAnimatedStyle(tasm::CSSPropertyID id, tasm::CSSValue value);
virtual void FlushAnimatedStyleInternal(tasm::CSSPropertyID id,
const tasm::CSSValue& value);
starlight::LayoutResultForRendering layout_result();
float width() { return width_; }
float height() { return height_; }
float top() { return top_; }
float left() { return left_; }
bool display_none() { return display_none_; }
bool enable_new_animator() { return enable_new_animator_; }
PropertiesResolvingStatus GenerateRootPropertyStatus() const;
void SetComputedFontSize(double font_size, double root_font_size);
void SetPlaceHolderStylesInternal(const PseudoPlaceHolderStyles& styles);
void ResetStyleInternal(CSSPropertyID id);
void SetDirectionInternal(const tasm::CSSValue& value) {
SetStyleInternal(kPropertyIDDirection, value);
}
inline const std::array<float, 4>& borders() { return borders_; }
inline const std::array<float, 4>& paddings() { return paddings_; }
inline const std::array<float, 4>& margins() { return margins_; }
inline float max_height() { return max_height_; }
inline bool need_update() { return subtree_need_update_; }
inline bool frame_changed() { return frame_changed_; }
inline void MarkUpdated() {
subtree_need_update_ = false;
frame_changed_ = false;
}
inline void MarkFrameChanged() { frame_changed_ = true; }
inline void set_config_flatten(bool value) { config_flatten_ = value; }
void MarkSubtreeNeedUpdate();
std::pair<CSSValuePattern, CSSValuePattern>
ConvertDynamicStyleFlagToCSSValuePattern(uint32_t style);
void NotifyElementSizeUpdated();
void NotifyUnitValuesUpdatedToAnimation(uint32_t style);
inline void set_is_layout_only(bool is_layout_only) {
is_layout_only_ = is_layout_only;
}
// APIs related to Sticky
inline bool is_sticky() { return is_sticky_; }
inline void set_is_sticky(bool is_sticky) { is_sticky_ = is_sticky; }
inline const base::auto_create_optional<std::array<float, 10>>&
sticky_positions() const {
return sticky_positions_;
}
// Check has_value() before usage to avoid unintentional construction.
inline const auto& keyframes_map() { return keyframes_map_; }
bool ShouldAvoidFlattenForView();
bool TendToFlatten();
bool NeedCreateNodeAsync() { return create_node_async_; }
bool HasPaintingNode() { return has_painting_node_; }
bool IsNewlyCreated() const { return dirty_ & kDirtyCreated; }
void MarkAsInline() {
is_inline_element_ = true;
has_layout_only_props_ = false;
}
// The text element can call this function to convert child fiber elements
// into inline elements. Currently, only view, text, image and wrapper
// elements may be converted into inline elements.
virtual void ConvertToInlineElement();
void ResetPropBundle();
void CheckFlattenRelatedProp(const base::String& key,
const lepus::Value& value = lepus::Value(true));
void CheckHasPlaceholder(const base::String& key,
const lepus::Value& value = lepus::Value(true));
void CheckHasTextSelection(const base::String& key,
const lepus::Value& value = lepus::Value(true));
void CheckTriggerGlobalEvent(const lynx::base::String& key,
const lynx::lepus::Value& value);
void CheckClassChangeTransmitAttribute(const base::String& key,
const lepus::Value& value);
void CheckGlobalBindTarget(
const lynx::base::String& key,
const lynx::lepus::Value& value = lepus::Value(base::String()));
void CheckTimingAttribute(const lynx::base::String& key,
const lynx::lepus::Value& value);
void CheckNewAnimatorAttr(const base::String& key, const lepus::Value& value);
// return true indicates current style is transtion related
bool CheckTransitionProps(CSSPropertyID id);
// return true indicates current style is keyframe related
bool CheckKeyframeProps(CSSPropertyID id);
void CheckHasNonFlattenCSSProps(CSSPropertyID id);
void CheckFixedSticky(CSSPropertyID id, const tasm::CSSValue& value);
bool DisableFlattenWithOpacity();
inline starlight::ComputedCSSStyle* computed_css_style() {
return platform_css_style_.get();
}
inline const starlight::ComputedCSSStyle* computed_css_style() const {
return platform_css_style_.get();
}
/**
* @brief Returns the base computed CSS style (before animation sampling).
*/
inline starlight::ComputedCSSStyle* base_css_style() {
return base_css_style_.get();
}
inline const starlight::ComputedCSSStyle* base_css_style() const {
return base_css_style_.get();
}
starlight::ComputedCSSStyle* GetParentComputedCSSStyle();