[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:52:57 UTC 2009
The following commit has been merged in the debian/unstable branch:
commit 92d1f93c799c03a5c7c18d2c4c6e764a28c3ee08
Author: kocienda <kocienda at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Wed Jul 28 16:22:45 2004 +0000
Reviewed by Darin
Fix for this bug:
<rdar://problem/3681552> html editing needs to preserve typing font when replacing selection
* khtml/css/css_valueimpl.cpp:
(CSSStyleDeclarationImpl::merge): New helper that merges styles together. Helpful for
dealing with typing styles.
* khtml/css/css_valueimpl.h:
* khtml/editing/htmlediting_impl.cpp:
(khtml::DeleteSelectionCommandImpl::computeTypingStyle): New helper that updates the
typing style based on the current selection. This is a convenient bottleneck for all
the code that needs to worry about typing style.
(khtml::DeleteSelectionCommandImpl::doApply): Update typing style before doing the delete.
(khtml::InputNewlineCommandImpl::doApply): No need to redeclare exceptionCode local.
Improve comments.
(khtml::InputTextCommandImpl::prepareForTextInsertion): Remove unneeded complication when
figuring out where to insert style node. Not even sure what I was trying to do here, but
it does not seem to be needed any more.
(khtml::InputTextCommandImpl::execute): Remove unneeded comment.
* khtml/editing/htmlediting_impl.h: Declare new computeTypingStyle helper.
* khtml/khtml_part.cpp:
(KHTMLPart::setCaretVisible): Call selectionLayoutChanged instead of notifySelectionChanged
in this function. The selection did not change simply by calling this function, but it
does need a layout.
(KHTMLPart::notifySelectionChanged): Treat clearing the typing style much like closing typing,
instead of clearing it unconditionally.
(KHTMLPart::applyStyle): In the case where the current selection is a caret, merge the
style being applied with any current typing style that already exists.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@7135 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/ChangeLog-2005-08-23 b/WebCore/ChangeLog-2005-08-23
index 754fd14..8805551 100644
--- a/WebCore/ChangeLog-2005-08-23
+++ b/WebCore/ChangeLog-2005-08-23
@@ -1,3 +1,36 @@
+2004-07-28 Ken Kocienda <kocienda at apple.com>
+
+ Reviewed by Darin
+
+ Fix for this bug:
+
+ <rdar://problem/3681552> html editing needs to preserve typing font when replacing selection
+
+ * khtml/css/css_valueimpl.cpp:
+ (CSSStyleDeclarationImpl::merge): New helper that merges styles together. Helpful for
+ dealing with typing styles.
+ * khtml/css/css_valueimpl.h:
+ * khtml/editing/htmlediting_impl.cpp:
+ (khtml::DeleteSelectionCommandImpl::computeTypingStyle): New helper that updates the
+ typing style based on the current selection. This is a convenient bottleneck for all
+ the code that needs to worry about typing style.
+ (khtml::DeleteSelectionCommandImpl::doApply): Update typing style before doing the delete.
+ (khtml::InputNewlineCommandImpl::doApply): No need to redeclare exceptionCode local.
+ Improve comments.
+ (khtml::InputTextCommandImpl::prepareForTextInsertion): Remove unneeded complication when
+ figuring out where to insert style node. Not even sure what I was trying to do here, but
+ it does not seem to be needed any more.
+ (khtml::InputTextCommandImpl::execute): Remove unneeded comment.
+ * khtml/editing/htmlediting_impl.h: Declare new computeTypingStyle helper.
+ * khtml/khtml_part.cpp:
+ (KHTMLPart::setCaretVisible): Call selectionLayoutChanged instead of notifySelectionChanged
+ in this function. The selection did not change simply by calling this function, but it
+ does need a layout.
+ (KHTMLPart::notifySelectionChanged): Treat clearing the typing style much like closing typing,
+ instead of clearing it unconditionally.
+ (KHTMLPart::applyStyle): In the case where the current selection is a caret, merge the
+ style being applied with any current typing style that already exists.
+
2004-07-28 Darin Adler <darin at apple.com>
Reviewed by Ken.
diff --git a/WebCore/khtml/css/css_valueimpl.cpp b/WebCore/khtml/css/css_valueimpl.cpp
index a853687..360a569 100644
--- a/WebCore/khtml/css/css_valueimpl.cpp
+++ b/WebCore/khtml/css/css_valueimpl.cpp
@@ -407,6 +407,22 @@ bool CSSStyleDeclarationImpl::parseString( const DOMString &/*string*/, bool )
// ###
}
+void CSSStyleDeclarationImpl::merge(CSSStyleDeclarationImpl *other, bool argOverridesOnConflict)
+{
+ for (QPtrListIterator<CSSProperty> it(*(other->values())); it.current(); ++it) {
+ CSSProperty *property = it.current();
+ if (getPropertyCSSValue(property->id())) {
+ if (!argOverridesOnConflict)
+ continue;
+ removeProperty(property->id());
+ m_lstValues->append(new CSSProperty(*property));
+ }
+ else {
+ m_lstValues->append(new CSSProperty(*property));
+ }
+ }
+}
+
// --------------------------------------------------------------------------------------
CSSValueImpl::CSSValueImpl()
diff --git a/WebCore/khtml/css/css_valueimpl.h b/WebCore/khtml/css/css_valueimpl.h
index 129fa49..3f69481 100644
--- a/WebCore/khtml/css/css_valueimpl.h
+++ b/WebCore/khtml/css/css_valueimpl.h
@@ -83,6 +83,8 @@ public:
QPtrList<CSSProperty> *values() { return m_lstValues; }
void setNode(NodeImpl *_node) { m_node = _node; }
NodeImpl* node() const { return m_node; }
+
+ void merge(CSSStyleDeclarationImpl *, bool argOverridesOnConflict=true);
void setChanged();
diff --git a/WebCore/khtml/editing/htmlediting_impl.cpp b/WebCore/khtml/editing/htmlediting_impl.cpp
index 6856c3a..591a47b 100644
--- a/WebCore/khtml/editing/htmlediting_impl.cpp
+++ b/WebCore/khtml/editing/htmlediting_impl.cpp
@@ -1171,6 +1171,46 @@ bool DeleteSelectionCommandImpl::containsOnlyWhitespace(const Position &start, c
return true;
}
+CSSStyleDeclarationImpl *DeleteSelectionCommandImpl::computeTypingStyle(const Position &pos) const
+{
+ ElementImpl *element = pos.element();
+ ElementImpl *shallowElement = pos.equivalentShallowPosition().element();
+
+ ElementImpl *parent = Position(shallowElement->parentNode(), 0).element();
+ if (!parent)
+ return 0;
+
+ // Loop from the element up to the shallowElement, building up the
+ // style that this node has that its parent does not.
+ CSSStyleDeclarationImpl *result = document()->createCSSStyleDeclaration();
+ NodeImpl *node = element;
+ while (1) {
+ // check for an inline style declaration
+ if (node->isHTMLElement()) {
+ CSSStyleDeclarationImpl *s = static_cast<HTMLElementImpl *>(node)->inlineStyleDecl();
+ if (s)
+ result->merge(s, false);
+ }
+ // check if this is a bold tag
+ if (node->id() == ID_B) {
+ CSSValueImpl *boldValue = result->getPropertyCSSValue(CSS_PROP_FONT_WEIGHT);
+ if (!boldValue)
+ result->setProperty(CSS_PROP_FONT_WEIGHT, "bold");
+ }
+ // check if this is an italic tag
+ if (node->id() == ID_I) {
+ CSSValueImpl *italicValue = result->getPropertyCSSValue(CSS_PROP_FONT_STYLE);
+ if (!italicValue)
+ result->setProperty(CSS_PROP_FONT_STYLE, "italic");
+ }
+ if (node == shallowElement)
+ break;
+ node = node->parentNode();
+ }
+
+ return result;
+}
+
void DeleteSelectionCommandImpl::doApply()
{
// If selection has not been set to a custom selection when the command was created,
@@ -1289,7 +1329,16 @@ void DeleteSelectionCommandImpl::doApply()
replaceText(textNode, leading.offset(), 1, nonBreakingSpaceString());
}
}
-
+
+ //
+ // Figure out the typing style and set it on the part.
+ // This point in the code is a "bottleneck" that takes care
+ // of updating the typing style for the delete key, the return
+ // key, typed characters, and other deleting functions like the
+ // cut command.
+ //
+ document()->part()->setTypingStyle(computeTypingStyle(downstreamStart));
+
//
// Do the delete
//
@@ -1485,7 +1534,6 @@ void InputNewlineCommandImpl::doApply()
// Handle the case where there is a typing style.
if (document()->part()->typingStyle()) {
- int exceptionCode = 0;
ElementImpl *styleElement = createTypingStyleElement();
styleElement->appendChild(breakNode, exceptionCode);
ASSERT(exceptionCode == 0);
@@ -1592,6 +1640,8 @@ Position InputTextCommandImpl::prepareForTextInsertion(bool adjustDownstream)
if (!pos.node()->isTextNode()) {
NodeImpl *textNode = document()->createEditingTextNode("");
NodeImpl *nodeToInsert = textNode;
+
+ // Handle the case where there is a typing style.
if (document()->part()->typingStyle()) {
int exceptionCode = 0;
ElementImpl *styleElement = createTypingStyleElement();
@@ -1640,11 +1690,8 @@ Position InputTextCommandImpl::prepareForTextInsertion(bool adjustDownstream)
styleElement->appendChild(editingTextNode, exceptionCode);
ASSERT(exceptionCode == 0);
- NodeImpl *node = endingSelection().start().node();
- if (endingSelection().start().isLastRenderedPositionOnLine())
- insertNodeAfter(styleElement, node);
- else
- insertNodeBefore(styleElement, node);
+ NodeImpl *node = endingSelection().start().equivalentUpstreamPosition().node();
+ insertNodeAfter(styleElement, node);
pos = Position(editingTextNode, 0);
}
}
@@ -1661,8 +1708,6 @@ void InputTextCommandImpl::execute(const DOMString &text)
deleteSelection();
else
deleteCollapsibleWhitespace();
-
- // EDIT FIXME: Need to take typing style from upstream text, if any.
// Make sure the document is set up to receive text
Position pos = prepareForTextInsertion(adjustDownstream);
diff --git a/WebCore/khtml/editing/htmlediting_impl.h b/WebCore/khtml/editing/htmlediting_impl.h
index afc4966..94e4632 100644
--- a/WebCore/khtml/editing/htmlediting_impl.h
+++ b/WebCore/khtml/editing/htmlediting_impl.h
@@ -252,6 +252,7 @@ private:
void deleteDownstreamWS(const DOM::Position &start);
bool containsOnlyWhitespace(const DOM::Position &start, const DOM::Position &end);
void joinTextNodesWithSameStyle();
+ DOM::CSSStyleDeclarationImpl *computeTypingStyle(const DOM::Position &pos) const;
DOM::Selection m_selectionToDelete;
bool m_hasSelectionToDelete;
diff --git a/WebCore/khtml/khtml_part.cpp b/WebCore/khtml/khtml_part.cpp
index db89dcb..4a20ff3 100644
--- a/WebCore/khtml/khtml_part.cpp
+++ b/WebCore/khtml/khtml_part.cpp
@@ -2323,7 +2323,7 @@ void KHTMLPart::setCaretVisible(bool flag)
clearCaretRectIfNeeded();
setFocusNodeIfNeeded(d->m_selection);
d->m_caretVisible = flag;
- notifySelectionChanged();
+ selectionLayoutChanged();
}
void KHTMLPart::slotClearSelection()
@@ -2397,10 +2397,11 @@ void KHTMLPart::selectionLayoutChanged()
void KHTMLPart::notifySelectionChanged(bool closeTyping)
{
selectionLayoutChanged();
- clearTypingStyle();
- if (closeTyping)
+ if (closeTyping) {
TypingCommand::closeTyping(lastEditCommand());
+ clearTypingStyle();
+ }
emitSelectionChanged();
@@ -5278,8 +5279,10 @@ void KHTMLPart::applyStyle(CSSStyleDeclarationImpl *style)
// do nothing
break;
case Selection::CARET:
- // FIXME: This blows away all the other properties of the typing style.
- setTypingStyle(style);
+ if (typingStyle())
+ typingStyle()->merge(style);
+ else
+ setTypingStyle(style);
break;
case Selection::RANGE:
if (xmlDocImpl() && style) {
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list