OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2004, 2008, 2009, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 2008, 2009, 2010 Apple 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 | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
108 | 108 |
109 FrameSelection::FrameSelection(Frame* frame) | 109 FrameSelection::FrameSelection(Frame* frame) |
110 : m_frame(frame) | 110 : m_frame(frame) |
111 , m_xPosForVerticalArrowNavigation(NoXPosForVerticalArrowNavigation()) | 111 , m_xPosForVerticalArrowNavigation(NoXPosForVerticalArrowNavigation()) |
112 , m_granularity(CharacterGranularity) | 112 , m_granularity(CharacterGranularity) |
113 , m_caretBlinkTimer(this, &FrameSelection::caretBlinkTimerFired) | 113 , m_caretBlinkTimer(this, &FrameSelection::caretBlinkTimerFired) |
114 , m_absCaretBoundsDirty(true) | 114 , m_absCaretBoundsDirty(true) |
115 , m_caretPaint(true) | 115 , m_caretPaint(true) |
116 , m_isCaretBlinkingSuspended(false) | 116 , m_isCaretBlinkingSuspended(false) |
117 , m_focused(frame && frame->page() && frame->page()->focusController()->focu sedFrame() == frame) | 117 , m_focused(frame && frame->page() && frame->page()->focusController()->focu sedFrame() == frame) |
118 , m_shouldShowBlockCursor(false) | |
118 { | 119 { |
119 if (shouldAlwaysUseDirectionalSelection(m_frame)) | 120 if (shouldAlwaysUseDirectionalSelection(m_frame)) |
120 m_selection.setIsDirectional(true); | 121 m_selection.setIsDirectional(true); |
121 } | 122 } |
122 | 123 |
123 Element* FrameSelection::rootEditableElementOrDocumentElement() const | 124 Element* FrameSelection::rootEditableElementOrDocumentElement() const |
124 { | 125 { |
125 Element* selectionRoot = m_selection.rootEditableElement(); | 126 Element* selectionRoot = m_selection.rootEditableElement(); |
126 return selectionRoot ? selectionRoot : m_frame->document()->documentElement( ); | 127 return selectionRoot ? selectionRoot : m_frame->document()->documentElement( ); |
127 } | 128 } |
(...skipping 1603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1731 return m_focused && m_frame->page() && m_frame->page()->focusController()->i sActive(); | 1732 return m_focused && m_frame->page() && m_frame->page()->focusController()->i sActive(); |
1732 } | 1733 } |
1733 | 1734 |
1734 inline static bool shouldStopBlinkingDueToTypingCommand(Frame* frame) | 1735 inline static bool shouldStopBlinkingDueToTypingCommand(Frame* frame) |
1735 { | 1736 { |
1736 return frame->editor()->lastEditCommand() && frame->editor()->lastEditComman d()->shouldStopCaretBlinking(); | 1737 return frame->editor()->lastEditCommand() && frame->editor()->lastEditComman d()->shouldStopCaretBlinking(); |
1737 } | 1738 } |
1738 | 1739 |
1739 void FrameSelection::updateAppearance() | 1740 void FrameSelection::updateAppearance() |
1740 { | 1741 { |
1742 // Paint a block cursor instead of a caret in overtype mode unless the caret is at the end of a line (in this case | |
1743 // the FrameSelection will paint a blinking caret as usual). | |
esprehn
2013/05/06 16:42:10
Why doesn't the block blink? I seem to recall edit
| |
1744 VisiblePosition forwardPosition; | |
1745 if (m_shouldShowBlockCursor && m_selection.isCaret()) { | |
1746 forwardPosition = modifyExtendingForward(CharacterGranularity); | |
1747 m_caretPaint = forwardPosition.isNull(); | |
1748 } | |
1749 | |
1741 bool caretRectChangedOrCleared = recomputeCaretRect(); | 1750 bool caretRectChangedOrCleared = recomputeCaretRect(); |
1742 | 1751 |
1743 bool caretBrowsing = m_frame->settings() && m_frame->settings()->caretBrowsi ngEnabled(); | 1752 bool caretBrowsing = m_frame->settings() && m_frame->settings()->caretBrowsi ngEnabled(); |
1744 bool shouldBlink = caretIsVisible() && isCaret() && (isContentEditable() || caretBrowsing); | 1753 bool shouldBlink = caretIsVisible() && isCaret() && (isContentEditable() || caretBrowsing) && forwardPosition.isNull(); |
1745 | 1754 |
1746 // If the caret moved, stop the blink timer so we can restart with a | 1755 // If the caret moved, stop the blink timer so we can restart with a |
1747 // black caret in the new location. | 1756 // black caret in the new location. |
1748 if (caretRectChangedOrCleared || !shouldBlink || shouldStopBlinkingDueToTypi ngCommand(m_frame)) | 1757 if (caretRectChangedOrCleared || !shouldBlink || shouldStopBlinkingDueToTypi ngCommand(m_frame)) |
1749 m_caretBlinkTimer.stop(); | 1758 m_caretBlinkTimer.stop(); |
1750 | 1759 |
1751 // Start blinking with a black caret. Be sure not to restart if we're | 1760 // Start blinking with a black caret. Be sure not to restart if we're |
1752 // already blinking in the right location. | 1761 // already blinking in the right location. |
1753 if (shouldBlink && !m_caretBlinkTimer.isActive()) { | 1762 if (shouldBlink && !m_caretBlinkTimer.isActive()) { |
1754 if (double blinkInterval = m_frame->page()->theme()->caretBlinkInterval( )) | 1763 if (double blinkInterval = m_frame->page()->theme()->caretBlinkInterval( )) |
1755 m_caretBlinkTimer.startRepeating(blinkInterval); | 1764 m_caretBlinkTimer.startRepeating(blinkInterval); |
1756 | 1765 |
1757 if (!m_caretPaint) { | 1766 if (!m_caretPaint) { |
1758 m_caretPaint = true; | 1767 m_caretPaint = true; |
1759 invalidateCaretRect(); | 1768 invalidateCaretRect(); |
1760 } | 1769 } |
1761 } | 1770 } |
1762 | 1771 |
1763 RenderView* view = m_frame->contentRenderer(); | 1772 RenderView* view = m_frame->contentRenderer(); |
1764 if (!view) | 1773 if (!view) |
1765 return; | 1774 return; |
1766 | 1775 |
1767 // Construct a new VisibleSolution, since m_selection is not necessarily val id, and the following steps | 1776 // Construct a new VisibleSolution, since m_selection is not necessarily val id, and the following steps |
1768 // assume a valid selection. See <https://bugs.webkit.org/show_bug.cgi?id=69 563> and <rdar://problem/10232866>. | 1777 // assume a valid selection. See <https://bugs.webkit.org/show_bug.cgi?id=69 563> and <rdar://problem/10232866>. |
1769 VisibleSelection selection(m_selection.visibleStart(), m_selection.visibleEn d()); | 1778 VisibleSelection selection(m_selection.visibleStart(), forwardPosition.isNot Null() ? forwardPosition : m_selection.visibleEnd()); |
1770 | 1779 |
1771 if (!selection.isRange()) { | 1780 if (!selection.isRange()) { |
1772 view->clearSelection(); | 1781 view->clearSelection(); |
1773 return; | 1782 return; |
1774 } | 1783 } |
1775 | 1784 |
1776 // Use the rightmost candidate for the start of the selection, and the leftm ost candidate for the end of the selection. | 1785 // Use the rightmost candidate for the start of the selection, and the leftm ost candidate for the end of the selection. |
1777 // Example: foo <a>bar</a>. Imagine that a line wrap occurs after 'foo', an d that 'bar' is selected. If we pass [foo, 3] | 1786 // Example: foo <a>bar</a>. Imagine that a line wrap occurs after 'foo', an d that 'bar' is selected. If we pass [foo, 3] |
1778 // as the start of the selection, the selection painting code will think tha t content on the line containing 'foo' is selected | 1787 // as the start of the selection, the selection painting code will think tha t content on the line containing 'foo' is selected |
1779 // and will fill the gap before 'bar'. | 1788 // and will fill the gap before 'bar'. |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2019 | 2028 |
2020 return selectStartTarget->dispatchEvent(Event::create(eventNames().selectsta rtEvent, true, true)); | 2029 return selectStartTarget->dispatchEvent(Event::create(eventNames().selectsta rtEvent, true, true)); |
2021 } | 2030 } |
2022 | 2031 |
2023 inline bool FrameSelection::visualWordMovementEnabled() const | 2032 inline bool FrameSelection::visualWordMovementEnabled() const |
2024 { | 2033 { |
2025 Settings* settings = m_frame ? m_frame->settings() : 0; | 2034 Settings* settings = m_frame ? m_frame->settings() : 0; |
2026 return settings && settings->visualWordMovementEnabled(); | 2035 return settings && settings->visualWordMovementEnabled(); |
2027 } | 2036 } |
2028 | 2037 |
2038 void FrameSelection::setShouldShowBlockCursor(bool shouldShowBlockCursor) | |
2039 { | |
2040 m_shouldShowBlockCursor = shouldShowBlockCursor; | |
2041 | |
2042 m_frame->document()->updateLayoutIgnorePendingStylesheets(); | |
2043 | |
2044 updateAppearance(); | |
2045 } | |
2046 | |
2029 #ifndef NDEBUG | 2047 #ifndef NDEBUG |
2030 | 2048 |
2031 void FrameSelection::formatForDebugger(char* buffer, unsigned length) const | 2049 void FrameSelection::formatForDebugger(char* buffer, unsigned length) const |
2032 { | 2050 { |
2033 m_selection.formatForDebugger(buffer, length); | 2051 m_selection.formatForDebugger(buffer, length); |
2034 } | 2052 } |
2035 | 2053 |
2036 void FrameSelection::showTreeForThis() const | 2054 void FrameSelection::showTreeForThis() const |
2037 { | 2055 { |
2038 m_selection.showTreeForThis(); | 2056 m_selection.showTreeForThis(); |
(...skipping 10 matching lines...) Expand all Loading... | |
2049 sel.showTreeForThis(); | 2067 sel.showTreeForThis(); |
2050 } | 2068 } |
2051 | 2069 |
2052 void showTree(const WebCore::FrameSelection* sel) | 2070 void showTree(const WebCore::FrameSelection* sel) |
2053 { | 2071 { |
2054 if (sel) | 2072 if (sel) |
2055 sel->showTreeForThis(); | 2073 sel->showTreeForThis(); |
2056 } | 2074 } |
2057 | 2075 |
2058 #endif | 2076 #endif |
OLD | NEW |