fcl-css: resolveR: surpress duplicate warnings

This commit is contained in:
mattias 2022-09-19 09:24:35 +02:00
parent 5a7664f7d1
commit 6454c931b8

View File

@ -60,10 +60,9 @@ element/type: 1 p, :before
*: 0 *: 0
ToDo: ToDo:
- replace parser invalidtoken for relational operators ctkStar, Tile, Pipe - replace parser invalidtoken for relational operators ctkGt, ctkTilde
- :has() - :has()
- 'all' attribute: resets all properties, except direction and unicode bidi - 'all' attribute: resets all properties, except direction and unicode bidi
- surpress duplicate warnings
- TCSSResolver.FindComputedAttribute use binary search for >8 elements - TCSSResolver.FindComputedAttribute use binary search for >8 elements
- namespaces - namespaces
- layers - layers
@ -309,6 +308,16 @@ const
DefaultCSSComputeOptions = [ccoCommit]; DefaultCSSComputeOptions = [ccoCommit];
type type
TCSSResolverLogEntry = class
public
MsgType: TEventType;
ID: TCSSMsgID;
Msg: string;
PosEl: TCSSElement;
end;
TCSSResolverLogEvent = procedure(Sender: TObject; Entry: TCSSResolverLogEntry) of object;
TCSSResStringComparison = ( TCSSResStringComparison = (
crscDefault, crscDefault,
crscCaseInsensitive, crscCaseInsensitive,
@ -316,9 +325,6 @@ type
); );
TCSSResStringComparisons = set of TCSSResStringComparison; TCSSResStringComparisons = set of TCSSResStringComparison;
TCSSResolverLogEvent = procedure(Sender: TObject; aType: TEventType;
const ID: TCSSMsgID; const Msg: string; PosEl: TCSSElement) of object;
{ TCSSResolver } { TCSSResolver }
TCSSResolver = class TCSSResolver = class
@ -332,6 +338,8 @@ type
FFirstElData: TCSSElResolverData; FFirstElData: TCSSElResolverData;
FLastElData: TCSSElResolverData; FLastElData: TCSSElResolverData;
function GetAttributes(Index: integer): PCSSComputedAttribute; function GetAttributes(Index: integer): PCSSComputedAttribute;
function GetLogCount: integer;
function GetLogEntries(Index: integer): TCSSResolverLogEntry;
function GetNumericalIDs(Kind: TCSSNumericalIDKind): TCSSNumericalIDs; function GetNumericalIDs(Kind: TCSSNumericalIDKind): TCSSNumericalIDs;
procedure SetNumericalIDs(Kind: TCSSNumericalIDKind; procedure SetNumericalIDs(Kind: TCSSNumericalIDKind;
const AValue: TCSSNumericalIDs); const AValue: TCSSNumericalIDs);
@ -340,6 +348,7 @@ type
FAttributes: TCSSComputedAttributeArray; FAttributes: TCSSComputedAttributeArray;
FAttributeCount: integer; FAttributeCount: integer;
FNode: TCSSNode; FNode: TCSSNode;
FLogEntries: TFPObjectList; // list of TCSSResolverLogEntry
procedure SetStyle(const AValue: TCSSElement); virtual; procedure SetStyle(const AValue: TCSSElement); virtual;
procedure ComputeElement(El: TCSSElement); virtual; procedure ComputeElement(El: TCSSElement); virtual;
procedure ComputeRule(aRule: TCSSRuleElement); virtual; procedure ComputeRule(aRule: TCSSRuleElement); virtual;
@ -382,6 +391,7 @@ type
public public
constructor Create; constructor Create;
destructor Destroy; override; destructor Destroy; override;
procedure Clear; virtual;
procedure ClearStyleCustomData; virtual; procedure ClearStyleCustomData; virtual;
procedure Compute(Node: TCSSNode; NodeStyle: TCSSElement = nil; procedure Compute(Node: TCSSNode; NodeStyle: TCSSElement = nil;
const CompOptions: TCSSComputeOptions = DefaultCSSComputeOptions); virtual; const CompOptions: TCSSComputeOptions = DefaultCSSComputeOptions); virtual;
@ -394,6 +404,8 @@ type
property AttributeCount: integer read FAttributeCount; property AttributeCount: integer read FAttributeCount;
property StringComparison: TCSSResStringComparison read FStringComparison; property StringComparison: TCSSResStringComparison read FStringComparison;
property OnLog: TCSSResolverLogEvent read FOnLog write FOnLog; property OnLog: TCSSResolverLogEvent read FOnLog write FOnLog;
property LogCount: integer read GetLogCount;
property LogEntries[Index: integer]: TCSSResolverLogEntry read GetLogEntries;
end; end;
implementation implementation
@ -473,6 +485,16 @@ begin
Result:=@FAttributes[Index]; Result:=@FAttributes[Index];
end; end;
function TCSSResolver.GetLogCount: integer;
begin
Result:=FLogEntries.Count;
end;
function TCSSResolver.GetLogEntries(Index: integer): TCSSResolverLogEntry;
begin
Result:=TCSSResolverLogEntry(FLogEntries[Index]);
end;
procedure TCSSResolver.SetNumericalIDs(Kind: TCSSNumericalIDKind; procedure TCSSResolver.SetNumericalIDs(Kind: TCSSNumericalIDKind;
const AValue: TCSSNumericalIDs); const AValue: TCSSNumericalIDs);
begin begin
@ -1792,9 +1814,29 @@ end;
procedure TCSSResolver.Log(MsgType: TEventType; const ID: TCSSMsgID; procedure TCSSResolver.Log(MsgType: TEventType; const ID: TCSSMsgID;
Msg: string; PosEl: TCSSElement); Msg: string; PosEl: TCSSElement);
var
Entry: TCSSResolverLogEntry;
i: Integer;
begin begin
if assigned(OnLog) then if Assigned(OnLog) then
OnLog(Self,MsgType,ID,Msg,PosEl); begin
for i:=0 to FLogEntries.Count-1 do
begin
Entry:=LogEntries[i];
if (Entry.PosEl=PosEl)
and (Entry.ID=ID)
and (Entry.MsgType=MsgType)
and (Entry.Msg=Msg) then
exit; // this warning was already logged
end;
Entry:=TCSSResolverLogEntry.Create;
Entry.MsgType:=MsgType;
Entry.ID:=ID;
Entry.Msg:=Msg;
Entry.PosEl:=PosEl;
FLogEntries.Add(Entry);
OnLog(Self,Entry);
end;
if (MsgType=etError) or (FOnLog=nil) then if (MsgType=etError) or (FOnLog=nil) then
begin begin
Msg:='['+IntToStr(ID)+'] '+Msg+' at '+GetElPos(PosEl); Msg:='['+IntToStr(ID)+'] '+Msg+' at '+GetElPos(PosEl);
@ -1821,17 +1863,23 @@ end;
constructor TCSSResolver.Create; constructor TCSSResolver.Create;
begin begin
FLogEntries:=TFPObjectList.Create(true);
end; end;
destructor TCSSResolver.Destroy; destructor TCSSResolver.Destroy;
begin begin
FreeAndNil(FLogEntries);
if FOwnsStyle then if FOwnsStyle then
FStyle.Free; FStyle.Free;
FStyle:=nil; FStyle:=nil;
inherited Destroy; inherited Destroy;
end; end;
procedure TCSSResolver.Clear;
begin
ClearStyleCustomData;
end;
procedure TCSSResolver.ClearStyleCustomData; procedure TCSSResolver.ClearStyleCustomData;
var var
Data: TCSSElResolverData; Data: TCSSElResolverData;