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_mac.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_mac.h" |
6 | 6 |
7 #import <Carbon/Carbon.h> | 7 #import <Carbon/Carbon.h> |
8 #import <objc/runtime.h> | 8 #import <objc/runtime.h> |
9 #include <OpenGL/gl.h> | 9 #include <OpenGL/gl.h> |
10 #include <QuartzCore/QuartzCore.h> | 10 #include <QuartzCore/QuartzCore.h> |
(...skipping 1737 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1748 | 1748 |
1749 if (changed_metrics & DisplayObserver::DISPLAY_METRIC_DEVICE_SCALE_FACTOR) { | 1749 if (changed_metrics & DisplayObserver::DISPLAY_METRIC_DEVICE_SCALE_FACTOR) { |
1750 RenderWidgetHostImpl* host = | 1750 RenderWidgetHostImpl* host = |
1751 RenderWidgetHostImpl::From(GetRenderWidgetHost()); | 1751 RenderWidgetHostImpl::From(GetRenderWidgetHost()); |
1752 if (host && host->delegate()) | 1752 if (host && host->delegate()) |
1753 host->delegate()->UpdateDeviceScaleFactor(display.device_scale_factor()); | 1753 host->delegate()->UpdateDeviceScaleFactor(display.device_scale_factor()); |
1754 } | 1754 } |
1755 | 1755 |
1756 UpdateScreenInfo(cocoa_view_); | 1756 UpdateScreenInfo(cocoa_view_); |
1757 } | 1757 } |
| 1758 void RenderWidgetHostViewMac::SendSyntheticWheelEventWithPhaseEnded( |
| 1759 blink::WebMouseWheelEvent wheel_event, |
| 1760 bool should_route_event) { |
| 1761 wheel_event.dispatch_type = |
| 1762 blink::WebInputEvent::DispatchType::kEventNonBlocking; |
| 1763 if (should_route_event) { |
| 1764 render_widget_host_->delegate() |
| 1765 ->GetInputEventRouter() |
| 1766 ->RouteMouseWheelEvent(this, &wheel_event, |
| 1767 ui::LatencyInfo(ui::SourceEventType::WHEEL)); |
| 1768 } else { |
| 1769 ProcessMouseWheelEvent(wheel_event, |
| 1770 ui::LatencyInfo(ui::SourceEventType::WHEEL)); |
| 1771 } |
| 1772 } |
| 1773 |
| 1774 void RenderWidgetHostViewMac::StartMouseWheelEndDispatchTimer( |
| 1775 blink::WebMouseWheelEvent wheel_event, |
| 1776 bool should_route_event) { |
| 1777 mouse_wheel_end_dispatch_timer_.Start( |
| 1778 FROM_HERE, |
| 1779 base::TimeDelta::FromMilliseconds( |
| 1780 kDefaultMouseWheelLatchingTransactionMs), |
| 1781 base::Bind( |
| 1782 &RenderWidgetHostViewMac::SendSyntheticWheelEventWithPhaseEnded, |
| 1783 base::Unretained(this), wheel_event, should_route_event)); |
| 1784 } |
1758 | 1785 |
1759 } // namespace content | 1786 } // namespace content |
1760 | 1787 |
1761 // RenderWidgetHostViewCocoa --------------------------------------------------- | 1788 // RenderWidgetHostViewCocoa --------------------------------------------------- |
1762 | 1789 |
1763 @implementation RenderWidgetHostViewCocoa | 1790 @implementation RenderWidgetHostViewCocoa |
1764 @synthesize selectedRange = selectedRange_; | 1791 @synthesize selectedRange = selectedRange_; |
1765 @synthesize suppressNextEscapeKeyUp = suppressNextEscapeKeyUp_; | 1792 @synthesize suppressNextEscapeKeyUp = suppressNextEscapeKeyUp_; |
1766 @synthesize markedRange = markedRange_; | 1793 @synthesize markedRange = markedRange_; |
1767 | 1794 |
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2349 if ([event phase] != NSEventPhaseEnded && | 2376 if ([event phase] != NSEventPhaseEnded && |
2350 [event phase] != NSEventPhaseCancelled) { | 2377 [event phase] != NSEventPhaseCancelled) { |
2351 return; | 2378 return; |
2352 } | 2379 } |
2353 | 2380 |
2354 if (renderWidgetHostView_->render_widget_host_) { | 2381 if (renderWidgetHostView_->render_widget_host_) { |
2355 // History-swiping is not possible if the logic reaches this point. | 2382 // History-swiping is not possible if the logic reaches this point. |
2356 WebMouseWheelEvent webEvent = WebMouseWheelEventBuilder::Build( | 2383 WebMouseWheelEvent webEvent = WebMouseWheelEventBuilder::Build( |
2357 event, self); | 2384 event, self); |
2358 webEvent.rails_mode = mouseWheelFilter_.UpdateRailsMode(webEvent); | 2385 webEvent.rails_mode = mouseWheelFilter_.UpdateRailsMode(webEvent); |
2359 ui::LatencyInfo latency_info(ui::SourceEventType::WHEEL); | 2386 if (renderWidgetHostView_->wheel_scroll_latching_enabled()) { |
2360 latency_info.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); | 2387 renderWidgetHostView_->StartMouseWheelEndDispatchTimer(webEvent, false); |
2361 renderWidgetHostView_->render_widget_host_-> | 2388 } else { |
2362 ForwardWheelEventWithLatencyInfo(webEvent, latency_info); | 2389 ui::LatencyInfo latency_info(ui::SourceEventType::WHEEL); |
| 2390 latency_info.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); |
| 2391 renderWidgetHostView_->render_widget_host_ |
| 2392 ->ForwardWheelEventWithLatencyInfo(webEvent, latency_info); |
| 2393 } |
2363 } | 2394 } |
2364 | 2395 |
2365 if (endWheelMonitor_) { | 2396 if (endWheelMonitor_) { |
2366 [NSEvent removeMonitor:endWheelMonitor_]; | 2397 [NSEvent removeMonitor:endWheelMonitor_]; |
2367 endWheelMonitor_ = nil; | 2398 endWheelMonitor_ = nil; |
2368 } | 2399 } |
2369 } | 2400 } |
2370 | 2401 |
2371 - (void)beginGestureWithEvent:(NSEvent*)event { | 2402 - (void)beginGestureWithEvent:(NSEvent*)event { |
2372 [responderDelegate_ beginGestureWithEvent:event]; | 2403 [responderDelegate_ beginGestureWithEvent:event]; |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2558 return blockEvent; | 2589 return blockEvent; |
2559 }]; | 2590 }]; |
2560 } | 2591 } |
2561 | 2592 |
2562 // This is responsible for content scrolling! | 2593 // This is responsible for content scrolling! |
2563 if (renderWidgetHostView_->render_widget_host_) { | 2594 if (renderWidgetHostView_->render_widget_host_) { |
2564 WebMouseWheelEvent webEvent = WebMouseWheelEventBuilder::Build(event, self); | 2595 WebMouseWheelEvent webEvent = WebMouseWheelEventBuilder::Build(event, self); |
2565 webEvent.rails_mode = mouseWheelFilter_.UpdateRailsMode(webEvent); | 2596 webEvent.rails_mode = mouseWheelFilter_.UpdateRailsMode(webEvent); |
2566 ui::LatencyInfo latency_info(ui::SourceEventType::WHEEL); | 2597 ui::LatencyInfo latency_info(ui::SourceEventType::WHEEL); |
2567 latency_info.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); | 2598 latency_info.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); |
| 2599 if (renderWidgetHostView_->wheel_scroll_latching_enabled()) { |
| 2600 if (webEvent.phase == blink::WebMouseWheelEvent::kPhaseEnded) { |
| 2601 // Don't send the wheel end event immediately, start a timer instead to |
| 2602 // see whether momentum phase of the scrolling starts or not. |
| 2603 renderWidgetHostView_->StartMouseWheelEndDispatchTimer( |
| 2604 webEvent, renderWidgetHostView_->ShouldRouteEvent(webEvent)); |
| 2605 return; |
| 2606 } |
| 2607 if (webEvent.phase == blink::WebMouseWheelEvent::kPhaseBegan) { |
| 2608 // A new scrolling sequence has started, stop the timer and send its |
| 2609 // wheel end event to end the previous scrolling sequence. |
| 2610 if (renderWidgetHostView_->mouse_wheel_end_dispatch_timer_ |
| 2611 .IsRunning()) { |
| 2612 base::Closure task = |
| 2613 renderWidgetHostView_->mouse_wheel_end_dispatch_timer_ |
| 2614 .user_task(); |
| 2615 renderWidgetHostView_->mouse_wheel_end_dispatch_timer_.Stop(); |
| 2616 task.Run(); |
| 2617 } |
| 2618 |
| 2619 } else if (webEvent.momentum_phase == |
| 2620 blink::WebMouseWheelEvent::kPhaseBegan) { |
| 2621 // Momentum phase has started, stop the timer to make sure that no |
| 2622 // wheel end event will be sent during the momentum phase of scrolling. |
| 2623 renderWidgetHostView_->mouse_wheel_end_dispatch_timer_.Stop(); |
| 2624 } |
| 2625 } |
| 2626 |
2568 if (renderWidgetHostView_->ShouldRouteEvent(webEvent)) { | 2627 if (renderWidgetHostView_->ShouldRouteEvent(webEvent)) { |
2569 renderWidgetHostView_->render_widget_host_->delegate() | 2628 renderWidgetHostView_->render_widget_host_->delegate() |
2570 ->GetInputEventRouter() | 2629 ->GetInputEventRouter() |
2571 ->RouteMouseWheelEvent(renderWidgetHostView_.get(), &webEvent, | 2630 ->RouteMouseWheelEvent(renderWidgetHostView_.get(), &webEvent, |
2572 latency_info); | 2631 latency_info); |
2573 } else { | 2632 } else { |
2574 renderWidgetHostView_->ProcessMouseWheelEvent(webEvent, latency_info); | 2633 renderWidgetHostView_->ProcessMouseWheelEvent(webEvent, latency_info); |
2575 } | 2634 } |
2576 } | 2635 } |
2577 } | 2636 } |
(...skipping 946 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3524 | 3583 |
3525 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding | 3584 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding |
3526 // regions that are not draggable. (See ControlRegionView in | 3585 // regions that are not draggable. (See ControlRegionView in |
3527 // native_app_window_cocoa.mm). This requires the render host view to be | 3586 // native_app_window_cocoa.mm). This requires the render host view to be |
3528 // draggable by default. | 3587 // draggable by default. |
3529 - (BOOL)mouseDownCanMoveWindow { | 3588 - (BOOL)mouseDownCanMoveWindow { |
3530 return YES; | 3589 return YES; |
3531 } | 3590 } |
3532 | 3591 |
3533 @end | 3592 @end |
OLD | NEW |