summaryrefslogtreecommitdiff
path: root/Source/WebCore/rendering/RenderTextControl.cpp
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
commit1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch)
tree46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/rendering/RenderTextControl.cpp
parent32761a6cee1d0dee366b885b7b9c777e67885688 (diff)
downloadWebKitGtk-tarball-master.tar.gz
Diffstat (limited to 'Source/WebCore/rendering/RenderTextControl.cpp')
-rw-r--r--Source/WebCore/rendering/RenderTextControl.cpp179
1 files changed, 26 insertions, 153 deletions
diff --git a/Source/WebCore/rendering/RenderTextControl.cpp b/Source/WebCore/rendering/RenderTextControl.cpp
index ace5fc6b9..12fda8e69 100644
--- a/Source/WebCore/rendering/RenderTextControl.cpp
+++ b/Source/WebCore/rendering/RenderTextControl.cpp
@@ -1,5 +1,5 @@
/**
- * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
+ * Copyright (C) 2006, 2007, 2014 Apple Inc. All rights reserved.
* (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
*
* This library is free software; you can redistribute it and/or
@@ -29,15 +29,15 @@
#include "RenderTheme.h"
#include "ScrollbarTheme.h"
#include "StyleInheritedData.h"
+#include "StyleProperties.h"
#include "TextControlInnerElements.h"
-#include "TextIterator.h"
#include "VisiblePosition.h"
#include <wtf/unicode/CharacterNames.h>
namespace WebCore {
-RenderTextControl::RenderTextControl(HTMLTextFormControlElement& element, PassRef<RenderStyle> style)
- : RenderBlockFlow(element, std::move(style))
+RenderTextControl::RenderTextControl(HTMLTextFormControlElement& element, RenderStyle&& style)
+ : RenderBlockFlow(element, WTFMove(style))
{
}
@@ -47,7 +47,7 @@ RenderTextControl::~RenderTextControl()
HTMLTextFormControlElement& RenderTextControl::textFormControlElement() const
{
- return toHTMLTextFormControlElement(nodeForNonAnonymous());
+ return downcast<HTMLTextFormControlElement>(nodeForNonAnonymous());
}
TextControlInnerTextElement* RenderTextControl::innerTextElement() const
@@ -65,58 +65,11 @@ void RenderTextControl::styleDidChange(StyleDifference diff, const RenderStyle*
if (innerTextRenderer) {
// We may have set the width and the height in the old style in layout().
// Reset them now to avoid getting a spurious layout hint.
- innerTextRenderer->style().setHeight(Length());
- innerTextRenderer->style().setWidth(Length());
- innerTextRenderer->setStyle(createInnerTextStyle(&style()));
- innerText->setNeedsStyleRecalc();
+ innerTextRenderer->mutableStyle().setHeight(Length());
+ innerTextRenderer->mutableStyle().setWidth(Length());
+ innerTextRenderer->setStyle(textFormControlElement().createInnerTextStyle(style()));
}
- textFormControlElement().updatePlaceholderVisibility(false);
-}
-
-static inline bool updateUserModifyProperty(const HTMLTextFormControlElement& element, RenderStyle* style)
-{
- bool isDisabled = element.isDisabledFormControl();
- bool isReadOnlyControl = element.isReadOnly();
-
- style->setUserModify((isReadOnlyControl || isDisabled) ? READ_ONLY : READ_WRITE_PLAINTEXT_ONLY);
- return isDisabled;
-}
-
-void RenderTextControl::adjustInnerTextStyle(const RenderStyle* startStyle, RenderStyle* textBlockStyle) const
-{
- // The inner block, if present, always has its direction set to LTR,
- // so we need to inherit the direction and unicode-bidi style from the element.
- textBlockStyle->setDirection(style().direction());
- textBlockStyle->setUnicodeBidi(style().unicodeBidi());
-
- bool disabled = updateUserModifyProperty(textFormControlElement(), textBlockStyle);
- if (disabled)
- textBlockStyle->setColor(theme().disabledTextColor(textBlockStyle->visitedDependentColor(CSSPropertyColor), startStyle->visitedDependentColor(CSSPropertyBackgroundColor)));
-#if PLATFORM(IOS)
- if (textBlockStyle->textSecurity() != TSNONE && !textBlockStyle->isLeftToRightDirection()) {
- // Preserve the alignment but force the direction to LTR so that the last-typed, unmasked character
- // (which cannot have RTL directionality) will appear to the right of the masked characters. See <rdar://problem/7024375>.
-
- switch (textBlockStyle->textAlign()) {
- case TASTART:
- case JUSTIFY:
- textBlockStyle->setTextAlign(RIGHT);
- break;
- case TAEND:
- textBlockStyle->setTextAlign(LEFT);
- break;
- case LEFT:
- case RIGHT:
- case CENTER:
- case WEBKIT_LEFT:
- case WEBKIT_RIGHT:
- case WEBKIT_CENTER:
- break;
- }
-
- textBlockStyle->setDirection(LTR);
- }
-#endif
+ textFormControlElement().updatePlaceholderVisibility();
}
int RenderTextControl::textBlockLogicalHeight() const
@@ -136,26 +89,19 @@ int RenderTextControl::textBlockLogicalWidth() const
return unitWidth;
}
-void RenderTextControl::updateFromElement()
-{
- TextControlInnerTextElement* innerText = innerTextElement();
- if (innerText && innerText->renderer())
- updateUserModifyProperty(textFormControlElement(), &innerText->renderer()->style());
-}
-
int RenderTextControl::scrollbarThickness() const
{
// FIXME: We should get the size of the scrollbar from the RenderTheme instead.
- return ScrollbarTheme::theme()->scrollbarThickness();
+ return ScrollbarTheme::theme().scrollbarThickness();
}
-void RenderTextControl::computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logicalTop, LogicalExtentComputedValues& computedValues) const
+RenderBox::LogicalExtentComputedValues RenderTextControl::computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logicalTop) const
{
TextControlInnerTextElement* innerText = innerTextElement();
ASSERT(innerText);
if (RenderBox* innerTextBox = innerText->renderBox()) {
- LayoutUnit nonContentHeight = innerTextBox->borderAndPaddingHeight() + innerTextBox->marginHeight();
- logicalHeight = computeControlLogicalHeight(innerTextBox->lineHeight(true, HorizontalLine, PositionOfInteriorLineBoxes), nonContentHeight) + borderAndPaddingHeight();
+ LayoutUnit nonContentHeight = innerTextBox->verticalBorderAndPaddingExtent() + innerTextBox->verticalMarginExtent();
+ logicalHeight = computeControlLogicalHeight(innerTextBox->lineHeight(true, HorizontalLine, PositionOfInteriorLineBoxes), nonContentHeight) + verticalBorderAndPaddingExtent();
// We are able to have a horizontal scrollbar if the overflow style is scroll, or if its auto and there's no word wrap.
if ((isHorizontalWritingMode() && (style().overflowX() == OSCROLL || (style().overflowX() == OAUTO && innerText->renderer()->style().overflowWrap() == NormalOverflowWrap)))
@@ -163,7 +109,7 @@ void RenderTextControl::computeLogicalHeight(LayoutUnit logicalHeight, LayoutUni
logicalHeight += scrollbarThickness();
}
- RenderBox::computeLogicalHeight(logicalHeight, logicalTop, computedValues);
+ return RenderBox::computeLogicalHeight(logicalHeight, logicalTop);
}
void RenderTextControl::hitInnerTextElement(HitTestResult& result, const LayoutPoint& pointInContainer, const LayoutPoint& accumulatedOffset)
@@ -173,89 +119,22 @@ void RenderTextControl::hitInnerTextElement(HitTestResult& result, const LayoutP
return;
LayoutPoint adjustedLocation = accumulatedOffset + location();
- LayoutPoint localPoint = pointInContainer - toLayoutSize(adjustedLocation + innerText->renderBox()->location());
- if (hasOverflowClip())
- localPoint += scrolledContentOffset();
+ LayoutPoint localPoint = pointInContainer - toLayoutSize(adjustedLocation + innerText->renderBox()->location()) + toLayoutSize(scrollPosition());
result.setInnerNode(innerText);
result.setInnerNonSharedNode(innerText);
result.setLocalPoint(localPoint);
}
-static const char* fontFamiliesWithInvalidCharWidth[] = {
- "American Typewriter",
- "Arial Hebrew",
- "Chalkboard",
- "Cochin",
- "Corsiva Hebrew",
- "Courier",
- "Euphemia UCAS",
- "Geneva",
- "Gill Sans",
- "Hei",
- "Helvetica",
- "Hoefler Text",
- "InaiMathi",
- "Kai",
- "Lucida Grande",
- "Marker Felt",
- "Monaco",
- "Mshtakan",
- "New Peninim MT",
- "Osaka",
- "Raanana",
- "STHeiti",
- "Symbol",
- "Times",
- "Apple Braille",
- "Apple LiGothic",
- "Apple LiSung",
- "Apple Symbols",
- "AppleGothic",
- "AppleMyungjo",
- "#GungSeo",
- "#HeadLineA",
- "#PCMyungjo",
- "#PilGi",
-};
-
-// For font families where any of the fonts don't have a valid entry in the OS/2 table
-// for avgCharWidth, fallback to the legacy webkit behavior of getting the avgCharWidth
-// from the width of a '0'. This only seems to apply to a fixed number of Mac fonts,
-// but, in order to get similar rendering across platforms, we do this check for
-// all platforms.
-bool RenderTextControl::hasValidAvgCharWidth(AtomicString family)
+float RenderTextControl::getAverageCharWidth()
{
- if (family.isEmpty())
- return false;
-
- // Internal fonts on OS X also have an invalid entry in the table for avgCharWidth.
- // They are hidden by having a name that begins with a period, so simply search
- // for that here rather than try to keep the list up to date.
- if (family.startsWith('.'))
- return false;
-
- static HashSet<AtomicString>* fontFamiliesWithInvalidCharWidthMap = 0;
-
- if (!fontFamiliesWithInvalidCharWidthMap) {
- fontFamiliesWithInvalidCharWidthMap = new HashSet<AtomicString>;
-
- for (size_t i = 0; i < WTF_ARRAY_LENGTH(fontFamiliesWithInvalidCharWidth); ++i)
- fontFamiliesWithInvalidCharWidthMap->add(AtomicString(fontFamiliesWithInvalidCharWidth[i]));
- }
-
- return !fontFamiliesWithInvalidCharWidthMap->contains(family);
-}
-
-float RenderTextControl::getAvgCharWidth(AtomicString family)
-{
- if (hasValidAvgCharWidth(family))
- return roundf(style().font().primaryFont()->avgCharWidth());
+ float width;
+ if (style().fontCascade().fastAverageCharWidthIfAvailable(width))
+ return width;
const UChar ch = '0';
const String str = String(&ch, 1);
- const Font& font = style().font();
- TextRun textRun = constructTextRun(this, font, str, style(), TextRun::AllowTrailingExpansion);
- textRun.disableRoundingHacks();
+ const FontCascade& font = style().fontCascade();
+ TextRun textRun = constructTextRun(str, style(), AllowTrailingExpansion);
return font.width(textRun);
}
@@ -263,17 +142,16 @@ float RenderTextControl::scaleEmToUnits(int x) const
{
// This matches the unitsPerEm value for MS Shell Dlg and Courier New from the "head" font table.
float unitsPerEm = 2048.0f;
- return roundf(style().font().size() * x / unitsPerEm);
+ return roundf(style().fontCascade().size() * x / unitsPerEm);
}
void RenderTextControl::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const
{
// Use average character width. Matches IE.
- const AtomicString& family = style().font().firstFamily();
- maxLogicalWidth = preferredContentLogicalWidth(const_cast<RenderTextControl*>(this)->getAvgCharWidth(family));
+ maxLogicalWidth = preferredContentLogicalWidth(const_cast<RenderTextControl*>(this)->getAverageCharWidth());
if (RenderBox* innerTextRenderBox = innerTextElement()->renderBox())
maxLogicalWidth += innerTextRenderBox->paddingStart() + innerTextRenderBox->paddingEnd();
- if (!style().logicalWidth().isPercent())
+ if (!style().logicalWidth().isPercentOrCalculated())
minLogicalWidth = maxLogicalWidth;
}
@@ -307,10 +185,10 @@ void RenderTextControl::computePreferredLogicalWidths()
setPreferredLogicalWidthsDirty(false);
}
-void RenderTextControl::addFocusRingRects(Vector<IntRect>& rects, const LayoutPoint& additionalOffset, const RenderLayerModelObject*)
+void RenderTextControl::addFocusRingRects(Vector<LayoutRect>& rects, const LayoutPoint& additionalOffset, const RenderLayerModelObject*)
{
if (!size().isEmpty())
- rects.append(pixelSnappedIntRect(additionalOffset, size()));
+ rects.append(LayoutRect(additionalOffset, size()));
}
RenderObject* RenderTextControl::layoutSpecialExcludedChild(bool relayoutChildren)
@@ -344,9 +222,4 @@ int RenderTextControl::innerLineHeight() const
}
#endif
-bool RenderTextControl::canBeReplacedWithInlineRunIn() const
-{
- return false;
-}
-
} // namespace WebCore