Reviewed by Darin.
authorthatcher <thatcher@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 28 Oct 2006 00:41:35 +0000 (00:41 +0000)
committerthatcher <thatcher@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 28 Oct 2006 00:41:35 +0000 (00:41 +0000)
        <rdar://problem/4478625> HTML Editing: Basic table editing and culling

        Expanded the Deletion UI to lists, positioned block element and block elementss with borders.

        * editing/DeleteButtonController.cpp:
        (WebCore::isDeletableElement):
        (WebCore::enclosingDeletableElement):
        (WebCore::DeleteButtonController::respondToChangedSelection):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@17392 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/editing/DeleteButtonController.cpp

index 416448d919b1e48d09ca4fd06aa5f8e3cabf5229..bb4a3ebd953d3a3b62ca9ef647ac574c7141cf61 100644 (file)
@@ -1,3 +1,16 @@
+2006-10-27  Timothy Hatcher  <timothy@apple.com>
+
+        Reviewed by Darin.
+
+        <rdar://problem/4478625> HTML Editing: Basic table editing and culling
+
+        Expanded the Deletion UI to lists, positioned block element and block elementss with borders.
+
+        * editing/DeleteButtonController.cpp:
+        (WebCore::isDeletableElement):
+        (WebCore::enclosingDeletableElement):
+        (WebCore::DeleteButtonController::respondToChangedSelection):
+
 2006-10-27  John Sullivan  <sullivan@apple.com>
 
         Reviewed by Kevin Decker
index 6fc47e1f8cc5b4902108fad257cc9511fd582b8e..3c63fc3ebedd7f7e6556032c61f0d5faf1fa1d22 100644 (file)
@@ -60,7 +60,32 @@ DeleteButtonController::DeleteButtonController(Frame* frame)
 {
 }
 
-static HTMLElement* enclosingDeletableTable(const Selection& selection)
+static bool isDeletableElement(Node* node)
+{
+    if (!node || !node->isHTMLElement() || !node->isContentEditable())
+        return false;
+
+    RenderObject* renderer = node->renderer();
+    if (!renderer || renderer->width() < 25 || renderer->height() < 25)
+        return false;
+
+    if (node->hasTagName(tableTag) || node->hasTagName(ulTag) || node->hasTagName(olTag))
+        return true;
+
+    if (renderer->isRenderBlock()) {
+        RenderStyle* style = renderer->style();
+        if (!style)
+            return false;
+        if (style->position() == AbsolutePosition || style->position() == FixedPosition)
+            return true;
+        if (style->border().hasBorder())
+            return true;
+    }
+
+    return false;
+}
+
+static HTMLElement* enclosingDeletableElement(const Selection& selection)
 {
     if (!selection.isContentEditable())
         return 0;
@@ -74,33 +99,29 @@ static HTMLElement* enclosingDeletableTable(const Selection& selection)
     ASSERT(container);
     ASSERT(ec == 0);
 
-    // The enclosingNodeWithTag function only works on nodes that are editable
+    // The enclosingNodeOfType function only works on nodes that are editable
     // (which is strange, given its name).
     if (!container->isContentEditable())
         return 0;
 
-    Node* table = enclosingNodeWithTag(container, tableTag);
-    if (!table)
-        return 0;
-
-    // The table must be editable too.
-    if (!table->isContentEditable())
+    Node* element = enclosingNodeOfType(container, &isDeletableElement);
+    if (!element)
         return 0;
 
-    ASSERT(table->isHTMLElement());
-    return static_cast<HTMLElement*>(table);
+    ASSERT(element->isHTMLElement());
+    return static_cast<HTMLElement*>(element);
 }
 
 void DeleteButtonController::respondToChangedSelection(const Selection& oldSelection)
 {
-    HTMLElement* oldTable = enclosingDeletableTable(oldSelection);
-    HTMLElement* newTable = enclosingDeletableTable(m_frame->selectionController()->selection());
-    if (oldTable == newTable)
+    HTMLElement* oldElement = enclosingDeletableElement(oldSelection);
+    HTMLElement* newElement = enclosingDeletableElement(m_frame->selectionController()->selection());
+    if (oldElement == newElement)
         return;
 
-    // If the base is inside an editable table, give the table a close widget.
-    if (newTable)
-        show(newTable);
+    // If the base is inside a deletable element, give the element a delete widget.
+    if (newElement)
+        show(newElement);
     else
         hide();
 }