2014-12-09 20:29:59 +00:00
|
|
|
/*
|
2020-05-27 21:04:41 +00:00
|
|
|
* Copyright (C) 2016-2020 Apple Inc. All rights reserved.
|
2014-12-09 20:29:59 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2016-09-27 19:08:34 +00:00
|
|
|
#pragma once
|
2016-02-26 19:49:36 +00:00
|
|
|
|
2016-03-03 23:49:18 +00:00
|
|
|
#include <initializer_list>
|
2016-03-08 19:33:10 +00:00
|
|
|
#include <iterator>
|
2021-06-02 06:45:51 +00:00
|
|
|
#include <optional>
|
2016-02-26 19:49:36 +00:00
|
|
|
#include <type_traits>
|
2016-03-08 19:33:10 +00:00
|
|
|
#include <wtf/Assertions.h>
|
2020-06-17 19:52:13 +00:00
|
|
|
#include <wtf/EnumTraits.h>
|
2016-03-08 19:33:10 +00:00
|
|
|
#include <wtf/MathExtras.h>
|
2020-07-12 09:47:05 +00:00
|
|
|
#include <wtf/StdLibExtras.h>
|
2016-02-26 19:49:36 +00:00
|
|
|
|
|
|
|
namespace WTF {
|
|
|
|
|
2020-05-27 21:04:41 +00:00
|
|
|
template<typename E> class OptionSet;
|
|
|
|
|
|
|
|
|
|
|
|
template<typename T, typename E> struct OptionSetValueChecker;
|
|
|
|
|
|
|
|
template<typename T, typename E, E e, E... es>
|
2020-06-17 19:52:13 +00:00
|
|
|
struct OptionSetValueChecker<T, EnumValues<E, e, es...>> {
|
2020-05-27 21:04:41 +00:00
|
|
|
static constexpr T allValidBits()
|
|
|
|
{
|
2020-06-17 19:52:13 +00:00
|
|
|
return static_cast<T>(e) | OptionSetValueChecker<T, EnumValues<E, es...>>::allValidBits();
|
2020-05-27 21:04:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static constexpr bool isValidOptionSetEnum(T t)
|
|
|
|
{
|
2020-06-17 19:52:13 +00:00
|
|
|
return (static_cast<T>(e) == t) ? true : OptionSetValueChecker<T, EnumValues<E, es...>>::isValidOptionSetEnum(t);
|
2020-05-27 21:04:41 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T, typename E>
|
2020-06-17 19:52:13 +00:00
|
|
|
struct OptionSetValueChecker<T, EnumValues<E>> {
|
2020-05-27 21:04:41 +00:00
|
|
|
static constexpr T allValidBits()
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static constexpr bool isValidOptionSetEnum(T)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-07-12 09:47:05 +00:00
|
|
|
template<typename E, std::enable_if_t<std::is_enum<E>::value && IsTypeComplete<EnumTraits<E>>>* = nullptr>
|
2020-05-27 21:04:41 +00:00
|
|
|
constexpr bool isValidOptionSetEnum(E e)
|
|
|
|
{
|
2020-06-17 19:52:13 +00:00
|
|
|
return OptionSetValueChecker<std::underlying_type_t<E>, typename EnumTraits<E>::values>::isValidOptionSetEnum(static_cast<std::underlying_type_t<E>>(e));
|
2020-05-27 21:04:41 +00:00
|
|
|
}
|
|
|
|
|
2020-07-12 09:47:05 +00:00
|
|
|
template<typename E, std::enable_if_t<std::is_enum<E>::value && !IsTypeComplete<EnumTraits<E>>>* = nullptr>
|
2020-05-27 21:04:41 +00:00
|
|
|
constexpr bool isValidOptionSetEnum(E e)
|
|
|
|
{
|
2020-06-17 19:52:13 +00:00
|
|
|
// FIXME: Remove once all OptionSet<> enums have EnumTraits<> defined.
|
2020-05-27 21:04:41 +00:00
|
|
|
return hasOneBitSet(static_cast<typename OptionSet<E>::StorageType>(e));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-12 09:47:05 +00:00
|
|
|
template<typename E, std::enable_if_t<std::is_enum<E>::value && IsTypeComplete<EnumTraits<E>>>* = nullptr>
|
2020-05-27 21:04:41 +00:00
|
|
|
constexpr typename OptionSet<E>::StorageType maskRawValue(typename OptionSet<E>::StorageType rawValue)
|
|
|
|
{
|
2020-06-17 19:52:13 +00:00
|
|
|
auto allValidBitsValue = OptionSetValueChecker<std::underlying_type_t<E>, typename EnumTraits<E>::values>::allValidBits();
|
2020-05-27 21:04:41 +00:00
|
|
|
return rawValue & allValidBitsValue;
|
|
|
|
}
|
|
|
|
|
2020-07-12 09:47:05 +00:00
|
|
|
template<typename E, std::enable_if_t<std::is_enum<E>::value && !IsTypeComplete<EnumTraits<E>>>* = nullptr>
|
2020-05-27 21:04:41 +00:00
|
|
|
constexpr typename OptionSet<E>::StorageType maskRawValue(typename OptionSet<E>::StorageType rawValue)
|
|
|
|
{
|
2020-06-17 19:52:13 +00:00
|
|
|
// FIXME: Remove once all OptionSet<> enums have EnumTraits<> defined.
|
2020-05-27 21:04:41 +00:00
|
|
|
return rawValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-03-08 19:33:10 +00:00
|
|
|
// OptionSet is a class that represents a set of enumerators in a space-efficient manner. The enumerators
|
|
|
|
// must be powers of two greater than 0. This class is useful as a replacement for passing a bitmask of
|
|
|
|
// enumerators around.
|
2020-05-27 21:04:41 +00:00
|
|
|
template<typename E> class OptionSet {
|
2019-08-12 20:57:15 +00:00
|
|
|
WTF_MAKE_FAST_ALLOCATED;
|
2020-05-27 21:04:41 +00:00
|
|
|
static_assert(std::is_enum<E>::value, "T is not an enum type");
|
2016-02-26 19:49:36 +00:00
|
|
|
|
|
|
|
public:
|
2020-05-27 21:04:41 +00:00
|
|
|
using StorageType = std::make_unsigned_t<std::underlying_type_t<E>>;
|
2019-11-26 01:55:32 +00:00
|
|
|
|
2016-03-08 19:33:10 +00:00
|
|
|
template<typename StorageType> class Iterator {
|
2019-08-12 20:57:15 +00:00
|
|
|
WTF_MAKE_FAST_ALLOCATED;
|
2016-03-08 19:33:10 +00:00
|
|
|
public:
|
|
|
|
// Isolate the rightmost set bit.
|
2020-05-27 21:04:41 +00:00
|
|
|
E operator*() const { return static_cast<E>(m_value & -m_value); }
|
2016-03-08 19:33:10 +00:00
|
|
|
|
|
|
|
// Iterates from smallest to largest enum value by turning off the rightmost set bit.
|
|
|
|
Iterator& operator++()
|
|
|
|
{
|
|
|
|
m_value &= m_value - 1;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
Iterator& operator++(int) = delete;
|
|
|
|
|
|
|
|
bool operator==(const Iterator& other) const { return m_value == other.m_value; }
|
|
|
|
bool operator!=(const Iterator& other) const { return m_value != other.m_value; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
Iterator(StorageType value) : m_value(value) { }
|
|
|
|
friend OptionSet;
|
|
|
|
|
|
|
|
StorageType m_value;
|
|
|
|
};
|
|
|
|
using iterator = Iterator<StorageType>;
|
|
|
|
|
2020-05-27 21:04:41 +00:00
|
|
|
static constexpr OptionSet fromRaw(StorageType rawValue)
|
2016-02-26 19:49:36 +00:00
|
|
|
{
|
2020-05-27 21:04:41 +00:00
|
|
|
return OptionSet(static_cast<E>(maskRawValue<E>(rawValue)), FromRawValue);
|
2016-02-26 19:49:36 +00:00
|
|
|
}
|
|
|
|
|
2016-03-03 23:49:18 +00:00
|
|
|
constexpr OptionSet() = default;
|
2016-02-26 19:49:36 +00:00
|
|
|
|
2020-05-27 21:04:41 +00:00
|
|
|
constexpr OptionSet(E e)
|
|
|
|
: m_storage(static_cast<StorageType>(e))
|
2016-02-26 19:49:36 +00:00
|
|
|
{
|
2020-05-27 21:04:41 +00:00
|
|
|
ASSERT(!m_storage || isValidOptionSetEnum(e));
|
2016-02-26 19:49:36 +00:00
|
|
|
}
|
2018-05-04 15:35:29 +00:00
|
|
|
|
2020-05-27 21:04:41 +00:00
|
|
|
constexpr OptionSet(std::initializer_list<E> initializerList)
|
2016-03-03 23:49:18 +00:00
|
|
|
{
|
2016-03-08 19:33:10 +00:00
|
|
|
for (auto& option : initializerList) {
|
2020-05-27 21:04:41 +00:00
|
|
|
ASSERT(isValidOptionSetEnum(option));
|
2016-03-03 23:49:18 +00:00
|
|
|
m_storage |= static_cast<StorageType>(option);
|
2016-03-08 19:33:10 +00:00
|
|
|
}
|
2016-03-03 23:49:18 +00:00
|
|
|
}
|
|
|
|
|
2021-05-30 16:11:40 +00:00
|
|
|
constexpr OptionSet(std::optional<E> optional)
|
2020-06-06 15:17:30 +00:00
|
|
|
: m_storage(optional ? static_cast<StorageType>(*optional) : 0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-02-26 19:49:36 +00:00
|
|
|
constexpr StorageType toRaw() const { return m_storage; }
|
|
|
|
|
2016-03-08 19:33:10 +00:00
|
|
|
constexpr bool isEmpty() const { return !m_storage; }
|
|
|
|
|
|
|
|
constexpr iterator begin() const { return m_storage; }
|
|
|
|
constexpr iterator end() const { return 0; }
|
|
|
|
|
2018-05-09 07:05:46 +00:00
|
|
|
constexpr explicit operator bool() { return !isEmpty(); }
|
|
|
|
|
2020-05-27 21:04:41 +00:00
|
|
|
constexpr bool contains(E option) const
|
2016-02-26 19:49:36 +00:00
|
|
|
{
|
2018-08-14 05:55:10 +00:00
|
|
|
return containsAny(option);
|
2018-08-13 19:16:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
constexpr bool containsAny(OptionSet optionSet) const
|
|
|
|
{
|
|
|
|
return !!(*this & optionSet);
|
|
|
|
}
|
|
|
|
|
|
|
|
constexpr bool containsAll(OptionSet optionSet) const
|
|
|
|
{
|
|
|
|
return (*this & optionSet) == optionSet;
|
2016-02-26 19:49:36 +00:00
|
|
|
}
|
|
|
|
|
2018-08-31 17:59:01 +00:00
|
|
|
constexpr void add(OptionSet optionSet)
|
2016-09-27 19:08:34 +00:00
|
|
|
{
|
2018-08-31 17:59:01 +00:00
|
|
|
m_storage |= optionSet.m_storage;
|
2016-09-27 19:08:34 +00:00
|
|
|
}
|
|
|
|
|
2018-08-31 17:59:01 +00:00
|
|
|
constexpr void remove(OptionSet optionSet)
|
2016-09-27 19:08:34 +00:00
|
|
|
{
|
2018-08-31 17:59:01 +00:00
|
|
|
m_storage &= ~optionSet.m_storage;
|
2016-09-27 19:08:34 +00:00
|
|
|
}
|
|
|
|
|
2020-09-09 09:03:48 +00:00
|
|
|
constexpr void set(OptionSet optionSet, bool value)
|
|
|
|
{
|
2020-09-10 03:40:23 +00:00
|
|
|
if (value)
|
|
|
|
add(optionSet);
|
|
|
|
else
|
|
|
|
remove(optionSet);
|
2020-09-09 09:03:48 +00:00
|
|
|
}
|
|
|
|
|
2020-06-11 18:54:13 +00:00
|
|
|
constexpr bool hasExactlyOneBitSet() const
|
|
|
|
{
|
|
|
|
return m_storage && !(m_storage & (m_storage - 1));
|
|
|
|
}
|
|
|
|
|
2021-05-30 16:11:40 +00:00
|
|
|
constexpr std::optional<E> toSingleValue() const
|
2020-06-11 18:54:13 +00:00
|
|
|
{
|
2021-05-30 16:11:40 +00:00
|
|
|
return hasExactlyOneBitSet() ? std::optional<E>(static_cast<E>(m_storage)) : std::nullopt;
|
2020-06-11 18:54:13 +00:00
|
|
|
}
|
|
|
|
|
2018-08-31 17:59:01 +00:00
|
|
|
constexpr friend bool operator==(OptionSet lhs, OptionSet rhs)
|
2016-02-26 19:49:36 +00:00
|
|
|
{
|
2018-08-31 17:59:01 +00:00
|
|
|
return lhs.m_storage == rhs.m_storage;
|
2016-02-26 19:49:36 +00:00
|
|
|
}
|
|
|
|
|
2018-08-31 17:59:01 +00:00
|
|
|
constexpr friend bool operator!=(OptionSet lhs, OptionSet rhs)
|
2017-02-28 21:26:27 +00:00
|
|
|
{
|
2018-08-31 17:59:01 +00:00
|
|
|
return lhs.m_storage != rhs.m_storage;
|
2017-02-28 21:26:27 +00:00
|
|
|
}
|
|
|
|
|
Fix dictionary leak in lookup, convert FindOptions to OptionSet, tweak code style nearby
https://bugs.webkit.org/show_bug.cgi?id=179981
Reviewed by Sam Weinig.
Source/WebCore:
* accessibility/AXObjectCache.cpp:
(WebCore::AXObjectCache::rangeMatchesTextNearRange): Pass { } instead of 0.
* accessibility/AccessibilityObject.cpp:
(WebCore::AccessibilityObject::rangeOfStringClosestToRangeInDirection const): Use { }
instead of | to construct value.
* editing/Editor.cpp:
(WebCore::Editor::findString): Use contains instead of & to test an option.
(WebCore::Editor::rangeOfString): Ditto.
(WebCore::Editor::countMatchesForText): Ditto.
* editing/EditorCommand.cpp:
(WebCore::executeFindString): Use { } instead of | to construct value.
* editing/FindOptions.h: Use OptionSet for type.
* editing/TextIterator.cpp:
(WebCore::SearchBuffer::SearchBuffer): Use contains instead of &. Also use -= instead
of &= coupled with ~ to remove a flag.
(WebCore::SearchBuffer::isWordEndMatch const): Ditto.
(WebCore::SearchBuffer::isWordStartMatch const): Ditto.
(WebCore::SearchBuffer::search): Ditto.
(WebCore::findIteratorOptions): Ditto.
(WebCore::findClosestPlainText): Ditto.
(WebCore::findPlainText): Ditto.
* editing/mac/DictionaryLookup.h: Changed optional dictionary out arguments to
RetainPtr<NSDictionary>. Before, they were returning a retained object, but callers
did not seem to realize that.
* editing/mac/DictionaryLookup.mm:
(WebCore::tokenRange): Added helper. Takes care of doing adoptNS on the options
dictionary, and also handles the Objective-C exception possibility cleanly. Also
fixed the exception case to return NSNotFound instead of a zero-length range at
the location we are searching, which is what the code expects.
(WebCore::DictionaryLookup::rangeForSelection): Refactored to use the tokenRange
helper function, and also to do much less work when the options pointer is null.
(WebCore::DictionaryLookup::rangeAtHitTestResult): Use the tokenRange helper
function and also use auto a bunch to tighten up the code a bit.
(WebCore::DictionaryLookup::stringForPDFSelection): Ditto.
* page/DOMWindow.cpp:
(WebCore::DOMWindow::find const): Use |= instead of | to build find options.
* page/Page.cpp:
(WebCore::Page::findString): Use contains instead of & and also - instead of
& combined with ~.
(WebCore::Page::findStringMatchingRanges): Ditto.
(WebCore::Page::rangeOfString): Ditto.
* page/mac/EventHandlerMac.mm:
(WebCore::EventHandler::selectClosestWordFromHitTestResultBasedOnLookup):
Pass nullptr to indicate we don't need the options dictionary. The code before
was passing a pointer to a null, which meant we would do the work to get the
options dictionary, not use it, and also leak it.
* testing/Internals.cpp:
(WebCore::Internals::rangeOfStringNearLocation): Pass { } instead of 0.
(WebCore::Internals::rangeForDictionaryLookupAtLocation): Pass nullptr to
indicate we don't need the options dictionary as above.
(WebCore::parseFindOptions): Initialize options without an explicit 0, since
an OptionSet starts out empty rather than uninitialized.
Source/WebKit:
* WebProcess/Plugins/PDF/PDFPlugin.h: Use some references instead of pointers. Made more
things final and private. Changed functions with multiple return values to use tuples
instead of out arguments for clarity, especially because some were using pointers and it
was ambiguous whether the pointers could be nullptr. Tweaked formatting. Moved initialization
of data members into the class definition.
* WebProcess/Plugins/PDF/PDFPlugin.mm:
(WebKit::PDFPlugin::create): Take a reference.
(WebKit::PDFPlugin::PDFPlugin): Ditto. Also moved some initialization to the class definition.
(WebKit::PDFPlugin::countFindMatches): Added comment about ignored maxMatchCount argument.
(WebKit::PDFPlugin::findString): Use contains instead of & to check bits in options.
Simplified slightly confusing match count code that was doing some unnecessary comparisons
with the maximum match count. Use auto a bit.
(WebKit::coreCursor): Renamed from pdfLayerControllerCursorTypeToCursor since this is C++
and overloading works based on the argument type.
(WebKit::PDFPlugin::notifyCursorChanged): Updated for name change.
(WebKit::PDFPlugin::lookupTextAtLocation const): Return a tuple instead of using two out
arguments and use a RetainPtr so we don't leak the options dictionary.
* WebProcess/Plugins/PluginProxy.h: Removed unneeded include of FindOptions.h.
* WebProcess/WebCoreSupport/mac/WebContextMenuClientMac.mm:
(WebKit::WebContextMenuClient::lookUpInDictionary): Pass a reference.
* WebProcess/WebPage/FindController.cpp:
(WebKit::core): Use |= instead of | to build up a FindOptions.
(WebKit::FindController::FindController): Initialize data members in the class definition.
(WebKit::pluginViewForFrame): Deleted. Callers now use WebPage::pluginViewForFrame.
(WebKit::FindController::updateFindUIAfterPageScroll): Added a FIXME about some peculiar code.
(WebKit::FindController::findString): Use |= rather than | to add in an option.
(WebKit::FindController::hideFindUI): Use { } rather than 0 for no options.
* WebProcess/WebPage/FindController.h: Moved initialization to the header. Exported the core
function that converts WebKit::FindOptions to WebCore::FindOptions.
* WebProcess/WebPage/WebFrame.cpp:
(WebKit::WebFrame::handlesPageScaleGesture const): Use WebPage::pluginViewForFrame.
(WebKit::WebFrame::requiresUnifiedScaleFactor const): Use WebPage::pluginViewForFrame.
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::createPlugin): Removed unneeded local variable and UNUSED_PARAM.
(WebKit::WebPage::focusedPluginViewForFrame): Use pluginViewForFrame.
(WebKit::WebPage::pluginViewForFrame): Added a null check since this takes a pointer.
Use is/downcast insteadof more ad hoc coding style.
(WebKit::WebPage::findStringFromInjectedBundle): Call core to convert WebKit::FindOptions
to WebCore::FindOptions. Before, this was accidentally relying on the bits from the two
enumrations matching! The stricter type checking of OptionSet helps us catch mistakes
like this.
* WebProcess/WebPage/WebPage.h: Updated for the above. Also flattened out nested #if
statements, made forward declarations unconditional, and re-sorted them. Changed the
Mac-specific lookupTextAtLocation to return a tuple (see below).
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::performDictionaryLookupForSelection): Take a reference instead of a pointer.
(WebKit::WebPage::performDictionaryLookupForRange): Ditto.
(WebKit::rangeNearPositionMatchesText): Use { } rather than 0 for no options.
* WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::WebPage::performDictionaryLookupAtLocation): Use RetainPtr<NSDictionary> to fix
code that used to leak.
(WebKit::WebPage::performDictionaryLookupForSelection): Ditto.
(WebKit::WebPage::performDictionaryLookupOfCurrentSelection): Use a reference.
(WebKit::WebPage::dictionaryPopupInfoForRange): Updated for changed argument types.
(WebKit::WebPage::dictionaryPopupInfoForSelectionInPDFPlugin): Ditto.
(WebKit::WebPage::performDictionaryLookupForRange): Ditto.
(WebKit::WebPage::performImmediateActionHitTestAtLocation): Updated to handle the
tuple result from the lookupTextAtLocation functions.
(WebKit::WebPage::lookupTextAtLocation): Changed to return a tuple and use RetainPtr
for the NSDictionary to help fix the leak.
Source/WebKitLegacy/mac:
* WebView/WebImmediateActionController.mm:
(-[WebImmediateActionController _animationControllerForText]): Use RetainPtr so we don't leak.
* WebView/WebView.mm:
(coreOptions): Use |= instead of | to build up FindOptions.
Source/WebKitLegacy/win:
* WebView.cpp:
(WebView::searchFor): Use |= instead of | to build FindOptions.
(WebView::markAllMatchesForText): Create FindOptions with |= instead of |.
(WebView::findString): Create FindOptions with |=; the old code just passed a
WebKit FindOptions through without converting to WebCore::FindOptions.
Source/WTF:
* wtf/OptionSet.h: Added some operators so it's easier to use | and - with individual
options from the set.
Canonical link: https://commits.webkit.org/196010@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225142 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-11-25 01:09:58 +00:00
|
|
|
constexpr friend OptionSet operator|(OptionSet lhs, OptionSet rhs)
|
|
|
|
{
|
|
|
|
return fromRaw(lhs.m_storage | rhs.m_storage);
|
|
|
|
}
|
|
|
|
|
2018-05-09 07:05:46 +00:00
|
|
|
constexpr friend OptionSet operator&(OptionSet lhs, OptionSet rhs)
|
Fix dictionary leak in lookup, convert FindOptions to OptionSet, tweak code style nearby
https://bugs.webkit.org/show_bug.cgi?id=179981
Reviewed by Sam Weinig.
Source/WebCore:
* accessibility/AXObjectCache.cpp:
(WebCore::AXObjectCache::rangeMatchesTextNearRange): Pass { } instead of 0.
* accessibility/AccessibilityObject.cpp:
(WebCore::AccessibilityObject::rangeOfStringClosestToRangeInDirection const): Use { }
instead of | to construct value.
* editing/Editor.cpp:
(WebCore::Editor::findString): Use contains instead of & to test an option.
(WebCore::Editor::rangeOfString): Ditto.
(WebCore::Editor::countMatchesForText): Ditto.
* editing/EditorCommand.cpp:
(WebCore::executeFindString): Use { } instead of | to construct value.
* editing/FindOptions.h: Use OptionSet for type.
* editing/TextIterator.cpp:
(WebCore::SearchBuffer::SearchBuffer): Use contains instead of &. Also use -= instead
of &= coupled with ~ to remove a flag.
(WebCore::SearchBuffer::isWordEndMatch const): Ditto.
(WebCore::SearchBuffer::isWordStartMatch const): Ditto.
(WebCore::SearchBuffer::search): Ditto.
(WebCore::findIteratorOptions): Ditto.
(WebCore::findClosestPlainText): Ditto.
(WebCore::findPlainText): Ditto.
* editing/mac/DictionaryLookup.h: Changed optional dictionary out arguments to
RetainPtr<NSDictionary>. Before, they were returning a retained object, but callers
did not seem to realize that.
* editing/mac/DictionaryLookup.mm:
(WebCore::tokenRange): Added helper. Takes care of doing adoptNS on the options
dictionary, and also handles the Objective-C exception possibility cleanly. Also
fixed the exception case to return NSNotFound instead of a zero-length range at
the location we are searching, which is what the code expects.
(WebCore::DictionaryLookup::rangeForSelection): Refactored to use the tokenRange
helper function, and also to do much less work when the options pointer is null.
(WebCore::DictionaryLookup::rangeAtHitTestResult): Use the tokenRange helper
function and also use auto a bunch to tighten up the code a bit.
(WebCore::DictionaryLookup::stringForPDFSelection): Ditto.
* page/DOMWindow.cpp:
(WebCore::DOMWindow::find const): Use |= instead of | to build find options.
* page/Page.cpp:
(WebCore::Page::findString): Use contains instead of & and also - instead of
& combined with ~.
(WebCore::Page::findStringMatchingRanges): Ditto.
(WebCore::Page::rangeOfString): Ditto.
* page/mac/EventHandlerMac.mm:
(WebCore::EventHandler::selectClosestWordFromHitTestResultBasedOnLookup):
Pass nullptr to indicate we don't need the options dictionary. The code before
was passing a pointer to a null, which meant we would do the work to get the
options dictionary, not use it, and also leak it.
* testing/Internals.cpp:
(WebCore::Internals::rangeOfStringNearLocation): Pass { } instead of 0.
(WebCore::Internals::rangeForDictionaryLookupAtLocation): Pass nullptr to
indicate we don't need the options dictionary as above.
(WebCore::parseFindOptions): Initialize options without an explicit 0, since
an OptionSet starts out empty rather than uninitialized.
Source/WebKit:
* WebProcess/Plugins/PDF/PDFPlugin.h: Use some references instead of pointers. Made more
things final and private. Changed functions with multiple return values to use tuples
instead of out arguments for clarity, especially because some were using pointers and it
was ambiguous whether the pointers could be nullptr. Tweaked formatting. Moved initialization
of data members into the class definition.
* WebProcess/Plugins/PDF/PDFPlugin.mm:
(WebKit::PDFPlugin::create): Take a reference.
(WebKit::PDFPlugin::PDFPlugin): Ditto. Also moved some initialization to the class definition.
(WebKit::PDFPlugin::countFindMatches): Added comment about ignored maxMatchCount argument.
(WebKit::PDFPlugin::findString): Use contains instead of & to check bits in options.
Simplified slightly confusing match count code that was doing some unnecessary comparisons
with the maximum match count. Use auto a bit.
(WebKit::coreCursor): Renamed from pdfLayerControllerCursorTypeToCursor since this is C++
and overloading works based on the argument type.
(WebKit::PDFPlugin::notifyCursorChanged): Updated for name change.
(WebKit::PDFPlugin::lookupTextAtLocation const): Return a tuple instead of using two out
arguments and use a RetainPtr so we don't leak the options dictionary.
* WebProcess/Plugins/PluginProxy.h: Removed unneeded include of FindOptions.h.
* WebProcess/WebCoreSupport/mac/WebContextMenuClientMac.mm:
(WebKit::WebContextMenuClient::lookUpInDictionary): Pass a reference.
* WebProcess/WebPage/FindController.cpp:
(WebKit::core): Use |= instead of | to build up a FindOptions.
(WebKit::FindController::FindController): Initialize data members in the class definition.
(WebKit::pluginViewForFrame): Deleted. Callers now use WebPage::pluginViewForFrame.
(WebKit::FindController::updateFindUIAfterPageScroll): Added a FIXME about some peculiar code.
(WebKit::FindController::findString): Use |= rather than | to add in an option.
(WebKit::FindController::hideFindUI): Use { } rather than 0 for no options.
* WebProcess/WebPage/FindController.h: Moved initialization to the header. Exported the core
function that converts WebKit::FindOptions to WebCore::FindOptions.
* WebProcess/WebPage/WebFrame.cpp:
(WebKit::WebFrame::handlesPageScaleGesture const): Use WebPage::pluginViewForFrame.
(WebKit::WebFrame::requiresUnifiedScaleFactor const): Use WebPage::pluginViewForFrame.
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::createPlugin): Removed unneeded local variable and UNUSED_PARAM.
(WebKit::WebPage::focusedPluginViewForFrame): Use pluginViewForFrame.
(WebKit::WebPage::pluginViewForFrame): Added a null check since this takes a pointer.
Use is/downcast insteadof more ad hoc coding style.
(WebKit::WebPage::findStringFromInjectedBundle): Call core to convert WebKit::FindOptions
to WebCore::FindOptions. Before, this was accidentally relying on the bits from the two
enumrations matching! The stricter type checking of OptionSet helps us catch mistakes
like this.
* WebProcess/WebPage/WebPage.h: Updated for the above. Also flattened out nested #if
statements, made forward declarations unconditional, and re-sorted them. Changed the
Mac-specific lookupTextAtLocation to return a tuple (see below).
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::performDictionaryLookupForSelection): Take a reference instead of a pointer.
(WebKit::WebPage::performDictionaryLookupForRange): Ditto.
(WebKit::rangeNearPositionMatchesText): Use { } rather than 0 for no options.
* WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::WebPage::performDictionaryLookupAtLocation): Use RetainPtr<NSDictionary> to fix
code that used to leak.
(WebKit::WebPage::performDictionaryLookupForSelection): Ditto.
(WebKit::WebPage::performDictionaryLookupOfCurrentSelection): Use a reference.
(WebKit::WebPage::dictionaryPopupInfoForRange): Updated for changed argument types.
(WebKit::WebPage::dictionaryPopupInfoForSelectionInPDFPlugin): Ditto.
(WebKit::WebPage::performDictionaryLookupForRange): Ditto.
(WebKit::WebPage::performImmediateActionHitTestAtLocation): Updated to handle the
tuple result from the lookupTextAtLocation functions.
(WebKit::WebPage::lookupTextAtLocation): Changed to return a tuple and use RetainPtr
for the NSDictionary to help fix the leak.
Source/WebKitLegacy/mac:
* WebView/WebImmediateActionController.mm:
(-[WebImmediateActionController _animationControllerForText]): Use RetainPtr so we don't leak.
* WebView/WebView.mm:
(coreOptions): Use |= instead of | to build up FindOptions.
Source/WebKitLegacy/win:
* WebView.cpp:
(WebView::searchFor): Use |= instead of | to build FindOptions.
(WebView::markAllMatchesForText): Create FindOptions with |= instead of |.
(WebView::findString): Create FindOptions with |=; the old code just passed a
WebKit FindOptions through without converting to WebCore::FindOptions.
Source/WTF:
* wtf/OptionSet.h: Added some operators so it's easier to use | and - with individual
options from the set.
Canonical link: https://commits.webkit.org/196010@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225142 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-11-25 01:09:58 +00:00
|
|
|
{
|
2018-05-09 07:05:46 +00:00
|
|
|
return fromRaw(lhs.m_storage & rhs.m_storage);
|
Fix dictionary leak in lookup, convert FindOptions to OptionSet, tweak code style nearby
https://bugs.webkit.org/show_bug.cgi?id=179981
Reviewed by Sam Weinig.
Source/WebCore:
* accessibility/AXObjectCache.cpp:
(WebCore::AXObjectCache::rangeMatchesTextNearRange): Pass { } instead of 0.
* accessibility/AccessibilityObject.cpp:
(WebCore::AccessibilityObject::rangeOfStringClosestToRangeInDirection const): Use { }
instead of | to construct value.
* editing/Editor.cpp:
(WebCore::Editor::findString): Use contains instead of & to test an option.
(WebCore::Editor::rangeOfString): Ditto.
(WebCore::Editor::countMatchesForText): Ditto.
* editing/EditorCommand.cpp:
(WebCore::executeFindString): Use { } instead of | to construct value.
* editing/FindOptions.h: Use OptionSet for type.
* editing/TextIterator.cpp:
(WebCore::SearchBuffer::SearchBuffer): Use contains instead of &. Also use -= instead
of &= coupled with ~ to remove a flag.
(WebCore::SearchBuffer::isWordEndMatch const): Ditto.
(WebCore::SearchBuffer::isWordStartMatch const): Ditto.
(WebCore::SearchBuffer::search): Ditto.
(WebCore::findIteratorOptions): Ditto.
(WebCore::findClosestPlainText): Ditto.
(WebCore::findPlainText): Ditto.
* editing/mac/DictionaryLookup.h: Changed optional dictionary out arguments to
RetainPtr<NSDictionary>. Before, they were returning a retained object, but callers
did not seem to realize that.
* editing/mac/DictionaryLookup.mm:
(WebCore::tokenRange): Added helper. Takes care of doing adoptNS on the options
dictionary, and also handles the Objective-C exception possibility cleanly. Also
fixed the exception case to return NSNotFound instead of a zero-length range at
the location we are searching, which is what the code expects.
(WebCore::DictionaryLookup::rangeForSelection): Refactored to use the tokenRange
helper function, and also to do much less work when the options pointer is null.
(WebCore::DictionaryLookup::rangeAtHitTestResult): Use the tokenRange helper
function and also use auto a bunch to tighten up the code a bit.
(WebCore::DictionaryLookup::stringForPDFSelection): Ditto.
* page/DOMWindow.cpp:
(WebCore::DOMWindow::find const): Use |= instead of | to build find options.
* page/Page.cpp:
(WebCore::Page::findString): Use contains instead of & and also - instead of
& combined with ~.
(WebCore::Page::findStringMatchingRanges): Ditto.
(WebCore::Page::rangeOfString): Ditto.
* page/mac/EventHandlerMac.mm:
(WebCore::EventHandler::selectClosestWordFromHitTestResultBasedOnLookup):
Pass nullptr to indicate we don't need the options dictionary. The code before
was passing a pointer to a null, which meant we would do the work to get the
options dictionary, not use it, and also leak it.
* testing/Internals.cpp:
(WebCore::Internals::rangeOfStringNearLocation): Pass { } instead of 0.
(WebCore::Internals::rangeForDictionaryLookupAtLocation): Pass nullptr to
indicate we don't need the options dictionary as above.
(WebCore::parseFindOptions): Initialize options without an explicit 0, since
an OptionSet starts out empty rather than uninitialized.
Source/WebKit:
* WebProcess/Plugins/PDF/PDFPlugin.h: Use some references instead of pointers. Made more
things final and private. Changed functions with multiple return values to use tuples
instead of out arguments for clarity, especially because some were using pointers and it
was ambiguous whether the pointers could be nullptr. Tweaked formatting. Moved initialization
of data members into the class definition.
* WebProcess/Plugins/PDF/PDFPlugin.mm:
(WebKit::PDFPlugin::create): Take a reference.
(WebKit::PDFPlugin::PDFPlugin): Ditto. Also moved some initialization to the class definition.
(WebKit::PDFPlugin::countFindMatches): Added comment about ignored maxMatchCount argument.
(WebKit::PDFPlugin::findString): Use contains instead of & to check bits in options.
Simplified slightly confusing match count code that was doing some unnecessary comparisons
with the maximum match count. Use auto a bit.
(WebKit::coreCursor): Renamed from pdfLayerControllerCursorTypeToCursor since this is C++
and overloading works based on the argument type.
(WebKit::PDFPlugin::notifyCursorChanged): Updated for name change.
(WebKit::PDFPlugin::lookupTextAtLocation const): Return a tuple instead of using two out
arguments and use a RetainPtr so we don't leak the options dictionary.
* WebProcess/Plugins/PluginProxy.h: Removed unneeded include of FindOptions.h.
* WebProcess/WebCoreSupport/mac/WebContextMenuClientMac.mm:
(WebKit::WebContextMenuClient::lookUpInDictionary): Pass a reference.
* WebProcess/WebPage/FindController.cpp:
(WebKit::core): Use |= instead of | to build up a FindOptions.
(WebKit::FindController::FindController): Initialize data members in the class definition.
(WebKit::pluginViewForFrame): Deleted. Callers now use WebPage::pluginViewForFrame.
(WebKit::FindController::updateFindUIAfterPageScroll): Added a FIXME about some peculiar code.
(WebKit::FindController::findString): Use |= rather than | to add in an option.
(WebKit::FindController::hideFindUI): Use { } rather than 0 for no options.
* WebProcess/WebPage/FindController.h: Moved initialization to the header. Exported the core
function that converts WebKit::FindOptions to WebCore::FindOptions.
* WebProcess/WebPage/WebFrame.cpp:
(WebKit::WebFrame::handlesPageScaleGesture const): Use WebPage::pluginViewForFrame.
(WebKit::WebFrame::requiresUnifiedScaleFactor const): Use WebPage::pluginViewForFrame.
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::createPlugin): Removed unneeded local variable and UNUSED_PARAM.
(WebKit::WebPage::focusedPluginViewForFrame): Use pluginViewForFrame.
(WebKit::WebPage::pluginViewForFrame): Added a null check since this takes a pointer.
Use is/downcast insteadof more ad hoc coding style.
(WebKit::WebPage::findStringFromInjectedBundle): Call core to convert WebKit::FindOptions
to WebCore::FindOptions. Before, this was accidentally relying on the bits from the two
enumrations matching! The stricter type checking of OptionSet helps us catch mistakes
like this.
* WebProcess/WebPage/WebPage.h: Updated for the above. Also flattened out nested #if
statements, made forward declarations unconditional, and re-sorted them. Changed the
Mac-specific lookupTextAtLocation to return a tuple (see below).
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::performDictionaryLookupForSelection): Take a reference instead of a pointer.
(WebKit::WebPage::performDictionaryLookupForRange): Ditto.
(WebKit::rangeNearPositionMatchesText): Use { } rather than 0 for no options.
* WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::WebPage::performDictionaryLookupAtLocation): Use RetainPtr<NSDictionary> to fix
code that used to leak.
(WebKit::WebPage::performDictionaryLookupForSelection): Ditto.
(WebKit::WebPage::performDictionaryLookupOfCurrentSelection): Use a reference.
(WebKit::WebPage::dictionaryPopupInfoForRange): Updated for changed argument types.
(WebKit::WebPage::dictionaryPopupInfoForSelectionInPDFPlugin): Ditto.
(WebKit::WebPage::performDictionaryLookupForRange): Ditto.
(WebKit::WebPage::performImmediateActionHitTestAtLocation): Updated to handle the
tuple result from the lookupTextAtLocation functions.
(WebKit::WebPage::lookupTextAtLocation): Changed to return a tuple and use RetainPtr
for the NSDictionary to help fix the leak.
Source/WebKitLegacy/mac:
* WebView/WebImmediateActionController.mm:
(-[WebImmediateActionController _animationControllerForText]): Use RetainPtr so we don't leak.
* WebView/WebView.mm:
(coreOptions): Use |= instead of | to build up FindOptions.
Source/WebKitLegacy/win:
* WebView.cpp:
(WebView::searchFor): Use |= instead of | to build FindOptions.
(WebView::markAllMatchesForText): Create FindOptions with |= instead of |.
(WebView::findString): Create FindOptions with |=; the old code just passed a
WebKit FindOptions through without converting to WebCore::FindOptions.
Source/WTF:
* wtf/OptionSet.h: Added some operators so it's easier to use | and - with individual
options from the set.
Canonical link: https://commits.webkit.org/196010@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225142 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-11-25 01:09:58 +00:00
|
|
|
}
|
|
|
|
|
2016-09-27 19:08:34 +00:00
|
|
|
constexpr friend OptionSet operator-(OptionSet lhs, OptionSet rhs)
|
|
|
|
{
|
Fix dictionary leak in lookup, convert FindOptions to OptionSet, tweak code style nearby
https://bugs.webkit.org/show_bug.cgi?id=179981
Reviewed by Sam Weinig.
Source/WebCore:
* accessibility/AXObjectCache.cpp:
(WebCore::AXObjectCache::rangeMatchesTextNearRange): Pass { } instead of 0.
* accessibility/AccessibilityObject.cpp:
(WebCore::AccessibilityObject::rangeOfStringClosestToRangeInDirection const): Use { }
instead of | to construct value.
* editing/Editor.cpp:
(WebCore::Editor::findString): Use contains instead of & to test an option.
(WebCore::Editor::rangeOfString): Ditto.
(WebCore::Editor::countMatchesForText): Ditto.
* editing/EditorCommand.cpp:
(WebCore::executeFindString): Use { } instead of | to construct value.
* editing/FindOptions.h: Use OptionSet for type.
* editing/TextIterator.cpp:
(WebCore::SearchBuffer::SearchBuffer): Use contains instead of &. Also use -= instead
of &= coupled with ~ to remove a flag.
(WebCore::SearchBuffer::isWordEndMatch const): Ditto.
(WebCore::SearchBuffer::isWordStartMatch const): Ditto.
(WebCore::SearchBuffer::search): Ditto.
(WebCore::findIteratorOptions): Ditto.
(WebCore::findClosestPlainText): Ditto.
(WebCore::findPlainText): Ditto.
* editing/mac/DictionaryLookup.h: Changed optional dictionary out arguments to
RetainPtr<NSDictionary>. Before, they were returning a retained object, but callers
did not seem to realize that.
* editing/mac/DictionaryLookup.mm:
(WebCore::tokenRange): Added helper. Takes care of doing adoptNS on the options
dictionary, and also handles the Objective-C exception possibility cleanly. Also
fixed the exception case to return NSNotFound instead of a zero-length range at
the location we are searching, which is what the code expects.
(WebCore::DictionaryLookup::rangeForSelection): Refactored to use the tokenRange
helper function, and also to do much less work when the options pointer is null.
(WebCore::DictionaryLookup::rangeAtHitTestResult): Use the tokenRange helper
function and also use auto a bunch to tighten up the code a bit.
(WebCore::DictionaryLookup::stringForPDFSelection): Ditto.
* page/DOMWindow.cpp:
(WebCore::DOMWindow::find const): Use |= instead of | to build find options.
* page/Page.cpp:
(WebCore::Page::findString): Use contains instead of & and also - instead of
& combined with ~.
(WebCore::Page::findStringMatchingRanges): Ditto.
(WebCore::Page::rangeOfString): Ditto.
* page/mac/EventHandlerMac.mm:
(WebCore::EventHandler::selectClosestWordFromHitTestResultBasedOnLookup):
Pass nullptr to indicate we don't need the options dictionary. The code before
was passing a pointer to a null, which meant we would do the work to get the
options dictionary, not use it, and also leak it.
* testing/Internals.cpp:
(WebCore::Internals::rangeOfStringNearLocation): Pass { } instead of 0.
(WebCore::Internals::rangeForDictionaryLookupAtLocation): Pass nullptr to
indicate we don't need the options dictionary as above.
(WebCore::parseFindOptions): Initialize options without an explicit 0, since
an OptionSet starts out empty rather than uninitialized.
Source/WebKit:
* WebProcess/Plugins/PDF/PDFPlugin.h: Use some references instead of pointers. Made more
things final and private. Changed functions with multiple return values to use tuples
instead of out arguments for clarity, especially because some were using pointers and it
was ambiguous whether the pointers could be nullptr. Tweaked formatting. Moved initialization
of data members into the class definition.
* WebProcess/Plugins/PDF/PDFPlugin.mm:
(WebKit::PDFPlugin::create): Take a reference.
(WebKit::PDFPlugin::PDFPlugin): Ditto. Also moved some initialization to the class definition.
(WebKit::PDFPlugin::countFindMatches): Added comment about ignored maxMatchCount argument.
(WebKit::PDFPlugin::findString): Use contains instead of & to check bits in options.
Simplified slightly confusing match count code that was doing some unnecessary comparisons
with the maximum match count. Use auto a bit.
(WebKit::coreCursor): Renamed from pdfLayerControllerCursorTypeToCursor since this is C++
and overloading works based on the argument type.
(WebKit::PDFPlugin::notifyCursorChanged): Updated for name change.
(WebKit::PDFPlugin::lookupTextAtLocation const): Return a tuple instead of using two out
arguments and use a RetainPtr so we don't leak the options dictionary.
* WebProcess/Plugins/PluginProxy.h: Removed unneeded include of FindOptions.h.
* WebProcess/WebCoreSupport/mac/WebContextMenuClientMac.mm:
(WebKit::WebContextMenuClient::lookUpInDictionary): Pass a reference.
* WebProcess/WebPage/FindController.cpp:
(WebKit::core): Use |= instead of | to build up a FindOptions.
(WebKit::FindController::FindController): Initialize data members in the class definition.
(WebKit::pluginViewForFrame): Deleted. Callers now use WebPage::pluginViewForFrame.
(WebKit::FindController::updateFindUIAfterPageScroll): Added a FIXME about some peculiar code.
(WebKit::FindController::findString): Use |= rather than | to add in an option.
(WebKit::FindController::hideFindUI): Use { } rather than 0 for no options.
* WebProcess/WebPage/FindController.h: Moved initialization to the header. Exported the core
function that converts WebKit::FindOptions to WebCore::FindOptions.
* WebProcess/WebPage/WebFrame.cpp:
(WebKit::WebFrame::handlesPageScaleGesture const): Use WebPage::pluginViewForFrame.
(WebKit::WebFrame::requiresUnifiedScaleFactor const): Use WebPage::pluginViewForFrame.
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::createPlugin): Removed unneeded local variable and UNUSED_PARAM.
(WebKit::WebPage::focusedPluginViewForFrame): Use pluginViewForFrame.
(WebKit::WebPage::pluginViewForFrame): Added a null check since this takes a pointer.
Use is/downcast insteadof more ad hoc coding style.
(WebKit::WebPage::findStringFromInjectedBundle): Call core to convert WebKit::FindOptions
to WebCore::FindOptions. Before, this was accidentally relying on the bits from the two
enumrations matching! The stricter type checking of OptionSet helps us catch mistakes
like this.
* WebProcess/WebPage/WebPage.h: Updated for the above. Also flattened out nested #if
statements, made forward declarations unconditional, and re-sorted them. Changed the
Mac-specific lookupTextAtLocation to return a tuple (see below).
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::performDictionaryLookupForSelection): Take a reference instead of a pointer.
(WebKit::WebPage::performDictionaryLookupForRange): Ditto.
(WebKit::rangeNearPositionMatchesText): Use { } rather than 0 for no options.
* WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::WebPage::performDictionaryLookupAtLocation): Use RetainPtr<NSDictionary> to fix
code that used to leak.
(WebKit::WebPage::performDictionaryLookupForSelection): Ditto.
(WebKit::WebPage::performDictionaryLookupOfCurrentSelection): Use a reference.
(WebKit::WebPage::dictionaryPopupInfoForRange): Updated for changed argument types.
(WebKit::WebPage::dictionaryPopupInfoForSelectionInPDFPlugin): Ditto.
(WebKit::WebPage::performDictionaryLookupForRange): Ditto.
(WebKit::WebPage::performImmediateActionHitTestAtLocation): Updated to handle the
tuple result from the lookupTextAtLocation functions.
(WebKit::WebPage::lookupTextAtLocation): Changed to return a tuple and use RetainPtr
for the NSDictionary to help fix the leak.
Source/WebKitLegacy/mac:
* WebView/WebImmediateActionController.mm:
(-[WebImmediateActionController _animationControllerForText]): Use RetainPtr so we don't leak.
* WebView/WebView.mm:
(coreOptions): Use |= instead of | to build up FindOptions.
Source/WebKitLegacy/win:
* WebView.cpp:
(WebView::searchFor): Use |= instead of | to build FindOptions.
(WebView::markAllMatchesForText): Create FindOptions with |= instead of |.
(WebView::findString): Create FindOptions with |=; the old code just passed a
WebKit FindOptions through without converting to WebCore::FindOptions.
Source/WTF:
* wtf/OptionSet.h: Added some operators so it's easier to use | and - with individual
options from the set.
Canonical link: https://commits.webkit.org/196010@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225142 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-11-25 01:09:58 +00:00
|
|
|
return fromRaw(lhs.m_storage & ~rhs.m_storage);
|
|
|
|
}
|
|
|
|
|
2018-08-16 12:49:01 +00:00
|
|
|
constexpr friend OptionSet operator^(OptionSet lhs, OptionSet rhs)
|
|
|
|
{
|
|
|
|
return fromRaw(lhs.m_storage ^ rhs.m_storage);
|
|
|
|
}
|
|
|
|
|
2016-02-26 19:49:36 +00:00
|
|
|
private:
|
2016-03-08 19:33:10 +00:00
|
|
|
enum InitializationTag { FromRawValue };
|
2020-05-27 21:04:41 +00:00
|
|
|
constexpr OptionSet(E e, InitializationTag)
|
|
|
|
: m_storage(static_cast<StorageType>(e))
|
2016-03-08 19:33:10 +00:00
|
|
|
{
|
|
|
|
}
|
2016-03-03 23:49:18 +00:00
|
|
|
StorageType m_storage { 0 };
|
2014-12-09 20:29:59 +00:00
|
|
|
};
|
|
|
|
|
2020-06-18 15:53:25 +00:00
|
|
|
template<typename E>
|
|
|
|
WARN_UNUSED_RETURN constexpr bool isValidOptionSet(OptionSet<E> optionSet)
|
|
|
|
{
|
2020-06-19 19:52:22 +00:00
|
|
|
auto allValidBitsValue = OptionSetValueChecker<std::make_unsigned_t<std::underlying_type_t<E>>, typename EnumTraits<E>::values>::allValidBits();
|
2020-06-18 15:53:25 +00:00
|
|
|
return (optionSet.toRaw() | allValidBitsValue) == allValidBitsValue;
|
|
|
|
}
|
|
|
|
|
2020-05-27 21:04:41 +00:00
|
|
|
} // namespace WTF
|
2016-02-26 19:49:36 +00:00
|
|
|
|
|
|
|
using WTF::OptionSet;
|