Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(612)

Side by Side Diff: ash/display/multi_display_manager.h

Issue 10905288: Switch primary display (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
49 // When set to ture, the MultiMonitorManager calls OnDisplayBoundsChanged
sky 2012/09/18 03:52:47 true
50 // even if the display's bounds didn't change. Used to swap primary
51 // display.
52 void set_force_bounds_changed(bool force_bounds_changed) {
53 force_bounds_changed_ = force_bounds_changed;
54 }
55
48 // Detects the internal display's ID, and stores gfx::Display 56 // Detects the internal display's ID, and stores gfx::Display
49 // in the cache, if any. 57 // in the cache, if any.
50 void InitInternalDisplayInfo(); 58 void InitInternalDisplayInfo();
51 59
60 // True if the given |display| is currently connected.
61 bool IsActiveDisplay(const gfx::Display& display) const;
62
52 // True if there is an internal display. 63 // True if there is an internal display.
53 bool HasInternalDisplay() const; 64 bool HasInternalDisplay() const;
54 65
55 bool UpdateWorkAreaOfDisplayNearestWindow(const aura::Window* window, 66 bool UpdateWorkAreaOfDisplayNearestWindow(const aura::Window* window,
56 const gfx::Insets& insets); 67 const gfx::Insets& insets);
57 68
58 // Finds the display that contains |point| in screeen coordinates. 69 // Finds the display that contains |point| in screeen coordinates.
59 // Returns invalid display if there is no display that can satisfy 70 // Returns invalid display if there is no display that can satisfy
60 // the condition. 71 // the condition.
61 const gfx::Display& FindDisplayContainingPoint( 72 const gfx::Display& FindDisplayContainingPoint(
62 const gfx::Point& point_in_screen) const; 73 const gfx::Point& point_in_screen) const;
63 74
64 // DisplayManager overrides: 75 // DisplayManager overrides:
65 virtual void OnNativeDisplaysChanged( 76 virtual void OnNativeDisplaysChanged(
66 const std::vector<gfx::Display>& displays) OVERRIDE; 77 const std::vector<gfx::Display>& displays) OVERRIDE;
67 virtual aura::RootWindow* CreateRootWindowForDisplay( 78 virtual aura::RootWindow* CreateRootWindowForDisplay(
68 const gfx::Display& display) OVERRIDE; 79 const gfx::Display& display) OVERRIDE;
69 virtual gfx::Display* GetDisplayAt(size_t index) OVERRIDE; 80 virtual gfx::Display* GetDisplayAt(size_t index) OVERRIDE;
70 81
71 virtual size_t GetNumDisplays() const OVERRIDE; 82 virtual size_t GetNumDisplays() const OVERRIDE;
72 virtual const gfx::Display& GetDisplayNearestPoint( 83 virtual const gfx::Display& GetDisplayNearestPoint(
73 const gfx::Point& point) const OVERRIDE; 84 const gfx::Point& point) const OVERRIDE;
74 virtual const gfx::Display& GetDisplayNearestWindow( 85 virtual const gfx::Display& GetDisplayNearestWindow(
75 const aura::Window* window) const OVERRIDE; 86 const aura::Window* window) const OVERRIDE;
76 virtual const gfx::Display& GetDisplayMatching( 87 virtual const gfx::Display& GetDisplayMatching(
77 const gfx::Rect& match_rect)const OVERRIDE; 88 const gfx::Rect& match_rect)const OVERRIDE;
78 virtual std::string GetDisplayNameAt(size_t index) OVERRIDE; 89 virtual std::string GetDisplayNameFor(const gfx::Display& display) OVERRIDE;
79 90
80 // RootWindowObserver overrides: 91 // RootWindowObserver overrides:
81 virtual void OnRootWindowResized(const aura::RootWindow* root, 92 virtual void OnRootWindowResized(const aura::RootWindow* root,
82 const gfx::Size& new_size) OVERRIDE; 93 const gfx::Size& new_size) OVERRIDE;
83 94
84 private: 95 private:
85 FRIEND_TEST_ALL_PREFIXES(ExtendedDesktopTest, ConvertPoint); 96 FRIEND_TEST_ALL_PREFIXES(ExtendedDesktopTest, ConvertPoint);
86 FRIEND_TEST_ALL_PREFIXES(MultiDisplayManagerTest, TestNativeDisplaysChanged); 97 FRIEND_TEST_ALL_PREFIXES(MultiDisplayManagerTest, TestNativeDisplaysChanged);
87 friend class test::AcceleratorControllerTest; 98 friend class test::AcceleratorControllerTest;
99 friend class test::AshTestBase;
100 friend class MultiDisplayManagerTest;
88 friend class test::SystemGestureEventFilterTest; 101 friend class test::SystemGestureEventFilterTest;
89 102
90 typedef std::vector<gfx::Display> Displays; 103 typedef std::vector<gfx::Display> DisplayList;
91 104
92 void Init(); 105 void Init();
93 void CycleDisplayImpl(); 106 void CycleDisplayImpl();
94 void ScaleDisplayImpl(); 107 void ScaleDisplayImpl();
108
95 gfx::Display& FindDisplayForRootWindow(const aura::RootWindow* root); 109 gfx::Display& FindDisplayForRootWindow(const aura::RootWindow* root);
110 gfx::Display& FindDisplayForId(int64 id);
96 111
97 // Refer to |aura::DisplayManager::CreateDisplayFromSpec| API for 112 // Refer to |aura::DisplayManager::CreateDisplayFromSpec| API for
98 // the format of |spec|. 113 // the format of |spec|.
99 void AddDisplayFromSpec(const std::string& spec); 114 void AddDisplayFromSpec(const std::string& spec);
100 115
101 // Enables internal display and returns the display Id for the internal 116 // Set the 1st display as an internal display and returns the display Id for
102 // display. 117 // the internal display.
103 int64 EnableInternalDisplayForTest(); 118 int64 SetFirstDisplayAsInternalDisplayForTest();
104 119
105 Displays displays_; 120 // Update the display's id in the |display_list| to match the ones
121 // stored in this display manager's |displays_|. This is used to
122 // emulate display change behavior during the test byn creating the
123 // display list with the same display ids but with different bounds
124 void SetDisplayIdsForTest(DisplayList* display_list) const;
125
126 DisplayList displays_;
106 127
107 int64 internal_display_id_; 128 int64 internal_display_id_;
108 129
109 // An internal display cache used when the internal display is disconnectd. 130 // An internal display cache used when the internal display is disconnectd.
110 scoped_ptr<gfx::Display> internal_display_; 131 scoped_ptr<gfx::Display> internal_display_;
111 132
133 bool force_bounds_changed_;
134
112 DISALLOW_COPY_AND_ASSIGN(MultiDisplayManager); 135 DISALLOW_COPY_AND_ASSIGN(MultiDisplayManager);
113 }; 136 };
114 137
115 extern const aura::WindowProperty<int64>* const kDisplayIdKey; 138 extern const aura::WindowProperty<int64>* const kDisplayIdKey;
116 139
117 } // namespace internal 140 } // namespace internal
118 } // namespace ash 141 } // namespace ash
119 142
120 #endif // ASH_DISPLAY_MULTI_DISPLAY_MANAGER_H_ 143 #endif // ASH_DISPLAY_MULTI_DISPLAY_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698