Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ash / display / display_layout_store.cc
blobc002e04e8f79769c6c6ac79ad2fbd8861dcd5748
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.
5 #include <stdio.h>
7 #include "ash/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/gfx/display.h"
16 namespace ash {
18 DisplayLayoutStore::DisplayLayoutStore() {
19 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
20 if (command_line->HasSwitch(switches::kAshSecondaryDisplayLayout)) {
21 std::string value = command_line->GetSwitchValueASCII(
22 switches::kAshSecondaryDisplayLayout);
23 char layout;
24 int offset = 0;
25 if (sscanf(value.c_str(), "%c,%d", &layout, &offset) == 2) {
26 if (layout == 't')
27 default_display_layout_.position = DisplayLayout::TOP;
28 else if (layout == 'b')
29 default_display_layout_.position = DisplayLayout::BOTTOM;
30 else if (layout == 'r')
31 default_display_layout_.position = DisplayLayout::RIGHT;
32 else if (layout == 'l')
33 default_display_layout_.position = DisplayLayout::LEFT;
34 default_display_layout_.offset = offset;
39 DisplayLayoutStore::~DisplayLayoutStore() {
42 void DisplayLayoutStore::SetDefaultDisplayLayout(const DisplayLayout& layout) {
43 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
44 if (!command_line->HasSwitch(switches::kAshSecondaryDisplayLayout))
45 default_display_layout_ = layout;
48 void DisplayLayoutStore::RegisterLayoutForDisplayIdPair(
49 int64 id1,
50 int64 id2,
51 const DisplayLayout& layout) {
52 auto key = CreateDisplayIdPair(id1, id2);
53 paired_layouts_[key] = layout;
56 DisplayLayout DisplayLayoutStore::GetRegisteredDisplayLayout(
57 const DisplayIdPair& pair) {
58 std::map<DisplayIdPair, DisplayLayout>::const_iterator iter =
59 paired_layouts_.find(pair);
60 return
61 iter != paired_layouts_.end() ? iter->second : CreateDisplayLayout(pair);
64 DisplayLayout DisplayLayoutStore::ComputeDisplayLayoutForDisplayIdPair(
65 const DisplayIdPair& pair) {
66 DisplayLayout layout = GetRegisteredDisplayLayout(pair);
67 DCHECK_NE(layout.primary_id, gfx::Display::kInvalidDisplayID);
68 // Invert if the primary was swapped. If mirrored, first is always
69 // primary.
70 return (layout.primary_id == gfx::Display::kInvalidDisplayID ||
71 pair.first == layout.primary_id) ? layout : layout.Invert();
74 void DisplayLayoutStore::UpdateMultiDisplayState(const DisplayIdPair& pair,
75 bool mirrored,
76 bool default_unified) {
77 if (paired_layouts_.find(pair) == paired_layouts_.end())
78 CreateDisplayLayout(pair);
79 paired_layouts_[pair].mirrored = mirrored;
80 paired_layouts_[pair].default_unified = default_unified;
83 void DisplayLayoutStore::UpdatePrimaryDisplayId(const DisplayIdPair& pair,
84 int64 display_id) {
85 if (paired_layouts_.find(pair) == paired_layouts_.end())
86 CreateDisplayLayout(pair);
87 paired_layouts_[pair].primary_id = display_id;
90 DisplayLayout DisplayLayoutStore::CreateDisplayLayout(
91 const DisplayIdPair& pair) {
92 DisplayLayout layout = default_display_layout_;
93 layout.primary_id = pair.first;
94 paired_layouts_[pair] = layout;
95 return layout;
98 } // namespace ash