Commit adad191b authored by Hugo Holgersson's avatar Hugo Holgersson Committed by Commit Bot

For readability, refactor some of blink::Editor's methods

This patch does not change any web facing logic.
Only private methods are changed, the public API is untouched.

Renamed methods:
  DispatchCPPEvent -> DispatchClipboardEvent
  TryDHTMLCopy     -> DispatchCopyEvent
  TryDHTMLCut      -> DispatchCutEvent
  TryDHTMLPaste    -> DispatchPasteEvent

These methods now return false upon preventDefault() from JavaScript.
Before this change, only the first method followed this convention.

Bug: 755459
Change-Id: I2b9dd77b0c0cd6a2ad29136e1ec2f9dec7d37622
Reviewed-on: https://chromium-review.googlesource.com/810806Reviewed-by: default avatarXiaocheng Hu <xiaochengh@chromium.org>
Commit-Queue: Hugo Holgersson <hugoh@vewd.com>
Cr-Commit-Position: refs/heads/master@{#523810}
parent e7015d5a
...@@ -250,7 +250,7 @@ bool Editor::HandleTextEvent(TextEvent* event) { ...@@ -250,7 +250,7 @@ bool Editor::HandleTextEvent(TextEvent* event) {
if (event->IsIncrementalInsertion()) if (event->IsIncrementalInsertion())
return false; return false;
// TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets // TODO(editing-dev): The use of UpdateStyleAndLayoutIgnorePendingStylesheets
// needs to be audited. See http://crbug.com/590369 for more details. // needs to be audited. See http://crbug.com/590369 for more details.
frame_->GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets(); frame_->GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets();
...@@ -310,25 +310,25 @@ bool Editor::CanEditRichly() const { ...@@ -310,25 +310,25 @@ bool Editor::CanEditRichly() const {
// copy/paste (like divs, or a document body). // copy/paste (like divs, or a document body).
bool Editor::CanDHTMLCut() { bool Editor::CanDHTMLCut() {
// TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets // TODO(editing-dev): The use of UpdateStyleAndLayoutIgnorePendingStylesheets
// needs to be audited. See http://crbug.com/590369 for more details. // needs to be audited. See http://crbug.com/590369 for more details.
GetFrame().GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets(); GetFrame().GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets();
return !IsInPasswordField(GetFrame() return !IsInPasswordField(GetFrame()
.Selection() .Selection()
.ComputeVisibleSelectionInDOMTree() .ComputeVisibleSelectionInDOMTree()
.Start()) && .Start()) &&
!DispatchCPPEvent(EventTypeNames::beforecut, kDataTransferNumb); !DispatchClipboardEvent(EventTypeNames::beforecut, kDataTransferNumb);
} }
bool Editor::CanDHTMLCopy() { bool Editor::CanDHTMLCopy() {
// TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets // TODO(editing-dev): The use of UpdateStyleAndLayoutIgnorePendingStylesheets
// needs to be audited. See http://crbug.com/590369 for more details. // needs to be audited. See http://crbug.com/590369 for more details.
GetFrame().GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets(); GetFrame().GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets();
return !IsInPasswordField(GetFrame() return !IsInPasswordField(GetFrame()
.Selection() .Selection()
.ComputeVisibleSelectionInDOMTree() .ComputeVisibleSelectionInDOMTree()
.Start()) && .Start()) &&
!DispatchCPPEvent(EventTypeNames::beforecopy, kDataTransferNumb); !DispatchClipboardEvent(EventTypeNames::beforecopy, kDataTransferNumb);
} }
bool Editor::CanCut() const { bool Editor::CanCut() const {
...@@ -484,30 +484,30 @@ void Editor::PasteAsFragment(DocumentFragment* pasting_fragment, ...@@ -484,30 +484,30 @@ void Editor::PasteAsFragment(DocumentFragment* pasting_fragment,
GetFrame().DomWindow(), pasting_fragment, smart_replace, match_style)); GetFrame().DomWindow(), pasting_fragment, smart_replace, match_style));
} }
bool Editor::TryDHTMLCopy() { bool Editor::DispatchCopyEvent() {
// TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets // TODO(editing-dev): The use of UpdateStyleAndLayoutIgnorePendingStylesheets
// needs to be audited. See http://crbug.com/590369 for more details. // needs to be audited. See http://crbug.com/590369 for more details.
GetFrame().GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets(); GetFrame().GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets();
if (IsInPasswordField( if (IsInPasswordField(
GetFrameSelection().ComputeVisibleSelectionInDOMTree().Start())) GetFrameSelection().ComputeVisibleSelectionInDOMTree().Start()))
return false; return true;
return !DispatchCPPEvent(EventTypeNames::copy, kDataTransferWritable); return DispatchClipboardEvent(EventTypeNames::copy, kDataTransferWritable);
} }
bool Editor::TryDHTMLCut() { bool Editor::DispatchCutEvent() {
// TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets // TODO(editing-dev): The use of UpdateStyleAndLayoutIgnorePendingStylesheets
// needs to be audited. See http://crbug.com/590369 for more details. // needs to be audited. See http://crbug.com/590369 for more details.
GetFrame().GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets(); GetFrame().GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets();
if (IsInPasswordField( if (IsInPasswordField(
GetFrameSelection().ComputeVisibleSelectionInDOMTree().Start())) GetFrameSelection().ComputeVisibleSelectionInDOMTree().Start()))
return false; return true;
return !DispatchCPPEvent(EventTypeNames::cut, kDataTransferWritable); return DispatchClipboardEvent(EventTypeNames::cut, kDataTransferWritable);
} }
bool Editor::TryDHTMLPaste(PasteMode paste_mode) { bool Editor::DispatchPasteEvent(PasteMode paste_mode) {
return !DispatchCPPEvent(EventTypeNames::paste, kDataTransferReadable, return DispatchClipboardEvent(EventTypeNames::paste, kDataTransferReadable,
paste_mode); paste_mode);
} }
...@@ -538,9 +538,9 @@ void Editor::PasteWithPasteboard(Pasteboard* pasteboard) { ...@@ -538,9 +538,9 @@ void Editor::PasteWithPasteboard(Pasteboard* pasteboard) {
if (!text.IsEmpty()) { if (!text.IsEmpty()) {
chose_plain_text = true; chose_plain_text = true;
// TODO(editing-dev): Use of updateStyleAndLayoutIgnorePendingStylesheets // TODO(editing-dev): Use of UpdateStyleAndLayoutIgnorePendingStylesheets
// needs to be audited. See http://crbug.com/590369 for more details. // needs to be audited. See http://crbug.com/590369 for more details.
// |selectedRange| requires clean layout for visible selection // |SelectedRange| requires clean layout for visible selection
// normalization. // normalization.
GetFrame().GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets(); GetFrame().GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets();
...@@ -618,9 +618,7 @@ static void WriteImageNodeToPasteboard(Pasteboard* pasteboard, ...@@ -618,9 +618,7 @@ static void WriteImageNodeToPasteboard(Pasteboard* pasteboard,
pasteboard->WriteImage(image.get(), url, title); pasteboard->WriteImage(image.get(), url, title);
} }
// Returns whether caller should continue with "the default processing", which bool Editor::DispatchClipboardEvent(const AtomicString& event_type,
// is the same as the event handler NOT setting the return value to false
bool Editor::DispatchCPPEvent(const AtomicString& event_type,
DataTransferAccessPolicy policy, DataTransferAccessPolicy policy,
PasteMode paste_mode) { PasteMode paste_mode) {
Element* target = FindEventTargetFromSelection(); Element* target = FindEventTargetFromSelection();
...@@ -640,7 +638,7 @@ bool Editor::DispatchCPPEvent(const AtomicString& event_type, ...@@ -640,7 +638,7 @@ bool Editor::DispatchCPPEvent(const AtomicString& event_type,
Pasteboard::GeneralPasteboard()->WriteDataObject( Pasteboard::GeneralPasteboard()->WriteDataObject(
data_transfer->GetDataObject()); data_transfer->GetDataObject());
// invalidate clipboard here for security // Invalidate clipboard here for security.
data_transfer->SetAccessPolicy(kDataTransferNumb); data_transfer->SetAccessPolicy(kDataTransferNumb);
return !no_default_processing; return !no_default_processing;
...@@ -1126,15 +1124,15 @@ bool Editor::InsertParagraphSeparator() { ...@@ -1126,15 +1124,15 @@ bool Editor::InsertParagraphSeparator() {
} }
void Editor::Cut(EditorCommandSource source) { void Editor::Cut(EditorCommandSource source) {
if (TryDHTMLCut()) if (!DispatchCutEvent())
return; // DHTML did the whole operation return;
if (!CanCut()) if (!CanCut())
return; return;
// TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets // TODO(editing-dev): The use of UpdateStyleAndLayoutIgnorePendingStylesheets
// needs to be audited. See http://crbug.com/590369 for more details. // needs to be audited. See http://crbug.com/590369 for more details.
// |tryDHTMLCut| dispatches cut event, which may make layout dirty, but we // A 'cut' event handler might have dirtied the layout so we need to update
// need clean layout to obtain the selected content. // before we obtain the selection.
GetFrame().GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets(); GetFrame().GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets();
if (source == kCommandFromMenuOrKeyBinding && if (source == kCommandFromMenuOrKeyBinding &&
...@@ -1172,15 +1170,15 @@ void Editor::Cut(EditorCommandSource source) { ...@@ -1172,15 +1170,15 @@ void Editor::Cut(EditorCommandSource source) {
} }
void Editor::Copy(EditorCommandSource) { void Editor::Copy(EditorCommandSource) {
if (TryDHTMLCopy()) if (!DispatchCopyEvent())
return; // DHTML did the whole operation return;
if (!CanCopy()) if (!CanCopy())
return; return;
// TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets // TODO(editing-dev): The use of UpdateStyleAndLayoutIgnorePendingStylesheets
// needs to be audited. See http://crbug.com/590369 for more details. // needs to be audited. See http://crbug.com/590369 for more details.
// |tryDHTMLCopy| dispatches copy event, which may make layout dirty, but // A 'copy' event handler might have dirtied the layout so we need to update
// we need clean layout to obtain the selected content. // before we obtain the selection.
GetFrame().GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets(); GetFrame().GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets();
if (EnclosingTextControl( if (EnclosingTextControl(
...@@ -1202,15 +1200,15 @@ void Editor::Copy(EditorCommandSource) { ...@@ -1202,15 +1200,15 @@ void Editor::Copy(EditorCommandSource) {
void Editor::Paste(EditorCommandSource source) { void Editor::Paste(EditorCommandSource source) {
DCHECK(GetFrame().GetDocument()); DCHECK(GetFrame().GetDocument());
if (TryDHTMLPaste(kAllMimeTypes)) if (!DispatchPasteEvent(kAllMimeTypes))
return; // DHTML did the whole operation return;
if (!CanPaste()) if (!CanPaste())
return; return;
// TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets // TODO(editing-dev): The use of UpdateStyleAndLayoutIgnorePendingStylesheets
// needs to be audited. See http://crbug.com/590369 for more details. // needs to be audited. See http://crbug.com/590369 for more details.
// |tryDHTMLPaste| dispatches copy event, which may make layout dirty, but // A 'paste' event handler might have dirtied the layout so we need to update
// we need clean layout to obtain the selected content. // before we obtain the selection.
GetFrame().GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets(); GetFrame().GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets();
if (source == kCommandFromMenuOrKeyBinding && if (source == kCommandFromMenuOrKeyBinding &&
...@@ -1244,15 +1242,15 @@ void Editor::Paste(EditorCommandSource source) { ...@@ -1244,15 +1242,15 @@ void Editor::Paste(EditorCommandSource source) {
} }
void Editor::PasteAsPlainText(EditorCommandSource source) { void Editor::PasteAsPlainText(EditorCommandSource source) {
if (TryDHTMLPaste(kPlainTextOnly)) if (!DispatchPasteEvent(kPlainTextOnly))
return; return;
if (!CanPaste()) if (!CanPaste())
return; return;
// TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets // TODO(editing-dev): The use of UpdateStyleAndLayoutIgnorePendingStylesheets
// needs to be audited. See http://crbug.com/590369 for more details. // needs to be audited. See http://crbug.com/590369 for more details.
// |tryDHTMLPaste| dispatches copy event, which may make layout dirty, but // A 'paste' event handler might have dirtied the layout so we need to update
// we need clean layout to obtain the selected content. // before we obtain the selection.
GetFrame().GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets(); GetFrame().GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets();
if (source == kCommandFromMenuOrKeyBinding && if (source == kCommandFromMenuOrKeyBinding &&
...@@ -1266,9 +1264,9 @@ void Editor::PerformDelete() { ...@@ -1266,9 +1264,9 @@ void Editor::PerformDelete() {
if (!CanDelete()) if (!CanDelete())
return; return;
// TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets // TODO(editing-dev): The use of UpdateStyleAndLayoutIgnorePendingStylesheets
// needs to be audited. See http://crbug.com/590369 for more details. // needs to be audited. See http://crbug.com/590369 for more details.
// |selectedRange| requires clean layout for visible selection normalization. // |SelectedRange| requires clean layout for visible selection normalization.
GetFrame().GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets(); GetFrame().GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets();
AddToKillRing(SelectedRange()); AddToKillRing(SelectedRange());
...@@ -1416,8 +1414,8 @@ void Transpose(LocalFrame& frame) { ...@@ -1416,8 +1414,8 @@ void Transpose(LocalFrame& frame) {
Document* const document = frame.GetDocument(); Document* const document = frame.GetDocument();
// TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets // TODO(editing-dev): The use of UpdateStyleAndLayoutIgnorePendingStylesheets
// needs to be audited. see http://crbug.com/590369 for more details. // needs to be audited. See http://crbug.com/590369 for more details.
document->UpdateStyleAndLayoutIgnorePendingStylesheets(); document->UpdateStyleAndLayoutIgnorePendingStylesheets();
const EphemeralRange& range = ComputeRangeForTranspose(frame); const EphemeralRange& range = ComputeRangeForTranspose(frame);
...@@ -1441,8 +1439,8 @@ void Transpose(LocalFrame& frame) { ...@@ -1441,8 +1439,8 @@ void Transpose(LocalFrame& frame) {
if (frame.GetDocument() != document) if (frame.GetDocument() != document)
return; return;
// TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets // TODO(editing-dev): The use of UpdateStyleAndLayoutIgnorePendingStylesheets
// needs to be audited. see http://crbug.com/590369 for more details. // needs to be audited. See http://crbug.com/590369 for more details.
document->UpdateStyleAndLayoutIgnorePendingStylesheets(); document->UpdateStyleAndLayoutIgnorePendingStylesheets();
// 'beforeinput' event handler may change selection, we need to re-calculate // 'beforeinput' event handler may change selection, we need to re-calculate
......
...@@ -339,17 +339,18 @@ class CORE_EXPORT Editor final : public GarbageCollectedFinalized<Editor> { ...@@ -339,17 +339,18 @@ class CORE_EXPORT Editor final : public GarbageCollectedFinalized<Editor> {
bool CanDeleteRange(const EphemeralRange&) const; bool CanDeleteRange(const EphemeralRange&) const;
bool TryDHTMLCopy(); // Returns true if Editor should continue with default processing.
bool TryDHTMLCut(); bool DispatchCopyEvent();
bool TryDHTMLPaste(PasteMode); bool DispatchCutEvent();
bool DispatchPasteEvent(PasteMode);
bool DispatchClipboardEvent(const AtomicString&,
DataTransferAccessPolicy,
PasteMode = kAllMimeTypes);
bool CanSmartReplaceWithPasteboard(Pasteboard*); bool CanSmartReplaceWithPasteboard(Pasteboard*);
void PasteAsPlainTextWithPasteboard(Pasteboard*); void PasteAsPlainTextWithPasteboard(Pasteboard*);
void PasteWithPasteboard(Pasteboard*); void PasteWithPasteboard(Pasteboard*);
void WriteSelectionToPasteboard(); void WriteSelectionToPasteboard();
bool DispatchCPPEvent(const AtomicString&,
DataTransferAccessPolicy,
PasteMode = kAllMimeTypes);
void RevealSelectionAfterEditingOperation( void RevealSelectionAfterEditingOperation(
const ScrollAlignment& = ScrollAlignment::kAlignCenterIfNeeded); const ScrollAlignment& = ScrollAlignment::kAlignCenterIfNeeded);
......
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