#ifndef TextFinder_h
#define TextFinder_h
-#include "WebFrame.h"
-
-#include "FrameLoaderClientImpl.h"
-#include "core/frame/LocalFrame.h"
+#include "core/editing/FindOptions.h"
#include "platform/geometry/FloatRect.h"
-#include "public/platform/WebFileSystemType.h"
-#include "wtf/Compiler.h"
-#include "wtf/HashSet.h"
-#include "wtf/OwnPtr.h"
-#include "wtf/RefCounted.h"
+#include "platform/heap/Handle.h"
+#include "public/platform/WebFloatPoint.h"
+#include "public/platform/WebFloatRect.h"
+#include "public/platform/WebRect.h"
+#include "public/web/WebFindOptions.h"
+#include "wtf/PassOwnPtr.h"
+#include "wtf/PassRefPtr.h"
+#include "wtf/Vector.h"
#include "wtf/text/WTFString.h"
namespace WebCore {
-class GraphicsContext;
-class HTMLInputElement;
-class HistoryItem;
-class IntSize;
-class KURL;
-class Node;
class Range;
-class SubstituteData;
-struct FrameLoadRequest;
-struct WindowFeatures;
}
namespace blink {
-class ChromePrintContext;
-class SharedWorkerRepositoryClientImpl;
-class WebDataSourceImpl;
-class WebInputElement;
-class WebFrameClient;
-class WebPerformance;
-class WebPluginContainerImpl;
-class WebView;
-class WebViewImpl;
-struct WebPrintParams;
+class WebLocalFrameImpl;
template <typename T> class WebVector;
-// Implementation of WebFrame, note that this is a reference counted object.
-class WebFrameImpl FINAL
- : public WebFrame
- , public RefCounted<WebFrameImpl> {
+class TextFinder {
public:
- // WebFrame methods:
- virtual void close() OVERRIDE;
- virtual WebString uniqueName() const OVERRIDE;
- virtual WebString assignedName() const OVERRIDE;
- virtual void setName(const WebString&) OVERRIDE;
- virtual WebVector<WebIconURL> iconURLs(int iconTypesMask) const OVERRIDE;
- virtual void setIsRemote(bool) OVERRIDE;
- virtual void setRemoteWebLayer(WebLayer*) OVERRIDE;
- virtual void setPermissionClient(WebPermissionClient*) OVERRIDE;
- virtual void setSharedWorkerRepositoryClient(WebSharedWorkerRepositoryClient*) OVERRIDE;
- virtual WebSize scrollOffset() const OVERRIDE;
- virtual void setScrollOffset(const WebSize&) OVERRIDE;
- virtual WebSize minimumScrollOffset() const OVERRIDE;
- virtual WebSize maximumScrollOffset() const OVERRIDE;
- virtual WebSize contentsSize() const OVERRIDE;
- virtual bool hasVisibleContent() const OVERRIDE;
- virtual WebRect visibleContentRect() const OVERRIDE;
- virtual bool hasHorizontalScrollbar() const OVERRIDE;
- virtual bool hasVerticalScrollbar() const OVERRIDE;
- virtual WebView* view() const OVERRIDE;
- virtual WebFrame* opener() const OVERRIDE;
- virtual void setOpener(WebFrame*) OVERRIDE;
- virtual void appendChild(WebFrame*) OVERRIDE;
- virtual void removeChild(WebFrame*) OVERRIDE;
- virtual WebFrame* parent() const OVERRIDE;
- virtual WebFrame* top() const OVERRIDE;
- virtual WebFrame* previousSibling() const OVERRIDE;
- virtual WebFrame* nextSibling() const OVERRIDE;
- virtual WebFrame* firstChild() const OVERRIDE;
- virtual WebFrame* lastChild() const OVERRIDE;
- virtual WebFrame* traversePrevious(bool wrap) const OVERRIDE;
- virtual WebFrame* traverseNext(bool wrap) const OVERRIDE;
- virtual WebFrame* findChildByName(const WebString&) const OVERRIDE;
- virtual WebFrame* findChildByExpression(const WebString&) const OVERRIDE;
- virtual WebDocument document() const OVERRIDE;
- virtual WebPerformance performance() const OVERRIDE;
- virtual NPObject* windowObject() const OVERRIDE;
- virtual void bindToWindowObject(const WebString& name, NPObject*) OVERRIDE;
- virtual void bindToWindowObject(const WebString& name, NPObject*, void*) OVERRIDE;
- virtual void executeScript(const WebScriptSource&) OVERRIDE;
- virtual void executeScriptInIsolatedWorld(
- int worldID, const WebScriptSource* sources, unsigned numSources,
- int extensionGroup) OVERRIDE;
- virtual void setIsolatedWorldSecurityOrigin(int worldID, const WebSecurityOrigin&) OVERRIDE;
- virtual void setIsolatedWorldContentSecurityPolicy(int worldID, const WebString&) OVERRIDE;
- virtual void addMessageToConsole(const WebConsoleMessage&) OVERRIDE;
- virtual void collectGarbage() OVERRIDE;
- virtual bool checkIfRunInsecureContent(const WebURL&) const OVERRIDE;
- virtual v8::Handle<v8::Value> executeScriptAndReturnValue(
- const WebScriptSource&) OVERRIDE;
- virtual void executeScriptInIsolatedWorld(
- int worldID, const WebScriptSource* sourcesIn, unsigned numSources,
- int extensionGroup, WebVector<v8::Local<v8::Value> >* results) OVERRIDE;
- virtual v8::Handle<v8::Value> callFunctionEvenIfScriptDisabled(
- v8::Handle<v8::Function>,
- v8::Handle<v8::Value>,
- int argc,
- v8::Handle<v8::Value> argv[]) OVERRIDE;
- virtual v8::Local<v8::Context> mainWorldScriptContext() const OVERRIDE;
- virtual void reload(bool ignoreCache) OVERRIDE;
- virtual void reloadWithOverrideURL(const WebURL& overrideUrl, bool ignoreCache) OVERRIDE;
- virtual void loadRequest(const WebURLRequest&) OVERRIDE;
- virtual void loadHistoryItem(const WebHistoryItem&, WebURLRequest::CachePolicy) OVERRIDE;
- virtual void loadData(
- const WebData&, const WebString& mimeType, const WebString& textEncoding,
- const WebURL& baseURL, const WebURL& unreachableURL, bool replace) OVERRIDE;
- virtual void loadHTMLString(
- const WebData& html, const WebURL& baseURL, const WebURL& unreachableURL,
- bool replace) OVERRIDE;
- virtual bool isLoading() const OVERRIDE;
- virtual void stopLoading() OVERRIDE;
- virtual WebDataSource* provisionalDataSource() const OVERRIDE;
- virtual WebDataSource* dataSource() const OVERRIDE;
- virtual WebHistoryItem previousHistoryItem() const OVERRIDE;
- virtual WebHistoryItem currentHistoryItem() const OVERRIDE;
- virtual void enableViewSourceMode(bool enable) OVERRIDE;
- virtual bool isViewSourceModeEnabled() const OVERRIDE;
- virtual void setReferrerForRequest(WebURLRequest&, const WebURL& referrer) OVERRIDE;
- virtual void dispatchWillSendRequest(WebURLRequest&) OVERRIDE;
- virtual WebURLLoader* createAssociatedURLLoader(const WebURLLoaderOptions&) OVERRIDE;
- virtual unsigned unloadListenerCount() const OVERRIDE;
- virtual void replaceSelection(const WebString&) OVERRIDE;
- virtual void insertText(const WebString&) OVERRIDE;
- virtual void setMarkedText(const WebString&, unsigned location, unsigned length) OVERRIDE;
- virtual void unmarkText() OVERRIDE;
- virtual bool hasMarkedText() const OVERRIDE;
- virtual WebRange markedRange() const OVERRIDE;
- virtual bool firstRectForCharacterRange(unsigned location, unsigned length, WebRect&) const OVERRIDE;
- virtual size_t characterIndexForPoint(const WebPoint&) const OVERRIDE;
- virtual bool executeCommand(const WebString&, const WebNode& = WebNode()) OVERRIDE;
- virtual bool executeCommand(const WebString&, const WebString& value, const WebNode& = WebNode()) OVERRIDE;
- virtual bool isCommandEnabled(const WebString&) const OVERRIDE;
- virtual void enableContinuousSpellChecking(bool) OVERRIDE;
- virtual bool isContinuousSpellCheckingEnabled() const OVERRIDE;
- virtual void requestTextChecking(const WebElement&) OVERRIDE;
- virtual void replaceMisspelledRange(const WebString&) OVERRIDE;
- virtual void removeSpellingMarkers() OVERRIDE;
- virtual bool hasSelection() const OVERRIDE;
- virtual WebRange selectionRange() const OVERRIDE;
- virtual WebString selectionAsText() const OVERRIDE;
- virtual WebString selectionAsMarkup() const OVERRIDE;
- virtual bool selectWordAroundCaret() OVERRIDE;
- virtual void selectRange(const WebPoint& base, const WebPoint& extent) OVERRIDE;
- virtual void selectRange(const WebRange&) OVERRIDE;
- virtual void moveRangeSelection(const WebPoint& base, const WebPoint& extent) OVERRIDE;
- virtual void moveCaretSelection(const WebPoint&) OVERRIDE;
- virtual void setCaretVisible(bool) OVERRIDE;
- virtual int printBegin(const WebPrintParams&, const WebNode& constrainToNode) OVERRIDE;
- virtual float printPage(int pageToPrint, WebCanvas*) OVERRIDE;
- virtual float getPrintPageShrink(int page) OVERRIDE;
- virtual void printEnd() OVERRIDE;
- virtual bool isPrintScalingDisabledForPlugin(const WebNode&) OVERRIDE;
- virtual bool hasCustomPageSizeStyle(int pageIndex) OVERRIDE;
- virtual bool isPageBoxVisible(int pageIndex) OVERRIDE;
- virtual void pageSizeAndMarginsInPixels(int pageIndex,
- WebSize& pageSize,
- int& marginTop,
- int& marginRight,
- int& marginBottom,
- int& marginLeft) OVERRIDE;
- virtual WebString pageProperty(const WebString& propertyName, int pageIndex) OVERRIDE;
- virtual void printPagesWithBoundaries(WebCanvas*, const WebSize&) OVERRIDE;
- virtual bool find(
+ static PassOwnPtr<TextFinder> create(WebLocalFrameImpl& ownerFrame);
+
+ bool find(
int identifier, const WebString& searchText, const WebFindOptions&,
- bool wrapWithinFrame, WebRect* selectionRect) OVERRIDE;
- virtual void stopFinding(bool clearSelection) OVERRIDE;
- virtual void scopeStringMatches(
+ bool wrapWithinFrame, WebRect* selectionRect);
+ void stopFindingAndClearSelection();
+ void scopeStringMatches(
int identifier, const WebString& searchText, const WebFindOptions&,
- bool reset) OVERRIDE;
- virtual void cancelPendingScopingEffort() OVERRIDE;
- virtual void increaseMatchCount(int count, int identifier) OVERRIDE;
- virtual void resetMatchCount() OVERRIDE;
- virtual int findMatchMarkersVersion() const OVERRIDE;
- virtual WebFloatRect activeFindMatchRect() OVERRIDE;
- virtual void findMatchRects(WebVector<WebFloatRect>&) OVERRIDE;
- virtual int selectNearestFindMatch(const WebFloatPoint&, WebRect* selectionRect) OVERRIDE;
-
- virtual void sendOrientationChangeEvent(int orientation) OVERRIDE;
-
- virtual void dispatchMessageEventWithOriginCheck(
- const WebSecurityOrigin& intendedTargetOrigin,
- const WebDOMEvent&) OVERRIDE;
-
- virtual WebString contentAsText(size_t maxChars) const OVERRIDE;
- virtual WebString contentAsMarkup() const OVERRIDE;
- virtual WebString renderTreeAsText(RenderAsTextControls toShow = RenderAsTextNormal) const OVERRIDE;
- virtual WebString markerTextForListItem(const WebElement&) const OVERRIDE;
- virtual WebRect selectionBoundsRect() const OVERRIDE;
-
- virtual bool selectionStartHasSpellingMarkerFor(int from, int length) const OVERRIDE;
- virtual WebString layerTreeAsText(bool showDebugInfo = false) const OVERRIDE;
-
- void willDetachParent();
-
- static WebFrameImpl* create(WebFrameClient*);
- virtual ~WebFrameImpl();
-
- // Called by the WebViewImpl to initialize the main frame for the page.
- void initializeAsMainFrame(WebCore::Page*);
-
- PassRefPtr<WebCore::LocalFrame> createChildFrame(
- const WebCore::FrameLoadRequest&, WebCore::HTMLFrameOwnerElement*);
-
- void didChangeContentsSize(const WebCore::IntSize&);
-
- void createFrameView();
-
- static WebFrameImpl* fromFrame(WebCore::LocalFrame* frame);
- static WebFrameImpl* fromFrameOwnerElement(WebCore::Element* element);
-
- // If the frame hosts a PluginDocument, this method returns the WebPluginContainerImpl
- // that hosts the plugin.
- static WebPluginContainerImpl* pluginContainerFromFrame(WebCore::LocalFrame*);
-
- // If the frame hosts a PluginDocument, this method returns the WebPluginContainerImpl
- // that hosts the plugin. If the provided node is a plugin, then it runs its
- // WebPluginContainerImpl.
- static WebPluginContainerImpl* pluginContainerFromNode(WebCore::LocalFrame*, const WebNode&);
-
- WebViewImpl* viewImpl() const;
-
- WebCore::FrameView* frameView() const { return frame() ? frame()->view() : 0; }
-
- // Getters for the impls corresponding to Get(Provisional)DataSource. They
- // may return 0 if there is no corresponding data source.
- WebDataSourceImpl* dataSourceImpl() const;
- WebDataSourceImpl* provisionalDataSourceImpl() const;
+ bool reset);
+ void cancelPendingScopingEffort();
+ void increaseMatchCount(int identifier, int count);
+ void resetMatchCount();
+ int findMatchMarkersVersion() const { return m_findMatchMarkersVersion; }
+ WebFloatRect activeFindMatchRect();
+ void findMatchRects(WebVector<WebFloatRect>&);
+ int selectNearestFindMatch(const WebFloatPoint&, WebRect* selectionRect);
// Returns which frame has an active match. This function should only be
// called on the main frame, as it is the only frame keeping track. Returned
// value can be 0 if no frame has an active match.
- WebFrameImpl* activeMatchFrame() const { return m_currentActiveMatchFrame; }
+ WebLocalFrameImpl* activeMatchFrame() const { return m_currentActiveMatchFrame; }
// Returns the active match in the current frame. Could be a null range if
// the local frame has no active match.
WebCore::Range* activeMatch() const { return m_activeMatch.get(); }
- // When a Find operation ends, we want to set the selection to what was active
- // and set focus to the first focusable node we find (starting with the first
- // node in the matched range and going up the inheritance chain). If we find
- // nothing to focus we focus the first focusable node in the range. This
- // allows us to set focus to a link (when we find text inside a link), which
- // allows us to navigate by pressing Enter after closing the Find box.
- void setFindEndstateFocusAndSelection();
-
- void didFail(const WebCore::ResourceError&, bool wasProvisional);
-
- // Sets whether the WebFrameImpl allows its document to be scrolled.
- // If the parameter is true, allow the document to be scrolled.
- // Otherwise, disallow scrolling.
- virtual void setCanHaveScrollbars(bool) OVERRIDE;
-
- WebCore::LocalFrame* frame() const { return m_frame.get(); }
- WebFrameClient* client() const { return m_client; }
- void setClient(WebFrameClient* client) { m_client = client; }
+ void flushCurrentScoping();
- WebPermissionClient* permissionClient() { return m_permissionClient; }
- SharedWorkerRepositoryClientImpl* sharedWorkerRepositoryClient() const { return m_sharedWorkerRepositoryClient.get(); }
+ void resetActiveMatch() { m_activeMatch = nullptr; }
- void setInputEventsTransformForEmulation(const WebCore::IntSize&, float);
+ int totalMatchCount() const { return m_totalMatchCount; }
+ bool scopingInProgress() const { return m_scopingInProgress; }
+ void increaseMarkerVersion() { ++m_findMatchMarkersVersion; }
- static void selectWordAroundPosition(WebCore::LocalFrame*, WebCore::VisiblePosition);
-
-private:
- class DeferredScopeStringMatches;
- friend class DeferredScopeStringMatches;
- friend class FrameLoaderClientImpl;
+ ~TextFinder();
- struct FindMatch {
- RefPtr<WebCore::Range> m_range;
+ class FindMatch {
+ ALLOW_ONLY_INLINE_ALLOCATION();
+ public:
+ RefPtrWillBeMember<WebCore::Range> m_range;
// 1-based index within this frame.
int m_ordinal;
// Lazily calculated by updateFindMatchRects.
WebCore::FloatRect m_rect;
- FindMatch(PassRefPtr<WebCore::Range>, int ordinal);
- };
+ FindMatch(PassRefPtrWillBeRawPtr<WebCore::Range>, int ordinal);
- // A bit mask specifying area of the frame to invalidate.
- enum AreaToInvalidate {
- InvalidateNothing,
- InvalidateContentArea,
- InvalidateScrollbar, // Vertical scrollbar only.
- InvalidateAll // Both content area and the scrollbar.
+ void trace(WebCore::Visitor*);
};
- explicit WebFrameImpl(WebFrameClient*);
+private:
+ class DeferredScopeStringMatches;
+ friend class DeferredScopeStringMatches;
- // Sets the local WebCore frame and registers destruction observers.
- void setWebCoreFrame(PassRefPtr<WebCore::LocalFrame>);
+ explicit TextFinder(WebLocalFrameImpl& ownerFrame);
// Notifies the delegate about a new selection rect.
void reportFindInPageSelection(
// Append the find-in-page match rects of the current frame to the provided vector.
void appendFindMatchRects(Vector<WebFloatRect>& frameRects);
- // Invalidates a certain area within the frame.
- void invalidateArea(AreaToInvalidate);
-
// Add a WebKit TextMatch-highlight marker to nodes in a range.
void addMarker(WebCore::Range*, bool activeMatch);
// function enumerates the frames, starting with the main frame and up to (but
// not including) the frame passed in as a parameter and counts how many
// matches have been found.
- int ordinalOfFirstMatchForFrame(WebFrameImpl*) const;
+ int ordinalOfFirstMatchForFrame(WebLocalFrameImpl*) const;
// Determines whether the scoping effort is required for a particular frame.
// It is not necessary if the frame is invisible, for example, or if this
// Determines whether to invalidate the content area and scrollbar.
void invalidateIfNecessary();
- void loadJavaScriptURL(const WebCore::KURL&);
-
- // Returns a hit-tested VisiblePosition for the given point
- WebCore::VisiblePosition visiblePositionForWindowPoint(const WebPoint&);
-
- FrameLoaderClientImpl m_frameLoaderClientImpl;
-
- // The embedder retains a reference to the WebCore LocalFrame while it is active in the DOM. This
- // reference is released when the frame is removed from the DOM or the entire page is closed.
- // FIXME: These will need to change to WebFrame when we introduce WebFrameProxy.
- RefPtr<WebCore::LocalFrame> m_frame;
- WebFrameImpl* m_parent;
- WebFrameImpl* m_previousSibling;
- WebFrameImpl* m_nextSibling;
- WebFrameImpl* m_firstChild;
- WebFrameImpl* m_lastChild;
+ // Sets the markers within a current match range as active or inactive.
+ void setMatchMarkerActive(bool);
- WebFrameImpl* m_opener;
- WTF::HashSet<WebFrameImpl*> m_openedFrames;
+ void decrementFramesScopingCount(int identifier);
- // Indicate whether the current LocalFrame is local or remote. Remote frames are
- // rendered in a different process from their parent frames.
- bool m_isRemote;
+ // Returns the ordinal of the first match in the owner frame.
+ int ordinalOfFirstMatch() const;
- WebFrameClient* m_client;
- WebPermissionClient* m_permissionClient;
- OwnPtr<SharedWorkerRepositoryClientImpl> m_sharedWorkerRepositoryClient;
+ WebLocalFrameImpl& m_ownerFrame;
// A way for the main frame to keep track of which frame has an active
// match. Should be 0 for all other frames.
- WebFrameImpl* m_currentActiveMatchFrame;
+ WebLocalFrameImpl* m_currentActiveMatchFrame;
// The range of the active match for the current frame.
- RefPtr<WebCore::Range> m_activeMatch;
+ RefPtrWillBePersistent<WebCore::Range> m_activeMatch;
// The index of the active match for the current frame.
int m_activeMatchIndexInCurrentFrame;
- // This flag is used by the scoping effort to determine if we need to figure
- // out which rectangle is the active match. Once we find the active
- // rectangle we clear this flag.
- bool m_locatingActiveRect;
-
// The scoping effort can time out and we need to keep track of where we
// ended our last search so we can continue from where we left of.
- RefPtr<WebCore::Range> m_resumeScopingFromRange;
+ //
+ // This range is collapsed to the start position of the last successful
+ // search; the new search should start from the next adjacent position.
+ RefPtrWillBePersistent<WebCore::Range> m_resumeScopingFromRange;
// Keeps track of the last string this frame searched for. This is used for
// short-circuiting searches in the following scenarios: When a frame has
// the frame in order to reply if required in case the frame is detached.
int m_findRequestIdentifier;
- // Keeps track of whether there is an scoping effort ongoing in the frame.
- bool m_scopingInProgress;
-
- // Keeps track of whether the last find request completed its scoping effort
- // without finding any matches in this frame.
- bool m_lastFindRequestCompletedWithNoMatches;
-
// Keeps track of when the scoping effort should next invalidate the scrollbar
// and the frame area.
int m_nextInvalidateAfter;
int m_findMatchMarkersVersion;
// Local cache of the find match markers currently displayed for this frame.
- Vector<FindMatch> m_findMatchesCache;
-
- // Determines if the rects in the find-in-page matches cache of this frame
- // are invalid and should be recomputed.
- bool m_findMatchRectsAreValid;
+ WillBePersistentHeapVector<FindMatch> m_findMatchesCache;
// Contents size when find-in-page match rects were last computed for this
// frame's cache.
WebCore::IntSize m_contentsSizeForCurrentFindMatchRects;
- // Valid between calls to BeginPrint() and EndPrint(). Containts the print
- // information. Is used by PrintPage().
- OwnPtr<ChromePrintContext> m_printContext;
+ // This flag is used by the scoping effort to determine if we need to figure
+ // out which rectangle is the active match. Once we find the active
+ // rectangle we clear this flag.
+ bool m_locatingActiveRect;
+
+ // Keeps track of whether there is an scoping effort ongoing in the frame.
+ bool m_scopingInProgress;
- // Stores the additional input events offset and scale when device metrics emulation is enabled.
- WebCore::IntSize m_inputEventsOffsetForEmulation;
- float m_inputEventsScaleFactorForEmulation;
-};
+ // Keeps track of whether the last find request completed its scoping effort
+ // without finding any matches in this frame.
+ bool m_lastFindRequestCompletedWithNoMatches;
-DEFINE_TYPE_CASTS(WebFrameImpl, WebFrame, frame, true, true);
+ // Determines if the rects in the find-in-page matches cache of this frame
+ // are invalid and should be recomputed.
+ bool m_findMatchRectsAreValid;
+};
} // namespace blink
+namespace WTF {
+template <> struct VectorTraits<blink::TextFinder::FindMatch> : VectorTraitsBase<blink::TextFinder::FindMatch> {
+ static const bool canInitializeWithMemset = true;
+};
+}
+
#endif