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