Commit 07c9a14b authored by ch.dumez@samsung.com's avatar ch.dumez@samsung.com

Use tighter typing in editing: Editor / EditorCommand

Use tighter typing in editing to increase code readability. This CL focuses on
Editor and EditorCommand.

R=leviw@chromium.org

Review URL: https://codereview.chromium.org/426433002

git-svn-id: svn://svn.chromium.org/blink/trunk@178988 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 1bbe534b
...@@ -344,7 +344,7 @@ void Editor::deleteSelectionWithSmartDelete(bool smartDelete) ...@@ -344,7 +344,7 @@ void Editor::deleteSelectionWithSmartDelete(bool smartDelete)
void Editor::pasteAsPlainText(const String& pastingText, bool smartReplace) void Editor::pasteAsPlainText(const String& pastingText, bool smartReplace)
{ {
Node* target = findEventTargetFromSelection(); Element* target = findEventTargetFromSelection();
if (!target) if (!target)
return; return;
target->dispatchEvent(TextEvent::createForPlainTextPaste(m_frame.domWindow(), pastingText, smartReplace), IGNORE_EXCEPTION); target->dispatchEvent(TextEvent::createForPlainTextPaste(m_frame.domWindow(), pastingText, smartReplace), IGNORE_EXCEPTION);
...@@ -352,7 +352,7 @@ void Editor::pasteAsPlainText(const String& pastingText, bool smartReplace) ...@@ -352,7 +352,7 @@ void Editor::pasteAsPlainText(const String& pastingText, bool smartReplace)
void Editor::pasteAsFragment(PassRefPtrWillBeRawPtr<DocumentFragment> pastingFragment, bool smartReplace, bool matchStyle) void Editor::pasteAsFragment(PassRefPtrWillBeRawPtr<DocumentFragment> pastingFragment, bool smartReplace, bool matchStyle)
{ {
Node* target = findEventTargetFromSelection(); Element* target = findEventTargetFromSelection();
if (!target) if (!target)
return; return;
target->dispatchEvent(TextEvent::createForFragmentPaste(m_frame.domWindow(), pastingFragment, smartReplace, matchStyle), IGNORE_EXCEPTION); target->dispatchEvent(TextEvent::createForFragmentPaste(m_frame.domWindow(), pastingFragment, smartReplace, matchStyle), IGNORE_EXCEPTION);
...@@ -457,11 +457,11 @@ static void writeImageNodeToPasteboard(Pasteboard* pasteboard, Node* node, const ...@@ -457,11 +457,11 @@ static void writeImageNodeToPasteboard(Pasteboard* pasteboard, Node* node, const
// FIXME: This should probably be reconciled with HitTestResult::absoluteImageURL. // FIXME: This should probably be reconciled with HitTestResult::absoluteImageURL.
AtomicString urlString; AtomicString urlString;
if (isHTMLImageElement(*node) || isHTMLInputElement(*node)) if (isHTMLImageElement(*node) || isHTMLInputElement(*node))
urlString = toElement(node)->getAttribute(srcAttr); urlString = toHTMLElement(node)->getAttribute(srcAttr);
else if (isSVGImageElement(*node)) else if (isSVGImageElement(*node))
urlString = toElement(node)->getAttribute(XLinkNames::hrefAttr); urlString = toSVGElement(node)->getAttribute(XLinkNames::hrefAttr);
else if (isHTMLEmbedElement(*node) || isHTMLObjectElement(*node) || isHTMLCanvasElement(*node)) else if (isHTMLEmbedElement(*node) || isHTMLObjectElement(*node) || isHTMLCanvasElement(*node))
urlString = toElement(node)->imageSourceURL(); urlString = toHTMLElement(node)->imageSourceURL();
KURL url = urlString.isEmpty() ? KURL() : node->document().completeURL(stripLeadingAndTrailingHTMLSpaces(urlString)); KURL url = urlString.isEmpty() ? KURL() : node->document().completeURL(stripLeadingAndTrailingHTMLSpaces(urlString));
pasteboard->writeImage(image.get(), url, title); pasteboard->writeImage(image.get(), url, title);
...@@ -469,9 +469,9 @@ static void writeImageNodeToPasteboard(Pasteboard* pasteboard, Node* node, const ...@@ -469,9 +469,9 @@ static void writeImageNodeToPasteboard(Pasteboard* pasteboard, Node* node, const
// Returns whether caller should continue with "the default processing", which is the same as // Returns whether caller should continue with "the default processing", which is the same as
// the event handler NOT setting the return value to false // the event handler NOT setting the return value to false
bool Editor::dispatchCPPEvent(const AtomicString &eventType, DataTransferAccessPolicy policy, PasteMode pasteMode) bool Editor::dispatchCPPEvent(const AtomicString& eventType, DataTransferAccessPolicy policy, PasteMode pasteMode)
{ {
Node* target = findEventTargetFromSelection(); Element* target = findEventTargetFromSelection();
if (!target) if (!target)
return true; return true;
...@@ -569,16 +569,16 @@ void Editor::clearLastEditCommand() ...@@ -569,16 +569,16 @@ void Editor::clearLastEditCommand()
m_lastEditCommand.clear(); m_lastEditCommand.clear();
} }
Node* Editor::findEventTargetFrom(const VisibleSelection& selection) const Element* Editor::findEventTargetFrom(const VisibleSelection& selection) const
{ {
Node* target = selection.start().element(); Element* target = selection.start().element();
if (!target) if (!target)
target = m_frame.document()->body(); target = m_frame.document()->body();
return target; return target;
} }
Node* Editor::findEventTargetFromSelection() const Element* Editor::findEventTargetFromSelection() const
{ {
return findEventTargetFrom(m_frame.selection().selection()); return findEventTargetFrom(m_frame.selection().selection());
} }
...@@ -749,7 +749,7 @@ void Editor::clear() ...@@ -749,7 +749,7 @@ void Editor::clear()
m_defaultParagraphSeparator = EditorParagraphSeparatorIsDiv; m_defaultParagraphSeparator = EditorParagraphSeparatorIsDiv;
} }
bool Editor::insertText(const String& text, Event* triggeringEvent) bool Editor::insertText(const String& text, KeyboardEvent* triggeringEvent)
{ {
return m_frame.eventHandler().handleTextInputEvent(text, triggeringEvent); return m_frame.eventHandler().handleTextInputEvent(text, triggeringEvent);
} }
......
...@@ -160,7 +160,7 @@ public: ...@@ -160,7 +160,7 @@ public:
bool executeCommand(const String&); bool executeCommand(const String&);
bool executeCommand(const String& commandName, const String& value); bool executeCommand(const String& commandName, const String& value);
bool insertText(const String&, Event* triggeringEvent); bool insertText(const String&, KeyboardEvent* triggeringEvent);
bool insertTextWithoutSendingTextEvent(const String&, bool selectInsertedText, TextEvent* triggeringEvent); bool insertTextWithoutSendingTextEvent(const String&, bool selectInsertedText, TextEvent* triggeringEvent);
bool insertLineBreak(); bool insertLineBreak();
bool insertParagraphSeparator(); bool insertParagraphSeparator();
...@@ -199,7 +199,7 @@ public: ...@@ -199,7 +199,7 @@ public:
void pasteAsFragment(PassRefPtrWillBeRawPtr<DocumentFragment>, bool smartReplace, bool matchStyle); void pasteAsFragment(PassRefPtrWillBeRawPtr<DocumentFragment>, bool smartReplace, bool matchStyle);
void pasteAsPlainText(const String&, bool smartReplace); void pasteAsPlainText(const String&, bool smartReplace);
Node* findEventTargetFrom(const VisibleSelection&) const; Element* findEventTargetFrom(const VisibleSelection&) const;
bool findString(const String&, FindOptions); bool findString(const String&, FindOptions);
// FIXME: Switch callers over to the FindOptions version and retire this one. // FIXME: Switch callers over to the FindOptions version and retire this one.
...@@ -269,7 +269,7 @@ private: ...@@ -269,7 +269,7 @@ private:
void changeSelectionAfterCommand(const VisibleSelection& newSelection, FrameSelection::SetSelectionOptions); void changeSelectionAfterCommand(const VisibleSelection& newSelection, FrameSelection::SetSelectionOptions);
void notifyComponentsOnChangedSelection(const VisibleSelection& oldSelection, FrameSelection::SetSelectionOptions); void notifyComponentsOnChangedSelection(const VisibleSelection& oldSelection, FrameSelection::SetSelectionOptions);
Node* findEventTargetFromSelection() const; Element* findEventTargetFromSelection() const;
PassRefPtrWillBeRawPtr<Range> rangeOfString(const String&, Range*, FindOptions); PassRefPtrWillBeRawPtr<Range> rangeOfString(const String&, Range*, FindOptions);
......
...@@ -200,7 +200,7 @@ static bool executeInsertFragment(LocalFrame& frame, PassRefPtrWillBeRawPtr<Docu ...@@ -200,7 +200,7 @@ static bool executeInsertFragment(LocalFrame& frame, PassRefPtrWillBeRawPtr<Docu
return true; return true;
} }
static bool executeInsertNode(LocalFrame& frame, PassRefPtrWillBeRawPtr<Node> content) static bool executeInsertElement(LocalFrame& frame, PassRefPtrWillBeRawPtr<HTMLElement> content)
{ {
ASSERT(frame.document()); ASSERT(frame.document());
RefPtrWillBeRawPtr<DocumentFragment> fragment = DocumentFragment::create(*frame.document()); RefPtrWillBeRawPtr<DocumentFragment> fragment = DocumentFragment::create(*frame.document());
...@@ -271,12 +271,13 @@ static unsigned verticalScrollDistance(LocalFrame& frame) ...@@ -271,12 +271,13 @@ static unsigned verticalScrollDistance(LocalFrame& frame)
RenderObject* renderer = focusedElement->renderer(); RenderObject* renderer = focusedElement->renderer();
if (!renderer || !renderer->isBox()) if (!renderer || !renderer->isBox())
return 0; return 0;
RenderStyle* style = renderer->style(); RenderBox& renderBox = toRenderBox(*renderer);
RenderStyle* style = renderBox.style();
if (!style) if (!style)
return 0; return 0;
if (!(style->overflowY() == OSCROLL || style->overflowY() == OAUTO || focusedElement->hasEditableStyle())) if (!(style->overflowY() == OSCROLL || style->overflowY() == OAUTO || focusedElement->hasEditableStyle()))
return 0; return 0;
int height = std::min<int>(toRenderBox(renderer)->clientHeight(), frame.view()->visibleHeight()); int height = std::min<int>(renderBox.clientHeight(), frame.view()->visibleHeight());
return static_cast<unsigned>(max(max<int>(height * ScrollableArea::minFractionToStepWhenPaging(), height - ScrollableArea::maxOverlapBetweenPages()), 1)); return static_cast<unsigned>(max(max<int>(height * ScrollableArea::minFractionToStepWhenPaging(), height - ScrollableArea::maxOverlapBetweenPages()), 1));
} }
...@@ -508,7 +509,7 @@ static bool executeInsertHorizontalRule(LocalFrame& frame, Event*, EditorCommand ...@@ -508,7 +509,7 @@ static bool executeInsertHorizontalRule(LocalFrame& frame, Event*, EditorCommand
RefPtrWillBeRawPtr<HTMLHRElement> rule = HTMLHRElement::create(*frame.document()); RefPtrWillBeRawPtr<HTMLHRElement> rule = HTMLHRElement::create(*frame.document());
if (!value.isEmpty()) if (!value.isEmpty())
rule->setIdAttribute(AtomicString(value)); rule->setIdAttribute(AtomicString(value));
return executeInsertNode(frame, rule.release()); return executeInsertElement(frame, rule.release());
} }
static bool executeInsertHTML(LocalFrame& frame, Event*, EditorCommandSource, const String& value) static bool executeInsertHTML(LocalFrame& frame, Event*, EditorCommandSource, const String& value)
...@@ -523,7 +524,7 @@ static bool executeInsertImage(LocalFrame& frame, Event*, EditorCommandSource, c ...@@ -523,7 +524,7 @@ static bool executeInsertImage(LocalFrame& frame, Event*, EditorCommandSource, c
ASSERT(frame.document()); ASSERT(frame.document());
RefPtrWillBeRawPtr<HTMLImageElement> image = HTMLImageElement::create(*frame.document()); RefPtrWillBeRawPtr<HTMLImageElement> image = HTMLImageElement::create(*frame.document());
image->setSrc(value); image->setSrc(value);
return executeInsertNode(frame, image.release()); return executeInsertElement(frame, image.release());
} }
static bool executeInsertLineBreak(LocalFrame& frame, Event* event, EditorCommandSource source, const String&) static bool executeInsertLineBreak(LocalFrame& frame, Event* event, EditorCommandSource source, const String&)
......
...@@ -438,7 +438,7 @@ bool DragController::dispatchTextInputEventFor(LocalFrame* innerFrame, DragData* ...@@ -438,7 +438,7 @@ bool DragController::dispatchTextInputEventFor(LocalFrame* innerFrame, DragData*
{ {
ASSERT(m_page->dragCaretController().hasCaret()); ASSERT(m_page->dragCaretController().hasCaret());
String text = m_page->dragCaretController().isContentRichlyEditable() ? "" : dragData->asPlainText(); String text = m_page->dragCaretController().isContentRichlyEditable() ? "" : dragData->asPlainText();
Node* target = innerFrame->editor().findEventTargetFrom(VisibleSelection(m_page->dragCaretController().caretPosition())); Element* target = innerFrame->editor().findEventTargetFrom(VisibleSelection(m_page->dragCaretController().caretPosition()));
return target->dispatchEvent(TextEvent::createForDrop(innerFrame->domWindow(), text), IGNORE_EXCEPTION); return target->dispatchEvent(TextEvent::createForDrop(innerFrame->domWindow(), text), IGNORE_EXCEPTION);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment