mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1056545 part.3 ns*EditorEventListener should conform to current coding rules r=ehsan
This commit is contained in:
parent
d0e3b33749
commit
f53995a29b
@ -91,9 +91,10 @@ DoCommandCallback(Command aCommand, void* aData)
|
||||
}
|
||||
}
|
||||
|
||||
nsEditorEventListener::nsEditorEventListener() :
|
||||
mEditor(nullptr), mCommitText(false),
|
||||
mInTransaction(false)
|
||||
nsEditorEventListener::nsEditorEventListener()
|
||||
: mEditor(nullptr)
|
||||
, mCommitText(false)
|
||||
, mInTransaction(false)
|
||||
#ifdef HANDLE_NATIVE_TEXT_DIRECTION_SWITCH
|
||||
, mHaveBidiKeyboards(false)
|
||||
, mShouldSwitchTextDirection(false)
|
||||
@ -447,8 +448,9 @@ bool IsCtrlShiftPressed(bool& isRTL)
|
||||
// To ignore the keys checked in 1, we set their status to 0 before
|
||||
// checking the key status.
|
||||
const int kKeyDownMask = 0x80;
|
||||
if ((keystate[VK_CONTROL] & kKeyDownMask) == 0)
|
||||
if ((keystate[VK_CONTROL] & kKeyDownMask) == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (keystate[VK_RSHIFT] & kKeyDownMask) {
|
||||
keystate[VK_RSHIFT] = 0;
|
||||
@ -471,8 +473,9 @@ bool IsCtrlShiftPressed(bool& isRTL)
|
||||
keystate[VK_RCONTROL] = 0;
|
||||
keystate[VK_LCONTROL] = 0;
|
||||
for (int i = 0; i <= VK_PACKET; ++i) {
|
||||
if (keystate[i] & kKeyDownMask)
|
||||
if (keystate[i] & kKeyDownMask) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -624,10 +627,8 @@ nsEditorEventListener::MouseClick(nsIDOMMouseEvent* aMouseEvent)
|
||||
int16_t button = -1;
|
||||
aMouseEvent->GetButton(&button);
|
||||
// middle-mouse click (paste);
|
||||
if (button == 1)
|
||||
{
|
||||
if (Preferences::GetBool("middlemouse.paste", false))
|
||||
{
|
||||
if (button == 1) {
|
||||
if (Preferences::GetBool("middlemouse.paste", false)) {
|
||||
// Set the selection to the point under the mouse cursor:
|
||||
nsCOMPtr<nsIDOMNode> parent;
|
||||
if (NS_FAILED(aMouseEvent->GetRangeParent(getter_AddRefs(parent)))) {
|
||||
@ -639,8 +640,9 @@ nsEditorEventListener::MouseClick(nsIDOMMouseEvent* aMouseEvent)
|
||||
}
|
||||
|
||||
nsCOMPtr<nsISelection> selection;
|
||||
if (NS_SUCCEEDED(mEditor->GetSelection(getter_AddRefs(selection))))
|
||||
(void)selection->Collapse(parent, offset);
|
||||
if (NS_SUCCEEDED(mEditor->GetSelection(getter_AddRefs(selection)))) {
|
||||
selection->Collapse(parent, offset);
|
||||
}
|
||||
|
||||
// If the ctrl key is pressed, we'll do paste as quotation.
|
||||
// Would've used the alt key, but the kde wmgr treats alt-middle specially.
|
||||
@ -648,8 +650,9 @@ nsEditorEventListener::MouseClick(nsIDOMMouseEvent* aMouseEvent)
|
||||
aMouseEvent->GetCtrlKey(&ctrlKey);
|
||||
|
||||
nsCOMPtr<nsIEditorMailSupport> mailEditor;
|
||||
if (ctrlKey)
|
||||
if (ctrlKey) {
|
||||
mailEditor = do_QueryObject(mEditor);
|
||||
}
|
||||
|
||||
int32_t clipboard = nsIClipboard::kGlobalClipboard;
|
||||
nsCOMPtr<nsIClipboard> clipboardService =
|
||||
@ -662,10 +665,11 @@ nsEditorEventListener::MouseClick(nsIDOMMouseEvent* aMouseEvent)
|
||||
}
|
||||
}
|
||||
|
||||
if (mailEditor)
|
||||
if (mailEditor) {
|
||||
mailEditor->PasteAsQuotation(clipboard);
|
||||
else
|
||||
} else {
|
||||
mEditor->Paste(clipboard);
|
||||
}
|
||||
|
||||
// Prevent the event from propagating up to be possibly handled
|
||||
// again by the containing window:
|
||||
@ -753,17 +757,14 @@ nsEditorEventListener::DragOver(nsIDOMDragEvent* aDragEvent)
|
||||
mCaret->SetVisible(true);
|
||||
mCaret->SetCaretPosition(parent, offset);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
if (!IsFileControlTextBox()) {
|
||||
// This is needed when dropping on an input, to prevent the editor for
|
||||
// the editable parent from receiving the event.
|
||||
aDragEvent->StopPropagation();
|
||||
}
|
||||
|
||||
if (mCaret)
|
||||
{
|
||||
if (mCaret) {
|
||||
mCaret->SetVisible(false);
|
||||
}
|
||||
}
|
||||
@ -774,13 +775,11 @@ nsEditorEventListener::DragOver(nsIDOMDragEvent* aDragEvent)
|
||||
void
|
||||
nsEditorEventListener::CleanupDragDropCaret()
|
||||
{
|
||||
if (mCaret)
|
||||
{
|
||||
if (mCaret) {
|
||||
mCaret->SetVisible(false); // hide it, so that it turns off its timer
|
||||
|
||||
nsCOMPtr<nsIPresShell> presShell = GetPresShell();
|
||||
if (presShell)
|
||||
{
|
||||
if (presShell) {
|
||||
nsCOMPtr<nsISelectionController> selCon(do_QueryInterface(presShell));
|
||||
if (selCon) {
|
||||
selCon->SetCaretEnabled(false);
|
||||
@ -869,8 +868,9 @@ nsEditorEventListener::CanDrop(nsIDOMDragEvent* aEvent)
|
||||
// is the same as the drag source.
|
||||
nsCOMPtr<nsIDOMNode> sourceNode;
|
||||
dataTransfer->GetMozSourceNode(getter_AddRefs(sourceNode));
|
||||
if (!sourceNode)
|
||||
if (!sourceNode) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// There is a source node, so compare the source documents and this document.
|
||||
// Disallow drops on the same document.
|
||||
@ -881,18 +881,22 @@ nsEditorEventListener::CanDrop(nsIDOMDragEvent* aEvent)
|
||||
nsCOMPtr<nsIDOMDocument> sourceDoc;
|
||||
nsresult rv = sourceNode->GetOwnerDocument(getter_AddRefs(sourceDoc));
|
||||
NS_ENSURE_SUCCESS(rv, false);
|
||||
if (domdoc == sourceDoc) // source and dest are the same document; disallow drops within the selection
|
||||
{
|
||||
|
||||
// source and dest are the same document; disallow drops within the selection
|
||||
if (domdoc == sourceDoc) {
|
||||
nsCOMPtr<nsISelection> selection;
|
||||
rv = mEditor->GetSelection(getter_AddRefs(selection));
|
||||
if (NS_FAILED(rv) || !selection)
|
||||
if (NS_FAILED(rv) || !selection) {
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
// Don't bother if collapsed - can always drop
|
||||
if (!selection->Collapsed()) {
|
||||
nsCOMPtr<nsIDOMNode> parent;
|
||||
rv = aEvent->GetRangeParent(getter_AddRefs(parent));
|
||||
if (NS_FAILED(rv) || !parent) return false;
|
||||
if (NS_FAILED(rv) || !parent) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t offset = 0;
|
||||
rv = aEvent->GetRangeOffset(&offset);
|
||||
@ -902,17 +906,20 @@ nsEditorEventListener::CanDrop(nsIDOMDragEvent* aEvent)
|
||||
rv = selection->GetRangeCount(&rangeCount);
|
||||
NS_ENSURE_SUCCESS(rv, false);
|
||||
|
||||
for (int32_t i = 0; i < rangeCount; i++)
|
||||
{
|
||||
for (int32_t i = 0; i < rangeCount; i++) {
|
||||
nsCOMPtr<nsIDOMRange> range;
|
||||
rv = selection->GetRangeAt(i, getter_AddRefs(range));
|
||||
if (NS_FAILED(rv) || !range)
|
||||
continue; //don't bail yet, iterate through them all
|
||||
if (NS_FAILED(rv) || !range) {
|
||||
// Don't bail yet, iterate through them all
|
||||
continue;
|
||||
}
|
||||
|
||||
bool inRange = true;
|
||||
(void)range->IsPointInRange(parent, offset, &inRange);
|
||||
if (inRange)
|
||||
return false; //okay, now you can bail, we are over the orginal selection
|
||||
range->IsPointInRange(parent, offset, &inRange);
|
||||
if (inRange) {
|
||||
// Okay, now you can bail, we are over the orginal selection
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -983,8 +990,9 @@ nsEditorEventListener::Focus(nsIDOMEvent* aEvent)
|
||||
|
||||
nsCOMPtr<nsIDOMElement> element;
|
||||
fm->GetFocusedElement(getter_AddRefs(element));
|
||||
if (!SameCOMIdentity(element, target))
|
||||
if (!SameCOMIdentity(element, target)) {
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1010,21 +1018,22 @@ nsEditorEventListener::Blur(nsIDOMEvent* aEvent)
|
||||
|
||||
nsCOMPtr<nsIDOMElement> element;
|
||||
fm->GetFocusedElement(getter_AddRefs(element));
|
||||
if (element)
|
||||
if (element) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
mEditor->FinalizeSelection();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsEditorEventListener::SpellCheckIfNeeded() {
|
||||
nsEditorEventListener::SpellCheckIfNeeded()
|
||||
{
|
||||
// If the spell check skip flag is still enabled from creation time,
|
||||
// disable it because focused editors are allowed to spell check.
|
||||
uint32_t currentFlags = 0;
|
||||
mEditor->GetFlags(¤tFlags);
|
||||
if(currentFlags & nsIPlaintextEditor::eEditorSkipSpellCheck)
|
||||
{
|
||||
if(currentFlags & nsIPlaintextEditor::eEditorSkipSpellCheck) {
|
||||
currentFlags ^= nsIPlaintextEditor::eEditorSkipSpellCheck;
|
||||
mEditor->SetFlags(currentFlags);
|
||||
}
|
||||
|
@ -34,7 +34,8 @@ nsresult
|
||||
nsHTMLEditorEventListener::Connect(nsEditor* aEditor)
|
||||
{
|
||||
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryObject(aEditor);
|
||||
nsCOMPtr<nsIHTMLInlineTableEditor> htmlInlineTableEditor = do_QueryObject(aEditor);
|
||||
nsCOMPtr<nsIHTMLInlineTableEditor> htmlInlineTableEditor =
|
||||
do_QueryObject(aEditor);
|
||||
NS_PRECONDITION(htmlEditor && htmlInlineTableEditor,
|
||||
"Set nsHTMLEditor or its sub class");
|
||||
return nsEditorEventListener::Connect(aEditor);
|
||||
@ -56,8 +57,8 @@ nsHTMLEditorEventListener::MouseUp(nsIDOMMouseEvent* aMouseEvent)
|
||||
nsHTMLEditor* htmlEditor = GetHTMLEditor();
|
||||
|
||||
nsCOMPtr<nsIDOMEventTarget> target;
|
||||
nsresult res = aMouseEvent->GetTarget(getter_AddRefs(target));
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
nsresult rv = aMouseEvent->GetTarget(getter_AddRefs(target));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
NS_ENSURE_TRUE(target, NS_ERROR_NULL_POINTER);
|
||||
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(target);
|
||||
|
||||
@ -77,21 +78,22 @@ nsHTMLEditorEventListener::MouseDown(nsIDOMMouseEvent* aMouseEvent)
|
||||
nsHTMLEditor* htmlEditor = GetHTMLEditor();
|
||||
|
||||
// Detect only "context menu" click
|
||||
//XXX This should be easier to do!
|
||||
// But eDOMEvents_contextmenu and NS_CONTEXTMENU is not exposed in any event interface :-(
|
||||
// XXX This should be easier to do!
|
||||
// But eDOMEvents_contextmenu and NS_CONTEXTMENU is not exposed in any event
|
||||
// interface :-(
|
||||
int16_t buttonNumber;
|
||||
nsresult res = aMouseEvent->GetButton(&buttonNumber);
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
nsresult rv = aMouseEvent->GetButton(&buttonNumber);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
bool isContextClick = buttonNumber == 2;
|
||||
|
||||
int32_t clickCount;
|
||||
res = aMouseEvent->GetDetail(&clickCount);
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
rv = aMouseEvent->GetDetail(&clickCount);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIDOMEventTarget> target;
|
||||
res = aMouseEvent->GetExplicitOriginalTarget(getter_AddRefs(target));
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
rv = aMouseEvent->GetExplicitOriginalTarget(getter_AddRefs(target));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
NS_ENSURE_TRUE(target, NS_ERROR_NULL_POINTER);
|
||||
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(target);
|
||||
|
||||
@ -100,86 +102,80 @@ nsHTMLEditorEventListener::MouseDown(nsIDOMMouseEvent* aMouseEvent)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (isContextClick || (buttonNumber == 0 && clickCount == 2))
|
||||
{
|
||||
if (isContextClick || (buttonNumber == 0 && clickCount == 2)) {
|
||||
nsCOMPtr<nsISelection> selection;
|
||||
mEditor->GetSelection(getter_AddRefs(selection));
|
||||
NS_ENSURE_TRUE(selection, NS_OK);
|
||||
|
||||
// Get location of mouse within target node
|
||||
nsCOMPtr<nsIDOMNode> parent;
|
||||
res = aMouseEvent->GetRangeParent(getter_AddRefs(parent));
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
rv = aMouseEvent->GetRangeParent(getter_AddRefs(parent));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
NS_ENSURE_TRUE(parent, NS_ERROR_FAILURE);
|
||||
|
||||
int32_t offset = 0;
|
||||
res = aMouseEvent->GetRangeOffset(&offset);
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
rv = aMouseEvent->GetRangeOffset(&offset);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// Detect if mouse point is within current selection for context click
|
||||
bool nodeIsInSelection = false;
|
||||
if (isContextClick && !selection->Collapsed()) {
|
||||
int32_t rangeCount;
|
||||
res = selection->GetRangeCount(&rangeCount);
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
rv = selection->GetRangeCount(&rangeCount);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
for (int32_t i = 0; i < rangeCount; i++) {
|
||||
nsCOMPtr<nsIDOMRange> range;
|
||||
|
||||
res = selection->GetRangeAt(i, getter_AddRefs(range));
|
||||
if (NS_FAILED(res) || !range)
|
||||
continue;//don't bail yet, iterate through them all
|
||||
rv = selection->GetRangeAt(i, getter_AddRefs(range));
|
||||
if (NS_FAILED(rv) || !range) {
|
||||
// Don't bail yet, iterate through them all
|
||||
continue;
|
||||
}
|
||||
|
||||
res = range->IsPointInRange(parent, offset, &nodeIsInSelection);
|
||||
range->IsPointInRange(parent, offset, &nodeIsInSelection);
|
||||
|
||||
// Done when we find a range that we are in
|
||||
if (nodeIsInSelection)
|
||||
if (nodeIsInSelection) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
nsCOMPtr<nsIDOMNode> node = do_QueryInterface(target);
|
||||
if (node && !nodeIsInSelection)
|
||||
{
|
||||
if (!element)
|
||||
{
|
||||
if (isContextClick)
|
||||
{
|
||||
if (node && !nodeIsInSelection) {
|
||||
if (!element) {
|
||||
if (isContextClick) {
|
||||
// Set the selection to the point under the mouse cursor:
|
||||
selection->Collapse(parent, offset);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// Get enclosing link if in text so we can select the link
|
||||
nsCOMPtr<nsIDOMElement> linkElement;
|
||||
res = htmlEditor->GetElementOrParentByTagName(NS_LITERAL_STRING("href"), node, getter_AddRefs(linkElement));
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
if (linkElement)
|
||||
rv = htmlEditor->GetElementOrParentByTagName(
|
||||
NS_LITERAL_STRING("href"), node,
|
||||
getter_AddRefs(linkElement));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (linkElement) {
|
||||
element = linkElement;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Select entire element clicked on if NOT within an existing selection
|
||||
// and not the entire body, or table-related elements
|
||||
if (element)
|
||||
{
|
||||
if (element) {
|
||||
nsCOMPtr<nsIDOMNode> selectAllNode =
|
||||
htmlEditor->FindUserSelectAllNode(element);
|
||||
|
||||
if (selectAllNode)
|
||||
{
|
||||
if (selectAllNode) {
|
||||
nsCOMPtr<nsIDOMElement> newElement = do_QueryInterface(selectAllNode);
|
||||
if (newElement)
|
||||
{
|
||||
if (newElement) {
|
||||
node = selectAllNode;
|
||||
element = newElement;
|
||||
}
|
||||
}
|
||||
|
||||
if (isContextClick && !nsHTMLEditUtils::IsImage(node))
|
||||
{
|
||||
if (isContextClick && !nsHTMLEditUtils::IsImage(node)) {
|
||||
selection->Collapse(parent, offset);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
htmlEditor->SelectElement(element);
|
||||
}
|
||||
}
|
||||
@ -190,14 +186,11 @@ nsHTMLEditorEventListener::MouseDown(nsIDOMMouseEvent* aMouseEvent)
|
||||
|
||||
// Prevent bubbling if we changed selection or
|
||||
// for all context clicks
|
||||
if (element || isContextClick)
|
||||
{
|
||||
if (element || isContextClick) {
|
||||
aMouseEvent->PreventDefault();
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
else if (!isContextClick && buttonNumber == 0 && clickCount == 1)
|
||||
{
|
||||
} else if (!isContextClick && buttonNumber == 0 && clickCount == 1) {
|
||||
// if the target element is an image, we have to display resizers
|
||||
int32_t clientX, clientY;
|
||||
aMouseEvent->GetClientX(&clientX);
|
||||
@ -214,8 +207,8 @@ nsHTMLEditorEventListener::MouseClick(nsIDOMMouseEvent* aMouseEvent)
|
||||
NS_ENSURE_TRUE(aMouseEvent, NS_OK);
|
||||
|
||||
nsCOMPtr<nsIDOMEventTarget> target;
|
||||
nsresult res = aMouseEvent->GetTarget(getter_AddRefs(target));
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
nsresult rv = aMouseEvent->GetTarget(getter_AddRefs(target));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
NS_ENSURE_TRUE(target, NS_ERROR_NULL_POINTER);
|
||||
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(target);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user