/* * Copyright 2006, The Android Open Source Project * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef WEBVIEWCORE_H #define WEBVIEWCORE_H #include "CacheBuilder.h" #include "CachedHistory.h" #include "DeviceMotionAndOrientationManager.h" #include "DOMSelection.h" #include "FileChooser.h" #include "PictureSet.h" #include "PlatformGraphicsContext.h" #include "SkColor.h" #include "SkTDArray.h" #include "SkRegion.h" #include "Timer.h" #include "WebCoreRefObject.h" #include "WebCoreJni.h" #include "WebRequestContext.h" #include "android_npapi.h" #include #include #include namespace WebCore { class Color; class FrameView; class HTMLAnchorElement; class HTMLElement; class HTMLImageElement; class HTMLSelectElement; class RenderPart; class RenderText; class Node; class PlatformKeyboardEvent; class QualifiedName; class RenderTextControl; class ScrollView; class TimerBase; class PageGroup; } #if USE(ACCELERATED_COMPOSITING) namespace WebCore { class GraphicsLayerAndroid; } #endif namespace WebCore { class BaseLayerAndroid; } struct PluginWidgetAndroid; class SkPicture; class SkIRect; namespace android { enum Direction { DIRECTION_BACKWARD = 0, DIRECTION_FORWARD = 1 }; enum NavigationAxis { AXIS_CHARACTER = 0, AXIS_WORD = 1, AXIS_SENTENCE = 2, AXIS_HEADING = 3, AXIS_SIBLING = 4, AXIS_PARENT_FIRST_CHILD = 5, AXIS_DOCUMENT = 6 }; class CachedFrame; class CachedNode; class CachedRoot; class ListBoxReply; class WebCoreReply : public WebCoreRefObject { public: virtual ~WebCoreReply() {} virtual void replyInt(int value) { SkDEBUGF(("WebCoreReply::replyInt(%d) not handled\n", value)); } virtual void replyIntArray(const int* array, int count) { SkDEBUGF(("WebCoreReply::replyIntArray() not handled\n")); } // add more replyFoo signatures as needed }; // one instance of WebViewCore per page for calling into Java's WebViewCore class WebViewCore : public WebCoreRefObject { public: /** * Initialize the native WebViewCore with a JNI environment, a Java * WebViewCore object and the main frame. */ WebViewCore(JNIEnv* env, jobject javaView, WebCore::Frame* mainframe); ~WebViewCore(); // helper function static WebViewCore* getWebViewCore(const WebCore::FrameView* view); static WebViewCore* getWebViewCore(const WebCore::ScrollView* view); // Followings are called from native WebCore to Java /** * Notification that a form was blurred. Pass a message to hide the * keyboard if it was showing for that Node. * @param Node The Node that blurred. */ void formDidBlur(const WebCore::Node*); void focusNodeChanged(const WebCore::Node*); /** * Scroll to an absolute position. * @param x The x coordinate. * @param y The y coordinate. * @param animate If it is true, animate to the new scroll position * * This method calls Java to trigger a gradual scroll event. */ void scrollTo(int x, int y, bool animate = false); /** * Scroll to the point x,y relative to the current position. * @param x The relative x position. * @param y The relative y position. * @param animate If it is true, animate to the new scroll position */ void scrollBy(int x, int y, bool animate); /** * Record the invalid rectangle */ void contentInvalidate(const WebCore::IntRect &rect); void contentInvalidateAll(); /** * Satisfy any outstanding invalidates, so that the current state * of the DOM is drawn. */ void contentDraw(); /** * copy the layers to the UI side */ void layersDraw(); #if USE(ACCELERATED_COMPOSITING) GraphicsLayerAndroid* graphicsRootLayer() const; #endif /** Invalidate the view/screen, NOT the content/DOM, but expressed in * content/DOM coordinates (i.e. they need to eventually be scaled, * by webview into view.java coordinates */ void viewInvalidate(const WebCore::IntRect& rect); /** * Invalidate part of the content that may be offscreen at the moment */ void offInvalidate(const WebCore::IntRect &rect); /** * Called by webcore when the progress indicator is done * used to rebuild and display any changes in focus */ void notifyProgressFinished(); /** * Notify the view that WebCore did its first layout. */ void didFirstLayout(); /** * Notify the view to update the viewport. */ void updateViewport(); /** * Notify the view to restore the screen width, which in turn restores * the scale. Also restore the scale for the text wrap. */ void restoreScale(float scale, float textWrapScale); /** * Tell the java side to update the focused textfield * @param pointer Pointer to the node for the input field. * @param changeToPassword If true, we are changing the textfield to * a password field, and ignore the String * @param text If changeToPassword is false, this is the new text that * should go into the textfield. */ void updateTextfield(WebCore::Node* pointer, bool changeToPassword, const WTF::String& text); /** * Tell the java side to update the current selection in the focused * textfield to the WebTextView. This function finds the currently * focused textinput, and passes its selection to java. * If there is no focus, or it is not a text input, this does nothing. */ void updateTextSelection(); void clearTextEntry(); // JavaScript support void jsAlert(const WTF::String& url, const WTF::String& text); bool jsConfirm(const WTF::String& url, const WTF::String& text); bool jsPrompt(const WTF::String& url, const WTF::String& message, const WTF::String& defaultValue, WTF::String& result); bool jsUnload(const WTF::String& url, const WTF::String& message); bool jsInterrupt(); /** * Tell the Java side that the origin has exceeded its database quota. * @param url The URL of the page that caused the quota overflow * @param databaseIdentifier the id of the database that caused the * quota overflow. * @param currentQuota The current quota for the origin * @param estimatedSize The estimated size of the database */ void exceededDatabaseQuota(const WTF::String& url, const WTF::String& databaseIdentifier, const unsigned long long currentQuota, const unsigned long long estimatedSize); /** * Tell the Java side that the appcache has exceeded its max size. * @param spaceNeeded is the amount of disk space that would be needed * in order for the last appcache operation to succeed. */ void reachedMaxAppCacheSize(const unsigned long long spaceNeeded); /** * Set up the PageGroup's idea of which links have been visited, * with the browser history. * @param group the object to deliver the links to. */ void populateVisitedLinks(WebCore::PageGroup*); /** * Instruct the browser to show a Geolocation permission prompt for the * specified origin. * @param origin The origin of the frame requesting Geolocation * permissions. */ void geolocationPermissionsShowPrompt(const WTF::String& origin); /** * Instruct the browser to hide the Geolocation permission prompt. */ void geolocationPermissionsHidePrompt(); jobject getDeviceMotionService(); jobject getDeviceOrientationService(); void addMessageToConsole(const String& message, unsigned int lineNumber, const String& sourceID, int msgLevel); /** * Tell the Java side of the scrollbar mode */ void setScrollbarModes(ScrollbarMode horizontalMode, ScrollbarMode verticalMode); // // Followings support calls from Java to native WebCore // WTF::String retrieveHref(int x, int y); WTF::String retrieveAnchorText(int x, int y); WTF::String retrieveImageSource(int x, int y); WTF::String requestLabel(WebCore::Frame* , WebCore::Node* ); // If the focus is a textfield (), textarea, or contentEditable, // scroll the selection on screen (if necessary). void revealSelection(); // Create a single picture to represent the drawn DOM (used by navcache) void recordPicture(SkPicture* picture); // Create a set of pictures to represent the drawn DOM, driven by // the invalidated region and the time required to draw (used to draw) void recordPictureSet(PictureSet* master); void moveFocus(WebCore::Frame* frame, WebCore::Node* node); void moveMouse(WebCore::Frame* frame, int x, int y); void moveMouseIfLatest(int moveGeneration, WebCore::Frame* frame, int x, int y); // set the scroll amount that webview.java is currently showing void setScrollOffset(int moveGeneration, int userScrolled, int dx, int dy); void setGlobalBounds(int x, int y, int h, int v); void setSizeScreenWidthAndScale(int width, int height, int screenWidth, float scale, int realScreenWidth, int screenHeight, int anchorX, int anchorY, bool ignoreHeight); /** * Handle key events from Java. * @return Whether keyCode was handled by this class. */ bool key(const WebCore::PlatformKeyboardEvent& event); /** * Handle (trackball) click event / dpad center press from Java. * Also used when typing into an unfocused textfield, in which case 'fake' * will be true. */ void click(WebCore::Frame* frame, WebCore::Node* node, bool fake); /** * Handle touch event */ bool handleTouchEvent(int action, Vector& ids, Vector& points, int metaState); /** * Handle motionUp event from the UI thread (called touchUp in the * WebCore thread). * @param touchGeneration Generation number for touches so we can ignore * touches when a newer one has been generated. * @param frame Pointer to Frame containing the node that was touched. * @param node Pointer to Node that was touched. * @param x x-position of the touch. * @param y y-position of the touch. * @param scrollY Only used for