Commit b5b5841e authored by aroben's avatar aroben

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> 2006-10-03 Justin Garcia <justin.garcia@apple.com>
Reviewed by mjs Reviewed by mjs
...@@ -522,8 +522,17 @@ bool EventTargetNode::disabled() const ...@@ -522,8 +522,17 @@ bool EventTargetNode::disabled() const
return false; 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 #ifndef NDEBUG
......
...@@ -1003,78 +1003,26 @@ bool FrameView::scrollTo(const IntRect& bounds) ...@@ -1003,78 +1003,26 @@ bool FrameView::scrollTo(const IntRect& bounds)
return scrollX != maxx && scrollY != maxy; 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. Document* document = m_frame->document();
// Only nodes that are selectable (i.e. for which isSelectable() returns true) are taken into account, and the order if (!document)
// used is that specified in the HTML spec (see Document::nextFocusNode() and Document::previousFocusNode() return false;
// for details).
Document *doc = m_frame->document(); Node* node = forward
Node *oldFocusNode = doc->focusNode(); ? document->nextFocusNode(document->focusNode())
Node *newFocusNode; : document->previousFocusNode(document->focusNode());
// Find the next/previous node from the current one if (!node)
if (next) // FIXME: Need to support tabbing out of the document to the UI.
newFocusNode = doc->nextFocusNode(oldFocusNode); return false;
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;
}
d->scrollBarMoved = false; if (!node->isElementNode())
// FIXME: May need a way to focus a document here.
return false;
if (!newFocusNode) static_cast<Element*>(node)->focus();
{ return true;
// 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);
} }
void FrameView::setMediaType(const String& mediaType) void FrameView::setMediaType(const String& mediaType)
......
...@@ -152,6 +152,8 @@ public: ...@@ -152,6 +152,8 @@ public:
void doAutoScroll(); void doAutoScroll();
bool advanceFocus(bool forward);
bool updateDragAndDrop(const PlatformMouseEvent&, Clipboard*); bool updateDragAndDrop(const PlatformMouseEvent&, Clipboard*);
void cancelDragAndDrop(const PlatformMouseEvent&, Clipboard*); void cancelDragAndDrop(const PlatformMouseEvent&, Clipboard*);
bool performDragAndDrop(const PlatformMouseEvent&, Clipboard*); bool performDragAndDrop(const PlatformMouseEvent&, Clipboard*);
...@@ -220,8 +222,6 @@ private: ...@@ -220,8 +222,6 @@ private:
bool scrollTo(const IntRect&); bool scrollTo(const IntRect&);
void focusNextPrevNode(bool next);
bool useSlowRepaints() const; bool useSlowRepaints() const;
void setUseSlowRepaints(); void setUseSlowRepaints();
void addSlowRepaintObject(); 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