| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/ui/app_list/app_list_positioner.h" | 5 #include "chrome/browser/ui/app_list/app_list_positioner.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 namespace { | 10 namespace { |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 gfx::Point DoGetAnchorPointForScreenCorner( | 86 gfx::Point DoGetAnchorPointForScreenCorner( |
| 87 AppListPositioner::ScreenCorner corner) const { | 87 AppListPositioner::ScreenCorner corner) const { |
| 88 return positioner_->GetAnchorPointForScreenCorner(corner); | 88 return positioner_->GetAnchorPointForScreenCorner(corner); |
| 89 } | 89 } |
| 90 | 90 |
| 91 gfx::Point DoGetAnchorPointForShelfCorner( | 91 gfx::Point DoGetAnchorPointForShelfCorner( |
| 92 AppListPositioner::ScreenEdge shelf_edge) const { | 92 AppListPositioner::ScreenEdge shelf_edge) const { |
| 93 return positioner_->GetAnchorPointForShelfCorner(shelf_edge); | 93 return positioner_->GetAnchorPointForShelfCorner(shelf_edge); |
| 94 } | 94 } |
| 95 | 95 |
| 96 gfx::Point DoGetAnchorPointForShelfCenter( |
| 97 AppListPositioner::ScreenEdge shelf_edge) const { |
| 98 return positioner_->GetAnchorPointForShelfCenter(shelf_edge); |
| 99 } |
| 100 |
| 96 gfx::Point DoGetAnchorPointForShelfCursor( | 101 gfx::Point DoGetAnchorPointForShelfCursor( |
| 97 AppListPositioner::ScreenEdge shelf_edge) const { | 102 AppListPositioner::ScreenEdge shelf_edge) const { |
| 98 return positioner_->GetAnchorPointForShelfCursor(shelf_edge, cursor_); | 103 return positioner_->GetAnchorPointForShelfCursor(shelf_edge, cursor_); |
| 99 } | 104 } |
| 100 | 105 |
| 101 AppListPositioner::ScreenEdge DoGetShelfEdge( | 106 AppListPositioner::ScreenEdge DoGetShelfEdge( |
| 102 const gfx::Rect& shelf_rect) const { | 107 const gfx::Rect& shelf_rect) const { |
| 103 return positioner_->GetShelfEdge(shelf_rect); | 108 return positioner_->GetShelfEdge(shelf_rect); |
| 104 } | 109 } |
| 105 | 110 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 | 174 |
| 170 // Shelf on bottom. Expect app list in bottom-left corner. | 175 // Shelf on bottom. Expect app list in bottom-left corner. |
| 171 PlaceShelf(AppListPositioner::SCREEN_EDGE_BOTTOM); | 176 PlaceShelf(AppListPositioner::SCREEN_EDGE_BOTTOM); |
| 172 EXPECT_EQ( | 177 EXPECT_EQ( |
| 173 gfx::Point(kWindowWidth / 2 + kMinDistanceFromEdge, | 178 gfx::Point(kWindowWidth / 2 + kMinDistanceFromEdge, |
| 174 kScreenHeight - kShelfSize - kWindowHeight / 2 - | 179 kScreenHeight - kShelfSize - kWindowHeight / 2 - |
| 175 kMinDistanceFromEdge), | 180 kMinDistanceFromEdge), |
| 176 DoGetAnchorPointForShelfCorner(AppListPositioner::SCREEN_EDGE_BOTTOM)); | 181 DoGetAnchorPointForShelfCorner(AppListPositioner::SCREEN_EDGE_BOTTOM)); |
| 177 } | 182 } |
| 178 | 183 |
| 184 TEST_F(AppListPositionerUnitTest, ShelfCenter) { |
| 185 // Position the app list on the shelf, aligned with the shelf center. |
| 186 PlaceShelf(AppListPositioner::SCREEN_EDGE_LEFT); |
| 187 // Shelf on left. Expect app list to be center-left. |
| 188 EXPECT_EQ( |
| 189 gfx::Point(kShelfSize + kWindowWidth / 2 + kMinDistanceFromEdge, |
| 190 (kMenuBarSize + kScreenHeight) / 2), |
| 191 DoGetAnchorPointForShelfCenter(AppListPositioner::SCREEN_EDGE_LEFT)); |
| 192 |
| 193 // Shelf on right. Expect app list to be center-right. |
| 194 PlaceShelf(AppListPositioner::SCREEN_EDGE_RIGHT); |
| 195 EXPECT_EQ( |
| 196 gfx::Point( |
| 197 kScreenWidth - kShelfSize - kWindowWidth / 2 - kMinDistanceFromEdge, |
| 198 (kMenuBarSize + kScreenHeight) / 2), |
| 199 DoGetAnchorPointForShelfCenter(AppListPositioner::SCREEN_EDGE_RIGHT)); |
| 200 |
| 201 // Shelf on top. Expect app list to be top-center. |
| 202 PlaceShelf(AppListPositioner::SCREEN_EDGE_TOP); |
| 203 EXPECT_EQ(gfx::Point(kScreenWidth / 2, |
| 204 kMenuBarSize + kShelfSize + kWindowHeight / 2 + |
| 205 kMinDistanceFromEdge), |
| 206 DoGetAnchorPointForShelfCenter(AppListPositioner::SCREEN_EDGE_TOP)); |
| 207 |
| 208 // Shelf on bottom. Expect app list to be bottom-center. |
| 209 PlaceShelf(AppListPositioner::SCREEN_EDGE_BOTTOM); |
| 210 EXPECT_EQ( |
| 211 gfx::Point(kScreenWidth / 2, |
| 212 kScreenHeight - kShelfSize - kWindowHeight / 2 - |
| 213 kMinDistanceFromEdge), |
| 214 DoGetAnchorPointForShelfCenter(AppListPositioner::SCREEN_EDGE_BOTTOM)); |
| 215 } |
| 216 |
| 179 TEST_F(AppListPositionerUnitTest, ShelfCursor) { | 217 TEST_F(AppListPositionerUnitTest, ShelfCursor) { |
| 180 // Position the app list on the shelf, aligned with the mouse cursor. | 218 // Position the app list on the shelf, aligned with the mouse cursor. |
| 181 | 219 |
| 182 // Shelf on left. Expect app list in top-left corner. | 220 // Shelf on left. Expect app list in top-left corner. |
| 183 PlaceShelf(AppListPositioner::SCREEN_EDGE_LEFT); | 221 PlaceShelf(AppListPositioner::SCREEN_EDGE_LEFT); |
| 184 PlaceCursor(kCursorIgnore, kWindowAwayFromEdge); | 222 PlaceCursor(kCursorIgnore, kWindowAwayFromEdge); |
| 185 EXPECT_EQ( | 223 EXPECT_EQ( |
| 186 gfx::Point(kShelfSize + kWindowWidth / 2 + kMinDistanceFromEdge, | 224 gfx::Point(kShelfSize + kWindowWidth / 2 + kMinDistanceFromEdge, |
| 187 kWindowAwayFromEdge), | 225 kWindowAwayFromEdge), |
| 188 DoGetAnchorPointForShelfCursor(AppListPositioner::SCREEN_EDGE_LEFT)); | 226 DoGetAnchorPointForShelfCursor(AppListPositioner::SCREEN_EDGE_LEFT)); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 EXPECT_EQ( | 329 EXPECT_EQ( |
| 292 kWindowAwayFromEdge - kShelfSize, | 330 kWindowAwayFromEdge - kShelfSize, |
| 293 DoGetCursorDistanceFromShelf(AppListPositioner::SCREEN_EDGE_BOTTOM)); | 331 DoGetCursorDistanceFromShelf(AppListPositioner::SCREEN_EDGE_BOTTOM)); |
| 294 | 332 |
| 295 // Shelf on bottom. Cursor inside shelf; expect 0. | 333 // Shelf on bottom. Cursor inside shelf; expect 0. |
| 296 PlaceShelf(AppListPositioner::SCREEN_EDGE_BOTTOM); | 334 PlaceShelf(AppListPositioner::SCREEN_EDGE_BOTTOM); |
| 297 PlaceCursor(kCursorIgnore, kScreenHeight - kCursorOnShelf); | 335 PlaceCursor(kCursorIgnore, kScreenHeight - kCursorOnShelf); |
| 298 EXPECT_EQ( | 336 EXPECT_EQ( |
| 299 0, DoGetCursorDistanceFromShelf(AppListPositioner::SCREEN_EDGE_BOTTOM)); | 337 0, DoGetCursorDistanceFromShelf(AppListPositioner::SCREEN_EDGE_BOTTOM)); |
| 300 } | 338 } |
| OLD | NEW |