Bug 1777562 [wpt PR 34663] - [FedCM] Rename FederatedCredential to IdentityCredential...
[gecko.git] / widget / gtk / nsNativeThemeGTK.h
blob7a710f20a3d65bcaabb87e33d1070cd9133feda0
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef _GTK_NSNATIVETHEMEGTK_H_
7 #define _GTK_NSNATIVETHEMEGTK_H_
9 #include "nsITheme.h"
10 #include "nsCOMPtr.h"
11 #include "nsAtom.h"
12 #include "Theme.h"
14 #include <gtk/gtk.h>
15 #include "gtkdrawing.h"
17 class nsNativeThemeGTK final : public mozilla::widget::Theme {
18 using Theme = mozilla::widget::Theme;
20 public:
21 // The nsITheme interface.
22 NS_IMETHOD DrawWidgetBackground(gfxContext* aContext, nsIFrame* aFrame,
23 StyleAppearance aAppearance,
24 const nsRect& aRect, const nsRect& aDirtyRect,
25 DrawOverflow) override;
27 bool CreateWebRenderCommandsForWidget(
28 mozilla::wr::DisplayListBuilder& aBuilder,
29 mozilla::wr::IpcResourceUpdateQueue& aResources,
30 const mozilla::layers::StackingContextHelper& aSc,
31 mozilla::layers::RenderRootStateManager* aManager, nsIFrame*,
32 StyleAppearance, const nsRect& aRect) override;
34 [[nodiscard]] LayoutDeviceIntMargin GetWidgetBorder(
35 nsDeviceContext* aContext, nsIFrame* aFrame,
36 StyleAppearance aAppearance) override;
38 bool GetWidgetPadding(nsDeviceContext* aContext, nsIFrame* aFrame,
39 StyleAppearance aAppearance,
40 LayoutDeviceIntMargin* aResult) override;
42 bool GetWidgetOverflow(nsDeviceContext* aContext, nsIFrame* aFrame,
43 StyleAppearance aAppearance,
44 nsRect* aOverflowRect) override;
46 // Whether we draw a non-native widget.
48 // We always draw scrollbars as non-native so that all of Firefox has
49 // consistent scrollbar styles both in chrome and content (plus, the
50 // non-native scrollbars support scrollbar-width, auto-darkening...).
52 // We draw other widgets as non-native when their color-scheme doesn't match
53 // the current GTK theme's color-scheme. We do that because frequently
54 // switching GTK themes at runtime is prohibitively expensive. In that case
55 // (`BecauseColorMismatch`) we don't call into the non-native theme for sizing
56 // information (GetWidgetPadding/Border and GetMinimumWidgetSize), to avoid
57 // subtle sizing changes. The non-native theme can basically draw at any size,
58 // so we prefer to have consistent sizing information.
59 enum class NonNative { No, Always, BecauseColorMismatch };
60 NonNative IsWidgetNonNative(nsIFrame*, StyleAppearance);
62 NS_IMETHOD GetMinimumWidgetSize(nsPresContext* aPresContext, nsIFrame* aFrame,
63 StyleAppearance aAppearance,
64 mozilla::LayoutDeviceIntSize* aResult,
65 bool* aIsOverridable) override;
67 NS_IMETHOD WidgetStateChanged(nsIFrame* aFrame, StyleAppearance aAppearance,
68 nsAtom* aAttribute, bool* aShouldRepaint,
69 const nsAttrValue* aOldValue) override;
71 NS_IMETHOD ThemeChanged() override;
73 NS_IMETHOD_(bool)
74 ThemeSupportsWidget(nsPresContext* aPresContext, nsIFrame* aFrame,
75 StyleAppearance aAppearance) override;
77 NS_IMETHOD_(bool) WidgetIsContainer(StyleAppearance aAppearance) override;
79 bool ThemeDrawsFocusForWidget(nsIFrame*, StyleAppearance) override;
81 bool ThemeNeedsComboboxDropmarker() override;
82 Transparency GetWidgetTransparency(nsIFrame*, StyleAppearance) override;
84 nsNativeThemeGTK();
86 protected:
87 virtual ~nsNativeThemeGTK();
89 private:
90 GtkTextDirection GetTextDirection(nsIFrame* aFrame);
91 gint GetTabMarginPixels(nsIFrame* aFrame);
92 bool GetGtkWidgetAndState(StyleAppearance aAppearance, nsIFrame* aFrame,
93 WidgetNodeType& aGtkWidgetType,
94 GtkWidgetState* aState, gint* aWidgetFlags);
95 bool GetExtraSizeForWidget(nsIFrame* aFrame, StyleAppearance aAppearance,
96 nsIntMargin* aExtra);
97 bool IsWidgetVisible(StyleAppearance aAppearance);
99 void RefreshWidgetWindow(nsIFrame* aFrame);
100 WidgetNodeType NativeThemeToGtkTheme(StyleAppearance aAppearance,
101 nsIFrame* aFrame);
103 uint8_t mDisabledWidgetTypes
104 [(static_cast<size_t>(mozilla::StyleAppearance::Count) + 7) / 8];
105 uint8_t
106 mSafeWidgetStates[static_cast<size_t>(mozilla::StyleAppearance::Count) *
107 4]; // 32 bits per widget
108 static const char* sDisabledEngines[];
110 // Because moz_gtk_get_widget_border can be slow, we cache its results
111 // by widget type. Each bit in mBorderCacheValid says whether the
112 // corresponding entry in mBorderCache is valid.
113 void GetCachedWidgetBorder(nsIFrame* aFrame, StyleAppearance aAppearance,
114 GtkTextDirection aDirection,
115 LayoutDeviceIntMargin* aResult);
116 uint8_t mBorderCacheValid[(MOZ_GTK_WIDGET_NODE_COUNT + 7) / 8];
117 LayoutDeviceIntMargin mBorderCache[MOZ_GTK_WIDGET_NODE_COUNT];
120 #endif