diff options
27 files changed, 253 insertions, 2119 deletions
@@ -293,6 +293,7 @@ LOCAL_LDLIBS += -lpthread -ldl # Build the list of shared libraries LOCAL_SHARED_LIBRARIES := \ libandroid \ + libandroidfw \ libandroid_runtime \ libnativehelper \ libsqlite \ @@ -390,8 +391,5 @@ include $(BUILD_SHARED_LIBRARY) # Build the wds client include $(WEBKIT_PATH)/android/wds/client/Android.mk -# Build the performance command line tool. -include $(WEBKIT_PATH)/android/benchmark/Android.mk - # Build the webkit merge tool. include $(BASE_PATH)/Tools/android/webkitmerge/Android.mk diff --git a/Source/WebCore/platform/android/RenderThemeAndroid.cpp b/Source/WebCore/platform/android/RenderThemeAndroid.cpp index b570d0e..ee406c2 100644 --- a/Source/WebCore/platform/android/RenderThemeAndroid.cpp +++ b/Source/WebCore/platform/android/RenderThemeAndroid.cpp @@ -181,6 +181,16 @@ Color RenderThemeAndroid::platformInactiveListBoxSelectionForegroundColor() cons return Color(Color::transparent); } +Color RenderThemeAndroid::platformActiveTextSearchHighlightColor() const +{ + return Color(0x00, 0x99, 0xcc, 0x99); // HOLO_DARK +} + +Color RenderThemeAndroid::platformInactiveTextSearchHighlightColor() const +{ + return Color(0x33, 0xb5, 0xe5, 0x66); // HOLO_LIGHT +} + int RenderThemeAndroid::baselinePosition(const RenderObject* obj) const { // From the description of this function in RenderTheme.h: @@ -623,30 +633,16 @@ bool RenderThemeAndroid::paintMenuListButton(RenderObject* obj, const PaintInfo& Color RenderThemeAndroid::platformFocusRingColor() const { - static Color focusRingColor(0x66, 0x33, 0xB5, 0xE5); + static Color focusRingColor(0x33, 0xB5, 0xE5, 0x66); return focusRingColor; } bool RenderThemeAndroid::supportsFocusRing(const RenderStyle* style) const { - // TODO: Draw this on the UI side - // For now, just return false to let WebKit draw the focus ring. We only - // draw this ring when navigating via the keyboard, this does not affect - // the touch ring - return false; - return style->opacity() > 0 - && style->hasAppearance() - && style->appearance() != TextFieldPart - && style->appearance() != SearchFieldPart - && style->appearance() != TextAreaPart - && style->appearance() != CheckboxPart - && style->appearance() != RadioPart - && style->appearance() != PushButtonPart - && style->appearance() != SquareButtonPart - && style->appearance() != ButtonPart - && style->appearance() != ButtonBevelPart - && style->appearance() != MenulistPart - && style->appearance() != MenulistButtonPart; + // Draw the focus ring ourselves unless it is a text area (webkit does borders better) + if (!style || !style->hasAppearance()) + return true; + return style->appearance() != TextFieldPart && style->appearance() != TextAreaPart; } } // namespace WebCore diff --git a/Source/WebCore/platform/android/RenderThemeAndroid.h b/Source/WebCore/platform/android/RenderThemeAndroid.h index 802d3c3..ed4d07f 100644 --- a/Source/WebCore/platform/android/RenderThemeAndroid.h +++ b/Source/WebCore/platform/android/RenderThemeAndroid.h @@ -48,7 +48,7 @@ public: ~RenderThemeAndroid(); virtual bool stateChanged(RenderObject*, ControlState) const; - + virtual bool supportsFocusRing(const RenderStyle*) const; // A method asking if the theme's controls actually care about redrawing when hovered. virtual bool supportsHover(const RenderStyle* style) const { return style->affectedByHoverRules(); } @@ -67,6 +67,9 @@ public: virtual Color platformActiveListBoxSelectionForegroundColor() const; virtual Color platformInactiveListBoxSelectionForegroundColor() const; + virtual Color platformActiveTextSearchHighlightColor() const; + virtual Color platformInactiveTextSearchHighlightColor() const; + virtual void systemFont(int, WebCore::FontDescription&) const {} virtual int minimumMenuListSize(RenderStyle*) const { return 0; } diff --git a/Source/WebCore/platform/graphics/android/BaseLayerAndroid.cpp b/Source/WebCore/platform/graphics/android/BaseLayerAndroid.cpp index 2d2867c..7208380 100644 --- a/Source/WebCore/platform/graphics/android/BaseLayerAndroid.cpp +++ b/Source/WebCore/platform/graphics/android/BaseLayerAndroid.cpp @@ -320,6 +320,8 @@ void BaseLayerAndroid::drawBasePictureInGL() void BaseLayerAndroid::updateLayerPositions(SkRect& visibleRect) { LayerAndroid* compositedRoot = static_cast<LayerAndroid*>(getChild(0)); + if (!compositedRoot) + return; TransformationMatrix ident; compositedRoot->updateFixedLayersPositions(visibleRect); FloatRect clip(0, 0, content()->width(), content()->height()); diff --git a/Source/WebCore/platform/graphics/android/GLExtras.cpp b/Source/WebCore/platform/graphics/android/GLExtras.cpp index b872951..8a1d2fa 100644 --- a/Source/WebCore/platform/graphics/android/GLExtras.cpp +++ b/Source/WebCore/platform/graphics/android/GLExtras.cpp @@ -26,7 +26,6 @@ #include "config.h" #include "DrawExtra.h" -#include "FindCanvas.h" #include "GLExtras.h" #include "IntRect.h" #include "TilesManager.h" @@ -58,8 +57,7 @@ #define MAX_NUMBER_OF_MATCHES_TO_DRAW 101 GLExtras::GLExtras() - : m_findOnPage(0) - , m_ring(0) + : m_ring(0) , m_drawExtra(0) , m_viewport() { @@ -170,58 +168,11 @@ void GLExtras::drawCursorRings(const LayerAndroid* layer) layer ? layer->drawTransform() : 0); } -void GLExtras::drawFindOnPage(const LayerAndroid* layer) -{ - WTF::Vector<MatchInfo>* matches = m_findOnPage->matches(); - XLOG("drawFindOnPage, matches: %p", matches); - if (!matches || !m_findOnPage->isCurrentLocationValid()) - return; - std::pair<unsigned, unsigned> matchRange = - m_findOnPage->getLayerMatchRange(layer ? layer->uniqueId() : -1); - if (matchRange.first >= matchRange.second) - return; - - int count = matches->size(); - unsigned current = m_findOnPage->currentMatchIndex(); - XLOG("match count: %d", count); - const TransformationMatrix* drawTransform = - layer ? layer->drawTransform() : 0; - if (count < MAX_NUMBER_OF_MATCHES_TO_DRAW) - for (unsigned i = matchRange.first; i < matchRange.second; i++) { - MatchInfo& info = matches->at(i); - const SkRegion& region = info.getLocation(); - SkIRect rect = region.getBounds(); - if (drawTransform) { - IntRect intRect(rect.fLeft, rect.fTop, rect.width(), - rect.height()); - IntRect transformedRect = drawTransform->mapRect(intRect); - rect.setXYWH(transformedRect.x(), transformedRect.y(), - transformedRect.width(), transformedRect.height()); - } - if (rect.intersect(m_viewport.fLeft, m_viewport.fTop, - m_viewport.fRight, m_viewport.fBottom)) - drawRegion(region, i == current, false, drawTransform, COLOR_HOLO_DARK); -#ifdef DEBUG - else - XLOG("Quick rejecting [%dx%d, %d, %d", rect.fLeft, rect.fTop, - rect.width(), rect.height()); -#endif // DEBUG - } - else { - if (matchRange.first <= current && current < matchRange.second) { - MatchInfo& info = matches->at(current); - drawRegion(info.getLocation(), true, false, drawTransform, COLOR_HOLO_DARK); - } - } -} - void GLExtras::drawGL(const LayerAndroid* layer) { if (m_drawExtra) { if (m_drawExtra == m_ring) drawCursorRings(layer); - else if (m_drawExtra == m_findOnPage) - drawFindOnPage(layer); else m_drawExtra->drawGL(this, layer); } diff --git a/Source/WebCore/platform/graphics/android/GLExtras.h b/Source/WebCore/platform/graphics/android/GLExtras.h index 51ad8d8..72ee41c 100644 --- a/Source/WebCore/platform/graphics/android/GLExtras.h +++ b/Source/WebCore/platform/graphics/android/GLExtras.h @@ -32,7 +32,6 @@ #include "SkRegion.h" namespace android { - class FindOnPage; class CursorRing; } @@ -47,9 +46,6 @@ public: virtual ~GLExtras(); void drawGL(const LayerAndroid* layer); - void setFindOnPageExtra(android::FindOnPage* findOnPage) { - m_findOnPage = findOnPage; - } void setCursorRingExtra(android::CursorRing* ring) { m_ring = ring; } void setDrawExtra(android::DrawExtra* extra) { m_drawExtra = extra; } void setViewport(const SkRect & viewport) { m_viewport = viewport; } @@ -60,9 +56,7 @@ public: private: void drawRing(SkRect& srcRect, Color color, const TransformationMatrix* drawMat); void drawCursorRings(const LayerAndroid* layer); - void drawFindOnPage(const LayerAndroid* layer); - android::FindOnPage* m_findOnPage; android::CursorRing* m_ring; android::DrawExtra* m_drawExtra; SkRect m_viewport; diff --git a/Source/WebCore/platform/graphics/android/MediaTexture.cpp b/Source/WebCore/platform/graphics/android/MediaTexture.cpp index f3d1756..2582a53 100644 --- a/Source/WebCore/platform/graphics/android/MediaTexture.cpp +++ b/Source/WebCore/platform/graphics/android/MediaTexture.cpp @@ -191,8 +191,7 @@ void MediaTexture::draw(const TransformationMatrix& contentMatrix, bool forceAlphaBlending = !( PIXEL_FORMAT_RGBX_8888 == f || PIXEL_FORMAT_RGB_888 == f || - PIXEL_FORMAT_RGB_565 == f || - PIXEL_FORMAT_RGB_332 == f); + PIXEL_FORMAT_RGB_565 == f); TilesManager::instance()->shader()->drawLayerQuad(contentMatrix, mediaBounds, diff --git a/Source/WebCore/platform/network/android/ResourceHandleAndroid.cpp b/Source/WebCore/platform/network/android/ResourceHandleAndroid.cpp index 13a26f0..4bc918b 100644 --- a/Source/WebCore/platform/network/android/ResourceHandleAndroid.cpp +++ b/Source/WebCore/platform/network/android/ResourceHandleAndroid.cpp @@ -96,9 +96,7 @@ void ResourceHandle::platformSetDefersLoading(bool) } // This static method is called to check to see if a POST response is in -// the cache. The JNI call through to the HTTP cache stored on the Java -// side may be slow, but is only used during a navigation to -// a POST response. +// the cache. bool ResourceHandle::willLoadFromCache(ResourceRequest& request, Frame*) { // set the cache policy correctly, copied from diff --git a/Source/WebCore/platform/network/android/ResourceLoaderAndroid.h b/Source/WebCore/platform/network/android/ResourceLoaderAndroid.h index f627d62..5ff2322 100644 --- a/Source/WebCore/platform/network/android/ResourceLoaderAndroid.h +++ b/Source/WebCore/platform/network/android/ResourceLoaderAndroid.h @@ -46,7 +46,6 @@ public: virtual void pauseLoad(bool) = 0; // END ANDROID TODO - // Call to java to find out if this URL is in the cache static bool willLoadFromCache(const WebCore::KURL&, int64_t identifier); protected: ResourceLoaderAndroid() { } diff --git a/Source/WebCore/rendering/RenderHTMLCanvas.cpp b/Source/WebCore/rendering/RenderHTMLCanvas.cpp index de2a2c1..03b406b 100644 --- a/Source/WebCore/rendering/RenderHTMLCanvas.cpp +++ b/Source/WebCore/rendering/RenderHTMLCanvas.cpp @@ -47,6 +47,13 @@ RenderHTMLCanvas::RenderHTMLCanvas(HTMLCanvasElement* element) bool RenderHTMLCanvas::requiresLayer() const { +#if PLATFORM(ANDROID) + // All Canvas are drawn on their own composited layer + // This improves performances a lot (as this simplify + // the repaint/inval chain dealing with the PictureSet) + return true; +#endif + if (RenderReplaced::requiresLayer()) return true; diff --git a/Source/WebCore/rendering/RenderLayerCompositor.cpp b/Source/WebCore/rendering/RenderLayerCompositor.cpp index 03f1e41..25a08e7 100644 --- a/Source/WebCore/rendering/RenderLayerCompositor.cpp +++ b/Source/WebCore/rendering/RenderLayerCompositor.cpp @@ -1410,6 +1410,10 @@ bool RenderLayerCompositor::requiresCompositingForAndroidLayers(const RenderLaye if (layer->isFixed()) return true; #endif + + if (layer->renderer()->isCanvas()) + return true; + return false; } #endif diff --git a/Source/WebKit/Android.mk b/Source/WebKit/Android.mk index ee7f3ce..36664dd 100644 --- a/Source/WebKit/Android.mk +++ b/Source/WebKit/Android.mk @@ -52,9 +52,6 @@ LOCAL_SRC_FILES += \ android/RenderSkinMediaButton.cpp \ android/RenderSkinNinePatch.cpp \ \ - android/benchmark/Intercept.cpp \ - android/benchmark/MyJavaVM.cpp \ - \ android/icu/unicode/ucnv.cpp \ \ android/jni/AndroidHitTestResult.cpp \ @@ -89,7 +86,6 @@ LOCAL_SRC_FILES += \ android/nav/CachedNode.cpp \ android/nav/CachedRoot.cpp \ android/nav/DrawExtra.cpp \ - android/nav/FindCanvas.cpp \ android/nav/SelectText.cpp \ android/nav/WebView.cpp \ \ diff --git a/Source/WebKit/android/benchmark/Android.mk b/Source/WebKit/android/benchmark/Android.mk deleted file mode 100644 index 5b189e1..0000000 --- a/Source/WebKit/android/benchmark/Android.mk +++ /dev/null @@ -1,41 +0,0 @@ -## -## -## Copyright 2009, The Android Open Source Project -## -## Redistribution and use in source and binary forms, with or without -## modification, are permitted provided that the following conditions -## are met: -## * Redistributions of source code must retain the above copyright -## notice, this list of conditions and the following disclaimer. -## * Redistributions in binary form must reproduce the above copyright -## notice, this list of conditions and the following disclaimer in the -## documentation and/or other materials provided with the distribution. -## -## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY -## EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -## PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR -## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -## EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -## PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -## PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY -## OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -## - -LOCAL_PATH:= $(call my-dir) -include $(CLEAR_VARS) - -LOCAL_SRC_FILES := \ - main.cpp - -# Pull the webkit definitions from the base webkit makefile. -LOCAL_SHARED_LIBRARIES := libwebcore $(WEBKIT_SHARED_LIBRARIES) -LOCAL_LDLIBS := $(WEBKIT_LDLIBS) - -LOCAL_MODULE := webcore_test - -LOCAL_MODULE_TAGS := optional - -include $(BUILD_EXECUTABLE) diff --git a/Source/WebKit/android/benchmark/Intercept.cpp b/Source/WebKit/android/benchmark/Intercept.cpp deleted file mode 100644 index 28ada5a..0000000 --- a/Source/WebKit/android/benchmark/Intercept.cpp +++ /dev/null @@ -1,190 +0,0 @@ -/* - * Copyright 2009, The Android Open Source Project - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#define LOG_TAG "webcore_test" -#include "config.h" - -#include "Base64.h" -#include "HTTPParsers.h" -#include "Intercept.h" -#include "ResourceHandle.h" -#include "ResourceHandleClient.h" -#include "ResourceRequest.h" -#include "ResourceResponse.h" -#include "TextEncoding.h" - -#include <utils/Log.h> -#include <wtf/HashMap.h> -#include <wtf/text/CString.h> -#include <wtf/text/StringHash.h> - -PassRefPtr<WebCore::ResourceLoaderAndroid> MyResourceLoader::create( - ResourceHandle* handle, String url) -{ - return adoptRef<WebCore::ResourceLoaderAndroid>( - new MyResourceLoader(handle, url)); -} - -void MyResourceLoader::handleRequest() -{ - if (protocolIs(m_url, "data")) - loadData(m_url.substring(5)); // 5 for data: - else if (protocolIs(m_url, "file")) - loadFile(m_url.substring(7)); // 7 for file:// -} - -void MyResourceLoader::loadData(const String& data) -{ - ALOGD("Loading data (%s) ...", data.latin1().data()); - ResourceHandleClient* client = m_handle->client(); - int index = data.find(','); - if (index == -1) { - client->cannotShowURL(m_handle); - return; - } - - String mediaType = data.substring(0, index); - String base64 = data.substring(index + 1); - - bool decode = mediaType.endsWith(";base64", false); - if (decode) - mediaType = mediaType.left(mediaType.length() - 7); // 7 for base64; - - if (mediaType.isEmpty()) - mediaType = "text/plain;charset=US-ASCII"; - - String mimeType = extractMIMETypeFromMediaType(mediaType); - String charset = extractCharsetFromMediaType(mediaType); - - ResourceResponse response; - response.setMimeType(mimeType); - - if (decode) { - base64 = decodeURLEscapeSequences(base64); - response.setTextEncodingName(charset); - client->didReceiveResponse(m_handle, response); - - // FIXME: This is annoying. WebCore's Base64 decoder chokes on spaces. - // That is correct with strict decoding but html authors (particularly - // the acid3 authors) put spaces in the data which should be ignored. - // Remove them here before sending to the decoder. - Vector<char> in; - CString str = base64.latin1(); - const char* chars = str.data(); - unsigned i = 0; - while (i < str.length()) { - char c = chars[i]; - // Don't send spaces or control characters. - if (c != ' ' && c != '\n' && c != '\t' && c != '\b' - && c != '\f' && c != '\r') - in.append(chars[i]); - i++; - } - Vector<char> out; - if (base64Decode(in, out) && out.size() > 0) - client->didReceiveData(m_handle, out.data(), out.size(), 0); - } else { - base64 = decodeURLEscapeSequences(base64, TextEncoding(charset)); - response.setTextEncodingName("UTF-16"); - client->didReceiveResponse(m_handle, response); - if (base64.length() > 0) - client->didReceiveData(m_handle, (const char*)base64.characters(), - base64.length() * sizeof(UChar), 0); - } - client->didFinishLoading(m_handle, 0); -} -static String mimeTypeForExtension(const String& file) -{ - static HashMap<String, String, CaseFoldingHash> extensionToMime; - if (extensionToMime.isEmpty()) { - extensionToMime.set("txt", "text/plain"); - extensionToMime.set("html", "text/html"); - extensionToMime.set("htm", "text/html"); - extensionToMime.set("png", "image/png"); - extensionToMime.set("jpeg", "image/jpeg"); - extensionToMime.set("jpg", "image/jpeg"); - extensionToMime.set("gif", "image/gif"); - extensionToMime.set("ico", "image/x-icon"); - extensionToMime.set("js", "text/javascript"); - } - int dot = file.reverseFind('.'); - String mime("text/plain"); - if (dot != -1) { - String ext = file.substring(dot + 1); - if (extensionToMime.contains(ext)) - mime = extensionToMime.get(ext); - } - return mime; -} - -void MyResourceLoader::loadFile(const String& file) -{ - ALOGD("Loading file (%s) ...", file.latin1().data()); - FILE* f = fopen(file.latin1().data(), "r"); - ResourceHandleClient* client = m_handle->client(); - if (!f) { - client->didFail(m_handle, - ResourceError("", -14, file, "Could not open file")); - } else { - ResourceResponse response; - response.setTextEncodingName("utf-8"); - response.setMimeType(mimeTypeForExtension(file)); - client->didReceiveResponse(m_handle, response); - char buf[512]; - while (true) { - int res = fread(buf, 1, sizeof(buf), f); - if (res <= 0) - break; - client->didReceiveData(m_handle, buf, res, 0); - } - fclose(f); - client->didFinishLoading(m_handle, 0); - } -} - -PassRefPtr<WebCore::ResourceLoaderAndroid> MyWebFrame::startLoadingResource( - ResourceHandle* handle, const ResourceRequest& req, bool ignore, - bool ignore2) -{ - RefPtr<WebCore::ResourceLoaderAndroid> loader = - MyResourceLoader::create(handle, req.url().string()); - m_requests.append(loader); - if (!m_timer.isActive()) - m_timer.startOneShot(0); - return loader.release(); -} - -void MyWebFrame::timerFired(Timer<MyWebFrame>*) -{ - ALOGD("Handling requests..."); - Vector<RefPtr<WebCore::ResourceLoaderAndroid> > reqs; - reqs.swap(m_requests); - Vector<RefPtr<WebCore::ResourceLoaderAndroid> >::iterator i = reqs.begin(); - Vector<RefPtr<WebCore::ResourceLoaderAndroid> >::iterator end = reqs.end(); - for (; i != end; i++) - static_cast<MyResourceLoader*>((*i).get())->handleRequest(); - - ALOGD("...done"); -} diff --git a/Source/WebKit/android/benchmark/Intercept.h b/Source/WebKit/android/benchmark/Intercept.h deleted file mode 100644 index 6694dba..0000000 --- a/Source/WebKit/android/benchmark/Intercept.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2009, The Android Open Source Project - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef Intercept_h -#define Intercept_h - -#include "MyJavaVM.h" -#include "PlatformString.h" -#include "Timer.h" -#include "WebCoreFrameBridge.h" -#include "WebCoreResourceLoader.h" -#include <JNIUtility.h> -#include <wtf/Vector.h> - -namespace WebCore { - class Page; - class ResourceHandle; - class ResourceRequest; -} - -using namespace android; -using namespace WebCore; -using namespace WTF; - -class MyResourceLoader : public WebCoreResourceLoader { -public: - static PassRefPtr<WebCore::ResourceLoaderAndroid> create( - ResourceHandle* handle, String url); - void handleRequest(); - -private: - MyResourceLoader(ResourceHandle* handle, String url) - : WebCoreResourceLoader(JSC::Bindings::getJNIEnv(), MY_JOBJECT) - , m_handle(handle) - , m_url(url) {} - - void loadData(const String&); - void loadFile(const String&); - ResourceHandle* m_handle; - String m_url; -}; - -class MyWebFrame : public WebFrame { -public: - MyWebFrame(Page* page) - : WebFrame(JSC::Bindings::getJNIEnv(), MY_JOBJECT, MY_JOBJECT, page) - , m_timer(this, &MyWebFrame::timerFired) {} - - virtual PassRefPtr<WebCore::ResourceLoaderAndroid> startLoadingResource( - ResourceHandle* handle, const ResourceRequest& req, bool, bool); - - virtual bool canHandleRequest(const ResourceRequest&) { return true; } - -private: - void timerFired(Timer<MyWebFrame>*); - Vector<RefPtr<WebCore::ResourceLoaderAndroid> > m_requests; - Timer<MyWebFrame> m_timer; -}; - -#endif diff --git a/Source/WebKit/android/benchmark/MyJavaVM.cpp b/Source/WebKit/android/benchmark/MyJavaVM.cpp deleted file mode 100644 index 574c745..0000000 --- a/Source/WebKit/android/benchmark/MyJavaVM.cpp +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright 2009, The Android Open Source Project - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" -#include "MyJavaVM.h" - -#include <JNIUtility.h> -#include <jni.h> - -static JNIEnv* s_env; -static JavaVM* s_jvm; - -// JavaVM functions -jint vm_attachCurrentThread(JavaVM*, JNIEnv** env, void*) { - *env = s_env; - return JNI_OK; -} - -// JNIEnv functions -jobject env_callObjectMethodV(JNIEnv*, jobject, jmethodID, va_list) { - return MY_JOBJECT; -} -void env_callVoidMethodV(JNIEnv*, jobject, jmethodID, va_list) {} -void env_deleteRef(JNIEnv*, jobject) {} -jboolean env_exceptionCheck(JNIEnv*) { - return false; -} -jclass env_findClass(JNIEnv*, const char*) { - return (jclass) 1; -} -jbyte* env_getByteArrayElements(JNIEnv*, jbyteArray, jboolean*) { - return NULL; -} -jmethodID env_getMethodID(JNIEnv*, jclass, const char*, const char*) { - return (jmethodID) 1; -} -jclass env_getObjectClass(JNIEnv*, jobject) { - return (jclass) 1; -} -static const char* s_fakeString = "Fake Java String"; -const jchar* env_getStringChars(JNIEnv*, jstring, jboolean* isCopy) { - if (isCopy) - *isCopy = false; - return (const jchar*)s_fakeString; -} -jsize env_getStringLength(JNIEnv*, jstring) { - return sizeof(s_fakeString) - 1; -} -jbyteArray env_newByteArray(JNIEnv*, jsize) { - return (jbyteArray) 1; -} -jobject env_newRef(JNIEnv*, jobject obj) { - return obj; -} -jobject env_newObjectV(JNIEnv*, jclass, jmethodID, va_list) { - return MY_JOBJECT; -} -jstring env_newString(JNIEnv*, const jchar*, jsize) { - return (jstring) 1; -} -void env_releaseByteArrayElements(JNIEnv*, jbyteArray, jbyte*, jint) {} -void env_releaseStringChars(JNIEnv*, jstring, const jchar*) {} -void env_setByteArrayRegion(JNIEnv*, jbyteArray, jsize, jsize, const jbyte*) {} -void env_setIntField(JNIEnv*, jobject, jfieldID, jint) {} - -void InitializeJavaVM() { - // First, create the fake vm - s_jvm = new JavaVM; - JNIInvokeInterface* i = new JNIInvokeInterface; - memset(i, 0, sizeof(JNIInvokeInterface)); - s_jvm->functions = i; - - // Now, assign the functions of the vm to our fake ones. - i->AttachCurrentThread = vm_attachCurrentThread; - - // Create the fake env next - s_env = new JNIEnv; - JNINativeInterface* n = new JNINativeInterface; - memset(n, 0, sizeof(JNINativeInterface)); - s_env->functions = n; - - // Point the functions we care about to out fake ones. - n->CallObjectMethodV = env_callObjectMethodV; - n->CallVoidMethodV = env_callVoidMethodV; - n->DeleteLocalRef = env_deleteRef; - n->DeleteGlobalRef = env_deleteRef; - n->DeleteWeakGlobalRef = env_deleteRef; - n->ExceptionCheck = env_exceptionCheck; - n->FindClass = env_findClass; - n->GetByteArrayElements = env_getByteArrayElements; - n->GetMethodID = env_getMethodID; - n->GetObjectClass = env_getObjectClass; - n->GetStringChars = env_getStringChars; - n->GetStringLength = env_getStringLength; - n->NewByteArray = env_newByteArray; - n->NewLocalRef = env_newRef; - n->NewGlobalRef = env_newRef; - n->NewWeakGlobalRef = env_newRef; - n->NewObjectV = env_newObjectV; - n->NewString = env_newString; - n->ReleaseByteArrayElements = env_releaseByteArrayElements; - n->ReleaseStringChars = env_releaseStringChars; - n->SetByteArrayRegion = env_setByteArrayRegion; - n->SetIntField = env_setIntField; - - // Tell WebCore about the vm - JSC::Bindings::setJavaVM(s_jvm); -} diff --git a/Source/WebKit/android/benchmark/MyJavaVM.h b/Source/WebKit/android/benchmark/MyJavaVM.h deleted file mode 100644 index 3092161..0000000 --- a/Source/WebKit/android/benchmark/MyJavaVM.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2009, The Android Open Source Project - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef MyJavaVM_h -#define MyJavaVM_h - -// Make it 1 just to appease any assertions or checks for valid objects -#define MY_JOBJECT ((jobject) 1) - -void InitializeJavaVM(); - -#endif diff --git a/Source/WebKit/android/benchmark/main.cpp b/Source/WebKit/android/benchmark/main.cpp deleted file mode 100644 index 0dcb80b..0000000 --- a/Source/WebKit/android/benchmark/main.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2009, The Android Open Source Project - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#define LOG_TAG "webcore_test" - -#include <stdlib.h> -#include <string.h> -#include <getopt.h> -#include <utils/Log.h> - -namespace android { -extern void benchmark(const char*, int, int ,int); -} - -int main(int argc, char** argv) { - int width = 800; - int height = 600; - int reloadCount = 0; - while (true) { - int c = getopt(argc, argv, "d:r:"); - if (c == -1) - break; - else if (c == 'd') { - char* x = strchr(optarg, 'x'); - if (x) { - width = atoi(optarg); - height = atoi(x + 1); - ALOGD("Rendering page at %dx%d", width, height); - } - } else if (c == 'r') { - reloadCount = atoi(optarg); - if (reloadCount < 0) - reloadCount = 0; - ALOGD("Reloading %d times", reloadCount); - } - } - if (optind >= argc) { - ALOGE("Please supply a file to read\n"); - return 1; - } - - android::benchmark(argv[optind], reloadCount, width, height); -} diff --git a/Source/WebKit/android/jni/AndroidHitTestResult.cpp b/Source/WebKit/android/jni/AndroidHitTestResult.cpp index 0a69007..6f94488 100644 --- a/Source/WebKit/android/jni/AndroidHitTestResult.cpp +++ b/Source/WebKit/android/jni/AndroidHitTestResult.cpp @@ -28,7 +28,9 @@ #include "config.h" #include "AndroidHitTestResult.h" +#include "Document.h" #include "Element.h" +#include "Frame.h" #include "HitTestResult.h" #include "KURL.h" #include "LayerAndroid.h" @@ -49,18 +51,19 @@ namespace android { using namespace WebCore; static bool gJniInitialized = false; -static struct JavaGlue { - jmethodID m_hitTestInit; - jfieldID m_hitTestLinkUrl; - jfieldID m_hitTestAnchorText; - jfieldID m_hitTestImageUrl; - jfieldID m_hitTestAltDisplayString; - jfieldID m_hitTestTitle; - jfieldID m_hitTestEditable; - jfieldID m_hitTestTouchRects; - jfieldID m_hitTestTapHighlightColor; - jfieldID m_hitTestEnclosingParentRects; -} gJavaGlue; +static struct { + jmethodID m_Init; + jfieldID m_LinkUrl; + jfieldID m_AnchorText; + jfieldID m_ImageUrl; + jfieldID m_AltDisplayString; + jfieldID m_Title; + jfieldID m_Editable; + jfieldID m_TouchRects; + jfieldID m_TapHighlightColor; + jfieldID m_EnclosingParentRects; + jfieldID m_HasFocus; +} gHitTestGlue; struct field { jclass m_class; @@ -79,19 +82,20 @@ static void InitJni(JNIEnv* env) jclass hitTestClass = env->FindClass("android/webkit/WebViewCore$WebKitHitTest"); ALOG_ASSERT(hitTestClass, "Could not find android/webkit/WebViewCore$WebKitHitTest"); - gJavaGlue.m_hitTestInit = env->GetMethodID(hitTestClass, "<init>", "()V"); - ALOG_ASSERT(gJavaGlue.m_hitTestInit, "Could not find init method on android/webkit/WebViewCore$WebKitHitTest"); + gHitTestGlue.m_Init = env->GetMethodID(hitTestClass, "<init>", "()V"); + ALOG_ASSERT(gHitTestGlue.m_Init, "Could not find init method on android/webkit/WebViewCore$WebKitHitTest"); field fields[] = { - { hitTestClass, "mTouchRects", "[Landroid/graphics/Rect;", &gJavaGlue.m_hitTestTouchRects }, - { hitTestClass, "mEditable", "Z", &gJavaGlue.m_hitTestEditable }, - { hitTestClass, "mLinkUrl", "Ljava/lang/String;", &gJavaGlue.m_hitTestLinkUrl }, - { hitTestClass, "mAnchorText", "Ljava/lang/String;", &gJavaGlue.m_hitTestAnchorText }, - { hitTestClass, "mImageUrl", "Ljava/lang/String;", &gJavaGlue.m_hitTestImageUrl }, - { hitTestClass, "mAltDisplayString", "Ljava/lang/String;", &gJavaGlue.m_hitTestAltDisplayString }, - { hitTestClass, "mTitle", "Ljava/lang/String;", &gJavaGlue.m_hitTestTitle }, - { hitTestClass, "mTapHighlightColor", "I", &gJavaGlue.m_hitTestTapHighlightColor }, - { hitTestClass, "mEnclosingParentRects", "[Landroid/graphics/Rect;", &gJavaGlue.m_hitTestEnclosingParentRects }, + { hitTestClass, "mTouchRects", "[Landroid/graphics/Rect;", &gHitTestGlue.m_TouchRects }, + { hitTestClass, "mEditable", "Z", &gHitTestGlue.m_Editable }, + { hitTestClass, "mLinkUrl", "Ljava/lang/String;", &gHitTestGlue.m_LinkUrl }, + { hitTestClass, "mAnchorText", "Ljava/lang/String;", &gHitTestGlue.m_AnchorText }, + { hitTestClass, "mImageUrl", "Ljava/lang/String;", &gHitTestGlue.m_ImageUrl }, + { hitTestClass, "mAltDisplayString", "Ljava/lang/String;", &gHitTestGlue.m_AltDisplayString }, + { hitTestClass, "mTitle", "Ljava/lang/String;", &gHitTestGlue.m_Title }, + { hitTestClass, "mTapHighlightColor", "I", &gHitTestGlue.m_TapHighlightColor }, + { hitTestClass, "mEnclosingParentRects", "[Landroid/graphics/Rect;", &gHitTestGlue.m_EnclosingParentRects }, + { hitTestClass, "mHasFocus", "Z", &gHitTestGlue.m_HasFocus }, {0, 0, 0, 0}, }; @@ -109,6 +113,33 @@ AndroidHitTestResult::AndroidHitTestResult(WebViewCore* webViewCore, WebCore::Hi : m_webViewCore(webViewCore) , m_hitTestResult(hitTestResult) { + buildHighlightRects(); +} + +void AndroidHitTestResult::setURLElement(Element* element) +{ + m_hitTestResult.setURLElement(element); + buildHighlightRects(); +} + +void AndroidHitTestResult::buildHighlightRects() +{ + m_highlightRects.clear(); + Node* node = m_hitTestResult.URLElement(); + if (!node || !node->renderer()) + node = m_hitTestResult.innerNode(); + if (!node || !node->renderer()) + return; + Frame* frame = node->document()->frame(); + IntPoint frameOffset = m_webViewCore->convertGlobalContentToFrameContent(IntPoint(), frame); + RenderObject* renderer = node->renderer(); + Vector<FloatQuad> quads; + renderer->absoluteFocusRingQuads(quads); + for (int i = 0; i < quads.size(); i++) { + IntRect boundingBox = quads[i].enclosingBoundingBox(); + boundingBox.move(-frameOffset.x(), -frameOffset.y()); + m_highlightRects.append(boundingBox); + } } void setStringField(JNIEnv* env, jobject obj, jfieldID field, const String& str) @@ -126,9 +157,9 @@ void setRectArray(JNIEnv* env, jobject obj, jfieldID field, Vector<IntRect> &rec } // Some helper macros specific to setting hitTest fields -#define _SET(jtype, jfield, value) env->Set ## jtype ## Field(hitTest, gJavaGlue.m_hitTest ## jfield, value) +#define _SET(jtype, jfield, value) env->Set ## jtype ## Field(hitTest, gHitTestGlue.m_ ## jfield, value) #define SET_BOOL(jfield, value) _SET(Boolean, jfield, value) -#define SET_STRING(jfield, value) setStringField(env, hitTest, gJavaGlue.m_hitTest ## jfield, value) +#define SET_STRING(jfield, value) setStringField(env, hitTest, gHitTestGlue.m_ ## jfield, value) #define SET_INT(jfield, value) _SET(Int, jfield, value) jobject AndroidHitTestResult::createJavaObject(JNIEnv* env) @@ -137,11 +168,11 @@ jobject AndroidHitTestResult::createJavaObject(JNIEnv* env) jclass hitTestClass = env->FindClass("android/webkit/WebViewCore$WebKitHitTest"); ALOG_ASSERT(hitTestClass, "Could not find android/webkit/WebViewCore$WebKitHitTest"); - jobject hitTest = env->NewObject(hitTestClass, gJavaGlue.m_hitTestInit); - setRectArray(env, hitTest, gJavaGlue.m_hitTestTouchRects, m_highlightRects); + jobject hitTest = env->NewObject(hitTestClass, gHitTestGlue.m_Init); + setRectArray(env, hitTest, gHitTestGlue.m_TouchRects, m_highlightRects); Vector<IntRect> rects = enclosingParentRects(m_hitTestResult.innerNode()); - setRectArray(env, hitTest, gJavaGlue.m_hitTestEnclosingParentRects, rects); + setRectArray(env, hitTest, gHitTestGlue.m_EnclosingParentRects, rects); SET_BOOL(Editable, m_hitTestResult.isContentEditable()); SET_STRING(LinkUrl, m_hitTestResult.absoluteLinkURL().string()); @@ -157,6 +188,11 @@ jobject AndroidHitTestResult::createJavaObject(JNIEnv* env) urlElement->renderer()->style()->tapHighlightColor().rgb()); } } + Node* focusedNode = m_webViewCore->focusedFrame()->document()->focusedNode(); + SET_BOOL(HasFocus, + focusedNode == m_hitTestResult.URLElement() + || focusedNode == m_hitTestResult.innerNode() + || focusedNode == m_hitTestResult.innerNonSharedNode()); env->DeleteLocalRef(hitTestClass); diff --git a/Source/WebKit/android/jni/AndroidHitTestResult.h b/Source/WebKit/android/jni/AndroidHitTestResult.h index e4233fd..f9709ac 100644 --- a/Source/WebKit/android/jni/AndroidHitTestResult.h +++ b/Source/WebKit/android/jni/AndroidHitTestResult.h @@ -26,6 +26,7 @@ #ifndef AndroidHitTestResult_h #define AndroidHitTestResult_h +#include "Element.h" #include "HitTestResult.h" #include "IntRect.h" #include "wtf/Vector.h" @@ -45,6 +46,9 @@ public: WebCore::HitTestResult& hitTestResult() { return m_hitTestResult; } Vector<WebCore::IntRect>& highlightRects() { return m_highlightRects; } + void setURLElement(WebCore::Element* element); + void buildHighlightRects(); + jobject createJavaObject(JNIEnv*); private: diff --git a/Source/WebKit/android/jni/WebCoreFrameBridge.cpp b/Source/WebKit/android/jni/WebCoreFrameBridge.cpp index 50c1fb2..2724d6b 100644 --- a/Source/WebKit/android/jni/WebCoreFrameBridge.cpp +++ b/Source/WebKit/android/jni/WebCoreFrameBridge.cpp @@ -1703,16 +1703,6 @@ static void AddJavascriptInterface(JNIEnv *env, jobject obj, jint nativeFramePoi } } -static void SetCacheDisabled(JNIEnv *env, jobject obj, jboolean disabled) -{ - WebCore::memoryCache()->setDisabled(disabled); -} - -static jboolean CacheDisabled(JNIEnv *env, jobject obj) -{ - return WebCore::memoryCache()->disabled(); -} - static void ClearWebCoreCache() { if (!WebCore::memoryCache()->disabled()) { @@ -2084,10 +2074,6 @@ static JNINativeMethod gBrowserFrameNativeMethods[] = { { "stringByEvaluatingJavaScriptFromString", "(Ljava/lang/String;)Ljava/lang/String;", (void*) StringByEvaluatingJavaScriptFromString }, - { "setCacheDisabled", "(Z)V", - (void*) SetCacheDisabled }, - { "cacheDisabled", "()Z", - (void*) CacheDisabled }, { "clearCache", "()V", (void*) ClearCache }, { "documentHasImages", "()Z", diff --git a/Source/WebKit/android/jni/WebCoreJniOnLoad.cpp b/Source/WebKit/android/jni/WebCoreJniOnLoad.cpp index fb959ac..64aeb7e 100644 --- a/Source/WebKit/android/jni/WebCoreJniOnLoad.cpp +++ b/Source/WebKit/android/jni/WebCoreJniOnLoad.cpp @@ -62,8 +62,6 @@ #include "WebCoreViewBridge.h" #include "WebFrameView.h" #include "WebViewCore.h" -#include "benchmark/Intercept.h" -#include "benchmark/MyJavaVM.h" #include <JNIUtility.h> #include <jni.h> @@ -162,160 +160,3 @@ EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) return JNI_VERSION_1_4; } - -class MyJavaSharedClient : public TimerClient, public CookieClient { -public: - MyJavaSharedClient() : m_hasTimer(false) {} - virtual void setSharedTimer(long long timemillis) { m_hasTimer = true; } - virtual void stopSharedTimer() { m_hasTimer = false; } - virtual void setSharedTimerCallback(void (*f)()) { m_func = f; } - virtual void signalServiceFuncPtrQueue() {} - - // Cookie methods that do nothing. - virtual void setCookies(const KURL&, const String&) {} - virtual String cookies(const KURL&) { return ""; } - virtual bool cookiesEnabled() { return false; } - - bool m_hasTimer; - void (*m_func)(); -}; - -static void historyItemChanged(HistoryItem* i) { - if (i->bridge()) - i->bridge()->updateHistoryItem(i); -} - -namespace android { - -EXPORT void benchmark(const char* url, int reloadCount, int width, int height) { - ScriptController::initializeThreading(); - - // Setting this allows data: urls to load from a local file. - SecurityOrigin::setLocalLoadPolicy(SecurityOrigin::AllowLocalLoadsForAll); - - // Create the fake JNIEnv and JavaVM - InitializeJavaVM(); - - // The real function is private to libwebcore but we know what it does. - notifyHistoryItemChanged = historyItemChanged; - - // Implement the shared timer callback - MyJavaSharedClient client; - JavaSharedClient::SetTimerClient(&client); - JavaSharedClient::SetCookieClient(&client); - - // Create the page with all the various clients - ChromeClientAndroid* chrome = new ChromeClientAndroid; - EditorClientAndroid* editor = new EditorClientAndroid; - DeviceMotionClientAndroid* deviceMotion = new DeviceMotionClientAndroid; - DeviceOrientationClientAndroid* deviceOrientation = new DeviceOrientationClientAndroid; - WebCore::Page::PageClients pageClients; - pageClients.chromeClient = chrome; - pageClients.contextMenuClient = new ContextMenuClientAndroid; - pageClients.editorClient = editor; - pageClients.dragClient = new DragClientAndroid; - pageClients.inspectorClient = new InspectorClientAndroid; - pageClients.deviceMotionClient = deviceMotion; - pageClients.deviceOrientationClient = deviceOrientation; - WebCore::Page* page = new WebCore::Page(pageClients); - editor->setPage(page); - - // Create MyWebFrame that intercepts network requests - MyWebFrame* webFrame = new MyWebFrame(page); - webFrame->setUserAgent("Performance testing"); // needs to be non-empty - chrome->setWebFrame(webFrame); - // ChromeClientAndroid maintains the reference. - Release(webFrame); - - // Create the Frame and the FrameLoaderClient - FrameLoaderClientAndroid* loader = new FrameLoaderClientAndroid(webFrame); - RefPtr<Frame> frame = Frame::create(page, NULL, loader); - loader->setFrame(frame.get()); - - // Build our View system, resize it to the given dimensions and release our - // references. Note: We keep a referenec to frameView so we can layout and - // draw later without risk of it being deleted. - WebViewCore* webViewCore = new WebViewCore(JSC::Bindings::getJNIEnv(), - MY_JOBJECT, frame.get()); - RefPtr<FrameView> frameView = FrameView::create(frame.get()); - WebFrameView* webFrameView = new WebFrameView(frameView.get(), webViewCore); - frame->setView(frameView); - frameView->resize(width, height); - Release(webViewCore); - Release(webFrameView); - - // Initialize the frame and turn of low-bandwidth display (it fails an - // assertion in the Cache code) - frame->init(); - frame->selection()->setFocused(true); - frame->page()->focusController()->setFocused(true); - - deviceMotion->setWebViewCore(webViewCore); - deviceOrientation->setWebViewCore(webViewCore); - - // Set all the default settings the Browser normally uses. - Settings* s = frame->settings(); -#ifdef ANDROID_LAYOUT - s->setLayoutAlgorithm(Settings::kLayoutNormal); // Normal layout for now -#endif - s->setStandardFontFamily("sans-serif"); - s->setFixedFontFamily("monospace"); - s->setSansSerifFontFamily("sans-serif"); - s->setSerifFontFamily("serif"); - s->setCursiveFontFamily("cursive"); - s->setFantasyFontFamily("fantasy"); - s->setMinimumFontSize(8); - s->setMinimumLogicalFontSize(8); - s->setDefaultFontSize(16); - s->setDefaultFixedFontSize(13); - s->setLoadsImagesAutomatically(true); - s->setJavaScriptEnabled(true); - s->setDefaultTextEncodingName("latin1"); - s->setPluginsEnabled(false); - s->setShrinksStandaloneImagesToFit(false); -#ifdef ANDROID_LAYOUT - s->setUseWideViewport(false); -#endif - - // Finally, load the actual data - ResourceRequest req(url); - frame->loader()->load(req, false); - - do { - // Layout the page and service the timer - frame->view()->layout(); - while (client.m_hasTimer) { - client.m_func(); - JavaSharedClient::ServiceFunctionPtrQueue(); - } - JavaSharedClient::ServiceFunctionPtrQueue(); - - // Layout more if needed. - while (frame->view()->needsLayout()) - frame->view()->layout(); - JavaSharedClient::ServiceFunctionPtrQueue(); - - if (reloadCount) - frame->loader()->reload(true); - } while (reloadCount--); - - // Draw into an offscreen bitmap - SkBitmap bmp; - bmp.setConfig(SkBitmap::kARGB_8888_Config, width, height); - bmp.allocPixels(); - SkCanvas canvas(bmp); - PlatformGraphicsContext ctx(&canvas); - GraphicsContext gc(&ctx); - frame->view()->paintContents(&gc, IntRect(0, 0, width, height)); - - // Write the bitmap to the sdcard - SkImageEncoder* enc = SkImageEncoder::Create(SkImageEncoder::kPNG_Type); - enc->encodeFile("/sdcard/webcore_test.png", bmp, 100); - delete enc; - - // Tear down the world. - frame->loader()->detachFromParent(); - delete page; -} - -} // namespace android diff --git a/Source/WebKit/android/jni/WebViewCore.cpp b/Source/WebKit/android/jni/WebViewCore.cpp index 8d819b2..4efe0d5 100644 --- a/Source/WebKit/android/jni/WebViewCore.cpp +++ b/Source/WebKit/android/jni/WebViewCore.cpp @@ -44,6 +44,7 @@ #include "CSSValueKeywords.h" #include "DatabaseTracker.h" #include "Document.h" +#include "DocumentMarkerController.h" #include "DOMWindow.h" #include "DOMSelection.h" #include "Element.h" @@ -296,7 +297,6 @@ struct WebViewCore::JavaGlue { jmethodID m_destroySurface; jmethodID m_getContext; jmethodID m_keepScreenOn; - jmethodID m_sendFindAgain; jmethodID m_showRect; jmethodID m_centerFitRect; jmethodID m_setScrollbarModes; @@ -306,6 +306,7 @@ struct WebViewCore::JavaGlue { jmethodID m_setWebTextViewAutoFillable; jmethodID m_selectAt; jmethodID m_initEditField; + jmethodID m_updateMatchCount; AutoJObject object(JNIEnv* env) { // We hold a weak reference to the Java WebViewCore to avoid memeory // leaks due to circular references when WebView.destroy() is not @@ -374,6 +375,9 @@ WebViewCore::WebViewCore(JNIEnv* env, jobject javaWebViewCore, WebCore::Frame* m , m_isPaused(false) , m_cacheMode(0) , m_fullscreenVideoMode(false) + , m_matchCount(0) + , m_activeMatchIndex(0) + , m_activeMatch(0) , m_pluginInvalTimer(this, &WebViewCore::pluginInvalTimerFired) , m_screenOnCounter(0) , m_currentNodeDomNavigationAxis(0) @@ -429,7 +433,6 @@ WebViewCore::WebViewCore(JNIEnv* env, jobject javaWebViewCore, WebCore::Frame* m m_javaGlue->m_destroySurface = GetJMethod(env, clazz, "destroySurface", "(Landroid/webkit/ViewManager$ChildView;)V"); m_javaGlue->m_getContext = GetJMethod(env, clazz, "getContext", "()Landroid/content/Context;"); m_javaGlue->m_keepScreenOn = GetJMethod(env, clazz, "keepScreenOn", "(Z)V"); - m_javaGlue->m_sendFindAgain = GetJMethod(env, clazz, "sendFindAgain", "()V"); m_javaGlue->m_showRect = GetJMethod(env, clazz, "showRect", "(IIIIIIFFFF)V"); m_javaGlue->m_centerFitRect = GetJMethod(env, clazz, "centerFitRect", "(IIII)V"); m_javaGlue->m_setScrollbarModes = GetJMethod(env, clazz, "setScrollbarModes", "(II)V"); @@ -441,6 +444,7 @@ WebViewCore::WebViewCore(JNIEnv* env, jobject javaWebViewCore, WebCore::Frame* m m_javaGlue->m_setWebTextViewAutoFillable = GetJMethod(env, clazz, "setWebTextViewAutoFillable", "(ILjava/lang/String;)V"); m_javaGlue->m_selectAt = GetJMethod(env, clazz, "selectAt", "(II)V"); m_javaGlue->m_initEditField = GetJMethod(env, clazz, "initEditField", "(ILjava/lang/String;II)V"); + m_javaGlue->m_updateMatchCount = GetJMethod(env, clazz, "updateMatchCount", "(IILjava/lang/String;)V"); env->DeleteLocalRef(clazz); env->SetIntField(javaWebViewCore, gWebViewCoreFields.m_nativeClass, (jint)this); @@ -748,15 +752,6 @@ void WebViewCore::recordPictureSet(PictureSet* content) DBG_NAV_LOG("call updateFrameCache"); updateFrameCache(); #endif - if (m_findIsUp) { - ALOG_ASSERT(m_javaGlue->m_obj, "A Java widget was not associated with this view bridge!"); - JNIEnv* env = JSC::Bindings::getJNIEnv(); - AutoJObject javaObject = m_javaGlue->object(env); - if (javaObject.get()) { - env->CallVoidMethod(javaObject.get(), m_javaGlue->m_sendFindAgain); - checkException(env); - } - } } // note: updateCursorBounds is called directly by the WebView thread @@ -1630,7 +1625,7 @@ static IntRect getAbsoluteBoundingBox(Node* node) { rect = toRenderText(render)->linesBoundingBox(); else ALOGE("getAbsoluteBoundingBox failed for node %p, name %s", node, render->renderName()); - FloatPoint absPos = render->localToAbsolute(); + FloatPoint absPos = render->localToAbsolute(FloatPoint(), false, true); rect.move(absPos.x(), absPos.y()); return rect; } @@ -2010,7 +2005,7 @@ AndroidHitTestResult WebViewCore::hitTestAtPoint(int x, int y, int slop, bool do IntRect rect = n->mBounds; rect.intersect(testRect); int a = rect.width() * rect.height(); - if (a > area) { + if (a > area || !final.mUrlNode) { final = *n; area = a; } @@ -2019,9 +2014,9 @@ AndroidHitTestResult WebViewCore::hitTestAtPoint(int x, int y, int slop, bool do if (final.mUrlNode) { if (final.mUrlNode->isElementNode()) { // We found a URL element. Update the hitTestResult - androidHitResult.hitTestResult().setURLElement(static_cast<Element*>(final.mUrlNode)); + androidHitResult.setURLElement(static_cast<Element*>(final.mUrlNode)); } else { - androidHitResult.hitTestResult().setURLElement(0); + androidHitResult.setURLElement(0); } // Update innerNode and innerNonSharedNode androidHitResult.hitTestResult().setInnerNode(final.mInnerNode); @@ -2031,81 +2026,8 @@ AndroidHitTestResult WebViewCore::hitTestAtPoint(int x, int y, int slop, bool do frameAdjust = frame->view()->contentsToWindow(IntPoint()); frameAdjust.move(m_scrollOffsetX, m_scrollOffsetY); } - Vector<IntRect>& rects = androidHitResult.highlightRects(); - if (final.mUrlNode->isLink() && final.mUrlNode->renderer()) { - // most of the links are inline instead of box style. So the bounding box is not - // a good representation for the highlights. Get the list of rectangles instead. - RenderObject* render = final.mUrlNode->renderer(); - IntPoint offset = roundedIntPoint(render->localToAbsolute()); - render->absoluteRects(rects, offset.x() + frameAdjust.x(), offset.y() + frameAdjust.y()); - if (final.mInnerNode && final.mInnerNode->renderer()) { - final.mInnerNode->renderer()->absoluteRects(rects, - offset.x() + frameAdjust.x(), offset.y() + frameAdjust.y()); - } - bool inside = false; - int distance = INT_MAX; - int newx = x, newy = y; - int i = rects.size(); - while (i--) { - if (rects[i].isEmpty()) { - rects.remove(i); - continue; - } - // check whether the point (x, y) is inside one of the rectangles. - if (inside) - continue; - if (rects[i].contains(x, y)) { - inside = true; - continue; - } - if (x >= rects[i].x() && x < rects[i].maxX()) { - if (y < rects[i].y()) { - if (rects[i].y() - y < distance) { - newx = x; - newy = rects[i].y(); - distance = rects[i].y() - y; - } - } else if (y >= rects[i].maxY()) { - if (y - rects[i].maxY() + 1 < distance) { - newx = x; - newy = rects[i].maxY() - 1; - distance = y - rects[i].maxY() + 1; - } - } - } else if (y >= rects[i].y() && y < rects[i].maxY()) { - if (x < rects[i].x()) { - if (rects[i].x() - x < distance) { - newx = rects[i].x(); - newy = y; - distance = rects[i].x() - x; - } - } else if (x >= rects[i].maxX()) { - if (x - rects[i].maxX() + 1 < distance) { - newx = rects[i].maxX() - 1; - newy = y; - distance = x - rects[i].maxX() + 1; - } - } - } - } - if (!rects.isEmpty()) { - if (!inside && doMoveMouse) { - // if neither x nor y has overlap, just pick the top/left of the first rectangle - if (newx == x && newy == y) { - newx = rects[0].x(); - newy = rects[0].y(); - } - moveMouse(m_mainFrame, newx, newy); - DBG_NAV_LOGD("Move x/y from (%d, %d) to (%d, %d) scrollOffset is (%d, %d)", - x, y, m_mousePos.x() + m_scrollOffsetX, m_mousePos.y() + m_scrollOffsetY, - m_scrollOffsetX, m_scrollOffsetY); - } - return androidHitResult; - } - } IntRect rect = final.mBounds; rect.move(frameAdjust.x(), frameAdjust.y()); - rects.append(rect); if (doMoveMouse) { // adjust m_mousePos if it is not inside the returned highlight rectangle testRect.move(frameAdjust.x(), frameAdjust.y()); @@ -3682,7 +3604,6 @@ void WebViewCore::focusNodeChanged(WebCore::Node* newFocus) } } AndroidHitTestResult androidHitTest(this, focusHitResult); - androidHitTest.highlightRects(); jobject jHitTestObj = androidHitTest.createJavaObject(env); env->CallVoidMethod(javaObject.get(), m_javaGlue->m_focusNodeChanged, jHitTestObj); env->DeleteLocalRef(jHitTestObj); @@ -4357,6 +4278,109 @@ void WebViewCore::insertText(const WTF::String &text) client->setUiGeneratedSelectionChange(false); } +void WebViewCore::resetFindOnPage() +{ + m_searchText.truncate(0); + m_matchCount = 0; + m_activeMatchIndex = 0; + m_activeMatch = 0; +} + +int WebViewCore::findTextOnPage(const WTF::String &text) +{ + resetFindOnPage(); // reset even if parameters are bad + + WebCore::Frame* frame = m_mainFrame; + if (!frame) + return 0; + + m_searchText = text; + FindOptions findOptions = WebCore::CaseInsensitive; + + do { + frame->document()->markers()->removeMarkers(DocumentMarker::TextMatch); + m_matchCount += frame->editor()->countMatchesForText(text, findOptions, + 0, true); + updateMatchCount(); + frame->editor()->setMarkedTextMatchesAreHighlighted(true); + frame = frame->tree()->traverseNextWithWrap(false); + } while (frame); + + m_activeMatchIndex = m_matchCount - 1; // prime first findNext + findNextOnPage(true); + return m_matchCount; +} + +void WebViewCore::findNextOnPage(bool forward) +{ + if (!m_mainFrame) + return; + if (!m_matchCount) + return; + + EditorClientAndroid* client = static_cast<EditorClientAndroid*>( + m_mainFrame->editor()->client()); + client->setUiGeneratedSelectionChange(true); + + // Clear previous active match. + if (m_activeMatch) { + m_mainFrame->document()->markers()->setMarkersActive( + m_activeMatch.get(), false); + } + + FindOptions findOptions = WebCore::CaseInsensitive + | WebCore::StartInSelection | WebCore::WrapAround; + if (!forward) + findOptions |= WebCore::Backwards; + + // Start from the previous active match. + if (m_activeMatch) { + m_mainFrame->selection()->setSelection(m_activeMatch.get()); + } + + bool found = m_mainFrame->editor()->findString(m_searchText, findOptions); + if (found) { + VisibleSelection selection(m_mainFrame->selection()->selection()); + if (selection.isNone() || selection.start() == selection.end()) { + // Temporary workaround for findString() refusing to select text + // marked "-webkit-user-select: none". + m_activeMatchIndex = 0; + m_activeMatch = 0; + } else { + // Mark current match "active". + if (forward) { + ++m_activeMatchIndex; + if (m_activeMatchIndex == m_matchCount) + m_activeMatchIndex = 0; + } else { + if (m_activeMatchIndex == 0) + m_activeMatchIndex = m_matchCount; + --m_activeMatchIndex; + } + m_activeMatch = selection.firstRange(); + m_mainFrame->document()->markers()->setMarkersActive( + m_activeMatch.get(), true); + } + updateMatchCount(); + } + + // Clear selection so it doesn't display. + m_mainFrame->selection()->clear(); + client->setUiGeneratedSelectionChange(false); +} + +void WebViewCore::updateMatchCount() const +{ + JNIEnv* env = JSC::Bindings::getJNIEnv(); + AutoJObject javaObject = m_javaGlue->object(env); + if (!javaObject.get()) + return; + jstring javaText = wtfStringToJstring(env, m_searchText, true); + env->CallVoidMethod(javaObject.get(), m_javaGlue->m_updateMatchCount, + m_activeMatchIndex, m_matchCount, javaText); + checkException(env); +} + String WebViewCore::getText(int startX, int startY, int endX, int endY) { String text; @@ -5056,6 +5080,21 @@ static void SelectAll(JNIEnv* env, jobject obj, jint nativeClass) viewImpl->focusedFrame()->selection()->selectAll(); } +static int FindAll(JNIEnv* env, jobject obj, jint nativeClass, + jstring text) +{ + WebViewCore* viewImpl = reinterpret_cast<WebViewCore*>(nativeClass); + WTF::String wtfText = jstringToWtfString(env, text); + return viewImpl->findTextOnPage(wtfText); +} + +static void FindNext(JNIEnv* env, jobject obj, jint nativeClass, + jboolean forward) +{ + WebViewCore* viewImpl = reinterpret_cast<WebViewCore*>(nativeClass); + viewImpl->findNextOnPage(forward); +} + // ---------------------------------------------------------------------------- /* @@ -5186,6 +5225,10 @@ static JNINativeMethod gJavaWebViewCoreMethods[] = { (void*) SelectAll }, { "nativeCertTrustChanged","()V", (void*) nativeCertTrustChanged }, + { "nativeFindAll", "(ILjava/lang/String;)I", + (void*) FindAll }, + { "nativeFindNext", "(IZ)V", + (void*) FindNext }, }; int registerWebViewCore(JNIEnv* env) diff --git a/Source/WebKit/android/jni/WebViewCore.h b/Source/WebKit/android/jni/WebViewCore.h index 952e39d..315b024 100644 --- a/Source/WebKit/android/jni/WebViewCore.h +++ b/Source/WebKit/android/jni/WebViewCore.h @@ -152,7 +152,7 @@ namespace android { * * This method calls Java to trigger a gradual scroll event. */ - void scrollTo(int x, int y, bool animate = false); + void scrollTo(int x, int y, bool animate = true); /** * Record the invalid rectangle @@ -560,6 +560,12 @@ namespace android { WTF::String getText(int startX, int startY, int endX, int endY); void insertText(const WTF::String &text); + // find on page + void resetFindOnPage(); + int findTextOnPage(const WTF::String &text); + void findNextOnPage(bool forward); + void updateMatchCount() const; + #if ENABLE(VIDEO) void enterFullscreenForVideoLayer(int layerId, const WTF::String& url); void exitFullscreenVideo(); @@ -757,6 +763,12 @@ namespace android { int m_cacheMode; bool m_fullscreenVideoMode; + // find on page data + WTF::String m_searchText; + int m_matchCount; + int m_activeMatchIndex; + RefPtr<WebCore::Range> m_activeMatch; + SkTDArray<PluginWidgetAndroid*> m_plugins; WebCore::Timer<WebViewCore> m_pluginInvalTimer; void pluginInvalTimerFired(WebCore::Timer<WebViewCore>*) { diff --git a/Source/WebKit/android/nav/FindCanvas.cpp b/Source/WebKit/android/nav/FindCanvas.cpp deleted file mode 100644 index dca9a75..0000000 --- a/Source/WebKit/android/nav/FindCanvas.cpp +++ /dev/null @@ -1,715 +0,0 @@ -/* - * Copyright 2008, The Android Open Source Project - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#define LOG_TAG "webviewglue" - -#include "config.h" -#include "FindCanvas.h" -#include "LayerAndroid.h" -#include "IntRect.h" -#include "SelectText.h" -#include "SkBlurMaskFilter.h" -#include "SkCornerPathEffect.h" -#include "SkRect.h" -#include "SkUtils.h" - -#include <utils/Log.h> - -#define INTEGER_OUTSET 2 - -namespace android { - -// MatchInfo methods -//////////////////////////////////////////////////////////////////////////////// - -MatchInfo::MatchInfo() { - m_picture = 0; -} - -MatchInfo::~MatchInfo() { - SkSafeUnref(m_picture); -} - -MatchInfo::MatchInfo(const MatchInfo& src) { - m_layerId = src.m_layerId; - m_location = src.m_location; - m_picture = src.m_picture; - SkSafeRef(m_picture); -} - -void MatchInfo::set(const SkRegion& region, SkPicture* pic, int layerId) { - SkSafeUnref(m_picture); - m_layerId = layerId; - m_location = region; - m_picture = pic; - SkASSERT(pic); - pic->ref(); -} - -// GlyphSet methods -//////////////////////////////////////////////////////////////////////////////// - -GlyphSet::GlyphSet(const SkPaint& paint, const UChar* lower, const UChar* upper, - size_t byteLength) { - SkPaint clonePaint(paint); - clonePaint.setTextEncoding(SkPaint::kUTF16_TextEncoding); - mTypeface = paint.getTypeface(); - mCount = clonePaint.textToGlyphs(lower, byteLength, NULL); - if (mCount > MAX_STORAGE_COUNT) { - mLowerGlyphs = new uint16_t[2*mCount]; - } else { - mLowerGlyphs = &mStorage[0]; - } - // Use one array, and have mUpperGlyphs point to a portion of it, - // so that we can reduce the number of new/deletes - mUpperGlyphs = mLowerGlyphs + mCount; - int count2 = clonePaint.textToGlyphs(lower, byteLength, mLowerGlyphs); - SkASSERT(mCount == count2); - count2 = clonePaint.textToGlyphs(upper, byteLength, mUpperGlyphs); - SkASSERT(mCount == count2); -} - -GlyphSet::~GlyphSet() { - // Do not need to delete mTypeface, which is not owned by us. - if (mCount > MAX_STORAGE_COUNT) { - delete[] mLowerGlyphs; - } // Otherwise, we just used local storage space, so no need to delete - // Also do not need to delete mUpperGlyphs, which simply points to a - // part of mLowerGlyphs -} - -GlyphSet& GlyphSet::operator=(GlyphSet& src) { - mTypeface = src.mTypeface; - mCount = src.mCount; - if (mCount > MAX_STORAGE_COUNT) { - mLowerGlyphs = new uint16_t[2*mCount]; - } else { - mLowerGlyphs = &mStorage[0]; - } - memcpy(mLowerGlyphs, src.mLowerGlyphs, 2*mCount*sizeof(uint16_t)); - mUpperGlyphs = mLowerGlyphs + mCount; - return *this; -} - -bool GlyphSet::characterMatches(uint16_t c, int index) { - SkASSERT(index < mCount && index >= 0); - return c == mLowerGlyphs[index] || c == mUpperGlyphs[index]; -} - -// FindCanvas methods -//////////////////////////////////////////////////////////////////////////////// - -FindCanvas::FindCanvas(int width, int height, const UChar* lower, - const UChar* upper, size_t byteLength) - : mLowerText(lower) - , mUpperText(upper) - , mLength(byteLength) - , mNumFound(0) { - // the text has been provided in read order. Reverse as needed so the - // result contains left-to-right characters. - const uint16_t* start = mLowerText; - size_t count = byteLength >> 1; - const uint16_t* end = mLowerText + count; - while (start < end) { - SkUnichar ch = SkUTF16_NextUnichar(&start); - WTF::Unicode::Direction charDirection = WTF::Unicode::direction(ch); - if (WTF::Unicode::RightToLeftArabic == charDirection - || WTF::Unicode::RightToLeft == charDirection) { - mLowerReversed.clear(); - mLowerReversed.append(mLowerText, count); - WebCore::ReverseBidi(mLowerReversed.begin(), count); - mLowerText = mLowerReversed.begin(); - mUpperReversed.clear(); - mUpperReversed.append(mUpperText, count); - WebCore::ReverseBidi(mUpperReversed.begin(), count); - mUpperText = mUpperReversed.begin(); - break; - } - } - - setBounder(&mBounder); - mOutset = -SkIntToScalar(INTEGER_OUTSET); - mMatches = new WTF::Vector<MatchInfo>(); - mWorkingIndex = 0; - mWorkingCanvas = 0; - mWorkingPicture = 0; -} - -FindCanvas::~FindCanvas() { - setBounder(NULL); - /* Just in case getAndClear was not called. */ - delete mMatches; - SkSafeUnref(mWorkingPicture); -} - -// Each version of addMatch returns a rectangle for a match. -// Not all of the parameters are used by each version. -SkRect FindCanvas::addMatchNormal(int index, - const SkPaint& paint, int count, const uint16_t* glyphs, - const SkScalar pos[], SkScalar y) { - const uint16_t* lineStart = glyphs - index; - /* Use the original paint, since "text" is in glyphs */ - SkScalar before = paint.measureText(lineStart, index * sizeof(uint16_t), 0); - SkRect rect; - rect.fLeft = pos[0] + before; - int countInBytes = count * sizeof(uint16_t); - rect.fRight = paint.measureText(glyphs, countInBytes, 0) + rect.fLeft; - SkPaint::FontMetrics fontMetrics; - paint.getFontMetrics(&fontMetrics); - SkScalar baseline = y; - rect.fTop = baseline + fontMetrics.fAscent; - rect.fBottom = baseline + fontMetrics.fDescent; - const SkMatrix& matrix = getTotalMatrix(); - matrix.mapRect(&rect); - // Add the text to our picture. - SkCanvas* canvas = getWorkingCanvas(); - int saveCount = canvas->save(); - canvas->concat(matrix); - canvas->drawText(glyphs, countInBytes, pos[0] + before, y, paint); - canvas->restoreToCount(saveCount); - return rect; -} - -SkRect FindCanvas::addMatchPos(int index, - const SkPaint& paint, int count, const uint16_t* glyphs, - const SkScalar xPos[], SkScalar /* y */) { - SkRect r; - r.setEmpty(); - const SkPoint* temp = reinterpret_cast<const SkPoint*> (xPos); - const SkPoint* points = &temp[index]; - int countInBytes = count * sizeof(uint16_t); - SkPaint::FontMetrics fontMetrics; - paint.getFontMetrics(&fontMetrics); - // Need to check each character individually, since the heights may be - // different. - for (int j = 0; j < count; j++) { - SkRect bounds; - bounds.fLeft = points[j].fX; - bounds.fRight = bounds.fLeft + - paint.measureText(&glyphs[j], sizeof(uint16_t), 0); - SkScalar baseline = points[j].fY; - bounds.fTop = baseline + fontMetrics.fAscent; - bounds.fBottom = baseline + fontMetrics.fDescent; - /* Accumulate and then add the resulting rect to mMatches */ - r.join(bounds); - } - SkMatrix matrix = getTotalMatrix(); - matrix.mapRect(&r); - SkCanvas* canvas = getWorkingCanvas(); - int saveCount = canvas->save(); - canvas->concat(matrix); - canvas->drawPosText(glyphs, countInBytes, points, paint); - canvas->restoreToCount(saveCount); - return r; -} - -SkRect FindCanvas::addMatchPosH(int index, - const SkPaint& paint, int count, const uint16_t* glyphs, - const SkScalar position[], SkScalar constY) { - SkRect r; - // We only care about the positions starting at the index of our match - const SkScalar* xPos = &position[index]; - // This assumes that the position array is monotonic increasing - // The left bounds will be the position of the left most character - r.fLeft = xPos[0]; - // The right bounds will be the position of the last character plus its - // width - int lastIndex = count - 1; - r.fRight = paint.measureText(&glyphs[lastIndex], sizeof(uint16_t), 0) - + xPos[lastIndex]; - // Grab font metrics to determine the top and bottom of the bounds - SkPaint::FontMetrics fontMetrics; - paint.getFontMetrics(&fontMetrics); - r.fTop = constY + fontMetrics.fAscent; - r.fBottom = constY + fontMetrics.fDescent; - const SkMatrix& matrix = getTotalMatrix(); - matrix.mapRect(&r); - SkCanvas* canvas = getWorkingCanvas(); - int saveCount = canvas->save(); - canvas->concat(matrix); - canvas->drawPosTextH(glyphs, count * sizeof(uint16_t), xPos, constY, paint); - canvas->restoreToCount(saveCount); - return r; -} - -void FindCanvas::drawLayers(LayerAndroid* layer, FindOnPage& findOnPage) { -#if USE(ACCELERATED_COMPOSITING) - int layerId = layer->uniqueId(); - unsigned matchesBegin = found(); - SkPicture* picture = layer->picture(); - if (picture) { - setLayerId(layerId); - drawPicture(*picture); - } - findOnPage.setLayerMatchRange(layerId, - std::pair<unsigned, unsigned>(matchesBegin, found())); - for (int i = 0; i < layer->countChildren(); i++) - drawLayers(layer->getChild(i), findOnPage); -#endif -} - -void FindCanvas::drawText(const void* text, size_t byteLength, SkScalar x, - SkScalar y, const SkPaint& paint) { - findHelper(text, byteLength, paint, &x, y, &FindCanvas::addMatchNormal); -} - -void FindCanvas::drawPosText(const void* text, size_t byteLength, - const SkPoint pos[], const SkPaint& paint) { - // Pass in the first y coordinate for y so that we can check to see whether - // it is lower than the last draw call (to check if we are continuing to - // another line). - findHelper(text, byteLength, paint, (const SkScalar*) pos, pos[0].fY, - &FindCanvas::addMatchPos); -} - -void FindCanvas::drawPosTextH(const void* text, size_t byteLength, - const SkScalar xpos[], SkScalar constY, - const SkPaint& paint) { - findHelper(text, byteLength, paint, xpos, constY, - &FindCanvas::addMatchPosH); -} - -/* The current behavior is to skip substring matches. This means that in the - * string - * batbatbat - * a search for - * batbat - * will return 1 match. If the desired behavior is to return 2 matches, define - * INCLUDE_SUBSTRING_MATCHES to be 1. - */ -#define INCLUDE_SUBSTRING_MATCHES 0 - -// Need a quick way to know a maximum distance between drawText calls to know if -// they are part of the same logical phrase when searching. By crude -// inspection, half the point size seems a good guess at the width of a space -// character. -static inline SkScalar approximateSpaceWidth(const SkPaint& paint) { - return SkScalarHalf(paint.getTextSize()); -} - -void FindCanvas::findHelper(const void* text, size_t byteLength, - const SkPaint& paint, const SkScalar positions[], - SkScalar y, - SkRect (FindCanvas::*addMatch)(int index, - const SkPaint& paint, int count, - const uint16_t* glyphs, - const SkScalar positions[], SkScalar y)) { - SkASSERT(paint.getTextEncoding() == SkPaint::kGlyphID_TextEncoding); - SkASSERT(mMatches); - GlyphSet* glyphSet = getGlyphs(paint); - const int count = glyphSet->getCount(); - int numCharacters = byteLength >> 1; - const uint16_t* chars = (const uint16_t*) text; - // This block will check to see if we are continuing from another line. If - // so, the user needs to have added a space, which we do not draw. - if (mWorkingIndex) { - SkPoint newY; - getTotalMatrix().mapXY(0, y, &newY); - SkIRect workingBounds = mWorkingRegion.getBounds(); - int newYInt = SkScalarRound(newY.fY); - if (workingBounds.fTop > newYInt) { - // The new text is above the working region, so we know it's not - // a continuation. - resetWorkingCanvas(); - mWorkingIndex = 0; - mWorkingRegion.setEmpty(); - } else if (workingBounds.fBottom < newYInt) { - // Now we know that this line is lower than our partial match. - SkPaint clonePaint(paint); - clonePaint.setTextEncoding(SkPaint::kUTF8_TextEncoding); - uint16_t space; - clonePaint.textToGlyphs(" ", 1, &space); - if (glyphSet->characterMatches(space, mWorkingIndex)) { - mWorkingIndex++; - if (mWorkingIndex == count) { - // We already know that it is not clipped out because we - // checked for that before saving the working region. - insertMatchInfo(mWorkingRegion); - - resetWorkingCanvas(); - mWorkingIndex = 0; - mWorkingRegion.setEmpty(); - // We have found a match, so continue on this line from - // scratch. - } - } else { - resetWorkingCanvas(); - mWorkingIndex = 0; - mWorkingRegion.setEmpty(); - } - } - // If neither one is true, then we are likely continuing on the same - // line, but are in a new draw call because the paint has changed. In - // this case, we can continue without adding a space. - } - // j is the position in the search text - // Start off with mWorkingIndex in case we are continuing from a prior call - int j = mWorkingIndex; - // index is the position in the drawn text - int index = 0; - for ( ; index != numCharacters; index++) { - if (glyphSet->characterMatches(chars[index], j)) { - // The jth character in the search text matches the indexth position - // in the drawn text, so increase j. - j++; - if (j != count) { - continue; - } - // The last count characters match, so we found the entire - // search string. - int remaining = count - mWorkingIndex; - int matchIndex = index - remaining + 1; - // Set up a pointer to the matching text in 'chars'. - const uint16_t* glyphs = chars + matchIndex; - SkRect rect = (this->*addMatch)(matchIndex, paint, - remaining, glyphs, positions, y); - // We need an SkIRect for SkRegion operations. - SkIRect iRect; - rect.roundOut(&iRect); - // Want to outset the drawn rectangle by the same amount as - // mOutset - iRect.inset(-INTEGER_OUTSET, -INTEGER_OUTSET); - SkRegion regionToAdd(iRect); - if (!mWorkingRegion.isEmpty()) { - // If this is on the same line as our working region, make - // sure that they are close enough together that they are - // supposed to be part of the same text string. - // The width of two spaces has arbitrarily been chosen. - const SkIRect& workingBounds = mWorkingRegion.getBounds(); - if (workingBounds.fTop <= iRect.fBottom && - workingBounds.fBottom >= iRect.fTop && - SkIntToScalar(iRect.fLeft - workingBounds.fRight) > - approximateSpaceWidth(paint)) { - index = -1; // Will increase to 0 on next run - // In this case, we need to start from the beginning of - // the text being searched and our search term. - j = 0; - mWorkingIndex = 0; - mWorkingRegion.setEmpty(); - continue; - } - // Add the mWorkingRegion, which contains rectangles from - // the previous line(s). - regionToAdd.op(mWorkingRegion, SkRegion::kUnion_Op); - } - insertMatchInfo(regionToAdd); -#if INCLUDE_SUBSTRING_MATCHES - // Reset index to the location of the match and reset j to the - // beginning, so that on the next iteration of the loop, index - // will advance by 1 and we will compare the next character in - // chars to the first character in the GlyphSet. - index = matchIndex; -#endif - // Whether the clip contained it or not, we need to start over - // with our recording canvas - resetWorkingCanvas(); - } else { - // Index needs to be set to index - j + 1. - // This is a ridiculous case, but imagine the situation where the - // user is looking for the string "jjog" in the drawText call for - // "jjjog". The first two letters match. However, when the index - // is 2, and we discover that 'o' and 'j' do not match, we should go - // back to 1, where we do, in fact, have a match - // FIXME: This does not work if (as in our example) "jj" is in one - // draw call and "jog" is in the next. Doing so would require a - // stack, keeping track of multiple possible working indeces and - // regions. This is likely an uncommon case. - index = index - j; // index will be increased by one on the next - // iteration - } - // We reach here in one of two cases: - // 1) We just completed a match, so any working rectangle/index is no - // longer needed, and we will start over from the beginning - // 2) The glyphs do not match, so we start over at the beginning of - // the search string. - j = 0; - mWorkingIndex = 0; - mWorkingRegion.setEmpty(); - } - // At this point, we have searched all of the text in the current drawText - // call. - // Keep track of a partial match that may start on this line. - if (j > 0) { // if j is greater than 0, we have a partial match - int relativeCount = j - mWorkingIndex; // Number of characters in this - // part of the match. - int partialIndex = index - relativeCount; // Index that starts our - // partial match. - const uint16_t* partialGlyphs = chars + partialIndex; - SkRect partial = (this->*addMatch)(partialIndex, paint, relativeCount, - partialGlyphs, positions, y); - partial.inset(mOutset, mOutset); - SkIRect dest; - partial.roundOut(&dest); - mWorkingRegion.op(dest, SkRegion::kUnion_Op); - mWorkingIndex = j; - return; - } - // This string doesn't go into the next drawText, so reset our working - // variables - mWorkingRegion.setEmpty(); - mWorkingIndex = 0; -} - -SkCanvas* FindCanvas::getWorkingCanvas() { - if (!mWorkingPicture) { - mWorkingPicture = new SkPicture; - mWorkingCanvas = mWorkingPicture->beginRecording(0,0); - } - return mWorkingCanvas; -} - -GlyphSet* FindCanvas::getGlyphs(const SkPaint& paint) { - SkTypeface* typeface = paint.getTypeface(); - GlyphSet* end = mGlyphSets.end(); - for (GlyphSet* ptr = mGlyphSets.begin();ptr != end; ptr++) { - if (ptr->getTypeface() == typeface) { - return ptr; - } - } - - GlyphSet set(paint, mLowerText, mUpperText, mLength); - *mGlyphSets.append() = set; - return &(mGlyphSets.top()); -} - -void FindCanvas::insertMatchInfo(const SkRegion& region) { - mNumFound++; - mWorkingPicture->endRecording(); - MatchInfo matchInfo; - mMatches->append(matchInfo); - ALOGD("%s region=%p pict=%p layer=%d", __FUNCTION__, - ®ion, mWorkingPicture, mLayerId); - mMatches->last().set(region, mWorkingPicture, mLayerId); -} - -void FindCanvas::resetWorkingCanvas() { - mWorkingPicture->unref(); - mWorkingPicture = 0; - // Do not need to reset mWorkingCanvas itself because we only access it via - // getWorkingCanvas. -} - -// This function sets up the paints that are used to draw the matches. -void FindOnPage::setUpFindPaint() { - // Set up the foreground paint - m_findPaint.setAntiAlias(true); - const SkScalar roundiness = SkIntToScalar(2); - SkCornerPathEffect* cornerEffect = new SkCornerPathEffect(roundiness); - m_findPaint.setPathEffect(cornerEffect); - m_findPaint.setARGB(255, 132, 190, 0); - - // Set up the background blur paint. - m_findBlurPaint.setAntiAlias(true); - m_findBlurPaint.setARGB(204, 0, 0, 0); - m_findBlurPaint.setPathEffect(cornerEffect); - cornerEffect->unref(); - SkMaskFilter* blurFilter = SkBlurMaskFilter::Create(SK_Scalar1, - SkBlurMaskFilter::kNormal_BlurStyle); - m_findBlurPaint.setMaskFilter(blurFilter)->unref(); - m_isFindPaintSetUp = true; -} - -IntRect FindOnPage::currentMatchBounds() const { - IntRect noBounds = IntRect(0, 0, 0, 0); - if (!m_matches || !m_matches->size()) - return noBounds; - MatchInfo& info = (*m_matches)[m_findIndex]; - return info.getLocation().getBounds(); -} - -bool FindOnPage::currentMatchIsInLayer() const { - if (!m_matches || !m_matches->size()) - return false; - MatchInfo& info = (*m_matches)[m_findIndex]; - return info.isInLayer(); -} - -int FindOnPage::currentMatchLayerId() const { - return (*m_matches)[m_findIndex].layerId(); -} - -// This function is only used by findNext and setMatches. In it, we store -// upper left corner of the match specified by m_findIndex in -// m_currentMatchLocation. -void FindOnPage::storeCurrentMatchLocation() { - SkASSERT(m_findIndex < m_matches->size()); - const SkIRect& bounds = (*m_matches)[m_findIndex].getLocation().getBounds(); - m_currentMatchLocation.set(bounds.fLeft, bounds.fTop); - m_hasCurrentLocation = true; -} - -// Put a cap on the number of matches to draw. If the current page has more -// matches than this, only draw the focused match. -#define MAX_NUMBER_OF_MATCHES_TO_DRAW 101 - -void FindOnPage::drawLegacy(SkCanvas* canvas, LayerAndroid* layer, IntRect* inval) { - if (!m_lastBounds.isEmpty()) { - inval->unite(m_lastBounds); - m_lastBounds.setEmpty(); - } - if (!m_hasCurrentLocation || !m_matches || !m_matches->size()) - return; - int layerId = layer ? layer->uniqueId() : -1; - if (m_findIndex >= m_matches->size()) - m_findIndex = 0; - const MatchInfo& matchInfo = (*m_matches)[m_findIndex]; - const SkRegion& currentMatchRegion = matchInfo.getLocation(); - - // Set up the paints used for drawing the matches - if (!m_isFindPaintSetUp) - setUpFindPaint(); - - // Draw the current match - if (matchInfo.layerId() == layerId) { - drawMatch(currentMatchRegion, canvas, true); - // Now draw the picture, so that it shows up on top of the rectangle - int saveCount = canvas->save(); - SkPath matchPath; - currentMatchRegion.getBoundaryPath(&matchPath); - canvas->clipPath(matchPath); - canvas->drawPicture(*matchInfo.getPicture()); - canvas->restoreToCount(saveCount); - const SkMatrix& matrix = canvas->getTotalMatrix(); - const SkRect& localBounds = matchPath.getBounds(); - SkRect globalBounds; - matrix.mapRect(&globalBounds, localBounds); - globalBounds.round(&m_lastBounds); - inval->unite(m_lastBounds); - } - // Draw the rest - unsigned numberOfMatches = m_matches->size(); - if (numberOfMatches > 1 - && numberOfMatches < MAX_NUMBER_OF_MATCHES_TO_DRAW) { - for (unsigned i = 0; i < numberOfMatches; i++) { - // The current match has already been drawn - if (i == m_findIndex) - continue; - if ((*m_matches)[i].layerId() != layerId) - continue; - const SkRegion& region = (*m_matches)[i].getLocation(); - // Do not draw matches which intersect the current one, or if it is - // offscreen - if (currentMatchRegion.intersects(region)) - continue; - SkRect bounds; - bounds.set(region.getBounds()); - if (canvas->quickReject(bounds, SkCanvas::kAA_EdgeType)) - continue; - drawMatch(region, canvas, false); - } - } -} - -// Draw the match specified by region to the canvas. -void FindOnPage::drawMatch(const SkRegion& region, SkCanvas* canvas, - bool focused) -{ - // For the match which has focus, use a filled paint. For the others, use - // a stroked paint. - if (focused) { - m_findPaint.setStyle(SkPaint::kFill_Style); - m_findBlurPaint.setStyle(SkPaint::kFill_Style); - } else { - m_findPaint.setStyle(SkPaint::kStroke_Style); - m_findPaint.setStrokeWidth(SK_Scalar1); - m_findBlurPaint.setStyle(SkPaint::kStroke_Style); - m_findBlurPaint.setStrokeWidth(SkIntToScalar(2)); - } - // Find the path for the current match - SkPath matchPath; - region.getBoundaryPath(&matchPath); - // Offset the path for a blurred shadow - SkPath blurPath; - matchPath.offset(SK_Scalar1, SkIntToScalar(2), &blurPath); - int saveCount = 0; - if (!focused) { - saveCount = canvas->save(); - canvas->clipPath(matchPath, SkRegion::kDifference_Op); - } - // Draw the blurred background - canvas->drawPath(blurPath, m_findBlurPaint); - if (!focused) - canvas->restoreToCount(saveCount); - // Draw the foreground - canvas->drawPath(matchPath, m_findPaint); -} - -void FindOnPage::findNext(bool forward) -{ - if (!m_matches || !m_matches->size() || !m_hasCurrentLocation) - return; - if (forward) { - m_findIndex++; - if (m_findIndex == m_matches->size()) - m_findIndex = 0; - } else { - if (m_findIndex == 0) { - m_findIndex = m_matches->size() - 1; - } else { - m_findIndex--; - } - } - storeCurrentMatchLocation(); -} - -// With this call, WebView takes ownership of matches, and is responsible for -// deleting it. -void FindOnPage::setMatches(WTF::Vector<MatchInfo>* matches) -{ - if (m_matches) - delete m_matches; - m_matches = matches; - if (m_matches->size()) { - if (m_hasCurrentLocation) { - for (unsigned i = 0; i < m_matches->size(); i++) { - const SkIRect& rect = (*m_matches)[i].getLocation().getBounds(); - if (rect.fLeft == m_currentMatchLocation.fX - && rect.fTop == m_currentMatchLocation.fY) { - m_findIndex = i; - return; - } - } - } - // If we did not have a stored location, or if we were unable to restore - // it, store the new one. - m_findIndex = 0; - storeCurrentMatchLocation(); - } else { - m_hasCurrentLocation = false; - } -} - -std::pair<unsigned, unsigned> FindOnPage::getLayerMatchRange(int layerId) const -{ - return m_layerMatchRangeMap.get(layerId); -} - -void FindOnPage::setLayerMatchRange(int layerId, - const std::pair<unsigned, unsigned> range) -{ - m_layerMatchRangeMap.set(layerId, range); -} - -} diff --git a/Source/WebKit/android/nav/FindCanvas.h b/Source/WebKit/android/nav/FindCanvas.h deleted file mode 100644 index 1d81f9a..0000000 --- a/Source/WebKit/android/nav/FindCanvas.h +++ /dev/null @@ -1,268 +0,0 @@ -/* - * Copyright 2008, The Android Open Source Project - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef Find_Canvas_h -#define Find_Canvas_h - -#include "DrawExtra.h" -#include "IntRect.h" -#include "SkBounder.h" -#include "SkCanvas.h" -#include "SkPicture.h" -#include "SkRect.h" -#include "SkRegion.h" -#include "SkTDArray.h" - -#include <unicode/umachine.h> -#include <wtf/Vector.h> -#include <wtf/HashMap.h> - -namespace android { -class FindOnPage; - -// Stores both region information and an SkPicture of the match, so that the -// region can be drawn, followed by drawing the matching text on top of it. -// This class owns its SkPicture -class MatchInfo { -public: - MatchInfo(); - ~MatchInfo(); - MatchInfo(const MatchInfo& src); - const SkRegion& getLocation() const { return m_location; } - // Return a pointer to our picture, representing the matching text. Does - // not transfer ownership of the picture. - SkPicture* getPicture() const { return m_picture; } - // This will make a copy of the region, and increase the ref count on the - // SkPicture. If this MatchInfo already had one, unref it. - void set(const SkRegion& region, SkPicture* pic, int layerId); - bool isInLayer() const { return m_layerId >= 0; } - int layerId() const { return m_layerId; } -private: - MatchInfo& operator=(MatchInfo& src); - SkRegion m_location; - SkPicture* m_picture; - int m_layerId; -}; - -// A class containing a typeface for reference, the length in glyphs, and -// the upper and lower case representations of the search string. -class GlyphSet { -public: - GlyphSet(const SkPaint& paint, const UChar* lower, const UChar* upper, - size_t byteLength); - ~GlyphSet(); - GlyphSet& operator=(GlyphSet& src); - - // Return true iff c matches one of our glyph arrays at index - bool characterMatches(uint16_t c, int index); - - int getCount() const { return mCount; } - - const SkTypeface* getTypeface() const { return mTypeface; } - -private: - // Disallow copy constructor - GlyphSet(GlyphSet& src) { } - - // mTypeface is used for comparison only - const SkTypeface* mTypeface; - // mLowerGlyphs points to all of our storage space: the lower set followed - // by the upper set. mUpperGlyphs is purely a convenience pointer to the - // start of the upper case glyphs. - uint16_t* mLowerGlyphs; - uint16_t* mUpperGlyphs; - // mCount is the number of glyphs of the search string. Must be the same - // for both the lower case set and the upper case set. - int mCount; - - // Arbitrarily chose the maximum storage to use in the GlyphSet. This is - // based on the length of the word being searched. If users are always - // searching for 3 letter words (for example), an ideal number would be 3. - // Each time the user searches for a word longer than (in this case, 3) that - // will result in calling new/delete. - enum Storage { - MAX_STORAGE_COUNT = 16 - }; - // In order to eliminate new/deletes, create storage that will be enough - // most of the time - uint16_t mStorage[2*MAX_STORAGE_COUNT]; -}; - -class FindBounder : public SkBounder { -public: - FindBounder() {} - ~FindBounder() {} -protected: - virtual bool onIRect(const SkIRect&) { return false; } -}; - -class FindCanvas : public SkCanvas { -public: - FindCanvas(int width, int height, const UChar* , const UChar*, - size_t byteLength); - - virtual ~FindCanvas(); - - virtual void drawText(const void* text, size_t byteLength, SkScalar x, - SkScalar y, const SkPaint& paint); - - /* FIXME: This path has not been tested. */ - virtual void drawPosText(const void* text, size_t byteLength, - const SkPoint pos[], const SkPaint& paint); - - /* Also untested */ - virtual void drawPosTextH(const void* text, size_t byteLength, - const SkScalar xpos[], SkScalar constY, - const SkPaint& paint); - - /* Not sure what to do here or for drawTextOnPathHV */ - virtual void drawTextOnPath(const void* text, size_t byteLength, - const SkPath& path, const SkMatrix* matrix, - const SkPaint& paint) { - } - - void drawLayers(LayerAndroid* rootLayer, FindOnPage& findOnPage); - int found() const { return mNumFound; } - void setLayerId(int layerId) { mLayerId = layerId; } - - // This method detaches our array of matches and passes ownership to - // the caller, who is then responsible for deleting them. - WTF::Vector<MatchInfo>* detachMatches() { - WTF::Vector<MatchInfo>* array = mMatches; - mMatches = NULL; - return array; - } - -private: - // These calls are made by findHelper to store information about each match - // that is found. They return a rectangle which is used to highlight the - // match. They also add to our SkPicture (which can be accessed with - // getDrawnMatches) a draw of each match. This way it can be drawn after - // the rectangle. The rect that is returned is in device coordinates. - SkRect addMatchNormal(int index, - const SkPaint& paint, int count, const uint16_t* glyphs, - const SkScalar pos[], SkScalar y); - - SkRect addMatchPos(int index, - const SkPaint& paint, int count, const uint16_t* glyphs, - const SkScalar xPos[], SkScalar /* y */); - - SkRect addMatchPosH(int index, - const SkPaint& paint, int count, const uint16_t* glyphs, - const SkScalar position[], SkScalar constY); - - // Helper for each of our draw calls - void findHelper(const void* text, size_t byteLength, const SkPaint& paint, - const SkScalar xPos[], SkScalar y, - SkRect (FindCanvas::*addMatch)(int index, - const SkPaint& paint, int count, const uint16_t* glyphs, - const SkScalar pos[], SkScalar y)); - - // If we already have a working canvas, grab it. Otherwise, create a new - // one. - SkCanvas* getWorkingCanvas(); - - // Return the set of glyphs and its count for the text being searched for - // and the parameter paint. If one has already been created and cached - // for this paint, use it. If not, create a new one and cache it. - GlyphSet* getGlyphs(const SkPaint& paint); - - // Store all the accumulated info about a match in our vector. - void insertMatchInfo(const SkRegion& region); - - // Throw away our cumulative information about our working SkCanvas. After - // this call, next call to getWorkingCanvas will create a new one. - void resetWorkingCanvas(); - - // Since we may transfer ownership of this array (see detachRects()), we - // hold a pointer to the array instead of just the array itself. - WTF::Vector<MatchInfo>* mMatches; - const UChar* mLowerText; - const UChar* mUpperText; - Vector<UChar> mLowerReversed; - Vector<UChar> mUpperReversed; - size_t mLength; - FindBounder mBounder; - int mNumFound; - SkScalar mOutset; - SkTDArray<GlyphSet> mGlyphSets; - - SkPicture* mWorkingPicture; - SkCanvas* mWorkingCanvas; - SkRegion mWorkingRegion; - int mWorkingIndex; - int mLayerId; -}; - -class FindOnPage : public DrawExtra { -public: - FindOnPage() { - m_matches = 0; - m_hasCurrentLocation = false; - m_isFindPaintSetUp = false; - m_lastBounds.setEmpty(); - } - virtual ~FindOnPage() { if (m_matches) delete m_matches; } - void clearCurrentLocation() { m_hasCurrentLocation = false; } - IntRect currentMatchBounds() const; - int currentMatchIndex() const { return m_findIndex; } - bool currentMatchIsInLayer() const; - // This requires the current match to be in a layer. See - // currentMatchIsInLayer(). - int currentMatchLayerId() const; - virtual void drawLegacy(SkCanvas* , LayerAndroid* , IntRect* ); - void findNext(bool forward); - bool isCurrentLocationValid() { return m_hasCurrentLocation; } - void setMatches(WTF::Vector<MatchInfo>* matches); - WTF::Vector<MatchInfo>* matches() { return m_matches; } - - // Some functions to determine which matches belong to which layers. - std::pair<unsigned, unsigned> getLayerMatchRange(int layerId) const; - void setLayerMatchRange(int layerId, - const std::pair<unsigned, unsigned> range); - -private: - void drawMatch(const SkRegion& region, SkCanvas* canvas, bool focused); - void setUpFindPaint(); - void storeCurrentMatchLocation(); - WTF::Vector<MatchInfo>* m_matches; - WTF::HashMap< int, std::pair<unsigned, unsigned> > m_layerMatchRangeMap; - // Stores the location of the current match. - SkIPoint m_currentMatchLocation; - // Tells whether the value in m_currentMatchLocation is valid. - bool m_hasCurrentLocation; - // Tells whether we have done the setup to draw the Find matches. - bool m_isFindPaintSetUp; - // Paint used to draw our Find matches. - SkPaint m_findPaint; - // Paint used for the background of our Find matches. - SkPaint m_findBlurPaint; - unsigned m_findIndex; - SkIRect m_lastBounds; -}; - -} - -#endif // Find_Canvas_h diff --git a/Source/WebKit/android/nav/WebView.cpp b/Source/WebKit/android/nav/WebView.cpp index d2d1321..2bd76f5 100644 --- a/Source/WebKit/android/nav/WebView.cpp +++ b/Source/WebKit/android/nav/WebView.cpp @@ -34,7 +34,6 @@ #include "CachedNode.h" #include "CachedRoot.h" #include "DrawExtra.h" -#include "FindCanvas.h" #include "Frame.h" #include "GraphicsJNI.h" #include "HTMLInputElement.h" @@ -107,12 +106,11 @@ enum FrameCachePermission { AllowNewer }; -#define DRAW_EXTRAS_SIZE 3 +#define DRAW_EXTRAS_SIZE 2 enum DrawExtras { // keep this in sync with WebView.java DrawExtrasNone = 0, - DrawExtrasFind = 1, - DrawExtrasSelection = 2, - DrawExtrasCursorRing = 3 + DrawExtrasSelection = 1, + DrawExtrasCursorRing = 2 }; struct JavaGlue { @@ -243,9 +241,6 @@ DrawExtra* getDrawExtraLegacy(DrawExtras extras) DrawExtra* extra = getDrawExtra(extras); if (!extra) { switch (extras) { - case DrawExtrasFind: - extra = &m_findOnPage; - break; case DrawExtrasCursorRing: if (drawCursorPreamble(root) && m_ring.setup()) { if (m_ring.m_isPressed || m_ringAnimationEnd == UINT_MAX) @@ -313,71 +308,6 @@ void debugDump() } #endif -void scrollToCurrentMatch() -{ - if (!m_findOnPage.currentMatchIsInLayer()) { - scrollRectOnScreen(m_findOnPage.currentMatchBounds()); - return; - } - - SkRect matchBounds = m_findOnPage.currentMatchBounds(); - LayerAndroid* rootLayer = compositeRoot(); - if (!rootLayer) - return; - - Layer* layerContainingMatch = rootLayer->findById(m_findOnPage.currentMatchLayerId()); - if (!layerContainingMatch) - return; - - // If the match is in a fixed position layer, there's nothing to do. - if (layerContainingMatch->shouldInheritFromRootTransform()) - return; - - // If the match is in a scrollable layer or a descendant of such a layer, - // there may be a range of of scroll configurations that will make the - // current match visible. Our approach is the simplest possible. Starting at - // the layer in which the match is found, we move up the layer tree, - // scrolling any scrollable layers as little as possible to make sure that - // the current match is in view. This approach has the disadvantage that we - // may end up scrolling a larger number of elements than is necessary, which - // may be visually jarring. However, minimising the number of layers - // scrolled would complicate the code significantly. - - bool didScrollLayer = false; - for (Layer* layer = layerContainingMatch; layer; layer = layer->getParent()) { - ASSERT(layer->getParent() || layer == rootLayer); - - if (layer->contentIsScrollable()) { - // Convert the match location to layer's local space and scroll it. - // Repeatedly calling Layer::localToAncestor() is inefficient as - // each call repeats part of the calculation. It would be more - // efficient to maintain the transform here and update it on each - // iteration, but that would mean duplicating logic from - // Layer::localToAncestor() and would complicate things. - SkMatrix transform; - layerContainingMatch->localToAncestor(layer, &transform); - SkRect transformedMatchBounds; - transform.mapRect(&transformedMatchBounds, matchBounds); - SkIRect roundedTransformedMatchBounds; - transformedMatchBounds.roundOut(&roundedTransformedMatchBounds); - // Only ScrollableLayerAndroid returns true for contentIsScrollable(). - didScrollLayer |= static_cast<ScrollableLayerAndroid*>(layer)->scrollRectIntoView(roundedTransformedMatchBounds); - } - } - // Invalidate, as the call below to scroll the main page may be a no-op. - if (didScrollLayer) - viewInvalidate(); - - // Convert matchBounds to the global space so we can scroll the main page. - SkMatrix transform; - layerContainingMatch->localToGlobal(&transform); - SkRect transformedMatchBounds; - transform.mapRect(&transformedMatchBounds, matchBounds); - SkIRect roundedTransformedMatchBounds; - transformedMatchBounds.roundOut(&roundedTransformedMatchBounds); - scrollRectOnScreen(roundedTransformedMatchBounds); -} - void scrollRectOnScreen(const IntRect& rect) { if (rect.isEmpty()) @@ -471,7 +401,6 @@ bool drawGL(WebCore::IntRect& viewRect, WebCore::IntRect* invalRect, TilesManager::instance()->setHighEndGfx(m_isHighEndGfx); m_glWebViewState = new GLWebViewState(); m_glWebViewState->glExtras()->setCursorRingExtra(&m_ring); - m_glWebViewState->glExtras()->setFindOnPageExtra(&m_findOnPage); if (m_baseLayer->content()) { SkRegion region; SkIRect rect; @@ -1083,12 +1012,6 @@ void setFindIsUp(bool up) m_viewImpl->m_findIsUp = up; } -void setFindIsEmpty() -{ - DBG_NAV_LOG(""); - m_findOnPage.clearCurrentLocation(); -} - void showCursorTimed() { DBG_NAV_LOG(""); @@ -1165,39 +1088,6 @@ void sendMotionUp(WebCore::Frame* framePtr, WebCore::Node* nodePtr, int x, int y checkException(env); } -void findNext(bool forward) -{ - m_findOnPage.findNext(forward); - scrollToCurrentMatch(); - viewInvalidate(); -} - -// With this call, WebView takes ownership of matches, and is responsible for -// deleting it. -void setMatches(WTF::Vector<MatchInfo>* matches, jboolean sameAsLastSearch) -{ - // If this search is the same as the last one, check against the old - // location to determine whether to scroll. If the same word is found - // in the same place, then do not scroll. - IntRect oldLocation; - bool checkAgainstOldLocation = false; - if (sameAsLastSearch && m_findOnPage.isCurrentLocationValid()) { - oldLocation = m_findOnPage.currentMatchBounds(); - checkAgainstOldLocation = true; - } - - m_findOnPage.setMatches(matches); - - if (!checkAgainstOldLocation || oldLocation != m_findOnPage.currentMatchBounds()) - scrollToCurrentMatch(); - viewInvalidate(); -} - -int currentMatchIndex() -{ - return m_findOnPage.currentMatchIndex(); -} - bool scrollBy(int dx, int dy) { ALOG_ASSERT(m_javaGlue.m_obj, "A java object was not associated with this native WebView!"); @@ -1394,10 +1284,6 @@ void setVisibleRect(SkRect& visibleRect) { m_visibleRect = visibleRect; } -FindOnPage& findOnPage() { - return m_findOnPage; -} - void setDrawExtra(DrawExtra *extra, DrawExtras type) { if (type == DrawExtrasNone) @@ -1415,7 +1301,7 @@ void setTextSelection(SelectText *selection) { int getHandleLayerId(SelectText::HandleId handleId, SkIRect& cursorRect) { SelectText* selectText = static_cast<SelectText*>(getDrawExtra(DrawExtrasSelection)); - if (!selectText) + if (!selectText || !m_baseLayer) return -1; int layerId = selectText->caretLayerId(handleId); IntRect rect = selectText->caretRect(handleId); @@ -1442,7 +1328,6 @@ private: // local state for WebView bool m_heightCanMeasure; int m_lastDx; SkMSec m_lastDxTime; - FindOnPage m_findOnPage; CursorRing m_ring; DrawExtra* m_extras[DRAW_EXTRAS_SIZE]; BaseLayerAndroid* m_baseLayer; @@ -2163,11 +2048,6 @@ static void nativeSetFindIsUp(JNIEnv *env, jobject obj, jboolean isUp) view->setFindIsUp(isUp); } -static void nativeSetFindIsEmpty(JNIEnv *env, jobject obj) -{ - GET_NATIVE_VIEW(env, obj)->setFindIsEmpty(); -} - static void nativeShowCursorTimed(JNIEnv *env, jobject obj) { GET_NATIVE_VIEW(env, obj)->showCursorTimed(); @@ -2196,88 +2076,6 @@ static jobject nativeGetCursorRingBounds(JNIEnv *env, jobject obj) return rect; } -static int nativeFindAll(JNIEnv *env, jobject obj, jstring findLower, - jstring findUpper, jboolean sameAsLastSearch) -{ - // If one or the other is null, do not search. - if (!(findLower && findUpper)) - return 0; - // Obtain the characters for both the lower case string and the upper case - // string representing the same word. - const jchar* findLowerChars = env->GetStringChars(findLower, 0); - const jchar* findUpperChars = env->GetStringChars(findUpper, 0); - // If one or the other is null, do not search. - if (!(findLowerChars && findUpperChars)) { - if (findLowerChars) - env->ReleaseStringChars(findLower, findLowerChars); - if (findUpperChars) - env->ReleaseStringChars(findUpper, findUpperChars); - checkException(env); - return 0; - } - WebView* view = GET_NATIVE_VIEW(env, obj); - ALOG_ASSERT(view, "view not set in nativeFindAll"); - BaseLayerAndroid* baseLayer = view->getBaseLayer(); - android::PictureSet* pictureSet = baseLayer ? baseLayer->content() : 0; - if (!pictureSet) { - env->ReleaseStringChars(findLower, findLowerChars); - env->ReleaseStringChars(findUpper, findUpperChars); - checkException(env); - return 0; - } - int length = env->GetStringLength(findLower); - // If the lengths of the strings do not match, then they are not the same - // word, so do not search. - if (!length || env->GetStringLength(findUpper) != length) { - env->ReleaseStringChars(findLower, findLowerChars); - env->ReleaseStringChars(findUpper, findUpperChars); - checkException(env); - return 0; - } - int width = pictureSet->width(); - int height = pictureSet->height(); - // Create a FindCanvas, which allows us to fake draw into it so we can - // figure out where our search string is rendered (and how many times). - FindCanvas canvas(width, height, (const UChar*) findLowerChars, - (const UChar*) findUpperChars, length << 1); - SkBitmap bitmap; - bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); - canvas.setBitmapDevice(bitmap); - FindOnPage& findOnPage = view->findOnPage(); - canvas.setLayerId(-1); - unsigned matchesBegin = canvas.found(); - baseLayer->drawCanvas(&canvas); - findOnPage.setLayerMatchRange(-1, - std::pair<unsigned, unsigned>(matchesBegin, canvas.found())); -#if USE(ACCELERATED_COMPOSITING) - LayerAndroid* compositeLayer = view->compositeRoot(); - if (compositeLayer) - canvas.drawLayers(compositeLayer, findOnPage); -#endif - WTF::Vector<MatchInfo>* matches = canvas.detachMatches(); - // With setMatches, the WebView takes ownership of matches - view->setMatches(matches, sameAsLastSearch); - - env->ReleaseStringChars(findLower, findLowerChars); - env->ReleaseStringChars(findUpper, findUpperChars); - checkException(env); - return canvas.found(); -} - -static void nativeFindNext(JNIEnv *env, jobject obj, bool forward) -{ - WebView* view = GET_NATIVE_VIEW(env, obj); - ALOG_ASSERT(view, "view not set in nativeFindNext"); - view->findNext(forward); -} - -static int nativeFindIndex(JNIEnv *env, jobject obj) -{ - WebView* view = GET_NATIVE_VIEW(env, obj); - ALOG_ASSERT(view, "view not set in nativeFindIndex"); - return view->currentMatchIndex(); -} - static void nativeUpdateCachedTextfield(JNIEnv *env, jobject obj, jstring updatedText, jint generation) { WebView* view = GET_NATIVE_VIEW(env, obj); @@ -2677,12 +2475,6 @@ static JNINativeMethod gJavaWebViewMethods[] = { (void*) nativeDumpDisplayTree }, { "nativeEvaluateLayersAnimations", "(I)Z", (void*) nativeEvaluateLayersAnimations }, - { "nativeFindAll", "(Ljava/lang/String;Ljava/lang/String;Z)I", - (void*) nativeFindAll }, - { "nativeFindNext", "(Z)V", - (void*) nativeFindNext }, - { "nativeFindIndex", "()I", - (void*) nativeFindIndex}, { "nativeFocusCandidateFramePointer", "()I", (void*) nativeFocusCandidateFramePointer }, { "nativeFocusCandidateHasNextTextfield", "()Z", @@ -2751,8 +2543,6 @@ static JNINativeMethod gJavaWebViewMethods[] = { (void*) nativeSelectBestAt }, { "nativeSelectAt", "(II)V", (void*) nativeSelectAt }, - { "nativeSetFindIsEmpty", "()V", - (void*) nativeSetFindIsEmpty }, { "nativeSetFindIsUp", "(Z)V", (void*) nativeSetFindIsUp }, { "nativeSetHeightCanMeasure", "(Z)V", |