| 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_DISPLAY_CONTROLLER_H_ | 5 #ifndef ASH_DISPLAY_DISPLAY_CONTROLLER_H_ |
| 6 #define ASH_DISPLAY_DISPLAY_CONTROLLER_H_ | 6 #define ASH_DISPLAY_DISPLAY_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "ash/ash_export.h" | 11 #include "ash/ash_export.h" |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "ui/aura/display_observer.h" | 14 #include "ui/aura/display_observer.h" |
| 15 #include "ui/aura/display_manager.h" | 15 #include "ui/aura/display_manager.h" |
| 16 | 16 |
| 17 namespace aura { | 17 namespace aura { |
| 18 class Display; | 18 class Display; |
| 19 class RootWindow; | 19 class RootWindow; |
| 20 } | 20 } |
| 21 | 21 |
| 22 namespace base { |
| 23 class Value; |
| 24 template <typename T> class JSONValueConverter; |
| 25 } |
| 26 |
| 22 namespace ash { | 27 namespace ash { |
| 23 namespace internal { | 28 namespace internal { |
| 24 class RootWindowController; | 29 class RootWindowController; |
| 30 } |
| 25 | 31 |
| 26 // DisplayController owns and maintains RootWindows for each attached | 32 struct ASH_EXPORT DisplayLayout { |
| 27 // display, keeping them in sync with display configuration changes. | |
| 28 class ASH_EXPORT DisplayController : public aura::DisplayObserver { | |
| 29 public: | |
| 30 // Layout options where the secondary display should be positioned. | 33 // Layout options where the secondary display should be positioned. |
| 31 enum SecondaryDisplayLayout { | 34 enum Position { |
| 32 TOP, | 35 TOP, |
| 33 RIGHT, | 36 RIGHT, |
| 34 BOTTOM, | 37 BOTTOM, |
| 35 LEFT | 38 LEFT |
| 36 }; | 39 }; |
| 37 | 40 |
| 41 DisplayLayout(); |
| 42 DisplayLayout(Position position, int offset); |
| 43 |
| 44 // Converter functions to/from base::Value. |
| 45 static bool ConvertFromValue(const base::Value& value, DisplayLayout* layout); |
| 46 static bool ConvertToValue(const DisplayLayout& layout, base::Value* value); |
| 47 |
| 48 // This method is used by base::JSONValueConverter, you don't need to call |
| 49 // this directly. Instead consider using converter functions above. |
| 50 static void RegisterJSONConverter( |
| 51 base::JSONValueConverter<DisplayLayout>* converter); |
| 52 |
| 53 Position position; |
| 54 |
| 55 // The offset of the position of the secondary display. The offset is |
| 56 // based on the top/left edge of the primary display. |
| 57 int offset; |
| 58 }; |
| 59 |
| 60 // DisplayController owns and maintains RootWindows for each attached |
| 61 // display, keeping them in sync with display configuration changes. |
| 62 class ASH_EXPORT DisplayController : public aura::DisplayObserver { |
| 63 public: |
| 38 DisplayController(); | 64 DisplayController(); |
| 39 virtual ~DisplayController(); | 65 virtual ~DisplayController(); |
| 40 | 66 |
| 41 // Initializes primary display. | 67 // Initializes primary display. |
| 42 void InitPrimaryDisplay(); | 68 void InitPrimaryDisplay(); |
| 43 | 69 |
| 44 // Initialize secondary displays. | 70 // Initialize secondary displays. |
| 45 void InitSecondaryDisplays(); | 71 void InitSecondaryDisplays(); |
| 46 | 72 |
| 47 // Returns the root window for primary display. | 73 // Returns the root window for primary display. |
| 48 aura::RootWindow* GetPrimaryRootWindow(); | 74 aura::RootWindow* GetPrimaryRootWindow(); |
| 49 | 75 |
| 50 // Returns the root window for |display_id|. | 76 // Returns the root window for |display_id|. |
| 51 aura::RootWindow* GetRootWindowForDisplayId(int64 id); | 77 aura::RootWindow* GetRootWindowForDisplayId(int64 id); |
| 52 | 78 |
| 53 // Closes all child windows in the all root windows. | 79 // Closes all child windows in the all root windows. |
| 54 void CloseChildWindows(); | 80 void CloseChildWindows(); |
| 55 | 81 |
| 56 // Returns all root windows. In non extended desktop mode, this | 82 // Returns all root windows. In non extended desktop mode, this |
| 57 // returns the primary root window only. | 83 // returns the primary root window only. |
| 58 std::vector<aura::RootWindow*> GetAllRootWindows(); | 84 std::vector<aura::RootWindow*> GetAllRootWindows(); |
| 59 | 85 |
| 60 // Returns all oot window controllers. In non extended desktop | 86 // Returns all oot window controllers. In non extended desktop |
| 61 // mode, this return a RootWindowController for the primary root window only. | 87 // mode, this return a RootWindowController for the primary root window only. |
| 62 std::vector<internal::RootWindowController*> GetAllRootWindowControllers(); | 88 std::vector<internal::RootWindowController*> GetAllRootWindowControllers(); |
| 63 | 89 |
| 64 SecondaryDisplayLayout secondary_display_layout() const { | 90 const DisplayLayout& default_display_layout() const { |
| 65 return secondary_display_layout_; | 91 return default_display_layout_; |
| 66 } | 92 } |
| 67 void SetSecondaryDisplayLayout(SecondaryDisplayLayout layout); | 93 void SetDefaultDisplayLayout(const DisplayLayout& layout); |
| 68 | 94 |
| 69 int secondary_display_offset() const { | 95 // Sets/gets the display layout for the specified display name. Getter |
| 70 return secondary_display_offset_; | 96 // returns the default value in case it doesn't have its own layout yet. |
| 71 } | 97 void SetLayoutForDisplayName(const std::string& name, |
| 72 void SetSecondaryDisplayOffset(int offset); | 98 const DisplayLayout& layout); |
| 99 const DisplayLayout& GetLayoutForDisplayName(const std::string& name); |
| 73 | 100 |
| 74 // aura::DisplayObserver overrides: | 101 // aura::DisplayObserver overrides: |
| 75 virtual void OnDisplayBoundsChanged( | 102 virtual void OnDisplayBoundsChanged( |
| 76 const gfx::Display& display) OVERRIDE; | 103 const gfx::Display& display) OVERRIDE; |
| 77 virtual void OnDisplayAdded(const gfx::Display& display) OVERRIDE; | 104 virtual void OnDisplayAdded(const gfx::Display& display) OVERRIDE; |
| 78 virtual void OnDisplayRemoved(const gfx::Display& display) OVERRIDE; | 105 virtual void OnDisplayRemoved(const gfx::Display& display) OVERRIDE; |
| 79 | 106 |
| 80 private: | 107 private: |
| 81 // Creates a root window for |display| and stores it in the |root_windows_| | 108 // Creates a root window for |display| and stores it in the |root_windows_| |
| 82 // map. | 109 // map. |
| 83 aura::RootWindow* AddRootWindowForDisplay(const gfx::Display& display); | 110 aura::RootWindow* AddRootWindowForDisplay(const gfx::Display& display); |
| 84 | 111 |
| 85 void UpdateDisplayBoundsForLayout(); | 112 void UpdateDisplayBoundsForLayout(); |
| 86 | 113 |
| 87 // The mapping from display ID to its root window. | 114 // The mapping from display ID to its root window. |
| 88 std::map<int64, aura::RootWindow*> root_windows_; | 115 std::map<int64, aura::RootWindow*> root_windows_; |
| 89 | 116 |
| 90 SecondaryDisplayLayout secondary_display_layout_; | 117 // The default display layout. |
| 118 DisplayLayout default_display_layout_; |
| 91 | 119 |
| 92 // The offset of the position of the secondary display. The offset is | 120 // Per-device display layout. |
| 93 // based on the top/left edge of the primary display. | 121 std::map<std::string, DisplayLayout> secondary_layouts_; |
| 94 int secondary_display_offset_; | |
| 95 | 122 |
| 96 DISALLOW_COPY_AND_ASSIGN(DisplayController); | 123 DISALLOW_COPY_AND_ASSIGN(DisplayController); |
| 97 }; | 124 }; |
| 98 | 125 |
| 99 } // namespace internal | |
| 100 } // namespace ash | 126 } // namespace ash |
| 101 | 127 |
| 102 #endif // ASH_DISPLAY_DISPLAY_CONTROLLER_H_ | 128 #endif // ASH_DISPLAY_DISPLAY_CONTROLLER_H_ |
| OLD | NEW |