Bug 184753

Summary: Detect system preview links
Product: WebKit Reporter: Dean Jackson <dino>
Component: New BugsAssignee: Dean Jackson <dino>
Status: RESOLVED FIXED    
Severity: Normal CC: cdumez, esprehn+autocc, ews-watchlist, graouts, gyuyoung.kim, sabouhallawa, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch
graouts: review+
Patch none

Dean Jackson
Reported 2018-04-18 13:29:44 PDT
Detect system preview links
Attachments
Patch (17.36 KB, patch)
2018-04-18 13:34 PDT, Dean Jackson
no flags
Patch (16.97 KB, patch)
2018-04-18 13:59 PDT, Dean Jackson
graouts: review+
Patch (17.05 KB, patch)
2018-04-18 14:59 PDT, Dean Jackson
no flags
Dean Jackson
Comment 1 2018-04-18 13:30:25 PDT
Dean Jackson
Comment 2 2018-04-18 13:34:30 PDT
Dean Jackson
Comment 3 2018-04-18 13:59:59 PDT
Antoine Quint
Comment 4 2018-04-18 14:07:54 PDT
Comment on attachment 338260 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=338260&action=review > Source/WebCore/html/HTMLAnchorElement.cpp:388 > + return (numChildren == 1 || numChildren == 2); Don't need the parentheses. > Source/WebCore/testing/Internals.cpp:4494 > + return downcast<HTMLAnchorElement>(element).isSystemPreviewLink(); return is<HTMLAnchorElement>(element) && downcast<HTMLAnchorElement>(element).isSystemPreviewLink(); > LayoutTests/system-preview/detection.html:12 > + children = link.children; Single-clause if statement should not use curly braces. > LayoutTests/system-preview/detection.html:25 > +window.addEventListener("load", function () { () => > LayoutTests/system-preview/detection.html:44 > + addResult(result, "No link."); Single-clause else statement should not use curly braces.
Dean Jackson
Comment 5 2018-04-18 14:59:02 PDT
Said Abou-Hallawa
Comment 6 2018-04-18 15:09:04 PDT
Comment on attachment 338260 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=338260&action=review > Source/WebCore/html/HTMLAnchorElement.cpp:380 > + // The relList is created on demand, which means that calling relList() > + // is only available in a non-const method. Does this comment describe the new code or the existing code? I think in your patch relList() is const which means it can be called from const and non-const methods. >> Source/WebCore/html/HTMLAnchorElement.cpp:388 >> + return (numChildren == 1 || numChildren == 2); > > Don't need the parentheses. It can also be written like this: auto* child = firstElementChild(); if (!child || childElementCount() > 2) return false; return is<HTMLImageElement>(child) || is<HTMLPictureElement>(child); Or even shorter auto* child = firstElementChild(); return child && childElementCount() <= 2 && (is<HTMLImageElement>(child) || is<HTMLPictureElement>(child)); > Source/WebCore/html/HTMLPictureElement.cpp:79 > +bool HTMLPictureElement::isSystemPreviewImage() const Why this function is named isSystemPreviewImage()? Should not this function be named isSystemPreviewPicture()? Or maybe it is better to remove the element name from all these functions: isSystemPreviewLink() isSystemPreviewImage() isSystemPreviewPicture() and have a single name for all of them isSystemPreviewable() > Source/WebCore/testing/Internals.cpp:4504 > +bool Internals::isSystemPreviewLink(Element& element) const > +{ > + if (!is<HTMLAnchorElement>(element)) > + return false; > + return downcast<HTMLAnchorElement>(element).isSystemPreviewLink(); > +} > + > +bool Internals::isSystemPreviewImage(Element& element) const > +{ > + if (is<HTMLImageElement>(element)) > + return downcast<HTMLImageElement>(element).isSystemPreviewImage(); > + if (is<HTMLPictureElement>(element)) > + return downcast<HTMLPictureElement>(element).isSystemPreviewImage(); > + return false; > +} Repeating the casting in the Internals and in HTMLPictureElement and HTMLImageElement may suggest having a virtual function Element::isSystemPreviewable() which returns false. HTMLPictureElement and HTMLImageElement override isSystemPreviewable() by just calling parent->isSystemPreviewable(). And of course HTMLAnchorElement::isSystemPreviewable() will have the real logic.
Dean Jackson
Comment 7 2018-04-18 15:14:15 PDT
Dean Jackson
Comment 8 2018-04-18 16:04:58 PDT
Thanks Said. I'll make follow-up fixes.
Note You need to log in before you can comment on or make changes to this bug.