-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add <input type=checkbox switch> macOS implementation
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
Showing
36 changed files
with
774 additions
and
29 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
...emantics/forms/the-input-element/input-type-checkbox-switch.tentative.window-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
PASS switch IDL attribute, setter | ||
PASS switch IDL attribute, getter | ||
|
1 change: 1 addition & 0 deletions
1
...s/html/semantics/forms/the-input-element/input-type-checkbox-switch.tentative.window.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 --> |
19 changes: 19 additions & 0 deletions
19
...sts/html/semantics/forms/the-input-element/input-type-checkbox-switch.tentative.window.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
Source/WebCore/platform/graphics/controls/SwitchThumbPart.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
51
Source/WebCore/platform/graphics/controls/SwitchTrackPart.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
Source/WebCore/platform/graphics/mac/controls/SwitchMacUtilities.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Oops, something went wrong.