| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "chrome/browser/extensions/display_info_provider_chromeos.h" | 5 #include "chrome/browser/extensions/display_info_provider_chromeos.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "ash/display/display_configuration_controller.h" | 9 #include "ash/display/display_configuration_controller.h" |
| 10 #include "ash/display/display_manager.h" | 10 #include "ash/display/display_manager.h" |
| 11 #include "ash/shell.h" | 11 #include "ash/shell.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "extensions/common/api/system_display.h" | 13 #include "extensions/common/api/system_display.h" |
| 14 #include "ui/display/manager/display_layout.h" |
| 14 #include "ui/gfx/display.h" | 15 #include "ui/gfx/display.h" |
| 15 #include "ui/gfx/geometry/point.h" | 16 #include "ui/gfx/geometry/point.h" |
| 16 #include "ui/gfx/geometry/rect.h" | 17 #include "ui/gfx/geometry/rect.h" |
| 17 | 18 |
| 18 namespace extensions { | 19 namespace extensions { |
| 19 | 20 |
| 20 using api::system_display::Bounds; | 21 using api::system_display::Bounds; |
| 21 using api::system_display::DisplayUnitInfo; | 22 using api::system_display::DisplayUnitInfo; |
| 22 using api::system_display::DisplayProperties; | 23 using api::system_display::DisplayProperties; |
| 23 using api::system_display::Insets; | 24 using api::system_display::Insets; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 // vector orthogonal (and facing the positive side) to |vector| is positive. | 60 // vector orthogonal (and facing the positive side) to |vector| is positive. |
| 60 // | 61 // |
| 61 // An orthogonal vector of (a, b) is (b, -a), as the scalar product of these | 62 // An orthogonal vector of (a, b) is (b, -a), as the scalar product of these |
| 62 // two is 0. | 63 // two is 0. |
| 63 // So, (x, y) is over (a, b) if x * b + y * (-a) >= 0, which is equivalent to | 64 // So, (x, y) is over (a, b) if x * b + y * (-a) >= 0, which is equivalent to |
| 64 // x * b >= y * a. | 65 // x * b >= y * a. |
| 65 return static_cast<int64_t>(point.x()) * static_cast<int64_t>(vector.y()) >= | 66 return static_cast<int64_t>(point.x()) * static_cast<int64_t>(vector.y()) >= |
| 66 static_cast<int64_t>(point.y()) * static_cast<int64_t>(vector.x()); | 67 static_cast<int64_t>(point.y()) * static_cast<int64_t>(vector.x()); |
| 67 } | 68 } |
| 68 | 69 |
| 69 // Created ash::DisplayPlacement value for |rectangle| compared to the | 70 // Created display::DisplayPlacement value for |rectangle| compared to the |
| 70 // |reference| | 71 // |reference| |
| 71 // rectangle. | 72 // rectangle. |
| 72 // The layout consists of two values: | 73 // The layout consists of two values: |
| 73 // - position: Whether the rectangle is positioned left, right, over or under | 74 // - position: Whether the rectangle is positioned left, right, over or under |
| 74 // the reference. | 75 // the reference. |
| 75 // - offset: The rectangle's offset from the reference origin along the axis | 76 // - offset: The rectangle's offset from the reference origin along the axis |
| 76 // opposite the position direction (if the rectangle is left or right along | 77 // opposite the position direction (if the rectangle is left or right along |
| 77 // y-axis, otherwise along x-axis). | 78 // y-axis, otherwise along x-axis). |
| 78 // The rectangle's position is calculated by dividing the space in areas defined | 79 // The rectangle's position is calculated by dividing the space in areas defined |
| 79 // by the |reference|'s diagonals and finding the area |rectangle|'s center | 80 // by the |reference|'s diagonals and finding the area |rectangle|'s center |
| (...skipping 10 matching lines...) Expand all Loading... |
| 90 // | REFERENCE | | 91 // | REFERENCE | |
| 91 // | | | 92 // | | |
| 92 // | | | 93 // | | |
| 93 // +---------------------+ | 94 // +---------------------+ |
| 94 // +-------------------------------------------------+ | 95 // +-------------------------------------------------+ |
| 95 // | RECTANGLE x | | 96 // | RECTANGLE x | |
| 96 // +-------------------------------------------------+ | 97 // +-------------------------------------------------+ |
| 97 // | 98 // |
| 98 // The rectangle shares an egde with the reference's bottom edge, but it's | 99 // The rectangle shares an egde with the reference's bottom edge, but it's |
| 99 // center point is in the left area. | 100 // center point is in the left area. |
| 100 ash::DisplayPlacement CreatePlacementForRectangles( | 101 display::DisplayPlacement CreatePlacementForRectangles( |
| 101 const gfx::Rect& reference, | 102 const gfx::Rect& reference, |
| 102 const gfx::Rect& rectangle) { | 103 const gfx::Rect& rectangle) { |
| 103 // Translate coordinate system so origin is in the reference's top left point | 104 // Translate coordinate system so origin is in the reference's top left point |
| 104 // (so the reference's down-diagonal vector starts in the (0, 0)) and scale it | 105 // (so the reference's down-diagonal vector starts in the (0, 0)) and scale it |
| 105 // up by two (to avoid division when calculating the rectangle's center | 106 // up by two (to avoid division when calculating the rectangle's center |
| 106 // point). | 107 // point). |
| 107 gfx::Point center(2 * (rectangle.x() - reference.x()) + rectangle.width(), | 108 gfx::Point center(2 * (rectangle.x() - reference.x()) + rectangle.width(), |
| 108 2 * (rectangle.y() - reference.y()) + rectangle.height()); | 109 2 * (rectangle.y() - reference.y()) + rectangle.height()); |
| 109 gfx::Point down_diag(2 * reference.width(), 2 * reference.height()); | 110 gfx::Point down_diag(2 * reference.width(), 2 * reference.height()); |
| 110 | 111 |
| 111 bool is_top_right = PointIsOverRadiusVector(center, down_diag); | 112 bool is_top_right = PointIsOverRadiusVector(center, down_diag); |
| 112 | 113 |
| 113 // Translate the coordinating system again, so the bottom right point of the | 114 // Translate the coordinating system again, so the bottom right point of the |
| 114 // reference is origin (so the references up-diagonal starts at (0, 0)). | 115 // reference is origin (so the references up-diagonal starts at (0, 0)). |
| 115 // Note that the coordinate system is scaled by 2. | 116 // Note that the coordinate system is scaled by 2. |
| 116 center.Offset(0, -2 * reference.height()); | 117 center.Offset(0, -2 * reference.height()); |
| 117 // Choose the vector orientation so the points on the diagonal are considered | 118 // Choose the vector orientation so the points on the diagonal are considered |
| 118 // to be left. | 119 // to be left. |
| 119 gfx::Point up_diag(-2 * reference.width(), 2 * reference.height()); | 120 gfx::Point up_diag(-2 * reference.width(), 2 * reference.height()); |
| 120 | 121 |
| 121 bool is_bottom_right = PointIsOverRadiusVector(center, up_diag); | 122 bool is_bottom_right = PointIsOverRadiusVector(center, up_diag); |
| 122 | 123 |
| 123 ash::DisplayPlacement::Position position; | 124 display::DisplayPlacement::Position position; |
| 124 if (is_top_right) { | 125 if (is_top_right) { |
| 125 position = is_bottom_right ? ash::DisplayPlacement::RIGHT | 126 position = is_bottom_right ? display::DisplayPlacement::RIGHT |
| 126 : ash::DisplayPlacement::TOP; | 127 : display::DisplayPlacement::TOP; |
| 127 } else { | 128 } else { |
| 128 position = is_bottom_right ? ash::DisplayPlacement::BOTTOM | 129 position = is_bottom_right ? display::DisplayPlacement::BOTTOM |
| 129 : ash::DisplayPlacement::LEFT; | 130 : display::DisplayPlacement::LEFT; |
| 130 } | 131 } |
| 131 | 132 |
| 132 // If the rectangle with the calculated position would not have common side | 133 // If the rectangle with the calculated position would not have common side |
| 133 // with the reference, try to position it so it shares another edge with the | 134 // with the reference, try to position it so it shares another edge with the |
| 134 // reference. | 135 // reference. |
| 135 if (is_top_right == is_bottom_right) { | 136 if (is_top_right == is_bottom_right) { |
| 136 if (rectangle.y() > reference.y() + reference.height()) { | 137 if (rectangle.y() > reference.y() + reference.height()) { |
| 137 // The rectangle is left or right, but completely under the reference. | 138 // The rectangle is left or right, but completely under the reference. |
| 138 position = ash::DisplayPlacement::BOTTOM; | 139 position = display::DisplayPlacement::BOTTOM; |
| 139 } else if (rectangle.y() + rectangle.height() < reference.y()) { | 140 } else if (rectangle.y() + rectangle.height() < reference.y()) { |
| 140 // The rectangle is left or right, but completely over the reference. | 141 // The rectangle is left or right, but completely over the reference. |
| 141 position = ash::DisplayPlacement::TOP; | 142 position = display::DisplayPlacement::TOP; |
| 142 } | 143 } |
| 143 } else { | 144 } else { |
| 144 if (rectangle.x() > reference.x() + reference.width()) { | 145 if (rectangle.x() > reference.x() + reference.width()) { |
| 145 // The rectangle is over or under, but completely right of the reference. | 146 // The rectangle is over or under, but completely right of the reference. |
| 146 position = ash::DisplayPlacement::RIGHT; | 147 position = display::DisplayPlacement::RIGHT; |
| 147 } else if (rectangle.x() + rectangle.width() < reference.x()) { | 148 } else if (rectangle.x() + rectangle.width() < reference.x()) { |
| 148 // The rectangle is over or under, but completely left of the reference. | 149 // The rectangle is over or under, but completely left of the reference. |
| 149 position = ash::DisplayPlacement::LEFT; | 150 position = display::DisplayPlacement::LEFT; |
| 150 } | 151 } |
| 151 } | 152 } |
| 152 int offset = (position == ash::DisplayPlacement::LEFT || | 153 int offset = (position == display::DisplayPlacement::LEFT || |
| 153 position == ash::DisplayPlacement::RIGHT) | 154 position == display::DisplayPlacement::RIGHT) |
| 154 ? rectangle.y() | 155 ? rectangle.y() |
| 155 : rectangle.x(); | 156 : rectangle.x(); |
| 156 return ash::DisplayPlacement(position, offset); | 157 return display::DisplayPlacement(position, offset); |
| 157 } | 158 } |
| 158 | 159 |
| 159 // Updates the display layout for the target display in reference to the primary | 160 // Updates the display layout for the target display in reference to the primary |
| 160 // display. | 161 // display. |
| 161 void UpdateDisplayLayout(const gfx::Rect& primary_display_bounds, | 162 void UpdateDisplayLayout(const gfx::Rect& primary_display_bounds, |
| 162 int64_t primary_display_id, | 163 int64_t primary_display_id, |
| 163 const gfx::Rect& target_display_bounds, | 164 const gfx::Rect& target_display_bounds, |
| 164 int64_t target_display_id) { | 165 int64_t target_display_id) { |
| 165 ash::DisplayPlacement placement(CreatePlacementForRectangles( | 166 display::DisplayPlacement placement(CreatePlacementForRectangles( |
| 166 primary_display_bounds, target_display_bounds)); | 167 primary_display_bounds, target_display_bounds)); |
| 167 placement.display_id = target_display_id; | 168 placement.display_id = target_display_id; |
| 168 placement.parent_display_id = primary_display_id; | 169 placement.parent_display_id = primary_display_id; |
| 169 | 170 |
| 170 scoped_ptr<ash::DisplayLayout> layout(new ash::DisplayLayout); | 171 scoped_ptr<display::DisplayLayout> layout(new display::DisplayLayout); |
| 171 layout->placement_list.push_back(placement); | 172 layout->placement_list.push_back(placement); |
| 172 layout->primary_id = primary_display_id; | 173 layout->primary_id = primary_display_id; |
| 173 | 174 |
| 174 ash::Shell::GetInstance() | 175 ash::Shell::GetInstance() |
| 175 ->display_configuration_controller() | 176 ->display_configuration_controller() |
| 176 ->SetDisplayLayout(std::move(layout), false /* user_action */); | 177 ->SetDisplayLayout(std::move(layout), false /* user_action */); |
| 177 } | 178 } |
| 178 | 179 |
| 179 // Validates that parameters passed to the SetInfo function are valid for the | 180 // Validates that parameters passed to the SetInfo function are valid for the |
| 180 // desired display and the current display manager state. | 181 // desired display and the current display manager state. |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 } | 416 } |
| 416 return all_displays; | 417 return all_displays; |
| 417 } | 418 } |
| 418 | 419 |
| 419 // static | 420 // static |
| 420 DisplayInfoProvider* DisplayInfoProvider::Create() { | 421 DisplayInfoProvider* DisplayInfoProvider::Create() { |
| 421 return new DisplayInfoProviderChromeOS(); | 422 return new DisplayInfoProviderChromeOS(); |
| 422 } | 423 } |
| 423 | 424 |
| 424 } // namespace extensions | 425 } // namespace extensions |
| OLD | NEW |