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
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
#ifndef nsContentEventHandler_h__
|
|
|
|
#define nsContentEventHandler_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"
|
2013-09-24 03:04:14 -07:00
|
|
|
#include "mozilla/EventForwards.h"
|
2008-02-19 23:40:04 -08:00
|
|
|
|
2013-03-21 17:05:20 -07:00
|
|
|
class nsCaret;
|
|
|
|
class nsPresContext;
|
|
|
|
|
2008-02-19 23:40:04 -08:00
|
|
|
struct nsRect;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Query Content Event Handler
|
2009-02-10 12:56:51 -08:00
|
|
|
* nsContentEventHandler is a helper class for nsEventStateManager.
|
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.
|
|
|
|
*/
|
|
|
|
|
2013-04-11 20:20:09 -07:00
|
|
|
class MOZ_STACK_CLASS nsContentEventHandler {
|
2008-02-19 23:40:04 -08:00
|
|
|
public:
|
2009-02-10 12:56:51 -08:00
|
|
|
nsContentEventHandler(nsPresContext *aPresContext);
|
2008-02-19 23:40:04 -08:00
|
|
|
|
|
|
|
// NS_QUERY_SELECTED_TEXT event handler
|
2013-10-01 00:23:00 -07:00
|
|
|
nsresult OnQuerySelectedText(mozilla::WidgetQueryContentEvent* aEvent);
|
2008-02-19 23:40:04 -08:00
|
|
|
// NS_QUERY_TEXT_CONTENT event handler
|
2013-10-01 00:23:00 -07:00
|
|
|
nsresult OnQueryTextContent(mozilla::WidgetQueryContentEvent* aEvent);
|
2008-02-19 23:40:04 -08:00
|
|
|
// NS_QUERY_CARET_RECT event handler
|
2013-10-01 00:23:00 -07:00
|
|
|
nsresult OnQueryCaretRect(mozilla::WidgetQueryContentEvent* aEvent);
|
2009-02-10 12:56:51 -08:00
|
|
|
// NS_QUERY_TEXT_RECT event handler
|
2013-10-01 00:23:00 -07:00
|
|
|
nsresult OnQueryTextRect(mozilla::WidgetQueryContentEvent* aEvent);
|
2009-02-10 12:56:51 -08:00
|
|
|
// NS_QUERY_EDITOR_RECT event handler
|
2013-10-01 00:23:00 -07:00
|
|
|
nsresult OnQueryEditorRect(mozilla::WidgetQueryContentEvent* aEvent);
|
2009-03-17 19:04:01 -07:00
|
|
|
// NS_QUERY_CONTENT_STATE event handler
|
2013-10-01 00:23:00 -07:00
|
|
|
nsresult OnQueryContentState(mozilla::WidgetQueryContentEvent* aEvent);
|
2009-03-17 19:04:01 -07:00
|
|
|
// NS_QUERY_SELECTION_AS_TRANSFERABLE event handler
|
2013-10-01 00:23:00 -07:00
|
|
|
nsresult OnQuerySelectionAsTransferable(
|
|
|
|
mozilla::WidgetQueryContentEvent* aEvent);
|
2009-05-14 17:46:24 -07:00
|
|
|
// NS_QUERY_CHARACTER_AT_POINT event handler
|
2013-10-01 00:23:00 -07:00
|
|
|
nsresult OnQueryCharacterAtPoint(mozilla::WidgetQueryContentEvent* aEvent);
|
2011-03-01 13:15:23 -08:00
|
|
|
// NS_QUERY_DOM_WIDGET_HITTEST event handler
|
2013-10-01 00:23:00 -07:00
|
|
|
nsresult OnQueryDOMWidgetHittest(mozilla::WidgetQueryContentEvent* aEvent);
|
2009-02-10 12:56:51 -08:00
|
|
|
|
|
|
|
// NS_SELECTION_* event
|
2013-10-01 00:23:01 -07:00
|
|
|
nsresult OnSelectionEvent(mozilla::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;
|
|
|
|
|
2013-10-01 00:23:00 -07:00
|
|
|
nsresult Init(mozilla::WidgetQueryContentEvent* aEvent);
|
2013-10-01 00:23:01 -07:00
|
|
|
nsresult Init(mozilla::WidgetSelectionEvent* aEvent);
|
2010-03-18 22:02:53 -07:00
|
|
|
|
|
|
|
// InitCommon() is called from each Init().
|
|
|
|
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.
|
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
// Get the offset in FlatText of the range. (also used by nsIMEStateManager)
|
|
|
|
static nsresult GetFlatTextOffsetOfRange(nsIContent* aRootContent,
|
|
|
|
nsINode* aNode,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aNodeOffset,
|
|
|
|
uint32_t* aOffset);
|
2009-02-10 12:56:51 -08:00
|
|
|
static nsresult GetFlatTextOffsetOfRange(nsIContent* aRootContent,
|
2012-01-10 06:19:54 -08:00
|
|
|
nsRange* aRange,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t* aOffset);
|
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:
|
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,
|
|
|
|
mozilla::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,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aNativeOffset,
|
|
|
|
uint32_t aNativeLength,
|
2013-07-11 00:46:35 -07:00
|
|
|
bool aExpandToClusterBoundaries,
|
|
|
|
uint32_t* aNewNativeOffset = 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
|
|
|
};
|
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
#endif // nsContentEventHandler_h__
|