Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(101)

Side by Side Diff: third_party/WebKit/Source/web/DevToolsEmulator.cpp

Issue 2861373004: Add blink::WebInputEvent::IsPinchGestureEventType(). (Closed)
Patch Set: rebase Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "web/DevToolsEmulator.h" 5 #include "web/DevToolsEmulator.h"
6 6
7 #include "core/exported/WebViewBase.h" 7 #include "core/exported/WebViewBase.h"
8 #include "core/frame/FrameView.h" 8 #include "core/frame/FrameView.h"
9 #include "core/frame/Settings.h" 9 #include "core/frame/Settings.h"
10 #include "core/frame/VisualViewport.h" 10 #include "core/frame/VisualViewport.h"
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 script_execution_disabled_ = script_execution_disabled; 511 script_execution_disabled_ = script_execution_disabled;
512 web_view_impl_->GetPage()->GetSettings().SetScriptEnabled( 512 web_view_impl_->GetPage()->GetSettings().SetScriptEnabled(
513 script_execution_disabled_ ? false : embedder_script_enabled_); 513 script_execution_disabled_ ? false : embedder_script_enabled_);
514 } 514 }
515 515
516 bool DevToolsEmulator::HandleInputEvent(const WebInputEvent& input_event) { 516 bool DevToolsEmulator::HandleInputEvent(const WebInputEvent& input_event) {
517 Page* page = web_view_impl_->GetPage(); 517 Page* page = web_view_impl_->GetPage();
518 if (!page) 518 if (!page)
519 return false; 519 return false;
520 520
521 if (!touch_event_emulation_enabled_ ||
522 !WebInputEvent::IsPinchGestureEventType(input_event.GetType())) {
523 return false;
524 }
525
521 // FIXME: This workaround is required for touch emulation on Mac, where 526 // FIXME: This workaround is required for touch emulation on Mac, where
522 // compositor-side pinch handling is not enabled. See http://crbug.com/138003. 527 // compositor-side pinch handling is not enabled. See http://crbug.com/138003.
523 bool is_pinch = input_event.GetType() == WebInputEvent::kGesturePinchBegin || 528 FrameView* frame_view = page->DeprecatedLocalMainFrame()->View();
524 input_event.GetType() == WebInputEvent::kGesturePinchUpdate || 529 WebGestureEvent scaled_event = TransformWebGestureEvent(
525 input_event.GetType() == WebInputEvent::kGesturePinchEnd; 530 frame_view, static_cast<const WebGestureEvent&>(input_event));
526 if (is_pinch && touch_event_emulation_enabled_) { 531 float page_scale_factor = page->PageScaleFactor();
527 FrameView* frame_view = page->DeprecatedLocalMainFrame()->View(); 532 if (scaled_event.GetType() == WebInputEvent::kGesturePinchBegin) {
528 WebGestureEvent scaled_event = TransformWebGestureEvent( 533 WebFloatPoint gesture_position = scaled_event.PositionInRootFrame();
529 frame_view, static_cast<const WebGestureEvent&>(input_event)); 534 last_pinch_anchor_css_ = WTF::WrapUnique(new IntPoint(
530 float page_scale_factor = page->PageScaleFactor(); 535 RoundedIntPoint(gesture_position + frame_view->GetScrollOffset())));
531 if (scaled_event.GetType() == WebInputEvent::kGesturePinchBegin) { 536 last_pinch_anchor_dip_ =
532 WebFloatPoint gesture_position = scaled_event.PositionInRootFrame(); 537 WTF::WrapUnique(new IntPoint(FlooredIntPoint(gesture_position)));
533 last_pinch_anchor_css_ = WTF::WrapUnique(new IntPoint( 538 last_pinch_anchor_dip_->Scale(page_scale_factor, page_scale_factor);
534 RoundedIntPoint(gesture_position + frame_view->GetScrollOffset())));
535 last_pinch_anchor_dip_ =
536 WTF::WrapUnique(new IntPoint(FlooredIntPoint(gesture_position)));
537 last_pinch_anchor_dip_->Scale(page_scale_factor, page_scale_factor);
538 }
539 if (scaled_event.GetType() == WebInputEvent::kGesturePinchUpdate &&
540 last_pinch_anchor_css_) {
541 float new_page_scale_factor =
542 page_scale_factor * scaled_event.PinchScale();
543 IntPoint anchor_css(*last_pinch_anchor_dip_.get());
544 anchor_css.Scale(1.f / new_page_scale_factor,
545 1.f / new_page_scale_factor);
546 web_view_impl_->SetPageScaleFactor(new_page_scale_factor);
547 web_view_impl_->MainFrame()->SetScrollOffset(
548 ToIntSize(*last_pinch_anchor_css_.get() - ToIntSize(anchor_css)));
549 }
550 if (scaled_event.GetType() == WebInputEvent::kGesturePinchEnd) {
551 last_pinch_anchor_css_.reset();
552 last_pinch_anchor_dip_.reset();
553 }
554 return true;
555 } 539 }
556 540 if (scaled_event.GetType() == WebInputEvent::kGesturePinchUpdate &&
557 return false; 541 last_pinch_anchor_css_) {
542 float new_page_scale_factor = page_scale_factor * scaled_event.PinchScale();
543 IntPoint anchor_css(*last_pinch_anchor_dip_.get());
544 anchor_css.Scale(1.f / new_page_scale_factor, 1.f / new_page_scale_factor);
545 web_view_impl_->SetPageScaleFactor(new_page_scale_factor);
546 web_view_impl_->MainFrame()->SetScrollOffset(
547 ToIntSize(*last_pinch_anchor_css_.get() - ToIntSize(anchor_css)));
548 }
549 if (scaled_event.GetType() == WebInputEvent::kGesturePinchEnd) {
550 last_pinch_anchor_css_.reset();
551 last_pinch_anchor_dip_.reset();
552 }
553 return true;
558 } 554 }
559 555
560 } // namespace blink 556 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698