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)
423 SkRect visible = SkRect::MakeEmpty();
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);
576 calcOurContentVisibleRect(&visibleRect);
577 // Make sure we have valid coordinates. We might not have valid coords
578 // if the zoom manager is still initializing. We will be redrawn
579 // once the correct scale is set
580 if (!visibleRect.hasValidCoordinates())
582 bool pagesSwapped = false;
583 bool ret = m_glWebViewState->drawGL(viewRect, visibleRect, invalRect,
584 webViewRect, titleBarHeight, clip, scale,
586 if (m_pageSwapCallbackRegistered && pagesSwapped) {
587 m_pageSwapCallbackRegistered = false;
588 LOG_ASSERT(m_javaGlue.m_obj, "A java object was not associated with this native WebView!");
589 JNIEnv* env = JSC::Bindings::getJNIEnv();
590 AutoJObject javaObject = m_javaGlue.object(env);
591 if (javaObject.get()) {
592 env->CallVoidMethod(javaObject.get(), m_javaGlue.m_pageSwapCallback);
596 if (ret || m_glWebViewState->currentPictureCounter() != pic)
602 PictureSet* draw(SkCanvas* canvas, SkColor bgColor, int extras, bool split)
606 canvas->drawColor(bgColor);
610 // draw the content of the base layer first
611 PictureSet* content = m_baseLayer->content();
612 int sc = canvas->save(SkCanvas::kClip_SaveFlag);
613 canvas->clipRect(SkRect::MakeLTRB(0, 0, content->width(),
614 content->height()), SkRegion::kDifference_Op);
615 canvas->drawColor(bgColor);
616 canvas->restoreToCount(sc);
617 if (content->draw(canvas))
618 ret = split ? new PictureSet(*content) : 0;
620 CachedRoot* root = getFrameCache(AllowNewer);
622 DBG_NAV_LOG("!root");
623 if (extras == DrawExtrasCursorRing)
626 LayerAndroid mainPicture(m_navPictureUI);
627 DrawExtra* extra = 0;
630 extra = &m_findOnPage;
632 case DrawExtrasSelection:
633 // This will involve a JNI call, but under normal circumstances we will
634 // not hit this anyway. Only if USE_JAVA_TEXT_SELECTION is disabled
635 // in WebView.java will we hit this (so really debug only)
636 updateSelectionHandles();
637 extra = &m_selectText;
639 case DrawExtrasCursorRing:
640 if (drawCursorPreamble(root) && m_ring.setup()) {
641 if (!m_ring.m_isButton)
643 drawCursorPostamble();
649 #if USE(ACCELERATED_COMPOSITING)
650 LayerAndroid* compositeLayer = compositeRoot();
651 if (compositeLayer) {
653 calcOurContentVisibleRect(&visible);
654 // call this to be sure we've adjusted for any scrolling or animations
655 // before we actually draw
656 compositeLayer->updateFixedLayersPositions(visible);
657 compositeLayer->updatePositions();
658 // We have to set the canvas' matrix on the base layer
659 // (to have fixed layers work as intended)
660 SkAutoCanvasRestore restore(canvas, true);
661 m_baseLayer->setMatrix(canvas->getTotalMatrix());
662 canvas->resetMatrix();
663 m_baseLayer->draw(canvas);
667 IntRect dummy; // inval area, unused for now
668 extra->draw(canvas, &mainPicture, &dummy);
674 bool cursorIsTextInput(FrameCachePermission allowNewer)
676 CachedRoot* root = getFrameCache(allowNewer);
678 DBG_NAV_LOG("!root");
681 const CachedNode* cursor = root->currentCursor();
683 DBG_NAV_LOG("!cursor");
686 DBG_NAV_LOGD("%s", cursor->isTextInput() ? "true" : "false");
687 return cursor->isTextInput();
690 void cursorRingBounds(WebCore::IntRect* bounds)
692 DBG_NAV_LOGD("%s", "");
693 CachedRoot* root = getFrameCache(DontAllowNewer);
695 const CachedFrame* cachedFrame;
696 const CachedNode* cachedNode = root->currentCursor(&cachedFrame);
698 *bounds = cachedNode->cursorRingBounds(cachedFrame);
699 DBG_NAV_LOGD("bounds={%d,%d,%d,%d}", bounds->x(), bounds->y(),
700 bounds->width(), bounds->height());
704 *bounds = WebCore::IntRect(0, 0, 0, 0);
709 m_viewImpl->gCursorBoundsMutex.lock();
710 bool hasCursorBounds = m_viewImpl->m_hasCursorBounds;
711 IntRect bounds = m_viewImpl->m_cursorBounds;
712 m_viewImpl->gCursorBoundsMutex.unlock();
713 if (!hasCursorBounds)
716 const CachedFrame* frame;
717 const CachedNode* node = m_frameCacheUI->findAt(bounds, &frame, &x, &y, true);
720 // require that node have approximately the same bounds (+/- 4) and the same
722 IntPoint oldCenter = IntPoint(bounds.x() + (bounds.width() >> 1),
723 bounds.y() + (bounds.height() >> 1));
724 IntRect newBounds = node->bounds(frame);
725 IntPoint newCenter = IntPoint(newBounds.x() + (newBounds.width() >> 1),
726 newBounds.y() + (newBounds.height() >> 1));
727 DBG_NAV_LOGD("oldCenter=(%d,%d) newCenter=(%d,%d)"
728 " bounds=(%d,%d,w=%d,h=%d) newBounds=(%d,%d,w=%d,h=%d)",
729 oldCenter.x(), oldCenter.y(), newCenter.x(), newCenter.y(),
730 bounds.x(), bounds.y(), bounds.width(), bounds.height(),
731 newBounds.x(), newBounds.y(), newBounds.width(), newBounds.height());
732 if (abs(oldCenter.x() - newCenter.x()) > 2)
734 if (abs(oldCenter.y() - newCenter.y()) > 2)
736 if (abs(bounds.x() - newBounds.x()) > 4)
738 if (abs(bounds.y() - newBounds.y()) > 4)
740 if (abs(bounds.maxX() - newBounds.maxX()) > 4)
742 if (abs(bounds.maxY() - newBounds.maxY()) > 4)
744 DBG_NAV_LOGD("node=%p frame=%p x=%d y=%d bounds=(%d,%d,w=%d,h=%d)",
745 node, frame, x, y, bounds.x(), bounds.y(), bounds.width(),
747 m_frameCacheUI->setCursor(const_cast<CachedFrame*>(frame),
748 const_cast<CachedNode*>(node));
751 CachedRoot* getFrameCache(FrameCachePermission allowNewer)
753 if (!m_viewImpl->m_updatedFrameCache) {
754 DBG_NAV_LOGV("%s", "!m_viewImpl->m_updatedFrameCache");
755 return m_frameCacheUI;
757 if (allowNewer == DontAllowNewer && m_viewImpl->m_lastGeneration < m_generation) {
758 DBG_NAV_LOGD("allowNewer==DontAllowNewer m_viewImpl->m_lastGeneration=%d"
759 " < m_generation=%d", m_viewImpl->m_lastGeneration, m_generation);
760 return m_frameCacheUI;
762 DBG_NAV_LOGD("%s", "m_viewImpl->m_updatedFrameCache == true");
763 const CachedFrame* oldCursorFrame;
764 const CachedNode* oldCursorNode = m_frameCacheUI ?
765 m_frameCacheUI->currentCursor(&oldCursorFrame) : 0;
766 #if USE(ACCELERATED_COMPOSITING)
768 if (oldCursorNode && oldCursorNode->isInLayer()) {
769 const LayerAndroid* cursorLayer = oldCursorFrame->layer(oldCursorNode)
770 ->layer(m_frameCacheUI->rootLayer());
772 layerId = cursorLayer->uniqueId();
775 // get id from old layer and use to find new layer
776 bool oldFocusIsTextInput = false;
777 void* oldFocusNodePointer = 0;
778 if (m_frameCacheUI) {
779 const CachedNode* oldFocus = m_frameCacheUI->currentFocus();
781 oldFocusIsTextInput = oldFocus->isTextInput();
782 oldFocusNodePointer = oldFocus->nodePointer();
785 m_viewImpl->gFrameCacheMutex.lock();
786 delete m_frameCacheUI;
787 SkSafeUnref(m_navPictureUI);
788 m_viewImpl->m_updatedFrameCache = false;
789 m_frameCacheUI = m_viewImpl->m_frameCacheKit;
790 m_navPictureUI = m_viewImpl->m_navPictureKit;
791 m_viewImpl->m_frameCacheKit = 0;
792 m_viewImpl->m_navPictureKit = 0;
793 m_viewImpl->gFrameCacheMutex.unlock();
795 m_frameCacheUI->setRootLayer(compositeRoot());
796 #if USE(ACCELERATED_COMPOSITING)
799 calcOurContentVisibleRect(&visible);
800 LayerAndroid* layer = const_cast<LayerAndroid*>(
801 m_frameCacheUI->rootLayer());
803 layer->updateFixedLayersPositions(visible);
804 layer->updatePositions();
809 if (oldFocusIsTextInput) {
810 const CachedNode* newFocus = m_frameCacheUI->currentFocus();
811 if (newFocus && oldFocusNodePointer != newFocus->nodePointer()
812 && newFocus->isTextInput()
813 && newFocus != m_frameCacheUI->currentCursor()) {
814 // The focus has changed. We may need to update things.
815 LOG_ASSERT(m_javaGlue.m_obj, "A java object was not associated with this native WebView!");
816 JNIEnv* env = JSC::Bindings::getJNIEnv();
817 AutoJObject javaObject = m_javaGlue.object(env);
818 if (javaObject.get()) {
819 env->CallVoidMethod(javaObject.get(), m_javaGlue.m_domChangedFocus);
824 if (oldCursorNode && (!m_frameCacheUI || !m_frameCacheUI->currentCursor()))
825 viewInvalidate(); // redraw in case cursor ring is still visible
826 return m_frameCacheUI;
829 int getScaledMaxXScroll()
831 LOG_ASSERT(m_javaGlue.m_obj, "A java object was not associated with this native WebView!");
832 JNIEnv* env = JSC::Bindings::getJNIEnv();
833 AutoJObject javaObject = m_javaGlue.object(env);
834 if (!javaObject.get())
836 int result = env->CallIntMethod(javaObject.get(), m_javaGlue.m_getScaledMaxXScroll);
841 int getScaledMaxYScroll()
843 LOG_ASSERT(m_javaGlue.m_obj, "A java object was not associated with this native WebView!");
844 JNIEnv* env = JSC::Bindings::getJNIEnv();
845 AutoJObject javaObject = m_javaGlue.object(env);
846 if (!javaObject.get())
848 int result = env->CallIntMethod(javaObject.get(), m_javaGlue.m_getScaledMaxYScroll);
853 IntRect getVisibleRect()
856 LOG_ASSERT(m_javaGlue.m_obj, "A java object was not associated with this native WebView!");
857 JNIEnv* env = JSC::Bindings::getJNIEnv();
858 AutoJObject javaObject = m_javaGlue.object(env);
859 if (!javaObject.get())
861 jobject jRect = env->CallObjectMethod(javaObject.get(), m_javaGlue.m_getVisibleRect);
863 rect.setX(env->GetIntField(jRect, m_javaGlue.m_rectLeft));
865 rect.setY(env->GetIntField(jRect, m_javaGlue.m_rectTop));
867 rect.setWidth(env->CallIntMethod(jRect, m_javaGlue.m_rectWidth));
869 rect.setHeight(env->CallIntMethod(jRect, m_javaGlue.m_rectHeight));
871 env->DeleteLocalRef(jRect);
876 static CachedFrame::Direction KeyToDirection(int32_t keyCode)
879 case AKEYCODE_DPAD_RIGHT:
880 DBG_NAV_LOGD("keyCode=%s", "right");
881 return CachedFrame::RIGHT;
882 case AKEYCODE_DPAD_LEFT:
883 DBG_NAV_LOGD("keyCode=%s", "left");
884 return CachedFrame::LEFT;
885 case AKEYCODE_DPAD_DOWN:
886 DBG_NAV_LOGD("keyCode=%s", "down");
887 return CachedFrame::DOWN;
888 case AKEYCODE_DPAD_UP:
889 DBG_NAV_LOGD("keyCode=%s", "up");
890 return CachedFrame::UP;
892 DBG_NAV_LOGD("bad key %d sent", keyCode);
893 return CachedFrame::UNINITIALIZED;
897 WTF::String imageURI(int x, int y)
899 const CachedRoot* root = getFrameCache(DontAllowNewer);
900 return root ? root->imageURI(x, y) : WTF::String();
903 bool cursorWantsKeyEvents()
905 const CachedRoot* root = getFrameCache(DontAllowNewer);
907 const CachedNode* focus = root->currentCursor();
909 return focus->wantsKeyEvents();
915 /* returns true if the key had no effect (neither scrolled nor changed cursor) */
916 bool moveCursor(int keyCode, int count, bool ignoreScroll)
918 CachedRoot* root = getFrameCache(AllowNewer);
920 DBG_NAV_LOG("!root");
924 m_viewImpl->m_moveGeneration++;
925 CachedFrame::Direction direction = KeyToDirection(keyCode);
926 const CachedFrame* cachedFrame, * oldFrame = 0;
927 const CachedNode* cursor = root->currentCursor(&oldFrame);
928 WebCore::IntPoint cursorLocation = root->cursorLocation();
929 DBG_NAV_LOGD("old cursor %d (nativeNode=%p) cursorLocation={%d, %d}",
930 cursor ? cursor->index() : 0,
931 cursor ? cursor->nodePointer() : 0, cursorLocation.x(), cursorLocation.y());
932 WebCore::IntRect visibleRect = setVisibleRect(root);
933 int xMax = getScaledMaxXScroll();
934 int yMax = getScaledMaxYScroll();
935 root->setMaxScroll(xMax, yMax);
936 const CachedNode* cachedNode = 0;
940 while (--counter >= 0) {
941 WebCore::IntPoint scroll = WebCore::IntPoint(0, 0);
942 cachedNode = root->moveCursor(direction, &cachedFrame, &scroll);
946 DBG_NAV_LOGD("new cursor %d (nativeNode=%p) cursorLocation={%d, %d}"
947 "bounds={%d,%d,w=%d,h=%d}", cachedNode ? cachedNode->index() : 0,
948 cachedNode ? cachedNode->nodePointer() : 0,
949 root->cursorLocation().x(), root->cursorLocation().y(),
950 cachedNode ? cachedNode->bounds(cachedFrame).x() : 0,
951 cachedNode ? cachedNode->bounds(cachedFrame).y() : 0,
952 cachedNode ? cachedNode->bounds(cachedFrame).width() : 0,
953 cachedNode ? cachedNode->bounds(cachedFrame).height() : 0);
954 // If !m_heightCanMeasure (such as in the browser), we want to scroll no
956 if (!ignoreScroll && (!m_heightCanMeasure ||
958 (cursor && cursor->nodePointer() == cachedNode->nodePointer())))
960 if (count == 1 && dx != 0 && dy == 0 && -m_lastDx == dx &&
961 SkTime::GetMSecs() - m_lastDxTime < 1000)
962 root->checkForJiggle(&dx);
963 DBG_NAV_LOGD("scrollBy %d,%d", dx, dy);
965 this->scrollBy(dx, dy);
967 m_lastDxTime = SkTime::GetMSecs();
972 m_viewImpl->updateCursorBounds(root, cachedFrame, cachedNode);
973 root->setCursor(const_cast<CachedFrame*>(cachedFrame),
974 const_cast<CachedNode*>(cachedNode));
975 const CachedNode* focus = root->currentFocus();
976 bool clearTextEntry = cachedNode != focus && focus
977 && cachedNode->nodePointer() != focus->nodePointer() && focus->isTextInput();
978 // Stop painting the caret if the old focus was a text input and so is the new cursor.
979 bool stopPaintingCaret = clearTextEntry && cachedNode->wantsKeyEvents();
980 sendMoveMouseIfLatest(clearTextEntry, stopPaintingCaret);
982 int docHeight = root->documentHeight();
983 int docWidth = root->documentWidth();
984 if (visibleRect.maxY() + dy > docHeight)
985 dy = docHeight - visibleRect.maxY();
986 else if (visibleRect.y() + dy < 0)
987 dy = -visibleRect.y();
988 if (visibleRect.maxX() + dx > docWidth)
989 dx = docWidth - visibleRect.maxX();
990 else if (visibleRect.x() < 0)
991 dx = -visibleRect.x();
992 result = direction == CachedFrame::LEFT ? dx >= 0 :
993 direction == CachedFrame::RIGHT ? dx <= 0 :
994 direction == CachedFrame::UP ? dy >= 0 : dy <= 0;
999 void notifyProgressFinished()
1001 DBG_NAV_LOGD("cursorIsTextInput=%d", cursorIsTextInput(DontAllowNewer));
1002 rebuildWebTextView();
1004 if (m_frameCacheUI) {
1005 const CachedNode* focus = m_frameCacheUI->currentFocus();
1006 DBG_NAV_LOGD("focus %d (nativeNode=%p)",
1007 focus ? focus->index() : 0,
1008 focus ? focus->nodePointer() : 0);
1013 const CachedNode* findAt(CachedRoot* root, const WebCore::IntRect& rect,
1014 const CachedFrame** framePtr, int* rxPtr, int* ryPtr)
1021 setVisibleRect(root);
1022 return root->findAt(rect, framePtr, rxPtr, ryPtr, true);
1025 IntRect setVisibleRect(CachedRoot* root)
1027 IntRect visibleRect = getVisibleRect();
1028 DBG_NAV_LOGD("getVisibleRect %d,%d,%d,%d",
1029 visibleRect.x(), visibleRect.y(), visibleRect.width(), visibleRect.height());
1030 root->setVisibleRect(visibleRect);
1034 void selectBestAt(const WebCore::IntRect& rect)
1036 const CachedFrame* frame;
1038 CachedRoot* root = getFrameCache(AllowNewer);
1041 const CachedNode* node = findAt(root, rect, &frame, &rx, &ry);
1043 DBG_NAV_LOGD("no nodes found root=%p", root);
1044 root->rootHistory()->setMouseBounds(rect);
1045 m_viewImpl->m_hasCursorBounds = false;
1046 root->setCursor(0, 0);
1049 DBG_NAV_LOGD("CachedNode:%p (%d)", node, node->index());
1050 WebCore::IntRect bounds = node->bounds(frame);
1051 root->rootHistory()->setMouseBounds(bounds);
1052 m_viewImpl->updateCursorBounds(root, frame, node);
1054 root->setCursor(const_cast<CachedFrame*>(frame),
1055 const_cast<CachedNode*>(node));
1057 sendMoveMouseIfLatest(false, false);
1060 const CachedNode* m_cacheHitNode;
1061 const CachedFrame* m_cacheHitFrame;
1063 bool pointInNavCache(int x, int y, int slop)
1065 CachedRoot* root = getFrameCache(AllowNewer);
1068 IntRect rect = IntRect(x - slop, y - slop, slop * 2, slop * 2);
1070 return (m_cacheHitNode = findAt(root, rect, &m_cacheHitFrame, &rx, &ry));
1073 bool motionUp(int x, int y, int slop)
1075 bool pageScrolled = false;
1076 IntRect rect = IntRect(x - slop, y - slop, slop * 2, slop * 2);
1078 CachedRoot* root = getFrameCache(AllowNewer);
1081 const CachedFrame* frame = 0;
1082 const CachedNode* result = findAt(root, rect, &frame, &rx, &ry);
1083 CachedHistory* history = root->rootHistory();
1085 DBG_NAV_LOGD("no nodes found root=%p", root);
1086 history->setNavBounds(rect);
1087 m_viewImpl->m_hasCursorBounds = false;
1089 int dx = root->checkForCenter(x, y);
1092 pageScrolled = true;
1094 sendMotionUp(frame ? (WebCore::Frame*) frame->framePointer() : 0,
1097 return pageScrolled;
1099 DBG_NAV_LOGD("CachedNode:%p (%d) x=%d y=%d rx=%d ry=%d", result,
1100 result->index(), x, y, rx, ry);
1101 WebCore::IntRect navBounds = WebCore::IntRect(rx, ry, 1, 1);
1102 history->setNavBounds(navBounds);
1103 history->setMouseBounds(navBounds);
1104 m_viewImpl->updateCursorBounds(root, frame, result);
1105 root->setCursor(const_cast<CachedFrame*>(frame),
1106 const_cast<CachedNode*>(result));
1107 if (result->isSyntheticLink())
1108 overrideUrlLoading(result->getExport());
1111 (WebCore::Frame*) frame->framePointer(),
1112 (WebCore::Node*) result->nodePointer(), rx, ry);
1114 if (result->isTextInput() || result->isSelect()
1115 || result->isContentEditable()) {
1116 showCursorUntimed();
1119 return pageScrolled;
1122 #if USE(ACCELERATED_COMPOSITING)
1123 static const ScrollableLayerAndroid* findScrollableLayer(
1124 const LayerAndroid* parent, int x, int y, SkIRect* foundBounds) {
1126 parent->bounds(&bounds);
1127 // Check the parent bounds first; this will clip to within a masking layer's
1129 if (parent->masksToBounds() && !bounds.contains(x, y))
1131 // Move the hit test local to parent.
1134 int count = parent->countChildren();
1136 const LayerAndroid* child = parent->getChild(count);
1137 const ScrollableLayerAndroid* result = findScrollableLayer(child, x, y,
1140 foundBounds->offset(bounds.fLeft, bounds.fTop);
1141 if (parent->masksToBounds()) {
1142 if (bounds.width() < foundBounds->width())
1143 foundBounds->fRight = foundBounds->fLeft + bounds.width();
1144 if (bounds.height() < foundBounds->height())
1145 foundBounds->fBottom = foundBounds->fTop + bounds.height();
1150 if (parent->contentIsScrollable()) {
1151 foundBounds->set(0, 0, bounds.width(), bounds.height());
1152 return static_cast<const ScrollableLayerAndroid*>(parent);
1158 int scrollableLayer(int x, int y, SkIRect* layerRect, SkIRect* bounds)
1160 #if USE(ACCELERATED_COMPOSITING)
1161 const LayerAndroid* layerRoot = compositeRoot();
1164 const ScrollableLayerAndroid* result = findScrollableLayer(layerRoot, x, y,
1167 result->getScrollRect(layerRect);
1168 return result->uniqueId();
1174 int getBlockLeftEdge(int x, int y, float scale)
1176 CachedRoot* root = getFrameCache(AllowNewer);
1178 return root->getBlockLeftEdge(x, y, scale);
1182 void overrideUrlLoading(const WTF::String& url)
1184 JNIEnv* env = JSC::Bindings::getJNIEnv();
1185 AutoJObject javaObject = m_javaGlue.object(env);
1186 if (!javaObject.get())
1188 jstring jName = wtfStringToJstring(env, url);
1189 env->CallVoidMethod(javaObject.get(), m_javaGlue.m_overrideLoading, jName);
1190 env->DeleteLocalRef(jName);
1193 void setFindIsUp(bool up)
1195 DBG_NAV_LOGD("up=%d", up);
1196 m_viewImpl->m_findIsUp = up;
1199 void setFindIsEmpty()
1202 m_findOnPage.clearCurrentLocation();
1205 void showCursorTimed()
1208 m_ringAnimationEnd = SkTime::GetMSecs() + PRESSED_STATE_DURATION;
1212 void showCursorUntimed()
1215 m_ring.m_isPressed = false;
1216 m_ringAnimationEnd = UINT_MAX;
1220 void setHeightCanMeasure(bool measure)
1222 m_heightCanMeasure = measure;
1225 String getSelection()
1227 return m_selectText.getSelection();
1230 void moveSelection(int x, int y)
1232 m_selectText.moveSelection(getVisibleRect(), x, y);
1235 IntPoint selectableText()
1237 const CachedRoot* root = getFrameCache(DontAllowNewer);
1239 return IntPoint(0, 0);
1240 return m_selectText.selectableText(root);
1245 m_selectText.selectAll();
1250 return m_selectText.selectionX();
1255 return m_selectText.selectionY();
1258 void resetSelection()
1260 m_selectText.reset();
1263 bool startSelection(int x, int y)
1265 const CachedRoot* root = getFrameCache(DontAllowNewer);
1268 updateSelectionHandles();
1269 return m_selectText.startSelection(root, getVisibleRect(), x, y);
1272 bool wordSelection(int x, int y)
1274 const CachedRoot* root = getFrameCache(DontAllowNewer);
1277 updateSelectionHandles();
1278 return m_selectText.wordSelection(root, getVisibleRect(), x, y);
1281 bool extendSelection(int x, int y)
1283 m_selectText.extendSelection(getVisibleRect(), x, y);
1287 bool hitSelection(int x, int y)
1289 updateSelectionHandles();
1290 return m_selectText.hitSelection(x, y);
1293 void setExtendSelection()
1295 m_selectText.setExtendSelection(true);
1298 void setSelectionPointer(bool set, float scale, int x, int y)
1300 m_selectText.setDrawPointer(set);
1303 m_selectText.m_inverseScale = scale;
1304 m_selectText.m_selectX = x;
1305 m_selectText.m_selectY = y;
1308 void sendMoveFocus(WebCore::Frame* framePtr, WebCore::Node* nodePtr)
1310 DBG_NAV_LOGD("framePtr=%p nodePtr=%p", framePtr, nodePtr);
1311 JNIEnv* env = JSC::Bindings::getJNIEnv();
1312 AutoJObject javaObject = m_javaGlue.object(env);
1313 if (!javaObject.get())
1315 env->CallVoidMethod(javaObject.get(), m_javaGlue.m_sendMoveFocus, (jint) framePtr, (jint) nodePtr);
1316 checkException(env);
1319 void sendMoveMouse(WebCore::Frame* framePtr, WebCore::Node* nodePtr, int x, int y)
1321 DBG_NAV_LOGD("framePtr=%p nodePtr=%p x=%d y=%d", framePtr, nodePtr, x, y);
1322 JNIEnv* env = JSC::Bindings::getJNIEnv();
1323 AutoJObject javaObject = m_javaGlue.object(env);
1324 if (!javaObject.get())
1326 env->CallVoidMethod(javaObject.get(), m_javaGlue.m_sendMoveMouse, reinterpret_cast<jint>(framePtr), reinterpret_cast<jint>(nodePtr), x, y);
1327 checkException(env);
1330 void sendMoveMouseIfLatest(bool clearTextEntry, bool stopPaintingCaret)
1332 LOG_ASSERT(m_javaGlue.m_obj, "A java object was not associated with this native WebView!");
1333 JNIEnv* env = JSC::Bindings::getJNIEnv();
1334 AutoJObject javaObject = m_javaGlue.object(env);
1335 if (!javaObject.get())
1337 env->CallVoidMethod(javaObject.get(), m_javaGlue.m_sendMoveMouseIfLatest, clearTextEntry, stopPaintingCaret);
1338 checkException(env);
1341 void sendMotionUp(WebCore::Frame* framePtr, WebCore::Node* nodePtr, int x, int y)
1343 DBG_NAV_LOGD("m_generation=%d framePtr=%p nodePtr=%p x=%d y=%d", m_generation, framePtr, nodePtr, x, y);
1344 LOG_ASSERT(m_javaGlue.m_obj, "A WebView was not associated with this WebViewNative!");
1346 JNIEnv* env = JSC::Bindings::getJNIEnv();
1347 AutoJObject javaObject = m_javaGlue.object(env);
1348 if (!javaObject.get())
1350 m_viewImpl->m_touchGeneration = ++m_generation;
1351 env->CallVoidMethod(javaObject.get(), m_javaGlue.m_sendMotionUp, m_generation, (jint) framePtr, (jint) nodePtr, x, y);
1352 checkException(env);
1355 void findNext(bool forward)
1357 m_findOnPage.findNext(forward);
1358 scrollToCurrentMatch();
1362 // With this call, WebView takes ownership of matches, and is responsible for
1364 void setMatches(WTF::Vector<MatchInfo>* matches, jboolean sameAsLastSearch)
1366 // If this search is the same as the last one, check against the old
1367 // location to determine whether to scroll. If the same word is found
1368 // in the same place, then do not scroll.
1369 IntRect oldLocation;
1370 bool checkAgainstOldLocation = false;
1371 if (sameAsLastSearch && m_findOnPage.isCurrentLocationValid()) {
1372 oldLocation = m_findOnPage.currentMatchBounds();
1373 checkAgainstOldLocation = true;
1376 m_findOnPage.setMatches(matches);
1378 if (!checkAgainstOldLocation || oldLocation != m_findOnPage.currentMatchBounds())
1379 scrollToCurrentMatch();
1383 int currentMatchIndex()
1385 return m_findOnPage.currentMatchIndex();
1388 bool scrollBy(int dx, int dy)
1390 LOG_ASSERT(m_javaGlue.m_obj, "A java object was not associated with this native WebView!");
1392 JNIEnv* env = JSC::Bindings::getJNIEnv();
1393 AutoJObject javaObject = m_javaGlue.object(env);
1394 if (!javaObject.get())
1396 bool result = env->CallBooleanMethod(javaObject.get(), m_javaGlue.m_scrollBy, dx, dy, true);
1397 checkException(env);
1401 void setIsScrolling(bool isScrolling)
1403 #if USE(ACCELERATED_COMPOSITING)
1404 if (m_glWebViewState)
1405 m_glWebViewState->setIsScrolling(isScrolling);
1409 bool hasCursorNode()
1411 CachedRoot* root = getFrameCache(DontAllowNewer);
1413 DBG_NAV_LOG("!root");
1416 const CachedNode* cursorNode = root->currentCursor();
1417 DBG_NAV_LOGD("cursorNode=%d (nodePointer=%p)",
1418 cursorNode ? cursorNode->index() : -1,
1419 cursorNode ? cursorNode->nodePointer() : 0);
1425 CachedRoot* root = getFrameCache(DontAllowNewer);
1427 DBG_NAV_LOG("!root");
1430 const CachedNode* focusNode = root->currentFocus();
1431 DBG_NAV_LOGD("focusNode=%d (nodePointer=%p)",
1432 focusNode ? focusNode->index() : -1,
1433 focusNode ? focusNode->nodePointer() : 0);
1437 void rebuildWebTextView()
1439 JNIEnv* env = JSC::Bindings::getJNIEnv();
1440 AutoJObject javaObject = m_javaGlue.object(env);
1441 if (!javaObject.get())
1443 env->CallVoidMethod(javaObject.get(), m_javaGlue.m_rebuildWebTextView);
1444 checkException(env);
1447 void viewInvalidate()
1449 JNIEnv* env = JSC::Bindings::getJNIEnv();
1450 AutoJObject javaObject = m_javaGlue.object(env);
1451 if (!javaObject.get())
1453 env->CallVoidMethod(javaObject.get(), m_javaGlue.m_viewInvalidate);
1454 checkException(env);
1457 void viewInvalidateRect(int l, int t, int r, int b)
1459 JNIEnv* env = JSC::Bindings::getJNIEnv();
1460 AutoJObject javaObject = m_javaGlue.object(env);
1461 if (!javaObject.get())
1463 env->CallVoidMethod(javaObject.get(), m_javaGlue.m_viewInvalidateRect, l, r, t, b);
1464 checkException(env);
1467 void postInvalidateDelayed(int64_t delay, const WebCore::IntRect& bounds)
1469 JNIEnv* env = JSC::Bindings::getJNIEnv();
1470 AutoJObject javaObject = m_javaGlue.object(env);
1471 if (!javaObject.get())
1473 env->CallVoidMethod(javaObject.get(), m_javaGlue.m_postInvalidateDelayed,
1474 delay, bounds.x(), bounds.y(), bounds.maxX(), bounds.maxY());
1475 checkException(env);
1478 bool inFullScreenMode()
1480 JNIEnv* env = JSC::Bindings::getJNIEnv();
1481 AutoJObject javaObject = m_javaGlue.object(env);
1482 if (!javaObject.get())
1484 jboolean result = env->CallBooleanMethod(javaObject.get(), m_javaGlue.m_inFullScreenMode);
1485 checkException(env);
1489 int moveGeneration()
1491 return m_viewImpl->m_moveGeneration;
1494 LayerAndroid* compositeRoot() const
1496 LOG_ASSERT(!m_baseLayer || m_baseLayer->countChildren() == 1,
1497 "base layer can't have more than one child %s", __FUNCTION__);
1498 if (m_baseLayer && m_baseLayer->countChildren() == 1)
1499 return static_cast<LayerAndroid*>(m_baseLayer->getChild(0));
1504 #if ENABLE(ANDROID_OVERFLOW_SCROLL)
1505 static void copyScrollPositionRecursive(const LayerAndroid* from,
1510 for (int i = 0; i < from->countChildren(); i++) {
1511 const LayerAndroid* l = from->getChild(i);
1512 if (l->contentIsScrollable()) {
1513 const SkPoint& pos = l->getPosition();
1514 LayerAndroid* match = root->findById(l->uniqueId());
1515 if (match && match->contentIsScrollable())
1516 match->setPosition(pos.fX, pos.fY);
1518 copyScrollPositionRecursive(l, root);
1523 void registerPageSwapCallback()
1525 m_pageSwapCallbackRegistered = true;
1528 void setBaseLayer(BaseLayerAndroid* layer, SkRegion& inval, bool showVisualIndicator,
1529 bool isPictureAfterFirstLayout, bool registerPageSwapCallback)
1531 #if USE(ACCELERATED_COMPOSITING)
1532 if (m_glWebViewState)
1533 m_glWebViewState->setBaseLayer(layer, inval, showVisualIndicator,
1534 isPictureAfterFirstLayout);
1535 m_pageSwapCallbackRegistered |= registerPageSwapCallback;
1538 #if ENABLE(ANDROID_OVERFLOW_SCROLL)
1540 LayerAndroid* newCompositeRoot = static_cast<LayerAndroid*>(layer->getChild(0));
1541 copyScrollPositionRecursive(compositeRoot(), newCompositeRoot);
1544 SkSafeUnref(m_baseLayer);
1545 m_baseLayer = layer;
1546 CachedRoot* root = getFrameCache(DontAllowNewer);
1549 root->resetLayers();
1550 root->setRootLayer(compositeRoot());
1553 void getTextSelectionRegion(SkRegion *region)
1555 m_selectText.getSelectionRegion(getVisibleRect(), region);
1558 void replaceBaseContent(PictureSet* set)
1562 m_baseLayer->setContent(*set);
1566 void copyBaseContentToPicture(SkPicture* picture)
1570 PictureSet* content = m_baseLayer->content();
1571 m_baseLayer->drawCanvas(picture->beginRecording(content->width(), content->height(),
1572 SkPicture::kUsePathBoundsForClip_RecordingFlag));
1573 picture->endRecording();
1579 return !m_baseLayer->content()->isEmpty();
1582 void setFunctor(Functor* functor) {
1583 delete m_glDrawFunctor;
1584 m_glDrawFunctor = functor;
1587 Functor* getFunctor() {
1588 return m_glDrawFunctor;
1591 BaseLayerAndroid* getBaseLayer() {
1595 private: // local state for WebView
1596 // private to getFrameCache(); other functions operate in a different thread
1597 CachedRoot* m_frameCacheUI; // navigation data ready for use
1598 WebViewCore* m_viewImpl;
1599 int m_generation; // associate unique ID with sent kit focus to match with ui
1600 SkPicture* m_navPictureUI;
1601 SkMSec m_ringAnimationEnd;
1602 // Corresponds to the same-named boolean on the java side.
1603 bool m_heightCanMeasure;
1605 SkMSec m_lastDxTime;
1606 SelectText m_selectText;
1607 FindOnPage m_findOnPage;
1609 BaseLayerAndroid* m_baseLayer;
1610 Functor* m_glDrawFunctor;
1611 #if USE(ACCELERATED_COMPOSITING)
1612 GLWebViewState* m_glWebViewState;
1613 bool m_pageSwapCallbackRegistered;
1615 RenderSkinButton* m_buttonSkin;
1616 }; // end of WebView class
1620 * This class holds a function pointer and parameters for calling drawGL into a specific
1621 * viewport. The pointer to the Functor will be put on a framework display list to be called
1622 * when the display list is replayed.
1624 class GLDrawFunctor : Functor {
1626 GLDrawFunctor(WebView* _wvInstance,
1627 bool(WebView::*_funcPtr)(WebCore::IntRect&, WebCore::IntRect*, WebCore::IntRect&, int, WebCore::IntRect&, jfloat, jint),
1628 WebCore::IntRect _viewRect, float _scale, int _extras) {
1629 wvInstance = _wvInstance;
1631 viewRect = _viewRect;
1635 status_t operator()(int messageId, void* data) {
1636 if (viewRect.isEmpty()) {
1637 // NOOP operation if viewport is empty
1641 WebCore::IntRect inval;
1642 int titlebarHeight = webViewRect.height() - viewRect.height();
1644 uirenderer::DrawGlInfo* info = reinterpret_cast<uirenderer::DrawGlInfo*>(data);
1645 WebCore::IntRect localViewRect = viewRect;
1647 localViewRect.move(-1 * localViewRect.x(), -1 * localViewRect.y());
1649 WebCore::IntRect clip(info->clipLeft, info->clipTop,
1650 info->clipRight - info->clipLeft,
1651 info->clipBottom - info->clipTop);
1653 bool retVal = (*wvInstance.*funcPtr)(localViewRect, &inval, webViewRect, titlebarHeight, clip, scale, extras);
1656 if (inval.isEmpty()) {
1657 finalInval = webViewRect;
1660 finalInval.setX(webViewRect.x() + inval.x());
1661 finalInval.setY(webViewRect.y() + titlebarHeight + inval.y());
1662 finalInval.setWidth(inval.width());
1663 finalInval.setHeight(inval.height());
1665 info->dirtyLeft = finalInval.x();
1666 info->dirtyTop = finalInval.y();
1667 info->dirtyRight = finalInval.maxX();
1668 info->dirtyBottom = finalInval.maxY();
1670 // return 1 if invalidation needed, 0 otherwise
1671 return retVal ? 1 : 0;
1673 void updateRect(WebCore::IntRect& _viewRect) {
1674 viewRect = _viewRect;
1676 void updateViewRect(WebCore::IntRect& _viewRect) {
1677 webViewRect = _viewRect;
1680 WebView* wvInstance;
1681 bool (WebView::*funcPtr)(WebCore::IntRect&, WebCore::IntRect*, WebCore::IntRect&, int, WebCore::IntRect&, float, int);
1682 WebCore::IntRect viewRect;
1683 WebCore::IntRect webViewRect;
1688 static jobject createJavaRect(JNIEnv* env, int x, int y, int right, int bottom)
1690 jclass rectClass = env->FindClass("android/graphics/Rect");
1691 jmethodID init = env->GetMethodID(rectClass, "<init>", "(IIII)V");
1692 jobject rect = env->NewObject(rectClass, init, x, y, right, bottom);
1693 env->DeleteLocalRef(rectClass);
1698 * Native JNI methods
1700 static int nativeCacheHitFramePointer(JNIEnv *env, jobject obj)
1702 return reinterpret_cast<int>(GET_NATIVE_VIEW(env, obj)
1703 ->m_cacheHitFrame->framePointer());
1706 static jobject nativeCacheHitNodeBounds(JNIEnv *env, jobject obj)
1708 WebCore::IntRect bounds = GET_NATIVE_VIEW(env, obj)
1709 ->m_cacheHitNode->originalAbsoluteBounds();
1710 return createJavaRect(env, bounds.x(), bounds.y(),
1711 bounds.maxX(), bounds.maxY());
1714 static int nativeCacheHitNodePointer(JNIEnv *env, jobject obj)
1716 return reinterpret_cast<int>(GET_NATIVE_VIEW(env, obj)
1717 ->m_cacheHitNode->nodePointer());
1720 static bool nativeCacheHitIsPlugin(JNIEnv *env, jobject obj)
1722 return GET_NATIVE_VIEW(env, obj)->m_cacheHitNode->isPlugin();
1725 static void nativeClearCursor(JNIEnv *env, jobject obj)
1727 WebView* view = GET_NATIVE_VIEW(env, obj);
1728 LOG_ASSERT(view, "view not set in %s", __FUNCTION__);
1729 view->clearCursor();
1732 static void nativeCreate(JNIEnv *env, jobject obj, int viewImpl, jstring drawableDir)
1734 WTF::String dir = jstringToWtfString(env, drawableDir);
1735 WebView* webview = new WebView(env, obj, viewImpl, dir);
1736 // NEED THIS OR SOMETHING LIKE IT!
1740 static jint nativeCursorFramePointer(JNIEnv *env, jobject obj)
1742 WebView* view = GET_NATIVE_VIEW(env, obj);
1743 CachedRoot* root = view->getFrameCache(WebView::DontAllowNewer);
1746 const CachedFrame* frame = 0;
1747 (void) root->currentCursor(&frame);
1748 return reinterpret_cast<int>(frame ? frame->framePointer() : 0);
1751 static const CachedNode* getCursorNode(JNIEnv *env, jobject obj)
1753 WebView* view = GET_NATIVE_VIEW(env, obj);
1754 CachedRoot* root = view->getFrameCache(WebView::DontAllowNewer);
1755 return root ? root->currentCursor() : 0;
1758 static const CachedNode* getCursorNode(JNIEnv *env, jobject obj,
1759 const CachedFrame** frame)
1761 WebView* view = GET_NATIVE_VIEW(env, obj);
1762 CachedRoot* root = view->getFrameCache(WebView::DontAllowNewer);
1763 return root ? root->currentCursor(frame) : 0;
1766 static const CachedNode* getFocusCandidate(JNIEnv *env, jobject obj,
1767 const CachedFrame** frame)
1769 WebView* view = GET_NATIVE_VIEW(env, obj);
1770 CachedRoot* root = view->getFrameCache(WebView::DontAllowNewer);
1773 const CachedNode* cursor = root->currentCursor(frame);
1774 if (cursor && cursor->wantsKeyEvents())
1776 return root->currentFocus(frame);
1779 static bool focusCandidateHasNextTextfield(JNIEnv *env, jobject obj)
1781 WebView* view = GET_NATIVE_VIEW(env, obj);
1782 CachedRoot* root = view->getFrameCache(WebView::DontAllowNewer);
1785 const CachedNode* cursor = root->currentCursor();
1786 if (!cursor || !cursor->isTextInput())
1787 cursor = root->currentFocus();
1788 if (!cursor || !cursor->isTextInput()) return false;
1789 return root->nextTextField(cursor, 0);
1792 static const CachedNode* getFocusNode(JNIEnv *env, jobject obj)
1794 WebView* view = GET_NATIVE_VIEW(env, obj);
1795 CachedRoot* root = view->getFrameCache(WebView::DontAllowNewer);
1796 return root ? root->currentFocus() : 0;
1799 static const CachedNode* getFocusNode(JNIEnv *env, jobject obj,
1800 const CachedFrame** frame)
1802 WebView* view = GET_NATIVE_VIEW(env, obj);
1803 CachedRoot* root = view->getFrameCache(WebView::DontAllowNewer);
1804 return root ? root->currentFocus(frame) : 0;
1807 static const CachedInput* getInputCandidate(JNIEnv *env, jobject obj)
1809 WebView* view = GET_NATIVE_VIEW(env, obj);
1810 CachedRoot* root = view->getFrameCache(WebView::DontAllowNewer);
1813 const CachedFrame* frame;
1814 const CachedNode* cursor = root->currentCursor(&frame);
1815 if (!cursor || !cursor->wantsKeyEvents())
1816 cursor = root->currentFocus(&frame);
1817 return cursor ? frame->textInput(cursor) : 0;
1820 static jboolean nativePageShouldHandleShiftAndArrows(JNIEnv *env, jobject obj)
1822 const CachedNode* focus = getFocusNode(env, obj);
1823 if (!focus) return false;
1824 // Plugins handle shift and arrows whether or not they have focus.
1825 if (focus->isPlugin()) return true;
1826 const CachedNode* cursor = getCursorNode(env, obj);
1827 // ContentEditable nodes should only receive shift and arrows if they have
1828 // both the cursor and the focus.
1829 return cursor && cursor->nodePointer() == focus->nodePointer()
1830 && cursor->isContentEditable();
1833 static jobject nativeCursorNodeBounds(JNIEnv *env, jobject obj)
1835 const CachedFrame* frame;
1836 const CachedNode* node = getCursorNode(env, obj, &frame);
1837 WebCore::IntRect bounds = node ? node->bounds(frame)
1838 : WebCore::IntRect(0, 0, 0, 0);
1839 return createJavaRect(env, bounds.x(), bounds.y(),
1840 bounds.maxX(), bounds.maxY());
1843 static jint nativeCursorNodePointer(JNIEnv *env, jobject obj)
1845 const CachedNode* node = getCursorNode(env, obj);
1846 return reinterpret_cast<int>(node ? node->nodePointer() : 0);
1849 static jobject nativeCursorPosition(JNIEnv *env, jobject obj)
1851 WebView* view = GET_NATIVE_VIEW(env, obj);
1852 const CachedRoot* root = view->getFrameCache(WebView::DontAllowNewer);
1853 WebCore::IntPoint pos = WebCore::IntPoint(0, 0);
1855 root->getSimulatedMousePosition(&pos);
1856 jclass pointClass = env->FindClass("android/graphics/Point");
1857 jmethodID init = env->GetMethodID(pointClass, "<init>", "(II)V");
1858 jobject point = env->NewObject(pointClass, init, pos.x(), pos.y());
1859 env->DeleteLocalRef(pointClass);
1863 static WebCore::IntRect jrect_to_webrect(JNIEnv* env, jobject obj)
1866 GraphicsJNI::get_jrect(env, obj, &L, &T, &R, &B);
1867 return WebCore::IntRect(L, T, R - L, B - T);
1870 static bool nativeCursorIntersects(JNIEnv *env, jobject obj, jobject visRect)
1872 const CachedFrame* frame;
1873 const CachedNode* node = getCursorNode(env, obj, &frame);
1874 return node ? node->bounds(frame).intersects(
1875 jrect_to_webrect(env, visRect)) : false;
1878 static bool nativeCursorIsAnchor(JNIEnv *env, jobject obj)
1880 const CachedNode* node = getCursorNode(env, obj);
1881 return node ? node->isAnchor() : false;
1884 static bool nativeCursorIsTextInput(JNIEnv *env, jobject obj)
1886 const CachedNode* node = getCursorNode(env, obj);
1887 return node ? node->isTextInput() : false;
1890 static jobject nativeCursorText(JNIEnv *env, jobject obj)
1892 const CachedNode* node = getCursorNode(env, obj);
1895 WTF::String value = node->getExport();
1896 return wtfStringToJstring(env, value);
1899 static void nativeDebugDump(JNIEnv *env, jobject obj)
1902 WebView* view = GET_NATIVE_VIEW(env, obj);
1903 LOG_ASSERT(view, "view not set in %s", __FUNCTION__);
1908 static jint nativeDraw(JNIEnv *env, jobject obj, jobject canv, jint color,
1909 jint extras, jboolean split) {
1910 SkCanvas* canvas = GraphicsJNI::getNativeCanvas(env, canv);
1911 return reinterpret_cast<jint>(GET_NATIVE_VIEW(env, obj)->draw(canvas, color, extras, split));
1914 static jint nativeGetDrawGLFunction(JNIEnv *env, jobject obj, jint nativeView,
1915 jobject jrect, jobject jviewrect,
1916 jfloat scale, jint extras) {
1917 WebCore::IntRect viewRect;
1918 if (jrect == NULL) {
1919 viewRect = WebCore::IntRect();
1921 viewRect = jrect_to_webrect(env, jrect);
1923 WebView *wvInstance = (WebView*) nativeView;
1924 GLDrawFunctor* functor = new GLDrawFunctor(wvInstance, &android::WebView::drawGL,
1925 viewRect, scale, extras);
1926 wvInstance->setFunctor((Functor*) functor);
1928 WebCore::IntRect webViewRect;
1929 if (jviewrect == NULL) {
1930 webViewRect = WebCore::IntRect();
1932 webViewRect = jrect_to_webrect(env, jviewrect);
1934 functor->updateViewRect(webViewRect);
1936 return (jint)functor;
1939 static void nativeUpdateDrawGLFunction(JNIEnv *env, jobject obj, jobject jrect, jobject jviewrect) {
1940 WebView *wvInstance = GET_NATIVE_VIEW(env, obj);
1941 if (wvInstance != NULL) {
1942 GLDrawFunctor* functor = (GLDrawFunctor*) wvInstance->getFunctor();
1943 if (functor != NULL) {
1944 WebCore::IntRect viewRect;
1945 if (jrect == NULL) {
1946 viewRect = WebCore::IntRect();
1948 viewRect = jrect_to_webrect(env, jrect);
1950 functor->updateRect(viewRect);
1952 WebCore::IntRect webViewRect;
1953 if (jviewrect == NULL) {
1954 webViewRect = WebCore::IntRect();
1956 webViewRect = jrect_to_webrect(env, jviewrect);
1958 functor->updateViewRect(webViewRect);
1963 static bool nativeEvaluateLayersAnimations(JNIEnv *env, jobject obj, jint nativeView)
1965 #if USE(ACCELERATED_COMPOSITING)
1966 LayerAndroid* root = ((WebView*)nativeView)->compositeRoot();
1968 return root->evaluateAnimations();
1973 static void nativeSetBaseLayer(JNIEnv *env, jobject obj, jint layer, jobject inval,
1974 jboolean showVisualIndicator,
1975 jboolean isPictureAfterFirstLayout,
1976 jboolean registerPageSwapCallback)
1978 BaseLayerAndroid* layerImpl = reinterpret_cast<BaseLayerAndroid*>(layer);
1979 SkRegion invalRegion;
1981 invalRegion = *GraphicsJNI::getNativeRegion(env, inval);
1982 GET_NATIVE_VIEW(env, obj)->setBaseLayer(layerImpl, invalRegion, showVisualIndicator,
1983 isPictureAfterFirstLayout,
1984 registerPageSwapCallback);
1987 static void nativeGetTextSelectionRegion(JNIEnv *env, jobject obj, jobject region)
1991 SkRegion* nregion = GraphicsJNI::getNativeRegion(env, region);
1992 GET_NATIVE_VIEW(env, obj)->getTextSelectionRegion(nregion);
1995 static BaseLayerAndroid* nativeGetBaseLayer(JNIEnv *env, jobject obj)
1997 return GET_NATIVE_VIEW(env, obj)->getBaseLayer();
2000 static void nativeReplaceBaseContent(JNIEnv *env, jobject obj, jint content)
2002 PictureSet* set = reinterpret_cast<PictureSet*>(content);
2003 GET_NATIVE_VIEW(env, obj)->replaceBaseContent(set);
2006 static void nativeCopyBaseContentToPicture(JNIEnv *env, jobject obj, jobject pict)
2008 SkPicture* picture = GraphicsJNI::getNativePicture(env, pict);
2009 GET_NATIVE_VIEW(env, obj)->copyBaseContentToPicture(picture);
2012 static bool nativeHasContent(JNIEnv *env, jobject obj)
2014 return GET_NATIVE_VIEW(env, obj)->hasContent();
2017 static jobject nativeImageURI(JNIEnv *env, jobject obj, jint x, jint y)
2019 WebView* view = GET_NATIVE_VIEW(env, obj);
2020 LOG_ASSERT(view, "view not set in %s", __FUNCTION__);
2021 WTF::String uri = view->imageURI(x, y);
2022 return wtfStringToJstring(env, uri);
2025 static jint nativeFocusCandidateFramePointer(JNIEnv *env, jobject obj)
2027 WebView* view = GET_NATIVE_VIEW(env, obj);
2028 CachedRoot* root = view->getFrameCache(WebView::DontAllowNewer);
2031 const CachedFrame* frame = 0;
2032 const CachedNode* cursor = root->currentCursor(&frame);
2033 if (!cursor || !cursor->wantsKeyEvents())
2034 (void) root->currentFocus(&frame);
2035 return reinterpret_cast<int>(frame ? frame->framePointer() : 0);
2038 static bool nativeFocusCandidateIsPassword(JNIEnv *env, jobject obj)
2040 const CachedInput* input = getInputCandidate(env, obj);
2041 return input && input->getType() == CachedInput::PASSWORD;
2044 static bool nativeFocusCandidateIsRtlText(JNIEnv *env, jobject obj)
2046 const CachedInput* input = getInputCandidate(env, obj);
2047 return input ? input->isRtlText() : false;
2050 static bool nativeFocusCandidateIsTextInput(JNIEnv *env, jobject obj)
2052 const CachedNode* node = getFocusCandidate(env, obj, 0);
2053 return node ? node->isTextInput() : false;
2056 static jint nativeFocusCandidateMaxLength(JNIEnv *env, jobject obj)
2058 const CachedInput* input = getInputCandidate(env, obj);
2059 return input ? input->maxLength() : false;
2062 static jint nativeFocusCandidateIsAutoComplete(JNIEnv *env, jobject obj)
2064 const CachedInput* input = getInputCandidate(env, obj);
2065 return input ? input->autoComplete() : false;
2068 static jobject nativeFocusCandidateName(JNIEnv *env, jobject obj)
2070 const CachedInput* input = getInputCandidate(env, obj);
2073 const WTF::String& name = input->name();
2074 return wtfStringToJstring(env, name);
2077 static jobject nativeFocusCandidateNodeBounds(JNIEnv *env, jobject obj)
2079 const CachedFrame* frame;
2080 const CachedNode* node = getFocusCandidate(env, obj, &frame);
2081 WebCore::IntRect bounds = node ? node->bounds(frame)
2082 : WebCore::IntRect(0, 0, 0, 0);
2083 // Inset the rect by 1 unit, so that the focus candidate's border can still
2084 // be seen behind it.
2085 return createJavaRect(env, bounds.x() + 1, bounds.y() + 1,
2086 bounds.maxX() - 1, bounds.maxY() - 1);
2089 static jobject nativeFocusCandidatePaddingRect(JNIEnv *env, jobject obj)
2091 const CachedInput* input = getInputCandidate(env, obj);
2094 // Note that the Java Rect is being used to pass four integers, rather than
2095 // being used as an actual rectangle.
2096 return createJavaRect(env, input->paddingLeft(), input->paddingTop(),
2097 input->paddingRight(), input->paddingBottom());
2100 static jint nativeFocusCandidatePointer(JNIEnv *env, jobject obj)
2102 const CachedNode* node = getFocusCandidate(env, obj, 0);
2103 return reinterpret_cast<int>(node ? node->nodePointer() : 0);
2106 static jint nativeFocusCandidateIsSpellcheck(JNIEnv *env, jobject obj)
2108 const CachedInput* input = getInputCandidate(env, obj);
2109 return input ? input->spellcheck() : false;
2112 static jobject nativeFocusCandidateText(JNIEnv *env, jobject obj)
2114 const CachedNode* node = getFocusCandidate(env, obj, 0);
2117 WTF::String value = node->getExport();
2118 return wtfStringToJstring(env, value);
2121 static int nativeFocusCandidateLineHeight(JNIEnv *env, jobject obj)
2123 const CachedInput* input = getInputCandidate(env, obj);
2124 return input ? input->lineHeight() : 0;
2127 static jfloat nativeFocusCandidateTextSize(JNIEnv *env, jobject obj)
2129 const CachedInput* input = getInputCandidate(env, obj);
2130 return input ? input->textSize() : 0.f;
2133 static int nativeFocusCandidateType(JNIEnv *env, jobject obj)
2135 const CachedInput* input = getInputCandidate(env, obj);
2137 return CachedInput::NONE;
2139 if (input->isTextArea())
2140 return CachedInput::TEXT_AREA;
2142 return input->getType();
2145 static bool nativeFocusIsPlugin(JNIEnv *env, jobject obj)
2147 const CachedNode* node = getFocusNode(env, obj);
2148 return node ? node->isPlugin() : false;
2151 static jobject nativeFocusNodeBounds(JNIEnv *env, jobject obj)
2153 const CachedFrame* frame;
2154 const CachedNode* node = getFocusNode(env, obj, &frame);
2155 WebCore::IntRect bounds = node ? node->bounds(frame)
2156 : WebCore::IntRect(0, 0, 0, 0);
2157 return createJavaRect(env, bounds.x(), bounds.y(),
2158 bounds.maxX(), bounds.maxY());
2161 static jint nativeFocusNodePointer(JNIEnv *env, jobject obj)
2163 const CachedNode* node = getFocusNode(env, obj);
2164 return node ? reinterpret_cast<int>(node->nodePointer()) : 0;
2167 static bool nativeCursorWantsKeyEvents(JNIEnv* env, jobject jwebview) {
2168 WebView* view = GET_NATIVE_VIEW(env, jwebview);
2169 LOG_ASSERT(view, "view not set in %s", __FUNCTION__);
2170 return view->cursorWantsKeyEvents();
2173 static void nativeHideCursor(JNIEnv *env, jobject obj)
2175 WebView* view = GET_NATIVE_VIEW(env, obj);
2176 LOG_ASSERT(view, "view not set in %s", __FUNCTION__);
2180 static void nativeInstrumentReport(JNIEnv *env, jobject obj)
2182 #ifdef ANDROID_INSTRUMENT
2183 TimeCounter::reportNow();
2187 static void nativeSelectBestAt(JNIEnv *env, jobject obj, jobject jrect)
2189 WebView* view = GET_NATIVE_VIEW(env, obj);
2190 LOG_ASSERT(view, "view not set in %s", __FUNCTION__);
2191 WebCore::IntRect rect = jrect_to_webrect(env, jrect);
2192 view->selectBestAt(rect);
2195 static void nativeSelectAt(JNIEnv *env, jobject obj, jint x, jint y)
2197 WebView* view = GET_NATIVE_VIEW(env, obj);
2198 LOG_ASSERT(view, "view not set in %s", __FUNCTION__);
2199 WebCore::IntRect rect = IntRect(x, y , 1, 1);
2200 view->selectBestAt(rect);
2201 if (view->hasCursorNode())
2202 view->showCursorUntimed();
2205 static jobject nativeLayerBounds(JNIEnv* env, jobject obj, jint jlayer)
2208 #if USE(ACCELERATED_COMPOSITING)
2209 LayerAndroid* layer = (LayerAndroid*) jlayer;
2210 r = layer->bounds();
2216 jclass rectClass = env->FindClass("android/graphics/Rect");
2217 jmethodID init = env->GetMethodID(rectClass, "<init>", "(IIII)V");
2218 jobject rect = env->NewObject(rectClass, init, irect.fLeft, irect.fTop,
2219 irect.fRight, irect.fBottom);
2220 env->DeleteLocalRef(rectClass);
2224 static jobject nativeSubtractLayers(JNIEnv* env, jobject obj, jobject jrect)
2226 SkIRect irect = jrect_to_webrect(env, jrect);
2227 #if USE(ACCELERATED_COMPOSITING)
2228 LayerAndroid* root = GET_NATIVE_VIEW(env, obj)->compositeRoot();
2232 rect = root->subtractLayers(rect);
2236 jclass rectClass = env->FindClass("android/graphics/Rect");
2237 jmethodID init = env->GetMethodID(rectClass, "<init>", "(IIII)V");
2238 jobject rect = env->NewObject(rectClass, init, irect.fLeft, irect.fTop,
2239 irect.fRight, irect.fBottom);
2240 env->DeleteLocalRef(rectClass);
2244 static jint nativeTextGeneration(JNIEnv *env, jobject obj)
2246 WebView* view = GET_NATIVE_VIEW(env, obj);
2247 CachedRoot* root = view->getFrameCache(WebView::DontAllowNewer);
2248 return root ? root->textGeneration() : 0;
2251 static bool nativePointInNavCache(JNIEnv *env, jobject obj,
2252 int x, int y, int slop)
2254 return GET_NATIVE_VIEW(env, obj)->pointInNavCache(x, y, slop);
2257 static bool nativeMotionUp(JNIEnv *env, jobject obj,
2258 int x, int y, int slop)
2260 WebView* view = GET_NATIVE_VIEW(env, obj);
2261 LOG_ASSERT(view, "view not set in %s", __FUNCTION__);
2262 return view->motionUp(x, y, slop);
2265 static bool nativeHasCursorNode(JNIEnv *env, jobject obj)
2267 return GET_NATIVE_VIEW(env, obj)->hasCursorNode();
2270 static bool nativeHasFocusNode(JNIEnv *env, jobject obj)
2272 return GET_NATIVE_VIEW(env, obj)->hasFocusNode();
2275 static bool nativeMoveCursor(JNIEnv *env, jobject obj,
2276 int key, int count, bool ignoreScroll)
2278 WebView* view = GET_NATIVE_VIEW(env, obj);
2279 DBG_NAV_LOGD("env=%p obj=%p view=%p", env, obj, view);
2280 LOG_ASSERT(view, "view not set in %s", __FUNCTION__);
2281 return view->moveCursor(key, count, ignoreScroll);
2284 static void nativeRecordButtons(JNIEnv* env, jobject obj, jint nativeView,
2285 bool hasFocus, bool pressed, bool invalidate)
2287 WebView* view = (WebView*) nativeView;
2288 LOG_ASSERT(view, "view not set in %s", __FUNCTION__);
2289 view->nativeRecordButtons(hasFocus, pressed, invalidate);
2292 static void nativeSetFindIsUp(JNIEnv *env, jobject obj, jboolean isUp)
2294 WebView* view = GET_NATIVE_VIEW(env, obj);
2295 LOG_ASSERT(view, "view not set in %s", __FUNCTION__);
2296 view->setFindIsUp(isUp);
2299 static void nativeSetFindIsEmpty(JNIEnv *env, jobject obj)
2301 GET_NATIVE_VIEW(env, obj)->setFindIsEmpty();
2304 static void nativeShowCursorTimed(JNIEnv *env, jobject obj)
2306 GET_NATIVE_VIEW(env, obj)->showCursorTimed();
2309 static void nativeSetHeightCanMeasure(JNIEnv *env, jobject obj, bool measure)
2311 WebView* view = GET_NATIVE_VIEW(env, obj);
2312 LOG_ASSERT(view, "view not set in nativeSetHeightCanMeasure");
2313 view->setHeightCanMeasure(measure);
2316 static jobject nativeGetCursorRingBounds(JNIEnv *env, jobject obj)
2318 WebView* view = GET_NATIVE_VIEW(env, obj);
2319 LOG_ASSERT(view, "view not set in %s", __FUNCTION__);
2320 jclass rectClass = env->FindClass("android/graphics/Rect");
2321 LOG_ASSERT(rectClass, "Could not find Rect class!");
2322 jmethodID init = env->GetMethodID(rectClass, "<init>", "(IIII)V");
2323 LOG_ASSERT(init, "Could not find constructor for Rect");
2324 WebCore::IntRect webRect;
2325 view->cursorRingBounds(&webRect);
2326 jobject rect = env->NewObject(rectClass, init, webRect.x(),
2327 webRect.y(), webRect.maxX(), webRect.maxY());
2328 env->DeleteLocalRef(rectClass);
2332 static int nativeFindAll(JNIEnv *env, jobject obj, jstring findLower,
2333 jstring findUpper, jboolean sameAsLastSearch)
2335 // If one or the other is null, do not search.
2336 if (!(findLower && findUpper))
2338 // Obtain the characters for both the lower case string and the upper case
2339 // string representing the same word.
2340 const jchar* findLowerChars = env->GetStringChars(findLower, 0);
2341 const jchar* findUpperChars = env->GetStringChars(findUpper, 0);
2342 // If one or the other is null, do not search.
2343 if (!(findLowerChars && findUpperChars)) {
2345 env->ReleaseStringChars(findLower, findLowerChars);
2347 env->ReleaseStringChars(findUpper, findUpperChars);
2348 checkException(env);
2351 WebView* view = GET_NATIVE_VIEW(env, obj);
2352 LOG_ASSERT(view, "view not set in nativeFindAll");
2353 CachedRoot* root = view->getFrameCache(WebView::AllowNewer);
2355 env->ReleaseStringChars(findLower, findLowerChars);
2356 env->ReleaseStringChars(findUpper, findUpperChars);
2357 checkException(env);
2360 int length = env->GetStringLength(findLower);
2361 // If the lengths of the strings do not match, then they are not the same
2362 // word, so do not search.
2363 if (!length || env->GetStringLength(findUpper) != length) {
2364 env->ReleaseStringChars(findLower, findLowerChars);
2365 env->ReleaseStringChars(findUpper, findUpperChars);
2366 checkException(env);
2369 int width = root->documentWidth();
2370 int height = root->documentHeight();
2371 // Create a FindCanvas, which allows us to fake draw into it so we can
2372 // figure out where our search string is rendered (and how many times).
2373 FindCanvas canvas(width, height, (const UChar*) findLowerChars,
2374 (const UChar*) findUpperChars, length << 1);
2376 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height);
2377 canvas.setBitmapDevice(bitmap);
2379 WTF::Vector<MatchInfo>* matches = canvas.detachMatches();
2380 // With setMatches, the WebView takes ownership of matches
2381 view->setMatches(matches, sameAsLastSearch);
2383 env->ReleaseStringChars(findLower, findLowerChars);
2384 env->ReleaseStringChars(findUpper, findUpperChars);
2385 checkException(env);
2386 return canvas.found();
2389 static void nativeFindNext(JNIEnv *env, jobject obj, bool forward)
2391 WebView* view = GET_NATIVE_VIEW(env, obj);
2392 LOG_ASSERT(view, "view not set in nativeFindNext");
2393 view->findNext(forward);
2396 static int nativeFindIndex(JNIEnv *env, jobject obj)
2398 WebView* view = GET_NATIVE_VIEW(env, obj);
2399 LOG_ASSERT(view, "view not set in nativeFindIndex");
2400 return view->currentMatchIndex();
2403 static void nativeUpdateCachedTextfield(JNIEnv *env, jobject obj, jstring updatedText, jint generation)
2405 WebView* view = GET_NATIVE_VIEW(env, obj);
2406 LOG_ASSERT(view, "view not set in nativeUpdateCachedTextfield");
2407 CachedRoot* root = view->getFrameCache(WebView::DontAllowNewer);
2410 const CachedNode* cachedFocusNode = root->currentFocus();
2411 if (!cachedFocusNode || !cachedFocusNode->isTextInput())
2413 WTF::String webcoreString = jstringToWtfString(env, updatedText);
2414 (const_cast<CachedNode*>(cachedFocusNode))->setExport(webcoreString);
2415 root->setTextGeneration(generation);
2416 checkException(env);
2419 static jint nativeGetBlockLeftEdge(JNIEnv *env, jobject obj, jint x, jint y,
2422 WebView* view = GET_NATIVE_VIEW(env, obj);
2423 LOG_ASSERT(view, "view not set in %s", __FUNCTION__);
2426 return view->getBlockLeftEdge(x, y, scale);
2429 static void nativeDestroy(JNIEnv *env, jobject obj)
2431 WebView* view = GET_NATIVE_VIEW(env, obj);
2432 LOGD("nativeDestroy view: %p", view);
2433 LOG_ASSERT(view, "view not set in nativeDestroy");
2437 static void nativeStopGL(JNIEnv *env, jobject obj)
2439 GET_NATIVE_VIEW(env, obj)->stopGL();
2442 static bool nativeMoveCursorToNextTextInput(JNIEnv *env, jobject obj)
2444 WebView* view = GET_NATIVE_VIEW(env, obj);
2445 CachedRoot* root = view->getFrameCache(WebView::DontAllowNewer);
2448 const CachedNode* current = root->currentCursor();
2449 if (!current || !current->isTextInput())
2450 current = root->currentFocus();
2451 if (!current || !current->isTextInput())
2453 const CachedFrame* frame;
2454 const CachedNode* next = root->nextTextField(current, &frame);
2457 const WebCore::IntRect& bounds = next->bounds(frame);
2458 root->rootHistory()->setMouseBounds(bounds);
2459 view->getWebViewCore()->updateCursorBounds(root, frame, next);
2460 view->showCursorUntimed();
2461 root->setCursor(const_cast<CachedFrame*>(frame),
2462 const_cast<CachedNode*>(next));
2463 view->sendMoveFocus(static_cast<WebCore::Frame*>(frame->framePointer()),
2464 static_cast<WebCore::Node*>(next->nodePointer()));
2465 if (!next->isInLayer())
2466 view->scrollRectOnScreen(bounds);
2467 view->getWebViewCore()->m_moveGeneration++;
2471 static int nativeMoveGeneration(JNIEnv *env, jobject obj)
2473 WebView* view = GET_NATIVE_VIEW(env, obj);
2476 return view->moveGeneration();
2479 static void nativeMoveSelection(JNIEnv *env, jobject obj, int x, int y)
2481 GET_NATIVE_VIEW(env, obj)->moveSelection(x, y);
2484 static void nativeResetSelection(JNIEnv *env, jobject obj)
2486 return GET_NATIVE_VIEW(env, obj)->resetSelection();
2489 static jobject nativeSelectableText(JNIEnv* env, jobject obj)
2491 IntPoint pos = GET_NATIVE_VIEW(env, obj)->selectableText();
2492 jclass pointClass = env->FindClass("android/graphics/Point");
2493 jmethodID init = env->GetMethodID(pointClass, "<init>", "(II)V");
2494 jobject point = env->NewObject(pointClass, init, pos.x(), pos.y());
2495 env->DeleteLocalRef(pointClass);
2499 static void nativeSelectAll(JNIEnv* env, jobject obj)
2501 GET_NATIVE_VIEW(env, obj)->selectAll();
2504 static void nativeSetExtendSelection(JNIEnv *env, jobject obj)
2506 GET_NATIVE_VIEW(env, obj)->setExtendSelection();
2509 static jboolean nativeStartSelection(JNIEnv *env, jobject obj, int x, int y)
2511 return GET_NATIVE_VIEW(env, obj)->startSelection(x, y);
2514 static jboolean nativeWordSelection(JNIEnv *env, jobject obj, int x, int y)
2516 return GET_NATIVE_VIEW(env, obj)->wordSelection(x, y);
2519 static void nativeExtendSelection(JNIEnv *env, jobject obj, int x, int y)
2521 GET_NATIVE_VIEW(env, obj)->extendSelection(x, y);
2524 static jobject nativeGetSelection(JNIEnv *env, jobject obj)
2526 WebView* view = GET_NATIVE_VIEW(env, obj);
2527 LOG_ASSERT(view, "view not set in %s", __FUNCTION__);
2528 String selection = view->getSelection();
2529 return wtfStringToJstring(env, selection);
2532 static jboolean nativeHitSelection(JNIEnv *env, jobject obj, int x, int y)
2534 return GET_NATIVE_VIEW(env, obj)->hitSelection(x, y);
2537 static jint nativeSelectionX(JNIEnv *env, jobject obj)
2539 return GET_NATIVE_VIEW(env, obj)->selectionX();
2542 static jint nativeSelectionY(JNIEnv *env, jobject obj)
2544 return GET_NATIVE_VIEW(env, obj)->selectionY();
2547 static void nativeSetSelectionPointer(JNIEnv *env, jobject obj, jint nativeView,
2548 jboolean set, jfloat scale, jint x, jint y)
2550 ((WebView*)nativeView)->setSelectionPointer(set, scale, x, y);
2553 static void nativeRegisterPageSwapCallback(JNIEnv *env, jobject obj)
2555 GET_NATIVE_VIEW(env, obj)->registerPageSwapCallback();
2558 static void nativeTileProfilingStart(JNIEnv *env, jobject obj)
2560 TilesManager::instance()->getProfiler()->start();
2563 static float nativeTileProfilingStop(JNIEnv *env, jobject obj)
2565 return TilesManager::instance()->getProfiler()->stop();
2568 static void nativeTileProfilingClear(JNIEnv *env, jobject obj)
2570 TilesManager::instance()->getProfiler()->clear();
2573 static int nativeTileProfilingNumFrames(JNIEnv *env, jobject obj)
2575 return TilesManager::instance()->getProfiler()->numFrames();
2578 static int nativeTileProfilingNumTilesInFrame(JNIEnv *env, jobject obj, int frame)
2580 return TilesManager::instance()->getProfiler()->numTilesInFrame(frame);
2583 static int nativeTileProfilingGetInt(JNIEnv *env, jobject obj, int frame, int tile, jstring jkey)
2585 WTF::String key = jstringToWtfString(env, jkey);
2586 TileProfileRecord* record = TilesManager::instance()->getProfiler()->getTile(frame, tile);
2589 return record->left;
2593 return record->right;
2594 if (key == "bottom")
2595 return record->bottom;
2597 return record->level;
2598 if (key == "isReady")
2599 return record->isReady ? 1 : 0;
2603 static float nativeTileProfilingGetFloat(JNIEnv *env, jobject obj, int frame, int tile, jstring jkey)
2605 TileProfileRecord* record = TilesManager::instance()->getProfiler()->getTile(frame, tile);
2606 return record->scale;
2609 #ifdef ANDROID_DUMP_DISPLAY_TREE
2610 static void dumpToFile(const char text[], void* file) {
2611 fwrite(text, 1, strlen(text), reinterpret_cast<FILE*>(file));
2612 fwrite("\n", 1, 1, reinterpret_cast<FILE*>(file));
2616 static bool nativeSetProperty(JNIEnv *env, jobject obj, jstring jkey, jstring jvalue)
2618 WTF::String key = jstringToWtfString(env, jkey);
2619 WTF::String value = jstringToWtfString(env, jvalue);
2620 if (key == "inverted") {
2621 if (value == "true")
2622 TilesManager::instance()->setInvertedScreen(true);
2624 TilesManager::instance()->setInvertedScreen(false);
2627 if (key == "inverted_contrast") {
2628 float contrast = value.toFloat();
2629 TilesManager::instance()->setInvertedScreenContrast(contrast);
2632 if (key == "enable_cpu_upload_path") {
2633 TilesManager::instance()->transferQueue()->setTextureUploadType(
2634 value == "true" ? CpuUpload : GpuUpload);
2640 static jstring nativeGetProperty(JNIEnv *env, jobject obj, jstring key)
2645 static void nativeOnTrimMemory(JNIEnv *env, jobject obj, jint level)
2647 if (TilesManager::hardwareAccelerationEnabled()) {
2648 bool freeAllTextures = (level > TRIM_MEMORY_UI_HIDDEN);
2649 TilesManager::instance()->deallocateTextures(freeAllTextures);
2653 static void nativeDumpDisplayTree(JNIEnv* env, jobject jwebview, jstring jurl)
2655 #ifdef ANDROID_DUMP_DISPLAY_TREE
2656 WebView* view = GET_NATIVE_VIEW(env, jwebview);
2657 LOG_ASSERT(view, "view not set in %s", __FUNCTION__);
2659 if (view && view->getWebViewCore()) {
2660 FILE* file = fopen(DISPLAY_TREE_LOG_FILE, "w");
2662 SkFormatDumper dumper(dumpToFile, file);
2665 const char* str = env->GetStringUTFChars(jurl, 0);
2666 SkDebugf("Dumping %s to %s\n", str, DISPLAY_TREE_LOG_FILE);
2667 dumpToFile(str, file);
2668 env->ReleaseStringUTFChars(jurl, str);
2670 // now dump the display tree
2671 SkDumpCanvas canvas(&dumper);
2672 // this will playback the picture into the canvas, which will
2673 // spew its contents to the dumper
2674 view->draw(&canvas, 0, 0, false);
2675 // we're done with the file now
2676 fwrite("\n", 1, 1, file);
2679 #if USE(ACCELERATED_COMPOSITING)
2680 const LayerAndroid* rootLayer = view->compositeRoot();
2682 FILE* file = fopen(LAYERS_TREE_LOG_FILE,"w");
2684 rootLayer->dumpLayers(file, 0);
2693 static int nativeScrollableLayer(JNIEnv* env, jobject jwebview, jint x, jint y,
2694 jobject rect, jobject bounds)
2696 WebView* view = GET_NATIVE_VIEW(env, jwebview);
2697 LOG_ASSERT(view, "view not set in %s", __FUNCTION__);
2698 SkIRect nativeRect, nativeBounds;
2699 int id = view->scrollableLayer(x, y, &nativeRect, &nativeBounds);
2701 GraphicsJNI::irect_to_jrect(nativeRect, env, rect);
2703 GraphicsJNI::irect_to_jrect(nativeBounds, env, bounds);
2707 static bool nativeScrollLayer(JNIEnv* env, jobject obj, jint layerId, jint x,
2710 #if ENABLE(ANDROID_OVERFLOW_SCROLL)
2711 WebView* view = GET_NATIVE_VIEW(env, obj);
2712 LayerAndroid* root = view->compositeRoot();
2715 LayerAndroid* layer = root->findById(layerId);
2716 if (!layer || !layer->contentIsScrollable())
2718 return static_cast<ScrollableLayerAndroid*>(layer)->scrollTo(x, y);
2723 static void nativeSetIsScrolling(JNIEnv* env, jobject jwebview, jboolean isScrolling)
2725 WebView* view = GET_NATIVE_VIEW(env, jwebview);
2726 LOG_ASSERT(view, "view not set in %s", __FUNCTION__);
2727 view->setIsScrolling(isScrolling);
2730 static void nativeUseHardwareAccelSkia(JNIEnv*, jobject, jboolean enabled)
2732 BaseRenderer::setCurrentRendererType(enabled ? BaseRenderer::Ganesh : BaseRenderer::Raster);
2735 static int nativeGetBackgroundColor(JNIEnv* env, jobject obj)
2737 WebView* view = GET_NATIVE_VIEW(env, obj);
2738 BaseLayerAndroid* baseLayer = view->getBaseLayer();
2740 WebCore::Color color = baseLayer->getBackgroundColor();
2741 if (color.isValid())
2742 return SkColorSetARGB(color.alpha(), color.red(),
2743 color.green(), color.blue());
2745 return SK_ColorWHITE;
2751 static JNINativeMethod gJavaWebViewMethods[] = {
2752 { "nativeCacheHitFramePointer", "()I",
2753 (void*) nativeCacheHitFramePointer },
2754 { "nativeCacheHitIsPlugin", "()Z",
2755 (void*) nativeCacheHitIsPlugin },
2756 { "nativeCacheHitNodeBounds", "()Landroid/graphics/Rect;",
2757 (void*) nativeCacheHitNodeBounds },
2758 { "nativeCacheHitNodePointer", "()I",
2759 (void*) nativeCacheHitNodePointer },
2760 { "nativeClearCursor", "()V",
2761 (void*) nativeClearCursor },
2762 { "nativeCreate", "(ILjava/lang/String;)V",
2763 (void*) nativeCreate },
2764 { "nativeCursorFramePointer", "()I",
2765 (void*) nativeCursorFramePointer },
2766 { "nativePageShouldHandleShiftAndArrows", "()Z",
2767 (void*) nativePageShouldHandleShiftAndArrows },
2768 { "nativeCursorNodeBounds", "()Landroid/graphics/Rect;",
2769 (void*) nativeCursorNodeBounds },
2770 { "nativeCursorNodePointer", "()I",
2771 (void*) nativeCursorNodePointer },
2772 { "nativeCursorIntersects", "(Landroid/graphics/Rect;)Z",
2773 (void*) nativeCursorIntersects },
2774 { "nativeCursorIsAnchor", "()Z",
2775 (void*) nativeCursorIsAnchor },
2776 { "nativeCursorIsTextInput", "()Z",
2777 (void*) nativeCursorIsTextInput },
2778 { "nativeCursorPosition", "()Landroid/graphics/Point;",
2779 (void*) nativeCursorPosition },
2780 { "nativeCursorText", "()Ljava/lang/String;",
2781 (void*) nativeCursorText },
2782 { "nativeCursorWantsKeyEvents", "()Z",
2783 (void*)nativeCursorWantsKeyEvents },
2784 { "nativeDebugDump", "()V",
2785 (void*) nativeDebugDump },
2786 { "nativeDestroy", "()V",
2787 (void*) nativeDestroy },
2788 { "nativeDraw", "(Landroid/graphics/Canvas;IIZ)I",
2789 (void*) nativeDraw },
2790 { "nativeGetDrawGLFunction", "(ILandroid/graphics/Rect;Landroid/graphics/Rect;FI)I",
2791 (void*) nativeGetDrawGLFunction },
2792 { "nativeUpdateDrawGLFunction", "(Landroid/graphics/Rect;Landroid/graphics/Rect;)V",
2793 (void*) nativeUpdateDrawGLFunction },
2794 { "nativeDumpDisplayTree", "(Ljava/lang/String;)V",
2795 (void*) nativeDumpDisplayTree },
2796 { "nativeEvaluateLayersAnimations", "(I)Z",
2797 (void*) nativeEvaluateLayersAnimations },
2798 { "nativeExtendSelection", "(II)V",
2799 (void*) nativeExtendSelection },
2800 { "nativeFindAll", "(Ljava/lang/String;Ljava/lang/String;Z)I",
2801 (void*) nativeFindAll },
2802 { "nativeFindNext", "(Z)V",
2803 (void*) nativeFindNext },
2804 { "nativeFindIndex", "()I",
2805 (void*) nativeFindIndex},
2806 { "nativeFocusCandidateFramePointer", "()I",
2807 (void*) nativeFocusCandidateFramePointer },
2808 { "nativeFocusCandidateHasNextTextfield", "()Z",
2809 (void*) focusCandidateHasNextTextfield },
2810 { "nativeFocusCandidateIsPassword", "()Z",
2811 (void*) nativeFocusCandidateIsPassword },
2812 { "nativeFocusCandidateIsRtlText", "()Z",
2813 (void*) nativeFocusCandidateIsRtlText },
2814 { "nativeFocusCandidateIsTextInput", "()Z",
2815 (void*) nativeFocusCandidateIsTextInput },
2816 { "nativeFocusCandidateLineHeight", "()I",
2817 (void*) nativeFocusCandidateLineHeight },
2818 { "nativeFocusCandidateMaxLength", "()I",
2819 (void*) nativeFocusCandidateMaxLength },
2820 { "nativeFocusCandidateIsAutoComplete", "()Z",
2821 (void*) nativeFocusCandidateIsAutoComplete },
2822 { "nativeFocusCandidateIsSpellcheck", "()Z",
2823 (void*) nativeFocusCandidateIsSpellcheck },
2824 { "nativeFocusCandidateName", "()Ljava/lang/String;",
2825 (void*) nativeFocusCandidateName },
2826 { "nativeFocusCandidateNodeBounds", "()Landroid/graphics/Rect;",
2827 (void*) nativeFocusCandidateNodeBounds },
2828 { "nativeFocusCandidatePaddingRect", "()Landroid/graphics/Rect;",
2829 (void*) nativeFocusCandidatePaddingRect },
2830 { "nativeFocusCandidatePointer", "()I",
2831 (void*) nativeFocusCandidatePointer },
2832 { "nativeFocusCandidateText", "()Ljava/lang/String;",
2833 (void*) nativeFocusCandidateText },
2834 { "nativeFocusCandidateTextSize", "()F",
2835 (void*) nativeFocusCandidateTextSize },
2836 { "nativeFocusCandidateType", "()I",
2837 (void*) nativeFocusCandidateType },
2838 { "nativeFocusIsPlugin", "()Z",
2839 (void*) nativeFocusIsPlugin },
2840 { "nativeFocusNodeBounds", "()Landroid/graphics/Rect;",
2841 (void*) nativeFocusNodeBounds },
2842 { "nativeFocusNodePointer", "()I",
2843 (void*) nativeFocusNodePointer },
2844 { "nativeGetCursorRingBounds", "()Landroid/graphics/Rect;",
2845 (void*) nativeGetCursorRingBounds },
2846 { "nativeGetSelection", "()Ljava/lang/String;",
2847 (void*) nativeGetSelection },
2848 { "nativeHasCursorNode", "()Z",
2849 (void*) nativeHasCursorNode },
2850 { "nativeHasFocusNode", "()Z",
2851 (void*) nativeHasFocusNode },
2852 { "nativeHideCursor", "()V",
2853 (void*) nativeHideCursor },
2854 { "nativeHitSelection", "(II)Z",
2855 (void*) nativeHitSelection },
2856 { "nativeImageURI", "(II)Ljava/lang/String;",
2857 (void*) nativeImageURI },
2858 { "nativeInstrumentReport", "()V",
2859 (void*) nativeInstrumentReport },
2860 { "nativeLayerBounds", "(I)Landroid/graphics/Rect;",
2861 (void*) nativeLayerBounds },
2862 { "nativeMotionUp", "(III)Z",
2863 (void*) nativeMotionUp },
2864 { "nativeMoveCursor", "(IIZ)Z",
2865 (void*) nativeMoveCursor },
2866 { "nativeMoveCursorToNextTextInput", "()Z",
2867 (void*) nativeMoveCursorToNextTextInput },
2868 { "nativeMoveGeneration", "()I",
2869 (void*) nativeMoveGeneration },
2870 { "nativeMoveSelection", "(II)V",
2871 (void*) nativeMoveSelection },
2872 { "nativePointInNavCache", "(III)Z",
2873 (void*) nativePointInNavCache },
2874 { "nativeRecordButtons", "(IZZZ)V",
2875 (void*) nativeRecordButtons },
2876 { "nativeResetSelection", "()V",
2877 (void*) nativeResetSelection },
2878 { "nativeSelectableText", "()Landroid/graphics/Point;",
2879 (void*) nativeSelectableText },
2880 { "nativeSelectAll", "()V",
2881 (void*) nativeSelectAll },
2882 { "nativeSelectBestAt", "(Landroid/graphics/Rect;)V",
2883 (void*) nativeSelectBestAt },
2884 { "nativeSelectAt", "(II)V",
2885 (void*) nativeSelectAt },
2886 { "nativeSelectionX", "()I",
2887 (void*) nativeSelectionX },
2888 { "nativeSelectionY", "()I",
2889 (void*) nativeSelectionY },
2890 { "nativeSetExtendSelection", "()V",
2891 (void*) nativeSetExtendSelection },
2892 { "nativeSetFindIsEmpty", "()V",
2893 (void*) nativeSetFindIsEmpty },
2894 { "nativeSetFindIsUp", "(Z)V",
2895 (void*) nativeSetFindIsUp },
2896 { "nativeSetHeightCanMeasure", "(Z)V",
2897 (void*) nativeSetHeightCanMeasure },
2898 { "nativeSetBaseLayer", "(ILandroid/graphics/Region;ZZZ)V",
2899 (void*) nativeSetBaseLayer },
2900 { "nativeGetTextSelectionRegion", "(Landroid/graphics/Region;)V",
2901 (void*) nativeGetTextSelectionRegion },
2902 { "nativeGetBaseLayer", "()I",
2903 (void*) nativeGetBaseLayer },
2904 { "nativeReplaceBaseContent", "(I)V",
2905 (void*) nativeReplaceBaseContent },
2906 { "nativeCopyBaseContentToPicture", "(Landroid/graphics/Picture;)V",
2907 (void*) nativeCopyBaseContentToPicture },
2908 { "nativeHasContent", "()Z",
2909 (void*) nativeHasContent },
2910 { "nativeSetSelectionPointer", "(IZFII)V",
2911 (void*) nativeSetSelectionPointer },
2912 { "nativeShowCursorTimed", "()V",
2913 (void*) nativeShowCursorTimed },
2914 { "nativeRegisterPageSwapCallback", "()V",
2915 (void*) nativeRegisterPageSwapCallback },
2916 { "nativeTileProfilingStart", "()V",
2917 (void*) nativeTileProfilingStart },
2918 { "nativeTileProfilingStop", "()F",
2919 (void*) nativeTileProfilingStop },
2920 { "nativeTileProfilingClear", "()V",
2921 (void*) nativeTileProfilingClear },
2922 { "nativeTileProfilingNumFrames", "()I",
2923 (void*) nativeTileProfilingNumFrames },
2924 { "nativeTileProfilingNumTilesInFrame", "(I)I",
2925 (void*) nativeTileProfilingNumTilesInFrame },
2926 { "nativeTileProfilingGetInt", "(IILjava/lang/String;)I",
2927 (void*) nativeTileProfilingGetInt },
2928 { "nativeTileProfilingGetFloat", "(IILjava/lang/String;)F",
2929 (void*) nativeTileProfilingGetFloat },
2930 { "nativeStartSelection", "(II)Z",
2931 (void*) nativeStartSelection },
2932 { "nativeStopGL", "()V",
2933 (void*) nativeStopGL },
2934 { "nativeSubtractLayers", "(Landroid/graphics/Rect;)Landroid/graphics/Rect;",
2935 (void*) nativeSubtractLayers },
2936 { "nativeTextGeneration", "()I",
2937 (void*) nativeTextGeneration },
2938 { "nativeUpdateCachedTextfield", "(Ljava/lang/String;I)V",
2939 (void*) nativeUpdateCachedTextfield },
2940 { "nativeWordSelection", "(II)Z",
2941 (void*) nativeWordSelection },
2942 { "nativeGetBlockLeftEdge", "(IIF)I",
2943 (void*) nativeGetBlockLeftEdge },
2944 { "nativeScrollableLayer", "(IILandroid/graphics/Rect;Landroid/graphics/Rect;)I",
2945 (void*) nativeScrollableLayer },
2946 { "nativeScrollLayer", "(III)Z",
2947 (void*) nativeScrollLayer },
2948 { "nativeSetIsScrolling", "(Z)V",
2949 (void*) nativeSetIsScrolling },
2950 { "nativeUseHardwareAccelSkia", "(Z)V",
2951 (void*) nativeUseHardwareAccelSkia },
2952 { "nativeGetBackgroundColor", "()I",
2953 (void*) nativeGetBackgroundColor },
2954 { "nativeSetProperty", "(Ljava/lang/String;Ljava/lang/String;)Z",
2955 (void*) nativeSetProperty },
2956 { "nativeGetProperty", "(Ljava/lang/String;)Ljava/lang/String;",
2957 (void*) nativeGetProperty },
2958 { "nativeOnTrimMemory", "(I)V",
2959 (void*) nativeOnTrimMemory },
2962 int registerWebView(JNIEnv* env)
2964 jclass clazz = env->FindClass("android/webkit/WebView");
2965 LOG_ASSERT(clazz, "Unable to find class android/webkit/WebView");
2966 gWebViewField = env->GetFieldID(clazz, "mNativeClass", "I");
2967 LOG_ASSERT(gWebViewField, "Unable to find android/webkit/WebView.mNativeClass");
2968 env->DeleteLocalRef(clazz);
2970 return jniRegisterNativeMethods(env, "android/webkit/WebView", gJavaWebViewMethods, NELEM(gJavaWebViewMethods));
2973 } // namespace android