From 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c Mon Sep 17 00:00:00 2001 From: Lorry Tar Creator Date: Tue, 27 Jun 2017 06:07:23 +0000 Subject: webkitgtk-2.16.5 --- Source/WebCore/rendering/RenderText.h | 169 +++++++++++++++++++++------------- 1 file changed, 106 insertions(+), 63 deletions(-) (limited to 'Source/WebCore/rendering/RenderText.h') diff --git a/Source/WebCore/rendering/RenderText.h b/Source/WebCore/rendering/RenderText.h index 6aea9d972..31cb47680 100644 --- a/Source/WebCore/rendering/RenderText.h +++ b/Source/WebCore/rendering/RenderText.h @@ -20,18 +20,19 @@ * */ -#ifndef RenderText_h -#define RenderText_h +#pragma once #include "RenderElement.h" #include "RenderTextLineBoxes.h" #include "SimpleLineLayout.h" #include "Text.h" #include +#include namespace WebCore { class InlineTextBox; +struct GlyphOverflow; class RenderText : public RenderObject { public: @@ -40,14 +41,19 @@ public: virtual ~RenderText(); - virtual const char* renderName() const override; + const char* renderName() const override; - Text* textNode() const; + WEBCORE_EXPORT Text* textNode() const; virtual bool isTextFragment() const; - RenderStyle& style() const; - RenderStyle& firstLineStyle() const; + const RenderStyle& style() const; + const RenderStyle& firstLineStyle() const; + const RenderStyle* getCachedPseudoStyle(PseudoId, const RenderStyle* parentStyle = nullptr) const; + + Color selectionBackgroundColor() const; + Color selectionForegroundColor() const; + Color selectionEmphasisMarkColor() const; virtual String originalText() const; @@ -61,32 +67,31 @@ public: InlineTextBox* createInlineTextBox() { return m_lineBoxes.createAndAppendLineBox(*this); } void dirtyLineBoxes(bool fullLayout); - virtual void absoluteRects(Vector&, const LayoutPoint& accumulatedOffset) const override final; + void absoluteRects(Vector&, const LayoutPoint& accumulatedOffset) const final; Vector absoluteRectsForRange(unsigned startOffset = 0, unsigned endOffset = UINT_MAX, bool useSelectionHeight = false, bool* wasFixed = nullptr) const; #if PLATFORM(IOS) - virtual void collectSelectionRects(Vector&, unsigned startOffset = 0, unsigned endOffset = std::numeric_limits::max()) override; + void collectSelectionRects(Vector&, unsigned startOffset = 0, unsigned endOffset = std::numeric_limits::max()) override; #endif - virtual void absoluteQuads(Vector&, bool* wasFixed) const override final; + void absoluteQuads(Vector&, bool* wasFixed) const final; Vector absoluteQuadsForRange(unsigned startOffset = 0, unsigned endOffset = UINT_MAX, bool useSelectionHeight = false, bool* wasFixed = nullptr) const; Vector absoluteQuadsClippedToEllipsis() const; - virtual VisiblePosition positionForPoint(const LayoutPoint&) override; + Position positionForPoint(const LayoutPoint&) override; + VisiblePosition positionForPoint(const LayoutPoint&, const RenderRegion*) override; - bool is8Bit() const { return m_text.is8Bit(); } + bool is8Bit() const { return m_text.impl()->is8Bit(); } const LChar* characters8() const { return m_text.impl()->characters8(); } const UChar* characters16() const { return m_text.impl()->characters16(); } - const UChar* characters() const { return deprecatedCharacters(); } // FIXME: Delete this. - const UChar* deprecatedCharacters() const { return m_text.deprecatedCharacters(); } UChar characterAt(unsigned) const; UChar uncheckedCharacterAt(unsigned) const; UChar operator[](unsigned i) const { return uncheckedCharacterAt(i); } unsigned textLength() const { return m_text.impl()->length(); } // non virtual implementation of length() void positionLineBox(InlineTextBox&); - virtual float width(unsigned from, unsigned len, const Font&, float xPos, HashSet* fallbackFonts = 0, GlyphOverflow* = 0) const; - virtual float width(unsigned from, unsigned len, float xPos, bool firstLine = false, HashSet* fallbackFonts = 0, GlyphOverflow* = 0) const; + virtual float width(unsigned from, unsigned len, const FontCascade&, float xPos, HashSet* fallbackFonts = 0, GlyphOverflow* = 0) const; + virtual float width(unsigned from, unsigned len, float xPos, bool firstLine = false, HashSet* fallbackFonts = 0, GlyphOverflow* = 0) const; float minLogicalWidth() const; float maxLogicalWidth() const; @@ -97,45 +102,49 @@ public: bool& hasBreakableChar, bool& hasBreak, float& beginMaxW, float& endMaxW, float& minW, float& maxW, bool& stripFrontSpaces); - - virtual IntRect linesBoundingBox() const; + float hangablePunctuationStartWidth(unsigned index) const; + float hangablePunctuationEndWidth(unsigned index) const; + unsigned firstCharacterIndexStrippingSpaces() const; + unsigned lastCharacterIndexStrippingSpaces() const; + bool isHangableStopOrComma(UChar) const; + + WEBCORE_EXPORT virtual IntRect linesBoundingBox() const; LayoutRect linesVisualOverflowBoundingBox() const; - FloatPoint firstRunOrigin() const; - float firstRunX() const; - float firstRunY() const; + WEBCORE_EXPORT IntPoint firstRunLocation() const; virtual void setText(const String&, bool force = false); void setTextWithOffset(const String&, unsigned offset, unsigned len, bool force = false); - virtual bool canBeSelectionLeaf() const override { return true; } - virtual void setSelectionState(SelectionState) override final; - virtual LayoutRect selectionRectForRepaint(const RenderLayerModelObject* repaintContainer, bool clipToVisibleContent = true) override; - virtual LayoutRect localCaretRect(InlineBox*, int caretOffset, LayoutUnit* extraWidthToEndOfLine = 0) override; + bool canBeSelectionLeaf() const override { return true; } + void setSelectionState(SelectionState) final; + LayoutRect selectionRectForRepaint(const RenderLayerModelObject* repaintContainer, bool clipToVisibleContent = true) override; + LayoutRect localCaretRect(InlineBox*, unsigned caretOffset, LayoutUnit* extraWidthToEndOfLine = 0) override; + + LayoutRect collectSelectionRectsForLineBoxes(const RenderLayerModelObject* repaintContainer, bool clipToVisibleContent, Vector& rects); LayoutUnit marginLeft() const { return minimumValueForLength(style().marginLeft(), 0); } LayoutUnit marginRight() const { return minimumValueForLength(style().marginRight(), 0); } - virtual LayoutRect clippedOverflowRectForRepaint(const RenderLayerModelObject* repaintContainer) const override final; + LayoutRect clippedOverflowRectForRepaint(const RenderLayerModelObject* repaintContainer) const final; InlineTextBox* firstTextBox() const { return m_lineBoxes.first(); } InlineTextBox* lastTextBox() const { return m_lineBoxes.last(); } - virtual int caretMinOffset() const override; - virtual int caretMaxOffset() const override; + int caretMinOffset() const override; + int caretMaxOffset() const override; unsigned countRenderedCharacterOffsetsUntil(unsigned) const; bool containsRenderedCharacterOffset(unsigned) const; bool containsCaretOffset(unsigned) const; bool hasRenderedText() const; - virtual int previousOffset(int current) const override final; - virtual int previousOffsetForBackwardDeletion(int current) const override final; - virtual int nextOffset(int current) const override final; + int previousOffset(int current) const final; + int previousOffsetForBackwardDeletion(int current) const final; + int nextOffset(int current) const final; bool containsReversedText() const { return m_containsReversedText; } - bool isSecure() const { return style().textSecurity() != TSNONE; } - void momentarilyRevealLastTypedCharacter(unsigned lastTypedCharacterOffset); + void momentarilyRevealLastTypedCharacter(unsigned offsetAfterLastTypedCharacter); InlineTextBox* findNextInlineTextBox(int offset, int& pos) const { return m_lineBoxes.findNext(offset, pos); } @@ -149,7 +158,7 @@ public: virtual std::unique_ptr createTextBox(); // Subclassed by RenderSVGInlineText. -#if ENABLE(IOS_TEXT_AUTOSIZING) +#if ENABLE(TEXT_AUTOSIZING) float candidateComputedTextSize() const { return m_candidateComputedTextSize; } void setCandidateComputedTextSize(float s) { m_candidateComputedTextSize = s; } #endif @@ -158,54 +167,69 @@ public: void deleteLineBoxesBeforeSimpleLineLayout(); const SimpleLineLayout::Layout* simpleLineLayout() const; + StringView stringView(unsigned start = 0, std::optional stop = std::nullopt) const; + + LayoutUnit topOfFirstText() const; + + bool containsOnlyWhitespace(unsigned from, unsigned len) const; + + bool canUseSimplifiedTextMeasuring() const { return m_canUseSimplifiedTextMeasuring; } + protected: virtual void computePreferredLogicalWidths(float leadWidth); - virtual void willBeDestroyed() override; + void willBeDestroyed() override; - virtual void setTextInternal(const String&); + virtual void setRenderedText(const String&); virtual UChar previousCharacter() const; private: - virtual bool canHaveChildren() const override final { return false; } + RenderText(Node&, const String&); - void computePreferredLogicalWidths(float leadWidth, HashSet& fallbackFonts, GlyphOverflow&); + bool canHaveChildren() const final { return false; } + + void computePreferredLogicalWidths(float leadWidth, HashSet& fallbackFonts, GlyphOverflow&); bool computeCanUseSimpleFontCodePath() const; // Make length() private so that callers that have a RenderText* // will use the more efficient textLength() instead, while // callers with a RenderObject* can continue to use length(). - virtual unsigned length() const override final { return textLength(); } + unsigned length() const final { return textLength(); } - virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation&, const LayoutPoint&, HitTestAction) override final { ASSERT_NOT_REACHED(); return false; } + bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation&, const LayoutPoint&, HitTestAction) final { ASSERT_NOT_REACHED(); return false; } - bool containsOnlyWhitespace(unsigned from, unsigned len) const; - float widthFromCache(const Font&, int start, int len, float xPos, HashSet* fallbackFonts, GlyphOverflow*, const RenderStyle&) const; + float widthFromCache(const FontCascade&, unsigned start, unsigned len, float xPos, HashSet* fallbackFonts, GlyphOverflow*, const RenderStyle&) const; bool isAllASCII() const { return m_isAllASCII; } bool computeUseBackslashAsYenSymbol() const; void secureText(UChar mask); + LayoutRect collectSelectionRectsForLineBoxes(const RenderLayerModelObject* repaintContainer, bool clipToVisibleContent, Vector*); + bool computeCanUseSimplifiedTextMeasuring() const; + void node() const = delete; + void container() const = delete; // Use parent() instead. + void container(const RenderLayerModelObject&, bool&) const = delete; // Use parent() instead. // We put the bitfield first to minimize padding on 64-bit. - bool m_hasBreakableChar : 1; // Whether or not we can be broken into multiple lines. - bool m_hasBreak : 1; // Whether or not we have a hard break (e.g.,
 with '\n').
-    bool m_hasTab : 1; // Whether or not we have a variable width tab character (e.g., 
 with '\t').
-    bool m_hasBeginWS : 1; // Whether or not we begin with WS (only true if we aren't pre)
-    bool m_hasEndWS : 1; // Whether or not we end with WS (only true if we aren't pre)
-    bool m_linesDirty : 1; // This bit indicates that the text run has already dirtied specific
+    unsigned m_hasBreakableChar : 1; // Whether or not we can be broken into multiple lines.
+    unsigned m_hasBreak : 1; // Whether or not we have a hard break (e.g., 
 with '\n').
+    unsigned m_hasTab : 1; // Whether or not we have a variable width tab character (e.g., 
 with '\t').
+    unsigned m_hasBeginWS : 1; // Whether or not we begin with WS (only true if we aren't pre)
+    unsigned m_hasEndWS : 1; // Whether or not we end with WS (only true if we aren't pre)
+    unsigned m_linesDirty : 1; // This bit indicates that the text run has already dirtied specific
                            // line boxes, and this hint will enable layoutInlineChildren to avoid
                            // just dirtying everything when character data is modified (e.g., appended/inserted
                            // or removed).
-    bool m_containsReversedText : 1;
-    bool m_isAllASCII : 1;
-    bool m_canUseSimpleFontCodePath : 1;
-    mutable bool m_knownToHaveNoOverflowAndNoFallbackFonts : 1;
-    bool m_useBackslashAsYenSymbol : 1;
-    bool m_originalTextDiffersFromRendered : 1;
-
-#if ENABLE(IOS_TEXT_AUTOSIZING)
+    unsigned m_containsReversedText : 1;
+    unsigned m_isAllASCII : 1;
+    unsigned m_canUseSimpleFontCodePath : 1;
+    mutable unsigned m_knownToHaveNoOverflowAndNoFallbackFonts : 1;
+    unsigned m_useBackslashAsYenSymbol : 1;
+    unsigned m_originalTextDiffersFromRendered : 1;
+    unsigned m_canUseSimplifiedTextMeasuring : 1;
+
+#if ENABLE(TEXT_AUTOSIZING)
     // FIXME: This should probably be part of the text sizing structures in Document instead. That would save some memory.
     float m_candidateComputedTextSize;
 #endif
@@ -233,26 +257,45 @@ inline UChar RenderText::characterAt(unsigned i) const
     return uncheckedCharacterAt(i);
 }
 
-template <> inline bool isRendererOfType(const RenderObject& renderer) { return renderer.isText(); }
-RENDER_OBJECT_TYPE_CASTS(RenderText, isText())
-
-inline RenderStyle& RenderText::style() const
+inline const RenderStyle& RenderText::style() const
 {
     return parent()->style();
 }
 
-inline RenderStyle& RenderText::firstLineStyle() const
+inline const RenderStyle& RenderText::firstLineStyle() const
 {
     return parent()->firstLineStyle();
 }
 
-void applyTextTransform(const RenderStyle&, String&, UChar);
+inline const RenderStyle* RenderText::getCachedPseudoStyle(PseudoId pseudoId, const RenderStyle* parentStyle) const
+{
+    return parent()->getCachedPseudoStyle(pseudoId, parentStyle);
+}
 
+inline Color RenderText::selectionBackgroundColor() const
+{
+    return parent()->selectionBackgroundColor();
+}
+
+inline Color RenderText::selectionForegroundColor() const
+{
+    return parent()->selectionForegroundColor();
+}
+
+inline Color RenderText::selectionEmphasisMarkColor() const
+{
+    return parent()->selectionEmphasisMarkColor();
+}
+
+void applyTextTransform(const RenderStyle&, String&, UChar);
+void makeCapitalized(String*, UChar previous);
+LineBreakIteratorMode mapLineBreakToIteratorMode(LineBreak);
+    
 inline RenderText* Text::renderer() const
 {
-    return toRenderText(Node::renderer());
+    return downcast(Node::renderer());
 }
 
 } // namespace WebCore
 
-#endif // RenderText_h
+SPECIALIZE_TYPE_TRAITS_RENDER_OBJECT(RenderText, isText())
-- 
cgit v1.2.1