Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "content/browser/renderer_host/input/web_input_event_builders_mac.h" | 5 #include "content/browser/renderer_host/input/web_input_event_builders_mac.h" |
| 6 | 6 |
| 7 #include <Carbon/Carbon.h> | 7 #include <Carbon/Carbon.h> |
| 8 #import <Cocoa/Cocoa.h> | 8 #import <Cocoa/Cocoa.h> |
| 9 #include <stddef.h> | 9 #include <stddef.h> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #import "ui/events/cocoa/cocoa_event_utils.h" | |
| 14 #include "ui/events/event.h" | |
| 13 #include "ui/events/keycodes/dom/dom_code.h" | 15 #include "ui/events/keycodes/dom/dom_code.h" |
| 14 #include "ui/events/keycodes/dom/dom_key.h" | 16 #include "ui/events/keycodes/dom/dom_key.h" |
| 15 #include "ui/events/keycodes/keyboard_codes.h" | 17 #include "ui/events/keycodes/keyboard_codes.h" |
| 18 #import "ui/events/test/cocoa_test_event_utils.h" | |
| 16 | 19 |
| 17 using blink::WebKeyboardEvent; | 20 using blink::WebKeyboardEvent; |
| 18 using blink::WebInputEvent; | 21 using blink::WebInputEvent; |
| 19 using content::WebKeyboardEventBuilder; | 22 using content::WebKeyboardEventBuilder; |
| 20 | 23 |
| 21 namespace { | 24 namespace { |
| 22 | 25 |
| 23 struct KeyMappingEntry { | 26 struct KeyMappingEntry { |
| 24 int mac_key_code; | 27 int mac_key_code; |
| 25 unichar character; | 28 unichar character; |
| (...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 552 {kVK_RightControl, ui::DomKey::CONTROL}, | 555 {kVK_RightControl, ui::DomKey::CONTROL}, |
| 553 {kVK_Function, ui::DomKey::FN}}; | 556 {kVK_Function, ui::DomKey::FN}}; |
| 554 | 557 |
| 555 for (const DomKeyTestCase& entry : table) { | 558 for (const DomKeyTestCase& entry : table) { |
| 556 NSEvent* mac_event = | 559 NSEvent* mac_event = |
| 557 BuildFakeKeyEvent(entry.mac_key_code, 0, 0, NSFlagsChanged); | 560 BuildFakeKeyEvent(entry.mac_key_code, 0, 0, NSFlagsChanged); |
| 558 WebKeyboardEvent web_event = WebKeyboardEventBuilder::Build(mac_event); | 561 WebKeyboardEvent web_event = WebKeyboardEventBuilder::Build(mac_event); |
| 559 EXPECT_EQ(entry.dom_key, web_event.domKey) << entry.mac_key_code; | 562 EXPECT_EQ(entry.dom_key, web_event.domKey) << entry.mac_key_code; |
| 560 } | 563 } |
| 561 } | 564 } |
| 565 | |
| 566 // Test that a ui::Event and blink::WebInputEvent made from the same NSEvent | |
| 567 // have the same values for comparable fields. | |
| 568 TEST(WebInputEventBuilderMacTest, ScrollWheelMatchesUIEvent) { | |
| 569 CGFloat delta_x = 123; | |
| 570 CGFloat delta_y = 321; | |
| 571 NSPoint location = NSMakePoint(11, 22); | |
| 572 | |
| 573 // WebMouseWheelEventBuilder requires a non-nil view to map coordinates. So | |
| 574 // create a dummy window, but don't show it. It will be released when closed. | |
| 575 NSWindow* window = | |
| 576 [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 100, 100) | |
| 577 styleMask:NSBorderlessWindowMask | |
| 578 backing:NSBackingStoreBuffered | |
| 579 defer:NO]; | |
| 580 | |
| 581 NSEvent* mac_event = cocoa_test_event_utils::TestScrollEvent( | |
| 582 location, window, delta_x, delta_y); | |
| 583 | |
| 584 blink::WebMouseWheelEvent web_event = | |
| 585 content::WebMouseWheelEventBuilder::Build(mac_event, [window contentView], | |
| 586 false, false); | |
|
tapted
2016/08/11 04:25:22
bleh - web_input_event_builders_mac.h doesn't chan
| |
| 587 ui::MouseWheelEvent ui_event(mac_event); | |
| 588 | |
| 589 EXPECT_EQ(delta_x * ui::kScrollbarPixelsPerCocoaTick, web_event.deltaX); | |
| 590 EXPECT_EQ(web_event.deltaX, ui_event.x_offset()); | |
| 591 | |
| 592 EXPECT_EQ(delta_y * ui::kScrollbarPixelsPerCocoaTick, web_event.deltaY); | |
| 593 EXPECT_EQ(web_event.deltaY, ui_event.y_offset()); | |
| 594 | |
| 595 EXPECT_EQ(11, web_event.x); | |
| 596 EXPECT_EQ(web_event.x, ui_event.x()); | |
| 597 | |
| 598 // Both ui:: and blink:: events use an origin at the top-left. | |
| 599 EXPECT_EQ(100 - 22, web_event.y); | |
| 600 EXPECT_EQ(web_event.y, ui_event.y()); | |
| 601 [window close]; | |
| 602 } | |
| OLD | NEW |