test_screen.cc revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
1// Copyright (c) 2012 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "ui/aura/test/test_screen.h" 6 7#include "base/logging.h" 8#include "ui/aura/env.h" 9#include "ui/aura/root_window.h" 10#include "ui/aura/root_window_host.h" 11#include "ui/aura/window.h" 12#include "ui/gfx/native_widget_types.h" 13#include "ui/gfx/rect_conversions.h" 14#include "ui/gfx/screen.h" 15 16namespace aura { 17 18// static 19TestScreen* TestScreen::Create() { 20 // Use (0,0) because the desktop aura tests are executed in 21 // native environment where the display's origin is (0,0). 22 return new TestScreen(gfx::Rect(0, 0, 800, 600)); 23} 24 25// static 26TestScreen* TestScreen::CreateFullscreen() { 27 return new TestScreen(gfx::Rect(RootWindowHost::GetNativeScreenSize())); 28} 29 30TestScreen::~TestScreen() { 31} 32 33RootWindow* TestScreen::CreateRootWindowForPrimaryDisplay() { 34 DCHECK(!root_window_); 35 root_window_ = new RootWindow(RootWindow::CreateParams(display_.bounds())); 36 root_window_->AddObserver(this); 37 root_window_->Init(); 38 return root_window_; 39} 40 41void TestScreen::SetDeviceScaleFactor(float device_scale_factor) { 42 gfx::Rect bounds = display_.bounds(); 43 gfx::Rect bounds_in_pixel = gfx::ToNearestRect( 44 gfx::ScaleRect(bounds, display_.device_scale_factor())); 45 display_.SetScaleAndBounds(device_scale_factor, bounds_in_pixel); 46 root_window_->OnHostResized(bounds_in_pixel.size()); 47} 48 49bool TestScreen::IsDIPEnabled() { 50 return true; 51} 52 53void TestScreen::OnWindowBoundsChanged( 54 Window* window, const gfx::Rect& old_bounds, const gfx::Rect& new_bounds) { 55 DCHECK_EQ(root_window_, window); 56 display_.SetSize(new_bounds.size()); 57} 58 59void TestScreen::OnWindowDestroying(Window* window) { 60 if (root_window_ == window) 61 root_window_ = NULL; 62} 63 64gfx::Point TestScreen::GetCursorScreenPoint() { 65 return Env::GetInstance()->last_mouse_location(); 66} 67 68gfx::NativeWindow TestScreen::GetWindowAtCursorScreenPoint() { 69 const gfx::Point point = GetCursorScreenPoint(); 70 return root_window_->GetTopWindowContainingPoint(point); 71} 72 73int TestScreen::GetNumDisplays() { 74 return 1; 75} 76 77gfx::Display TestScreen::GetDisplayNearestWindow( 78 gfx::NativeWindow window) const { 79 return display_; 80} 81 82gfx::Display TestScreen::GetDisplayNearestPoint(const gfx::Point& point) const { 83 return display_; 84} 85 86gfx::Display TestScreen::GetDisplayMatching(const gfx::Rect& match_rect) const { 87 return display_; 88} 89 90gfx::Display TestScreen::GetPrimaryDisplay() const { 91 return display_; 92} 93 94void TestScreen::AddObserver(gfx::DisplayObserver* observer) { 95} 96 97void TestScreen::RemoveObserver(gfx::DisplayObserver* observer) { 98} 99 100TestScreen::TestScreen(const gfx::Rect& screen_bounds) : root_window_(NULL) { 101 static int64 synthesized_display_id = 2000; 102 display_.set_id(synthesized_display_id++); 103 display_.SetScaleAndBounds(1.0f, screen_bounds); 104} 105 106} // namespace aura 107