Closed Bug 167068 Opened 23 years ago Closed 22 years ago

[CSS3] implement ::selection pseudo-element

Categories

(Core :: CSS Parsing and Computation, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: glazou, Assigned: glazou)

Details

Attachments

(5 files, 3 obsolete files)

Implement the CSS 3 ::selection pseudo-element. The spec is available at http://www.w3.org/TR/css3-selectors/#UIfragments CSS properties that apply to ::selection pseudo-elements are : color, cursor, background, outline.
Attached patch patch v0.9 (obsolete) — Splinter Review
Mike, this patch does everything needed to deal with the background-color of the selection. The other properties we have to deal with in the context of -moz-selection are color cursor outline background-image background-attachment background-position background-repeat to be honest, I don't like the 4 last ones in the context of the selection. Attaching later a test case for this patch.
Shouldn't that be "::-moz-selection"? (Psudo-element, not psudo-class)
Minor nit: +class CSSSelectionRule : public CSSFirstLineRule { That seems wrong. Shouldn't they both inherit from a common ancestor? Otherwise, interesting stuff!
Oh. Ugh. I should probably finish the patch in bug 103189 at some point.
Actually, though, you probably don't need that special selection rule, since you're not creating a frame with this style context -- you're actually just reimplementing the allowed properties in a one-off sort of way.
> Minor nit: > > +class CSSSelectionRule : public CSSFirstLineRule { > > That seems wrong. Shouldn't they both inherit from a common ancestor? Right, I did that too fast. But please note that CSSFirstLetterrRule also inherits from that class. I just did the same mistake. > Otherwise, interesting stuff! What's interesting is not my code. It just reuses the superb power of Mike Judge's code and design. Adding ::selection to his code is a child's play and I should have done that looooong ago.
Status: NEW → ASSIGNED
> Shouldn't that be "::-moz-selection"? (Psudo-element, not psudo-class) Absolutely. The patch is ready but not checked in yet. This is covered by another bug and I'll make it land asap since we absolutely need it to be able to exit Selectors CR.
Status: ASSIGNED → RESOLVED
Closed: 23 years ago
Resolution: --- → FIXED
> Oh. Ugh. I should probably finish the patch in bug 103189 at some point. David, do you want to do that first or can I move forward w/o waiting for your check-in ? (yes, I also saw that CSSFirstLineRule::MapRuleInfoInto was involved into bug 103189) OOOOOPSSSS, marked RESO/FIXED by error, sorry for that, my mouse is going to spend the next ten days in hell as a punishment.
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
sorry for spam
Status: REOPENED → ASSIGNED
I actually don't think it matters, since I don't think you need the CSSSelectionRule at all to fix this bug. (See comment 6.)
+ nsIStyleContext* sc = nsnull; Seems to leak.
Attached file more complete and better test case (obsolete) —
Attachment #98134 - Attachment is obsolete: true
Attached patch patch v1.0Splinter Review
I think that this patch is ok for reviews. David, Mike, Boris, care to r/sr please ? You can test the patch with the attached test case.
Attachment #98133 - Attachment is obsolete: true
just because I have been through this before I am going to be very picky here. + nsIStyleContext *sc = nsnull; should probably be an nsCOMPtr. I see that you may want to release it sooner. (for all I know you copied this from my own code) if you want when you call + NS_RELEASE(sc) just instead set sc=0; to force a free of the nsCOMPtr at that time *Note: thanks for cleaning up these tabs i had in here somehow. Looks like tab wierdness near bottom of patch ** if (newDimensions.width) { - if (iter.CurrentBackGroundColor(currentBKColor)) + if (iter.CurrentBackGroundColor(currentBKColor, &isCurrentBKColorTransparent)) {//DRAW RECT HERE!!! - aRenderingContext.SetColor(currentBKColor); - aRenderingContext.FillRect(currentX, dy, newDimensions.width, mRect.height); - currentFGColor = EnsureDifferentColors(currentFGColor, currentBKColor); + if (!isCurrentBKColorTransparent) { + aRenderingContext.SetColor(currentBKColor); + aRenderingContext.FillRect(currentX, dy, newDimensions.width, mRect.height); + } + currentFGColor = EnsureDifferentColors(currentFGColor, currentBKColor); } } ** One last thing which I am sure you are not looking forward to.. with 14835 which is in the trunk right now I use the seleciton color to alpha blend the image that is selected. Does this newly implemented style rule affect this? We may have to talk about how to best solve this one.
put down an r for me after you address the things i said. either change the comptr, fix the indents or not I leave it to you. r=mjudge
Attached patch patch v1.1Splinter Review
this patch in answer to mjudge's comments also fixes indentation and coding style in the whole file since I had a lot of difficulty to read some portions of it Kin, for your super-review, please prefer the "clean" part in patch v1.0 above
Comment on attachment 99519 [details] [diff] [review] patch v1.1 Yowza, this diff went from ~300 lines to ~2100 lines ... I think next time it would be a lot easier to do the formatting sweep in some other diff so it doesn't hide your changes, this would also make it easier on reviewers too. ==== This needs the args to line up like the rest of your changes: + NS_IMETHOD CheckVisibility(nsIPresContext* aContext, + PRInt32 aStartIndex, + PRInt32 aEndIndex, + PRBool aRecurse, + PRBool *aFinished, + PRBool *_retval); ==== This doesn't line up properly: NS_IMETHOD GetChildFrameContainingOffset(PRInt32 inContentOffset, - PRBool inHint, - PRInt32* outFrameContentOffset, - nsIFrame* *outChildFrame); + PRBool inHint, + PRInt32* outFrameContentOffset, + nsIFrame* *outChildFrame); ==== Shouldn't we check for |aContent == nsnull| before dereferencing |aContent|? See later comments. + nsCOMPtr<nsIStyleContext> sc; + nsCOMPtr<nsIContent> parentContent; + aContent->GetParent(*getter_AddRefs(parentContent)); + aPresContext->ProbePseudoStyleContextFor(parentContent, ==== Do we have to check for null before dereferencing |bg| or |color|? + const nsStyleBackground* bg = (const nsStyleBackground*)sc->GetStyleData(eStyleStruct_Background); + const nsStyleColor* color =(const nsStyleColor*) sc->GetStyleData(eStyleStruct_Color); ==== This doesn't look like it lines up right: - aTextStyle.mNormalFont->GetUnderline(offset, size); + aTextStyle.mNormalFont->GetUnderline(offset, size); aRenderingContext.SetColor(IME_CONVERTED_COLOR); aRenderingContext.FillRect(aX + startOffset+size, aY + baseline - offset, textWidth-2*size, size); }break; ==== In 4 different places, you moved the |content| declaration outside an |if| block, which was responsible for retrieving it's value, and then later you pass |content| into |DrawSelectionIterator iter()| ... if |content| is ever null, we will crash because the |DrawSelectionIterator| constructor doesn't check the passed in content node ptr for null before dereferencing it ... perhaps a check should be added to the constructor: - if (NS_SUCCEEDED(rv) && frameSelection){ - nsCOMPtr<nsIContent> content; + nsCOMPtr<nsIContent> content; + if (NS_SUCCEEDED(rv) && frameSelection) { ... - DrawSelectionIterator iter(details,text,(PRUint32)textLength, ts, nsISelectionController::SELECTION_NORMAL, aPresContext); + DrawSelectionIterator iter(content, details,text,(PRUint32)textLength, ts, nsISelectionController::SELECTION_NORMAL, aPresContext, mStyleContext); ==== Line the comment up and move the comment after the ';' to under the comment it belongs. - //increment twips X start but remember to get ready for next draw by reducing current x by letter spacing amount - currentX+=newDimensions.width;// + aTextStyle.mLetterSpacing; + //increment twips X start but remember to get ready for next draw by reducing current x by letter spacing amount + currentX+=newDimensions.width;// + aTextStyle.mLetterSpacing; ==== Fix the indentation: + if (!isCurrentBKColorTransparent) { + aRenderingContext.SetColor(currentBKColor); + aRenderingContext.FillRect(currentX, dy, newWidth, mRect.height); + } + currentFGColor = EnsureDifferentColors(currentFGColor, currentBKColor); ==== Why aren't we setting the color anymore here? if (isPaginated && !iter.IsBeforeOrAfter()) { - aRenderingContext.SetColor(nsCSSRendering::TransformColor(aTextStyle.mColor->mC olor,canDarkenC olor)); aRenderingContext.DrawString(currenttext, currentlength, currentX, dy + mAscent); ==== This still doesn't line up correctly: TryNextFrame: - GetNextInFlow(&frameUsed); + GetNextInFlow(&frameUsed); start = 0; }
> Yowza, this diff went from ~300 lines to ~2100 lines ... I think next time it > would be a lot easier to do the formatting sweep in some other diff so it > doesn't hide your changes, this would also make it easier on reviewers too. That's why I said above 'Kin, for your super-review, please prefer the "clean" part in patch v1.0 above'...
Kin, this one is more readable and answers to your comments. About the result of sc->GetStyle(), no need to null check it.
Comment on attachment 99958 [details] [diff] [review] patch v1.1, modifs only, no indent cleanup carries forward r=mjudge
Attachment #99958 - Flags: review+
Comment on attachment 99958 [details] [diff] [review] patch v1.1, modifs only, no indent cleanup sr=kin@netscape.com Just fix the indentation here: if (newDimensions.width) { - if (iter.CurrentBackGroundColor(currentBKColor)) + if (iter.CurrentBackGroundColor(currentBKColor, &isCurrentBKColorTransparent)) {//DRAW RECT HERE!!! - aRenderingContext.SetColor(currentBKColor); - aRenderingContext.FillRect(currentX, dy, newDimensions.width, mRect.height); - currentFGColor = EnsureDifferentColors(currentFGColor, currentBKColor); + if (!isCurrentBKColorTransparent) { + aRenderingContext.SetColor(currentBKColor); + aRenderingContext.FillRect(currentX, dy, newDimensions.width, mRect.height); + } + currentFGColor = EnsureDifferentColors(currentFGColor, currentBKColor); } }
Attachment #99958 - Flags: superreview+
checked in trunk
Status: ASSIGNED → RESOLVED
Closed: 23 years ago23 years ago
Resolution: --- → FIXED
why is it -moz ?
This does not work with xul:textbox and html:textarea and other form elements. Test case coming up
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Erik: Please file a separate bug (and mark it as blocking bug 176170). This bug was about the initial implementation, which is done. Keeping each issue separate results in patches being much easier to track. Cheers.
Status: REOPENED → RESOLVED
Closed: 23 years ago22 years ago
Resolution: --- → FIXED
Depends on: 211883
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: