Bug 1931748. Fix some readability-else-after-return issues in layout code. r=jfkthame
[gecko.git] / widget / ThemeDrawing.h
blob469c29ea2fd63d864f84425b9940221e292cdb55
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 #ifndef mozilla_widget_ThemeDrawing_h
8 #define mozilla_widget_ThemeDrawing_h
10 #include "mozilla/layers/IpcResourceUpdateQueue.h"
11 #include "mozilla/layers/RenderRootStateManager.h"
12 #include "mozilla/layers/StackingContextHelper.h"
13 #include "RetainedDisplayListBuilder.h"
15 namespace mozilla::widget {
17 struct WebRenderBackendData {
18 wr::DisplayListBuilder& mBuilder;
19 wr::IpcResourceUpdateQueue& mResources;
20 const layers::StackingContextHelper& mSc;
21 layers::RenderRootStateManager* mManager;
24 class ThemeDrawing {
25 protected:
26 using DrawTarget = gfx::DrawTarget;
27 using sRGBColor = gfx::sRGBColor;
28 using DPIRatio = CSSToLayoutDeviceScale;
30 public:
31 virtual ~ThemeDrawing() = 0;
33 static void FillRect(DrawTarget&, const LayoutDeviceRect&, const sRGBColor&);
34 static void FillRect(WebRenderBackendData&, const LayoutDeviceRect&,
35 const sRGBColor&);
37 // Returns the right scale for points in a aSize x aSize sized box, centered
38 // at 0x0 to fill aRect in the smaller dimension.
39 static float ScaleToFillRect(const LayoutDeviceRect& aRect,
40 const float& aSize) {
41 return std::min(aRect.width, aRect.height) / aSize;
44 static LayoutDeviceIntCoord SnapBorderWidth(const CSSCoord& aCssWidth,
45 const DPIRatio& aDpiRatio);
47 static void PaintArrow(DrawTarget&, const LayoutDeviceRect&,
48 const float aArrowPolygonX[],
49 const float aArrowPolygonY[],
50 const float aArrowPolygonSize,
51 const int32_t aArrowNumPoints,
52 const sRGBColor aFillColor);
54 static void PaintRoundedRectWithRadius(
55 DrawTarget&, const LayoutDeviceRect& aRect,
56 const LayoutDeviceRect& aClipRect, const sRGBColor& aBackgroundColor,
57 const sRGBColor& aBorderColor, const CSSCoord& aBorderWidth,
58 const CSSCoord& aRadius, const DPIRatio&);
59 static void PaintRoundedRectWithRadius(
60 WebRenderBackendData&, const LayoutDeviceRect& aRect,
61 const LayoutDeviceRect& aClipRect, const sRGBColor& aBackgroundColor,
62 const sRGBColor& aBorderColor, const CSSCoord& aBorderWidth,
63 const CSSCoord& aRadius, const DPIRatio&);
64 template <typename PaintBackendData>
65 static void PaintRoundedRectWithRadius(PaintBackendData& aData,
66 const LayoutDeviceRect& aRect,
67 const sRGBColor& aBackgroundColor,
68 const sRGBColor& aBorderColor,
69 const CSSCoord& aBorderWidth,
70 const CSSCoord& aRadius,
71 const DPIRatio& aDpiRatio) {
72 PaintRoundedRectWithRadius(aData, aRect, aRect, aBackgroundColor,
73 aBorderColor, aBorderWidth, aRadius, aDpiRatio);
77 } // namespace mozilla::widget
79 #endif