OLD | NEW |
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 Loading... |
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 Loading... |
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 |
OLD | NEW |