[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677
kocienda
kocienda at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 08:43:05 UTC 2009
The following commit has been merged in the debian/unstable branch:
commit f13a569b6102e29d440dd337707d8f0612d290f9
Author: kocienda <kocienda at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Tue Jun 1 20:58:31 2004 +0000
Reviewed by Darin
Fix for these bugs:
<rdar://problem/3655028>: "Text styles have hard-coded values making bold the only supported text style"
<rdar://problem/3656969>: "HTML Editing: Font panel doesn't work"
* khtml/css/css_valueimpl.cpp:
(FontFamilyValueImpl::cssText): Added implementation for this subclass. Returns parsedFontName.
* khtml/css/css_valueimpl.h: Declare cssText() on FontFamilyValueImpl.
(DOM::CSSProperty::value):
* khtml/editing/htmlediting.cpp:
(khtml::ApplyStyleCommand::ApplyStyleCommand): Changed signature to take a CSSStyleDeclarationImpl.
(khtml::ApplyStyleCommand::style): Added accessor.
* khtml/editing/htmlediting.h: Changed constructor signature to take a CSSStyleDeclarationImpl.
* khtml/editing/htmlediting_impl.cpp:
(khtml::styleSpanClassString): Added helper to return attribute used to tag spans we add to apply styles.
(khtml::ApplyStyleCommandImpl::ApplyStyleCommandImpl): Ref style passed in.
(khtml::ApplyStyleCommandImpl::~ApplyStyleCommandImpl): Deref style passed in.
(khtml::ApplyStyleCommandImpl::doApply): m_removingStyle is obsolete. Removed.
(khtml::ApplyStyleCommandImpl::isHTMLStyleNode): Now checks all properties in the object's declaration.
(khtml::ApplyStyleCommandImpl::removeCSSStyle): Again, now is multi-property-savvy. Will now remove an empty span
if we added it.
(khtml::ApplyStyleCommandImpl::currentlyHasStyle): Replaced, bold-only code with code that can handle all styles.
(khtml::ApplyStyleCommandImpl::computeStyleChange): Helper which helps to determine whether we want to apply
HTML-style markup for bold and italic, and gathers up all style changes that need to be done.
(khtml::ApplyStyleCommandImpl::positionInsertionPoint): Added comment explaining possible optimization that might be
done in the future.
(khtml::ApplyStyleCommandImpl::applyStyleIfNeeded): Significant reworking; now handles applying multiple styles.
(khtml::ApplyStyleCommandImpl::cloneSelection): Assert fragment has at least one child. Don't want to work
on empty fragments.
(khtml::ApplyStyleCommandImpl::surroundContentsWithElement): New helper.
(khtml::RemoveCSSPropertyCommandImpl::~RemoveCSSPropertyCommandImpl): Juggle asserts and lifecycle methods to be
more like other commands.
(khtml::RemoveCSSPropertyCommandImpl::doApply): Ditto.
(khtml::RemoveNodeAttributeCommandImpl::~RemoveNodeAttributeCommandImpl): Ditto.
(khtml::RemoveNodeAttributeCommandImpl::doApply):Ditto.
* khtml/editing/htmlediting_impl.h:
(khtml::ApplyStyleCommandImpl::style): Added.
(khtml::ApplyStyleCommandImpl::StyleChange::StyleChange): Added.
* kwq/DOM-CSS.mm:
(-[DOMCSSStyleDeclaration setProperty:::]): Fix problem where passing an empty NSString to a function expecting a boolean
made all properties important priority.
* kwq/WebCoreBridge.mm:
(-[WebCoreBridge applyStyle:]): Remove provisional code and comment. Now pass along style, following the intended design.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@6736 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/ChangeLog-2005-08-23 b/WebCore/ChangeLog-2005-08-23
index 4bd7b97..52e4336 100644
--- a/WebCore/ChangeLog-2005-08-23
+++ b/WebCore/ChangeLog-2005-08-23
@@ -1,3 +1,51 @@
+2004-06-01 Ken Kocienda <kocienda at apple.com>
+
+ Reviewed by Darin
+
+ Fix for these bugs:
+
+ <rdar://problem/3655028>: "Text styles have hard-coded values making bold the only supported text style"
+ <rdar://problem/3656969>: "HTML Editing: Font panel doesn't work"
+
+ * khtml/css/css_valueimpl.cpp:
+ (FontFamilyValueImpl::cssText): Added implementation for this subclass. Returns parsedFontName.
+ * khtml/css/css_valueimpl.h: Declare cssText() on FontFamilyValueImpl.
+ (DOM::CSSProperty::value):
+ * khtml/editing/htmlediting.cpp:
+ (khtml::ApplyStyleCommand::ApplyStyleCommand): Changed signature to take a CSSStyleDeclarationImpl.
+ (khtml::ApplyStyleCommand::style): Added accessor.
+ * khtml/editing/htmlediting.h: Changed constructor signature to take a CSSStyleDeclarationImpl.
+ * khtml/editing/htmlediting_impl.cpp:
+ (khtml::styleSpanClassString): Added helper to return attribute used to tag spans we add to apply styles.
+ (khtml::ApplyStyleCommandImpl::ApplyStyleCommandImpl): Ref style passed in.
+ (khtml::ApplyStyleCommandImpl::~ApplyStyleCommandImpl): Deref style passed in.
+ (khtml::ApplyStyleCommandImpl::doApply): m_removingStyle is obsolete. Removed.
+ (khtml::ApplyStyleCommandImpl::isHTMLStyleNode): Now checks all properties in the object's declaration.
+ (khtml::ApplyStyleCommandImpl::removeCSSStyle): Again, now is multi-property-savvy. Will now remove an empty span
+ if we added it.
+ (khtml::ApplyStyleCommandImpl::currentlyHasStyle): Replaced, bold-only code with code that can handle all styles.
+ (khtml::ApplyStyleCommandImpl::computeStyleChange): Helper which helps to determine whether we want to apply
+ HTML-style markup for bold and italic, and gathers up all style changes that need to be done.
+ (khtml::ApplyStyleCommandImpl::positionInsertionPoint): Added comment explaining possible optimization that might be
+ done in the future.
+ (khtml::ApplyStyleCommandImpl::applyStyleIfNeeded): Significant reworking; now handles applying multiple styles.
+ (khtml::ApplyStyleCommandImpl::cloneSelection): Assert fragment has at least one child. Don't want to work
+ on empty fragments.
+ (khtml::ApplyStyleCommandImpl::surroundContentsWithElement): New helper.
+ (khtml::RemoveCSSPropertyCommandImpl::~RemoveCSSPropertyCommandImpl): Juggle asserts and lifecycle methods to be
+ more like other commands.
+ (khtml::RemoveCSSPropertyCommandImpl::doApply): Ditto.
+ (khtml::RemoveNodeAttributeCommandImpl::~RemoveNodeAttributeCommandImpl): Ditto.
+ (khtml::RemoveNodeAttributeCommandImpl::doApply):Ditto.
+ * khtml/editing/htmlediting_impl.h:
+ (khtml::ApplyStyleCommandImpl::style): Added.
+ (khtml::ApplyStyleCommandImpl::StyleChange::StyleChange): Added.
+ * kwq/DOM-CSS.mm:
+ (-[DOMCSSStyleDeclaration setProperty:::]): Fix problem where passing an empty NSString to a function expecting a boolean
+ made all properties important priority.
+ * kwq/WebCoreBridge.mm:
+ (-[WebCoreBridge applyStyle:]): Remove provisional code and comment. Now pass along style, following the intended design.
+
2004-06-01 Chris Blumenberg <cblu at apple.com>
Reviewed by kocienda.
@@ -9,11 +57,10 @@
2004-05-28 John Louch <ouch at apple.com>
Reviewed by gramps.
-
- - removed setShadowWithColor and change setShadow to work with optional attributes
- it follows the same rules as setFill/StrokeColor
- - Fixed bug in setFillColor and setStrokeColor for CMYK colors (missing break in case).
-
+
+ - removed setShadowWithColor and change setShadow to work with optional attributes
+ it follows the same rules as setFill/StrokeColor
+ - Fixed bug in setFillColor and setStrokeColor for CMYK colors (missing break in case).
* khtml/ecma/kjs_html.cpp:
(KJS::Context2DFunction::tryCall):
diff --git a/WebCore/khtml/css/css_valueimpl.cpp b/WebCore/khtml/css/css_valueimpl.cpp
index 285847f..0f71d45 100644
--- a/WebCore/khtml/css/css_valueimpl.cpp
+++ b/WebCore/khtml/css/css_valueimpl.cpp
@@ -924,6 +924,11 @@ FontFamilyValueImpl::FontFamilyValueImpl( const QString &string)
#endif // !APPLE_CHANGES
}
+DOM::DOMString FontFamilyValueImpl::cssText() const
+{
+ return parsedFontName;
+}
+
FontValueImpl::FontValueImpl()
: style(0), variant(0), weight(0), size(0), lineHeight(0), family(0)
{
diff --git a/WebCore/khtml/css/css_valueimpl.h b/WebCore/khtml/css/css_valueimpl.h
index 6549185..37e4016 100644
--- a/WebCore/khtml/css/css_valueimpl.h
+++ b/WebCore/khtml/css/css_valueimpl.h
@@ -307,6 +307,8 @@ public:
const QString &fontName() const { return parsedFontName; }
int genericFamilyType() const { return _genericFamilyType; }
+ virtual DOM::DOMString cssText() const;
+
QString parsedFontName;
private:
int _genericFamilyType;
@@ -384,7 +386,7 @@ public:
int id() const { return m_id; }
bool isImportant() const { return m_bImportant; }
- CSSValueImpl *value() { return m_value; }
+ CSSValueImpl *value() const { return m_value; }
DOM::DOMString cssText() const;
diff --git a/WebCore/khtml/editing/htmlediting.cpp b/WebCore/khtml/editing/htmlediting.cpp
index 8d78d67..439a305 100644
--- a/WebCore/khtml/editing/htmlediting.cpp
+++ b/WebCore/khtml/editing/htmlediting.cpp
@@ -239,7 +239,7 @@ NodeImpl *AppendNodeCommand::appendChild() const
//------------------------------------------------------------------------------------------
// ApplyStyleCommand
-ApplyStyleCommand::ApplyStyleCommand(DocumentImpl *document, EStyle style)
+ApplyStyleCommand::ApplyStyleCommand(DocumentImpl *document, CSSStyleDeclarationImpl *style)
: CompositeEditCommand(new ApplyStyleCommandImpl(document, style))
{
}
@@ -253,6 +253,12 @@ ApplyStyleCommandImpl *ApplyStyleCommand::impl() const
return static_cast<ApplyStyleCommandImpl *>(get());
}
+CSSStyleDeclarationImpl *ApplyStyleCommand::style() const
+{
+ IF_IMPL_NULL_RETURN_ARG(0);
+ return impl()->style();
+}
+
//------------------------------------------------------------------------------------------
// DeleteCollapsibleWhitespaceCommand
diff --git a/WebCore/khtml/editing/htmlediting.h b/WebCore/khtml/editing/htmlediting.h
index 8eb9955..13feb74 100644
--- a/WebCore/khtml/editing/htmlediting.h
+++ b/WebCore/khtml/editing/htmlediting.h
@@ -201,12 +201,11 @@ private:
class ApplyStyleCommand : public CompositeEditCommand
{
public:
-
- enum EStyle { NONE, BOLD };
-
- ApplyStyleCommand(DOM::DocumentImpl *, EStyle);
+ ApplyStyleCommand(DOM::DocumentImpl *, DOM::CSSStyleDeclarationImpl *);
virtual ~ApplyStyleCommand();
+ DOM::CSSStyleDeclarationImpl *style() const;
+
private:
inline ApplyStyleCommandImpl *impl() const;
};
diff --git a/WebCore/khtml/editing/htmlediting_impl.cpp b/WebCore/khtml/editing/htmlediting_impl.cpp
index 4302ebc..b5dbb7e 100644
--- a/WebCore/khtml/editing/htmlediting_impl.cpp
+++ b/WebCore/khtml/editing/htmlediting_impl.cpp
@@ -35,6 +35,7 @@
#include "htmltags.h"
#include "khtml_part.h"
#include "khtmlview.h"
+#include "qptrlist.h"
#include "rendering/render_object.h"
#include "rendering/render_style.h"
#include "rendering/render_text.h"
@@ -58,6 +59,7 @@ using DOM::CSSPrimitiveValue;
using DOM::CSSPrimitiveValueImpl;
using DOM::CSSProperty;
using DOM::CSSStyleDeclarationImpl;
+using DOM::CSSValueImpl;
using DOM::DocumentFragmentImpl;
using DOM::DocumentImpl;
using DOM::DOMString;
@@ -67,6 +69,7 @@ using DOM::EditIterator;
using DOM::ElementImpl;
using DOM::HTMLElementImpl;
using DOM::HTMLImageElementImpl;
+using DOM::NamedAttrMapImpl;
using DOM::Node;
using DOM::NodeImpl;
using DOM::NodeListImpl;
@@ -208,6 +211,12 @@ static DOMString &nonBreakingSpaceString()
return nonBreakingSpaceString;
}
+static DOMString &styleSpanClassString()
+{
+ static DOMString styleSpanClassString = "khtml-style-span";
+ return styleSpanClassString;
+}
+
static void debugPosition(const char *prefix, const Position &pos)
{
LOG(Editing, "%s%s %p : %d", prefix, getTagName(pos.node()->id()).string().latin1(), pos.node(), pos.offset());
@@ -574,13 +583,17 @@ void AppendNodeCommandImpl::doUnapply()
//------------------------------------------------------------------------------------------
// ApplyStyleCommandImpl
-ApplyStyleCommandImpl::ApplyStyleCommandImpl(DocumentImpl *document, ApplyStyleCommand::EStyle style)
- : CompositeEditCommandImpl(document), m_styleConstant(style)
+ApplyStyleCommandImpl::ApplyStyleCommandImpl(DocumentImpl *document, CSSStyleDeclarationImpl *style)
+ : CompositeEditCommandImpl(document), m_style(style)
{
+ ASSERT(m_style);
+ m_style->ref();
}
ApplyStyleCommandImpl::~ApplyStyleCommandImpl()
{
+ ASSERT(m_style);
+ m_style->deref();
}
int ApplyStyleCommandImpl::commandID() const
@@ -593,8 +606,6 @@ void ApplyStyleCommandImpl::doApply()
if (endingSelection().state() != Selection::RANGE)
return;
- m_removingStyle = currentlyHasStyle();
-
// Right now, we only apply in place if the start and end are in the same
// node. This could be improved in the future to handle more cases that
// are only a bit more complex than this case.
@@ -611,13 +622,21 @@ void ApplyStyleCommandImpl::doApply()
bool ApplyStyleCommandImpl::isHTMLStyleNode(HTMLElementImpl *elem)
{
- switch (m_styleConstant) {
- case ApplyStyleCommand::BOLD:
- return elem->id() == ID_B;
- default:
- case ApplyStyleCommand::NONE:
- return false;
+ for (QPtrListIterator<CSSProperty> it(*(style()->values())); it.current(); ++it) {
+ CSSProperty *property = it.current();
+ switch (property->id()) {
+ case CSS_PROP_FONT_WEIGHT:
+ if (elem->id() == ID_B)
+ return true;
+ break;
+ case CSS_PROP_FONT_STYLE:
+ if (elem->id() == ID_I)
+ return true;
+ break;
+ }
}
+
+ return false;
}
void ApplyStyleCommandImpl::removeHTMLStyleNode(HTMLElementImpl *elem, EUndoable undoable)
@@ -635,11 +654,14 @@ void ApplyStyleCommandImpl::removeCSSStyle(HTMLElementImpl *elem, EUndoable undo
ASSERT(elem);
CSSStyleDeclarationImpl *decl = elem->inlineStyleDecl();
- int property = cssProperty();
- if (!decl || !decl->getPropertyCSSValue(property))
+ if (!decl)
return;
-
- removeCSSProperty(decl, property, undoable);
+
+ for (QPtrListIterator<CSSProperty> it(*(style()->values())); it.current(); ++it) {
+ CSSProperty *property = it.current();
+ if (decl->getPropertyCSSValue(property->id()))
+ removeCSSProperty(decl, property->id(), undoable);
+ }
// EDIT FIXME: These four lines of code should not be necessary.
// The DOM should update without having to do this extra work.
@@ -647,6 +669,15 @@ void ApplyStyleCommandImpl::removeCSSStyle(HTMLElementImpl *elem, EUndoable undo
setNodeAttribute(elem, ATTR_STYLE, decl->cssText(), undoable);
else
removeNodeAttribute(elem, ATTR_STYLE, undoable);
+
+ if (elem->id() == ID_SPAN) {
+ // Check to see if the span is one we added to apply style.
+ // If it is, and there are no more attributes on the span other than our
+ // class marker, remove the span.
+ NamedAttrMapImpl *map = elem->attributes();
+ if (map && map->length() == 1 && elem->getAttribute(ATTR_CLASS) == styleSpanClassString())
+ removeNodePreservingChildren(elem, undoable);
+ }
}
void ApplyStyleCommandImpl::removeCSSProperty(CSSStyleDeclarationImpl *decl, int property, EUndoable undoable)
@@ -707,88 +738,52 @@ void ApplyStyleCommandImpl::removeNodePreservingChildren(NodeImpl *parent, EUndo
//------------------------------------------------------------------------------------------
// ApplyStyleCommandImpl: shared helpers
-bool ApplyStyleCommandImpl::mustExlicitlyApplyStyle(const Position &pos) const
-{
- bool hasStyle = currentlyHasStyle(pos);
- return (removingStyle() && hasStyle) || (!removingStyle() && !hasStyle);
-}
-
-NodeImpl *ApplyStyleCommandImpl::createExplicitApplyStyleNode() const
-{
- int exceptionCode = 0;
-
- switch (m_styleConstant) {
- case ApplyStyleCommand::BOLD:
- if (removingStyle()) {
- ElementImpl *elem = document()->createHTMLElement("SPAN", exceptionCode);
- ASSERT(exceptionCode == 0);
- elem->setAttribute(ATTR_STYLE, "font-weight: normal");
- return elem;
- }
- else {
- ElementImpl *elem = document()->createHTMLElement("B", exceptionCode);
- ASSERT(exceptionCode == 0);
- return elem;
- }
- default:
- case ApplyStyleCommand::NONE:
- ASSERT_NOT_REACHED();
- }
-
- return 0;
-}
-
-bool ApplyStyleCommandImpl::currentlyHasStyle() const
-{
- return currentlyHasStyle(endingSelection().start().equivalentDownstreamPosition());
-}
-
-bool ApplyStyleCommandImpl::currentlyHasStyle(const Position &pos) const
+bool ApplyStyleCommandImpl::currentlyHasStyle(const Position &pos, const CSSProperty *property) const
{
ASSERT(pos.notEmpty());
-
- NodeImpl *node = pos.node();
- while (node && !node->isElementNode())
- node = node->parentNode();
- ASSERT(node);
-
- CSSStyleDeclarationImpl *decl = document()->defaultView()->getComputedStyle(static_cast<ElementImpl *>(node), 0);
+ CSSStyleDeclarationImpl *decl = document()->defaultView()->getComputedStyle(pos.element(), 0);
ASSERT(decl);
-
- switch (m_styleConstant) {
- case ApplyStyleCommand::BOLD: {
- CSSPrimitiveValueImpl *value = static_cast<CSSPrimitiveValueImpl *>(decl->getPropertyCSSValue(CSS_PROP_FONT_WEIGHT));
- return !strcasecmp(value->getStringValue(), "bold");
- }
- case ApplyStyleCommand::NONE:
- ASSERT(0);
- break;
- }
-
- return false;
+ CSSValueImpl *value = decl->getPropertyCSSValue(property->id());
+ return strcasecmp(value->cssText(), property->value()->cssText()) == 0;
}
-int ApplyStyleCommandImpl::cssProperty() const
+ApplyStyleCommandImpl::StyleChange ApplyStyleCommandImpl::computeStyleChange(const Position &insertionPoint, CSSStyleDeclarationImpl *style)
{
- switch (m_styleConstant) {
- case ApplyStyleCommand::BOLD:
- return CSS_PROP_FONT_WEIGHT;
- default:
- case ApplyStyleCommand::NONE:
- ASSERT_NOT_REACHED();
+ ASSERT(insertionPoint.notEmpty());
+ ASSERT(style);
+
+ StyleChange styleChange;
+
+ for (QPtrListIterator<CSSProperty> it(*(style->values())); it.current(); ++it) {
+ CSSProperty *property = it.current();
+ if (!currentlyHasStyle(insertionPoint, property)) {
+ switch (property->id()) {
+ case CSS_PROP_FONT_WEIGHT:
+ if (strcasecmp(property->value()->cssText(), "bold") == 0)
+ styleChange.applyBold = true;
+ else
+ styleChange.cssStyle += property->cssText();
+ break;
+ case CSS_PROP_FONT_STYLE: {
+ DOMString cssText(property->value()->cssText());
+ if (strcasecmp(cssText, "italic") == 0 || strcasecmp(cssText, "oblique") == 0)
+ styleChange.applyItalic = true;
+ else
+ styleChange.cssStyle += property->cssText();
+ }
+ break;
+ default:
+ styleChange.cssStyle += property->cssText();
+ break;
+ }
+ }
}
-
- return 0;
+ return styleChange;
}
//------------------------------------------------------------------------------------------
// ApplyStyleCommandImpl: apply-in-place helpers
-bool ApplyStyleCommandImpl::matchesTargetStyle(bool hasStyle) const
-{
- return (removingStyle() && !hasStyle) || (!removingStyle() && hasStyle);
-}
-
Position ApplyStyleCommandImpl::positionInsertionPoint(Position pos)
{
if (pos.node()->isTextNode() && (pos.offset() > 0 && pos.offset() < pos.node()->maxOffset())) {
@@ -797,7 +792,13 @@ Position ApplyStyleCommandImpl::positionInsertionPoint(Position pos)
pos = Position(split.node(), 0);
}
- if (matchesTargetStyle(currentlyHasStyle(pos)))
+#if 0
+ // EDIT FIXME: If modified to work with the internals of applying style,
+ // this code can work to optimize cases where a style change is taking place on
+ // a boundary between nodes where one of the nodes has the desired style. In other
+ // words, it is possible for content to be merged into existing nodes rather than adding
+ // additional markup.
+ if (currentlyHasStyle(pos))
return pos;
// try next node
@@ -805,7 +806,7 @@ Position ApplyStyleCommandImpl::positionInsertionPoint(Position pos)
NodeImpl *nextNode = pos.node()->traverseNextNode();
if (nextNode) {
Position next = Position(nextNode, 0);
- if (matchesTargetStyle(currentlyHasStyle(next)))
+ if (currentlyHasStyle(next))
return next;
}
}
@@ -815,10 +816,11 @@ Position ApplyStyleCommandImpl::positionInsertionPoint(Position pos)
NodeImpl *prevNode = pos.node()->traversePreviousNode();
if (prevNode) {
Position prev = Position(prevNode, prevNode->maxOffset());
- if (matchesTargetStyle(currentlyHasStyle(prev)))
+ if (currentlyHasStyle(prev))
return prev;
}
}
+#endif
return pos;
}
@@ -854,13 +856,35 @@ bool ApplyStyleCommandImpl::splitTextAtEndIfNeeded(const Position &start, const
void ApplyStyleCommandImpl::applyStyleIfNeeded(const Position &insertionPoint)
{
ASSERT(insertionPoint.notEmpty());
- if (mustExlicitlyApplyStyle(insertionPoint)) {
- NodeImpl *styleNode = createExplicitApplyStyleNode();
- ASSERT(styleNode);
- NodeImpl *contentNode = insertionPoint.node();
- insertNodeBefore(styleNode, contentNode);
+
+ StyleChange styleChange = computeStyleChange(insertionPoint, style());
+ NodeImpl *contentNode = insertionPoint.node();
+ int exceptionCode = 0;
+
+ if (styleChange.cssStyle.length() > 0) {
+ ElementImpl *styleElement = document()->createHTMLElement("SPAN", exceptionCode);
+ ASSERT(exceptionCode == 0);
+ styleElement->setAttribute(ATTR_STYLE, styleChange.cssStyle);
+ styleElement->setAttribute(ATTR_CLASS, styleSpanClassString());
+ insertNodeBefore(styleElement, contentNode);
removeNode(contentNode);
- appendNode(styleNode, contentNode);
+ appendNode(styleElement, contentNode);
+ }
+
+ if (styleChange.applyBold) {
+ ElementImpl *boldElement = document()->createHTMLElement("B", exceptionCode);
+ ASSERT(exceptionCode == 0);
+ insertNodeBefore(boldElement, contentNode);
+ removeNode(contentNode);
+ appendNode(boldElement, contentNode);
+ }
+
+ if (styleChange.applyItalic) {
+ ElementImpl *italicElement = document()->createHTMLElement("I", exceptionCode);
+ ASSERT(exceptionCode == 0);
+ insertNodeBefore(italicElement, contentNode);
+ removeNode(contentNode);
+ appendNode(italicElement, contentNode);
}
}
@@ -903,6 +927,7 @@ DocumentFragmentImpl *ApplyStyleCommandImpl::cloneSelection() const
DocumentFragmentImpl *fragment = range->cloneContents(exceptionCode);
ASSERT(exceptionCode == 0);
+ ASSERT(fragment->firstChild());
range->detach(exceptionCode);
ASSERT(exceptionCode == 0);
@@ -930,28 +955,52 @@ void ApplyStyleCommandImpl::removeStyle(DocumentFragmentImpl *fragment)
}
}
-void ApplyStyleCommandImpl::applyStyleIfNeeded(DocumentFragmentImpl *fragment, const Position &insertionPoint)
+void ApplyStyleCommandImpl::surroundContentsWithElement(DocumentFragmentImpl *fragment, ElementImpl *element)
{
ASSERT(fragment);
+ ASSERT(element);
+
+ int exceptionCode = 0;
+ NodeImpl *node = fragment->firstChild();
+ while (node) {
+ NodeImpl *next = node->nextSibling();
+ node->ref();
+ fragment->removeChild(node, exceptionCode);
+ ASSERT(exceptionCode == 0);
+ element->appendChild(node, exceptionCode);
+ ASSERT(exceptionCode == 0);
+ node->deref();
+ node = next;
+ }
+ fragment->appendChild(element, exceptionCode);
+ ASSERT(exceptionCode == 0);
+}
+
+void ApplyStyleCommandImpl::applyStyleIfNeeded(DocumentFragmentImpl *fragment, const Position &insertionPoint)
+{
ASSERT(insertionPoint.notEmpty());
- if (mustExlicitlyApplyStyle(insertionPoint)) {
- NodeImpl *styleNode = createExplicitApplyStyleNode();
- ASSERT(styleNode);
- int exceptionCode = 0;
- NodeImpl *node = fragment->firstChild();
- while (node) {
- NodeImpl *next = node->nextSibling();
- node->ref();
- fragment->removeChild(node, exceptionCode);
- ASSERT(exceptionCode == 0);
- styleNode->appendChild(node, exceptionCode);
- ASSERT(exceptionCode == 0);
- node->deref();
- node = next;
- }
- fragment->appendChild(styleNode, exceptionCode);
+ StyleChange styleChange = computeStyleChange(insertionPoint, style());
+ int exceptionCode = 0;
+
+ if (styleChange.cssStyle.length() > 0) {
+ ElementImpl *styleElement = document()->createHTMLElement("SPAN", exceptionCode);
+ ASSERT(exceptionCode == 0);
+ styleElement->setAttribute(ATTR_STYLE, styleChange.cssStyle);
+ styleElement->setAttribute(ATTR_CLASS, styleSpanClassString());
+ surroundContentsWithElement(fragment, styleElement);
+ }
+
+ if (styleChange.applyBold) {
+ ElementImpl *boldElement = document()->createHTMLElement("B", exceptionCode);
ASSERT(exceptionCode == 0);
+ surroundContentsWithElement(fragment, boldElement);
+ }
+
+ if (styleChange.applyItalic) {
+ ElementImpl *italicElement = document()->createHTMLElement("I", exceptionCode);
+ ASSERT(exceptionCode == 0);
+ surroundContentsWithElement(fragment, italicElement);
}
}
@@ -2065,8 +2114,8 @@ RemoveCSSPropertyCommandImpl::RemoveCSSPropertyCommandImpl(DocumentImpl *documen
RemoveCSSPropertyCommandImpl::~RemoveCSSPropertyCommandImpl()
{
- if (m_decl)
- m_decl->deref();
+ ASSERT(m_decl);
+ m_decl->deref();
}
int RemoveCSSPropertyCommandImpl::commandID() const
@@ -2079,6 +2128,8 @@ void RemoveCSSPropertyCommandImpl::doApply()
ASSERT(m_decl);
m_oldValue = m_decl->getPropertyValue(m_property);
+ ASSERT(!m_oldValue.isNull());
+
m_important = m_decl->getPropertyPriority(m_property);
m_decl->removeProperty(m_property);
}
@@ -2103,8 +2154,8 @@ RemoveNodeAttributeCommandImpl::RemoveNodeAttributeCommandImpl(DocumentImpl *doc
RemoveNodeAttributeCommandImpl::~RemoveNodeAttributeCommandImpl()
{
- if (m_element)
- m_element->deref();
+ ASSERT(m_element);
+ m_element->deref();
}
int RemoveNodeAttributeCommandImpl::commandID() const
@@ -2116,8 +2167,10 @@ void RemoveNodeAttributeCommandImpl::doApply()
{
ASSERT(m_element);
- int exceptionCode = 0;
m_oldValue = m_element->getAttribute(m_attribute);
+ ASSERT(!m_oldValue.isNull());
+
+ int exceptionCode = 0;
m_element->removeAttribute(m_attribute, exceptionCode);
ASSERT(exceptionCode == 0);
}
diff --git a/WebCore/khtml/editing/htmlediting_impl.h b/WebCore/khtml/editing/htmlediting_impl.h
index b737416..131f49d 100644
--- a/WebCore/khtml/editing/htmlediting_impl.h
+++ b/WebCore/khtml/editing/htmlediting_impl.h
@@ -37,6 +37,7 @@
namespace DOM {
class AtomicString;
+ class CSSProperty;
class CSSStyleDeclarationImpl;
class DocumentImpl;
class DOMString;
@@ -171,13 +172,22 @@ private:
class ApplyStyleCommandImpl : public CompositeEditCommandImpl
{
public:
- ApplyStyleCommandImpl(DOM::DocumentImpl *, ApplyStyleCommand::EStyle);
+ ApplyStyleCommandImpl(DOM::DocumentImpl *, DOM::CSSStyleDeclarationImpl *style);
virtual ~ApplyStyleCommandImpl();
virtual int commandID() const;
virtual void doApply();
+ DOM::CSSStyleDeclarationImpl *style() const { return m_style; }
+
+ struct StyleChange {
+ StyleChange() : applyBold(false), applyItalic(false) {}
+ DOM::DOMString cssStyle;
+ bool applyBold:1;
+ bool applyItalic:1;
+ };
+
private:
// style-removal helpers
enum EUndoable { UNDOABLE, NOTUNDOABLE };
@@ -190,15 +200,10 @@ private:
void removeNodePreservingChildren(DOM::NodeImpl *, EUndoable undoable);
// shared helpers
- bool mustExlicitlyApplyStyle(const DOM::Position &) const;
- DOM::NodeImpl *createExplicitApplyStyleNode() const;
- bool removingStyle() const { return m_removingStyle; }
- bool currentlyHasStyle() const;
- bool currentlyHasStyle(const DOM::Position &) const;
- int cssProperty() const;
+ bool currentlyHasStyle(const DOM::Position &, const DOM::CSSProperty *) const;
+ StyleChange computeStyleChange(const DOM::Position &, DOM::CSSStyleDeclarationImpl *);
// apply-in-place helpers
- bool matchesTargetStyle(bool hasStyle) const;
DOM::Position positionInsertionPoint(DOM::Position);
bool splitTextAtStartIfNeeded(const DOM::Position &start, const DOM::Position &end);
bool splitTextAtEndIfNeeded(const DOM::Position &start, const DOM::Position &end);
@@ -208,6 +213,7 @@ private:
// apply using fragment helpers
DOM::DocumentFragmentImpl *cloneSelection() const;
void removeStyle(DOM::DocumentFragmentImpl *);
+ void surroundContentsWithElement(DOM::DocumentFragmentImpl *, DOM::ElementImpl *);
void applyStyleIfNeeded(DOM::DocumentFragmentImpl *, const DOM::Position &);
void insertFragment(DOM::DocumentFragmentImpl *, const DOM::Position &);
@@ -215,8 +221,7 @@ private:
void applyInPlace(const DOM::Position &s, const DOM::Position &e);
void applyUsingFragment();
- ApplyStyleCommand::EStyle m_styleConstant;
- bool m_removingStyle;
+ DOM::CSSStyleDeclarationImpl *m_style;
};
//------------------------------------------------------------------------------------------
diff --git a/WebCore/kwq/DOM-CSS.mm b/WebCore/kwq/DOM-CSS.mm
index aa1f030..9b8f33f 100644
--- a/WebCore/kwq/DOM-CSS.mm
+++ b/WebCore/kwq/DOM-CSS.mm
@@ -757,7 +757,8 @@ static inline int getPropertyID(NSString *string)
int propid = getPropertyID(propertyName);
if (!propid)
return;
- [self _styleDeclarationImpl]->setProperty(propid, value, priority);
+ bool important = strcasecmp(DOMString(priority), "important") == 0;
+ [self _styleDeclarationImpl]->setProperty(propid, value, important);
}
- (unsigned long)length
diff --git a/WebCore/kwq/WebCoreBridge.mm b/WebCore/kwq/WebCoreBridge.mm
index 5d893d4..31c614f 100644
--- a/WebCore/kwq/WebCoreBridge.mm
+++ b/WebCore/kwq/WebCoreBridge.mm
@@ -1550,10 +1550,7 @@ static HTMLFormElementImpl *formElementFromDOMElement(DOMElement *element)
if (!_part || !_part->xmlDocImpl() || !style)
return;
- // FIXME: Temporarily hard-coded to BOLD until more styles are implemented.
- // ...or...
- // Any style you want, as long as it's BOLD. :)
- ApplyStyleCommand cmd(_part->xmlDocImpl(), ApplyStyleCommand::BOLD);
+ ApplyStyleCommand cmd(_part->xmlDocImpl(), [style _styleDeclarationImpl]);
cmd.apply();
}
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list