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

Side by Side Diff: content/browser/renderer_host/input/web_input_event_builders_mac.mm

Issue 2226933004: Mac: Share kScrollbarPixelsPerCocoaTick between ui:: and blink:: events (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase for r411201 Created 4 years, 4 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 | « no previous file | content/browser/renderer_host/input/web_input_event_builders_mac_unittest.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 /* 5 /*
6 * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved. 6 * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved.
7 * Copyright (C) 2006-2009 Google Inc. 7 * Copyright (C) 2006-2009 Google Inc.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
(...skipping 22 matching lines...) Expand all
33 #import <ApplicationServices/ApplicationServices.h> 33 #import <ApplicationServices/ApplicationServices.h>
34 #import <Cocoa/Cocoa.h> 34 #import <Cocoa/Cocoa.h>
35 35
36 #include <stdint.h> 36 #include <stdint.h>
37 37
38 #include "base/mac/sdk_forward_declarations.h" 38 #include "base/mac/sdk_forward_declarations.h"
39 #include "base/strings/string_util.h" 39 #include "base/strings/string_util.h"
40 #include "content/browser/renderer_host/input/web_input_event_util.h" 40 #include "content/browser/renderer_host/input/web_input_event_util.h"
41 #include "third_party/WebKit/public/web/WebInputEvent.h" 41 #include "third_party/WebKit/public/web/WebInputEvent.h"
42 #include "ui/base/cocoa/cocoa_base_utils.h" 42 #include "ui/base/cocoa/cocoa_base_utils.h"
43 #import "ui/events/cocoa/cocoa_event_utils.h"
43 #include "ui/events/keycodes/keyboard_code_conversion.h" 44 #include "ui/events/keycodes/keyboard_code_conversion.h"
44 #include "ui/events/keycodes/keyboard_code_conversion_mac.h" 45 #include "ui/events/keycodes/keyboard_code_conversion_mac.h"
45 46
46 namespace content { 47 namespace content {
47 48
48 namespace { 49 namespace {
49 50
50 // Return true if the target modifier key is up. OS X has an "official" flag 51 // Return true if the target modifier key is up. OS X has an "official" flag
51 // to test whether either left or right versions of a modifier key are held, 52 // to test whether either left or right versions of a modifier key are held,
52 // and "unofficial" flags for the left and right versions independently. This 53 // and "unofficial" flags for the left and right versions independently. This
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 DCHECK(cg_event); 536 DCHECK(cg_event);
536 537
537 // Wheel ticks are supposed to be raw, unaccelerated values, one per physical 538 // Wheel ticks are supposed to be raw, unaccelerated values, one per physical
538 // mouse wheel notch. The delta event is perfect for this (being a good 539 // mouse wheel notch. The delta event is perfect for this (being a good
539 // "specific edge case" as mentioned above). Trackpads, unfortunately, do 540 // "specific edge case" as mentioned above). Trackpads, unfortunately, do
540 // event chunking, and sending mousewheel events with 0 ticks causes some 541 // event chunking, and sending mousewheel events with 0 ticks causes some
541 // websites to malfunction. Therefore, for all continuous input devices we use 542 // websites to malfunction. Therefore, for all continuous input devices we use
542 // the point delta data instead, since we cannot distinguish trackpad data 543 // the point delta data instead, since we cannot distinguish trackpad data
543 // from data from any other continuous device. 544 // from data from any other continuous device.
544 545
545 // Conversion between wheel delta amounts and number of pixels to scroll.
546 static const double kScrollbarPixelsPerCocoaTick = 40.0;
547
548 if (CGEventGetIntegerValueField(cg_event, kCGScrollWheelEventIsContinuous)) { 546 if (CGEventGetIntegerValueField(cg_event, kCGScrollWheelEventIsContinuous)) {
549 result.deltaX = CGEventGetIntegerValueField( 547 result.deltaX = CGEventGetIntegerValueField(
550 cg_event, kCGScrollWheelEventPointDeltaAxis2); 548 cg_event, kCGScrollWheelEventPointDeltaAxis2);
551 result.deltaY = CGEventGetIntegerValueField( 549 result.deltaY = CGEventGetIntegerValueField(
552 cg_event, kCGScrollWheelEventPointDeltaAxis1); 550 cg_event, kCGScrollWheelEventPointDeltaAxis1);
553 result.wheelTicksX = result.deltaX / kScrollbarPixelsPerCocoaTick; 551 result.wheelTicksX = result.deltaX / ui::kScrollbarPixelsPerCocoaTick;
554 result.wheelTicksY = result.deltaY / kScrollbarPixelsPerCocoaTick; 552 result.wheelTicksY = result.deltaY / ui::kScrollbarPixelsPerCocoaTick;
555 result.hasPreciseScrollingDeltas = true; 553 result.hasPreciseScrollingDeltas = true;
556 } else { 554 } else {
557 result.deltaX = [event deltaX] * kScrollbarPixelsPerCocoaTick; 555 result.deltaX = [event deltaX] * ui::kScrollbarPixelsPerCocoaTick;
558 result.deltaY = [event deltaY] * kScrollbarPixelsPerCocoaTick; 556 result.deltaY = [event deltaY] * ui::kScrollbarPixelsPerCocoaTick;
559 result.wheelTicksY = 557 result.wheelTicksY =
560 CGEventGetIntegerValueField(cg_event, kCGScrollWheelEventDeltaAxis1); 558 CGEventGetIntegerValueField(cg_event, kCGScrollWheelEventDeltaAxis1);
561 result.wheelTicksX = 559 result.wheelTicksX =
562 CGEventGetIntegerValueField(cg_event, kCGScrollWheelEventDeltaAxis2); 560 CGEventGetIntegerValueField(cg_event, kCGScrollWheelEventDeltaAxis2);
563 } 561 }
564 562
565 result.timeStampSeconds = [event timestamp]; 563 result.timeStampSeconds = [event timestamp];
566 564
567 result.phase = PhaseForEvent(event); 565 result.phase = PhaseForEvent(event);
568 result.momentumPhase = MomentumPhaseForEvent(event); 566 result.momentumPhase = MomentumPhaseForEvent(event);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 break; 607 break;
610 default: 608 default:
611 NOTIMPLEMENTED(); 609 NOTIMPLEMENTED();
612 result.type = blink::WebInputEvent::Undefined; 610 result.type = blink::WebInputEvent::Undefined;
613 } 611 }
614 612
615 return result; 613 return result;
616 } 614 }
617 615
618 } // namespace content 616 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/renderer_host/input/web_input_event_builders_mac_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698