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.
7 #include "ash/ash_switches.h"
8 #include "ash/display/display_layout_store.h"
9 #include "base/command_line.h"
10 #include "base/logging.h"
11 #include "ui/gfx/display.h"
15 DisplayLayoutStore::DisplayLayoutStore() {
16 base::CommandLine
* command_line
= base::CommandLine::ForCurrentProcess();
17 if (command_line
->HasSwitch(switches::kAshSecondaryDisplayLayout
)) {
18 std::string value
= command_line
->GetSwitchValueASCII(
19 switches::kAshSecondaryDisplayLayout
);
22 if (sscanf(value
.c_str(), "%c,%d", &layout
, &offset
) == 2) {
24 default_display_layout_
.position
= DisplayLayout::TOP
;
25 else if (layout
== 'b')
26 default_display_layout_
.position
= DisplayLayout::BOTTOM
;
27 else if (layout
== 'r')
28 default_display_layout_
.position
= DisplayLayout::RIGHT
;
29 else if (layout
== 'l')
30 default_display_layout_
.position
= DisplayLayout::LEFT
;
31 default_display_layout_
.offset
= offset
;
36 DisplayLayoutStore::~DisplayLayoutStore() {
39 void DisplayLayoutStore::SetDefaultDisplayLayout(const DisplayLayout
& layout
) {
40 base::CommandLine
* command_line
= base::CommandLine::ForCurrentProcess();
41 if (!command_line
->HasSwitch(switches::kAshSecondaryDisplayLayout
))
42 default_display_layout_
= layout
;
45 void DisplayLayoutStore::RegisterLayoutForDisplayIdPair(
48 const DisplayLayout
& layout
) {
49 paired_layouts_
[std::make_pair(id1
, id2
)] = layout
;
52 DisplayLayout
DisplayLayoutStore::GetRegisteredDisplayLayout(
53 const DisplayIdPair
& pair
) {
54 std::map
<DisplayIdPair
, DisplayLayout
>::const_iterator iter
=
55 paired_layouts_
.find(pair
);
57 iter
!= paired_layouts_
.end() ? iter
->second
: CreateDisplayLayout(pair
);
60 DisplayLayout
DisplayLayoutStore::ComputeDisplayLayoutForDisplayIdPair(
61 const DisplayIdPair
& pair
) {
62 DisplayLayout layout
= GetRegisteredDisplayLayout(pair
);
63 DCHECK_NE(layout
.primary_id
, gfx::Display::kInvalidDisplayID
);
64 // Invert if the primary was swapped. If mirrored, first is always
66 return (layout
.primary_id
== gfx::Display::kInvalidDisplayID
||
67 pair
.first
== layout
.primary_id
) ? layout
: layout
.Invert();
70 void DisplayLayoutStore::UpdateMirrorStatus(const DisplayIdPair
& pair
,
72 if (paired_layouts_
.find(pair
) == paired_layouts_
.end())
73 CreateDisplayLayout(pair
);
74 paired_layouts_
[pair
].mirrored
= mirrored
;
77 void DisplayLayoutStore::UpdatePrimaryDisplayId(const DisplayIdPair
& pair
,
79 if (paired_layouts_
.find(pair
) == paired_layouts_
.end())
80 CreateDisplayLayout(pair
);
81 paired_layouts_
[pair
].primary_id
= display_id
;
84 DisplayLayout
DisplayLayoutStore::CreateDisplayLayout(
85 const DisplayIdPair
& pair
) {
86 DisplayLayout layout
= default_display_layout_
;
87 layout
.primary_id
= pair
.first
;
88 paired_layouts_
[pair
] = layout
;