summaryrefslogtreecommitdiffstats
path: root/widget/cocoa/nsNativeBasicThemeCocoa.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--widget/cocoa/nsNativeBasicThemeCocoa.cpp109
1 files changed, 109 insertions, 0 deletions
diff --git a/widget/cocoa/nsNativeBasicThemeCocoa.cpp b/widget/cocoa/nsNativeBasicThemeCocoa.cpp
new file mode 100644
index 0000000000..c6efa2e7d9
--- /dev/null
+++ b/widget/cocoa/nsNativeBasicThemeCocoa.cpp
@@ -0,0 +1,109 @@
+/* -*- Mode: C++; tab-width: 40; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "nsNativeBasicThemeCocoa.h"
+#include "mozilla/gfx/Helpers.h"
+
+already_AddRefed<nsITheme> do_GetBasicNativeThemeDoNotUseDirectly() {
+ static mozilla::StaticRefPtr<nsITheme> gInstance;
+ if (MOZ_UNLIKELY(!gInstance)) {
+ gInstance = new nsNativeBasicThemeCocoa();
+ ClearOnShutdown(&gInstance);
+ }
+ return do_AddRef(gInstance);
+}
+
+NS_IMETHODIMP
+nsNativeBasicThemeCocoa::GetMinimumWidgetSize(
+ nsPresContext* aPresContext, nsIFrame* aFrame, StyleAppearance aAppearance,
+ mozilla::LayoutDeviceIntSize* aResult, bool* aIsOverridable) {
+ DPIRatio dpiRatio = GetDPIRatio(aFrame);
+
+ switch (aAppearance) {
+ case StyleAppearance::ScrollbarthumbHorizontal:
+ case StyleAppearance::ScrollbarthumbVertical:
+ case StyleAppearance::ScrollbarHorizontal:
+ case StyleAppearance::ScrollbarVertical:
+ case StyleAppearance::ScrollbartrackVertical:
+ case StyleAppearance::ScrollbartrackHorizontal:
+ case StyleAppearance::ScrollbarbuttonUp:
+ case StyleAppearance::ScrollbarbuttonDown:
+ case StyleAppearance::ScrollbarbuttonLeft:
+ case StyleAppearance::ScrollbarbuttonRight: {
+ *aIsOverridable = false;
+ *aResult = ScrollbarDrawingMac::GetMinimumWidgetSize(aAppearance, aFrame,
+ dpiRatio.scale);
+ break;
+ }
+
+ default:
+ return nsNativeBasicTheme::GetMinimumWidgetSize(
+ aPresContext, aFrame, aAppearance, aResult, aIsOverridable);
+ }
+
+ return NS_OK;
+}
+
+void nsNativeBasicThemeCocoa::PaintScrollbarThumb(
+ DrawTarget* aDrawTarget, const LayoutDeviceRect& aRect, bool aHorizontal,
+ nsIFrame* aFrame, const ComputedStyle& aStyle,
+ const EventStates& aElementState, const EventStates& aDocumentState,
+ DPIRatio aDpiRatio) {
+ ScrollbarParams params =
+ ScrollbarDrawingMac::ComputeScrollbarParams(aFrame, aStyle, aHorizontal);
+ auto rect = aRect.ToUnknownRect();
+ if (aDpiRatio.scale >= 2.0f) {
+ mozilla::gfx::AutoRestoreTransform autoRestoreTransform(aDrawTarget);
+ aDrawTarget->SetTransform(aDrawTarget->GetTransform().PreScale(2.0f, 2.0f));
+ rect.Scale(1.0f / 2.0f);
+ ScrollbarDrawingMac::DrawScrollbarThumb(*aDrawTarget, rect, params);
+ } else {
+ ScrollbarDrawingMac::DrawScrollbarThumb(*aDrawTarget, rect, params);
+ }
+}
+
+void nsNativeBasicThemeCocoa::PaintScrollbarTrack(
+ DrawTarget* aDrawTarget, const LayoutDeviceRect& aRect, bool aHorizontal,
+ nsIFrame* aFrame, const ComputedStyle& aStyle,
+ const EventStates& aDocumentState, DPIRatio aDpiRatio, bool aIsRoot) {
+ ScrollbarParams params =
+ ScrollbarDrawingMac::ComputeScrollbarParams(aFrame, aStyle, aHorizontal);
+ auto rect = aRect.ToUnknownRect();
+ if (aDpiRatio.scale >= 2.0f) {
+ mozilla::gfx::AutoRestoreTransform autoRestoreTransform(aDrawTarget);
+ aDrawTarget->SetTransform(aDrawTarget->GetTransform().PreScale(2.0f, 2.0f));
+ rect.Scale(1.0f / 2.0f);
+ ScrollbarDrawingMac::DrawScrollbarTrack(*aDrawTarget, rect, params);
+ } else {
+ ScrollbarDrawingMac::DrawScrollbarTrack(*aDrawTarget, rect, params);
+ }
+}
+
+void nsNativeBasicThemeCocoa::PaintScrollbar(DrawTarget* aDrawTarget,
+ const LayoutDeviceRect& aRect,
+ bool aHorizontal, nsIFrame* aFrame,
+ const ComputedStyle& aStyle,
+ const EventStates& aDocumentState,
+ DPIRatio aDpiRatio, bool aIsRoot) {
+ // Draw nothing; the scrollbar track is drawn in PaintScrollbarTrack.
+}
+
+void nsNativeBasicThemeCocoa::PaintScrollCorner(
+ DrawTarget* aDrawTarget, const LayoutDeviceRect& aRect, nsIFrame* aFrame,
+ const ComputedStyle& aStyle, const EventStates& aDocumentState,
+ DPIRatio aDpiRatio, bool aIsRoot) {
+ ScrollbarParams params =
+ ScrollbarDrawingMac::ComputeScrollbarParams(aFrame, aStyle, false);
+ if (aDpiRatio.scale >= 2.0f) {
+ mozilla::gfx::AutoRestoreTransform autoRestoreTransform(aDrawTarget);
+ aDrawTarget->SetTransform(aDrawTarget->GetTransform().PreScale(2.0f, 2.0f));
+ auto rect = aRect.ToUnknownRect();
+ rect.Scale(1 / 2.0f);
+ ScrollbarDrawingMac::DrawScrollCorner(*aDrawTarget, rect, params);
+ } else {
+ auto rect = aRect.ToUnknownRect();
+ ScrollbarDrawingMac::DrawScrollCorner(*aDrawTarget, rect, params);
+ }
+}