Exemplo n.º 1
0
static bool shouldEmitExtraNewlineForNode(Node* node)
{
    // When there is a significant collapsed bottom margin, emit an extra
    // newline for a more realistic result.  We end up getting the right
    // result even without margin collapsing. For example: <div><p>text</p></div>
    // will work right even if both the <div> and the <p> have bottom margins.
    RenderObject* r = node->renderer();
    if (!r)
        return false;
    
    // NOTE: We only do this for a select set of nodes, and fwiw WinIE appears
    // not to do this at all
    if (node->hasTagName(h1Tag)
        || node->hasTagName(h2Tag)
        || node->hasTagName(h3Tag)
        || node->hasTagName(h4Tag)
        || node->hasTagName(h5Tag)
        || node->hasTagName(h6Tag)
        || node->hasTagName(pTag)) {
        RenderStyle* style = r->style();
        if (style) {
            int bottomMargin = r->collapsedMarginBottom();
            int fontSize = style->fontDescription().computedPixelSize();
            if (bottomMargin * 2 >= fontSize)
                return true;
        }
    }
    
    return false;
}
Exemplo n.º 2
0
void RenderSVGInlineText::computeNewScaledFontForStyle(const RenderObject& renderer, const RenderStyle& style, float& scalingFactor, FontCascade& scaledFont)
{
    // Alter font-size to the right on-screen value to avoid scaling the glyphs themselves, except when GeometricPrecision is specified
    scalingFactor = SVGRenderingContext::calculateScreenFontSizeScalingFactor(renderer);
    if (scalingFactor == 1 || !scalingFactor || style.fontDescription().textRenderingMode() == GeometricPrecision) {
        scalingFactor = 1;
        scaledFont = style.fontCascade();
        return;
    }

    FontDescription fontDescription(style.fontDescription());

    // FIXME: We need to better handle the case when we compute very small fonts below (below 1pt).
    fontDescription.setComputedSize(Style::computedFontSizeFromSpecifiedSizeForSVGInlineText(fontDescription.computedSize(), fontDescription.isAbsoluteSize(), scalingFactor, renderer.document()));

    scaledFont = FontCascade(fontDescription, 0, 0);
    scaledFont.update(&renderer.document().fontSelector());
}
Exemplo n.º 3
0
void AutofillPopupMenuClient::initialize(
    HTMLInputElement* textField,
    const WebVector<WebString>& names,
    const WebVector<WebString>& labels,
    const WebVector<WebString>& icons,
    const WebVector<int>& uniqueIDs,
    int separatorIndex)
{
    ASSERT(names.size() == labels.size());
    ASSERT(names.size() == icons.size());
    ASSERT(names.size() == uniqueIDs.size());
    ASSERT(separatorIndex < static_cast<int>(names.size()));

    m_selectedIndex = -1;
    m_textField = textField;

    // The suggestions must be set before initializing the
    // AutofillPopupMenuClient.
    setSuggestions(names, labels, icons, uniqueIDs, separatorIndex);

    FontDescription regularFontDescription;
    RenderTheme::defaultTheme()->systemFont(CSSValueWebkitControl,
                                            regularFontDescription);
    RenderStyle* style = m_textField->computedStyle();
    regularFontDescription.setComputedSize(style->fontDescription().computedSize());

    Font regularFont(regularFontDescription, 0, 0);
    regularFont.update(textField->document()->styleSelector()->fontSelector());
    // The direction of text in popup menu is set the same as the direction of
    // the input element: textField.
    m_regularStyle = adoptPtr(new PopupMenuStyle(Color::black, Color::white, regularFont, true, false,
                                                 Length(WebCore::Fixed), textField->renderer()->style()->direction(),
                                                 textField->renderer()->style()->unicodeBidi() == Override,
                                                 PopupMenuStyle::AutofillPopup));

    FontDescription warningFontDescription = regularFont.fontDescription();
    warningFontDescription.setItalic(true);
    Font warningFont(warningFontDescription, regularFont.letterSpacing(), regularFont.wordSpacing());
    warningFont.update(regularFont.fontSelector());
    m_warningStyle = adoptPtr(new PopupMenuStyle(Color::darkGray, m_regularStyle->backgroundColor(), warningFont,
                                                 m_regularStyle->isVisible(), m_regularStyle->isDisplayNone(),
                                                 m_regularStyle->textIndent(), m_regularStyle->textDirection(),
                                                 m_regularStyle->hasTextDirectionOverride(),
                                                 PopupMenuStyle::AutofillPopup));
}
void AutofillPopupMenuClient::initialize(
    HTMLInputElement* textField,
    const WebVector<WebString>& names,
    const WebVector<WebString>& labels,
    const WebVector<WebString>& icons,
    const WebVector<int>& itemIDs,
    int separatorIndex)
{
    ASSERT(names.size() == labels.size());
    ASSERT(names.size() == icons.size());
    ASSERT(names.size() == itemIDs.size());

    m_selectedIndex = -1;
    m_textField = textField;

    if (separatorIndex == -1) {
        // The suggestions must be set before initializing the
        // AutofillPopupMenuClient.
        setSuggestions(names, labels, icons, itemIDs);
    } else {
        m_useLegacyBehavior = true;
        WebVector<WebString> namesWithSeparator(names.size() + 1);
        WebVector<WebString> labelsWithSeparator(labels.size() + 1);
        WebVector<WebString> iconsWithSeparator(icons.size() + 1);
        WebVector<int> itemIDsWithSeparator(itemIDs.size() + 1);
        for (size_t i = 0; i < names.size(); ++i) {
            size_t j = i < static_cast<size_t>(separatorIndex) ? i : i + 1;
            namesWithSeparator[j] = names[i];
            labelsWithSeparator[j] = labels[i];
            iconsWithSeparator[j] = icons[i];
            itemIDsWithSeparator[j] = itemIDs[i];
        }
        itemIDsWithSeparator[separatorIndex] = WebAutofillClient::MenuItemIDSeparator;
        setSuggestions(namesWithSeparator, labelsWithSeparator, iconsWithSeparator, itemIDsWithSeparator);
    }

    FontDescription regularFontDescription;
    RenderTheme::theme().systemFont(CSSValueWebkitControl,
                                            regularFontDescription);
    RenderStyle* style = m_textField->computedStyle();
    regularFontDescription.setComputedSize(style->fontDescription().computedSize());

    Font regularFont(regularFontDescription, 0, 0);
    regularFont.update(textField->document().styleResolver()->fontSelector());
    // The direction of text in popup menu is set the same as the direction of
    // the input element: textField.
    m_regularStyle = adoptPtr(new PopupMenuStyle(Color::black, Color::white, regularFont, true, false,
        Length(WebCore::Fixed), textField->renderer()->style()->direction(),
        textField->renderer()->style()->unicodeBidi() == Override,
        PopupMenuStyle::CustomBackgroundColor, PopupMenuStyle::AutofillPopup));

    FontDescription warningFontDescription = regularFont.fontDescription();
    warningFontDescription.setItalic(true);
    Font warningFont(warningFontDescription, regularFont.letterSpacing(), regularFont.wordSpacing());
    warningFont.update(regularFont.fontSelector());
    m_warningStyle = adoptPtr(new PopupMenuStyle(Color::darkGray, m_regularStyle->backgroundColor(), warningFont,
        m_regularStyle->isVisible(), m_regularStyle->isDisplayNone(),
        m_regularStyle->textIndent(), m_regularStyle->textDirection(),
        m_regularStyle->hasTextDirectionOverride(),
        PopupMenuStyle::CustomBackgroundColor, PopupMenuStyle::AutofillPopup));
}