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

Side by Side Diff: webkit/glue/webinputevent_mac.mm

Issue 40135: Various fixes to mouse wheel scrolling:... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 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 | Annotate | Revision Log
« no previous file with comments | « webkit/glue/webinputevent_linux.cc ('k') | webkit/glue/webinputevent_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved.
3 * Copyright (C) 2006-2009 Google Inc. 3 * Copyright (C) 2006-2009 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 112
113 layout_test_click_count = 0; 113 layout_test_click_count = 0;
114 } 114 }
115 115
116 // WebMouseWheelEvent --------------------------------------------------------- 116 // WebMouseWheelEvent ---------------------------------------------------------
117 117
118 WebMouseWheelEvent::WebMouseWheelEvent(NSEvent *event, NSView* view) { 118 WebMouseWheelEvent::WebMouseWheelEvent(NSEvent *event, NSView* view) {
119 type = MOUSE_WHEEL; 119 type = MOUSE_WHEEL;
120 button = BUTTON_NONE; 120 button = BUTTON_NONE;
121 121
122 NSPoint location = [NSEvent mouseLocation]; // global coordinates 122 // Set modifiers based on key state.
123 global_x = location.x;
124 global_y = location.y;
125
126 NSPoint windowLocal = [event locationInWindow];
127 location = [view convertPoint:windowLocal fromView:nil];
128 y = [view frame].size.height - location.y; // flip y
129 x = location.x;
130
131 int wheel_delta = [event deltaY];
132 const int delta_lines = wheel_delta * kDefaultScrollLinesPerWheelDelta;
133
134 // Scroll horizontally if shift is held. WebKit's WebKit/win/WebView.cpp
135 // does the equivalent.
136 // TODO(jackson): Support WM_MOUSEHWHEEL = 0x020E event as well.
137 // (Need a mouse with horizontal scrolling capabilities to test it.)
138 if ([event modifierFlags] & NSShiftKeyMask) {
139 // Scrolling up should move left, scrolling down should move right
140 delta_x = -delta_lines;
141 delta_y = 0;
142 } else {
143 delta_x = 0;
144 delta_y = delta_lines;
145 }
146
147 if ([event modifierFlags] & NSControlKeyMask) 123 if ([event modifierFlags] & NSControlKeyMask)
148 modifiers |= CTRL_KEY; 124 modifiers |= CTRL_KEY;
149 if ([event modifierFlags] & NSShiftKeyMask) 125 if ([event modifierFlags] & NSShiftKeyMask)
150 modifiers |= SHIFT_KEY; 126 modifiers |= SHIFT_KEY;
151 if ([event modifierFlags] & NSAlternateKeyMask) 127 if ([event modifierFlags] & NSAlternateKeyMask)
152 modifiers |= ALT_KEY; 128 modifiers |= ALT_KEY;
129
130 // Set coordinates by translating event coordinates from screen to client.
131 NSPoint location = [NSEvent mouseLocation]; // global coordinates
132 global_x = location.x;
133 global_y = location.y;
134 NSPoint windowLocal = [event locationInWindow];
135 location = [view convertPoint:windowLocal fromView:nil];
136 x = location.x;
137 y = [view frame].size.height - location.y; // flip y
138
139 // Convert wheel delta amount to a number of lines to scroll.
140 float wheel_delta = [event deltaY];
141 const float delta_lines = wheel_delta * kDefaultScrollLinesPerWheelDelta;
142
143 // Set scroll amount based on above calculations.
144 if ([event modifierFlags] & NSShiftKeyMask) {
145 // Scrolling up should move left, scrolling down should move right. This is
146 // opposite Safari, but seems more consistent with vertical scrolling.
Avi (use Gerrit) 2009/03/05 02:10:36 Nonono. Safari's shift-scrolling matches Cocoa's,
147 delta_x = delta_lines;
148 delta_y = 0;
149 } else {
150 delta_x = 0;
151 delta_y = delta_lines;
152 }
153 scroll_by_page = false;
153 } 154 }
154 155
155 // WebKeyboardEvent ----------------------------------------------------------- 156 // WebKeyboardEvent -----------------------------------------------------------
156 157
157 // ---------------------------------------------------------------------- 158 // ----------------------------------------------------------------------
158 // Begin Apple code, copied from KeyEventMac.mm 159 // Begin Apple code, copied from KeyEventMac.mm
159 // 160 //
160 // We can share some of this code if we factored it out of KeyEventMac, but 161 // We can share some of this code if we factored it out of KeyEventMac, but
161 // the main problem is that it relies on the NSString ctor on String for 162 // the main problem is that it relies on the NSString ctor on String for
162 // conversions, and since we're building without PLATFORM(MAC), we don't have 163 // conversions, and since we're building without PLATFORM(MAC), we don't have
(...skipping 842 matching lines...) Expand 10 before | Expand all | Expand 10 after
1005 [unmodified_str length] < kTextLengthCap) { 1006 [unmodified_str length] < kTextLengthCap) {
1006 [text_str getCharacters:&text[0]]; 1007 [text_str getCharacters:&text[0]];
1007 [unmodified_str getCharacters:&unmodified_text[0]]; 1008 [unmodified_str getCharacters:&unmodified_text[0]];
1008 } else { 1009 } else {
1009 LOG(ERROR) << "Event had text too long; dropped"; 1010 LOG(ERROR) << "Event had text too long; dropped";
1010 } 1011 }
1011 [identifier_str getCString:&key_identifier[0] 1012 [identifier_str getCString:&key_identifier[0]
1012 maxLength:kIdentifierLengthCap 1013 maxLength:kIdentifierLengthCap
1013 encoding:NSASCIIStringEncoding]; 1014 encoding:NSASCIIStringEncoding];
1014 } 1015 }
OLDNEW
« no previous file with comments | « webkit/glue/webinputevent_linux.cc ('k') | webkit/glue/webinputevent_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698