Commit b5b5841e authored by aroben's avatar aroben
Browse files

Reviewed by Darin.

        Handle tab key presses in the DOM.

        * dom/EventTargetNode.cpp:
        (WebCore::EventTargetNode::defaultEventHandler): Add tab key handling.
        * page/FrameView.cpp:
        (WebCore::FrameView::advanceFocus): Rename and reimplement
        focusNextPrevNode. Now we just call Element::focus().
        * page/FrameView.h: Rename focusNextPrevNode to advanceFocus and make
        it public.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@16741 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent de22f921
2006-10-03 Adam Roben <aroben@apple.com>
Reviewed by Darin.
Handle tab key presses in the DOM.
* dom/EventTargetNode.cpp:
(WebCore::EventTargetNode::defaultEventHandler): Add tab key handling.
* page/FrameView.cpp:
(WebCore::FrameView::advanceFocus): Rename and reimplement
focusNextPrevNode. Now we just call Element::focus().
* page/FrameView.h: Rename focusNextPrevNode to advanceFocus and make
it public.
2006-10-03 Justin Garcia <justin.garcia@apple.com>
 
Reviewed by mjs
......@@ -522,8 +522,17 @@ bool EventTargetNode::disabled() const
return false;
}
void EventTargetNode::defaultEventHandler(Event *evt)
void EventTargetNode::defaultEventHandler(Event* event)
{
if (event->type() == keypressEvent && event->isKeyboardEvent()) {
KeyboardEvent* keyEvent = static_cast<KeyboardEvent*>(event);
if (keyEvent->keyIdentifier() == "U+000009") {
Frame* frame = document()->frame();
if (frame && frame->view())
frame->view()->advanceFocus(!keyEvent->shiftKey());
event->setDefaultHandled();
}
}
}
#ifndef NDEBUG
......
......@@ -1003,78 +1003,26 @@ bool FrameView::scrollTo(const IntRect& bounds)
return scrollX != maxx && scrollY != maxy;
}
void FrameView::focusNextPrevNode(bool next)
bool FrameView::advanceFocus(bool forward)
{
// Sets the focus node of the document to be the node after (or if next is false, before) the current focus node.
// Only nodes that are selectable (i.e. for which isSelectable() returns true) are taken into account, and the order
// used is that specified in the HTML spec (see Document::nextFocusNode() and Document::previousFocusNode()
// for details).
Document* document = m_frame->document();
if (!document)
return false;
Document *doc = m_frame->document();
Node *oldFocusNode = doc->focusNode();
Node *newFocusNode;
Node* node = forward
? document->nextFocusNode(document->focusNode())
: document->previousFocusNode(document->focusNode());
// Find the next/previous node from the current one
if (next)
newFocusNode = doc->nextFocusNode(oldFocusNode);
else
newFocusNode = doc->previousFocusNode(oldFocusNode);
// If there was previously no focus node and the user has scrolled the document, then instead of picking the first
// focusable node in the document, use the first one that lies within the visible area (if possible).
if (!oldFocusNode && newFocusNode && d->scrollBarMoved) {
bool visible = false;
Node *toFocus = newFocusNode;
while (!visible && toFocus) {
if (toFocus->getRect().intersects(IntRect(contentsX(), contentsY(), visibleWidth(), visibleHeight()))) {
// toFocus is visible in the contents area
visible = true;
} else {
// toFocus is _not_ visible in the contents area, pick the next node
if (next)
toFocus = doc->nextFocusNode(toFocus);
else
toFocus = doc->previousFocusNode(toFocus);
}
}
if (toFocus)
newFocusNode = toFocus;
}
if (!node)
// FIXME: Need to support tabbing out of the document to the UI.
return false;
d->scrollBarMoved = false;
if (!node->isElementNode())
// FIXME: May need a way to focus a document here.
return false;
if (!newFocusNode)
{
// No new focus node, scroll to bottom or top depending on next
if (next)
scrollTo(IntRect(contentsX()+visibleWidth()/2,contentsHeight(),0,0));
else
scrollTo(IntRect(contentsX()+visibleWidth()/2,0,0,0));
}
else {
// EDIT FIXME: if it's an editable element, activate the caret
// otherwise, hide it
if (newFocusNode->isContentEditable()) {
// make caret visible
}
else {
// hide caret
}
// Scroll the view as necessary to ensure that the new focus node is visible
if (oldFocusNode) {
if (!scrollTo(newFocusNode->getRect()))
return;
}
else {
if (doc->renderer()) {
doc->renderer()->enclosingLayer()->scrollRectToVisible(IntRect(contentsX(), next ? 0: contentsHeight(), 0, 0));
}
}
}
// Set focus node on the document
m_frame->document()->setFocusNode(newFocusNode);
static_cast<Element*>(node)->focus();
return true;
}
void FrameView::setMediaType(const String& mediaType)
......
......@@ -152,6 +152,8 @@ public:
void doAutoScroll();
bool advanceFocus(bool forward);
bool updateDragAndDrop(const PlatformMouseEvent&, Clipboard*);
void cancelDragAndDrop(const PlatformMouseEvent&, Clipboard*);
bool performDragAndDrop(const PlatformMouseEvent&, Clipboard*);
......@@ -220,8 +222,6 @@ private:
bool scrollTo(const IntRect&);
void focusNextPrevNode(bool next);
bool useSlowRepaints() const;
void setUseSlowRepaints();
void addSlowRepaintObject();
......
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