Simplify and improve Gradient, some other small color-related removals
https://bugs.webkit.org/show_bug.cgi?id=214221

Reviewed by Sam Weinig.

* css/CSSGradientValue.cpp: Removed some unneeded includes.

* html/ColorInputType.cpp:
(WebCore::ColorInputType::currentColor): Deleted.
(WebCore::ColorInputType::shouldShowSuggestions const): Deleted.
* html/ColorInputType.h: Updated for the above.

* html/HTMLDocument.cpp: Removed unneeded include of HashTools.h.

* html/canvas/CanvasGradient.cpp:
(WebCore::CanvasGradient::create): Moved these functions out of the
header since inlining should be the same or better with them here.
(WebCore::CanvasGradient::~CanvasGradient): Moved this out of the
header so we don't need to include Gradient.h in the header.
(WebCore::CanvasGradient::addColorStop): Updated for change to
Gradient::addColorStop and move Color rather than copying it.

* html/canvas/CanvasGradient.h: Removed include of Gradient.h.
Moved things out of the header to make that work.

* inspector/InspectorCanvas.cpp:
(WebCore::InspectorCanvas::buildArrayForCanvasGradient): Removed
use of Gradient::type and instead unify the type string code with
the code that interprets the data for the different types.

* page/FrameView.cpp:
(WebCore::FrameView::recalculateScrollbarOverlayStyle): Refactored
to eliminate the multiple redundant code paths, otherwising leaving
the logic unchanged.

* platform/ColorChooserClient.h: Remove unneeded includes and unused
currentColor and shouldShowSuggestions functions.

* platform/graphics/Gradient.cpp:
(WebCore::Gradient::create): Replaced create functions that take
type-specific data structure with one that takes the variant Data.
(WebCore::Gradient::Gradient): Ditto. Also removed platformInit.
(WebCore::Gradient::~Gradient): Removed platformDestroy.
(WebCore::Gradient::type const): Deleted.
(WebCore::Gradient::addColorStop): Take an rvalue reference to cut down
a little bit on reference count churn. Replaced the platformDestroy
function with a new stopsChanged function. Removed an unneeded overload
that takes the two parts of a ColorStop separately.
(WebCore::Gradient::setSortedColorStops): Use stopsChanged.
(WebCore::Gradient::sortStops const): Simplify a bit, using a lambda.
Also gave this a shorter name; it still optimizes by not sorting if
the vector is already sorted.
(WebCore::Gradient::hasAlpha const): Deleted.
(WebCore::Gradient::setSpreadMethod): Removed some slightly overzealous
code checking this isn't used after creating the platform-specific gradient.
Decided not to bother with this for now.
(WebCore::Gradient::setGradientSpaceTransform): Tweaked formatting.
(WebCore::add): Added overloads to add(Hasher&) so we can use computeHash.
(WebCore::Gradient::hash const): Use computeHash instead of hashMemory.

* platform/graphics/Gradient.h: Use RetainPtr, COMPtr, and RefPtr instead
of manually managing the lifetimes of the platform-specific underlying
gradient objects. Also removed the unhelpful PlatformGradient type. This
pattern, all too common in our platform library, provides no useful
abstraction here. Removed unneeded constructors from ColorStop.
Updated for changes above. Added platform-specific functions createBrush,
createPattern, and createCGGradient. Simplify encoding and decoding by
taking advantage of the support for encoding/decoding variants.
Remove the enum Gradient::Type entirely. Removed the invalidateHash
function because it's only used in a few setters and setting the hash
to 0 is a fine way to write it there.

* platform/graphics/GraphicsContext.cpp:
(WebCore::GraphicsContextState::GraphicsContextState): Moved here from
the header so we don't need to include Gradient.h in the header.
(WebCore::GraphicsContextState::~GraphicsContextState): Ditto.
(WebCore::GraphicsContextState::operator=): Ditto.

* platform/graphics/GraphicsContext.h: Removed include of Gradient.h.
Moved things out of the header to make that work.

* platform/graphics/cairo/CairoOperations.cpp:
(WebCore::Cairo::FillSource::FillSource): Use createPattern instead of
createPlatformGradient.
(WebCore::Cairo::StrokeSource::StrokeSource): Ditto.

* platform/graphics/cairo/GradientCairo.cpp:
(WebCore::Gradient::stopsChanged): Renamed from platformDestroy.
(WebCore::interpolateColorStop): Rewrote to use existing blend functions.
(WebCore::createConic): Changed return type to RefPtr. Tweaked to match
WebKit coding style a bit better, use auto, use Vector::first/last, and
updated for removal of the Gradient::ColorStop constructor.
(WebCore::Gradient::createPattern): Renamed from createPlatformGradient.
Changed to return a RefPtr instead of a raw pointer the caller needs to
adopt at each call site. Refactored so it no longer uses Gradient::type.
(WebCore::Gradient::fill): Use createPattern.
* platform/graphics/cairo/GraphicsContextImplCairo.cpp:
(WebCore::GraphicsContextImplCairo::fillRect): Ditto.

* platform/graphics/cg/GradientCG.cpp:
(WebCore::Gradient::stopsChanged): Renamed from platformDestroy, and
simplified implementation now that we use RetainPtr.
(WebCore::Gradient::createCGGradient): Renamed from platformGradient,
got rid of the return value, and made it caller responsibility to only
call this when a gradeitn needs to be allocated.
(WebCore::Gradient::paint): Updated to use the above.

* platform/graphics/cg/GraphicsContextCG.cpp: Add include of Gradient.h.

* platform/graphics/displaylists/DisplayListItems.h:
Added include of Gradient.h since the function templates in this file
encode and decode gradients.

* platform/graphics/nicosia/cairo/NicosiaCairoOperationRecorder.cpp:
(Nicosia::CairoOperationRecorder::fillRect): Use createPattern.

* platform/graphics/win/Direct2DOperations.cpp:
(WebCore::Direct2D::FillSource::FillSource): Use createBrush
(WebCore::Direct2D::StrokeSource::StrokeSource): Ditto.

* platform/graphics/win/GradientDirect2D.cpp:
(WebCore::Gradient::stopsChanged): Renamed from platformDestroy and
simplified implementation now that we use COMPtr.
(WebCore::Gradient::platformGradient): Deleted.
(WebCore::Gradient::createPlatformGradientIfNecessary): Deleted.
(WebCore::Gradient::createBrush): Renamed from generateGradient and
added a return value. Simplified now that we use COMPtr, optimized
the code a bit, and added some FIXME about mistakes I noticed.
(WebCore::Gradient::fill): Use createBrush and m_brush.
* platform/graphics/win/GraphicsContextImplDirect2D.cpp:
(WebCore::GraphicsContextImplDirect2D::fillRect): Use createBrush.

* platform/mac/ScrollAnimatorMac.mm: Added include of Gradient.h.

* rendering/RenderThemeIOS.mm:
(WebCore::RenderThemeIOS::paintProgressBar): Updated for changes to
addColorStop. Also remove a lot of unnecessary conversion from float
to double and back to float.

* rendering/svg/RenderSVGResourceGradient.cpp:
(WebCore::RenderSVGResourceGradient::addStops): Update to make
and move a new color stop instead of copying it, modifying it in
place, and then copying it again.
* rendering/svg/RenderSVGResourceGradient.cpp: Removed include of
Gradient.h.

* svg/SVGGradientElement.cpp:
(WebCore::SVGGradientElement::buildStops): Use std::clamp to convert
the offsets into monotonically increasing ones in a more direct way,
using variable names instead of comments to clarify what we are doing.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@264280 268f45cc-cd09-0410-ab3c-d52691b4dbfc
30 files changed
tree: 190dbafbe72f9198204d84be82297aa490d91ff5
  1. JSTests/
  2. LayoutTests/
  3. ManualTests/
  4. PerformanceTests/
  5. Source/
  6. Tools/
  7. WebDriverTests/
  8. WebKit.xcworkspace/
  9. WebKitLibraries/
  10. Websites/
  11. .clang-format
  12. .dir-locals.el
  13. .editorconfig
  14. .gitattributes
  15. .gitignore
  16. ChangeLog
  17. ChangeLog-2012-05-22
  18. ChangeLog-2018-01-01
  19. CMakeLists.txt
  20. Makefile
  21. Makefile.shared
  22. ReadMe.md
ReadMe.md

WebKit

WebKit is a cross-platform web browser engine. On iOS and macOS, it powers Safari, Mail, iBooks, and many other applications.

Feature Status

Visit WebKit Feature Status page to see which Web API has been implemented, in development, or under consideration.

Trying the Latest

On macOS, download Safari Technology Preview to test the latest version of WebKit. On Linux, download Epiphany Technology Preview. On Windows, you'll have to build it yourself.

Reporting Bugs

  1. Search WebKit Bugzilla to see if there is an existing report for the bug you've encountered.
  2. Create a Bugzilla account to to report bugs (and to comment on them) if you haven't done so already.
  3. File a bug in accordance with our guidelines.

Once your bug is filed, you will receive email when it is updated at each stage in the bug life cycle. After the bug is considered fixed, you may be asked to download the latest nightly and confirm that the fix works for you.

Getting the Code

On Windows, follow the instructions on our website.

Cloning the Git SVN Repository

Run the following command to clone WebKit's Git SVN repository:

git clone git://git.webkit.org/WebKit.git WebKit

or

git clone https://git.webkit.org/git/WebKit.git WebKit

If you want to be able to commit changes to the repository, or just want to check out branches that aren’t contained in WebKit.git, you will need track WebKit's Subversion repository. You can run the following command to configure this and other options of the new Git clone for WebKit development.

Tools/Scripts/webkit-patch setup-git-clone

For information about this, and other aspects of using Git with WebKit, read the wiki page.

Checking out the Subversion Repository

If you don‘t want to use Git, run the following command to check out WebKit’s Subversion repository:

svn checkout https://svn.webkit.org/repository/webkit/trunk WebKit

Building WebKit

Building macOS Port

Install Xcode and its command line tools if you haven't done so already:

  1. Install Xcode Get Xcode from https://developer.apple.com/downloads. To build WebKit for OS X, Xcode 5.1.1 or later is required. To build WebKit for iOS Simulator, Xcode 7 or later is required.
  2. Install the Xcode Command Line Tools In Terminal, run the command: xcode-select --install

Run the following command to build a debug build with debugging symbols and assertions:

Tools/Scripts/build-webkit --debug

For performance testing, and other purposes, use --release instead.

Using Xcode

You can open WebKit.xcworkspace to build and debug WebKit within Xcode.

If you don't use a custom build location in Xcode preferences, you have to update the workspace settings to use WebKitBuild directory. In menu bar, choose File > Workspace Settings, then click the Advanced button, select “Custom”, “Relative to Workspace”, and enter WebKitBuild for both Products and Intermediates.

Building iOS Port

The first time after you install a new Xcode, you will need to run the following command to enable Xcode to build command line tools for iOS Simulator:

sudo Tools/Scripts/configure-xcode-for-ios-development

Without this step, you will see the error message: “target specifies product type ‘com.apple.product-type.tool’, but there’s no such product type for the ‘iphonesimulator’ platform.” when building target JSCLLIntOffsetsExtractor of project JavaScriptCore.

Run the following command to build a debug build with debugging symbols and assertions for iOS:

Tools/Scripts/build-webkit --debug --ios-simulator

Building the GTK+ Port

For production builds:

cmake -DPORT=GTK -DCMAKE_BUILD_TYPE=RelWithDebInfo -GNinja
ninja
sudo ninja install

For development builds:

Tools/gtk/install-dependencies
Tools/Scripts/update-webkitgtk-libs
Tools/Scripts/build-webkit --gtk --debug

For more information on building WebKitGTK+, see the wiki page.

Building the WPE Port

For production builds:

cmake -DPORT=WPE -DCMAKE_BUILD_TYPE=RelWithDebInfo -GNinja
ninja
sudo ninja install

For development builds:

Tools/wpe/install-dependencies
Tools/Scripts/update-webkitwpe-libs
Tools/Scripts/build-webkit --wpe --debug

Building Windows Port

For building WebKit on Windows, see the wiki page.

Running WebKit

With Safari and Other macOS Applications

Run the following command to launch Safari with your local build of WebKit:

Tools/Scripts/run-safari --debug

The run-safari script sets the DYLD_FRAMEWORK_PATH environment variable to point to your build products, and then launches /Applications/Safari.app. DYLD_FRAMEWORK_PATH tells the system loader to prefer your build products over the frameworks installed in /System/Library/Frameworks.

To run other applications with your local build of WebKit, run the following command:

Tools/Scripts/run-webkit-app <application-path>

iOS Simulator

Run the following command to launch iOS simulator with your local build of WebKit:

run-safari --debug --ios-simulator

In both cases, if you have built release builds instead, use --release instead of --debug.

Linux Ports

If you have a development build, you can use the run-minibrowser script, e.g.:

run-minibrowser --debug --wpe

Pass one of --gtk, --jsc-only, or --wpe to indicate the port to use.

Contribute

Congratulations! You’re up and running. Now you can begin coding in WebKit and contribute your fixes and new features to the project. For details on submitting your code to the project, read Contributing Code.