1 /* 2 * Copyright 2006, The Android Open Source Project 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * * Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * * Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26 #ifndef WebViewCore_h 27 #define WebViewCore_h 28 29 #include "DeviceMotionAndOrientationManager.h" 30 #include "DOMSelection.h" 31 #include "FileChooser.h" 32 #include "FocusDirection.h" 33 #include "HitTestResult.h" 34 #include "PicturePile.h" 35 #include "PlatformGraphicsContext.h" 36 #include "Position.h" 37 #include "ScrollTypes.h" 38 #include "SkColor.h" 39 #include "SkTDArray.h" 40 #include "SkRegion.h" 41 #include "Text.h" 42 #include "Timer.h" 43 #include "WebCoreRefObject.h" 44 #include "WebCoreJni.h" 45 #include "WebRequestContext.h" 46 #include "android_npapi.h" 47 #include "VisiblePosition.h" 48 #include "SelectText.h" 49 50 #include <jni.h> 51 #include <androidfw/KeycodeLabels.h> 52 #include <ui/PixelFormat.h> 53 #include <utils/threads.h> 54 #include <wtf/Threading.h> 55 56 namespace WebCore { 57 class Color; 58 class GraphicsOperationCollection; 59 class FrameView; 60 class HTMLAnchorElement; 61 class HTMLElement; 62 class HTMLImageElement; 63 class HTMLSelectElement; 64 class RenderPart; 65 class RenderText; 66 class Node; 67 class PlatformKeyboardEvent; 68 class QualifiedName; 69 class RenderTextControl; 70 class ScrollView; 71 class TimerBase; 72 class PageGroup; 73 } 74 75 #if USE(ACCELERATED_COMPOSITING) 76 namespace WebCore { 77 class GraphicsLayerAndroid; 78 class LayerAndroid; 79 } 80 #endif 81 82 namespace WebCore { 83 class BaseLayerAndroid; 84 } 85 86 struct PluginWidgetAndroid; 87 class SkPicture; 88 class SkIRect; 89 90 namespace android { 91 92 enum Direction { 93 DIRECTION_BACKWARD = 0, 94 DIRECTION_FORWARD = 1 95 }; 96 97 enum NavigationAxis { 98 AXIS_CHARACTER = 0, 99 AXIS_WORD = 1, 100 AXIS_SENTENCE = 2, 101 AXIS_HEADING = 3, 102 AXIS_SIBLING = 4, 103 AXIS_PARENT_FIRST_CHILD = 5, 104 AXIS_DOCUMENT = 6 105 }; 106 107 class ListBoxReply; 108 class AndroidHitTestResult; 109 110 class WebCoreReply : public WebCoreRefObject { 111 public: 112 virtual ~WebCoreReply() {} 113 114 virtual void replyInt(int value) { 115 SkDEBUGF(("WebCoreReply::replyInt(%d) not handled\n", value)); 116 } 117 118 virtual void replyIntArray(const int* array, int count) { 119 SkDEBUGF(("WebCoreReply::replyIntArray() not handled\n")); 120 } 121 // add more replyFoo signatures as needed 122 }; 123 124 // one instance of WebViewCore per page for calling into Java's WebViewCore 125 class WebViewCore : public WebCoreRefObject, public WebCore::PicturePainter { 126 public: 127 /** 128 * Initialize the native WebViewCore with a JNI environment, a Java 129 * WebViewCore object and the main frame. 130 */ 131 WebViewCore(JNIEnv* env, jobject javaView, WebCore::Frame* mainframe); 132 ~WebViewCore(); 133 134 // helper function 135 static WebViewCore* getWebViewCore(const WebCore::FrameView* view); 136 static WebViewCore* getWebViewCore(const WebCore::ScrollView* view); 137 138 // Followings are called from native WebCore to Java 139 140 void focusNodeChanged(WebCore::Node*); 141 142 /** 143 * Scroll to an absolute position. 144 * @param x The x coordinate. 145 * @param y The y coordinate. 146 * @param animate If it is true, animate to the new scroll position 147 * 148 * This method calls Java to trigger a gradual scroll event. 149 */ 150 void scrollTo(int x, int y, bool animate = false); 151 152 /** 153 * Record the invalid rectangle 154 */ 155 void contentInvalidate(const WebCore::IntRect &rect); 156 void contentInvalidateAll(); 157 158 /** 159 * Satisfy any outstanding invalidates, so that the current state 160 * of the DOM is drawn. 161 */ 162 void contentDraw(); 163 164 #if USE(ACCELERATED_COMPOSITING) 165 WebCore::GraphicsLayerAndroid* graphicsRootLayer() const; 166 #endif 167 168 /** Invalidate the view/screen, NOT the content/DOM, but expressed in 169 * content/DOM coordinates (i.e. they need to eventually be scaled, 170 * by webview into view.java coordinates 171 */ 172 void viewInvalidate(const WebCore::IntRect& rect); 173 174 /** 175 * Invalidate part of the content that may be offscreen at the moment 176 */ 177 void offInvalidate(const WebCore::IntRect &rect); 178 179 /** 180 * Called by webcore when the progress indicator is done 181 * used to rebuild and display any changes in focus 182 */ 183 void notifyProgressFinished(); 184 185 /** 186 * Notify the view that WebCore did its first layout. 187 */ 188 void didFirstLayout(); 189 190 /** 191 * Notify the view to update the viewport. 192 */ 193 void updateViewport(); 194 195 /** 196 * Notify the view to restore the screen width, which in turn restores 197 * the scale. Also restore the scale for the text wrap. 198 */ 199 void restoreScale(float scale, float textWrapScale); 200 201 /** 202 * Tell the java side to update the focused textfield 203 * @param pointer Pointer to the node for the input field. 204 * @param changeToPassword If true, we are changing the textfield to 205 * a password field, and ignore the WTF::String 206 * @param text If changeToPassword is false, this is the new text that 207 * should go into the textfield. 208 */ 209 void updateTextfield(WebCore::Node* pointer, 210 bool changeToPassword, const WTF::String& text); 211 212 /** 213 * Tell the java side to update the current selection in the focused 214 * textfield to the WebTextView. This function finds the currently 215 * focused textinput, and passes its selection to java. 216 * If there is no focus, or it is not a text input, this does nothing. 217 */ 218 void updateTextSelection(); 219 220 /** 221 * Updates the java side with the node's content size and scroll 222 * position. 223 */ 224 void updateTextSizeAndScroll(WebCore::Node* node); 225 226 void clearTextEntry(); 227 // JavaScript support 228 void jsAlert(const WTF::String& url, const WTF::String& text); 229 bool jsConfirm(const WTF::String& url, const WTF::String& text); 230 bool jsPrompt(const WTF::String& url, const WTF::String& message, 231 const WTF::String& defaultValue, WTF::String& result); 232 bool jsUnload(const WTF::String& url, const WTF::String& message); 233 bool jsInterrupt(); 234 235 /** 236 * Posts a message to the UI thread to inform the Java side that the 237 * origin has exceeded its database quota. 238 * @param url The URL of the page that caused the quota overflow 239 * @param databaseIdentifier the id of the database that caused the 240 * quota overflow. 241 * @param currentQuota The current quota for the origin 242 * @param estimatedSize The estimated size of the database 243 * @return Whether the message was successfully sent. 244 */ 245 bool exceededDatabaseQuota(const WTF::String& url, 246 const WTF::String& databaseIdentifier, 247 const unsigned long long currentQuota, 248 const unsigned long long estimatedSize); 249 250 /** 251 * Posts a message to the UI thread to inform the Java side that the 252 * appcache has exceeded its max size. 253 * @param spaceNeeded is the amount of disk space that would be needed 254 * in order for the last appcache operation to succeed. 255 * @return Whether the message was successfully sent. 256 */ 257 bool reachedMaxAppCacheSize(const unsigned long long spaceNeeded); 258 259 /** 260 * Set up the PageGroup's idea of which links have been visited, 261 * with the browser history. 262 * @param group the object to deliver the links to. 263 */ 264 void populateVisitedLinks(WebCore::PageGroup*); 265 266 /** 267 * Instruct the browser to show a Geolocation permission prompt for the 268 * specified origin. 269 * @param origin The origin of the frame requesting Geolocation 270 * permissions. 271 */ 272 void geolocationPermissionsShowPrompt(const WTF::String& origin); 273 /** 274 * Instruct the browser to hide the Geolocation permission prompt. 275 */ 276 void geolocationPermissionsHidePrompt(); 277 278 jobject getDeviceMotionService(); 279 jobject getDeviceOrientationService(); 280 281 void addMessageToConsole(const WTF::String& message, unsigned int lineNumber, const WTF::String& sourceID, int msgLevel); 282 283 /** 284 * Tell the Java side of the scrollbar mode 285 */ 286 void setScrollbarModes(WebCore::ScrollbarMode horizontalMode, 287 WebCore::ScrollbarMode verticalMode); 288 289 // 290 // Followings support calls from Java to native WebCore 291 // 292 293 WTF::String retrieveHref(int x, int y); 294 WTF::String retrieveAnchorText(int x, int y); 295 WTF::String retrieveImageSource(int x, int y); 296 WTF::String requestLabel(WebCore::Frame* , WebCore::Node* ); 297 298 // If the focus is a textfield (<input>), textarea, or contentEditable, 299 // scroll the selection on screen (if necessary). 300 void revealSelection(); 301 302 void moveMouse(int x, int y, WebCore::HitTestResult* hoveredNode = 0, 303 bool isClickCandidate = false); 304 305 // set the scroll amount that webview.java is currently showing 306 void setScrollOffset(bool sendScrollEvent, int dx, int dy); 307 308 void setGlobalBounds(int x, int y, int h, int v); 309 310 void setSizeScreenWidthAndScale(int width, int height, int screenWidth, 311 float scale, int realScreenWidth, int screenHeight, int anchorX, 312 int anchorY, bool ignoreHeight); 313 314 /** 315 * Handle key events from Java. 316 * @return Whether keyCode was handled by this class. 317 */ 318 bool key(const WebCore::PlatformKeyboardEvent& event); 319 bool chromeCanTakeFocus(WebCore::FocusDirection direction); 320 void chromeTakeFocus(WebCore::FocusDirection direction); 321 void setInitialFocus(const WebCore::PlatformKeyboardEvent& event); 322 323 /** 324 * Handle touch event 325 * Returns an int with the following flags: 326 * bit 0: hit an event handler 327 * bit 1: preventDefault was called 328 */ 329 int handleTouchEvent(int action, WTF::Vector<int>& ids, 330 WTF::Vector<WebCore::IntPoint>& points, 331 int actionIndex, int metaState); 332 333 /** 334 * Clicks the mouse at its current location 335 */ 336 bool performMouseClick(); 337 338 /** 339 * Sets the index of the label from a popup 340 */ 341 void popupReply(int index); 342 void popupReply(const int* array, int count); 343 344 /** 345 * Delete text from start to end in the focused textfield. 346 * If start == end, set the selection, but perform no deletion. 347 * If there is no focus, silently fail. 348 * If start and end are out of order, swap them. 349 */ 350 void deleteSelection(int start, int end, int textGeneration); 351 352 /** 353 * Set the selection of the currently focused textfield to (start, end). 354 * If start and end are out of order, swap them. 355 */ 356 void setSelection(int start, int end); 357 358 /** 359 * Modifies the current selection. 360 * 361 * Note: Accessibility support. 362 * 363 * direction - The direction in which to alter the selection. 364 * granularity - The granularity of the selection modification. 365 * 366 * returns - The selected HTML as a WTF::String. This is not a well formed 367 * HTML, rather the selection annotated with the tags of all 368 * intermediary elements it crosses. 369 */ 370 WTF::String modifySelection(const int direction, const int granularity); 371 372 /** 373 * Moves the selection to the given node in a given frame i.e. selects that node. 374 * 375 * Note: Accessibility support. 376 * 377 * frame - The frame in which to select is the node to be selected. 378 * node - The node to be selected. 379 * 380 * returns - The selected HTML as a WTF::String. This is not a well formed 381 * HTML, rather the selection annotated with the tags of all 382 * intermediary elements it crosses. 383 */ 384 WTF::String moveSelection(WebCore::Frame* frame, WebCore::Node* node); 385 386 /** 387 * In the currently focused textfield, replace the characters from oldStart to oldEnd 388 * (if oldStart == oldEnd, this will be an insert at that position) with replace, 389 * and set the selection to (start, end). 390 */ 391 void replaceTextfieldText(int oldStart, 392 int oldEnd, const WTF::String& replace, int start, int end, 393 int textGeneration); 394 void passToJs(int generation, 395 const WTF::String& , const WebCore::PlatformKeyboardEvent& ); 396 /** 397 * Scroll the focused textfield to (x, y) in document space 398 */ 399 WebCore::IntRect scrollFocusedTextInput(float x, int y); 400 /** 401 * Set the FocusController's active and focused states, so that 402 * the caret will draw (true) or not. 403 */ 404 void setFocusControllerActive(bool active); 405 406 void saveDocumentState(WebCore::Frame* frame); 407 408 void addVisitedLink(const UChar*, int); 409 410 // TODO: I don't like this hack but I need to access the java object in 411 // order to send it as a parameter to java 412 AutoJObject getJavaObject(); 413 414 // Return the parent WebView Java object associated with this 415 // WebViewCore. 416 jobject getWebViewJavaObject(); 417 418 void setBackgroundColor(SkColor c); 419 420 void dumpDomTree(bool); 421 void dumpRenderTree(bool); 422 423 /* We maintain a list of active plugins. The list is edited by the 424 pluginview itself. The list is used to service invals to the plugin 425 pageflipping bitmap. 426 */ 427 void addPlugin(PluginWidgetAndroid*); 428 void removePlugin(PluginWidgetAndroid*); 429 // returns true if the pluginwidgit is in our active list 430 bool isPlugin(PluginWidgetAndroid*) const; 431 void invalPlugin(PluginWidgetAndroid*); 432 void drawPlugins(); 433 434 // send the current screen size/zoom to all of the plugins in our list 435 void sendPluginVisibleScreen(); 436 437 // notify plugin that a new drawing surface was created in the UI thread 438 void sendPluginSurfaceReady(); 439 440 // send onLoad event to plugins who are descendents of the given frame 441 void notifyPluginsOnFrameLoad(const WebCore::Frame*); 442 443 // gets a rect representing the current on-screen portion of the document 444 void getVisibleScreen(ANPRectI&); 445 446 // send this event to all of the plugins in our list 447 void sendPluginEvent(const ANPEvent&); 448 449 // lookup the plugin widget struct given an NPP 450 PluginWidgetAndroid* getPluginWidget(NPP npp); 451 452 // Notify the Java side whether it needs to pass down the touch events 453 void needTouchEvents(bool); 454 455 void requestKeyboardWithSelection(const WebCore::Node*, int selStart, int selEnd); 456 // Notify the Java side that webkit is requesting a keyboard 457 void requestKeyboard(bool showKeyboard); 458 459 // Generates a class loader that contains classes from the plugin's apk 460 jclass getPluginClass(const WTF::String& libName, const char* className); 461 462 // Creates a full screen surface for a plugin 463 void showFullScreenPlugin(jobject webkitPlugin, int32_t orientation, NPP npp); 464 465 // Instructs the UI thread to discard the plugin's full-screen surface 466 void hideFullScreenPlugin(); 467 468 // Creates a childView for the plugin but does not attach to the view hierarchy 469 jobject createSurface(jobject view); 470 471 // Adds the plugin's view (aka surface) to the view hierarchy 472 jobject addSurface(jobject view, int x, int y, int width, int height); 473 474 // Updates a Surface coordinates and dimensions for a plugin 475 void updateSurface(jobject childView, int x, int y, int width, int height); 476 477 // Destroys a SurfaceView for a plugin 478 void destroySurface(jobject childView); 479 480 // Returns the context (android.content.Context) of the WebView 481 jobject getContext(); 482 483 // Manages requests to keep the screen on while the WebView is visible 484 void keepScreenOn(bool screenOn); 485 486 // Make the rect (left, top, width, height) visible. If it can be fully 487 // fit, center it on the screen. Otherwise make sure the point specified 488 // by (left + xPercentInDoc * width, top + yPercentInDoc * height) 489 // pinned at the screen position (xPercentInView, yPercentInView). 490 void showRect(int left, int top, int width, int height, int contentWidth, 491 int contentHeight, float xPercentInDoc, float xPercentInView, 492 float yPercentInDoc, float yPercentInView); 493 494 // Scale the rect (x, y, width, height) to make it just fit and centered 495 // in the current view. 496 void centerFitRect(int x, int y, int width, int height); 497 498 // return a list of rects matching the touch point (x, y) with the slop 499 WTF::Vector<WebCore::IntRect> getTouchHighlightRects(int x, int y, int slop, 500 WebCore::Node** node, WebCore::HitTestResult* hitTestResult); 501 // This does a sloppy hit test 502 AndroidHitTestResult hitTestAtPoint(int x, int y, int slop, bool doMoveMouse = false); 503 static bool nodeIsClickableOrFocusable(WebCore::Node* node); 504 505 // Open a file chooser for selecting a file to upload 506 void openFileChooser(PassRefPtr<WebCore::FileChooser> ); 507 508 // reset the picture set to empty 509 void clearContent(); 510 511 bool focusBoundsChanged(); 512 513 // record content in a new BaseLayerAndroid, copying the layer tree as well 514 WebCore::BaseLayerAndroid* recordContent(SkIPoint* ); 515 516 // This creates a new BaseLayerAndroid by copying the current m_content 517 // and doing a copy of the layers. The layers' content may be updated 518 // as we are calling layersSync(). 519 WebCore::BaseLayerAndroid* createBaseLayer(GraphicsLayerAndroid* root); 520 bool updateLayers(WebCore::LayerAndroid*); 521 void notifyAnimationStarted(); 522 523 int textWrapWidth() const { return m_textWrapWidth; } 524 float scale() const { return m_scale; } 525 float textWrapScale() const { return m_screenWidth * m_scale / m_textWrapWidth; } 526 WebCore::Frame* mainFrame() const { return m_mainFrame; } 527 WebCore::Frame* focusedFrame() const; 528 529 void notifyWebAppCanBeInstalled(); 530 531 void deleteText(int startX, int startY, int endX, int endY); 532 WTF::String getText(int startX, int startY, int endX, int endY); 533 void insertText(const WTF::String &text); 534 535 // find on page 536 void resetFindOnPage(); 537 int findTextOnPage(const WTF::String &text); 538 int findNextOnPage(bool forward); 539 void updateMatchCount() const; 540 541 #if ENABLE(VIDEO) 542 void enterFullscreenForVideoLayer(int layerId, const WTF::String& url); 543 void exitFullscreenVideo(); 544 #endif 545 546 void setWebTextViewAutoFillable(int queryId, const string16& previewSummary); 547 548 DeviceMotionAndOrientationManager* deviceMotionAndOrientationManager() { return &m_deviceMotionAndOrientationManager; } 549 550 void listBoxRequest(WebCoreReply* reply, const uint16_t** labels, 551 size_t count, const int enabled[], size_t enabledCount, 552 bool multiple, const int selected[], size_t selectedCountOrSelection); 553 bool isPaused() const { return m_isPaused; } 554 void setIsPaused(bool isPaused) { m_isPaused = isPaused; } 555 bool drawIsPaused() const; 556 // The actual content (without title bar) size in doc coordinate 557 int screenWidth() const { return m_screenWidth; } 558 int screenHeight() const { return m_screenHeight; } 559 void setWebRequestContextUserAgent(); 560 void setWebRequestContextCacheMode(int mode); 561 WebRequestContext* webRequestContext(); 562 // Attempts to scroll the layer to the x,y coordinates of rect. The 563 // layer is the id of the LayerAndroid. 564 void scrollRenderLayer(int layer, const SkRect& rect); 565 // call only from webkit thread (like add/remove), return true if inst 566 // is still alive 567 static bool isInstance(WebViewCore*); 568 // if there exists at least one WebViewCore instance then we return the 569 // application context, otherwise NULL is returned. 570 static jobject getApplicationContext(); 571 // Check whether a media mimeType is supported in Android media framework. 572 static bool isSupportedMediaMimeType(const WTF::String& mimeType); 573 574 /** 575 * Returns all text ranges consumed by the cursor points referred 576 * to by startX, startY, endX, and endY. The vector will be empty 577 * if no text is in the given area or if the positions are invalid. 578 */ 579 Vector<WebCore::VisibleSelection> getTextRanges( 580 int startX, int startY, int endX, int endY); 581 static int platformLayerIdFromNode(WebCore::Node* node, 582 WebCore::LayerAndroid** outLayer = 0); 583 void selectText(int startX, int startY, int endX, int endY); 584 bool selectWordAt(int x, int y); 585 586 // Converts from the global content coordinates that WebView sends 587 // to frame-local content coordinates using the focused frame 588 WebCore::IntPoint convertGlobalContentToFrameContent(const WebCore::IntPoint& point, WebCore::Frame* frame = 0); 589 static void layerToAbsoluteOffset(const WebCore::LayerAndroid* layer, 590 WebCore::IntPoint& offset); 591 592 // Retrieves the current locale from system properties 593 void getLocale(String& language, WTF::String& region); 594 595 // Handles changes in system locale 596 void updateLocale(); 597 598 // these members are shared with webview.cpp 599 int m_touchGeneration; // copy of state in WebViewNative triggered by touch 600 int m_lastGeneration; // last action using up to date cache 601 // end of shared members 602 603 void setPrerenderingEnabled(bool enable); 604 605 // internal functions 606 private: 607 enum InputType { 608 NONE = -1, 609 NORMAL_TEXT_FIELD = 0, 610 TEXT_AREA = 1, 611 PASSWORD = 2, 612 SEARCH = 3, 613 EMAIL = 4, 614 NUMBER = 5, 615 TELEPHONE = 6, 616 URL = 7, 617 }; 618 619 WebCore::Node* currentFocus(); 620 void layout(); 621 // Create a set of pictures to represent the drawn DOM, driven by 622 // the invalidated region and the time required to draw (used to draw) 623 void recordPicturePile(); 624 625 virtual void paintContents(WebCore::GraphicsContext* gc, WebCore::IntRect& dirty); 626 virtual SkCanvas* createPrerenderCanvas(WebCore::PrerenderedInval* prerendered); 627 #ifdef CONTEXT_RECORDING 628 WebCore::GraphicsOperationCollection* rebuildGraphicsOperationCollection(const SkIRect& inval); 629 #endif 630 void sendNotifyProgressFinished(); 631 /* 632 * Handle a mouse click, either from a touch or trackball press. 633 * @param frame Pointer to the Frame containing the node that was clicked on. 634 * @param node Pointer to the Node that was clicked on. 635 * @param fake This is a fake mouse click, used to put a textfield into focus. Do not 636 * open the IME. 637 */ 638 WebCore::HTMLAnchorElement* retrieveAnchorElement(int x, int y); 639 WebCore::HTMLElement* retrieveElement(int x, int y, 640 const WebCore::QualifiedName& ); 641 WebCore::HTMLImageElement* retrieveImageElement(int x, int y); 642 // below are members responsible for accessibility support 643 WTF::String modifySelectionTextNavigationAxis(WebCore::DOMSelection* selection, 644 int direction, int granularity); 645 WTF::String modifySelectionDomNavigationAxis(WebCore::DOMSelection* selection, 646 int direction, int granularity); 647 WebCore::Text* traverseNextContentTextNode(WebCore::Node* fromNode, 648 WebCore::Node* toNode, 649 int direction); 650 bool isVisible(WebCore::Node* node); 651 bool isHeading(WebCore::Node* node); 652 WTF::String formatMarkup(WebCore::DOMSelection* selection); 653 void selectAt(int x, int y); 654 655 void scrollNodeIntoView(WebCore::Frame* frame, WebCore::Node* node); 656 bool isContentTextNode(WebCore::Node* node); 657 WebCore::Node* getIntermediaryInputElement(WebCore::Node* fromNode, 658 WebCore::Node* toNode, 659 int direction); 660 bool isContentInputElement(WebCore::Node* node); 661 bool isDescendantOf(WebCore::Node* parent, WebCore::Node* node); 662 void advanceAnchorNode(WebCore::DOMSelection* selection, int direction, 663 WTF::String& markup, bool ignoreFirstNode, 664 WebCore::ExceptionCode& ec); 665 WebCore::Node* getNextAnchorNode(WebCore::Node* anchorNode, 666 bool skipFirstHack, int direction); 667 WebCore::Node* getImplicitBoundaryNode(WebCore::Node* node, 668 unsigned offset, int direction); 669 jobject createTextFieldInitData(WebCore::Node* node); 670 /** 671 * Calls into java to reset the text edit field with the 672 * current contents and selection. 673 */ 674 void initEditField(WebCore::Node* node); 675 676 /** 677 * If node is not a text input field or if it explicitly requests 678 * not to have keyboard input, then the soft keyboard is closed. If 679 * it is a text input field then initEditField is called and 680 * auto-fill information is requested for HTML form input fields. 681 */ 682 void initializeTextInput(WebCore::Node* node, bool fake); 683 684 /** 685 * Gets the input type a Node. NONE is returned if it isn't an 686 * input field. 687 */ 688 InputType getInputType(WebCore::Node* node); 689 690 /** 691 * If node is an input field, the spellcheck value for the 692 * field is returned. Otherwise true is returned. 693 */ 694 static bool isSpellCheckEnabled(WebCore::Node* node); 695 696 /** 697 * Returns the offsets of the selection area for both normal text 698 * fields and content editable fields. start and end are modified 699 * by this method. 700 */ 701 static void getSelectionOffsets(WebCore::Node* node, int& start, int& end); 702 /** 703 * Gets the plain text of the specified editable text field. node 704 * may be content-editable or a plain text fields. 705 */ 706 static WTF::String getInputText(WebCore::Node* node); 707 /** 708 * Gets the RenderTextControl for the given node if it has one. 709 * If its renderer isn't a RenderTextControl, then NULL is returned. 710 */ 711 static WebCore::RenderTextControl* toRenderTextControl(WebCore::Node *node); 712 /** 713 * Sets the selection for node's editable field to the offsets 714 * between start (inclusive) and end (exclusive). 715 */ 716 static void setSelection(WebCore::Node* node, int start, int end); 717 /** 718 * Returns the Position for the given offset for an editable 719 * field. The offset is relative to the node start. 720 */ 721 static WebCore::Position getPositionForOffset(WebCore::Node* node, int offset); 722 723 WebCore::VisiblePosition visiblePositionForContentPoint(int x, int y); 724 WebCore::VisiblePosition visiblePositionForContentPoint(const WebCore::IntPoint& point); 725 bool selectWordAroundPosition(WebCore::Frame* frame, 726 WebCore::VisiblePosition pos); 727 SelectText* createSelectText(const WebCore::VisibleSelection&); 728 void setSelectionCaretInfo(SelectText* selectTextContainer, 729 const WebCore::Position& position, 730 const WebCore::IntPoint& frameOffset, 731 SelectText::HandleId handleId, int offset, 732 EAffinity affinity); 733 static int getMaxLength(WebCore::Node* node); 734 static WTF::String getFieldName(WebCore::Node* node); 735 static bool isAutoCompleteEnabled(WebCore::Node* node); 736 WebCore::IntRect absoluteContentRect(WebCore::Node* node, 737 WebCore::LayerAndroid* layer); 738 static WebCore::IntRect positionToTextRect(const WebCore::Position& position, 739 WebCore::EAffinity affinity, const WebCore::IntPoint& offset); 740 static bool isLtr(const WebCore::Position& position); 741 static WebCore::Position trimSelectionPosition( 742 const WebCore::Position& start, const WebCore::Position& stop); 743 744 // called from constructor, to add this to a global list 745 static void addInstance(WebViewCore*); 746 // called from destructor, to remove this from a global list 747 static void removeInstance(WebViewCore*); 748 749 bool prerenderingEnabled(); 750 751 friend class ListBoxReply; 752 struct JavaGlue; 753 struct JavaGlue* m_javaGlue; 754 struct TextFieldInitDataGlue; 755 struct TextFieldInitDataGlue* m_textFieldInitDataGlue; 756 WebCore::Frame* m_mainFrame; 757 WebCoreReply* m_popupReply; 758 WebCore::PicturePile m_content; // the set of pictures to draw 759 // Used in passToJS to avoid updating the UI text field until after the 760 // key event has been processed. 761 bool m_blockTextfieldUpdates; 762 bool m_focusBoundsChanged; 763 bool m_skipContentDraw; 764 // Passed in with key events to know when they were generated. Store it 765 // with the cache so that we can ignore stale text changes. 766 int m_textGeneration; 767 int m_maxXScroll; 768 int m_maxYScroll; 769 int m_scrollOffsetX; // webview.java's current scroll in X 770 int m_scrollOffsetY; // webview.java's current scroll in Y 771 double m_scrollSetTime; // when the scroll was last set 772 WebCore::IntPoint m_mousePos; 773 // This is the location at which we will click. This is tracked 774 // separately from m_mousePos, because m_mousePos may be updated 775 // in the interval between ACTION_UP and when the click fires since 776 // that occurs after a delay. This also works around potential hardware 777 // issues if we get onHoverEvents when using the touch screen, as that 778 // will nullify the slop checking we do in hitTest (aka, ACTION_DOWN) 779 WebCore::IntPoint m_mouseClickPos; 780 int m_screenWidth; // width of the visible rect in document coordinates 781 int m_screenHeight;// height of the visible rect in document coordinates 782 int m_textWrapWidth; 783 float m_scale; 784 WebCore::PageGroup* m_groupForVisitedLinks; 785 bool m_isPaused; 786 int m_cacheMode; 787 bool m_fullscreenVideoMode; 788 789 // find on page data 790 WTF::String m_searchText; 791 int m_matchCount; 792 int m_activeMatchIndex; 793 RefPtr<WebCore::Range> m_activeMatch; 794 795 SkTDArray<PluginWidgetAndroid*> m_plugins; 796 WebCore::Timer<WebViewCore> m_pluginInvalTimer; 797 void pluginInvalTimerFired(WebCore::Timer<WebViewCore>*) { 798 this->drawPlugins(); 799 } 800 801 int m_screenOnCounter; 802 WebCore::Node* m_currentNodeDomNavigationAxis; 803 DeviceMotionAndOrientationManager m_deviceMotionAndOrientationManager; 804 805 #if ENABLE(TOUCH_EVENTS) 806 bool m_forwardingTouchEvents; 807 #endif 808 809 scoped_refptr<WebRequestContext> m_webRequestContext; 810 811 WTF::Mutex m_prerenderLock; 812 bool m_prerenderEnabled; 813 }; 814 815 } // namespace android 816 817 #endif // WebViewCore_h 818