| 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" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 // | REFERENCE | | 90 // | REFERENCE | |
| 91 // | | | 91 // | | |
| 92 // | | | 92 // | | |
| 93 // +---------------------+ | 93 // +---------------------+ |
| 94 // +-------------------------------------------------+ | 94 // +-------------------------------------------------+ |
| 95 // | RECTANGLE x | | 95 // | RECTANGLE x | |
| 96 // +-------------------------------------------------+ | 96 // +-------------------------------------------------+ |
| 97 // | 97 // |
| 98 // The rectangle shares an egde with the reference's bottom edge, but it's | 98 // The rectangle shares an egde with the reference's bottom edge, but it's |
| 99 // center point is in the left area. | 99 // center point is in the left area. |
| 100 scoped_ptr<ash::DisplayPlacement> CreatePlacementForRectangles( | 100 ash::DisplayPlacement CreatePlacementForRectangles( |
| 101 const gfx::Rect& reference, | 101 const gfx::Rect& reference, |
| 102 const gfx::Rect& rectangle) { | 102 const gfx::Rect& rectangle) { |
| 103 // Translate coordinate system so origin is in the reference's top left point | 103 // 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 | 104 // (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 | 105 // up by two (to avoid division when calculating the rectangle's center |
| 106 // point). | 106 // point). |
| 107 gfx::Point center(2 * (rectangle.x() - reference.x()) + rectangle.width(), | 107 gfx::Point center(2 * (rectangle.x() - reference.x()) + rectangle.width(), |
| 108 2 * (rectangle.y() - reference.y()) + rectangle.height()); | 108 2 * (rectangle.y() - reference.y()) + rectangle.height()); |
| 109 gfx::Point down_diag(2 * reference.width(), 2 * reference.height()); | 109 gfx::Point down_diag(2 * reference.width(), 2 * reference.height()); |
| 110 | 110 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 position = ash::DisplayPlacement::RIGHT; | 146 position = ash::DisplayPlacement::RIGHT; |
| 147 } else if (rectangle.x() + rectangle.width() < reference.x()) { | 147 } else if (rectangle.x() + rectangle.width() < reference.x()) { |
| 148 // The rectangle is over or under, but completely left of the reference. | 148 // The rectangle is over or under, but completely left of the reference. |
| 149 position = ash::DisplayPlacement::LEFT; | 149 position = ash::DisplayPlacement::LEFT; |
| 150 } | 150 } |
| 151 } | 151 } |
| 152 int offset = (position == ash::DisplayPlacement::LEFT || | 152 int offset = (position == ash::DisplayPlacement::LEFT || |
| 153 position == ash::DisplayPlacement::RIGHT) | 153 position == ash::DisplayPlacement::RIGHT) |
| 154 ? rectangle.y() | 154 ? rectangle.y() |
| 155 : rectangle.x(); | 155 : rectangle.x(); |
| 156 return make_scoped_ptr(new ash::DisplayPlacement(position, offset)); | 156 return ash::DisplayPlacement(position, offset); |
| 157 } | 157 } |
| 158 | 158 |
| 159 // Updates the display layout for the target display in reference to the primary | 159 // Updates the display layout for the target display in reference to the primary |
| 160 // display. | 160 // display. |
| 161 void UpdateDisplayLayout(const gfx::Rect& primary_display_bounds, | 161 void UpdateDisplayLayout(const gfx::Rect& primary_display_bounds, |
| 162 int64_t primary_display_id, | 162 int64_t primary_display_id, |
| 163 const gfx::Rect& target_display_bounds, | 163 const gfx::Rect& target_display_bounds, |
| 164 int64_t target_display_id) { | 164 int64_t target_display_id) { |
| 165 scoped_ptr<ash::DisplayPlacement> placement(CreatePlacementForRectangles( | 165 ash::DisplayPlacement placement(CreatePlacementForRectangles( |
| 166 primary_display_bounds, target_display_bounds)); | 166 primary_display_bounds, target_display_bounds)); |
| 167 placement->display_id = target_display_id; | 167 placement.display_id = target_display_id; |
| 168 placement->parent_display_id = primary_display_id; | 168 placement.parent_display_id = primary_display_id; |
| 169 | 169 |
| 170 scoped_ptr<ash::DisplayLayout> layout(new ash::DisplayLayout); | 170 scoped_ptr<ash::DisplayLayout> layout(new ash::DisplayLayout); |
| 171 layout->placement_list.push_back(std::move(placement)); | 171 layout->placement_list.push_back(placement); |
| 172 layout->primary_id = primary_display_id; | 172 layout->primary_id = primary_display_id; |
| 173 | 173 |
| 174 ash::Shell::GetInstance() | 174 ash::Shell::GetInstance() |
| 175 ->display_configuration_controller() | 175 ->display_configuration_controller() |
| 176 ->SetDisplayLayout(std::move(layout), false /* user_action */); | 176 ->SetDisplayLayout(std::move(layout), false /* user_action */); |
| 177 } | 177 } |
| 178 | 178 |
| 179 // Validates that parameters passed to the SetInfo function are valid for the | 179 // Validates that parameters passed to the SetInfo function are valid for the |
| 180 // desired display and the current display manager state. | 180 // desired display and the current display manager state. |
| 181 // Returns whether the parameters are valid. On failure |error| is set to the | 181 // Returns whether the parameters are valid. On failure |error| is set to the |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 } | 415 } |
| 416 return all_displays; | 416 return all_displays; |
| 417 } | 417 } |
| 418 | 418 |
| 419 // static | 419 // static |
| 420 DisplayInfoProvider* DisplayInfoProvider::Create() { | 420 DisplayInfoProvider* DisplayInfoProvider::Create() { |
| 421 return new DisplayInfoProviderChromeOS(); | 421 return new DisplayInfoProviderChromeOS(); |
| 422 } | 422 } |
| 423 | 423 |
| 424 } // namespace extensions | 424 } // namespace extensions |
| OLD | NEW |