+2004-10-22 Ken Kocienda <kocienda@apple.com>
+
+ Reviewed by Hyatt
+
+ Fix for this bug:
+
+ <rdar://problem/3844662> REGRESSION (Mail): Style changes can affect adjacent, unselected text
+
+ * khtml/editing/htmlediting.cpp:
+ (khtml::ApplyStyleCommand::doApply): Move end position downstream to be sure we remove style from
+ everything that could be affected.
+ (khtml::ApplyStyleCommand::removeCSSStyle): Comma in intended function call was outside the
+ braces, making it act as a comma operator, with a zero value as the right value!!! This made
+ an important check always fail!!! It turns out that we do not want the constant at all, since
+ that constant is only needed when checking a computed style, not an inline style as is being
+ done here.
+ (khtml::ApplyStyleCommand::removeStyle): Call nodeFullySelected with new interface.
+ (khtml::ApplyStyleCommand::nodeFullySelected): Change interface and implementation to rely on
+ RangeImpl::compareBoundaryPoints to perform the required check.
+ * khtml/editing/htmlediting.h: Changed nodeFullySelected function interface.
+
2004-10-22 Ken Kocienda <kocienda@apple.com>
Reviewed by Hyatt
for (QPtrListIterator<CSSProperty> it(*(style()->values())); it.current(); ++it) {
CSSProperty *property = it.current();
- if (decl->getPropertyCSSValue(property->id()), DoNotUpdateLayout)
+ if (decl->getPropertyCSSValue(property->id()))
removeCSSProperty(decl, property->id());
}
void ApplyStyleCommand::removeStyle(const Position &start, const Position &end)
{
+ ASSERT(start.isNotNull());
+ ASSERT(end.isNotNull());
+ ASSERT(start.node()->inDocument());
+ ASSERT(end.node()->inDocument());
+
NodeImpl *node = start.node();
- while (1) {
+ while (node) {
NodeImpl *next = node->traverseNextNode();
- if (node->isHTMLElement() && nodeFullySelected(start, node)) {
+ if (node->isHTMLElement() && nodeFullySelected(node, start, end)) {
HTMLElementImpl *elem = static_cast<HTMLElementImpl *>(node);
if (isHTMLStyleNode(elem))
removeHTMLStyleNode(elem);
}
}
-bool ApplyStyleCommand::nodeFullySelected(const Position &start, const NodeImpl *node) const
+bool ApplyStyleCommand::nodeFullySelected(NodeImpl *node, const Position &start, const Position &end) const
{
ASSERT(node);
- if (node == start.node())
- return start.offset() >= node->caretMaxOffset();
-
- for (NodeImpl *child = node->lastChild(); child; child = child->lastChild()) {
- if (child == start.node())
- return start.offset() >= child->caretMaxOffset();
- }
-
- return !start.node()->isAncestor(node);
+ Position pos = Position(node, node->childNodeCount()).upstream();
+ return RangeImpl::compareBoundaryPoints(node, 0, start.node(), start.offset()) >= 0 &&
+ RangeImpl::compareBoundaryPoints(pos.node(), pos.offset(), end.node(), end.offset()) <= 0;
}
//------------------------------------------------------------------------------------------
void removeHTMLStyleNode(DOM::HTMLElementImpl *);
void removeCSSStyle(DOM::HTMLElementImpl *);
void removeStyle(const DOM::Position &start, const DOM::Position &end);
- bool nodeFullySelected(const DOM::Position &, const DOM::NodeImpl *node) const;
+ bool nodeFullySelected(DOM::NodeImpl *, const DOM::Position &start, const DOM::Position &end) const;
// style-application helpers
bool splitTextAtStartIfNeeded(const DOM::Position &start, const DOM::Position &end);