Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights | 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights |
| 3 * reserved. | 3 * reserved. |
| 4 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) | 4 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) |
| 5 * Copyright (C) 2012 Digia Plc. and/or its subsidiary(-ies) | 5 * Copyright (C) 2012 Digia Plc. and/or its subsidiary(-ies) |
| 6 * | 6 * |
| 7 * Redistribution and use in source and binary forms, with or without | 7 * Redistribution and use in source and binary forms, with or without |
| 8 * modification, are permitted provided that the following conditions | 8 * modification, are permitted provided that the following conditions |
| 9 * are met: | 9 * are met: |
| 10 * 1. Redistributions of source code must retain the above copyright | 10 * 1. Redistributions of source code must retain the above copyright |
| (...skipping 1784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1795 | 1795 |
| 1796 GetSelectionController().SendContextMenuEvent(mev, position_in_contents); | 1796 GetSelectionController().SendContextMenuEvent(mev, position_in_contents); |
| 1797 | 1797 |
| 1798 Node* target_node = | 1798 Node* target_node = |
| 1799 override_target_node ? override_target_node : mev.InnerNode(); | 1799 override_target_node ? override_target_node : mev.InnerNode(); |
| 1800 return mouse_event_manager_->DispatchMouseEvent( | 1800 return mouse_event_manager_->DispatchMouseEvent( |
| 1801 UpdateMouseEventTargetNode(target_node), EventTypeNames::contextmenu, | 1801 UpdateMouseEventTargetNode(target_node), EventTypeNames::contextmenu, |
| 1802 event, mev.GetHitTestResult().CanvasRegionId(), 0); | 1802 event, mev.GetHitTestResult().CanvasRegionId(), 0); |
| 1803 } | 1803 } |
| 1804 | 1804 |
| 1805 static bool ShouldShowContextMenuAtSelection(const LocalFrame& frame) { | |
|
Xiaocheng
2017/05/17 19:20:26
nit: I prefer passing FrameSelection to reduce a c
yosin_UTC9
2017/05/18 01:17:15
me too.
hugoh_UTC2
2017/05/22 12:26:12
Done.
| |
| 1806 FrameSelection& selection = frame.Selection(); | |
| 1807 VisibleSelection visible_selection = | |
| 1808 selection.ComputeVisibleSelectionInDOMTreeDeprecated(); | |
| 1809 if (!visible_selection.IsRange() && !visible_selection.RootEditableElement()) | |
| 1810 return false; | |
| 1811 | |
|
yosin_UTC9
2017/05/18 01:17:15
nit: Please remove an extra blank line.
hugoh_UTC2
2017/05/22 12:26:12
Done.
| |
| 1812 return selection.SelectionHasFocus(); | |
| 1813 } | |
| 1814 | |
| 1805 WebInputEventResult EventHandler::SendContextMenuEventForKey( | 1815 WebInputEventResult EventHandler::SendContextMenuEventForKey( |
| 1806 Element* override_target_element) { | 1816 Element* override_target_element) { |
| 1807 FrameView* view = frame_->View(); | 1817 FrameView* view = frame_->View(); |
| 1808 if (!view) | 1818 if (!view) |
| 1809 return WebInputEventResult::kNotHandled; | 1819 return WebInputEventResult::kNotHandled; |
| 1810 | 1820 |
| 1811 Document* doc = frame_->GetDocument(); | 1821 Document* doc = frame_->GetDocument(); |
| 1812 if (!doc) | 1822 if (!doc) |
| 1813 return WebInputEventResult::kNotHandled; | 1823 return WebInputEventResult::kNotHandled; |
| 1814 | 1824 |
| 1815 static const int kContextMenuMargin = 1; | 1825 static const int kContextMenuMargin = 1; |
| 1816 | 1826 |
| 1817 #if OS(WIN) | 1827 #if OS(WIN) |
| 1818 int right_aligned = ::GetSystemMetrics(SM_MENUDROPALIGNMENT); | 1828 int right_aligned = ::GetSystemMetrics(SM_MENUDROPALIGNMENT); |
| 1819 #else | 1829 #else |
| 1820 int right_aligned = 0; | 1830 int right_aligned = 0; |
| 1821 #endif | 1831 #endif |
| 1822 IntPoint location_in_root_frame; | 1832 IntPoint location_in_root_frame; |
| 1823 | 1833 |
| 1824 Element* focused_element = | 1834 Element* focused_element = |
| 1825 override_target_element ? override_target_element : doc->FocusedElement(); | 1835 override_target_element ? override_target_element : doc->FocusedElement(); |
| 1826 FrameSelection& selection = frame_->Selection(); | 1836 FrameSelection& selection = frame_->Selection(); |
| 1827 Position start = | |
| 1828 selection.ComputeVisibleSelectionInDOMTreeDeprecated().Start(); | |
| 1829 VisualViewport& visual_viewport = frame_->GetPage()->GetVisualViewport(); | 1837 VisualViewport& visual_viewport = frame_->GetPage()->GetVisualViewport(); |
| 1830 | 1838 |
| 1831 if (!override_target_element && start.AnchorNode() && !selection.IsHidden() && | 1839 if (!override_target_element && ShouldShowContextMenuAtSelection(*frame_)) { |
| 1832 (selection.ComputeVisibleSelectionInDOMTreeDeprecated() | |
| 1833 .RootEditableElement() || | |
| 1834 selection.ComputeVisibleSelectionInDOMTreeDeprecated().IsRange())) { | |
| 1835 // TODO(editing-dev): Use of updateStyleAndLayoutIgnorePendingStylesheets | 1840 // TODO(editing-dev): Use of updateStyleAndLayoutIgnorePendingStylesheets |
| 1836 // needs to be audited. See http://crbug.com/590369 for more details. | 1841 // needs to be audited. See http://crbug.com/590369 for more details. |
| 1837 doc->UpdateStyleAndLayoutIgnorePendingStylesheets(); | 1842 doc->UpdateStyleAndLayoutIgnorePendingStylesheets(); |
| 1838 | 1843 |
| 1839 IntRect first_rect = frame_->GetEditor().FirstRectForRange( | 1844 IntRect first_rect = frame_->GetEditor().FirstRectForRange( |
| 1840 selection.ComputeVisibleSelectionInDOMTree() | 1845 selection.ComputeVisibleSelectionInDOMTree() |
| 1841 .ToNormalizedEphemeralRange()); | 1846 .ToNormalizedEphemeralRange()); |
| 1842 | 1847 |
| 1843 int x = right_aligned ? first_rect.MaxX() : first_rect.X(); | 1848 int x = right_aligned ? first_rect.MaxX() : first_rect.X(); |
| 1844 // In a multiline edit, firstRect.maxY() would end up on the next line, so | 1849 // In a multiline edit, firstRect.maxY() would end up on the next line, so |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2119 MouseEventWithHitTestResults& mev, | 2124 MouseEventWithHitTestResults& mev, |
| 2120 LocalFrame* subframe) { | 2125 LocalFrame* subframe) { |
| 2121 WebInputEventResult result = | 2126 WebInputEventResult result = |
| 2122 subframe->GetEventHandler().HandleMouseReleaseEvent(mev.Event()); | 2127 subframe->GetEventHandler().HandleMouseReleaseEvent(mev.Event()); |
| 2123 if (result != WebInputEventResult::kNotHandled) | 2128 if (result != WebInputEventResult::kNotHandled) |
| 2124 return result; | 2129 return result; |
| 2125 return WebInputEventResult::kHandledSystem; | 2130 return WebInputEventResult::kHandledSystem; |
| 2126 } | 2131 } |
| 2127 | 2132 |
| 2128 } // namespace blink | 2133 } // namespace blink |
| OLD | NEW |