2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2003-04-12 07:08:23 +04:00
|
|
|
|
|
|
|
#include "nsGlobalWindowCommands.h"
|
|
|
|
|
|
|
|
#include "nsIInterfaceRequestor.h"
|
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
2018-07-10 14:04:21 +03:00
|
|
|
#include "nsCommandParams.h"
|
2003-04-12 07:08:23 +04:00
|
|
|
#include "nsCRT.h"
|
2003-04-22 22:11:12 +04:00
|
|
|
#include "nsString.h"
|
2013-12-09 06:52:54 +04:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2011-05-25 10:31:59 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2019-04-13 04:03:13 +03:00
|
|
|
#include "mozilla/PresShell.h"
|
2003-04-12 07:08:23 +04:00
|
|
|
|
2019-04-03 15:52:14 +03:00
|
|
|
#include "nsControllerCommandTable.h"
|
|
|
|
#include "nsCommandParams.h"
|
2003-04-12 07:08:23 +04:00
|
|
|
|
2005-11-29 02:56:44 +03:00
|
|
|
#include "nsPIDOMWindow.h"
|
2003-04-12 07:08:23 +04:00
|
|
|
#include "nsIDocShell.h"
|
|
|
|
#include "nsISelectionController.h"
|
|
|
|
#include "nsIWebNavigation.h"
|
|
|
|
#include "nsIContentViewerEdit.h"
|
|
|
|
#include "nsIContentViewer.h"
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
#include "nsFocusManager.h"
|
2010-03-19 21:32:13 +03:00
|
|
|
#include "nsCopySupport.h"
|
2013-08-07 22:52:38 +04:00
|
|
|
#include "nsIClipboard.h"
|
2016-05-02 05:41:20 +03:00
|
|
|
#include "ContentEventHandler.h"
|
|
|
|
#include "nsContentUtils.h"
|
2012-06-15 06:31:55 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-09-25 15:21:22 +04:00
|
|
|
#include "mozilla/BasicEvents.h"
|
2016-05-02 05:41:20 +03:00
|
|
|
#include "mozilla/TextEvents.h"
|
2019-04-26 23:29:30 +03:00
|
|
|
#include "mozilla/dom/Document.h"
|
2014-11-27 01:06:00 +03:00
|
|
|
#include "mozilla/dom/Selection.h"
|
2017-06-16 01:06:00 +03:00
|
|
|
#include "mozilla/layers/KeyboardMap.h"
|
2003-04-12 07:08:23 +04:00
|
|
|
|
2011-05-25 10:31:59 +04:00
|
|
|
using namespace mozilla;
|
2017-06-06 02:17:30 +03:00
|
|
|
using namespace mozilla::layers;
|
2011-05-25 10:31:59 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
constexpr const char* sSelectAllString = "cmd_selectAll";
|
|
|
|
constexpr const char* sSelectNoneString = "cmd_selectNone";
|
|
|
|
constexpr const char* sCopyImageLocationString = "cmd_copyImageLocation";
|
|
|
|
constexpr const char* sCopyImageContentsString = "cmd_copyImageContents";
|
|
|
|
constexpr const char* sCopyImageString = "cmd_copyImage";
|
|
|
|
|
|
|
|
constexpr const char* sScrollTopString = "cmd_scrollTop";
|
|
|
|
constexpr const char* sScrollBottomString = "cmd_scrollBottom";
|
|
|
|
constexpr const char* sScrollPageUpString = "cmd_scrollPageUp";
|
|
|
|
constexpr const char* sScrollPageDownString = "cmd_scrollPageDown";
|
|
|
|
constexpr const char* sScrollLineUpString = "cmd_scrollLineUp";
|
|
|
|
constexpr const char* sScrollLineDownString = "cmd_scrollLineDown";
|
|
|
|
constexpr const char* sScrollLeftString = "cmd_scrollLeft";
|
|
|
|
constexpr const char* sScrollRightString = "cmd_scrollRight";
|
|
|
|
constexpr const char* sMoveTopString = "cmd_moveTop";
|
|
|
|
constexpr const char* sMoveBottomString = "cmd_moveBottom";
|
|
|
|
constexpr const char* sMovePageUpString = "cmd_movePageUp";
|
|
|
|
constexpr const char* sMovePageDownString = "cmd_movePageDown";
|
|
|
|
constexpr const char* sLinePreviousString = "cmd_linePrevious";
|
|
|
|
constexpr const char* sLineNextString = "cmd_lineNext";
|
|
|
|
constexpr const char* sCharPreviousString = "cmd_charPrevious";
|
|
|
|
constexpr const char* sCharNextString = "cmd_charNext";
|
2003-04-12 07:08:23 +04:00
|
|
|
|
|
|
|
// These are so the browser can use editor navigation key bindings
|
|
|
|
// helps with accessibility (boolean pref accessibility.browsewithcaret)
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
constexpr const char* sSelectCharPreviousString = "cmd_selectCharPrevious";
|
|
|
|
constexpr const char* sSelectCharNextString = "cmd_selectCharNext";
|
2003-04-12 07:08:23 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
constexpr const char* sWordPreviousString = "cmd_wordPrevious";
|
|
|
|
constexpr const char* sWordNextString = "cmd_wordNext";
|
|
|
|
constexpr const char* sSelectWordPreviousString = "cmd_selectWordPrevious";
|
|
|
|
constexpr const char* sSelectWordNextString = "cmd_selectWordNext";
|
2003-04-12 07:08:23 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
constexpr const char* sBeginLineString = "cmd_beginLine";
|
|
|
|
constexpr const char* sEndLineString = "cmd_endLine";
|
|
|
|
constexpr const char* sSelectBeginLineString = "cmd_selectBeginLine";
|
|
|
|
constexpr const char* sSelectEndLineString = "cmd_selectEndLine";
|
2003-04-12 07:08:23 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
constexpr const char* sSelectLinePreviousString = "cmd_selectLinePrevious";
|
|
|
|
constexpr const char* sSelectLineNextString = "cmd_selectLineNext";
|
2003-04-12 07:08:23 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
constexpr const char* sSelectPageUpString = "cmd_selectPageUp";
|
|
|
|
constexpr const char* sSelectPageDownString = "cmd_selectPageDown";
|
2003-04-12 07:08:23 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
constexpr const char* sSelectTopString = "cmd_selectTop";
|
|
|
|
constexpr const char* sSelectBottomString = "cmd_selectBottom";
|
2003-04-12 07:08:23 +04:00
|
|
|
|
2014-11-22 17:39:04 +03:00
|
|
|
// Physical-direction movement and selection commands
|
2019-05-01 11:47:10 +03:00
|
|
|
constexpr const char* sMoveLeftString = "cmd_moveLeft";
|
|
|
|
constexpr const char* sMoveRightString = "cmd_moveRight";
|
|
|
|
constexpr const char* sMoveUpString = "cmd_moveUp";
|
|
|
|
constexpr const char* sMoveDownString = "cmd_moveDown";
|
|
|
|
constexpr const char* sMoveLeft2String = "cmd_moveLeft2";
|
|
|
|
constexpr const char* sMoveRight2String = "cmd_moveRight2";
|
|
|
|
constexpr const char* sMoveUp2String = "cmd_moveUp2";
|
|
|
|
constexpr const char* sMoveDown2String = "cmd_moveDown2";
|
|
|
|
|
|
|
|
constexpr const char* sSelectLeftString = "cmd_selectLeft";
|
|
|
|
constexpr const char* sSelectRightString = "cmd_selectRight";
|
|
|
|
constexpr const char* sSelectUpString = "cmd_selectUp";
|
|
|
|
constexpr const char* sSelectDownString = "cmd_selectDown";
|
|
|
|
constexpr const char* sSelectLeft2String = "cmd_selectLeft2";
|
|
|
|
constexpr const char* sSelectRight2String = "cmd_selectRight2";
|
|
|
|
constexpr const char* sSelectUp2String = "cmd_selectUp2";
|
|
|
|
constexpr const char* sSelectDown2String = "cmd_selectDown2";
|
2003-04-12 07:08:23 +04:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
# pragma mark -
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// a base class for selection-related commands, for code sharing
|
|
|
|
class nsSelectionCommandsBase : public nsIControllerCommand {
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
2019-05-01 11:47:10 +03:00
|
|
|
NS_IMETHOD IsCommandEnabled(const char* aCommandName,
|
|
|
|
nsISupports* aCommandContext,
|
|
|
|
bool* _retval) override;
|
|
|
|
NS_IMETHOD GetCommandStateParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* aCommandContext) override;
|
2019-03-12 04:57:42 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
2019-05-01 11:47:10 +03:00
|
|
|
NS_IMETHOD DoCommandParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* aCommandContext) override;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2003-04-12 07:08:23 +04:00
|
|
|
protected:
|
2020-02-21 13:41:47 +03:00
|
|
|
virtual ~nsSelectionCommandsBase() = default;
|
2003-04-12 07:08:23 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
static nsresult GetPresShellFromWindow(nsPIDOMWindowOuter* aWindow,
|
|
|
|
PresShell** aPresShell);
|
2016-01-30 20:05:36 +03:00
|
|
|
static nsresult GetSelectionControllerFromWindow(
|
2019-05-01 11:47:10 +03:00
|
|
|
nsPIDOMWindowOuter* aWindow, nsISelectionController** aSelCon);
|
2003-04-12 07:08:23 +04:00
|
|
|
|
|
|
|
// no member variables, please, we're stateless!
|
|
|
|
};
|
|
|
|
|
|
|
|
// this class implements commands whose behavior depends on the 'browse with
|
|
|
|
// caret' setting
|
|
|
|
class nsSelectMoveScrollCommand : public nsSelectionCommandsBase {
|
2012-01-06 01:33:41 +04:00
|
|
|
public:
|
2019-05-01 11:47:10 +03:00
|
|
|
NS_IMETHOD DoCommand(const char* aCommandName,
|
|
|
|
nsISupports* aCommandContext) override;
|
2003-04-12 07:08:23 +04:00
|
|
|
|
|
|
|
// no member variables, please, we're stateless!
|
|
|
|
};
|
|
|
|
|
2014-11-22 17:39:04 +03:00
|
|
|
// this class implements physical-movement versions of the above
|
|
|
|
class nsPhysicalSelectMoveScrollCommand : public nsSelectionCommandsBase {
|
|
|
|
public:
|
2019-05-01 11:47:10 +03:00
|
|
|
NS_IMETHOD DoCommand(const char* aCommandName,
|
|
|
|
nsISupports* aCommandContext) override;
|
2014-11-22 17:39:04 +03:00
|
|
|
|
|
|
|
// no member variables, please, we're stateless!
|
|
|
|
};
|
|
|
|
|
2003-04-12 07:08:23 +04:00
|
|
|
// this class implements other selection commands
|
|
|
|
class nsSelectCommand : public nsSelectionCommandsBase {
|
2012-01-06 01:33:41 +04:00
|
|
|
public:
|
2019-05-01 11:47:10 +03:00
|
|
|
NS_IMETHOD DoCommand(const char* aCommandName,
|
|
|
|
nsISupports* aCommandContext) override;
|
2003-04-12 07:08:23 +04:00
|
|
|
|
|
|
|
// no member variables, please, we're stateless!
|
|
|
|
};
|
|
|
|
|
2014-11-22 17:39:04 +03:00
|
|
|
// this class implements physical-movement versions of selection commands
|
|
|
|
class nsPhysicalSelectCommand : public nsSelectionCommandsBase {
|
|
|
|
public:
|
2019-05-01 11:47:10 +03:00
|
|
|
NS_IMETHOD DoCommand(const char* aCommandName,
|
|
|
|
nsISupports* aCommandContext) override;
|
2014-11-22 17:39:04 +03:00
|
|
|
|
|
|
|
// no member variables, please, we're stateless!
|
|
|
|
};
|
|
|
|
|
2003-04-12 07:08:23 +04:00
|
|
|
#if 0
|
|
|
|
# pragma mark -
|
|
|
|
#endif
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsSelectionCommandsBase, nsIControllerCommand)
|
2003-04-12 07:08:23 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2019-05-01 11:47:10 +03:00
|
|
|
nsSelectionCommandsBase::IsCommandEnabled(const char* aCommandName,
|
|
|
|
nsISupports* aCommandContext,
|
|
|
|
bool* outCmdEnabled) {
|
2003-04-12 07:08:23 +04:00
|
|
|
// XXX this needs fixing. e.g. you can't scroll up if you're already at the
|
|
|
|
// top of the document.
|
2011-10-17 18:59:28 +04:00
|
|
|
*outCmdEnabled = true;
|
2003-04-12 07:08:23 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2019-05-01 11:47:10 +03:00
|
|
|
nsSelectionCommandsBase::GetCommandStateParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* aCommandContext) {
|
2003-04-12 07:08:23 +04:00
|
|
|
// XXX we should probably return the enabled state
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2019-05-01 11:47:10 +03:00
|
|
|
nsSelectionCommandsBase::DoCommandParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* aCommandContext) {
|
2003-04-12 07:08:23 +04:00
|
|
|
return DoCommand(aCommandName, aCommandContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
// protected methods
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsresult nsSelectionCommandsBase::GetPresShellFromWindow(
|
2019-05-01 11:47:10 +03:00
|
|
|
nsPIDOMWindowOuter* aWindow, PresShell** aPresShell) {
|
2012-07-30 18:20:58 +04:00
|
|
|
*aPresShell = nullptr;
|
2012-01-06 01:33:41 +04:00
|
|
|
NS_ENSURE_TRUE(aWindow, NS_ERROR_FAILURE);
|
2003-04-12 07:08:23 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
nsIDocShell* docShell = aWindow->GetDocShell();
|
2003-04-12 07:08:23 +04:00
|
|
|
NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
|
|
|
|
|
2012-12-29 05:56:42 +04:00
|
|
|
NS_IF_ADDREF(*aPresShell = docShell->GetPresShell());
|
|
|
|
return NS_OK;
|
2003-04-12 07:08:23 +04:00
|
|
|
}
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsresult nsSelectionCommandsBase::GetSelectionControllerFromWindow(
|
2019-05-01 11:47:10 +03:00
|
|
|
nsPIDOMWindowOuter* aWindow, nsISelectionController** aSelCon) {
|
2019-04-13 04:03:13 +03:00
|
|
|
RefPtr<PresShell> presShell;
|
2003-04-12 07:08:23 +04:00
|
|
|
GetPresShellFromWindow(aWindow, getter_AddRefs(presShell));
|
2019-04-13 04:03:13 +03:00
|
|
|
if (!presShell) {
|
|
|
|
*aSelCon = nullptr;
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
*aSelCon = presShell.forget().take();
|
|
|
|
return NS_OK;
|
2003-04-12 07:08:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
# pragma mark -
|
|
|
|
#endif
|
|
|
|
|
2014-11-22 17:39:04 +03:00
|
|
|
// Helpers for nsSelectMoveScrollCommand and nsPhysicalSelectMoveScrollCommand
|
2019-05-01 11:47:10 +03:00
|
|
|
static void AdjustFocusAfterCaretMove(nsPIDOMWindowOuter* aWindow) {
|
2014-11-22 17:39:04 +03:00
|
|
|
// adjust the focus to the new caret position
|
2019-05-01 11:47:10 +03:00
|
|
|
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
2014-11-22 17:39:04 +03:00
|
|
|
if (fm) {
|
2018-04-26 17:37:47 +03:00
|
|
|
RefPtr<dom::Element> result;
|
2014-11-22 17:39:04 +03:00
|
|
|
fm->MoveFocus(aWindow, nullptr, nsIFocusManager::MOVEFOCUS_CARET,
|
|
|
|
nsIFocusManager::FLAG_NOSCROLL, getter_AddRefs(result));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
static bool IsCaretOnInWindow(nsPIDOMWindowOuter* aWindow,
|
|
|
|
nsISelectionController* aSelCont) {
|
2014-11-22 17:39:04 +03:00
|
|
|
// We allow the caret to be moved with arrow keys on any window for which
|
|
|
|
// the caret is enabled. In particular, this includes caret-browsing mode
|
|
|
|
// in non-chrome documents.
|
|
|
|
bool caretOn = false;
|
|
|
|
aSelCont->GetCaretEnabled(&caretOn);
|
|
|
|
if (!caretOn) {
|
|
|
|
caretOn = Preferences::GetBool("accessibility.browsewithcaret");
|
|
|
|
if (caretOn) {
|
|
|
|
nsCOMPtr<nsIDocShell> docShell = aWindow->GetDocShell();
|
|
|
|
if (docShell && docShell->ItemType() == nsIDocShellTreeItem::typeChrome) {
|
|
|
|
caretOn = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return caretOn;
|
|
|
|
}
|
|
|
|
|
2017-02-01 05:42:33 +03:00
|
|
|
static constexpr struct BrowseCommand {
|
2012-01-06 01:33:41 +04:00
|
|
|
const char *reverse, *forward;
|
2017-06-06 02:17:30 +03:00
|
|
|
KeyboardScrollAction::KeyboardScrollActionType scrollAction;
|
2012-01-06 01:33:41 +04:00
|
|
|
nsresult (NS_STDCALL nsISelectionController::*scroll)(bool);
|
|
|
|
nsresult (NS_STDCALL nsISelectionController::*move)(bool, bool);
|
|
|
|
} browseCommands[] = {
|
|
|
|
{sScrollTopString, sScrollBottomString,
|
2017-06-06 02:17:30 +03:00
|
|
|
KeyboardScrollAction::eScrollComplete,
|
2012-01-06 01:33:41 +04:00
|
|
|
&nsISelectionController::CompleteScroll},
|
|
|
|
{sScrollPageUpString, sScrollPageDownString,
|
|
|
|
KeyboardScrollAction::eScrollPage, &nsISelectionController::ScrollPage},
|
|
|
|
{sScrollLineUpString, sScrollLineDownString,
|
|
|
|
KeyboardScrollAction::eScrollLine, &nsISelectionController::ScrollLine},
|
|
|
|
{sScrollLeftString, sScrollRightString,
|
2017-06-06 02:17:30 +03:00
|
|
|
KeyboardScrollAction::eScrollCharacter,
|
2012-01-06 01:33:41 +04:00
|
|
|
&nsISelectionController::ScrollCharacter},
|
2017-06-06 02:17:30 +03:00
|
|
|
{sMoveTopString, sMoveBottomString, KeyboardScrollAction::eScrollComplete,
|
2012-01-06 01:33:41 +04:00
|
|
|
&nsISelectionController::CompleteScroll,
|
|
|
|
&nsISelectionController::CompleteMove},
|
|
|
|
{sMovePageUpString, sMovePageDownString, KeyboardScrollAction::eScrollPage,
|
|
|
|
&nsISelectionController::ScrollPage, &nsISelectionController::PageMove},
|
|
|
|
{sLinePreviousString, sLineNextString, KeyboardScrollAction::eScrollLine,
|
|
|
|
&nsISelectionController::ScrollLine, &nsISelectionController::LineMove},
|
|
|
|
{sWordPreviousString, sWordNextString,
|
2017-06-06 02:17:30 +03:00
|
|
|
KeyboardScrollAction::eScrollCharacter,
|
2012-01-06 01:33:41 +04:00
|
|
|
&nsISelectionController::ScrollCharacter,
|
|
|
|
&nsISelectionController::WordMove},
|
|
|
|
{sCharPreviousString, sCharNextString,
|
2017-06-06 02:17:30 +03:00
|
|
|
KeyboardScrollAction::eScrollCharacter,
|
2012-01-06 01:33:41 +04:00
|
|
|
&nsISelectionController::ScrollCharacter,
|
|
|
|
&nsISelectionController::CharacterMove},
|
2017-06-06 02:17:30 +03:00
|
|
|
{sBeginLineString, sEndLineString, KeyboardScrollAction::eScrollComplete,
|
2012-01-06 01:33:41 +04:00
|
|
|
&nsISelectionController::CompleteScroll,
|
|
|
|
&nsISelectionController::IntraLineMove}};
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
nsresult nsSelectMoveScrollCommand::DoCommand(const char* aCommandName,
|
|
|
|
nsISupports* aCommandContext) {
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> piWindow(do_QueryInterface(aCommandContext));
|
2003-04-12 07:08:23 +04:00
|
|
|
nsCOMPtr<nsISelectionController> selCont;
|
2012-01-06 01:33:41 +04:00
|
|
|
GetSelectionControllerFromWindow(piWindow, getter_AddRefs(selCont));
|
2017-07-06 15:00:35 +03:00
|
|
|
NS_ENSURE_TRUE(selCont, NS_ERROR_NOT_INITIALIZED);
|
2003-04-12 07:08:23 +04:00
|
|
|
|
2014-11-22 17:39:04 +03:00
|
|
|
bool caretOn = IsCaretOnInWindow(piWindow, selCont);
|
2003-04-12 07:08:23 +04:00
|
|
|
|
2012-02-21 13:34:01 +04:00
|
|
|
for (size_t i = 0; i < ArrayLength(browseCommands); i++) {
|
2012-01-06 01:33:41 +04:00
|
|
|
bool forward = !strcmp(aCommandName, browseCommands[i].forward);
|
|
|
|
if (forward || !strcmp(aCommandName, browseCommands[i].reverse)) {
|
|
|
|
if (caretOn && browseCommands[i].move &&
|
|
|
|
NS_SUCCEEDED((selCont->*(browseCommands[i].move))(forward, false))) {
|
2014-11-22 17:39:04 +03:00
|
|
|
AdjustFocusAfterCaretMove(piWindow);
|
2012-01-06 01:33:41 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return (selCont->*(browseCommands[i].scroll))(forward);
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
}
|
2003-04-12 07:08:23 +04:00
|
|
|
}
|
2014-11-22 17:39:04 +03:00
|
|
|
|
2012-01-06 01:33:41 +04:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2003-04-12 07:08:23 +04:00
|
|
|
}
|
|
|
|
|
2014-11-22 17:39:04 +03:00
|
|
|
// XXX It's not clear to me yet how we should handle the "scroll" option
|
|
|
|
// for these commands; for now, I'm mapping them back to ScrollCharacter,
|
|
|
|
// ScrollLine, etc., as if for horizontal-mode content, but this may need
|
|
|
|
// to be reconsidered once we have more experience with vertical content.
|
|
|
|
static const struct PhysicalBrowseCommand {
|
2019-05-01 11:47:10 +03:00
|
|
|
const char* command;
|
2014-11-22 17:39:04 +03:00
|
|
|
int16_t direction, amount;
|
2017-06-06 02:17:30 +03:00
|
|
|
KeyboardScrollAction::KeyboardScrollActionType scrollAction;
|
2014-11-22 17:39:04 +03:00
|
|
|
nsresult (NS_STDCALL nsISelectionController::*scroll)(bool);
|
|
|
|
} physicalBrowseCommands[] = {
|
|
|
|
{sMoveLeftString, nsISelectionController::MOVE_LEFT, 0,
|
2017-06-06 02:17:30 +03:00
|
|
|
KeyboardScrollAction::eScrollCharacter,
|
2014-11-22 17:39:04 +03:00
|
|
|
&nsISelectionController::ScrollCharacter},
|
|
|
|
{sMoveRightString, nsISelectionController::MOVE_RIGHT, 0,
|
2017-06-06 02:17:30 +03:00
|
|
|
KeyboardScrollAction::eScrollCharacter,
|
2014-11-22 17:39:04 +03:00
|
|
|
&nsISelectionController::ScrollCharacter},
|
|
|
|
{sMoveUpString, nsISelectionController::MOVE_UP, 0,
|
|
|
|
KeyboardScrollAction::eScrollLine, &nsISelectionController::ScrollLine},
|
|
|
|
{sMoveDownString, nsISelectionController::MOVE_DOWN, 0,
|
|
|
|
KeyboardScrollAction::eScrollLine, &nsISelectionController::ScrollLine},
|
|
|
|
{sMoveLeft2String, nsISelectionController::MOVE_LEFT, 1,
|
2017-06-06 02:17:30 +03:00
|
|
|
KeyboardScrollAction::eScrollCharacter,
|
2014-11-22 17:39:04 +03:00
|
|
|
&nsISelectionController::ScrollCharacter},
|
|
|
|
{sMoveRight2String, nsISelectionController::MOVE_RIGHT, 1,
|
2017-06-06 02:17:30 +03:00
|
|
|
KeyboardScrollAction::eScrollCharacter,
|
2014-11-22 17:39:04 +03:00
|
|
|
&nsISelectionController::ScrollCharacter},
|
|
|
|
{sMoveUp2String, nsISelectionController::MOVE_UP, 1,
|
2017-06-06 02:17:30 +03:00
|
|
|
KeyboardScrollAction::eScrollComplete,
|
2014-11-22 17:39:04 +03:00
|
|
|
&nsISelectionController::CompleteScroll},
|
|
|
|
{sMoveDown2String, nsISelectionController::MOVE_DOWN, 1,
|
2017-06-06 02:17:30 +03:00
|
|
|
KeyboardScrollAction::eScrollComplete,
|
2014-11-22 17:39:04 +03:00
|
|
|
&nsISelectionController::CompleteScroll},
|
|
|
|
};
|
|
|
|
|
|
|
|
nsresult nsPhysicalSelectMoveScrollCommand::DoCommand(
|
2019-05-01 11:47:10 +03:00
|
|
|
const char* aCommandName, nsISupports* aCommandContext) {
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> piWindow(do_QueryInterface(aCommandContext));
|
2014-11-22 17:39:04 +03:00
|
|
|
nsCOMPtr<nsISelectionController> selCont;
|
|
|
|
GetSelectionControllerFromWindow(piWindow, getter_AddRefs(selCont));
|
2017-07-06 15:00:35 +03:00
|
|
|
NS_ENSURE_TRUE(selCont, NS_ERROR_NOT_INITIALIZED);
|
2014-11-22 17:39:04 +03:00
|
|
|
|
|
|
|
bool caretOn = IsCaretOnInWindow(piWindow, selCont);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < ArrayLength(physicalBrowseCommands); i++) {
|
2019-05-01 11:47:10 +03:00
|
|
|
const PhysicalBrowseCommand& cmd = physicalBrowseCommands[i];
|
2014-11-22 17:39:04 +03:00
|
|
|
if (!strcmp(aCommandName, cmd.command)) {
|
|
|
|
int16_t dir = cmd.direction;
|
|
|
|
if (caretOn &&
|
|
|
|
NS_SUCCEEDED(selCont->PhysicalMove(dir, cmd.amount, false))) {
|
|
|
|
AdjustFocusAfterCaretMove(piWindow);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool forward = (dir == nsISelectionController::MOVE_RIGHT ||
|
|
|
|
dir == nsISelectionController::MOVE_DOWN);
|
|
|
|
return (selCont->*(cmd.scroll))(forward);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
2003-04-12 07:08:23 +04:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
# pragma mark -
|
|
|
|
#endif
|
|
|
|
|
2014-11-22 17:39:04 +03:00
|
|
|
static const struct SelectCommand {
|
|
|
|
const char *reverse, *forward;
|
|
|
|
nsresult (NS_STDCALL nsISelectionController::*select)(bool, bool);
|
|
|
|
} selectCommands[] = {{sSelectCharPreviousString, sSelectCharNextString,
|
|
|
|
&nsISelectionController::CharacterMove},
|
|
|
|
{sSelectWordPreviousString, sSelectWordNextString,
|
|
|
|
&nsISelectionController::WordMove},
|
|
|
|
{sSelectBeginLineString, sSelectEndLineString,
|
|
|
|
&nsISelectionController::IntraLineMove},
|
|
|
|
{sSelectLinePreviousString, sSelectLineNextString,
|
|
|
|
&nsISelectionController::LineMove},
|
|
|
|
{sSelectPageUpString, sSelectPageDownString,
|
|
|
|
&nsISelectionController::PageMove},
|
|
|
|
{sSelectTopString, sSelectBottomString,
|
|
|
|
&nsISelectionController::CompleteMove}};
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
nsresult nsSelectCommand::DoCommand(const char* aCommandName,
|
|
|
|
nsISupports* aCommandContext) {
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> piWindow(do_QueryInterface(aCommandContext));
|
2003-04-12 07:08:23 +04:00
|
|
|
nsCOMPtr<nsISelectionController> selCont;
|
2012-01-06 01:33:41 +04:00
|
|
|
GetSelectionControllerFromWindow(piWindow, getter_AddRefs(selCont));
|
2017-07-06 15:00:35 +03:00
|
|
|
NS_ENSURE_TRUE(selCont, NS_ERROR_NOT_INITIALIZED);
|
2003-04-12 07:08:23 +04:00
|
|
|
|
|
|
|
// These commands are so the browser can use caret navigation key bindings -
|
|
|
|
// Helps with accessibility - aaronl@netscape.com
|
2014-11-22 17:39:04 +03:00
|
|
|
for (size_t i = 0; i < ArrayLength(selectCommands); i++) {
|
|
|
|
bool forward = !strcmp(aCommandName, selectCommands[i].forward);
|
|
|
|
if (forward || !strcmp(aCommandName, selectCommands[i].reverse)) {
|
|
|
|
return (selCont->*(selectCommands[i].select))(forward, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
# pragma mark -
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static const struct PhysicalSelectCommand {
|
2019-05-01 11:47:10 +03:00
|
|
|
const char* command;
|
2014-11-22 17:39:04 +03:00
|
|
|
int16_t direction, amount;
|
|
|
|
} physicalSelectCommands[] = {
|
|
|
|
{sSelectLeftString, nsISelectionController::MOVE_LEFT, 0},
|
|
|
|
{sSelectRightString, nsISelectionController::MOVE_RIGHT, 0},
|
|
|
|
{sSelectUpString, nsISelectionController::MOVE_UP, 0},
|
|
|
|
{sSelectDownString, nsISelectionController::MOVE_DOWN, 0},
|
|
|
|
{sSelectLeft2String, nsISelectionController::MOVE_LEFT, 1},
|
|
|
|
{sSelectRight2String, nsISelectionController::MOVE_RIGHT, 1},
|
|
|
|
{sSelectUp2String, nsISelectionController::MOVE_UP, 1},
|
|
|
|
{sSelectDown2String, nsISelectionController::MOVE_DOWN, 1}};
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
nsresult nsPhysicalSelectCommand::DoCommand(const char* aCommandName,
|
|
|
|
nsISupports* aCommandContext) {
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> piWindow(do_QueryInterface(aCommandContext));
|
2014-11-22 17:39:04 +03:00
|
|
|
nsCOMPtr<nsISelectionController> selCont;
|
|
|
|
GetSelectionControllerFromWindow(piWindow, getter_AddRefs(selCont));
|
2017-07-06 15:00:35 +03:00
|
|
|
NS_ENSURE_TRUE(selCont, NS_ERROR_NOT_INITIALIZED);
|
2014-11-22 17:39:04 +03:00
|
|
|
|
|
|
|
for (size_t i = 0; i < ArrayLength(physicalSelectCommands); i++) {
|
|
|
|
if (!strcmp(aCommandName, physicalSelectCommands[i].command)) {
|
|
|
|
return selCont->PhysicalMove(physicalSelectCommands[i].direction,
|
|
|
|
physicalSelectCommands[i].amount, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2003-04-12 07:08:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
# pragma mark -
|
|
|
|
#endif
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsClipboardCommand final : public nsIControllerCommand {
|
2020-02-21 13:41:47 +03:00
|
|
|
~nsClipboardCommand() = default;
|
2014-06-23 23:56:07 +04:00
|
|
|
|
2010-03-19 21:32:13 +03:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSICONTROLLERCOMMAND
|
|
|
|
};
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsClipboardCommand, nsIControllerCommand)
|
2010-03-19 21:32:13 +03:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
nsresult nsClipboardCommand::IsCommandEnabled(const char* aCommandName,
|
|
|
|
nsISupports* aContext,
|
|
|
|
bool* outCmdEnabled) {
|
2010-03-19 21:32:13 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(outCmdEnabled);
|
2011-10-17 18:59:28 +04:00
|
|
|
*outCmdEnabled = false;
|
2010-03-19 21:32:13 +03:00
|
|
|
|
2019-02-13 03:11:03 +03:00
|
|
|
if (strcmp(aCommandName, "cmd_copy") && strcmp(aCommandName, "cmd_cut") &&
|
|
|
|
strcmp(aCommandName, "cmd_paste")) {
|
2010-03-19 21:32:13 +03:00
|
|
|
return NS_OK;
|
2019-02-13 03:11:03 +03:00
|
|
|
}
|
2010-03-19 21:32:13 +03:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> window = do_QueryInterface(aContext);
|
2010-03-19 21:32:13 +03:00
|
|
|
NS_ENSURE_TRUE(window, NS_ERROR_FAILURE);
|
2019-04-26 23:29:30 +03:00
|
|
|
RefPtr<dom::Document> doc = window->GetExtantDoc();
|
2019-02-13 03:11:03 +03:00
|
|
|
NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);
|
2010-03-19 21:32:13 +03:00
|
|
|
|
2019-06-18 23:40:19 +03:00
|
|
|
if (doc->IsHTMLOrXHTML() && !nsContentUtils::IsChromeDoc(doc)) {
|
2016-05-13 21:16:30 +03:00
|
|
|
// In HTML and XHTML documents, we always want the cut, copy and paste
|
2019-06-18 23:40:19 +03:00
|
|
|
// commands to be enabled, but if the document is chrome, let it control it.
|
2015-06-30 15:17:27 +03:00
|
|
|
*outCmdEnabled = true;
|
|
|
|
} else {
|
|
|
|
// Cut isn't enabled in xul documents which use nsClipboardCommand
|
2019-02-22 04:39:14 +03:00
|
|
|
if (strcmp(aCommandName, "cmd_copy") == 0) {
|
2015-06-30 15:17:27 +03:00
|
|
|
*outCmdEnabled = nsCopySupport::CanCopy(doc);
|
|
|
|
}
|
|
|
|
}
|
2010-03-19 21:32:13 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
nsresult nsClipboardCommand::DoCommand(const char* aCommandName,
|
|
|
|
nsISupports* aContext) {
|
2015-05-13 09:51:00 +03:00
|
|
|
if (strcmp(aCommandName, "cmd_cut") && strcmp(aCommandName, "cmd_copy") &&
|
2016-05-13 21:16:30 +03:00
|
|
|
strcmp(aCommandName, "cmd_paste"))
|
2010-03-19 21:32:13 +03:00
|
|
|
return NS_OK;
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> window = do_QueryInterface(aContext);
|
2010-03-19 21:32:13 +03:00
|
|
|
NS_ENSURE_TRUE(window, NS_ERROR_FAILURE);
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
nsIDocShell* docShell = window->GetDocShell();
|
2010-03-19 21:32:13 +03:00
|
|
|
NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
|
|
|
|
|
2019-04-13 04:03:13 +03:00
|
|
|
RefPtr<PresShell> presShell = docShell->GetPresShell();
|
2010-03-19 21:32:13 +03:00
|
|
|
NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE);
|
|
|
|
|
2015-09-08 17:33:34 +03:00
|
|
|
EventMessage eventMessage = eCopy;
|
2015-05-13 09:51:00 +03:00
|
|
|
if (strcmp(aCommandName, "cmd_cut") == 0) {
|
2015-09-08 17:33:35 +03:00
|
|
|
eventMessage = eCut;
|
2016-05-13 21:16:30 +03:00
|
|
|
} else if (strcmp(aCommandName, "cmd_paste") == 0) {
|
|
|
|
eventMessage = ePaste;
|
2015-05-13 09:51:00 +03:00
|
|
|
}
|
|
|
|
|
2018-03-28 14:25:57 +03:00
|
|
|
bool actionTaken = false;
|
2019-02-22 04:39:14 +03:00
|
|
|
nsCopySupport::FireClipboardEvent(eventMessage,
|
|
|
|
nsIClipboard::kGlobalClipboard, presShell,
|
|
|
|
nullptr, &actionTaken);
|
2014-11-27 01:06:00 +03:00
|
|
|
|
2018-03-26 22:18:05 +03:00
|
|
|
return actionTaken ? NS_OK : NS_SUCCESS_DOM_NO_OPERATION;
|
2010-03-19 21:32:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2019-05-01 11:47:10 +03:00
|
|
|
nsClipboardCommand::GetCommandStateParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* aCommandContext) {
|
2010-03-19 21:32:13 +03:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
nsresult nsClipboardCommand::DoCommandParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* aContext) {
|
2010-03-19 21:32:13 +03:00
|
|
|
return DoCommand(aCommandName, aContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
# pragma mark -
|
|
|
|
#endif
|
|
|
|
|
|
|
|
class nsSelectionCommand : public nsIControllerCommand {
|
2003-04-12 07:08:23 +04:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSICONTROLLERCOMMAND
|
|
|
|
|
|
|
|
protected:
|
2020-02-21 13:41:47 +03:00
|
|
|
virtual ~nsSelectionCommand() = default;
|
2003-04-12 07:08:23 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
virtual nsresult IsClipboardCommandEnabled(const char* aCommandName,
|
|
|
|
nsIContentViewerEdit* aEdit,
|
|
|
|
bool* outCmdEnabled) = 0;
|
|
|
|
virtual nsresult DoClipboardCommand(const char* aCommandName,
|
|
|
|
nsIContentViewerEdit* aEdit,
|
|
|
|
nsICommandParams* aParams) = 0;
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2003-04-12 07:08:23 +04:00
|
|
|
static nsresult GetContentViewerEditFromContext(
|
2019-05-01 11:47:10 +03:00
|
|
|
nsISupports* aContext, nsIContentViewerEdit** aEditInterface);
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2003-04-12 07:08:23 +04:00
|
|
|
// no member variables, please, we're stateless!
|
|
|
|
};
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsSelectionCommand, nsIControllerCommand)
|
2003-04-12 07:08:23 +04:00
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------
|
|
|
|
|
2010-03-19 21:32:13 +03:00
|
|
|
nsSelectionCommand
|
2003-04-12 07:08:23 +04:00
|
|
|
|
|
|
|
----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2019-05-01 11:47:10 +03:00
|
|
|
nsSelectionCommand::IsCommandEnabled(const char* aCommandName,
|
|
|
|
nsISupports* aCommandContext,
|
|
|
|
bool* outCmdEnabled) {
|
2003-04-12 07:08:23 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(outCmdEnabled);
|
2011-10-17 18:59:28 +04:00
|
|
|
*outCmdEnabled = false;
|
2003-04-12 07:08:23 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIContentViewerEdit> contentEdit;
|
|
|
|
GetContentViewerEditFromContext(aCommandContext, getter_AddRefs(contentEdit));
|
|
|
|
NS_ENSURE_TRUE(contentEdit, NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
|
|
|
return IsClipboardCommandEnabled(aCommandName, contentEdit, outCmdEnabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2019-05-01 11:47:10 +03:00
|
|
|
nsSelectionCommand::DoCommand(const char* aCommandName,
|
|
|
|
nsISupports* aCommandContext) {
|
2003-04-12 07:08:23 +04:00
|
|
|
nsCOMPtr<nsIContentViewerEdit> contentEdit;
|
|
|
|
GetContentViewerEditFromContext(aCommandContext, getter_AddRefs(contentEdit));
|
|
|
|
NS_ENSURE_TRUE(contentEdit, NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return DoClipboardCommand(aCommandName, contentEdit, nullptr);
|
2003-04-12 07:08:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2019-05-01 11:47:10 +03:00
|
|
|
nsSelectionCommand::GetCommandStateParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* aCommandContext) {
|
2003-04-12 07:08:23 +04:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2019-05-01 11:47:10 +03:00
|
|
|
nsSelectionCommand::DoCommandParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* aCommandContext) {
|
2003-04-22 22:11:12 +04:00
|
|
|
nsCOMPtr<nsIContentViewerEdit> contentEdit;
|
|
|
|
GetContentViewerEditFromContext(aCommandContext, getter_AddRefs(contentEdit));
|
|
|
|
NS_ENSURE_TRUE(contentEdit, NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
|
|
|
return DoClipboardCommand(aCommandName, contentEdit, aParams);
|
2003-04-12 07:08:23 +04:00
|
|
|
}
|
|
|
|
|
2010-03-19 21:32:13 +03:00
|
|
|
nsresult nsSelectionCommand::GetContentViewerEditFromContext(
|
2019-05-01 11:47:10 +03:00
|
|
|
nsISupports* aContext, nsIContentViewerEdit** aEditInterface) {
|
2003-04-12 07:08:23 +04:00
|
|
|
NS_ENSURE_ARG(aEditInterface);
|
2012-07-30 18:20:58 +04:00
|
|
|
*aEditInterface = nullptr;
|
2003-04-12 07:08:23 +04:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> window = do_QueryInterface(aContext);
|
2003-04-12 07:08:23 +04:00
|
|
|
NS_ENSURE_TRUE(window, NS_ERROR_INVALID_ARG);
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
nsIDocShell* docShell = window->GetDocShell();
|
2003-04-12 07:08:23 +04:00
|
|
|
NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContentViewer> viewer;
|
|
|
|
docShell->GetContentViewer(getter_AddRefs(viewer));
|
|
|
|
nsCOMPtr<nsIContentViewerEdit> edit(do_QueryInterface(viewer));
|
|
|
|
NS_ENSURE_TRUE(edit, NS_ERROR_FAILURE);
|
|
|
|
|
2015-03-31 17:03:49 +03:00
|
|
|
edit.forget(aEditInterface);
|
2003-04-12 07:08:23 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
# pragma mark -
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define NS_DECL_CLIPBOARD_COMMAND(_cmd) \
|
2012-06-15 06:31:55 +04:00
|
|
|
class _cmd : public nsSelectionCommand { \
|
2003-04-12 07:08:23 +04:00
|
|
|
protected: \
|
2019-05-01 11:47:10 +03:00
|
|
|
virtual nsresult IsClipboardCommandEnabled(const char* aCommandName, \
|
|
|
|
nsIContentViewerEdit* aEdit, \
|
|
|
|
bool* outCmdEnabled) override; \
|
|
|
|
virtual nsresult DoClipboardCommand(const char* aCommandName, \
|
|
|
|
nsIContentViewerEdit* aEdit, \
|
|
|
|
nsICommandParams* aParams) override; \
|
2003-04-12 07:08:23 +04:00
|
|
|
/* no member variables, please, we're stateless! */ \
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_DECL_CLIPBOARD_COMMAND(nsClipboardCopyLinkCommand)
|
|
|
|
NS_DECL_CLIPBOARD_COMMAND(nsClipboardImageCommands)
|
|
|
|
NS_DECL_CLIPBOARD_COMMAND(nsClipboardSelectAllNoneCommands)
|
2003-04-22 22:11:12 +04:00
|
|
|
NS_DECL_CLIPBOARD_COMMAND(nsClipboardGetContentsCommand)
|
2003-04-12 07:08:23 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
nsresult nsClipboardCopyLinkCommand::IsClipboardCommandEnabled(
|
2019-05-01 11:47:10 +03:00
|
|
|
const char* aCommandName, nsIContentViewerEdit* aEdit,
|
|
|
|
bool* outCmdEnabled) {
|
2003-04-12 07:08:23 +04:00
|
|
|
return aEdit->GetInLink(outCmdEnabled);
|
|
|
|
}
|
|
|
|
|
2003-04-22 22:11:12 +04:00
|
|
|
nsresult nsClipboardCopyLinkCommand::DoClipboardCommand(
|
2019-05-01 11:47:10 +03:00
|
|
|
const char* aCommandName, nsIContentViewerEdit* aEdit,
|
|
|
|
nsICommandParams* aParams) {
|
2003-04-12 07:08:23 +04:00
|
|
|
return aEdit->CopyLinkLocation();
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
# pragma mark -
|
|
|
|
#endif
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
nsresult nsClipboardImageCommands::IsClipboardCommandEnabled(
|
2019-05-01 11:47:10 +03:00
|
|
|
const char* aCommandName, nsIContentViewerEdit* aEdit,
|
|
|
|
bool* outCmdEnabled) {
|
2003-04-12 07:08:23 +04:00
|
|
|
return aEdit->GetInImage(outCmdEnabled);
|
|
|
|
}
|
|
|
|
|
2003-04-22 22:11:12 +04:00
|
|
|
nsresult nsClipboardImageCommands::DoClipboardCommand(
|
2019-05-01 11:47:10 +03:00
|
|
|
const char* aCommandName, nsIContentViewerEdit* aEdit,
|
|
|
|
nsICommandParams* aParams) {
|
2003-04-12 07:08:23 +04:00
|
|
|
if (!nsCRT::strcmp(sCopyImageLocationString, aCommandName))
|
2005-03-11 14:12:15 +03:00
|
|
|
return aEdit->CopyImage(nsIContentViewerEdit::COPY_IMAGE_TEXT);
|
2005-05-05 20:14:00 +04:00
|
|
|
if (!nsCRT::strcmp(sCopyImageContentsString, aCommandName))
|
|
|
|
return aEdit->CopyImage(nsIContentViewerEdit::COPY_IMAGE_DATA);
|
2017-07-06 15:00:35 +03:00
|
|
|
int32_t copyFlags = nsIContentViewerEdit::COPY_IMAGE_DATA |
|
2012-04-30 21:08:16 +04:00
|
|
|
nsIContentViewerEdit::COPY_IMAGE_HTML;
|
2018-07-10 14:04:21 +03:00
|
|
|
if (aParams) {
|
|
|
|
copyFlags = aParams->AsCommandParams()->GetInt("imageCopy");
|
|
|
|
}
|
2005-03-11 14:12:15 +03:00
|
|
|
return aEdit->CopyImage(copyFlags);
|
2003-04-12 07:08:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
# pragma mark -
|
|
|
|
#endif
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
nsresult nsClipboardSelectAllNoneCommands::IsClipboardCommandEnabled(
|
2019-05-01 11:47:10 +03:00
|
|
|
const char* aCommandName, nsIContentViewerEdit* aEdit,
|
|
|
|
bool* outCmdEnabled) {
|
2011-10-17 18:59:28 +04:00
|
|
|
*outCmdEnabled = true;
|
2003-04-12 07:08:23 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-04-22 22:11:12 +04:00
|
|
|
nsresult nsClipboardSelectAllNoneCommands::DoClipboardCommand(
|
2019-05-01 11:47:10 +03:00
|
|
|
const char* aCommandName, nsIContentViewerEdit* aEdit,
|
|
|
|
nsICommandParams* aParams) {
|
2003-04-12 07:08:23 +04:00
|
|
|
if (!nsCRT::strcmp(sSelectAllString, aCommandName)) return aEdit->SelectAll();
|
|
|
|
|
|
|
|
return aEdit->ClearSelection();
|
|
|
|
}
|
|
|
|
|
2003-04-22 22:11:12 +04:00
|
|
|
#if 0
|
|
|
|
# pragma mark -
|
|
|
|
#endif
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
nsresult nsClipboardGetContentsCommand::IsClipboardCommandEnabled(
|
2019-05-01 11:47:10 +03:00
|
|
|
const char* aCommandName, nsIContentViewerEdit* aEdit,
|
|
|
|
bool* outCmdEnabled) {
|
2003-04-22 22:11:12 +04:00
|
|
|
return aEdit->GetCanGetContents(outCmdEnabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsClipboardGetContentsCommand::DoClipboardCommand(
|
2019-05-01 11:47:10 +03:00
|
|
|
const char* aCommandName, nsIContentViewerEdit* aEdit,
|
|
|
|
nsICommandParams* aParams) {
|
2003-04-22 22:11:12 +04:00
|
|
|
NS_ENSURE_ARG(aParams);
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
nsCommandParams* params = aParams->AsCommandParams();
|
2018-07-10 14:04:21 +03:00
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString mimeType("text/plain");
|
2003-04-22 22:11:12 +04:00
|
|
|
|
2018-07-10 12:04:46 +03:00
|
|
|
nsAutoCString format;
|
2018-07-10 14:04:21 +03:00
|
|
|
if (NS_SUCCEEDED(params->GetCString("format", format))) {
|
2003-04-22 22:11:12 +04:00
|
|
|
mimeType.Assign(format);
|
2018-07-10 12:04:46 +03:00
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2003-04-22 22:11:12 +04:00
|
|
|
nsAutoString contents;
|
2018-07-10 14:04:21 +03:00
|
|
|
nsresult rv = aEdit->GetContents(mimeType.get(),
|
|
|
|
params->GetBool("selection_only"), contents);
|
|
|
|
if (NS_FAILED(rv)) {
|
2003-04-22 22:11:12 +04:00
|
|
|
return rv;
|
2018-07-10 14:04:21 +03:00
|
|
|
}
|
|
|
|
return params->SetString("result", contents);
|
2003-04-22 22:11:12 +04:00
|
|
|
}
|
|
|
|
|
2012-06-15 06:31:55 +04:00
|
|
|
#if 0 // Remove unless needed again, bug 204777
|
2003-04-12 07:08:23 +04:00
|
|
|
class nsWebNavigationBaseCommand : public nsIControllerCommand
|
|
|
|
{
|
|
|
|
public:
|
2012-06-15 06:31:55 +04:00
|
|
|
virtual ~nsWebNavigationBaseCommand() {}
|
2003-04-12 07:08:23 +04:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSICONTROLLERCOMMAND
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual nsresult IsWebNavCommandEnabled(const char * aCommandName, nsIWebNavigation* aWebNavigation, bool *outCmdEnabled) = 0;
|
2003-04-12 07:08:23 +04:00
|
|
|
virtual nsresult DoWebNavCommand(const char *aCommandName, nsIWebNavigation* aWebNavigation) = 0;
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2003-04-12 07:08:23 +04:00
|
|
|
static nsresult GetWebNavigationFromContext(nsISupports *aContext, nsIWebNavigation **aWebNavigation);
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2003-04-12 07:08:23 +04:00
|
|
|
// no member variables, please, we're stateless!
|
|
|
|
};
|
|
|
|
|
|
|
|
class nsGoForwardCommand : public nsWebNavigationBaseCommand
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual nsresult IsWebNavCommandEnabled(const char * aCommandName, nsIWebNavigation* aWebNavigation, bool *outCmdEnabled);
|
2003-04-12 07:08:23 +04:00
|
|
|
virtual nsresult DoWebNavCommand(const char *aCommandName, nsIWebNavigation* aWebNavigation);
|
|
|
|
// no member variables, please, we're stateless!
|
|
|
|
};
|
|
|
|
|
|
|
|
class nsGoBackCommand : public nsWebNavigationBaseCommand
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual nsresult IsWebNavCommandEnabled(const char * aCommandName, nsIWebNavigation* aWebNavigation, bool *outCmdEnabled);
|
2003-04-12 07:08:23 +04:00
|
|
|
virtual nsresult DoWebNavCommand(const char *aCommandName, nsIWebNavigation* aWebNavigation);
|
|
|
|
// no member variables, please, we're stateless!
|
|
|
|
};
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
nsWebNavigationCommands
|
|
|
|
no params
|
|
|
|
----------------------------------------------------------------------------*/
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsWebNavigationBaseCommand, nsIControllerCommand)
|
2003-04-12 07:08:23 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebNavigationBaseCommand::IsCommandEnabled(const char * aCommandName,
|
|
|
|
nsISupports *aCommandContext,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool *outCmdEnabled)
|
2003-04-12 07:08:23 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(outCmdEnabled);
|
2011-10-17 18:59:28 +04:00
|
|
|
*outCmdEnabled = false;
|
2003-04-12 07:08:23 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIWebNavigation> webNav;
|
|
|
|
GetWebNavigationFromContext(aCommandContext, getter_AddRefs(webNav));
|
|
|
|
NS_ENSURE_TRUE(webNav, NS_ERROR_INVALID_ARG);
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2003-04-12 07:08:23 +04:00
|
|
|
return IsCommandEnabled(aCommandName, webNav, outCmdEnabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebNavigationBaseCommand::GetCommandStateParams(const char *aCommandName,
|
|
|
|
nsICommandParams *aParams, nsISupports *aCommandContext)
|
|
|
|
{
|
|
|
|
// XXX we should probably return the enabled state
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebNavigationBaseCommand::DoCommand(const char *aCommandName,
|
|
|
|
nsISupports *aCommandContext)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIWebNavigation> webNav;
|
|
|
|
GetWebNavigationFromContext(aCommandContext, getter_AddRefs(webNav));
|
|
|
|
NS_ENSURE_TRUE(webNav, NS_ERROR_INVALID_ARG);
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2003-04-14 20:10:47 +04:00
|
|
|
return DoWebNavCommand(aCommandName, webNav);
|
2003-04-12 07:08:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebNavigationBaseCommand::DoCommandParams(const char *aCommandName,
|
|
|
|
nsICommandParams *aParams, nsISupports *aCommandContext)
|
|
|
|
{
|
|
|
|
return DoCommand(aCommandName, aCommandContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsWebNavigationBaseCommand::GetWebNavigationFromContext(nsISupports *aContext, nsIWebNavigation **aWebNavigation)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIInterfaceRequestor> windowReq = do_QueryInterface(aContext);
|
|
|
|
CallGetInterface(windowReq.get(), aWebNavigation);
|
|
|
|
return (*aWebNavigation) ? NS_OK : NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2011-09-29 10:19:26 +04:00
|
|
|
nsGoForwardCommand::IsWebNavCommandEnabled(const char * aCommandName, nsIWebNavigation* aWebNavigation, bool *outCmdEnabled)
|
2003-04-12 07:08:23 +04:00
|
|
|
{
|
|
|
|
return aWebNavigation->GetCanGoForward(outCmdEnabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsGoForwardCommand::DoWebNavCommand(const char *aCommandName, nsIWebNavigation* aWebNavigation)
|
|
|
|
{
|
|
|
|
return aWebNavigation->GoForward();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2011-09-29 10:19:26 +04:00
|
|
|
nsGoBackCommand::IsWebNavCommandEnabled(const char * aCommandName, nsIWebNavigation* aWebNavigation, bool *outCmdEnabled)
|
2003-04-12 07:08:23 +04:00
|
|
|
{
|
|
|
|
return aWebNavigation->GetCanGoBack(outCmdEnabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsGoBackCommand::DoWebNavCommand(const char *aCommandName, nsIWebNavigation* aWebNavigation)
|
|
|
|
{
|
|
|
|
return aWebNavigation->GoBack();
|
|
|
|
}
|
2003-05-25 23:39:21 +04:00
|
|
|
#endif
|
2003-04-12 07:08:23 +04:00
|
|
|
|
2016-05-02 05:41:20 +03:00
|
|
|
class nsLookUpDictionaryCommand final : public nsIControllerCommand {
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSICONTROLLERCOMMAND
|
|
|
|
|
|
|
|
private:
|
2020-02-21 13:41:47 +03:00
|
|
|
virtual ~nsLookUpDictionaryCommand() = default;
|
2016-05-02 05:41:20 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(nsLookUpDictionaryCommand, nsIControllerCommand)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2019-05-01 11:47:10 +03:00
|
|
|
nsLookUpDictionaryCommand::IsCommandEnabled(const char* aCommandName,
|
|
|
|
nsISupports* aCommandContext,
|
|
|
|
bool* aRetval) {
|
2016-05-02 05:41:20 +03:00
|
|
|
*aRetval = true;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2019-05-01 11:47:10 +03:00
|
|
|
nsLookUpDictionaryCommand::GetCommandStateParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* aCommandContext) {
|
2016-05-02 05:41:20 +03:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2019-05-01 11:47:10 +03:00
|
|
|
nsLookUpDictionaryCommand::DoCommand(const char* aCommandName,
|
|
|
|
nsISupports* aCommandContext) {
|
2016-05-02 05:41:20 +03:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2019-05-01 11:47:10 +03:00
|
|
|
nsLookUpDictionaryCommand::DoCommandParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* aCommandContext) {
|
2016-05-02 05:41:20 +03:00
|
|
|
if (NS_WARN_IF(!nsContentUtils::IsSafeToRunScript())) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
nsCommandParams* params = aParams->AsCommandParams();
|
2016-05-02 05:41:20 +03:00
|
|
|
|
2018-07-10 14:04:21 +03:00
|
|
|
ErrorResult error;
|
|
|
|
int32_t x = params->GetInt("x", error);
|
|
|
|
if (NS_WARN_IF(error.Failed())) {
|
|
|
|
return error.StealNSResult();
|
2016-05-02 05:41:20 +03:00
|
|
|
}
|
2018-07-10 14:04:21 +03:00
|
|
|
int32_t y = params->GetInt("y", error);
|
|
|
|
if (NS_WARN_IF(error.Failed())) {
|
|
|
|
return error.StealNSResult();
|
2016-05-02 05:41:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
LayoutDeviceIntPoint point(x, y);
|
|
|
|
|
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> window = do_QueryInterface(aCommandContext);
|
|
|
|
if (NS_WARN_IF(!window)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
nsIDocShell* docShell = window->GetDocShell();
|
2016-05-02 05:41:20 +03:00
|
|
|
if (NS_WARN_IF(!docShell)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
PresShell* presShell = docShell->GetPresShell();
|
2016-05-02 05:41:20 +03:00
|
|
|
if (NS_WARN_IF(!presShell)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
nsPresContext* presContext = presShell->GetPresContext();
|
2016-05-02 05:41:20 +03:00
|
|
|
if (NS_WARN_IF(!presContext)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWidget> widget = presContext->GetRootWidget();
|
|
|
|
if (NS_WARN_IF(!widget)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
WidgetQueryContentEvent charAt(true, eQueryCharacterAtPoint, widget);
|
|
|
|
charAt.mRefPoint.x = x;
|
|
|
|
charAt.mRefPoint.y = y;
|
|
|
|
ContentEventHandler handler(presContext);
|
|
|
|
handler.OnQueryCharacterAtPoint(&charAt);
|
|
|
|
|
|
|
|
if (NS_WARN_IF(!charAt.mSucceeded) ||
|
|
|
|
charAt.mReply.mOffset == WidgetQueryContentEvent::NOT_FOUND) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
WidgetQueryContentEvent textContent(true, eQueryTextContent, widget);
|
|
|
|
// OSX 10.7 queries 50 characters before/after current point. So we fetch
|
|
|
|
// same length.
|
|
|
|
uint32_t offset = charAt.mReply.mOffset;
|
|
|
|
if (offset > 50) {
|
|
|
|
offset -= 50;
|
|
|
|
} else {
|
|
|
|
offset = 0;
|
|
|
|
}
|
|
|
|
textContent.InitForQueryTextContent(offset, 100);
|
|
|
|
handler.OnQueryTextContent(&textContent);
|
|
|
|
if (NS_WARN_IF(!textContent.mSucceeded ||
|
|
|
|
textContent.mReply.mString.IsEmpty())) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX nsIWordBreaker doesn't use contextual breaker.
|
|
|
|
// If OS provides it, widget should use it if contextual breaker is needed.
|
2017-12-14 07:17:38 +03:00
|
|
|
RefPtr<mozilla::intl::WordBreaker> wordBreaker =
|
|
|
|
nsContentUtils::WordBreaker();
|
2016-05-02 05:41:20 +03:00
|
|
|
if (NS_WARN_IF(!wordBreaker)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2017-12-14 07:17:38 +03:00
|
|
|
mozilla::intl::WordRange range = wordBreaker->FindWord(
|
2016-05-02 05:41:20 +03:00
|
|
|
textContent.mReply.mString.get(), textContent.mReply.mString.Length(),
|
|
|
|
charAt.mReply.mOffset - offset);
|
|
|
|
if (range.mEnd == range.mBegin) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
range.mBegin += offset;
|
|
|
|
range.mEnd += offset;
|
|
|
|
|
|
|
|
WidgetQueryContentEvent lookUpContent(true, eQueryTextContent, widget);
|
|
|
|
lookUpContent.InitForQueryTextContent(range.mBegin,
|
|
|
|
range.mEnd - range.mBegin);
|
|
|
|
lookUpContent.RequestFontRanges();
|
|
|
|
handler.OnQueryTextContent(&lookUpContent);
|
|
|
|
if (NS_WARN_IF(!lookUpContent.mSucceeded ||
|
|
|
|
lookUpContent.mReply.mString.IsEmpty())) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
WidgetQueryContentEvent charRect(true, eQueryTextRect, widget);
|
|
|
|
charRect.InitForQueryTextRect(range.mBegin, range.mEnd - range.mBegin);
|
|
|
|
handler.OnQueryTextRect(&charRect);
|
|
|
|
if (NS_WARN_IF(!charRect.mSucceeded)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
widget->LookUpDictionary(lookUpContent.mReply.mString,
|
|
|
|
lookUpContent.mReply.mFontRanges,
|
|
|
|
charRect.mReply.mWritingMode.IsVertical(),
|
|
|
|
charRect.mReply.mRect.TopLeft());
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-04-12 07:08:23 +04:00
|
|
|
/*---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
RegisterWindowCommands
|
|
|
|
|
|
|
|
----------------------------------------------------------------------------*/
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
#define NS_REGISTER_ONE_COMMAND(_cmdClass, _cmdName) \
|
|
|
|
{ \
|
|
|
|
_cmdClass* theCmd = new _cmdClass(); \
|
|
|
|
rv = aCommandTable->RegisterCommand( \
|
|
|
|
_cmdName, static_cast<nsIControllerCommand*>(theCmd)); \
|
2003-04-12 07:08:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#define NS_REGISTER_FIRST_COMMAND(_cmdClass, _cmdName) \
|
|
|
|
{ \
|
2019-05-01 11:47:10 +03:00
|
|
|
_cmdClass* theCmd = new _cmdClass(); \
|
2019-04-03 15:52:14 +03:00
|
|
|
rv = aCommandTable->RegisterCommand( \
|
2019-05-01 11:47:10 +03:00
|
|
|
_cmdName, static_cast<nsIControllerCommand*>(theCmd));
|
2003-04-12 07:08:23 +04:00
|
|
|
|
|
|
|
#define NS_REGISTER_NEXT_COMMAND(_cmdClass, _cmdName) \
|
2019-04-03 15:52:14 +03:00
|
|
|
rv = aCommandTable->RegisterCommand( \
|
2019-05-01 11:47:10 +03:00
|
|
|
_cmdName, static_cast<nsIControllerCommand*>(theCmd));
|
2003-04-12 07:08:23 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
#define NS_REGISTER_LAST_COMMAND(_cmdClass, _cmdName) \
|
|
|
|
rv = aCommandTable->RegisterCommand( \
|
|
|
|
_cmdName, static_cast<nsIControllerCommand*>(theCmd)); \
|
2003-04-12 07:08:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
nsresult nsWindowCommandRegistration::RegisterWindowCommands(
|
2019-05-01 11:47:10 +03:00
|
|
|
nsControllerCommandTable* aCommandTable) {
|
2003-04-12 07:08:23 +04:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// XXX rework the macros to use a loop is possible, reducing code size
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2003-04-12 07:08:23 +04:00
|
|
|
// this set of commands is affected by the 'browse with caret' setting
|
|
|
|
NS_REGISTER_FIRST_COMMAND(nsSelectMoveScrollCommand, sScrollTopString);
|
|
|
|
NS_REGISTER_NEXT_COMMAND(nsSelectMoveScrollCommand, sScrollBottomString);
|
2012-01-06 01:33:41 +04:00
|
|
|
NS_REGISTER_NEXT_COMMAND(nsSelectMoveScrollCommand, sScrollPageUpString);
|
|
|
|
NS_REGISTER_NEXT_COMMAND(nsSelectMoveScrollCommand, sScrollPageDownString);
|
|
|
|
NS_REGISTER_NEXT_COMMAND(nsSelectMoveScrollCommand, sScrollLineUpString);
|
|
|
|
NS_REGISTER_NEXT_COMMAND(nsSelectMoveScrollCommand, sScrollLineDownString);
|
|
|
|
NS_REGISTER_NEXT_COMMAND(nsSelectMoveScrollCommand, sScrollLeftString);
|
|
|
|
NS_REGISTER_NEXT_COMMAND(nsSelectMoveScrollCommand, sScrollRightString);
|
2011-12-24 04:11:30 +04:00
|
|
|
NS_REGISTER_NEXT_COMMAND(nsSelectMoveScrollCommand, sMoveTopString);
|
|
|
|
NS_REGISTER_NEXT_COMMAND(nsSelectMoveScrollCommand, sMoveBottomString);
|
2004-12-21 08:28:59 +03:00
|
|
|
NS_REGISTER_NEXT_COMMAND(nsSelectMoveScrollCommand, sWordPreviousString);
|
|
|
|
NS_REGISTER_NEXT_COMMAND(nsSelectMoveScrollCommand, sWordNextString);
|
|
|
|
NS_REGISTER_NEXT_COMMAND(nsSelectMoveScrollCommand, sBeginLineString);
|
|
|
|
NS_REGISTER_NEXT_COMMAND(nsSelectMoveScrollCommand, sEndLineString);
|
2003-04-12 07:08:23 +04:00
|
|
|
NS_REGISTER_NEXT_COMMAND(nsSelectMoveScrollCommand, sMovePageUpString);
|
|
|
|
NS_REGISTER_NEXT_COMMAND(nsSelectMoveScrollCommand, sMovePageDownString);
|
2011-12-24 04:11:30 +04:00
|
|
|
NS_REGISTER_NEXT_COMMAND(nsSelectMoveScrollCommand, sLinePreviousString);
|
|
|
|
NS_REGISTER_NEXT_COMMAND(nsSelectMoveScrollCommand, sLineNextString);
|
|
|
|
NS_REGISTER_NEXT_COMMAND(nsSelectMoveScrollCommand, sCharPreviousString);
|
|
|
|
NS_REGISTER_LAST_COMMAND(nsSelectMoveScrollCommand, sCharNextString);
|
2003-04-12 07:08:23 +04:00
|
|
|
|
2014-11-22 17:39:04 +03:00
|
|
|
NS_REGISTER_FIRST_COMMAND(nsPhysicalSelectMoveScrollCommand, sMoveLeftString);
|
|
|
|
NS_REGISTER_NEXT_COMMAND(nsPhysicalSelectMoveScrollCommand, sMoveRightString);
|
|
|
|
NS_REGISTER_NEXT_COMMAND(nsPhysicalSelectMoveScrollCommand, sMoveUpString);
|
|
|
|
NS_REGISTER_NEXT_COMMAND(nsPhysicalSelectMoveScrollCommand, sMoveDownString);
|
|
|
|
NS_REGISTER_NEXT_COMMAND(nsPhysicalSelectMoveScrollCommand, sMoveLeft2String);
|
|
|
|
NS_REGISTER_NEXT_COMMAND(nsPhysicalSelectMoveScrollCommand,
|
|
|
|
sMoveRight2String);
|
|
|
|
NS_REGISTER_NEXT_COMMAND(nsPhysicalSelectMoveScrollCommand, sMoveUp2String);
|
|
|
|
NS_REGISTER_LAST_COMMAND(nsPhysicalSelectMoveScrollCommand, sMoveDown2String);
|
|
|
|
|
2003-04-12 07:08:23 +04:00
|
|
|
NS_REGISTER_FIRST_COMMAND(nsSelectCommand, sSelectCharPreviousString);
|
|
|
|
NS_REGISTER_NEXT_COMMAND(nsSelectCommand, sSelectCharNextString);
|
|
|
|
NS_REGISTER_NEXT_COMMAND(nsSelectCommand, sSelectWordPreviousString);
|
|
|
|
NS_REGISTER_NEXT_COMMAND(nsSelectCommand, sSelectWordNextString);
|
|
|
|
NS_REGISTER_NEXT_COMMAND(nsSelectCommand, sSelectBeginLineString);
|
|
|
|
NS_REGISTER_NEXT_COMMAND(nsSelectCommand, sSelectEndLineString);
|
|
|
|
NS_REGISTER_NEXT_COMMAND(nsSelectCommand, sSelectLinePreviousString);
|
|
|
|
NS_REGISTER_NEXT_COMMAND(nsSelectCommand, sSelectLineNextString);
|
2011-12-24 04:11:30 +04:00
|
|
|
NS_REGISTER_NEXT_COMMAND(nsSelectCommand, sSelectPageUpString);
|
|
|
|
NS_REGISTER_NEXT_COMMAND(nsSelectCommand, sSelectPageDownString);
|
2005-02-18 10:29:40 +03:00
|
|
|
NS_REGISTER_NEXT_COMMAND(nsSelectCommand, sSelectTopString);
|
|
|
|
NS_REGISTER_LAST_COMMAND(nsSelectCommand, sSelectBottomString);
|
2014-11-22 17:39:04 +03:00
|
|
|
|
|
|
|
NS_REGISTER_FIRST_COMMAND(nsPhysicalSelectCommand, sSelectLeftString);
|
|
|
|
NS_REGISTER_NEXT_COMMAND(nsPhysicalSelectCommand, sSelectRightString);
|
|
|
|
NS_REGISTER_NEXT_COMMAND(nsPhysicalSelectCommand, sSelectUpString);
|
|
|
|
NS_REGISTER_NEXT_COMMAND(nsPhysicalSelectCommand, sSelectDownString);
|
|
|
|
NS_REGISTER_NEXT_COMMAND(nsPhysicalSelectCommand, sSelectLeft2String);
|
|
|
|
NS_REGISTER_NEXT_COMMAND(nsPhysicalSelectCommand, sSelectRight2String);
|
|
|
|
NS_REGISTER_NEXT_COMMAND(nsPhysicalSelectCommand, sSelectUp2String);
|
|
|
|
NS_REGISTER_LAST_COMMAND(nsPhysicalSelectCommand, sSelectDown2String);
|
2003-04-12 07:08:23 +04:00
|
|
|
|
2010-03-19 21:32:13 +03:00
|
|
|
NS_REGISTER_ONE_COMMAND(nsClipboardCommand, "cmd_cut");
|
|
|
|
NS_REGISTER_ONE_COMMAND(nsClipboardCommand, "cmd_copy");
|
|
|
|
NS_REGISTER_ONE_COMMAND(nsClipboardCommand, "cmd_paste");
|
2003-04-12 07:08:23 +04:00
|
|
|
NS_REGISTER_ONE_COMMAND(nsClipboardCopyLinkCommand, "cmd_copyLink");
|
|
|
|
NS_REGISTER_FIRST_COMMAND(nsClipboardImageCommands, sCopyImageLocationString);
|
2005-05-05 20:14:00 +04:00
|
|
|
NS_REGISTER_NEXT_COMMAND(nsClipboardImageCommands, sCopyImageContentsString);
|
|
|
|
NS_REGISTER_LAST_COMMAND(nsClipboardImageCommands, sCopyImageString);
|
2003-04-12 07:08:23 +04:00
|
|
|
NS_REGISTER_FIRST_COMMAND(nsClipboardSelectAllNoneCommands, sSelectAllString);
|
|
|
|
NS_REGISTER_LAST_COMMAND(nsClipboardSelectAllNoneCommands, sSelectNoneString);
|
|
|
|
|
2003-04-22 22:11:12 +04:00
|
|
|
NS_REGISTER_ONE_COMMAND(nsClipboardGetContentsCommand, "cmd_getContents");
|
|
|
|
|
2003-05-25 23:39:21 +04:00
|
|
|
#if 0 // Remove unless needed again, bug 204777
|
2003-04-15 23:55:10 +04:00
|
|
|
NS_REGISTER_ONE_COMMAND(nsGoBackCommand, "cmd_browserBack");
|
|
|
|
NS_REGISTER_ONE_COMMAND(nsGoForwardCommand, "cmd_browserForward");
|
2003-05-25 23:39:21 +04:00
|
|
|
#endif
|
2003-04-12 07:08:23 +04:00
|
|
|
|
2016-05-02 05:41:20 +03:00
|
|
|
NS_REGISTER_ONE_COMMAND(nsLookUpDictionaryCommand, "cmd_lookUpDictionary");
|
|
|
|
|
2003-04-12 07:08:23 +04:00
|
|
|
return rv;
|
|
|
|
}
|
2017-06-06 02:17:30 +03:00
|
|
|
|
2019-02-26 01:05:29 +03:00
|
|
|
/* static */
|
|
|
|
bool nsGlobalWindowCommands::FindScrollCommand(
|
2019-05-01 11:47:10 +03:00
|
|
|
const char* aCommandName, KeyboardScrollAction* aOutAction) {
|
2017-06-06 02:17:30 +03:00
|
|
|
// Search for a keyboard scroll action to do for this command in
|
|
|
|
// browseCommands and physicalBrowseCommands. Each command exists in only one
|
|
|
|
// of them, so the order we examine browseCommands and physicalBrowseCommands
|
|
|
|
// doesn't matter.
|
|
|
|
|
|
|
|
for (size_t i = 0; i < ArrayLength(browseCommands); i++) {
|
2019-05-01 11:47:10 +03:00
|
|
|
const BrowseCommand& cmd = browseCommands[i];
|
2017-06-06 02:17:30 +03:00
|
|
|
bool forward = !strcmp(aCommandName, cmd.forward);
|
|
|
|
bool reverse = !strcmp(aCommandName, cmd.reverse);
|
|
|
|
if (forward || reverse) {
|
|
|
|
*aOutAction = KeyboardScrollAction(cmd.scrollAction, forward);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t i = 0; i < ArrayLength(physicalBrowseCommands); i++) {
|
2019-05-01 11:47:10 +03:00
|
|
|
const PhysicalBrowseCommand& cmd = physicalBrowseCommands[i];
|
2017-06-06 02:17:30 +03:00
|
|
|
if (!strcmp(aCommandName, cmd.command)) {
|
|
|
|
int16_t dir = cmd.direction;
|
|
|
|
bool forward = (dir == nsISelectionController::MOVE_RIGHT ||
|
|
|
|
dir == nsISelectionController::MOVE_DOWN);
|
|
|
|
|
|
|
|
*aOutAction = KeyboardScrollAction(cmd.scrollAction, forward);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|