| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef ASH_DISPLAY_MULTI_DISPLAY_MANAGER_H_ | 5 #ifndef ASH_DISPLAY_MULTI_DISPLAY_MANAGER_H_ |
| 6 #define ASH_DISPLAY_MULTI_DISPLAY_MANAGER_H_ | 6 #define ASH_DISPLAY_MULTI_DISPLAY_MANAGER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "ash/ash_export.h" | 11 #include "ash/ash_export.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
| 14 #include "ui/aura/display_manager.h" | 14 #include "ui/aura/display_manager.h" |
| 15 #include "ui/aura/root_window_observer.h" | 15 #include "ui/aura/root_window_observer.h" |
| 16 #include "ui/aura/window.h" | 16 #include "ui/aura/window.h" |
| 17 | 17 |
| 18 namespace gfx { | 18 namespace gfx { |
| 19 class Display; | 19 class Display; |
| 20 class Insets; | 20 class Insets; |
| 21 class Rect; | 21 class Rect; |
| 22 } | 22 } |
| 23 | 23 |
| 24 namespace ash { | 24 namespace ash { |
| 25 namespace test { | 25 namespace test { |
| 26 class AcceleratorControllerTest; | 26 class AcceleratorControllerTest; |
| 27 class AshTestBase; |
| 27 class SystemGestureEventFilterTest; | 28 class SystemGestureEventFilterTest; |
| 28 } | 29 } |
| 29 namespace internal { | 30 namespace internal { |
| 30 | 31 |
| 31 // MultiDisplayManager maintains the current display configurations, | 32 // MultiDisplayManager maintains the current display configurations, |
| 32 // and notifies observers when configuration changes. | 33 // and notifies observers when configuration changes. |
| 33 // This is exported for unittest. | 34 // This is exported for unittest. |
| 34 // | 35 // |
| 35 // TODO(oshima): gfx::Screen needs to return translated coordinates | 36 // TODO(oshima): gfx::Screen needs to return translated coordinates |
| 36 // if the root window is translated. crbug.com/119268. | 37 // if the root window is translated. crbug.com/119268. |
| 37 class ASH_EXPORT MultiDisplayManager : public aura::DisplayManager, | 38 class ASH_EXPORT MultiDisplayManager : public aura::DisplayManager, |
| 38 public aura::RootWindowObserver { | 39 public aura::RootWindowObserver { |
| 39 public: | 40 public: |
| 40 MultiDisplayManager(); | 41 MultiDisplayManager(); |
| 41 virtual ~MultiDisplayManager(); | 42 virtual ~MultiDisplayManager(); |
| 42 | 43 |
| 43 // Used to emulate display change when run in a desktop environment instead | 44 // Used to emulate display change when run in a desktop environment instead |
| 44 // of on a device. | 45 // of on a device. |
| 45 static void CycleDisplay(); | 46 static void CycleDisplay(); |
| 46 static void ToggleDisplayScale(); | 47 static void ToggleDisplayScale(); |
| 47 | 48 |
| 48 // Detects the internal display's ID, and stores gfx::Display | 49 // When set to true, the MultiMonitorManager calls OnDisplayBoundsChanged |
| 49 // in the cache, if any. | 50 // even if the display's bounds didn't change. Used to swap primary |
| 50 void InitInternalDisplayInfo(); | 51 // display. |
| 52 void set_force_bounds_changed(bool force_bounds_changed) { |
| 53 force_bounds_changed_ = force_bounds_changed; |
| 54 } |
| 55 |
| 56 // True if the given |display| is currently connected. |
| 57 bool IsActiveDisplay(const gfx::Display& display) const; |
| 51 | 58 |
| 52 // True if there is an internal display. | 59 // True if there is an internal display. |
| 53 bool HasInternalDisplay() const; | 60 bool HasInternalDisplay() const; |
| 54 | 61 |
| 62 bool IsInternalDisplayId(int64 id) const; |
| 63 |
| 55 bool UpdateWorkAreaOfDisplayNearestWindow(const aura::Window* window, | 64 bool UpdateWorkAreaOfDisplayNearestWindow(const aura::Window* window, |
| 56 const gfx::Insets& insets); | 65 const gfx::Insets& insets); |
| 57 | 66 |
| 58 // Finds the display that contains |point| in screeen coordinates. | 67 // Finds the display that contains |point| in screeen coordinates. |
| 59 // Returns invalid display if there is no display that can satisfy | 68 // Returns invalid display if there is no display that can satisfy |
| 60 // the condition. | 69 // the condition. |
| 61 const gfx::Display& FindDisplayContainingPoint( | 70 const gfx::Display& FindDisplayContainingPoint( |
| 62 const gfx::Point& point_in_screen) const; | 71 const gfx::Point& point_in_screen) const; |
| 63 | 72 |
| 64 // DisplayManager overrides: | 73 // DisplayManager overrides: |
| 65 virtual void OnNativeDisplaysChanged( | 74 virtual void OnNativeDisplaysChanged( |
| 66 const std::vector<gfx::Display>& displays) OVERRIDE; | 75 const std::vector<gfx::Display>& displays) OVERRIDE; |
| 67 virtual aura::RootWindow* CreateRootWindowForDisplay( | 76 virtual aura::RootWindow* CreateRootWindowForDisplay( |
| 68 const gfx::Display& display) OVERRIDE; | 77 const gfx::Display& display) OVERRIDE; |
| 69 virtual gfx::Display* GetDisplayAt(size_t index) OVERRIDE; | 78 virtual gfx::Display* GetDisplayAt(size_t index) OVERRIDE; |
| 70 | 79 |
| 71 virtual size_t GetNumDisplays() const OVERRIDE; | 80 virtual size_t GetNumDisplays() const OVERRIDE; |
| 72 virtual const gfx::Display& GetDisplayNearestPoint( | 81 virtual const gfx::Display& GetDisplayNearestPoint( |
| 73 const gfx::Point& point) const OVERRIDE; | 82 const gfx::Point& point) const OVERRIDE; |
| 74 virtual const gfx::Display& GetDisplayNearestWindow( | 83 virtual const gfx::Display& GetDisplayNearestWindow( |
| 75 const aura::Window* window) const OVERRIDE; | 84 const aura::Window* window) const OVERRIDE; |
| 76 virtual const gfx::Display& GetDisplayMatching( | 85 virtual const gfx::Display& GetDisplayMatching( |
| 77 const gfx::Rect& match_rect)const OVERRIDE; | 86 const gfx::Rect& match_rect)const OVERRIDE; |
| 78 virtual std::string GetDisplayNameAt(size_t index) OVERRIDE; | 87 virtual std::string GetDisplayNameFor(const gfx::Display& display) OVERRIDE; |
| 79 | 88 |
| 80 // RootWindowObserver overrides: | 89 // RootWindowObserver overrides: |
| 81 virtual void OnRootWindowResized(const aura::RootWindow* root, | 90 virtual void OnRootWindowResized(const aura::RootWindow* root, |
| 82 const gfx::Size& new_size) OVERRIDE; | 91 const gfx::Size& new_size) OVERRIDE; |
| 83 | 92 |
| 84 private: | 93 private: |
| 85 FRIEND_TEST_ALL_PREFIXES(ExtendedDesktopTest, ConvertPoint); | 94 FRIEND_TEST_ALL_PREFIXES(ExtendedDesktopTest, ConvertPoint); |
| 86 FRIEND_TEST_ALL_PREFIXES(MultiDisplayManagerTest, TestNativeDisplaysChanged); | 95 FRIEND_TEST_ALL_PREFIXES(MultiDisplayManagerTest, TestNativeDisplaysChanged); |
| 87 friend class test::AcceleratorControllerTest; | 96 friend class test::AcceleratorControllerTest; |
| 97 friend class test::AshTestBase; |
| 98 friend class MultiDisplayManagerTest; |
| 88 friend class test::SystemGestureEventFilterTest; | 99 friend class test::SystemGestureEventFilterTest; |
| 89 | 100 |
| 90 typedef std::vector<gfx::Display> Displays; | 101 typedef std::vector<gfx::Display> DisplayList; |
| 91 | 102 |
| 92 void Init(); | 103 void Init(); |
| 93 void CycleDisplayImpl(); | 104 void CycleDisplayImpl(); |
| 94 void ScaleDisplayImpl(); | 105 void ScaleDisplayImpl(); |
| 106 |
| 95 gfx::Display& FindDisplayForRootWindow(const aura::RootWindow* root); | 107 gfx::Display& FindDisplayForRootWindow(const aura::RootWindow* root); |
| 108 gfx::Display& FindDisplayForId(int64 id); |
| 96 | 109 |
| 97 // Refer to |aura::DisplayManager::CreateDisplayFromSpec| API for | 110 // Refer to |aura::DisplayManager::CreateDisplayFromSpec| API for |
| 98 // the format of |spec|. | 111 // the format of |spec|. |
| 99 void AddDisplayFromSpec(const std::string& spec); | 112 void AddDisplayFromSpec(const std::string& spec); |
| 100 | 113 |
| 101 // Enables internal display and returns the display Id for the internal | 114 // Set the 1st display as an internal display and returns the display Id for |
| 102 // display. | 115 // the internal display. |
| 103 int64 EnableInternalDisplayForTest(); | 116 int64 SetFirstDisplayAsInternalDisplayForTest(); |
| 104 | 117 |
| 105 Displays displays_; | 118 // Update the display's id in the |display_list| to match the ones |
| 119 // stored in this display manager's |displays_|. This is used to |
| 120 // emulate display change behavior during the test byn creating the |
| 121 // display list with the same display ids but with different bounds |
| 122 void SetDisplayIdsForTest(DisplayList* display_list) const; |
| 123 |
| 124 DisplayList displays_; |
| 106 | 125 |
| 107 int64 internal_display_id_; | 126 int64 internal_display_id_; |
| 108 | 127 |
| 109 // An internal display cache used when the internal display is disconnectd. | 128 // An internal display cache used when the internal display is disconnectd. |
| 110 scoped_ptr<gfx::Display> internal_display_; | 129 scoped_ptr<gfx::Display> internal_display_; |
| 111 | 130 |
| 131 bool force_bounds_changed_; |
| 132 |
| 112 DISALLOW_COPY_AND_ASSIGN(MultiDisplayManager); | 133 DISALLOW_COPY_AND_ASSIGN(MultiDisplayManager); |
| 113 }; | 134 }; |
| 114 | 135 |
| 115 extern const aura::WindowProperty<int64>* const kDisplayIdKey; | 136 extern const aura::WindowProperty<int64>* const kDisplayIdKey; |
| 116 | 137 |
| 117 } // namespace internal | 138 } // namespace internal |
| 118 } // namespace ash | 139 } // namespace ash |
| 119 | 140 |
| 120 #endif // ASH_DISPLAY_MULTI_DISPLAY_MANAGER_H_ | 141 #endif // ASH_DISPLAY_MULTI_DISPLAY_MANAGER_H_ |
| OLD | NEW |