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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 | 104 |
105 FrameSelection::FrameSelection(Frame* frame) | 105 FrameSelection::FrameSelection(Frame* frame) |
106 : m_frame(frame) | 106 : m_frame(frame) |
107 , m_xPosForVerticalArrowNavigation(NoXPosForVerticalArrowNavigation()) | 107 , m_xPosForVerticalArrowNavigation(NoXPosForVerticalArrowNavigation()) |
108 , m_granularity(CharacterGranularity) | 108 , m_granularity(CharacterGranularity) |
109 , m_caretBlinkTimer(this, &FrameSelection::caretBlinkTimerFired) | 109 , m_caretBlinkTimer(this, &FrameSelection::caretBlinkTimerFired) |
110 , m_absCaretBoundsDirty(true) | 110 , m_absCaretBoundsDirty(true) |
111 , m_caretPaint(true) | 111 , m_caretPaint(true) |
112 , m_isCaretBlinkingSuspended(false) | 112 , m_isCaretBlinkingSuspended(false) |
113 , m_focused(frame && frame->page() && frame->page()->focusController()->focu
sedFrame() == frame) | 113 , m_focused(frame && frame->page() && frame->page()->focusController()->focu
sedFrame() == frame) |
| 114 , m_shouldShowBlockCursor(false) |
114 { | 115 { |
115 if (shouldAlwaysUseDirectionalSelection(m_frame)) | 116 if (shouldAlwaysUseDirectionalSelection(m_frame)) |
116 m_selection.setIsDirectional(true); | 117 m_selection.setIsDirectional(true); |
117 } | 118 } |
118 | 119 |
119 Element* FrameSelection::rootEditableElementOrDocumentElement() const | 120 Element* FrameSelection::rootEditableElementOrDocumentElement() const |
120 { | 121 { |
121 Element* selectionRoot = m_selection.rootEditableElement(); | 122 Element* selectionRoot = m_selection.rootEditableElement(); |
122 return selectionRoot ? selectionRoot : m_frame->document()->documentElement(
); | 123 return selectionRoot ? selectionRoot : m_frame->document()->documentElement(
); |
123 } | 124 } |
(...skipping 1629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1753 return m_focused && m_frame->page() && m_frame->page()->focusController()->i
sActive(); | 1754 return m_focused && m_frame->page() && m_frame->page()->focusController()->i
sActive(); |
1754 } | 1755 } |
1755 | 1756 |
1756 inline static bool shouldStopBlinkingDueToTypingCommand(Frame* frame) | 1757 inline static bool shouldStopBlinkingDueToTypingCommand(Frame* frame) |
1757 { | 1758 { |
1758 return frame->editor()->lastEditCommand() && frame->editor()->lastEditComman
d()->shouldStopCaretBlinking(); | 1759 return frame->editor()->lastEditCommand() && frame->editor()->lastEditComman
d()->shouldStopCaretBlinking(); |
1759 } | 1760 } |
1760 | 1761 |
1761 void FrameSelection::updateAppearance() | 1762 void FrameSelection::updateAppearance() |
1762 { | 1763 { |
| 1764 // Paint a block cursor instead of a caret in overtype mode unless the caret
is at the end of a line (in this case |
| 1765 // the FrameSelection will paint a blinking caret as usual). |
| 1766 VisiblePosition forwardPosition; |
| 1767 if (m_shouldShowBlockCursor && m_selection.isCaret()) { |
| 1768 forwardPosition = modifyExtendingForward(CharacterGranularity); |
| 1769 m_caretPaint = forwardPosition.isNull(); |
| 1770 } |
| 1771 |
1763 bool caretRectChangedOrCleared = recomputeCaretRect(); | 1772 bool caretRectChangedOrCleared = recomputeCaretRect(); |
1764 | 1773 |
1765 bool caretBrowsing = m_frame->settings() && m_frame->settings()->caretBrowsi
ngEnabled(); | 1774 bool caretBrowsing = m_frame->settings() && m_frame->settings()->caretBrowsi
ngEnabled(); |
1766 bool shouldBlink = caretIsVisible() && isCaret() && (isContentEditable() ||
caretBrowsing); | 1775 bool shouldBlink = caretIsVisible() && isCaret() && (isContentEditable() ||
caretBrowsing) && forwardPosition.isNull(); |
1767 | 1776 |
1768 // If the caret moved, stop the blink timer so we can restart with a | 1777 // If the caret moved, stop the blink timer so we can restart with a |
1769 // black caret in the new location. | 1778 // black caret in the new location. |
1770 if (caretRectChangedOrCleared || !shouldBlink || shouldStopBlinkingDueToTypi
ngCommand(m_frame)) | 1779 if (caretRectChangedOrCleared || !shouldBlink || shouldStopBlinkingDueToTypi
ngCommand(m_frame)) |
1771 m_caretBlinkTimer.stop(); | 1780 m_caretBlinkTimer.stop(); |
1772 | 1781 |
1773 // Start blinking with a black caret. Be sure not to restart if we're | 1782 // Start blinking with a black caret. Be sure not to restart if we're |
1774 // already blinking in the right location. | 1783 // already blinking in the right location. |
1775 if (shouldBlink && !m_caretBlinkTimer.isActive()) { | 1784 if (shouldBlink && !m_caretBlinkTimer.isActive()) { |
1776 if (double blinkInterval = m_frame->page()->theme()->caretBlinkInterval(
)) | 1785 if (double blinkInterval = m_frame->page()->theme()->caretBlinkInterval(
)) |
1777 m_caretBlinkTimer.startRepeating(blinkInterval); | 1786 m_caretBlinkTimer.startRepeating(blinkInterval); |
1778 | 1787 |
1779 if (!m_caretPaint) { | 1788 if (!m_caretPaint) { |
1780 m_caretPaint = true; | 1789 m_caretPaint = true; |
1781 invalidateCaretRect(); | 1790 invalidateCaretRect(); |
1782 } | 1791 } |
1783 } | 1792 } |
1784 | 1793 |
1785 RenderView* view = m_frame->contentRenderer(); | 1794 RenderView* view = m_frame->contentRenderer(); |
1786 if (!view) | 1795 if (!view) |
1787 return; | 1796 return; |
1788 | 1797 |
1789 // Construct a new VisibleSolution, since m_selection is not necessarily val
id, and the following steps | 1798 // Construct a new VisibleSolution, since m_selection is not necessarily val
id, and the following steps |
1790 // assume a valid selection. See <https://bugs.webkit.org/show_bug.cgi?id=69
563> and <rdar://problem/10232866>. | 1799 // assume a valid selection. See <https://bugs.webkit.org/show_bug.cgi?id=69
563> and <rdar://problem/10232866>. |
1791 VisibleSelection selection(m_selection.visibleStart(), m_selection.visibleEn
d()); | 1800 VisibleSelection selection(m_selection.visibleStart(), forwardPosition.isNot
Null() ? forwardPosition : m_selection.visibleEnd()); |
1792 | 1801 |
1793 if (!selection.isRange()) { | 1802 if (!selection.isRange()) { |
1794 view->clearSelection(); | 1803 view->clearSelection(); |
1795 return; | 1804 return; |
1796 } | 1805 } |
1797 | 1806 |
1798 // Use the rightmost candidate for the start of the selection, and the leftm
ost candidate for the end of the selection. | 1807 // Use the rightmost candidate for the start of the selection, and the leftm
ost candidate for the end of the selection. |
1799 // Example: foo <a>bar</a>. Imagine that a line wrap occurs after 'foo', an
d that 'bar' is selected. If we pass [foo, 3] | 1808 // Example: foo <a>bar</a>. Imagine that a line wrap occurs after 'foo', an
d that 'bar' is selected. If we pass [foo, 3] |
1800 // as the start of the selection, the selection painting code will think tha
t content on the line containing 'foo' is selected | 1809 // as the start of the selection, the selection painting code will think tha
t content on the line containing 'foo' is selected |
1801 // and will fill the gap before 'bar'. | 1810 // and will fill the gap before 'bar'. |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2041 | 2050 |
2042 return selectStartTarget->dispatchEvent(Event::create(eventNames().selectsta
rtEvent, true, true)); | 2051 return selectStartTarget->dispatchEvent(Event::create(eventNames().selectsta
rtEvent, true, true)); |
2043 } | 2052 } |
2044 | 2053 |
2045 inline bool FrameSelection::visualWordMovementEnabled() const | 2054 inline bool FrameSelection::visualWordMovementEnabled() const |
2046 { | 2055 { |
2047 Settings* settings = m_frame ? m_frame->settings() : 0; | 2056 Settings* settings = m_frame ? m_frame->settings() : 0; |
2048 return settings && settings->visualWordMovementEnabled(); | 2057 return settings && settings->visualWordMovementEnabled(); |
2049 } | 2058 } |
2050 | 2059 |
| 2060 void FrameSelection::setShouldShowBlockCursor(bool shouldShowBlockCursor) |
| 2061 { |
| 2062 m_shouldShowBlockCursor = shouldShowBlockCursor; |
| 2063 |
| 2064 m_frame->document()->updateLayoutIgnorePendingStylesheets(); |
| 2065 |
| 2066 updateAppearance(); |
| 2067 } |
| 2068 |
2051 #ifndef NDEBUG | 2069 #ifndef NDEBUG |
2052 | 2070 |
2053 void FrameSelection::formatForDebugger(char* buffer, unsigned length) const | 2071 void FrameSelection::formatForDebugger(char* buffer, unsigned length) const |
2054 { | 2072 { |
2055 m_selection.formatForDebugger(buffer, length); | 2073 m_selection.formatForDebugger(buffer, length); |
2056 } | 2074 } |
2057 | 2075 |
2058 void FrameSelection::showTreeForThis() const | 2076 void FrameSelection::showTreeForThis() const |
2059 { | 2077 { |
2060 m_selection.showTreeForThis(); | 2078 m_selection.showTreeForThis(); |
(...skipping 10 matching lines...) Expand all Loading... |
2071 sel.showTreeForThis(); | 2089 sel.showTreeForThis(); |
2072 } | 2090 } |
2073 | 2091 |
2074 void showTree(const WebCore::FrameSelection* sel) | 2092 void showTree(const WebCore::FrameSelection* sel) |
2075 { | 2093 { |
2076 if (sel) | 2094 if (sel) |
2077 sel->showTreeForThis(); | 2095 sel->showTreeForThis(); |
2078 } | 2096 } |
2079 | 2097 |
2080 #endif | 2098 #endif |
OLD | NEW |