зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1664411 - Factor out a condition to unconditionally enable clipboard events in some documents. r=masayuki
This patch shouldn't introduce any behavior change. Differential Revision: https://phabricator.services.mozilla.com/D89834
This commit is contained in:
Родитель
f4aee8119a
Коммит
20252cfeaf
|
@ -11790,6 +11790,10 @@ void Document::UnsuppressEventHandlingAndFireEvents(bool aFireEvents) {
|
|||
}
|
||||
}
|
||||
|
||||
bool Document::AreClipboardCommandsUnconditionallyEnabled() const {
|
||||
return IsHTMLOrXHTML() && !nsContentUtils::IsChromeDoc(this);
|
||||
}
|
||||
|
||||
void Document::AddSuspendedChannelEventQueue(net::ChannelEventQueue* aQueue) {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(EventHandlingSuppressed());
|
||||
|
|
|
@ -2713,6 +2713,13 @@ class Document : public nsINode,
|
|||
UpdateFrameRequestCallbackSchedulingState();
|
||||
}
|
||||
|
||||
/**
|
||||
* Some clipboard commands are unconditionally enabled on some documents, so
|
||||
* as to always dispatch copy / paste events even though you'd normally not be
|
||||
* able to copy.
|
||||
*/
|
||||
bool AreClipboardCommandsUnconditionallyEnabled() const;
|
||||
|
||||
/**
|
||||
* Note a ChannelEventQueue which has been suspended on the document's behalf
|
||||
* to prevent XHRs from running content scripts while event handling is
|
||||
|
|
|
@ -487,7 +487,7 @@ nsresult nsClipboardCommand::IsCommandEnabled(const char* aCommandName,
|
|||
RefPtr<dom::Document> doc = window->GetExtantDoc();
|
||||
NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);
|
||||
|
||||
if (doc->IsHTMLOrXHTML() && !nsContentUtils::IsChromeDoc(doc)) {
|
||||
if (doc->AreClipboardCommandsUnconditionallyEnabled()) {
|
||||
// In HTML and XHTML documents, we always want the cut, copy and paste
|
||||
// commands to be enabled, but if the document is chrome, let it control it.
|
||||
*outCmdEnabled = true;
|
||||
|
|
|
@ -2160,11 +2160,7 @@ static const char* textHtmlEditorFlavors[] = {kUnicodeMime, kHTMLMime,
|
|||
kPNGImageMime, kGIFImageMime};
|
||||
|
||||
bool HTMLEditor::CanPaste(int32_t aClipboardType) const {
|
||||
// Always enable the paste command when inside of a HTML or XHTML document,
|
||||
// but if the document is chrome, let it control it.
|
||||
Document* document = GetDocument();
|
||||
if (document && document->IsHTMLOrXHTML() &&
|
||||
!nsContentUtils::IsChromeDoc(document)) {
|
||||
if (AreClipboardCommandsUnconditionallyEnabled()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -1200,17 +1200,18 @@ nsresult TextEditor::CutAsAction(nsIPrincipal* aPrincipal) {
|
|||
return EditorBase::ToGenericNSResult(rv);
|
||||
}
|
||||
|
||||
bool TextEditor::AreClipboardCommandsUnconditionallyEnabled() const {
|
||||
Document* document = GetDocument();
|
||||
return document && document->AreClipboardCommandsUnconditionallyEnabled();
|
||||
}
|
||||
|
||||
bool TextEditor::IsCutCommandEnabled() const {
|
||||
AutoEditActionDataSetter editActionData(*this, EditAction::eNotEditing);
|
||||
if (NS_WARN_IF(!editActionData.CanHandle())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Cut is always enabled in HTML documents, but if the document is chrome,
|
||||
// let it control it.
|
||||
Document* document = GetDocument();
|
||||
if (document && document->IsHTMLOrXHTML() &&
|
||||
!nsContentUtils::IsChromeDoc(document)) {
|
||||
if (AreClipboardCommandsUnconditionallyEnabled()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1236,11 +1237,7 @@ bool TextEditor::IsCopyCommandEnabled() const {
|
|||
return false;
|
||||
}
|
||||
|
||||
// Copy is always enabled in HTML documents, but if the document is chrome,
|
||||
// let it control it.
|
||||
Document* document = GetDocument();
|
||||
if (document && document->IsHTMLOrXHTML() &&
|
||||
!nsContentUtils::IsChromeDoc(document)) {
|
||||
if (AreClipboardCommandsUnconditionallyEnabled()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -86,6 +86,11 @@ class TextEditor : public EditorBase, public nsITimerCallback, public nsINamed {
|
|||
*/
|
||||
MOZ_CAN_RUN_SCRIPT nsresult CutAsAction(nsIPrincipal* aPrincipal = nullptr);
|
||||
|
||||
/**
|
||||
* See Document::AreClipboardCommandsUnconditionallyEnabled.
|
||||
*/
|
||||
bool AreClipboardCommandsUnconditionallyEnabled() const;
|
||||
|
||||
/**
|
||||
* IsCutCommandEnabled() returns whether cut command can be enabled or
|
||||
* disabled. This always returns true if we're in non-chrome HTML/XHTML
|
||||
|
|
|
@ -664,10 +664,7 @@ nsresult TextEditor::PasteTransferableAsAction(nsITransferable* aTransferable,
|
|||
}
|
||||
|
||||
bool TextEditor::CanPaste(int32_t aClipboardType) const {
|
||||
// Always enable the paste command when inside of a HTML or XHTML document,
|
||||
// but if the document is chrome, let it control it.
|
||||
RefPtr<Document> doc = GetDocument();
|
||||
if (doc && doc->IsHTMLOrXHTML() && !nsContentUtils::IsChromeDoc(doc)) {
|
||||
if (AreClipboardCommandsUnconditionallyEnabled()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче