From 906802483067db688b706dc15e7d8c91fb350a3d Mon Sep 17 00:00:00 2001 From: "commit-queue@webkit.org" Date: Sat, 24 Sep 2011 00:23:55 +0000 Subject: [PATCH] .: Refactor WebViewImpl::scrollFocusedNodeIntoRect to a better place and add tests https://bugs.webkit.org/show_bug.cgi?id=68198 Patch by Varun Jain on 2011-09-23 Reviewed by Dimitri Glazkov. * Source/autotools/symbols.filter: Source/WebCore: Refactor WebViewImpl::scrollFocusedNodeIntoRect to a better place and add tests https://bugs.webkit.org/show_bug.cgi?id=68198 Patch by Varun Jain on 2011-09-23 Reviewed by Dimitri Glazkov. Tests: fast/dom/scroll-element-to-rect-centered.html fast/dom/scroll-element-to-rect.html * WebCore.exp.in: * page/FrameView.cpp: (WebCore::FrameView::scrollElementToRect): * page/FrameView.h: * testing/Internals.cpp: (WebCore::Internals::scrollElementToRect): * testing/Internals.h: * testing/Internals.idl: Source/WebKit/chromium: Refactor WebViewImpl::scrollFocusedNodeIntoRect to a better place and add tests https://bugs.webkit.org/show_bug.cgi?id=68198 Patch by Varun Jain on 2011-09-23 Reviewed by Dimitri Glazkov. * public/WebView.h: (WebKit::WebView::scrollFocusedNodeIntoRect): * src/WebViewImpl.cpp: (WebKit::WebViewImpl::scrollFocusedNodeIntoRect): Source/WebKit2: Refactor WebViewImpl::scrollFocusedNodeIntoRect to a better place and add tests https://bugs.webkit.org/show_bug.cgi?id=68198 Patch by Varun Jain on 2011-09-23 Reviewed by Dimitri Glazkov. * win/WebKit2.def: * win/WebKit2CFLite.def: LayoutTests: Refactor WebViewImpl::scrollFocusedNodeIntoRect to a better place and add tests https://bugs.webkit.org/show_bug.cgi?id=68198 Patch by Varun Jain on 2011-09-23 Reviewed by Dimitri Glazkov. * fast/dom/scroll-element-to-rect-centered-expected.txt: Added. * fast/dom/scroll-element-to-rect-centered.html: Added. * fast/dom/scroll-element-to-rect-expected.txt: Added. * fast/dom/scroll-element-to-rect.html: Added. git-svn-id: http://svn.webkit.org/repository/webkit/trunk@95890 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- ChangeLog | 9 +++++++ LayoutTests/ChangeLog | 12 +++++++++ .../scroll-element-to-rect-centered-expected.txt | 7 +++++ .../fast/dom/scroll-element-to-rect-centered.html | 30 ++++++++++++++++++++++ .../fast/dom/scroll-element-to-rect-expected.txt | 7 +++++ LayoutTests/fast/dom/scroll-element-to-rect.html | 28 ++++++++++++++++++++ Source/WebCore/ChangeLog | 19 ++++++++++++++ Source/WebCore/WebCore.exp.in | 1 + Source/WebCore/page/FrameView.cpp | 10 ++++++++ Source/WebCore/page/FrameView.h | 2 ++ Source/WebCore/testing/Internals.cpp | 11 ++++++++ Source/WebCore/testing/Internals.h | 1 + Source/WebCore/testing/Internals.idl | 2 ++ Source/WebKit/chromium/ChangeLog | 12 +++++++++ Source/WebKit/chromium/public/WebView.h | 4 +-- Source/WebKit/chromium/src/WebViewImpl.cpp | 11 +++----- Source/WebKit2/ChangeLog | 10 ++++++++ Source/WebKit2/win/WebKit2.def | 1 + Source/WebKit2/win/WebKit2CFLite.def | 1 + Source/autotools/symbols.filter | 1 + 20 files changed, 169 insertions(+), 10 deletions(-) create mode 100644 LayoutTests/fast/dom/scroll-element-to-rect-centered-expected.txt create mode 100644 LayoutTests/fast/dom/scroll-element-to-rect-centered.html create mode 100644 LayoutTests/fast/dom/scroll-element-to-rect-expected.txt create mode 100644 LayoutTests/fast/dom/scroll-element-to-rect.html diff --git a/ChangeLog b/ChangeLog index f798e82..091b70d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2011-09-23 Varun Jain + + Refactor WebViewImpl::scrollFocusedNodeIntoRect to a better place and add tests + https://bugs.webkit.org/show_bug.cgi?id=68198 + + Reviewed by Dimitri Glazkov. + + * Source/autotools/symbols.filter: + 2011-09-23 Mark Hahnenberg Add static version of JSCell::visitChildren diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog index 7c38cef..29ec1ca 100644 --- a/LayoutTests/ChangeLog +++ b/LayoutTests/ChangeLog @@ -1,3 +1,15 @@ +2011-09-23 Varun Jain + + Refactor WebViewImpl::scrollFocusedNodeIntoRect to a better place and add tests + https://bugs.webkit.org/show_bug.cgi?id=68198 + + Reviewed by Dimitri Glazkov. + + * fast/dom/scroll-element-to-rect-centered-expected.txt: Added. + * fast/dom/scroll-element-to-rect-centered.html: Added. + * fast/dom/scroll-element-to-rect-expected.txt: Added. + * fast/dom/scroll-element-to-rect.html: Added. + 2011-09-23 Dean Jackson Add -webkit-filter to CSSPropertyNames diff --git a/LayoutTests/fast/dom/scroll-element-to-rect-centered-expected.txt b/LayoutTests/fast/dom/scroll-element-to-rect-centered-expected.txt new file mode 100644 index 0000000..872311c --- /dev/null +++ b/LayoutTests/fast/dom/scroll-element-to-rect-centered-expected.txt @@ -0,0 +1,7 @@ +Scrolled element to rect +PASS rect.left is computedLeft +PASS rect.top is computedTop +PASS successfullyParsed is true + +TEST COMPLETE + diff --git a/LayoutTests/fast/dom/scroll-element-to-rect-centered.html b/LayoutTests/fast/dom/scroll-element-to-rect-centered.html new file mode 100644 index 0000000..5c5df82 --- /dev/null +++ b/LayoutTests/fast/dom/scroll-element-to-rect-centered.html @@ -0,0 +1,30 @@ + + + +
+
+
+
+
+ + + + + + + diff --git a/LayoutTests/fast/dom/scroll-element-to-rect-expected.txt b/LayoutTests/fast/dom/scroll-element-to-rect-expected.txt new file mode 100644 index 0000000..872311c --- /dev/null +++ b/LayoutTests/fast/dom/scroll-element-to-rect-expected.txt @@ -0,0 +1,7 @@ +Scrolled element to rect +PASS rect.left is computedLeft +PASS rect.top is computedTop +PASS successfullyParsed is true + +TEST COMPLETE + diff --git a/LayoutTests/fast/dom/scroll-element-to-rect.html b/LayoutTests/fast/dom/scroll-element-to-rect.html new file mode 100644 index 0000000..77623ba --- /dev/null +++ b/LayoutTests/fast/dom/scroll-element-to-rect.html @@ -0,0 +1,28 @@ + + + +
+
+
+
+ + + + + + diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog index 56810cc..622b8a0 100644 --- a/Source/WebCore/ChangeLog +++ b/Source/WebCore/ChangeLog @@ -1,3 +1,22 @@ +2011-09-23 Varun Jain + + Refactor WebViewImpl::scrollFocusedNodeIntoRect to a better place and add tests + https://bugs.webkit.org/show_bug.cgi?id=68198 + + Reviewed by Dimitri Glazkov. + + Tests: fast/dom/scroll-element-to-rect-centered.html + fast/dom/scroll-element-to-rect.html + + * WebCore.exp.in: + * page/FrameView.cpp: + (WebCore::FrameView::scrollElementToRect): + * page/FrameView.h: + * testing/Internals.cpp: + (WebCore::Internals::scrollElementToRect): + * testing/Internals.h: + * testing/Internals.idl: + 2011-09-23 Mihai Parparita Unreviewed, rolling out r95860. diff --git a/Source/WebCore/WebCore.exp.in b/Source/WebCore/WebCore.exp.in index 12c0b81..7381b4efc 100644 --- a/Source/WebCore/WebCore.exp.in +++ b/Source/WebCore/WebCore.exp.in @@ -985,6 +985,7 @@ __ZN7WebCore9FrameView38syncCompositingStateIncludingSubframesEv __ZN7WebCore9FrameView6createEPNS_5FrameE __ZN7WebCore9FrameView6createEPNS_5FrameERKNS_7IntSizeE __ZN7WebCore9FrameView17paintControlTintsEv +__ZN7WebCore9FrameView19scrollElementToRectEPNS_7ElementERKNS_7IntRectE __ZN7WebCore9HTMLNames10listingTagE __ZN7WebCore9HTMLNames11textareaTagE __ZN7WebCore9HTMLNames13blockquoteTagE diff --git a/Source/WebCore/page/FrameView.cpp b/Source/WebCore/page/FrameView.cpp index b0ff8b2..532b3e8 100644 --- a/Source/WebCore/page/FrameView.cpp +++ b/Source/WebCore/page/FrameView.cpp @@ -1622,6 +1622,16 @@ void FrameView::maintainScrollPositionAtAnchor(Node* anchorNode) scrollToAnchor(); } +void FrameView::scrollElementToRect(Element* element, const IntRect& rect) +{ + m_frame->document()->updateLayoutIgnorePendingStylesheets(); + + LayoutRect bounds = element->boundsInWindowSpace(); + int centeringOffsetX = (rect.width() - bounds.width()) / 2; + int centeringOffsetY = (rect.height() - bounds.height()) / 2; + scrollBy(IntSize(bounds.x() - centeringOffsetX - rect.x(), bounds.y() - centeringOffsetY - rect.y())); +} + void FrameView::setScrollPosition(const LayoutPoint& scrollPoint) { bool wasInProgrammaticScroll = m_inProgrammaticScroll; diff --git a/Source/WebCore/page/FrameView.h b/Source/WebCore/page/FrameView.h index 93ee91a..f9face0 100644 --- a/Source/WebCore/page/FrameView.h +++ b/Source/WebCore/page/FrameView.h @@ -36,6 +36,7 @@ namespace WebCore { class Color; +class Element; class Event; class FloatSize; class Frame; @@ -260,6 +261,7 @@ public: bool scrollToFragment(const KURL&); bool scrollToAnchor(const String&); void maintainScrollPositionAtAnchor(Node*); + void scrollElementToRect(Element*, const IntRect&); // Methods to convert points and rects between the coordinate space of the renderer, and this view. virtual LayoutRect convertFromRenderer(const RenderObject*, const LayoutRect&) const; diff --git a/Source/WebCore/testing/Internals.cpp b/Source/WebCore/testing/Internals.cpp index fa92051..f9a78a2 100644 --- a/Source/WebCore/testing/Internals.cpp +++ b/Source/WebCore/testing/Internals.cpp @@ -37,6 +37,7 @@ #include "HTMLNames.h" #include "HTMLTextAreaElement.h" #include "InspectorController.h" +#include "IntRect.h" #include "MemoryCache.h" #include "NodeRenderingContext.h" #include "Page.h" @@ -376,4 +377,14 @@ void Internals::paintControlTints(Document* document, ExceptionCode& ec) frameView->paintControlTints(); } +void Internals::scrollElementToRect(Element* element, long x, long y, long w, long h, ExceptionCode& ec) +{ + if (!element || !element->document() || !element->document()->view()) { + ec = INVALID_ACCESS_ERR; + return; + } + FrameView* frameView = element->document()->view(); + frameView->scrollElementToRect(element, IntRect(x, y, w, h)); +} + } diff --git a/Source/WebCore/testing/Internals.h b/Source/WebCore/testing/Internals.h index 7c456fb..c2c264f 100644 --- a/Source/WebCore/testing/Internals.h +++ b/Source/WebCore/testing/Internals.h @@ -87,6 +87,7 @@ public: bool wasLastChangeUserEdit(Element* textField, ExceptionCode&); String suggestedValue(Element* inputElement, ExceptionCode&); void setSuggestedValue(Element* inputElement, const String&, ExceptionCode&); + void scrollElementToRect(Element*, long x, long y, long w, long h, ExceptionCode&); static const char* internalsId; diff --git a/Source/WebCore/testing/Internals.idl b/Source/WebCore/testing/Internals.idl index d8a0a6d..c267e48 100644 --- a/Source/WebCore/testing/Internals.idl +++ b/Source/WebCore/testing/Internals.idl @@ -63,6 +63,8 @@ module window { void setSuggestedValue(in Element inputElement, in DOMString value) raises (DOMException); void paintControlTints(in Document document) raises (DOMException); + + void scrollElementToRect(in Element element, in long x, in long y, in long w, in long h) raises (DOMException); }; } diff --git a/Source/WebKit/chromium/ChangeLog b/Source/WebKit/chromium/ChangeLog index cabb328..2d44b51 100644 --- a/Source/WebKit/chromium/ChangeLog +++ b/Source/WebKit/chromium/ChangeLog @@ -1,3 +1,15 @@ +2011-09-23 Varun Jain + + Refactor WebViewImpl::scrollFocusedNodeIntoRect to a better place and add tests + https://bugs.webkit.org/show_bug.cgi?id=68198 + + Reviewed by Dimitri Glazkov. + + * public/WebView.h: + (WebKit::WebView::scrollFocusedNodeIntoRect): + * src/WebViewImpl.cpp: + (WebKit::WebViewImpl::scrollFocusedNodeIntoRect): + 2011-09-23 Mihai Parparita Unreviewed, rolling out r95860. diff --git a/Source/WebKit/chromium/public/WebView.h b/Source/WebKit/chromium/public/WebView.h index 338c2ad..75e0bb0 100644 --- a/Source/WebKit/chromium/public/WebView.h +++ b/Source/WebKit/chromium/public/WebView.h @@ -175,8 +175,8 @@ public: virtual void scrollFocusedNodeIntoView() = 0; // Scrolls the node currently in focus into |rect|, where |rect| is in - // screen space. - virtual void scrollFocusedNodeIntoRect(const WebRect& rect) { } + // window space. + virtual void scrollFocusedNodeIntoRect(const WebRect&) { } // Zoom ---------------------------------------------------------------- diff --git a/Source/WebKit/chromium/src/WebViewImpl.cpp b/Source/WebKit/chromium/src/WebViewImpl.cpp index eb6a42c..88b22ed 100644 --- a/Source/WebKit/chromium/src/WebViewImpl.cpp +++ b/Source/WebKit/chromium/src/WebViewImpl.cpp @@ -1820,17 +1820,12 @@ void WebViewImpl::scrollFocusedNodeIntoView() void WebViewImpl::scrollFocusedNodeIntoRect(const WebRect& rect) { + Frame* frame = page()->mainFrame(); Node* focusedNode = focusedWebCoreNode(); - if (!focusedNode || !focusedNode->isElementNode()) + if (!frame || !frame->view() || !focusedNode || !focusedNode->isElementNode()) return; Element* elementNode = static_cast(focusedNode); - LayoutRect bounds = elementNode->boundsInWindowSpace(); - int centeringOffsetX = (rect.width - bounds.width()) / 2; - int centeringOffsetY = (rect.height - bounds.height()) / 2; - IntSize scrollOffset(bounds.x() - centeringOffsetX, bounds.y() - centeringOffsetY); - Frame* frame = mainFrameImpl()->frame(); - if (frame && frame->view()) - frame->view()->scrollBy(scrollOffset); + frame->view()->scrollElementToRect(elementNode, IntRect(rect.x, rect.y, rect.width, rect.height)); } double WebViewImpl::zoomLevel() diff --git a/Source/WebKit2/ChangeLog b/Source/WebKit2/ChangeLog index d22730f..d2c4411 100644 --- a/Source/WebKit2/ChangeLog +++ b/Source/WebKit2/ChangeLog @@ -1,3 +1,13 @@ +2011-09-23 Varun Jain + + Refactor WebViewImpl::scrollFocusedNodeIntoRect to a better place and add tests + https://bugs.webkit.org/show_bug.cgi?id=68198 + + Reviewed by Dimitri Glazkov. + + * win/WebKit2.def: + * win/WebKit2CFLite.def: + 2011-09-23 Chang Shu [WK2] [Qt] Implement MouseDown/MouseUp/MouseMoveTo functions for WebKit2 EventSender diff --git a/Source/WebKit2/win/WebKit2.def b/Source/WebKit2/win/WebKit2.def index 68d893e..fa518e3 100644 --- a/Source/WebKit2/win/WebKit2.def +++ b/Source/WebKit2/win/WebKit2.def @@ -162,6 +162,7 @@ EXPORTS ?memoryCache@WebCore@@YAPAVMemoryCache@1@XZ ?page@Document@WebCore@@QBEPAVPage@2@XZ ?paintControlTints@FrameView@WebCore@@AAEXXZ + ?scrollElementToRect@FrameView@WebCore@@QAEXPAVElement@2@ABVIntRect@2@@Z ?removeShadowRoot@Element@WebCore@@QAEXXZ ?setDisabled@MemoryCache@WebCore@@QAEX_N@Z ?setDOMException@WebCore@@YAXPAVExecState@JSC@@H@Z diff --git a/Source/WebKit2/win/WebKit2CFLite.def b/Source/WebKit2/win/WebKit2CFLite.def index edaecc1..8482b49 100644 --- a/Source/WebKit2/win/WebKit2CFLite.def +++ b/Source/WebKit2/win/WebKit2CFLite.def @@ -156,6 +156,7 @@ EXPORTS ?memoryCache@WebCore@@YAPAVMemoryCache@1@XZ ?page@Document@WebCore@@QBEPAVPage@2@XZ ?paintControlTints@FrameView@WebCore@@AAEXXZ + ?scrollElementToRect@FrameView@WebCore@@QAEXPAVElement@2@ABVIntRect@2@@Z ?removeShadowRoot@Element@WebCore@@QAEXXZ ?setDisabled@MemoryCache@WebCore@@QAEX_N@Z ?setDOMException@WebCore@@YAXPAVExecState@JSC@@H@Z diff --git a/Source/autotools/symbols.filter b/Source/autotools/symbols.filter index afc7bce..7d39c45 100644 --- a/Source/autotools/symbols.filter +++ b/Source/autotools/symbols.filter @@ -77,6 +77,7 @@ _ZNK7WebCore9TreeScope14getElementByIdERKN3WTF12AtomicStringE; _ZN7WebCore14ScrollableArea28setScrollOffsetFromInternalsERKNS_8IntPointE; _ZN7WebCore10ScrollView23setScrollbarsSuppressedEbb; _ZN7WebCore9FrameView17paintControlTintsEv; +_ZN7WebCore9FrameView19scrollElementToRectEPNS_7ElementERKNS_7IntRectE; local: _Z*; cti*; -- 2.7.4