Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #import "ui/gfx/mac/coordinate_conversion.h" | 5 #import "ui/gfx/mac/coordinate_conversion.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 | 8 |
| 9 #import "base/mac/scoped_objc_class_swizzler.h" | 9 #import "base/mac/scoped_objc_class_swizzler.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 74 // 189 10 Window of height 40 fills in pixel | 74 // 189 10 Window of height 40 fills in pixel |
| 75 // 179 --------- 20 at index 20 | 75 // 179 --------- 20 at index 20 |
| 76 // 169 | | 30 through | 76 // 169 | | 30 through |
| 77 // ... : : .. to | 77 // ... : : .. to |
| 78 // 150 | | 49 pixel | 78 // 150 | | 49 pixel |
| 79 // 140 --------- 59 at index 59 | 79 // 140 --------- 59 at index 59 |
| 80 // 130 69 (inclusive). | 80 // 130 69 (inclusive). |
| 81 // .. .. | 81 // .. .. |
| 82 // 0 199 | 82 // 0 199 |
| 83 TEST_F(MacCoordinateConversionTest, ScreenRectToFromNSRect) { | 83 TEST_F(MacCoordinateConversionTest, ScreenRectToFromNSRect) { |
| 84 // Window on the primary screen. | |
| 84 Rect gfx_rect = Rect(10, 20, 30, 40); | 85 Rect gfx_rect = Rect(10, 20, 30, 40); |
| 85 NSRect ns_rect = ScreenRectToNSRect(gfx_rect); | 86 NSRect ns_rect = ScreenRectToNSRect(gfx_rect); |
| 86 EXPECT_NSEQ(NSMakeRect(10, 140, 30, 40), ns_rect); | 87 EXPECT_NSEQ(NSMakeRect(10, 140, 30, 40), ns_rect); |
| 87 EXPECT_EQ(gfx_rect.ToString(), ScreenRectFromNSRect(ns_rect).ToString()); | 88 EXPECT_EQ(gfx_rect, ScreenRectFromNSRect(ns_rect)); |
| 88 | 89 |
| 89 // Window in a screen to the left of the primary screen. | 90 // Window in a screen to the left of the primary screen. |
| 90 gfx_rect = Rect(-40, 20, 30, 40); | 91 gfx_rect = Rect(-40, 20, 30, 40); |
| 91 ns_rect = ScreenRectToNSRect(gfx_rect); | 92 ns_rect = ScreenRectToNSRect(gfx_rect); |
| 92 EXPECT_NSEQ(NSMakeRect(-40, 140, 30, 40), ns_rect); | 93 EXPECT_NSEQ(NSMakeRect(-40, 140, 30, 40), ns_rect); |
| 93 EXPECT_EQ(gfx_rect.ToString(), ScreenRectFromNSRect(ns_rect).ToString()); | 94 EXPECT_EQ(gfx_rect, ScreenRectFromNSRect(ns_rect)); |
| 94 | 95 |
| 95 // Window in a screen below the primary screen. | 96 // Window in a screen below the primary screen. |
| 96 gfx_rect = Rect(10, 220, 30, 40); | 97 gfx_rect = Rect(10, 220, 30, 40); |
| 97 ns_rect = ScreenRectToNSRect(gfx_rect); | 98 ns_rect = ScreenRectToNSRect(gfx_rect); |
| 98 EXPECT_NSEQ(NSMakeRect(10, -60, 30, 40), ns_rect); | 99 EXPECT_NSEQ(NSMakeRect(10, -60, 30, 40), ns_rect); |
| 99 EXPECT_EQ(gfx_rect.ToString(), ScreenRectFromNSRect(ns_rect).ToString()); | 100 EXPECT_EQ(gfx_rect, ScreenRectFromNSRect(ns_rect)); |
| 100 | 101 |
| 101 // Window in a screen below and to the left primary screen. | 102 // Window in a screen below and to the left primary screen. |
| 102 gfx_rect = Rect(-40, 220, 30, 40); | 103 gfx_rect = Rect(-40, 220, 30, 40); |
| 103 ns_rect = ScreenRectToNSRect(gfx_rect); | 104 ns_rect = ScreenRectToNSRect(gfx_rect); |
| 104 EXPECT_NSEQ(NSMakeRect(-40, -60, 30, 40), ns_rect); | 105 EXPECT_NSEQ(NSMakeRect(-40, -60, 30, 40), ns_rect); |
| 105 EXPECT_EQ(gfx_rect.ToString(), ScreenRectFromNSRect(ns_rect).ToString()); | 106 EXPECT_EQ(gfx_rect, ScreenRectFromNSRect(ns_rect)); |
| 107 } | |
| 108 | |
| 109 TEST_F(MacCoordinateConversionTest, ScreenPointToFromNSPoint) { | |
|
tapted
2015/08/11 04:01:01
nit: boring comment. I guess something like
// Te
jackhou1
2015/08/11 06:40:56
Done.
| |
| 110 // Point on the primary screen. | |
| 111 Point gfx_point = Point(10, 20); | |
| 112 NSPoint ns_point = ScreenPointToNSPoint(gfx_point); | |
| 113 EXPECT_NSEQ(NSMakePoint(10, 180), ns_point); | |
| 114 EXPECT_EQ(gfx_point, ScreenPointFromNSPoint(ns_point)); | |
| 115 | |
| 116 // Point in a screen to the left of the primary screen. | |
| 117 gfx_point = Point(-40, 20); | |
| 118 ns_point = ScreenPointToNSPoint(gfx_point); | |
| 119 EXPECT_NSEQ(NSMakePoint(-40, 180), ns_point); | |
| 120 EXPECT_EQ(gfx_point, ScreenPointFromNSPoint(ns_point)); | |
| 121 | |
| 122 // Point in a screen below the primary screen. | |
| 123 gfx_point = Point(10, 220); | |
| 124 ns_point = ScreenPointToNSPoint(gfx_point); | |
| 125 EXPECT_NSEQ(NSMakePoint(10, -20), ns_point); | |
| 126 EXPECT_EQ(gfx_point, ScreenPointFromNSPoint(ns_point)); | |
| 127 | |
| 128 // Point in a screen below and to the left primary screen. | |
| 129 gfx_point = Point(-40, 220); | |
| 130 ns_point = ScreenPointToNSPoint(gfx_point); | |
| 131 EXPECT_NSEQ(NSMakePoint(-40, -20), ns_point); | |
| 132 EXPECT_EQ(gfx_point, ScreenPointFromNSPoint(ns_point)); | |
| 106 } | 133 } |
| 107 | 134 |
| 108 } // namespace gfx | 135 } // namespace gfx |
| OLD | NEW |