| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include <stdio.h> | |
| 6 | |
| 7 #include "ash/common/ash_switches.h" | |
| 8 #include "ash/display/display_layout_store.h" | |
| 9 #include "ash/display/display_manager.h" | |
| 10 #include "ash/display/display_util.h" | |
| 11 #include "ash/shell.h" | |
| 12 #include "base/command_line.h" | |
| 13 #include "base/logging.h" | |
| 14 #include "ui/display/display.h" | |
| 15 | |
| 16 namespace ash { | |
| 17 | |
| 18 DisplayLayoutStore::DisplayLayoutStore() | |
| 19 : default_display_placement_(display::DisplayPlacement::RIGHT, 0) { | |
| 20 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
| 21 if (command_line->HasSwitch(switches::kAshSecondaryDisplayLayout)) { | |
| 22 std::string value = | |
| 23 command_line->GetSwitchValueASCII(switches::kAshSecondaryDisplayLayout); | |
| 24 char layout; | |
| 25 int offset = 0; | |
| 26 if (sscanf(value.c_str(), "%c,%d", &layout, &offset) == 2) { | |
| 27 if (layout == 't') | |
| 28 default_display_placement_.position = display::DisplayPlacement::TOP; | |
| 29 else if (layout == 'b') | |
| 30 default_display_placement_.position = display::DisplayPlacement::BOTTOM; | |
| 31 else if (layout == 'r') | |
| 32 default_display_placement_.position = display::DisplayPlacement::RIGHT; | |
| 33 else if (layout == 'l') | |
| 34 default_display_placement_.position = display::DisplayPlacement::LEFT; | |
| 35 default_display_placement_.offset = offset; | |
| 36 } | |
| 37 } | |
| 38 } | |
| 39 | |
| 40 DisplayLayoutStore::~DisplayLayoutStore() {} | |
| 41 | |
| 42 void DisplayLayoutStore::SetDefaultDisplayPlacement( | |
| 43 const display::DisplayPlacement& placement) { | |
| 44 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
| 45 if (!command_line->HasSwitch(switches::kAshSecondaryDisplayLayout)) | |
| 46 default_display_placement_ = placement; | |
| 47 } | |
| 48 | |
| 49 void DisplayLayoutStore::RegisterLayoutForDisplayIdList( | |
| 50 const display::DisplayIdList& list, | |
| 51 std::unique_ptr<display::DisplayLayout> layout) { | |
| 52 // m50/51 dev/beta channel may have bad layout data saved in local state. | |
| 53 // TODO(oshima): Consider removing this after m53. | |
| 54 if (list.size() == 2 && layout->placement_list.size() > 1) | |
| 55 return; | |
| 56 | |
| 57 // Do not overwrite the valid data with old invalid date. | |
| 58 if (layouts_.count(list) && !CompareDisplayIds(list[0], list[1])) | |
| 59 return; | |
| 60 | |
| 61 // Old data may not have the display_id/parent_display_id. | |
| 62 // Guess these values based on the saved primary_id. | |
| 63 if (layout->placement_list.size() >= 1 && | |
| 64 layout->placement_list[0].display_id == | |
| 65 display::Display::kInvalidDisplayID) { | |
| 66 if (layout->primary_id == list[1]) { | |
| 67 layout->placement_list[0].display_id = list[0]; | |
| 68 layout->placement_list[0].parent_display_id = list[1]; | |
| 69 } else { | |
| 70 layout->placement_list[0].display_id = list[1]; | |
| 71 layout->placement_list[0].parent_display_id = list[0]; | |
| 72 } | |
| 73 } | |
| 74 DCHECK(display::DisplayLayout::Validate(list, *layout.get())) | |
| 75 << "ids=" << DisplayIdListToString(list) | |
| 76 << ", layout=" << layout->ToString(); | |
| 77 layouts_[list] = std::move(layout); | |
| 78 } | |
| 79 | |
| 80 const display::DisplayLayout& DisplayLayoutStore::GetRegisteredDisplayLayout( | |
| 81 const display::DisplayIdList& list) { | |
| 82 DCHECK_NE(1u, list.size()); | |
| 83 const auto iter = layouts_.find(list); | |
| 84 const display::DisplayLayout* layout = iter != layouts_.end() | |
| 85 ? iter->second.get() | |
| 86 : CreateDefaultDisplayLayout(list); | |
| 87 DCHECK(display::DisplayLayout::Validate(list, *layout)) << layout->ToString(); | |
| 88 DCHECK_NE(layout->primary_id, display::Display::kInvalidDisplayID); | |
| 89 return *layout; | |
| 90 } | |
| 91 | |
| 92 void DisplayLayoutStore::UpdateMultiDisplayState( | |
| 93 const display::DisplayIdList& list, | |
| 94 bool mirrored, | |
| 95 bool default_unified) { | |
| 96 DCHECK(layouts_.find(list) != layouts_.end()); | |
| 97 if (layouts_.find(list) == layouts_.end()) | |
| 98 CreateDefaultDisplayLayout(list); | |
| 99 | |
| 100 layouts_[list]->mirrored = mirrored; | |
| 101 layouts_[list]->default_unified = default_unified; | |
| 102 } | |
| 103 | |
| 104 display::DisplayLayout* DisplayLayoutStore::CreateDefaultDisplayLayout( | |
| 105 const display::DisplayIdList& list) { | |
| 106 std::unique_ptr<display::DisplayLayout> layout(new display::DisplayLayout); | |
| 107 // The first display is the primary by default. | |
| 108 layout->primary_id = list[0]; | |
| 109 layout->placement_list.clear(); | |
| 110 for (size_t i = 0; i < list.size() - 1; i++) { | |
| 111 display::DisplayPlacement placement(default_display_placement_); | |
| 112 placement.display_id = list[i + 1]; | |
| 113 placement.parent_display_id = list[i]; | |
| 114 layout->placement_list.push_back(placement); | |
| 115 } | |
| 116 layouts_[list] = std::move(layout); | |
| 117 auto iter = layouts_.find(list); | |
| 118 return iter->second.get(); | |
| 119 } | |
| 120 | |
| 121 } // namespace ash | |
| OLD | NEW |