Commit 809f9979 authored by rniwa@webkit.org's avatar rniwa@webkit.org

2011-01-05 Ryosuke Niwa <rniwa@webkit.org>

        Reviewed by Eric Seidel.

        ApplyStyleCommand::applyRelativeFontStyleChange should take EditingStyle*
        https://bugs.webkit.org/show_bug.cgi?id=50641

        Modified applyRelativeFontStyleChange to take EditingStyle instead of CSSMutableStyleDeclaration.
        Also extracted the logic to obtain the font size delta from ApplyStyleCommand to EditingStyle.
        The font size delta is now stored as a member variable of EditingStyle as supposed to a property
        in CSSMutableStyleDeclration as soon as EditingStyle is instantiated.

        No new tests are added since this is a refactoring.

        * editing/ApplyStyleCommand.cpp:
        (WebCore::ApplyStyleCommand::doApply): Calls applyRelativeFontStyleChange.
        (WebCore::ApplyStyleCommand::applyRelativeFontStyleChange): Takes EditingStyle.
        * editing/ApplyStyleCommand.h:
        * editing/EditingStyle.cpp:
        (WebCore::EditingStyle::EditingStyle): Initializes m_fontSizeDelta.
        (WebCore::EditingStyle::init): Ditto.
        (WebCore::EditingStyle::extractFontSizeDelta): Extracted from applyRelativeFontStyleChange.
        (WebCore::EditingStyle::isEmpty): Takes care of m_fontSizeDelta.
        (WebCore::EditingStyle::setStyle): Calls extractFontSizeDelta.
        (WebCore::EditingStyle::overrideWithStyle): Ditto.
        (WebCore::EditingStyle::clear): Initializes m_fontSizeDelta.
        (WebCore::EditingStyle::copy): Calls extractFontSizeDelta.
        * editing/EditingStyle.h:
        (WebCore::EditingStyle::fontSizeDelta): Added.
        (WebCore::EditingStyle::hasFontSizeDelta): Added.
        * editing/Editor.h:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@75080 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 95dcf973
2011-01-05 Ryosuke Niwa <rniwa@webkit.org>
Reviewed by Eric Seidel.
ApplyStyleCommand::applyRelativeFontStyleChange should take EditingStyle*
https://bugs.webkit.org/show_bug.cgi?id=50641
Modified applyRelativeFontStyleChange to take EditingStyle instead of CSSMutableStyleDeclaration.
Also extracted the logic to obtain the font size delta from ApplyStyleCommand to EditingStyle.
The font size delta is now stored as a member variable of EditingStyle as supposed to a property
in CSSMutableStyleDeclration as soon as EditingStyle is instantiated.
No new tests are added since this is a refactoring.
* editing/ApplyStyleCommand.cpp:
(WebCore::ApplyStyleCommand::doApply): Calls applyRelativeFontStyleChange.
(WebCore::ApplyStyleCommand::applyRelativeFontStyleChange): Takes EditingStyle.
* editing/ApplyStyleCommand.h:
* editing/EditingStyle.cpp:
(WebCore::EditingStyle::EditingStyle): Initializes m_fontSizeDelta.
(WebCore::EditingStyle::init): Ditto.
(WebCore::EditingStyle::extractFontSizeDelta): Extracted from applyRelativeFontStyleChange.
(WebCore::EditingStyle::isEmpty): Takes care of m_fontSizeDelta.
(WebCore::EditingStyle::setStyle): Calls extractFontSizeDelta.
(WebCore::EditingStyle::overrideWithStyle): Ditto.
(WebCore::EditingStyle::clear): Initializes m_fontSizeDelta.
(WebCore::EditingStyle::copy): Calls extractFontSizeDelta.
* editing/EditingStyle.h:
(WebCore::EditingStyle::fontSizeDelta): Added.
(WebCore::EditingStyle::hasFontSizeDelta): Added.
* editing/Editor.h:
2011-01-05 Dan Bernstein <mitz@apple.com>
Reviewed by Darin Adler.
......
......@@ -525,7 +525,7 @@ void ApplyStyleCommand::doApply()
// Apply any remaining styles to the inline elements.
if (!m_style->isEmpty() || m_styledInlineElement || m_isInlineElementToRemoveFunction) {
RefPtr<CSSMutableStyleDeclaration> style = m_style->style() ? m_style->style() : CSSMutableStyleDeclaration::create();
applyRelativeFontStyleChange(style.get());
applyRelativeFontStyleChange(m_style.get());
applyInlineStyle(style.get());
}
break;
......@@ -607,35 +607,13 @@ void ApplyStyleCommand::applyBlockStyle(CSSMutableStyleDeclaration *style)
updateStartEnd(startRange->startPosition(), endRange->startPosition());
}
#define NoFontDelta (0.0f)
#define MinimumFontSize (0.1f)
void ApplyStyleCommand::applyRelativeFontStyleChange(CSSMutableStyleDeclaration *style)
void ApplyStyleCommand::applyRelativeFontStyleChange(EditingStyle* style)
{
RefPtr<CSSValue> value = style->getPropertyCSSValue(CSSPropertyFontSize);
if (value) {
// Explicit font size overrides any delta.
style->removeProperty(CSSPropertyWebkitFontSizeDelta);
return;
}
static const float MinimumFontSize = 0.1f;
// Get the adjustment amount out of the style.
value = style->getPropertyCSSValue(CSSPropertyWebkitFontSizeDelta);
if (!value)
return;
float adjustment = NoFontDelta;
if (value->cssValueType() == CSSValue::CSS_PRIMITIVE_VALUE) {
CSSPrimitiveValue *primitiveValue = static_cast<CSSPrimitiveValue *>(value.get());
if (primitiveValue->primitiveType() == CSSPrimitiveValue::CSS_PX) {
// Only PX handled now. If we handle more types in the future, perhaps
// a switch statement here would be more appropriate.
adjustment = primitiveValue->getFloatValue();
}
}
style->removeProperty(CSSPropertyWebkitFontSizeDelta);
if (adjustment == NoFontDelta)
if (!style || !style->hasFontSizeDelta())
return;
Position start = startPosition();
Position end = endPosition();
if (comparePositions(end, start) < 0) {
......@@ -643,7 +621,7 @@ void ApplyStyleCommand::applyRelativeFontStyleChange(CSSMutableStyleDeclaration
start = end;
end = swap;
}
// Join up any adjacent text nodes.
if (start.node()->isTextNode()) {
joinChildTextNodes(start.node()->parentNode(), start, end);
......@@ -714,7 +692,7 @@ void ApplyStyleCommand::applyRelativeFontStyleChange(CSSMutableStyleDeclaration
CSSMutableStyleDeclaration* inlineStyleDecl = element->getInlineStyleDecl();
float currentFontSize = computedFontSize(node);
float desiredFontSize = max(MinimumFontSize, startingFontSizes.get(node) + adjustment);
float desiredFontSize = max(MinimumFontSize, startingFontSizes.get(node) + style->fontSizeDelta());
RefPtr<CSSValue> value = inlineStyleDecl->getPropertyCSSValue(CSSPropertyFontSize);
if (value) {
inlineStyleDecl->removeProperty(CSSPropertyFontSize, true);
......@@ -737,9 +715,6 @@ void ApplyStyleCommand::applyRelativeFontStyleChange(CSSMutableStyleDeclaration
removeNodePreservingChildren(unstyledSpans[i].get());
}
#undef NoFontDelta
#undef MinimumFontSize
static Node* dummySpanAncestorForNode(const Node* node)
{
while (node && !isStyleSpan(node))
......
......@@ -91,7 +91,7 @@ private:
// style-application helpers
void applyBlockStyle(CSSMutableStyleDeclaration*);
void applyRelativeFontStyleChange(CSSMutableStyleDeclaration*);
void applyRelativeFontStyleChange(EditingStyle*);
void applyInlineStyle(CSSMutableStyleDeclaration*);
void fixRangeAndApplyInlineStyle(CSSMutableStyleDeclaration*, const Position& start, const Position& end);
void applyInlineStyleToNodeRange(CSSMutableStyleDeclaration*, Node* startNode, Node* pastEndNode);
......
......@@ -82,19 +82,24 @@ static PassRefPtr<CSSMutableStyleDeclaration> editingStyleFromComputedStyle(Pass
return copyEditingProperties(style.get());
}
float EditingStyle::NoFontDelta = 0.0f;
EditingStyle::EditingStyle()
: m_shouldUseFixedDefaultFontSize(false)
, m_fontSizeDelta(NoFontDelta)
{
}
EditingStyle::EditingStyle(Node* node)
: m_shouldUseFixedDefaultFontSize(false)
, m_fontSizeDelta(NoFontDelta)
{
init(node);
}
EditingStyle::EditingStyle(const Position& position)
: m_shouldUseFixedDefaultFontSize(false)
, m_fontSizeDelta(NoFontDelta)
{
init(position.node());
}
......@@ -102,7 +107,9 @@ EditingStyle::EditingStyle(const Position& position)
EditingStyle::EditingStyle(const CSSStyleDeclaration* style)
: m_mutableStyle(style->copy())
, m_shouldUseFixedDefaultFontSize(false)
, m_fontSizeDelta(NoFontDelta)
{
extractFontSizeDelta();
}
EditingStyle::~EditingStyle()
......@@ -121,6 +128,7 @@ void EditingStyle::init(Node* node)
}
m_shouldUseFixedDefaultFontSize = computedStyleAtPosition->useFixedFontDefaultSize();
extractFontSizeDelta();
}
void EditingStyle::removeTextFillAndStrokeColorsIfNeeded(RenderStyle* renderStyle)
......@@ -143,9 +151,33 @@ void EditingStyle::replaceFontSizeByKeywordIfPossible(RenderStyle* renderStyle,
m_mutableStyle->setProperty(CSSPropertyFontSize, computedStyle->getFontSizeCSSValuePreferringKeyword()->cssText());
}
void EditingStyle::extractFontSizeDelta()
{
if (m_mutableStyle->getPropertyCSSValue(CSSPropertyFontSize)) {
// Explicit font size overrides any delta.
m_mutableStyle->removeProperty(CSSPropertyWebkitFontSizeDelta);
return;
}
// Get the adjustment amount out of the style.
RefPtr<CSSValue> value = m_mutableStyle->getPropertyCSSValue(CSSPropertyWebkitFontSizeDelta);
if (!value || value->cssValueType() != CSSValue::CSS_PRIMITIVE_VALUE)
return;
CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value.get());
// Only PX handled now. If we handle more types in the future, perhaps
// a switch statement here would be more appropriate.
if (primitiveValue->primitiveType() != CSSPrimitiveValue::CSS_PX)
return;
m_fontSizeDelta = primitiveValue->getFloatValue();
m_mutableStyle->removeProperty(CSSPropertyWebkitFontSizeDelta);
}
bool EditingStyle::isEmpty() const
{
return !m_mutableStyle || m_mutableStyle->isEmpty();
return (!m_mutableStyle || m_mutableStyle->isEmpty()) && m_fontSizeDelta == NoFontDelta;
}
bool EditingStyle::textDirection(WritingDirection& writingDirection) const
......@@ -181,6 +213,7 @@ void EditingStyle::setStyle(PassRefPtr<CSSMutableStyleDeclaration> style)
// FIXME: We should be able to figure out whether or not font is fixed width for mutable style.
// We need to check font-family is monospace as in FontDescription but we don't want to duplicate code here.
m_shouldUseFixedDefaultFontSize = false;
extractFontSizeDelta();
}
void EditingStyle::overrideWithStyle(const CSSMutableStyleDeclaration* style)
......@@ -190,12 +223,14 @@ void EditingStyle::overrideWithStyle(const CSSMutableStyleDeclaration* style)
if (!m_mutableStyle)
m_mutableStyle = CSSMutableStyleDeclaration::create();
m_mutableStyle->merge(style);
extractFontSizeDelta();
}
void EditingStyle::clear()
{
m_mutableStyle.clear();
m_shouldUseFixedDefaultFontSize = false;
m_fontSizeDelta = NoFontDelta;
}
PassRefPtr<EditingStyle> EditingStyle::copy() const
......@@ -204,6 +239,7 @@ PassRefPtr<EditingStyle> EditingStyle::copy() const
if (m_mutableStyle)
copy->m_mutableStyle = m_mutableStyle->copy();
copy->m_shouldUseFixedDefaultFontSize = m_shouldUseFixedDefaultFontSize;
copy->m_fontSizeDelta = m_fontSizeDelta;
return copy;
}
......
......@@ -46,8 +46,9 @@ class RenderStyle;
class EditingStyle : public RefCounted<EditingStyle> {
public:
enum ShouldPreserveWritingDirection { PreserveWritingDirection, DoNotPreserveWritingDirection };
static float NoFontDelta;
static PassRefPtr<EditingStyle> create()
{
......@@ -85,6 +86,9 @@ public:
void removeNonEditingProperties();
void prepareToApplyAt(const Position&, ShouldPreserveWritingDirection = DoNotPreserveWritingDirection);
float fontSizeDelta() const { return m_fontSizeDelta; }
bool hasFontSizeDelta() const { return m_fontSizeDelta != NoFontDelta; }
private:
EditingStyle();
EditingStyle(Node*);
......@@ -93,9 +97,11 @@ private:
void init(Node*);
void removeTextFillAndStrokeColorsIfNeeded(RenderStyle*);
void replaceFontSizeByKeywordIfPossible(RenderStyle*, CSSComputedStyleDeclaration*);
void extractFontSizeDelta();
RefPtr<CSSMutableStyleDeclaration> m_mutableStyle;
bool m_shouldUseFixedDefaultFontSize;
float m_fontSizeDelta;
};
PassRefPtr<EditingStyle> editingStyleIncludingTypingStyle(const Position&);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment