diff options
Diffstat (limited to 'src/3rdparty/webkit/WebCore/rendering/RenderTextControl.cpp')
-rw-r--r-- | src/3rdparty/webkit/WebCore/rendering/RenderTextControl.cpp | 104 |
1 files changed, 86 insertions, 18 deletions
diff --git a/src/3rdparty/webkit/WebCore/rendering/RenderTextControl.cpp b/src/3rdparty/webkit/WebCore/rendering/RenderTextControl.cpp index f430399..b98900a 100644 --- a/src/3rdparty/webkit/WebCore/rendering/RenderTextControl.cpp +++ b/src/3rdparty/webkit/WebCore/rendering/RenderTextControl.cpp @@ -70,8 +70,8 @@ static Color disabledTextColor(const Color& textColor, const Color& backgroundCo RenderTextControl::RenderTextControl(Node* node, bool placeholderVisible) : RenderBlock(node) , m_placeholderVisible(placeholderVisible) - , m_edited(false) - , m_userEdited(false) + , m_wasChangedSinceLastChangeEvent(false) + , m_lastChangeWasUserEdit(false) { } @@ -195,17 +195,17 @@ void RenderTextControl::setInnerTextValue(const String& innerTextValue) ASSERT(!ec); } - m_edited = false; - m_userEdited = false; + // We set m_lastChangeWasUserEdit to false since this change was not explicitly made by the user (say, via typing on the keyboard), see <rdar://problem/5359921>. + m_lastChangeWasUserEdit = false; } static_cast<Element*>(node())->setFormControlValueMatchesRenderer(true); } -void RenderTextControl::setUserEdited(bool isUserEdited) +void RenderTextControl::setLastChangeWasUserEdit(bool lastChangeWasUserEdit) { - m_userEdited = isUserEdited; - document()->setIgnoreAutofocus(isUserEdited); + m_lastChangeWasUserEdit = lastChangeWasUserEdit; + document()->setIgnoreAutofocus(lastChangeWasUserEdit); } int RenderTextControl::selectionStart() @@ -266,11 +266,6 @@ void RenderTextControl::setSelectionRange(int start, int end) if (Frame* frame = document()->frame()) frame->selection()->setSelection(newSelection); - - // FIXME: Granularity is stored separately on the frame, but also in the selection controller. - // The granularity in the selection controller should be used, and then this line of code would not be needed. - if (Frame* frame = document()->frame()) - frame->setSelectionGranularity(CharacterGranularity); } VisibleSelection RenderTextControl::selection(int start, int end) const @@ -312,8 +307,8 @@ int RenderTextControl::indexForVisiblePosition(const VisiblePosition& pos) void RenderTextControl::subtreeHasChanged() { - m_edited = true; - m_userEdited = true; + m_wasChangedSinceLastChangeEvent = true; + m_lastChangeWasUserEdit = true; } String RenderTextControl::finishText(Vector<UChar>& result) const @@ -459,6 +454,78 @@ IntRect RenderTextControl::controlClipRect(int tx, int ty) const return clipRect; } +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) +{ + static HashSet<AtomicString>* fontFamiliesWithInvalidCharWidthMap = 0; + + if (!fontFamiliesWithInvalidCharWidthMap) { + fontFamiliesWithInvalidCharWidthMap = new HashSet<AtomicString>; + + for (unsigned i = 0; i < sizeof(fontFamiliesWithInvalidCharWidth) / sizeof(fontFamiliesWithInvalidCharWidth[0]); i++) + fontFamiliesWithInvalidCharWidthMap->add(AtomicString(fontFamiliesWithInvalidCharWidth[i])); + } + + return !fontFamiliesWithInvalidCharWidthMap->contains(family); +} + +float RenderTextControl::getAvgCharWidth(AtomicString family) +{ + if (hasValidAvgCharWidth(family)) + return roundf(style()->font().primaryFont()->avgCharWidth()); + + const UChar ch = '0'; + return style()->font().floatWidth(TextRun(&ch, 1, false, 0, 0, false, false, false)); +} + +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); +} + void RenderTextControl::calcPrefWidths() { ASSERT(prefWidthsDirty()); @@ -470,8 +537,8 @@ void RenderTextControl::calcPrefWidths() m_minPrefWidth = m_maxPrefWidth = calcContentBoxWidth(style()->width().value()); else { // Use average character width. Matches IE. - float charWidth = style()->font().primaryFont()->avgCharWidth(); - m_maxPrefWidth = preferredContentWidth(charWidth) + m_innerText->renderBox()->paddingLeft() + m_innerText->renderBox()->paddingRight(); + AtomicString family = style()->font().family().family(); + m_maxPrefWidth = preferredContentWidth(getAvgCharWidth(family)) + m_innerText->renderBox()->paddingLeft() + m_innerText->renderBox()->paddingRight(); } if (style()->minWidth().isFixed() && style()->minWidth().value() > 0) { @@ -505,9 +572,10 @@ void RenderTextControl::selectionChanged(bool userTriggered) } } -void RenderTextControl::addFocusRingRects(GraphicsContext* graphicsContext, int tx, int ty) +void RenderTextControl::addFocusRingRects(Vector<IntRect>& rects, int tx, int ty) { - graphicsContext->addFocusRingRect(IntRect(tx, ty, width(), height())); + if (width() && height()) + rects.append(IntRect(tx, ty, width(), height())); } HTMLElement* RenderTextControl::innerTextElement() const |