test_screen.h revision 6d86b77056ed63eb6871182f42a9fd5f07550f90
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#ifndef UI_AURA_TEST_TEST_SCREEN_H_ 6#define UI_AURA_TEST_TEST_SCREEN_H_ 7 8#include "base/compiler_specific.h" 9#include "ui/aura/window_observer.h" 10#include "ui/gfx/display.h" 11#include "ui/gfx/screen.h" 12 13namespace gfx { 14class Rect; 15class Transform; 16} 17 18namespace aura { 19class Window; 20class WindowTreeHost; 21 22// A minimal, testing Aura implementation of gfx::Screen. 23class TestScreen : public gfx::Screen, 24 public WindowObserver { 25 public: 26 // Creates a gfx::Screen of the specified size. If no size is specified, then 27 // creates a 800x600 screen. |size| is in physical pixels. 28 static TestScreen* Create(const gfx::Size& size); 29 // Creates a TestScreen that uses fullscreen for the display. 30 static TestScreen* CreateFullscreen(); 31 virtual ~TestScreen(); 32 33 WindowTreeHost* CreateHostForPrimaryDisplay(); 34 35 void SetDeviceScaleFactor(float device_scale_fator); 36 void SetDisplayRotation(gfx::Display::Rotation rotation); 37 void SetUIScale(float ui_scale); 38 39 protected: 40 gfx::Transform GetRotationTransform() const; 41 gfx::Transform GetUIScaleTransform() const; 42 43 // WindowObserver overrides: 44 virtual void OnWindowBoundsChanged(Window* window, 45 const gfx::Rect& old_bounds, 46 const gfx::Rect& new_bounds) OVERRIDE; 47 virtual void OnWindowDestroying(Window* window) OVERRIDE; 48 49 // gfx::Screen overrides: 50 virtual bool IsDIPEnabled() OVERRIDE; 51 virtual gfx::Point GetCursorScreenPoint() OVERRIDE; 52 virtual gfx::NativeWindow GetWindowUnderCursor() OVERRIDE; 53 virtual gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) 54 OVERRIDE; 55 virtual int GetNumDisplays() const OVERRIDE; 56 virtual std::vector<gfx::Display> GetAllDisplays() const OVERRIDE; 57 virtual gfx::Display GetDisplayNearestWindow( 58 gfx::NativeView view) const OVERRIDE; 59 virtual gfx::Display GetDisplayNearestPoint( 60 const gfx::Point& point) const OVERRIDE; 61 virtual gfx::Display GetDisplayMatching( 62 const gfx::Rect& match_rect) const OVERRIDE; 63 virtual gfx::Display GetPrimaryDisplay() const OVERRIDE; 64 virtual void AddObserver(gfx::DisplayObserver* observer) OVERRIDE; 65 virtual void RemoveObserver(gfx::DisplayObserver* observer) OVERRIDE; 66 67 private: 68 explicit TestScreen(const gfx::Rect& screen_bounds); 69 70 aura::WindowTreeHost* host_; 71 72 gfx::Display display_; 73 74 float ui_scale_; 75 76 DISALLOW_COPY_AND_ASSIGN(TestScreen); 77}; 78 79} // namespace aura 80 81#endif // UI_AURA_TEST_TEST_SCREEN_H_ 82