| 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 "ui/display/win/screen_win.h" | 5 #include "ui/display/win/screen_win.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <inttypes.h> | 8 #include <inttypes.h> |
| 9 #include <stddef.h> | 9 #include <stddef.h> |
| 10 | 10 |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 } | 383 } |
| 384 | 384 |
| 385 namespace { | 385 namespace { |
| 386 | 386 |
| 387 // Single Display of 1.25 Device Scale Factor. | 387 // Single Display of 1.25 Device Scale Factor. |
| 388 class ScreenWinTestSingleDisplay1_25x : public ScreenWinTest { | 388 class ScreenWinTestSingleDisplay1_25x : public ScreenWinTest { |
| 389 public: | 389 public: |
| 390 ScreenWinTestSingleDisplay1_25x() = default; | 390 ScreenWinTestSingleDisplay1_25x() = default; |
| 391 | 391 |
| 392 void SetUpScreen(TestScreenWinInitializer* initializer) override { | 392 void SetUpScreen(TestScreenWinInitializer* initializer) override { |
| 393 // Add Monitor of Scale Factor 1.0 since 1.25 is clamped to 1.0. | |
| 394 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200), | 393 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200), |
| 395 gfx::Rect(0, 0, 1920, 1100), | 394 gfx::Rect(0, 0, 1920, 1100), |
| 396 L"primary", | 395 L"primary", |
| 397 1.0); | 396 1.25); |
| 398 fake_hwnd_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100)); | 397 fake_hwnd_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100)); |
| 399 } | 398 } |
| 400 | 399 |
| 401 HWND GetFakeHwnd() { | 400 HWND GetFakeHwnd() { |
| 402 return fake_hwnd_; | 401 return fake_hwnd_; |
| 403 } | 402 } |
| 404 | 403 |
| 405 private: | 404 private: |
| 406 HWND fake_hwnd_ = nullptr; | 405 HWND fake_hwnd_ = nullptr; |
| 407 | 406 |
| 408 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestSingleDisplay1_25x); | 407 DISALLOW_COPY_AND_ASSIGN(ScreenWinTestSingleDisplay1_25x); |
| 409 }; | 408 }; |
| 410 | 409 |
| 411 } // namespace | 410 } // namespace |
| 412 | 411 |
| 413 TEST_F(ScreenWinTestSingleDisplay1_25x, ScreenToDIPPoints) { | 412 TEST_F(ScreenWinTestSingleDisplay1_25x, ScreenToDIPPoints) { |
| 414 gfx::Point origin(0, 0); | 413 EXPECT_EQ(gfx::Point(0, 0), ScreenWin::ScreenToDIPPoint(gfx::Point(0, 0))); |
| 415 gfx::Point middle(365, 694); | 414 EXPECT_EQ(gfx::Point(292, 555), |
| 416 gfx::Point lower_right(1919, 1199); | 415 ScreenWin::ScreenToDIPPoint(gfx::Point(365, 694))); |
| 417 EXPECT_EQ(origin, ScreenWin::ScreenToDIPPoint(origin)); | 416 EXPECT_EQ(gfx::Point(1535, 959), |
| 418 EXPECT_EQ(middle, ScreenWin::ScreenToDIPPoint(middle)); | 417 ScreenWin::ScreenToDIPPoint(gfx::Point(1919, 1199))); |
| 419 EXPECT_EQ(lower_right, ScreenWin::ScreenToDIPPoint(lower_right)); | |
| 420 } | 418 } |
| 421 | 419 |
| 422 TEST_F(ScreenWinTestSingleDisplay1_25x, DIPToScreenPoints) { | 420 TEST_F(ScreenWinTestSingleDisplay1_25x, DIPToScreenPoints) { |
| 423 gfx::Point origin(0, 0); | 421 EXPECT_EQ(gfx::Point(0, 0), ScreenWin::DIPToScreenPoint(gfx::Point(0, 0))); |
| 424 gfx::Point middle(365, 694); | 422 EXPECT_EQ(gfx::Point(303, 577), |
| 425 gfx::Point lower_right(1919, 1199); | 423 ScreenWin::DIPToScreenPoint(gfx::Point(243, 462))); |
| 426 EXPECT_EQ(origin, ScreenWin::DIPToScreenPoint(origin)); | 424 EXPECT_EQ(gfx::Point(1598, 998), |
| 427 EXPECT_EQ(middle, ScreenWin::DIPToScreenPoint(middle)); | 425 ScreenWin::DIPToScreenPoint(gfx::Point(1279, 799))); |
| 428 EXPECT_EQ(lower_right, ScreenWin::DIPToScreenPoint(lower_right)); | |
| 429 } | 426 } |
| 430 | 427 |
| 431 TEST_F(ScreenWinTestSingleDisplay1_25x, ClientToDIPPoints) { | 428 TEST_F(ScreenWinTestSingleDisplay1_25x, ClientToDIPPoints) { |
| 432 HWND hwnd = GetFakeHwnd(); | 429 HWND hwnd = GetFakeHwnd(); |
| 433 gfx::Point origin(0, 0); | 430 EXPECT_EQ(gfx::Point(0, 0), |
| 434 gfx::Point middle(365, 694); | 431 ScreenWin::ClientToDIPPoint(hwnd, gfx::Point(0, 0))); |
| 435 gfx::Point lower_right(1919, 1199); | 432 EXPECT_EQ(gfx::Point(292, 555), |
| 436 EXPECT_EQ(origin, ScreenWin::ClientToDIPPoint(hwnd, origin)); | 433 ScreenWin::ClientToDIPPoint(hwnd, gfx::Point(365, 694))); |
| 437 EXPECT_EQ(middle, ScreenWin::ClientToDIPPoint(hwnd, middle)); | 434 EXPECT_EQ(gfx::Point(1535, 959), |
| 438 EXPECT_EQ(lower_right, ScreenWin::ClientToDIPPoint(hwnd, lower_right)); | 435 ScreenWin::ClientToDIPPoint(hwnd, gfx::Point(1919, 1199))); |
| 439 } | 436 } |
| 440 | 437 |
| 441 TEST_F(ScreenWinTestSingleDisplay1_25x, DIPToClientPoints) { | 438 TEST_F(ScreenWinTestSingleDisplay1_25x, DIPToClientPoints) { |
| 442 HWND hwnd = GetFakeHwnd(); | 439 HWND hwnd = GetFakeHwnd(); |
| 443 gfx::Point origin(0, 0); | 440 EXPECT_EQ(gfx::Point(0, 0), |
| 444 gfx::Point middle(365, 694); | 441 ScreenWin::DIPToClientPoint(hwnd, gfx::Point(0, 0))); |
| 445 gfx::Point lower_right(1919, 1199); | 442 EXPECT_EQ(gfx::Point(303, 577), |
| 446 EXPECT_EQ(origin, ScreenWin::DIPToClientPoint(hwnd, origin)); | 443 ScreenWin::DIPToClientPoint(hwnd, gfx::Point(243, 462))); |
| 447 EXPECT_EQ(middle, ScreenWin::DIPToClientPoint(hwnd, middle)); | 444 EXPECT_EQ(gfx::Point(1598, 998), |
| 448 EXPECT_EQ(lower_right, ScreenWin::DIPToClientPoint(hwnd, lower_right)); | 445 ScreenWin::DIPToClientPoint(hwnd, gfx::Point(1279, 799))); |
| 449 } | 446 } |
| 450 | 447 |
| 451 TEST_F(ScreenWinTestSingleDisplay1_25x, ScreenToDIPRects) { | 448 TEST_F(ScreenWinTestSingleDisplay1_25x, ScreenToDIPRects) { |
| 452 HWND hwnd = GetFakeHwnd(); | 449 HWND hwnd = GetFakeHwnd(); |
| 453 gfx::Rect origin(0, 0, 50, 100); | 450 EXPECT_EQ(gfx::Rect(0, 0, 40, 80), |
| 454 gfx::Rect middle(253, 495, 41, 52); | 451 ScreenWin::ScreenToDIPRect(hwnd, gfx::Rect(0, 0, 50, 100))); |
| 455 EXPECT_EQ(origin, ScreenWin::ScreenToDIPRect(hwnd, origin)); | 452 EXPECT_EQ(gfx::Rect(202, 396, 34, 43), |
| 456 EXPECT_EQ(middle, ScreenWin::ScreenToDIPRect(hwnd, middle)); | 453 ScreenWin::ScreenToDIPRect(hwnd, gfx::Rect(253, 496, 41, 52))); |
| 457 } | 454 } |
| 458 | 455 |
| 459 TEST_F(ScreenWinTestSingleDisplay1_25x, DIPToScreenRects) { | 456 TEST_F(ScreenWinTestSingleDisplay1_25x, DIPToScreenRects) { |
| 460 HWND hwnd = GetFakeHwnd(); | 457 HWND hwnd = GetFakeHwnd(); |
| 461 gfx::Rect origin(0, 0, 50, 100); | 458 EXPECT_EQ(gfx::Rect(0, 0, 43, 84), |
| 462 gfx::Rect middle(253, 495, 41, 52); | 459 ScreenWin::DIPToScreenRect(hwnd, gfx::Rect(0, 0, 34, 67))); |
| 463 EXPECT_EQ(origin, ScreenWin::DIPToScreenRect(hwnd, origin)); | 460 EXPECT_EQ(gfx::Rect(210, 412, 35, 46), |
| 464 EXPECT_EQ(middle, ScreenWin::DIPToScreenRect(hwnd, middle)); | 461 ScreenWin::DIPToScreenRect(hwnd, gfx::Rect(168, 330, 28, 36))); |
| 465 } | 462 } |
| 466 | 463 |
| 467 TEST_F(ScreenWinTestSingleDisplay1_25x, ClientToDIPRects) { | 464 TEST_F(ScreenWinTestSingleDisplay1_25x, ClientToDIPRects) { |
| 468 HWND hwnd = GetFakeHwnd(); | 465 HWND hwnd = GetFakeHwnd(); |
| 469 gfx::Rect origin(0, 0, 50, 100); | 466 EXPECT_EQ(gfx::Rect(0, 0, 40, 80), |
| 470 gfx::Rect middle(253, 495, 41, 52); | 467 ScreenWin::ClientToDIPRect(hwnd, gfx::Rect(0, 0, 50, 100))); |
| 471 EXPECT_EQ(origin, ScreenWin::ClientToDIPRect(hwnd, origin)); | 468 EXPECT_EQ(gfx::Rect(202, 396, 34, 43), |
| 472 EXPECT_EQ(middle, ScreenWin::ClientToDIPRect(hwnd, middle)); | 469 ScreenWin::ClientToDIPRect(hwnd, gfx::Rect(253, 496, 41, 52))); |
| 473 } | 470 } |
| 474 | 471 |
| 475 TEST_F(ScreenWinTestSingleDisplay1_25x, DIPToClientRects) { | 472 TEST_F(ScreenWinTestSingleDisplay1_25x, DIPToClientRects) { |
| 476 HWND hwnd = GetFakeHwnd(); | 473 HWND hwnd = GetFakeHwnd(); |
| 477 gfx::Rect origin(0, 0, 50, 100); | 474 EXPECT_EQ(gfx::Rect(0, 0, 43, 84), |
| 478 gfx::Rect middle(253, 495, 41, 52); | 475 ScreenWin::DIPToClientRect(hwnd, gfx::Rect(0, 0, 34, 67))); |
| 479 EXPECT_EQ(origin, ScreenWin::DIPToClientRect(hwnd, origin)); | 476 EXPECT_EQ(gfx::Rect(210, 412, 35, 46), |
| 480 EXPECT_EQ(middle, ScreenWin::DIPToClientRect(hwnd, middle)); | 477 ScreenWin::DIPToClientRect(hwnd, gfx::Rect(168, 330, 28, 36))); |
| 481 } | 478 } |
| 482 | 479 |
| 483 TEST_F(ScreenWinTestSingleDisplay1_25x, ScreenToDIPSize) { | 480 TEST_F(ScreenWinTestSingleDisplay1_25x, ScreenToDIPSize) { |
| 484 HWND hwnd = GetFakeHwnd(); | 481 EXPECT_EQ(gfx::Size(34, 105), |
| 485 gfx::Size size(42, 131); | 482 ScreenWin::ScreenToDIPSize(GetFakeHwnd(), gfx::Size(42, 131))); |
| 486 EXPECT_EQ(size, ScreenWin::ScreenToDIPSize(hwnd, size)); | |
| 487 } | 483 } |
| 488 | 484 |
| 489 TEST_F(ScreenWinTestSingleDisplay1_25x, DIPToScreenSize) { | 485 TEST_F(ScreenWinTestSingleDisplay1_25x, DIPToScreenSize) { |
| 490 HWND hwnd = GetFakeHwnd(); | 486 EXPECT_EQ(gfx::Size(35, 110), |
| 491 gfx::Size size(42, 131); | 487 ScreenWin::DIPToScreenSize(GetFakeHwnd(), gfx::Size(28, 88))); |
| 492 EXPECT_EQ(size, ScreenWin::DIPToScreenSize(hwnd, size)); | |
| 493 } | 488 } |
| 494 | 489 |
| 495 TEST_F(ScreenWinTestSingleDisplay1_25x, GetSystemMetricsForHwnd) { | 490 TEST_F(ScreenWinTestSingleDisplay1_25x, GetSystemMetricsForHwnd) { |
| 496 HWND hwnd = GetFakeHwnd(); | 491 HWND hwnd = GetFakeHwnd(); |
| 497 EXPECT_EQ(31, ScreenWin::GetSystemMetricsForHwnd(hwnd, 31)); | 492 EXPECT_EQ(31, ScreenWin::GetSystemMetricsForHwnd(hwnd, 31)); |
| 498 EXPECT_EQ(42, ScreenWin::GetSystemMetricsForHwnd(hwnd, 42)); | 493 EXPECT_EQ(42, ScreenWin::GetSystemMetricsForHwnd(hwnd, 42)); |
| 499 EXPECT_EQ(31, ScreenWin::GetSystemMetricsForHwnd(nullptr, 31)); | 494 EXPECT_EQ(31, ScreenWin::GetSystemMetricsForHwnd(nullptr, 31)); |
| 500 EXPECT_EQ(42, ScreenWin::GetSystemMetricsForHwnd(nullptr, 42)); | 495 EXPECT_EQ(42, ScreenWin::GetSystemMetricsForHwnd(nullptr, 42)); |
| 501 } | 496 } |
| 502 | 497 |
| 503 TEST_F(ScreenWinTestSingleDisplay1_25x, GetDisplays) { | 498 TEST_F(ScreenWinTestSingleDisplay1_25x, GetDisplays) { |
| 504 std::vector<Display> displays = GetScreen()->GetAllDisplays(); | 499 std::vector<Display> displays = GetScreen()->GetAllDisplays(); |
| 505 ASSERT_EQ(1u, displays.size()); | 500 ASSERT_EQ(1u, displays.size()); |
| 506 // On Windows, scale factors of 1.25 or lower are clamped to 1.0. | 501 EXPECT_EQ(gfx::Rect(0, 0, 1536, 960), displays[0].bounds()); |
| 507 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1200), displays[0].bounds()); | 502 EXPECT_EQ(gfx::Rect(0, 0, 1536, 880), displays[0].work_area()); |
| 508 EXPECT_EQ(gfx::Rect(0, 0, 1920, 1100), displays[0].work_area()); | |
| 509 } | 503 } |
| 510 | 504 |
| 511 TEST_F(ScreenWinTestSingleDisplay1_25x, GetDisplayNearestWindow) { | 505 TEST_F(ScreenWinTestSingleDisplay1_25x, GetDisplayNearestWindow) { |
| 512 Screen* screen = GetScreen(); | 506 Screen* screen = GetScreen(); |
| 513 gfx::NativeWindow native_window = GetNativeWindowFromHWND(GetFakeHwnd()); | 507 gfx::NativeWindow native_window = GetNativeWindowFromHWND(GetFakeHwnd()); |
| 514 EXPECT_EQ(screen->GetAllDisplays()[0], | 508 EXPECT_EQ(screen->GetAllDisplays()[0], |
| 515 screen->GetDisplayNearestWindow(native_window)); | 509 screen->GetDisplayNearestWindow(native_window)); |
| 516 } | 510 } |
| 517 | 511 |
| 518 TEST_F(ScreenWinTestSingleDisplay1_25x, GetDisplayNearestPoint) { | 512 TEST_F(ScreenWinTestSingleDisplay1_25x, GetDisplayNearestPoint) { |
| 519 Screen* screen = GetScreen(); | 513 Screen* screen = GetScreen(); |
| 520 Display display = screen->GetAllDisplays()[0]; | 514 Display display = screen->GetAllDisplays()[0]; |
| 521 EXPECT_EQ(display, screen->GetDisplayNearestPoint(gfx::Point(0, 0))); | 515 EXPECT_EQ(display, screen->GetDisplayNearestPoint(gfx::Point(0, 0))); |
| 522 EXPECT_EQ(display, screen->GetDisplayNearestPoint(gfx::Point(250, 952))); | 516 EXPECT_EQ(display, screen->GetDisplayNearestPoint(gfx::Point(250, 952))); |
| 523 EXPECT_EQ(display, screen->GetDisplayNearestPoint(gfx::Point(1919, 1199))); | 517 EXPECT_EQ(display, screen->GetDisplayNearestPoint(gfx::Point(1535, 959))); |
| 524 } | 518 } |
| 525 | 519 |
| 526 TEST_F(ScreenWinTestSingleDisplay1_25x, GetDisplayMatching) { | 520 TEST_F(ScreenWinTestSingleDisplay1_25x, GetDisplayMatching) { |
| 527 Screen* screen = GetScreen(); | 521 Screen* screen = GetScreen(); |
| 528 Display display = screen->GetAllDisplays()[0]; | 522 Display display = screen->GetAllDisplays()[0]; |
| 529 EXPECT_EQ(display, screen->GetDisplayMatching(gfx::Rect(0, 0, 100, 100))); | 523 EXPECT_EQ(display, screen->GetDisplayMatching(gfx::Rect(0, 0, 100, 100))); |
| 530 EXPECT_EQ(display, | 524 EXPECT_EQ(display, |
| 531 screen->GetDisplayMatching(gfx::Rect(1819, 1099, 100, 100))); | 525 screen->GetDisplayMatching(gfx::Rect(1819, 1099, 100, 100))); |
| 532 } | 526 } |
| 533 TEST_F(ScreenWinTestSingleDisplay1_25x, GetPrimaryDisplay) { | 527 TEST_F(ScreenWinTestSingleDisplay1_25x, GetPrimaryDisplay) { |
| 534 Screen* screen = GetScreen(); | 528 Screen* screen = GetScreen(); |
| 535 EXPECT_EQ(gfx::Point(0, 0), screen->GetPrimaryDisplay().bounds().origin()); | 529 EXPECT_EQ(gfx::Point(0, 0), screen->GetPrimaryDisplay().bounds().origin()); |
| 536 } | 530 } |
| 537 | 531 |
| 538 namespace { | 532 namespace { |
| 539 | 533 |
| 540 // Single Display of 1.25 Device Scale Factor. | 534 // Single Display of 1.5 Device Scale Factor. |
| 541 class ScreenWinTestSingleDisplay1_5x : public ScreenWinTest { | 535 class ScreenWinTestSingleDisplay1_5x : public ScreenWinTest { |
| 542 public: | 536 public: |
| 543 ScreenWinTestSingleDisplay1_5x() = default; | 537 ScreenWinTestSingleDisplay1_5x() = default; |
| 544 | 538 |
| 545 void SetUpScreen(TestScreenWinInitializer* initializer) override { | 539 void SetUpScreen(TestScreenWinInitializer* initializer) override { |
| 546 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200), | 540 initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200), |
| 547 gfx::Rect(0, 0, 1920, 1100), | 541 gfx::Rect(0, 0, 1920, 1100), |
| 548 L"primary", | 542 L"primary", |
| 549 1.5); | 543 1.5); |
| 550 fake_hwnd_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100)); | 544 fake_hwnd_ = initializer->CreateFakeHwnd(gfx::Rect(0, 0, 1920, 1100)); |
| (...skipping 2866 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3417 } | 3411 } |
| 3418 | 3412 |
| 3419 TEST_F(ScreenWinUninitializedForced2x, GetSystemMetricsForHwnd) { | 3413 TEST_F(ScreenWinUninitializedForced2x, GetSystemMetricsForHwnd) { |
| 3420 // GetSystemMetricsForHwnd falls back to the system's GetSystemMetrics, so | 3414 // GetSystemMetricsForHwnd falls back to the system's GetSystemMetrics, so |
| 3421 // this test is to make sure we don't crash. | 3415 // this test is to make sure we don't crash. |
| 3422 ScreenWin::GetSystemMetricsForHwnd(nullptr, SM_CXSIZEFRAME); | 3416 ScreenWin::GetSystemMetricsForHwnd(nullptr, SM_CXSIZEFRAME); |
| 3423 } | 3417 } |
| 3424 | 3418 |
| 3425 } // namespace win | 3419 } // namespace win |
| 3426 } // namespace display | 3420 } // namespace display |
| OLD | NEW |