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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 890 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 { 901 {
902 } 902 }
903 903
904 void WebViewImpl::setFocus(bool enable) 904 void WebViewImpl::setFocus(bool enable)
905 { 905 {
906 m_page->focusController()->setFocused(enable); 906 m_page->focusController()->setFocused(enable);
907 if (enable) { 907 if (enable) {
908 // Note that we don't call setActive() when disabled as this cause extra 908 // Note that we don't call setActive() when disabled as this cause extra
909 // focus/blur events to be dispatched. 909 // focus/blur events to be dispatched.
910 m_page->focusController()->setActive(true); 910 m_page->focusController()->setActive(true);
911 RefPtr<Frame> focusedFrame = m_page->focusController()->focusedFrame();
912 if (focusedFrame) {
913 Node* focusedNode = focusedFrame->document()->focusedNode();
914 if (focusedNode && focusedNode->isElementNode()
915 && focusedFrame->selection()->selection().isNone()) {
916 // If the selection was cleared while the WebView was not
917 // focused, then the focus element shows with a focus ring but
918 // no caret and does respond to keyboard inputs.
919 Element* element = static_cast<Element*>(focusedNode);
920 if (element->isTextFormControl()) {
921 element->updateFocusAppearance(true);
922 } else {
923 // updateFocusAppearance() selects all the text of
924 // contentseditable DIVs. So we set the selection explicitly
925 // instead. Note that this has the side effect of moving the
926 // caret back to the begining of the text.
927 Position position(focusedNode, 0,
928 Position::PositionIsOffsetInAnchor);
929 focusedFrame->selection()->setSelection(
930 VisibleSelection(position, SEL_DEFAULT_AFFINITY));
931 }
932 }
933 }
911 m_imeAcceptEvents = true; 934 m_imeAcceptEvents = true;
912 } else { 935 } else {
913 hideAutoCompletePopup(); 936 hideAutoCompletePopup();
914 937
915 // Clear focus on the currently focused frame if any. 938 // Clear focus on the currently focused frame if any.
916 if (!m_page.get()) 939 if (!m_page.get())
917 return; 940 return;
918 941
919 Frame* frame = m_page->mainFrame(); 942 Frame* frame = m_page->mainFrame();
920 if (!frame) 943 if (!frame)
(...skipping 830 matching lines...) Expand 10 before | Expand all | Expand 10 after
1751 { 1774 {
1752 m_tabsToLinks = enable; 1775 m_tabsToLinks = enable;
1753 } 1776 }
1754 1777
1755 bool WebViewImpl::tabsToLinks() const 1778 bool WebViewImpl::tabsToLinks() const
1756 { 1779 {
1757 return m_tabsToLinks; 1780 return m_tabsToLinks;
1758 } 1781 }
1759 1782
1760 } // namespace WebKit 1783 } // namespace WebKit
OLDNEW
« 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