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 1738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 | 1758 |
| 1759 void RenderWidgetHostViewMac::ScheduleMouseWheelEndDispatching( |
| 1760 blink::WebMouseWheelEvent wheel_event, |
| 1761 bool should_route_event) { |
| 1762 mouse_wheel_end_dispatch_timer_.Start( |
| 1763 FROM_HERE, |
| 1764 base::TimeDelta::FromMilliseconds( |
| 1765 kDefaultMouseWheelLatchingTransactionMs), |
| 1766 base::Bind( |
| 1767 &RenderWidgetHostViewMac::SendSyntheticWheelEventWithPhaseEnded, |
| 1768 base::Unretained(this), wheel_event, should_route_event)); |
| 1769 } |
| 1770 |
| 1771 void RenderWidgetHostViewMac::DispatchPendingWheelEndEvent() { |
| 1772 if (mouse_wheel_end_dispatch_timer_.IsRunning()) { |
| 1773 base::Closure task = mouse_wheel_end_dispatch_timer_.user_task(); |
| 1774 mouse_wheel_end_dispatch_timer_.Stop(); |
| 1775 task.Run(); |
| 1776 } |
| 1777 } |
| 1778 |
| 1779 void RenderWidgetHostViewMac::IgnorePendingWheelEndEvent() { |
| 1780 mouse_wheel_end_dispatch_timer_.Stop(); |
| 1781 } |
| 1782 |
| 1783 bool RenderWidgetHostViewMac::HasPendingWheelEndEvent() { |
| 1784 return mouse_wheel_end_dispatch_timer_.IsRunning(); |
| 1785 } |
| 1786 |
| 1787 void RenderWidgetHostViewMac::SendSyntheticWheelEventWithPhaseEnded( |
| 1788 blink::WebMouseWheelEvent wheel_event, |
| 1789 bool should_route_event) { |
| 1790 wheel_event.dispatch_type = |
| 1791 blink::WebInputEvent::DispatchType::kEventNonBlocking; |
| 1792 if (should_route_event) { |
| 1793 render_widget_host_->delegate() |
| 1794 ->GetInputEventRouter() |
| 1795 ->RouteMouseWheelEvent(this, &wheel_event, |
| 1796 ui::LatencyInfo(ui::SourceEventType::WHEEL)); |
| 1797 } else { |
| 1798 ProcessMouseWheelEvent(wheel_event, |
| 1799 ui::LatencyInfo(ui::SourceEventType::WHEEL)); |
| 1800 } |
| 1801 } |
| 1802 |
1759 } // namespace content | 1803 } // namespace content |
1760 | 1804 |
1761 // RenderWidgetHostViewCocoa --------------------------------------------------- | 1805 // RenderWidgetHostViewCocoa --------------------------------------------------- |
1762 | 1806 |
1763 @implementation RenderWidgetHostViewCocoa | 1807 @implementation RenderWidgetHostViewCocoa |
1764 @synthesize selectedRange = selectedRange_; | 1808 @synthesize selectedRange = selectedRange_; |
1765 @synthesize suppressNextEscapeKeyUp = suppressNextEscapeKeyUp_; | 1809 @synthesize suppressNextEscapeKeyUp = suppressNextEscapeKeyUp_; |
1766 @synthesize markedRange = markedRange_; | 1810 @synthesize markedRange = markedRange_; |
1767 | 1811 |
1768 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r { | 1812 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r { |
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2349 if ([event phase] != NSEventPhaseEnded && | 2393 if ([event phase] != NSEventPhaseEnded && |
2350 [event phase] != NSEventPhaseCancelled) { | 2394 [event phase] != NSEventPhaseCancelled) { |
2351 return; | 2395 return; |
2352 } | 2396 } |
2353 | 2397 |
2354 if (renderWidgetHostView_->render_widget_host_) { | 2398 if (renderWidgetHostView_->render_widget_host_) { |
2355 // History-swiping is not possible if the logic reaches this point. | 2399 // History-swiping is not possible if the logic reaches this point. |
2356 WebMouseWheelEvent webEvent = WebMouseWheelEventBuilder::Build( | 2400 WebMouseWheelEvent webEvent = WebMouseWheelEventBuilder::Build( |
2357 event, self); | 2401 event, self); |
2358 webEvent.rails_mode = mouseWheelFilter_.UpdateRailsMode(webEvent); | 2402 webEvent.rails_mode = mouseWheelFilter_.UpdateRailsMode(webEvent); |
2359 ui::LatencyInfo latency_info(ui::SourceEventType::WHEEL); | 2403 if (renderWidgetHostView_->wheel_scroll_latching_enabled()) { |
2360 latency_info.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); | 2404 renderWidgetHostView_->ScheduleMouseWheelEndDispatching(webEvent, false); |
2361 renderWidgetHostView_->render_widget_host_-> | 2405 } else { |
2362 ForwardWheelEventWithLatencyInfo(webEvent, latency_info); | 2406 ui::LatencyInfo latency_info(ui::SourceEventType::WHEEL); |
| 2407 latency_info.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); |
| 2408 renderWidgetHostView_->render_widget_host_ |
| 2409 ->ForwardWheelEventWithLatencyInfo(webEvent, latency_info); |
| 2410 } |
2363 } | 2411 } |
2364 | 2412 |
2365 if (endWheelMonitor_) { | 2413 if (endWheelMonitor_) { |
2366 [NSEvent removeMonitor:endWheelMonitor_]; | 2414 [NSEvent removeMonitor:endWheelMonitor_]; |
2367 endWheelMonitor_ = nil; | 2415 endWheelMonitor_ = nil; |
2368 } | 2416 } |
2369 } | 2417 } |
2370 | 2418 |
2371 - (void)beginGestureWithEvent:(NSEvent*)event { | 2419 - (void)beginGestureWithEvent:(NSEvent*)event { |
2372 [responderDelegate_ beginGestureWithEvent:event]; | 2420 [responderDelegate_ beginGestureWithEvent:event]; |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2558 return blockEvent; | 2606 return blockEvent; |
2559 }]; | 2607 }]; |
2560 } | 2608 } |
2561 | 2609 |
2562 // This is responsible for content scrolling! | 2610 // This is responsible for content scrolling! |
2563 if (renderWidgetHostView_->render_widget_host_) { | 2611 if (renderWidgetHostView_->render_widget_host_) { |
2564 WebMouseWheelEvent webEvent = WebMouseWheelEventBuilder::Build(event, self); | 2612 WebMouseWheelEvent webEvent = WebMouseWheelEventBuilder::Build(event, self); |
2565 webEvent.rails_mode = mouseWheelFilter_.UpdateRailsMode(webEvent); | 2613 webEvent.rails_mode = mouseWheelFilter_.UpdateRailsMode(webEvent); |
2566 ui::LatencyInfo latency_info(ui::SourceEventType::WHEEL); | 2614 ui::LatencyInfo latency_info(ui::SourceEventType::WHEEL); |
2567 latency_info.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); | 2615 latency_info.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); |
| 2616 if (renderWidgetHostView_->wheel_scroll_latching_enabled()) { |
| 2617 if (webEvent.phase == blink::WebMouseWheelEvent::kPhaseEnded) { |
| 2618 // Don't send the wheel end event immediately, start a timer instead to |
| 2619 // see whether momentum phase of the scrolling starts or not. |
| 2620 renderWidgetHostView_->ScheduleMouseWheelEndDispatching( |
| 2621 webEvent, renderWidgetHostView_->ShouldRouteEvent(webEvent)); |
| 2622 return; |
| 2623 } |
| 2624 if (webEvent.phase == blink::WebMouseWheelEvent::kPhaseBegan) { |
| 2625 // A new scrolling sequence has started, send the pending wheel end |
| 2626 // event to end the previous scrolling sequence. |
| 2627 renderWidgetHostView_->DispatchPendingWheelEndEvent(); |
| 2628 |
| 2629 } else if (webEvent.momentum_phase == |
| 2630 blink::WebMouseWheelEvent::kPhaseBegan) { |
| 2631 // Momentum phase has started, drop the pending wheel end event to make |
| 2632 // sure that no wheel end event will be sent during the momentum phase |
| 2633 // of scrolling. |
| 2634 renderWidgetHostView_->IgnorePendingWheelEndEvent(); |
| 2635 } |
| 2636 } |
| 2637 |
2568 if (renderWidgetHostView_->ShouldRouteEvent(webEvent)) { | 2638 if (renderWidgetHostView_->ShouldRouteEvent(webEvent)) { |
2569 renderWidgetHostView_->render_widget_host_->delegate() | 2639 renderWidgetHostView_->render_widget_host_->delegate() |
2570 ->GetInputEventRouter() | 2640 ->GetInputEventRouter() |
2571 ->RouteMouseWheelEvent(renderWidgetHostView_.get(), &webEvent, | 2641 ->RouteMouseWheelEvent(renderWidgetHostView_.get(), &webEvent, |
2572 latency_info); | 2642 latency_info); |
2573 } else { | 2643 } else { |
2574 renderWidgetHostView_->ProcessMouseWheelEvent(webEvent, latency_info); | 2644 renderWidgetHostView_->ProcessMouseWheelEvent(webEvent, latency_info); |
2575 } | 2645 } |
2576 } | 2646 } |
2577 } | 2647 } |
(...skipping 946 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3524 | 3594 |
3525 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding | 3595 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding |
3526 // regions that are not draggable. (See ControlRegionView in | 3596 // regions that are not draggable. (See ControlRegionView in |
3527 // native_app_window_cocoa.mm). This requires the render host view to be | 3597 // native_app_window_cocoa.mm). This requires the render host view to be |
3528 // draggable by default. | 3598 // draggable by default. |
3529 - (BOOL)mouseDownCanMoveWindow { | 3599 - (BOOL)mouseDownCanMoveWindow { |
3530 return YES; | 3600 return YES; |
3531 } | 3601 } |
3532 | 3602 |
3533 @end | 3603 @end |
OLD | NEW |