Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(108)

Unified Diff: webkit/api/src/WebViewImpl.cpp

Issue 342099: Focus problem when clearing selection (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/api/src/WebViewImpl.cpp
===================================================================
--- webkit/api/src/WebViewImpl.cpp (revision 30896)
+++ webkit/api/src/WebViewImpl.cpp (working copy)
@@ -908,6 +908,29 @@
// 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();
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698