Title: [241588] trunk/Source/WebCore
- Revision
- 241588
- Author
- [email protected]
- Date
- 2019-02-15 08:52:33 -0800 (Fri, 15 Feb 2019)
Log Message
Refactor EditingStyle::textDirection to return an Optional<WritingDirection> instead of a bool
https://bugs.webkit.org/show_bug.cgi?id=194686
Reviewed by Ryosuke Niwa.
Changes EditingStyle::textDirection to return an Optional<WritingDirection>, instead of taking a reference to
the resulting WritingDirection. No change in behavior.
* editing/ApplyStyleCommand.cpp:
(WebCore::ApplyStyleCommand::splitAncestorsWithUnicodeBidi):
(WebCore::ApplyStyleCommand::applyInlineStyle):
* editing/EditingStyle.cpp:
(WebCore::EditingStyle::textDirection const):
(WebCore::EditingStyle::textDirectionForSelection):
* editing/EditingStyle.h:
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (241587 => 241588)
--- trunk/Source/WebCore/ChangeLog 2019-02-15 16:19:15 UTC (rev 241587)
+++ trunk/Source/WebCore/ChangeLog 2019-02-15 16:52:33 UTC (rev 241588)
@@ -1,3 +1,21 @@
+2019-02-15 Wenson Hsieh <[email protected]>
+
+ Refactor EditingStyle::textDirection to return an Optional<WritingDirection> instead of a bool
+ https://bugs.webkit.org/show_bug.cgi?id=194686
+
+ Reviewed by Ryosuke Niwa.
+
+ Changes EditingStyle::textDirection to return an Optional<WritingDirection>, instead of taking a reference to
+ the resulting WritingDirection. No change in behavior.
+
+ * editing/ApplyStyleCommand.cpp:
+ (WebCore::ApplyStyleCommand::splitAncestorsWithUnicodeBidi):
+ (WebCore::ApplyStyleCommand::applyInlineStyle):
+ * editing/EditingStyle.cpp:
+ (WebCore::EditingStyle::textDirection const):
+ (WebCore::EditingStyle::textDirectionForSelection):
+ * editing/EditingStyle.h:
+
2019-02-10 Darin Adler <[email protected]>
Replace more uses of String::format with StringConcatenate (mostly non-Apple platform-specific cases)
Modified: trunk/Source/WebCore/editing/ApplyStyleCommand.cpp (241587 => 241588)
--- trunk/Source/WebCore/editing/ApplyStyleCommand.cpp 2019-02-15 16:19:15 UTC (rev 241587)
+++ trunk/Source/WebCore/editing/ApplyStyleCommand.cpp 2019-02-15 16:52:33 UTC (rev 241588)
@@ -485,17 +485,15 @@
HTMLElement* unsplitAncestor = nullptr;
- WritingDirection highestAncestorDirection;
- if (allowedDirection != WritingDirection::Natural
- && highestAncestorUnicodeBidi != CSSValueBidiOverride
- && is<HTMLElement>(*highestAncestorWithUnicodeBidi)
- && EditingStyle::create(highestAncestorWithUnicodeBidi, EditingStyle::AllProperties)->textDirection(highestAncestorDirection)
- && highestAncestorDirection == allowedDirection) {
- if (!nextHighestAncestorWithUnicodeBidi)
- return downcast<HTMLElement>(highestAncestorWithUnicodeBidi);
+ if (allowedDirection != WritingDirection::Natural && highestAncestorUnicodeBidi != CSSValueBidiOverride && is<HTMLElement>(*highestAncestorWithUnicodeBidi)) {
+ auto highestAncestorDirection = EditingStyle::create(highestAncestorWithUnicodeBidi, EditingStyle::AllProperties)->textDirection();
+ if (highestAncestorDirection && *highestAncestorDirection == allowedDirection) {
+ if (!nextHighestAncestorWithUnicodeBidi)
+ return downcast<HTMLElement>(highestAncestorWithUnicodeBidi);
- unsplitAncestor = downcast<HTMLElement>(highestAncestorWithUnicodeBidi);
- highestAncestorWithUnicodeBidi = nextHighestAncestorWithUnicodeBidi;
+ unsplitAncestor = downcast<HTMLElement>(highestAncestorWithUnicodeBidi);
+ highestAncestorWithUnicodeBidi = nextHighestAncestorWithUnicodeBidi;
+ }
}
// Split every ancestor through highest ancestor with embedding.
@@ -616,14 +614,13 @@
// and prevent us from adding redundant ones, as described in:
// <rdar://problem/3724344> Bolding and unbolding creates extraneous tags
Position removeStart = start.upstream();
- WritingDirection textDirection = WritingDirection::Natural;
- bool hasTextDirection = style.textDirection(textDirection);
+ auto textDirection = style.textDirection();
RefPtr<EditingStyle> styleWithoutEmbedding;
RefPtr<EditingStyle> embeddingStyle;
- if (hasTextDirection) {
+ if (textDirection.hasValue()) {
// Leave alone an ancestor that provides the desired single level embedding, if there is one.
- HTMLElement* startUnsplitAncestor = splitAncestorsWithUnicodeBidi(start.deprecatedNode(), true, textDirection);
- HTMLElement* endUnsplitAncestor = splitAncestorsWithUnicodeBidi(end.deprecatedNode(), false, textDirection);
+ auto* startUnsplitAncestor = splitAncestorsWithUnicodeBidi(start.deprecatedNode(), true, *textDirection);
+ auto* endUnsplitAncestor = splitAncestorsWithUnicodeBidi(end.deprecatedNode(), false, *textDirection);
removeEmbeddingUpToEnclosingBlock(start.deprecatedNode(), startUnsplitAncestor);
removeEmbeddingUpToEnclosingBlock(end.deprecatedNode(), endUnsplitAncestor);
@@ -671,7 +668,7 @@
document().updateLayoutIgnorePendingStylesheets();
RefPtr<EditingStyle> styleToApply = &style;
- if (hasTextDirection) {
+ if (textDirection.hasValue()) {
// Avoid applying the unicode-bidi and direction properties beneath ancestors that already have them.
Node* embeddingStartNode = highestEmbeddingAncestor(start.deprecatedNode(), enclosingBlock(start.deprecatedNode()));
Node* embeddingEndNode = highestEmbeddingAncestor(end.deprecatedNode(), enclosingBlock(end.deprecatedNode()));
Modified: trunk/Source/WebCore/editing/EditingStyle.cpp (241587 => 241588)
--- trunk/Source/WebCore/editing/EditingStyle.cpp 2019-02-15 16:19:15 UTC (rev 241587)
+++ trunk/Source/WebCore/editing/EditingStyle.cpp 2019-02-15 16:52:33 UTC (rev 241588)
@@ -553,32 +553,28 @@
return style;
}
-bool EditingStyle::textDirection(WritingDirection& writingDirection) const
+Optional<WritingDirection> EditingStyle::textDirection() const
{
if (!m_mutableStyle)
- return false;
+ return WTF::nullopt;
RefPtr<CSSValue> unicodeBidi = m_mutableStyle->getPropertyCSSValue(CSSPropertyUnicodeBidi);
if (!is<CSSPrimitiveValue>(unicodeBidi))
- return false;
+ return WTF::nullopt;
CSSValueID unicodeBidiValue = downcast<CSSPrimitiveValue>(*unicodeBidi).valueID();
if (unicodeBidiValue == CSSValueEmbed) {
RefPtr<CSSValue> direction = m_mutableStyle->getPropertyCSSValue(CSSPropertyDirection);
if (!is<CSSPrimitiveValue>(direction))
- return false;
+ return WTF::nullopt;
- writingDirection = downcast<CSSPrimitiveValue>(*direction).valueID() == CSSValueLtr ? WritingDirection::LeftToRight : WritingDirection::RightToLeft;
-
- return true;
+ return downcast<CSSPrimitiveValue>(*direction).valueID() == CSSValueLtr ? WritingDirection::LeftToRight : WritingDirection::RightToLeft;
}
- if (unicodeBidiValue == CSSValueNormal) {
- writingDirection = WritingDirection::Natural;
- return true;
- }
+ if (unicodeBidiValue == CSSValueNormal)
+ return WritingDirection::Natural;
- return false;
+ return WTF::nullopt;
}
void EditingStyle::setStyle(RefPtr<MutableStyleProperties>&& style)
@@ -1497,10 +1493,11 @@
}
if (selection.isCaret()) {
- WritingDirection direction;
- if (typingStyle && typingStyle->textDirection(direction)) {
- hasNestedOrMultipleEmbeddings = false;
- return direction;
+ if (typingStyle) {
+ if (auto direction = typingStyle->textDirection()) {
+ hasNestedOrMultipleEmbeddings = false;
+ return *direction;
+ }
}
node = selection.visibleStart().deepEquivalent().deprecatedNode();
}
Modified: trunk/Source/WebCore/editing/EditingStyle.h (241587 => 241588)
--- trunk/Source/WebCore/editing/EditingStyle.h 2019-02-15 16:19:15 UTC (rev 241587)
+++ trunk/Source/WebCore/editing/EditingStyle.h 2019-02-15 16:52:33 UTC (rev 241588)
@@ -36,6 +36,7 @@
#include "StyleProperties.h"
#include "WritingDirection.h"
#include <wtf/Forward.h>
+#include <wtf/Optional.h>
#include <wtf/RefCounted.h>
#include <wtf/RefPtr.h>
#include <wtf/TriState.h>
@@ -110,7 +111,7 @@
MutableStyleProperties* style() { return m_mutableStyle.get(); }
Ref<MutableStyleProperties> styleWithResolvedTextDecorations() const;
- bool textDirection(WritingDirection&) const;
+ Optional<WritingDirection> textDirection() const;
bool isEmpty() const;
void setStyle(RefPtr<MutableStyleProperties>&&);
void overrideWithStyle(const StyleProperties&);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes