.: Refactor WebViewImpl::scrollFocusedNodeIntoRect to a better place and add tests
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 24 Sep 2011 00:23:55 +0000 (00:23 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 24 Sep 2011 00:23:55 +0000 (00:23 +0000)
https://bugs.webkit.org/show_bug.cgi?id=68198

Patch by Varun Jain <varunjain@google.com> 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 <varunjain@google.com> 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 <varunjain@google.com> 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 <varunjain@google.com> 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 <varunjain@google.com> 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: https://svn.webkit.org/repository/webkit/trunk@95890 268f45cc-cd09-0410-ab3c-d52691b4dbfc

20 files changed:
ChangeLog
LayoutTests/ChangeLog
LayoutTests/fast/dom/scroll-element-to-rect-centered-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/scroll-element-to-rect-centered.html [new file with mode: 0644]
LayoutTests/fast/dom/scroll-element-to-rect-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/scroll-element-to-rect.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/WebCore.exp.in
Source/WebCore/page/FrameView.cpp
Source/WebCore/page/FrameView.h
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/Internals.h
Source/WebCore/testing/Internals.idl
Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/public/WebView.h
Source/WebKit/chromium/src/WebViewImpl.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/win/WebKit2.def
Source/WebKit2/win/WebKit2CFLite.def
Source/autotools/symbols.filter

index f798e82..091b70d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2011-09-23  Varun Jain  <varunjain@google.com>
+
+        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  <mhahnenberg@apple.com>
 
         Add static version of JSCell::visitChildren
index 7c38cef..29ec1ca 100644 (file)
@@ -1,3 +1,15 @@
+2011-09-23  Varun Jain  <varunjain@google.com>
+
+        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  <dino@apple.com>
 
         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 (file)
index 0000000..872311c
--- /dev/null
@@ -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 (file)
index 0000000..5c5df82
--- /dev/null
@@ -0,0 +1,30 @@
+<html>
+  <head>
+    <body>
+      <div id="console"></div>
+      <div style="position: relative; width: 2400px; height: 2400px; background-color: white;">
+        <div style="position:fixed; left: 50px; top: 30px; width: 200px; height: 250px; background-color: green;"></div>
+        <div style="position:absolute; left: 600px; top: 800px;"> <input id="textbox" type="text"></div>
+      </div>
+    </body>
+    <script src="../js/resources/js-test-pre.js"></script>
+    <script>
+      if (window.internals) {
+        var box = document.getElementById('textbox');
+        window.internals.scrollElementToRect(box, 50, 30, 200, 250);
+      }
+      var rect = box.getBoundingClientRect();
+      var computedLeft = 50 + Math.floor((200 - rect.width) / 2);
+      var computedTop = 30 + Math.floor((250 - rect.height) / 2);
+      debug("Scrolled element to rect");
+      shouldBe("rect.left", "computedLeft");
+      shouldBe("rect.top", "computedTop");
+      if (window.layoutTestController) {
+        layoutTestController.dumpAsText();
+      }
+      successfullyParsed = true;
+    </script>
+    <script src="../js/resources/js-test-post.js"></script>
+    </script>
+  </head>
+</html>
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 (file)
index 0000000..872311c
--- /dev/null
@@ -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 (file)
index 0000000..77623ba
--- /dev/null
@@ -0,0 +1,28 @@
+<html>
+  <head>
+    <body>
+      <div id="console"></div>
+      <div style="position: relative; width: 1600px; height: 2400px; background-color: green;">
+        <div style="position:absolute; left: 600px; top: 800px;"> <input id="textbox" type="text"></div>
+      </div>
+    </body>
+    <script src="../js/resources/js-test-pre.js"></script>
+    <script>
+      if (window.internals) {
+        var box = document.getElementById('textbox');
+        window.internals.scrollElementToRect(box, 0, 0, 300, 300);
+      }
+      var rect = box.getBoundingClientRect();
+      var computedLeft = Math.floor((300 - rect.width) / 2);
+      var computedTop = Math.floor((300 - rect.height) / 2);
+      debug("Scrolled element to rect");
+      shouldBe("rect.left", "computedLeft");
+      shouldBe("rect.top", "computedTop");
+      if (window.layoutTestController) {
+        layoutTestController.dumpAsText();
+      }
+      successfullyParsed = true;
+    </script>
+    <script src="../js/resources/js-test-post.js"></script>
+  </head>
+</html>
index 56810cc..622b8a0 100644 (file)
@@ -1,3 +1,22 @@
+2011-09-23  Varun Jain  <varunjain@google.com>
+
+        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  <mihaip@chromium.org>
 
         Unreviewed, rolling out r95860.
index 12c0b81..7381b4e 100644 (file)
@@ -985,6 +985,7 @@ __ZN7WebCore9FrameView38syncCompositingStateIncludingSubframesEv
 __ZN7WebCore9FrameView6createEPNS_5FrameE
 __ZN7WebCore9FrameView6createEPNS_5FrameERKNS_7IntSizeE
 __ZN7WebCore9FrameView17paintControlTintsEv
+__ZN7WebCore9FrameView19scrollElementToRectEPNS_7ElementERKNS_7IntRectE
 __ZN7WebCore9HTMLNames10listingTagE
 __ZN7WebCore9HTMLNames11textareaTagE
 __ZN7WebCore9HTMLNames13blockquoteTagE
index b0ff8b2..532b3e8 100644 (file)
@@ -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;
index 93ee91a..f9face0 100644 (file)
@@ -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;
index fa92051..f9a78a2 100644 (file)
@@ -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));
+}
+
 }
index 7c456fb..c2c264f 100644 (file)
@@ -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;
 
index d8a0a6d..c267e48 100644 (file)
@@ -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);
     };
 }
 
index cabb328..2d44b51 100644 (file)
@@ -1,3 +1,15 @@
+2011-09-23  Varun Jain  <varunjain@google.com>
+
+        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  <mihaip@chromium.org>
 
         Unreviewed, rolling out r95860.
index 338c2ad..75e0bb0 100644 (file)
@@ -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 ----------------------------------------------------------------
index eb6a42c..88b22ed 100644 (file)
@@ -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<Element*>(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()
index d22730f..d2c4411 100644 (file)
@@ -1,3 +1,13 @@
+2011-09-23  Varun Jain  <varunjain@google.com>
+
+        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  <cshu@webkit.org>
 
         [WK2] [Qt] Implement MouseDown/MouseUp/MouseMoveTo functions for WebKit2 EventSender
index 68d893e..fa518e3 100644 (file)
@@ -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
index edaecc1..8482b49 100644 (file)
@@ -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
index afc7bce..7d39c45 100644 (file)
@@ -77,6 +77,7 @@ _ZNK7WebCore9TreeScope14getElementByIdERKN3WTF12AtomicStringE;
 _ZN7WebCore14ScrollableArea28setScrollOffsetFromInternalsERKNS_8IntPointE;
 _ZN7WebCore10ScrollView23setScrollbarsSuppressedEbb;
 _ZN7WebCore9FrameView17paintControlTintsEv;
+_ZN7WebCore9FrameView19scrollElementToRectEPNS_7ElementERKNS_7IntRectE;
 local:
 _Z*;
 cti*;