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_at_minimum_scale_(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 897 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1463 desired_size); | 1464 desired_size); |
1464 } | 1465 } |
1465 return false; | 1466 return false; |
1466 } | 1467 } |
1467 | 1468 |
1468 void RenderWidgetHostViewMac::OnSwapCompositorFrame( | 1469 void RenderWidgetHostViewMac::OnSwapCompositorFrame( |
1469 uint32 output_surface_id, scoped_ptr<cc::CompositorFrame> frame) { | 1470 uint32 output_surface_id, scoped_ptr<cc::CompositorFrame> frame) { |
1470 TRACE_EVENT0("browser", "RenderWidgetHostViewMac::OnSwapCompositorFrame"); | 1471 TRACE_EVENT0("browser", "RenderWidgetHostViewMac::OnSwapCompositorFrame"); |
1471 | 1472 |
1472 last_scroll_offset_ = frame->metadata.root_scroll_offset; | 1473 last_scroll_offset_ = frame->metadata.root_scroll_offset; |
| 1474 |
| 1475 page_at_minimum_scale_ = frame->metadata.page_scale_factor == |
| 1476 frame->metadata.min_page_scale_factor; |
| 1477 |
1473 if (frame->delegated_frame_data) { | 1478 if (frame->delegated_frame_data) { |
1474 float scale_factor = frame->metadata.device_scale_factor; | 1479 float scale_factor = frame->metadata.device_scale_factor; |
1475 | 1480 |
1476 // Compute the frame size based on the root render pass rect size. | 1481 // Compute the frame size based on the root render pass rect size. |
1477 cc::RenderPass* root_pass = | 1482 cc::RenderPass* root_pass = |
1478 frame->delegated_frame_data->render_pass_list.back(); | 1483 frame->delegated_frame_data->render_pass_list.back(); |
1479 gfx::Size pixel_size = root_pass->output_rect.size(); | 1484 gfx::Size pixel_size = root_pass->output_rect.size(); |
1480 gfx::Size dip_size = gfx::ConvertSizeToDIP(scale_factor, pixel_size); | 1485 gfx::Size dip_size = gfx::ConvertSizeToDIP(scale_factor, pixel_size); |
1481 | 1486 |
1482 root_layer_->SetBounds(gfx::Rect(dip_size)); | 1487 root_layer_->SetBounds(gfx::Rect(dip_size)); |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1743 self = [super initWithFrame:NSZeroRect]; | 1748 self = [super initWithFrame:NSZeroRect]; |
1744 if (self) { | 1749 if (self) { |
1745 self.acceptsTouchEvents = YES; | 1750 self.acceptsTouchEvents = YES; |
1746 editCommand_helper_.reset(new RenderWidgetHostViewMacEditCommandHelper); | 1751 editCommand_helper_.reset(new RenderWidgetHostViewMacEditCommandHelper); |
1747 editCommand_helper_->AddEditingSelectorsToClass([self class]); | 1752 editCommand_helper_->AddEditingSelectorsToClass([self class]); |
1748 | 1753 |
1749 renderWidgetHostView_.reset(r); | 1754 renderWidgetHostView_.reset(r); |
1750 canBeKeyView_ = YES; | 1755 canBeKeyView_ = YES; |
1751 opaque_ = YES; | 1756 opaque_ = YES; |
1752 focusedPluginIdentifier_ = -1; | 1757 focusedPluginIdentifier_ = -1; |
1753 lastUsedPinchEventTimestamp_ = 0; | 1758 pinchHasReachedZoomThreshold_ = false; |
1754 | 1759 |
1755 // OpenGL support: | 1760 // OpenGL support: |
1756 if ([self respondsToSelector: | 1761 if ([self respondsToSelector: |
1757 @selector(setWantsBestResolutionOpenGLSurface:)]) { | 1762 @selector(setWantsBestResolutionOpenGLSurface:)]) { |
1758 [self setWantsBestResolutionOpenGLSurface:YES]; | 1763 [self setWantsBestResolutionOpenGLSurface:YES]; |
1759 } | 1764 } |
1760 [[NSNotificationCenter defaultCenter] | 1765 [[NSNotificationCenter defaultCenter] |
1761 addObserver:self | 1766 addObserver:self |
1762 selector:@selector(didChangeScreenParameters:) | 1767 selector:@selector(didChangeScreenParameters:) |
1763 name:NSApplicationDidChangeScreenParametersNotification | 1768 name:NSApplicationDidChangeScreenParametersNotification |
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2275 if (endWheelMonitor_) { | 2280 if (endWheelMonitor_) { |
2276 [NSEvent removeMonitor:endWheelMonitor_]; | 2281 [NSEvent removeMonitor:endWheelMonitor_]; |
2277 endWheelMonitor_ = nil; | 2282 endWheelMonitor_ = nil; |
2278 } | 2283 } |
2279 } | 2284 } |
2280 | 2285 |
2281 - (void)beginGestureWithEvent:(NSEvent*)event { | 2286 - (void)beginGestureWithEvent:(NSEvent*)event { |
2282 [responderDelegate_ beginGestureWithEvent:event]; | 2287 [responderDelegate_ beginGestureWithEvent:event]; |
2283 gestureBeginEvent_.reset( | 2288 gestureBeginEvent_.reset( |
2284 new WebGestureEvent(WebInputEventFactory::gestureEvent(event, self))); | 2289 new WebGestureEvent(WebInputEventFactory::gestureEvent(event, self))); |
2285 unusedPinchAmount_ = 0; | 2290 |
| 2291 // If the page is at the minimum zoom level, require a threshold be reached |
| 2292 // before the pinch has an effect. |
| 2293 if (renderWidgetHostView_->page_at_minimum_scale_) { |
| 2294 pinchHasReachedZoomThreshold_ = false; |
| 2295 pinchUnusedAmount_ = 1; |
| 2296 } |
2286 } | 2297 } |
2287 | 2298 |
2288 - (void)endGestureWithEvent:(NSEvent*)event { | 2299 - (void)endGestureWithEvent:(NSEvent*)event { |
2289 [responderDelegate_ endGestureWithEvent:event]; | 2300 [responderDelegate_ endGestureWithEvent:event]; |
2290 gestureBeginEvent_.reset(); | 2301 gestureBeginEvent_.reset(); |
2291 | 2302 |
2292 if (!renderWidgetHostView_->render_widget_host_) | 2303 if (!renderWidgetHostView_->render_widget_host_) |
2293 return; | 2304 return; |
2294 | 2305 |
2295 if (gestureBeginPinchSent_) { | 2306 if (gestureBeginPinchSent_) { |
2296 WebGestureEvent endEvent(WebInputEventFactory::gestureEvent(event, self)); | 2307 WebGestureEvent endEvent(WebInputEventFactory::gestureEvent(event, self)); |
2297 endEvent.type = WebInputEvent::GesturePinchEnd; | 2308 endEvent.type = WebInputEvent::GesturePinchEnd; |
2298 renderWidgetHostView_->render_widget_host_->ForwardGestureEvent(endEvent); | 2309 renderWidgetHostView_->render_widget_host_->ForwardGestureEvent(endEvent); |
2299 gestureBeginPinchSent_ = NO; | 2310 gestureBeginPinchSent_ = NO; |
2300 lastUsedPinchEventTimestamp_ = [event timestamp]; | |
2301 } | 2311 } |
2302 } | 2312 } |
2303 | 2313 |
2304 - (void)touchesMovedWithEvent:(NSEvent*)event { | 2314 - (void)touchesMovedWithEvent:(NSEvent*)event { |
2305 [responderDelegate_ touchesMovedWithEvent:event]; | 2315 [responderDelegate_ touchesMovedWithEvent:event]; |
2306 } | 2316 } |
2307 | 2317 |
2308 - (void)touchesBeganWithEvent:(NSEvent*)event { | 2318 - (void)touchesBeganWithEvent:(NSEvent*)event { |
2309 [responderDelegate_ touchesBeganWithEvent:event]; | 2319 [responderDelegate_ touchesBeganWithEvent:event]; |
2310 } | 2320 } |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2403 - (void)magnifyWithEvent:(NSEvent*)event { | 2413 - (void)magnifyWithEvent:(NSEvent*)event { |
2404 if (!renderWidgetHostView_->render_widget_host_) | 2414 if (!renderWidgetHostView_->render_widget_host_) |
2405 return; | 2415 return; |
2406 | 2416 |
2407 // 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 |
2408 // 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 |
2409 // of the gesture. | 2419 // of the gesture. |
2410 if (!gestureBeginEvent_) | 2420 if (!gestureBeginEvent_) |
2411 return; | 2421 return; |
2412 | 2422 |
| 2423 if (!pinchHasReachedZoomThreshold_) { |
| 2424 pinchUnusedAmount_ *= (1 + [event magnification]); |
| 2425 if (pinchUnusedAmount_ < 0.667 || pinchUnusedAmount_ > 1.5) |
| 2426 pinchHasReachedZoomThreshold_ = true; |
| 2427 } |
| 2428 |
2413 // Send a GesturePinchBegin event if none has been sent yet. | 2429 // Send a GesturePinchBegin event if none has been sent yet. |
2414 if (!gestureBeginPinchSent_) { | 2430 if (!gestureBeginPinchSent_) { |
2415 // If less than 1 second has passed since an intentional pinch zoom | |
2416 // was done, don't threshold zooms, because subsequent zooms are likely | |
2417 // intentional. | |
2418 const NSTimeInterval kSecondsUntilZoomThresholdReEnabled = 1; | |
2419 if ([event timestamp] - lastUsedPinchEventTimestamp_ > | |
2420 kSecondsUntilZoomThresholdReEnabled) { | |
2421 // Require that a 40% zoom be hit before actually zooming the page, | |
2422 // to avoid accidental zooms. | |
2423 // http://crbug.com/478981 | |
2424 unusedPinchAmount_ += [event magnification]; | |
2425 if (unusedPinchAmount_ > -0.4 && unusedPinchAmount_ < 0.4) | |
2426 return; | |
2427 } | |
2428 | |
2429 WebGestureEvent beginEvent(*gestureBeginEvent_); | 2431 WebGestureEvent beginEvent(*gestureBeginEvent_); |
2430 beginEvent.type = WebInputEvent::GesturePinchBegin; | 2432 beginEvent.type = WebInputEvent::GesturePinchBegin; |
2431 renderWidgetHostView_->render_widget_host_->ForwardGestureEvent(beginEvent); | 2433 renderWidgetHostView_->render_widget_host_->ForwardGestureEvent(beginEvent); |
2432 gestureBeginPinchSent_ = YES; | 2434 gestureBeginPinchSent_ = YES; |
2433 } | 2435 } |
2434 | 2436 |
2435 // Send a GesturePinchUpdate event. | 2437 // Send a GesturePinchUpdate event. |
2436 const WebGestureEvent& updateEvent = | 2438 WebGestureEvent updateEvent = |
2437 WebInputEventFactory::gestureEvent(event, self); | 2439 WebInputEventFactory::gestureEvent(event, self); |
| 2440 updateEvent.data.pinchUpdate.zoomDisabled = !pinchHasReachedZoomThreshold_; |
2438 renderWidgetHostView_->render_widget_host_->ForwardGestureEvent(updateEvent); | 2441 renderWidgetHostView_->render_widget_host_->ForwardGestureEvent(updateEvent); |
2439 } | 2442 } |
2440 | 2443 |
2441 - (void)viewWillMoveToWindow:(NSWindow*)newWindow { | 2444 - (void)viewWillMoveToWindow:(NSWindow*)newWindow { |
2442 NSWindow* oldWindow = [self window]; | 2445 NSWindow* oldWindow = [self window]; |
2443 | 2446 |
2444 NSNotificationCenter* notificationCenter = | 2447 NSNotificationCenter* notificationCenter = |
2445 [NSNotificationCenter defaultCenter]; | 2448 [NSNotificationCenter defaultCenter]; |
2446 | 2449 |
2447 // 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... |
3484 | 3487 |
3485 // "-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 |
3486 // regions that are not draggable. (See ControlRegionView in | 3489 // regions that are not draggable. (See ControlRegionView in |
3487 // 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 |
3488 // draggable by default. | 3491 // draggable by default. |
3489 - (BOOL)mouseDownCanMoveWindow { | 3492 - (BOOL)mouseDownCanMoveWindow { |
3490 return YES; | 3493 return YES; |
3491 } | 3494 } |
3492 | 3495 |
3493 @end | 3496 @end |
OLD | NEW |