diff options
author | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-04 21:09:56 +0000 |
---|---|---|
committer | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-04 21:09:56 +0000 |
commit | 5370a4dd9c56a780eccbe57f27c61ffa7d94efe2 (patch) | |
tree | 6b13872d31b72a63bf4e5efa05a17bb909079da8 | |
parent | cec0a28770788ef39d820f890e18bd047d54c356 (diff) | |
download | chromium_src-5370a4dd9c56a780eccbe57f27c61ffa7d94efe2.zip chromium_src-5370a4dd9c56a780eccbe57f27c61ffa7d94efe2.tar.gz chromium_src-5370a4dd9c56a780eccbe57f27c61ffa7d94efe2.tar.bz2 |
When doing an unselect in a page, the focused node is kept focused but
it does not get the keyboard input anymore and for text editable
nodes there is no caret.
This was happening because the focus is messed up when the selection does
not include the focused node.
This CL ensure the selection includes the focused node to work-around that
issue.
BUG=21388
TEST=Open google.com, CTRL-F and search for something not in the page.
ESC to close the find-box. The search field on the Google page
should have focus and typing should work.
Now focus a link in the page, do a find for some text not in the
page. Press ESC. Pressing enter should trigger the link.
Review URL: http://codereview.chromium.org/342099
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30999 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | webkit/api/src/WebViewImpl.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/webkit/api/src/WebViewImpl.cpp b/webkit/api/src/WebViewImpl.cpp index 093a9d4..96840c1 100644 --- a/webkit/api/src/WebViewImpl.cpp +++ b/webkit/api/src/WebViewImpl.cpp @@ -908,6 +908,29 @@ void WebViewImpl::setFocus(bool enable) // Note that we don't call setActive() when disabled as this cause extra // focus/blur events to be dispatched. m_page->focusController()->setActive(true); + RefPtr<Frame> focusedFrame = m_page->focusController()->focusedFrame(); + if (focusedFrame) { + Node* focusedNode = focusedFrame->document()->focusedNode(); + if (focusedNode && focusedNode->isElementNode() + && focusedFrame->selection()->selection().isNone()) { + // If the selection was cleared while the WebView was not + // focused, then the focus element shows with a focus ring but + // no caret and does respond to keyboard inputs. + Element* element = static_cast<Element*>(focusedNode); + if (element->isTextFormControl()) { + element->updateFocusAppearance(true); + } else { + // updateFocusAppearance() selects all the text of + // contentseditable DIVs. So we set the selection explicitly + // instead. Note that this has the side effect of moving the + // caret back to the begining of the text. + Position position(focusedNode, 0, + Position::PositionIsOffsetInAnchor); + focusedFrame->selection()->setSelection( + VisibleSelection(position, SEL_DEFAULT_AFFINITY)); + } + } + } m_imeAcceptEvents = true; } else { hideAutoCompletePopup(); |