Skip to content

Commit

Permalink
Add <input type=checkbox switch> macOS implementation
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=263372
rdar://117199685

Reviewed by Aditya Keerthi.

Add a macOS implementation that has these known shortcomings:

- There's no animation support.
- There's no focus support.
- There's no support for dragging the thumb.

Also correct an issue with m_hasSwitchAttribute invalidation. An early
return could be triggered when modifying the control through Web
Inspector which then resulted in the state not being updated correctly.

This builds on excellent prototyping work done by Lily Spiniolas. And
also greatly benefited from the advice and guidance of Aditya, Elika,
and Wenson.

Tests have been added in 270176@main and tests added here are upstreamed
via web-platform-tests/wpt#42945.

* LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/the-input-element/input-type-checkbox-switch.tentative.window-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/the-input-element/input-type-checkbox-switch.tentative.window.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/the-input-element/input-type-checkbox-switch.tentative.window.js: Added.
* LayoutTests/imported/w3c/web-platform-tests/html/semantics/selectors/pseudo-classes/input-checkbox-switch.tentative.window-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/semantics/selectors/pseudo-classes/input-checkbox-switch.tentative.window.js:
* Source/WebCore/Headers.cmake:
* Source/WebCore/PAL/pal/spi/mac/CoreUISPI.h:
* Source/WebCore/SourcesCocoa.txt:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/css/CSSPrimitiveValueMappings.h:
(WebCore::toCSSValueID):
* Source/WebCore/css/htmlSwitchControl.css:
(@namespace "http://www.w3.org/1999/xhtml";):
(input[type="checkbox"][switch]::thumb, input[type="checkbox"][switch]::track):
* Source/WebCore/html/CheckboxInputType.cpp:
(WebCore::CheckboxInputType::valueMissingText const):
* Source/WebCore/html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::attributeChanged):
* Source/WebCore/platform/graphics/controls/ControlFactory.h:
* Source/WebCore/platform/graphics/controls/SwitchThumbPart.h: Added.
* Source/WebCore/platform/graphics/controls/SwitchTrackPart.h: Added.
* Source/WebCore/platform/graphics/ios/controls/ControlFactoryIOS.h:
* Source/WebCore/platform/graphics/ios/controls/ControlFactoryIOS.mm:
(WebCore::ControlFactoryIOS::createPlatformSwitchThumb):
(WebCore::ControlFactoryIOS::createPlatformSwitchTrack):
* Source/WebCore/platform/graphics/mac/controls/ControlFactoryMac.h:
* Source/WebCore/platform/graphics/mac/controls/ControlFactoryMac.mm:
(WebCore::ControlFactoryMac::createPlatformSwitchThumb):
(WebCore::ControlFactoryMac::createPlatformSwitchTrack):
* Source/WebCore/platform/graphics/mac/controls/ControlMac.h:
* Source/WebCore/platform/graphics/mac/controls/ControlMac.mm:
(WebCore::ControlMac::userPrefersWithoutColorDifferentiation):
* Source/WebCore/platform/graphics/mac/controls/SwitchMacUtilities.h: Added.
* Source/WebCore/platform/graphics/mac/controls/SwitchMacUtilities.mm: Added.
(WebCore::SwitchMacUtilities::cellSize):
(WebCore::SwitchMacUtilities::cellOutsets):
(WebCore::SwitchMacUtilities::rectForBounds):
(WebCore::SwitchMacUtilities::coreUISizeForControlSize):
* Source/WebCore/platform/graphics/mac/controls/SwitchThumbMac.h: Added.
* Source/WebCore/platform/graphics/mac/controls/SwitchThumbMac.mm: Added.
(WebCore::SwitchThumbMac::SwitchThumbMac):
(WebCore::SwitchThumbMac::cellSize const):
(WebCore::SwitchThumbMac::cellOutsets const):
(WebCore::SwitchThumbMac::rectForBounds const):
(WebCore::SwitchThumbMac::draw):
* Source/WebCore/platform/graphics/mac/controls/SwitchTrackMac.h: Added.
* Source/WebCore/platform/graphics/mac/controls/SwitchTrackMac.mm: Added.
(WebCore::SwitchTrackMac::SwitchTrackMac):
(WebCore::SwitchTrackMac::cellSize const):
(WebCore::SwitchTrackMac::cellOutsets const):
(WebCore::SwitchTrackMac::rectForBounds const):
(WebCore::SwitchTrackMac::draw):
* Source/WebCore/platform/graphics/mac/controls/TextAreaMac.mm:
* Source/WebCore/platform/mac/ThemeMac.mm:
(WebCore::switchSizes):
(WebCore::switchMargins):
(WebCore::switchSize):
(WebCore::ThemeMac::controlSize const):
(WebCore::ThemeMac::inflateControlPaintRect const):
* Source/WebCore/rendering/RenderTheme.cpp:
(WebCore::RenderTheme::adjustStyle):
(WebCore::RenderTheme::autoAppearanceForElement const):
(WebCore::RenderTheme::createControlPart const):
* Source/WebCore/rendering/RenderThemeMac.mm:
(WebCore::RenderThemeMac::canPaint const):
(WebCore::RenderThemeMac::canCreateControlPartForRenderer const):
(WebCore::RenderThemeMac::adjustRepaintRect):
* Source/WebCore/style/StyleAppearance.cpp:
(WebCore::operator<<):
* Source/WebCore/style/StyleAppearance.h:
* Source/WebKit/Shared/WebCoreArgumentCoders.cpp:
(IPC::ArgumentCoder<ControlPart>::encode):
(IPC::ArgumentCoder<ControlPart>::decode):
* Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in:

Canonical link: https://commits.webkit.org/270342@main
  • Loading branch information
annevk committed Nov 7, 2023
1 parent c181ce5 commit 9ccdb74
Show file tree
Hide file tree
Showing 36 changed files with 774 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

PASS switch IDL attribute, setter
PASS switch IDL attribute, getter

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!-- This file is required for WebKit test infrastructure to run the templated test -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
test(t => {
const input = document.createElement("input");
input.switch = true;

assert_true(input.hasAttribute("switch"));
assert_equals(input.getAttribute("switch"), "");
assert_equals(input.type, "text");
}, "switch IDL attribute, setter");

test(t => {
const container = document.createElement("div");
container.innerHTML = "<input type=checkbox switch>";
const input = container.firstChild;

assert_true(input.hasAttribute("switch"));
assert_equals(input.getAttribute("switch"), "");
assert_equals(input.type, "checkbox");
assert_true(input.switch);
}, "switch IDL attribute, getter");
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ PASS Checkbox that is no longer a switch control does match :indeterminate
PASS Checkbox that becomes a switch control does not match :indeterminate
PASS Parent of a checkbox that becomes a switch control does not match :has(:indeterminate)
PASS Parent of a switch control that becomes a checkbox continues to match :has(:checked)
PASS A switch control that becomes a checkbox in a roundabout way

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ test(t => {
input.type = "checkbox";
input.switch = true;
input.indeterminate = true;

assert_false(input.matches(":indeterminate"));
}, "Switch control does not match :indeterminate");

Expand Down Expand Up @@ -60,3 +60,16 @@ test(t => {
input.checked = false;
assert_false(document.body.matches(":has(:checked)"));
}, "Parent of a switch control that becomes a checkbox continues to match :has(:checked)");

test(t => {
const input = document.body.appendChild(document.createElement("input"));
t.add_cleanup(() => input.remove());
input.type = "checkbox";
input.switch = true;
input.indeterminate = true;
assert_false(input.matches(":indeterminate"));
input.type = "text";
input.removeAttribute("switch");
input.type = "checkbox";
assert_true(input.matches(":indeterminate"));
}, "A switch control that becomes a checkbox in a roundabout way");
2 changes: 2 additions & 0 deletions Source/WebCore/Headers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2044,6 +2044,8 @@ set(WebCore_PRIVATE_FRAMEWORK_HEADERS
platform/graphics/controls/SearchFieldResultsPart.h
platform/graphics/controls/SliderThumbPart.h
platform/graphics/controls/SliderTrackPart.h
platform/graphics/controls/SwitchThumbPart.h
platform/graphics/controls/SwitchTrackPart.h
platform/graphics/controls/TextAreaPart.h
platform/graphics/controls/TextFieldPart.h
platform/graphics/controls/ToggleButtonPart.h
Expand Down
6 changes: 6 additions & 0 deletions Source/WebCore/PAL/pal/spi/mac/CoreUISPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ extern const CFStringRef kCUIStatePressed;

extern const CFStringRef kCUIUserInterfaceLayoutDirectionKey;
extern const CFStringRef kCUIUserInterfaceLayoutDirectionLeftToRight;
extern const CFStringRef kCUIUserInterfaceLayoutDirectionRightToLeft;

extern const CFStringRef kCUIValueKey;

Expand All @@ -69,5 +70,10 @@ extern const CFStringRef kCUIWidgetButtonLittleArrows;
extern const CFStringRef kCUIWidgetProgressIndeterminateBar;
extern const CFStringRef kCUIWidgetProgressBar;
extern const CFStringRef kCUIWidgetScrollBarTrackCorner;
extern const CFStringRef kCUIWidgetSwitchKnob;
extern const CFStringRef kCUIWidgetSwitchBorder;
extern const CFStringRef kCUIWidgetSwitchFill;
extern const CFStringRef kCUIWidgetSwitchFillMask;
extern const CFStringRef kCUIWidgetSwitchOnOffLabel;

#endif
3 changes: 3 additions & 0 deletions Source/WebCore/SourcesCocoa.txt
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,9 @@ platform/graphics/mac/controls/SearchFieldMac.mm
platform/graphics/mac/controls/SearchFieldResultsMac.mm
platform/graphics/mac/controls/SliderThumbMac.mm
platform/graphics/mac/controls/SliderTrackMac.mm
platform/graphics/mac/controls/SwitchMacUtilities.mm
platform/graphics/mac/controls/SwitchThumbMac.mm
platform/graphics/mac/controls/SwitchTrackMac.mm
platform/graphics/mac/controls/TextAreaMac.mm
platform/graphics/mac/controls/TextFieldMac.mm
platform/graphics/mac/controls/ToggleButtonMac.mm
Expand Down
61 changes: 41 additions & 20 deletions Source/WebCore/WebCore.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Source/WebCore/css/CSSPrimitiveValueMappings.h
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ constexpr CSSValueID toCSSValueID(StyleAppearance e)
case StyleAppearance::SearchFieldCancelButton:
case StyleAppearance::SliderThumbHorizontal:
case StyleAppearance::SliderThumbVertical:
case StyleAppearance::Switch:
case StyleAppearance::SwitchThumb:
case StyleAppearance::SwitchTrack:
ASSERT_NOT_REACHED_UNDER_CONSTEXPR_CONTEXT();
Expand Down
2 changes: 2 additions & 0 deletions Source/WebCore/css/htmlSwitchControl.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@

input[type="checkbox"][switch] {
margin: initial;
display: inline-grid;
}

input[type="checkbox"][switch]::thumb, input[type="checkbox"][switch]::track {
appearance: inherit !important;
grid-area: 1/1;
}
3 changes: 1 addition & 2 deletions Source/WebCore/html/CheckboxInputType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ bool CheckboxInputType::valueMissing(const String&) const

String CheckboxInputType::valueMissingText() const
{
ASSERT(element());
if (element()->isSwitch())
if (isSwitch())
return validationMessageValueMissingForSwitchText();
return validationMessageValueMissingForCheckboxText();
}
Expand Down
2 changes: 0 additions & 2 deletions Source/WebCore/html/HTMLInputElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -854,8 +854,6 @@ void HTMLInputElement::attributeChanged(const QualifiedName& name, const AtomStr
case AttributeNames::switchAttr:
if (document().settings().switchControlEnabled()) {
auto hasSwitchAttribute = !newValue.isNull();
if (hasSwitchAttribute == isSwitch())
return;
m_hasSwitchAttribute = hasSwitchAttribute;
if (isSwitch())
m_inputType->createShadowSubtreeIfNeeded();
Expand Down
4 changes: 4 additions & 0 deletions Source/WebCore/platform/graphics/controls/ControlFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class SearchFieldPart;
class SearchFieldResultsPart;
class SliderThumbPart;
class SliderTrackPart;
class SwitchThumbPart;
class SwitchTrackPart;
class TextAreaPart;
class TextFieldPart;
class ToggleButtonPart;
Expand Down Expand Up @@ -74,6 +76,8 @@ class ControlFactory {
virtual std::unique_ptr<PlatformControl> createPlatformSearchFieldResults(SearchFieldResultsPart&) = 0;
virtual std::unique_ptr<PlatformControl> createPlatformSliderThumb(SliderThumbPart&) = 0;
virtual std::unique_ptr<PlatformControl> createPlatformSliderTrack(SliderTrackPart&) = 0;
virtual std::unique_ptr<PlatformControl> createPlatformSwitchThumb(SwitchThumbPart&) = 0;
virtual std::unique_ptr<PlatformControl> createPlatformSwitchTrack(SwitchTrackPart&) = 0;
virtual std::unique_ptr<PlatformControl> createPlatformTextArea(TextAreaPart&) = 0;
virtual std::unique_ptr<PlatformControl> createPlatformTextField(TextFieldPart&) = 0;
virtual std::unique_ptr<PlatformControl> createPlatformToggleButton(ToggleButtonPart&) = 0;
Expand Down
51 changes: 51 additions & 0 deletions Source/WebCore/platform/graphics/controls/SwitchThumbPart.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (C) 2023 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#pragma once

#include "ControlFactory.h"
#include "ControlPart.h"

namespace WebCore {

class SwitchThumbPart final : public ControlPart {
public:
static Ref<SwitchThumbPart> create()
{
return adoptRef(*new SwitchThumbPart());
}

private:
SwitchThumbPart()
: ControlPart(StyleAppearance::SwitchThumb)
{
}

std::unique_ptr<PlatformControl> createPlatformControl() final
{
return controlFactory().createPlatformSwitchThumb(*this);
}
};

} // namespace WebCore
51 changes: 51 additions & 0 deletions Source/WebCore/platform/graphics/controls/SwitchTrackPart.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (C) 2023 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#pragma once

#include "ControlFactory.h"
#include "ControlPart.h"

namespace WebCore {

class SwitchTrackPart final : public ControlPart {
public:
static Ref<SwitchTrackPart> create()
{
return adoptRef(*new SwitchTrackPart());
}

private:
SwitchTrackPart()
: ControlPart(StyleAppearance::SwitchTrack)
{
}

std::unique_ptr<PlatformControl> createPlatformControl() final
{
return controlFactory().createPlatformSwitchTrack(*this);
}
};

} // namespace WebCore
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class ControlFactoryIOS final : public ControlFactoryCocoa {
std::unique_ptr<PlatformControl> createPlatformSearchFieldResults(SearchFieldResultsPart&) final;
std::unique_ptr<PlatformControl> createPlatformSliderThumb(SliderThumbPart&) final;
std::unique_ptr<PlatformControl> createPlatformSliderTrack(SliderTrackPart&) final;
std::unique_ptr<PlatformControl> createPlatformSwitchThumb(SwitchThumbPart&) final;
std::unique_ptr<PlatformControl> createPlatformSwitchTrack(SwitchTrackPart&) final;
std::unique_ptr<PlatformControl> createPlatformTextArea(TextAreaPart&) final;
std::unique_ptr<PlatformControl> createPlatformTextField(TextFieldPart&) final;
std::unique_ptr<PlatformControl> createPlatformToggleButton(ToggleButtonPart&) final;
Expand Down
12 changes: 12 additions & 0 deletions Source/WebCore/platform/graphics/ios/controls/ControlFactoryIOS.mm
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,18 @@
return nullptr;
}

std::unique_ptr<PlatformControl> ControlFactoryIOS::createPlatformSwitchThumb(SwitchThumbPart&)
{
notImplemented();
return nullptr;
}

std::unique_ptr<PlatformControl> ControlFactoryIOS::createPlatformSwitchTrack(SwitchTrackPart&)
{
notImplemented();
return nullptr;
}

std::unique_ptr<PlatformControl> ControlFactoryIOS::createPlatformTextArea(TextAreaPart&)
{
notImplemented();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class ControlFactoryMac final : public ControlFactoryCocoa {
std::unique_ptr<PlatformControl> createPlatformSearchFieldResults(SearchFieldResultsPart&) final;
std::unique_ptr<PlatformControl> createPlatformSliderThumb(SliderThumbPart&) final;
std::unique_ptr<PlatformControl> createPlatformSliderTrack(SliderTrackPart&) final;
std::unique_ptr<PlatformControl> createPlatformSwitchThumb(SwitchThumbPart&) final;
std::unique_ptr<PlatformControl> createPlatformSwitchTrack(SwitchTrackPart&) final;
std::unique_ptr<PlatformControl> createPlatformTextArea(TextAreaPart&) final;
std::unique_ptr<PlatformControl> createPlatformTextField(TextFieldPart&) final;
std::unique_ptr<PlatformControl> createPlatformToggleButton(ToggleButtonPart&) final;
Expand Down
12 changes: 12 additions & 0 deletions Source/WebCore/platform/graphics/mac/controls/ControlFactoryMac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
#import "SearchFieldResultsPart.h"
#import "SliderThumbMac.h"
#import "SliderTrackMac.h"
#import "SwitchThumbMac.h"
#import "SwitchTrackMac.h"
#import "TextAreaMac.h"
#import "TextFieldMac.h"
#import "ToggleButtonMac.h"
Expand Down Expand Up @@ -295,6 +297,16 @@
return makeUnique<SliderTrackMac>(part, *this);
}

std::unique_ptr<PlatformControl> ControlFactoryMac::createPlatformSwitchThumb(SwitchThumbPart& part)
{
return makeUnique<SwitchThumbMac>(part, *this);
}

std::unique_ptr<PlatformControl> ControlFactoryMac::createPlatformSwitchTrack(SwitchTrackPart& part)
{
return makeUnique<SwitchTrackMac>(part, *this);
}

std::unique_ptr<PlatformControl> ControlFactoryMac::createPlatformTextArea(TextAreaPart& part)
{
return makeUnique<TextAreaMac>(part);
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/platform/graphics/mac/controls/ControlMac.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class ControlMac : public PlatformControl {

protected:
static bool userPrefersContrast();
static bool userPrefersWithoutColorDifferentiation();
static FloatRect inflatedRect(const FloatRect& bounds, const FloatSize&, const IntOutsets&, const ControlStyle&);

static void updateCheckedState(NSCell *, const ControlStyle&);
Expand Down
5 changes: 5 additions & 0 deletions Source/WebCore/platform/graphics/mac/controls/ControlMac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@
return [[NSWorkspace sharedWorkspace] accessibilityDisplayShouldIncreaseContrast];
}

bool ControlMac::userPrefersWithoutColorDifferentiation()
{
return [[NSWorkspace sharedWorkspace] accessibilityDisplayShouldDifferentiateWithoutColor];
}

FloatRect ControlMac::inflatedRect(const FloatRect& bounds, const FloatSize& size, const IntOutsets& outsets, const ControlStyle& style)
{
auto scaledOutsets = FloatBoxExtent {
Expand Down
38 changes: 38 additions & 0 deletions Source/WebCore/platform/graphics/mac/controls/SwitchMacUtilities.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (C) 2023 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#pragma once

#if PLATFORM(MAC)

namespace WebCore::SwitchMacUtilities {

static IntSize cellSize(NSControlSize);
static IntOutsets cellOutsets(NSControlSize);
static FloatRect rectForBounds(const FloatRect&);
static NSString *coreUISizeForControlSize(const NSControlSize);

} // namespace WebCore::SwitchMacUtilities

#endif // PLATFORM(MAC)
Loading

0 comments on commit 9ccdb74

Please sign in to comment.