2 * Copyright 2007, The Android Open Source Project
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
26 #define LOG_TAG "webviewglue"
30 #include "AndroidAnimation.h"
31 #include "AndroidLog.h"
32 #include "BaseLayerAndroid.h"
33 #include "CachedFrame.h"
34 #include "CachedNode.h"
35 #include "CachedRoot.h"
36 #include "DrawExtra.h"
37 #include "FindCanvas.h"
39 #include "GraphicsJNI.h"
40 #include "HTMLInputElement.h"
43 #include "LayerAndroid.h"
45 #include "utils/Functor.h"
46 #include "private/hwui/DrawGlInfo.h"
47 #include "PlatformGraphicsContext.h"
48 #include "PlatformString.h"
49 #include "ScrollableLayerAndroid.h"
50 #include "SelectText.h"
52 #include "SkDumpCanvas.h"
53 #include "SkPicture.h"
56 #ifdef ANDROID_INSTRUMENT
57 #include "TimeCounter.h"
59 #include "TilesManager.h"
60 #include "WebCoreJni.h"
61 #include "WebRequestContext.h"
62 #include "WebViewCore.h"
63 #include "android_graphics.h"
65 #ifdef GET_NATIVE_VIEW
66 #undef GET_NATIVE_VIEW
69 #define GET_NATIVE_VIEW(env, obj) ((WebView*)env->GetIntField(obj, gWebViewField))
71 #include <JNIUtility.h>
74 #include <ui/KeycodeLabels.h>
75 #include <wtf/text/AtomicString.h>
76 #include <wtf/text/CString.h>
78 // Free as much as we possible can
79 #define TRIM_MEMORY_COMPLETE 80
80 // Free a lot (all textures gone)
81 #define TRIM_MEMORY_MODERATE 60
82 // More moderate free (keep bare minimum to restore quickly-ish - possibly clear all textures)
83 #define TRIM_MEMORY_BACKGROUND 40
84 // Moderate free (clear cached tiles, keep visible ones)
85 #define TRIM_MEMORY_UI_HIDDEN 20
86 // Duration to show the pressed cursor ring
87 #define PRESSED_STATE_DURATION 400
91 static jfieldID gWebViewField;
93 //-------------------------------------
95 static jmethodID GetJMethod(JNIEnv* env, jclass clazz, const char name[], const char signature[])
97 jmethodID m = env->GetMethodID(clazz, name, signature);
98 LOG_ASSERT(m, "Could not find method %s", name);
102 //-------------------------------------
103 // This class provides JNI for making calls into native code from the UI side
104 // of the multi-threaded WebView.
108 enum FrameCachePermission {
113 enum DrawExtras { // keep this in sync with WebView.java
116 DrawExtrasSelection = 2,
117 DrawExtrasCursorRing = 3
122 jmethodID m_calcOurContentVisibleRectF;
123 jmethodID m_overrideLoading;
124 jmethodID m_scrollBy;
125 jmethodID m_sendMoveFocus;
126 jmethodID m_sendMoveMouse;
127 jmethodID m_sendMoveMouseIfLatest;
128 jmethodID m_sendMotionUp;
129 jmethodID m_domChangedFocus;
130 jmethodID m_getScaledMaxXScroll;
131 jmethodID m_getScaledMaxYScroll;
132 jmethodID m_getVisibleRect;
133 jmethodID m_rebuildWebTextView;
134 jmethodID m_viewInvalidate;
135 jmethodID m_viewInvalidateRect;
136 jmethodID m_postInvalidateDelayed;
137 jmethodID m_pageSwapCallback;
138 jmethodID m_inFullScreenMode;
141 jmethodID m_rectWidth;
142 jmethodID m_rectHeight;
143 jfieldID m_rectFLeft;
145 jmethodID m_rectFWidth;
146 jmethodID m_rectFHeight;
147 jmethodID m_getTextHandleScale;
148 AutoJObject object(JNIEnv* env) {
149 return getRealObject(env, m_obj);
153 WebView(JNIEnv* env, jobject javaWebView, int viewImpl, WTF::String drawableDir) :
154 m_ring((WebViewCore*) viewImpl)
156 jclass clazz = env->FindClass("android/webkit/WebView");
157 // m_javaGlue = new JavaGlue;
158 m_javaGlue.m_obj = env->NewWeakGlobalRef(javaWebView);
159 m_javaGlue.m_scrollBy = GetJMethod(env, clazz, "setContentScrollBy", "(IIZ)Z");
160 m_javaGlue.m_calcOurContentVisibleRectF = GetJMethod(env, clazz, "calcOurContentVisibleRectF", "(Landroid/graphics/RectF;)V");
161 m_javaGlue.m_overrideLoading = GetJMethod(env, clazz, "overrideLoading", "(Ljava/lang/String;)V");
162 m_javaGlue.m_sendMoveFocus = GetJMethod(env, clazz, "sendMoveFocus", "(II)V");
163 m_javaGlue.m_sendMoveMouse = GetJMethod(env, clazz, "sendMoveMouse", "(IIII)V");
164 m_javaGlue.m_sendMoveMouseIfLatest = GetJMethod(env, clazz, "sendMoveMouseIfLatest", "(ZZ)V");
165 m_javaGlue.m_sendMotionUp = GetJMethod(env, clazz, "sendMotionUp", "(IIIII)V");
166 m_javaGlue.m_domChangedFocus = GetJMethod(env, clazz, "domChangedFocus", "()V");
167 m_javaGlue.m_getScaledMaxXScroll = GetJMethod(env, clazz, "getScaledMaxXScroll", "()I");
168 m_javaGlue.m_getScaledMaxYScroll = GetJMethod(env, clazz, "getScaledMaxYScroll", "()I");
169 m_javaGlue.m_getVisibleRect = GetJMethod(env, clazz, "sendOurVisibleRect", "()Landroid/graphics/Rect;");
170 m_javaGlue.m_rebuildWebTextView = GetJMethod(env, clazz, "rebuildWebTextView", "()V");
171 m_javaGlue.m_viewInvalidate = GetJMethod(env, clazz, "viewInvalidate", "()V");
172 m_javaGlue.m_viewInvalidateRect = GetJMethod(env, clazz, "viewInvalidate", "(IIII)V");
173 m_javaGlue.m_postInvalidateDelayed = GetJMethod(env, clazz,
174 "viewInvalidateDelayed", "(JIIII)V");
175 m_javaGlue.m_pageSwapCallback = GetJMethod(env, clazz, "pageSwapCallback", "()V");
176 m_javaGlue.m_inFullScreenMode = GetJMethod(env, clazz, "inFullScreenMode", "()Z");
177 m_javaGlue.m_getTextHandleScale = GetJMethod(env, clazz, "getTextHandleScale", "()F");
178 env->DeleteLocalRef(clazz);
180 jclass rectClass = env->FindClass("android/graphics/Rect");
181 LOG_ASSERT(rectClass, "Could not find Rect class");
182 m_javaGlue.m_rectLeft = env->GetFieldID(rectClass, "left", "I");
183 m_javaGlue.m_rectTop = env->GetFieldID(rectClass, "top", "I");
184 m_javaGlue.m_rectWidth = GetJMethod(env, rectClass, "width", "()I");
185 m_javaGlue.m_rectHeight = GetJMethod(env, rectClass, "height", "()I");
186 env->DeleteLocalRef(rectClass);
188 jclass rectClassF = env->FindClass("android/graphics/RectF");
189 LOG_ASSERT(rectClassF, "Could not find RectF class");
190 m_javaGlue.m_rectFLeft = env->GetFieldID(rectClassF, "left", "F");
191 m_javaGlue.m_rectFTop = env->GetFieldID(rectClassF, "top", "F");
192 m_javaGlue.m_rectFWidth = GetJMethod(env, rectClassF, "width", "()F");
193 m_javaGlue.m_rectFHeight = GetJMethod(env, rectClassF, "height", "()F");
194 env->DeleteLocalRef(rectClassF);
196 env->SetIntField(javaWebView, gWebViewField, (jint)this);
197 m_viewImpl = (WebViewCore*) viewImpl;
201 m_heightCanMeasure = false;
204 m_ringAnimationEnd = 0;
207 m_buttonSkin = drawableDir.isEmpty() ? 0 : new RenderSkinButton(drawableDir);
208 #if USE(ACCELERATED_COMPOSITING)
209 m_glWebViewState = 0;
210 m_pageSwapCallbackRegistered = false;
216 if (m_javaGlue.m_obj)
218 JNIEnv* env = JSC::Bindings::getJNIEnv();
219 env->DeleteWeakGlobalRef(m_javaGlue.m_obj);
220 m_javaGlue.m_obj = 0;
222 #if USE(ACCELERATED_COMPOSITING)
223 // We must remove the m_glWebViewState prior to deleting m_baseLayer. If we
224 // do not remove it here, we risk having BaseTiles trying to paint using a
225 // deallocated base layer.
228 delete m_frameCacheUI;
229 delete m_navPictureUI;
230 SkSafeUnref(m_baseLayer);
231 delete m_glDrawFunctor;
237 #if USE(ACCELERATED_COMPOSITING)
238 delete m_glWebViewState;
239 m_glWebViewState = 0;
243 WebViewCore* getWebViewCore() const {
247 float getTextHandleScale()
249 LOG_ASSERT(m_javaGlue.m_obj, "A java object was not associated with this native WebView!");
250 JNIEnv* env = JSC::Bindings::getJNIEnv();
251 AutoJObject javaObject = m_javaGlue.object(env);
252 if (!javaObject.get())
254 float result = env->CallFloatMethod(javaObject.get(), m_javaGlue.m_getTextHandleScale);
259 void updateSelectionHandles()
263 // Adjust for device density & scale
264 m_selectText.updateHandleScale(getTextHandleScale());
267 // removes the cursor altogether (e.g., when going to a new page)
270 CachedRoot* root = getFrameCache(AllowNewer);
274 m_viewImpl->m_hasCursorBounds = false;
279 // leaves the cursor where it is, but suppresses drawing it
282 CachedRoot* root = getFrameCache(AllowNewer);
290 void hideCursor(CachedRoot* root)
292 DBG_NAV_LOG("inner");
293 m_viewImpl->m_hasCursorBounds = false;
300 CachedRoot* root = getFrameCache(DontAllowNewer);
302 root->mDebug.print();
306 // Traverse our stored array of buttons that are in our picture, and update
307 // their subpictures according to their current state.
308 // Called from the UI thread. This is the one place in the UI thread where we
309 // access the buttons stored in the WebCore thread.
310 // hasFocus keeps track of whether the WebView has focus && windowFocus.
311 // If not, we do not want to draw the button in a selected or pressed state
312 void nativeRecordButtons(bool hasFocus, bool pressed, bool invalidate)
314 bool cursorIsOnButton = false;
315 const CachedFrame* cachedFrame;
316 const CachedNode* cachedCursor = 0;
317 // Lock the mutex, since we now share with the WebCore thread.
318 m_viewImpl->gButtonMutex.lock();
319 if (m_viewImpl->m_buttons.size() && m_buttonSkin) {
320 // FIXME: In a future change, we should keep track of whether the selection
321 // has changed to short circuit (note that we would still need to update
322 // if we received new buttons from the WebCore thread).
323 WebCore::Node* cursor = 0;
324 CachedRoot* root = getFrameCache(DontAllowNewer);
326 cachedCursor = root->currentCursor(&cachedFrame);
328 cursor = (WebCore::Node*) cachedCursor->nodePointer();
331 // Traverse the array, and update each button, depending on whether it
333 Container* end = m_viewImpl->m_buttons.end();
334 for (Container* ptr = m_viewImpl->m_buttons.begin(); ptr != end; ptr++) {
335 RenderSkinAndroid::State state = RenderSkinAndroid::kNormal;
336 if (ptr->matches(cursor)) {
337 cursorIsOnButton = true;
338 // If the WebView is out of focus/window focus, set the state to
339 // normal, but still keep track of the fact that the selected is a
342 if (pressed || m_ring.m_isPressed)
343 state = RenderSkinAndroid::kPressed;
344 else if (SkTime::GetMSecs() < m_ringAnimationEnd)
345 state = RenderSkinAndroid::kFocused;
348 ptr->updateFocusState(state, m_buttonSkin);
351 m_viewImpl->gButtonMutex.unlock();
352 if (invalidate && cachedCursor && cursorIsOnButton) {
353 const WebCore::IntRect& b = cachedCursor->bounds(cachedFrame);
354 viewInvalidateRect(b.x(), b.y(), b.maxX(), b.maxY());
358 void scrollToCurrentMatch()
360 if (!m_findOnPage.currentMatchIsInLayer()) {
361 scrollRectOnScreen(m_findOnPage.currentMatchBounds());
365 SkRect matchBounds = m_findOnPage.currentMatchBounds();
366 LayerAndroid* rootLayer = getFrameCache(DontAllowNewer)->rootLayer();
367 Layer* layerContainingMatch = rootLayer->findById(m_findOnPage.currentMatchLayerId());
368 ASSERT(layerContainingMatch);
370 // If the match is in a fixed position layer, there's nothing to do.
371 if (layerContainingMatch->shouldInheritFromRootTransform())
374 // If the match is in a scrollable layer or a descendant of such a layer,
375 // there may be a range of of scroll configurations that will make the
376 // current match visible. Our approach is the simplest possible. Starting at
377 // the layer in which the match is found, we move up the layer tree,
378 // scrolling any scrollable layers as little as possible to make sure that
379 // the current match is in view. This approach has the disadvantage that we
380 // may end up scrolling a larger number of elements than is necessary, which
381 // may be visually jarring. However, minimising the number of layers
382 // scrolled would complicate the code significantly.
384 bool didScrollLayer = false;
385 for (Layer* layer = layerContainingMatch; layer; layer = layer->getParent()) {
386 ASSERT(layer->getParent() || layer == rootLayer);
388 if (layer->contentIsScrollable()) {
389 // Convert the match location to layer's local space and scroll it.
390 // Repeatedly calling Layer::localToAncestor() is inefficient as
391 // each call repeats part of the calculation. It would be more
392 // efficient to maintain the transform here and update it on each
393 // iteration, but that would mean duplicating logic from
394 // Layer::localToAncestor() and would complicate things.
396 layerContainingMatch->localToAncestor(layer, &transform);
397 SkRect transformedMatchBounds;
398 transform.mapRect(&transformedMatchBounds, matchBounds);
399 SkIRect roundedTransformedMatchBounds;
400 transformedMatchBounds.roundOut(&roundedTransformedMatchBounds);
401 // Only ScrollableLayerAndroid returns true for contentIsScrollable().
402 didScrollLayer |= static_cast<ScrollableLayerAndroid*>(layer)->scrollRectIntoView(roundedTransformedMatchBounds);
405 // Invalidate, as the call below to scroll the main page may be a no-op.
409 // Convert matchBounds to the global space so we can scroll the main page.
411 layerContainingMatch->localToGlobal(&transform);
412 SkRect transformedMatchBounds;
413 transform.mapRect(&transformedMatchBounds, matchBounds);
414 SkIRect roundedTransformedMatchBounds;
415 transformedMatchBounds.roundOut(&roundedTransformedMatchBounds);
416 scrollRectOnScreen(roundedTransformedMatchBounds);
419 void scrollRectOnScreen(const IntRect& rect)
424 calcOurContentVisibleRect(&visible);
427 int right = rect.maxX();
428 if (left < visible.fLeft) {
429 dx = left - visible.fLeft;
430 // Only scroll right if the entire width can fit on screen.
431 } else if (right > visible.fRight && right - left < visible.width()) {
432 dx = right - visible.fRight;
436 int bottom = rect.maxY();
437 if (top < visible.fTop) {
438 dy = top - visible.fTop;
439 // Only scroll down if the entire height can fit on screen
440 } else if (bottom > visible.fBottom && bottom - top < visible.height()) {
441 dy = bottom - visible.fBottom;
443 if ((dx|dy) == 0 || !scrollBy(dx, dy))
448 void calcOurContentVisibleRect(SkRect* r)
450 JNIEnv* env = JSC::Bindings::getJNIEnv();
451 AutoJObject javaObject = m_javaGlue.object(env);
452 if (!javaObject.get())
454 jclass rectClass = env->FindClass("android/graphics/RectF");
455 jmethodID init = env->GetMethodID(rectClass, "<init>", "(FFFF)V");
456 jobject jRect = env->NewObject(rectClass, init, 0, 0, 0, 0);
457 env->CallVoidMethod(javaObject.get(), m_javaGlue.m_calcOurContentVisibleRectF, jRect);
458 r->fLeft = env->GetFloatField(jRect, m_javaGlue.m_rectFLeft);
459 r->fTop = env->GetFloatField(jRect, m_javaGlue.m_rectFTop);
460 r->fRight = r->fLeft + env->CallFloatMethod(jRect, m_javaGlue.m_rectFWidth);
461 r->fBottom = r->fTop + env->CallFloatMethod(jRect, m_javaGlue.m_rectFHeight);
462 env->DeleteLocalRef(rectClass);
463 env->DeleteLocalRef(jRect);
467 void resetCursorRing()
469 m_ringAnimationEnd = 0;
470 m_viewImpl->m_hasCursorBounds = false;
473 bool drawCursorPreamble(CachedRoot* root)
475 if (!root) return false;
476 const CachedFrame* frame;
477 const CachedNode* node = root->currentCursor(&frame);
479 DBG_NAV_LOGV("%s", "!node");
483 m_ring.setIsButton(node);
484 if (node->isHidden()) {
485 DBG_NAV_LOG("node->isHidden()");
486 m_viewImpl->m_hasCursorBounds = false;
489 #if USE(ACCELERATED_COMPOSITING)
490 if (node->isInLayer() && root->rootLayer()) {
491 LayerAndroid* layer = root->rootLayer();
493 calcOurContentVisibleRect(&visible);
494 layer->updateFixedLayersPositions(visible);
495 layer->updatePositions();
498 setVisibleRect(root);
499 m_ring.m_root = root;
500 m_ring.m_frame = frame;
501 m_ring.m_node = node;
502 SkMSec time = SkTime::GetMSecs();
503 m_ring.m_isPressed = time < m_ringAnimationEnd
504 && m_ringAnimationEnd != UINT_MAX;
508 void drawCursorPostamble()
510 if (m_ringAnimationEnd == UINT_MAX)
512 SkMSec time = SkTime::GetMSecs();
513 if (time < m_ringAnimationEnd) {
514 // views assume that inval bounds coordinates are non-negative
515 WebCore::IntRect invalBounds(0, 0, INT_MAX, INT_MAX);
516 invalBounds.intersect(m_ring.m_absBounds);
517 postInvalidateDelayed(m_ringAnimationEnd - time, invalBounds);
519 hideCursor(const_cast<CachedRoot*>(m_ring.m_root));
523 bool drawGL(WebCore::IntRect& viewRect, WebCore::IntRect* invalRect, WebCore::IntRect& webViewRect,
524 int titleBarHeight, WebCore::IntRect& clip, float scale, int extras)
526 #if USE(ACCELERATED_COMPOSITING)
527 if (!m_baseLayer || inFullScreenMode())
530 if (!m_glWebViewState) {
531 m_glWebViewState = new GLWebViewState(&m_viewImpl->gButtonMutex);
532 m_glWebViewState->glExtras()->setCursorRingExtra(&m_ring);
533 m_glWebViewState->glExtras()->setFindOnPageExtra(&m_findOnPage);
534 if (m_baseLayer->content()) {
537 rect.set(0, 0, m_baseLayer->content()->width(), m_baseLayer->content()->height());
538 region.setRect(rect);
539 m_glWebViewState->setBaseLayer(m_baseLayer, region, false, true);
543 CachedRoot* root = getFrameCache(AllowNewer);
545 DBG_NAV_LOG("!root");
546 if (extras == DrawExtrasCursorRing)
549 DrawExtra* extra = 0;
552 extra = &m_findOnPage;
554 case DrawExtrasSelection:
555 // This will involve a JNI call, but under normal circumstances we will
556 // not hit this anyway. Only if USE_JAVA_TEXT_SELECTION is disabled
557 // in WebView.java will we hit this (so really debug only)
558 updateSelectionHandles();
559 extra = &m_selectText;
561 case DrawExtrasCursorRing:
562 if (drawCursorPreamble(root) && m_ring.setup()) {
563 if (m_ring.m_isPressed || m_ringAnimationEnd == UINT_MAX)
565 drawCursorPostamble();
572 unsigned int pic = m_glWebViewState->currentPictureCounter();
573 m_glWebViewState->glExtras()->setDrawExtra(extra);
575 LayerAndroid* compositeLayer = compositeRoot();
577 compositeLayer->setExtra(0);
580 calcOurContentVisibleRect(&visibleRect);
581 // Make sure we have valid coordinates. We might not have valid coords
582 // if the zoom manager is still initializing. We will be redrawn
583 // once the correct scale is set
584 if (!visibleRect.hasValidCoordinates())
586 bool pagesSwapped = false;
587 bool ret = m_glWebViewState->drawGL(viewRect, visibleRect, invalRect,
588 webViewRect, titleBarHeight, clip, scale,
590 if (m_pageSwapCallbackRegistered && pagesSwapped) {
591 m_pageSwapCallbackRegistered = false;
592 LOG_ASSERT(m_javaGlue.m_obj, "A java object was not associated with this native WebView!");
593 JNIEnv* env = JSC::Bindings::getJNIEnv();
594 AutoJObject javaObject = m_javaGlue.object(env);
595 if (javaObject.get()) {
596 env->CallVoidMethod(javaObject.get(), m_javaGlue.m_pageSwapCallback);
600 if (ret || m_glWebViewState->currentPictureCounter() != pic)
606 PictureSet* draw(SkCanvas* canvas, SkColor bgColor, int extras, bool split)
610 canvas->drawColor(bgColor);
614 // draw the content of the base layer first
615 PictureSet* content = m_baseLayer->content();
616 int sc = canvas->save(SkCanvas::kClip_SaveFlag);
617 canvas->clipRect(SkRect::MakeLTRB(0, 0, content->width(),
618 content->height()), SkRegion::kDifference_Op);
619 canvas->drawColor(bgColor);
620 canvas->restoreToCount(sc);
621 if (content->draw(canvas))
622 ret = split ? new PictureSet(*content) : 0;
624 CachedRoot* root = getFrameCache(AllowNewer);
626 DBG_NAV_LOG("!root");
627 if (extras == DrawExtrasCursorRing)
630 LayerAndroid mainPicture(m_navPictureUI);
631 DrawExtra* extra = 0;
634 extra = &m_findOnPage;
636 case DrawExtrasSelection:
637 // This will involve a JNI call, but under normal circumstances we will
638 // not hit this anyway. Only if USE_JAVA_TEXT_SELECTION is disabled
639 // in WebView.java will we hit this (so really debug only)
640 updateSelectionHandles();
641 extra = &m_selectText;
643 case DrawExtrasCursorRing:
644 if (drawCursorPreamble(root) && m_ring.setup()) {
645 if (!m_ring.m_isButton)
647 drawCursorPostamble();
654 IntRect dummy; // inval area, unused for now
655 extra->draw(canvas, &mainPicture, &dummy);
657 #if USE(ACCELERATED_COMPOSITING)
658 LayerAndroid* compositeLayer = compositeRoot();
661 compositeLayer->setExtra(extra);
663 calcOurContentVisibleRect(&visible);
664 // call this to be sure we've adjusted for any scrolling or animations
665 // before we actually draw
666 compositeLayer->updateFixedLayersPositions(visible);
667 compositeLayer->updatePositions();
668 // We have to set the canvas' matrix on the base layer
669 // (to have fixed layers work as intended)
670 SkAutoCanvasRestore restore(canvas, true);
671 m_baseLayer->setMatrix(canvas->getTotalMatrix());
672 canvas->resetMatrix();
673 m_baseLayer->draw(canvas);
679 bool cursorIsTextInput(FrameCachePermission allowNewer)
681 CachedRoot* root = getFrameCache(allowNewer);
683 DBG_NAV_LOG("!root");
686 const CachedNode* cursor = root->currentCursor();
688 DBG_NAV_LOG("!cursor");
691 DBG_NAV_LOGD("%s", cursor->isTextInput() ? "true" : "false");
692 return cursor->isTextInput();
695 void cursorRingBounds(WebCore::IntRect* bounds)
697 DBG_NAV_LOGD("%s", "");
698 CachedRoot* root = getFrameCache(DontAllowNewer);
700 const CachedFrame* cachedFrame;
701 const CachedNode* cachedNode = root->currentCursor(&cachedFrame);
703 *bounds = cachedNode->cursorRingBounds(cachedFrame);
704 DBG_NAV_LOGD("bounds={%d,%d,%d,%d}", bounds->x(), bounds->y(),
705 bounds->width(), bounds->height());
709 *bounds = WebCore::IntRect(0, 0, 0, 0);
714 m_viewImpl->gCursorBoundsMutex.lock();
715 bool hasCursorBounds = m_viewImpl->m_hasCursorBounds;
716 IntRect bounds = m_viewImpl->m_cursorBounds;
717 m_viewImpl->gCursorBoundsMutex.unlock();
718 if (!hasCursorBounds)
721 const CachedFrame* frame;
722 const CachedNode* node = m_frameCacheUI->findAt(bounds, &frame, &x, &y, true);
725 // require that node have approximately the same bounds (+/- 4) and the same
727 IntPoint oldCenter = IntPoint(bounds.x() + (bounds.width() >> 1),
728 bounds.y() + (bounds.height() >> 1));
729 IntRect newBounds = node->bounds(frame);
730 IntPoint newCenter = IntPoint(newBounds.x() + (newBounds.width() >> 1),
731 newBounds.y() + (newBounds.height() >> 1));
732 DBG_NAV_LOGD("oldCenter=(%d,%d) newCenter=(%d,%d)"
733 " bounds=(%d,%d,w=%d,h=%d) newBounds=(%d,%d,w=%d,h=%d)",
734 oldCenter.x(), oldCenter.y(), newCenter.x(), newCenter.y(),
735 bounds.x(), bounds.y(), bounds.width(), bounds.height(),
736 newBounds.x(), newBounds.y(), newBounds.width(), newBounds.height());
737 if (abs(oldCenter.x() - newCenter.x()) > 2)
739 if (abs(oldCenter.y() - newCenter.y()) > 2)
741 if (abs(bounds.x() - newBounds.x()) > 4)
743 if (abs(bounds.y() - newBounds.y()) > 4)
745 if (abs(bounds.maxX() - newBounds.maxX()) > 4)
747 if (abs(bounds.maxY() - newBounds.maxY()) > 4)
749 DBG_NAV_LOGD("node=%p frame=%p x=%d y=%d bounds=(%d,%d,w=%d,h=%d)",
750 node, frame, x, y, bounds.x(), bounds.y(), bounds.width(),
752 m_frameCacheUI->setCursor(const_cast<CachedFrame*>(frame),
753 const_cast<CachedNode*>(node));
756 CachedRoot* getFrameCache(FrameCachePermission allowNewer)
758 if (!m_viewImpl->m_updatedFrameCache) {
759 DBG_NAV_LOGV("%s", "!m_viewImpl->m_updatedFrameCache");
760 return m_frameCacheUI;
762 if (allowNewer == DontAllowNewer && m_viewImpl->m_lastGeneration < m_generation) {
763 DBG_NAV_LOGD("allowNewer==DontAllowNewer m_viewImpl->m_lastGeneration=%d"
764 " < m_generation=%d", m_viewImpl->m_lastGeneration, m_generation);
765 return m_frameCacheUI;
767 DBG_NAV_LOGD("%s", "m_viewImpl->m_updatedFrameCache == true");
768 const CachedFrame* oldCursorFrame;
769 const CachedNode* oldCursorNode = m_frameCacheUI ?
770 m_frameCacheUI->currentCursor(&oldCursorFrame) : 0;
771 #if USE(ACCELERATED_COMPOSITING)
773 if (oldCursorNode && oldCursorNode->isInLayer()) {
774 const LayerAndroid* cursorLayer = oldCursorFrame->layer(oldCursorNode)
775 ->layer(m_frameCacheUI->rootLayer());
777 layerId = cursorLayer->uniqueId();
780 // get id from old layer and use to find new layer
781 bool oldFocusIsTextInput = false;
782 void* oldFocusNodePointer = 0;
783 if (m_frameCacheUI) {
784 const CachedNode* oldFocus = m_frameCacheUI->currentFocus();
786 oldFocusIsTextInput = oldFocus->isTextInput();
787 oldFocusNodePointer = oldFocus->nodePointer();
790 m_viewImpl->gFrameCacheMutex.lock();
791 delete m_frameCacheUI;
792 SkSafeUnref(m_navPictureUI);
793 m_viewImpl->m_updatedFrameCache = false;
794 m_frameCacheUI = m_viewImpl->m_frameCacheKit;
795 m_navPictureUI = m_viewImpl->m_navPictureKit;
796 m_viewImpl->m_frameCacheKit = 0;
797 m_viewImpl->m_navPictureKit = 0;
798 m_viewImpl->gFrameCacheMutex.unlock();
800 m_frameCacheUI->setRootLayer(compositeRoot());
801 #if USE(ACCELERATED_COMPOSITING)
804 calcOurContentVisibleRect(&visible);
805 LayerAndroid* layer = const_cast<LayerAndroid*>(
806 m_frameCacheUI->rootLayer());
808 layer->updateFixedLayersPositions(visible);
809 layer->updatePositions();
814 if (oldFocusIsTextInput) {
815 const CachedNode* newFocus = m_frameCacheUI->currentFocus();
816 if (newFocus && oldFocusNodePointer != newFocus->nodePointer()
817 && newFocus->isTextInput()
818 && newFocus != m_frameCacheUI->currentCursor()) {
819 // The focus has changed. We may need to update things.
820 LOG_ASSERT(m_javaGlue.m_obj, "A java object was not associated with this native WebView!");
821 JNIEnv* env = JSC::Bindings::getJNIEnv();
822 AutoJObject javaObject = m_javaGlue.object(env);
823 if (javaObject.get()) {
824 env->CallVoidMethod(javaObject.get(), m_javaGlue.m_domChangedFocus);
829 if (oldCursorNode && (!m_frameCacheUI || !m_frameCacheUI->currentCursor()))
830 viewInvalidate(); // redraw in case cursor ring is still visible
831 return m_frameCacheUI;
834 int getScaledMaxXScroll()
836 LOG_ASSERT(m_javaGlue.m_obj, "A java object was not associated with this native WebView!");
837 JNIEnv* env = JSC::Bindings::getJNIEnv();
838 AutoJObject javaObject = m_javaGlue.object(env);
839 if (!javaObject.get())
841 int result = env->CallIntMethod(javaObject.get(), m_javaGlue.m_getScaledMaxXScroll);
846 int getScaledMaxYScroll()
848 LOG_ASSERT(m_javaGlue.m_obj, "A java object was not associated with this native WebView!");
849 JNIEnv* env = JSC::Bindings::getJNIEnv();
850 AutoJObject javaObject = m_javaGlue.object(env);
851 if (!javaObject.get())
853 int result = env->CallIntMethod(javaObject.get(), m_javaGlue.m_getScaledMaxYScroll);
858 IntRect getVisibleRect()
861 LOG_ASSERT(m_javaGlue.m_obj, "A java object was not associated with this native WebView!");
862 JNIEnv* env = JSC::Bindings::getJNIEnv();
863 AutoJObject javaObject = m_javaGlue.object(env);
864 if (!javaObject.get())
866 jobject jRect = env->CallObjectMethod(javaObject.get(), m_javaGlue.m_getVisibleRect);
868 rect.setX(env->GetIntField(jRect, m_javaGlue.m_rectLeft));
870 rect.setY(env->GetIntField(jRect, m_javaGlue.m_rectTop));
872 rect.setWidth(env->CallIntMethod(jRect, m_javaGlue.m_rectWidth));
874 rect.setHeight(env->CallIntMethod(jRect, m_javaGlue.m_rectHeight));
876 env->DeleteLocalRef(jRect);
881 static CachedFrame::Direction KeyToDirection(int32_t keyCode)
884 case AKEYCODE_DPAD_RIGHT:
885 DBG_NAV_LOGD("keyCode=%s", "right");
886 return CachedFrame::RIGHT;
887 case AKEYCODE_DPAD_LEFT:
888 DBG_NAV_LOGD("keyCode=%s", "left");
889 return CachedFrame::LEFT;
890 case AKEYCODE_DPAD_DOWN:
891 DBG_NAV_LOGD("keyCode=%s", "down");
892 return CachedFrame::DOWN;
893 case AKEYCODE_DPAD_UP:
894 DBG_NAV_LOGD("keyCode=%s", "up");
895 return CachedFrame::UP;
897 DBG_NAV_LOGD("bad key %d sent", keyCode);
898 return CachedFrame::UNINITIALIZED;
902 WTF::String imageURI(int x, int y)
904 const CachedRoot* root = getFrameCache(DontAllowNewer);
905 return root ? root->imageURI(x, y) : WTF::String();
908 bool cursorWantsKeyEvents()
910 const CachedRoot* root = getFrameCache(DontAllowNewer);
912 const CachedNode* focus = root->currentCursor();
914 return focus->wantsKeyEvents();
920 /* returns true if the key had no effect (neither scrolled nor changed cursor) */
921 bool moveCursor(int keyCode, int count, bool ignoreScroll)
923 CachedRoot* root = getFrameCache(AllowNewer);
925 DBG_NAV_LOG("!root");
929 m_viewImpl->m_moveGeneration++;
930 CachedFrame::Direction direction = KeyToDirection(keyCode);
931 const CachedFrame* cachedFrame, * oldFrame = 0;
932 const CachedNode* cursor = root->currentCursor(&oldFrame);
933 WebCore::IntPoint cursorLocation = root->cursorLocation();
934 DBG_NAV_LOGD("old cursor %d (nativeNode=%p) cursorLocation={%d, %d}",
935 cursor ? cursor->index() : 0,
936 cursor ? cursor->nodePointer() : 0, cursorLocation.x(), cursorLocation.y());
937 WebCore::IntRect visibleRect = setVisibleRect(root);
938 int xMax = getScaledMaxXScroll();
939 int yMax = getScaledMaxYScroll();
940 root->setMaxScroll(xMax, yMax);
941 const CachedNode* cachedNode = 0;
945 while (--counter >= 0) {
946 WebCore::IntPoint scroll = WebCore::IntPoint(0, 0);
947 cachedNode = root->moveCursor(direction, &cachedFrame, &scroll);
951 DBG_NAV_LOGD("new cursor %d (nativeNode=%p) cursorLocation={%d, %d}"
952 "bounds={%d,%d,w=%d,h=%d}", cachedNode ? cachedNode->index() : 0,
953 cachedNode ? cachedNode->nodePointer() : 0,
954 root->cursorLocation().x(), root->cursorLocation().y(),
955 cachedNode ? cachedNode->bounds(cachedFrame).x() : 0,
956 cachedNode ? cachedNode->bounds(cachedFrame).y() : 0,
957 cachedNode ? cachedNode->bounds(cachedFrame).width() : 0,
958 cachedNode ? cachedNode->bounds(cachedFrame).height() : 0);
959 // If !m_heightCanMeasure (such as in the browser), we want to scroll no
961 if (!ignoreScroll && (!m_heightCanMeasure ||
963 (cursor && cursor->nodePointer() == cachedNode->nodePointer())))
965 if (count == 1 && dx != 0 && dy == 0 && -m_lastDx == dx &&
966 SkTime::GetMSecs() - m_lastDxTime < 1000)
967 root->checkForJiggle(&dx);
968 DBG_NAV_LOGD("scrollBy %d,%d", dx, dy);
970 this->scrollBy(dx, dy);
972 m_lastDxTime = SkTime::GetMSecs();
977 m_viewImpl->updateCursorBounds(root, cachedFrame, cachedNode);
978 root->setCursor(const_cast<CachedFrame*>(cachedFrame),
979 const_cast<CachedNode*>(cachedNode));
980 const CachedNode* focus = root->currentFocus();
981 bool clearTextEntry = cachedNode != focus && focus
982 && cachedNode->nodePointer() != focus->nodePointer() && focus->isTextInput();
983 // Stop painting the caret if the old focus was a text input and so is the new cursor.
984 bool stopPaintingCaret = clearTextEntry && cachedNode->wantsKeyEvents();
985 sendMoveMouseIfLatest(clearTextEntry, stopPaintingCaret);
987 int docHeight = root->documentHeight();
988 int docWidth = root->documentWidth();
989 if (visibleRect.maxY() + dy > docHeight)
990 dy = docHeight - visibleRect.maxY();
991 else if (visibleRect.y() + dy < 0)
992 dy = -visibleRect.y();
993 if (visibleRect.maxX() + dx > docWidth)
994 dx = docWidth - visibleRect.maxX();
995 else if (visibleRect.x() < 0)
996 dx = -visibleRect.x();
997 result = direction == CachedFrame::LEFT ? dx >= 0 :
998 direction == CachedFrame::RIGHT ? dx <= 0 :
999 direction == CachedFrame::UP ? dy >= 0 : dy <= 0;
1004 void notifyProgressFinished()
1006 DBG_NAV_LOGD("cursorIsTextInput=%d", cursorIsTextInput(DontAllowNewer));
1007 rebuildWebTextView();
1009 if (m_frameCacheUI) {
1010 const CachedNode* focus = m_frameCacheUI->currentFocus();
1011 DBG_NAV_LOGD("focus %d (nativeNode=%p)",
1012 focus ? focus->index() : 0,
1013 focus ? focus->nodePointer() : 0);
1018 const CachedNode* findAt(CachedRoot* root, const WebCore::IntRect& rect,
1019 const CachedFrame** framePtr, int* rxPtr, int* ryPtr)
1026 setVisibleRect(root);
1027 return root->findAt(rect, framePtr, rxPtr, ryPtr, true);
1030 IntRect setVisibleRect(CachedRoot* root)
1032 IntRect visibleRect = getVisibleRect();
1033 DBG_NAV_LOGD("getVisibleRect %d,%d,%d,%d",
1034 visibleRect.x(), visibleRect.y(), visibleRect.width(), visibleRect.height());
1035 root->setVisibleRect(visibleRect);
1039 void selectBestAt(const WebCore::IntRect& rect)
1041 const CachedFrame* frame;
1043 CachedRoot* root = getFrameCache(AllowNewer);
1046 const CachedNode* node = findAt(root, rect, &frame, &rx, &ry);
1048 DBG_NAV_LOGD("no nodes found root=%p", root);
1049 root->rootHistory()->setMouseBounds(rect);
1050 m_viewImpl->m_hasCursorBounds = false;
1051 root->setCursor(0, 0);
1054 DBG_NAV_LOGD("CachedNode:%p (%d)", node, node->index());
1055 WebCore::IntRect bounds = node->bounds(frame);
1056 root->rootHistory()->setMouseBounds(bounds);
1057 m_viewImpl->updateCursorBounds(root, frame, node);
1059 root->setCursor(const_cast<CachedFrame*>(frame),
1060 const_cast<CachedNode*>(node));
1062 sendMoveMouseIfLatest(false, false);
1065 const CachedNode* m_cacheHitNode;
1066 const CachedFrame* m_cacheHitFrame;
1068 bool pointInNavCache(int x, int y, int slop)
1070 CachedRoot* root = getFrameCache(AllowNewer);
1073 IntRect rect = IntRect(x - slop, y - slop, slop * 2, slop * 2);
1075 return (m_cacheHitNode = findAt(root, rect, &m_cacheHitFrame, &rx, &ry));
1078 bool motionUp(int x, int y, int slop)
1080 bool pageScrolled = false;
1081 IntRect rect = IntRect(x - slop, y - slop, slop * 2, slop * 2);
1083 CachedRoot* root = getFrameCache(AllowNewer);
1086 const CachedFrame* frame = 0;
1087 const CachedNode* result = findAt(root, rect, &frame, &rx, &ry);
1088 CachedHistory* history = root->rootHistory();
1090 DBG_NAV_LOGD("no nodes found root=%p", root);
1091 history->setNavBounds(rect);
1092 m_viewImpl->m_hasCursorBounds = false;
1094 int dx = root->checkForCenter(x, y);
1097 pageScrolled = true;
1099 sendMotionUp(frame ? (WebCore::Frame*) frame->framePointer() : 0,
1102 return pageScrolled;
1104 DBG_NAV_LOGD("CachedNode:%p (%d) x=%d y=%d rx=%d ry=%d", result,
1105 result->index(), x, y, rx, ry);
1106 WebCore::IntRect navBounds = WebCore::IntRect(rx, ry, 1, 1);
1107 history->setNavBounds(navBounds);
1108 history->setMouseBounds(navBounds);
1109 m_viewImpl->updateCursorBounds(root, frame, result);
1110 root->setCursor(const_cast<CachedFrame*>(frame),
1111 const_cast<CachedNode*>(result));
1112 if (result->isSyntheticLink())
1113 overrideUrlLoading(result->getExport());
1116 (WebCore::Frame*) frame->framePointer(),
1117 (WebCore::Node*) result->nodePointer(), rx, ry);
1119 if (result->isTextInput() || result->isSelect()
1120 || result->isContentEditable()) {
1121 showCursorUntimed();
1124 return pageScrolled;
1127 #if USE(ACCELERATED_COMPOSITING)
1128 static const ScrollableLayerAndroid* findScrollableLayer(
1129 const LayerAndroid* parent, int x, int y, SkIRect* foundBounds) {
1131 parent->bounds(&bounds);
1132 // Check the parent bounds first; this will clip to within a masking layer's
1134 if (parent->masksToBounds() && !bounds.contains(x, y))
1136 // Move the hit test local to parent.
1139 int count = parent->countChildren();
1141 const LayerAndroid* child = parent->getChild(count);
1142 const ScrollableLayerAndroid* result = findScrollableLayer(child, x, y,
1145 foundBounds->offset(bounds.fLeft, bounds.fTop);
1146 if (parent->masksToBounds()) {
1147 if (bounds.width() < foundBounds->width())
1148 foundBounds->fRight = foundBounds->fLeft + bounds.width();
1149 if (bounds.height() < foundBounds->height())
1150 foundBounds->fBottom = foundBounds->fTop + bounds.height();
1155 if (parent->contentIsScrollable()) {
1156 foundBounds->set(0, 0, bounds.width(), bounds.height());
1157 return static_cast<const ScrollableLayerAndroid*>(parent);
1163 int scrollableLayer(int x, int y, SkIRect* layerRect, SkIRect* bounds)
1165 #if USE(ACCELERATED_COMPOSITING)
1166 const LayerAndroid* layerRoot = compositeRoot();
1169 const ScrollableLayerAndroid* result = findScrollableLayer(layerRoot, x, y,
1172 result->getScrollRect(layerRect);
1173 return result->uniqueId();
1179 int getBlockLeftEdge(int x, int y, float scale)
1181 CachedRoot* root = getFrameCache(AllowNewer);
1183 return root->getBlockLeftEdge(x, y, scale);
1187 void overrideUrlLoading(const WTF::String& url)
1189 JNIEnv* env = JSC::Bindings::getJNIEnv();
1190 AutoJObject javaObject = m_javaGlue.object(env);
1191 if (!javaObject.get())
1193 jstring jName = wtfStringToJstring(env, url);
1194 env->CallVoidMethod(javaObject.get(), m_javaGlue.m_overrideLoading, jName);
1195 env->DeleteLocalRef(jName);
1198 void setFindIsUp(bool up)
1200 DBG_NAV_LOGD("up=%d", up);
1201 m_viewImpl->m_findIsUp = up;
1204 void setFindIsEmpty()
1207 m_findOnPage.clearCurrentLocation();
1210 void showCursorTimed()
1213 m_ringAnimationEnd = SkTime::GetMSecs() + PRESSED_STATE_DURATION;
1217 void showCursorUntimed()
1220 m_ring.m_isPressed = false;
1221 m_ringAnimationEnd = UINT_MAX;
1225 void setHeightCanMeasure(bool measure)
1227 m_heightCanMeasure = measure;
1230 String getSelection()
1232 return m_selectText.getSelection();
1235 void moveSelection(int x, int y)
1237 m_selectText.moveSelection(getVisibleRect(), x, y);
1240 IntPoint selectableText()
1242 const CachedRoot* root = getFrameCache(DontAllowNewer);
1244 return IntPoint(0, 0);
1245 return m_selectText.selectableText(root);
1250 m_selectText.selectAll();
1255 return m_selectText.selectionX();
1260 return m_selectText.selectionY();
1263 void resetSelection()
1265 m_selectText.reset();
1268 bool startSelection(int x, int y)
1270 const CachedRoot* root = getFrameCache(DontAllowNewer);
1273 updateSelectionHandles();
1274 return m_selectText.startSelection(root, getVisibleRect(), x, y);
1277 bool wordSelection(int x, int y)
1279 const CachedRoot* root = getFrameCache(DontAllowNewer);
1282 updateSelectionHandles();
1283 return m_selectText.wordSelection(root, getVisibleRect(), x, y);
1286 bool extendSelection(int x, int y)
1288 m_selectText.extendSelection(getVisibleRect(), x, y);
1292 bool hitSelection(int x, int y)
1294 updateSelectionHandles();
1295 return m_selectText.hitSelection(x, y);
1298 void setExtendSelection()
1300 m_selectText.setExtendSelection(true);
1303 void setSelectionPointer(bool set, float scale, int x, int y)
1305 m_selectText.setDrawPointer(set);
1308 m_selectText.m_inverseScale = scale;
1309 m_selectText.m_selectX = x;
1310 m_selectText.m_selectY = y;
1313 void sendMoveFocus(WebCore::Frame* framePtr, WebCore::Node* nodePtr)
1315 DBG_NAV_LOGD("framePtr=%p nodePtr=%p", framePtr, nodePtr);
1316 JNIEnv* env = JSC::Bindings::getJNIEnv();
1317 AutoJObject javaObject = m_javaGlue.object(env);
1318 if (!javaObject.get())
1320 env->CallVoidMethod(javaObject.get(), m_javaGlue.m_sendMoveFocus, (jint) framePtr, (jint) nodePtr);
1321 checkException(env);
1324 void sendMoveMouse(WebCore::Frame* framePtr, WebCore::Node* nodePtr, int x, int y)
1326 DBG_NAV_LOGD("framePtr=%p nodePtr=%p x=%d y=%d", framePtr, nodePtr, x, y);
1327 JNIEnv* env = JSC::Bindings::getJNIEnv();
1328 AutoJObject javaObject = m_javaGlue.object(env);
1329 if (!javaObject.get())
1331 env->CallVoidMethod(javaObject.get(), m_javaGlue.m_sendMoveMouse, reinterpret_cast<jint>(framePtr), reinterpret_cast<jint>(nodePtr), x, y);
1332 checkException(env);
1335 void sendMoveMouseIfLatest(bool clearTextEntry, bool stopPaintingCaret)
1337 LOG_ASSERT(m_javaGlue.m_obj, "A java object was not associated with this native WebView!");
1338 JNIEnv* env = JSC::Bindings::getJNIEnv();
1339 AutoJObject javaObject = m_javaGlue.object(env);
1340 if (!javaObject.get())
1342 env->CallVoidMethod(javaObject.get(), m_javaGlue.m_sendMoveMouseIfLatest, clearTextEntry, stopPaintingCaret);
1343 checkException(env);
1346 void sendMotionUp(WebCore::Frame* framePtr, WebCore::Node* nodePtr, int x, int y)
1348 DBG_NAV_LOGD("m_generation=%d framePtr=%p nodePtr=%p x=%d y=%d", m_generation, framePtr, nodePtr, x, y);
1349 LOG_ASSERT(m_javaGlue.m_obj, "A WebView was not associated with this WebViewNative!");
1351 JNIEnv* env = JSC::Bindings::getJNIEnv();
1352 AutoJObject javaObject = m_javaGlue.object(env);
1353 if (!javaObject.get())
1355 m_viewImpl->m_touchGeneration = ++m_generation;
1356 env->CallVoidMethod(javaObject.get(), m_javaGlue.m_sendMotionUp, m_generation, (jint) framePtr, (jint) nodePtr, x, y);
1357 checkException(env);
1360 void findNext(bool forward)
1362 m_findOnPage.findNext(forward);
1363 scrollToCurrentMatch();
1367 // With this call, WebView takes ownership of matches, and is responsible for
1369 void setMatches(WTF::Vector<MatchInfo>* matches, jboolean sameAsLastSearch)
1371 // If this search is the same as the last one, check against the old
1372 // location to determine whether to scroll. If the same word is found
1373 // in the same place, then do not scroll.
1374 IntRect oldLocation;
1375 bool checkAgainstOldLocation = false;
1376 if (sameAsLastSearch && m_findOnPage.isCurrentLocationValid()) {
1377 oldLocation = m_findOnPage.currentMatchBounds();
1378 checkAgainstOldLocation = true;
1381 m_findOnPage.setMatches(matches);
1383 if (!checkAgainstOldLocation || oldLocation != m_findOnPage.currentMatchBounds())
1384 scrollToCurrentMatch();
1388 int currentMatchIndex()
1390 return m_findOnPage.currentMatchIndex();
1393 bool scrollBy(int dx, int dy)
1395 LOG_ASSERT(m_javaGlue.m_obj, "A java object was not associated with this native WebView!");
1397 JNIEnv* env = JSC::Bindings::getJNIEnv();
1398 AutoJObject javaObject = m_javaGlue.object(env);
1399 if (!javaObject.get())
1401 bool result = env->CallBooleanMethod(javaObject.get(), m_javaGlue.m_scrollBy, dx, dy, true);
1402 checkException(env);
1406 void setIsScrolling(bool isScrolling)
1408 #if USE(ACCELERATED_COMPOSITING)
1409 if (m_glWebViewState)
1410 m_glWebViewState->setIsScrolling(isScrolling);
1414 bool hasCursorNode()
1416 CachedRoot* root = getFrameCache(DontAllowNewer);
1418 DBG_NAV_LOG("!root");
1421 const CachedNode* cursorNode = root->currentCursor();
1422 DBG_NAV_LOGD("cursorNode=%d (nodePointer=%p)",
1423 cursorNode ? cursorNode->index() : -1,
1424 cursorNode ? cursorNode->nodePointer() : 0);
1430 CachedRoot* root = getFrameCache(DontAllowNewer);
1432 DBG_NAV_LOG("!root");
1435 const CachedNode* focusNode = root->currentFocus();
1436 DBG_NAV_LOGD("focusNode=%d (nodePointer=%p)",
1437 focusNode ? focusNode->index() : -1,
1438 focusNode ? focusNode->nodePointer() : 0);
1442 void rebuildWebTextView()
1444 JNIEnv* env = JSC::Bindings::getJNIEnv();
1445 AutoJObject javaObject = m_javaGlue.object(env);
1446 if (!javaObject.get())
1448 env->CallVoidMethod(javaObject.get(), m_javaGlue.m_rebuildWebTextView);
1449 checkException(env);
1452 void viewInvalidate()
1454 JNIEnv* env = JSC::Bindings::getJNIEnv();
1455 AutoJObject javaObject = m_javaGlue.object(env);
1456 if (!javaObject.get())
1458 env->CallVoidMethod(javaObject.get(), m_javaGlue.m_viewInvalidate);
1459 checkException(env);
1462 void viewInvalidateRect(int l, int t, int r, int b)
1464 JNIEnv* env = JSC::Bindings::getJNIEnv();
1465 AutoJObject javaObject = m_javaGlue.object(env);
1466 if (!javaObject.get())
1468 env->CallVoidMethod(javaObject.get(), m_javaGlue.m_viewInvalidateRect, l, r, t, b);
1469 checkException(env);
1472 void postInvalidateDelayed(int64_t delay, const WebCore::IntRect& bounds)
1474 JNIEnv* env = JSC::Bindings::getJNIEnv();
1475 AutoJObject javaObject = m_javaGlue.object(env);
1476 if (!javaObject.get())
1478 env->CallVoidMethod(javaObject.get(), m_javaGlue.m_postInvalidateDelayed,
1479 delay, bounds.x(), bounds.y(), bounds.maxX(), bounds.maxY());
1480 checkException(env);
1483 bool inFullScreenMode()
1485 JNIEnv* env = JSC::Bindings::getJNIEnv();
1486 AutoJObject javaObject = m_javaGlue.object(env);
1487 if (!javaObject.get())
1489 jboolean result = env->CallBooleanMethod(javaObject.get(), m_javaGlue.m_inFullScreenMode);
1490 checkException(env);
1494 int moveGeneration()
1496 return m_viewImpl->m_moveGeneration;
1499 LayerAndroid* compositeRoot() const
1501 LOG_ASSERT(!m_baseLayer || m_baseLayer->countChildren() == 1,
1502 "base layer can't have more than one child %s", __FUNCTION__);
1503 if (m_baseLayer && m_baseLayer->countChildren() == 1)
1504 return static_cast<LayerAndroid*>(m_baseLayer->getChild(0));
1509 #if ENABLE(ANDROID_OVERFLOW_SCROLL)
1510 static void copyScrollPositionRecursive(const LayerAndroid* from,
1515 for (int i = 0; i < from->countChildren(); i++) {
1516 const LayerAndroid* l = from->getChild(i);
1517 if (l->contentIsScrollable()) {
1518 const SkPoint& pos = l->getPosition();
1519 LayerAndroid* match = root->findById(l->uniqueId());
1520 if (match && match->contentIsScrollable())
1521 match->setPosition(pos.fX, pos.fY);
1523 copyScrollPositionRecursive(l, root);
1528 void registerPageSwapCallback()
1530 m_pageSwapCallbackRegistered = true;
1533 void setBaseLayer(BaseLayerAndroid* layer, SkRegion& inval, bool showVisualIndicator,
1534 bool isPictureAfterFirstLayout, bool registerPageSwapCallback)
1536 #if USE(ACCELERATED_COMPOSITING)
1537 if (m_glWebViewState)
1538 m_glWebViewState->setBaseLayer(layer, inval, showVisualIndicator,
1539 isPictureAfterFirstLayout);
1540 m_pageSwapCallbackRegistered |= registerPageSwapCallback;
1543 #if ENABLE(ANDROID_OVERFLOW_SCROLL)
1545 LayerAndroid* newCompositeRoot = static_cast<LayerAndroid*>(layer->getChild(0));
1546 copyScrollPositionRecursive(compositeRoot(), newCompositeRoot);
1549 SkSafeUnref(m_baseLayer);
1550 m_baseLayer = layer;
1551 CachedRoot* root = getFrameCache(DontAllowNewer);
1554 root->resetLayers();
1555 root->setRootLayer(compositeRoot());
1558 void getTextSelectionRegion(SkRegion *region)
1560 m_selectText.getSelectionRegion(getVisibleRect(), region);
1563 void replaceBaseContent(PictureSet* set)
1567 m_baseLayer->setContent(*set);
1571 void copyBaseContentToPicture(SkPicture* picture)
1575 PictureSet* content = m_baseLayer->content();
1576 m_baseLayer->drawCanvas(picture->beginRecording(content->width(), content->height(),
1577 SkPicture::kUsePathBoundsForClip_RecordingFlag));
1578 picture->endRecording();
1584 return !m_baseLayer->content()->isEmpty();
1587 void setFunctor(Functor* functor) {
1588 delete m_glDrawFunctor;
1589 m_glDrawFunctor = functor;
1592 Functor* getFunctor() {
1593 return m_glDrawFunctor;
1596 BaseLayerAndroid* getBaseLayer() {
1600 private: // local state for WebView
1601 // private to getFrameCache(); other functions operate in a different thread
1602 CachedRoot* m_frameCacheUI; // navigation data ready for use
1603 WebViewCore* m_viewImpl;
1604 int m_generation; // associate unique ID with sent kit focus to match with ui
1605 SkPicture* m_navPictureUI;
1606 SkMSec m_ringAnimationEnd;
1607 // Corresponds to the same-named boolean on the java side.
1608 bool m_heightCanMeasure;
1610 SkMSec m_lastDxTime;
1611 SelectText m_selectText;
1612 FindOnPage m_findOnPage;
1614 BaseLayerAndroid* m_baseLayer;
1615 Functor* m_glDrawFunctor;
1616 #if USE(ACCELERATED_COMPOSITING)
1617 GLWebViewState* m_glWebViewState;
1618 bool m_pageSwapCallbackRegistered;
1620 RenderSkinButton* m_buttonSkin;
1621 }; // end of WebView class
1625 * This class holds a function pointer and parameters for calling drawGL into a specific
1626 * viewport. The pointer to the Functor will be put on a framework display list to be called
1627 * when the display list is replayed.
1629 class GLDrawFunctor : Functor {
1631 GLDrawFunctor(WebView* _wvInstance,
1632 bool(WebView::*_funcPtr)(WebCore::IntRect&, WebCore::IntRect*, WebCore::IntRect&, int, WebCore::IntRect&, jfloat, jint),
1633 WebCore::IntRect _viewRect, float _scale, int _extras) {
1634 wvInstance = _wvInstance;
1636 viewRect = _viewRect;
1640 status_t operator()(int messageId, void* data) {
1641 if (viewRect.isEmpty()) {
1642 // NOOP operation if viewport is empty
1646 WebCore::IntRect inval;
1647 int titlebarHeight = webViewRect.height() - viewRect.height();
1649 uirenderer::DrawGlInfo* info = reinterpret_cast<uirenderer::DrawGlInfo*>(data);
1650 WebCore::IntRect localViewRect = viewRect;
1652 localViewRect.move(-1 * localViewRect.x(), -1 * localViewRect.y());
1654 WebCore::IntRect clip(info->clipLeft, info->clipTop,
1655 info->clipRight - info->clipLeft,
1656 info->clipBottom - info->clipTop);
1658 bool retVal = (*wvInstance.*funcPtr)(localViewRect, &inval, webViewRect, titlebarHeight, clip, scale, extras);
1661 if (inval.isEmpty()) {
1662 finalInval = webViewRect;
1665 finalInval.setX(webViewRect.x() + inval.x());
1666 finalInval.setY(webViewRect.y() + titlebarHeight + inval.y());
1667 finalInval.setWidth(inval.width());
1668 finalInval.setHeight(inval.height());
1670 info->dirtyLeft = finalInval.x();
1671 info->dirtyTop = finalInval.y();
1672 info->dirtyRight = finalInval.maxX();
1673 info->dirtyBottom = finalInval.maxY();
1675 // return 1 if invalidation needed, 0 otherwise
1676 return retVal ? 1 : 0;
1678 void updateRect(WebCore::IntRect& _viewRect) {
1679 viewRect = _viewRect;
1681 void updateViewRect(WebCore::IntRect& _viewRect) {
1682 webViewRect = _viewRect;
1685 WebView* wvInstance;
1686 bool (WebView::*funcPtr)(WebCore::IntRect&, WebCore::IntRect*, WebCore::IntRect&, int, WebCore::IntRect&, float, int);
1687 WebCore::IntRect viewRect;
1688 WebCore::IntRect webViewRect;
1693 static jobject createJavaRect(JNIEnv* env, int x, int y, int right, int bottom)
1695 jclass rectClass = env->FindClass("android/graphics/Rect");
1696 jmethodID init = env->GetMethodID(rectClass, "<init>", "(IIII)V");
1697 jobject rect = env->NewObject(rectClass, init, x, y, right, bottom);
1698 env->DeleteLocalRef(rectClass);
1703 * Native JNI methods
1705 static int nativeCacheHitFramePointer(JNIEnv *env, jobject obj)
1707 return reinterpret_cast<int>(GET_NATIVE_VIEW(env, obj)
1708 ->m_cacheHitFrame->framePointer());
1711 static jobject nativeCacheHitNodeBounds(JNIEnv *env, jobject obj)
1713 WebCore::IntRect bounds = GET_NATIVE_VIEW(env, obj)
1714 ->m_cacheHitNode->originalAbsoluteBounds();
1715 return createJavaRect(env, bounds.x(), bounds.y(),
1716 bounds.maxX(), bounds.maxY());
1719 static int nativeCacheHitNodePointer(JNIEnv *env, jobject obj)
1721 return reinterpret_cast<int>(GET_NATIVE_VIEW(env, obj)
1722 ->m_cacheHitNode->nodePointer());
1725 static bool nativeCacheHitIsPlugin(JNIEnv *env, jobject obj)
1727 return GET_NATIVE_VIEW(env, obj)->m_cacheHitNode->isPlugin();
1730 static void nativeClearCursor(JNIEnv *env, jobject obj)
1732 WebView* view = GET_NATIVE_VIEW(env, obj);
1733 LOG_ASSERT(view, "view not set in %s", __FUNCTION__);
1734 view->clearCursor();
1737 static void nativeCreate(JNIEnv *env, jobject obj, int viewImpl, jstring drawableDir)
1739 WTF::String dir = jstringToWtfString(env, drawableDir);
1740 WebView* webview = new WebView(env, obj, viewImpl, dir);
1741 // NEED THIS OR SOMETHING LIKE IT!
1745 static jint nativeCursorFramePointer(JNIEnv *env, jobject obj)
1747 WebView* view = GET_NATIVE_VIEW(env, obj);
1748 CachedRoot* root = view->getFrameCache(WebView::DontAllowNewer);
1751 const CachedFrame* frame = 0;
1752 (void) root->currentCursor(&frame);
1753 return reinterpret_cast<int>(frame ? frame->framePointer() : 0);
1756 static const CachedNode* getCursorNode(JNIEnv *env, jobject obj)
1758 WebView* view = GET_NATIVE_VIEW(env, obj);
1759 CachedRoot* root = view->getFrameCache(WebView::DontAllowNewer);
1760 return root ? root->currentCursor() : 0;
1763 static const CachedNode* getCursorNode(JNIEnv *env, jobject obj,
1764 const CachedFrame** frame)
1766 WebView* view = GET_NATIVE_VIEW(env, obj);
1767 CachedRoot* root = view->getFrameCache(WebView::DontAllowNewer);
1768 return root ? root->currentCursor(frame) : 0;
1771 static const CachedNode* getFocusCandidate(JNIEnv *env, jobject obj,
1772 const CachedFrame** frame)
1774 WebView* view = GET_NATIVE_VIEW(env, obj);
1775 CachedRoot* root = view->getFrameCache(WebView::DontAllowNewer);
1778 const CachedNode* cursor = root->currentCursor(frame);
1779 if (cursor && cursor->wantsKeyEvents())
1781 return root->currentFocus(frame);
1784 static bool focusCandidateHasNextTextfield(JNIEnv *env, jobject obj)
1786 WebView* view = GET_NATIVE_VIEW(env, obj);
1787 CachedRoot* root = view->getFrameCache(WebView::DontAllowNewer);
1790 const CachedNode* cursor = root->currentCursor();
1791 if (!cursor || !cursor->isTextInput())
1792 cursor = root->currentFocus();
1793 if (!cursor || !cursor->isTextInput()) return false;
1794 return root->nextTextField(cursor, 0);
1797 static const CachedNode* getFocusNode(JNIEnv *env, jobject obj)
1799 WebView* view = GET_NATIVE_VIEW(env, obj);
1800 CachedRoot* root = view->getFrameCache(WebView::DontAllowNewer);
1801 return root ? root->currentFocus() : 0;
1804 static const CachedNode* getFocusNode(JNIEnv *env, jobject obj,
1805 const CachedFrame** frame)
1807 WebView* view = GET_NATIVE_VIEW(env, obj);
1808 CachedRoot* root = view->getFrameCache(WebView::DontAllowNewer);
1809 return root ? root->currentFocus(frame) : 0;
1812 static const CachedInput* getInputCandidate(JNIEnv *env, jobject obj)
1814 WebView* view = GET_NATIVE_VIEW(env, obj);
1815 CachedRoot* root = view->getFrameCache(WebView::DontAllowNewer);
1818 const CachedFrame* frame;
1819 const CachedNode* cursor = root->currentCursor(&frame);
1820 if (!cursor || !cursor->wantsKeyEvents())
1821 cursor = root->currentFocus(&frame);
1822 return cursor ? frame->textInput(cursor) : 0;
1825 static jboolean nativePageShouldHandleShiftAndArrows(JNIEnv *env, jobject obj)
1827 const CachedNode* focus = getFocusNode(env, obj);
1828 if (!focus) return false;
1829 // Plugins handle shift and arrows whether or not they have focus.
1830 if (focus->isPlugin()) return true;
1831 const CachedNode* cursor = getCursorNode(env, obj);
1832 // ContentEditable nodes should only receive shift and arrows if they have
1833 // both the cursor and the focus.
1834 return cursor && cursor->nodePointer() == focus->nodePointer()
1835 && cursor->isContentEditable();
1838 static jobject nativeCursorNodeBounds(JNIEnv *env, jobject obj)
1840 const CachedFrame* frame;
1841 const CachedNode* node = getCursorNode(env, obj, &frame);
1842 WebCore::IntRect bounds = node ? node->bounds(frame)
1843 : WebCore::IntRect(0, 0, 0, 0);
1844 return createJavaRect(env, bounds.x(), bounds.y(),
1845 bounds.maxX(), bounds.maxY());
1848 static jint nativeCursorNodePointer(JNIEnv *env, jobject obj)
1850 const CachedNode* node = getCursorNode(env, obj);
1851 return reinterpret_cast<int>(node ? node->nodePointer() : 0);
1854 static jobject nativeCursorPosition(JNIEnv *env, jobject obj)
1856 WebView* view = GET_NATIVE_VIEW(env, obj);
1857 const CachedRoot* root = view->getFrameCache(WebView::DontAllowNewer);
1858 WebCore::IntPoint pos = WebCore::IntPoint(0, 0);
1860 root->getSimulatedMousePosition(&pos);
1861 jclass pointClass = env->FindClass("android/graphics/Point");
1862 jmethodID init = env->GetMethodID(pointClass, "<init>", "(II)V");
1863 jobject point = env->NewObject(pointClass, init, pos.x(), pos.y());
1864 env->DeleteLocalRef(pointClass);
1868 static WebCore::IntRect jrect_to_webrect(JNIEnv* env, jobject obj)
1871 GraphicsJNI::get_jrect(env, obj, &L, &T, &R, &B);
1872 return WebCore::IntRect(L, T, R - L, B - T);
1875 static bool nativeCursorIntersects(JNIEnv *env, jobject obj, jobject visRect)
1877 const CachedFrame* frame;
1878 const CachedNode* node = getCursorNode(env, obj, &frame);
1879 return node ? node->bounds(frame).intersects(
1880 jrect_to_webrect(env, visRect)) : false;
1883 static bool nativeCursorIsAnchor(JNIEnv *env, jobject obj)
1885 const CachedNode* node = getCursorNode(env, obj);
1886 return node ? node->isAnchor() : false;
1889 static bool nativeCursorIsTextInput(JNIEnv *env, jobject obj)
1891 const CachedNode* node = getCursorNode(env, obj);
1892 return node ? node->isTextInput() : false;
1895 static jobject nativeCursorText(JNIEnv *env, jobject obj)
1897 const CachedNode* node = getCursorNode(env, obj);
1900 WTF::String value = node->getExport();
1901 return wtfStringToJstring(env, value);
1904 static void nativeDebugDump(JNIEnv *env, jobject obj)
1907 WebView* view = GET_NATIVE_VIEW(env, obj);
1908 LOG_ASSERT(view, "view not set in %s", __FUNCTION__);
1913 static jint nativeDraw(JNIEnv *env, jobject obj, jobject canv, jint color,
1914 jint extras, jboolean split) {
1915 SkCanvas* canvas = GraphicsJNI::getNativeCanvas(env, canv);
1916 return reinterpret_cast<jint>(GET_NATIVE_VIEW(env, obj)->draw(canvas, color, extras, split));
1919 static jint nativeGetDrawGLFunction(JNIEnv *env, jobject obj, jobject jrect, jobject jviewrect,
1920 jfloat scale, jint extras) {
1921 WebCore::IntRect viewRect;
1922 if (jrect == NULL) {
1923 viewRect = WebCore::IntRect();
1925 viewRect = jrect_to_webrect(env, jrect);
1927 WebView *wvInstance = GET_NATIVE_VIEW(env, obj);
1928 GLDrawFunctor* functor = new GLDrawFunctor(wvInstance, &android::WebView::drawGL,
1929 viewRect, scale, extras);
1930 wvInstance->setFunctor((Functor*) functor);
1932 WebCore::IntRect webViewRect;
1933 if (jviewrect == NULL) {
1934 webViewRect = WebCore::IntRect();
1936 webViewRect = jrect_to_webrect(env, jviewrect);
1938 functor->updateViewRect(webViewRect);
1940 return (jint)functor;
1943 static void nativeUpdateDrawGLFunction(JNIEnv *env, jobject obj, jobject jrect, jobject jviewrect) {
1944 WebView *wvInstance = GET_NATIVE_VIEW(env, obj);
1945 if (wvInstance != NULL) {
1946 GLDrawFunctor* functor = (GLDrawFunctor*) wvInstance->getFunctor();
1947 if (functor != NULL) {
1948 WebCore::IntRect viewRect;
1949 if (jrect == NULL) {
1950 viewRect = WebCore::IntRect();
1952 viewRect = jrect_to_webrect(env, jrect);
1954 functor->updateRect(viewRect);
1956 WebCore::IntRect webViewRect;
1957 if (jviewrect == NULL) {
1958 webViewRect = WebCore::IntRect();
1960 webViewRect = jrect_to_webrect(env, jviewrect);
1962 functor->updateViewRect(webViewRect);
1967 static bool nativeEvaluateLayersAnimations(JNIEnv *env, jobject obj)
1969 #if USE(ACCELERATED_COMPOSITING)
1970 LayerAndroid* root = GET_NATIVE_VIEW(env, obj)->compositeRoot();
1972 return root->evaluateAnimations();
1977 static void nativeSetBaseLayer(JNIEnv *env, jobject obj, jint layer, jobject inval,
1978 jboolean showVisualIndicator,
1979 jboolean isPictureAfterFirstLayout,
1980 jboolean registerPageSwapCallback)
1982 BaseLayerAndroid* layerImpl = reinterpret_cast<BaseLayerAndroid*>(layer);
1983 SkRegion invalRegion;
1985 invalRegion = *GraphicsJNI::getNativeRegion(env, inval);
1986 GET_NATIVE_VIEW(env, obj)->setBaseLayer(layerImpl, invalRegion, showVisualIndicator,
1987 isPictureAfterFirstLayout,
1988 registerPageSwapCallback);
1991 static void nativeGetTextSelectionRegion(JNIEnv *env, jobject obj, jobject region)
1995 SkRegion* nregion = GraphicsJNI::getNativeRegion(env, region);
1996 GET_NATIVE_VIEW(env, obj)->getTextSelectionRegion(nregion);
1999 static BaseLayerAndroid* nativeGetBaseLayer(JNIEnv *env, jobject obj)
2001 return GET_NATIVE_VIEW(env, obj)->getBaseLayer();
2004 static void nativeReplaceBaseContent(JNIEnv *env, jobject obj, jint content)
2006 PictureSet* set = reinterpret_cast<PictureSet*>(content);
2007 GET_NATIVE_VIEW(env, obj)->replaceBaseContent(set);
2010 static void nativeCopyBaseContentToPicture(JNIEnv *env, jobject obj, jobject pict)
2012 SkPicture* picture = GraphicsJNI::getNativePicture(env, pict);
2013 GET_NATIVE_VIEW(env, obj)->copyBaseContentToPicture(picture);
2016 static bool nativeHasContent(JNIEnv *env, jobject obj)
2018 return GET_NATIVE_VIEW(env, obj)->hasContent();
2021 static jobject nativeImageURI(JNIEnv *env, jobject obj, jint x, jint y)
2023 WebView* view = GET_NATIVE_VIEW(env, obj);
2024 LOG_ASSERT(view, "view not set in %s", __FUNCTION__);
2025 WTF::String uri = view->imageURI(x, y);
2026 return wtfStringToJstring(env, uri);
2029 static jint nativeFocusCandidateFramePointer(JNIEnv *env, jobject obj)
2031 WebView* view = GET_NATIVE_VIEW(env, obj);
2032 CachedRoot* root = view->getFrameCache(WebView::DontAllowNewer);
2035 const CachedFrame* frame = 0;
2036 const CachedNode* cursor = root->currentCursor(&frame);
2037 if (!cursor || !cursor->wantsKeyEvents())
2038 (void) root->currentFocus(&frame);
2039 return reinterpret_cast<int>(frame ? frame->framePointer() : 0);
2042 static bool nativeFocusCandidateIsPassword(JNIEnv *env, jobject obj)
2044 const CachedInput* input = getInputCandidate(env, obj);
2045 return input && input->getType() == CachedInput::PASSWORD;
2048 static bool nativeFocusCandidateIsRtlText(JNIEnv *env, jobject obj)
2050 const CachedInput* input = getInputCandidate(env, obj);
2051 return input ? input->isRtlText() : false;
2054 static bool nativeFocusCandidateIsTextInput(JNIEnv *env, jobject obj)
2056 const CachedNode* node = getFocusCandidate(env, obj, 0);
2057 return node ? node->isTextInput() : false;
2060 static jint nativeFocusCandidateMaxLength(JNIEnv *env, jobject obj)
2062 const CachedInput* input = getInputCandidate(env, obj);
2063 return input ? input->maxLength() : false;
2066 static jint nativeFocusCandidateIsAutoComplete(JNIEnv *env, jobject obj)
2068 const CachedInput* input = getInputCandidate(env, obj);
2069 return input ? input->autoComplete() : false;
2072 static jobject nativeFocusCandidateName(JNIEnv *env, jobject obj)
2074 const CachedInput* input = getInputCandidate(env, obj);
2077 const WTF::String& name = input->name();
2078 return wtfStringToJstring(env, name);
2081 static jobject nativeFocusCandidateNodeBounds(JNIEnv *env, jobject obj)
2083 const CachedFrame* frame;
2084 const CachedNode* node = getFocusCandidate(env, obj, &frame);
2085 WebCore::IntRect bounds = node ? node->bounds(frame)
2086 : WebCore::IntRect(0, 0, 0, 0);
2087 // Inset the rect by 1 unit, so that the focus candidate's border can still
2088 // be seen behind it.
2089 return createJavaRect(env, bounds.x() + 1, bounds.y() + 1,
2090 bounds.maxX() - 1, bounds.maxY() - 1);
2093 static jobject nativeFocusCandidatePaddingRect(JNIEnv *env, jobject obj)
2095 const CachedInput* input = getInputCandidate(env, obj);
2098 // Note that the Java Rect is being used to pass four integers, rather than
2099 // being used as an actual rectangle.
2100 return createJavaRect(env, input->paddingLeft(), input->paddingTop(),
2101 input->paddingRight(), input->paddingBottom());
2104 static jint nativeFocusCandidatePointer(JNIEnv *env, jobject obj)
2106 const CachedNode* node = getFocusCandidate(env, obj, 0);
2107 return reinterpret_cast<int>(node ? node->nodePointer() : 0);
2110 static jint nativeFocusCandidateIsSpellcheck(JNIEnv *env, jobject obj)
2112 const CachedInput* input = getInputCandidate(env, obj);
2113 return input ? input->spellcheck() : false;
2116 static jobject nativeFocusCandidateText(JNIEnv *env, jobject obj)
2118 const CachedNode* node = getFocusCandidate(env, obj, 0);
2121 WTF::String value = node->getExport();
2122 return wtfStringToJstring(env, value);
2125 static int nativeFocusCandidateLineHeight(JNIEnv *env, jobject obj)
2127 const CachedInput* input = getInputCandidate(env, obj);
2128 return input ? input->lineHeight() : 0;
2131 static jfloat nativeFocusCandidateTextSize(JNIEnv *env, jobject obj)
2133 const CachedInput* input = getInputCandidate(env, obj);
2134 return input ? input->textSize() : 0.f;
2137 static int nativeFocusCandidateType(JNIEnv *env, jobject obj)
2139 const CachedInput* input = getInputCandidate(env, obj);
2141 return CachedInput::NONE;
2143 if (input->isTextArea())
2144 return CachedInput::TEXT_AREA;
2146 return input->getType();
2149 static bool nativeFocusIsPlugin(JNIEnv *env, jobject obj)
2151 const CachedNode* node = getFocusNode(env, obj);
2152 return node ? node->isPlugin() : false;
2155 static jobject nativeFocusNodeBounds(JNIEnv *env, jobject obj)
2157 const CachedFrame* frame;
2158 const CachedNode* node = getFocusNode(env, obj, &frame);
2159 WebCore::IntRect bounds = node ? node->bounds(frame)
2160 : WebCore::IntRect(0, 0, 0, 0);
2161 return createJavaRect(env, bounds.x(), bounds.y(),
2162 bounds.maxX(), bounds.maxY());
2165 static jint nativeFocusNodePointer(JNIEnv *env, jobject obj)
2167 const CachedNode* node = getFocusNode(env, obj);
2168 return node ? reinterpret_cast<int>(node->nodePointer()) : 0;
2171 static bool nativeCursorWantsKeyEvents(JNIEnv* env, jobject jwebview) {
2172 WebView* view = GET_NATIVE_VIEW(env, jwebview);
2173 LOG_ASSERT(view, "view not set in %s", __FUNCTION__);
2174 return view->cursorWantsKeyEvents();
2177 static void nativeHideCursor(JNIEnv *env, jobject obj)
2179 WebView* view = GET_NATIVE_VIEW(env, obj);
2180 LOG_ASSERT(view, "view not set in %s", __FUNCTION__);
2184 static void nativeInstrumentReport(JNIEnv *env, jobject obj)
2186 #ifdef ANDROID_INSTRUMENT
2187 TimeCounter::reportNow();
2191 static void nativeSelectBestAt(JNIEnv *env, jobject obj, jobject jrect)
2193 WebView* view = GET_NATIVE_VIEW(env, obj);
2194 LOG_ASSERT(view, "view not set in %s", __FUNCTION__);
2195 WebCore::IntRect rect = jrect_to_webrect(env, jrect);
2196 view->selectBestAt(rect);
2199 static void nativeSelectAt(JNIEnv *env, jobject obj, jint x, jint y)
2201 WebView* view = GET_NATIVE_VIEW(env, obj);
2202 LOG_ASSERT(view, "view not set in %s", __FUNCTION__);
2203 WebCore::IntRect rect = IntRect(x, y , 1, 1);
2204 view->selectBestAt(rect);
2205 if (view->hasCursorNode())
2206 view->showCursorUntimed();
2209 static jobject nativeLayerBounds(JNIEnv* env, jobject obj, jint jlayer)
2212 #if USE(ACCELERATED_COMPOSITING)
2213 LayerAndroid* layer = (LayerAndroid*) jlayer;
2214 r = layer->bounds();
2220 jclass rectClass = env->FindClass("android/graphics/Rect");
2221 jmethodID init = env->GetMethodID(rectClass, "<init>", "(IIII)V");
2222 jobject rect = env->NewObject(rectClass, init, irect.fLeft, irect.fTop,
2223 irect.fRight, irect.fBottom);
2224 env->DeleteLocalRef(rectClass);
2228 static jobject nativeSubtractLayers(JNIEnv* env, jobject obj, jobject jrect)
2230 SkIRect irect = jrect_to_webrect(env, jrect);
2231 #if USE(ACCELERATED_COMPOSITING)
2232 LayerAndroid* root = GET_NATIVE_VIEW(env, obj)->compositeRoot();
2236 rect = root->subtractLayers(rect);
2240 jclass rectClass = env->FindClass("android/graphics/Rect");
2241 jmethodID init = env->GetMethodID(rectClass, "<init>", "(IIII)V");
2242 jobject rect = env->NewObject(rectClass, init, irect.fLeft, irect.fTop,
2243 irect.fRight, irect.fBottom);
2244 env->DeleteLocalRef(rectClass);
2248 static jint nativeTextGeneration(JNIEnv *env, jobject obj)
2250 WebView* view = GET_NATIVE_VIEW(env, obj);
2251 CachedRoot* root = view->getFrameCache(WebView::DontAllowNewer);
2252 return root ? root->textGeneration() : 0;
2255 static bool nativePointInNavCache(JNIEnv *env, jobject obj,
2256 int x, int y, int slop)
2258 return GET_NATIVE_VIEW(env, obj)->pointInNavCache(x, y, slop);
2261 static bool nativeMotionUp(JNIEnv *env, jobject obj,
2262 int x, int y, int slop)
2264 WebView* view = GET_NATIVE_VIEW(env, obj);
2265 LOG_ASSERT(view, "view not set in %s", __FUNCTION__);
2266 return view->motionUp(x, y, slop);
2269 static bool nativeHasCursorNode(JNIEnv *env, jobject obj)
2271 return GET_NATIVE_VIEW(env, obj)->hasCursorNode();
2274 static bool nativeHasFocusNode(JNIEnv *env, jobject obj)
2276 return GET_NATIVE_VIEW(env, obj)->hasFocusNode();
2279 static bool nativeMoveCursor(JNIEnv *env, jobject obj,
2280 int key, int count, bool ignoreScroll)
2282 WebView* view = GET_NATIVE_VIEW(env, obj);
2283 DBG_NAV_LOGD("env=%p obj=%p view=%p", env, obj, view);
2284 LOG_ASSERT(view, "view not set in %s", __FUNCTION__);
2285 return view->moveCursor(key, count, ignoreScroll);
2288 static void nativeRecordButtons(JNIEnv* env, jobject obj, bool hasFocus,
2289 bool pressed, bool invalidate)
2291 WebView* view = GET_NATIVE_VIEW(env, obj);
2292 LOG_ASSERT(view, "view not set in %s", __FUNCTION__);
2293 view->nativeRecordButtons(hasFocus, pressed, invalidate);
2296 static void nativeSetFindIsUp(JNIEnv *env, jobject obj, jboolean isUp)
2298 WebView* view = GET_NATIVE_VIEW(env, obj);
2299 LOG_ASSERT(view, "view not set in %s", __FUNCTION__);
2300 view->setFindIsUp(isUp);
2303 static void nativeSetFindIsEmpty(JNIEnv *env, jobject obj)
2305 GET_NATIVE_VIEW(env, obj)->setFindIsEmpty();
2308 static void nativeShowCursorTimed(JNIEnv *env, jobject obj)
2310 GET_NATIVE_VIEW(env, obj)->showCursorTimed();
2313 static void nativeSetHeightCanMeasure(JNIEnv *env, jobject obj, bool measure)
2315 WebView* view = GET_NATIVE_VIEW(env, obj);
2316 LOG_ASSERT(view, "view not set in nativeSetHeightCanMeasure");
2317 view->setHeightCanMeasure(measure);
2320 static jobject nativeGetCursorRingBounds(JNIEnv *env, jobject obj)
2322 WebView* view = GET_NATIVE_VIEW(env, obj);
2323 LOG_ASSERT(view, "view not set in %s", __FUNCTION__);
2324 jclass rectClass = env->FindClass("android/graphics/Rect");
2325 LOG_ASSERT(rectClass, "Could not find Rect class!");
2326 jmethodID init = env->GetMethodID(rectClass, "<init>", "(IIII)V");
2327 LOG_ASSERT(init, "Could not find constructor for Rect");
2328 WebCore::IntRect webRect;
2329 view->cursorRingBounds(&webRect);
2330 jobject rect = env->NewObject(rectClass, init, webRect.x(),
2331 webRect.y(), webRect.maxX(), webRect.maxY());
2332 env->DeleteLocalRef(rectClass);
2336 static int nativeFindAll(JNIEnv *env, jobject obj, jstring findLower,
2337 jstring findUpper, jboolean sameAsLastSearch)
2339 // If one or the other is null, do not search.
2340 if (!(findLower && findUpper))
2342 // Obtain the characters for both the lower case string and the upper case
2343 // string representing the same word.
2344 const jchar* findLowerChars = env->GetStringChars(findLower, 0);
2345 const jchar* findUpperChars = env->GetStringChars(findUpper, 0);
2346 // If one or the other is null, do not search.
2347 if (!(findLowerChars && findUpperChars)) {
2349 env->ReleaseStringChars(findLower, findLowerChars);
2351 env->ReleaseStringChars(findUpper, findUpperChars);
2352 checkException(env);
2355 WebView* view = GET_NATIVE_VIEW(env, obj);
2356 LOG_ASSERT(view, "view not set in nativeFindAll");
2357 CachedRoot* root = view->getFrameCache(WebView::AllowNewer);
2359 env->ReleaseStringChars(findLower, findLowerChars);
2360 env->ReleaseStringChars(findUpper, findUpperChars);
2361 checkException(env);
2364 int length = env->GetStringLength(findLower);
2365 // If the lengths of the strings do not match, then they are not the same
2366 // word, so do not search.
2367 if (!length || env->GetStringLength(findUpper) != length) {
2368 env->ReleaseStringChars(findLower, findLowerChars);
2369 env->ReleaseStringChars(findUpper, findUpperChars);
2370 checkException(env);
2373 int width = root->documentWidth();
2374 int height = root->documentHeight();
2375 // Create a FindCanvas, which allows us to fake draw into it so we can
2376 // figure out where our search string is rendered (and how many times).
2377 FindCanvas canvas(width, height, (const UChar*) findLowerChars,
2378 (const UChar*) findUpperChars, length << 1);
2380 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height);
2381 canvas.setBitmapDevice(bitmap);
2383 WTF::Vector<MatchInfo>* matches = canvas.detachMatches();
2384 // With setMatches, the WebView takes ownership of matches
2385 view->setMatches(matches, sameAsLastSearch);
2387 env->ReleaseStringChars(findLower, findLowerChars);
2388 env->ReleaseStringChars(findUpper, findUpperChars);
2389 checkException(env);
2390 return canvas.found();
2393 static void nativeFindNext(JNIEnv *env, jobject obj, bool forward)
2395 WebView* view = GET_NATIVE_VIEW(env, obj);
2396 LOG_ASSERT(view, "view not set in nativeFindNext");
2397 view->findNext(forward);
2400 static int nativeFindIndex(JNIEnv *env, jobject obj)
2402 WebView* view = GET_NATIVE_VIEW(env, obj);
2403 LOG_ASSERT(view, "view not set in nativeFindIndex");
2404 return view->currentMatchIndex();
2407 static void nativeUpdateCachedTextfield(JNIEnv *env, jobject obj, jstring updatedText, jint generation)
2409 WebView* view = GET_NATIVE_VIEW(env, obj);
2410 LOG_ASSERT(view, "view not set in nativeUpdateCachedTextfield");
2411 CachedRoot* root = view->getFrameCache(WebView::DontAllowNewer);
2414 const CachedNode* cachedFocusNode = root->currentFocus();
2415 if (!cachedFocusNode || !cachedFocusNode->isTextInput())
2417 WTF::String webcoreString = jstringToWtfString(env, updatedText);
2418 (const_cast<CachedNode*>(cachedFocusNode))->setExport(webcoreString);
2419 root->setTextGeneration(generation);
2420 checkException(env);
2423 static jint nativeGetBlockLeftEdge(JNIEnv *env, jobject obj, jint x, jint y,
2426 WebView* view = GET_NATIVE_VIEW(env, obj);
2427 LOG_ASSERT(view, "view not set in %s", __FUNCTION__);
2430 return view->getBlockLeftEdge(x, y, scale);
2433 static void nativeDestroy(JNIEnv *env, jobject obj)
2435 WebView* view = GET_NATIVE_VIEW(env, obj);
2436 LOGD("nativeDestroy view: %p", view);
2437 LOG_ASSERT(view, "view not set in nativeDestroy");
2441 static void nativeStopGL(JNIEnv *env, jobject obj)
2443 GET_NATIVE_VIEW(env, obj)->stopGL();
2446 static bool nativeMoveCursorToNextTextInput(JNIEnv *env, jobject obj)
2448 WebView* view = GET_NATIVE_VIEW(env, obj);
2449 CachedRoot* root = view->getFrameCache(WebView::DontAllowNewer);
2452 const CachedNode* current = root->currentCursor();
2453 if (!current || !current->isTextInput())
2454 current = root->currentFocus();
2455 if (!current || !current->isTextInput())
2457 const CachedFrame* frame;
2458 const CachedNode* next = root->nextTextField(current, &frame);
2461 const WebCore::IntRect& bounds = next->bounds(frame);
2462 root->rootHistory()->setMouseBounds(bounds);
2463 view->getWebViewCore()->updateCursorBounds(root, frame, next);
2464 view->showCursorUntimed();
2465 root->setCursor(const_cast<CachedFrame*>(frame),
2466 const_cast<CachedNode*>(next));
2467 view->sendMoveFocus(static_cast<WebCore::Frame*>(frame->framePointer()),
2468 static_cast<WebCore::Node*>(next->nodePointer()));
2469 if (!next->isInLayer())
2470 view->scrollRectOnScreen(bounds);
2471 view->getWebViewCore()->m_moveGeneration++;
2475 static int nativeMoveGeneration(JNIEnv *env, jobject obj)
2477 WebView* view = GET_NATIVE_VIEW(env, obj);
2480 return view->moveGeneration();
2483 static void nativeMoveSelection(JNIEnv *env, jobject obj, int x, int y)
2485 GET_NATIVE_VIEW(env, obj)->moveSelection(x, y);
2488 static void nativeResetSelection(JNIEnv *env, jobject obj)
2490 return GET_NATIVE_VIEW(env, obj)->resetSelection();
2493 static jobject nativeSelectableText(JNIEnv* env, jobject obj)
2495 IntPoint pos = GET_NATIVE_VIEW(env, obj)->selectableText();
2496 jclass pointClass = env->FindClass("android/graphics/Point");
2497 jmethodID init = env->GetMethodID(pointClass, "<init>", "(II)V");
2498 jobject point = env->NewObject(pointClass, init, pos.x(), pos.y());
2499 env->DeleteLocalRef(pointClass);
2503 static void nativeSelectAll(JNIEnv* env, jobject obj)
2505 GET_NATIVE_VIEW(env, obj)->selectAll();
2508 static void nativeSetExtendSelection(JNIEnv *env, jobject obj)
2510 GET_NATIVE_VIEW(env, obj)->setExtendSelection();
2513 static jboolean nativeStartSelection(JNIEnv *env, jobject obj, int x, int y)
2515 return GET_NATIVE_VIEW(env, obj)->startSelection(x, y);
2518 static jboolean nativeWordSelection(JNIEnv *env, jobject obj, int x, int y)
2520 return GET_NATIVE_VIEW(env, obj)->wordSelection(x, y);
2523 static void nativeExtendSelection(JNIEnv *env, jobject obj, int x, int y)
2525 GET_NATIVE_VIEW(env, obj)->extendSelection(x, y);
2528 static jobject nativeGetSelection(JNIEnv *env, jobject obj)
2530 WebView* view = GET_NATIVE_VIEW(env, obj);
2531 LOG_ASSERT(view, "view not set in %s", __FUNCTION__);
2532 String selection = view->getSelection();
2533 return wtfStringToJstring(env, selection);
2536 static jboolean nativeHitSelection(JNIEnv *env, jobject obj, int x, int y)
2538 return GET_NATIVE_VIEW(env, obj)->hitSelection(x, y);
2541 static jint nativeSelectionX(JNIEnv *env, jobject obj)
2543 return GET_NATIVE_VIEW(env, obj)->selectionX();
2546 static jint nativeSelectionY(JNIEnv *env, jobject obj)
2548 return GET_NATIVE_VIEW(env, obj)->selectionY();
2551 static void nativeSetSelectionPointer(JNIEnv *env, jobject obj, jboolean set,
2552 jfloat scale, jint x, jint y)
2554 GET_NATIVE_VIEW(env, obj)->setSelectionPointer(set, scale, x, y);
2557 static void nativeRegisterPageSwapCallback(JNIEnv *env, jobject obj)
2559 GET_NATIVE_VIEW(env, obj)->registerPageSwapCallback();
2562 static void nativeTileProfilingStart(JNIEnv *env, jobject obj)
2564 TilesManager::instance()->getProfiler()->start();
2567 static float nativeTileProfilingStop(JNIEnv *env, jobject obj)
2569 return TilesManager::instance()->getProfiler()->stop();
2572 static void nativeTileProfilingClear(JNIEnv *env, jobject obj)
2574 TilesManager::instance()->getProfiler()->clear();
2577 static int nativeTileProfilingNumFrames(JNIEnv *env, jobject obj)
2579 return TilesManager::instance()->getProfiler()->numFrames();
2582 static int nativeTileProfilingNumTilesInFrame(JNIEnv *env, jobject obj, int frame)
2584 return TilesManager::instance()->getProfiler()->numTilesInFrame(frame);
2587 static int nativeTileProfilingGetInt(JNIEnv *env, jobject obj, int frame, int tile, jstring jkey)
2589 WTF::String key = jstringToWtfString(env, jkey);
2590 TileProfileRecord* record = TilesManager::instance()->getProfiler()->getTile(frame, tile);
2593 return record->left;
2597 return record->right;
2598 if (key == "bottom")
2599 return record->bottom;
2601 return record->level;
2602 if (key == "isReady")
2603 return record->isReady ? 1 : 0;
2607 static float nativeTileProfilingGetFloat(JNIEnv *env, jobject obj, int frame, int tile, jstring jkey)
2609 TileProfileRecord* record = TilesManager::instance()->getProfiler()->getTile(frame, tile);
2610 return record->scale;
2613 #ifdef ANDROID_DUMP_DISPLAY_TREE
2614 static void dumpToFile(const char text[], void* file) {
2615 fwrite(text, 1, strlen(text), reinterpret_cast<FILE*>(file));
2616 fwrite("\n", 1, 1, reinterpret_cast<FILE*>(file));
2620 static bool nativeSetProperty(JNIEnv *env, jobject obj, jstring jkey, jstring jvalue)
2622 WTF::String key = jstringToWtfString(env, jkey);
2623 WTF::String value = jstringToWtfString(env, jvalue);
2624 if (key == "inverted") {
2625 if (value == "true")
2626 TilesManager::instance()->setInvertedScreen(true);
2628 TilesManager::instance()->setInvertedScreen(false);
2631 if (key == "inverted_contrast") {
2632 float contrast = value.toFloat();
2633 TilesManager::instance()->setInvertedScreenContrast(contrast);
2636 if (key == "enable_cpu_upload_path") {
2637 TilesManager::instance()->transferQueue()->setTextureUploadType(
2638 value == "true" ? CpuUpload : GpuUpload);
2644 static jstring nativeGetProperty(JNIEnv *env, jobject obj, jstring key)
2649 static void nativeOnTrimMemory(JNIEnv *env, jobject obj, jint level)
2651 if (TilesManager::hardwareAccelerationEnabled()) {
2652 bool freeAllTextures = (level > TRIM_MEMORY_UI_HIDDEN);
2653 TilesManager::instance()->deallocateTextures(freeAllTextures);
2657 static void nativeDumpDisplayTree(JNIEnv* env, jobject jwebview, jstring jurl)
2659 #ifdef ANDROID_DUMP_DISPLAY_TREE
2660 WebView* view = GET_NATIVE_VIEW(env, jwebview);
2661 LOG_ASSERT(view, "view not set in %s", __FUNCTION__);
2663 if (view && view->getWebViewCore()) {
2664 FILE* file = fopen(DISPLAY_TREE_LOG_FILE, "w");
2666 SkFormatDumper dumper(dumpToFile, file);
2669 const char* str = env->GetStringUTFChars(jurl, 0);
2670 SkDebugf("Dumping %s to %s\n", str, DISPLAY_TREE_LOG_FILE);
2671 dumpToFile(str, file);
2672 env->ReleaseStringUTFChars(jurl, str);
2674 // now dump the display tree
2675 SkDumpCanvas canvas(&dumper);
2676 // this will playback the picture into the canvas, which will
2677 // spew its contents to the dumper
2678 view->draw(&canvas, 0, 0, false);
2679 // we're done with the file now
2680 fwrite("\n", 1, 1, file);
2683 #if USE(ACCELERATED_COMPOSITING)
2684 const LayerAndroid* rootLayer = view->compositeRoot();
2686 FILE* file = fopen(LAYERS_TREE_LOG_FILE,"w");
2688 rootLayer->dumpLayers(file, 0);
2697 static int nativeScrollableLayer(JNIEnv* env, jobject jwebview, jint x, jint y,
2698 jobject rect, jobject bounds)
2700 WebView* view = GET_NATIVE_VIEW(env, jwebview);
2701 LOG_ASSERT(view, "view not set in %s", __FUNCTION__);
2702 SkIRect nativeRect, nativeBounds;
2703 int id = view->scrollableLayer(x, y, &nativeRect, &nativeBounds);
2705 GraphicsJNI::irect_to_jrect(nativeRect, env, rect);
2707 GraphicsJNI::irect_to_jrect(nativeBounds, env, bounds);
2711 static bool nativeScrollLayer(JNIEnv* env, jobject obj, jint layerId, jint x,
2714 #if ENABLE(ANDROID_OVERFLOW_SCROLL)
2715 WebView* view = GET_NATIVE_VIEW(env, obj);
2716 LayerAndroid* root = view->compositeRoot();
2719 LayerAndroid* layer = root->findById(layerId);
2720 if (!layer || !layer->contentIsScrollable())
2722 return static_cast<ScrollableLayerAndroid*>(layer)->scrollTo(x, y);
2727 static void nativeSetIsScrolling(JNIEnv* env, jobject jwebview, jboolean isScrolling)
2729 WebView* view = GET_NATIVE_VIEW(env, jwebview);
2730 LOG_ASSERT(view, "view not set in %s", __FUNCTION__);
2731 view->setIsScrolling(isScrolling);
2734 static void nativeUseHardwareAccelSkia(JNIEnv*, jobject, jboolean enabled)
2736 BaseRenderer::setCurrentRendererType(enabled ? BaseRenderer::Ganesh : BaseRenderer::Raster);
2739 static int nativeGetBackgroundColor(JNIEnv* env, jobject obj)
2741 WebView* view = GET_NATIVE_VIEW(env, obj);
2742 BaseLayerAndroid* baseLayer = view->getBaseLayer();
2744 WebCore::Color color = baseLayer->getBackgroundColor();
2745 if (color.isValid())
2746 return SkColorSetARGB(color.alpha(), color.red(),
2747 color.green(), color.blue());
2749 return SK_ColorWHITE;
2755 static JNINativeMethod gJavaWebViewMethods[] = {
2756 { "nativeCacheHitFramePointer", "()I",
2757 (void*) nativeCacheHitFramePointer },
2758 { "nativeCacheHitIsPlugin", "()Z",
2759 (void*) nativeCacheHitIsPlugin },
2760 { "nativeCacheHitNodeBounds", "()Landroid/graphics/Rect;",
2761 (void*) nativeCacheHitNodeBounds },
2762 { "nativeCacheHitNodePointer", "()I",
2763 (void*) nativeCacheHitNodePointer },
2764 { "nativeClearCursor", "()V",
2765 (void*) nativeClearCursor },
2766 { "nativeCreate", "(ILjava/lang/String;)V",
2767 (void*) nativeCreate },
2768 { "nativeCursorFramePointer", "()I",
2769 (void*) nativeCursorFramePointer },
2770 { "nativePageShouldHandleShiftAndArrows", "()Z",
2771 (void*) nativePageShouldHandleShiftAndArrows },
2772 { "nativeCursorNodeBounds", "()Landroid/graphics/Rect;",
2773 (void*) nativeCursorNodeBounds },
2774 { "nativeCursorNodePointer", "()I",
2775 (void*) nativeCursorNodePointer },
2776 { "nativeCursorIntersects", "(Landroid/graphics/Rect;)Z",
2777 (void*) nativeCursorIntersects },
2778 { "nativeCursorIsAnchor", "()Z",
2779 (void*) nativeCursorIsAnchor },
2780 { "nativeCursorIsTextInput", "()Z",
2781 (void*) nativeCursorIsTextInput },
2782 { "nativeCursorPosition", "()Landroid/graphics/Point;",
2783 (void*) nativeCursorPosition },
2784 { "nativeCursorText", "()Ljava/lang/String;",
2785 (void*) nativeCursorText },
2786 { "nativeCursorWantsKeyEvents", "()Z",
2787 (void*)nativeCursorWantsKeyEvents },
2788 { "nativeDebugDump", "()V",
2789 (void*) nativeDebugDump },
2790 { "nativeDestroy", "()V",
2791 (void*) nativeDestroy },
2792 { "nativeDraw", "(Landroid/graphics/Canvas;IIZ)I",
2793 (void*) nativeDraw },
2794 { "nativeGetDrawGLFunction", "(Landroid/graphics/Rect;Landroid/graphics/Rect;FI)I",
2795 (void*) nativeGetDrawGLFunction },
2796 { "nativeUpdateDrawGLFunction", "(Landroid/graphics/Rect;Landroid/graphics/Rect;)V",
2797 (void*) nativeUpdateDrawGLFunction },
2798 { "nativeDumpDisplayTree", "(Ljava/lang/String;)V",
2799 (void*) nativeDumpDisplayTree },
2800 { "nativeEvaluateLayersAnimations", "()Z",
2801 (void*) nativeEvaluateLayersAnimations },
2802 { "nativeExtendSelection", "(II)V",
2803 (void*) nativeExtendSelection },
2804 { "nativeFindAll", "(Ljava/lang/String;Ljava/lang/String;Z)I",
2805 (void*) nativeFindAll },
2806 { "nativeFindNext", "(Z)V",
2807 (void*) nativeFindNext },
2808 { "nativeFindIndex", "()I",
2809 (void*) nativeFindIndex},
2810 { "nativeFocusCandidateFramePointer", "()I",
2811 (void*) nativeFocusCandidateFramePointer },
2812 { "nativeFocusCandidateHasNextTextfield", "()Z",
2813 (void*) focusCandidateHasNextTextfield },
2814 { "nativeFocusCandidateIsPassword", "()Z",
2815 (void*) nativeFocusCandidateIsPassword },
2816 { "nativeFocusCandidateIsRtlText", "()Z",
2817 (void*) nativeFocusCandidateIsRtlText },
2818 { "nativeFocusCandidateIsTextInput", "()Z",
2819 (void*) nativeFocusCandidateIsTextInput },
2820 { "nativeFocusCandidateLineHeight", "()I",
2821 (void*) nativeFocusCandidateLineHeight },
2822 { "nativeFocusCandidateMaxLength", "()I",
2823 (void*) nativeFocusCandidateMaxLength },
2824 { "nativeFocusCandidateIsAutoComplete", "()Z",
2825 (void*) nativeFocusCandidateIsAutoComplete },
2826 { "nativeFocusCandidateIsSpellcheck", "()Z",
2827 (void*) nativeFocusCandidateIsSpellcheck },
2828 { "nativeFocusCandidateName", "()Ljava/lang/String;",
2829 (void*) nativeFocusCandidateName },
2830 { "nativeFocusCandidateNodeBounds", "()Landroid/graphics/Rect;",
2831 (void*) nativeFocusCandidateNodeBounds },
2832 { "nativeFocusCandidatePaddingRect", "()Landroid/graphics/Rect;",
2833 (void*) nativeFocusCandidatePaddingRect },
2834 { "nativeFocusCandidatePointer", "()I",
2835 (void*) nativeFocusCandidatePointer },
2836 { "nativeFocusCandidateText", "()Ljava/lang/String;",
2837 (void*) nativeFocusCandidateText },
2838 { "nativeFocusCandidateTextSize", "()F",
2839 (void*) nativeFocusCandidateTextSize },
2840 { "nativeFocusCandidateType", "()I",
2841 (void*) nativeFocusCandidateType },
2842 { "nativeFocusIsPlugin", "()Z",
2843 (void*) nativeFocusIsPlugin },
2844 { "nativeFocusNodeBounds", "()Landroid/graphics/Rect;",
2845 (void*) nativeFocusNodeBounds },
2846 { "nativeFocusNodePointer", "()I",
2847 (void*) nativeFocusNodePointer },
2848 { "nativeGetCursorRingBounds", "()Landroid/graphics/Rect;",
2849 (void*) nativeGetCursorRingBounds },
2850 { "nativeGetSelection", "()Ljava/lang/String;",
2851 (void*) nativeGetSelection },
2852 { "nativeHasCursorNode", "()Z",
2853 (void*) nativeHasCursorNode },
2854 { "nativeHasFocusNode", "()Z",
2855 (void*) nativeHasFocusNode },
2856 { "nativeHideCursor", "()V",
2857 (void*) nativeHideCursor },
2858 { "nativeHitSelection", "(II)Z",
2859 (void*) nativeHitSelection },
2860 { "nativeImageURI", "(II)Ljava/lang/String;",
2861 (void*) nativeImageURI },
2862 { "nativeInstrumentReport", "()V",
2863 (void*) nativeInstrumentReport },
2864 { "nativeLayerBounds", "(I)Landroid/graphics/Rect;",
2865 (void*) nativeLayerBounds },
2866 { "nativeMotionUp", "(III)Z",
2867 (void*) nativeMotionUp },
2868 { "nativeMoveCursor", "(IIZ)Z",
2869 (void*) nativeMoveCursor },
2870 { "nativeMoveCursorToNextTextInput", "()Z",
2871 (void*) nativeMoveCursorToNextTextInput },
2872 { "nativeMoveGeneration", "()I",
2873 (void*) nativeMoveGeneration },
2874 { "nativeMoveSelection", "(II)V",
2875 (void*) nativeMoveSelection },
2876 { "nativePointInNavCache", "(III)Z",
2877 (void*) nativePointInNavCache },
2878 { "nativeRecordButtons", "(ZZZ)V",
2879 (void*) nativeRecordButtons },
2880 { "nativeResetSelection", "()V",
2881 (void*) nativeResetSelection },
2882 { "nativeSelectableText", "()Landroid/graphics/Point;",
2883 (void*) nativeSelectableText },
2884 { "nativeSelectAll", "()V",
2885 (void*) nativeSelectAll },
2886 { "nativeSelectBestAt", "(Landroid/graphics/Rect;)V",
2887 (void*) nativeSelectBestAt },
2888 { "nativeSelectAt", "(II)V",
2889 (void*) nativeSelectAt },
2890 { "nativeSelectionX", "()I",
2891 (void*) nativeSelectionX },
2892 { "nativeSelectionY", "()I",
2893 (void*) nativeSelectionY },
2894 { "nativeSetExtendSelection", "()V",
2895 (void*) nativeSetExtendSelection },
2896 { "nativeSetFindIsEmpty", "()V",
2897 (void*) nativeSetFindIsEmpty },
2898 { "nativeSetFindIsUp", "(Z)V",
2899 (void*) nativeSetFindIsUp },
2900 { "nativeSetHeightCanMeasure", "(Z)V",
2901 (void*) nativeSetHeightCanMeasure },
2902 { "nativeSetBaseLayer", "(ILandroid/graphics/Region;ZZZ)V",
2903 (void*) nativeSetBaseLayer },
2904 { "nativeGetTextSelectionRegion", "(Landroid/graphics/Region;)V",
2905 (void*) nativeGetTextSelectionRegion },
2906 { "nativeGetBaseLayer", "()I",
2907 (void*) nativeGetBaseLayer },
2908 { "nativeReplaceBaseContent", "(I)V",
2909 (void*) nativeReplaceBaseContent },
2910 { "nativeCopyBaseContentToPicture", "(Landroid/graphics/Picture;)V",
2911 (void*) nativeCopyBaseContentToPicture },
2912 { "nativeHasContent", "()Z",
2913 (void*) nativeHasContent },
2914 { "nativeSetSelectionPointer", "(ZFII)V",
2915 (void*) nativeSetSelectionPointer },
2916 { "nativeShowCursorTimed", "()V",
2917 (void*) nativeShowCursorTimed },
2918 { "nativeRegisterPageSwapCallback", "()V",
2919 (void*) nativeRegisterPageSwapCallback },
2920 { "nativeTileProfilingStart", "()V",
2921 (void*) nativeTileProfilingStart },
2922 { "nativeTileProfilingStop", "()F",
2923 (void*) nativeTileProfilingStop },
2924 { "nativeTileProfilingClear", "()V",
2925 (void*) nativeTileProfilingClear },
2926 { "nativeTileProfilingNumFrames", "()I",
2927 (void*) nativeTileProfilingNumFrames },
2928 { "nativeTileProfilingNumTilesInFrame", "(I)I",
2929 (void*) nativeTileProfilingNumTilesInFrame },
2930 { "nativeTileProfilingGetInt", "(IILjava/lang/String;)I",
2931 (void*) nativeTileProfilingGetInt },
2932 { "nativeTileProfilingGetFloat", "(IILjava/lang/String;)F",
2933 (void*) nativeTileProfilingGetFloat },
2934 { "nativeStartSelection", "(II)Z",
2935 (void*) nativeStartSelection },
2936 { "nativeStopGL", "()V",
2937 (void*) nativeStopGL },
2938 { "nativeSubtractLayers", "(Landroid/graphics/Rect;)Landroid/graphics/Rect;",
2939 (void*) nativeSubtractLayers },
2940 { "nativeTextGeneration", "()I",
2941 (void*) nativeTextGeneration },
2942 { "nativeUpdateCachedTextfield", "(Ljava/lang/String;I)V",
2943 (void*) nativeUpdateCachedTextfield },
2944 { "nativeWordSelection", "(II)Z",
2945 (void*) nativeWordSelection },
2946 { "nativeGetBlockLeftEdge", "(IIF)I",
2947 (void*) nativeGetBlockLeftEdge },
2948 { "nativeScrollableLayer", "(IILandroid/graphics/Rect;Landroid/graphics/Rect;)I",
2949 (void*) nativeScrollableLayer },
2950 { "nativeScrollLayer", "(III)Z",
2951 (void*) nativeScrollLayer },
2952 { "nativeSetIsScrolling", "(Z)V",
2953 (void*) nativeSetIsScrolling },
2954 { "nativeUseHardwareAccelSkia", "(Z)V",
2955 (void*) nativeUseHardwareAccelSkia },
2956 { "nativeGetBackgroundColor", "()I",
2957 (void*) nativeGetBackgroundColor },
2958 { "nativeSetProperty", "(Ljava/lang/String;Ljava/lang/String;)Z",
2959 (void*) nativeSetProperty },
2960 { "nativeGetProperty", "(Ljava/lang/String;)Ljava/lang/String;",
2961 (void*) nativeGetProperty },
2962 { "nativeOnTrimMemory", "(I)V",
2963 (void*) nativeOnTrimMemory },
2966 int registerWebView(JNIEnv* env)
2968 jclass clazz = env->FindClass("android/webkit/WebView");
2969 LOG_ASSERT(clazz, "Unable to find class android/webkit/WebView");
2970 gWebViewField = env->GetFieldID(clazz, "mNativeClass", "I");
2971 LOG_ASSERT(gWebViewField, "Unable to find android/webkit/WebView.mNativeClass");
2972 env->DeleteLocalRef(clazz);
2974 return jniRegisterNativeMethods(env, "android/webkit/WebView", gJavaWebViewMethods, NELEM(gJavaWebViewMethods));
2977 } // namespace android