layout/base/nsCSSRendering.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 /* utility functions for drawing borders and backgrounds */
michael@0 7
michael@0 8 #ifndef nsCSSRendering_h___
michael@0 9 #define nsCSSRendering_h___
michael@0 10
michael@0 11 #include "gfxBlur.h"
michael@0 12 #include "gfxContext.h"
michael@0 13 #include "nsLayoutUtils.h"
michael@0 14 #include "nsStyleStruct.h"
michael@0 15 #include "nsIFrame.h"
michael@0 16
michael@0 17 class nsStyleContext;
michael@0 18 class nsPresContext;
michael@0 19 class nsRenderingContext;
michael@0 20
michael@0 21 namespace mozilla {
michael@0 22
michael@0 23 namespace layers {
michael@0 24 class ImageContainer;
michael@0 25 }
michael@0 26
michael@0 27 // A CSSSizeOrRatio represents a (possibly partially specified) size for use
michael@0 28 // in computing image sizes. Either or both of the width and height might be
michael@0 29 // given. A ratio of width to height may also be given. If we at least two
michael@0 30 // of these then we can compute a concrete size, that is a width and height.
michael@0 31 struct CSSSizeOrRatio
michael@0 32 {
michael@0 33 CSSSizeOrRatio()
michael@0 34 : mRatio(0, 0)
michael@0 35 , mHasWidth(false)
michael@0 36 , mHasHeight(false) {}
michael@0 37
michael@0 38 bool CanComputeConcreteSize() const
michael@0 39 {
michael@0 40 return mHasWidth + mHasHeight + HasRatio() >= 2;
michael@0 41 }
michael@0 42 bool IsConcrete() const { return mHasWidth && mHasHeight; }
michael@0 43 bool HasRatio() const { return mRatio.width > 0 && mRatio.height > 0; }
michael@0 44 bool IsEmpty() const
michael@0 45 {
michael@0 46 return (mHasWidth && mWidth <= 0) ||
michael@0 47 (mHasHeight && mHeight <= 0) ||
michael@0 48 mRatio.width <= 0 || mRatio.height <= 0;
michael@0 49 }
michael@0 50
michael@0 51 // CanComputeConcreteSize must return true when ComputeConcreteSize is
michael@0 52 // called.
michael@0 53 nsSize ComputeConcreteSize() const;
michael@0 54
michael@0 55 void SetWidth(nscoord aWidth)
michael@0 56 {
michael@0 57 mWidth = aWidth;
michael@0 58 mHasWidth = true;
michael@0 59 if (mHasHeight) {
michael@0 60 mRatio = nsSize(mWidth, mHeight);
michael@0 61 }
michael@0 62 }
michael@0 63 void SetHeight(nscoord aHeight)
michael@0 64 {
michael@0 65 mHeight = aHeight;
michael@0 66 mHasHeight = true;
michael@0 67 if (mHasWidth) {
michael@0 68 mRatio = nsSize(mWidth, mHeight);
michael@0 69 }
michael@0 70 }
michael@0 71 void SetSize(const nsSize& aSize)
michael@0 72 {
michael@0 73 mWidth = aSize.width;
michael@0 74 mHeight = aSize.height;
michael@0 75 mHasWidth = true;
michael@0 76 mHasHeight = true;
michael@0 77 mRatio = aSize;
michael@0 78 }
michael@0 79 void SetRatio(const nsSize& aRatio)
michael@0 80 {
michael@0 81 MOZ_ASSERT(!mHasWidth || !mHasHeight,
michael@0 82 "Probably shouldn't be setting a ratio if we have a concrete size");
michael@0 83 mRatio = aRatio;
michael@0 84 }
michael@0 85
michael@0 86 nsSize mRatio;
michael@0 87 nscoord mWidth;
michael@0 88 nscoord mHeight;
michael@0 89 bool mHasWidth;
michael@0 90 bool mHasHeight;
michael@0 91 };
michael@0 92
michael@0 93 }
michael@0 94
michael@0 95 /**
michael@0 96 * This is a small wrapper class to encapsulate image drawing that can draw an
michael@0 97 * nsStyleImage image, which may internally be a real image, a sub image, or a
michael@0 98 * CSS gradient.
michael@0 99 *
michael@0 100 * @note Always call the member functions in the order of PrepareImage(),
michael@0 101 * SetSize(), and Draw*().
michael@0 102 */
michael@0 103 class nsImageRenderer {
michael@0 104 public:
michael@0 105 typedef mozilla::layers::LayerManager LayerManager;
michael@0 106 typedef mozilla::layers::ImageContainer ImageContainer;
michael@0 107
michael@0 108 enum {
michael@0 109 FLAG_SYNC_DECODE_IMAGES = 0x01,
michael@0 110 FLAG_PAINTING_TO_WINDOW = 0x02
michael@0 111 };
michael@0 112 enum FitType
michael@0 113 {
michael@0 114 CONTAIN,
michael@0 115 COVER
michael@0 116 };
michael@0 117
michael@0 118 nsImageRenderer(nsIFrame* aForFrame, const nsStyleImage* aImage, uint32_t aFlags);
michael@0 119 ~nsImageRenderer();
michael@0 120 /**
michael@0 121 * Populates member variables to get ready for rendering.
michael@0 122 * @return true iff the image is ready, and there is at least a pixel to
michael@0 123 * draw.
michael@0 124 */
michael@0 125 bool PrepareImage();
michael@0 126
michael@0 127 /**
michael@0 128 * The three Compute*Size functions correspond to the sizing algorthms and
michael@0 129 * definitions from the CSS Image Values and Replaced Content spec. See
michael@0 130 * http://dev.w3.org/csswg/css-images-3/#sizing .
michael@0 131 */
michael@0 132
michael@0 133 /**
michael@0 134 * Compute the intrinsic size of the image as defined in the CSS Image Values
michael@0 135 * spec. The intrinsic size is the unscaled size which the image would ideally
michael@0 136 * like to be in app units.
michael@0 137 */
michael@0 138 mozilla::CSSSizeOrRatio ComputeIntrinsicSize();
michael@0 139
michael@0 140 /**
michael@0 141 * Compute the size of the rendered image using either the 'cover' or
michael@0 142 * 'contain' constraints (aFitType).
michael@0 143 * aIntrinsicRatio may be an invalid ratio, that is one or both of its
michael@0 144 * dimensions can be less than or equal to zero.
michael@0 145 */
michael@0 146 static nsSize ComputeConstrainedSize(const nsSize& aConstrainingSize,
michael@0 147 const nsSize& aIntrinsicRatio,
michael@0 148 FitType aFitType);
michael@0 149 /**
michael@0 150 * Compute the size of the rendered image (the concrete size) where no cover/
michael@0 151 * contain constraints are given. The 'default algorithm' from the CSS Image
michael@0 152 * Values spec.
michael@0 153 */
michael@0 154 static nsSize ComputeConcreteSize(const mozilla::CSSSizeOrRatio& aSpecifiedSize,
michael@0 155 const mozilla::CSSSizeOrRatio& aIntrinsicSize,
michael@0 156 const nsSize& aDefaultSize);
michael@0 157
michael@0 158 /**
michael@0 159 * Set this image's preferred size. This will be its intrinsic size where
michael@0 160 * specified and the default size where it is not. Used as the unscaled size
michael@0 161 * when rendering the image.
michael@0 162 */
michael@0 163 void SetPreferredSize(const mozilla::CSSSizeOrRatio& aIntrinsicSize,
michael@0 164 const nsSize& aDefaultSize);
michael@0 165
michael@0 166 /**
michael@0 167 * Draws the image to the target rendering context.
michael@0 168 * aSrc is a rect on the source image which will be mapped to aDest.
michael@0 169 * @see nsLayoutUtils::DrawImage() for other parameters.
michael@0 170 */
michael@0 171 void Draw(nsPresContext* aPresContext,
michael@0 172 nsRenderingContext& aRenderingContext,
michael@0 173 const nsRect& aDirtyRect,
michael@0 174 const nsRect& aFill,
michael@0 175 const nsRect& aDest,
michael@0 176 const mozilla::CSSIntRect& aSrc);
michael@0 177 /**
michael@0 178 * Draws the image to the target rendering context using background-specific
michael@0 179 * arguments.
michael@0 180 * @see nsLayoutUtils::DrawImage() for parameters.
michael@0 181 */
michael@0 182 void DrawBackground(nsPresContext* aPresContext,
michael@0 183 nsRenderingContext& aRenderingContext,
michael@0 184 const nsRect& aDest,
michael@0 185 const nsRect& aFill,
michael@0 186 const nsPoint& aAnchor,
michael@0 187 const nsRect& aDirty);
michael@0 188
michael@0 189 /**
michael@0 190 * Draw the image to a single component of a border-image style rendering.
michael@0 191 * aFill The destination rect to be drawn into
michael@0 192 * aSrc is the part of the image to be rendered into a tile (aUnitSize in
michael@0 193 * aFill), if aSrc and the dest tile are different sizes, the image will be
michael@0 194 * scaled to map aSrc onto the dest tile.
michael@0 195 * aHFill and aVFill are the repeat patterns for the component -
michael@0 196 * NS_STYLE_BORDER_IMAGE_REPEAT_*
michael@0 197 * aUnitSize The scaled size of a single source rect (in destination coords)
michael@0 198 * aIndex identifies the component: 0 1 2
michael@0 199 * 3 4 5
michael@0 200 * 6 7 8
michael@0 201 */
michael@0 202 void
michael@0 203 DrawBorderImageComponent(nsPresContext* aPresContext,
michael@0 204 nsRenderingContext& aRenderingContext,
michael@0 205 const nsRect& aDirtyRect,
michael@0 206 const nsRect& aFill,
michael@0 207 const mozilla::CSSIntRect& aSrc,
michael@0 208 uint8_t aHFill,
michael@0 209 uint8_t aVFill,
michael@0 210 const nsSize& aUnitSize,
michael@0 211 uint8_t aIndex);
michael@0 212
michael@0 213 bool IsRasterImage();
michael@0 214 bool IsAnimatedImage();
michael@0 215 already_AddRefed<ImageContainer> GetContainer(LayerManager* aManager);
michael@0 216
michael@0 217 bool IsReady() { return mIsReady; }
michael@0 218
michael@0 219 private:
michael@0 220 /**
michael@0 221 * Helper method for creating a gfxDrawable from mPaintServerFrame or
michael@0 222 * mImageElementSurface.
michael@0 223 * Requires mType is eStyleImageType_Element.
michael@0 224 * Returns null if we cannot create the drawable.
michael@0 225 */
michael@0 226 already_AddRefed<gfxDrawable> DrawableForElement(const nsRect& aImageRect,
michael@0 227 nsRenderingContext& aRenderingContext);
michael@0 228
michael@0 229 nsIFrame* mForFrame;
michael@0 230 const nsStyleImage* mImage;
michael@0 231 nsStyleImageType mType;
michael@0 232 nsCOMPtr<imgIContainer> mImageContainer;
michael@0 233 nsRefPtr<nsStyleGradient> mGradientData;
michael@0 234 nsIFrame* mPaintServerFrame;
michael@0 235 nsLayoutUtils::SurfaceFromElementResult mImageElementSurface;
michael@0 236 bool mIsReady;
michael@0 237 nsSize mSize; // unscaled size of the image, in app units
michael@0 238 uint32_t mFlags;
michael@0 239 };
michael@0 240
michael@0 241 /**
michael@0 242 * A struct representing all the information needed to paint a background
michael@0 243 * image to some target, taking into account all CSS background-* properties.
michael@0 244 * See PrepareBackgroundLayer.
michael@0 245 */
michael@0 246 struct nsBackgroundLayerState {
michael@0 247 /**
michael@0 248 * @param aFlags some combination of nsCSSRendering::PAINTBG_* flags
michael@0 249 */
michael@0 250 nsBackgroundLayerState(nsIFrame* aForFrame, const nsStyleImage* aImage, uint32_t aFlags)
michael@0 251 : mImageRenderer(aForFrame, aImage, aFlags), mCompositingOp(gfxContext::OPERATOR_OVER) {}
michael@0 252
michael@0 253 /**
michael@0 254 * The nsImageRenderer that will be used to draw the background.
michael@0 255 */
michael@0 256 nsImageRenderer mImageRenderer;
michael@0 257 /**
michael@0 258 * A rectangle that one copy of the image tile is mapped onto. Same
michael@0 259 * coordinate system as aBorderArea/aBGClipRect passed into
michael@0 260 * PrepareBackgroundLayer.
michael@0 261 */
michael@0 262 nsRect mDestArea;
michael@0 263 /**
michael@0 264 * The actual rectangle that should be filled with (complete or partial)
michael@0 265 * image tiles. Same coordinate system as aBorderArea/aBGClipRect passed into
michael@0 266 * PrepareBackgroundLayer.
michael@0 267 */
michael@0 268 nsRect mFillArea;
michael@0 269 /**
michael@0 270 * The anchor point that should be snapped to a pixel corner. Same
michael@0 271 * coordinate system as aBorderArea/aBGClipRect passed into
michael@0 272 * PrepareBackgroundLayer.
michael@0 273 */
michael@0 274 nsPoint mAnchor;
michael@0 275 /**
michael@0 276 * The compositing operation that the image should use
michael@0 277 */
michael@0 278 gfxContext::GraphicsOperator mCompositingOp;
michael@0 279 };
michael@0 280
michael@0 281 struct nsCSSRendering {
michael@0 282 /**
michael@0 283 * Initialize any static variables used by nsCSSRendering.
michael@0 284 */
michael@0 285 static void Init();
michael@0 286
michael@0 287 /**
michael@0 288 * Clean up any static variables used by nsCSSRendering.
michael@0 289 */
michael@0 290 static void Shutdown();
michael@0 291
michael@0 292 static void PaintBoxShadowInner(nsPresContext* aPresContext,
michael@0 293 nsRenderingContext& aRenderingContext,
michael@0 294 nsIFrame* aForFrame,
michael@0 295 const nsRect& aFrameArea,
michael@0 296 const nsRect& aDirtyRect);
michael@0 297
michael@0 298 static void PaintBoxShadowOuter(nsPresContext* aPresContext,
michael@0 299 nsRenderingContext& aRenderingContext,
michael@0 300 nsIFrame* aForFrame,
michael@0 301 const nsRect& aFrameArea,
michael@0 302 const nsRect& aDirtyRect,
michael@0 303 float aOpacity = 1.0);
michael@0 304
michael@0 305 static void ComputePixelRadii(const nscoord *aAppUnitsRadii,
michael@0 306 nscoord aAppUnitsPerPixel,
michael@0 307 gfxCornerSizes *oBorderRadii);
michael@0 308
michael@0 309 /**
michael@0 310 * Render the border for an element using css rendering rules
michael@0 311 * for borders. aSkipSides is a bitmask of the sides to skip
michael@0 312 * when rendering. If 0 then no sides are skipped.
michael@0 313 */
michael@0 314 static void PaintBorder(nsPresContext* aPresContext,
michael@0 315 nsRenderingContext& aRenderingContext,
michael@0 316 nsIFrame* aForFrame,
michael@0 317 const nsRect& aDirtyRect,
michael@0 318 const nsRect& aBorderArea,
michael@0 319 nsStyleContext* aStyleContext,
michael@0 320 int aSkipSides = 0);
michael@0 321
michael@0 322 /**
michael@0 323 * Like PaintBorder, but taking an nsStyleBorder argument instead of
michael@0 324 * getting it from aStyleContext.
michael@0 325 */
michael@0 326 static void PaintBorderWithStyleBorder(nsPresContext* aPresContext,
michael@0 327 nsRenderingContext& aRenderingContext,
michael@0 328 nsIFrame* aForFrame,
michael@0 329 const nsRect& aDirtyRect,
michael@0 330 const nsRect& aBorderArea,
michael@0 331 const nsStyleBorder& aBorderStyle,
michael@0 332 nsStyleContext* aStyleContext,
michael@0 333 int aSkipSides = 0);
michael@0 334
michael@0 335
michael@0 336 /**
michael@0 337 * Render the outline for an element using css rendering rules
michael@0 338 * for borders. aSkipSides is a bitmask of the sides to skip
michael@0 339 * when rendering. If 0 then no sides are skipped.
michael@0 340 */
michael@0 341 static void PaintOutline(nsPresContext* aPresContext,
michael@0 342 nsRenderingContext& aRenderingContext,
michael@0 343 nsIFrame* aForFrame,
michael@0 344 const nsRect& aDirtyRect,
michael@0 345 const nsRect& aBorderArea,
michael@0 346 nsStyleContext* aStyleContext);
michael@0 347
michael@0 348 /**
michael@0 349 * Render keyboard focus on an element.
michael@0 350 * |aFocusRect| is the outer rectangle of the focused element.
michael@0 351 * Uses a fixed style equivalent to "1px dotted |aColor|".
michael@0 352 * Not used for controls, because the native theme may differ.
michael@0 353 */
michael@0 354 static void PaintFocus(nsPresContext* aPresContext,
michael@0 355 nsRenderingContext& aRenderingContext,
michael@0 356 const nsRect& aFocusRect,
michael@0 357 nscolor aColor);
michael@0 358
michael@0 359 /**
michael@0 360 * Render a gradient for an element.
michael@0 361 * aDest is the rect for a single tile of the gradient on the destination.
michael@0 362 * aFill is the rect on the destination to be covered by repeated tiling of
michael@0 363 * the gradient.
michael@0 364 * aSrc is the part of the gradient to be rendered into a tile (aDest), if
michael@0 365 * aSrc and aDest are different sizes, the image will be scaled to map aSrc
michael@0 366 * onto aDest.
michael@0 367 * aIntrinsicSize is the size of the source gradient.
michael@0 368 */
michael@0 369 static void PaintGradient(nsPresContext* aPresContext,
michael@0 370 nsRenderingContext& aRenderingContext,
michael@0 371 nsStyleGradient* aGradient,
michael@0 372 const nsRect& aDirtyRect,
michael@0 373 const nsRect& aDest,
michael@0 374 const nsRect& aFill,
michael@0 375 const mozilla::CSSIntRect& aSrc,
michael@0 376 const nsSize& aIntrinsiceSize);
michael@0 377
michael@0 378 /**
michael@0 379 * Find the frame whose background style should be used to draw the
michael@0 380 * canvas background. aForFrame must be the frame for the root element
michael@0 381 * whose background style should be used. This function will return
michael@0 382 * aForFrame unless the <body> background should be propagated, in
michael@0 383 * which case we return the frame associated with the <body>'s background.
michael@0 384 */
michael@0 385 static nsIFrame* FindBackgroundStyleFrame(nsIFrame* aForFrame);
michael@0 386
michael@0 387 /**
michael@0 388 * @return true if |aFrame| is a canvas frame, in the CSS sense.
michael@0 389 */
michael@0 390 static bool IsCanvasFrame(nsIFrame* aFrame);
michael@0 391
michael@0 392 /**
michael@0 393 * Fill in an aBackgroundSC to be used to paint the background
michael@0 394 * for an element. This applies the rules for propagating
michael@0 395 * backgrounds between BODY, the root element, and the canvas.
michael@0 396 * @return true if there is some meaningful background.
michael@0 397 */
michael@0 398 static bool FindBackground(nsIFrame* aForFrame,
michael@0 399 nsStyleContext** aBackgroundSC);
michael@0 400
michael@0 401 /**
michael@0 402 * As FindBackground, but the passed-in frame is known to be a root frame
michael@0 403 * (returned from nsCSSFrameConstructor::GetRootElementStyleFrame())
michael@0 404 * and there is always some meaningful background returned.
michael@0 405 */
michael@0 406 static nsStyleContext* FindRootFrameBackground(nsIFrame* aForFrame);
michael@0 407
michael@0 408 /**
michael@0 409 * Returns background style information for the canvas.
michael@0 410 *
michael@0 411 * @param aForFrame
michael@0 412 * the frame used to represent the canvas, in the CSS sense (i.e.
michael@0 413 * nsCSSRendering::IsCanvasFrame(aForFrame) must be true)
michael@0 414 * @param aRootElementFrame
michael@0 415 * the frame representing the root element of the document
michael@0 416 * @param aBackground
michael@0 417 * contains background style information for the canvas on return
michael@0 418 */
michael@0 419 static nsStyleContext*
michael@0 420 FindCanvasBackground(nsIFrame* aForFrame, nsIFrame* aRootElementFrame)
michael@0 421 {
michael@0 422 NS_ABORT_IF_FALSE(IsCanvasFrame(aForFrame), "not a canvas frame");
michael@0 423 if (aRootElementFrame)
michael@0 424 return FindRootFrameBackground(aRootElementFrame);
michael@0 425
michael@0 426 // This should always give transparent, so we'll fill it in with the
michael@0 427 // default color if needed. This seems to happen a bit while a page is
michael@0 428 // being loaded.
michael@0 429 return aForFrame->StyleContext();
michael@0 430 }
michael@0 431
michael@0 432 /**
michael@0 433 * Find a frame which draws a non-transparent background,
michael@0 434 * for various table-related and HR-related backwards-compatibility hacks.
michael@0 435 * This function will also stop if it finds themed frame which might draw
michael@0 436 * background.
michael@0 437 *
michael@0 438 * Be very hesitant if you're considering calling this function -- it's
michael@0 439 * usually not what you want.
michael@0 440 */
michael@0 441 static nsIFrame*
michael@0 442 FindNonTransparentBackgroundFrame(nsIFrame* aFrame,
michael@0 443 bool aStartAtParent = false);
michael@0 444
michael@0 445 /**
michael@0 446 * Determine the background color to draw taking into account print settings.
michael@0 447 */
michael@0 448 static nscolor
michael@0 449 DetermineBackgroundColor(nsPresContext* aPresContext,
michael@0 450 nsStyleContext* aStyleContext,
michael@0 451 nsIFrame* aFrame,
michael@0 452 bool& aDrawBackgroundImage,
michael@0 453 bool& aDrawBackgroundColor);
michael@0 454
michael@0 455 static nsRect
michael@0 456 ComputeBackgroundPositioningArea(nsPresContext* aPresContext,
michael@0 457 nsIFrame* aForFrame,
michael@0 458 const nsRect& aBorderArea,
michael@0 459 const nsStyleBackground& aBackground,
michael@0 460 const nsStyleBackground::Layer& aLayer,
michael@0 461 nsIFrame** aAttachedToFrame);
michael@0 462
michael@0 463 static nsBackgroundLayerState
michael@0 464 PrepareBackgroundLayer(nsPresContext* aPresContext,
michael@0 465 nsIFrame* aForFrame,
michael@0 466 uint32_t aFlags,
michael@0 467 const nsRect& aBorderArea,
michael@0 468 const nsRect& aBGClipRect,
michael@0 469 const nsStyleBackground& aBackground,
michael@0 470 const nsStyleBackground::Layer& aLayer);
michael@0 471
michael@0 472 /**
michael@0 473 * Render the background for an element using css rendering rules
michael@0 474 * for backgrounds.
michael@0 475 */
michael@0 476 enum {
michael@0 477 /**
michael@0 478 * When this flag is passed, the element's nsDisplayBorder will be
michael@0 479 * painted immediately on top of this background.
michael@0 480 */
michael@0 481 PAINTBG_WILL_PAINT_BORDER = 0x01,
michael@0 482 /**
michael@0 483 * When this flag is passed, images are synchronously decoded.
michael@0 484 */
michael@0 485 PAINTBG_SYNC_DECODE_IMAGES = 0x02,
michael@0 486 /**
michael@0 487 * When this flag is passed, painting will go to the screen so we can
michael@0 488 * take advantage of the fact that it will be clipped to the viewport.
michael@0 489 */
michael@0 490 PAINTBG_TO_WINDOW = 0x04
michael@0 491 };
michael@0 492 static void PaintBackground(nsPresContext* aPresContext,
michael@0 493 nsRenderingContext& aRenderingContext,
michael@0 494 nsIFrame* aForFrame,
michael@0 495 const nsRect& aDirtyRect,
michael@0 496 const nsRect& aBorderArea,
michael@0 497 uint32_t aFlags,
michael@0 498 nsRect* aBGClipRect = nullptr,
michael@0 499 int32_t aLayer = -1);
michael@0 500
michael@0 501 static void PaintBackgroundColor(nsPresContext* aPresContext,
michael@0 502 nsRenderingContext& aRenderingContext,
michael@0 503 nsIFrame* aForFrame,
michael@0 504 const nsRect& aDirtyRect,
michael@0 505 const nsRect& aBorderArea,
michael@0 506 uint32_t aFlags);
michael@0 507
michael@0 508 /**
michael@0 509 * Same as |PaintBackground|, except using the provided style structs.
michael@0 510 * This short-circuits the code that ensures that the root element's
michael@0 511 * background is drawn on the canvas.
michael@0 512 * The aLayer parameter allows you to paint a single layer of the background.
michael@0 513 * The default value for aLayer, -1, means that all layers will be painted.
michael@0 514 * The background color will only be painted if the back-most layer is also
michael@0 515 * being painted.
michael@0 516 */
michael@0 517 static void PaintBackgroundWithSC(nsPresContext* aPresContext,
michael@0 518 nsRenderingContext& aRenderingContext,
michael@0 519 nsIFrame* aForFrame,
michael@0 520 const nsRect& aDirtyRect,
michael@0 521 const nsRect& aBorderArea,
michael@0 522 nsStyleContext *aStyleContext,
michael@0 523 const nsStyleBorder& aBorder,
michael@0 524 uint32_t aFlags,
michael@0 525 nsRect* aBGClipRect = nullptr,
michael@0 526 int32_t aLayer = -1);
michael@0 527
michael@0 528 static void PaintBackgroundColorWithSC(nsPresContext* aPresContext,
michael@0 529 nsRenderingContext& aRenderingContext,
michael@0 530 nsIFrame* aForFrame,
michael@0 531 const nsRect& aDirtyRect,
michael@0 532 const nsRect& aBorderArea,
michael@0 533 nsStyleContext *aStyleContext,
michael@0 534 const nsStyleBorder& aBorder,
michael@0 535 uint32_t aFlags);
michael@0 536 /**
michael@0 537 * Returns the rectangle covered by the given background layer image, taking
michael@0 538 * into account background positioning, sizing, and repetition, but not
michael@0 539 * clipping.
michael@0 540 */
michael@0 541 static nsRect GetBackgroundLayerRect(nsPresContext* aPresContext,
michael@0 542 nsIFrame* aForFrame,
michael@0 543 const nsRect& aBorderArea,
michael@0 544 const nsRect& aClipRect,
michael@0 545 const nsStyleBackground& aBackground,
michael@0 546 const nsStyleBackground::Layer& aLayer,
michael@0 547 uint32_t aFlags);
michael@0 548
michael@0 549 /**
michael@0 550 * Checks if image in layer aLayer of aBackground is currently decoded.
michael@0 551 */
michael@0 552 static bool IsBackgroundImageDecodedForStyleContextAndLayer(
michael@0 553 const nsStyleBackground *aBackground, uint32_t aLayer);
michael@0 554
michael@0 555 /**
michael@0 556 * Checks if all images that are part of the background for aFrame are
michael@0 557 * currently decoded.
michael@0 558 */
michael@0 559 static bool AreAllBackgroundImagesDecodedForFrame(nsIFrame* aFrame);
michael@0 560
michael@0 561 /**
michael@0 562 * Called when we start creating a display list. The frame tree will not
michael@0 563 * change until a matching EndFrameTreeLocked is called.
michael@0 564 */
michael@0 565 static void BeginFrameTreesLocked();
michael@0 566 /**
michael@0 567 * Called when we've finished using a display list. When all
michael@0 568 * BeginFrameTreeLocked calls have been balanced by an EndFrameTreeLocked,
michael@0 569 * the frame tree may start changing again.
michael@0 570 */
michael@0 571 static void EndFrameTreesLocked();
michael@0 572
michael@0 573 // Draw a border segment in the table collapsing border model without
michael@0 574 // beveling corners
michael@0 575 static void DrawTableBorderSegment(nsRenderingContext& aContext,
michael@0 576 uint8_t aBorderStyle,
michael@0 577 nscolor aBorderColor,
michael@0 578 const nsStyleBackground* aBGColor,
michael@0 579 const nsRect& aBorderRect,
michael@0 580 int32_t aAppUnitsPerCSSPixel,
michael@0 581 uint8_t aStartBevelSide = 0,
michael@0 582 nscoord aStartBevelOffset = 0,
michael@0 583 uint8_t aEndBevelSide = 0,
michael@0 584 nscoord aEndBevelOffset = 0);
michael@0 585
michael@0 586 /**
michael@0 587 * Function for painting the decoration lines for the text.
michael@0 588 * NOTE: aPt, aLineSize, aAscent and aOffset are non-rounded device pixels,
michael@0 589 * not app units.
michael@0 590 * input:
michael@0 591 * @param aFrame the frame which needs the decoration line
michael@0 592 * @param aGfxContext
michael@0 593 * @param aDirtyRect no need to paint outside this rect
michael@0 594 * @param aColor the color of the decoration line
michael@0 595 * @param aPt the top/left edge of the text
michael@0 596 * @param aXInFrame the distance between aPt.x and left edge of
michael@0 597 * aFrame. If the decoration line is for shadow,
michael@0 598 * set the distance between the left edge of
michael@0 599 * the aFrame and the position of the text as
michael@0 600 * positioned without offset of the shadow.
michael@0 601 * @param aLineSize the width and the height of the decoration
michael@0 602 * line
michael@0 603 * @param aAscent the ascent of the text
michael@0 604 * @param aOffset the offset of the decoration line from
michael@0 605 * the baseline of the text (if the value is
michael@0 606 * positive, the line is lifted up)
michael@0 607 * @param aDecoration which line will be painted. The value can be
michael@0 608 * NS_STYLE_TEXT_DECORATION_LINE_UNDERLINE or
michael@0 609 * NS_STYLE_TEXT_DECORATION_LINE_OVERLINE or
michael@0 610 * NS_STYLE_TEXT_DECORATION_LINE_LINE_THROUGH.
michael@0 611 * @param aStyle the style of the decoration line such as
michael@0 612 * NS_STYLE_TEXT_DECORATION_STYLE_*.
michael@0 613 * @param aDescentLimit If aDescentLimit is zero or larger and the
michael@0 614 * underline overflows from the descent space,
michael@0 615 * the underline should be lifted up as far as
michael@0 616 * possible. Note that this does not mean the
michael@0 617 * underline never overflows from this
michael@0 618 * limitation. Because if the underline is
michael@0 619 * positioned to the baseline or upper, it causes
michael@0 620 * unreadability. Note that if this is zero
michael@0 621 * or larger, the underline rect may be shrunken
michael@0 622 * if it's possible. Therefore, this value is
michael@0 623 * used for strikeout line and overline too.
michael@0 624 */
michael@0 625 static void PaintDecorationLine(nsIFrame* aFrame,
michael@0 626 gfxContext* aGfxContext,
michael@0 627 const gfxRect& aDirtyRect,
michael@0 628 const nscolor aColor,
michael@0 629 const gfxPoint& aPt,
michael@0 630 const gfxFloat aXInFrame,
michael@0 631 const gfxSize& aLineSize,
michael@0 632 const gfxFloat aAscent,
michael@0 633 const gfxFloat aOffset,
michael@0 634 const uint8_t aDecoration,
michael@0 635 const uint8_t aStyle,
michael@0 636 const gfxFloat aDescentLimit = -1.0);
michael@0 637
michael@0 638 /**
michael@0 639 * Adds a path corresponding to the outline of the decoration line to
michael@0 640 * the specified context. Arguments have the same meaning as for
michael@0 641 * PaintDecorationLine. Currently this only works for solid
michael@0 642 * decorations; for other decoration styles, an empty path is added
michael@0 643 * to the context.
michael@0 644 */
michael@0 645 static void DecorationLineToPath(nsIFrame* aFrame,
michael@0 646 gfxContext* aGfxContext,
michael@0 647 const gfxRect& aDirtyRect,
michael@0 648 const nscolor aColor,
michael@0 649 const gfxPoint& aPt,
michael@0 650 const gfxFloat aXInFrame,
michael@0 651 const gfxSize& aLineSize,
michael@0 652 const gfxFloat aAscent,
michael@0 653 const gfxFloat aOffset,
michael@0 654 const uint8_t aDecoration,
michael@0 655 const uint8_t aStyle,
michael@0 656 const gfxFloat aDescentLimit = -1.0);
michael@0 657
michael@0 658 /**
michael@0 659 * Function for getting the decoration line rect for the text.
michael@0 660 * NOTE: aLineSize, aAscent and aOffset are non-rounded device pixels,
michael@0 661 * not app units.
michael@0 662 * input:
michael@0 663 * @param aPresContext
michael@0 664 * @param aLineSize the width and the height of the decoration
michael@0 665 * line
michael@0 666 * @param aAscent the ascent of the text
michael@0 667 * @param aOffset the offset of the decoration line from
michael@0 668 * the baseline of the text (if the value is
michael@0 669 * positive, the line is lifted up)
michael@0 670 * @param aDecoration which line will be painted. The value can be
michael@0 671 * NS_STYLE_TEXT_DECORATION_LINE_UNDERLINE or
michael@0 672 * NS_STYLE_TEXT_DECORATION_LINE_OVERLINE or
michael@0 673 * NS_STYLE_TEXT_DECORATION_LINE_LINE_THROUGH.
michael@0 674 * @param aStyle the style of the decoration line such as
michael@0 675 * NS_STYLE_TEXT_DECORATION_STYLE_*.
michael@0 676 * @param aDescentLimit If aDescentLimit is zero or larger and the
michael@0 677 * underline overflows from the descent space,
michael@0 678 * the underline should be lifted up as far as
michael@0 679 * possible. Note that this does not mean the
michael@0 680 * underline never overflows from this
michael@0 681 * limitation. Because if the underline is
michael@0 682 * positioned to the baseline or upper, it causes
michael@0 683 * unreadability. Note that if this is zero
michael@0 684 * or larger, the underline rect may be shrunken
michael@0 685 * if it's possible. Therefore, this value is
michael@0 686 * used for strikeout line and overline too.
michael@0 687 * output:
michael@0 688 * @return the decoration line rect for the input,
michael@0 689 * the each values are app units.
michael@0 690 */
michael@0 691 static nsRect GetTextDecorationRect(nsPresContext* aPresContext,
michael@0 692 const gfxSize& aLineSize,
michael@0 693 const gfxFloat aAscent,
michael@0 694 const gfxFloat aOffset,
michael@0 695 const uint8_t aDecoration,
michael@0 696 const uint8_t aStyle,
michael@0 697 const gfxFloat aDescentLimit = -1.0);
michael@0 698
michael@0 699 static gfxContext::GraphicsOperator GetGFXBlendMode(uint8_t mBlendMode) {
michael@0 700 switch (mBlendMode) {
michael@0 701 case NS_STYLE_BLEND_NORMAL: return gfxContext::OPERATOR_OVER;
michael@0 702 case NS_STYLE_BLEND_MULTIPLY: return gfxContext::OPERATOR_MULTIPLY;
michael@0 703 case NS_STYLE_BLEND_SCREEN: return gfxContext::OPERATOR_SCREEN;
michael@0 704 case NS_STYLE_BLEND_OVERLAY: return gfxContext::OPERATOR_OVERLAY;
michael@0 705 case NS_STYLE_BLEND_DARKEN: return gfxContext::OPERATOR_DARKEN;
michael@0 706 case NS_STYLE_BLEND_LIGHTEN: return gfxContext::OPERATOR_LIGHTEN;
michael@0 707 case NS_STYLE_BLEND_COLOR_DODGE: return gfxContext::OPERATOR_COLOR_DODGE;
michael@0 708 case NS_STYLE_BLEND_COLOR_BURN: return gfxContext::OPERATOR_COLOR_BURN;
michael@0 709 case NS_STYLE_BLEND_HARD_LIGHT: return gfxContext::OPERATOR_HARD_LIGHT;
michael@0 710 case NS_STYLE_BLEND_SOFT_LIGHT: return gfxContext::OPERATOR_SOFT_LIGHT;
michael@0 711 case NS_STYLE_BLEND_DIFFERENCE: return gfxContext::OPERATOR_DIFFERENCE;
michael@0 712 case NS_STYLE_BLEND_EXCLUSION: return gfxContext::OPERATOR_EXCLUSION;
michael@0 713 case NS_STYLE_BLEND_HUE: return gfxContext::OPERATOR_HUE;
michael@0 714 case NS_STYLE_BLEND_SATURATION: return gfxContext::OPERATOR_SATURATION;
michael@0 715 case NS_STYLE_BLEND_COLOR: return gfxContext::OPERATOR_COLOR;
michael@0 716 case NS_STYLE_BLEND_LUMINOSITY: return gfxContext::OPERATOR_LUMINOSITY;
michael@0 717 default: MOZ_ASSERT(false); return gfxContext::OPERATOR_OVER;
michael@0 718 }
michael@0 719
michael@0 720 return gfxContext::OPERATOR_OVER;
michael@0 721 }
michael@0 722
michael@0 723 protected:
michael@0 724 static gfxRect GetTextDecorationRectInternal(const gfxPoint& aPt,
michael@0 725 const gfxSize& aLineSize,
michael@0 726 const gfxFloat aAscent,
michael@0 727 const gfxFloat aOffset,
michael@0 728 const uint8_t aDecoration,
michael@0 729 const uint8_t aStyle,
michael@0 730 const gfxFloat aDscentLimit);
michael@0 731
michael@0 732 /**
michael@0 733 * Returns inflated rect for painting a decoration line.
michael@0 734 * Complex style decoration lines should be painted from leftmost of nearest
michael@0 735 * ancestor block box because that makes better look of connection of lines
michael@0 736 * for different nodes. ExpandPaintingRectForDecorationLine() returns
michael@0 737 * a rect for actual painting rect for the clipped rect.
michael@0 738 *
michael@0 739 * input:
michael@0 740 * @param aFrame the frame which needs the decoration line.
michael@0 741 * @param aStyle the style of the complex decoration line
michael@0 742 * NS_STYLE_TEXT_DECORATION_STYLE_DOTTED or
michael@0 743 * NS_STYLE_TEXT_DECORATION_STYLE_DASHED or
michael@0 744 * NS_STYLE_TEXT_DECORATION_STYLE_WAVY.
michael@0 745 * @param aClippedRect the clipped rect for the decoration line.
michael@0 746 * in other words, visible area of the line.
michael@0 747 * @param aXInFrame the distance between left edge of aFrame and
michael@0 748 * aClippedRect.pos.x.
michael@0 749 * @param aCycleLength the width of one cycle of the line style.
michael@0 750 */
michael@0 751 static gfxRect ExpandPaintingRectForDecorationLine(
michael@0 752 nsIFrame* aFrame,
michael@0 753 const uint8_t aStyle,
michael@0 754 const gfxRect &aClippedRect,
michael@0 755 const gfxFloat aXInFrame,
michael@0 756 const gfxFloat aCycleLength);
michael@0 757 };
michael@0 758
michael@0 759 /*
michael@0 760 * nsContextBoxBlur
michael@0 761 * Creates an 8-bit alpha channel context for callers to draw in, blurs the
michael@0 762 * contents of that context and applies it as a 1-color mask on a
michael@0 763 * different existing context. Uses gfxAlphaBoxBlur as its back end.
michael@0 764 *
michael@0 765 * You must call Init() first to create a suitable temporary surface to draw
michael@0 766 * on. You must then draw any desired content onto the given context, then
michael@0 767 * call DoPaint() to apply the blurred content as a single-color mask. You
michael@0 768 * can only call Init() once, so objects cannot be reused.
michael@0 769 *
michael@0 770 * This is very useful for creating drop shadows or silhouettes.
michael@0 771 */
michael@0 772 class nsContextBoxBlur {
michael@0 773 public:
michael@0 774 enum {
michael@0 775 FORCE_MASK = 0x01
michael@0 776 };
michael@0 777 /**
michael@0 778 * Prepares a gfxContext to draw on. Do not call this twice; if you want
michael@0 779 * to get the gfxContext again use GetContext().
michael@0 780 *
michael@0 781 * @param aRect The coordinates of the surface to create.
michael@0 782 * All coordinates must be in app units.
michael@0 783 * This must not include the blur radius, pass
michael@0 784 * it as the second parameter and everything
michael@0 785 * is taken care of.
michael@0 786 *
michael@0 787 * @param aBlurRadius The blur radius in app units.
michael@0 788 *
michael@0 789 * @param aAppUnitsPerDevPixel The number of app units in a device pixel,
michael@0 790 * for conversion. Most of the time you'll
michael@0 791 * pass this from the current PresContext if
michael@0 792 * available.
michael@0 793 *
michael@0 794 * @param aDestinationCtx The graphics context to apply the blurred
michael@0 795 * mask to when you call DoPaint(). Make sure
michael@0 796 * it is not destroyed before you call
michael@0 797 * DoPaint(). To set the color of the
michael@0 798 * resulting blurred graphic mask, you must
michael@0 799 * set the color on this context before
michael@0 800 * calling Init().
michael@0 801 *
michael@0 802 * @param aDirtyRect The absolute dirty rect in app units. Used to
michael@0 803 * optimize the temporary surface size and speed up blur.
michael@0 804 *
michael@0 805 * @param aSkipRect An area in device pixels (NOT app units!) to avoid
michael@0 806 * blurring over, to prevent unnecessary work.
michael@0 807 *
michael@0 808 * @param aFlags FORCE_MASK to ensure that the content drawn to the
michael@0 809 * returned gfxContext is used as a mask, and not
michael@0 810 * drawn directly to aDestinationCtx.
michael@0 811 *
michael@0 812 * @return A blank 8-bit alpha-channel-only graphics context to
michael@0 813 * draw on, or null on error. Must not be freed. The
michael@0 814 * context has a device offset applied to it given by
michael@0 815 * aRect. This means you can use coordinates as if it
michael@0 816 * were at the desired position at aRect and you don't
michael@0 817 * need to worry about translating any coordinates to
michael@0 818 * draw on this temporary surface.
michael@0 819 *
michael@0 820 * If aBlurRadius is 0, the returned context is aDestinationCtx and
michael@0 821 * DoPaint() does nothing, because no blurring is required. Therefore, you
michael@0 822 * should prepare the destination context as if you were going to draw
michael@0 823 * directly on it instead of any temporary surface created in this class.
michael@0 824 */
michael@0 825 gfxContext* Init(const nsRect& aRect, nscoord aSpreadRadius,
michael@0 826 nscoord aBlurRadius,
michael@0 827 int32_t aAppUnitsPerDevPixel, gfxContext* aDestinationCtx,
michael@0 828 const nsRect& aDirtyRect, const gfxRect* aSkipRect,
michael@0 829 uint32_t aFlags = 0);
michael@0 830
michael@0 831 /**
michael@0 832 * Does the actual blurring and mask applying. Users of this object *must*
michael@0 833 * have called Init() first, then have drawn whatever they want to be
michael@0 834 * blurred onto the internal gfxContext before calling this.
michael@0 835 */
michael@0 836 void DoPaint();
michael@0 837
michael@0 838 /**
michael@0 839 * Gets the internal gfxContext at any time. Must not be freed. Avoid
michael@0 840 * calling this before calling Init() since the context would not be
michael@0 841 * constructed at that point.
michael@0 842 */
michael@0 843 gfxContext* GetContext();
michael@0 844
michael@0 845
michael@0 846 /**
michael@0 847 * Get the margin associated with the given blur radius, i.e., the
michael@0 848 * additional area that might be painted as a result of it. (The
michael@0 849 * margin for a spread radius is itself, on all sides.)
michael@0 850 */
michael@0 851 static nsMargin GetBlurRadiusMargin(nscoord aBlurRadius,
michael@0 852 int32_t aAppUnitsPerDevPixel);
michael@0 853
michael@0 854 /**
michael@0 855 * Blurs a coloured rectangle onto aDestinationCtx. This is equivalent
michael@0 856 * to calling Init(), drawing a rectangle onto the returned surface
michael@0 857 * and then calling DoPaint, but may let us optimize better in the
michael@0 858 * backend.
michael@0 859 *
michael@0 860 * @param aDestinationCtx The destination to blur to.
michael@0 861 * @param aRect The rectangle to blur in app units.
michael@0 862 * @param aAppUnitsPerDevPixel The number of app units in a device pixel,
michael@0 863 * for conversion. Most of the time you'll
michael@0 864 * pass this from the current PresContext if
michael@0 865 * available.
michael@0 866 * @param aCornerRadii Corner radii for aRect, if it is a rounded
michael@0 867 * rectangle.
michael@0 868 * @param aBlurRadius The blur radius in app units.
michael@0 869 * @param aShadowColor The color to draw the blurred shadow.
michael@0 870 * @param aDirtyRect The absolute dirty rect in app units. Used to
michael@0 871 * optimize the temporary surface size and speed up blur.
michael@0 872 * @param aSkipRect An area in device pixels (NOT app units!) to avoid
michael@0 873 * blurring over, to prevent unnecessary work.
michael@0 874 */
michael@0 875 static void BlurRectangle(gfxContext* aDestinationCtx,
michael@0 876 const nsRect& aRect,
michael@0 877 int32_t aAppUnitsPerDevPixel,
michael@0 878 gfxCornerSizes* aCornerRadii,
michael@0 879 nscoord aBlurRadius,
michael@0 880 const gfxRGBA& aShadowColor,
michael@0 881 const nsRect& aDirtyRect,
michael@0 882 const gfxRect& aSkipRect);
michael@0 883
michael@0 884 protected:
michael@0 885 gfxAlphaBoxBlur blur;
michael@0 886 nsRefPtr<gfxContext> mContext;
michael@0 887 gfxContext* mDestinationCtx;
michael@0 888
michael@0 889 /* This is true if the blur already has it's content transformed
michael@0 890 * by mDestinationCtx's transform */
michael@0 891 bool mPreTransformed;
michael@0 892
michael@0 893 };
michael@0 894
michael@0 895 #endif /* nsCSSRendering_h___ */

mercurial