Backed out 3 changesets (bug 1870106, bug 1845276) for causing doc generate failures...
[gecko.git] / widget / gtk / nsNativeThemeGTK.h
blob2d0878290ead93a5501dd7aa29b45baf88eaf5f3
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 static bool IsWidgetAlwaysNonNative(nsIFrame*, StyleAppearance);
61 NonNative IsWidgetNonNative(nsIFrame*, StyleAppearance);
63 mozilla::LayoutDeviceIntSize GetMinimumWidgetSize(
64 nsPresContext* aPresContext, nsIFrame* aFrame,
65 StyleAppearance aAppearance) 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 mozilla::CSSIntMargin GetExtraSizeForWidget(nsIFrame*, StyleAppearance);
96 bool IsWidgetVisible(StyleAppearance aAppearance);
98 void RefreshWidgetWindow(nsIFrame* aFrame);
99 WidgetNodeType NativeThemeToGtkTheme(StyleAppearance aAppearance,
100 nsIFrame* aFrame);
102 uint8_t mDisabledWidgetTypes
103 [(static_cast<size_t>(mozilla::StyleAppearance::Count) + 7) / 8];
104 uint8_t
105 mSafeWidgetStates[static_cast<size_t>(mozilla::StyleAppearance::Count) *
106 4]; // 32 bits per widget
107 static const char* sDisabledEngines[];
109 // Because moz_gtk_get_widget_border can be slow, we cache its results
110 // by widget type. Each bit in mBorderCacheValid says whether the
111 // corresponding entry in mBorderCache is valid.
112 mozilla::CSSIntMargin GetCachedWidgetBorder(nsIFrame* aFrame,
113 StyleAppearance aAppearance,
114 GtkTextDirection aDirection);
115 uint8_t mBorderCacheValid[(MOZ_GTK_WIDGET_NODE_COUNT + 7) / 8];
116 mozilla::CSSIntMargin mBorderCache[MOZ_GTK_WIDGET_NODE_COUNT];
119 #endif