diff options
| author | Grace Kloba <klobag@google.com> | 2010-05-28 18:06:43 -0700 |
|---|---|---|
| committer | Grace Kloba <klobag@google.com> | 2010-05-28 18:06:43 -0700 |
| commit | c05b3a990126a5a1de357c025e25e6acd4e4e185 (patch) | |
| tree | 134668b4dcc0710c586921213fc5f7811f3121d6 /WebKit | |
| parent | 27d79a6495971cad26199bdf5dc79abcb1ff1c9e (diff) | |
| download | external_webkit-c05b3a990126a5a1de357c025e25e6acd4e4e185.zip external_webkit-c05b3a990126a5a1de357c025e25e6acd4e4e185.tar.gz external_webkit-c05b3a990126a5a1de357c025e25e6acd4e4e185.tar.bz2 | |
Code clean up, http://b/issue?id=2724743
Change Widget:screenWidth() to Widget:textWrapWidth()
as the text wrap width may be different than the
screen width after pinch zoom.
Change AndroidWebHistoryBridge's m_screenWidthScale
to m_textWrapScale to reflect its meaning.
Remove unused screenWidth/screenHeight in PlatformBridge.
Merge two restore methods to one. There is a matching
CL in framework/base.
Only setUseFixedLayout if layout width is different
than screen width.
Change from Node* to Ref<Node> to avoid a crash.
Fix http://b/issue?id=2660396
Diffstat (limited to 'WebKit')
| -rw-r--r-- | WebKit/android/WebCoreSupport/FrameLoaderClientAndroid.cpp | 8 | ||||
| -rw-r--r-- | WebKit/android/WebCoreSupport/PlatformBridge.cpp | 12 | ||||
| -rw-r--r-- | WebKit/android/jni/WebHistory.cpp | 10 | ||||
| -rw-r--r-- | WebKit/android/jni/WebHistory.h | 6 | ||||
| -rw-r--r-- | WebKit/android/jni/WebViewCore.cpp | 61 | ||||
| -rw-r--r-- | WebKit/android/jni/WebViewCore.h | 17 |
6 files changed, 37 insertions, 77 deletions
diff --git a/WebKit/android/WebCoreSupport/FrameLoaderClientAndroid.cpp b/WebKit/android/WebCoreSupport/FrameLoaderClientAndroid.cpp index 3daa162..9278bf8 100644 --- a/WebKit/android/WebCoreSupport/FrameLoaderClientAndroid.cpp +++ b/WebKit/android/WebCoreSupport/FrameLoaderClientAndroid.cpp @@ -810,7 +810,7 @@ void FrameLoaderClientAndroid::saveViewStateToItem(HistoryItem* item) { if (!m_frame->tree()->parent()) { WebViewCore* webViewCore = WebViewCore::getWebViewCore(m_frame->view()); bridge->setScale((int)(webViewCore->scale() * 100)); - bridge->setScreenWidthScale((int)(webViewCore->screenWidthScale() * 100)); + bridge->setTextWrapScale((int)(webViewCore->textWrapScale() * 100)); } WebCore::notifyHistoryItemChanged(item); @@ -822,11 +822,7 @@ void FrameLoaderClientAndroid::restoreViewState() { AndroidWebHistoryBridge* bridge = item->bridge(); // restore the scale (only) for the top frame if (!m_frame->tree()->parent()) { - int scale = bridge->scale(); - webViewCore->restoreScale(scale); - int screenWidthScale = bridge->screenWidthScale(); - if (screenWidthScale != scale) - webViewCore->restoreScreenWidthScale(screenWidthScale); + webViewCore->restoreScale(bridge->scale(), bridge->textWrapScale()); } } diff --git a/WebKit/android/WebCoreSupport/PlatformBridge.cpp b/WebKit/android/WebCoreSupport/PlatformBridge.cpp index c64bb9d..006f529 100644 --- a/WebKit/android/WebCoreSupport/PlatformBridge.cpp +++ b/WebKit/android/WebCoreSupport/PlatformBridge.cpp @@ -62,18 +62,6 @@ void PlatformBridge::immediateRepaint(const WebCore::FrameView* view) #endif // USE(ACCELERATED_COMPOSITING) -int PlatformBridge::screenWidth(const WebCore::FrameView* view) -{ - android::WebViewCore* core = android::WebViewCore::getWebViewCore(view); - return static_cast<int>((core->screenWidthScale() * core->screenWidth()) / core->scale()); -} - -int PlatformBridge::screenHeight(const WebCore::FrameView* view) -{ - android::WebViewCore* core = android::WebViewCore::getWebViewCore(view); - return core->screenHeight(); -} - WTF::Vector<String> PlatformBridge::getSupportedKeyStrengthList() { KeyGeneratorClient* client = JavaSharedClient::GetKeyGeneratorClient(); diff --git a/WebKit/android/jni/WebHistory.cpp b/WebKit/android/jni/WebHistory.cpp index b2af67a..37a4d1d 100644 --- a/WebKit/android/jni/WebHistory.cpp +++ b/WebKit/android/jni/WebHistory.cpp @@ -419,9 +419,9 @@ static void write_item(WTF::Vector<char>& v, WebCore::HistoryItem* item) const int scale = bridge->scale(); LOGV("Writing scale %d", scale); v.append((char*)&scale, sizeof(int)); - const int screenWidthScale = bridge->screenWidthScale(); - LOGV("Writing screen width scale %d", screenWidthScale); - v.append((char*)&screenWidthScale, sizeof(int)); + const int textWrapScale = bridge->textWrapScale(); + LOGV("Writing text wrap scale %d", textWrapScale); + v.append((char*)&textWrapScale, sizeof(int)); // Document state const WTF::Vector<WebCore::String>& docState = item->documentState(); @@ -603,8 +603,8 @@ static bool read_item_recursive(WebCore::HistoryItem* newItem, bridge->setScale(l); data += sizeofUnsigned; memcpy(&l, data, sizeofUnsigned); - LOGV("Screen width scale %d", l); - bridge->setScreenWidthScale(l); + LOGV("Text wrap scale %d", l); + bridge->setTextWrapScale(l); data += sizeofUnsigned; if (end - data < sizeofUnsigned) diff --git a/WebKit/android/jni/WebHistory.h b/WebKit/android/jni/WebHistory.h index 12bf00a..2d86aa4 100644 --- a/WebKit/android/jni/WebHistory.h +++ b/WebKit/android/jni/WebHistory.h @@ -44,9 +44,9 @@ public: static void UpdateHistoryIndex(const AutoJObject&, int); }; -// there are two scale factors saved with each history item. mScale reflects the -// viewport scale factor, default to 100 means 100%. mScreenWidthScale records -// the scale factor for the screen width used to wrap the text paragraph. +// there are two scale factors saved with each history item. m_scale reflects the +// viewport scale factor, default to 100 means 100%. m_textWrapScale records +// the scale factor for wrapping the text paragraph. class WebHistoryItem : public WebCore::AndroidWebHistoryBridge { public: WebHistoryItem(WebHistoryItem* parent) diff --git a/WebKit/android/jni/WebViewCore.cpp b/WebKit/android/jni/WebViewCore.cpp index 78b6b05..f95672a 100644 --- a/WebKit/android/jni/WebViewCore.cpp +++ b/WebKit/android/jni/WebViewCore.cpp @@ -236,7 +236,6 @@ struct WebViewCore::JavaGlue { jmethodID m_updateTextSelection; jmethodID m_clearTextEntry; jmethodID m_restoreScale; - jmethodID m_restoreScreenWidthScale; jmethodID m_needTouchEvents; jmethodID m_requestKeyboard; jmethodID m_requestKeyboardWithSelection; @@ -293,8 +292,8 @@ WebViewCore::WebViewCore(JNIEnv* env, jobject javaWebViewCore, WebCore::Frame* m m_maxYScroll = 240/4; m_textGeneration = 0; m_screenWidth = 320; + m_textWrapWidth = 320; m_scale = 1; - m_screenWidthScale = 1; #if ENABLE(TOUCH_EVENTS) m_forwardingTouchEvents = false; #endif @@ -326,8 +325,7 @@ WebViewCore::WebViewCore(JNIEnv* env, jobject javaWebViewCore, WebCore::Frame* m m_javaGlue->m_updateTextfield = GetJMethod(env, clazz, "updateTextfield", "(IZLjava/lang/String;I)V"); m_javaGlue->m_updateTextSelection = GetJMethod(env, clazz, "updateTextSelection", "(IIII)V"); m_javaGlue->m_clearTextEntry = GetJMethod(env, clazz, "clearTextEntry", "()V"); - m_javaGlue->m_restoreScale = GetJMethod(env, clazz, "restoreScale", "(I)V"); - m_javaGlue->m_restoreScreenWidthScale = GetJMethod(env, clazz, "restoreScreenWidthScale", "(I)V"); + m_javaGlue->m_restoreScale = GetJMethod(env, clazz, "restoreScale", "(II)V"); m_javaGlue->m_needTouchEvents = GetJMethod(env, clazz, "needTouchEvents", "(Z)V"); m_javaGlue->m_requestKeyboard = GetJMethod(env, clazz, "requestKeyboard", "(Z)V"); m_javaGlue->m_requestKeyboardWithSelection = GetJMethod(env, clazz, "requestKeyboardWithSelection", "(IIII)V"); @@ -1048,24 +1046,13 @@ void WebViewCore::updateViewport() checkException(env); } -void WebViewCore::restoreScale(int scale) +void WebViewCore::restoreScale(int scale, int textWrapScale) { DEBUG_NAV_UI_LOGD("%s", __FUNCTION__); LOG_ASSERT(m_javaGlue->m_obj, "A Java widget was not associated with this view bridge!"); JNIEnv* env = JSC::Bindings::getJNIEnv(); - env->CallVoidMethod(m_javaGlue->object(env).get(), m_javaGlue->m_restoreScale, scale); - checkException(env); -} - -void WebViewCore::restoreScreenWidthScale(int scale) -{ - DEBUG_NAV_UI_LOGD("%s", __FUNCTION__); - LOG_ASSERT(m_javaGlue->m_obj, "A Java widget was not associated with this view bridge!"); - - JNIEnv* env = JSC::Bindings::getJNIEnv(); - env->CallVoidMethod(m_javaGlue->object(env).get(), - m_javaGlue->m_restoreScreenWidthScale, scale); + env->CallVoidMethod(m_javaGlue->object(env).get(), m_javaGlue->m_restoreScale, scale, textWrapScale); checkException(env); } @@ -1176,49 +1163,45 @@ void WebViewCore::setGlobalBounds(int x, int y, int h, int v) } void WebViewCore::setSizeScreenWidthAndScale(int width, int height, - int screenWidth, float scale, int realScreenWidth, int screenHeight, + int textWrapWidth, float scale, int screenWidth, int screenHeight, int anchorX, int anchorY, bool ignoreHeight) { WebCoreViewBridge* window = m_mainFrame->view()->platformWidget(); int ow = window->width(); int oh = window->height(); window->setSize(width, height); - window->setVisibleSize(realScreenWidth, screenHeight); - if (width > 0) { + window->setVisibleSize(screenWidth, screenHeight); + if (width != screenWidth) { m_mainFrame->view()->setUseFixedLayout(true); m_mainFrame->view()->setFixedLayoutSize(IntSize(width, height)); } else { m_mainFrame->view()->setUseFixedLayout(false); } int osw = m_screenWidth; - int orsw = m_screenWidth * m_screenWidthScale / m_scale; int osh = m_screenHeight; + int otw = m_textWrapWidth; DBG_NAV_LOGD("old:(w=%d,h=%d,sw=%d,scale=%g) new:(w=%d,h=%d,sw=%d,scale=%g)", ow, oh, osw, m_scale, width, height, screenWidth, scale); m_screenWidth = screenWidth; m_screenHeight = screenHeight; - if (scale >= 0) { // negative means ignore + m_textWrapWidth = textWrapWidth; + if (scale >= 0) // negative means keep the current scale m_scale = scale; - if (screenWidth != realScreenWidth) - m_screenWidthScale = realScreenWidth * scale / screenWidth; - else - m_screenWidthScale = m_scale; - } m_maxXScroll = screenWidth >> 2; - m_maxYScroll = (screenWidth * height / width) >> 2; - if (ow != width || (!ignoreHeight && oh != height) || osw != screenWidth) { + m_maxYScroll = m_maxXScroll * height / width; + if (ow != width || (!ignoreHeight && oh != height) || otw != textWrapWidth) { WebCore::RenderObject *r = m_mainFrame->contentRenderer(); DBG_NAV_LOGD("renderer=%p view=(w=%d,h=%d)", r, - realScreenWidth, screenHeight); + screenWidth, screenHeight); if (r) { WebCore::IntPoint anchorPoint = WebCore::IntPoint(anchorX, anchorY); DBG_NAV_LOGD("anchorX=%d anchorY=%d", anchorX, anchorY); - WebCore::Node* node = 0; + RefPtr<WebCore::Node> node; WebCore::IntRect bounds; WebCore::IntPoint offset; - // If the screen width changed, it is probably zoom change or + // If the text wrap changed, it is probably zoom change or // orientation change. Try to keep the anchor at the same place. - if (osw && screenWidth && osw != screenWidth) { + if (otw && textWrapWidth && otw != textWrapWidth) { WebCore::HitTestResult hitTestResult = m_mainFrame->eventHandler()-> hitTestResultAtPoint( anchorPoint, false); @@ -1248,19 +1231,19 @@ void WebViewCore::setSizeScreenWidthAndScale(int width, int height, DBG_NAV_LOGD("nb:(x=%d,y=%d,w=%d," "h=%d)", newBounds.x(), newBounds.y(), newBounds.width(), newBounds.height()); - if ((orsw && osh && bounds.width() && bounds.height()) + if ((osw && osh && bounds.width() && bounds.height()) && (bounds != newBounds)) { WebCore::FrameView* view = m_mainFrame->view(); // force left align if width is not changed while height changed. // the anchorPoint is probably at some white space in the node // which is affected by text wrap around the screen width. - const bool leftAlign = (osw != m_screenWidth) + const bool leftAlign = (otw != textWrapWidth) && (bounds.width() == newBounds.width()) && (bounds.height() != newBounds.height()); const float xPercentInDoc = leftAlign ? 0.0 : (float) (anchorX - bounds.x()) / bounds.width(); const float xPercentInView = - leftAlign ? 0.0 : (float) (anchorX - m_scrollOffsetX) / orsw; + leftAlign ? 0.0 : (float) (anchorX - m_scrollOffsetX) / osw; const float yPercentInDoc = (float) (anchorY - bounds.y()) / bounds.height(); const float yPercentInView = (float) (anchorY - m_scrollOffsetY) / osh; showRect(newBounds.x(), newBounds.y(), newBounds.width(), @@ -2908,7 +2891,7 @@ static void UpdateFrameCacheIfLoading(JNIEnv *env, jobject obj) } static void SetSize(JNIEnv *env, jobject obj, jint width, jint height, - jint screenWidth, jfloat scale, jint realScreenWidth, jint screenHeight, + jint textWrapWidth, jfloat scale, jint screenWidth, jint screenHeight, jint anchorX, jint anchorY, jboolean ignoreHeight) { #ifdef ANDROID_INSTRUMENT @@ -2917,8 +2900,8 @@ static void SetSize(JNIEnv *env, jobject obj, jint width, jint height, WebViewCore* viewImpl = GET_NATIVE_VIEW(env, obj); LOGV("webviewcore::nativeSetSize(%u %u)\n viewImpl: %p", (unsigned)width, (unsigned)height, viewImpl); LOG_ASSERT(viewImpl, "viewImpl not set in nativeSetSize"); - viewImpl->setSizeScreenWidthAndScale(width, height, screenWidth, scale, - realScreenWidth, screenHeight, anchorX, anchorY, ignoreHeight); + viewImpl->setSizeScreenWidthAndScale(width, height, textWrapWidth, scale, + screenWidth, screenHeight, anchorX, anchorY, ignoreHeight); } static void SetScrollOffset(JNIEnv *env, jobject obj, jint gen, jint x, jint y) diff --git a/WebKit/android/jni/WebViewCore.h b/WebKit/android/jni/WebViewCore.h index c5461f7..44d7bcc 100644 --- a/WebKit/android/jni/WebViewCore.h +++ b/WebKit/android/jni/WebViewCore.h @@ -170,15 +170,9 @@ namespace android { /** * Notify the view to restore the screen width, which in turn restores - * the scale. + * the scale. Also restore the scale for the text wrap. */ - void restoreScale(int); - - /** - * Notify the view to restore the scale used to calculate the screen - * width for wrapping the text - */ - void restoreScreenWidthScale(int); + void restoreScale(int scale, int textWrapScale); /** * Tell the java side to update the focused textfield @@ -465,10 +459,9 @@ namespace android { // record the inval area, and the picture size bool recordContent(SkRegion* , SkIPoint* ); - int screenWidth() const { return m_screenWidth; } - int screenHeight() const { return m_screenHeight; } + int textWrapWidth() const { return m_textWrapWidth; } float scale() const { return m_scale; } - float screenWidthScale() const { return m_screenWidthScale; } + float textWrapScale() const { return m_screenWidth * m_scale / m_textWrapWidth; } WebCore::Frame* mainFrame() const { return m_mainFrame; } void updateCursorBounds(const CachedRoot* root, const CachedFrame* cachedFrame, const CachedNode* cachedNode); @@ -551,8 +544,8 @@ namespace android { CachedHistory m_history; int m_screenWidth; // width of the visible rect in document coordinates int m_screenHeight;// height of the visible rect in document coordinates + int m_textWrapWidth; float m_scale; - float m_screenWidthScale; unsigned m_domtree_version; bool m_check_domtree_version; PageGroup* m_groupForVisitedLinks; |
