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 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 display_link_->NotifyCurrentTime(base::TimeTicks::Now()); | 433 display_link_->NotifyCurrentTime(base::TimeTicks::Now()); |
434 } | 434 } |
435 | 435 |
436 /////////////////////////////////////////////////////////////////////////////// | 436 /////////////////////////////////////////////////////////////////////////////// |
437 // RenderWidgetHostViewMac, public: | 437 // RenderWidgetHostViewMac, public: |
438 | 438 |
439 RenderWidgetHostViewMac::RenderWidgetHostViewMac(RenderWidgetHost* widget, | 439 RenderWidgetHostViewMac::RenderWidgetHostViewMac(RenderWidgetHost* widget, |
440 bool is_guest_view_hack) | 440 bool is_guest_view_hack) |
441 : render_widget_host_(RenderWidgetHostImpl::From(widget)), | 441 : render_widget_host_(RenderWidgetHostImpl::From(widget)), |
442 page_at_minimum_scale_(true), | 442 page_at_minimum_scale_(true), |
| 443 mouse_wheel_phase_handler_(RenderWidgetHostImpl::From(widget), this), |
443 is_loading_(false), | 444 is_loading_(false), |
444 allow_pause_for_resize_or_repaint_(true), | 445 allow_pause_for_resize_or_repaint_(true), |
445 is_guest_view_hack_(is_guest_view_hack), | 446 is_guest_view_hack_(is_guest_view_hack), |
446 fullscreen_parent_host_view_(nullptr), | 447 fullscreen_parent_host_view_(nullptr), |
447 needs_flush_input_(false), | 448 needs_flush_input_(false), |
448 weak_factory_(this) { | 449 weak_factory_(this) { |
449 // |cocoa_view_| owns us and we will be deleted when |cocoa_view_| | 450 // |cocoa_view_| owns us and we will be deleted when |cocoa_view_| |
450 // goes away. Since we autorelease it, our caller must put | 451 // goes away. Since we autorelease it, our caller must put |
451 // |GetNativeView()| into the view hierarchy right after calling us. | 452 // |GetNativeView()| into the view hierarchy right after calling us. |
452 cocoa_view_ = [[[RenderWidgetHostViewCocoa alloc] | 453 cocoa_view_ = [[[RenderWidgetHostViewCocoa alloc] |
(...skipping 1293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1746 if (changed_metrics & DisplayObserver::DISPLAY_METRIC_DEVICE_SCALE_FACTOR) { | 1747 if (changed_metrics & DisplayObserver::DISPLAY_METRIC_DEVICE_SCALE_FACTOR) { |
1747 RenderWidgetHostImpl* host = | 1748 RenderWidgetHostImpl* host = |
1748 RenderWidgetHostImpl::From(GetRenderWidgetHost()); | 1749 RenderWidgetHostImpl::From(GetRenderWidgetHost()); |
1749 if (host && host->delegate()) | 1750 if (host && host->delegate()) |
1750 host->delegate()->UpdateDeviceScaleFactor(display.device_scale_factor()); | 1751 host->delegate()->UpdateDeviceScaleFactor(display.device_scale_factor()); |
1751 } | 1752 } |
1752 | 1753 |
1753 UpdateScreenInfo(cocoa_view_); | 1754 UpdateScreenInfo(cocoa_view_); |
1754 } | 1755 } |
1755 | 1756 |
1756 void RenderWidgetHostViewMac::ScheduleMouseWheelEndDispatching( | |
1757 blink::WebMouseWheelEvent wheel_event, | |
1758 bool should_route_event) { | |
1759 mouse_wheel_end_dispatch_timer_.Start( | |
1760 FROM_HERE, | |
1761 base::TimeDelta::FromMilliseconds( | |
1762 kDefaultMouseWheelLatchingTransactionMs), | |
1763 base::Bind( | |
1764 &RenderWidgetHostViewMac::SendSyntheticWheelEventWithPhaseEnded, | |
1765 base::Unretained(this), wheel_event, should_route_event)); | |
1766 } | |
1767 | |
1768 void RenderWidgetHostViewMac::DispatchPendingWheelEndEvent() { | |
1769 if (mouse_wheel_end_dispatch_timer_.IsRunning()) { | |
1770 base::Closure task = mouse_wheel_end_dispatch_timer_.user_task(); | |
1771 mouse_wheel_end_dispatch_timer_.Stop(); | |
1772 task.Run(); | |
1773 } | |
1774 } | |
1775 | |
1776 void RenderWidgetHostViewMac::IgnorePendingWheelEndEvent() { | |
1777 mouse_wheel_end_dispatch_timer_.Stop(); | |
1778 } | |
1779 | |
1780 bool RenderWidgetHostViewMac::HasPendingWheelEndEvent() { | |
1781 return mouse_wheel_end_dispatch_timer_.IsRunning(); | |
1782 } | |
1783 | |
1784 void RenderWidgetHostViewMac::SendSyntheticWheelEventWithPhaseEnded( | |
1785 blink::WebMouseWheelEvent wheel_event, | |
1786 bool should_route_event) { | |
1787 wheel_event.dispatch_type = | |
1788 blink::WebInputEvent::DispatchType::kEventNonBlocking; | |
1789 if (should_route_event) { | |
1790 render_widget_host_->delegate() | |
1791 ->GetInputEventRouter() | |
1792 ->RouteMouseWheelEvent(this, &wheel_event, | |
1793 ui::LatencyInfo(ui::SourceEventType::WHEEL)); | |
1794 } else { | |
1795 ProcessMouseWheelEvent(wheel_event, | |
1796 ui::LatencyInfo(ui::SourceEventType::WHEEL)); | |
1797 } | |
1798 } | |
1799 | |
1800 } // namespace content | 1757 } // namespace content |
1801 | 1758 |
1802 // RenderWidgetHostViewCocoa --------------------------------------------------- | 1759 // RenderWidgetHostViewCocoa --------------------------------------------------- |
1803 | 1760 |
1804 @implementation RenderWidgetHostViewCocoa | 1761 @implementation RenderWidgetHostViewCocoa |
1805 @synthesize selectedRange = selectedRange_; | 1762 @synthesize selectedRange = selectedRange_; |
1806 @synthesize suppressNextEscapeKeyUp = suppressNextEscapeKeyUp_; | 1763 @synthesize suppressNextEscapeKeyUp = suppressNextEscapeKeyUp_; |
1807 @synthesize markedRange = markedRange_; | 1764 @synthesize markedRange = markedRange_; |
1808 | 1765 |
1809 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r { | 1766 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r { |
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2391 [event phase] != NSEventPhaseCancelled) { | 2348 [event phase] != NSEventPhaseCancelled) { |
2392 return; | 2349 return; |
2393 } | 2350 } |
2394 | 2351 |
2395 if (renderWidgetHostView_->render_widget_host_) { | 2352 if (renderWidgetHostView_->render_widget_host_) { |
2396 // History-swiping is not possible if the logic reaches this point. | 2353 // History-swiping is not possible if the logic reaches this point. |
2397 WebMouseWheelEvent webEvent = WebMouseWheelEventBuilder::Build( | 2354 WebMouseWheelEvent webEvent = WebMouseWheelEventBuilder::Build( |
2398 event, self); | 2355 event, self); |
2399 webEvent.rails_mode = mouseWheelFilter_.UpdateRailsMode(webEvent); | 2356 webEvent.rails_mode = mouseWheelFilter_.UpdateRailsMode(webEvent); |
2400 if (renderWidgetHostView_->wheel_scroll_latching_enabled()) { | 2357 if (renderWidgetHostView_->wheel_scroll_latching_enabled()) { |
2401 renderWidgetHostView_->ScheduleMouseWheelEndDispatching(webEvent, false); | 2358 renderWidgetHostView_->mouse_wheel_phase_handler_ |
| 2359 .AddPhaseIfNeededAndScheduleEndEvent(webEvent, false); |
2402 } else { | 2360 } else { |
2403 ui::LatencyInfo latency_info(ui::SourceEventType::WHEEL); | 2361 ui::LatencyInfo latency_info(ui::SourceEventType::WHEEL); |
2404 latency_info.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); | 2362 latency_info.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); |
2405 renderWidgetHostView_->render_widget_host_ | 2363 renderWidgetHostView_->render_widget_host_ |
2406 ->ForwardWheelEventWithLatencyInfo(webEvent, latency_info); | 2364 ->ForwardWheelEventWithLatencyInfo(webEvent, latency_info); |
2407 } | 2365 } |
2408 } | 2366 } |
2409 | 2367 |
2410 if (endWheelMonitor_) { | 2368 if (endWheelMonitor_) { |
2411 [NSEvent removeMonitor:endWheelMonitor_]; | 2369 [NSEvent removeMonitor:endWheelMonitor_]; |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2604 }]; | 2562 }]; |
2605 } | 2563 } |
2606 | 2564 |
2607 // This is responsible for content scrolling! | 2565 // This is responsible for content scrolling! |
2608 if (renderWidgetHostView_->render_widget_host_) { | 2566 if (renderWidgetHostView_->render_widget_host_) { |
2609 WebMouseWheelEvent webEvent = WebMouseWheelEventBuilder::Build(event, self); | 2567 WebMouseWheelEvent webEvent = WebMouseWheelEventBuilder::Build(event, self); |
2610 webEvent.rails_mode = mouseWheelFilter_.UpdateRailsMode(webEvent); | 2568 webEvent.rails_mode = mouseWheelFilter_.UpdateRailsMode(webEvent); |
2611 ui::LatencyInfo latency_info(ui::SourceEventType::WHEEL); | 2569 ui::LatencyInfo latency_info(ui::SourceEventType::WHEEL); |
2612 latency_info.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); | 2570 latency_info.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); |
2613 if (renderWidgetHostView_->wheel_scroll_latching_enabled()) { | 2571 if (renderWidgetHostView_->wheel_scroll_latching_enabled()) { |
| 2572 renderWidgetHostView_->mouse_wheel_phase_handler_ |
| 2573 .AddPhaseIfNeededAndScheduleEndEvent( |
| 2574 webEvent, renderWidgetHostView_->ShouldRouteEvent(webEvent)); |
2614 if (webEvent.phase == blink::WebMouseWheelEvent::kPhaseEnded) { | 2575 if (webEvent.phase == blink::WebMouseWheelEvent::kPhaseEnded) { |
2615 // Don't send the wheel end event immediately, start a timer instead to | 2576 // A wheel end event is scheduled and will get dispatched if momentum |
2616 // see whether momentum phase of the scrolling starts or not. | 2577 // phase doesn't start in 100ms. Don't sent the wheel end event |
2617 renderWidgetHostView_->ScheduleMouseWheelEndDispatching( | 2578 // immediately. |
2618 webEvent, renderWidgetHostView_->ShouldRouteEvent(webEvent)); | |
2619 return; | 2579 return; |
2620 } | 2580 } |
2621 if (webEvent.phase == blink::WebMouseWheelEvent::kPhaseBegan) { | |
2622 // A new scrolling sequence has started, send the pending wheel end | |
2623 // event to end the previous scrolling sequence. | |
2624 renderWidgetHostView_->DispatchPendingWheelEndEvent(); | |
2625 | |
2626 } else if (webEvent.momentum_phase == | |
2627 blink::WebMouseWheelEvent::kPhaseBegan) { | |
2628 // Momentum phase has started, drop the pending wheel end event to make | |
2629 // sure that no wheel end event will be sent during the momentum phase | |
2630 // of scrolling. | |
2631 renderWidgetHostView_->IgnorePendingWheelEndEvent(); | |
2632 } | |
2633 } | 2581 } |
2634 | 2582 |
2635 if (renderWidgetHostView_->ShouldRouteEvent(webEvent)) { | 2583 if (renderWidgetHostView_->ShouldRouteEvent(webEvent)) { |
2636 renderWidgetHostView_->render_widget_host_->delegate() | 2584 renderWidgetHostView_->render_widget_host_->delegate() |
2637 ->GetInputEventRouter() | 2585 ->GetInputEventRouter() |
2638 ->RouteMouseWheelEvent(renderWidgetHostView_.get(), &webEvent, | 2586 ->RouteMouseWheelEvent(renderWidgetHostView_.get(), &webEvent, |
2639 latency_info); | 2587 latency_info); |
2640 } else { | 2588 } else { |
2641 renderWidgetHostView_->ProcessMouseWheelEvent(webEvent, latency_info); | 2589 renderWidgetHostView_->ProcessMouseWheelEvent(webEvent, latency_info); |
2642 } | 2590 } |
(...skipping 948 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3591 | 3539 |
3592 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding | 3540 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding |
3593 // regions that are not draggable. (See ControlRegionView in | 3541 // regions that are not draggable. (See ControlRegionView in |
3594 // native_app_window_cocoa.mm). This requires the render host view to be | 3542 // native_app_window_cocoa.mm). This requires the render host view to be |
3595 // draggable by default. | 3543 // draggable by default. |
3596 - (BOOL)mouseDownCanMoveWindow { | 3544 - (BOOL)mouseDownCanMoveWindow { |
3597 return YES; | 3545 return YES; |
3598 } | 3546 } |
3599 | 3547 |
3600 @end | 3548 @end |
OLD | NEW |