LayoutTests:
[WebKit-https.git] / WebCore / editing / Editor.cpp
index 1d6067918039f82442268125b98bd13da7da6312..d13a58963cfdb8f139ea10760b41acc3fc7b0a77 100644 (file)
 #include "config.h"
 #include "Editor.h"
 
+#include "DeleteButtonController.h"
 #include "EditorClient.h"
-#include "Frame.h"
+#include "htmlediting.h"
 #include "HTMLElement.h"
+#include "HTMLNames.h"
 #include "Range.h"
+#include "SelectionController.h"
 #include "Sound.h"
 
 namespace WebCore {
 
+using namespace HTMLNames;
+
 // implement as platform-specific
-Pasteboard generalPasteboard()
+static Pasteboard generalPasteboard()
 {
     return 0;
 }
 
 bool Editor::canCopy()
-{ return false; }
+{
+    return false;
+}
 
 bool Editor::canCut()
-{ return false; }
+{
+    return false;
+}
 
 bool Editor::canDelete()
-{ return false; }
+{
+    return false;
+}
 
 bool Editor::canDeleteRange(Range* range)
 {
     ExceptionCode ec = 0;
-    Node *startContainer = range->startContainer(ec);
-    Node *endContainer = range->endContainer(ec);
+    NodestartContainer = range->startContainer(ec);
+    NodeendContainer = range->endContainer(ec);
     if (!startContainer || !endContainer)
         return false;
     
@@ -71,28 +82,40 @@ bool Editor::canDeleteRange(Range* range)
 }
 
 bool Editor::canPaste()
-{ return false; }
+{
+    return false;
+}
 
 bool Editor::canSmartCopyOrDelete()
-{ return false; }
+{
+    return false;
+}
 
 void Editor::deleteSelection()
-{}
+{
+}
 
 void Editor::deleteSelectionWithSmartDelete(bool enabled)
-{}
+{
+}
 
 bool Editor::isSelectionRichlyEditable()
-{ return false; }
+{
+    return false;
+}
 
 void Editor::pasteAsPlainTextWithPasteboard(Pasteboard pasteboard)
-{}
+{
+}
 
 void Editor::pasteWithPasteboard(Pasteboard pasteboard, bool allowPlainText)
-{}
+{
+}
 
 Range* Editor::selectedRange()
-{ return NULL; }
+{
+    return 0;
+}
 
 bool Editor::shouldDeleteRange(Range* range)
 {
@@ -125,23 +148,66 @@ bool Editor::tryDHTMLPaste()
 }
 
 void Editor::writeSelectionToPasteboard(Pasteboard pasteboard)
-{}
+{
+}
 
 bool Editor::shouldShowDeleteInterface(HTMLElement* element)
 {
     return m_client->shouldShowDeleteInterface(element);
 }
 
+void Editor::respondToChangedSelection(const Selection& oldSelection)
+{
+    m_deleteButtonController->respondToChangedSelection(oldSelection);
+}
+
+void Editor::respondToChangedContents()
+{
+    m_deleteButtonController->respondToChangedContents();
+}
+
+Frame::TriState Editor::selectionUnorderedListState() const
+{
+    if (m_frame->selectionController()->isCaret()) {
+        Node* selectionNode = m_frame->selectionController()->selection().start().node();
+        if (enclosingNodeWithTag(selectionNode, ulTag))
+            return Frame::trueTriState;
+    } else if (m_frame->selectionController()->isRange()) {
+        Node* startNode = enclosingNodeWithTag(m_frame->selectionController()->selection().start().node(), ulTag);
+        Node* endNode = enclosingNodeWithTag(m_frame->selectionController()->selection().end().node(), ulTag);
+        if (startNode && endNode && startNode == endNode)
+            return Frame::trueTriState;
+    }
+
+    return Frame::falseTriState;
+}
+
+Frame::TriState Editor::selectionOrderedListState() const
+{
+    if (m_frame->selectionController()->isCaret()) {
+        Node* selectionNode = m_frame->selectionController()->selection().start().node();
+        if (enclosingNodeWithTag(selectionNode, olTag))
+            return Frame::trueTriState;
+    } else if (m_frame->selectionController()->isRange()) {
+        Node* startNode = enclosingNodeWithTag(m_frame->selectionController()->selection().start().node(), olTag);
+        Node* endNode = enclosingNodeWithTag(m_frame->selectionController()->selection().end().node(), olTag);
+        if (startNode && endNode && startNode == endNode)
+            return Frame::trueTriState;
+    }
+
+    return Frame::falseTriState;
+}
+
 // =============================================================================
 //
 // public editing commands
 //
 // =============================================================================
 
-Editor::Editor(Frame* frame, EditorClient* client)
+Editor::Editor(Frame* frame, PassRefPtr<EditorClient> client)
     : m_frame(frame)
     , m_client(client)
-    , m_deleteButtonController(this)
+    , m_deleteButtonController(new DeleteButtonController(frame))
 { 
 }
 
@@ -166,7 +232,6 @@ void Editor::cut()
 
 void Editor::copy()
 {
-
     if (tryDHTMLCopy())
         return; // DHTML did the whole operation
     if (!canCopy()) {