Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
|
oshima
2016/08/26 21:55:59
IIRC, you don't have to update this when you're m
rjkroege
2016/08/30 19:11:06
Good to know. Thanks. I'll leave.
| |
| 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_UTIL_H_ | 5 #ifndef UI_DISPLAY_MANAGER_DISPLAY_MANAGER_UTILITIES_H_ |
| 6 #define ASH_DISPLAY_DISPLAY_UTIL_H_ | 6 #define UI_DISPLAY_MANAGER_DISPLAY_MANAGER_UTILITIES_H_ |
| 7 | |
| 8 #include <stdint.h> | |
| 9 | 7 |
| 10 #include <set> | 8 #include <set> |
| 11 #include <utility> | |
| 12 #include <vector> | |
| 13 | 9 |
| 14 #include "ash/ash_export.h" | 10 #include "ui/display/display.h" |
| 15 #include "base/memory/ref_counted.h" | 11 #include "ui/display/display_export.h" |
| 16 #include "ui/display/manager/display_layout.h" | 12 #include "ui/display/manager/display_layout.h" |
| 17 #include "ui/display/manager/managed_display_info.h" | 13 #include "ui/display/manager/managed_display_info.h" |
| 18 | 14 |
| 19 namespace gfx { | 15 namespace gfx { |
| 20 class Point; | 16 class Point; |
| 21 class Rect; | 17 class Rect; |
| 22 class Size; | 18 class Size; |
| 23 } | 19 } |
| 24 | 20 |
| 25 namespace ui { | 21 namespace ui { |
| 26 class ManagedDisplayInfo; | 22 class ManagedDisplayInfo; |
| 27 } | |
| 28 | |
| 29 namespace ash { | |
| 30 class AshWindowTreeHost; | |
| 31 class ManagedDisplayMode; | 23 class ManagedDisplayMode; |
| 32 | 24 |
| 33 // Creates the display mode list for internal display | 25 // Creates the display mode list for internal display |
| 34 // based on |native_mode|. | 26 // based on |native_mode|. |
| 35 ASH_EXPORT ui::ManagedDisplayInfo::ManagedDisplayModeList | 27 DISPLAY_EXPORT ui::ManagedDisplayInfo::ManagedDisplayModeList |
| 36 CreateInternalManagedDisplayModeList( | 28 CreateInternalManagedDisplayModeList( |
| 37 const scoped_refptr<ui::ManagedDisplayMode>& native_mode); | 29 const scoped_refptr<ui::ManagedDisplayMode>& native_mode); |
| 38 | 30 |
| 39 // Creates the display mode list for unified display | 31 // Creates the display mode list for unified display |
| 40 // based on |native_mode| and |scales|. | 32 // based on |native_mode| and |scales|. |
| 41 ASH_EXPORT ui::ManagedDisplayInfo::ManagedDisplayModeList | 33 DISPLAY_EXPORT ui::ManagedDisplayInfo::ManagedDisplayModeList |
| 42 CreateUnifiedManagedDisplayModeList( | 34 CreateUnifiedManagedDisplayModeList( |
| 43 const scoped_refptr<ui::ManagedDisplayMode>& native_mode, | 35 const scoped_refptr<ui::ManagedDisplayMode>& native_mode, |
| 44 const std::set<std::pair<float, float>>& dsf_scale_list); | 36 const std::set<std::pair<float, float>>& dsf_scale_list); |
| 45 | 37 |
| 46 // Gets the display mode for |resolution|. Returns false if no display | 38 // Gets the display mode for |resolution|. Returns false if no display |
| 47 // mode matches the resolution, or the display is an internal display. | 39 // mode matches the resolution, or the display is an internal display. |
| 48 ASH_EXPORT scoped_refptr<ui::ManagedDisplayMode> GetDisplayModeForResolution( | 40 DISPLAY_EXPORT scoped_refptr<ui::ManagedDisplayMode> |
| 49 const ui::ManagedDisplayInfo& info, | 41 GetDisplayModeForResolution(const ui::ManagedDisplayInfo& info, |
| 50 const gfx::Size& resolution); | 42 const gfx::Size& resolution); |
| 51 | 43 |
| 52 // Gets the display mode for the next valid UI scale. Returns false | 44 // Gets the display mode for the next valid UI scale. Returns false |
| 53 // if the display is not an internal display. | 45 // if the display is not an internal display. |
| 54 ASH_EXPORT scoped_refptr<ui::ManagedDisplayMode> GetDisplayModeForNextUIScale( | 46 DISPLAY_EXPORT scoped_refptr<ui::ManagedDisplayMode> |
| 55 const ui::ManagedDisplayInfo& info, | 47 GetDisplayModeForNextUIScale(const ui::ManagedDisplayInfo& info, bool up); |
| 56 bool up); | |
| 57 | 48 |
| 58 // Gets the display mode for the next valid resolution. Returns false | 49 // Gets the display mode for the next valid resolution. Returns false |
| 59 // if the display is an internal display. | 50 // if the display is an internal display. |
| 60 ASH_EXPORT scoped_refptr<ui::ManagedDisplayMode> | 51 DISPLAY_EXPORT scoped_refptr<ui::ManagedDisplayMode> |
| 61 GetDisplayModeForNextResolution(const ui::ManagedDisplayInfo& info, bool up); | 52 GetDisplayModeForNextResolution(const ui::ManagedDisplayInfo& info, bool up); |
| 62 | 53 |
| 63 // Sets the UI scale for the |display_id|. Returns false if the | |
| 64 // display_id is not an internal display. | |
| 65 ASH_EXPORT bool SetDisplayUIScale(int64_t display_id, float scale); | |
| 66 | |
| 67 // Tests if the |info| has display mode that matches |ui_scale|. | 54 // Tests if the |info| has display mode that matches |ui_scale|. |
| 68 bool HasDisplayModeForUIScale(const ui::ManagedDisplayInfo& info, | 55 bool HasDisplayModeForUIScale(const ui::ManagedDisplayInfo& info, |
| 69 float ui_scale); | 56 float ui_scale); |
| 70 | 57 |
| 71 // Computes the bounds that defines the bounds between two displays. | 58 // Computes the bounds that defines the bounds between two displays. |
| 72 // Returns false if two displays do not intersect. | 59 // Returns false if two displays do not intersect. |
| 73 bool ComputeBoundary(const display::Display& primary_display, | 60 DISPLAY_EXPORT bool ComputeBoundary(const display::Display& primary_display, |
| 74 const display::Display& secondary_display, | 61 const display::Display& secondary_display, |
| 75 gfx::Rect* primary_edge_in_screen, | 62 gfx::Rect* primary_edge_in_screen, |
| 76 gfx::Rect* secondary_edge_in_screen); | 63 gfx::Rect* secondary_edge_in_screen); |
| 77 | |
| 78 // Creates edge bounds from |bounds_in_screen| that fits the edge | |
| 79 // of the native window for |ash_host|. | |
| 80 ASH_EXPORT gfx::Rect GetNativeEdgeBounds(AshWindowTreeHost* ash_host, | |
| 81 const gfx::Rect& bounds_in_screen); | |
| 82 | |
| 83 // Moves the cursor to the point inside the |ash_host| that is closest to | |
| 84 // the point_in_screen, which may be outside of the root window. | |
| 85 // |update_last_loation_now| is used for the test to update the mouse | |
| 86 // location synchronously. | |
| 87 void MoveCursorTo(AshWindowTreeHost* ash_host, | |
| 88 const gfx::Point& point_in_screen, | |
| 89 bool update_last_location_now); | |
| 90 | 64 |
| 91 // Returns the index in the displays whose bounds contains |point_in_screen|. | 65 // Returns the index in the displays whose bounds contains |point_in_screen|. |
| 92 // Returns -1 if no such display exist. | 66 // Returns -1 if no such display exist. |
| 93 ASH_EXPORT int FindDisplayIndexContainingPoint( | 67 DISPLAY_EXPORT int FindDisplayIndexContainingPoint( |
| 94 const std::vector<display::Display>& displays, | 68 const std::vector<display::Display>& displays, |
| 95 const gfx::Point& point_in_screen); | 69 const gfx::Point& point_in_screen); |
| 96 | 70 |
| 97 // Sorts id list using |CompareDisplayIds| below. | 71 // Sorts id list using |CompareDisplayIds| below. |
| 98 ASH_EXPORT void SortDisplayIdList(display::DisplayIdList* list); | 72 DISPLAY_EXPORT void SortDisplayIdList(display::DisplayIdList* list); |
| 99 | 73 |
| 100 // Default id generator. | 74 // Default id generator. |
| 101 class DefaultDisplayIdGenerator { | 75 class DefaultDisplayIdGenerator { |
| 102 public: | 76 public: |
| 103 int64_t operator()(int64_t id) { return id; } | 77 int64_t operator()(int64_t id) { return id; } |
| 104 }; | 78 }; |
| 105 | 79 |
| 106 // Generate sorted display::DisplayIdList from iterators. | 80 // Generate sorted display::DisplayIdList from iterators. |
| 107 template <class ForwardIterator, class Generator = DefaultDisplayIdGenerator> | 81 template <class ForwardIterator, class Generator = DefaultDisplayIdGenerator> |
| 108 display::DisplayIdList GenerateDisplayIdList( | 82 display::DisplayIdList GenerateDisplayIdList( |
| 109 ForwardIterator first, | 83 ForwardIterator first, |
| 110 ForwardIterator last, | 84 ForwardIterator last, |
| 111 Generator generator = Generator()) { | 85 Generator generator = Generator()) { |
| 112 display::DisplayIdList list; | 86 display::DisplayIdList list; |
| 113 while (first != last) { | 87 while (first != last) { |
| 114 list.push_back(generator(*first)); | 88 list.push_back(generator(*first)); |
| 115 ++first; | 89 ++first; |
| 116 } | 90 } |
| 117 SortDisplayIdList(&list); | 91 SortDisplayIdList(&list); |
| 118 return list; | 92 return list; |
| 119 } | 93 } |
| 120 | 94 |
| 121 // Creates sorted display::DisplayIdList. | 95 // Creates sorted display::DisplayIdList. |
| 122 ASH_EXPORT display::DisplayIdList CreateDisplayIdList( | 96 DISPLAY_EXPORT display::DisplayIdList CreateDisplayIdList( |
| 123 const display::DisplayList& list); | 97 const display::DisplayList& list); |
| 124 | 98 |
| 125 ASH_EXPORT std::string DisplayIdListToString( | 99 DISPLAY_EXPORT std::string DisplayIdListToString( |
| 126 const display::DisplayIdList& list); | 100 const display::DisplayIdList& list); |
| 127 | 101 |
| 128 // Returns true if one of following conditinos is met. | 102 // Returns true if one of following conditions is met. |
| 129 // 1) id1 is internal. | 103 // 1) id1 is internal. |
| 130 // 2) output index of id1 < output index of id2 and id2 isn't internal. | 104 // 2) output index of id1 < output index of id2 and id2 isn't internal. |
| 131 ASH_EXPORT bool CompareDisplayIds(int64_t id1, int64_t id2); | 105 DISPLAY_EXPORT bool CompareDisplayIds(int64_t id1, int64_t id2); |
| 132 | 106 |
| 133 #if defined(OS_CHROMEOS) | 107 } // namespace ui |
| 134 // Shows the notification message for display related issues. | |
| 135 void ShowDisplayErrorNotification(int message_id); | |
| 136 #endif | |
| 137 | 108 |
| 138 ASH_EXPORT base::string16 GetDisplayErrorNotificationMessageForTest(); | 109 #endif // UI_DISPLAY_MANAGER_DISPLAY_MANAGER_UTILITIES_H_ |
| 139 | |
| 140 } // namespace ash | |
| 141 | |
| 142 #endif // ASH_DISPLAY_DISPLAY_UTIL_H_ | |
| OLD | NEW |