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/. */
|
2008-02-20 10:40:04 +03:00
|
|
|
|
2014-03-11 09:08:02 +04:00
|
|
|
#ifndef mozilla_ContentEventHandler_h_
|
|
|
|
#define mozilla_ContentEventHandler_h_
|
2008-02-20 10:40:04 +03:00
|
|
|
|
2014-03-11 09:08:02 +04:00
|
|
|
#include "mozilla/EventForwards.h"
|
2015-07-01 18:41:17 +03:00
|
|
|
#include "mozilla/dom/Selection.h"
|
2008-02-20 10:40:04 +03:00
|
|
|
#include "nsCOMPtr.h"
|
2012-01-10 18:19:54 +04:00
|
|
|
#include "nsRange.h"
|
2008-02-20 10:40:04 +03:00
|
|
|
|
2013-03-22 04:05:20 +04:00
|
|
|
class nsPresContext;
|
|
|
|
|
2008-02-20 10:40:04 +03:00
|
|
|
struct nsRect;
|
|
|
|
|
2014-03-11 09:08:02 +04:00
|
|
|
namespace mozilla {
|
|
|
|
|
2014-04-26 03:52:12 +04:00
|
|
|
enum LineBreakType
|
|
|
|
{
|
|
|
|
LINE_BREAK_TYPE_NATIVE,
|
|
|
|
LINE_BREAK_TYPE_XP
|
|
|
|
};
|
|
|
|
|
2008-02-20 10:40:04 +03:00
|
|
|
/*
|
|
|
|
* Query Content Event Handler
|
2014-04-01 08:09:23 +04:00
|
|
|
* ContentEventHandler is a helper class for EventStateManager.
|
2008-02-20 10:40:04 +03:00
|
|
|
* The platforms request some content informations, e.g., the selected text,
|
|
|
|
* the offset of the selected text and the text for specified range.
|
|
|
|
* This class answers to NS_QUERY_* events from actual contents.
|
|
|
|
*/
|
|
|
|
|
2014-03-11 09:08:02 +04:00
|
|
|
class MOZ_STACK_CLASS ContentEventHandler
|
|
|
|
{
|
2008-02-20 10:40:04 +03:00
|
|
|
public:
|
2015-07-01 18:41:17 +03:00
|
|
|
typedef dom::Selection Selection;
|
|
|
|
|
2014-09-02 02:26:43 +04:00
|
|
|
explicit ContentEventHandler(nsPresContext* aPresContext);
|
2008-02-20 10:40:04 +03:00
|
|
|
|
2015-09-08 06:54:14 +03:00
|
|
|
// Handle aEvent in the current process.
|
|
|
|
nsresult HandleQueryContentEvent(WidgetQueryContentEvent* aEvent);
|
|
|
|
|
2015-09-10 04:40:05 +03:00
|
|
|
// eQuerySelectedText event handler
|
2014-03-11 09:08:02 +04:00
|
|
|
nsresult OnQuerySelectedText(WidgetQueryContentEvent* aEvent);
|
2015-09-10 04:40:05 +03:00
|
|
|
// eQueryTextContent event handler
|
2014-03-11 09:08:02 +04:00
|
|
|
nsresult OnQueryTextContent(WidgetQueryContentEvent* aEvent);
|
2015-09-10 04:40:06 +03:00
|
|
|
// eQueryCaretRect event handler
|
2014-03-11 09:08:02 +04:00
|
|
|
nsresult OnQueryCaretRect(WidgetQueryContentEvent* aEvent);
|
2015-09-11 15:21:26 +03:00
|
|
|
// eQueryTextRect event handler
|
2014-03-11 09:08:02 +04:00
|
|
|
nsresult OnQueryTextRect(WidgetQueryContentEvent* aEvent);
|
2015-09-10 04:40:06 +03:00
|
|
|
// eQueryEditorRect event handler
|
2014-03-11 09:08:02 +04:00
|
|
|
nsresult OnQueryEditorRect(WidgetQueryContentEvent* aEvent);
|
2015-09-10 04:40:06 +03:00
|
|
|
// eQueryContentState event handler
|
2014-03-11 09:08:02 +04:00
|
|
|
nsresult OnQueryContentState(WidgetQueryContentEvent* aEvent);
|
2015-09-10 04:40:05 +03:00
|
|
|
// eQuerySelectionAsTransferable event handler
|
2014-03-11 09:08:02 +04:00
|
|
|
nsresult OnQuerySelectionAsTransferable(WidgetQueryContentEvent* aEvent);
|
2015-09-10 04:40:06 +03:00
|
|
|
// eQueryCharacterAtPoint event handler
|
2014-03-11 09:08:02 +04:00
|
|
|
nsresult OnQueryCharacterAtPoint(WidgetQueryContentEvent* aEvent);
|
2015-09-10 04:40:06 +03:00
|
|
|
// eQueryDOMWidgetHittest event handler
|
2014-03-11 09:08:02 +04:00
|
|
|
nsresult OnQueryDOMWidgetHittest(WidgetQueryContentEvent* aEvent);
|
2009-02-10 23:56:51 +03:00
|
|
|
|
|
|
|
// NS_SELECTION_* event
|
2014-03-11 09:08:02 +04:00
|
|
|
nsresult OnSelectionEvent(WidgetSelectionEvent* aEvent);
|
2009-02-10 23:56:51 +03:00
|
|
|
|
2008-02-20 10:40:04 +03:00
|
|
|
protected:
|
|
|
|
nsPresContext* mPresContext;
|
2010-08-05 18:42:02 +04:00
|
|
|
nsCOMPtr<nsIPresShell> mPresShell;
|
2015-07-01 18:41:17 +03:00
|
|
|
nsRefPtr<Selection> mSelection;
|
2012-01-10 18:19:54 +04:00
|
|
|
nsRefPtr<nsRange> mFirstSelectedRange;
|
2008-02-20 10:40:04 +03:00
|
|
|
nsCOMPtr<nsIContent> mRootContent;
|
|
|
|
|
2014-03-11 09:08:02 +04:00
|
|
|
nsresult Init(WidgetQueryContentEvent* aEvent);
|
|
|
|
nsresult Init(WidgetSelectionEvent* aEvent);
|
2010-03-19 08:02:53 +03:00
|
|
|
|
2014-04-30 20:55:40 +04:00
|
|
|
nsresult InitBasic();
|
2010-03-19 08:02:53 +03:00
|
|
|
nsresult InitCommon();
|
2008-02-20 10:40:04 +03:00
|
|
|
|
2009-02-10 23:56:51 +03:00
|
|
|
public:
|
2008-02-20 10:40:04 +03:00
|
|
|
// FlatText means the text that is generated from DOM tree. The BR elements
|
|
|
|
// are replaced to native linefeeds. Other elements are ignored.
|
|
|
|
|
2014-03-08 05:20:07 +04:00
|
|
|
// Get the offset in FlatText of the range. (also used by IMEContentObserver)
|
2009-02-10 23:56:51 +03:00
|
|
|
static nsresult GetFlatTextOffsetOfRange(nsIContent* aRootContent,
|
|
|
|
nsINode* aNode,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aNodeOffset,
|
2014-04-26 03:52:12 +04:00
|
|
|
uint32_t* aOffset,
|
|
|
|
LineBreakType aLineBreakType);
|
2009-02-10 23:56:51 +03:00
|
|
|
static nsresult GetFlatTextOffsetOfRange(nsIContent* aRootContent,
|
2012-01-10 18:19:54 +04:00
|
|
|
nsRange* aRange,
|
2014-04-26 03:52:12 +04:00
|
|
|
uint32_t* aOffset,
|
|
|
|
LineBreakType aLineBreakType);
|
2014-07-31 08:38:01 +04:00
|
|
|
// Computes the native text length between aStartOffset and aEndOffset of
|
|
|
|
// aContent. Currently, this method supports only text node or br element
|
|
|
|
// for aContent.
|
|
|
|
static uint32_t GetNativeTextLength(nsIContent* aContent,
|
|
|
|
uint32_t aStartOffset,
|
|
|
|
uint32_t aEndOffset);
|
2012-12-05 20:09:56 +04:00
|
|
|
// Get the native text length of a content node excluding any children
|
|
|
|
static uint32_t GetNativeTextLength(nsIContent* aContent,
|
|
|
|
uint32_t aMaxLength = UINT32_MAX);
|
2015-01-31 10:17:12 +03:00
|
|
|
// Get the text length of a given range of a content node in
|
|
|
|
// the given line break type.
|
|
|
|
static uint32_t GetTextLengthInRange(nsIContent* aContent,
|
|
|
|
uint32_t aXPStartOffset,
|
|
|
|
uint32_t aXPEndOffset,
|
|
|
|
LineBreakType aLineBreakType);
|
2009-02-10 23:56:51 +03:00
|
|
|
protected:
|
2014-04-26 03:52:12 +04:00
|
|
|
static uint32_t GetTextLength(nsIContent* aContent,
|
|
|
|
LineBreakType aLineBreakType,
|
|
|
|
uint32_t aMaxLength = UINT32_MAX);
|
|
|
|
static LineBreakType GetLineBreakType(WidgetQueryContentEvent* aEvent);
|
|
|
|
static LineBreakType GetLineBreakType(WidgetSelectionEvent* aEvent);
|
|
|
|
static LineBreakType GetLineBreakType(bool aUseNativeLineBreak);
|
2013-12-18 05:43:11 +04:00
|
|
|
// Returns focused content (including its descendant documents).
|
|
|
|
nsIContent* GetFocusedContent();
|
|
|
|
// Returns true if the content is a plugin host.
|
|
|
|
bool IsPlugin(nsIContent* aContent);
|
|
|
|
// QueryContentRect() sets the rect of aContent's frame(s) to aEvent.
|
|
|
|
nsresult QueryContentRect(nsIContent* aContent,
|
2014-03-11 09:08:02 +04:00
|
|
|
WidgetQueryContentEvent* aEvent);
|
2008-02-20 10:40:04 +03:00
|
|
|
// Make the DOM range from the offset of FlatText and the text length.
|
|
|
|
// If aExpandToClusterBoundaries is true, the start offset and the end one are
|
|
|
|
// expanded to nearest cluster boundaries.
|
2012-01-10 18:19:54 +04:00
|
|
|
nsresult SetRangeFromFlatTextOffset(nsRange* aRange,
|
2014-04-26 03:52:13 +04:00
|
|
|
uint32_t aOffset,
|
|
|
|
uint32_t aLength,
|
2014-04-26 03:52:12 +04:00
|
|
|
LineBreakType aLineBreakType,
|
2013-07-11 11:46:35 +04:00
|
|
|
bool aExpandToClusterBoundaries,
|
2014-04-26 03:52:13 +04:00
|
|
|
uint32_t* aNewOffset = nullptr);
|
2015-06-04 04:09:56 +03:00
|
|
|
// If the aRange isn't in text node but next to a text node, this method
|
|
|
|
// modifies it in the text node. Otherwise, not modified.
|
|
|
|
nsresult AdjustCollapsedRangeMaybeIntoTextNode(nsRange* aCollapsedRange);
|
|
|
|
// Find the first frame for the range and get the start offset in it.
|
|
|
|
nsresult GetStartFrameAndOffset(const nsRange* aRange,
|
|
|
|
nsIFrame*& aFrame,
|
|
|
|
int32_t& aOffsetInFrame);
|
2015-10-05 08:46:39 +03:00
|
|
|
// Convert the frame relative offset to the root frame of the root presContext
|
|
|
|
// relative offset.
|
|
|
|
nsresult ConvertToRootRelativeOffset(nsIFrame* aFrame,
|
|
|
|
nsRect& aRect);
|
2008-02-20 10:40:04 +03:00
|
|
|
// Expand aXPOffset to the nearest offset in cluster boundary. aForward is
|
|
|
|
// true, it is expanded to forward.
|
2011-09-29 10:19:26 +04:00
|
|
|
nsresult ExpandToClusterBoundary(nsIContent* aContent, bool aForward,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t* aXPOffset);
|
2015-01-31 10:17:12 +03:00
|
|
|
|
|
|
|
typedef nsTArray<mozilla::FontRange> FontRangeArray;
|
|
|
|
static void AppendFontRanges(FontRangeArray& aFontRanges,
|
|
|
|
nsIContent* aContent,
|
|
|
|
int32_t aBaseOffset,
|
|
|
|
int32_t aXPStartOffset,
|
|
|
|
int32_t aXPEndOffset,
|
|
|
|
LineBreakType aLineBreakType);
|
|
|
|
static nsresult GenerateFlatFontRanges(nsRange* aRange,
|
|
|
|
FontRangeArray& aFontRanges,
|
|
|
|
uint32_t& aLength,
|
|
|
|
LineBreakType aLineBreakType);
|
2008-02-20 10:40:04 +03:00
|
|
|
};
|
|
|
|
|
2014-03-11 09:08:02 +04:00
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_ContentEventHandler_h_
|