2008-02-20 07:40:04 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00: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 07:40:04 +00:00
|
|
|
|
2014-03-11 05:08:02 +00:00
|
|
|
#ifndef mozilla_ContentEventHandler_h_
|
|
|
|
#define mozilla_ContentEventHandler_h_
|
2008-02-20 07:40:04 +00:00
|
|
|
|
2014-03-11 05:08:02 +00:00
|
|
|
#include "mozilla/EventForwards.h"
|
2008-02-20 07:40:04 +00:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsISelection.h"
|
2012-01-10 14:19:54 +00:00
|
|
|
#include "nsRange.h"
|
2008-02-20 07:40:04 +00:00
|
|
|
|
2013-03-22 00:05:20 +00:00
|
|
|
class nsPresContext;
|
|
|
|
|
2008-02-20 07:40:04 +00:00
|
|
|
struct nsRect;
|
|
|
|
|
2014-03-11 05:08:02 +00:00
|
|
|
namespace mozilla {
|
|
|
|
|
2014-04-25 23:52:12 +00:00
|
|
|
enum LineBreakType
|
|
|
|
{
|
|
|
|
LINE_BREAK_TYPE_NATIVE,
|
|
|
|
LINE_BREAK_TYPE_XP
|
|
|
|
};
|
|
|
|
|
2008-02-20 07:40:04 +00:00
|
|
|
/*
|
|
|
|
* Query Content Event Handler
|
2014-04-01 04:09:23 +00:00
|
|
|
* ContentEventHandler is a helper class for EventStateManager.
|
2008-02-20 07:40:04 +00: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 05:08:02 +00:00
|
|
|
class MOZ_STACK_CLASS ContentEventHandler
|
|
|
|
{
|
2008-02-20 07:40:04 +00:00
|
|
|
public:
|
2014-03-11 05:08:02 +00:00
|
|
|
ContentEventHandler(nsPresContext* aPresContext);
|
2008-02-20 07:40:04 +00:00
|
|
|
|
|
|
|
// NS_QUERY_SELECTED_TEXT event handler
|
2014-03-11 05:08:02 +00:00
|
|
|
nsresult OnQuerySelectedText(WidgetQueryContentEvent* aEvent);
|
2008-02-20 07:40:04 +00:00
|
|
|
// NS_QUERY_TEXT_CONTENT event handler
|
2014-03-11 05:08:02 +00:00
|
|
|
nsresult OnQueryTextContent(WidgetQueryContentEvent* aEvent);
|
2008-02-20 07:40:04 +00:00
|
|
|
// NS_QUERY_CARET_RECT event handler
|
2014-03-11 05:08:02 +00:00
|
|
|
nsresult OnQueryCaretRect(WidgetQueryContentEvent* aEvent);
|
2009-02-10 20:56:51 +00:00
|
|
|
// NS_QUERY_TEXT_RECT event handler
|
2014-03-11 05:08:02 +00:00
|
|
|
nsresult OnQueryTextRect(WidgetQueryContentEvent* aEvent);
|
2009-02-10 20:56:51 +00:00
|
|
|
// NS_QUERY_EDITOR_RECT event handler
|
2014-03-11 05:08:02 +00:00
|
|
|
nsresult OnQueryEditorRect(WidgetQueryContentEvent* aEvent);
|
2009-03-18 02:04:01 +00:00
|
|
|
// NS_QUERY_CONTENT_STATE event handler
|
2014-03-11 05:08:02 +00:00
|
|
|
nsresult OnQueryContentState(WidgetQueryContentEvent* aEvent);
|
2009-03-18 02:04:01 +00:00
|
|
|
// NS_QUERY_SELECTION_AS_TRANSFERABLE event handler
|
2014-03-11 05:08:02 +00:00
|
|
|
nsresult OnQuerySelectionAsTransferable(WidgetQueryContentEvent* aEvent);
|
2009-05-15 00:46:24 +00:00
|
|
|
// NS_QUERY_CHARACTER_AT_POINT event handler
|
2014-03-11 05:08:02 +00:00
|
|
|
nsresult OnQueryCharacterAtPoint(WidgetQueryContentEvent* aEvent);
|
2011-03-01 21:15:23 +00:00
|
|
|
// NS_QUERY_DOM_WIDGET_HITTEST event handler
|
2014-03-11 05:08:02 +00:00
|
|
|
nsresult OnQueryDOMWidgetHittest(WidgetQueryContentEvent* aEvent);
|
2009-02-10 20:56:51 +00:00
|
|
|
|
|
|
|
// NS_SELECTION_* event
|
2014-03-11 05:08:02 +00:00
|
|
|
nsresult OnSelectionEvent(WidgetSelectionEvent* aEvent);
|
2009-02-10 20:56:51 +00:00
|
|
|
|
2008-02-20 07:40:04 +00:00
|
|
|
protected:
|
|
|
|
nsPresContext* mPresContext;
|
2010-08-05 14:42:02 +00:00
|
|
|
nsCOMPtr<nsIPresShell> mPresShell;
|
2008-02-20 07:40:04 +00:00
|
|
|
nsCOMPtr<nsISelection> mSelection;
|
2012-01-10 14:19:54 +00:00
|
|
|
nsRefPtr<nsRange> mFirstSelectedRange;
|
2008-02-20 07:40:04 +00:00
|
|
|
nsCOMPtr<nsIContent> mRootContent;
|
|
|
|
|
2014-03-11 05:08:02 +00:00
|
|
|
nsresult Init(WidgetQueryContentEvent* aEvent);
|
|
|
|
nsresult Init(WidgetSelectionEvent* aEvent);
|
2010-03-19 05:02:53 +00:00
|
|
|
|
2014-04-30 16:55:40 +00:00
|
|
|
nsresult InitBasic();
|
2010-03-19 05:02:53 +00:00
|
|
|
nsresult InitCommon();
|
2008-02-20 07:40:04 +00:00
|
|
|
|
2009-02-10 20:56:51 +00:00
|
|
|
public:
|
2008-02-20 07:40:04 +00: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 01:20:07 +00:00
|
|
|
// Get the offset in FlatText of the range. (also used by IMEContentObserver)
|
2009-02-10 20:56:51 +00:00
|
|
|
static nsresult GetFlatTextOffsetOfRange(nsIContent* aRootContent,
|
|
|
|
nsINode* aNode,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aNodeOffset,
|
2014-04-25 23:52:12 +00:00
|
|
|
uint32_t* aOffset,
|
|
|
|
LineBreakType aLineBreakType);
|
2009-02-10 20:56:51 +00:00
|
|
|
static nsresult GetFlatTextOffsetOfRange(nsIContent* aRootContent,
|
2012-01-10 14:19:54 +00:00
|
|
|
nsRange* aRange,
|
2014-04-25 23:52:12 +00:00
|
|
|
uint32_t* aOffset,
|
|
|
|
LineBreakType aLineBreakType);
|
2012-12-05 16:09:56 +00:00
|
|
|
// Get the native text length of a content node excluding any children
|
|
|
|
static uint32_t GetNativeTextLength(nsIContent* aContent,
|
|
|
|
uint32_t aMaxLength = UINT32_MAX);
|
2009-02-10 20:56:51 +00:00
|
|
|
protected:
|
2014-04-25 23:52:12 +00: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 01:43:11 +00: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 05:08:02 +00:00
|
|
|
WidgetQueryContentEvent* aEvent);
|
2008-02-20 07:40:04 +00: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 14:19:54 +00:00
|
|
|
nsresult SetRangeFromFlatTextOffset(nsRange* aRange,
|
2014-04-25 23:52:13 +00:00
|
|
|
uint32_t aOffset,
|
|
|
|
uint32_t aLength,
|
2014-04-25 23:52:12 +00:00
|
|
|
LineBreakType aLineBreakType,
|
2013-07-11 07:46:35 +00:00
|
|
|
bool aExpandToClusterBoundaries,
|
2014-04-25 23:52:13 +00:00
|
|
|
uint32_t* aNewOffset = nullptr);
|
2008-02-20 07:40:04 +00:00
|
|
|
// Find the first textframe for the range, and get the start offset in
|
|
|
|
// the frame.
|
2012-01-10 14:19:54 +00:00
|
|
|
nsresult GetStartFrameAndOffset(nsRange* aRange,
|
2009-02-10 20:56:51 +00:00
|
|
|
nsIFrame** aFrame,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t* aOffsetInFrame);
|
2008-02-20 07:40:04 +00:00
|
|
|
// Convert the frame relative offset to the root view relative offset.
|
2009-02-10 20:56:51 +00:00
|
|
|
nsresult ConvertToRootViewRelativeOffset(nsIFrame* aFrame,
|
|
|
|
nsRect& aRect);
|
2008-02-20 07:40:04 +00:00
|
|
|
// Expand aXPOffset to the nearest offset in cluster boundary. aForward is
|
|
|
|
// true, it is expanded to forward.
|
2011-09-29 06:19:26 +00:00
|
|
|
nsresult ExpandToClusterBoundary(nsIContent* aContent, bool aForward,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t* aXPOffset);
|
2008-02-20 07:40:04 +00:00
|
|
|
};
|
|
|
|
|
2014-03-11 05:08:02 +00:00
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_ContentEventHandler_h_
|