OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. |
3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) | 3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) |
4 * Copyright (C) 2009 Igalia S.L. | 4 * Copyright (C) 2009 Igalia S.L. |
5 * | 5 * |
6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
8 * are met: | 8 * are met: |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 1866 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1877 static bool enabledCut(LocalFrame& frame, Event*, EditorCommandSource source) { | 1877 static bool enabledCut(LocalFrame& frame, Event*, EditorCommandSource source) { |
1878 if (!canWriteClipboard(frame, source)) | 1878 if (!canWriteClipboard(frame, source)) |
1879 return false; | 1879 return false; |
1880 return frame.editor().canDHTMLCut() || frame.editor().canCut(); | 1880 return frame.editor().canDHTMLCut() || frame.editor().canCut(); |
1881 } | 1881 } |
1882 | 1882 |
1883 static bool enabledInEditableText(LocalFrame& frame, | 1883 static bool enabledInEditableText(LocalFrame& frame, |
1884 Event* event, | 1884 Event* event, |
1885 EditorCommandSource) { | 1885 EditorCommandSource) { |
1886 frame.document()->updateStyleAndLayoutIgnorePendingStylesheets(); | 1886 frame.document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
1887 | |
1888 // We should update selection to canonicalize with current layout and style, | |
1889 // before accessing |FrameSelection::selection()|. | |
1890 frame.selection().updateIfNeeded(); | |
1891 return frame.editor().selectionForCommand(event).rootEditableElement(); | 1887 return frame.editor().selectionForCommand(event).rootEditableElement(); |
1892 } | 1888 } |
1893 | 1889 |
1894 static bool enabledDelete(LocalFrame& frame, | 1890 static bool enabledDelete(LocalFrame& frame, |
1895 Event* event, | 1891 Event* event, |
1896 EditorCommandSource source) { | 1892 EditorCommandSource source) { |
1897 switch (source) { | 1893 switch (source) { |
1898 case CommandFromMenuOrKeyBinding: | 1894 case CommandFromMenuOrKeyBinding: |
1899 return frame.editor().canDelete(); | 1895 return frame.editor().canDelete(); |
1900 case CommandFromDOM: | 1896 case CommandFromDOM: |
1901 // "Delete" from DOM is like delete/backspace keypress, affects selected | 1897 // "Delete" from DOM is like delete/backspace keypress, affects selected |
1902 // range if non-empty, otherwise removes a character | 1898 // range if non-empty, otherwise removes a character |
1903 return enabledInEditableText(frame, event, source); | 1899 return enabledInEditableText(frame, event, source); |
1904 } | 1900 } |
1905 NOTREACHED(); | 1901 NOTREACHED(); |
1906 return false; | 1902 return false; |
1907 } | 1903 } |
1908 | 1904 |
1909 static bool enabledInRichlyEditableText(LocalFrame& frame, | 1905 static bool enabledInRichlyEditableText(LocalFrame& frame, |
1910 Event*, | 1906 Event*, |
1911 EditorCommandSource) { | 1907 EditorCommandSource) { |
1912 frame.document()->updateStyleAndLayoutIgnorePendingStylesheets(); | 1908 frame.document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
1913 | |
1914 // We should update selection to canonicalize with current layout and style, | |
1915 // before accessing |FrameSelection::selection()|. | |
1916 frame.selection().updateIfNeeded(); | |
1917 return !frame.selection() | 1909 return !frame.selection() |
1918 .computeVisibleSelectionInDOMTreeDeprecated() | 1910 .computeVisibleSelectionInDOMTreeDeprecated() |
1919 .isNone() && | 1911 .isNone() && |
1920 frame.selection() | 1912 frame.selection() |
1921 .computeVisibleSelectionInDOMTreeDeprecated() | 1913 .computeVisibleSelectionInDOMTreeDeprecated() |
1922 .isContentRichlyEditable() && | 1914 .isContentRichlyEditable() && |
1923 frame.selection() | 1915 frame.selection() |
1924 .computeVisibleSelectionInDOMTreeDeprecated() | 1916 .computeVisibleSelectionInDOMTreeDeprecated() |
1925 .rootEditableElement(); | 1917 .rootEditableElement(); |
1926 } | 1918 } |
1927 | 1919 |
1928 static bool enabledPaste(LocalFrame& frame, | 1920 static bool enabledPaste(LocalFrame& frame, |
1929 Event*, | 1921 Event*, |
1930 EditorCommandSource source) { | 1922 EditorCommandSource source) { |
1931 if (!canReadClipboard(frame, source)) | 1923 if (!canReadClipboard(frame, source)) |
1932 return false; | 1924 return false; |
1933 return frame.editor().canPaste(); | 1925 return frame.editor().canPaste(); |
1934 } | 1926 } |
1935 | 1927 |
1936 static bool enabledRangeInEditableText(LocalFrame& frame, | 1928 static bool enabledRangeInEditableText(LocalFrame& frame, |
1937 Event*, | 1929 Event*, |
1938 EditorCommandSource) { | 1930 EditorCommandSource) { |
1939 frame.document()->updateStyleAndLayoutIgnorePendingStylesheets(); | 1931 frame.document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
1940 | |
1941 // We should update selection to canonicalize with current layout and style, | |
1942 // before accessing |FrameSelection::selection()|. | |
1943 frame.selection().updateIfNeeded(); | |
1944 return frame.selection() | 1932 return frame.selection() |
1945 .computeVisibleSelectionInDOMTreeDeprecated() | 1933 .computeVisibleSelectionInDOMTreeDeprecated() |
1946 .isRange() && | 1934 .isRange() && |
1947 frame.selection() | 1935 frame.selection() |
1948 .computeVisibleSelectionInDOMTreeDeprecated() | 1936 .computeVisibleSelectionInDOMTreeDeprecated() |
1949 .isContentEditable(); | 1937 .isContentEditable(); |
1950 } | 1938 } |
1951 | 1939 |
1952 static bool enabledRangeInRichlyEditableText(LocalFrame& frame, | 1940 static bool enabledRangeInRichlyEditableText(LocalFrame& frame, |
1953 Event*, | 1941 Event*, |
1954 EditorCommandSource) { | 1942 EditorCommandSource) { |
1955 frame.document()->updateStyleAndLayoutIgnorePendingStylesheets(); | 1943 frame.document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
1956 | |
1957 // We should update selection to canonicalize with current layout and style, | |
1958 // before accessing |FrameSelection::selection()|. | |
1959 frame.selection().updateIfNeeded(); | |
1960 return frame.selection() | 1944 return frame.selection() |
1961 .computeVisibleSelectionInDOMTreeDeprecated() | 1945 .computeVisibleSelectionInDOMTreeDeprecated() |
1962 .isRange() && | 1946 .isRange() && |
1963 frame.selection() | 1947 frame.selection() |
1964 .computeVisibleSelectionInDOMTreeDeprecated() | 1948 .computeVisibleSelectionInDOMTreeDeprecated() |
1965 .isContentRichlyEditable(); | 1949 .isContentRichlyEditable(); |
1966 } | 1950 } |
1967 | 1951 |
1968 static bool enabledRedo(LocalFrame& frame, Event*, EditorCommandSource) { | 1952 static bool enabledRedo(LocalFrame& frame, Event*, EditorCommandSource) { |
1969 return frame.editor().canRedo(); | 1953 return frame.editor().canRedo(); |
(...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2766 *m_frame, DirectionBackward, WordGranularity); | 2750 *m_frame, DirectionBackward, WordGranularity); |
2767 case WebEditingCommandType::DeleteWordForward: | 2751 case WebEditingCommandType::DeleteWordForward: |
2768 return RangesFromCurrentSelectionOrExtendCaret(*m_frame, DirectionForward, | 2752 return RangesFromCurrentSelectionOrExtendCaret(*m_frame, DirectionForward, |
2769 WordGranularity); | 2753 WordGranularity); |
2770 default: | 2754 default: |
2771 return targetRangesForInputEvent(*target); | 2755 return targetRangesForInputEvent(*target); |
2772 } | 2756 } |
2773 } | 2757 } |
2774 | 2758 |
2775 } // namespace blink | 2759 } // namespace blink |
OLD | NEW |