Title: [295147] trunk/Source
Revision
295147
Author
pan...@apple.com
Date
2022-06-02 14:43:23 -0700 (Thu, 02 Jun 2022)

Log Message

Web Inspector: Color picker should allow picking a color from any pixel on screen
https://bugs.webkit.org/show_bug.cgi?id=124357
rdar://15469621

Reviewed by Devin Rousso.

Add the long-missing "eyedropper" for picking a color from the screen to the Color Picker in Web Inspector. This
implementation supports both sRGB color space as well as Display P3 (the two colorspaces currently supported by the Web
Inspector frontend). The existing value format and gamut is preserved as best as possible while not clamping the color
(unless interacting with a color swatch/picker that does not allow changing the format). For example, on macOS the color
picker will return a Display-P3 color on supported displays, but the color itself may be representable in sRGB. If the
existing color you are overwriting is already in sRGB, that is preserved by converting the system's Display-P3 color
into sRGB. If the sampled color can not be represented in sRGB, we update the CSS value to support the new wider gamut
of the selected color in order to provide the best fidelity in color matching.

The picker is implemented in two places. The first is the Color Picker popovers used in Web Inspector. The second place
is as an Option-Click action for inline swatches to allow you to quickly begin color selection without opening the
picker itself.

* Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js:
* Source/WebInspectorUI/UserInterface/Images/Pipette.svg: Added.

* Source/WebInspectorUI/UserInterface/Models/Color.js:
(WI.Color.prototype.fromStringBestMatchingSuggestedFormatAndGamut):
- New convencience "constructor" for creating a color from a String while attempting (or forcing) preservation of an
existing format and gamut.

* Source/WebInspectorUI/UserInterface/Views/ColorPicker.css:
(.color-picker > .color-inputs-wrapper):
(.color-picker > .color-inputs-wrapper > .color-inputs):
(.color-picker > .color-inputs-wrapper > .color-inputs > div):
(.color-picker > .color-inputs-wrapper > .color-inputs > div + div):
(.color-picker > .color-inputs-wrapper > .color-inputs input):
(.color-picker > .color-inputs-wrapper > .pick-color-from-screen):
(.color-picker > .color-inputs-wrapper > .pick-color-from-screen.active):
(.color-picker > .color-inputs): Deleted.
(.color-picker > .color-inputs > div): Deleted.
(.color-picker > .color-inputs > div + div): Deleted.
(.color-picker > .color-inputs input): Deleted.
* Source/WebInspectorUI/UserInterface/Views/ColorPicker.js:
(WI.ColorPicker.async pickColorFromScreen):
- Add new static method to picking a color from the screen (so that InlineSwatch can use it), and add a new Pipette icon
to begin the modal color picking mode.

* Source/WebInspectorUI/UserInterface/Views/InlineSwatch.js:
(WI.InlineSwatch.prototype._updateSwatch):
- Add Option-Click for color swatches to immediately enter the modal color picking mode.

* Source/WebCore/inspector/InspectorFrontendClient.h:
* Source/WebCore/inspector/InspectorFrontendClientLocal.h:
* Source/WebCore/inspector/InspectorFrontendHost.cpp:
(WebCore::InspectorFrontendHost::canPickColorFromScreen):
(WebCore::InspectorFrontendHost::pickColorFromScreen):
* Source/WebCore/inspector/InspectorFrontendHost.h:
* Source/WebCore/inspector/InspectorFrontendHost.idl:
* Source/WebKit/UIProcess/Inspector/RemoteWebInspectorUIProxy.cpp:
(WebKit::RemoteWebInspectorUIProxy::pickColorFromScreen):
(WebKit::RemoteWebInspectorUIProxy::platformPickColorFromScreen):
* Source/WebKit/UIProcess/Inspector/RemoteWebInspectorUIProxy.h:
* Source/WebKit/UIProcess/Inspector/RemoteWebInspectorUIProxy.messages.in:
* Source/WebKit/UIProcess/Inspector/WebInspectorUIProxy.cpp:
(WebKit::WebInspectorUIProxy::pickColorFromScreen):
(WebKit::WebInspectorUIProxy::platformPickColorFromScreen):
* Source/WebKit/UIProcess/Inspector/WebInspectorUIProxy.h:
* Source/WebKit/UIProcess/Inspector/WebInspectorUIProxy.messages.in:
* Source/WebKit/WebProcess/Inspector/RemoteWebInspectorUI.cpp:
(WebKit::RemoteWebInspectorUI::pickColorFromScreen):
* Source/WebKit/WebProcess/Inspector/RemoteWebInspectorUI.h:
* Source/WebKit/WebProcess/Inspector/WebInspectorUI.cpp:
(WebKit::WebInspectorUI::pickColorFromScreen):
(WebKit::WebInspectorUI::canPickColorFromScreen):
* Source/WebKit/WebProcess/Inspector/WebInspectorUI.h:
- Add plubming for picking a color from the screen.

* Source/WebKit/UIProcess/Inspector/mac/RemoteWebInspectorUIProxyMac.mm:
(WebKit::RemoteWebInspectorUIProxy::platformPickColorFromScreen):
* Source/WebKit/UIProcess/Inspector/mac/WebInspectorUIProxyMac.mm:
(WebKit::WebInspectorUIProxy::platformPickColorFromScreen):
- Use NSColorSampler to get the system "pick a color from the screen" UI.

* Source/WebKit/UIProcess/Inspector/gtk/RemoteWebInspectorUIProxyGtk.cpp:
(WebKit::RemoteWebInspectorUIProxy::platformPickColorFromScreen):
* Source/WebKit/UIProcess/Inspector/gtk/WebInspectorUIProxyGtk.cpp:
(WebKit::WebInspectorUIProxy::platformPickColorFromScreen):
* Source/WebKit/UIProcess/Inspector/win/RemoteWebInspectorUIProxyWin.cpp:
(WebKit::RemoteWebInspectorUIProxy::platformPickColorFromScreen):
* Source/WebKit/UIProcess/Inspector/win/WebInspectorUIProxyWin.cpp:
(WebKit::WebInspectorUIProxy::platformPickColorFromScreen):
* Source/WebKit/WebProcess/Inspector/gtk/WebInspectorUIGtk.cpp:
(WebKit::WebInspectorUI::canPickColorFromScreen):
* Source/WebKit/WebProcess/Inspector/mac/WebInspectorUIMac.mm:
(WebKit::WebInspectorUI::canPickColorFromScreen):
* Source/WebKit/WebProcess/Inspector/win/WebInspectorUIWin.cpp:
(WebKit::WebInspectorUI::canPickColorFromScreen):
- Add stubs for Windows/GTK implementations.

Canonical link: https://commits.webkit.org/251236@main

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/inspector/InspectorFrontendClient.h (295146 => 295147)


--- trunk/Source/WebCore/inspector/InspectorFrontendClient.h	2022-06-02 21:33:24 UTC (rev 295146)
+++ trunk/Source/WebCore/inspector/InspectorFrontendClient.h	2022-06-02 21:43:23 UTC (rev 295147)
@@ -32,6 +32,7 @@
 #pragma once
 
 #include "CertificateInfo.h"
+#include "Color.h"
 #include "DiagnosticLoggingClient.h"
 #include "FrameIdentifier.h"
 #include "InspectorDebuggableType.h"
@@ -113,6 +114,9 @@
     virtual bool canLoad() = 0;
     virtual void load(const String& path, CompletionHandler<void(const String&)>&&) = 0;
 
+    virtual bool canPickColorFromScreen() = 0;
+    virtual void pickColorFromScreen(CompletionHandler<void(const std::optional<WebCore::Color>&)>&&) = 0;
+
     virtual void inspectedURLChanged(const String&) = 0;
     virtual void showCertificate(const CertificateInfo&) = 0;
 

Modified: trunk/Source/WebCore/inspector/InspectorFrontendClientLocal.h (295146 => 295147)


--- trunk/Source/WebCore/inspector/InspectorFrontendClientLocal.h	2022-06-02 21:33:24 UTC (rev 295146)
+++ trunk/Source/WebCore/inspector/InspectorFrontendClientLocal.h	2022-06-02 21:43:23 UTC (rev 295147)
@@ -39,6 +39,7 @@
 
 namespace WebCore {
 
+class Color;
 class FloatRect;
 class Frame;
 class InspectorController;
@@ -87,6 +88,9 @@
     bool canLoad()  override { return false; }
     void load(const String&, CompletionHandler<void(const String&)>&& completionHandler) override { completionHandler(nullString()); }
 
+    bool canPickColorFromScreen() override { return false; }
+    void pickColorFromScreen(CompletionHandler<void(const std::optional<WebCore::Color>&)>&& completionHandler) override { completionHandler({ }); }
+
     virtual void attachWindow(DockSide) = 0;
     virtual void detachWindow() = 0;
 

Modified: trunk/Source/WebCore/inspector/InspectorFrontendHost.cpp (295146 => 295147)


--- trunk/Source/WebCore/inspector/InspectorFrontendHost.cpp	2022-06-02 21:33:24 UTC (rev 295146)
+++ trunk/Source/WebCore/inspector/InspectorFrontendHost.cpp	2022-06-02 21:43:23 UTC (rev 295147)
@@ -31,6 +31,9 @@
 #include "InspectorFrontendHost.h"
 
 #include "CertificateInfo.h"
+#include "ColorConversion.h"
+#include "ColorSerialization.h"
+#include "ColorSpace.h"
 #include "ContextMenu.h"
 #include "ContextMenuController.h"
 #include "ContextMenuItem.h"
@@ -494,6 +497,40 @@
     });
 }
 
+bool InspectorFrontendHost::canPickColorFromScreen()
+{
+    if (m_client)
+        return m_client->canPickColorFromScreen();
+    return false;
+}
+
+void InspectorFrontendHost::pickColorFromScreen(Ref<DeferredPromise>&& promise)
+{
+    if (!m_client) {
+        promise->reject(InvalidStateError);
+        return;
+    }
+
+    m_client->pickColorFromScreen([promise = WTFMove(promise)](const std::optional<WebCore::Color>& color) {
+        if (!color) {
+            promise->resolve();
+            return;
+        }
+
+        String serializedColor;
+        // FIXME: <webkit.org/b/241198> Inspector frontend should support all color function gamuts.
+        if (color->colorSpace() != ColorSpace::SRGB || color->colorSpace() != ColorSpace::DisplayP3) {
+            // DisplayP3 is the least-lossy format the frontend currently supports. This conversion will only be lossy
+            // if the color space the system is providing colors in were to support a wider gamut than DisplayP3.
+            auto colorForFrontend = color->toColorTypeLossy<DisplayP3<float>>();
+            serializedColor = serializationForCSS(colorForFrontend);
+        } else
+            serializedColor = serializationForCSS(*color);
+
+        promise->resolve<IDLDOMString>(serializedColor);
+    });
+}
+
 void InspectorFrontendHost::close(const String&)
 {
 }

Modified: trunk/Source/WebCore/inspector/InspectorFrontendHost.h (295146 => 295147)


--- trunk/Source/WebCore/inspector/InspectorFrontendHost.h	2022-06-02 21:33:24 UTC (rev 295146)
+++ trunk/Source/WebCore/inspector/InspectorFrontendHost.h	2022-06-02 21:43:23 UTC (rev 295147)
@@ -116,6 +116,9 @@
     void load(const String& path, Ref<DeferredPromise>&&);
     void close(const String& url);
 
+    bool canPickColorFromScreen();
+    void pickColorFromScreen(Ref<DeferredPromise>&&);
+
     String getPath(const File&);
 
     struct ContextMenuItem {

Modified: trunk/Source/WebCore/inspector/InspectorFrontendHost.idl (295146 => 295147)


--- trunk/Source/WebCore/inspector/InspectorFrontendHost.idl	2022-06-02 21:33:24 UTC (rev 295146)
+++ trunk/Source/WebCore/inspector/InspectorFrontendHost.idl	2022-06-02 21:43:23 UTC (rev 295147)
@@ -79,6 +79,9 @@
     [NewObject] Promise<DOMString> load(DOMString path);
     undefined close(DOMString url);
 
+    boolean canPickColorFromScreen();
+    [NewObject] Promise<DOMString> pickColorFromScreen();
+
     DOMString getPath(File file);
 
     readonly attribute DOMString port;

Modified: trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js (295146 => 295147)


--- trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js	2022-06-02 21:33:24 UTC (rev 295146)
+++ trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js	2022-06-02 21:43:23 UTC (rev 295147)
@@ -333,8 +333,7 @@
 localizedStrings["Click to import a file and create a Local Override\nShift-click to create a Local Override from this content"] = "Click to import a file and create a Local Override\nShift-click to create a Local Override from this content";
 /* Title of text button that resets the gesture controls in the image resource content view. */
 localizedStrings["Click to reset @ Image Resource Content View Gesture Controls"] = "Click to reset";
-localizedStrings["Click to select a color"] = "Click to select a color";
-localizedStrings["Click to select a color\nShift-click to switch color formats"] = "Click to select a color\nShift-click to switch color formats";
+localizedStrings["Click to select a color."] = "Click to select a color.";
 localizedStrings["Click to show %d error in the Console"] = "Click to show %d error in the Console";
 localizedStrings["Click to show %d errors in the Console"] = "Click to show %d errors in the Console";
 localizedStrings["Click to show %d warning in the Console"] = "Click to show %d warning in the Console";
@@ -1071,6 +1070,7 @@
 localizedStrings["Open closed tabs\u2026"] = "Open closed tabs\u2026";
 /* Context menu item for opening the target item in a new window. */
 localizedStrings["Open in New Window @ Context Menu Item"] = "Open in New Window";
+localizedStrings["Option-click to pick color from screen."] = "Option-click to pick color from screen.";
 localizedStrings["Option-click to show source"] = "Option-click to show source";
 /* Tooltip with instructions on how to show all hidden CSS variables */
 localizedStrings["Option-click to show unused CSS variables from all rules @ Styles Sidebar Panel Tooltip"] = "Option-click to show unused CSS variables from all rules";
@@ -1131,6 +1131,8 @@
 localizedStrings["Periods of high CPU utilization will rapidly drain battery. Strive to keep idle pages under %s average CPU utilization."] = "Periods of high CPU utilization will rapidly drain battery. Strive to keep idle pages under %s average CPU utilization.";
 /* Property value for `font-variant-capitals: petite-caps`. */
 localizedStrings["Petite Capitals @ Font Details Sidebar Property Value"] = "Petite Capitals";
+/* Color picker view tooltip for picking a color from the screen. */
+localizedStrings["Pick color from screen"] = "Pick color from screen";
 localizedStrings["Ping"] = "Ping";
 localizedStrings["Ping Frame"] = "Ping Frame";
 localizedStrings["Pings"] = "Pings";
@@ -1374,6 +1376,7 @@
 localizedStrings["Shadow Content"] = "Shadow Content";
 localizedStrings["Shadow Content (%s)"] = "Shadow Content (%s)";
 localizedStrings["Shared Focus"] = "Shared Focus";
+localizedStrings["Shift-click to switch color formats."] = "Shift-click to switch color formats.";
 localizedStrings["Shortest property path to %s"] = "Shortest property path to %s";
 localizedStrings["Show %d More"] = "Show %d More";
 /* Text label for button to reveal one unused CSS variable */
@@ -1805,7 +1808,7 @@
 /* Shown in the 'Type' column of the Network Table for document resources. */
 localizedStrings["document @ Network Tab Resource Type Column Value"] = "document";
 localizedStrings["ensuring that common debugging functions are available on every page via the Console"] = "ensuring that common debugging functions are available on every page via the Console";
-/* Shown in the 'Type' column of the Network Table for EventSource resources. */
+/* Shown in the 'Type' column of the Network Table for resources loaded via the EventSource API. */
 localizedStrings["eventsource @ Network Tab Resource Type Column Value"] = "eventsource";
 /* Shown in the 'Type' column of the Network Table for resources loaded via the 'fetch' method. */
 localizedStrings["fetch @ Network Tab Resource Type Column Value"] = "fetch";

Added: trunk/Source/WebInspectorUI/UserInterface/Images/Pipette.svg (0 => 295147)


--- trunk/Source/WebInspectorUI/UserInterface/Images/Pipette.svg	                        (rev 0)
+++ trunk/Source/WebInspectorUI/UserInterface/Images/Pipette.svg	2022-06-02 21:43:23 UTC (rev 295147)
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright © 2022 Apple Inc. All rights reserved. -->
+<svg xmlns="http://www.w3.org/2000/svg" id="root" version="1.1" viewBox="0 0 16 16">
+    <path fill="currentColor" d="M10.194,6.702l-6.952,6.944c-0.133,0.138 -0.28,0.221 -0.441,0.249c-0.161,0.029 -0.307,-0.029 -0.44,-0.172c-0.143,-0.153 -0.205,-0.304 -0.184,-0.452c0.02,-0.148 0.107,-0.299 0.26,-0.452l6.929,-6.96l-0.659,-0.651l-6.193,6.193c-0.475,0.475 -0.828,0.856 -1.058,1.142c-0.23,0.286 -0.391,0.521 -0.483,0.705c-0.092,0.184 -0.162,0.358 -0.21,0.521c-0.049,0.164 -0.124,0.355 -0.226,0.575c-0.103,0.22 -0.282,0.511 -0.537,0.874l0.69,0.728c0.347,-0.256 0.632,-0.429 0.854,-0.521c0.223,-0.092 0.421,-0.158 0.594,-0.196c0.174,-0.038 0.359,-0.098 0.556,-0.18c0.197,-0.082 0.445,-0.236 0.744,-0.464c0.299,-0.227 0.691,-0.581 1.176,-1.061l6.216,-6.178l-0.636,-0.644Zm1.824,1.388l0.215,-0.238c0.189,-0.194 0.285,-0.401 0.287,-0.621c0.003,-0.22 -0.096,-0.429 -0.295,-0.628l-0.23,-0.223c0.297,-0.265 0.595,-0.483 0.897,-0.651c0.301,-0.169 0.597,-0.317 0.885,-0.445c0.289,-0.127 0.561,-0.262 0.816,-0.402c0.256,-0.141 0.483,-0.313 0.683,-0.518c0.383,-0.383 0.612,-0.799
  0.686,-1.249c0.074,-0.45 0.041,-0.881 -0.1,-1.295c-0.141,-0.414 -0.346,-0.754 -0.617,-1.02c-0.266,-0.27 -0.603,-0.475 -1.012,-0.613c-0.409,-0.138 -0.839,-0.168 -1.291,-0.092c-0.452,0.077 -0.873,0.302 -1.261,0.675c-0.21,0.199 -0.383,0.426 -0.521,0.682c-0.138,0.255 -0.272,0.528 -0.403,0.816c-0.13,0.289 -0.278,0.585 -0.444,0.889c-0.166,0.304 -0.382,0.602 -0.648,0.893l-0.222,-0.23c-0.199,-0.199 -0.408,-0.297 -0.625,-0.295c-0.217,0.003 -0.425,0.099 -0.624,0.288l-0.23,0.214c-0.241,0.225 -0.348,0.44 -0.322,0.644c0.025,0.204 0.138,0.409 0.337,0.613l2.782,2.783c0.205,0.199 0.409,0.311 0.613,0.337c0.205,0.025 0.419,-0.079 0.644,-0.314Z"/>
+</svg>

Modified: trunk/Source/WebInspectorUI/UserInterface/Models/Color.js (295146 => 295147)


--- trunk/Source/WebInspectorUI/UserInterface/Models/Color.js	2022-06-02 21:33:24 UTC (rev 295146)
+++ trunk/Source/WebInspectorUI/UserInterface/Models/Color.js	2022-06-02 21:43:23 UTC (rev 295147)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009, 2013 Apple Inc.  All rights reserved.
+ * Copyright (C) 2009-2022 Apple Inc.  All rights reserved.
  * Copyright (C) 2009 Joseph Pecoraro
  *
  * Redistribution and use in source and binary forms, with or without
@@ -209,6 +209,75 @@
         return null;
     }
 
+    static fromStringBestMatchingSuggestedFormatAndGamut(colorString, {suggestedFormat, suggestedGamut, forceSuggestedFormatAndGamut} = {})
+    {
+        let newColor = WI.Color.fromString(colorString);
+
+        if (forceSuggestedFormatAndGamut) {
+            newColor.format = suggestedFormat;
+            newColor.gamut = suggestedGamut;
+            return newColor;
+        }
+
+        // Match the suggested gamut if we can do so losslessly.
+        if (suggestedGamut === WI.Color.Gamut.DisplayP3 && newColor.gamut !== WI.Color.Gamut.DisplayP3)
+            newColor.gamut = WI.Color.Gamut.DisplayP3;
+        else if (suggestedGamut !== WI.Color.Gamut.DisplayP3 && newColor.gamut === WI.Color.Gamut.DisplayP3 && !newColor.isOutsideSRGB())
+            newColor.gamut = WI.Color.Gamut.SRGB;
+
+        // Non-sRGB gamuts can only be expressed in the Color Function format.
+        if (newColor.gamut !== WI.Color.Gamut.SRGB)
+            return newColor;
+
+        // Match as closely as possible the suggested format, and progressively adjust the format (e.g. ShortHEX -> HEX
+        // -> HEXAlpha) if an exact match would be lossy.
+        switch (suggestedFormat) {
+        case WI.Color.Format.Original:
+            console.assert(false, "No color should have a format of 'Original'.");
+            break;
+
+        case WI.Color.Format.Keyword:
+            // Use the format of the color string as-provided.
+            break;
+
+        case WI.Color.Format.HEX:
+            newColor.format = newColor.simple ? WI.Color.Format.HEX : WI.Color.Format.HEXAlpha;
+            break;
+
+        case WI.Color.Format.ShortHEX:
+            if (newColor.canBeSerializedAsShortHEX())
+                newColor.format = newColor.simple ? WI.Color.Format.ShortHEX : WI.Color.Format.ShortHEXAlpha;
+            else
+                newColor.format = newColor.simple ? WI.Color.Format.HEX : WI.Color.Format.HEXAlpha;
+            break;
+
+        case WI.Color.Format.ShortHEXAlpha:
+            newColor.format = newColor.canBeSerializedAsShortHEX() ? WI.Color.Format.ShortHEXAlpha : WI.Color.Format.HEXAlpha;
+            break;
+
+        case WI.Color.Format.RGB:
+            newColor.format = newColor.simple ? WI.Color.Format.RGB : WI.Color.Format.RGBA;
+            break;
+
+        case WI.Color.Format.HSL:
+            newColor.format = newColor.simple ? WI.Color.Format.HSL : WI.Color.Format.HSLA;
+            break;
+
+        case WI.Color.Format.HEXAlpha:
+        case WI.Color.Format.RGBA:
+        case WI.Color.Format.HSLA:
+        case WI.Color.Format.ColorFunction:
+            newColor.format = suggestedFormat;
+            break;
+
+        default:
+            console.assert(false, "Should not be reached.", suggestedFormat);
+            break;
+        }
+
+        return newColor;
+    }
+
     static rgb2hsl(r, g, b)
     {
         r = WI.Color._eightBitChannel(r) / 255;

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/ColorPicker.css (295146 => 295147)


--- trunk/Source/WebInspectorUI/UserInterface/Views/ColorPicker.css	2022-06-02 21:33:24 UTC (rev 295146)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/ColorPicker.css	2022-06-02 21:43:23 UTC (rev 295147)
@@ -76,23 +76,39 @@
     }
 }
 
-.color-picker > .color-inputs {
+.color-picker > .color-inputs-wrapper {
     display: flex;
+    align-items: center;
+    gap: var(--color-inputs-spacing);
+    margin-top: var(--color-inputs-spacing);
+
+    --color-inputs-spacing: 8px;
+}
+
+.color-picker > .color-inputs-wrapper > .color-inputs {
+    display: flex;
     justify-content: space-between;
-    margin-top: 8px;
+    flex: 1;
 }
 
-.color-picker > .color-inputs > div {
+.color-picker > .color-inputs-wrapper > .color-inputs > div {
     display: flex;
     align-items: center;
     width: 100%;
 }
 
-.color-picker > .color-inputs > div + div {
-    margin-inline-start: 4px;
-}
-
-.color-picker > .color-inputs input {
+.color-picker > .color-inputs-wrapper > .color-inputs input {
     width: 100%;
     margin: 0 0.25em;
 }
+
+.color-picker > .color-inputs-wrapper > .pick-color-from-screen {
+    width: 16px;
+    height: 16px;
+    color: var(--glyph-color);
+    opacity: var(--glyph-opacity);
+}
+
+.color-picker > .color-inputs-wrapper > .pick-color-from-screen.active {
+    color: var(--glyph-color-active);
+}

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/ColorPicker.js (295146 => 295147)


--- trunk/Source/WebInspectorUI/UserInterface/Views/ColorPicker.js	2022-06-02 21:33:24 UTC (rev 295146)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/ColorPicker.js	2022-06-02 21:43:23 UTC (rev 295147)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013, 2015 Apple Inc. All rights reserved.
+ * Copyright (C) 2013-2022 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -25,10 +25,12 @@
 
 WI.ColorPicker = class ColorPicker extends WI.Object
 {
-    constructor()
+    constructor({preventChangingColorFormats} = {})
     {
         super();
 
+        this._preventChangingColorFormats = !!preventChangingColorFormats;
+
         this._colorSquare = new WI.ColorSquare(this, 200);
 
         this._hueSlider = new WI.Slider;
@@ -56,8 +58,32 @@
         wrapper.appendChild(this._hueSlider.element);
         wrapper.appendChild(this._opacitySlider.element);
 
-        this._element.appendChild(this._colorInputsContainerElement);
+        let colorInputsWrapperElement = this._element.appendChild(document.createElement("div"));
+        colorInputsWrapperElement.classList.add("color-inputs-wrapper");
+        colorInputsWrapperElement.appendChild(this._colorInputsContainerElement);
 
+        if (InspectorFrontendHost.canPickColorFromScreen()) {
+            let pickColorElement = WI.ImageUtilities.useSVGSymbol("Images/Pipette.svg", "pick-color-from-screen", WI.UIString("Pick color from screen", "Color picker view tooltip for picking a color from the screen."));
+            pickColorElement.role = "button";
+            pickColorElement.addEventListener("click", async (event) => {
+                pickColorElement.classList.add("active");
+                let pickedColor = await WI.ColorPicker.pickColorFromScreen({
+                    suggestedFormat: this.color.format,
+                    suggestedGamut: this.color.gamut,
+                    forceSuggestedFormatAndGamut: this._preventChangingColorFormats,
+                });
+                pickColorElement.classList.remove("active");
+
+                if (!pickedColor)
+                    return;
+
+                this.color = pickedColor;
+                this.dispatchEventToListeners(WI.ColorPicker.Event.ColorChanged, {color: this._color});
+            });
+
+            colorInputsWrapperElement.appendChild(pickColorElement);
+        }
+
         this._opacity = 0;
         this._opacityPattern = "url(Images/Checkers.svg)";
 
@@ -68,6 +94,33 @@
         this._enableColorComponentInputs = true;
     }
 
+    // Static
+
+    static async pickColorFromScreen({suggestedFormat, suggestedGamut, forceSuggestedFormatAndGamut} = {})
+    {
+        console.assert(InspectorFrontendHost.canPickColorFromScreen());
+
+        // There is a brief moment where the frontend page remains interactable before the backend actually begins the
+        // modal color picking mode. In order to avoid accidentally hovering an element and showing its highlight on the
+        // page and not being able to hide the highlight while selecting a color, make the document inert so that even
+        // immediate mouse movement doesn't accidentaly cause any highlighting to occur.
+        document.body.inert = true;
+
+        let pickedColorCSSString = null;
+        try {
+            pickedColorCSSString = await InspectorFrontendHost.pickColorFromScreen();
+        } catch (e) {
+            WI.reportInternalError(error);
+        }
+
+        document.body.inert = false;
+
+        if (!pickedColorCSSString)
+            return null;
+
+        return WI.Color.fromStringBestMatchingSuggestedFormatAndGamut(pickedColorCSSString, {suggestedFormat, suggestedGamut, forceSuggestedFormatAndGamut});
+    }
+
     // Public
 
     get element() { return this._element; }

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/InlineSwatch.js (295146 => 295147)


--- trunk/Source/WebInspectorUI/UserInterface/Views/InlineSwatch.js	2022-06-02 21:33:24 UTC (rev 295146)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/InlineSwatch.js	2022-06-02 21:43:23 UTC (rev 295147)
@@ -192,10 +192,13 @@
 
         switch (this._type) {
         case WI.InlineSwatch.Type.Color:
+            let title = WI.UIString("Click to select a color.");
             if (this._allowChangingColorFormats())
-                this._swatchElement.title = WI.UIString("Click to select a color\nShift-click to switch color formats");
-            else
-                this._swatchElement.title = WI.UIString("Click to select a color");
+                title += "\n" + WI.UIString("Shift-click to switch color formats.");
+            if (InspectorFrontendHost.canPickColorFromScreen())
+                title += "\n" + WI.UIString("Option-click to pick color from screen.");
+
+            this._swatchElement.title = title;
             // fallthrough
 
         case WI.InlineSwatch.Type.Gradient:
@@ -251,6 +254,23 @@
             }
         }
 
+        if (event.altKey && value) {
+            if (this._type === WI.InlineSwatch.Type.Color) {
+                WI.ColorPicker.pickColorFromScreen({
+                    suggestedFormat: value.format,
+                    suggestedGamut: value.gamut,
+                    forceSuggestedFormatAndGamut: this._preventChangingColorFormats,
+                }).then((pickedColor) => {
+                    if (!pickedColor)
+                        return;
+
+                    this._value = pickedColor;
+                    this._updateSwatch();
+                });
+                return;
+            }
+        }
+
         if (this._valueEditor)
             return;
 
@@ -276,7 +296,7 @@
             break;
 
         case WI.InlineSwatch.Type.Color:
-            this._valueEditor = new WI.ColorPicker;
+            this._valueEditor = new WI.ColorPicker({preventChangingColorFormats: this._preventChangingColorFormats});
             this._valueEditor.addEventListener(WI.ColorPicker.Event.ColorChanged, this._valueEditorValueDidChange, this);
             break;
 

Modified: trunk/Source/WebKit/UIProcess/Inspector/RemoteWebInspectorUIProxy.cpp (295146 => 295147)


--- trunk/Source/WebKit/UIProcess/Inspector/RemoteWebInspectorUIProxy.cpp	2022-06-02 21:33:24 UTC (rev 295146)
+++ trunk/Source/WebKit/UIProcess/Inspector/RemoteWebInspectorUIProxy.cpp	2022-06-02 21:43:23 UTC (rev 295147)
@@ -159,6 +159,11 @@
     platformLoad(path, WTFMove(completionHandler));
 }
 
+void RemoteWebInspectorUIProxy::pickColorFromScreen(CompletionHandler<void(const std::optional<WebCore::Color>&)>&& completionHandler)
+{
+    platformPickColorFromScreen(WTFMove(completionHandler));
+}
+
 void RemoteWebInspectorUIProxy::setSheetRect(const FloatRect& rect)
 {
     platformSetSheetRect(rect);
@@ -244,6 +249,7 @@
 void RemoteWebInspectorUIProxy::platformSave(const String&, const String&, bool, bool) { }
 void RemoteWebInspectorUIProxy::platformAppend(const String&, const String&) { }
 void RemoteWebInspectorUIProxy::platformLoad(const String&, CompletionHandler<void(const String&)>&& completionHandler) { completionHandler(nullString()); }
+void RemoteWebInspectorUIProxy::platformPickColorFromScreen(CompletionHandler<void(const std::optional<WebCore::Color>&)>&& completionHandler) { completionHandler({ }); }
 void RemoteWebInspectorUIProxy::platformSetSheetRect(const FloatRect&) { }
 void RemoteWebInspectorUIProxy::platformSetForcedAppearance(InspectorFrontendClient::Appearance) { }
 void RemoteWebInspectorUIProxy::platformStartWindowDrag() { }

Modified: trunk/Source/WebKit/UIProcess/Inspector/RemoteWebInspectorUIProxy.h (295146 => 295147)


--- trunk/Source/WebKit/UIProcess/Inspector/RemoteWebInspectorUIProxy.h	2022-06-02 21:33:24 UTC (rev 295146)
+++ trunk/Source/WebKit/UIProcess/Inspector/RemoteWebInspectorUIProxy.h	2022-06-02 21:43:23 UTC (rev 295147)
@@ -27,6 +27,7 @@
 
 #include "APIObject.h"
 #include "MessageReceiver.h"
+#include <WebCore/Color.h>
 #include <WebCore/FloatRect.h>
 #include <WebCore/InspectorFrontendClient.h>
 #include <wtf/Forward.h>
@@ -134,6 +135,7 @@
     void save(const String& filename, const String& content, bool base64Encoded, bool forceSaveAs);
     void append(const String& filename, const String& content);
     void load(const String& path, CompletionHandler<void(const String&)>&&);
+    void pickColorFromScreen(CompletionHandler<void(const std::optional<WebCore::Color>&)>&&);
     void setSheetRect(const WebCore::FloatRect&);
     void setForcedAppearance(WebCore::InspectorFrontendClient::Appearance);
     void startWindowDrag();
@@ -153,6 +155,7 @@
     void platformSave(const String& filename, const String& content, bool base64Encoded, bool forceSaveAs);
     void platformAppend(const String& filename, const String& content);
     void platformLoad(const String& path, CompletionHandler<void(const String&)>&&);
+    void platformPickColorFromScreen(CompletionHandler<void(const std::optional<WebCore::Color>&)>&&);
     void platformSetSheetRect(const WebCore::FloatRect&);
     void platformSetForcedAppearance(WebCore::InspectorFrontendClient::Appearance);
     void platformStartWindowDrag();

Modified: trunk/Source/WebKit/UIProcess/Inspector/RemoteWebInspectorUIProxy.messages.in (295146 => 295147)


--- trunk/Source/WebKit/UIProcess/Inspector/RemoteWebInspectorUIProxy.messages.in	2022-06-02 21:33:24 UTC (rev 295146)
+++ trunk/Source/WebKit/UIProcess/Inspector/RemoteWebInspectorUIProxy.messages.in	2022-06-02 21:43:23 UTC (rev 295147)
@@ -30,6 +30,7 @@
     Save(String filename, String content, bool base64Encoded, bool forceSaveAs)
     Append(String filename, String content)
     Load(String path) -> (String content)
+    PickColorFromScreen() -> (std::optional<WebCore::Color> color)
 
     SetForcedAppearance(WebCore::InspectorFrontendClient::Appearance appearance)
 

Modified: trunk/Source/WebKit/UIProcess/Inspector/WebInspectorUIProxy.cpp (295146 => 295147)


--- trunk/Source/WebKit/UIProcess/Inspector/WebInspectorUIProxy.cpp	2022-06-02 21:33:24 UTC (rev 295146)
+++ trunk/Source/WebKit/UIProcess/Inspector/WebInspectorUIProxy.cpp	2022-06-02 21:43:23 UTC (rev 295147)
@@ -741,6 +741,16 @@
     platformLoad(path, WTFMove(completionHandler));
 }
 
+void WebInspectorUIProxy::pickColorFromScreen(CompletionHandler<void(const std::optional<WebCore::Color> &)>&& completionHandler)
+{
+    if (!m_inspectedPage->preferences().developerExtrasEnabled()) {
+        completionHandler({ });
+        return;
+    }
+
+    platformPickColorFromScreen(WTFMove(completionHandler));
+}
+
 bool WebInspectorUIProxy::shouldOpenAttached()
 {
     return inspectorPagePreferences().inspectorStartsAttached() && canAttach();
@@ -846,6 +856,12 @@
     completionHandler(nullString());
 }
 
+void WebInspectorUIProxy::platformPickColorFromScreen(CompletionHandler<void(const std::optional<WebCore::Color>&)>&& completionHandler)
+{
+    notImplemented();
+    completionHandler({ });
+}
+
 unsigned WebInspectorUIProxy::platformInspectedWindowHeight()
 {
     notImplemented();

Modified: trunk/Source/WebKit/UIProcess/Inspector/WebInspectorUIProxy.h (295146 => 295147)


--- trunk/Source/WebKit/UIProcess/Inspector/WebInspectorUIProxy.h	2022-06-02 21:33:24 UTC (rev 295146)
+++ trunk/Source/WebKit/UIProcess/Inspector/WebInspectorUIProxy.h	2022-06-02 21:43:23 UTC (rev 295147)
@@ -33,6 +33,7 @@
 #include "WebInspectorUtilities.h"
 #include "WebPageProxyIdentifier.h"
 #include <_javascript_Core/InspectorFrontendChannel.h>
+#include <WebCore/Color.h>
 #include <WebCore/FloatRect.h>
 #include <WebCore/InspectorClient.h>
 #include <WebCore/InspectorFrontendClient.h>
@@ -239,6 +240,7 @@
     void platformSave(const String& filename, const String& content, bool base64Encoded, bool forceSaveAs);
     void platformAppend(const String& filename, const String& content);
     void platformLoad(const String& path, CompletionHandler<void(const String&)>&&);
+    void platformPickColorFromScreen(CompletionHandler<void(const std::optional<WebCore::Color>&)>&&);
 
 #if PLATFORM(MAC)
     bool platformCanAttach(bool webProcessCanAttach);
@@ -266,6 +268,7 @@
     void save(const String& filename, const String& content, bool base64Encoded, bool forceSaveAs);
     void append(const String& filename, const String& content);
     void load(const String& path, CompletionHandler<void(const String&)>&&);
+    void pickColorFromScreen(CompletionHandler<void(const std::optional<WebCore::Color>&)>&&);
 
     bool canAttach() const { return m_canAttach; }
     bool shouldOpenAttached();

Modified: trunk/Source/WebKit/UIProcess/Inspector/WebInspectorUIProxy.messages.in (295146 => 295147)


--- trunk/Source/WebKit/UIProcess/Inspector/WebInspectorUIProxy.messages.in	2022-06-02 21:33:24 UTC (rev 295146)
+++ trunk/Source/WebKit/UIProcess/Inspector/WebInspectorUIProxy.messages.in	2022-06-02 21:43:23 UTC (rev 295147)
@@ -45,6 +45,7 @@
     Save(String filename, String content, bool base64Encoded, bool forceSaveAs)
     Append(String filename, String content)
     Load(String path) -> (String content)
+    PickColorFromScreen() -> (std::optional<WebCore::Color> color)
 
     AttachBottom()
     AttachRight()

Modified: trunk/Source/WebKit/UIProcess/Inspector/gtk/RemoteWebInspectorUIProxyGtk.cpp (295146 => 295147)


--- trunk/Source/WebKit/UIProcess/Inspector/gtk/RemoteWebInspectorUIProxyGtk.cpp	2022-06-02 21:33:24 UTC (rev 295146)
+++ trunk/Source/WebKit/UIProcess/Inspector/gtk/RemoteWebInspectorUIProxyGtk.cpp	2022-06-02 21:43:23 UTC (rev 295147)
@@ -167,6 +167,11 @@
     completionHandler(nullString());
 }
 
+void RemoteWebInspectorUIProxy::platformPickColorFromScreen(CompletionHandler<void(const std::optional<WebCore::Color>&)>&& completionHandler)
+{
+    completionHandler({ });
+}
+
 void RemoteWebInspectorUIProxy::platformSetSheetRect(const FloatRect&)
 {
 }

Modified: trunk/Source/WebKit/UIProcess/Inspector/gtk/WebInspectorUIProxyGtk.cpp (295146 => 295147)


--- trunk/Source/WebKit/UIProcess/Inspector/gtk/WebInspectorUIProxyGtk.cpp	2022-06-02 21:33:24 UTC (rev 295146)
+++ trunk/Source/WebKit/UIProcess/Inspector/gtk/WebInspectorUIProxyGtk.cpp	2022-06-02 21:43:23 UTC (rev 295147)
@@ -573,6 +573,12 @@
     completionHandler(nullString());
 }
 
+void WebInspectorUIProxy::platformPickColorFromScreen(CompletionHandler<void(const std::optional<WebCore::Color>&)>&& completionHandler)
+{
+    notImplemented();
+    completionHandler({ });
+}
+
 void WebInspectorUIProxy::platformAttachAvailabilityChanged(bool available)
 {
     if (m_client)

Modified: trunk/Source/WebKit/UIProcess/Inspector/mac/RemoteWebInspectorUIProxyMac.mm (295146 => 295147)


--- trunk/Source/WebKit/UIProcess/Inspector/mac/RemoteWebInspectorUIProxyMac.mm	2022-06-02 21:33:24 UTC (rev 295146)
+++ trunk/Source/WebKit/UIProcess/Inspector/mac/RemoteWebInspectorUIProxyMac.mm	2022-06-02 21:43:23 UTC (rev 295147)
@@ -43,6 +43,8 @@
 #import <SecurityInterface/SFCertificatePanel.h>
 #import <SecurityInterface/SFCertificateView.h>
 #import <WebCore/CertificateInfo.h>
+#import <WebCore/Color.h>
+#import <wtf/BlockPtr.h>
 #import <wtf/text/Base64.h>
 
 @interface WKRemoteWebInspectorUIProxyObjCAdapter : NSObject <NSWindowDelegate, WKInspectorViewControllerDelegate> {
@@ -241,6 +243,19 @@
         completionHandler(nullString());
 }
 
+void RemoteWebInspectorUIProxy::platformPickColorFromScreen(CompletionHandler<void(const std::optional<WebCore::Color>&)>&& completionHandler)
+{
+    auto sampler = adoptNS([[NSColorSampler alloc] init]);
+    [sampler.get() showSamplerWithSelectionHandler:makeBlockPtr([completionHandler = WTFMove(completionHandler)](NSColor *selectedColor) mutable {
+        if (!selectedColor) {
+            completionHandler(std::nullopt);
+            return;
+        }
+
+        completionHandler(Color::createAndPreserveColorSpace(selectedColor.CGColor));
+    }).get()];
+}
+
 void RemoteWebInspectorUIProxy::platformSetSheetRect(const FloatRect& rect)
 {
     m_sheetRect = rect;

Modified: trunk/Source/WebKit/UIProcess/Inspector/mac/WebInspectorUIProxyMac.mm (295146 => 295147)


--- trunk/Source/WebKit/UIProcess/Inspector/mac/WebInspectorUIProxyMac.mm	2022-06-02 21:33:24 UTC (rev 295146)
+++ trunk/Source/WebKit/UIProcess/Inspector/mac/WebInspectorUIProxyMac.mm	2022-06-02 21:43:23 UTC (rev 295147)
@@ -47,9 +47,11 @@
 #import <SecurityInterface/SFCertificatePanel.h>
 #import <SecurityInterface/SFCertificateView.h>
 #import <WebCore/CertificateInfo.h>
+#import <WebCore/Color.h>
 #import <WebCore/InspectorFrontendClientLocal.h>
 #import <WebCore/LocalizedStrings.h>
 #import <pal/spi/cf/CFUtilitiesSPI.h>
+#import <wtf/BlockPtr.h>
 #import <wtf/text/Base64.h>
 
 static const NSUInteger windowStyleMask = NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskResizable | NSWindowStyleMaskFullSizeContentView;
@@ -590,6 +592,19 @@
         completionHandler(nullString());
 }
 
+void WebInspectorUIProxy::platformPickColorFromScreen(CompletionHandler<void(const std::optional<WebCore::Color>&)>&& completionHandler)
+{
+    auto sampler = adoptNS([[NSColorSampler alloc] init]);
+    [sampler.get() showSamplerWithSelectionHandler:makeBlockPtr([completionHandler = WTFMove(completionHandler)](NSColor *selectedColor) mutable {
+        if (!selectedColor) {
+            completionHandler(std::nullopt);
+            return;
+        }
+
+        completionHandler(Color::createAndPreserveColorSpace(selectedColor.CGColor));
+    }).get()];
+}
+
 void WebInspectorUIProxy::windowFrameDidChange()
 {
     ASSERT(!m_isAttached);

Modified: trunk/Source/WebKit/UIProcess/Inspector/win/RemoteWebInspectorUIProxyWin.cpp (295146 => 295147)


--- trunk/Source/WebKit/UIProcess/Inspector/win/RemoteWebInspectorUIProxyWin.cpp	2022-06-02 21:33:24 UTC (rev 295146)
+++ trunk/Source/WebKit/UIProcess/Inspector/win/RemoteWebInspectorUIProxyWin.cpp	2022-06-02 21:43:23 UTC (rev 295147)
@@ -136,6 +136,7 @@
 void RemoteWebInspectorUIProxy::platformSave(const String&, const String&, bool, bool) { }
 void RemoteWebInspectorUIProxy::platformAppend(const String&, const String&) { }
 void RemoteWebInspectorUIProxy::platformLoad(const String&, CompletionHandler<void(const String&)>&& completionHandler) { completionHandler(nullString()); }
+void RemoteWebInspectorUIProxy::platformPickColorFromScreen(CompletionHandler<void(const std::optional<WebCore::Color>&)>&& completionHandler) { completionHandler({ }); }
 void RemoteWebInspectorUIProxy::platformSetSheetRect(const WebCore::FloatRect&) { }
 void RemoteWebInspectorUIProxy::platformSetForcedAppearance(WebCore::InspectorFrontendClient::Appearance) { }
 void RemoteWebInspectorUIProxy::platformStartWindowDrag() { }

Modified: trunk/Source/WebKit/UIProcess/Inspector/win/WebInspectorUIProxyWin.cpp (295146 => 295147)


--- trunk/Source/WebKit/UIProcess/Inspector/win/WebInspectorUIProxyWin.cpp	2022-06-02 21:33:24 UTC (rev 295146)
+++ trunk/Source/WebKit/UIProcess/Inspector/win/WebInspectorUIProxyWin.cpp	2022-06-02 21:43:23 UTC (rev 295147)
@@ -429,6 +429,12 @@
     completionHandler(nullString());
 }
 
+void WebInspectorUIProxy::platformPickColorFromScreen(CompletionHandler<void(const std::optional<WebCore::Color>&)>&& completionHandler)
+{
+    notImplemented();
+    completionHandler({ });
+}
+
 void WebInspectorUIProxy::platformAttachAvailabilityChanged(bool /* available */)
 {
     notImplemented();

Modified: trunk/Source/WebKit/WebProcess/Inspector/RemoteWebInspectorUI.cpp (295146 => 295147)


--- trunk/Source/WebKit/WebProcess/Inspector/RemoteWebInspectorUI.cpp	2022-06-02 21:33:24 UTC (rev 295146)
+++ trunk/Source/WebKit/WebProcess/Inspector/RemoteWebInspectorUI.cpp	2022-06-02 21:43:23 UTC (rev 295147)
@@ -238,6 +238,11 @@
     WebProcess::singleton().parentProcessConnection()->sendWithAsyncReply(Messages::RemoteWebInspectorUIProxy::Load(path), WTFMove(completionHandler), m_page.identifier());
 }
 
+void RemoteWebInspectorUI::pickColorFromScreen(CompletionHandler<void(const std::optional<WebCore::Color>&)>&& completionHandler)
+{
+    WebProcess::singleton().parentProcessConnection()->sendWithAsyncReply(Messages::RemoteWebInspectorUIProxy::PickColorFromScreen(), WTFMove(completionHandler), m_page.identifier());
+}
+
 void RemoteWebInspectorUI::inspectedURLChanged(const String& urlString)
 {
     // Do nothing. The remote side can know if the main resource changed.

Modified: trunk/Source/WebKit/WebProcess/Inspector/RemoteWebInspectorUI.h (295146 => 295147)


--- trunk/Source/WebKit/WebProcess/Inspector/RemoteWebInspectorUI.h	2022-06-02 21:33:24 UTC (rev 295146)
+++ trunk/Source/WebKit/WebProcess/Inspector/RemoteWebInspectorUI.h	2022-06-02 21:43:23 UTC (rev 295147)
@@ -27,6 +27,7 @@
 
 #include "DebuggableInfoData.h"
 #include "MessageReceiver.h"
+#include <WebCore/Color.h>
 #include <WebCore/FrameIdentifier.h>
 #include <WebCore/InspectorFrontendAPIDispatcher.h>
 #include <WebCore/InspectorFrontendClient.h>
@@ -109,6 +110,7 @@
     void save(const String& url, const String& content, bool base64Encoded, bool forceSaveAs) override;
     void append(const String& url, const String& content) override;
     void load(const String& path, CompletionHandler<void(const String&)>&&) override;
+    void pickColorFromScreen(CompletionHandler<void(const std::optional<WebCore::Color>&)>&&) override;
     void inspectedURLChanged(const String&) override;
     void showCertificate(const WebCore::CertificateInfo&) override;
     void sendMessageToBackend(const String&) override;
@@ -131,6 +133,7 @@
 
     bool canSave() override { return true; }
     bool canLoad() override { return true; }
+    bool canPickColorFromScreen() override { return true; }
     bool isUnderTest() override { return false; }
     unsigned inspectionLevel() const override { return 1; }
     void requestSetDockSide(DockSide) override { }

Modified: trunk/Source/WebKit/WebProcess/Inspector/WebInspectorUI.cpp (295146 => 295147)


--- trunk/Source/WebKit/WebProcess/Inspector/WebInspectorUI.cpp	2022-06-02 21:33:24 UTC (rev 295146)
+++ trunk/Source/WebKit/WebProcess/Inspector/WebInspectorUI.cpp	2022-06-02 21:43:23 UTC (rev 295147)
@@ -316,6 +316,11 @@
     WebProcess::singleton().parentProcessConnection()->sendWithAsyncReply(Messages::WebInspectorUIProxy::Load(path), WTFMove(completionHandler), m_inspectedPageIdentifier);
 }
 
+void WebInspectorUI::pickColorFromScreen(CompletionHandler<void(const std::optional<WebCore::Color>&)>&& completionHandler)
+{
+    WebProcess::singleton().parentProcessConnection()->sendWithAsyncReply(Messages::WebInspectorUIProxy::PickColorFromScreen(), WTFMove(completionHandler), m_inspectedPageIdentifier);
+}
+
 void WebInspectorUI::inspectedURLChanged(const String& urlString)
 {
     WebProcess::singleton().parentProcessConnection()->send(Messages::WebInspectorUIProxy::InspectedURLChanged(urlString), m_inspectedPageIdentifier);
@@ -490,6 +495,12 @@
     return false;
 }
 
+bool WebInspectorUI::canPickColorFromScreen()
+{
+    notImplemented();
+    return false;
+}
+
 String WebInspectorUI::localizedStringsURL() const
 {
     notImplemented();

Modified: trunk/Source/WebKit/WebProcess/Inspector/WebInspectorUI.h (295146 => 295147)


--- trunk/Source/WebKit/WebProcess/Inspector/WebInspectorUI.h	2022-06-02 21:33:24 UTC (rev 295146)
+++ trunk/Source/WebKit/WebProcess/Inspector/WebInspectorUI.h	2022-06-02 21:43:23 UTC (rev 295147)
@@ -28,6 +28,7 @@
 #include "Connection.h"
 #include "DebuggableInfoData.h"
 #include "WebPageProxyIdentifier.h"
+#include <WebCore/Color.h>
 #include <WebCore/FrameIdentifier.h>
 #include <WebCore/InspectorDebuggableType.h>
 #include <WebCore/InspectorFrontendAPIDispatcher.h>
@@ -146,6 +147,9 @@
     bool canLoad() override;
     void load(const WTF::String& path, WTF::CompletionHandler<void(const WTF::String&)>&&) override;
 
+    bool canPickColorFromScreen() override;
+    void pickColorFromScreen(WTF::CompletionHandler<void(const std::optional<WebCore::Color>&)>&&) override;
+
     void inspectedURLChanged(const String&) override;
     void showCertificate(const WebCore::CertificateInfo&) override;
 

Modified: trunk/Source/WebKit/WebProcess/Inspector/gtk/WebInspectorUIGtk.cpp (295146 => 295147)


--- trunk/Source/WebKit/WebProcess/Inspector/gtk/WebInspectorUIGtk.cpp	2022-06-02 21:33:24 UTC (rev 295146)
+++ trunk/Source/WebKit/WebProcess/Inspector/gtk/WebInspectorUIGtk.cpp	2022-06-02 21:43:23 UTC (rev 295147)
@@ -44,6 +44,11 @@
     return false;
 }
 
+bool WebInspectorUI::canPickColorFromScreen()
+{
+    return false;
+}
+
 String WebInspectorUI::localizedStringsURL() const
 {
     return "resource:///org/webkit/inspector/Localizations/en.lproj/localizedStrings.js"_s;

Modified: trunk/Source/WebKit/WebProcess/Inspector/mac/WebInspectorUIMac.mm (295146 => 295147)


--- trunk/Source/WebKit/WebProcess/Inspector/mac/WebInspectorUIMac.mm	2022-06-02 21:33:24 UTC (rev 295146)
+++ trunk/Source/WebKit/WebProcess/Inspector/mac/WebInspectorUIMac.mm	2022-06-02 21:43:23 UTC (rev 295147)
@@ -42,6 +42,11 @@
     return true;
 }
 
+bool WebInspectorUI::canPickColorFromScreen()
+{
+    return true;
+}
+
 static String webInspectorUILocalizedStringsURL()
 {
     return [WKInspectorViewController URLForInspectorResource:@"localizedStrings.js"].absoluteString;

Modified: trunk/Source/WebKit/WebProcess/Inspector/win/WebInspectorUIWin.cpp (295146 => 295147)


--- trunk/Source/WebKit/WebProcess/Inspector/win/WebInspectorUIWin.cpp	2022-06-02 21:33:24 UTC (rev 295146)
+++ trunk/Source/WebKit/WebProcess/Inspector/win/WebInspectorUIWin.cpp	2022-06-02 21:43:23 UTC (rev 295147)
@@ -44,6 +44,11 @@
     return false;
 }
 
+bool WebInspectorUI::canPickColorFromScreen()
+{
+    return false;
+}
+
 String WebInspectorUI::localizedStringsURL() const
 {
     return "inspector-resource:///localizedStrings.js"_s;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to