.: 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.

* 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: http://svn.webkit.org/repository/webkit/trunk@95890 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 54ffaf76
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
......
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
Scrolled element to rect
PASS rect.left is computedLeft
PASS rect.top is computedTop
PASS successfullyParsed is true
TEST COMPLETE
<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>
Scrolled element to rect
PASS rect.left is computedLeft
PASS rect.top is computedTop
PASS successfullyParsed is true
TEST COMPLETE
<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>
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.
......@@ -985,6 +985,7 @@ __ZN7WebCore9FrameView38syncCompositingStateIncludingSubframesEv
__ZN7WebCore9FrameView6createEPNS_5FrameE
__ZN7WebCore9FrameView6createEPNS_5FrameERKNS_7IntSizeE
__ZN7WebCore9FrameView17paintControlTintsEv
__ZN7WebCore9FrameView19scrollElementToRectEPNS_7ElementERKNS_7IntRectE
__ZN7WebCore9HTMLNames10listingTagE
__ZN7WebCore9HTMLNames11textareaTagE
__ZN7WebCore9HTMLNames13blockquoteTagE
......
......@@ -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;
......
......@@ -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;
......
......@@ -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));
}
}
......@@ -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;
......
......@@ -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);
};
}
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.
......
......@@ -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 ----------------------------------------------------------------
......
......@@ -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()
......
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
......
......@@ -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
......
......@@ -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
......
......@@ -77,6 +77,7 @@ _ZNK7WebCore9TreeScope14getElementByIdERKN3WTF12AtomicStringE;
_ZN7WebCore14ScrollableArea28setScrollOffsetFromInternalsERKNS_8IntPointE;
_ZN7WebCore10ScrollView23setScrollbarsSuppressedEbb;
_ZN7WebCore9FrameView17paintControlTintsEv;
_ZN7WebCore9FrameView19scrollElementToRectEPNS_7ElementERKNS_7IntRectE;
local:
_Z*;
cti*;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment