summaryrefslogtreecommitdiff
path: root/Source/WebCore/rendering/RenderTextControlSingleLine.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/RenderTextControlSingleLine.cpp
parent32761a6cee1d0dee366b885b7b9c777e67885688 (diff)
downloadWebKitGtk-tarball-master.tar.gz
Diffstat (limited to 'Source/WebCore/rendering/RenderTextControlSingleLine.cpp')
-rw-r--r--Source/WebCore/rendering/RenderTextControlSingleLine.cpp160
1 files changed, 35 insertions, 125 deletions
diff --git a/Source/WebCore/rendering/RenderTextControlSingleLine.cpp b/Source/WebCore/rendering/RenderTextControlSingleLine.cpp
index 99ce289a3..ec76c01a6 100644
--- a/Source/WebCore/rendering/RenderTextControlSingleLine.cpp
+++ b/Source/WebCore/rendering/RenderTextControlSingleLine.cpp
@@ -26,21 +26,17 @@
#include "CSSFontSelector.h"
#include "CSSValueKeywords.h"
-#include "Chrome.h"
+#include "Font.h"
#include "Frame.h"
#include "FrameSelection.h"
#include "FrameView.h"
#include "HTMLNames.h"
#include "HitTestResult.h"
#include "LocalizedStrings.h"
-#include "Page.h"
-#include "PlatformKeyboardEvent.h"
#include "RenderLayer.h"
#include "RenderScrollbar.h"
#include "RenderTheme.h"
#include "RenderView.h"
-#include "Settings.h"
-#include "SimpleFontData.h"
#include "StyleResolver.h"
#include "TextControlInnerElements.h"
#include <wtf/StackStats.h>
@@ -53,10 +49,8 @@ namespace WebCore {
using namespace HTMLNames;
-RenderTextControlSingleLine::RenderTextControlSingleLine(HTMLInputElement& element, PassRef<RenderStyle> style)
- : RenderTextControl(element, std::move(style))
- , m_shouldDrawCapsLockIndicator(false)
- , m_desiredInnerTextLogicalHeight(-1)
+RenderTextControlSingleLine::RenderTextControlSingleLine(HTMLInputElement& element, RenderStyle&& style)
+ : RenderTextControl(element, WTFMove(style))
{
}
@@ -69,25 +63,6 @@ inline HTMLElement* RenderTextControlSingleLine::innerSpinButtonElement() const
return inputElement().innerSpinButtonElement();
}
-void RenderTextControlSingleLine::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
-{
- RenderTextControl::paint(paintInfo, paintOffset);
-
- if (paintInfo.phase == PaintPhaseBlockBackground && m_shouldDrawCapsLockIndicator) {
- LayoutRect contentsRect = contentBoxRect();
-
- // Center in the block progression direction.
- if (isHorizontalWritingMode())
- contentsRect.setY((height() - contentsRect.height()) / 2);
- else
- contentsRect.setX((width() - contentsRect.width()) / 2);
-
- // Convert the rect into the coords used for painting the content
- contentsRect.moveBy(paintOffset + location());
- theme().paintCapsLockIndicator(this, paintInfo, pixelSnappedIntRect(contentsRect));
- }
-}
-
LayoutUnit RenderTextControlSingleLine::computeLogicalHeightLimit() const
{
return containerElement() ? contentLogicalHeight() : logicalHeight();
@@ -129,11 +104,11 @@ void RenderTextControlSingleLine::layout()
// To ensure consistency between layouts, we need to reset any conditionally overriden height.
if (innerTextRenderer && !innerTextRenderer->style().logicalHeight().isAuto()) {
- innerTextRenderer->style().setLogicalHeight(Length(Auto));
+ innerTextRenderer->mutableStyle().setLogicalHeight(Length(Auto));
setNeedsLayoutOnAncestors(innerTextRenderer, this);
}
if (innerBlockRenderer && !innerBlockRenderer->style().logicalHeight().isAuto()) {
- innerBlockRenderer->style().setLogicalHeight(Length(Auto));
+ innerBlockRenderer->mutableStyle().setLogicalHeight(Length(Auto));
setNeedsLayoutOnAncestors(innerBlockRenderer, this);
}
@@ -149,12 +124,10 @@ void RenderTextControlSingleLine::layout()
if (desiredLogicalHeight != innerTextRenderer->logicalHeight())
setNeedsLayout(MarkOnlyThis);
- m_desiredInnerTextLogicalHeight = desiredLogicalHeight;
-
- innerTextRenderer->style().setLogicalHeight(Length(desiredLogicalHeight, Fixed));
+ innerTextRenderer->mutableStyle().setLogicalHeight(Length(desiredLogicalHeight, Fixed));
innerTextRenderer->setNeedsLayout(MarkOnlyThis);
if (innerBlockRenderer) {
- innerBlockRenderer->style().setLogicalHeight(Length(desiredLogicalHeight, Fixed));
+ innerBlockRenderer->mutableStyle().setLogicalHeight(Length(desiredLogicalHeight, Fixed));
innerBlockRenderer->setNeedsLayout(MarkOnlyThis);
}
}
@@ -163,13 +136,13 @@ void RenderTextControlSingleLine::layout()
containerRenderer->layoutIfNeeded();
LayoutUnit containerLogicalHeight = containerRenderer->logicalHeight();
if (containerLogicalHeight > logicalHeightLimit) {
- containerRenderer->style().setLogicalHeight(Length(logicalHeightLimit, Fixed));
+ containerRenderer->mutableStyle().setLogicalHeight(Length(logicalHeightLimit, Fixed));
setNeedsLayout(MarkOnlyThis);
} else if (containerRenderer->logicalHeight() < contentLogicalHeight()) {
- containerRenderer->style().setLogicalHeight(Length(contentLogicalHeight(), Fixed));
+ containerRenderer->mutableStyle().setLogicalHeight(Length(contentLogicalHeight(), Fixed));
setNeedsLayout(MarkOnlyThis);
} else
- containerRenderer->style().setLogicalHeight(Length(containerLogicalHeight, Fixed));
+ containerRenderer->mutableStyle().setLogicalHeight(Length(containerLogicalHeight, Fixed));
}
// If we need another layout pass, we have changed one of children's height so we need to relayout them.
@@ -197,8 +170,8 @@ void RenderTextControlSingleLine::layout()
LayoutSize innerTextSize;
if (innerTextRenderer)
innerTextSize = innerTextRenderer->size();
- placeholderBox->style().setWidth(Length(innerTextSize.width() - placeholderBox->borderAndPaddingWidth(), Fixed));
- placeholderBox->style().setHeight(Length(innerTextSize.height() - placeholderBox->borderAndPaddingHeight(), Fixed));
+ placeholderBox->mutableStyle().setWidth(Length(innerTextSize.width() - placeholderBox->horizontalBorderAndPaddingExtent(), Fixed));
+ placeholderBox->mutableStyle().setHeight(Length(innerTextSize.height() - placeholderBox->verticalBorderAndPaddingExtent(), Fixed));
bool neededLayout = placeholderBox->needsLayout();
bool placeholderBoxHadLayout = placeholderBox->everHadLayout();
placeholderBox->layoutIfNeeded();
@@ -225,7 +198,7 @@ void RenderTextControlSingleLine::layout()
#if PLATFORM(IOS)
// FIXME: We should not be adjusting styles during layout. <rdar://problem/7675493>
if (inputElement().isSearchField())
- RenderThemeIOS::adjustRoundBorderRadius(style(), this);
+ RenderThemeIOS::adjustRoundBorderRadius(mutableStyle(), *this);
#endif
}
@@ -254,46 +227,29 @@ bool RenderTextControlSingleLine::nodeAtPoint(const HitTestRequest& request, Hit
void RenderTextControlSingleLine::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
{
- m_desiredInnerTextLogicalHeight = -1;
RenderTextControl::styleDidChange(diff, oldStyle);
// 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.
HTMLElement* innerBlock = innerBlockElement();
- if (RenderObject* innerBlockRenderer = innerBlock ? innerBlock->renderer() : 0) {
- innerBlockRenderer->style().setHeight(Length());
- innerBlockRenderer->style().setWidth(Length());
+ if (auto* innerBlockRenderer = innerBlock ? innerBlock->renderer() : nullptr) {
+ innerBlockRenderer->mutableStyle().setHeight(Length());
+ innerBlockRenderer->mutableStyle().setWidth(Length());
}
HTMLElement* container = containerElement();
- if (RenderObject* containerRenderer = container ? container->renderer() : 0) {
- containerRenderer->style().setHeight(Length());
- containerRenderer->style().setWidth(Length());
+ if (auto* containerRenderer = container ? container->renderer() : nullptr) {
+ containerRenderer->mutableStyle().setHeight(Length());
+ containerRenderer->mutableStyle().setWidth(Length());
}
- RenderTextControlInnerBlock* innerTextRenderer = innerTextElement()->renderer();
- if (innerTextRenderer && diff == StyleDifferenceLayout)
- innerTextRenderer->setNeedsLayout(MarkContainingBlockChain);
- if (HTMLElement* placeholder = inputElement().placeholderElement())
- placeholder->setInlineStyleProperty(CSSPropertyTextOverflow, textShouldBeTruncated() ? CSSValueEllipsis : CSSValueClip);
- setHasOverflowClip(false);
-}
-
-void RenderTextControlSingleLine::capsLockStateMayHaveChanged()
-{
- // Only draw the caps lock indicator if these things are true:
- // 1) The field is a password field
- // 2) The frame is active
- // 3) The element is focused
- // 4) The caps lock is on
- bool shouldDrawCapsLockIndicator =
- inputElement().isPasswordField()
- && frame().selection().isFocusedAndActive()
- && document().focusedElement() == &inputElement()
- && PlatformKeyboardEvent::currentCapsLockState();
-
- if (shouldDrawCapsLockIndicator != m_shouldDrawCapsLockIndicator) {
- m_shouldDrawCapsLockIndicator = shouldDrawCapsLockIndicator;
- repaint();
+ if (diff == StyleDifferenceLayout) {
+ if (auto* innerTextRenderer = innerTextElement()->renderer())
+ innerTextRenderer->setNeedsLayout(MarkContainingBlockChain);
+ if (auto* placeholder = inputElement().placeholderElement()) {
+ if (placeholder->renderer())
+ placeholder->renderer()->setNeedsLayout(MarkContainingBlockChain);
+ }
}
+ setHasOverflowClip(false);
}
bool RenderTextControlSingleLine::hasControlClip() const
@@ -312,18 +268,18 @@ LayoutRect RenderTextControlSingleLine::controlClipRect(const LayoutPoint& addit
return clipRect;
}
-float RenderTextControlSingleLine::getAvgCharWidth(AtomicString family)
+float RenderTextControlSingleLine::getAverageCharWidth()
{
#if !PLATFORM(IOS)
// Since Lucida Grande is the default font, we want this to match the width
// of MS Shell Dlg, the default font for textareas in Firefox, Safari Win and
// IE for some encodings (in IE, the default font is encoding specific).
// 901 is the avgCharWidth value in the OS/2 table for MS Shell Dlg.
- if (family == "Lucida Grande")
+ if (style().fontCascade().firstFamily() == "Lucida Grande")
return scaleEmToUnits(901);
#endif
- return RenderTextControl::getAvgCharWidth(family);
+ return RenderTextControl::getAverageCharWidth();
}
LayoutUnit RenderTextControlSingleLine::preferredContentLogicalWidth(float charWidth) const
@@ -333,20 +289,20 @@ LayoutUnit RenderTextControlSingleLine::preferredContentLogicalWidth(float charW
if (factor <= 0)
factor = 20;
- LayoutUnit result = static_cast<LayoutUnit>(ceiledLayoutUnit(charWidth * factor));
+ LayoutUnit result = LayoutUnit::fromFloatCeil(charWidth * factor);
float maxCharWidth = 0.f;
#if !PLATFORM(IOS)
- const AtomicString& family = style().font().firstFamily();
+ const AtomicString& family = style().fontCascade().firstFamily();
// Since Lucida Grande is the default font, we want this to match the width
// of MS Shell Dlg, the default font for textareas in Firefox, Safari Win and
// IE for some encodings (in IE, the default font is encoding specific).
// 4027 is the (xMax - xMin) value in the "head" font table for MS Shell Dlg.
if (family == "Lucida Grande")
maxCharWidth = scaleEmToUnits(4027);
- else if (hasValidAvgCharWidth(family))
- maxCharWidth = roundf(style().font().primaryFont()->maxCharWidth());
+ else if (style().fontCascade().hasValidAverageCharWidth())
+ maxCharWidth = roundf(style().fontCascade().primaryFont().maxCharWidth());
#endif
// For text inputs, IE adds some extra width.
@@ -364,52 +320,6 @@ LayoutUnit RenderTextControlSingleLine::computeControlLogicalHeight(LayoutUnit l
return lineHeight + nonContentHeight;
}
-PassRef<RenderStyle> RenderTextControlSingleLine::createInnerTextStyle(const RenderStyle* startStyle) const
-{
- auto textBlockStyle = RenderStyle::create();
- textBlockStyle.get().inheritFrom(startStyle);
- adjustInnerTextStyle(startStyle, &textBlockStyle.get());
-
- textBlockStyle.get().setWhiteSpace(PRE);
- textBlockStyle.get().setOverflowWrap(NormalOverflowWrap);
- textBlockStyle.get().setOverflowX(OHIDDEN);
- textBlockStyle.get().setOverflowY(OHIDDEN);
- textBlockStyle.get().setTextOverflow(textShouldBeTruncated() ? TextOverflowEllipsis : TextOverflowClip);
-
- if (m_desiredInnerTextLogicalHeight >= 0)
- textBlockStyle.get().setLogicalHeight(Length(m_desiredInnerTextLogicalHeight, Fixed));
- // Do not allow line-height to be smaller than our default.
- if (textBlockStyle.get().fontMetrics().lineSpacing() > lineHeight(true, HorizontalLine, PositionOfInteriorLineBoxes))
- textBlockStyle.get().setLineHeight(RenderStyle::initialLineHeight());
-
- textBlockStyle.get().setDisplay(BLOCK);
-
- return textBlockStyle;
-}
-
-PassRef<RenderStyle> RenderTextControlSingleLine::createInnerBlockStyle(const RenderStyle* startStyle) const
-{
- auto innerBlockStyle = RenderStyle::create();
- innerBlockStyle.get().inheritFrom(startStyle);
-
- innerBlockStyle.get().setFlexGrow(1);
- // min-width: 0; is needed for correct shrinking.
- // FIXME: Remove this line when https://bugs.webkit.org/show_bug.cgi?id=111790 is fixed.
- innerBlockStyle.get().setMinWidth(Length(0, Fixed));
- innerBlockStyle.get().setDisplay(BLOCK);
- innerBlockStyle.get().setDirection(LTR);
-
- // We don't want the shadow dom to be editable, so we set this block to read-only in case the input itself is editable.
- innerBlockStyle.get().setUserModify(READ_ONLY);
-
- return innerBlockStyle;
-}
-
-bool RenderTextControlSingleLine::textShouldBeTruncated() const
-{
- return document().focusedElement() != &inputElement() && style().textOverflow() == TextOverflowEllipsis;
-}
-
void RenderTextControlSingleLine::autoscroll(const IntPoint& position)
{
RenderTextControlInnerBlock* renderer = innerTextElement()->renderer();
@@ -481,7 +391,7 @@ bool RenderTextControlSingleLine::logicalScroll(ScrollLogicalDirection direction
HTMLInputElement& RenderTextControlSingleLine::inputElement() const
{
- return toHTMLInputElement(RenderTextControl::textFormControlElement());
+ return downcast<HTMLInputElement>(RenderTextControl::textFormControlElement());
}
}