+2005-02-17 Ken Kocienda <kocienda@apple.com>
+
+ Reviewed by Hyatt
+
+ Fix for this bug:
+
+ <rdar://problem/4003463> Mail.app HTML uses inline styling markup not understood by Entourage and Eudora
+
+ * khtml/editing/htmlediting.cpp:
+ (khtml::StyleChange::styleModeForParseMode): Helper to map a document parse mode to a use/don't use
+ legacy-html-styles value.
+ (khtml::StyleChange::checkForLegacyHTMLStyleChange): Add support for colors, font faces, and font sizes.
+ (khtml::ApplyStyleCommand::applyTextDecorationStyle): Now call styleModeForParseMode to determine
+ whether to use legacy html styles or not.
+ (khtml::ApplyStyleCommand::addBlockStyleIfNeeded): Ditto.
+ (khtml::ApplyStyleCommand::addInlineStyleIfNeeded): Ditto.
+ * khtml/editing/htmlediting.h: All the following support the new bits of data we need to store.
+ (khtml::StyleChange::applyFontColor)
+ (khtml::StyleChange::applyFontFace)
+ (khtml::StyleChange::applyFontSize)
+ (khtml::StyleChange::fontColor)
+ (khtml::StyleChange::fontFace)
+ (khtml::StyleChange::fontSize)
+
2005-02-17 Richard Williamson <rjw@apple.com>
Fixed <rdar://problem/4008163> dynamic support for -apple-dashboard-region is flakey
#include "khtml_part.h"
#include "khtml_part.h"
#include "khtmlview.h"
+#include "qcolor.h"
#include "qptrlist.h"
#include "render_object.h"
#include "render_style.h"
m_cssStyle = styleText.stripWhiteSpace();
}
-bool StyleChange::checkForLegacyHTMLStyleChange(const DOM::CSSProperty *property)
+StyleChange::ELegacyHTMLStyles StyleChange::styleModeForParseMode(bool isQuirksMode)
+{
+ return isQuirksMode ? UseLegacyHTMLStyles : DoNotUseLegacyHTMLStyles;
+}
+
+bool StyleChange::checkForLegacyHTMLStyleChange(const CSSProperty *property)
{
DOMString valueText(property->value()->cssText());
switch (property->id()) {
return true;
}
break;
+ case CSS_PROP_COLOR: {
+ QColor color(CSSParser::parseColor(valueText));
+ m_applyFontColor = color.name();
+ return true;
+ }
+ case CSS_PROP_FONT_FAMILY:
+ m_applyFontFace = valueText;
+ return true;
+ case CSS_PROP_FONT_SIZE:
+ if (property->value()->cssValueType() == CSSValue::CSS_PRIMITIVE_VALUE) {
+ CSSPrimitiveValueImpl *value = static_cast<CSSPrimitiveValueImpl *>(property->value());
+ float number = value->getFloatValue(CSSPrimitiveValue::CSS_PX);
+ if (number <= 9)
+ m_applyFontSize = "1";
+ else if (number <= 10)
+ m_applyFontSize = "2";
+ else if (number <= 13)
+ m_applyFontSize = "3";
+ else if (number <= 16)
+ m_applyFontSize = "4";
+ else if (number <= 18)
+ m_applyFontSize = "5";
+ else if (number <= 24)
+ m_applyFontSize = "6";
+ else
+ m_applyFontSize = "7";
+ // Huge quirk in Microsft Entourage is that they understand CSS font-size, but also write
+ // out legacy 1-7 values in font tags (I guess for mailers that are not CSS-savvy at all,
+ // like Eudora). Yes, they write out *both*. We need to write out both as well. Return false.
+ return false;
+ }
+ else {
+ // Can't make sense of the number. Put no font size.
+ return true;
+ }
}
return false;
}
HTMLElementImpl *element = static_cast<HTMLElementImpl *>(node);
- StyleChange styleChange(style, Position(element, 0), StyleChange::DoNotUseLegacyHTMLStyles);
+ StyleChange styleChange(style, Position(element, 0), StyleChange::styleModeForParseMode(document()->inCompatMode()));
if (styleChange.cssStyle().length() > 0) {
DOMString cssText = styleChange.cssStyle();
CSSMutableStyleDeclarationImpl *decl = element->inlineStyleDecl();
if (!block)
return;
- StyleChange styleChange(style, Position(block, 0), StyleChange::DoNotUseLegacyHTMLStyles);
+ StyleChange styleChange(style, Position(block, 0), StyleChange::styleModeForParseMode(document()->inCompatMode()));
if (styleChange.cssStyle().length() > 0) {
moveParagraphContentsToNewBlockIfNecessary(Position(node, 0));
block = static_cast<HTMLElementImpl *>(node->enclosingBlockFlowElement());
void ApplyStyleCommand::addInlineStyleIfNeeded(CSSMutableStyleDeclarationImpl *style, NodeImpl *startNode, NodeImpl *endNode)
{
- StyleChange styleChange(style, Position(startNode, 0));
+ StyleChange styleChange(style, Position(startNode, 0), StyleChange::styleModeForParseMode(document()->inCompatMode()));
int exceptionCode = 0;
+ //
+ // Font tags need to go outside of CSS so that CSS font sizes override leagcy font sizes.
+ //
+ if (styleChange.applyFontColor() || styleChange.applyFontFace() || styleChange.applyFontSize()) {
+ ElementImpl *fontElement = document()->createHTMLElement("font", exceptionCode);
+ ASSERT(exceptionCode == 0);
+ insertNodeBefore(fontElement, startNode);
+ if (styleChange.applyFontColor())
+ fontElement->setAttribute(ATTR_COLOR, styleChange.fontColor());
+ if (styleChange.applyFontFace())
+ fontElement->setAttribute(ATTR_FACE, styleChange.fontFace());
+ if (styleChange.applyFontSize())
+ fontElement->setAttribute(ATTR_SIZE, styleChange.fontSize());
+ surroundNodeRangeWithElement(startNode, endNode, fontElement);
+ }
+
if (styleChange.cssStyle().length() > 0) {
ElementImpl *styleElement = createStyleSpanElement(document());
styleElement->setAttribute(ATTR_STYLE, styleChange.cssStyle());
explicit StyleChange(DOM::CSSStyleDeclarationImpl *, ELegacyHTMLStyles usesLegacyStyles=UseLegacyHTMLStyles);
StyleChange(DOM::CSSStyleDeclarationImpl *, const DOM::Position &, ELegacyHTMLStyles usesLegacyStyles=UseLegacyHTMLStyles);
+ static ELegacyHTMLStyles styleModeForParseMode(bool);
+
DOM::DOMString cssStyle() const { return m_cssStyle; }
bool applyBold() const { return m_applyBold; }
bool applyItalic() const { return m_applyItalic; }
+ bool applyFontColor() const { return m_applyFontColor.length() > 0; }
+ bool applyFontFace() const { return m_applyFontFace.length() > 0; }
+ bool applyFontSize() const { return m_applyFontSize.length() > 0; }
+
+ DOM::DOMString fontColor() { return m_applyFontColor; }
+ DOM::DOMString fontFace() { return m_applyFontFace; }
+ DOM::DOMString fontSize() { return m_applyFontSize; }
+
bool usesLegacyStyles() const { return m_usesLegacyStyles; }
private:
DOM::DOMString m_cssStyle;
bool m_applyBold;
bool m_applyItalic;
+ DOM::DOMString m_applyFontColor;
+ DOM::DOMString m_applyFontFace;
+ DOM::DOMString m_applyFontSize;
bool m_usesLegacyStyles;
};