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_isDrawingPaused = false;
208 m_buttonSkin = drawableDir.isEmpty() ? 0 : new RenderSkinButton(drawableDir);
209 #if USE(ACCELERATED_COMPOSITING)
210 m_glWebViewState = 0;
211 m_pageSwapCallbackRegistered = false;
217 if (m_javaGlue.m_obj)
219 JNIEnv* env = JSC::Bindings::getJNIEnv();
220 env->DeleteWeakGlobalRef(m_javaGlue.m_obj);
221 m_javaGlue.m_obj = 0;
223 #if USE(ACCELERATED_COMPOSITING)
224 // We must remove the m_glWebViewState prior to deleting m_baseLayer. If we
225 // do not remove it here, we risk having BaseTiles trying to paint using a
226 // deallocated base layer.
229 delete m_frameCacheUI;
230 delete m_navPictureUI;
231 SkSafeUnref(m_baseLayer);
232 delete m_glDrawFunctor;
238 #if USE(ACCELERATED_COMPOSITING)
239 delete m_glWebViewState;
240 m_glWebViewState = 0;
244 WebViewCore* getWebViewCore() const {
248 float getTextHandleScale()
250 LOG_ASSERT(m_javaGlue.m_obj, "A java object was not associated with this native WebView!");
251 JNIEnv* env = JSC::Bindings::getJNIEnv();
252 AutoJObject javaObject = m_javaGlue.object(env);
253 if (!javaObject.get())
255 float result = env->CallFloatMethod(javaObject.get(), m_javaGlue.m_getTextHandleScale);
260 void updateSelectionHandles()
264 // Adjust for device density & scale
265 m_selectText.updateHandleScale(getTextHandleScale());
268 // removes the cursor altogether (e.g., when going to a new page)
271 CachedRoot* root = getFrameCache(AllowNewer);
275 m_viewImpl->m_hasCursorBounds = false;
280 // leaves the cursor where it is, but suppresses drawing it
283 CachedRoot* root = getFrameCache(AllowNewer);
291 void hideCursor(CachedRoot* root)
293 DBG_NAV_LOG("inner");
294 m_viewImpl->m_hasCursorBounds = false;
301 CachedRoot* root = getFrameCache(DontAllowNewer);
303 root->mDebug.print();
307 void scrollToCurrentMatch()
309 if (!m_findOnPage.currentMatchIsInLayer()) {
310 scrollRectOnScreen(m_findOnPage.currentMatchBounds());
314 SkRect matchBounds = m_findOnPage.currentMatchBounds();
315 LayerAndroid* rootLayer = getFrameCache(DontAllowNewer)->rootLayer();
316 Layer* layerContainingMatch = rootLayer->findById(m_findOnPage.currentMatchLayerId());
317 ASSERT(layerContainingMatch);
319 // If the match is in a fixed position layer, there's nothing to do.
320 if (layerContainingMatch->shouldInheritFromRootTransform())
323 // If the match is in a scrollable layer or a descendant of such a layer,
324 // there may be a range of of scroll configurations that will make the
325 // current match visible. Our approach is the simplest possible. Starting at
326 // the layer in which the match is found, we move up the layer tree,
327 // scrolling any scrollable layers as little as possible to make sure that
328 // the current match is in view. This approach has the disadvantage that we
329 // may end up scrolling a larger number of elements than is necessary, which
330 // may be visually jarring. However, minimising the number of layers
331 // scrolled would complicate the code significantly.
333 bool didScrollLayer = false;
334 for (Layer* layer = layerContainingMatch; layer; layer = layer->getParent()) {
335 ASSERT(layer->getParent() || layer == rootLayer);
337 if (layer->contentIsScrollable()) {
338 // Convert the match location to layer's local space and scroll it.
339 // Repeatedly calling Layer::localToAncestor() is inefficient as
340 // each call repeats part of the calculation. It would be more
341 // efficient to maintain the transform here and update it on each
342 // iteration, but that would mean duplicating logic from
343 // Layer::localToAncestor() and would complicate things.
345 layerContainingMatch->localToAncestor(layer, &transform);
346 SkRect transformedMatchBounds;
347 transform.mapRect(&transformedMatchBounds, matchBounds);
348 SkIRect roundedTransformedMatchBounds;
349 transformedMatchBounds.roundOut(&roundedTransformedMatchBounds);
350 // Only ScrollableLayerAndroid returns true for contentIsScrollable().
351 didScrollLayer |= static_cast<ScrollableLayerAndroid*>(layer)->scrollRectIntoView(roundedTransformedMatchBounds);
354 // Invalidate, as the call below to scroll the main page may be a no-op.
358 // Convert matchBounds to the global space so we can scroll the main page.
360 layerContainingMatch->localToGlobal(&transform);
361 SkRect transformedMatchBounds;
362 transform.mapRect(&transformedMatchBounds, matchBounds);
363 SkIRect roundedTransformedMatchBounds;
364 transformedMatchBounds.roundOut(&roundedTransformedMatchBounds);
365 scrollRectOnScreen(roundedTransformedMatchBounds);
368 void scrollRectOnScreen(const IntRect& rect)
372 SkRect visible = SkRect::MakeEmpty();
373 calcOurContentVisibleRect(&visible);
376 int right = rect.maxX();
377 if (left < visible.fLeft) {
378 dx = left - visible.fLeft;
379 // Only scroll right if the entire width can fit on screen.
380 } else if (right > visible.fRight && right - left < visible.width()) {
381 dx = right - visible.fRight;
385 int bottom = rect.maxY();
386 if (top < visible.fTop) {
387 dy = top - visible.fTop;
388 // Only scroll down if the entire height can fit on screen
389 } else if (bottom > visible.fBottom && bottom - top < visible.height()) {
390 dy = bottom - visible.fBottom;
392 if ((dx|dy) == 0 || !scrollBy(dx, dy))
397 void calcOurContentVisibleRect(SkRect* r)
399 JNIEnv* env = JSC::Bindings::getJNIEnv();
400 AutoJObject javaObject = m_javaGlue.object(env);
401 if (!javaObject.get())
403 jclass rectClass = env->FindClass("android/graphics/RectF");
404 jmethodID init = env->GetMethodID(rectClass, "<init>", "(FFFF)V");
405 jobject jRect = env->NewObject(rectClass, init, 0, 0, 0, 0);
406 env->CallVoidMethod(javaObject.get(), m_javaGlue.m_calcOurContentVisibleRectF, jRect);
407 r->fLeft = env->GetFloatField(jRect, m_javaGlue.m_rectFLeft);
408 r->fTop = env->GetFloatField(jRect, m_javaGlue.m_rectFTop);
409 r->fRight = r->fLeft + env->CallFloatMethod(jRect, m_javaGlue.m_rectFWidth);
410 r->fBottom = r->fTop + env->CallFloatMethod(jRect, m_javaGlue.m_rectFHeight);
411 env->DeleteLocalRef(rectClass);
412 env->DeleteLocalRef(jRect);
416 void resetCursorRing()
418 m_ringAnimationEnd = 0;
419 m_viewImpl->m_hasCursorBounds = false;
422 bool drawCursorPreamble(CachedRoot* root)
424 if (!root) return false;
425 const CachedFrame* frame;
426 const CachedNode* node = root->currentCursor(&frame);
428 DBG_NAV_LOGV("%s", "!node");
432 m_ring.setIsButton(node);
433 if (node->isHidden()) {
434 DBG_NAV_LOG("node->isHidden()");
435 m_viewImpl->m_hasCursorBounds = false;
438 #if USE(ACCELERATED_COMPOSITING)
439 if (node->isInLayer() && root->rootLayer()) {
440 LayerAndroid* layer = root->rootLayer();
442 calcOurContentVisibleRect(&visible);
443 layer->updateFixedLayersPositions(visible);
444 layer->updatePositions();
447 setVisibleRect(root);
448 m_ring.m_root = root;
449 m_ring.m_frame = frame;
450 m_ring.m_node = node;
451 SkMSec time = SkTime::GetMSecs();
452 m_ring.m_isPressed = time < m_ringAnimationEnd
453 && m_ringAnimationEnd != UINT_MAX;
457 void drawCursorPostamble()
459 if (m_ringAnimationEnd == UINT_MAX)
461 SkMSec time = SkTime::GetMSecs();
462 if (time < m_ringAnimationEnd) {
463 // views assume that inval bounds coordinates are non-negative
464 WebCore::IntRect invalBounds(0, 0, INT_MAX, INT_MAX);
465 invalBounds.intersect(m_ring.m_absBounds);
466 postInvalidateDelayed(m_ringAnimationEnd - time, invalBounds);
468 hideCursor(const_cast<CachedRoot*>(m_ring.m_root));
472 bool drawGL(WebCore::IntRect& viewRect, WebCore::IntRect* invalRect, WebCore::IntRect& webViewRect,
473 int titleBarHeight, WebCore::IntRect& clip, float scale, int extras)
475 #if USE(ACCELERATED_COMPOSITING)
476 if (!m_baseLayer || inFullScreenMode())
479 if (!m_glWebViewState) {
480 m_glWebViewState = new GLWebViewState();
481 m_glWebViewState->glExtras()->setCursorRingExtra(&m_ring);
482 m_glWebViewState->glExtras()->setFindOnPageExtra(&m_findOnPage);
483 if (m_baseLayer->content()) {
486 rect.set(0, 0, m_baseLayer->content()->width(), m_baseLayer->content()->height());
487 region.setRect(rect);
488 m_glWebViewState->setBaseLayer(m_baseLayer, region, false, true);
492 CachedRoot* root = getFrameCache(AllowNewer);
494 DBG_NAV_LOG("!root");
495 if (extras == DrawExtrasCursorRing)
498 DrawExtra* extra = 0;
501 extra = &m_findOnPage;
503 case DrawExtrasSelection:
504 // This will involve a JNI call, but under normal circumstances we will
505 // not hit this anyway. Only if USE_JAVA_TEXT_SELECTION is disabled
506 // in WebView.java will we hit this (so really debug only)
507 updateSelectionHandles();
508 extra = &m_selectText;
510 case DrawExtrasCursorRing:
511 if (drawCursorPreamble(root) && m_ring.setup()) {
512 if (m_ring.m_isPressed || m_ringAnimationEnd == UINT_MAX)
514 drawCursorPostamble();
521 unsigned int pic = m_glWebViewState->currentPictureCounter();
522 m_glWebViewState->glExtras()->setDrawExtra(extra);
525 calcOurContentVisibleRect(&visibleRect);
526 // Make sure we have valid coordinates. We might not have valid coords
527 // if the zoom manager is still initializing. We will be redrawn
528 // once the correct scale is set
529 if (!visibleRect.hasValidCoordinates())
531 bool pagesSwapped = false;
532 bool ret = m_glWebViewState->drawGL(viewRect, visibleRect, invalRect,
533 webViewRect, titleBarHeight, clip, scale,
535 if (m_pageSwapCallbackRegistered && pagesSwapped) {
536 m_pageSwapCallbackRegistered = false;
537 LOG_ASSERT(m_javaGlue.m_obj, "A java object was not associated with this native WebView!");
538 JNIEnv* env = JSC::Bindings::getJNIEnv();
539 AutoJObject javaObject = m_javaGlue.object(env);
540 if (javaObject.get()) {
541 env->CallVoidMethod(javaObject.get(), m_javaGlue.m_pageSwapCallback);
545 if (ret || m_glWebViewState->currentPictureCounter() != pic)
546 return !m_isDrawingPaused;
551 PictureSet* draw(SkCanvas* canvas, SkColor bgColor, int extras, bool split)
555 canvas->drawColor(bgColor);
559 // draw the content of the base layer first
560 PictureSet* content = m_baseLayer->content();
561 int sc = canvas->save(SkCanvas::kClip_SaveFlag);
562 canvas->clipRect(SkRect::MakeLTRB(0, 0, content->width(),
563 content->height()), SkRegion::kDifference_Op);
564 canvas->drawColor(bgColor);
565 canvas->restoreToCount(sc);
566 if (content->draw(canvas))
567 ret = split ? new PictureSet(*content) : 0;
569 CachedRoot* root = getFrameCache(AllowNewer);
571 DBG_NAV_LOG("!root");
572 if (extras == DrawExtrasCursorRing)
575 LayerAndroid mainPicture(m_navPictureUI);
576 DrawExtra* extra = 0;
579 extra = &m_findOnPage;
581 case DrawExtrasSelection:
582 // This will involve a JNI call, but under normal circumstances we will
583 // not hit this anyway. Only if USE_JAVA_TEXT_SELECTION is disabled
584 // in WebView.java will we hit this (so really debug only)
585 updateSelectionHandles();
586 extra = &m_selectText;
588 case DrawExtrasCursorRing:
589 if (drawCursorPreamble(root) && m_ring.setup()) {
591 drawCursorPostamble();
597 #if USE(ACCELERATED_COMPOSITING)
598 LayerAndroid* compositeLayer = compositeRoot();
599 if (compositeLayer) {
601 calcOurContentVisibleRect(&visible);
602 // call this to be sure we've adjusted for any scrolling or animations
603 // before we actually draw
604 compositeLayer->updateFixedLayersPositions(visible);
605 compositeLayer->updatePositions();
606 // We have to set the canvas' matrix on the base layer
607 // (to have fixed layers work as intended)
608 SkAutoCanvasRestore restore(canvas, true);
609 m_baseLayer->setMatrix(canvas->getTotalMatrix());
610 canvas->resetMatrix();
611 m_baseLayer->draw(canvas);
615 IntRect dummy; // inval area, unused for now
616 extra->draw(canvas, &mainPicture, &dummy);
622 bool cursorIsTextInput(FrameCachePermission allowNewer)
624 CachedRoot* root = getFrameCache(allowNewer);
626 DBG_NAV_LOG("!root");
629 const CachedNode* cursor = root->currentCursor();
631 DBG_NAV_LOG("!cursor");
634 DBG_NAV_LOGD("%s", cursor->isTextInput() ? "true" : "false");
635 return cursor->isTextInput();
638 void cursorRingBounds(WebCore::IntRect* bounds)
640 DBG_NAV_LOGD("%s", "");
641 CachedRoot* root = getFrameCache(DontAllowNewer);
643 const CachedFrame* cachedFrame;
644 const CachedNode* cachedNode = root->currentCursor(&cachedFrame);
646 *bounds = cachedNode->cursorRingBounds(cachedFrame);
647 DBG_NAV_LOGD("bounds={%d,%d,%d,%d}", bounds->x(), bounds->y(),
648 bounds->width(), bounds->height());
652 *bounds = WebCore::IntRect(0, 0, 0, 0);
657 m_viewImpl->gCursorBoundsMutex.lock();
658 bool hasCursorBounds = m_viewImpl->m_hasCursorBounds;
659 IntRect bounds = m_viewImpl->m_cursorBounds;
660 m_viewImpl->gCursorBoundsMutex.unlock();
661 if (!hasCursorBounds)
664 const CachedFrame* frame;
665 const CachedNode* node = m_frameCacheUI->findAt(bounds, &frame, &x, &y, true);
668 // require that node have approximately the same bounds (+/- 4) and the same
670 IntPoint oldCenter = IntPoint(bounds.x() + (bounds.width() >> 1),
671 bounds.y() + (bounds.height() >> 1));
672 IntRect newBounds = node->bounds(frame);
673 IntPoint newCenter = IntPoint(newBounds.x() + (newBounds.width() >> 1),
674 newBounds.y() + (newBounds.height() >> 1));
675 DBG_NAV_LOGD("oldCenter=(%d,%d) newCenter=(%d,%d)"
676 " bounds=(%d,%d,w=%d,h=%d) newBounds=(%d,%d,w=%d,h=%d)",
677 oldCenter.x(), oldCenter.y(), newCenter.x(), newCenter.y(),
678 bounds.x(), bounds.y(), bounds.width(), bounds.height(),
679 newBounds.x(), newBounds.y(), newBounds.width(), newBounds.height());
680 if (abs(oldCenter.x() - newCenter.x()) > 2)
682 if (abs(oldCenter.y() - newCenter.y()) > 2)
684 if (abs(bounds.x() - newBounds.x()) > 4)
686 if (abs(bounds.y() - newBounds.y()) > 4)
688 if (abs(bounds.maxX() - newBounds.maxX()) > 4)
690 if (abs(bounds.maxY() - newBounds.maxY()) > 4)
692 DBG_NAV_LOGD("node=%p frame=%p x=%d y=%d bounds=(%d,%d,w=%d,h=%d)",
693 node, frame, x, y, bounds.x(), bounds.y(), bounds.width(),
695 m_frameCacheUI->setCursor(const_cast<CachedFrame*>(frame),
696 const_cast<CachedNode*>(node));
699 CachedRoot* getFrameCache(FrameCachePermission allowNewer)
701 if (!m_viewImpl->m_updatedFrameCache) {
702 DBG_NAV_LOGV("%s", "!m_viewImpl->m_updatedFrameCache");
703 return m_frameCacheUI;
705 if (allowNewer == DontAllowNewer && m_viewImpl->m_lastGeneration < m_generation) {
706 DBG_NAV_LOGD("allowNewer==DontAllowNewer m_viewImpl->m_lastGeneration=%d"
707 " < m_generation=%d", m_viewImpl->m_lastGeneration, m_generation);
708 return m_frameCacheUI;
710 DBG_NAV_LOGD("%s", "m_viewImpl->m_updatedFrameCache == true");
711 const CachedFrame* oldCursorFrame;
712 const CachedNode* oldCursorNode = m_frameCacheUI ?
713 m_frameCacheUI->currentCursor(&oldCursorFrame) : 0;
714 #if USE(ACCELERATED_COMPOSITING)
716 if (oldCursorNode && oldCursorNode->isInLayer()) {
717 const LayerAndroid* cursorLayer = oldCursorFrame->layer(oldCursorNode)
718 ->layer(m_frameCacheUI->rootLayer());
720 layerId = cursorLayer->uniqueId();
723 // get id from old layer and use to find new layer
724 bool oldFocusIsTextInput = false;
725 void* oldFocusNodePointer = 0;
726 if (m_frameCacheUI) {
727 const CachedNode* oldFocus = m_frameCacheUI->currentFocus();
729 oldFocusIsTextInput = oldFocus->isTextInput();
730 oldFocusNodePointer = oldFocus->nodePointer();
733 m_viewImpl->gFrameCacheMutex.lock();
734 delete m_frameCacheUI;
735 SkSafeUnref(m_navPictureUI);
736 m_viewImpl->m_updatedFrameCache = false;
737 m_frameCacheUI = m_viewImpl->m_frameCacheKit;
738 m_navPictureUI = m_viewImpl->m_navPictureKit;
739 m_viewImpl->m_frameCacheKit = 0;
740 m_viewImpl->m_navPictureKit = 0;
741 m_viewImpl->gFrameCacheMutex.unlock();
743 m_frameCacheUI->setRootLayer(compositeRoot());
744 #if USE(ACCELERATED_COMPOSITING)
747 calcOurContentVisibleRect(&visible);
748 LayerAndroid* layer = const_cast<LayerAndroid*>(
749 m_frameCacheUI->rootLayer());
751 layer->updateFixedLayersPositions(visible);
752 layer->updatePositions();
757 if (oldFocusIsTextInput) {
758 const CachedNode* newFocus = m_frameCacheUI->currentFocus();
759 if (newFocus && oldFocusNodePointer != newFocus->nodePointer()
760 && newFocus->isTextInput()
761 && newFocus != m_frameCacheUI->currentCursor()) {
762 // The focus has changed. We may need to update things.
763 LOG_ASSERT(m_javaGlue.m_obj, "A java object was not associated with this native WebView!");
764 JNIEnv* env = JSC::Bindings::getJNIEnv();
765 AutoJObject javaObject = m_javaGlue.object(env);
766 if (javaObject.get()) {
767 env->CallVoidMethod(javaObject.get(), m_javaGlue.m_domChangedFocus);
772 if (oldCursorNode && (!m_frameCacheUI || !m_frameCacheUI->currentCursor()))
773 viewInvalidate(); // redraw in case cursor ring is still visible
774 return m_frameCacheUI;
777 int getScaledMaxXScroll()
779 LOG_ASSERT(m_javaGlue.m_obj, "A java object was not associated with this native WebView!");
780 JNIEnv* env = JSC::Bindings::getJNIEnv();
781 AutoJObject javaObject = m_javaGlue.object(env);
782 if (!javaObject.get())
784 int result = env->CallIntMethod(javaObject.get(), m_javaGlue.m_getScaledMaxXScroll);
789 int getScaledMaxYScroll()
791 LOG_ASSERT(m_javaGlue.m_obj, "A java object was not associated with this native WebView!");
792 JNIEnv* env = JSC::Bindings::getJNIEnv();
793 AutoJObject javaObject = m_javaGlue.object(env);
794 if (!javaObject.get())
796 int result = env->CallIntMethod(javaObject.get(), m_javaGlue.m_getScaledMaxYScroll);
801 IntRect getVisibleRect()
804 LOG_ASSERT(m_javaGlue.m_obj, "A java object was not associated with this native WebView!");
805 JNIEnv* env = JSC::Bindings::getJNIEnv();
806 AutoJObject javaObject = m_javaGlue.object(env);
807 if (!javaObject.get())
809 jobject jRect = env->CallObjectMethod(javaObject.get(), m_javaGlue.m_getVisibleRect);
811 rect.setX(env->GetIntField(jRect, m_javaGlue.m_rectLeft));
813 rect.setY(env->GetIntField(jRect, m_javaGlue.m_rectTop));
815 rect.setWidth(env->CallIntMethod(jRect, m_javaGlue.m_rectWidth));
817 rect.setHeight(env->CallIntMethod(jRect, m_javaGlue.m_rectHeight));
819 env->DeleteLocalRef(jRect);
824 static CachedFrame::Direction KeyToDirection(int32_t keyCode)
827 case AKEYCODE_DPAD_RIGHT:
828 DBG_NAV_LOGD("keyCode=%s", "right");
829 return CachedFrame::RIGHT;
830 case AKEYCODE_DPAD_LEFT:
831 DBG_NAV_LOGD("keyCode=%s", "left");
832 return CachedFrame::LEFT;
833 case AKEYCODE_DPAD_DOWN:
834 DBG_NAV_LOGD("keyCode=%s", "down");
835 return CachedFrame::DOWN;
836 case AKEYCODE_DPAD_UP:
837 DBG_NAV_LOGD("keyCode=%s", "up");
838 return CachedFrame::UP;
840 DBG_NAV_LOGD("bad key %d sent", keyCode);
841 return CachedFrame::UNINITIALIZED;
845 WTF::String imageURI(int x, int y)
847 const CachedRoot* root = getFrameCache(DontAllowNewer);
848 return root ? root->imageURI(x, y) : WTF::String();
851 bool cursorWantsKeyEvents()
853 const CachedRoot* root = getFrameCache(DontAllowNewer);
855 const CachedNode* focus = root->currentCursor();
857 return focus->wantsKeyEvents();
863 /* returns true if the key had no effect (neither scrolled nor changed cursor) */
864 bool moveCursor(int keyCode, int count, bool ignoreScroll)
866 CachedRoot* root = getFrameCache(AllowNewer);
868 DBG_NAV_LOG("!root");
872 m_viewImpl->m_moveGeneration++;
873 CachedFrame::Direction direction = KeyToDirection(keyCode);
874 const CachedFrame* cachedFrame, * oldFrame = 0;
875 const CachedNode* cursor = root->currentCursor(&oldFrame);
876 WebCore::IntPoint cursorLocation = root->cursorLocation();
877 DBG_NAV_LOGD("old cursor %d (nativeNode=%p) cursorLocation={%d, %d}",
878 cursor ? cursor->index() : 0,
879 cursor ? cursor->nodePointer() : 0, cursorLocation.x(), cursorLocation.y());
880 WebCore::IntRect visibleRect = setVisibleRect(root);
881 int xMax = getScaledMaxXScroll();
882 int yMax = getScaledMaxYScroll();
883 root->setMaxScroll(xMax, yMax);
884 const CachedNode* cachedNode = 0;
888 while (--counter >= 0) {
889 WebCore::IntPoint scroll = WebCore::IntPoint(0, 0);
890 cachedNode = root->moveCursor(direction, &cachedFrame, &scroll);
894 DBG_NAV_LOGD("new cursor %d (nativeNode=%p) cursorLocation={%d, %d}"
895 "bounds={%d,%d,w=%d,h=%d}", cachedNode ? cachedNode->index() : 0,
896 cachedNode ? cachedNode->nodePointer() : 0,
897 root->cursorLocation().x(), root->cursorLocation().y(),
898 cachedNode ? cachedNode->bounds(cachedFrame).x() : 0,
899 cachedNode ? cachedNode->bounds(cachedFrame).y() : 0,
900 cachedNode ? cachedNode->bounds(cachedFrame).width() : 0,
901 cachedNode ? cachedNode->bounds(cachedFrame).height() : 0);
902 // If !m_heightCanMeasure (such as in the browser), we want to scroll no
904 if (!ignoreScroll && (!m_heightCanMeasure ||
906 (cursor && cursor->nodePointer() == cachedNode->nodePointer())))
908 if (count == 1 && dx != 0 && dy == 0 && -m_lastDx == dx &&
909 SkTime::GetMSecs() - m_lastDxTime < 1000)
910 root->checkForJiggle(&dx);
911 DBG_NAV_LOGD("scrollBy %d,%d", dx, dy);
913 this->scrollBy(dx, dy);
915 m_lastDxTime = SkTime::GetMSecs();
920 m_viewImpl->updateCursorBounds(root, cachedFrame, cachedNode);
921 root->setCursor(const_cast<CachedFrame*>(cachedFrame),
922 const_cast<CachedNode*>(cachedNode));
923 const CachedNode* focus = root->currentFocus();
924 bool clearTextEntry = cachedNode != focus && focus
925 && cachedNode->nodePointer() != focus->nodePointer() && focus->isTextInput();
926 // Stop painting the caret if the old focus was a text input and so is the new cursor.
927 bool stopPaintingCaret = clearTextEntry && cachedNode->wantsKeyEvents();
928 sendMoveMouseIfLatest(clearTextEntry, stopPaintingCaret);
930 int docHeight = root->documentHeight();
931 int docWidth = root->documentWidth();
932 if (visibleRect.maxY() + dy > docHeight)
933 dy = docHeight - visibleRect.maxY();
934 else if (visibleRect.y() + dy < 0)
935 dy = -visibleRect.y();
936 if (visibleRect.maxX() + dx > docWidth)
937 dx = docWidth - visibleRect.maxX();
938 else if (visibleRect.x() < 0)
939 dx = -visibleRect.x();
940 result = direction == CachedFrame::LEFT ? dx >= 0 :
941 direction == CachedFrame::RIGHT ? dx <= 0 :
942 direction == CachedFrame::UP ? dy >= 0 : dy <= 0;
947 void notifyProgressFinished()
949 DBG_NAV_LOGD("cursorIsTextInput=%d", cursorIsTextInput(DontAllowNewer));
950 rebuildWebTextView();
952 if (m_frameCacheUI) {
953 const CachedNode* focus = m_frameCacheUI->currentFocus();
954 DBG_NAV_LOGD("focus %d (nativeNode=%p)",
955 focus ? focus->index() : 0,
956 focus ? focus->nodePointer() : 0);
961 const CachedNode* findAt(CachedRoot* root, const WebCore::IntRect& rect,
962 const CachedFrame** framePtr, int* rxPtr, int* ryPtr)
969 setVisibleRect(root);
970 return root->findAt(rect, framePtr, rxPtr, ryPtr, true);
973 IntRect setVisibleRect(CachedRoot* root)
975 IntRect visibleRect = getVisibleRect();
976 DBG_NAV_LOGD("getVisibleRect %d,%d,%d,%d",
977 visibleRect.x(), visibleRect.y(), visibleRect.width(), visibleRect.height());
978 root->setVisibleRect(visibleRect);
982 void selectBestAt(const WebCore::IntRect& rect)
984 const CachedFrame* frame;
986 CachedRoot* root = getFrameCache(AllowNewer);
989 const CachedNode* node = findAt(root, rect, &frame, &rx, &ry);
991 DBG_NAV_LOGD("no nodes found root=%p", root);
992 root->rootHistory()->setMouseBounds(rect);
993 m_viewImpl->m_hasCursorBounds = false;
994 root->setCursor(0, 0);
997 DBG_NAV_LOGD("CachedNode:%p (%d)", node, node->index());
998 WebCore::IntRect bounds = node->bounds(frame);
999 root->rootHistory()->setMouseBounds(bounds);
1000 m_viewImpl->updateCursorBounds(root, frame, node);
1002 root->setCursor(const_cast<CachedFrame*>(frame),
1003 const_cast<CachedNode*>(node));
1005 sendMoveMouseIfLatest(false, false);
1008 const CachedNode* m_cacheHitNode;
1009 const CachedFrame* m_cacheHitFrame;
1011 bool pointInNavCache(int x, int y, int slop)
1013 CachedRoot* root = getFrameCache(AllowNewer);
1016 IntRect rect = IntRect(x - slop, y - slop, slop * 2, slop * 2);
1018 return (m_cacheHitNode = findAt(root, rect, &m_cacheHitFrame, &rx, &ry));
1021 bool motionUp(int x, int y, int slop)
1023 bool pageScrolled = false;
1024 IntRect rect = IntRect(x - slop, y - slop, slop * 2, slop * 2);
1026 CachedRoot* root = getFrameCache(AllowNewer);
1029 const CachedFrame* frame = 0;
1030 const CachedNode* result = findAt(root, rect, &frame, &rx, &ry);
1031 CachedHistory* history = root->rootHistory();
1033 DBG_NAV_LOGD("no nodes found root=%p", root);
1034 history->setNavBounds(rect);
1035 m_viewImpl->m_hasCursorBounds = false;
1037 int dx = root->checkForCenter(x, y);
1040 pageScrolled = true;
1042 sendMotionUp(frame ? (WebCore::Frame*) frame->framePointer() : 0,
1045 return pageScrolled;
1047 DBG_NAV_LOGD("CachedNode:%p (%d) x=%d y=%d rx=%d ry=%d", result,
1048 result->index(), x, y, rx, ry);
1049 WebCore::IntRect navBounds = WebCore::IntRect(rx, ry, 1, 1);
1050 history->setNavBounds(navBounds);
1051 history->setMouseBounds(navBounds);
1052 m_viewImpl->updateCursorBounds(root, frame, result);
1053 root->setCursor(const_cast<CachedFrame*>(frame),
1054 const_cast<CachedNode*>(result));
1055 if (result->isSyntheticLink())
1056 overrideUrlLoading(result->getExport());
1059 (WebCore::Frame*) frame->framePointer(),
1060 (WebCore::Node*) result->nodePointer(), rx, ry);
1062 if (result->isTextInput() || result->isSelect()
1063 || result->isContentEditable()) {
1064 showCursorUntimed();
1067 return pageScrolled;
1070 #if USE(ACCELERATED_COMPOSITING)
1071 static const ScrollableLayerAndroid* findScrollableLayer(
1072 const LayerAndroid* parent, int x, int y, SkIRect* foundBounds) {
1074 parent->bounds(&bounds);
1075 // Check the parent bounds first; this will clip to within a masking layer's
1077 if (parent->masksToBounds() && !bounds.contains(x, y))
1079 // Move the hit test local to parent.
1082 int count = parent->countChildren();
1084 const LayerAndroid* child = parent->getChild(count);
1085 const ScrollableLayerAndroid* result = findScrollableLayer(child, x, y,
1088 foundBounds->offset(bounds.fLeft, bounds.fTop);
1089 if (parent->masksToBounds()) {
1090 if (bounds.width() < foundBounds->width())
1091 foundBounds->fRight = foundBounds->fLeft + bounds.width();
1092 if (bounds.height() < foundBounds->height())
1093 foundBounds->fBottom = foundBounds->fTop + bounds.height();
1098 if (parent->contentIsScrollable()) {
1099 foundBounds->set(0, 0, bounds.width(), bounds.height());
1100 return static_cast<const ScrollableLayerAndroid*>(parent);
1106 int scrollableLayer(int x, int y, SkIRect* layerRect, SkIRect* bounds)
1108 #if USE(ACCELERATED_COMPOSITING)
1109 const LayerAndroid* layerRoot = compositeRoot();
1112 const ScrollableLayerAndroid* result = findScrollableLayer(layerRoot, x, y,
1115 result->getScrollRect(layerRect);
1116 return result->uniqueId();
1122 int getBlockLeftEdge(int x, int y, float scale)
1124 CachedRoot* root = getFrameCache(AllowNewer);
1126 return root->getBlockLeftEdge(x, y, scale);
1130 void overrideUrlLoading(const WTF::String& url)
1132 JNIEnv* env = JSC::Bindings::getJNIEnv();
1133 AutoJObject javaObject = m_javaGlue.object(env);
1134 if (!javaObject.get())
1136 jstring jName = wtfStringToJstring(env, url);
1137 env->CallVoidMethod(javaObject.get(), m_javaGlue.m_overrideLoading, jName);
1138 env->DeleteLocalRef(jName);
1141 void setFindIsUp(bool up)
1143 DBG_NAV_LOGD("up=%d", up);
1144 m_viewImpl->m_findIsUp = up;
1147 void setFindIsEmpty()
1150 m_findOnPage.clearCurrentLocation();
1153 void showCursorTimed()
1156 m_ringAnimationEnd = SkTime::GetMSecs() + PRESSED_STATE_DURATION;
1160 void showCursorUntimed()
1163 m_ring.m_isPressed = false;
1164 m_ringAnimationEnd = UINT_MAX;
1168 void setHeightCanMeasure(bool measure)
1170 m_heightCanMeasure = measure;
1173 String getSelection()
1175 return m_selectText.getSelection();
1178 void moveSelection(int x, int y)
1180 m_selectText.moveSelection(getVisibleRect(), x, y);
1183 IntPoint selectableText()
1185 const CachedRoot* root = getFrameCache(DontAllowNewer);
1187 return IntPoint(0, 0);
1188 return m_selectText.selectableText(root);
1193 m_selectText.selectAll();
1198 return m_selectText.selectionX();
1203 return m_selectText.selectionY();
1206 void resetSelection()
1208 m_selectText.reset();
1211 bool startSelection(int x, int y)
1213 const CachedRoot* root = getFrameCache(DontAllowNewer);
1216 updateSelectionHandles();
1217 return m_selectText.startSelection(root, getVisibleRect(), x, y);
1220 bool wordSelection(int x, int y)
1222 const CachedRoot* root = getFrameCache(DontAllowNewer);
1225 updateSelectionHandles();
1226 return m_selectText.wordSelection(root, getVisibleRect(), x, y);
1229 bool extendSelection(int x, int y)
1231 m_selectText.extendSelection(getVisibleRect(), x, y);
1235 bool hitSelection(int x, int y)
1237 updateSelectionHandles();
1238 return m_selectText.hitSelection(x, y);
1241 void setExtendSelection()
1243 m_selectText.setExtendSelection(true);
1246 void setSelectionPointer(bool set, float scale, int x, int y)
1248 m_selectText.setDrawPointer(set);
1251 m_selectText.m_inverseScale = scale;
1252 m_selectText.m_selectX = x;
1253 m_selectText.m_selectY = y;
1256 void sendMoveFocus(WebCore::Frame* framePtr, WebCore::Node* nodePtr)
1258 DBG_NAV_LOGD("framePtr=%p nodePtr=%p", framePtr, nodePtr);
1259 JNIEnv* env = JSC::Bindings::getJNIEnv();
1260 AutoJObject javaObject = m_javaGlue.object(env);
1261 if (!javaObject.get())
1263 env->CallVoidMethod(javaObject.get(), m_javaGlue.m_sendMoveFocus, (jint) framePtr, (jint) nodePtr);
1264 checkException(env);
1267 void sendMoveMouse(WebCore::Frame* framePtr, WebCore::Node* nodePtr, int x, int y)
1269 DBG_NAV_LOGD("framePtr=%p nodePtr=%p x=%d y=%d", framePtr, nodePtr, x, y);
1270 JNIEnv* env = JSC::Bindings::getJNIEnv();
1271 AutoJObject javaObject = m_javaGlue.object(env);
1272 if (!javaObject.get())
1274 env->CallVoidMethod(javaObject.get(), m_javaGlue.m_sendMoveMouse, reinterpret_cast<jint>(framePtr), reinterpret_cast<jint>(nodePtr), x, y);
1275 checkException(env);
1278 void sendMoveMouseIfLatest(bool clearTextEntry, bool stopPaintingCaret)
1280 LOG_ASSERT(m_javaGlue.m_obj, "A java object was not associated with this native WebView!");
1281 JNIEnv* env = JSC::Bindings::getJNIEnv();
1282 AutoJObject javaObject = m_javaGlue.object(env);
1283 if (!javaObject.get())
1285 env->CallVoidMethod(javaObject.get(), m_javaGlue.m_sendMoveMouseIfLatest, clearTextEntry, stopPaintingCaret);
1286 checkException(env);
1289 void sendMotionUp(WebCore::Frame* framePtr, WebCore::Node* nodePtr, int x, int y)
1291 DBG_NAV_LOGD("m_generation=%d framePtr=%p nodePtr=%p x=%d y=%d", m_generation, framePtr, nodePtr, x, y);
1292 LOG_ASSERT(m_javaGlue.m_obj, "A WebView was not associated with this WebViewNative!");
1294 JNIEnv* env = JSC::Bindings::getJNIEnv();
1295 AutoJObject javaObject = m_javaGlue.object(env);
1296 if (!javaObject.get())
1298 m_viewImpl->m_touchGeneration = ++m_generation;
1299 env->CallVoidMethod(javaObject.get(), m_javaGlue.m_sendMotionUp, m_generation, (jint) framePtr, (jint) nodePtr, x, y);
1300 checkException(env);
1303 void findNext(bool forward)
1305 m_findOnPage.findNext(forward);
1306 scrollToCurrentMatch();
1310 // With this call, WebView takes ownership of matches, and is responsible for
1312 void setMatches(WTF::Vector<MatchInfo>* matches, jboolean sameAsLastSearch)
1314 // If this search is the same as the last one, check against the old
1315 // location to determine whether to scroll. If the same word is found
1316 // in the same place, then do not scroll.
1317 IntRect oldLocation;
1318 bool checkAgainstOldLocation = false;
1319 if (sameAsLastSearch && m_findOnPage.isCurrentLocationValid()) {
1320 oldLocation = m_findOnPage.currentMatchBounds();
1321 checkAgainstOldLocation = true;
1324 m_findOnPage.setMatches(matches);
1326 if (!checkAgainstOldLocation || oldLocation != m_findOnPage.currentMatchBounds())
1327 scrollToCurrentMatch();
1331 int currentMatchIndex()
1333 return m_findOnPage.currentMatchIndex();
1336 bool scrollBy(int dx, int dy)
1338 LOG_ASSERT(m_javaGlue.m_obj, "A java object was not associated with this native WebView!");
1340 JNIEnv* env = JSC::Bindings::getJNIEnv();
1341 AutoJObject javaObject = m_javaGlue.object(env);
1342 if (!javaObject.get())
1344 bool result = env->CallBooleanMethod(javaObject.get(), m_javaGlue.m_scrollBy, dx, dy, true);
1345 checkException(env);
1349 void setIsScrolling(bool isScrolling)
1351 #if USE(ACCELERATED_COMPOSITING)
1352 if (m_glWebViewState)
1353 m_glWebViewState->setIsScrolling(isScrolling);
1357 bool hasCursorNode()
1359 CachedRoot* root = getFrameCache(DontAllowNewer);
1361 DBG_NAV_LOG("!root");
1364 const CachedNode* cursorNode = root->currentCursor();
1365 DBG_NAV_LOGD("cursorNode=%d (nodePointer=%p)",
1366 cursorNode ? cursorNode->index() : -1,
1367 cursorNode ? cursorNode->nodePointer() : 0);
1373 CachedRoot* root = getFrameCache(DontAllowNewer);
1375 DBG_NAV_LOG("!root");
1378 const CachedNode* focusNode = root->currentFocus();
1379 DBG_NAV_LOGD("focusNode=%d (nodePointer=%p)",
1380 focusNode ? focusNode->index() : -1,
1381 focusNode ? focusNode->nodePointer() : 0);
1385 void rebuildWebTextView()
1387 JNIEnv* env = JSC::Bindings::getJNIEnv();
1388 AutoJObject javaObject = m_javaGlue.object(env);
1389 if (!javaObject.get())
1391 env->CallVoidMethod(javaObject.get(), m_javaGlue.m_rebuildWebTextView);
1392 checkException(env);
1395 void viewInvalidate()
1397 JNIEnv* env = JSC::Bindings::getJNIEnv();
1398 AutoJObject javaObject = m_javaGlue.object(env);
1399 if (!javaObject.get())
1401 env->CallVoidMethod(javaObject.get(), m_javaGlue.m_viewInvalidate);
1402 checkException(env);
1405 void viewInvalidateRect(int l, int t, int r, int b)
1407 JNIEnv* env = JSC::Bindings::getJNIEnv();
1408 AutoJObject javaObject = m_javaGlue.object(env);
1409 if (!javaObject.get())
1411 env->CallVoidMethod(javaObject.get(), m_javaGlue.m_viewInvalidateRect, l, r, t, b);
1412 checkException(env);
1415 void postInvalidateDelayed(int64_t delay, const WebCore::IntRect& bounds)
1417 JNIEnv* env = JSC::Bindings::getJNIEnv();
1418 AutoJObject javaObject = m_javaGlue.object(env);
1419 if (!javaObject.get())
1421 env->CallVoidMethod(javaObject.get(), m_javaGlue.m_postInvalidateDelayed,
1422 delay, bounds.x(), bounds.y(), bounds.maxX(), bounds.maxY());
1423 checkException(env);
1426 bool inFullScreenMode()
1428 JNIEnv* env = JSC::Bindings::getJNIEnv();
1429 AutoJObject javaObject = m_javaGlue.object(env);
1430 if (!javaObject.get())
1432 jboolean result = env->CallBooleanMethod(javaObject.get(), m_javaGlue.m_inFullScreenMode);
1433 checkException(env);
1437 int moveGeneration()
1439 return m_viewImpl->m_moveGeneration;
1442 LayerAndroid* compositeRoot() const
1444 LOG_ASSERT(!m_baseLayer || m_baseLayer->countChildren() == 1,
1445 "base layer can't have more than one child %s", __FUNCTION__);
1446 if (m_baseLayer && m_baseLayer->countChildren() == 1)
1447 return static_cast<LayerAndroid*>(m_baseLayer->getChild(0));
1452 #if ENABLE(ANDROID_OVERFLOW_SCROLL)
1453 static void copyScrollPositionRecursive(const LayerAndroid* from,
1458 for (int i = 0; i < from->countChildren(); i++) {
1459 const LayerAndroid* l = from->getChild(i);
1460 if (l->contentIsScrollable()) {
1461 const SkPoint& pos = l->getPosition();
1462 LayerAndroid* match = root->findById(l->uniqueId());
1463 if (match && match->contentIsScrollable())
1464 match->setPosition(pos.fX, pos.fY);
1466 copyScrollPositionRecursive(l, root);
1471 void registerPageSwapCallback()
1473 m_pageSwapCallbackRegistered = true;
1476 void setBaseLayer(BaseLayerAndroid* layer, SkRegion& inval, bool showVisualIndicator,
1477 bool isPictureAfterFirstLayout, bool registerPageSwapCallback)
1479 #if USE(ACCELERATED_COMPOSITING)
1480 if (m_glWebViewState)
1481 m_glWebViewState->setBaseLayer(layer, inval, showVisualIndicator,
1482 isPictureAfterFirstLayout);
1483 m_pageSwapCallbackRegistered |= registerPageSwapCallback;
1486 #if ENABLE(ANDROID_OVERFLOW_SCROLL)
1488 LayerAndroid* newCompositeRoot = static_cast<LayerAndroid*>(layer->getChild(0));
1489 copyScrollPositionRecursive(compositeRoot(), newCompositeRoot);
1492 SkSafeUnref(m_baseLayer);
1493 m_baseLayer = layer;
1494 CachedRoot* root = getFrameCache(DontAllowNewer);
1497 root->resetLayers();
1498 root->setRootLayer(compositeRoot());
1501 void getTextSelectionRegion(SkRegion *region)
1503 m_selectText.getSelectionRegion(getVisibleRect(), region, compositeRoot());
1506 void getTextSelectionHandles(int* handles)
1508 m_selectText.getSelectionHandles(handles);
1511 void replaceBaseContent(PictureSet* set)
1515 m_baseLayer->setContent(*set);
1519 void copyBaseContentToPicture(SkPicture* picture)
1523 PictureSet* content = m_baseLayer->content();
1524 m_baseLayer->drawCanvas(picture->beginRecording(content->width(), content->height(),
1525 SkPicture::kUsePathBoundsForClip_RecordingFlag));
1526 picture->endRecording();
1532 return !m_baseLayer->content()->isEmpty();
1535 void setFunctor(Functor* functor) {
1536 delete m_glDrawFunctor;
1537 m_glDrawFunctor = functor;
1540 Functor* getFunctor() {
1541 return m_glDrawFunctor;
1544 BaseLayerAndroid* getBaseLayer() {
1548 bool m_isDrawingPaused;
1549 private: // local state for WebView
1550 // private to getFrameCache(); other functions operate in a different thread
1551 CachedRoot* m_frameCacheUI; // navigation data ready for use
1552 WebViewCore* m_viewImpl;
1553 int m_generation; // associate unique ID with sent kit focus to match with ui
1554 SkPicture* m_navPictureUI;
1555 SkMSec m_ringAnimationEnd;
1556 // Corresponds to the same-named boolean on the java side.
1557 bool m_heightCanMeasure;
1559 SkMSec m_lastDxTime;
1560 SelectText m_selectText;
1561 FindOnPage m_findOnPage;
1563 BaseLayerAndroid* m_baseLayer;
1564 Functor* m_glDrawFunctor;
1565 #if USE(ACCELERATED_COMPOSITING)
1566 GLWebViewState* m_glWebViewState;
1567 bool m_pageSwapCallbackRegistered;
1569 RenderSkinButton* m_buttonSkin;
1570 }; // end of WebView class
1574 * This class holds a function pointer and parameters for calling drawGL into a specific
1575 * viewport. The pointer to the Functor will be put on a framework display list to be called
1576 * when the display list is replayed.
1578 class GLDrawFunctor : Functor {
1580 GLDrawFunctor(WebView* _wvInstance,
1581 bool(WebView::*_funcPtr)(WebCore::IntRect&, WebCore::IntRect*, WebCore::IntRect&, int, WebCore::IntRect&, jfloat, jint),
1582 WebCore::IntRect _viewRect, float _scale, int _extras) {
1583 wvInstance = _wvInstance;
1585 viewRect = _viewRect;
1589 status_t operator()(int messageId, void* data) {
1590 if (viewRect.isEmpty()) {
1591 // NOOP operation if viewport is empty
1595 WebCore::IntRect inval;
1596 int titlebarHeight = webViewRect.height() - viewRect.height();
1598 uirenderer::DrawGlInfo* info = reinterpret_cast<uirenderer::DrawGlInfo*>(data);
1599 WebCore::IntRect localViewRect = viewRect;
1601 localViewRect.move(-1 * localViewRect.x(), -1 * localViewRect.y());
1603 WebCore::IntRect clip(info->clipLeft, info->clipTop,
1604 info->clipRight - info->clipLeft,
1605 info->clipBottom - info->clipTop);
1607 bool retVal = (*wvInstance.*funcPtr)(localViewRect, &inval, webViewRect, titlebarHeight, clip, scale, extras);
1610 if (inval.isEmpty()) {
1611 finalInval = webViewRect;
1614 finalInval.setX(webViewRect.x() + inval.x());
1615 finalInval.setY(webViewRect.y() + titlebarHeight + inval.y());
1616 finalInval.setWidth(inval.width());
1617 finalInval.setHeight(inval.height());
1619 info->dirtyLeft = finalInval.x();
1620 info->dirtyTop = finalInval.y();
1621 info->dirtyRight = finalInval.maxX();
1622 info->dirtyBottom = finalInval.maxY();
1624 // return 1 if invalidation needed, 0 otherwise
1625 return retVal ? 1 : 0;
1627 void updateRect(WebCore::IntRect& _viewRect) {
1628 viewRect = _viewRect;
1630 void updateViewRect(WebCore::IntRect& _viewRect) {
1631 webViewRect = _viewRect;
1634 WebView* wvInstance;
1635 bool (WebView::*funcPtr)(WebCore::IntRect&, WebCore::IntRect*, WebCore::IntRect&, int, WebCore::IntRect&, float, int);
1636 WebCore::IntRect viewRect;
1637 WebCore::IntRect webViewRect;
1642 static jobject createJavaRect(JNIEnv* env, int x, int y, int right, int bottom)
1644 jclass rectClass = env->FindClass("android/graphics/Rect");
1645 jmethodID init = env->GetMethodID(rectClass, "<init>", "(IIII)V");
1646 jobject rect = env->NewObject(rectClass, init, x, y, right, bottom);
1647 env->DeleteLocalRef(rectClass);
1652 * Native JNI methods
1654 static int nativeCacheHitFramePointer(JNIEnv *env, jobject obj)
1656 return reinterpret_cast<int>(GET_NATIVE_VIEW(env, obj)
1657 ->m_cacheHitFrame->framePointer());
1660 static jobject nativeCacheHitNodeBounds(JNIEnv *env, jobject obj)
1662 WebCore::IntRect bounds = GET_NATIVE_VIEW(env, obj)
1663 ->m_cacheHitNode->originalAbsoluteBounds();
1664 return createJavaRect(env, bounds.x(), bounds.y(),
1665 bounds.maxX(), bounds.maxY());
1668 static int nativeCacheHitNodePointer(JNIEnv *env, jobject obj)
1670 return reinterpret_cast<int>(GET_NATIVE_VIEW(env, obj)
1671 ->m_cacheHitNode->nodePointer());
1674 static bool nativeCacheHitIsPlugin(JNIEnv *env, jobject obj)
1676 return GET_NATIVE_VIEW(env, obj)->m_cacheHitNode->isPlugin();
1679 static void nativeClearCursor(JNIEnv *env, jobject obj)
1681 WebView* view = GET_NATIVE_VIEW(env, obj);
1682 LOG_ASSERT(view, "view not set in %s", __FUNCTION__);
1683 view->clearCursor();
1686 static void nativeCreate(JNIEnv *env, jobject obj, int viewImpl, jstring drawableDir)
1688 WTF::String dir = jstringToWtfString(env, drawableDir);
1689 WebView* webview = new WebView(env, obj, viewImpl, dir);
1690 // NEED THIS OR SOMETHING LIKE IT!
1694 static jint nativeCursorFramePointer(JNIEnv *env, jobject obj)
1696 WebView* view = GET_NATIVE_VIEW(env, obj);
1697 CachedRoot* root = view->getFrameCache(WebView::DontAllowNewer);
1700 const CachedFrame* frame = 0;
1701 (void) root->currentCursor(&frame);
1702 return reinterpret_cast<int>(frame ? frame->framePointer() : 0);
1705 static const CachedNode* getCursorNode(JNIEnv *env, jobject obj)
1707 WebView* view = GET_NATIVE_VIEW(env, obj);
1708 CachedRoot* root = view->getFrameCache(WebView::DontAllowNewer);
1709 return root ? root->currentCursor() : 0;
1712 static const CachedNode* getCursorNode(JNIEnv *env, jobject obj,
1713 const CachedFrame** frame)
1715 WebView* view = GET_NATIVE_VIEW(env, obj);
1716 CachedRoot* root = view->getFrameCache(WebView::DontAllowNewer);
1717 return root ? root->currentCursor(frame) : 0;
1720 static const CachedNode* getFocusCandidate(JNIEnv *env, jobject obj,
1721 const CachedFrame** frame)
1723 WebView* view = GET_NATIVE_VIEW(env, obj);
1724 CachedRoot* root = view->getFrameCache(WebView::DontAllowNewer);
1727 const CachedNode* cursor = root->currentCursor(frame);
1728 if (cursor && cursor->wantsKeyEvents())
1730 return root->currentFocus(frame);
1733 static bool focusCandidateHasNextTextfield(JNIEnv *env, jobject obj)
1735 WebView* view = GET_NATIVE_VIEW(env, obj);
1736 CachedRoot* root = view->getFrameCache(WebView::DontAllowNewer);
1739 const CachedNode* cursor = root->currentCursor();
1740 if (!cursor || !cursor->isTextInput())
1741 cursor = root->currentFocus();
1742 if (!cursor || !cursor->isTextInput()) return false;
1743 return root->nextTextField(cursor, 0);
1746 static const CachedNode* getFocusNode(JNIEnv *env, jobject obj)
1748 WebView* view = GET_NATIVE_VIEW(env, obj);
1749 CachedRoot* root = view->getFrameCache(WebView::DontAllowNewer);
1750 return root ? root->currentFocus() : 0;
1753 static const CachedNode* getFocusNode(JNIEnv *env, jobject obj,
1754 const CachedFrame** frame)
1756 WebView* view = GET_NATIVE_VIEW(env, obj);
1757 CachedRoot* root = view->getFrameCache(WebView::DontAllowNewer);
1758 return root ? root->currentFocus(frame) : 0;
1761 static const CachedInput* getInputCandidate(JNIEnv *env, jobject obj)
1763 WebView* view = GET_NATIVE_VIEW(env, obj);
1764 CachedRoot* root = view->getFrameCache(WebView::DontAllowNewer);
1767 const CachedFrame* frame;
1768 const CachedNode* cursor = root->currentCursor(&frame);
1769 if (!cursor || !cursor->wantsKeyEvents())
1770 cursor = root->currentFocus(&frame);
1771 return cursor ? frame->textInput(cursor) : 0;
1774 static jboolean nativePageShouldHandleShiftAndArrows(JNIEnv *env, jobject obj)
1776 const CachedNode* focus = getFocusNode(env, obj);
1777 if (!focus) return false;
1778 // Plugins handle shift and arrows whether or not they have focus.
1779 if (focus->isPlugin()) return true;
1780 const CachedNode* cursor = getCursorNode(env, obj);
1781 // ContentEditable nodes should only receive shift and arrows if they have
1782 // both the cursor and the focus.
1783 return cursor && cursor->nodePointer() == focus->nodePointer()
1784 && cursor->isContentEditable();
1787 static jobject nativeCursorNodeBounds(JNIEnv *env, jobject obj)
1789 const CachedFrame* frame;
1790 const CachedNode* node = getCursorNode(env, obj, &frame);
1791 WebCore::IntRect bounds = node ? node->bounds(frame)
1792 : WebCore::IntRect(0, 0, 0, 0);
1793 return createJavaRect(env, bounds.x(), bounds.y(),
1794 bounds.maxX(), bounds.maxY());
1797 static jint nativeCursorNodePointer(JNIEnv *env, jobject obj)
1799 const CachedNode* node = getCursorNode(env, obj);
1800 return reinterpret_cast<int>(node ? node->nodePointer() : 0);
1803 static jobject nativeCursorPosition(JNIEnv *env, jobject obj)
1805 WebView* view = GET_NATIVE_VIEW(env, obj);
1806 const CachedRoot* root = view->getFrameCache(WebView::DontAllowNewer);
1807 WebCore::IntPoint pos = WebCore::IntPoint(0, 0);
1809 root->getSimulatedMousePosition(&pos);
1810 jclass pointClass = env->FindClass("android/graphics/Point");
1811 jmethodID init = env->GetMethodID(pointClass, "<init>", "(II)V");
1812 jobject point = env->NewObject(pointClass, init, pos.x(), pos.y());
1813 env->DeleteLocalRef(pointClass);
1817 static WebCore::IntRect jrect_to_webrect(JNIEnv* env, jobject obj)
1820 GraphicsJNI::get_jrect(env, obj, &L, &T, &R, &B);
1821 return WebCore::IntRect(L, T, R - L, B - T);
1824 static bool nativeCursorIntersects(JNIEnv *env, jobject obj, jobject visRect)
1826 const CachedFrame* frame;
1827 const CachedNode* node = getCursorNode(env, obj, &frame);
1828 return node ? node->bounds(frame).intersects(
1829 jrect_to_webrect(env, visRect)) : false;
1832 static bool nativeCursorIsAnchor(JNIEnv *env, jobject obj)
1834 const CachedNode* node = getCursorNode(env, obj);
1835 return node ? node->isAnchor() : false;
1838 static bool nativeCursorIsTextInput(JNIEnv *env, jobject obj)
1840 const CachedNode* node = getCursorNode(env, obj);
1841 return node ? node->isTextInput() : false;
1844 static jobject nativeCursorText(JNIEnv *env, jobject obj)
1846 const CachedNode* node = getCursorNode(env, obj);
1849 WTF::String value = node->getExport();
1850 return wtfStringToJstring(env, value);
1853 static void nativeDebugDump(JNIEnv *env, jobject obj)
1856 WebView* view = GET_NATIVE_VIEW(env, obj);
1857 LOG_ASSERT(view, "view not set in %s", __FUNCTION__);
1862 static jint nativeDraw(JNIEnv *env, jobject obj, jobject canv, jint color,
1863 jint extras, jboolean split) {
1864 SkCanvas* canvas = GraphicsJNI::getNativeCanvas(env, canv);
1865 return reinterpret_cast<jint>(GET_NATIVE_VIEW(env, obj)->draw(canvas, color, extras, split));
1868 static jint nativeGetDrawGLFunction(JNIEnv *env, jobject obj, jint nativeView,
1869 jobject jrect, jobject jviewrect,
1870 jfloat scale, jint extras) {
1871 WebCore::IntRect viewRect;
1872 if (jrect == NULL) {
1873 viewRect = WebCore::IntRect();
1875 viewRect = jrect_to_webrect(env, jrect);
1877 WebView *wvInstance = (WebView*) nativeView;
1878 GLDrawFunctor* functor = new GLDrawFunctor(wvInstance, &android::WebView::drawGL,
1879 viewRect, scale, extras);
1880 wvInstance->setFunctor((Functor*) functor);
1882 WebCore::IntRect webViewRect;
1883 if (jviewrect == NULL) {
1884 webViewRect = WebCore::IntRect();
1886 webViewRect = jrect_to_webrect(env, jviewrect);
1888 functor->updateViewRect(webViewRect);
1890 return (jint)functor;
1893 static void nativeUpdateDrawGLFunction(JNIEnv *env, jobject obj, jobject jrect, jobject jviewrect) {
1894 WebView *wvInstance = GET_NATIVE_VIEW(env, obj);
1895 if (wvInstance != NULL) {
1896 GLDrawFunctor* functor = (GLDrawFunctor*) wvInstance->getFunctor();
1897 if (functor != NULL) {
1898 WebCore::IntRect viewRect;
1899 if (jrect == NULL) {
1900 viewRect = WebCore::IntRect();
1902 viewRect = jrect_to_webrect(env, jrect);
1904 functor->updateRect(viewRect);
1906 WebCore::IntRect webViewRect;
1907 if (jviewrect == NULL) {
1908 webViewRect = WebCore::IntRect();
1910 webViewRect = jrect_to_webrect(env, jviewrect);
1912 functor->updateViewRect(webViewRect);
1917 static bool nativeEvaluateLayersAnimations(JNIEnv *env, jobject obj, jint nativeView)
1919 #if USE(ACCELERATED_COMPOSITING)
1920 LayerAndroid* root = ((WebView*)nativeView)->compositeRoot();
1922 return root->evaluateAnimations();
1927 static void nativeSetBaseLayer(JNIEnv *env, jobject obj, jint layer, jobject inval,
1928 jboolean showVisualIndicator,
1929 jboolean isPictureAfterFirstLayout,
1930 jboolean registerPageSwapCallback)
1932 BaseLayerAndroid* layerImpl = reinterpret_cast<BaseLayerAndroid*>(layer);
1933 SkRegion invalRegion;
1935 invalRegion = *GraphicsJNI::getNativeRegion(env, inval);
1936 GET_NATIVE_VIEW(env, obj)->setBaseLayer(layerImpl, invalRegion, showVisualIndicator,
1937 isPictureAfterFirstLayout,
1938 registerPageSwapCallback);
1941 static void nativeGetTextSelectionRegion(JNIEnv *env, jobject obj, jint view,
1946 SkRegion* nregion = GraphicsJNI::getNativeRegion(env, region);
1947 ((WebView*)view)->getTextSelectionRegion(nregion);
1950 static void nativeGetSelectionHandles(JNIEnv *env, jobject obj, jint view,
1954 ((WebView*)view)->getTextSelectionHandles(handles);
1955 env->SetIntArrayRegion(arr, 0, 4, handles);
1956 checkException(env);
1959 static BaseLayerAndroid* nativeGetBaseLayer(JNIEnv *env, jobject obj)
1961 return GET_NATIVE_VIEW(env, obj)->getBaseLayer();
1964 static void nativeReplaceBaseContent(JNIEnv *env, jobject obj, jint content)
1966 PictureSet* set = reinterpret_cast<PictureSet*>(content);
1967 GET_NATIVE_VIEW(env, obj)->replaceBaseContent(set);
1970 static void nativeCopyBaseContentToPicture(JNIEnv *env, jobject obj, jobject pict)
1972 SkPicture* picture = GraphicsJNI::getNativePicture(env, pict);
1973 GET_NATIVE_VIEW(env, obj)->copyBaseContentToPicture(picture);
1976 static bool nativeHasContent(JNIEnv *env, jobject obj)
1978 return GET_NATIVE_VIEW(env, obj)->hasContent();
1981 static jobject nativeImageURI(JNIEnv *env, jobject obj, jint x, jint y)
1983 WebView* view = GET_NATIVE_VIEW(env, obj);
1984 LOG_ASSERT(view, "view not set in %s", __FUNCTION__);
1985 WTF::String uri = view->imageURI(x, y);
1986 return wtfStringToJstring(env, uri);
1989 static jint nativeFocusCandidateFramePointer(JNIEnv *env, jobject obj)
1991 WebView* view = GET_NATIVE_VIEW(env, obj);
1992 CachedRoot* root = view->getFrameCache(WebView::DontAllowNewer);
1995 const CachedFrame* frame = 0;
1996 const CachedNode* cursor = root->currentCursor(&frame);
1997 if (!cursor || !cursor->wantsKeyEvents())
1998 (void) root->currentFocus(&frame);
1999 return reinterpret_cast<int>(frame ? frame->framePointer() : 0);
2002 static bool nativeFocusCandidateIsPassword(JNIEnv *env, jobject obj)
2004 const CachedInput* input = getInputCandidate(env, obj);
2005 return input && input->getType() == CachedInput::PASSWORD;
2008 static bool nativeFocusCandidateIsRtlText(JNIEnv *env, jobject obj)
2010 const CachedInput* input = getInputCandidate(env, obj);
2011 return input ? input->isRtlText() : false;
2014 static bool nativeFocusCandidateIsTextInput(JNIEnv *env, jobject obj)
2016 const CachedNode* node = getFocusCandidate(env, obj, 0);
2017 return node ? node->isTextInput() : false;
2020 static jint nativeFocusCandidateMaxLength(JNIEnv *env, jobject obj)
2022 const CachedInput* input = getInputCandidate(env, obj);
2023 return input ? input->maxLength() : false;
2026 static jint nativeFocusCandidateIsAutoComplete(JNIEnv *env, jobject obj)
2028 const CachedInput* input = getInputCandidate(env, obj);
2029 return input ? input->autoComplete() : false;
2032 static jobject nativeFocusCandidateName(JNIEnv *env, jobject obj)
2034 const CachedInput* input = getInputCandidate(env, obj);
2037 const WTF::String& name = input->name();
2038 return wtfStringToJstring(env, name);
2041 static jobject nativeFocusCandidateNodeBounds(JNIEnv *env, jobject obj)
2043 const CachedFrame* frame;
2044 const CachedNode* node = getFocusCandidate(env, obj, &frame);
2045 WebCore::IntRect bounds = node ? node->bounds(frame)
2046 : WebCore::IntRect(0, 0, 0, 0);
2047 // Inset the rect by 1 unit, so that the focus candidate's border can still
2048 // be seen behind it.
2049 return createJavaRect(env, bounds.x() + 1, bounds.y() + 1,
2050 bounds.maxX() - 1, bounds.maxY() - 1);
2053 static jobject nativeFocusCandidatePaddingRect(JNIEnv *env, jobject obj)
2055 const CachedInput* input = getInputCandidate(env, obj);
2058 // Note that the Java Rect is being used to pass four integers, rather than
2059 // being used as an actual rectangle.
2060 return createJavaRect(env, input->paddingLeft(), input->paddingTop(),
2061 input->paddingRight(), input->paddingBottom());
2064 static jint nativeFocusCandidatePointer(JNIEnv *env, jobject obj)
2066 const CachedNode* node = getFocusCandidate(env, obj, 0);
2067 return reinterpret_cast<int>(node ? node->nodePointer() : 0);
2070 static jint nativeFocusCandidateIsSpellcheck(JNIEnv *env, jobject obj)
2072 const CachedInput* input = getInputCandidate(env, obj);
2073 return input ? input->spellcheck() : false;
2076 static jobject nativeFocusCandidateText(JNIEnv *env, jobject obj)
2078 const CachedNode* node = getFocusCandidate(env, obj, 0);
2081 WTF::String value = node->getExport();
2082 return wtfStringToJstring(env, value);
2085 static int nativeFocusCandidateLineHeight(JNIEnv *env, jobject obj)
2087 const CachedInput* input = getInputCandidate(env, obj);
2088 return input ? input->lineHeight() : 0;
2091 static jfloat nativeFocusCandidateTextSize(JNIEnv *env, jobject obj)
2093 const CachedInput* input = getInputCandidate(env, obj);
2094 return input ? input->textSize() : 0.f;
2097 static int nativeFocusCandidateType(JNIEnv *env, jobject obj)
2099 const CachedInput* input = getInputCandidate(env, obj);
2101 return CachedInput::NONE;
2103 if (input->isTextArea())
2104 return CachedInput::TEXT_AREA;
2106 return input->getType();
2109 static bool nativeFocusIsPlugin(JNIEnv *env, jobject obj)
2111 const CachedNode* node = getFocusNode(env, obj);
2112 return node ? node->isPlugin() : false;
2115 static jobject nativeFocusNodeBounds(JNIEnv *env, jobject obj)
2117 const CachedFrame* frame;
2118 const CachedNode* node = getFocusNode(env, obj, &frame);
2119 WebCore::IntRect bounds = node ? node->bounds(frame)
2120 : WebCore::IntRect(0, 0, 0, 0);
2121 return createJavaRect(env, bounds.x(), bounds.y(),
2122 bounds.maxX(), bounds.maxY());
2125 static jint nativeFocusNodePointer(JNIEnv *env, jobject obj)
2127 const CachedNode* node = getFocusNode(env, obj);
2128 return node ? reinterpret_cast<int>(node->nodePointer()) : 0;
2131 static bool nativeCursorWantsKeyEvents(JNIEnv* env, jobject jwebview) {
2132 WebView* view = GET_NATIVE_VIEW(env, jwebview);
2133 LOG_ASSERT(view, "view not set in %s", __FUNCTION__);
2134 return view->cursorWantsKeyEvents();
2137 static void nativeHideCursor(JNIEnv *env, jobject obj)
2139 WebView* view = GET_NATIVE_VIEW(env, obj);
2140 LOG_ASSERT(view, "view not set in %s", __FUNCTION__);
2144 static void nativeInstrumentReport(JNIEnv *env, jobject obj)
2146 #ifdef ANDROID_INSTRUMENT
2147 TimeCounter::reportNow();
2151 static void nativeSelectBestAt(JNIEnv *env, jobject obj, jobject jrect)
2153 WebView* view = GET_NATIVE_VIEW(env, obj);
2154 LOG_ASSERT(view, "view not set in %s", __FUNCTION__);
2155 WebCore::IntRect rect = jrect_to_webrect(env, jrect);
2156 view->selectBestAt(rect);
2159 static void nativeSelectAt(JNIEnv *env, jobject obj, jint x, jint y)
2161 WebView* view = GET_NATIVE_VIEW(env, obj);
2162 LOG_ASSERT(view, "view not set in %s", __FUNCTION__);
2163 WebCore::IntRect rect = IntRect(x, y , 1, 1);
2164 view->selectBestAt(rect);
2165 if (view->hasCursorNode())
2166 view->showCursorUntimed();
2169 static jobject nativeLayerBounds(JNIEnv* env, jobject obj, jint jlayer)
2172 #if USE(ACCELERATED_COMPOSITING)
2173 LayerAndroid* layer = (LayerAndroid*) jlayer;
2174 r = layer->bounds();
2180 jclass rectClass = env->FindClass("android/graphics/Rect");
2181 jmethodID init = env->GetMethodID(rectClass, "<init>", "(IIII)V");
2182 jobject rect = env->NewObject(rectClass, init, irect.fLeft, irect.fTop,
2183 irect.fRight, irect.fBottom);
2184 env->DeleteLocalRef(rectClass);
2188 static jobject nativeSubtractLayers(JNIEnv* env, jobject obj, jobject jrect)
2190 SkIRect irect = jrect_to_webrect(env, jrect);
2191 #if USE(ACCELERATED_COMPOSITING)
2192 LayerAndroid* root = GET_NATIVE_VIEW(env, obj)->compositeRoot();
2196 rect = root->subtractLayers(rect);
2200 jclass rectClass = env->FindClass("android/graphics/Rect");
2201 jmethodID init = env->GetMethodID(rectClass, "<init>", "(IIII)V");
2202 jobject rect = env->NewObject(rectClass, init, irect.fLeft, irect.fTop,
2203 irect.fRight, irect.fBottom);
2204 env->DeleteLocalRef(rectClass);
2208 static jint nativeTextGeneration(JNIEnv *env, jobject obj)
2210 WebView* view = GET_NATIVE_VIEW(env, obj);
2211 CachedRoot* root = view->getFrameCache(WebView::DontAllowNewer);
2212 return root ? root->textGeneration() : 0;
2215 static bool nativePointInNavCache(JNIEnv *env, jobject obj,
2216 int x, int y, int slop)
2218 return GET_NATIVE_VIEW(env, obj)->pointInNavCache(x, y, slop);
2221 static bool nativeMotionUp(JNIEnv *env, jobject obj,
2222 int x, int y, int slop)
2224 WebView* view = GET_NATIVE_VIEW(env, obj);
2225 LOG_ASSERT(view, "view not set in %s", __FUNCTION__);
2226 return view->motionUp(x, y, slop);
2229 static bool nativeHasCursorNode(JNIEnv *env, jobject obj)
2231 return GET_NATIVE_VIEW(env, obj)->hasCursorNode();
2234 static bool nativeHasFocusNode(JNIEnv *env, jobject obj)
2236 return GET_NATIVE_VIEW(env, obj)->hasFocusNode();
2239 static bool nativeMoveCursor(JNIEnv *env, jobject obj,
2240 int key, int count, bool ignoreScroll)
2242 WebView* view = GET_NATIVE_VIEW(env, obj);
2243 DBG_NAV_LOGD("env=%p obj=%p view=%p", env, obj, view);
2244 LOG_ASSERT(view, "view not set in %s", __FUNCTION__);
2245 return view->moveCursor(key, count, ignoreScroll);
2248 static void nativeSetFindIsUp(JNIEnv *env, jobject obj, jboolean isUp)
2250 WebView* view = GET_NATIVE_VIEW(env, obj);
2251 LOG_ASSERT(view, "view not set in %s", __FUNCTION__);
2252 view->setFindIsUp(isUp);
2255 static void nativeSetFindIsEmpty(JNIEnv *env, jobject obj)
2257 GET_NATIVE_VIEW(env, obj)->setFindIsEmpty();
2260 static void nativeShowCursorTimed(JNIEnv *env, jobject obj)
2262 GET_NATIVE_VIEW(env, obj)->showCursorTimed();
2265 static void nativeSetHeightCanMeasure(JNIEnv *env, jobject obj, bool measure)
2267 WebView* view = GET_NATIVE_VIEW(env, obj);
2268 LOG_ASSERT(view, "view not set in nativeSetHeightCanMeasure");
2269 view->setHeightCanMeasure(measure);
2272 static jobject nativeGetCursorRingBounds(JNIEnv *env, jobject obj)
2274 WebView* view = GET_NATIVE_VIEW(env, obj);
2275 LOG_ASSERT(view, "view not set in %s", __FUNCTION__);
2276 jclass rectClass = env->FindClass("android/graphics/Rect");
2277 LOG_ASSERT(rectClass, "Could not find Rect class!");
2278 jmethodID init = env->GetMethodID(rectClass, "<init>", "(IIII)V");
2279 LOG_ASSERT(init, "Could not find constructor for Rect");
2280 WebCore::IntRect webRect;
2281 view->cursorRingBounds(&webRect);
2282 jobject rect = env->NewObject(rectClass, init, webRect.x(),
2283 webRect.y(), webRect.maxX(), webRect.maxY());
2284 env->DeleteLocalRef(rectClass);
2288 static int nativeFindAll(JNIEnv *env, jobject obj, jstring findLower,
2289 jstring findUpper, jboolean sameAsLastSearch)
2291 // If one or the other is null, do not search.
2292 if (!(findLower && findUpper))
2294 // Obtain the characters for both the lower case string and the upper case
2295 // string representing the same word.
2296 const jchar* findLowerChars = env->GetStringChars(findLower, 0);
2297 const jchar* findUpperChars = env->GetStringChars(findUpper, 0);
2298 // If one or the other is null, do not search.
2299 if (!(findLowerChars && findUpperChars)) {
2301 env->ReleaseStringChars(findLower, findLowerChars);
2303 env->ReleaseStringChars(findUpper, findUpperChars);
2304 checkException(env);
2307 WebView* view = GET_NATIVE_VIEW(env, obj);
2308 LOG_ASSERT(view, "view not set in nativeFindAll");
2309 CachedRoot* root = view->getFrameCache(WebView::AllowNewer);
2311 env->ReleaseStringChars(findLower, findLowerChars);
2312 env->ReleaseStringChars(findUpper, findUpperChars);
2313 checkException(env);
2316 int length = env->GetStringLength(findLower);
2317 // If the lengths of the strings do not match, then they are not the same
2318 // word, so do not search.
2319 if (!length || env->GetStringLength(findUpper) != length) {
2320 env->ReleaseStringChars(findLower, findLowerChars);
2321 env->ReleaseStringChars(findUpper, findUpperChars);
2322 checkException(env);
2325 int width = root->documentWidth();
2326 int height = root->documentHeight();
2327 // Create a FindCanvas, which allows us to fake draw into it so we can
2328 // figure out where our search string is rendered (and how many times).
2329 FindCanvas canvas(width, height, (const UChar*) findLowerChars,
2330 (const UChar*) findUpperChars, length << 1);
2332 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height);
2333 canvas.setBitmapDevice(bitmap);
2335 WTF::Vector<MatchInfo>* matches = canvas.detachMatches();
2336 // With setMatches, the WebView takes ownership of matches
2337 view->setMatches(matches, sameAsLastSearch);
2339 env->ReleaseStringChars(findLower, findLowerChars);
2340 env->ReleaseStringChars(findUpper, findUpperChars);
2341 checkException(env);
2342 return canvas.found();
2345 static void nativeFindNext(JNIEnv *env, jobject obj, bool forward)
2347 WebView* view = GET_NATIVE_VIEW(env, obj);
2348 LOG_ASSERT(view, "view not set in nativeFindNext");
2349 view->findNext(forward);
2352 static int nativeFindIndex(JNIEnv *env, jobject obj)
2354 WebView* view = GET_NATIVE_VIEW(env, obj);
2355 LOG_ASSERT(view, "view not set in nativeFindIndex");
2356 return view->currentMatchIndex();
2359 static void nativeUpdateCachedTextfield(JNIEnv *env, jobject obj, jstring updatedText, jint generation)
2361 WebView* view = GET_NATIVE_VIEW(env, obj);
2362 LOG_ASSERT(view, "view not set in nativeUpdateCachedTextfield");
2363 CachedRoot* root = view->getFrameCache(WebView::DontAllowNewer);
2366 const CachedNode* cachedFocusNode = root->currentFocus();
2367 if (!cachedFocusNode || !cachedFocusNode->isTextInput())
2369 WTF::String webcoreString = jstringToWtfString(env, updatedText);
2370 (const_cast<CachedNode*>(cachedFocusNode))->setExport(webcoreString);
2371 root->setTextGeneration(generation);
2372 checkException(env);
2375 static jint nativeGetBlockLeftEdge(JNIEnv *env, jobject obj, jint x, jint y,
2378 WebView* view = GET_NATIVE_VIEW(env, obj);
2379 LOG_ASSERT(view, "view not set in %s", __FUNCTION__);
2382 return view->getBlockLeftEdge(x, y, scale);
2385 static void nativeDestroy(JNIEnv *env, jobject obj)
2387 WebView* view = GET_NATIVE_VIEW(env, obj);
2388 LOGD("nativeDestroy view: %p", view);
2389 LOG_ASSERT(view, "view not set in nativeDestroy");
2393 static void nativeStopGL(JNIEnv *env, jobject obj)
2395 GET_NATIVE_VIEW(env, obj)->stopGL();
2398 static bool nativeMoveCursorToNextTextInput(JNIEnv *env, jobject obj)
2400 WebView* view = GET_NATIVE_VIEW(env, obj);
2401 CachedRoot* root = view->getFrameCache(WebView::DontAllowNewer);
2404 const CachedNode* current = root->currentCursor();
2405 if (!current || !current->isTextInput())
2406 current = root->currentFocus();
2407 if (!current || !current->isTextInput())
2409 const CachedFrame* frame;
2410 const CachedNode* next = root->nextTextField(current, &frame);
2413 const WebCore::IntRect& bounds = next->bounds(frame);
2414 root->rootHistory()->setMouseBounds(bounds);
2415 view->getWebViewCore()->updateCursorBounds(root, frame, next);
2416 view->showCursorUntimed();
2417 root->setCursor(const_cast<CachedFrame*>(frame),
2418 const_cast<CachedNode*>(next));
2419 view->sendMoveFocus(static_cast<WebCore::Frame*>(frame->framePointer()),
2420 static_cast<WebCore::Node*>(next->nodePointer()));
2421 if (!next->isInLayer())
2422 view->scrollRectOnScreen(bounds);
2423 view->getWebViewCore()->m_moveGeneration++;
2427 static int nativeMoveGeneration(JNIEnv *env, jobject obj)
2429 WebView* view = GET_NATIVE_VIEW(env, obj);
2432 return view->moveGeneration();
2435 static void nativeMoveSelection(JNIEnv *env, jobject obj, int x, int y)
2437 GET_NATIVE_VIEW(env, obj)->moveSelection(x, y);
2440 static void nativeResetSelection(JNIEnv *env, jobject obj)
2442 return GET_NATIVE_VIEW(env, obj)->resetSelection();
2445 static jobject nativeSelectableText(JNIEnv* env, jobject obj)
2447 IntPoint pos = GET_NATIVE_VIEW(env, obj)->selectableText();
2448 jclass pointClass = env->FindClass("android/graphics/Point");
2449 jmethodID init = env->GetMethodID(pointClass, "<init>", "(II)V");
2450 jobject point = env->NewObject(pointClass, init, pos.x(), pos.y());
2451 env->DeleteLocalRef(pointClass);
2455 static void nativeSelectAll(JNIEnv* env, jobject obj)
2457 GET_NATIVE_VIEW(env, obj)->selectAll();
2460 static void nativeSetExtendSelection(JNIEnv *env, jobject obj)
2462 GET_NATIVE_VIEW(env, obj)->setExtendSelection();
2465 static jboolean nativeStartSelection(JNIEnv *env, jobject obj, int x, int y)
2467 return GET_NATIVE_VIEW(env, obj)->startSelection(x, y);
2470 static jboolean nativeWordSelection(JNIEnv *env, jobject obj, int x, int y)
2472 return GET_NATIVE_VIEW(env, obj)->wordSelection(x, y);
2475 static void nativeExtendSelection(JNIEnv *env, jobject obj, int x, int y)
2477 GET_NATIVE_VIEW(env, obj)->extendSelection(x, y);
2480 static jobject nativeGetSelection(JNIEnv *env, jobject obj)
2482 WebView* view = GET_NATIVE_VIEW(env, obj);
2483 LOG_ASSERT(view, "view not set in %s", __FUNCTION__);
2484 String selection = view->getSelection();
2485 return wtfStringToJstring(env, selection);
2488 static jboolean nativeHitSelection(JNIEnv *env, jobject obj, int x, int y)
2490 return GET_NATIVE_VIEW(env, obj)->hitSelection(x, y);
2493 static jint nativeSelectionX(JNIEnv *env, jobject obj)
2495 return GET_NATIVE_VIEW(env, obj)->selectionX();
2498 static jint nativeSelectionY(JNIEnv *env, jobject obj)
2500 return GET_NATIVE_VIEW(env, obj)->selectionY();
2503 static void nativeSetSelectionPointer(JNIEnv *env, jobject obj, jint nativeView,
2504 jboolean set, jfloat scale, jint x, jint y)
2506 ((WebView*)nativeView)->setSelectionPointer(set, scale, x, y);
2509 static void nativeRegisterPageSwapCallback(JNIEnv *env, jobject obj)
2511 GET_NATIVE_VIEW(env, obj)->registerPageSwapCallback();
2514 static void nativeTileProfilingStart(JNIEnv *env, jobject obj)
2516 TilesManager::instance()->getProfiler()->start();
2519 static float nativeTileProfilingStop(JNIEnv *env, jobject obj)
2521 return TilesManager::instance()->getProfiler()->stop();
2524 static void nativeTileProfilingClear(JNIEnv *env, jobject obj)
2526 TilesManager::instance()->getProfiler()->clear();
2529 static int nativeTileProfilingNumFrames(JNIEnv *env, jobject obj)
2531 return TilesManager::instance()->getProfiler()->numFrames();
2534 static int nativeTileProfilingNumTilesInFrame(JNIEnv *env, jobject obj, int frame)
2536 return TilesManager::instance()->getProfiler()->numTilesInFrame(frame);
2539 static int nativeTileProfilingGetInt(JNIEnv *env, jobject obj, int frame, int tile, jstring jkey)
2541 WTF::String key = jstringToWtfString(env, jkey);
2542 TileProfileRecord* record = TilesManager::instance()->getProfiler()->getTile(frame, tile);
2545 return record->left;
2549 return record->right;
2550 if (key == "bottom")
2551 return record->bottom;
2553 return record->level;
2554 if (key == "isReady")
2555 return record->isReady ? 1 : 0;
2559 static float nativeTileProfilingGetFloat(JNIEnv *env, jobject obj, int frame, int tile, jstring jkey)
2561 TileProfileRecord* record = TilesManager::instance()->getProfiler()->getTile(frame, tile);
2562 return record->scale;
2565 #ifdef ANDROID_DUMP_DISPLAY_TREE
2566 static void dumpToFile(const char text[], void* file) {
2567 fwrite(text, 1, strlen(text), reinterpret_cast<FILE*>(file));
2568 fwrite("\n", 1, 1, reinterpret_cast<FILE*>(file));
2572 static bool nativeSetProperty(JNIEnv *env, jobject obj, jstring jkey, jstring jvalue)
2574 WTF::String key = jstringToWtfString(env, jkey);
2575 WTF::String value = jstringToWtfString(env, jvalue);
2576 if (key == "inverted") {
2577 if (value == "true")
2578 TilesManager::instance()->setInvertedScreen(true);
2580 TilesManager::instance()->setInvertedScreen(false);
2583 else if (key == "inverted_contrast") {
2584 float contrast = value.toFloat();
2585 TilesManager::instance()->setInvertedScreenContrast(contrast);
2588 else if (key == "enable_cpu_upload_path") {
2589 TilesManager::instance()->transferQueue()->setTextureUploadType(
2590 value == "true" ? CpuUpload : GpuUpload);
2593 else if (key == "use_minimal_memory") {
2594 TilesManager::instance()->setUseMinimalMemory(value == "true");
2600 static jstring nativeGetProperty(JNIEnv *env, jobject obj, jstring key)
2605 static void nativeOnTrimMemory(JNIEnv *env, jobject obj, jint level)
2607 if (TilesManager::hardwareAccelerationEnabled()) {
2608 bool freeAllTextures = (level > TRIM_MEMORY_UI_HIDDEN);
2609 TilesManager::instance()->deallocateTextures(freeAllTextures);
2613 static void nativeDumpDisplayTree(JNIEnv* env, jobject jwebview, jstring jurl)
2615 #ifdef ANDROID_DUMP_DISPLAY_TREE
2616 WebView* view = GET_NATIVE_VIEW(env, jwebview);
2617 LOG_ASSERT(view, "view not set in %s", __FUNCTION__);
2619 if (view && view->getWebViewCore()) {
2620 FILE* file = fopen(DISPLAY_TREE_LOG_FILE, "w");
2622 SkFormatDumper dumper(dumpToFile, file);
2625 const char* str = env->GetStringUTFChars(jurl, 0);
2626 SkDebugf("Dumping %s to %s\n", str, DISPLAY_TREE_LOG_FILE);
2627 dumpToFile(str, file);
2628 env->ReleaseStringUTFChars(jurl, str);
2630 // now dump the display tree
2631 SkDumpCanvas canvas(&dumper);
2632 // this will playback the picture into the canvas, which will
2633 // spew its contents to the dumper
2634 view->draw(&canvas, 0, 0, false);
2635 // we're done with the file now
2636 fwrite("\n", 1, 1, file);
2639 #if USE(ACCELERATED_COMPOSITING)
2640 const LayerAndroid* rootLayer = view->compositeRoot();
2642 FILE* file = fopen(LAYERS_TREE_LOG_FILE,"w");
2644 rootLayer->dumpLayers(file, 0);
2653 static int nativeScrollableLayer(JNIEnv* env, jobject jwebview, jint x, jint y,
2654 jobject rect, jobject bounds)
2656 WebView* view = GET_NATIVE_VIEW(env, jwebview);
2657 LOG_ASSERT(view, "view not set in %s", __FUNCTION__);
2658 SkIRect nativeRect, nativeBounds;
2659 int id = view->scrollableLayer(x, y, &nativeRect, &nativeBounds);
2661 GraphicsJNI::irect_to_jrect(nativeRect, env, rect);
2663 GraphicsJNI::irect_to_jrect(nativeBounds, env, bounds);
2667 static bool nativeScrollLayer(JNIEnv* env, jobject obj, jint layerId, jint x,
2670 #if ENABLE(ANDROID_OVERFLOW_SCROLL)
2671 WebView* view = GET_NATIVE_VIEW(env, obj);
2672 LayerAndroid* root = view->compositeRoot();
2675 LayerAndroid* layer = root->findById(layerId);
2676 if (!layer || !layer->contentIsScrollable())
2678 return static_cast<ScrollableLayerAndroid*>(layer)->scrollTo(x, y);
2683 static void nativeSetIsScrolling(JNIEnv* env, jobject jwebview, jboolean isScrolling)
2685 WebView* view = GET_NATIVE_VIEW(env, jwebview);
2686 LOG_ASSERT(view, "view not set in %s", __FUNCTION__);
2687 view->setIsScrolling(isScrolling);
2690 static void nativeUseHardwareAccelSkia(JNIEnv*, jobject, jboolean enabled)
2692 BaseRenderer::setCurrentRendererType(enabled ? BaseRenderer::Ganesh : BaseRenderer::Raster);
2695 static int nativeGetBackgroundColor(JNIEnv* env, jobject obj)
2697 WebView* view = GET_NATIVE_VIEW(env, obj);
2698 BaseLayerAndroid* baseLayer = view->getBaseLayer();
2700 WebCore::Color color = baseLayer->getBackgroundColor();
2701 if (color.isValid())
2702 return SkColorSetARGB(color.alpha(), color.red(),
2703 color.green(), color.blue());
2705 return SK_ColorWHITE;
2708 static void nativeSetPauseDrawing(JNIEnv *env, jobject obj, jint nativeView,
2711 ((WebView*)nativeView)->m_isDrawingPaused = pause;
2717 static JNINativeMethod gJavaWebViewMethods[] = {
2718 { "nativeCacheHitFramePointer", "()I",
2719 (void*) nativeCacheHitFramePointer },
2720 { "nativeCacheHitIsPlugin", "()Z",
2721 (void*) nativeCacheHitIsPlugin },
2722 { "nativeCacheHitNodeBounds", "()Landroid/graphics/Rect;",
2723 (void*) nativeCacheHitNodeBounds },
2724 { "nativeCacheHitNodePointer", "()I",
2725 (void*) nativeCacheHitNodePointer },
2726 { "nativeClearCursor", "()V",
2727 (void*) nativeClearCursor },
2728 { "nativeCreate", "(ILjava/lang/String;)V",
2729 (void*) nativeCreate },
2730 { "nativeCursorFramePointer", "()I",
2731 (void*) nativeCursorFramePointer },
2732 { "nativePageShouldHandleShiftAndArrows", "()Z",
2733 (void*) nativePageShouldHandleShiftAndArrows },
2734 { "nativeCursorNodeBounds", "()Landroid/graphics/Rect;",
2735 (void*) nativeCursorNodeBounds },
2736 { "nativeCursorNodePointer", "()I",
2737 (void*) nativeCursorNodePointer },
2738 { "nativeCursorIntersects", "(Landroid/graphics/Rect;)Z",
2739 (void*) nativeCursorIntersects },
2740 { "nativeCursorIsAnchor", "()Z",
2741 (void*) nativeCursorIsAnchor },
2742 { "nativeCursorIsTextInput", "()Z",
2743 (void*) nativeCursorIsTextInput },
2744 { "nativeCursorPosition", "()Landroid/graphics/Point;",
2745 (void*) nativeCursorPosition },
2746 { "nativeCursorText", "()Ljava/lang/String;",
2747 (void*) nativeCursorText },
2748 { "nativeCursorWantsKeyEvents", "()Z",
2749 (void*)nativeCursorWantsKeyEvents },
2750 { "nativeDebugDump", "()V",
2751 (void*) nativeDebugDump },
2752 { "nativeDestroy", "()V",
2753 (void*) nativeDestroy },
2754 { "nativeDraw", "(Landroid/graphics/Canvas;IIZ)I",
2755 (void*) nativeDraw },
2756 { "nativeGetDrawGLFunction", "(ILandroid/graphics/Rect;Landroid/graphics/Rect;FI)I",
2757 (void*) nativeGetDrawGLFunction },
2758 { "nativeUpdateDrawGLFunction", "(Landroid/graphics/Rect;Landroid/graphics/Rect;)V",
2759 (void*) nativeUpdateDrawGLFunction },
2760 { "nativeDumpDisplayTree", "(Ljava/lang/String;)V",
2761 (void*) nativeDumpDisplayTree },
2762 { "nativeEvaluateLayersAnimations", "(I)Z",
2763 (void*) nativeEvaluateLayersAnimations },
2764 { "nativeExtendSelection", "(II)V",
2765 (void*) nativeExtendSelection },
2766 { "nativeFindAll", "(Ljava/lang/String;Ljava/lang/String;Z)I",
2767 (void*) nativeFindAll },
2768 { "nativeFindNext", "(Z)V",
2769 (void*) nativeFindNext },
2770 { "nativeFindIndex", "()I",
2771 (void*) nativeFindIndex},
2772 { "nativeFocusCandidateFramePointer", "()I",
2773 (void*) nativeFocusCandidateFramePointer },
2774 { "nativeFocusCandidateHasNextTextfield", "()Z",
2775 (void*) focusCandidateHasNextTextfield },
2776 { "nativeFocusCandidateIsPassword", "()Z",
2777 (void*) nativeFocusCandidateIsPassword },
2778 { "nativeFocusCandidateIsRtlText", "()Z",
2779 (void*) nativeFocusCandidateIsRtlText },
2780 { "nativeFocusCandidateIsTextInput", "()Z",
2781 (void*) nativeFocusCandidateIsTextInput },
2782 { "nativeFocusCandidateLineHeight", "()I",
2783 (void*) nativeFocusCandidateLineHeight },
2784 { "nativeFocusCandidateMaxLength", "()I",
2785 (void*) nativeFocusCandidateMaxLength },
2786 { "nativeFocusCandidateIsAutoComplete", "()Z",
2787 (void*) nativeFocusCandidateIsAutoComplete },
2788 { "nativeFocusCandidateIsSpellcheck", "()Z",
2789 (void*) nativeFocusCandidateIsSpellcheck },
2790 { "nativeFocusCandidateName", "()Ljava/lang/String;",
2791 (void*) nativeFocusCandidateName },
2792 { "nativeFocusCandidateNodeBounds", "()Landroid/graphics/Rect;",
2793 (void*) nativeFocusCandidateNodeBounds },
2794 { "nativeFocusCandidatePaddingRect", "()Landroid/graphics/Rect;",
2795 (void*) nativeFocusCandidatePaddingRect },
2796 { "nativeFocusCandidatePointer", "()I",
2797 (void*) nativeFocusCandidatePointer },
2798 { "nativeFocusCandidateText", "()Ljava/lang/String;",
2799 (void*) nativeFocusCandidateText },
2800 { "nativeFocusCandidateTextSize", "()F",
2801 (void*) nativeFocusCandidateTextSize },
2802 { "nativeFocusCandidateType", "()I",
2803 (void*) nativeFocusCandidateType },
2804 { "nativeFocusIsPlugin", "()Z",
2805 (void*) nativeFocusIsPlugin },
2806 { "nativeFocusNodeBounds", "()Landroid/graphics/Rect;",
2807 (void*) nativeFocusNodeBounds },
2808 { "nativeFocusNodePointer", "()I",
2809 (void*) nativeFocusNodePointer },
2810 { "nativeGetCursorRingBounds", "()Landroid/graphics/Rect;",
2811 (void*) nativeGetCursorRingBounds },
2812 { "nativeGetSelection", "()Ljava/lang/String;",
2813 (void*) nativeGetSelection },
2814 { "nativeHasCursorNode", "()Z",
2815 (void*) nativeHasCursorNode },
2816 { "nativeHasFocusNode", "()Z",
2817 (void*) nativeHasFocusNode },
2818 { "nativeHideCursor", "()V",
2819 (void*) nativeHideCursor },
2820 { "nativeHitSelection", "(II)Z",
2821 (void*) nativeHitSelection },
2822 { "nativeImageURI", "(II)Ljava/lang/String;",
2823 (void*) nativeImageURI },
2824 { "nativeInstrumentReport", "()V",
2825 (void*) nativeInstrumentReport },
2826 { "nativeLayerBounds", "(I)Landroid/graphics/Rect;",
2827 (void*) nativeLayerBounds },
2828 { "nativeMotionUp", "(III)Z",
2829 (void*) nativeMotionUp },
2830 { "nativeMoveCursor", "(IIZ)Z",
2831 (void*) nativeMoveCursor },
2832 { "nativeMoveCursorToNextTextInput", "()Z",
2833 (void*) nativeMoveCursorToNextTextInput },
2834 { "nativeMoveGeneration", "()I",
2835 (void*) nativeMoveGeneration },
2836 { "nativeMoveSelection", "(II)V",
2837 (void*) nativeMoveSelection },
2838 { "nativePointInNavCache", "(III)Z",
2839 (void*) nativePointInNavCache },
2840 { "nativeResetSelection", "()V",
2841 (void*) nativeResetSelection },
2842 { "nativeSelectableText", "()Landroid/graphics/Point;",
2843 (void*) nativeSelectableText },
2844 { "nativeSelectAll", "()V",
2845 (void*) nativeSelectAll },
2846 { "nativeSelectBestAt", "(Landroid/graphics/Rect;)V",
2847 (void*) nativeSelectBestAt },
2848 { "nativeSelectAt", "(II)V",
2849 (void*) nativeSelectAt },
2850 { "nativeSelectionX", "()I",
2851 (void*) nativeSelectionX },
2852 { "nativeSelectionY", "()I",
2853 (void*) nativeSelectionY },
2854 { "nativeSetExtendSelection", "()V",
2855 (void*) nativeSetExtendSelection },
2856 { "nativeSetFindIsEmpty", "()V",
2857 (void*) nativeSetFindIsEmpty },
2858 { "nativeSetFindIsUp", "(Z)V",
2859 (void*) nativeSetFindIsUp },
2860 { "nativeSetHeightCanMeasure", "(Z)V",
2861 (void*) nativeSetHeightCanMeasure },
2862 { "nativeSetBaseLayer", "(ILandroid/graphics/Region;ZZZ)V",
2863 (void*) nativeSetBaseLayer },
2864 { "nativeGetTextSelectionRegion", "(ILandroid/graphics/Region;)V",
2865 (void*) nativeGetTextSelectionRegion },
2866 { "nativeGetSelectionHandles", "(I[I)V",
2867 (void*) nativeGetSelectionHandles },
2868 { "nativeGetBaseLayer", "()I",
2869 (void*) nativeGetBaseLayer },
2870 { "nativeReplaceBaseContent", "(I)V",
2871 (void*) nativeReplaceBaseContent },
2872 { "nativeCopyBaseContentToPicture", "(Landroid/graphics/Picture;)V",
2873 (void*) nativeCopyBaseContentToPicture },
2874 { "nativeHasContent", "()Z",
2875 (void*) nativeHasContent },
2876 { "nativeSetSelectionPointer", "(IZFII)V",
2877 (void*) nativeSetSelectionPointer },
2878 { "nativeShowCursorTimed", "()V",
2879 (void*) nativeShowCursorTimed },
2880 { "nativeRegisterPageSwapCallback", "()V",
2881 (void*) nativeRegisterPageSwapCallback },
2882 { "nativeTileProfilingStart", "()V",
2883 (void*) nativeTileProfilingStart },
2884 { "nativeTileProfilingStop", "()F",
2885 (void*) nativeTileProfilingStop },
2886 { "nativeTileProfilingClear", "()V",
2887 (void*) nativeTileProfilingClear },
2888 { "nativeTileProfilingNumFrames", "()I",
2889 (void*) nativeTileProfilingNumFrames },
2890 { "nativeTileProfilingNumTilesInFrame", "(I)I",
2891 (void*) nativeTileProfilingNumTilesInFrame },
2892 { "nativeTileProfilingGetInt", "(IILjava/lang/String;)I",
2893 (void*) nativeTileProfilingGetInt },
2894 { "nativeTileProfilingGetFloat", "(IILjava/lang/String;)F",
2895 (void*) nativeTileProfilingGetFloat },
2896 { "nativeStartSelection", "(II)Z",
2897 (void*) nativeStartSelection },
2898 { "nativeStopGL", "()V",
2899 (void*) nativeStopGL },
2900 { "nativeSubtractLayers", "(Landroid/graphics/Rect;)Landroid/graphics/Rect;",
2901 (void*) nativeSubtractLayers },
2902 { "nativeTextGeneration", "()I",
2903 (void*) nativeTextGeneration },
2904 { "nativeUpdateCachedTextfield", "(Ljava/lang/String;I)V",
2905 (void*) nativeUpdateCachedTextfield },
2906 { "nativeWordSelection", "(II)Z",
2907 (void*) nativeWordSelection },
2908 { "nativeGetBlockLeftEdge", "(IIF)I",
2909 (void*) nativeGetBlockLeftEdge },
2910 { "nativeScrollableLayer", "(IILandroid/graphics/Rect;Landroid/graphics/Rect;)I",
2911 (void*) nativeScrollableLayer },
2912 { "nativeScrollLayer", "(III)Z",
2913 (void*) nativeScrollLayer },
2914 { "nativeSetIsScrolling", "(Z)V",
2915 (void*) nativeSetIsScrolling },
2916 { "nativeUseHardwareAccelSkia", "(Z)V",
2917 (void*) nativeUseHardwareAccelSkia },
2918 { "nativeGetBackgroundColor", "()I",
2919 (void*) nativeGetBackgroundColor },
2920 { "nativeSetProperty", "(Ljava/lang/String;Ljava/lang/String;)Z",
2921 (void*) nativeSetProperty },
2922 { "nativeGetProperty", "(Ljava/lang/String;)Ljava/lang/String;",
2923 (void*) nativeGetProperty },
2924 { "nativeOnTrimMemory", "(I)V",
2925 (void*) nativeOnTrimMemory },
2926 { "nativeSetPauseDrawing", "(IZ)V",
2927 (void*) nativeSetPauseDrawing },
2930 int registerWebView(JNIEnv* env)
2932 jclass clazz = env->FindClass("android/webkit/WebView");
2933 LOG_ASSERT(clazz, "Unable to find class android/webkit/WebView");
2934 gWebViewField = env->GetFieldID(clazz, "mNativeClass", "I");
2935 LOG_ASSERT(gWebViewField, "Unable to find android/webkit/WebView.mNativeClass");
2936 env->DeleteLocalRef(clazz);
2938 return jniRegisterNativeMethods(env, "android/webkit/WebView", gJavaWebViewMethods, NELEM(gJavaWebViewMethods));
2941 } // namespace android