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 <objc/runtime.h> | 7 #import <objc/runtime.h> |
8 #include <OpenGL/gl.h> | 8 #include <OpenGL/gl.h> |
9 #include <QuartzCore/QuartzCore.h> | 9 #include <QuartzCore/QuartzCore.h> |
10 | 10 |
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
546 /////////////////////////////////////////////////////////////////////////////// | 546 /////////////////////////////////////////////////////////////////////////////// |
547 // RenderWidgetHostViewMac, public: | 547 // RenderWidgetHostViewMac, public: |
548 | 548 |
549 RenderWidgetHostViewMac::RenderWidgetHostViewMac(RenderWidgetHost* widget, | 549 RenderWidgetHostViewMac::RenderWidgetHostViewMac(RenderWidgetHost* widget, |
550 bool is_guest_view_hack) | 550 bool is_guest_view_hack) |
551 : render_widget_host_(RenderWidgetHostImpl::From(widget)), | 551 : render_widget_host_(RenderWidgetHostImpl::From(widget)), |
552 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), | 552 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), |
553 can_compose_inline_(true), | 553 can_compose_inline_(true), |
554 browser_compositor_state_(BrowserCompositorDestroyed), | 554 browser_compositor_state_(BrowserCompositorDestroyed), |
555 browser_compositor_placeholder_(new BrowserCompositorMacPlaceholder), | 555 browser_compositor_placeholder_(new BrowserCompositorMacPlaceholder), |
556 page_is_at_scale_one_(true), | |
556 is_loading_(false), | 557 is_loading_(false), |
557 allow_pause_for_resize_or_repaint_(true), | 558 allow_pause_for_resize_or_repaint_(true), |
558 is_guest_view_hack_(is_guest_view_hack), | 559 is_guest_view_hack_(is_guest_view_hack), |
559 fullscreen_parent_host_view_(NULL), | 560 fullscreen_parent_host_view_(NULL), |
560 weak_factory_(this) { | 561 weak_factory_(this) { |
561 // |cocoa_view_| owns us and we will be deleted when |cocoa_view_| | 562 // |cocoa_view_| owns us and we will be deleted when |cocoa_view_| |
562 // goes away. Since we autorelease it, our caller must put | 563 // goes away. Since we autorelease it, our caller must put |
563 // |GetNativeView()| into the view hierarchy right after calling us. | 564 // |GetNativeView()| into the view hierarchy right after calling us. |
564 cocoa_view_ = [[[RenderWidgetHostViewCocoa alloc] | 565 cocoa_view_ = [[[RenderWidgetHostViewCocoa alloc] |
565 initWithRenderWidgetHostViewMac:this] autorelease]; | 566 initWithRenderWidgetHostViewMac:this] autorelease]; |
(...skipping 894 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1460 desired_size); | 1461 desired_size); |
1461 } | 1462 } |
1462 return false; | 1463 return false; |
1463 } | 1464 } |
1464 | 1465 |
1465 void RenderWidgetHostViewMac::OnSwapCompositorFrame( | 1466 void RenderWidgetHostViewMac::OnSwapCompositorFrame( |
1466 uint32 output_surface_id, scoped_ptr<cc::CompositorFrame> frame) { | 1467 uint32 output_surface_id, scoped_ptr<cc::CompositorFrame> frame) { |
1467 TRACE_EVENT0("browser", "RenderWidgetHostViewMac::OnSwapCompositorFrame"); | 1468 TRACE_EVENT0("browser", "RenderWidgetHostViewMac::OnSwapCompositorFrame"); |
1468 | 1469 |
1469 last_scroll_offset_ = frame->metadata.root_scroll_offset; | 1470 last_scroll_offset_ = frame->metadata.root_scroll_offset; |
1471 | |
1472 page_is_at_scale_one_ = (frame->metadata.page_scale_factor == 1); | |
aelias_OOO_until_Jul13
2015/05/11 18:32:32
Please check for "== min_page_scale_factor" instea
ccameron
2015/05/11 19:21:43
If we end up doing the rubber-band bounce for pinc
aelias_OOO_until_Jul13
2015/05/11 21:22:34
If we do, I would probably favor storing the "over
| |
1473 | |
1470 if (frame->delegated_frame_data) { | 1474 if (frame->delegated_frame_data) { |
1471 float scale_factor = frame->metadata.device_scale_factor; | 1475 float scale_factor = frame->metadata.device_scale_factor; |
1472 | 1476 |
1473 // Compute the frame size based on the root render pass rect size. | 1477 // Compute the frame size based on the root render pass rect size. |
1474 cc::RenderPass* root_pass = | 1478 cc::RenderPass* root_pass = |
1475 frame->delegated_frame_data->render_pass_list.back(); | 1479 frame->delegated_frame_data->render_pass_list.back(); |
1476 gfx::Size pixel_size = root_pass->output_rect.size(); | 1480 gfx::Size pixel_size = root_pass->output_rect.size(); |
1477 gfx::Size dip_size = gfx::ConvertSizeToDIP(scale_factor, pixel_size); | 1481 gfx::Size dip_size = gfx::ConvertSizeToDIP(scale_factor, pixel_size); |
1478 | 1482 |
1479 root_layer_->SetBounds(gfx::Rect(dip_size)); | 1483 root_layer_->SetBounds(gfx::Rect(dip_size)); |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1744 self = [super initWithFrame:NSZeroRect]; | 1748 self = [super initWithFrame:NSZeroRect]; |
1745 if (self) { | 1749 if (self) { |
1746 self.acceptsTouchEvents = YES; | 1750 self.acceptsTouchEvents = YES; |
1747 editCommand_helper_.reset(new RenderWidgetHostViewMacEditCommandHelper); | 1751 editCommand_helper_.reset(new RenderWidgetHostViewMacEditCommandHelper); |
1748 editCommand_helper_->AddEditingSelectorsToClass([self class]); | 1752 editCommand_helper_->AddEditingSelectorsToClass([self class]); |
1749 | 1753 |
1750 renderWidgetHostView_.reset(r); | 1754 renderWidgetHostView_.reset(r); |
1751 canBeKeyView_ = YES; | 1755 canBeKeyView_ = YES; |
1752 opaque_ = YES; | 1756 opaque_ = YES; |
1753 focusedPluginIdentifier_ = -1; | 1757 focusedPluginIdentifier_ = -1; |
1754 lastUsedPinchEventTimestamp_ = 0; | 1758 pinchHasReachedZoomThreshold_ = false; |
1755 | 1759 |
1756 // OpenGL support: | 1760 // OpenGL support: |
1757 if ([self respondsToSelector: | 1761 if ([self respondsToSelector: |
1758 @selector(setWantsBestResolutionOpenGLSurface:)]) { | 1762 @selector(setWantsBestResolutionOpenGLSurface:)]) { |
1759 [self setWantsBestResolutionOpenGLSurface:YES]; | 1763 [self setWantsBestResolutionOpenGLSurface:YES]; |
1760 } | 1764 } |
1761 [[NSNotificationCenter defaultCenter] | 1765 [[NSNotificationCenter defaultCenter] |
1762 addObserver:self | 1766 addObserver:self |
1763 selector:@selector(didChangeScreenParameters:) | 1767 selector:@selector(didChangeScreenParameters:) |
1764 name:NSApplicationDidChangeScreenParametersNotification | 1768 name:NSApplicationDidChangeScreenParametersNotification |
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2276 if (endWheelMonitor_) { | 2280 if (endWheelMonitor_) { |
2277 [NSEvent removeMonitor:endWheelMonitor_]; | 2281 [NSEvent removeMonitor:endWheelMonitor_]; |
2278 endWheelMonitor_ = nil; | 2282 endWheelMonitor_ = nil; |
2279 } | 2283 } |
2280 } | 2284 } |
2281 | 2285 |
2282 - (void)beginGestureWithEvent:(NSEvent*)event { | 2286 - (void)beginGestureWithEvent:(NSEvent*)event { |
2283 [responderDelegate_ beginGestureWithEvent:event]; | 2287 [responderDelegate_ beginGestureWithEvent:event]; |
2284 gestureBeginEvent_.reset( | 2288 gestureBeginEvent_.reset( |
2285 new WebGestureEvent(WebInputEventFactory::gestureEvent(event, self))); | 2289 new WebGestureEvent(WebInputEventFactory::gestureEvent(event, self))); |
2286 unusedPinchAmount_ = 0; | 2290 |
2291 // If more than 1 second has passed since the last pinch gesture ended, reset | |
aelias_OOO_until_Jul13
2015/05/11 18:32:32
This comment is out of date.
ccameron
2015/05/11 19:21:43
Done.
| |
2292 // the zoom threshold levels. | |
2293 if (renderWidgetHostView_->page_is_at_scale_one_) { | |
2294 pinchHasReachedZoomThreshold_ = false; | |
2295 pinchUnusedAmount_ = 1; | |
2296 } | |
2287 } | 2297 } |
2288 | 2298 |
2289 - (void)endGestureWithEvent:(NSEvent*)event { | 2299 - (void)endGestureWithEvent:(NSEvent*)event { |
2290 [responderDelegate_ endGestureWithEvent:event]; | 2300 [responderDelegate_ endGestureWithEvent:event]; |
2291 gestureBeginEvent_.reset(); | 2301 gestureBeginEvent_.reset(); |
2292 | 2302 |
2293 if (!renderWidgetHostView_->render_widget_host_) | 2303 if (!renderWidgetHostView_->render_widget_host_) |
2294 return; | 2304 return; |
2295 | 2305 |
2296 if (gestureBeginPinchSent_) { | 2306 if (gestureBeginPinchSent_) { |
2297 WebGestureEvent endEvent(WebInputEventFactory::gestureEvent(event, self)); | 2307 WebGestureEvent endEvent(WebInputEventFactory::gestureEvent(event, self)); |
2298 endEvent.type = WebInputEvent::GesturePinchEnd; | 2308 endEvent.type = WebInputEvent::GesturePinchEnd; |
2299 renderWidgetHostView_->render_widget_host_->ForwardGestureEvent(endEvent); | 2309 renderWidgetHostView_->render_widget_host_->ForwardGestureEvent(endEvent); |
2300 gestureBeginPinchSent_ = NO; | 2310 gestureBeginPinchSent_ = NO; |
2301 lastUsedPinchEventTimestamp_ = [event timestamp]; | |
2302 } | 2311 } |
2303 } | 2312 } |
2304 | 2313 |
2305 - (void)touchesMovedWithEvent:(NSEvent*)event { | 2314 - (void)touchesMovedWithEvent:(NSEvent*)event { |
2306 [responderDelegate_ touchesMovedWithEvent:event]; | 2315 [responderDelegate_ touchesMovedWithEvent:event]; |
2307 } | 2316 } |
2308 | 2317 |
2309 - (void)touchesBeganWithEvent:(NSEvent*)event { | 2318 - (void)touchesBeganWithEvent:(NSEvent*)event { |
2310 [responderDelegate_ touchesBeganWithEvent:event]; | 2319 [responderDelegate_ touchesBeganWithEvent:event]; |
2311 } | 2320 } |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2404 - (void)magnifyWithEvent:(NSEvent*)event { | 2413 - (void)magnifyWithEvent:(NSEvent*)event { |
2405 if (!renderWidgetHostView_->render_widget_host_) | 2414 if (!renderWidgetHostView_->render_widget_host_) |
2406 return; | 2415 return; |
2407 | 2416 |
2408 // If, due to nesting of multiple gestures (e.g, from multiple touch | 2417 // If, due to nesting of multiple gestures (e.g, from multiple touch |
2409 // devices), the beginning of the gesture has been lost, skip the remainder | 2418 // devices), the beginning of the gesture has been lost, skip the remainder |
2410 // of the gesture. | 2419 // of the gesture. |
2411 if (!gestureBeginEvent_) | 2420 if (!gestureBeginEvent_) |
2412 return; | 2421 return; |
2413 | 2422 |
2423 if (!pinchHasReachedZoomThreshold_) { | |
2424 pinchUnusedAmount_ *= (1 + [event magnification]); | |
2425 if (pinchUnusedAmount_ < 0.667 || pinchUnusedAmount_ > 1.5) | |
2426 pinchHasReachedZoomThreshold_ = true; | |
2427 } | |
2428 | |
2414 // Send a GesturePinchBegin event if none has been sent yet. | 2429 // Send a GesturePinchBegin event if none has been sent yet. |
2415 if (!gestureBeginPinchSent_) { | 2430 if (!gestureBeginPinchSent_) { |
2416 // If less than 1 second has passed since an intentional pinch zoom | |
2417 // was done, don't threshold zooms, because subsequent zooms are likely | |
2418 // intentional. | |
2419 const NSTimeInterval kSecondsUntilZoomThresholdReEnabled = 1; | |
2420 if ([event timestamp] - lastUsedPinchEventTimestamp_ > | |
2421 kSecondsUntilZoomThresholdReEnabled) { | |
2422 // Require that a 40% zoom be hit before actually zooming the page, | |
2423 // to avoid accidental zooms. | |
2424 // http://crbug.com/478981 | |
2425 unusedPinchAmount_ += [event magnification]; | |
2426 if (unusedPinchAmount_ > -0.4 && unusedPinchAmount_ < 0.4) | |
2427 return; | |
2428 } | |
2429 | |
2430 WebGestureEvent beginEvent(*gestureBeginEvent_); | 2431 WebGestureEvent beginEvent(*gestureBeginEvent_); |
2431 beginEvent.type = WebInputEvent::GesturePinchBegin; | 2432 beginEvent.type = WebInputEvent::GesturePinchBegin; |
2432 renderWidgetHostView_->render_widget_host_->ForwardGestureEvent(beginEvent); | 2433 renderWidgetHostView_->render_widget_host_->ForwardGestureEvent(beginEvent); |
2433 gestureBeginPinchSent_ = YES; | 2434 gestureBeginPinchSent_ = YES; |
2434 } | 2435 } |
2435 | 2436 |
2436 // Send a GesturePinchUpdate event. | 2437 // Send a GesturePinchUpdate event. |
2437 const WebGestureEvent& updateEvent = | 2438 WebGestureEvent updateEvent = |
2438 WebInputEventFactory::gestureEvent(event, self); | 2439 WebInputEventFactory::gestureEvent(event, self); |
2440 updateEvent.data.pinchUpdate.zoomDisabled = !pinchHasReachedZoomThreshold_; | |
2439 renderWidgetHostView_->render_widget_host_->ForwardGestureEvent(updateEvent); | 2441 renderWidgetHostView_->render_widget_host_->ForwardGestureEvent(updateEvent); |
2440 } | 2442 } |
2441 | 2443 |
2442 - (void)viewWillMoveToWindow:(NSWindow*)newWindow { | 2444 - (void)viewWillMoveToWindow:(NSWindow*)newWindow { |
2443 NSWindow* oldWindow = [self window]; | 2445 NSWindow* oldWindow = [self window]; |
2444 | 2446 |
2445 NSNotificationCenter* notificationCenter = | 2447 NSNotificationCenter* notificationCenter = |
2446 [NSNotificationCenter defaultCenter]; | 2448 [NSNotificationCenter defaultCenter]; |
2447 | 2449 |
2448 // Backing property notifications crash on 10.6 when building with the 10.7 | 2450 // Backing property notifications crash on 10.6 when building with the 10.7 |
(...skipping 1036 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3485 | 3487 |
3486 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding | 3488 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding |
3487 // regions that are not draggable. (See ControlRegionView in | 3489 // regions that are not draggable. (See ControlRegionView in |
3488 // native_app_window_cocoa.mm). This requires the render host view to be | 3490 // native_app_window_cocoa.mm). This requires the render host view to be |
3489 // draggable by default. | 3491 // draggable by default. |
3490 - (BOOL)mouseDownCanMoveWindow { | 3492 - (BOOL)mouseDownCanMoveWindow { |
3491 return YES; | 3493 return YES; |
3492 } | 3494 } |
3493 | 3495 |
3494 @end | 3496 @end |
OLD | NEW |