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

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_mac.mm

Issue 1008993002: Protoype Mac input event filter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_mac.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 #include "ui/base/layout.h" 68 #include "ui/base/layout.h"
69 #include "ui/compositor/compositor.h" 69 #include "ui/compositor/compositor.h"
70 #include "ui/compositor/layer.h" 70 #include "ui/compositor/layer.h"
71 #include "ui/events/keycodes/keyboard_codes.h" 71 #include "ui/events/keycodes/keyboard_codes.h"
72 #include "ui/gfx/display.h" 72 #include "ui/gfx/display.h"
73 #include "ui/gfx/frame_time.h" 73 #include "ui/gfx/frame_time.h"
74 #include "ui/gfx/geometry/dip_util.h" 74 #include "ui/gfx/geometry/dip_util.h"
75 #include "ui/gfx/geometry/point.h" 75 #include "ui/gfx/geometry/point.h"
76 #include "ui/gfx/geometry/rect_conversions.h" 76 #include "ui/gfx/geometry/rect_conversions.h"
77 #include "ui/gfx/geometry/size_conversions.h" 77 #include "ui/gfx/geometry/size_conversions.h"
78 #include "ui/gfx/geometry/vector2d_f.h"
78 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" 79 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
79 #include "ui/gfx/screen.h" 80 #include "ui/gfx/screen.h"
80 #include "ui/gl/gl_switches.h" 81 #include "ui/gl/gl_switches.h"
81 82
82 using content::BrowserAccessibility; 83 using content::BrowserAccessibility;
83 using content::BrowserAccessibilityManager; 84 using content::BrowserAccessibilityManager;
84 using content::EditCommand; 85 using content::EditCommand;
85 using content::FrameTreeNode; 86 using content::FrameTreeNode;
86 using content::NativeWebKeyboardEvent; 87 using content::NativeWebKeyboardEvent;
87 using content::RenderFrameHost; 88 using content::RenderFrameHost;
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 results.orientationType = 385 results.orientationType =
385 content::RenderWidgetHostViewBase::GetOrientationTypeForDesktop(display); 386 content::RenderWidgetHostViewBase::GetOrientationTypeForDesktop(display);
386 387
387 return results; 388 return results;
388 } 389 }
389 390
390 } // namespace 391 } // namespace
391 392
392 namespace content { 393 namespace content {
393 394
395 class WheelEventRailFilterMac {
396 public:
397 WheelEventRailFilterMac() :
398 mode_(MODE_UNINITIALIZED) {
399 }
400
401 ~WheelEventRailFilterMac() {
402 }
403
404 WebMouseWheelEvent FilterWheelEvent(const WebMouseWheelEvent& event) {
405 // This number came from 0.5 feeling too big and 0.9 feeling too small.
406 const float kDecayConstant = 0.8f;
407 // Require a slightly-more-than-diagonal motion against the current
408 // scroll to break the rails.
409 const float kSinThetaToBreakRails = 0.8f;
410 // Require a consistently-unidirectional motion to reset the rails
411 // after they have been broken.
412 const float kSinThetaToResetRails = 0.02f;
413
414 if (event.phase == blink::WebMouseWheelEvent::PhaseBegan) {
415 mode_ = MODE_UNINITIALIZED;
416 decayed_delta_ = gfx::Vector2dF();
417 }
418 if (event.deltaX == 0 && event.deltaY == 0)
419 return event;
420
421 decayed_delta_.Scale(kDecayConstant);
422 decayed_delta_ += gfx::Vector2dF(fabsf(event.deltaX), fabsf(event.deltaY));
423
424 float sin_theta_horizontal = decayed_delta_.y() / decayed_delta_.Length();
425 float sin_theta_vertical = decayed_delta_.x() / decayed_delta_.Length();
426
427 switch (mode_) {
428 case MODE_UNINITIALIZED:
429 if (decayed_delta_.x() > decayed_delta_.y())
430 mode_ = MODE_HORIZONTAL;
431 else
432 mode_ = MODE_VERTICAL;
433 break;
434 case MODE_HORIZONTAL:
435 if (sin_theta_horizontal > kSinThetaToBreakRails)
436 mode_ = MODE_FREE;
437 break;
438 case MODE_VERTICAL:
439 if (sin_theta_vertical > kSinThetaToBreakRails)
440 mode_ = MODE_FREE;
441 break;
442 case MODE_FREE:
443 if (sin_theta_horizontal < kSinThetaToResetRails)
444 mode_ = MODE_HORIZONTAL;
445 if (sin_theta_vertical < kSinThetaToResetRails)
446 mode_ = MODE_VERTICAL;
447 break;
448 }
449
450 WebMouseWheelEvent result = event;
451 switch (mode_) {
452 case MODE_HORIZONTAL:
453 printf("mode:Horiz\n");
454 result.deltaY = 0;
455 break;
456 case MODE_VERTICAL:
457 printf("mode:Vert\n");
458 result.deltaX = 0;
459 break;
460 default:
461 printf("Free\n");
462 break;
463 }
464 return result;
465 }
466
467 private:
468 enum Mode {
469 MODE_UNINITIALIZED,
470 MODE_HORIZONTAL,
471 MODE_VERTICAL,
472 MODE_FREE,
473 };
474 Mode mode_;
475 gfx::Vector2dF decayed_delta_;
476 gfx::Vector2dF decayed_delta_other_;
477 };
478
394 //////////////////////////////////////////////////////////////////////////////// 479 ////////////////////////////////////////////////////////////////////////////////
395 // DelegatedFrameHost, public: 480 // DelegatedFrameHost, public:
396 481
397 ui::Layer* RenderWidgetHostViewMac::DelegatedFrameHostGetLayer() const { 482 ui::Layer* RenderWidgetHostViewMac::DelegatedFrameHostGetLayer() const {
398 return root_layer_.get(); 483 return root_layer_.get();
399 } 484 }
400 485
401 bool RenderWidgetHostViewMac::DelegatedFrameHostIsVisible() const { 486 bool RenderWidgetHostViewMac::DelegatedFrameHostIsVisible() const {
402 return !render_widget_host_->is_hidden(); 487 return !render_widget_host_->is_hidden();
403 } 488 }
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 void RenderWidgetHostViewBase::GetDefaultScreenInfo( 603 void RenderWidgetHostViewBase::GetDefaultScreenInfo(
519 blink::WebScreenInfo* results) { 604 blink::WebScreenInfo* results) {
520 *results = GetWebScreenInfo(NULL); 605 *results = GetWebScreenInfo(NULL);
521 } 606 }
522 607
523 /////////////////////////////////////////////////////////////////////////////// 608 ///////////////////////////////////////////////////////////////////////////////
524 // RenderWidgetHostViewMac, public: 609 // RenderWidgetHostViewMac, public:
525 610
526 RenderWidgetHostViewMac::RenderWidgetHostViewMac(RenderWidgetHost* widget, 611 RenderWidgetHostViewMac::RenderWidgetHostViewMac(RenderWidgetHost* widget,
527 bool is_guest_view_hack) 612 bool is_guest_view_hack)
528 : render_widget_host_(RenderWidgetHostImpl::From(widget)), 613 : wheel_event_rail_filter_(new WheelEventRailFilterMac),
614 render_widget_host_(RenderWidgetHostImpl::From(widget)),
529 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), 615 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
530 can_compose_inline_(true), 616 can_compose_inline_(true),
531 browser_compositor_state_(BrowserCompositorDestroyed), 617 browser_compositor_state_(BrowserCompositorDestroyed),
532 browser_compositor_placeholder_(new BrowserCompositorMacPlaceholder), 618 browser_compositor_placeholder_(new BrowserCompositorMacPlaceholder),
533 is_loading_(false), 619 is_loading_(false),
534 allow_pause_for_resize_or_repaint_(true), 620 allow_pause_for_resize_or_repaint_(true),
535 is_guest_view_hack_(is_guest_view_hack), 621 is_guest_view_hack_(is_guest_view_hack),
536 fullscreen_parent_host_view_(NULL), 622 fullscreen_parent_host_view_(NULL),
537 weak_factory_(this) { 623 weak_factory_(this) {
538 // |cocoa_view_| owns us and we will be deleted when |cocoa_view_| 624 // |cocoa_view_| owns us and we will be deleted when |cocoa_view_|
(...skipping 1711 matching lines...) Expand 10 before | Expand all | Expand 10 after
2250 return; 2336 return;
2251 } 2337 }
2252 2338
2253 if (renderWidgetHostView_->render_widget_host_) { 2339 if (renderWidgetHostView_->render_widget_host_) {
2254 // History-swiping is not possible if the logic reaches this point. 2340 // History-swiping is not possible if the logic reaches this point.
2255 // Allow rubber-banding in both directions. 2341 // Allow rubber-banding in both directions.
2256 bool canRubberbandLeft = true; 2342 bool canRubberbandLeft = true;
2257 bool canRubberbandRight = true; 2343 bool canRubberbandRight = true;
2258 const WebMouseWheelEvent webEvent = WebInputEventFactory::mouseWheelEvent( 2344 const WebMouseWheelEvent webEvent = WebInputEventFactory::mouseWheelEvent(
2259 event, self, canRubberbandLeft, canRubberbandRight); 2345 event, self, canRubberbandLeft, canRubberbandRight);
2260 renderWidgetHostView_->render_widget_host_->ForwardWheelEvent(webEvent); 2346 renderWidgetHostView_->render_widget_host_->ForwardWheelEvent(
2347 renderWidgetHostView_->wheel_event_rail_filter_->FilterWheelEvent(
2348 webEvent));
2261 } 2349 }
2262 2350
2263 if (endWheelMonitor_) { 2351 if (endWheelMonitor_) {
2264 [NSEvent removeMonitor:endWheelMonitor_]; 2352 [NSEvent removeMonitor:endWheelMonitor_];
2265 endWheelMonitor_ = nil; 2353 endWheelMonitor_ = nil;
2266 } 2354 }
2267 } 2355 }
2268 2356
2269 - (void)beginGestureWithEvent:(NSEvent*)event { 2357 - (void)beginGestureWithEvent:(NSEvent*)event {
2270 [responderDelegate_ beginGestureWithEvent:event]; 2358 [responderDelegate_ beginGestureWithEvent:event];
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
2373 return blockEvent; 2461 return blockEvent;
2374 }]; 2462 }];
2375 } 2463 }
2376 2464
2377 // This is responsible for content scrolling! 2465 // This is responsible for content scrolling!
2378 if (renderWidgetHostView_->render_widget_host_) { 2466 if (renderWidgetHostView_->render_widget_host_) {
2379 BOOL canRubberbandLeft = [responderDelegate_ canRubberbandLeft:self]; 2467 BOOL canRubberbandLeft = [responderDelegate_ canRubberbandLeft:self];
2380 BOOL canRubberbandRight = [responderDelegate_ canRubberbandRight:self]; 2468 BOOL canRubberbandRight = [responderDelegate_ canRubberbandRight:self];
2381 const WebMouseWheelEvent webEvent = WebInputEventFactory::mouseWheelEvent( 2469 const WebMouseWheelEvent webEvent = WebInputEventFactory::mouseWheelEvent(
2382 event, self, canRubberbandLeft, canRubberbandRight); 2470 event, self, canRubberbandLeft, canRubberbandRight);
2383 renderWidgetHostView_->render_widget_host_->ForwardWheelEvent(webEvent); 2471 renderWidgetHostView_->render_widget_host_->ForwardWheelEvent(
2472 renderWidgetHostView_->wheel_event_rail_filter_->FilterWheelEvent(
2473 webEvent));
2384 } 2474 }
2385 } 2475 }
2386 2476
2387 // Called repeatedly during a pinch gesture, with incremental change values. 2477 // Called repeatedly during a pinch gesture, with incremental change values.
2388 - (void)magnifyWithEvent:(NSEvent*)event { 2478 - (void)magnifyWithEvent:(NSEvent*)event {
2389 if (!renderWidgetHostView_->render_widget_host_) 2479 if (!renderWidgetHostView_->render_widget_host_)
2390 return; 2480 return;
2391 2481
2392 // If, due to nesting of multiple gestures (e.g, from multiple touch 2482 // If, due to nesting of multiple gestures (e.g, from multiple touch
2393 // devices), the beginning of the gesture has been lost, skip the remainder 2483 // devices), the beginning of the gesture has been lost, skip the remainder
(...skipping 1056 matching lines...) Expand 10 before | Expand all | Expand 10 after
3450 3540
3451 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding 3541 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding
3452 // regions that are not draggable. (See ControlRegionView in 3542 // regions that are not draggable. (See ControlRegionView in
3453 // native_app_window_cocoa.mm). This requires the render host view to be 3543 // native_app_window_cocoa.mm). This requires the render host view to be
3454 // draggable by default. 3544 // draggable by default.
3455 - (BOOL)mouseDownCanMoveWindow { 3545 - (BOOL)mouseDownCanMoveWindow {
3456 return YES; 3546 return YES;
3457 } 3547 }
3458 3548
3459 @end 3549 @end
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_mac.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698