Open Bug 706209 Opened 13 years ago Updated 3 months ago

have a way to style the selection in inactive windows (apply ::-moz-selection or add similar but different way)

Categories

(Core :: Layout: Text and Fonts, enhancement)

enhancement

Tracking

()

People

(Reporter: aadib, Unassigned)

References

(Blocks 1 open bug)

Details

It'd be nice if we could combine moz-selection with moz-window-active/inactive, so that we could override FF's default behavior of making selected text both opaque and gray in inactive windows (at least on OS X).

This would be useful for our pdf.js project, where we have a transparent layer of text on top of a canvas used for faking text selection: Currently, when the user inactivates a window the forced opaque-gray selection hides the canvas content behind it.

Here's a discussion on this by someone else:

http://css-tricks.com/9288-window-inactive-styling/

Thanks!
This seems to be quite purposeful.  In particular, nsTextPaintStyle::InitSelectionColors does this:

3447      if (selectionElement &&
3448          selectionStatus == nsISelectionController::SELECTION_ON) {

around looking up ::selection styles.  When the window is active, the selectionStatus is SELECTION_ON.  Otherwise it's SELECTION_DISABLED, at least on Mac.

This behavior was introduced by bug 56314, looks like.  Masayuki, why is that check there?
Component: Style System (CSS) → Layout: Text
QA Contact: style-system → layout.fonts-and-text
Summary: moz-selection cannot be used with moz-window-active/inactive → moz-selection is ignored in inactive windows
Because the -moz-selection is for specifying normal selection styles rather than other styles (including disabled). If we apply the specified style to -moz-selection simply, we always paint the selection on some sites as active even if the window is inactive.

We can think that the inactive selection style is another feature, so, different from normal selection. If the suggested trick is needed by web developers, I think there should be -moz-selection-disabled or something. If so, we can paint the disabled selection even on such pages.
I can't claim I understand the rationale for not preserving the -moz-selection style in inactive windows (somehow WebKit gets away with preserving it), but anyway another solution that would work for us is to combine -moz-selection and -moz-window-inactive as suggested in the link above:

::-moz-selection:-moz-window-inactive {
  background: rgba(255,0,0,0.3);
}
That won't help; the code that looks at the moz-selection value has no idea what selector was used to apply it.
Bummer. I guess we're stuck with gray-and-opaque then?
Well, we could add ::-moz-disabled-selection.
Summary: moz-selection is ignored in inactive windows → have a way to style the selection in inactive windows (apply ::-moz-selection or add similar but different way)
There is a related Firefox bug where the selection always appears inactive in an iframe that has been dynamically created by script, thus preventing any styling of the selection in such an iframe:

http://stackoverflow.com/questions/6730814/
This behavior becomes a real problem when you combine it with bug 554039.  That is, we could work around the inability to style the inactive window selection color by making that window active, but bug 554039 prevent that.

For more info see these discussions: 
    http://stackoverflow.com/questions/10502099
    http://stackoverflow.com/questions/10501381
(In reply to Boris Zbarsky (:bz) from comment #6)
> Well, we could add ::-moz-disabled-selection.

Should a separate bug be opened to implement ::-moz-disabled-selection?
Blocks: 815170
Blocks: 176170
See Also: → 1158204
Severity: normal → enhancement
OS: Mac OS X → All
Hardware: x86 → All
This is called ::inactive-selection in CSS pseudo-elements level 4: https://drafts.csswg.org/css-pseudo-4/#selectordef-inactive-selection

I'm guessing that it would be best to hide this being a pref rather than adding a new ::-moz-inactive-selection for consistency, yes? Can you think of a reason to avoid implementing this for now, pref or not?
Flags: needinfo?(bzbarsky)
That's a question for dbaron; I don't know how stable this spec draft is.
Flags: needinfo?(bzbarsky) → needinfo?(dbaron)
I'm not sure how stable the spec draft is, but the feature seems (assuming ::selection is complete!) relatively straightforward, so it seems reasonable to implement behind a pref.  Having an implementation also makes the feature more stable.
Flags: needinfo?(dbaron)
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.