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

Side by Side Diff: ui/events/cocoa/events_mac_unittest.mm

Issue 316053008: MacViews: Allow ui::EventLocationFromNative to handle native titlebars (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: selfnit Created 6 years, 6 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
« ui/events/cocoa/events_mac.mm ('K') | « ui/events/cocoa/events_mac.mm ('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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "ui/events/event_utils.h" 5 #include "ui/events/event_utils.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 8
9 #include "base/mac/scoped_cftyperef.h" 9 #include "base/mac/scoped_cftyperef.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 30 matching lines...) Expand all
41 41
42 namespace ui { 42 namespace ui {
43 43
44 namespace { 44 namespace {
45 45
46 class EventsMacTest : public CocoaTest { 46 class EventsMacTest : public CocoaTest {
47 public: 47 public:
48 EventsMacTest() {} 48 EventsMacTest() {}
49 49
50 gfx::Point Flip(gfx::Point window_location) { 50 gfx::Point Flip(gfx::Point window_location) {
51 window_location.set_y( 51 NSRect window_frame = [test_window() frame];
52 NSHeight([test_window() frame]) - window_location.y()); 52 CGFloat content_height =
53 NSHeight([test_window() contentRectForFrameRect:window_frame]);
54 window_location.set_y(content_height - window_location.y());
53 return window_location; 55 return window_location;
54 } 56 }
55 57
56 void SwizzleMiddleMouseButton() { 58 void SwizzleMiddleMouseButton() {
57 DCHECK(!swizzler_); 59 DCHECK(!swizzler_);
58 swizzler_.reset(new ScopedClassSwizzler( 60 swizzler_.reset(new ScopedClassSwizzler(
59 [NSEvent class], 61 [NSEvent class],
60 [MiddleMouseButtonNumberDonor class], 62 [MiddleMouseButtonNumberDonor class],
61 @selector(buttonNumber))); 63 @selector(buttonNumber)));
62 } 64 }
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 event = TestScrollEvent(location, -1, 0); 235 event = TestScrollEvent(location, -1, 0);
234 EXPECT_EQ(ui::ET_MOUSEWHEEL, ui::EventTypeFromNative(event)); 236 EXPECT_EQ(ui::ET_MOUSEWHEEL, ui::EventTypeFromNative(event));
235 EXPECT_EQ(0, ui::EventFlagsFromNative(event)); 237 EXPECT_EQ(0, ui::EventFlagsFromNative(event));
236 EXPECT_EQ(location, ui::EventLocationFromNative(event)); 238 EXPECT_EQ(location, ui::EventLocationFromNative(event));
237 offset = ui::GetMouseWheelOffset(event); 239 offset = ui::GetMouseWheelOffset(event);
238 EXPECT_EQ(0, offset.y()); 240 EXPECT_EQ(0, offset.y());
239 EXPECT_LT(offset.x(), 0); 241 EXPECT_LT(offset.x(), 0);
240 ClearSwizzle(); 242 ClearSwizzle();
241 } 243 }
242 244
245 // Test correct location when the window has a native titlebar.
246 TEST_F(EventsMacTest, NativeTitlebarEventLocation) {
247 gfx::Point location(5, 10);
248 NSUInteger style_mask = NSTitledWindowMask | NSClosableWindowMask |
249 NSMiniaturizableWindowMask | NSResizableWindowMask;
250
251 // First check that the window provided by ui::CocoaTest is how we think.
252 DCHECK_EQ(NSBorderlessWindowMask, [test_window() styleMask]);
253 [test_window() setStyleMask:style_mask];
254 DCHECK_EQ(style_mask, [test_window() styleMask]);
255
256 // EventLocationFromNative should behave the same as the ButtonEvents test.
257 NSEvent* event = TestMouseEvent(NSLeftMouseDown, location, 0);
258 EXPECT_EQ(ui::ET_MOUSE_PRESSED, ui::EventTypeFromNative(event));
259 EXPECT_EQ(ui::EF_LEFT_MOUSE_BUTTON, ui::EventFlagsFromNative(event));
260 EXPECT_EQ(location, ui::EventLocationFromNative(event));
261
262 // And be explicit, to ensure the test doesn't depend on some property of the
263 // test harness. The change to the frame rect could be OS-specfic, so set it
264 // to a known value.
265 const CGFloat kTestHeight = 400;
266 NSRect content_rect = NSMakeRect(0, 0, 600, kTestHeight);
267 NSRect frame_rect = [test_window() frameRectForContentRect:content_rect];
268 [test_window() setFrame:frame_rect display:YES];
269 event = [NSEvent mouseEventWithType:NSLeftMouseDown
270 location:NSMakePoint(0, 0) // Bottom-left corner.
271 modifierFlags:0
272 timestamp:0
273 windowNumber:[test_window() windowNumber]
274 context:nil
275 eventNumber:0
276 clickCount:0
277 pressure:1.0];
278 // Bottom-left corner should be flipped.
279 EXPECT_EQ(gfx::Point(0, kTestHeight), ui::EventLocationFromNative(event));
280
281 // Removing the border, and sending the same event should move it down in the
282 // toolkit-views coordinate system.
283 int height_change = NSHeight(frame_rect) - kTestHeight;
284 EXPECT_GT(height_change, 0);
285 [test_window() setStyleMask:NSBorderlessWindowMask];
286 [test_window() setFrame:frame_rect display:YES];
287 EXPECT_EQ(gfx::Point(0, kTestHeight + height_change),
288 ui::EventLocationFromNative(event));
289 }
290
243 } // namespace ui 291 } // namespace ui
OLDNEW
« ui/events/cocoa/events_mac.mm ('K') | « ui/events/cocoa/events_mac.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698