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)
void Editor::pasteAsPlainText(const String& pastingText, bool smartReplace)
{
Node* target = findEventTargetFromSelection();
Element* target = findEventTargetFromSelection();
if (!target)
return;
target->dispatchEvent(TextEvent::createForPlainTextPaste(m_frame.domWindow(), pastingText, smartReplace), IGNORE_EXCEPTION);
......@@ -352,7 +352,7 @@ void Editor::pasteAsPlainText(const String& pastingText, bool smartReplace)
void Editor::pasteAsFragment(PassRefPtrWillBeRawPtr<DocumentFragment> pastingFragment, bool smartReplace, bool matchStyle)
{
Node* target = findEventTargetFromSelection();
Element* target = findEventTargetFromSelection();
if (!target)
return;
target->dispatchEvent(TextEvent::createForFragmentPaste(m_frame.domWindow(), pastingFragment, smartReplace, matchStyle), IGNORE_EXCEPTION);
......@@ -457,11 +457,11 @@ static void writeImageNodeToPasteboard(Pasteboard* pasteboard, Node* node, const
// FIXME: This should probably be reconciled with HitTestResult::absoluteImageURL.
AtomicString urlString;
if (isHTMLImageElement(*node) || isHTMLInputElement(*node))
urlString = toElement(node)->getAttribute(srcAttr);
urlString = toHTMLElement(node)->getAttribute(srcAttr);
else if (isSVGImageElement(*node))
urlString = toElement(node)->getAttribute(XLinkNames::hrefAttr);
urlString = toSVGElement(node)->getAttribute(XLinkNames::hrefAttr);
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));
pasteboard->writeImage(image.get(), url, title);
......@@ -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
// 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)
return true;
......@@ -569,16 +569,16 @@ void Editor::clearLastEditCommand()
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)
target = m_frame.document()->body();
return target;
}
Node* Editor::findEventTargetFromSelection() const
Element* Editor::findEventTargetFromSelection() const
{
return findEventTargetFrom(m_frame.selection().selection());
}
......@@ -749,7 +749,7 @@ void Editor::clear()
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);
}
......
......@@ -160,7 +160,7 @@ public:
bool executeCommand(const String&);
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 insertLineBreak();
bool insertParagraphSeparator();
......@@ -199,7 +199,7 @@ public:
void pasteAsFragment(PassRefPtrWillBeRawPtr<DocumentFragment>, bool smartReplace, bool matchStyle);
void pasteAsPlainText(const String&, bool smartReplace);
Node* findEventTargetFrom(const VisibleSelection&) const;
Element* findEventTargetFrom(const VisibleSelection&) const;
bool findString(const String&, FindOptions);
// FIXME: Switch callers over to the FindOptions version and retire this one.
......@@ -269,7 +269,7 @@ private:
void changeSelectionAfterCommand(const VisibleSelection& newSelection, FrameSelection::SetSelectionOptions);
void notifyComponentsOnChangedSelection(const VisibleSelection& oldSelection, FrameSelection::SetSelectionOptions);
Node* findEventTargetFromSelection() const;
Element* findEventTargetFromSelection() const;
PassRefPtrWillBeRawPtr<Range> rangeOfString(const String&, Range*, FindOptions);
......
......@@ -200,7 +200,7 @@ static bool executeInsertFragment(LocalFrame& frame, PassRefPtrWillBeRawPtr<Docu
return true;
}
static bool executeInsertNode(LocalFrame& frame, PassRefPtrWillBeRawPtr<Node> content)
static bool executeInsertElement(LocalFrame& frame, PassRefPtrWillBeRawPtr<HTMLElement> content)
{
ASSERT(frame.document());
RefPtrWillBeRawPtr<DocumentFragment> fragment = DocumentFragment::create(*frame.document());
......@@ -271,12 +271,13 @@ static unsigned verticalScrollDistance(LocalFrame& frame)
RenderObject* renderer = focusedElement->renderer();
if (!renderer || !renderer->isBox())
return 0;
RenderStyle* style = renderer->style();
RenderBox& renderBox = toRenderBox(*renderer);
RenderStyle* style = renderBox.style();
if (!style)
return 0;
if (!(style->overflowY() == OSCROLL || style->overflowY() == OAUTO || focusedElement->hasEditableStyle()))
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));
}
......@@ -508,7 +509,7 @@ static bool executeInsertHorizontalRule(LocalFrame& frame, Event*, EditorCommand
RefPtrWillBeRawPtr<HTMLHRElement> rule = HTMLHRElement::create(*frame.document());
if (!value.isEmpty())
rule->setIdAttribute(AtomicString(value));
return executeInsertNode(frame, rule.release());
return executeInsertElement(frame, rule.release());
}
static bool executeInsertHTML(LocalFrame& frame, Event*, EditorCommandSource, const String& value)
......@@ -523,7 +524,7 @@ static bool executeInsertImage(LocalFrame& frame, Event*, EditorCommandSource, c
ASSERT(frame.document());
RefPtrWillBeRawPtr<HTMLImageElement> image = HTMLImageElement::create(*frame.document());
image->setSrc(value);
return executeInsertNode(frame, image.release());
return executeInsertElement(frame, image.release());
}
static bool executeInsertLineBreak(LocalFrame& frame, Event* event, EditorCommandSource source, const String&)
......
......@@ -438,7 +438,7 @@ bool DragController::dispatchTextInputEventFor(LocalFrame* innerFrame, DragData*
{
ASSERT(m_page->dragCaretController().hasCaret());
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);
}
......
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