1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 /* utility functions for drawing borders and backgrounds */
9 #ifndef nsCSSRendering_h___
10 #define nsCSSRendering_h___
13 #include "gfxContext.h"
14 #include "mozilla/gfx/PathHelpers.h"
15 #include "mozilla/gfx/Rect.h"
16 #include "mozilla/TypedEnumBits.h"
17 #include "nsStyleStruct.h"
19 #include "nsImageRenderer.h"
20 #include "nsCSSRenderingBorders.h"
21 #include "gfxTextRun.h"
37 class StackingContextHelper
;
38 class WebRenderParentCommand
;
39 class WebRenderLayerManager
;
40 class RenderRootStateManager
;
44 class DisplayListBuilder
;
47 enum class PaintBorderFlags
: uint8_t { SyncDecodeImages
= 1 << 0 };
48 MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(PaintBorderFlags
)
50 } // namespace mozilla
53 * A struct representing all the information needed to paint a background
54 * image to some target, taking into account all CSS background-* properties.
55 * See PrepareImageLayer.
57 struct nsBackgroundLayerState
{
58 typedef mozilla::gfx::CompositionOp CompositionOp
;
59 typedef mozilla::nsImageRenderer nsImageRenderer
;
62 * @param aFlags some combination of nsCSSRendering::PAINTBG_* flags
64 nsBackgroundLayerState(nsIFrame
* aForFrame
, const mozilla::StyleImage
* aImage
,
66 : mImageRenderer(aForFrame
, aImage
, aFlags
) {}
69 * The nsImageRenderer that will be used to draw the background.
71 nsImageRenderer mImageRenderer
;
73 * A rectangle that one copy of the image tile is mapped onto. Same
74 * coordinate system as aBorderArea/aBGClipRect passed into
79 * The actual rectangle that should be filled with (complete or partial)
80 * image tiles. Same coordinate system as aBorderArea/aBGClipRect passed into
85 * The anchor point that should be snapped to a pixel corner. Same
86 * coordinate system as aBorderArea/aBGClipRect passed into
91 * The background-repeat property space keyword computes the
92 * repeat size which is image size plus spacing.
97 struct nsCSSRendering
{
98 typedef mozilla::gfx::sRGBColor sRGBColor
;
99 typedef mozilla::gfx::CompositionOp CompositionOp
;
100 typedef mozilla::gfx::DrawTarget DrawTarget
;
101 typedef mozilla::gfx::Float Float
;
102 typedef mozilla::gfx::Point Point
;
103 typedef mozilla::gfx::Rect Rect
;
104 typedef mozilla::gfx::Size Size
;
105 typedef mozilla::gfx::RectCornerRadii RectCornerRadii
;
106 typedef mozilla::layers::WebRenderLayerManager WebRenderLayerManager
;
107 typedef mozilla::image::ImgDrawResult ImgDrawResult
;
108 typedef nsIFrame::Sides Sides
;
111 * Initialize any static variables used by nsCSSRendering.
116 * Clean up any static variables used by nsCSSRendering.
118 static void Shutdown();
120 static bool IsBoxDecorationSlice(const nsStyleBorder
& aStyleBorder
);
121 static nsRect
BoxDecorationRectForBorder(
122 nsIFrame
* aFrame
, const nsRect
& aBorderArea
, Sides aSkipSides
,
123 const nsStyleBorder
* aStyleBorder
= nullptr);
124 static nsRect
BoxDecorationRectForBackground(
125 nsIFrame
* aFrame
, const nsRect
& aBorderArea
, Sides aSkipSides
,
126 const nsStyleBorder
* aStyleBorder
= nullptr);
128 static bool GetShadowInnerRadii(nsIFrame
* aFrame
, const nsRect
& aFrameArea
,
129 RectCornerRadii
& aOutInnerRadii
);
130 static nsRect
GetBoxShadowInnerPaddingRect(nsIFrame
* aFrame
,
131 const nsRect
& aFrameArea
);
132 static bool ShouldPaintBoxShadowInner(nsIFrame
* aFrame
);
133 static void PaintBoxShadowInner(nsPresContext
* aPresContext
,
134 gfxContext
& aRenderingContext
,
136 const nsRect
& aFrameArea
);
138 static bool GetBorderRadii(const nsRect
& aFrameRect
,
139 const nsRect
& aBorderRect
, nsIFrame
* aFrame
,
140 RectCornerRadii
& aOutRadii
);
141 static nsRect
GetShadowRect(const nsRect
& aFrameArea
, bool aNativeTheme
,
142 nsIFrame
* aForFrame
);
143 static mozilla::gfx::sRGBColor
GetShadowColor(
144 const mozilla::StyleSimpleShadow
&, nsIFrame
* aFrame
, float aOpacity
);
145 // Returns if the frame has a themed frame.
146 // aMaybeHasBorderRadius will return false if we can early detect
147 // that we don't have a border radius.
148 static bool HasBoxShadowNativeTheme(nsIFrame
* aFrame
,
149 bool& aMaybeHasBorderRadius
);
150 static void PaintBoxShadowOuter(nsPresContext
* aPresContext
,
151 gfxContext
& aRenderingContext
,
152 nsIFrame
* aForFrame
, const nsRect
& aFrameArea
,
153 const nsRect
& aDirtyRect
,
154 float aOpacity
= 1.0);
156 static void ComputePixelRadii(const nscoord
* aAppUnitsRadii
,
157 nscoord aAppUnitsPerPixel
,
158 RectCornerRadii
* oBorderRadii
);
161 * Render the border for an element using css rendering rules
162 * for borders. aSkipSides says which sides to skip
163 * when rendering, the default is to skip none.
165 static ImgDrawResult
PaintBorder(
166 nsPresContext
* aPresContext
, gfxContext
& aRenderingContext
,
167 nsIFrame
* aForFrame
, const nsRect
& aDirtyRect
, const nsRect
& aBorderArea
,
168 mozilla::ComputedStyle
* aStyle
, mozilla::PaintBorderFlags aFlags
,
169 Sides aSkipSides
= Sides());
172 * Like PaintBorder, but taking an nsStyleBorder argument instead of
173 * getting it from aStyle. aSkipSides says which sides to skip
174 * when rendering, the default is to skip none.
176 static ImgDrawResult
PaintBorderWithStyleBorder(
177 nsPresContext
* aPresContext
, gfxContext
& aRenderingContext
,
178 nsIFrame
* aForFrame
, const nsRect
& aDirtyRect
, const nsRect
& aBorderArea
,
179 const nsStyleBorder
& aBorderStyle
, mozilla::ComputedStyle
* aStyle
,
180 mozilla::PaintBorderFlags aFlags
, Sides aSkipSides
= Sides());
182 static mozilla::Maybe
<nsCSSBorderRenderer
> CreateBorderRenderer(
183 nsPresContext
* aPresContext
, DrawTarget
* aDrawTarget
, nsIFrame
* aForFrame
,
184 const nsRect
& aDirtyRect
, const nsRect
& aBorderArea
,
185 mozilla::ComputedStyle
* aStyle
, bool* aOutBorderIsEmpty
,
186 Sides aSkipSides
= Sides());
188 static mozilla::Maybe
<nsCSSBorderRenderer
>
189 CreateBorderRendererWithStyleBorder(
190 nsPresContext
* aPresContext
, DrawTarget
* aDrawTarget
, nsIFrame
* aForFrame
,
191 const nsRect
& aDirtyRect
, const nsRect
& aBorderArea
,
192 const nsStyleBorder
& aBorderStyle
, mozilla::ComputedStyle
* aStyle
,
193 bool* aOutBorderIsEmpty
, Sides aSkipSides
= Sides());
195 static mozilla::Maybe
<nsCSSBorderRenderer
>
196 CreateNullBorderRendererWithStyleBorder(
197 nsPresContext
* aPresContext
, DrawTarget
* aDrawTarget
, nsIFrame
* aForFrame
,
198 const nsRect
& aDirtyRect
, const nsRect
& aBorderArea
,
199 const nsStyleBorder
& aBorderStyle
, mozilla::ComputedStyle
* aStyle
,
200 bool* aOutBorderIsEmpty
, Sides aSkipSides
= Sides());
202 static mozilla::Maybe
<nsCSSBorderRenderer
>
203 CreateBorderRendererForNonThemedOutline(nsPresContext
* aPresContext
,
204 DrawTarget
* aDrawTarget
,
206 const nsRect
& aDirtyRect
,
207 const nsRect
& aInnerRect
,
208 mozilla::ComputedStyle
* aStyle
);
210 static ImgDrawResult
CreateWebRenderCommandsForBorder(
211 mozilla::nsDisplayItem
* aItem
, nsIFrame
* aForFrame
,
212 const nsRect
& aBorderArea
, mozilla::wr::DisplayListBuilder
& aBuilder
,
213 mozilla::wr::IpcResourceUpdateQueue
& aResources
,
214 const mozilla::layers::StackingContextHelper
& aSc
,
215 mozilla::layers::RenderRootStateManager
* aManager
,
216 mozilla::nsDisplayListBuilder
* aDisplayListBuilder
);
218 static void CreateWebRenderCommandsForNullBorder(
219 mozilla::nsDisplayItem
* aItem
, nsIFrame
* aForFrame
,
220 const nsRect
& aBorderArea
, mozilla::wr::DisplayListBuilder
& aBuilder
,
221 mozilla::wr::IpcResourceUpdateQueue
& aResources
,
222 const mozilla::layers::StackingContextHelper
& aSc
,
223 const nsStyleBorder
& aStyleBorder
);
225 static ImgDrawResult
CreateWebRenderCommandsForBorderWithStyleBorder(
226 mozilla::nsDisplayItem
* aItem
, nsIFrame
* aForFrame
,
227 const nsRect
& aBorderArea
, mozilla::wr::DisplayListBuilder
& aBuilder
,
228 mozilla::wr::IpcResourceUpdateQueue
& aResources
,
229 const mozilla::layers::StackingContextHelper
& aSc
,
230 mozilla::layers::RenderRootStateManager
* aManager
,
231 mozilla::nsDisplayListBuilder
* aDisplayListBuilder
,
232 const nsStyleBorder
& aStyleBorder
);
235 * Render the outline for an element using css rendering rules for borders.
237 static void PaintNonThemedOutline(nsPresContext
* aPresContext
,
238 gfxContext
& aRenderingContext
,
240 const nsRect
& aDirtyRect
,
241 const nsRect
& aInnerRect
,
242 mozilla::ComputedStyle
* aStyle
);
245 * Render keyboard focus on an element.
246 * |aFocusRect| is the outer rectangle of the focused element.
247 * Uses a fixed style equivalent to "1px dotted |aColor|".
248 * Not used for controls, because the native theme may differ.
250 static void PaintFocus(nsPresContext
* aPresContext
, DrawTarget
* aDrawTarget
,
251 const nsRect
& aFocusRect
, nscolor aColor
);
254 * Render a gradient for an element.
255 * aDest is the rect for a single tile of the gradient on the destination.
256 * aFill is the rect on the destination to be covered by repeated tiling of
258 * aSrc is the part of the gradient to be rendered into a tile (aDest), if
259 * aSrc and aDest are different sizes, the image will be scaled to map aSrc
261 * aIntrinsicSize is the size of the source gradient.
263 static void PaintGradient(nsPresContext
* aPresContext
, gfxContext
& aContext
,
264 const mozilla::StyleGradient
& aGradient
,
265 const nsRect
& aDirtyRect
, const nsRect
& aDest
,
266 const nsRect
& aFill
, const nsSize
& aRepeatSize
,
267 const mozilla::CSSIntRect
& aSrc
,
268 const nsSize
& aIntrinsiceSize
,
269 float aOpacity
= 1.0);
272 * Find the frame whose background style should be used to draw the
273 * canvas background. aForFrame must be the frame for the root element
274 * whose background style should be used. This function will return
275 * aForFrame unless the <body> background should be propagated, in
276 * which case we return the frame associated with the <body>'s background.
278 static nsIFrame
* FindBackgroundStyleFrame(nsIFrame
* aForFrame
);
281 * Returns the ComputedStyle to be used to paint the background for the given
282 * frame, if its element has a meaningful background. This applies the rules
283 * for propagating backgrounds between BODY, the root element, and the
286 * @return the ComputedStyle (if any) to be used for painting aForFrame's
289 static mozilla::ComputedStyle
* FindBackground(const nsIFrame
* aForFrame
);
290 static nsIFrame
* FindBackgroundFrame(const nsIFrame
* aForFrame
);
293 * As FindBackground, but the passed-in frame is known to be a root frame
294 * (returned from nsCSSFrameConstructor::GetRootElementStyleFrame())
295 * and there is always some meaningful background returned.
297 static mozilla::ComputedStyle
* FindRootFrameBackground(nsIFrame
* aForFrame
);
300 * Find a non-transparent background color on an ancestor, for various
301 * contrast checks. Note that this only accounts for background-color and
302 * might stop at themed frames (depending on the argument), so it might not be
303 * what you want. Note that if we stop at themed frames we might, in fact, end
304 * up returning a transparent color (but then mIsThemed will be set to true).
306 * For semi-transparent colors, right now we blend with the default
307 * background-color rather than with all ancestor backgrounds.
309 * If aPreferBodyToCanvas is true, we prefer the background color of the
310 * <body> frame, even though we found a canvas background, because the body
311 * background color is most likely what will be visible as the background
312 * color of the page, even if the html element has a different background
313 * color which prevents that of the body frame to propagate to the viewport.
315 struct EffectiveBackgroundColor
{
317 bool mIsThemed
= false;
319 static EffectiveBackgroundColor
FindEffectiveBackgroundColor(
320 nsIFrame
* aFrame
, bool aStopAtThemed
= true,
321 bool aPreferBodyToCanvas
= false);
324 * Determine the background color to draw taking into account print settings.
326 static nscolor
DetermineBackgroundColor(nsPresContext
* aPresContext
,
327 const mozilla::ComputedStyle
* aStyle
,
329 bool& aDrawBackgroundImage
,
330 bool& aDrawBackgroundColor
);
332 static nsRect
ComputeImageLayerPositioningArea(
333 nsPresContext
* aPresContext
, nsIFrame
* aForFrame
,
334 const nsRect
& aBorderArea
, const nsStyleImageLayers::Layer
& aLayer
,
335 nsIFrame
** aAttachedToFrame
, bool* aOutTransformedFixed
);
337 // Implementation of the formula for computation of background-repeat round
338 // See http://dev.w3.org/csswg/css3-background/#the-background-size
339 // This function returns the adjusted size of the background image.
340 static nscoord
ComputeRoundedSize(nscoord aCurrentSize
,
341 nscoord aPositioningSize
);
343 /* ComputeBorderSpacedRepeatSize
344 * aImageDimension: the image width/height
345 * aAvailableSpace: the background positioning area width/height
346 * aSpace: the space between each image
347 * Returns the image size plus gap size of app units for use as spacing
349 static nscoord
ComputeBorderSpacedRepeatSize(nscoord aImageDimension
,
350 nscoord aAvailableSpace
,
353 static nsBackgroundLayerState
PrepareImageLayer(
354 nsPresContext
* aPresContext
, nsIFrame
* aForFrame
, uint32_t aFlags
,
355 const nsRect
& aBorderArea
, const nsRect
& aBGClipRect
,
356 const nsStyleImageLayers::Layer
& aLayer
,
357 bool* aOutIsTransformedFixed
= nullptr);
359 struct ImageLayerClipState
{
360 nsRect mBGClipArea
; // Affected by mClippedRadii
361 nsRect mAdditionalBGClipArea
; // Not affected by mClippedRadii
362 nsRect mDirtyRectInAppUnits
;
363 gfxRect mDirtyRectInDevPx
;
366 RectCornerRadii mClippedRadii
;
367 bool mHasRoundedCorners
;
368 bool mHasAdditionalBGClipArea
;
370 // Whether we are being asked to draw with a caller provided background
371 // clipping area. If this is true we also disable rounded corners.
374 ImageLayerClipState()
375 : mHasRoundedCorners(false),
376 mHasAdditionalBGClipArea(false),
378 memset(mRadii
, 0, sizeof(nscoord
) * 8);
381 bool IsValid() const;
384 static void GetImageLayerClip(const nsStyleImageLayers::Layer
& aLayer
,
386 const nsStyleBorder
& aBorder
,
387 const nsRect
& aBorderArea
,
388 const nsRect
& aCallerDirtyRect
,
389 bool aWillPaintBorder
,
390 nscoord aAppUnitsPerPixel
,
391 /* out */ ImageLayerClipState
* aClipState
);
394 * Render the background for an element using css rendering rules
395 * for backgrounds or mask.
399 * When this flag is passed, the element's nsDisplayBorder will be
400 * painted immediately on top of this background.
402 PAINTBG_WILL_PAINT_BORDER
= 0x01,
404 * When this flag is passed, images are synchronously decoded.
406 PAINTBG_SYNC_DECODE_IMAGES
= 0x02,
408 * When this flag is passed, painting will go to the screen so we can
409 * take advantage of the fact that it will be clipped to the viewport.
411 PAINTBG_TO_WINDOW
= 0x04,
413 * When this flag is passed, painting will read properties of mask-image
414 * style, instead of background-image.
416 PAINTBG_MASK_IMAGE
= 0x08,
418 * When this flag is passed, images are downscaled during decode. This
419 * is also implied by PAINTBG_TO_WINDOW.
421 PAINTBG_HIGH_QUALITY_SCALING
= 0x10,
424 struct PaintBGParams
{
425 nsPresContext
& presCtx
;
430 nsRect
* bgClipRect
= nullptr;
431 int32_t layer
; // -1 means painting all layers; other
432 // value means painting one specific
434 CompositionOp compositionOp
;
437 static PaintBGParams
ForAllLayers(nsPresContext
& aPresCtx
,
438 const nsRect
& aDirtyRect
,
439 const nsRect
& aBorderArea
,
440 nsIFrame
* aFrame
, uint32_t aPaintFlags
,
441 float aOpacity
= 1.0);
442 static PaintBGParams
ForSingleLayer(
443 nsPresContext
& aPresCtx
, const nsRect
& aDirtyRect
,
444 const nsRect
& aBorderArea
, nsIFrame
* aFrame
, uint32_t aPaintFlags
,
445 int32_t aLayer
, CompositionOp aCompositionOp
= CompositionOp::OP_OVER
,
446 float aOpacity
= 1.0);
449 PaintBGParams(nsPresContext
& aPresCtx
, const nsRect
& aDirtyRect
,
450 const nsRect
& aBorderArea
, nsIFrame
* aFrame
,
451 uint32_t aPaintFlags
, int32_t aLayer
,
452 CompositionOp aCompositionOp
, float aOpacity
)
454 dirtyRect(aDirtyRect
),
455 borderArea(aBorderArea
),
457 paintFlags(aPaintFlags
),
459 compositionOp(aCompositionOp
),
463 static ImgDrawResult
PaintStyleImageLayer(const PaintBGParams
& aParams
,
464 gfxContext
& aRenderingCtx
);
467 * Same as |PaintStyleImageLayer|, except using the provided style structs.
468 * This short-circuits the code that ensures that the root element's
469 * {background|mask} is drawn on the canvas.
470 * The aLayer parameter allows you to paint a single layer of the
472 * The default value for aLayer, -1, means that all layers will be painted.
473 * The background color will only be painted if the back-most layer is also
474 * being painted and (aParams.paintFlags & PAINTBG_MASK_IMAGE) is false.
475 * aCompositionOp is only respected if a single layer is specified (aLayer !=
476 * -1). If all layers are painted, the image layer's blend mode (or the mask
477 * layer's composition mode) will be used.
479 static ImgDrawResult
PaintStyleImageLayerWithSC(
480 const PaintBGParams
& aParams
, gfxContext
& aRenderingCtx
,
481 const mozilla::ComputedStyle
* aBackgroundSC
,
482 const nsStyleBorder
& aBorder
);
484 static bool CanBuildWebRenderDisplayItemsForStyleImageLayer(
485 WebRenderLayerManager
* aManager
, nsPresContext
& aPresCtx
,
486 nsIFrame
* aFrame
, const nsStyleBackground
* aBackgroundStyle
,
487 int32_t aLayer
, uint32_t aPaintFlags
);
488 static ImgDrawResult
BuildWebRenderDisplayItemsForStyleImageLayer(
489 const PaintBGParams
& aParams
, mozilla::wr::DisplayListBuilder
& aBuilder
,
490 mozilla::wr::IpcResourceUpdateQueue
& aResources
,
491 const mozilla::layers::StackingContextHelper
& aSc
,
492 mozilla::layers::RenderRootStateManager
* aManager
,
493 mozilla::nsDisplayItem
* aItem
);
495 static ImgDrawResult
BuildWebRenderDisplayItemsForStyleImageLayerWithSC(
496 const PaintBGParams
& aParams
, mozilla::wr::DisplayListBuilder
& aBuilder
,
497 mozilla::wr::IpcResourceUpdateQueue
& aResources
,
498 const mozilla::layers::StackingContextHelper
& aSc
,
499 mozilla::layers::RenderRootStateManager
* aManager
,
500 mozilla::nsDisplayItem
* aItem
, mozilla::ComputedStyle
* mBackgroundSC
,
501 const nsStyleBorder
& aBorder
);
504 * Returns the rectangle covered by the given background layer image, taking
505 * into account background positioning, sizing, and repetition, but not
508 static nsRect
GetBackgroundLayerRect(nsPresContext
* aPresContext
,
510 const nsRect
& aBorderArea
,
511 const nsRect
& aClipRect
,
512 const nsStyleImageLayers::Layer
& aLayer
,
516 * Called when we start creating a display list. The frame tree will not
517 * change until a matching EndFrameTreeLocked is called.
519 static void BeginFrameTreesLocked();
521 * Called when we've finished using a display list. When all
522 * BeginFrameTreeLocked calls have been balanced by an EndFrameTreeLocked,
523 * the frame tree may start changing again.
525 static void EndFrameTreesLocked();
527 // Draw a border segment in the table collapsing border model with beveling
529 static void DrawTableBorderSegment(
530 DrawTarget
& aDrawTarget
, mozilla::StyleBorderStyle aBorderStyle
,
531 nscolor aBorderColor
, const nsRect
& aBorderRect
,
532 int32_t aAppUnitsPerDevPixel
, mozilla::Side aStartBevelSide
,
533 nscoord aStartBevelOffset
, mozilla::Side aEndBevelSide
,
534 nscoord aEndBevelOffset
);
536 // A single border bevel.
542 // A single solid beveled border segment.
543 struct SolidBeveledBorderSegment
{
550 // Collect the table border segments with beveling. Can't be called with
551 // dashed / dotted borders, since we don't support beveling those.
552 static void GetTableBorderSolidSegments(
553 nsTArray
<SolidBeveledBorderSegment
>& aSegments
,
554 mozilla::StyleBorderStyle aBorderStyle
, nscolor aBorderColor
,
555 const nsRect
& aBorderRect
, int32_t aAppUnitsPerDevPixel
,
556 mozilla::Side aStartBevelSide
, nscoord aStartBevelOffset
,
557 mozilla::Side aEndBevelSide
, nscoord aEndBevelOffset
);
559 // NOTE: pt, dirtyRect, lineSize, ascent, offset in the following
560 // structs are non-rounded device pixels, not app units.
561 struct DecorationRectParams
{
562 // The width [length] and the height [thickness] of the decoration
563 // line. This is a "logical" size in textRun orientation, so that
564 // for a vertical textrun, width will actually be a physical height;
565 // and conversely, height will be a physical width.
567 // The default height [thickness] of the line given by the font metrics.
568 // This is used for obtaining the correct offset for the decoration line
569 // when CSS specifies a unique thickness for a text-decoration,
570 // since the offset given by the font is derived from the font metric's
571 // assumed line height
572 Float defaultLineThickness
= 0.0f
;
573 // The ascent of the text.
575 // The offset of the decoration line from the baseline of the text
576 // (if the value is positive, the line is lifted up).
578 // If descentLimit is zero or larger and the underline overflows
579 // from the descent space, the underline should be lifted up as far
580 // as possible. Note that this does not mean the underline never
581 // overflows from this limitation, because if the underline is
582 // positioned to the baseline or upper, it causes unreadability.
583 // Note that if this is zero or larger, the underline rect may be
584 // shrunken if it's possible. Therefore, this value is used for
585 // strikeout line and overline too.
586 Float descentLimit
= -1.0f
;
587 // Which line will be painted. The value can be
588 // UNDERLINE or OVERLINE or LINE_THROUGH.
589 mozilla::StyleTextDecorationLine decoration
=
590 mozilla::StyleTextDecorationLine::UNDERLINE
;
591 // The style of the decoration line
592 mozilla::StyleTextDecorationStyle style
=
593 mozilla::StyleTextDecorationStyle::None
;
594 bool vertical
= false;
595 bool sidewaysLeft
= false;
596 gfxTextRun::Range glyphRange
;
597 gfxTextRun::PropertyProvider
* provider
;
600 struct PaintDecorationLineParams
: DecorationRectParams
{
601 // No need to paint outside this rect.
603 // The top/left edge of the text.
605 // The color of the decoration line.
606 nscolor color
= NS_RGBA(0, 0, 0, 0);
607 // The distance between the left edge of the given frame and the
608 // position of the text as positioned without offset of the shadow.
609 Float icoordInFrame
= 0.0f
;
610 // Baseline offset being applied to this text (block-direction adjustment
611 // applied to glyph positions when computing skip-ink intercepts).
612 Float baselineOffset
= 0.0f
;
616 * Function for painting the clipped decoration lines for the text.
617 * Takes into account the rect clipping that occurs when
618 * text-decoration-skip-ink is being used for underlines or overlines
621 * @param aFrame the frame which needs the decoration line
622 * @param aDrawTarget the target/backend being drawn to
623 * @param aParams the parameters for the decoration line
625 * @param aRect the rect representing the decoration line
627 static void PaintDecorationLineInternal(
628 nsIFrame
* aFrame
, DrawTarget
& aDrawTarget
,
629 const PaintDecorationLineParams
& aParams
, Rect aRect
);
632 * Function for painting the decoration lines for the text.
635 * @param aFrame the frame which needs the decoration line
636 * @param aDrawTarget the target/backend being drawn to
637 * @param aParams the parameters for the decoration line
640 static void PaintDecorationLine(nsIFrame
* aFrame
, DrawTarget
& aDrawTarget
,
641 const PaintDecorationLineParams
& aParams
);
644 * Returns a Rect corresponding to the outline of the decoration line for the
645 * given text metrics. Arguments have the same meaning as for
646 * PaintDecorationLine. Currently this only works for solid
647 * decorations; for other decoration styles the returned Rect will be empty.
649 static Rect
DecorationLineToPath(const PaintDecorationLineParams
& aParams
);
652 * Function for getting the decoration line rect for the text.
653 * NOTE: aLineSize, aAscent and aOffset are non-rounded device pixels,
656 * @param aPresContext
658 * @return the decoration line rect for the input,
659 * the each values are app units.
661 static nsRect
GetTextDecorationRect(nsPresContext
* aPresContext
,
662 const DecorationRectParams
& aParams
);
664 static CompositionOp
GetGFXBlendMode(mozilla::StyleBlend aBlendMode
) {
665 switch (aBlendMode
) {
666 case mozilla::StyleBlend::Normal
:
667 return CompositionOp::OP_OVER
;
668 case mozilla::StyleBlend::Multiply
:
669 return CompositionOp::OP_MULTIPLY
;
670 case mozilla::StyleBlend::Screen
:
671 return CompositionOp::OP_SCREEN
;
672 case mozilla::StyleBlend::Overlay
:
673 return CompositionOp::OP_OVERLAY
;
674 case mozilla::StyleBlend::Darken
:
675 return CompositionOp::OP_DARKEN
;
676 case mozilla::StyleBlend::Lighten
:
677 return CompositionOp::OP_LIGHTEN
;
678 case mozilla::StyleBlend::ColorDodge
:
679 return CompositionOp::OP_COLOR_DODGE
;
680 case mozilla::StyleBlend::ColorBurn
:
681 return CompositionOp::OP_COLOR_BURN
;
682 case mozilla::StyleBlend::HardLight
:
683 return CompositionOp::OP_HARD_LIGHT
;
684 case mozilla::StyleBlend::SoftLight
:
685 return CompositionOp::OP_SOFT_LIGHT
;
686 case mozilla::StyleBlend::Difference
:
687 return CompositionOp::OP_DIFFERENCE
;
688 case mozilla::StyleBlend::Exclusion
:
689 return CompositionOp::OP_EXCLUSION
;
690 case mozilla::StyleBlend::Hue
:
691 return CompositionOp::OP_HUE
;
692 case mozilla::StyleBlend::Saturation
:
693 return CompositionOp::OP_SATURATION
;
694 case mozilla::StyleBlend::Color
:
695 return CompositionOp::OP_COLOR
;
696 case mozilla::StyleBlend::Luminosity
:
697 return CompositionOp::OP_LUMINOSITY
;
698 case mozilla::StyleBlend::PlusLighter
:
699 return CompositionOp::OP_ADD
;
702 return CompositionOp::OP_OVER
;
706 static CompositionOp
GetGFXCompositeMode(
707 mozilla::StyleMaskComposite aCompositeMode
) {
708 switch (aCompositeMode
) {
709 case mozilla::StyleMaskComposite::Add
:
710 return CompositionOp::OP_OVER
;
711 case mozilla::StyleMaskComposite::Subtract
:
712 return CompositionOp::OP_OUT
;
713 case mozilla::StyleMaskComposite::Intersect
:
714 return CompositionOp::OP_IN
;
715 case mozilla::StyleMaskComposite::Exclude
:
716 return CompositionOp::OP_XOR
;
719 return CompositionOp::OP_OVER
;
724 static gfxRect
GetTextDecorationRectInternal(
725 const Point
& aPt
, const DecorationRectParams
& aParams
);
728 * Returns inflated rect for painting a decoration line.
729 * Complex style decoration lines should be painted from leftmost of nearest
730 * ancestor block box because that makes better look of connection of lines
731 * for different nodes. ExpandPaintingRectForDecorationLine() returns
732 * a rect for actual painting rect for the clipped rect.
735 * @param aFrame the frame which needs the decoration line.
736 * @param aStyle the style of the complex decoration line
737 * @param aClippedRect the clipped rect for the decoration line.
738 * in other words, visible area of the line.
739 * @param aICoordInFrame the distance between inline-start edge of aFrame
740 * and aClippedRect.pos.
741 * @param aCycleLength the width of one cycle of the line style.
743 static Rect
ExpandPaintingRectForDecorationLine(
744 nsIFrame
* aFrame
, const mozilla::StyleTextDecorationStyle aStyle
,
745 const Rect
& aClippedRect
, const Float aICoordInFrame
,
746 const Float aCycleLength
, bool aVertical
);
751 * Creates an 8-bit alpha channel context for callers to draw in, blurs the
752 * contents of that context and applies it as a 1-color mask on a
753 * different existing context. Uses gfxAlphaBoxBlur as its back end.
755 * You must call Init() first to create a suitable temporary surface to draw
756 * on. You must then draw any desired content onto the given context, then
757 * call DoPaint() to apply the blurred content as a single-color mask. You
758 * can only call Init() once, so objects cannot be reused.
760 * This is very useful for creating drop shadows or silhouettes.
762 class nsContextBoxBlur
{
763 typedef mozilla::gfx::sRGBColor sRGBColor
;
764 typedef mozilla::gfx::DrawTarget DrawTarget
;
765 typedef mozilla::gfx::RectCornerRadii RectCornerRadii
;
768 enum { FORCE_MASK
= 0x01, DISABLE_HARDWARE_ACCELERATION_BLUR
= 0x02 };
770 * Prepares a gfxContext to draw on. Do not call this twice; if you want
771 * to get the gfxContext again use GetContext().
773 * @param aRect The coordinates of the surface to create.
774 * All coordinates must be in app units.
775 * This must not include the blur radius, pass
776 * it as the second parameter and everything
779 * @param aBlurRadius The blur radius in app units.
781 * @param aAppUnitsPerDevPixel The number of app units in a device pixel,
782 * for conversion. Most of the time you'll
783 * pass this from the current PresContext if
786 * @param aDestinationCtx The graphics context to apply the blurred
787 * mask to when you call DoPaint(). Make sure
788 * it is not destroyed before you call
789 * DoPaint(). To set the color of the
790 * resulting blurred graphic mask, you must
791 * set the color on this context before
794 * @param aDirtyRect The absolute dirty rect in app units. Used to
795 * optimize the temporary surface size and speed
798 * @param aSkipRect An area in device pixels (NOT app units!) to
799 * avoid blurring over, to prevent unnecessary work.
801 * @param aFlags FORCE_MASK to ensure that the content drawn to
802 * the returned gfxContext is used as a mask, and not drawn directly to
805 * @return A blank 8-bit alpha-channel-only graphics context to
806 * draw on, or null on error. Must not be freed. The
807 * context has a device offset applied to it given by
808 * aRect. This means you can use coordinates as if it
809 * were at the desired position at aRect and you don't
810 * need to worry about translating any coordinates to
811 * draw on this temporary surface.
813 * If aBlurRadius is 0, the returned context is aDestinationCtx and
814 * DoPaint() does nothing, because no blurring is required. Therefore, you
815 * should prepare the destination context as if you were going to draw
816 * directly on it instead of any temporary surface created in this class.
818 gfxContext
* Init(const nsRect
& aRect
, nscoord aSpreadRadius
,
819 nscoord aBlurRadius
, int32_t aAppUnitsPerDevPixel
,
820 gfxContext
* aDestinationCtx
, const nsRect
& aDirtyRect
,
821 const gfxRect
* aSkipRect
, uint32_t aFlags
= 0);
824 * Does the actual blurring and mask applying. Users of this object *must*
825 * have called Init() first, then have drawn whatever they want to be
826 * blurred onto the internal gfxContext before calling this.
831 * Gets the internal gfxContext at any time. Must not be freed. Avoid
832 * calling this before calling Init() since the context would not be
833 * constructed at that point.
835 gfxContext
* GetContext();
838 * Get the margin associated with the given blur radius, i.e., the
839 * additional area that might be painted as a result of it. (The
840 * margin for a spread radius is itself, on all sides.)
842 static nsMargin
GetBlurRadiusMargin(nscoord aBlurRadius
,
843 int32_t aAppUnitsPerDevPixel
);
846 * Blurs a coloured rectangle onto aDestinationCtx. This is equivalent
847 * to calling Init(), drawing a rectangle onto the returned surface
848 * and then calling DoPaint, but may let us optimize better in the
851 * @param aDestinationCtx The destination to blur to.
852 * @param aRect The rectangle to blur in app units.
853 * @param aAppUnitsPerDevPixel The number of app units in a device pixel,
854 * for conversion. Most of the time you'll
855 * pass this from the current PresContext if
857 * @param aCornerRadii Corner radii for aRect, if it is a rounded
859 * @param aBlurRadius The blur radius in app units.
860 * @param aShadowColor The color to draw the blurred shadow.
861 * @param aDirtyRect The absolute dirty rect in app units. Used to
862 * optimize the temporary surface size and speed
864 * @param aSkipRect An area in device pixels (NOT app units!) to
865 * avoid blurring over, to prevent unnecessary work.
867 static void BlurRectangle(gfxContext
* aDestinationCtx
, const nsRect
& aRect
,
868 int32_t aAppUnitsPerDevPixel
,
869 RectCornerRadii
* aCornerRadii
, nscoord aBlurRadius
,
870 const sRGBColor
& aShadowColor
,
871 const nsRect
& aDirtyRect
, const gfxRect
& aSkipRect
);
874 * Draws a blurred inset box shadow shape onto the destination surface.
875 * Like BlurRectangle, this is equivalent to calling Init(),
876 * drawing a rectangle onto the returned surface
877 * and then calling DoPaint, but may let us optimize better in the
880 * @param aDestinationCtx The destination to blur to.
881 * @param aDestinationRect The rectangle to blur in app units.
882 * @param aShadowClipRect The inside clip rect that creates the path.
883 * @param aShadowColor The color of the blur
884 * @param aBlurRadiusAppUnits The blur radius in app units
885 * @param aSpreadRadiusAppUnits The spread radius in app units.
886 * @param aAppUnitsPerDevPixel The number of app units in a device pixel,
887 * for conversion. Most of the time you'll
888 * pass this from the current PresContext if
890 * @param aHasBorderRadius If this inset box blur has a border radius
891 * @param aInnerClipRectRadii The clip rect radii used for the inside rect's
893 * @param aSkipRect An area in device pixels (NOT app units!) to
894 * avoid blurring over, to prevent unnecessary work.
896 bool InsetBoxBlur(gfxContext
* aDestinationCtx
,
897 mozilla::gfx::Rect aDestinationRect
,
898 mozilla::gfx::Rect aShadowClipRect
,
899 mozilla::gfx::sRGBColor
& aShadowColor
,
900 nscoord aBlurRadiusAppUnits
, nscoord aSpreadRadiusAppUnits
,
901 int32_t aAppUnitsPerDevPixel
, bool aHasBorderRadius
,
902 RectCornerRadii
& aInnerClipRectRadii
,
903 mozilla::gfx::Rect aSkipRect
,
904 mozilla::gfx::Point aShadowOffset
);
907 static void GetBlurAndSpreadRadius(DrawTarget
* aDestDrawTarget
,
908 int32_t aAppUnitsPerDevPixel
,
909 nscoord aBlurRadius
, nscoord aSpreadRadius
,
910 mozilla::gfx::IntSize
& aOutBlurRadius
,
911 mozilla::gfx::IntSize
& aOutSpreadRadius
,
912 bool aConstrainSpreadRadius
= true);
914 gfxAlphaBoxBlur mAlphaBoxBlur
;
915 mozilla::UniquePtr
<gfxContext
> mOwnedContext
;
916 gfxContext
* mContext
; // may be either mOwnedContext or mDestinationContext
917 gfxContext
* mDestinationCtx
;
919 /* This is true if the blur already has it's content transformed
920 * by mDestinationCtx's transform */
921 bool mPreTransformed
;
924 #endif /* nsCSSRendering_h___ */