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/web_contents/web_contents_impl.h" | 5 #include "content/browser/web_contents/web_contents_impl.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 capturer_count_(0), | 343 capturer_count_(0), |
344 should_normally_be_visible_(true), | 344 should_normally_be_visible_(true), |
345 is_being_destroyed_(false), | 345 is_being_destroyed_(false), |
346 notify_disconnection_(false), | 346 notify_disconnection_(false), |
347 dialog_manager_(NULL), | 347 dialog_manager_(NULL), |
348 is_showing_before_unload_dialog_(false), | 348 is_showing_before_unload_dialog_(false), |
349 last_active_time_(base::TimeTicks::Now()), | 349 last_active_time_(base::TimeTicks::Now()), |
350 closed_by_user_gesture_(false), | 350 closed_by_user_gesture_(false), |
351 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)), | 351 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)), |
352 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)), | 352 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)), |
353 totalPinchGestureAmount_(0), | |
354 currentPinchZoomStepDelta_(0), | |
355 render_view_message_source_(NULL), | 353 render_view_message_source_(NULL), |
356 render_frame_message_source_(NULL), | 354 render_frame_message_source_(NULL), |
357 fullscreen_widget_routing_id_(MSG_ROUTING_NONE), | 355 fullscreen_widget_routing_id_(MSG_ROUTING_NONE), |
358 fullscreen_widget_had_focus_at_shutdown_(false), | 356 fullscreen_widget_had_focus_at_shutdown_(false), |
359 is_subframe_(false), | 357 is_subframe_(false), |
360 force_disable_overscroll_content_(false), | 358 force_disable_overscroll_content_(false), |
361 last_dialog_suppressed_(false), | 359 last_dialog_suppressed_(false), |
362 geolocation_service_context_(new GeolocationServiceContext()), | 360 geolocation_service_context_(new GeolocationServiceContext()), |
363 accessibility_mode_( | 361 accessibility_mode_( |
364 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode()), | 362 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode()), |
(...skipping 1055 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1420 } | 1418 } |
1421 #endif | 1419 #endif |
1422 return false; | 1420 return false; |
1423 } | 1421 } |
1424 | 1422 |
1425 bool WebContentsImpl::PreHandleGestureEvent( | 1423 bool WebContentsImpl::PreHandleGestureEvent( |
1426 const blink::WebGestureEvent& event) { | 1424 const blink::WebGestureEvent& event) { |
1427 return delegate_ && delegate_->PreHandleGestureEvent(this, event); | 1425 return delegate_ && delegate_->PreHandleGestureEvent(this, event); |
1428 } | 1426 } |
1429 | 1427 |
1430 bool WebContentsImpl::HandleGestureEvent( | |
1431 const blink::WebGestureEvent& event) { | |
1432 // Some platforms (eg. Mac) send GesturePinch events for trackpad pinch-zoom. | |
1433 // Use them to implement browser zoom, as for HandleWheelEvent above. | |
1434 if (event.type == blink::WebInputEvent::GesturePinchUpdate && | |
1435 event.sourceDevice == blink::WebGestureDeviceTouchpad) { | |
1436 // The scale difference necessary to trigger a zoom action. Derived from | |
1437 // experimentation to find a value that feels reasonable. | |
1438 const float kZoomStepValue = 0.6f; | |
1439 | |
1440 // Find the (absolute) thresholds on either side of the current zoom factor, | |
1441 // then convert those to actual numbers to trigger a zoom in or out. | |
1442 // This logic deliberately makes the range around the starting zoom value | |
1443 // for the gesture twice as large as the other ranges (i.e., the notches are | |
1444 // at ..., -3*step, -2*step, -step, step, 2*step, 3*step, ... but not at 0) | |
1445 // so that it's easier to get back to your starting point than it is to | |
1446 // overshoot. | |
1447 float nextStep = (abs(currentPinchZoomStepDelta_) + 1) * kZoomStepValue; | |
1448 float backStep = abs(currentPinchZoomStepDelta_) * kZoomStepValue; | |
1449 float zoomInThreshold = (currentPinchZoomStepDelta_ >= 0) ? nextStep | |
1450 : -backStep; | |
1451 float zoomOutThreshold = (currentPinchZoomStepDelta_ <= 0) ? -nextStep | |
1452 : backStep; | |
1453 | |
1454 totalPinchGestureAmount_ += (event.data.pinchUpdate.scale - 1.0); | |
1455 if (totalPinchGestureAmount_ > zoomInThreshold) { | |
1456 currentPinchZoomStepDelta_++; | |
1457 if (delegate_) | |
1458 delegate_->ContentsZoomChange(true); | |
1459 } else if (totalPinchGestureAmount_ < zoomOutThreshold) { | |
1460 currentPinchZoomStepDelta_--; | |
1461 if (delegate_) | |
1462 delegate_->ContentsZoomChange(false); | |
1463 } | |
1464 return true; | |
1465 } | |
1466 | |
1467 return false; | |
1468 } | |
1469 | |
1470 void WebContentsImpl::HandleMouseDown() { | 1428 void WebContentsImpl::HandleMouseDown() { |
1471 if (delegate_) | 1429 if (delegate_) |
1472 delegate_->HandleMouseDown(); | 1430 delegate_->HandleMouseDown(); |
1473 } | 1431 } |
1474 | 1432 |
1475 void WebContentsImpl::HandleMouseUp() { | 1433 void WebContentsImpl::HandleMouseUp() { |
1476 if (delegate_) | 1434 if (delegate_) |
1477 delegate_->HandleMouseUp(); | 1435 delegate_->HandleMouseUp(); |
1478 } | 1436 } |
1479 | 1437 |
(...skipping 3062 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4542 node->render_manager()->ResumeResponseDeferredAtStart(); | 4500 node->render_manager()->ResumeResponseDeferredAtStart(); |
4543 } | 4501 } |
4544 | 4502 |
4545 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { | 4503 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { |
4546 force_disable_overscroll_content_ = force_disable; | 4504 force_disable_overscroll_content_ = force_disable; |
4547 if (view_) | 4505 if (view_) |
4548 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); | 4506 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
4549 } | 4507 } |
4550 | 4508 |
4551 } // namespace content | 4509 } // namespace content |
OLD | NEW |