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