View Issue Details

IDProjectCategoryView StatusLast Update
0017587LazarusPatchpublic2010-10-14 13:08
ReporterŽilvinas LedasAssigned ToPaul Ishenin 
PrioritynormalSeverityminorReproducibilityhave not tried
Status closedResolutionfixed 
Product Version0.9.29 (SVN)Product Build 
Target VersionFixed in Version0.9.29 (SVN) 
Summary0017587: turbopoweripro: fixed hint showing; added hints for <abbr> and <acronym> tags; fixed a bug in attributes parsing
DescriptionThis patch does three things:
1) Fixes bug in TIpHtml.ParsePhraseElement() where NextToken; was called before CurPhrase.ParseBaseProps(Self); and properties were reset in NextToken function and as a result CurPhrase.ParseBaseProps(Self); failed to find attributes (title for example).
2) Fixes hint showing - hint showing logic was somehow "broken". Hint did not change correctly if only hint text changed (for example tho consequent <a> tags) and hints did not reposition themselves. Now: hints are updated correctly when hint text changes and hints are repositioned when mouse pointer moves more than 4 pixels.
3) Adds hint showing for <abbr> and <acronym> tags (an example of such tag in a browser: http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_abbr_test ).
TagsNo tags attached.
Fixed in Revision27703
LazTarget0.9.30
Widgetset
Attached Files
  • iphtml_fix_hints_add_abbr_acronym_hints.patch (3,494 bytes)
    Index: iphtml.pas
    ===================================================================
    --- iphtml.pas	(revision 27629)
    +++ iphtml.pas	(working copy)
    @@ -6973,7 +6973,6 @@
     var
       CurPhrase : TIpHtmlNodePhrase;
     begin
    -  NextToken;
       CurPhrase := TIpHtmlNodePhrase.Create(Parent);
       case StartToken of
       IpHtmlTagEM :
    @@ -6998,6 +6997,7 @@
         CurPhrase.Style := hpsACRONYM;
       end;
       CurPhrase.ParseBaseProps(Self);
    +  NextToken; // this can not be before previous line, as NextToken resets properties
       ParseBodyText(CurPhrase, [EndToken] + EndTokens);
       if CurToken = EndToken then
         NextToken
    @@ -17125,13 +17125,13 @@
       {$ENDIF}
     begin
       {$IFDEF IP_LAZARUS}
    -  if HtmlPanel.ShowHints and (NewHint <> CurHint) then begin
    +  if HtmlPanel.ShowHints then begin
       {$ELSE}
       IPHC := HtmlPanel; //JMN
       if Assigned (IPHC) and IPHC.ShowHints and (NewHint <> CurHint) then begin
       {$ENDIF}
         {$IFDEF IP_LAZARUS}
    -    if (NewHint<>'') and not HintWindow.Visible then begin
    +    if (NewHint<>'') then begin
           Tw := HintWindow.Canvas.TextWidth(NewHint);
           Th := HintWindow.Canvas.TextHeight(NewHint);
           Sc := ClientToScreen(Point(HintX,HintY));
    @@ -17140,7 +17140,8 @@
                                        Sc.X + Tw div 2 + 6,
                                        Sc.Y + Th + 16 + 6),
                                   NewHint);
    -    end;
    +    end else
    +      HideHint;
         {$ELSE}
         if (NewHint <> '') and not IsWindowVisible(HintWindow.Handle) then begin
           Tw := HintWindow.Canvas.TextWidth(NewHint);
    @@ -17151,7 +17152,8 @@
                                        Sc.X + Tw div 2 + 4,
                                        Sc.Y + Th + 16),
                                   NewHint);
    -    end;
    +    end else
    +      HideHint;
         {$ENDIF}
         CurHint := NewHint;
         HintShownHere := True;
    @@ -17165,6 +17167,7 @@
       {$IFNDEF IP_LAZARUS}
       IPHC: TIpHtmlCustomPanel; //JMN
       {$ENDIF}
    +  TmpOwnerNode: TIpHtmlNode;
     begin
       if MouseIsDown and HaveSelection then begin
         SelEnd := Point(X + ViewLeft, Y + ViewTop);
    @@ -17220,17 +17223,32 @@
       end;
       {$ENDIF}
       inherited;
    -  if (Hint <> CurHint) and ((abs(HintX - X) > 4) or (abs(HintY - Y) > 4)) then begin
    -    {$IFDEF IP_LAZARUS}
    -    if HintWindow.Visible then
    -    {$ELSE}
    -    if IsWindowVisible(HintWindow.Handle) then
    -    {$ENDIF}
    -      HideHint;
    +
    +  // show hints for IpHtmlTagABBR and IpHtmlTagACRONYM
    +  if (Hyper <> nil) and (Hyper.CurElement <> nil) then begin
    +
    +    TmpOwnerNode := Hyper.CurElement.Owner;
    +    while TmpOwnerNode <> nil do begin
    +      if TmpOwnerNode is TIpHtmlNodePhrase then begin
    +        if (TIpHtmlNodePhrase(TmpOwnerNode).Style = hpsABBR) or (TIpHtmlNodePhrase(TmpOwnerNode).Style = hpsACRONYM) then begin
    +          Hint := TIpHtmlNodePhrase(TmpOwnerNode).Title;
    +          Break;
    +        end else begin
    +          TmpOwnerNode := TmpOwnerNode.FParentNode;
    +        end;
    +      end else begin
    +        TmpOwnerNode := TmpOwnerNode.FParentNode;
    +      end;
    +    end;
    +
    +  end;
    +
    +  // "refresh" hint if it should have new value OR cursors position changes significantly (then we reposition the hint with the same text)
    +  if (Hint <> CurHint) or ((abs(HintX - X) > 4) or (abs(HintY - Y) > 4)) then begin
         HintShownHere := False;
    +    HintX := X;
    +    HintY := Y;
       end;
    -  HintX := X;
    -  HintY := Y;
       if not HintShownHere then
         ShowHintNow(Hint);
     end;
    
  • iphtml_fix_hints_add_abbr_acronym_hints__v2.patch (4,410 bytes)
    Index: iphtml.pas
    ===================================================================
    --- iphtml.pas	(revision 27629)
    +++ iphtml.pas	(working copy)
    @@ -6973,7 +6973,6 @@
     var
       CurPhrase : TIpHtmlNodePhrase;
     begin
    -  NextToken;
       CurPhrase := TIpHtmlNodePhrase.Create(Parent);
       case StartToken of
       IpHtmlTagEM :
    @@ -6998,6 +6997,7 @@
         CurPhrase.Style := hpsACRONYM;
       end;
       CurPhrase.ParseBaseProps(Self);
    +  NextToken; // this can not be before previous line, as NextToken resets properties
       ParseBodyText(CurPhrase, [EndToken] + EndTokens);
       if CurToken = EndToken then
         NextToken
    @@ -12250,7 +12250,10 @@
     
     function TIpHtmlNodeA.GetHint: string;
     begin
    -  Result := HRef;
    +  if Title = '' then
    +    Result := HRef
    +  else
    +    Result := Title;
     end;
     
     { TIpHtmlNodeDIV }
    @@ -17125,33 +17128,35 @@
       {$ENDIF}
     begin
       {$IFDEF IP_LAZARUS}
    -  if HtmlPanel.ShowHints and (NewHint <> CurHint) then begin
    +  if HtmlPanel.ShowHints then begin
       {$ELSE}
       IPHC := HtmlPanel; //JMN
       if Assigned (IPHC) and IPHC.ShowHints and (NewHint <> CurHint) then begin
       {$ENDIF}
         {$IFDEF IP_LAZARUS}
    -    if (NewHint<>'') and not HintWindow.Visible then begin
    +    if (NewHint<>'') then begin
           Tw := HintWindow.Canvas.TextWidth(NewHint);
           Th := HintWindow.Canvas.TextHeight(NewHint);
           Sc := ClientToScreen(Point(HintX,HintY));
    -      HintWindow.ActivateHint(Rect(Sc.X - Tw div 2 - 6,
    +      HintWindow.ActivateHint(Rect(Sc.X + 6,
                                        Sc.Y + 16 - 6,
    -                                   Sc.X + Tw div 2 + 6,
    +                                   Sc.X + Tw + 18,
                                        Sc.Y + Th + 16 + 6),
                                   NewHint);
    -    end;
    +    end else
    +      HideHint;
         {$ELSE}
         if (NewHint <> '') and not IsWindowVisible(HintWindow.Handle) then begin
           Tw := HintWindow.Canvas.TextWidth(NewHint);
           Th := HintWindow.Canvas.TextHeight(NewHint);
           Sc := ClientToScreen(Point(HintX,HintY));
    -      HintWindow.ActivateHint(Rect(Sc.X - Tw div 2 - 4,
    +      HintWindow.ActivateHint(Rect(Sc.X + 4,
                                        Sc.Y + 16,
    -                                   Sc.X + Tw div 2 + 4,
    +                                   Sc.X + Tw + 12,
                                        Sc.Y + Th + 16),
                                   NewHint);
    -    end;
    +    end else
    +      HideHint;
         {$ENDIF}
         CurHint := NewHint;
         HintShownHere := True;
    @@ -17165,6 +17170,7 @@
       {$IFNDEF IP_LAZARUS}
       IPHC: TIpHtmlCustomPanel; //JMN
       {$ENDIF}
    +  TmpOwnerNode: TIpHtmlNode;
     begin
       if MouseIsDown and HaveSelection then begin
         SelEnd := Point(X + ViewLeft, Y + ViewTop);
    @@ -17220,17 +17226,32 @@
       end;
       {$ENDIF}
       inherited;
    -  if (Hint <> CurHint) and ((abs(HintX - X) > 4) or (abs(HintY - Y) > 4)) then begin
    -    {$IFDEF IP_LAZARUS}
    -    if HintWindow.Visible then
    -    {$ELSE}
    -    if IsWindowVisible(HintWindow.Handle) then
    -    {$ENDIF}
    -      HideHint;
    +
    +  // show hints for IpHtmlTagABBR and IpHtmlTagACRONYM
    +  if (Hyper <> nil) and (Hyper.CurElement <> nil) then begin
    +
    +    TmpOwnerNode := Hyper.CurElement.Owner;
    +    while TmpOwnerNode <> nil do begin
    +      if TmpOwnerNode is TIpHtmlNodePhrase then begin
    +        if (TIpHtmlNodePhrase(TmpOwnerNode).Style = hpsABBR) or (TIpHtmlNodePhrase(TmpOwnerNode).Style = hpsACRONYM) then begin
    +          Hint := TIpHtmlNodePhrase(TmpOwnerNode).Title;
    +          Break;
    +        end else begin
    +          TmpOwnerNode := TmpOwnerNode.FParentNode;
    +        end;
    +      end else begin
    +        TmpOwnerNode := TmpOwnerNode.FParentNode;
    +      end;
    +    end;
    +
    +  end;
    +
    +  // "refresh" hint if it should have new value OR cursors position changes significantly (then we reposition the hint with the same text)
    +  if (Hint <> CurHint) or ((abs(HintX - X) > 4) or (abs(HintY - Y) > 4)) then begin
         HintShownHere := False;
    +    HintX := X;
    +    HintY := Y;
       end;
    -  HintX := X;
    -  HintY := Y;
       if not HintShownHere then
         ShowHintNow(Hint);
     end;
    @@ -17355,7 +17376,6 @@
           Printer.PageWidth - RMarginPix,
           Printer.PageHeight - BMarginPix);}                               {!!.12}
         PrintPageRect := Hyper.GetPageRect(Printer.Canvas,
    -      PrintWidth, PrintHeight);
         H := PrintPageRect.Bottom - PrintPageRect.Top;
         PageCount := H div PrintHeight;
         if H mod PrintHeight <> 0 then
    

Activities

2010-10-09 13:14

 

iphtml_fix_hints_add_abbr_acronym_hints.patch (3,494 bytes)
Index: iphtml.pas
===================================================================
--- iphtml.pas	(revision 27629)
+++ iphtml.pas	(working copy)
@@ -6973,7 +6973,6 @@
 var
   CurPhrase : TIpHtmlNodePhrase;
 begin
-  NextToken;
   CurPhrase := TIpHtmlNodePhrase.Create(Parent);
   case StartToken of
   IpHtmlTagEM :
@@ -6998,6 +6997,7 @@
     CurPhrase.Style := hpsACRONYM;
   end;
   CurPhrase.ParseBaseProps(Self);
+  NextToken; // this can not be before previous line, as NextToken resets properties
   ParseBodyText(CurPhrase, [EndToken] + EndTokens);
   if CurToken = EndToken then
     NextToken
@@ -17125,13 +17125,13 @@
   {$ENDIF}
 begin
   {$IFDEF IP_LAZARUS}
-  if HtmlPanel.ShowHints and (NewHint <> CurHint) then begin
+  if HtmlPanel.ShowHints then begin
   {$ELSE}
   IPHC := HtmlPanel; //JMN
   if Assigned (IPHC) and IPHC.ShowHints and (NewHint <> CurHint) then begin
   {$ENDIF}
     {$IFDEF IP_LAZARUS}
-    if (NewHint<>'') and not HintWindow.Visible then begin
+    if (NewHint<>'') then begin
       Tw := HintWindow.Canvas.TextWidth(NewHint);
       Th := HintWindow.Canvas.TextHeight(NewHint);
       Sc := ClientToScreen(Point(HintX,HintY));
@@ -17140,7 +17140,8 @@
                                    Sc.X + Tw div 2 + 6,
                                    Sc.Y + Th + 16 + 6),
                               NewHint);
-    end;
+    end else
+      HideHint;
     {$ELSE}
     if (NewHint <> '') and not IsWindowVisible(HintWindow.Handle) then begin
       Tw := HintWindow.Canvas.TextWidth(NewHint);
@@ -17151,7 +17152,8 @@
                                    Sc.X + Tw div 2 + 4,
                                    Sc.Y + Th + 16),
                               NewHint);
-    end;
+    end else
+      HideHint;
     {$ENDIF}
     CurHint := NewHint;
     HintShownHere := True;
@@ -17165,6 +17167,7 @@
   {$IFNDEF IP_LAZARUS}
   IPHC: TIpHtmlCustomPanel; //JMN
   {$ENDIF}
+  TmpOwnerNode: TIpHtmlNode;
 begin
   if MouseIsDown and HaveSelection then begin
     SelEnd := Point(X + ViewLeft, Y + ViewTop);
@@ -17220,17 +17223,32 @@
   end;
   {$ENDIF}
   inherited;
-  if (Hint <> CurHint) and ((abs(HintX - X) > 4) or (abs(HintY - Y) > 4)) then begin
-    {$IFDEF IP_LAZARUS}
-    if HintWindow.Visible then
-    {$ELSE}
-    if IsWindowVisible(HintWindow.Handle) then
-    {$ENDIF}
-      HideHint;
+
+  // show hints for IpHtmlTagABBR and IpHtmlTagACRONYM
+  if (Hyper <> nil) and (Hyper.CurElement <> nil) then begin
+
+    TmpOwnerNode := Hyper.CurElement.Owner;
+    while TmpOwnerNode <> nil do begin
+      if TmpOwnerNode is TIpHtmlNodePhrase then begin
+        if (TIpHtmlNodePhrase(TmpOwnerNode).Style = hpsABBR) or (TIpHtmlNodePhrase(TmpOwnerNode).Style = hpsACRONYM) then begin
+          Hint := TIpHtmlNodePhrase(TmpOwnerNode).Title;
+          Break;
+        end else begin
+          TmpOwnerNode := TmpOwnerNode.FParentNode;
+        end;
+      end else begin
+        TmpOwnerNode := TmpOwnerNode.FParentNode;
+      end;
+    end;
+
+  end;
+
+  // "refresh" hint if it should have new value OR cursors position changes significantly (then we reposition the hint with the same text)
+  if (Hint <> CurHint) or ((abs(HintX - X) > 4) or (abs(HintY - Y) > 4)) then begin
     HintShownHere := False;
+    HintX := X;
+    HintY := Y;
   end;
-  HintX := X;
-  HintY := Y;
   if not HintShownHere then
     ShowHintNow(Hint);
 end;

2010-10-09 20:10

 

iphtml_fix_hints_add_abbr_acronym_hints__v2.patch (4,410 bytes)
Index: iphtml.pas
===================================================================
--- iphtml.pas	(revision 27629)
+++ iphtml.pas	(working copy)
@@ -6973,7 +6973,6 @@
 var
   CurPhrase : TIpHtmlNodePhrase;
 begin
-  NextToken;
   CurPhrase := TIpHtmlNodePhrase.Create(Parent);
   case StartToken of
   IpHtmlTagEM :
@@ -6998,6 +6997,7 @@
     CurPhrase.Style := hpsACRONYM;
   end;
   CurPhrase.ParseBaseProps(Self);
+  NextToken; // this can not be before previous line, as NextToken resets properties
   ParseBodyText(CurPhrase, [EndToken] + EndTokens);
   if CurToken = EndToken then
     NextToken
@@ -12250,7 +12250,10 @@
 
 function TIpHtmlNodeA.GetHint: string;
 begin
-  Result := HRef;
+  if Title = '' then
+    Result := HRef
+  else
+    Result := Title;
 end;
 
 { TIpHtmlNodeDIV }
@@ -17125,33 +17128,35 @@
   {$ENDIF}
 begin
   {$IFDEF IP_LAZARUS}
-  if HtmlPanel.ShowHints and (NewHint <> CurHint) then begin
+  if HtmlPanel.ShowHints then begin
   {$ELSE}
   IPHC := HtmlPanel; //JMN
   if Assigned (IPHC) and IPHC.ShowHints and (NewHint <> CurHint) then begin
   {$ENDIF}
     {$IFDEF IP_LAZARUS}
-    if (NewHint<>'') and not HintWindow.Visible then begin
+    if (NewHint<>'') then begin
       Tw := HintWindow.Canvas.TextWidth(NewHint);
       Th := HintWindow.Canvas.TextHeight(NewHint);
       Sc := ClientToScreen(Point(HintX,HintY));
-      HintWindow.ActivateHint(Rect(Sc.X - Tw div 2 - 6,
+      HintWindow.ActivateHint(Rect(Sc.X + 6,
                                    Sc.Y + 16 - 6,
-                                   Sc.X + Tw div 2 + 6,
+                                   Sc.X + Tw + 18,
                                    Sc.Y + Th + 16 + 6),
                               NewHint);
-    end;
+    end else
+      HideHint;
     {$ELSE}
     if (NewHint <> '') and not IsWindowVisible(HintWindow.Handle) then begin
       Tw := HintWindow.Canvas.TextWidth(NewHint);
       Th := HintWindow.Canvas.TextHeight(NewHint);
       Sc := ClientToScreen(Point(HintX,HintY));
-      HintWindow.ActivateHint(Rect(Sc.X - Tw div 2 - 4,
+      HintWindow.ActivateHint(Rect(Sc.X + 4,
                                    Sc.Y + 16,
-                                   Sc.X + Tw div 2 + 4,
+                                   Sc.X + Tw + 12,
                                    Sc.Y + Th + 16),
                               NewHint);
-    end;
+    end else
+      HideHint;
     {$ENDIF}
     CurHint := NewHint;
     HintShownHere := True;
@@ -17165,6 +17170,7 @@
   {$IFNDEF IP_LAZARUS}
   IPHC: TIpHtmlCustomPanel; //JMN
   {$ENDIF}
+  TmpOwnerNode: TIpHtmlNode;
 begin
   if MouseIsDown and HaveSelection then begin
     SelEnd := Point(X + ViewLeft, Y + ViewTop);
@@ -17220,17 +17226,32 @@
   end;
   {$ENDIF}
   inherited;
-  if (Hint <> CurHint) and ((abs(HintX - X) > 4) or (abs(HintY - Y) > 4)) then begin
-    {$IFDEF IP_LAZARUS}
-    if HintWindow.Visible then
-    {$ELSE}
-    if IsWindowVisible(HintWindow.Handle) then
-    {$ENDIF}
-      HideHint;
+
+  // show hints for IpHtmlTagABBR and IpHtmlTagACRONYM
+  if (Hyper <> nil) and (Hyper.CurElement <> nil) then begin
+
+    TmpOwnerNode := Hyper.CurElement.Owner;
+    while TmpOwnerNode <> nil do begin
+      if TmpOwnerNode is TIpHtmlNodePhrase then begin
+        if (TIpHtmlNodePhrase(TmpOwnerNode).Style = hpsABBR) or (TIpHtmlNodePhrase(TmpOwnerNode).Style = hpsACRONYM) then begin
+          Hint := TIpHtmlNodePhrase(TmpOwnerNode).Title;
+          Break;
+        end else begin
+          TmpOwnerNode := TmpOwnerNode.FParentNode;
+        end;
+      end else begin
+        TmpOwnerNode := TmpOwnerNode.FParentNode;
+      end;
+    end;
+
+  end;
+
+  // "refresh" hint if it should have new value OR cursors position changes significantly (then we reposition the hint with the same text)
+  if (Hint <> CurHint) or ((abs(HintX - X) > 4) or (abs(HintY - Y) > 4)) then begin
     HintShownHere := False;
+    HintX := X;
+    HintY := Y;
   end;
-  HintX := X;
-  HintY := Y;
   if not HintShownHere then
     ShowHintNow(Hint);
 end;
@@ -17355,7 +17376,6 @@
       Printer.PageWidth - RMarginPix,
       Printer.PageHeight - BMarginPix);}                               {!!.12}
     PrintPageRect := Hyper.GetPageRect(Printer.Canvas,
-      PrintWidth, PrintHeight);
     H := PrintPageRect.Bottom - PrintPageRect.Top;
     PageCount := H div PrintHeight;
     if H mod PrintHeight <> 0 then

Žilvinas Ledas

2010-10-09 20:17

reporter   ~0041661

I have uploaded updated patch (__v2). It includes two modifications:
1) Show Title of <a> alement if title is available (previously href was shown always). Browsers show title if it is awailable and do not show href at all - maybe we should not show href too?
2) Aligns hint to the right-bottom of the mouse cursor (previously it was center-bottom). Previous alignment was bad as mouse cursor was hiding some hint text and to move it down even more would be not good for the <abbr> and <acronym> hints (I guess the exact hint position should depend on the used cursor, but it is too difficult at least for now). What is more, at least Firefox shows hint right-bottom so this position should be expected.

Paul Ishenin

2010-10-14 05:20

manager   ~0041795

Thanks, applied. Although I had merge conflicts - so please review the merge.

Žilvinas Ledas

2010-10-14 13:08

reporter   ~0041808

Thanks. Everything seems to be good!

Issue History

Date Modified Username Field Change
2010-10-09 13:14 Žilvinas Ledas New Issue
2010-10-09 13:14 Žilvinas Ledas File Added: iphtml_fix_hints_add_abbr_acronym_hints.patch
2010-10-09 15:46 Maxim Ganetsky LazTarget => 0.9.30
2010-10-09 20:10 Žilvinas Ledas File Added: iphtml_fix_hints_add_abbr_acronym_hints__v2.patch
2010-10-09 20:17 Žilvinas Ledas Note Added: 0041661
2010-10-14 05:20 Paul Ishenin Fixed in Revision => 27703
2010-10-14 05:20 Paul Ishenin Status new => resolved
2010-10-14 05:20 Paul Ishenin Fixed in Version => 0.9.29 (SVN)
2010-10-14 05:20 Paul Ishenin Resolution open => fixed
2010-10-14 05:20 Paul Ishenin Assigned To => Paul Ishenin
2010-10-14 05:20 Paul Ishenin Note Added: 0041795
2010-10-14 13:08 Žilvinas Ledas Status resolved => closed
2010-10-14 13:08 Žilvinas Ledas Note Added: 0041808