Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/renderer_host/render_widget_host_view_aura.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_aura.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
| (...skipping 1801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1812 // We don't have to communicate with an input method here. | 1812 // We don't have to communicate with an input method here. |
| 1813 NativeWebKeyboardEvent webkit_event(*event); | 1813 NativeWebKeyboardEvent webkit_event(*event); |
| 1814 ForwardKeyboardEvent(webkit_event); | 1814 ForwardKeyboardEvent(webkit_event); |
| 1815 } | 1815 } |
| 1816 event->SetHandled(); | 1816 event->SetHandled(); |
| 1817 } | 1817 } |
| 1818 | 1818 |
| 1819 void RenderWidgetHostViewAura::OnMouseEvent(ui::MouseEvent* event) { | 1819 void RenderWidgetHostViewAura::OnMouseEvent(ui::MouseEvent* event) { |
| 1820 TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnMouseEvent"); | 1820 TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnMouseEvent"); |
| 1821 | 1821 |
| 1822 if (event->type() == ui::ET_MOUSE_MOVED) { | |
|
scheib
2016/10/04 02:01:34
It seems correct only if a move event will always
ananta
2016/10/04 02:21:20
On Windows, a visible window can safely assume tha
| |
| 1823 last_mouse_position_.set_x(event->x()); | |
| 1824 last_mouse_position_.set_y(event->y()); | |
| 1825 } else if (event->type() == ui::ET_MOUSE_ENTERED || | |
| 1826 event->type() == ui::ET_MOUSE_EXITED) { | |
| 1827 // For mouse entered and exited states the |ui_mouse_event| parameter | |
| 1828 // contains the location of the cursor which does not work for webpages as | |
| 1829 // they may track mouse movement deltas. To ensure that the deltas are | |
| 1830 // correct we set the location of the event to the last mouse move | |
| 1831 // location. | |
| 1832 event->set_location(last_mouse_position_); | |
| 1833 } | |
| 1834 | |
| 1822 ForwardMouseEventToParent(event); | 1835 ForwardMouseEventToParent(event); |
| 1836 | |
| 1823 // TODO(mgiuca): Return if event->handled() returns true. This currently | 1837 // TODO(mgiuca): Return if event->handled() returns true. This currently |
| 1824 // breaks drop-down lists which means something is incorrectly setting | 1838 // breaks drop-down lists which means something is incorrectly setting |
| 1825 // event->handled to true (http://crbug.com/577983). | 1839 // event->handled to true (http://crbug.com/577983). |
| 1826 | 1840 |
| 1827 if (mouse_locked_) { | 1841 if (mouse_locked_) { |
| 1828 aura::client::CursorClient* cursor_client = | 1842 aura::client::CursorClient* cursor_client = |
| 1829 aura::client::GetCursorClient(window_->GetRootWindow()); | 1843 aura::client::GetCursorClient(window_->GetRootWindow()); |
| 1830 DCHECK(!cursor_client || !cursor_client->IsCursorVisible()); | 1844 DCHECK(!cursor_client || !cursor_client->IsCursorVisible()); |
| 1831 | 1845 |
| 1832 if (event->type() == ui::ET_MOUSEWHEEL) { | 1846 if (event->type() == ui::ET_MOUSEWHEEL) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1868 IsFractionalScaleFactor(current_device_scale_factor_)) { | 1882 IsFractionalScaleFactor(current_device_scale_factor_)) { |
| 1869 if (event->type() == ui::ET_MOUSE_MOVED || | 1883 if (event->type() == ui::ET_MOUSE_MOVED || |
| 1870 event->type() == ui::ET_MOUSE_DRAGGED) { | 1884 event->type() == ui::ET_MOUSE_DRAGGED) { |
| 1871 if ((abs(mouse_event.x - center.x()) <= 2) && | 1885 if ((abs(mouse_event.x - center.x()) <= 2) && |
| 1872 (abs(mouse_event.y - center.y()) <= 2)) { | 1886 (abs(mouse_event.y - center.y()) <= 2)) { |
| 1873 is_move_to_center_event = true; | 1887 is_move_to_center_event = true; |
| 1874 } | 1888 } |
| 1875 } | 1889 } |
| 1876 } | 1890 } |
| 1877 | 1891 |
| 1878 ModifyEventMovementAndCoords(&mouse_event); | 1892 ModifyEventMovementAndCoords(&mouse_event, event); |
| 1879 | 1893 |
| 1880 bool should_not_forward = is_move_to_center_event && synthetic_move_sent_; | 1894 bool should_not_forward = is_move_to_center_event && synthetic_move_sent_; |
| 1881 if (should_not_forward) { | 1895 if (should_not_forward) { |
| 1882 synthetic_move_sent_ = false; | 1896 synthetic_move_sent_ = false; |
| 1883 } else { | 1897 } else { |
| 1884 // Check if the mouse has reached the border and needs to be centered. | 1898 // Check if the mouse has reached the border and needs to be centered. |
| 1885 if (ShouldMoveToCenter()) { | 1899 if (ShouldMoveToCenter()) { |
| 1886 synthetic_move_sent_ = true; | 1900 synthetic_move_sent_ = true; |
| 1887 window_->MoveCursorTo(center); | 1901 window_->MoveCursorTo(center); |
| 1888 } | 1902 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1947 popup_child_host_view_ && popup_child_host_view_->NeedsInputGrab(); | 1961 popup_child_host_view_ && popup_child_host_view_->NeedsInputGrab(); |
| 1948 if (CanRendererHandleEvent(event, mouse_locked_, is_selection_popup) && | 1962 if (CanRendererHandleEvent(event, mouse_locked_, is_selection_popup) && |
| 1949 !(event->flags() & ui::EF_FROM_TOUCH)) { | 1963 !(event->flags() & ui::EF_FROM_TOUCH)) { |
| 1950 // Confirm existing composition text on mouse press, to make sure | 1964 // Confirm existing composition text on mouse press, to make sure |
| 1951 // the input caret won't be moved with an ongoing composition text. | 1965 // the input caret won't be moved with an ongoing composition text. |
| 1952 if (event->type() == ui::ET_MOUSE_PRESSED) | 1966 if (event->type() == ui::ET_MOUSE_PRESSED) |
| 1953 FinishImeCompositionSession(); | 1967 FinishImeCompositionSession(); |
| 1954 | 1968 |
| 1955 blink::WebMouseEvent mouse_event = ui::MakeWebMouseEvent( | 1969 blink::WebMouseEvent mouse_event = ui::MakeWebMouseEvent( |
| 1956 *event, base::Bind(&GetScreenLocationFromEvent)); | 1970 *event, base::Bind(&GetScreenLocationFromEvent)); |
| 1957 ModifyEventMovementAndCoords(&mouse_event); | 1971 ModifyEventMovementAndCoords(&mouse_event, event); |
| 1958 if (ShouldRouteEvent(event)) { | 1972 if (ShouldRouteEvent(event)) { |
| 1959 host_->delegate()->GetInputEventRouter()->RouteMouseEvent( | 1973 host_->delegate()->GetInputEventRouter()->RouteMouseEvent( |
| 1960 this, &mouse_event, *event->latency()); | 1974 this, &mouse_event, *event->latency()); |
| 1961 } else { | 1975 } else { |
| 1962 ProcessMouseEvent(mouse_event, *event->latency()); | 1976 ProcessMouseEvent(mouse_event, *event->latency()); |
| 1963 } | 1977 } |
| 1964 | 1978 |
| 1965 // Ensure that we get keyboard focus on mouse down as a plugin window may | 1979 // Ensure that we get keyboard focus on mouse down as a plugin window may |
| 1966 // have grabbed keyboard focus. | 1980 // have grabbed keyboard focus. |
| 1967 if (event->type() == ui::ET_MOUSE_PRESSED) | 1981 if (event->type() == ui::ET_MOUSE_PRESSED) |
| (...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2493 if (!has_composition_text_) | 2507 if (!has_composition_text_) |
| 2494 return; | 2508 return; |
| 2495 | 2509 |
| 2496 if (!!text_input_manager_ && !!text_input_manager_->GetActiveWidget()) { | 2510 if (!!text_input_manager_ && !!text_input_manager_->GetActiveWidget()) { |
| 2497 text_input_manager_->GetActiveWidget()->ImeFinishComposingText(false); | 2511 text_input_manager_->GetActiveWidget()->ImeFinishComposingText(false); |
| 2498 } | 2512 } |
| 2499 ImeCancelComposition(); | 2513 ImeCancelComposition(); |
| 2500 } | 2514 } |
| 2501 | 2515 |
| 2502 void RenderWidgetHostViewAura::ModifyEventMovementAndCoords( | 2516 void RenderWidgetHostViewAura::ModifyEventMovementAndCoords( |
| 2503 blink::WebMouseEvent* event) { | 2517 blink::WebMouseEvent* event, |
| 2518 ui::MouseEvent* ui_mouse_event) { | |
| 2504 // If the mouse has just entered, we must report zero movementX/Y. Hence we | 2519 // If the mouse has just entered, we must report zero movementX/Y. Hence we |
| 2505 // reset any global_mouse_position set previously. | 2520 // reset any global_mouse_position set previously. |
| 2506 if (event->type == blink::WebInputEvent::MouseEnter || | 2521 if ((ui_mouse_event->type() == ui::ET_MOUSE_ENTERED || |
| 2507 event->type == blink::WebInputEvent::MouseLeave) | 2522 ui_mouse_event->type() == ui::ET_MOUSE_EXITED)) { |
| 2508 global_mouse_position_.SetPoint(event->globalX, event->globalY); | 2523 global_mouse_position_.SetPoint(event->globalX, event->globalY); |
| 2524 } | |
| 2509 | 2525 |
| 2510 // Movement is computed by taking the difference of the new cursor position | 2526 // Movement is computed by taking the difference of the new cursor position |
| 2511 // and the previous. Under mouse lock the cursor will be warped back to the | 2527 // and the previous. Under mouse lock the cursor will be warped back to the |
| 2512 // center so that we are not limited by clipping boundaries. | 2528 // center so that we are not limited by clipping boundaries. |
| 2513 // We do not measure movement as the delta from cursor to center because | 2529 // We do not measure movement as the delta from cursor to center because |
| 2514 // we may receive more mouse movement events before our warp has taken | 2530 // we may receive more mouse movement events before our warp has taken |
| 2515 // effect. | 2531 // effect. |
| 2516 event->movementX = event->globalX - global_mouse_position_.x(); | 2532 event->movementX = event->globalX - global_mouse_position_.x(); |
| 2517 event->movementY = event->globalY - global_mouse_position_.y(); | 2533 event->movementY = event->globalY - global_mouse_position_.y(); |
| 2518 | 2534 |
| (...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3042 ->GetTextSelection(focused_view) | 3058 ->GetTextSelection(focused_view) |
| 3043 ->GetSelectedText(&selected_text)) { | 3059 ->GetSelectedText(&selected_text)) { |
| 3044 // Set the CLIPBOARD_TYPE_SELECTION to the ui::Clipboard. | 3060 // Set the CLIPBOARD_TYPE_SELECTION to the ui::Clipboard. |
| 3045 ui::ScopedClipboardWriter clipboard_writer(ui::CLIPBOARD_TYPE_SELECTION); | 3061 ui::ScopedClipboardWriter clipboard_writer(ui::CLIPBOARD_TYPE_SELECTION); |
| 3046 clipboard_writer.WriteText(selected_text); | 3062 clipboard_writer.WriteText(selected_text); |
| 3047 } | 3063 } |
| 3048 #endif // defined(USE_X11) && !defined(OS_CHROMEOS) | 3064 #endif // defined(USE_X11) && !defined(OS_CHROMEOS) |
| 3049 } | 3065 } |
| 3050 | 3066 |
| 3051 } // namespace content | 3067 } // namespace content |
| OLD | NEW |